// // C++ Implementation: PndMvdGeoHandling // // Description: // // // Author: t.stockmanns , (C) 2007 // // Copyright: See COPYING file that comes with this distribution // // #include "PndMvdGeoHandling.h" #include "PndStringVector.h" #include #include #include "PndStringVector.h" #include "TROOT.h" #include "TGeoManager.h" ClassImp(PndMvdGeoHandling); PndMvdGeoHandling::PndMvdGeoHandling() { if (gROOT->FindObjectAny("CBMGeom") == 0){ std::cout << " -E- PndMvdGeoHandling: No Geometry existing!" << std::endl; return; } fGeoMan = gGeoManager; } PndMvdGeoHandling::PndMvdGeoHandling(TString fileName) { if (gROOT->FindObjectAny("CBMGeom") == 0){ TGeoManager* fGeoMan = new TGeoManager("geoMan","geoMan"); fGeoMan->Import(fileName.Data()); } fGeoMan = gGeoManager; } TString PndMvdGeoHandling::GetCurrentID() { Int_t level; Int_t copyNr[100]; Int_t volNr[100]; TString result; level = fGeoMan->GetLevel(); level++; fGeoMan->GetBranchNumbers(copyNr, volNr); for (int i=0; iGetPath(); fGeoMan->cd(path.Data()); result = GetCurrentID(); fGeoMan->cd(currentPath.Data()); return result; } TString PndMvdGeoHandling::GetPath(TString id) { TString result; std::vector idVector; PndStringVector pathAna(id.Data(), "/_"); idVector = pathAna.GetStringVector(); for(Int_t i = 0; i < idVector.size(); i+=2){ result += "/"; Int_t VolId = atoi(idVector[i].c_str()); Int_t CopyNr = atoi(idVector[i+1].c_str()); result += fGeoMan->GetVolume(VolId)->GetName(); result += "_"; result += CopyNr; } return result; } Bool_t PndMvdGeoHandling::cd(TString id) { return fGeoMan->cd(GetPath(id).Data()); } TString PndMvdGeoHandling::GetVolumeID(TString name) { TString result; TGeoVolume* vol = fGeoMan->FindVolumeFast(name); if (vol == 0) return result; result += vol->GetNumber(); return result; } std::vector PndMvdGeoHandling::GetNamesLevel(Int_t level, TString startPath, bool fullPath) { TString actPath = fGeoMan->GetPath(); fLevelNames.clear(); if (startPath == ""){ fGeoMan->CdTop(); fLevel = level; } else{ if (fGeoMan->cd(startPath.Data())== 0) return fLevelNames; else { fLevel = fGeoMan->GetLevel() + level; } } FillLevelNames(); return fLevelNames; } void PndMvdGeoHandling::FillLevelNames() { TGeoNode* myNode = fGeoMan->GetCurrentNode(); if (fLevel == fGeoMan->GetLevel()){ if (fFullPath) fLevelNames.push_back(fGeoMan->GetPath()); else fLevelNames.push_back(myNode->GetName()); } else { Int_t nDaughters = myNode->GetNdaughters(); for (Int_t i = 0; i < nDaughters; i++){ fGeoMan->CdDown(i); FillLevelNames(); fGeoMan->CdUp(); } } } void PndMvdGeoHandling::GetOUVPath(TString path, TVector3& o, TVector3& u, TVector3& v) { Double_t result[3]; Double_t* temp; TString actPath = fGeoMan->GetPath(); fGeoMan->cd(path); TGeoHMatrix* currMatrix = fGeoMan->GetCurrentMatrix(); temp = currMatrix->GetTranslation(); o.SetXYZ(temp[0], temp[1], temp[2]); temp[0] = 1; temp[1] = 0; temp[2] = 0; fGeoMan->LocalToMasterVect(temp, result); u.SetXYZ(result[0], result[1], result[2]); temp[0] = 0; temp[1] = 1; temp[2] = 0; fGeoMan->LocalToMasterVect(temp, result); v.SetXYZ(result[0], result[1], result[2]); } void PndMvdGeoHandling::GetOUVId(TString id, TVector3& o, TVector3& u, TVector3& v) { GetOUVPath(GetPath(id),o,u,v); }