19 #include "TGeoVolume.h"
20 #include "TGeoShape.h"
24 #include "FairMCEventHeader.h"
25 #include "FairParRootFileIo.h"
26 #include "FairBaseParSet.h"
38 std::cout<<
"Info in (PndGeoHandling::Instance): Making a new instance using the framework."<<std::endl;
48 FairRun*
run = FairRun::Instance();
52 this->
SetName(
"PndGeoHandling");
54 run->AddTask((FairTask*)
this);
55 fRtdb = run->GetRuntimeDb();
59 std::cout <<
"PndGeoHandling. No FairRun object found. If used in a macro take another constructor." << std::endl;
76 FairRun*
run = FairRun::Instance();
77 if (!run) Fatal(
"PndGeoHandling",
"No FairRun object found.");
78 fRtdb = run->GetRuntimeDb();
79 if (!
fRtdb) Fatal(
"PndGeoHandling",
"No runtime database found.");
81 if (
fRunId < 0) Error(
"PndGeoHandling",
"No valid run ID? %i",
fRunId);
84 if (!
fGeoMan) Fatal(
"PndGeoHandling",
"No gGeoManager found.");
86 if ( !
fSensorNamePar) Fatal(
"PndGeoHandling",
"No PndSensorNamePar parameters found.");
88 FairTask::SetParContainers();
132 TFile
f(mcFile.Data());
133 TTree*
t = (TTree*)
f.Get(
"pndsim");
134 FairMCEventHeader* header=
new FairMCEventHeader();
135 t->SetBranchStatus(
"MCEventHeader.",1);
136 t->SetBranchAddress(
"MCEventHeader.", &header);
138 fRunId = header->GetRunID();
140 t->SetBranchStatus(
"MCEventHeader.",0);
151 std::cout <<
"PndGeoHandling::GetSensorNamePar()" << std::endl;
159 fRtdb = FairRuntimeDb::instance();
160 FairParRootFileIo*
parInput1 =
new FairParRootFileIo(kTRUE);
161 parInput1->open(parFileName.Data(),
"UPDATE");
162 fRtdb->setFirstInput(parInput1);
163 fRtdb->setOutput(parInput1);
170 FairBaseParSet*
par=(FairBaseParSet*)(
fRtdb->getContainer(
"FairGeoParSet"));
211 TObjString myPath(path.Data());
218 std::cout <<
"-E- PndGeoHandling::GetShortID: SensorNamePar is missing!" << std::endl;
228 std::cout <<
"-E- PndGeoHandling::GetPath(Int_t shortID): Missing SensorNamePar" << std::endl;
274 TGeoVolume* vol =
fGeoMan->FindVolumeFast(name);
277 result += vol->GetNumber();
286 if (startPath ==
""){
291 if (
fGeoMan->cd(startPath.Data())== 0)
303 TGeoNode* myNode =
fGeoMan->GetCurrentNode();
311 Int_t nDaughters = myNode->GetNdaughters();
312 for (Int_t
i = 0;
i < nDaughters;
i++){
327 TGeoHMatrix* currMatrix =
fGeoMan->GetCurrentMatrix();
328 temp = currMatrix->GetTranslation();
329 o.SetXYZ(temp[0], temp[1], temp[2]);
334 fGeoMan->LocalToMasterVect(temp, result);
335 u.SetXYZ(result[0], result[1], result[2]);
340 fGeoMan->LocalToMasterVect(temp, result);
341 v.SetXYZ(result[0], result[1], result[2]);
343 if(actPath!=
"" && actPath!=
" ")
fGeoMan->cd(actPath);
359 TGeoVolume* actVolume =
gGeoManager->GetCurrentVolume();
360 TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
361 dim.SetX(actBox->GetDX());
362 dim.SetY(actBox->GetDY());
363 dim.SetZ(actBox->GetDZ());
365 if(actPath!=
"" && actPath!=
" ")
fGeoMan->cd(actPath);
381 TGeoHMatrix* currMatrix =
fGeoMan->GetCurrentMatrix();
407 temp[0] = master.X();
408 temp[1] = master.Y();
409 temp[2] = master.Z();
413 fGeoMan->MasterToLocal(temp, result);
414 if(actPath !=
"" && actPath !=
" ")
fGeoMan->cd(actPath);
415 return TVector3(result[0],result[1],result[2]);
435 fGeoMan->LocalToMaster(temp, result);
436 if(actPath !=
"" && actPath !=
" ")
fGeoMan->cd(actPath);
437 return TVector3(result[0],result[1],result[2]);
456 std::cout<<
" -I- PndGeoHandling::MasterToLocalErrorsPath: print matrices: master, rotation, result=R*M*R^T"<<std::endl;
461 if(actPath !=
"" && actPath !=
" ")
fGeoMan->cd(actPath);
481 std::cout<<
" -I- PndGeoHandling::LocalToMasterErrorsPath: print matrices: master, rotation, result=R^T*M*R"<<std::endl;
486 if(actPath !=
"" && actPath !=
" ")
fGeoMan->cd(actPath);
511 const char* oldpath =
fGeoMan->GetPath();
522 TGeoNode *currentNode =
fGeoMan->GetCurrentNode();
523 if (currentNode == node)
return;
524 for (Int_t iNod=0; iNod<currentNode->GetNdaughters();iNod++)
528 if (
fGeoMan->GetCurrentNode() == node)
return;
535 TGeoNode *currentNode =
fGeoMan->GetCurrentNode();
536 TString nodeName(currentNode->GetName());
537 if (nodeName.Contains(name)){
540 for (Int_t iNod = 0; iNod < currentNode->GetNdaughters(); iNod++) {
543 nodeName =
fGeoMan->GetCurrentNode()->GetName();
544 if (nodeName.Contains(name)){
554 TGeoNode *currentNode =
fGeoMan->GetCurrentNode();
555 TString nodeName(currentNode->GetName());
561 if (sepString.size() > 0 && sepString[sepString.size() - 1].find(
"PartAss") == std::string::npos){
562 TObjString* myName =
new TObjString(
fGeoMan->GetPath());
566 for (Int_t iNod = 0; iNod < currentNode->GetNdaughters(); iNod++) {
574 std::cout <<
"-E- PndMvdGeoHandling::DiveDownToFillSensNamePar: fSensorNamePar does not exist!" << std::endl;
591 std::cout <<
"-I- PndMvdGeoHandling::CreateUniqueSensorId: StartNode: " <<
fGeoMan->GetPath() << std::endl;
598 for (
unsigned int i = 0;
i < listOfSensitives.size();
i++){
599 if (path.Contains(listOfSensitives[
i].c_str()))
TString FindNodePath(TGeoNode *node)
Int_t GetRunId(TString mcFile)
void DiveDownToNode(TGeoNode *node)
void DiveDownToNodeContainingString(TString name)
runs through the GeoManager until a path is found with a substring which matches to the given string ...
cout<< "-----------------------------------------------> Quarter VOLUME<<endl;name="QuarterShape";QuarterShape=newTGeoArb8(name,dz,vertQuar);name="Quarter4Vol";TStringmedium="air";QuarterVol=newTGeoVolumeAssembly(name);name="SubunitShape";SubunitShape=newTGeoArb8(name,dz,vertSub);TStringmedium="air";name="SubunitVol";name1="SubunitVol1";name2="SubunitVol2";name3="SubunitVol3";name4="SubunitVol4";name5="SubunitVol5";name6="SubunitVol6";name7="SubunitVol7";name8="SubunitVol8";name9="SubunitVol9";SubunitVol=newTGeoVolumeAssembly(name);SubunitVol1=newTGeoVolumeAssembly(name1);SubunitVol2=newTGeoVolumeAssembly(name2);SubunitVol3=newTGeoVolumeAssembly(name3);SubunitVol4=newTGeoVolumeAssembly(name4);SubunitVol5=newTGeoVolumeAssembly(name5);SubunitVol6=newTGeoVolumeAssembly(name6);SubunitVol7=newTGeoVolumeAssembly(name7);SubunitVol8=newTGeoVolumeAssembly(name8);SubunitVol9=newTGeoVolumeAssembly(name9);name="BoxShape";BoxShape=newTGeoArb8(name,dz,vertBox);TStringmedium="air";name="BoxVol";BoxVol=newTGeoVolumeAssembly(name);name1="BoxVol1";name2="BoxVol2";name3="BoxVol3";name4="BoxVol4";BoxVol1=newTGeoVolumeAssembly(name1);BoxVol2=newTGeoVolumeAssembly(name2);BoxVol3=newTGeoVolumeAssembly(name3);BoxVol4=newTGeoVolumeAssembly(name4);for(Int_tb=0;b<kNumOfBoxes;b++){cout<<""<<endl;cout<<"---------------->BOXnumber:"<<b<<endl;if(b==0){trBox=newTGeoTranslation(tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(0.465518);rotBox.RotateY(-0.465518);}if(b==1){trBox=newTGeoTranslation(-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(-0.465518);rotBox.RotateY(0.465518);}if(b==2){trBox=newTGeoTranslation(tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(-0.465518);rotBox.RotateY(-0.465518);}if(b==3){trBox=newTGeoTranslation(-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(0.465518);rotBox.RotateY(0.465518);}TGeoCombiTrans*trrotBox=newTGeoCombiTrans(trBox,rotBox);name="BoxVol";name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol->AddNode(BoxVol,b,trrotBox);if(b==1){name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol1->AddNode(BoxVol,b,trrotBox);}if(b==2){name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol2->AddNode(BoxVol1,b,trrotBox);}if(b==0){name+=b;trrotBox-> SetName(name)
std::vector< std::string > GetStringVector(void)
TGeoHMatrix * GetMatrixPath(TString path)
std::vector< TString > fLevelNames
virtual void SetParContainers()
void CreateUniqueSensorId(TString startName, std::vector< std::string > listOfSensitives)
Has to be called during simulation to create unique sensor id.
TString GetSensorName(Int_t index)
TVector3 GetSensorDimensionsPath(TString path)
Int_t SensorInList(TObjString *name)
TGeoManager * gGeoManager
TVector3 MasterToLocalPath(const TVector3 &master, const TString &id)
void FillLevelNames()
fills vector fLevelNames with the names (or the paths) of the volumes down to the level give...
static PndGeoHandling * fInstance
TString GetPath(Int_t shortID)
for a given shortID the path is returned
Int_t AddSensorName(TObjString *name)
h_MC_angle SetTitle("MC truth: opening angle of #pi^{0}")
Class to access the naming information of the MVD.
TString GetVolumeID(TString name)
returns the volume ID for a given volume name
void GetOUVPath(TString path, TVector3 &o, TVector3 &u, TVector3 &v)
for a volume given by its path the o, u, v vectors for the plane are returned
TMatrixD GetCurrentRotationMatrix()
void InitRuntimeDb(TString parFileName)
TMatrixD LocalToMasterErrorsPath(const TMatrixD &local, const TString &id)
Bool_t cd(Int_t id)
as the cd command of TGeoManager just with the ID
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
TVector3 LocalToMasterPath(const TVector3 &local, const TString &id)
static PndGeoHandling * Instance()
FairParRootFileIo * parInput1
TMatrixD MasterToLocalErrorsPath(const TMatrixD &master, const TString &id)
void DiveDownToFillSensNamePar(std::vector< std::string > listOfSensitives)
bool VolumeIsSensitive(TString &path, std::vector< std::string > &listOfSensitives)
Checks if the path contains a substring which matches one of the given strings in listOfSensitives...
PndSensorNamePar * fSensorNamePar
TMatrixT< double > TMatrixD
std::vector< TString > GetNamesLevel(Int_t level, TString startPath="")
PndGeoHandling()
default constructor. Has to be called in SetParContainers if the support of shortId is needed...
Unique match between SensorID and path in TGeoManager.