27#include <TCollection.h>
29#include <TGeoManager.h>
30#include <TGeoMaterial.h>
31#include <TGeoMatrix.h>
32#include <TGeoMedium.h>
34#include <TGeoVolume.h>
35#include <TGeoVoxelFinder.h>
42#include <TVirtualMC.h>
45#include <TGDMLParse.h>
62 <<
"The method ConstructGeometry has to be implemented in the detector class which inherits from FairModule";
68 <<
"The method ConstructOpGeometry has to be implemented in the detector class which inherits from FairModule";
75 , fMotherVolumeName(
"")
76 , fgeoVer(
"Not defined")
77 , fgeoName(
"Not defined")
80 , fNbOfSensitiveVol(0)
96 , fMotherVolumeName(rhs.fMotherVolumeName)
97 , fgeoVer(rhs.fgeoVer)
98 , fgeoName(rhs.fgeoName)
100 , fActive(rhs.fActive)
101 , fNbOfSensitiveVol(rhs.fNbOfSensitiveVol)
102 , fVerboseLevel(rhs.fVerboseLevel)
104 , fGeoSaved(rhs.fGeoSaved)
109 for (Int_t
i = 0;
i < rhs.svList->GetEntries();
i++) {
110 svList->Add(rhs.svList->At(
i));
116 for (Int_t
i = 0;
i < rhs.vList->getEntries();
i++) {
122 fMC = TVirtualMC::GetMC();
136 , fMotherVolumeName(
"")
137 , fgeoVer(
"Not defined")
138 , fgeoName(
"Not defined")
141 , fNbOfSensitiveVol(0)
155 TNamed::operator=(rhs);
167 fMC = TVirtualMC::GetMC();
181void FairModule::Streamer(TBuffer&
b)
203 if (fname.BeginsWith(
"/")) {
204 if (gSystem->AccessPathName(fname.Data())) {
205 LOG(fatal) << fName <<
": geometry file " << fname <<
" not found in absolut path!";
215 TString userPath = getenv(
"GEOMPATH");
216 userPath.ReplaceAll(
"//",
"/");
217 if (!userPath.IsNull()) {
218 if (!userPath.EndsWith(
"/")) {
222 if (!gSystem->AccessPathName(
fgeoName.Data())) {
226 LOG(
debug) << fName <<
": geometry file " << fname <<
" not found in GEOMPATH " << userPath;
232 if (!gSystem->AccessPathName(
fgeoName.Data())) {
238 LOG(fatal) << fName <<
": geometry file " << fname <<
" not found in standard path ";
249 LOG(debug2) <<
"AddSensitiveVolume " <<
v->GetName();
289 TGeoManager* OldGeo = gGeoManager;
290 TGeoManager* NewGeo = 0;
291 TGeoVolume* volume = 0;
294 TList* l =
f->GetListOfKeys();
299 while ((
key =
static_cast<TKey*
>(next()))) {
303 if (strcmp(
key->GetClassName(),
"TGeoManager") != 0) {
307 NewGeo =
static_cast<TGeoManager*
>(
key->ReadObj());
315 volume =
static_cast<TGeoVolume*
>(NewGeo->GetNode(0)->GetDaughter(0)->GetVolume());
316 v1 = volume->MakeCopyVolume(volume->GetShape());
327 key =
static_cast<TKey*
>(l->At(0));
328 volume =
dynamic_cast<TGeoVolume*
>(
key->ReadObj());
330 n = volume->GetNode(0);
340 gGeoManager = OldGeo;
345 TGeoVolume* Cave =
nullptr;
347 Cave = gGeoManager->GetTopVolume();
351 if (Cave !=
nullptr) {
353 gGeoManager->AddVolume(
v1);
355 TGeoVoxelFinder* voxels =
v1->GetVoxels();
357 voxels->SetNeedRebuild();
367 TGeoMatrix* M =
n->GetMatrix();
370 TGeoHMatrix* M2 =
new TGeoHMatrix(*M);
383 M2->Multiply(shiftM);
386 SetDefaultMatrixName(M2);
394 gGeoManager->GetListOfMatrices()->Remove(M2);
395 TGeoHMatrix* global = gGeoManager->GetHMatrix();
396 gGeoManager->GetListOfMatrices()->Remove(global);
399 Cave->AddNode(
v1, 0, M2);
402 AssignMediumAtImport(
v1);
411 <<
" where the geomanger should be added.";
430 gGeoManager->GetTopVolume()->AddNode(gdmlTop, 1, posrot);
431 ExpandNodeForGDML(gGeoManager->GetTopVolume()->GetNode(gGeoManager->GetTopVolume()->GetNdaughters() - 1));
438 TGeoVolume* curVol = curNode->GetVolume();
439 AssignMediumAtImport(curVol);
442 if ((this->InheritsFrom(
"FairDetector")) &&
IsSensitive(curVol->GetName())) {
443 LOG(debug2) <<
"Sensitive Volume " << curVol->GetName();
448 if (curVol->GetNdaughters() != 0) {
449 TObjArray* NodeChildList = curVol->GetNodes();
450 TGeoNode* curNodeChild;
451 for (Int_t
j = 0;
j < NodeChildList->GetEntriesFast();
j++) {
452 curNodeChild =
static_cast<TGeoNode*
>(NodeChildList->At(
j));
462 LOG(
error) <<
"Could not construct magnet geometry from gdml file.";
463 LOG(
error) <<
"The used ROOT version does not support gdml.";
464 LOG(
error) <<
"Please recompile ROOT with gdml support.";
465 LOG(fatal) <<
"Stop execution at this point.";
472void FairModule::ReAssignMediaId()
475 LOG(fatal) <<
"FairModule: no FairGeoLoader, the ASCII/ROOT geometry import of FairRoot is not set up in O2";
480 TList* media = gGeoManager->GetListOfMedia();
484 for (Int_t
i = geoBuilder->
GetNMedia();
i < media->GetEntries();
i++) {
485 med =
static_cast<TGeoMedium*
>(media->At(
i));
489 geoBuilder->
SetNMedia(media->GetEntries());
492 TList*
materials = gGeoManager->GetListOfMaterials();
493 TIter next1(materials);
495 std::map<TString, Bool_t> mapMatName;
497 while ((mat =
static_cast<TGeoMaterial*
>(next1()))) {
499 if (mapMatName[mat->GetName()]) {
502 mapMatName[mat->GetName()] = kTRUE;
509 LOG(warn) <<
"The method ConstructASCIIGeometry has to be implemented in the detector class which inherits from "
518#pragma GCC diagnostic push
519#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
521#pragma GCC diagnostic pop
530 TGeoMatrix* Matrix = fN->GetMatrix();
531 if (gGeoManager->GetListOfMatrices()->FindObject(Matrix)) {
532 gGeoManager->GetListOfMatrices()->Remove(Matrix);
534 TGeoVolume*
v1 = fN->GetVolume();
535 TObjArray* NodeList =
v1->GetNodes();
536 for (Int_t Nod = 0; Nod < NodeList->GetEntriesFast(); Nod++) {
537 TGeoNode* fNode =
static_cast<TGeoNode*
>(NodeList->At(Nod));
538 TGeoMatrix* M = fNode->GetMatrix();
540 SetDefaultMatrixName(M);
541 if (fNode->GetNdaughters() > 0) {
544 TGeoVolume*
v = fNode->GetVolume();
545 AssignMediumAtImport(
v);
546 if (!gGeoManager->FindVolumeFast(
v->GetName())) {
547 LOG(debug2) <<
"Register Volume " <<
v->GetName();
548 v->RegisterYourself();
550 if ((this->InheritsFrom(
"FairDetector")) &&
IsSensitive(
v->GetName())) {
551 LOG(debug2) <<
"Sensitive Volume " <<
v->GetName();
554 v->GetShape()->AfterStreamer();
558void FairModule::SetDefaultMatrixName(TGeoMatrix* matrix)
573 if (strlen(matrix->GetName())) {
577 if (matrix->IsTranslation()) {
580 if (matrix->IsRotation()) {
583 if (matrix->IsScale()) {
586 if (matrix->IsCombi()) {
589 if (matrix->IsGeneral()) {
592 TObjArray* matrices = gGeoManager->GetListOfMatrices();
595 index = matrices->GetEntriesFast() - 1;
597 matrix->SetName(Form(
"%c%i",
type,
index));
600void FairModule::AssignMediumAtImport(TGeoVolume*
v)
609 LOG(fatal) <<
"FairModule: no FairGeoLoader, the ASCII/ROOT geometry import of FairRoot is not set up in O2";
614 TGeoMedium* med1 =
v->GetMedium();
625 TString medName =
static_cast<TString
>(med1->GetName());
626 if (medName.EqualTo(
"dummy") &&
nullptr == gGeoManager->GetMedium(medName)) {
628 TGeoMaterial* dummyMaterial =
new TGeoMaterial();
629 dummyMaterial->SetName(
"dummy");
631 TGeoMedium* dummyMedium =
new TGeoMedium();
632 dummyMedium->SetName(
"dummy");
633 dummyMedium->SetMaterial(dummyMaterial);
635 gGeoManager->GetListOfMedia()->Add(dummyMedium);
636 gGeoManager->AddMaterial(dummyMaterial);
639 TGeoMaterial* mat1 =
v->GetMaterial();
640 TGeoMaterial* newMat = gGeoManager->GetMaterial(mat1->GetName());
646 LOG(fatal) <<
"Material " << mat1->GetName() <<
"is not defined in ASCII file nor in Root file.";
652 v->SetMedium(gGeoManager->GetMedium(nmed));
653 gGeoManager->SetAllIndex();
657 TGeoMedium* med2 = gGeoManager->GetMedium(mat1->GetName());
661 if (strcmp(
v->ClassName(),
"TGeoVolumeAssembly") != 0) {
663 LOG(fatal) <<
"The volume " <<
v->GetName()
664 <<
"has no medium information and not an Assembly so we have to quit";
671 Fatal(
"CloneModule",
"Has to be overriden in multi-threading applications.");
char error[CURL_ERROR_SIZE]
void SetNMedia(const Int_t &nmed)
virtual Int_t createMedium(FairGeoMedium *)=0
const Int_t & GetNMedia() const
FairGeoMedia * getMedia()
FairGeoInterface * getGeoInterface()
static FairGeoLoader * Instance()
FairGeoBuilder * getGeoBuilder()
FairModule & operator=(const FairModule &)
virtual void ExpandNodeForGDML(__attribute__((unused)) TGeoNode *curNode)
Bool_t fGeoSaved
list of Detector Geometry parameters
TString fMotherVolumeName
static thread_local Int_t fNbOfVolumes
void AddSensitiveVolume(TGeoVolume *v)
virtual void ConstructOpGeometry()
virtual void ExpandNode(TGeoNode *Node)
virtual void ConstructRootGeometry(TGeoMatrix *shiftM=nullptr)
virtual void ConstructGDMLGeometry(__attribute__((unused)) TGeoMatrix *posrot)
virtual void ConstructASCIIGeometry()
FairVolume * getFairVolume(FairGeoNode *fNode)
virtual TString GetGeometryFileName()
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
TVirtualMC * fMC
flag for initialisation
static thread_local TArrayI * volNumber
virtual FairModule * CloneModule() const
static thread_local FairVolumeList * vList
virtual void ConstructGeometry()
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)
static thread_local TRefArray * svList
void addVolume(FairVolume *elem)
FairVolume * At(Int_t pos)
FairVolume * findObject(TString name)
void SetModule(FairModule *mod)
FairGeoNode * getGeoNode()
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GLint GLint GLsizei GLint GLenum GLenum type
const std::unordered_map< MaterialID, MaterialProperties > materials
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"