7#include <FairGeoBuilder.h>
8#include <FairGeoInterface.h>
9#include <FairGeoLoader.h>
10#include <FairGeoMedia.h>
11#include <FairModule.h>
14#include <RtypesCore.h>
15#include <TCollection.h>
16#include <TDirectory.h>
18#include <TGeoManager.h>
19#include <TGeoMaterial.h>
20#include <TGeoMatrix.h>
21#include <TGeoMedium.h>
23#include <TGeoVolume.h>
41 TList* media = gGeoManager->GetListOfMedia();
44 while ((med =
static_cast<TGeoMedium*
>(next1()))) {
45 LOG(info) <<
"Medium " << med->GetName() <<
" with ID " << med->GetId();
52 TList* material = gGeoManager->GetListOfMaterials();
53 TIter next1(material);
55 while ((mat =
static_cast<TGeoMaterial*
>(next1()))) {
56 LOG(info) <<
"Material " << mat->GetName() <<
" with ID " << mat->GetIndex();
74 TList* media = gGeoManager->GetListOfMedia();
81 while (j < media->GetSize()) {
83 med = (TGeoMedium*) media->At(j);
84 mat = med->GetMaterial();
88 for (
size_t i = 0; i < strlen(mat->GetName()); ++i) {
89 if (mat->GetName()[i] >=
'A' && mat->GetName()[i] <=
'Z') {
91 ((
Int_t) pow((
double) base, (
double) i) % INT_MAX) * ((
Int_t) mat->GetName()[i] -
'B');
93 else if (med->GetMaterial()->GetName()[i] >=
'a' && mat->GetName()[i] <=
'z') {
95 ((
Int_t) pow((
double) base, (
double) i) % INT_MAX) * ((
Int_t) mat->GetName()[i] -
'b');
99 ((
Int_t) pow((
double) base, (
double) i + 1) % INT_MAX) * ((
Int_t) mat->GetName()[i]);
103 med->SetId((UniqueID > 0) ? UniqueID : -1 * UniqueID);
104 mat->SetIndex((UniqueID > 0) ? UniqueID : -1 * UniqueID);
106 LOG(debug) <<
"Reset ID number of Medium " << med->GetName() <<
" to " << med->GetId();
107 LOG(debug) <<
"Reset ID number of Material " << mat->GetName() <<
" to " << mat->GetIndex();
117 TList* materials = gGeoManager->GetListOfMaterials();
118 TIter next(materials);
120 std::map<TString, Bool_t> mapMatName;
122 while ((mat =
static_cast<TGeoMaterial*
>(next()))) {
124 if (mapMatName[mat->GetName()]) {
125 LOG(debug) <<
"Removing duplicate material " << mat->GetName();
126 materials->Remove(mat);
129 mapMatName[mat->GetName()] = kTRUE;
137 TList* media = gGeoManager->GetListOfMedia();
140 std::map<TString, Bool_t> mapMedName;
142 while ((med =
static_cast<TGeoMedium*
>(next()))) {
144 if (mapMedName[med->GetName()]) {
145 LOG(debug) <<
"Removing duplicate medium " << med->GetName();
149 mapMedName[med->GetName()] = kTRUE;
157 FairGeoBuilder* geoBuilder = FairGeoLoader::Instance()->getGeoBuilder();
159 TList* media = gGeoManager->GetListOfMedia();
161 gGeoManager->GetListOfMedia()->Print();
165 for (
Int_t i = geoBuilder->GetNMedia(); i < media->GetEntries(); i++) {
166 med =
static_cast<TGeoMedium*
>(media->At(i));
170 geoBuilder->SetNMedia(media->GetEntries());
175 media = gGeoManager->GetListOfMedia();
177 while ((med =
static_cast<TGeoMedium*
>(next3()))) {
178 TGeoMaterial* mat = med->GetMaterial();
183 LOG(info) <<
"No Material found for medium " << med->GetName();
186 gGeoManager->SetAllIndex();
191 TString tempString {
""};
192 TGeoMatrix* tempMatrix {
nullptr};
199 TString fVolumeName {
""};
200 TGeoMatrix* tempMatrix {
nullptr};
204 TGeoVolume* module1 = TGeoVolume::Import(filename, fVolumeName.Data());
206 if (fair::Logger::Logging(fair::Severity::debug)) {
207 LOG(debug) <<
"Information about imported volume:";
210 LOG(debug) <<
"Information about imported transformation matrix:";
213 LOG(debug) <<
"There is a transformation matrix passed "
214 <<
"from the module class which overwrites "
215 <<
"the imported matrix.";
217 LOG(debug) <<
"Information about passed transformation matrix:";
228 if (mat) { gGeoManager->GetTopVolume()->AddNode(module1, 0, mat); }
230 gGeoManager->GetTopVolume()->AddNode(module1, 0, tempMatrix);
234 gGeoManager->SetAllIndex();
240 TFile* oldFile = gFile;
241 TDirectory* oldDirectory = gDirectory;
243 TFile* f =
new TFile(filename);
244 TList* l = f->GetListOfKeys();
245 Int_t numKeys = l->GetSize();
248 LOG(debug) <<
"Not exactly two keys in the file. File is not of new type.";
255 Bool_t foundGeoVolume = kFALSE;
256 Bool_t foundGeoMatrix = kFALSE;
258 while ((key = (TKey*) next())) {
259 if (key->ReadObj()->InheritsFrom(
"TGeoVolume")) {
260 volumeName = key->GetName();
261 foundGeoVolume = kTRUE;
262 LOG(debug) <<
"Found TGeoVolume with name " << volumeName;
265 if (key->ReadObj()->InheritsFrom(
"TGeoMatrix")) {
266 *matrix =
dynamic_cast<TGeoMatrix*
>(key->ReadObj());
267 foundGeoMatrix = kTRUE;
268 LOG(debug) <<
"Found TGeoMatrix derrived object.";
277 gDirectory = oldDirectory;
279 if (foundGeoVolume && foundGeoMatrix) {
280 LOG(debug) <<
"Geometry file is of new type.";
284 if (!foundGeoVolume) { LOG(fatal) <<
"No TGeoVolume found in geometry file. File is of unknown type."; }
285 if (!foundGeoMatrix) {
286 LOG(fatal) <<
"No TGeoMatrix derived object found in geometry file. "
287 "File is of unknown type.";
302 FairGeoMedia* Media = FairGeoLoader::Instance()->getGeoInterface()->getMedia();
303 FairGeoBuilder* geobuild = FairGeoLoader::Instance()->getGeoBuilder();
305 TGeoMedium* med1 =
v->GetMedium();
316 TString medName =
static_cast<TString
>(med1->GetName());
317 if ((medName.EqualTo(
"dummy")) && (
nullptr == gGeoManager->GetMedium(medName))) {
318 TGeoMaterial* dummyMaterial =
new TGeoMaterial();
319 dummyMaterial->SetName(
"dummy");
321 TGeoMedium* dummyMedium =
new TGeoMedium();
322 dummyMedium->SetName(
"dummy");
323 dummyMedium->SetMaterial(dummyMaterial);
325 gGeoManager->GetListOfMedia()->Add(dummyMedium);
326 gGeoManager->AddMaterial(dummyMaterial);
329 TGeoMaterial* mat1 =
v->GetMaterial();
330 TGeoMaterial* newMat = gGeoManager->GetMaterial(mat1->GetName());
331 if (
nullptr == newMat) {
335 LOG(info) <<
"Create new material " << mat1->GetName();
336 FairGeoMedium* FairMedium = Media->getMedium(mat1->GetName());
338 LOG(fatal) <<
"Material " << mat1->GetName() <<
"is neither defined in ASCII file nor in Root file.";
341 Int_t nmed = geobuild->createMedium(FairMedium);
342 v->SetMedium(gGeoManager->GetMedium(nmed));
343 gGeoManager->SetAllIndex();
348 TGeoMedium* med2 = gGeoManager->GetMedium(mat1->GetName());
353 if (strcmp(
v->ClassName(),
"TGeoVolumeAssembly") != 0) {
354 LOG(fatal) <<
"The volume " <<
v->GetName()
355 <<
"has no medium information and is not an Assembly so "
365 TObjArray* NodeList = vol->GetNodes();
366 for (
Int_t Nod = 0; Nod < NodeList->GetEntriesFast(); Nod++) {
367 TGeoNode* fNode = (TGeoNode*) NodeList->At(Nod);
369 TGeoVolume*
v = fNode->GetVolume();
373 if ((mod->InheritsFrom(
"FairDetector")) && mod->IsSensitive(
v->GetName())) {
374 LOG(debug) <<
"Module " <<
v->GetName() <<
" of detector " << mod->GetName() <<
" is sensitive";
375 mod->AddSensitiveVolume(
v);
391 double r00 = m.GetRotationMatrix()[0];
392 double r01 = m.GetRotationMatrix()[1];
393 double r10 = m.GetRotationMatrix()[3];
394 double r11 = m.GetRotationMatrix()[4];
397 double rc00 = r00 * c00 + r01 * c10;
398 double rc01 = r00 * c10 + r01 * c11;
399 double rc10 = r10 * c00 + r11 * c10;
400 double rc11 = r10 * c10 + r11 * c11;
403 covXX = rc00 * r00 + rc01 * r01;
404 covXY = rc10 * r00 + rc11 * r01;
405 covYY = rc10 * r10 + rc11 * r11;
414 FairGeoLoader* geoLoad =
new FairGeoLoader(
"TGeo",
"FairGeoLoader");
415 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
416 TString geoPath = gSystem->Getenv(
"VMCWORKDIR");
417 TString geoFile = geoPath +
"/geometry/media.geo";
418 geoFace->setMediaFile(geoFile);
419 geoFace->readMedia();
422 FairGeoMedia* geoMedia = geoFace->getMedia();
423 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
425 int num = geoMedia->getListOfMedia()->GetSize();
426 FairGeoMedium* med =
new FairGeoMedium();
428 for (
int i = 0; i < num; i++) {
429 med = geoMedia->getMedium(geoMedia->getListOfMedia()->At(i)->GetName());
430 geoBuild->createMedium(med);
433 gGeoManager->SetTitle(name);
439 bool add_binary(
const char rootFile[], TGeoVolume* top, TGeoMedium* med,
Int_t inum, TGeoMatrix* mat)
442 TFile* file = TFile::Open(rootFile,
"OPEN");
444 LOG(info) <<
"Error file " << rootFile <<
" not opened";
448 ((TGeoVolume*) file->Get(file->GetListOfKeys()->First()->GetName()))->SetMedium(med);
449 top->AddNode((TGeoVolume*) (file->Get(file->GetListOfKeys()->First()->GetName()))->Clone(), inum, mat);
452 (top->GetNode(top->GetNodes()->Last()->GetName()))->GetVolume()->SetMedium(med);
458 TGeoMatrix*
cad_matrix(
double XX,
double XY,
double XZ,
double YX,
double YY,
double YZ,
double ZX,
double ZY,
459 double ZZ,
double TX,
double TY,
double TZ)
462 TGeoHMatrix* hmat =
new TGeoHMatrix();
463 (hmat->GetRotationMatrix())[0] = XX;
464 (hmat->GetRotationMatrix())[3] = XY;
465 (hmat->GetRotationMatrix())[6] = XZ;
467 (hmat->GetRotationMatrix())[1] = YX;
468 (hmat->GetRotationMatrix())[4] = YY;
469 (hmat->GetRotationMatrix())[7] = YZ;
471 (hmat->GetRotationMatrix())[2] = ZX;
472 (hmat->GetRotationMatrix())[5] = ZY;
473 (hmat->GetRotationMatrix())[8] = ZZ;
475 TGeoRotation* rot =
new TGeoRotation();
476 rot->SetRotation(*hmat);
478 TGeoCombiTrans* mat =
new TGeoCombiTrans(TX / 1, TY / 1, TZ / 1, rot);
void RemoveDuplicateMedia()
TGeoMatrix * cad_matrix(double XX, double XY, double XZ, double YX, double YY, double YZ, double ZX, double ZY, double ZZ, double TX, double TY, double TZ)
void AssignMediumAtImport(TGeoVolume *v)
Bool_t IsNewGeometryFile(TString &filename)
void ExpandNodes(TGeoVolume *vol, FairModule *mod)
void RemoveDuplicateMaterials()
void ImportRootGeometry(TString &filename, FairModule *mod, TGeoMatrix *mat)
void LocalToMasterCovarianceMatrix(const TGeoMatrix &m, Double_t &covXX, Double_t &covXY, Double_t &covYY)
Convert the local X/Y covariance matrix to global coordinates.
TGeoManager * pop_TGeoManager(const char *name)
bool add_binary(const char rootFile[], TGeoVolume *top, TGeoMedium *med, Int_t inum, TGeoMatrix *mat)