EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmModule.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmModule.cxx
1 #include "CbmModule.h"
2 
3 #include "FairGeoLoader.h"
4 #include "FairGeoInterface.h"
5 #include "FairGeoMedium.h"
6 #include "FairGeoMedia.h"
7 #include "FairGeoBuilder.h"
8 #include "FairLogger.h"
9 
10 #include "TGDMLParse.h"
11 #include "TGeoManager.h"
12 #include "TGeoMatrix.h"
13 #include "TGeoNode.h"
14 #include "TList.h"
15 #include "TFile.h"
16 
17 std::map<TString, Int_t> CbmModule::fixedMats;
18 Bool_t CbmModule::isFirstGDML=false;
19 
21 {
22 }
23 
24 CbmModule::CbmModule(const char* name, const char* Title)
25  : FairModule (name, Title)
26 {
27 }
28 
30 {
31 }
32 
33 #ifdef ROOT_HAS_GDML
34 void CbmModule::ConstructGDMLGeometry(TGeoMatrix* posrot)
35 {
36  TFile *old = gFile;
37  TGDMLParse parser;
38  TGeoVolume* gdmlTop;
39  gdmlTop = parser.GDMLReadFile(GetGeometryFileName());
40  gGeoManager->GetTopVolume()->AddNode(gdmlTop,1,posrot);
41  ExpandNodeForGDML(gGeoManager->GetTopVolume()->GetNode(gGeoManager->GetTopVolume()->GetNdaughters()-1));
42  isFirstGDML = 0;
43  gFile = old;
44 }
45 
47 {
48  TFile *old = gFile;
49  TGDMLParse parser;
50  TGeoVolume* gdmlTop;
51  gdmlTop = parser.GDMLReadFile(GetGeometryFileName());
52  gGeoManager->GetTopVolume()->AddNode(gdmlTop,1);//,posrot);
53  ExpandNodeForGDML(gGeoManager->GetTopVolume()->GetNode(gGeoManager->GetTopVolume()->GetNdaughters()-1));
54  isFirstGDML = 0;
55  gFile = old;
56 }
57 
58 void CbmModule::ExpandNodeForGDML(TGeoNode* curNode)
59 {
60  TGeoVolume* curVol = curNode->GetVolume();
61 
63  if (!curVol->IsAssembly()) {
64  TString curMedName = "air";//curNode->GetMedium()->GetName();
65  TGeoMedium* curMedInGeoManager = gGeoManager->GetMedium(curMedName);
66  Int_t matIndToDel = gGeoManager->GetMaterialIndex(curMedName);
67 
68  if (curMedName.BeginsWith("G4_")) {
69  curMedName.Remove(0, 3);
70  }
71 
72  Int_t nmed;
73 
75  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
76  FairGeoMedia* geoMediaBase = geoFace->getMedia();
77  FairGeoBuilder* geobuild = geoLoad->getGeoBuilder();
78  FairGeoMedium* curMedInGeo;
79 
80  if (curMedInGeoManager == 0) {
81  std::cout << "[ExpandNodeForGDML] New medium found in gmdl - it is not in gGeoManager list." << std::endl;
85  } else {
88 
89  curMedInGeo = geoMediaBase->getMedium(curMedName);
90  if (curMedInGeo == 0)
91  {
92  std::cout << "[ExpandNodeForGDML] Media not found in Geo file." << std::endl;
96  }
97  else
98  {
99  if (fixedMats.find(curMedName) == fixedMats.end()) {
100  nmed = geobuild->createMedium(curMedInGeo);
101  fixedMats[curMedName] = gGeoManager->GetListOfMedia()->GetEntries();
102  }
103  curNode->GetVolume()->SetMedium(gGeoManager->GetMedium(curMedName));
104  gGeoManager->SetAllIndex();
105  }
106  }
107 
109  if (curMedInGeo->getSensitivityFlag()) {
110  AddSensitiveVolume(curVol);
111  }
112  }
113 
115  if (curVol->GetNdaughters() != 0)
116  {
117  TObjArray* NodeChildList = curVol->GetNodes();
118  TGeoNode* curNodeChild;
119  for (Int_t j=0; j<NodeChildList->GetEntriesFast(); j++)
120  {
121  curNodeChild = (TGeoNode*)NodeChildList->At(j);
122  ExpandNodeForGDML(curNodeChild);
123  }
124  }
125 }
126 #else
127 void CbmModule::ConstructGDMLGeometry(TGeoMatrix* posrot)
128 {
129  gLogger->Error(MESSAGE_ORIGIN," Could not construct magnet geometry from gdml file. ");
130  gLogger->Error(MESSAGE_ORIGIN," The used ROOT version does not support gdml. ");
131  gLogger->Error(MESSAGE_ORIGIN," Please recompile ROOT with gdml support. ");
132  gLogger->Fatal(MESSAGE_ORIGIN," Stop execution at this point. ");
133 }
134 
135 void CbmModule::ExpandNodeForGDML(TGeoNode* curNode)
136 {
137 }
138 #endif
139