MpdEtof.cxx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <limits>
  4. #include <TGeoManager.h>
  5. #include <TClonesArray.h>
  6. #include <TVirtualMC.h>
  7. #include <TGeoManager.h>
  8. #include <TGeoBBox.h>
  9. #include <TGeoMatrix.h>
  10. #include "FairGeoInterface.h"
  11. #include "FairGeoLoader.h"
  12. #include "FairGeoNode.h"
  13. #include "FairGeoRootBuilder.h"
  14. #include "FairRootManager.h"
  15. #include "MpdStack.h"
  16. #include "FairRuntimeDb.h"
  17. #include "FairRunAna.h"
  18. #include "FairVolume.h"
  19. #include "MpdEtofGeo.h"
  20. #include "MpdTofPoint.h"
  21. #include "MpdEtofGeoPar.h"
  22. #include "MpdEtof.h"
  23. ClassImp(MpdEtof)
  24. using namespace std;
  25. //------------------------------------------------------------------------------------------------------------------------
  26. MpdEtof::MpdEtof(const char* name, Bool_t active)
  27. : FairDetector(name, active), nan(std::numeric_limits<double>::quiet_NaN())
  28. {
  29. aTofHits = new TClonesArray("MpdTofPoint");
  30. fPosIndex = 0;
  31. fVerboseLevel = 1;
  32. }
  33. //------------------------------------------------------------------------------------------------------------------------
  34. MpdEtof::~MpdEtof()
  35. {
  36. if(aTofHits){ aTofHits->Delete(); delete aTofHits; }
  37. }
  38. //------------------------------------------------------------------------------------------------------------------------
  39. Bool_t MpdEtof::ProcessHits(FairVolume* vol)
  40. {
  41. Int_t strip, box, sector; //detector,
  42. // Set parameters at entrance of volume. Reset ELoss.
  43. if(gMC->IsTrackEntering())
  44. {
  45. fELoss = 0.;
  46. fTime = gMC->TrackTime() * 1.0e09;
  47. fLength = gMC->TrackLength();
  48. gMC->TrackPosition(fPos);
  49. gMC->TrackMomentum(fMom);
  50. }
  51. // Sum energy loss for all steps in the active volume
  52. fELoss += gMC->Edep();
  53. // Create MpdTofPoint at exit of active volume
  54. if(fELoss > 0 && (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) )
  55. {
  56. fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
  57. TString padname = vol->GetName(); padname.Remove(0, 7); strip = padname.Atoi();//gMC->CurrentVolOffID(1, pad);
  58. //detector = 1;
  59. gMC->CurrentVolOffID(2, box);
  60. gMC->CurrentVolOffID(3, sector);
  61. fVolumeID = MpdTofPoint::GetSuid72(sector, box, strip); // stub!!!
  62. AddPoint(fTrackID, fVolumeID, fPos.Vect(), fMom.Vect(), fTime, fLength, fELoss);
  63. ((MpdStack*)gMC->GetStack())->AddPoint(kETOF);
  64. ResetParameters();
  65. }
  66. return kTRUE;
  67. }
  68. //------------------------------------------------------------------------------------------------------------------------
  69. void MpdEtof::EndOfEvent()
  70. {
  71. if(fVerboseLevel) Print();
  72. aTofHits->Delete();
  73. fPosIndex = 0;
  74. }
  75. //------------------------------------------------------------------------------------------------------------------------
  76. void MpdEtof::Register(){ FairRootManager::Instance()->Register("ETOFPoint", "Etof", aTofHits, kTRUE); }
  77. //------------------------------------------------------------------------------------------------------------------------
  78. TClonesArray* MpdEtof::GetCollection(Int_t iColl) const
  79. {
  80. if(iColl == 0) return aTofHits;
  81. return nullptr;
  82. }
  83. //------------------------------------------------------------------------------------------------------------------------
  84. void MpdEtof::Print() const
  85. {
  86. Int_t nHits = aTofHits->GetEntriesFast();
  87. cout << "-I- MpdEtof: " << nHits << " points registered in this event." << endl;
  88. if(fVerboseLevel > 1) for(Int_t i=0; i<nHits; i++) (*aTofHits)[i]->Print();
  89. }
  90. //------------------------------------------------------------------------------------------------------------------------
  91. void MpdEtof::Reset(){ aTofHits->Delete(); ResetParameters(); }
  92. //------------------------------------------------------------------------------------------------------------------------
  93. void MpdEtof::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
  94. {
  95. Int_t nEntries = cl1->GetEntriesFast();
  96. cout << "-I- MpdEtof: " << nEntries << " entries to add." << endl;
  97. TClonesArray& clref = *cl2;
  98. MpdTofPoint* oldpoint = nullptr;
  99. for(Int_t i=0; i<nEntries; i++)
  100. {
  101. oldpoint = (MpdTofPoint*) cl1->At(i);
  102. Int_t index = oldpoint->GetTrackID() + offset;
  103. oldpoint->SetTrackID(index);
  104. new (clref[fPosIndex]) MpdTofPoint(*oldpoint);
  105. fPosIndex++;
  106. }
  107. cout << "-I- MpdEtof: " << cl2->GetEntriesFast() << " merged entries." << endl;
  108. }
  109. //------------------------------------------------------------------------------------------------------------------------
  110. void MpdEtof::ConstructGeometry()
  111. {
  112. FairGeoLoader* geoLoad = FairGeoLoader::Instance();
  113. FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  114. MpdEtofGeo* tofGeo = new MpdEtofGeo();
  115. tofGeo->setGeomFile(GetGeometryFileName());
  116. geoFace->addGeoModule(tofGeo);
  117. Bool_t rc = geoFace->readSet(tofGeo);
  118. if(rc) tofGeo->create(geoLoad->getGeoBuilder());
  119. TList* volList = tofGeo->getListOfVolumes();
  120. // store geo parameter
  121. FairRun *fRun = FairRun::Instance();
  122. FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
  123. MpdEtofGeoPar* par =(MpdEtofGeoPar*)(rtdb->getContainer("MpdEtofGeoPar"));
  124. TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
  125. TObjArray *fPassNodes = par->GetGeoPassiveNodes();
  126. FairGeoNode *node = nullptr;
  127. FairGeoVolume *aVol = nullptr;
  128. TListIter iter(volList);
  129. while((node = (FairGeoNode*)iter.Next()))
  130. {
  131. aVol = dynamic_cast<FairGeoVolume*> (node);
  132. if(node->isSensitive()) fSensNodes->AddLast(aVol);
  133. else fPassNodes->AddLast(aVol);
  134. }
  135. par->setChanged();
  136. par->setInputVersion(fRun->GetRunId(), 1);
  137. ProcessNodes(volList);
  138. }
  139. //------------------------------------------------------------------------------------------------------------------------
  140. MpdTofPoint* MpdEtof::AddPoint(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
  141. {
  142. return new((*aTofHits)[aTofHits->GetEntriesFast()]) MpdTofPoint(trackID, detID, pos, mom, time, length, eLoss);
  143. }
  144. //------------------------------------------------------------------------------------------------------------------------