28 #include <TCollection.h>
30 #include <TGeoManager.h>
31 #include <TGeoMaterial.h>
32 #include <TGeoMatrix.h>
33 #include <TGeoMedium.h>
35 #include <TGeoVolume.h>
36 #include <TGeoVoxelFinder.h>
39 #include <TObjArray.h>
41 #include <TRefArray.h>
43 #include <TVirtualMC.h>
46 #include <TGDMLParse.h>
63 <<
"The method ConstructGeometry has to be implemented in the detector class which inherits from FairModule";
69 <<
"The method ConstructOpGeometry has to be implemented in the detector class which inherits from FairModule";
76 , fMotherVolumeName(
"")
77 , fgeoVer(
"Not defined")
78 , fgeoName(
"Not defined")
81 , fNbOfSensitiveVol(0)
97 , fMotherVolumeName(rhs.fMotherVolumeName)
98 , fgeoVer(rhs.fgeoVer)
99 , fgeoName(rhs.fgeoName)
101 , fActive(rhs.fActive)
102 , fNbOfSensitiveVol(rhs.fNbOfSensitiveVol)
103 , fVerboseLevel(rhs.fVerboseLevel)
105 , fGeoSaved(rhs.fGeoSaved)
110 for (Int_t i = 0; i < rhs.
svList->GetEntries(); i++) {
123 fMC = TVirtualMC::GetMC();
137 , fMotherVolumeName(
"")
138 , fgeoVer(
"Not defined")
139 , fgeoName(
"Not defined")
142 , fNbOfSensitiveVol(0)
156 TNamed::operator=(rhs);
168 fMC = TVirtualMC::GetMC();
182 void FairModule::Streamer(TBuffer& b)
204 if (fname.BeginsWith(
"/")) {
205 if (gSystem->AccessPathName(fname.Data())) {
206 LOG(fatal) << fName <<
": geometry file " << fname <<
" not found in absolut path!";
210 LOG(debug) << fName <<
": using geometry file " <<
fgeoName;
216 TString userPath = getenv(
"GEOMPATH");
217 userPath.ReplaceAll(
"//",
"/");
218 if (!userPath.IsNull()) {
219 if (!userPath.EndsWith(
"/")) {
223 if (!gSystem->AccessPathName(
fgeoName.Data())) {
224 LOG(debug) << fName <<
": using geometry file " <<
fgeoName;
227 LOG(debug) << fName <<
": geometry file " << fname <<
" not found in GEOMPATH " << userPath;
233 if (!gSystem->AccessPathName(
fgeoName.Data())) {
234 LOG(debug) << fName <<
": using geometry file " <<
fgeoName;
239 LOG(fatal) << fName <<
": geometry file " << fname <<
" not found in standard path ";
247 LOG(fatal) <<
"Detected call to FairModule::ProcessNodes() \
248 while not in FairMCApplication::ConstructGeometry()\n\
249 Call templated function FairModule::ConstructASCIIGeometry()\
250 from ConstructGeometry() of your detector class. Aborting...";
260 TListIter iter(aList);
267 while ((node = static_cast<FairGeoNode*>(iter.Next()))) {
277 if (MotherNode != 0) {
288 fNodes->AddLast(aVol);
297 LOG(debug2) <<
"AddSensitiveVolume " << v->GetName();
337 TGeoManager* OldGeo = gGeoManager;
338 TGeoManager* NewGeo = 0;
339 TGeoVolume* volume = 0;
342 TList* l = f->GetListOfKeys();
347 while ((key = static_cast<TKey*>(next()))) {
351 if (strcmp(key->GetClassName(),
"TGeoManager") != 0) {
355 NewGeo =
static_cast<TGeoManager*
>(key->ReadObj());
363 volume =
static_cast<TGeoVolume*
>(NewGeo->GetNode(0)->GetDaughter(0)->GetVolume());
364 v1 = volume->MakeCopyVolume(volume->GetShape());
375 key =
static_cast<TKey*
>(l->At(0));
376 volume =
dynamic_cast<TGeoVolume*
>(key->ReadObj());
378 n = volume->GetNode(0);
388 gGeoManager = OldGeo;
393 TGeoVolume* Cave =
nullptr;
395 Cave = gGeoManager->GetTopVolume();
399 if (Cave !=
nullptr) {
401 gGeoManager->AddVolume(v1);
403 TGeoVoxelFinder* voxels = v1->GetVoxels();
405 voxels->SetNeedRebuild();
415 TGeoMatrix* M = n->GetMatrix();
418 TGeoHMatrix* M2 =
new TGeoHMatrix(*M);
431 M2->Multiply(shiftM);
434 SetDefaultMatrixName(M2);
442 gGeoManager->GetListOfMatrices()->Remove(M2);
443 TGeoHMatrix* global = gGeoManager->GetHMatrix();
444 gGeoManager->GetListOfMatrices()->Remove(global);
447 Cave->AddNode(v1, 0, M2);
450 AssignMediumAtImport(v1);
459 <<
" where the geomanger should be added.";
478 gGeoManager->GetTopVolume()->AddNode(gdmlTop, 1, posrot);
479 ExpandNodeForGDML(gGeoManager->GetTopVolume()->GetNode(gGeoManager->GetTopVolume()->GetNdaughters() - 1));
486 TGeoVolume* curVol = curNode->GetVolume();
487 AssignMediumAtImport(curVol);
490 if ((this->InheritsFrom(
"FairDetector")) &&
IsSensitive(curVol->GetName())) {
491 LOG(debug2) <<
"Sensitive Volume " << curVol->GetName();
496 if (curVol->GetNdaughters() != 0) {
497 TObjArray* NodeChildList = curVol->GetNodes();
498 TGeoNode* curNodeChild;
499 for (Int_t j = 0; j < NodeChildList->GetEntriesFast(); j++) {
500 curNodeChild =
static_cast<TGeoNode*
>(NodeChildList->At(j));
510 LOG(error) <<
"Could not construct magnet geometry from gdml file.";
511 LOG(error) <<
"The used ROOT version does not support gdml.";
512 LOG(error) <<
"Please recompile ROOT with gdml support.";
513 LOG(fatal) <<
"Stop execution at this point.";
520 void FairModule::ReAssignMediaId()
525 TList* media = gGeoManager->GetListOfMedia();
529 for (Int_t i = geoBuilder->
GetNMedia(); i < media->GetEntries(); i++) {
530 med =
static_cast<TGeoMedium*
>(media->At(i));
534 geoBuilder->
SetNMedia(media->GetEntries());
537 TList* materials = gGeoManager->GetListOfMaterials();
538 TIter next1(materials);
540 std::map<TString, Bool_t> mapMatName;
542 while ((mat = static_cast<TGeoMaterial*>(next1()))) {
544 if (mapMatName[mat->GetName()]) {
545 materials->Remove(mat);
547 mapMatName[mat->GetName()] = kTRUE;
554 LOG(warn) <<
"The method ConstructASCIIGeometry has to be implemented in the detector class which inherits from "
563 #pragma GCC diagnostic push
564 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
566 #pragma GCC diagnostic pop
575 TGeoMatrix* Matrix = fN->GetMatrix();
576 if (gGeoManager->GetListOfMatrices()->FindObject(Matrix)) {
577 gGeoManager->GetListOfMatrices()->Remove(Matrix);
579 TGeoVolume* v1 = fN->GetVolume();
580 TObjArray* NodeList = v1->GetNodes();
581 for (Int_t Nod = 0; Nod < NodeList->GetEntriesFast(); Nod++) {
582 TGeoNode* fNode =
static_cast<TGeoNode*
>(NodeList->At(Nod));
583 TGeoMatrix* M = fNode->GetMatrix();
585 SetDefaultMatrixName(M);
586 if (fNode->GetNdaughters() > 0) {
589 TGeoVolume* v = fNode->GetVolume();
590 AssignMediumAtImport(v);
591 if (!gGeoManager->FindVolumeFast(v->GetName())) {
592 LOG(debug2) <<
"Register Volume " << v->GetName();
593 v->RegisterYourself();
595 if ((this->InheritsFrom(
"FairDetector")) &&
IsSensitive(v->GetName())) {
596 LOG(debug2) <<
"Sensitive Volume " << v->GetName();
599 v->GetShape()->AfterStreamer();
603 void FairModule::SetDefaultMatrixName(TGeoMatrix* matrix)
618 if (strlen(matrix->GetName())) {
622 if (matrix->IsTranslation()) {
625 if (matrix->IsRotation()) {
628 if (matrix->IsScale()) {
631 if (matrix->IsCombi()) {
634 if (matrix->IsGeneral()) {
637 TObjArray* matrices = gGeoManager->GetListOfMatrices();
640 index = matrices->GetEntriesFast() - 1;
642 matrix->SetName(Form(
"%c%i", type, index));
645 void FairModule::AssignMediumAtImport(TGeoVolume* v)
656 TGeoMedium* med1 = v->GetMedium();
667 TString medName =
static_cast<TString
>(med1->GetName());
668 if (medName.EqualTo(
"dummy") &&
nullptr == gGeoManager->GetMedium(medName)) {
670 TGeoMaterial* dummyMaterial =
new TGeoMaterial();
671 dummyMaterial->SetName(
"dummy");
673 TGeoMedium* dummyMedium =
new TGeoMedium();
674 dummyMedium->SetName(
"dummy");
675 dummyMedium->SetMaterial(dummyMaterial);
677 gGeoManager->GetListOfMedia()->Add(dummyMedium);
678 gGeoManager->AddMaterial(dummyMaterial);
681 TGeoMaterial* mat1 = v->GetMaterial();
682 TGeoMaterial* newMat = gGeoManager->GetMaterial(mat1->GetName());
688 LOG(fatal) <<
"Material " << mat1->GetName() <<
"is not defined in ASCII file nor in Root file.";
694 v->SetMedium(gGeoManager->GetMedium(nmed));
695 gGeoManager->SetAllIndex();
699 TGeoMedium* med2 = gGeoManager->GetMedium(mat1->GetName());
703 if (strcmp(v->ClassName(),
"TGeoVolumeAssembly") != 0) {
705 LOG(fatal) <<
"The volume " << v->GetName()
706 <<
"has no medium information and not an Assembly so we have to quit";
713 Fatal(
"CloneModule",
"Has to be overriden in multi-threading applications.");
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
void AddSensitiveVolume(TGeoVolume *v)
void SetNMedia(const Int_t &nmed)
virtual void see Tutorial4 for examples LOG(warn)<< "This function is deprecated. Use FairAlignmentHandler instead
virtual void ConstructGeometry()
list of container factories
FairGeoMedia * getMedia()
FairGeoNode * getMotherNode()
static thread_local TRefArray * svList
TObjArray * GetGeoNodes()
FairGeoTransform * calcLabTransform()
virtual void ConstructOpGeometry()
static thread_local Int_t fNbOfVolumes
void setGeoNode(FairGeoNode *d)
void ProcessNodes(TList *aList)
FairGeoInterface * getGeoInterface()
static FairGeoLoader * Instance()
static FairRun * Instance()
FairGeoNode * getGeoNode()
ClassImp(FairEventBuilder)
Bool_t fGeoSaved
list of Detector Geometry parameters
virtual void ConstructGDMLGeometry(__attribute__((unused)) TGeoMatrix *posrot)
static thread_local FairVolumeList * vList
virtual void ConstructASCIIGeometry()
TVirtualMC * fMC
flag for initialisation
virtual void ExpandNode(TGeoNode *Node)
static thread_local TArrayI * volNumber
FairParSet * getContainer(const Text_t *)
void SetModule(FairModule *mod)
virtual void ExpandNodeForGDML(__attribute__((unused)) TGeoNode *curNode)
const Int_t & GetNMedia() const
static FairMCApplication * Instance()
FairModule & operator=(const FairModule &)
void addVolume(FairVolume *elem)
FairMQExParamsParOne * par
virtual FairModule * CloneModule() const
FairGeoBuilder * getGeoBuilder()
virtual void ConstructRootGeometry(TGeoMatrix *shiftM=nullptr)
FairRuntimeDb * GetRuntimeDb(void)
const char * getTruncName()
void setMotherId(Int_t fM)
virtual TString GetGeometryFileName()
virtual Bool_t CheckIfSensitive(__attribute__((unused)) std::string name) __attribute__((deprecated("The method CheckIfSensitive is deprecated. Implement IsSensitive in the detector classes.")))
virtual Bool_t IsSensitive(const std::string &name)
TString fMotherVolumeName
virtual Int_t createMedium(FairGeoMedium *)=0
void setMotherCopyNo(Int_t CopyNo)
FairVolume * getFairVolume(FairGeoNode *fNode)
void setRealName(TString name)
FairVolume * At(Int_t pos)
FairVolume * findObject(TString name)