MpdStrawendcap.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. //------------------------------------------------------------------------------------------------------------------------
  2. // -------------------------------------------------------------------------
  3. // ----- MpdStrawendcap source file -----
  4. // -------------------------------------------------------------------------
  5. #include <iostream>
  6. #include "TClonesArray.h"
  7. #include "TLorentzVector.h"
  8. #include "TParticle.h"
  9. #include "TVirtualMC.h"
  10. #include "TGeoManager.h"
  11. #include "TGeoMatrix.h"
  12. #include "FairGeoInterface.h"
  13. #include "FairGeoLoader.h"
  14. #include "FairGeoNode.h"
  15. #include "FairGeoRootBuilder.h"
  16. #include "MpdStack.h"
  17. #include "MpdStrawendcapGeo.h"
  18. #include "FairRootManager.h"
  19. #include "MpdStrawendcap.h"
  20. #include "MpdStrawendcapPoint.h"
  21. #include "FairRuntimeDb.h"
  22. #include "MpdStrawendcapGeoPar.h"
  23. #include "TObjArray.h"
  24. #include "FairRun.h"
  25. #include "FairVolume.h"
  26. #include "TMath.h"
  27. #include "TParticlePDG.h"
  28. #include "TGeoManager.h"
  29. #include "TGDMLParse.h"
  30. #include "FairGeoMedia.h"
  31. class FairVolume;
  32. //------------------------------------------------------------------------------------------------------------------------
  33. MpdStrawendcap::MpdStrawendcap()
  34. : FairDetector("STT", kTRUE)
  35. {
  36. fStrawendcapCollection = new TClonesArray("MpdStrawendcapPoint");
  37. fPosIndex = 0;
  38. fVerboseLevel = 1;
  39. }
  40. //------------------------------------------------------------------------------------------------------------------------
  41. MpdStrawendcap::MpdStrawendcap(const char* name, Bool_t active)
  42. : FairDetector(name, active)
  43. {
  44. fStrawendcapCollection = new TClonesArray("MpdStrawendcapPoint");
  45. fPosIndex = 0;
  46. fVerboseLevel = 1;
  47. }
  48. //------------------------------------------------------------------------------------------------------------------------
  49. MpdStrawendcap::~MpdStrawendcap()
  50. {
  51. if(fStrawendcapCollection){ fStrawendcapCollection->Delete(); delete fStrawendcapCollection; }
  52. }
  53. //------------------------------------------------------------------------------------------------------------------------
  54. int MpdStrawendcap::DistAndPoints(TVector3 p1, TVector3 p2, TVector3 p3, TVector3 p4, TVector3& pa, TVector3& pb) {
  55. TVector3 A = p2 - p1;
  56. TVector3 B = p4 - p3;
  57. TVector3 C = p1 - p3;
  58. if (p3 == p4) {
  59. pb = p4;
  60. TVector3 unit = A.Unit();
  61. Double_t dist = unit.Dot(-C);
  62. pa = p1 + dist * unit;
  63. return 0;
  64. }
  65. Double_t numer = C.Dot(B) * B.Dot(A) - C.Dot(A) * B.Dot(B);
  66. Double_t denom = A.Dot(A) * B.Dot(B) - B.Dot(A) * B.Dot(A);
  67. if (denom == 0) {
  68. // parallel lines
  69. pa.SetXYZ(-10000,-10000,-10000);
  70. pb.SetXYZ(-10000,-10000,-10000);
  71. return 1;
  72. }
  73. Double_t ma = numer / denom;
  74. Double_t mb = ( C.Dot(B) + B.Dot(A)*ma ) / B.Dot(B);
  75. pa = p1 + A*ma;
  76. pb = p3 + B*mb;
  77. return 0;
  78. }
  79. //------------------------------------------------------------------------------------------------------------------------
  80. TVector3 MpdStrawendcap::GlobalToLocal(TVector3& global) {
  81. Double_t globPos[3];
  82. Double_t localPos[3];
  83. global.GetXYZ(globPos);
  84. gMC->Gmtod(globPos, localPos, 1);
  85. return TVector3(localPos);
  86. }
  87. //------------------------------------------------------------------------------------------------------------------------
  88. TVector3 MpdStrawendcap::LocalToGlobal(TVector3& local) {
  89. Double_t globPos[3];
  90. Double_t localPos[3];
  91. local.GetXYZ(localPos);
  92. gMC->Gdtom(localPos, globPos, 1);
  93. return TVector3(globPos);
  94. }
  95. //----------------------------------------------------------------------------------------------------------------------
  96. Bool_t MpdStrawendcap::ProcessHits(FairVolume* vol) {
  97. //AZ
  98. static Int_t first = 1, nLayMod = 30; //!!! geometry dependent
  99. static Double_t z0[4] = {156.5, 186.5, 0, 0};
  100. if (first) {
  101. first = 0;
  102. TGeoHMatrix matrix;
  103. if (gGeoManager) {
  104. if (gGeoManager->GetCurrentNavigator()->CheckPath("/cave_1/stt01layerradial_1")) { //EL
  105. if (gMC->GetTransformation("/cave_1/stt01layerradial_1",matrix))
  106. z0[0] = TMath::Abs (matrix.GetTranslation()[2]);
  107. }
  108. //matrix.Print();
  109. //cout << gGeoManager->GetPath() << " " << matrix.GetTranslation()[2] << endl;
  110. if (gGeoManager->GetCurrentNavigator()->CheckPath("/cave_1/stt02layerradial_1")) { //EL
  111. if (gMC->GetTransformation("/cave_1/stt02layerradial_1",matrix))
  112. z0[1] = TMath::Abs (matrix.GetTranslation()[2]);
  113. }
  114. if (gGeoManager->GetCurrentNavigator()->CheckPath("/cave_1/stt03layerradial_1")) {
  115. if (gMC->GetTransformation("/cave_1/stt03layerradial_1",matrix))
  116. z0[2] = TMath::Abs (matrix.GetTranslation()[2]);
  117. }
  118. if (gGeoManager->GetCurrentNavigator()->CheckPath("/cave_1/stt04layerradial_1")) {
  119. if (gMC->GetTransformation("/cave_1/stt04layerradial_1",matrix))
  120. z0[3] = TMath::Abs (matrix.GetTranslation()[2]);
  121. }
  122. }
  123. }
  124. //AZ
  125. Int_t gap, cell, module, region;
  126. static Int_t sameVol = 0;
  127. TString Volname;
  128. // Set parameters at entrance of volume. Reset ELoss.
  129. // Check if this is not due to passing through the anode wire.
  130. // If anode wire, do not reset anything.
  131. if (gMC->IsTrackEntering()) {
  132. sameVol = 1;
  133. gMC->CurrentVolOffID(2, module);
  134. if (gMC->GetStack()->GetCurrentTrackNumber() != fTrackID ||
  135. gMC->CurrentVolID(gap)+1000*module != fVolumeID) {
  136. ResetParameters();
  137. sameVol = 0;
  138. fELoss = 0.;
  139. fTime = gMC->TrackTime() * 1.0e09;
  140. fLength = gMC->TrackLength();
  141. fIsPrimary = 0;
  142. fCharge = -1;
  143. fPdgId = 0;
  144. TLorentzVector PosIn;
  145. gMC->TrackPosition(PosIn);
  146. fPosIn.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
  147. gMC->TrackMomentum(fMom);
  148. TParticle* part = 0;
  149. part = gMC->GetStack()->GetCurrentTrack();
  150. if (part) {
  151. fIsPrimary = (Int_t)part->IsPrimary();
  152. fCharge = (Int_t)part->GetPDG()->Charge();
  153. fPdgId = (Int_t)part->GetPdgCode();
  154. }
  155. fVolumeID = gMC->CurrentVolID(gap) + 1000 * module;
  156. fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
  157. }
  158. }
  159. // Sum energy loss for all steps in the active volume
  160. fELoss += gMC->Edep();
  161. // Create MpdStrawendcapPoint at EXIT of active volume;
  162. //if (gMC->IsTrackExiting() && fELoss > 0) {
  163. if ( (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) && fELoss > 0 ) {
  164. fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
  165. // Volname = vol->getName();
  166. Volname = vol->getRealName(); // EL
  167. //cout << Volname << endl;
  168. //AZ region = Volname[5] - '0'; //?????????????????????????
  169. gMC->CurrentVolID(gap);
  170. gMC->CurrentVolOffID(1, cell);
  171. gMC->CurrentVolOffID(2, module);
  172. TLorentzVector PosOut;
  173. gMC->TrackPosition(PosOut);
  174. fPosOut.SetXYZ(PosOut.X(), PosOut.Y(), PosOut.Z());
  175. //AZ Get layer number
  176. Int_t wheel;
  177. sscanf(&(Volname[4]),"%d",&wheel); // wheel number
  178. Double_t dz = TMath::Abs(PosOut.Z()) - z0[wheel-1];
  179. //Int_t lay = TMath::Nint(dz/1.) + 1;
  180. //Int_t lay = TMath::Nint(dz/1.) + 2; // geometry with triplets
  181. Int_t lay = TMath::Nint(dz/0.85) + 1; // geometry with triplets
  182. if (wheel == 2 || wheel == 4) lay += nLayMod;
  183. region = lay * 1000 + cell; // lay*1000+tubeID
  184. /*
  185. Double_t posG[3], posL[3];
  186. fPosOut.GetXYZ(posG);
  187. gMC->Gmtod(posG, posL, 1);
  188. cout << lay << " " << cell << " " << fTrackID << " " << posL[0] << " "
  189. << posL[1] << " " << posL[2] << " " << gap << " " << module << endl; */
  190. //AZ
  191. // Straw line defined in local coordinates
  192. TVector3 p1(0,0, -10); // -10,10 - arbitrary number in Z axis...
  193. TVector3 p2(0,0, 10);
  194. // Conversion to global coordinates
  195. p1 = LocalToGlobal(p1);
  196. p2 = LocalToGlobal(p2);
  197. Double_t phi = TMath::ATan2 (p2.Y()-p1.Y(),p2.X()-p1.X()); //AZ
  198. // "will-be-filled-out-soon" Points of closest approach
  199. TVector3 trackPosition(0,0,0); // trackPosition => point on track, fPos => point on straw
  200. // calculate points of closest approach between track and straw
  201. int result = DistAndPoints(p1, p2, fPosIn, fPosOut, fPos, trackPosition);
  202. //TVector3 dist = trackPosition - fPos;
  203. //std::cout << "Dist: " << dist.Mag() << std::endl;
  204. //TVector3 trackPosition(0,0,0);
  205. //if (result == 0) { // track and straw should not be parallel!
  206. // convert point coordinates to back to global system
  207. // TVector3 dist = pa - pb;
  208. // std::cout << "distance: " << dist.Mag() << std::endl;
  209. //}
  210. //AZ fVolumeID = ((region-1)<<24);
  211. // Remove point if it is from the same track and in the same tube (to account for the cases
  212. // when the track goes through the anode wire - probably will not work if secondaries are
  213. // produced inside the anode wire (they are transported before the parent track?).
  214. if (sameVol) fStrawendcapCollection->RemoveAt(fStrawendcapCollection->GetEntriesFast()-1);
  215. MpdStrawendcapPoint *p =
  216. AddHit(fTrackID, region, fPos, fPos.Perp(), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
  217. fTime, (fLength+gMC->TrackLength())/2, fELoss, fIsPrimary, fCharge, fPdgId, trackPosition);
  218. p->SetPhi(phi); //AZ
  219. ((MpdStack*)gMC->GetStack())->AddPoint(kECT);
  220. //ResetParameters();
  221. }
  222. return kTRUE;
  223. }
  224. //------------------------------------------------------------------------------------------------------------------------
  225. void MpdStrawendcap::EndOfEvent()
  226. {
  227. if(fVerboseLevel) Print();
  228. fStrawendcapCollection->Delete();
  229. fPosIndex = 0;
  230. }
  231. //------------------------------------------------------------------------------------------------------------------------
  232. void MpdStrawendcap::Register(){ FairRootManager::Instance()->Register("STRAWPoint", "Strawendcap", fStrawendcapCollection, kTRUE); }
  233. //------------------------------------------------------------------------------------------------------------------------
  234. TClonesArray* MpdStrawendcap::GetCollection(Int_t iColl) const {
  235. if(iColl == 0) return fStrawendcapCollection;
  236. return NULL;
  237. }
  238. //------------------------------------------------------------------------------------------------------------------------
  239. void MpdStrawendcap::Print() const
  240. {
  241. Int_t nHits = fStrawendcapCollection->GetEntriesFast();
  242. cout << "-I- MpdStrawendcap: " << nHits << " points registered in this event." << endl;
  243. if(fVerboseLevel > 1)
  244. for(Int_t i=0; i<nHits; i++) (*fStrawendcapCollection)[i]->Print();
  245. }
  246. //------------------------------------------------------------------------------------------------------------------------
  247. void MpdStrawendcap::Reset(){ fStrawendcapCollection->Delete(); ResetParameters(); }
  248. //------------------------------------------------------------------------------------------------------------------------
  249. void MpdStrawendcap::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
  250. {
  251. Int_t nEntries = cl1->GetEntriesFast();
  252. cout << "-I- MpdStrawendcap: " << nEntries << " entries to add." << endl;
  253. TClonesArray& clref = *cl2;
  254. MpdStrawendcapPoint* oldpoint = NULL;
  255. for(Int_t i=0; i<nEntries; i++) {
  256. oldpoint = (MpdStrawendcapPoint*) cl1->At(i);
  257. Int_t index = oldpoint->GetTrackID() + offset;
  258. oldpoint->SetTrackID(index);
  259. new (clref[fPosIndex]) MpdStrawendcapPoint(*oldpoint);
  260. fPosIndex++;
  261. }
  262. cout << "-I- MpdStrawendcap: " << cl2->GetEntriesFast() << " merged entries." << endl;
  263. }
  264. //------------------------------------------------------------------------------------------------------------------------
  265. void MpdStrawendcap::ConstructGeometry() {
  266. TString fileName = GetGeometryFileName();
  267. if ( fileName.EndsWith(".root") ) {
  268. gLogger->Info(MESSAGE_ORIGIN,
  269. "Constructing TPC geometry from ROOT file %s",
  270. fileName.Data());
  271. ConstructRootGeometry();
  272. }
  273. else if ( fileName.EndsWith(".geo") ) {
  274. gLogger->Info(MESSAGE_ORIGIN,
  275. "Constructing TPC geometry from ASCII file %s",
  276. fileName.Data());
  277. ConstructAsciiGeometry();
  278. }
  279. else if ( fileName.EndsWith(".gdml") ) {
  280. gLogger->Info(MESSAGE_ORIGIN,
  281. "Constructing TPC geometry from GDML file %s",
  282. fileName.Data());
  283. //ConstructGDMLGeometry();
  284. }
  285. else {
  286. gLogger->Fatal(MESSAGE_ORIGIN,
  287. "Geometry format of TPC file %s not supported.",
  288. fileName.Data());
  289. }
  290. }
  291. // ----- ConstructAsciiGeometry -------------------------------------------
  292. void MpdStrawendcap::ConstructAsciiGeometry() {
  293. Int_t count=0;
  294. Int_t count_tot=0;
  295. FairGeoLoader* geoLoad = FairGeoLoader::Instance();
  296. FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  297. MpdStrawendcapGeo* sttGeo = new MpdStrawendcapGeo();
  298. sttGeo->setGeomFile(GetGeometryFileName());
  299. geoFace->addGeoModule(sttGeo);
  300. Bool_t rc = geoFace->readSet(sttGeo);
  301. if(rc) sttGeo->create(geoLoad->getGeoBuilder());
  302. TList* volList = sttGeo->getListOfVolumes();
  303. // store geo parameter
  304. FairRun *fRun = FairRun::Instance();
  305. FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
  306. MpdStrawendcapGeoPar* par =(MpdStrawendcapGeoPar*)(rtdb->getContainer("MpdStrawendcapGeoPar"));
  307. TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
  308. TObjArray *fPassNodes = par->GetGeoPassiveNodes();
  309. FairGeoNode *node = NULL;
  310. FairGeoVolume *aVol = NULL;
  311. TListIter iter(volList);
  312. while((node = (FairGeoNode*)iter.Next())) {
  313. aVol = dynamic_cast<FairGeoVolume*> (node);
  314. if(node->isSensitive()){ fSensNodes->AddLast(aVol); count++; }
  315. else fPassNodes->AddLast(aVol);
  316. count_tot++;
  317. }
  318. par->setChanged();
  319. par->setInputVersion(fRun->GetRunId(), 1);
  320. ProcessNodes(volList);
  321. }
  322. // ----------------------------------------------------------------------------
  323. // ----- ConstructGDMLGeometry -------------------------------------------
  324. void MpdStrawendcap::ConstructGDMLGeometry()
  325. {
  326. TFile *old = gFile;
  327. TGDMLParse parser;
  328. TGeoVolume* gdmlTop;
  329. // Before importing GDML
  330. Int_t maxInd = gGeoManager->GetListOfMedia()->GetEntries() - 1;
  331. gdmlTop = parser.GDMLReadFile(GetGeometryFileName());
  332. // Cheating - reassigning media indices after GDML import (need to fix this in TGDMLParse class!!!)
  333. // for (Int_t i=0; i<gGeoManager->GetListOfMedia()->GetEntries(); i++)
  334. // gGeoManager->GetListOfMedia()->At(i)->Dump();
  335. // After importing GDML
  336. Int_t j = gGeoManager->GetListOfMedia()->GetEntries() - 1;
  337. Int_t curId;
  338. TGeoMedium* m;
  339. do {
  340. m = (TGeoMedium*)gGeoManager->GetListOfMedia()->At(j);
  341. curId = m->GetId();
  342. m->SetId(curId+maxInd);
  343. j--;
  344. } while (curId > 1);
  345. // LOG(DEBUG) << "====================================================================" << FairLogger::endl;
  346. // for (Int_t i=0; i<gGeoManager->GetListOfMedia()->GetEntries(); i++)
  347. // gGeoManager->GetListOfMedia()->At(i)->Dump();
  348. Int_t newMaxInd = gGeoManager->GetListOfMedia()->GetEntries() - 1;
  349. gGeoManager->GetTopVolume()->AddNode(gdmlTop, 1, 0);
  350. ExpandNodeForGdml(gGeoManager->GetTopVolume()->GetNode(gGeoManager->GetTopVolume()->GetNdaughters()-1));
  351. for (Int_t k = maxInd+1; k < newMaxInd+1; k++) {
  352. TGeoMedium* medToDel = (TGeoMedium*)(gGeoManager->GetListOfMedia()->At(maxInd+1));
  353. LOG(DEBUG) << " removing media " << medToDel->GetName() << " with id " << medToDel->GetId() << " (k=" << k << ")" << FairLogger::endl;
  354. gGeoManager->GetListOfMedia()->Remove(medToDel);
  355. }
  356. gGeoManager->SetAllIndex();
  357. gFile = old;
  358. }
  359. void MpdStrawendcap::ExpandNodeForGdml(TGeoNode* node)
  360. {
  361. LOG(DEBUG) << "----------------------------------------- ExpandNodeForGdml for node " << node->GetName() << FairLogger::endl;
  362. TGeoVolume* curVol = node->GetVolume();
  363. LOG(DEBUG) << " volume: " << curVol->GetName() << FairLogger::endl;
  364. if (curVol->IsAssembly()) {
  365. LOG(DEBUG) << " skipping volume-assembly" << FairLogger::endl;
  366. }
  367. else {
  368. TGeoMedium* curMed = curVol->GetMedium();
  369. TGeoMaterial* curMat = curVol->GetMaterial();
  370. TGeoMedium* curMedInGeoManager = gGeoManager->GetMedium(curMed->GetName());
  371. TGeoMaterial* curMatOfMedInGeoManager = curMedInGeoManager->GetMaterial();
  372. TGeoMaterial* curMatInGeoManager = gGeoManager->GetMaterial(curMat->GetName());
  373. // Current medium and material assigned to the volume from GDML
  374. LOG(DEBUG2) << " curMed\t\t\t\t" << curMed << "\t" << curMed->GetName() << "\t" << curMed->GetId() << FairLogger::endl;
  375. LOG(DEBUG2) << " curMat\t\t\t\t" << curMat << "\t" << curMat->GetName() << "\t" << curMat->GetIndex() << FairLogger::endl;
  376. // Medium and material found in the gGeoManager - either the pre-loaded one or one from GDML
  377. LOG(DEBUG2) << " curMedInGeoManager\t\t" << curMedInGeoManager
  378. << "\t" << curMedInGeoManager->GetName() << "\t" << curMedInGeoManager->GetId() << FairLogger::endl;
  379. LOG(DEBUG2) << " curMatOfMedInGeoManager\t\t" << curMatOfMedInGeoManager
  380. << "\t" << curMatOfMedInGeoManager->GetName() << "\t" << curMatOfMedInGeoManager->GetIndex() << FairLogger::endl;
  381. LOG(DEBUG2) << " curMatInGeoManager\t\t" << curMatInGeoManager
  382. << "\t" << curMatInGeoManager->GetName() << "\t" << curMatInGeoManager->GetIndex() << FairLogger::endl;
  383. TString matName = curMat->GetName();
  384. TString medName = curMed->GetName();
  385. if (curMed->GetId() != curMedInGeoManager->GetId()) {
  386. if (fFixedMedia.find(medName) == fFixedMedia.end()) {
  387. LOG(DEBUG) << " Medium needs to be fixed" << FairLogger::endl;
  388. fFixedMedia[medName] = curMedInGeoManager;
  389. Int_t ind = curMat->GetIndex();
  390. gGeoManager->RemoveMaterial(ind);
  391. LOG(DEBUG) << " removing material " << curMat->GetName()
  392. << " with index " << ind << FairLogger::endl;
  393. for (Int_t i=ind; i<gGeoManager->GetListOfMaterials()->GetEntries(); i++) {
  394. TGeoMaterial* m = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(i);
  395. m->SetIndex(m->GetIndex()-1);
  396. }
  397. LOG(DEBUG) << " Medium fixed" << FairLogger::endl;
  398. }
  399. else {
  400. LOG(DEBUG) << " Already fixed medium found in the list " << FairLogger::endl;
  401. }
  402. }
  403. else {
  404. if (fFixedMedia.find(medName) == fFixedMedia.end()) {
  405. LOG(DEBUG) << " There is no correct medium in the memory yet" << FairLogger::endl;
  406. FairGeoLoader* geoLoad = FairGeoLoader::Instance();
  407. FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  408. FairGeoMedia* geoMediaBase = geoFace->getMedia();
  409. FairGeoBuilder* geobuild = geoLoad->getGeoBuilder();
  410. FairGeoMedium* curMedInGeo = geoMediaBase->getMedium(medName);
  411. if (curMedInGeo == 0) {
  412. LOG(FATAL) << " Media not found in Geo file: " << medName << FairLogger::endl;
  413. //! This should not happen.
  414. //! This means that somebody uses material in GDML that is not in the media.geo file.
  415. //! Most probably this is the sign to the user to check materials' names in the CATIA model.
  416. }
  417. else {
  418. LOG(DEBUG) << " Found media in Geo file" << medName << FairLogger::endl;
  419. Int_t nmed = geobuild->createMedium(curMedInGeo);
  420. fFixedMedia[medName] = (TGeoMedium*)gGeoManager->GetListOfMedia()->Last();
  421. gGeoManager->RemoveMaterial(curMatOfMedInGeoManager->GetIndex());
  422. LOG(DEBUG) << " removing material " << curMatOfMedInGeoManager->GetName()
  423. << " with index " << curMatOfMedInGeoManager->GetIndex() << FairLogger::endl;
  424. for (Int_t i=curMatOfMedInGeoManager->GetIndex(); i<gGeoManager->GetListOfMaterials()->GetEntries(); i++) {
  425. TGeoMaterial* m = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(i);
  426. m->SetIndex(m->GetIndex()-1);
  427. }
  428. }
  429. if (curMedInGeo->getSensitivityFlag()) {
  430. LOG(DEBUG) << " Adding sensitive " << curVol->GetName() << FairLogger::endl;
  431. AddSensitiveVolume(curVol);
  432. }
  433. }
  434. else {
  435. LOG(DEBUG) << " Already fixed medium found in the list" << FairLogger::endl;
  436. LOG(DEBUG) << "!!! Sensitivity: " << fFixedMedia[medName]->GetParam(0) << FairLogger::endl;
  437. if (fFixedMedia[medName]->GetParam(0) == 1) {
  438. LOG(DEBUG) << " Adding sensitive " << curVol->GetName() << FairLogger::endl;
  439. AddSensitiveVolume(curVol);
  440. }
  441. }
  442. }
  443. curVol->SetMedium(fFixedMedia[medName]);
  444. gGeoManager->SetAllIndex();
  445. // gGeoManager->GetListOfMaterials()->Print();
  446. // gGeoManager->GetListOfMedia()->Print();
  447. }
  448. //! Recursevly go down the tree of nodes
  449. if (curVol->GetNdaughters() != 0) {
  450. TObjArray* NodeChildList = curVol->GetNodes();
  451. TGeoNode* curNodeChild;
  452. for (Int_t j=0; j<NodeChildList->GetEntriesFast(); j++) {
  453. curNodeChild = (TGeoNode*)NodeChildList->At(j);
  454. ExpandNodeForGdml(curNodeChild);
  455. }
  456. }
  457. }
  458. //-----------------------------------------------------------------------------
  459. //Check if Sensitive-----------------------------------------------------------
  460. Bool_t MpdStrawendcap::CheckIfSensitive(std::string name) {
  461. TString tsname = name;
  462. if (tsname.Contains("straw_gas")) {
  463. return kTRUE;
  464. }
  465. return kFALSE;
  466. }
  467. //-----------------------------------------------------------------------------
  468. MpdStrawendcapPoint* MpdStrawendcap::AddHit(Int_t trackID, Int_t detID, TVector3 pos, Double_t radius,
  469. TVector3 mom, Double_t time, Double_t length,
  470. Double_t eLoss, Int_t isPrimary, Double_t charge, Int_t pdgId, TVector3 trackPos) {
  471. TClonesArray& clref = *fStrawendcapCollection;
  472. Int_t size = clref.GetEntriesFast();
  473. //std::cout << "ELoss: " << eLoss << "\n";
  474. return new(clref[size]) MpdStrawendcapPoint(trackID, detID, pos, radius, mom, time, length, eLoss, isPrimary, charge, pdgId, trackPos);
  475. }
  476. //------------------------------------------------------------------------------------------------------------------------
  477. ClassImp(MpdStrawendcap)