8 #include "FairGeoInterface.h"
9 #include "FairGeoLoader.h"
10 #include "FairGeoNode.h"
11 #include "FairGeoRootBuilder.h"
12 #include "FairRootManager.h"
14 #include "FairRuntimeDb.h"
15 #include "FairVolume.h"
17 #include "Math/Interpolator.h"
18 #include "TClonesArray.h"
19 #include "TGeoMCGeometry.h"
20 #include "TGeoManager.h"
21 #include "TGeoMatrix.h"
22 #include "TGeoMedium.h"
24 #include "TLorentzVector.h"
25 #include "TObjArray.h"
26 #include "TParticle.h"
27 #include "TParticlePDG.h"
28 #include "TVirtualMC.h"
31 #include "FairGeoBuilder.h"
32 #include "FairGeoMedia.h"
34 #include "TGDMLParse.h"
47 , fRegisterPhotonsOnSensitivePlane(true)
48 , fRichPoints(new TClonesArray(
"CbmRichPoint"))
49 , fRichRefPlanePoints(new TClonesArray(
"CbmRichPoint"))
50 , fRichMirrorPoints(new TClonesArray(
"CbmRichPoint"))
52 , fPositionRotation(NULL) {
66 , fRegisterPhotonsOnSensitivePlane(true)
67 , fRichPoints(new TClonesArray(
"CbmRichPoint"))
68 , fRichRefPlanePoints(new TClonesArray(
"CbmRichPoint"))
69 , fRichMirrorPoints(new TClonesArray(
"CbmRichPoint"))
70 , fRotation(new TGeoRotation(
"", rx, ry, rz))
71 , fPositionRotation(new TGeoCombiTrans(px, py, pz, fRotation)) {
95 TString volName = name;
96 if (volName.Contains(
"pmt_pixel") || volName.Contains(
"sens_plane"))
99 if (volName.Contains(
"mirror_tile_type"))
return kTRUE;
105 Int_t pdgCode = gMC->TrackPid();
106 Int_t iVol = vol->getMCid();
107 TString volName = TString(vol->GetName());
109 if (volName.Contains(
"pmt_pixel")) {
110 if (gMC->IsTrackEntering()) {
112 TParticle* part = gMC->GetStack()->GetCurrentTrack();
113 Double_t charge = part->GetPDG()->Charge() / 3.;
114 Int_t trackID = gMC->GetStack()->GetCurrentTrackNumber();
115 Double_t time = gMC->TrackTime() * 1.0e09;
116 Double_t length = gMC->TrackLength();
117 Double_t eLoss = gMC->Edep();
119 TLorentzVector tPos, tMom;
120 gMC->TrackPosition(tPos);
121 gMC->TrackMomentum(tMom);
123 if (pdgCode == 50000050) {
127 TVector3(tPos.X(), tPos.Y(), tPos.Z()),
128 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
143 TVector3(tPos.X(), tPos.Y(), tPos.Z()),
144 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
159 if (volName.Contains(
"sens_plane")) {
162 if (gMC->IsTrackEntering()) {
163 TParticle* part = gMC->GetStack()->GetCurrentTrack();
164 Double_t charge = part->GetPDG()->Charge() / 3.;
168 Int_t trackID = gMC->GetStack()->GetCurrentTrackNumber();
169 Double_t time = gMC->TrackTime() * 1.0e09;
170 Double_t length = gMC->TrackLength();
171 Double_t eLoss = gMC->Edep();
172 TLorentzVector tPos, tMom;
174 gMC->TrackPosition(tPos);
175 gMC->TrackMomentum(tMom);
179 TVector3(tPos.X(), tPos.Y(), tPos.Z()),
180 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
196 Bool_t isMirror = (volName.Contains(
"mirror_tile_type"));
200 if (gMC->IsTrackEntering()) {
201 TParticle* part = gMC->GetStack()->GetCurrentTrack();
202 Double_t charge = part->GetPDG()->Charge() / 3.;
205 Int_t trackID = gMC->GetStack()->GetCurrentTrackNumber();
207 Double_t time = gMC->TrackTime() * 1.0e09;
208 Double_t length = gMC->TrackLength();
209 Double_t eLoss = gMC->Edep();
210 TLorentzVector tPos, tMom;
212 gMC->TrackPosition(tPos);
213 gMC->TrackMomentum(tMom);
217 TVector3(tPos.X(), tPos.Y(), tPos.Z()),
218 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
231 if (fVerboseLevel)
Print(
"");
236 FairRootManager::Instance()->Register(
238 FairRootManager::Instance()->Register(
240 FairRootManager::Instance()->Register(
253 LOG(info) << fName <<
": " << nHits <<
" points registered in this event.";
255 if (fVerboseLevel > 1)
256 for (Int_t
i = 0;
i < nHits;
i++)
268 Int_t nEntries = cl1->GetEntriesFast();
269 LOG(info) <<
"CbmRich: " << nEntries <<
" entries to add.";
270 TClonesArray& clref = *cl2;
272 for (Int_t
i = 0;
i < nEntries;
i++) {
274 Int_t index = oldpoint->GetTrackID() + offset;
275 oldpoint->SetTrackID(index);
279 LOG(info) <<
"CbmRich: " << cl2->GetEntriesFast() <<
" merged entries.";
283 LOG(info) <<
"CbmRich::ConstructOpGeometry()";
288 TString fileName = GetGeometryFileName();
289 if (fileName.EndsWith(
".root")) {
291 LOG(info) <<
"Importing RICH geometry from ROOT file " << fgeoName.Data();
296 LOG(info) <<
"Constructing RICH geometry from ROOT file "
298 FairModule::ConstructRootGeometry();
300 }
else if (fileName.EndsWith(
".gdml")) {
301 LOG(info) <<
"Constructing RICH geometry from GDML file "
305 LOG(fatal) <<
"Geometry format of RICH file " << fileName.Data()
306 <<
" not supported. Only ROOT and GDML formats are supported.";
311 FairRun* run = FairRun::Instance();
312 Bool_t isGeant4 = std::string(run->GetName()) ==
"TGeant4";
313 LOG(info) <<
"CbmRich::SetRichGlassPropertiesForGeant4() Transport engine:"
314 << std::string(run->GetName());
318 LOG(info) <<
"CbmRich::SetRichGlassPropertiesForGeant4() fIsGeant4 is "
319 "false. No need to set RICH glass properties. Return.";
322 LOG(info) <<
"CbmRich::SetRichGlassPropertiesForGeant4() fIsGeant4 is "
323 "true. RICH glass properties will be set.";
326 std::vector<Double_t> energyAr = {
327 6.1997, 5.9045, 5.6361, 5.391, 5.1664, 4.9598, 4.769, 4.5924, 4.4284,
328 4.2757, 4.1331, 3.9998, 3.8748, 3.7574, 3.6469, 3.5427, 3.4443, 3.3512,
329 3.263, 3.1793, 3.0998, 3.0242, 2.9522, 2.8836, 2.818, 2.7554, 2.6955,
330 2.6382, 2.5832, 2.5305, 2.4799, 2.4313, 2.3845, 2.3395, 2.2962, 2.2544,
331 2.2142, 2.1753, 2.1378, 2.1016, 2.0666, 2.0327, 1.9999, 1.9682, 1.9374,
332 1.9076, 1.8787, 1.8507, 1.8234, 1.797, 1.7713, 1.7464, 1.7221, 1.6985,
333 1.6756, 1.6533, 1.6315, 1.6103, 1.5897, 1.5695, 1.5499};
335 for (
size_t i = 0;
i < energyAr.size();
i++) {
336 energyAr[
i] = 1.e-9 * energyAr[
i];
339 std::vector<Double_t> reflectivityAr = {
340 0.22529, 0.1862, 0.15901, 0.14713, 0.13963, 0.13898, 0.13762, 0.13622,
341 0.13868, 0.13951, 0.14031, 0.14073, 0.1409, 0.13977, 0.14205, 0.14072,
342 0.1396, 0.13826, 0.13665, 0.13513, 0.13463, 0.13287, 0.13182, 0.13084,
343 0.12824, 0.12601, 0.12622, 0.12681, 0.12193, 0.12011, 0.12109, 0.11908,
344 0.11526, 0.11364, 0.11385, 0.12015, 0.11935, 0.11712, 0.1208, 0.12021,
345 0.11909, 0.11783, 0.12257, 0.1215, 0.12199, 0.12494, 0.13101, 0.12089,
346 0.12284, 0.12569, 0.13136, 0.13307, 0.13705, 0.13844, 0.13753, 0.14416,
347 0.14761, 0.14953, 0.15218, 0.15315, 0.15719};
349 for (
size_t i = 0;
i < reflectivityAr.size();
i++) {
350 reflectivityAr[
i] = 1. - reflectivityAr[
i];
353 gMC->DefineOpSurface(
354 "RICHglassSurf", kGlisur, kDielectric_metal, kPolished, 0.0);
355 gMC->SetMaterialProperty(
"RICHglassSurf",
359 reflectivityAr.data());
361 for (
int i = 0;
i < 10;
i++) {
362 if (gGeoManager->FindVolumeFast(
363 (
"mirror_tile_type" + std::to_string(
i)).c_str())
366 gMC->SetSkinSurface((
"RICHglassSkin" + std::to_string(
i)).c_str(),
367 (
"mirror_tile_type" + std::to_string(
i)).c_str(),
378 Int_t maxInd = gGeoManager->GetListOfMedia()->GetEntries() - 1;
380 gdmlTop = parser.GDMLReadFile(GetGeometryFileName());
386 Int_t j = gGeoManager->GetListOfMedia()->GetEntries() - 1;
390 m = (TGeoMedium*) gGeoManager->GetListOfMedia()->At(j);
392 m->SetId(curId + maxInd);
399 Int_t newMaxInd = gGeoManager->GetListOfMedia()->GetEntries() - 1;
401 gGeoManager->GetTopVolume()->AddNode(gdmlTop, 1, geoMatrix);
403 gGeoManager->GetTopVolume()->GetNdaughters() - 1));
405 for (Int_t k = maxInd + 1; k < newMaxInd + 1; k++) {
406 TGeoMedium* medToDel =
407 (TGeoMedium*) (gGeoManager->GetListOfMedia()->At(maxInd + 1));
408 LOG(debug) <<
" removing media " << medToDel->GetName() <<
" with id "
409 << medToDel->GetId() <<
" (k=" << k <<
")";
410 gGeoManager->GetListOfMedia()->Remove(medToDel);
412 gGeoManager->SetAllIndex();
419 <<
"----------------------------------------- ExpandNodeForGdml for node "
422 TGeoVolume* curVol = node->GetVolume();
424 LOG(debug) <<
" volume: " << curVol->GetName();
426 if (curVol->IsAssembly()) {
427 LOG(debug) <<
" skipping volume-assembly";
430 TGeoMedium* curMed = curVol->GetMedium();
431 TGeoMaterial* curMat = curVol->GetMaterial();
432 TGeoMedium* curMedInGeoManager = gGeoManager->GetMedium(curMed->GetName());
433 TGeoMaterial* curMatOfMedInGeoManager = curMedInGeoManager->GetMaterial();
434 TGeoMaterial* curMatInGeoManager =
435 gGeoManager->GetMaterial(curMat->GetName());
438 LOG(debug2) <<
" curMed\t\t\t\t" << curMed <<
"\t" << curMed->GetName()
439 <<
"\t" << curMed->GetId();
440 LOG(debug2) <<
" curMat\t\t\t\t" << curMat <<
"\t" << curMat->GetName()
441 <<
"\t" << curMat->GetIndex();
444 LOG(debug2) <<
" curMedInGeoManager\t\t" << curMedInGeoManager <<
"\t"
445 << curMedInGeoManager->GetName() <<
"\t"
446 << curMedInGeoManager->GetId();
447 LOG(debug2) <<
" curMatOfMedInGeoManager\t\t" << curMatOfMedInGeoManager
448 <<
"\t" << curMatOfMedInGeoManager->GetName() <<
"\t"
449 << curMatOfMedInGeoManager->GetIndex();
450 LOG(debug2) <<
" curMatInGeoManager\t\t" << curMatInGeoManager <<
"\t"
451 << curMatInGeoManager->GetName() <<
"\t"
452 << curMatInGeoManager->GetIndex();
454 TString matName = curMat->GetName();
455 TString medName = curMed->GetName();
457 if (curMed->GetId() != curMedInGeoManager->GetId()) {
459 LOG(debug) <<
" Medium needs to be fixed";
461 Int_t ind = curMat->GetIndex();
462 gGeoManager->RemoveMaterial(ind);
463 LOG(debug) <<
" removing material " << curMat->GetName()
464 <<
" with index " << ind;
465 for (Int_t
i = ind;
i < gGeoManager->GetListOfMaterials()->GetEntries();
468 (TGeoMaterial*) gGeoManager->GetListOfMaterials()->At(
i);
469 m->SetIndex(
m->GetIndex() - 1);
472 LOG(debug) <<
" Medium fixed";
474 LOG(debug) <<
" Already fixed medium found in the list ";
479 LOG(debug) <<
" There is no correct medium in the memory yet";
481 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
482 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
483 FairGeoMedia* geoMediaBase = geoFace->getMedia();
486 FairGeoMedium* curMedInGeo = geoMediaBase->getMedium(medName);
487 if (curMedInGeo == 0) {
488 LOG(fatal) << medName <<
" Media not found in Geo file.";
493 LOG(debug) <<
" Found media in Geo file" << medName;
496 (TGeoMedium*) gGeoManager->GetListOfMedia()->Last();
497 gGeoManager->RemoveMaterial(curMatOfMedInGeoManager->GetIndex());
498 LOG(debug) <<
" removing material "
499 << curMatOfMedInGeoManager->GetName() <<
" with index "
500 << curMatOfMedInGeoManager->GetIndex();
501 for (Int_t
i = curMatOfMedInGeoManager->GetIndex();
502 i < gGeoManager->GetListOfMaterials()->GetEntries();
505 (TGeoMaterial*) gGeoManager->GetListOfMaterials()->At(
i);
506 m->SetIndex(
m->GetIndex() - 1);
510 if (curMedInGeo->getSensitivityFlag()) {
511 LOG(debug) <<
" Adding sensitive " << curVol->GetName();
512 AddSensitiveVolume(curVol);
516 LOG(debug) <<
" Already fixed medium found in the list";
517 LOG(debug) <<
"!!! Sensitivity: " <<
fFixedMedia[medName]->GetParam(0);
519 LOG(debug) <<
" Adding sensitive " << curVol->GetName();
520 AddSensitiveVolume(curVol);
526 gGeoManager->SetAllIndex();
533 if (curVol->GetNdaughters() != 0) {
534 TObjArray* NodeChildList = curVol->GetNodes();
535 TGeoNode* curNodeChild;
536 for (Int_t j = 0; j < NodeChildList->GetEntriesFast(); j++) {
537 curNodeChild = (TGeoNode*) NodeChildList->At(j);
551 Int_t size = clref.GetEntriesFast();
552 return new (clref[size])
564 Int_t tsize = clref.GetEntriesFast();
565 return new (clref[tsize])
577 Int_t tsize = clref.GetEntriesFast();
578 return new (clref[tsize])