MpdMcord.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * MpdMcord.cxx
  3. *
  4. * Created on: 20 maj 2019
  5. * Author: Daniel Wielanek
  6. * E-mail: daniel.wielanek@gmail.com
  7. * Warsaw University of Technology, Faculty of Physics
  8. */
  9. #include "MpdMcord.h"
  10. #include "MpdMcordPoint.h"
  11. #include "MpdDetectorList.h" // for DetectorId::kTutDet
  12. #include "FairGeoInterface.h" // for FairGeoInterface
  13. #include "FairGeoLoader.h" // for FairGeoLoader
  14. #include "FairGeoNode.h" // for FairGeoNode
  15. #include "FairGeoVolume.h" // for FairGeoVolume
  16. #include "FairRootManager.h" // for FairRootManager
  17. #include "FairRun.h" // for FairRun
  18. #include "FairRuntimeDb.h" // for FairRuntimeDb
  19. #include "MpdMcordGeo.h" // for FairTutorialDet1Geo
  20. #include "MpdMcordGeoPar.h" // for FairTutorialDet1GeoPar
  21. #include "MpdMcordPoint.h" // for FairTutorialDet1Point
  22. #include "FairVolume.h" // for FairVolume
  23. #include "FairLogger.h" // for logging
  24. #include "TVirtualMC.h"
  25. #include "MpdStack.h"
  26. #include "MpdMcordGeo.h"
  27. #include "MpdMcordGeoPar.h"
  28. #include "MpdMcordPoint.h"
  29. #include "TLorentzVector.h"
  30. MpdMcordGeo *MpdMcord::fgGeo = nullptr;
  31. MpdMcord::MpdMcord() :MpdMcord("mcord",kTRUE) {
  32. }
  33. MpdMcord::MpdMcord(const char* name, Bool_t active) :
  34. FairDetector(name, active),
  35. fTrackID(0),fVolumeID(0),fPos(0,0,0,0),fMom(0,0,0,0),
  36. fTime(0),fLength(0),fELoss(0)
  37. {
  38. fPointCollection = new TClonesArray("MpdMcordPoint");
  39. }
  40. MpdMcord::~MpdMcord() {
  41. delete fPointCollection;
  42. }
  43. Bool_t MpdMcord::ProcessHits(FairVolume* vol) {
  44. LOG(debug) << "In Mcord ::ProcessHits";
  45. //Set parameters at entrance of volume. Reset ELoss.
  46. if ( TVirtualMC::GetMC()->IsTrackEntering() ) {
  47. fELoss = 0.;
  48. fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
  49. fLength = TVirtualMC::GetMC()->TrackLength();
  50. TVirtualMC::GetMC()->TrackPosition(fPos);
  51. TVirtualMC::GetMC()->TrackMomentum(fMom);
  52. }
  53. // Sum energy loss for all steps in the active volume
  54. fELoss += TVirtualMC::GetMC()->Edep();
  55. // Create FairTutorialDet1Point at exit of active volume
  56. if ( TVirtualMC::GetMC()->IsTrackExiting() ||
  57. TVirtualMC::GetMC()->IsTrackStop() ||
  58. TVirtualMC::GetMC()->IsTrackDisappeared() ) {
  59. fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
  60. fVolumeID = vol->getMCid();
  61. if (fELoss == 0. ) { return kFALSE; }
  62. AddHit(fTrackID, fVolumeID, fPos.Vect(),fMom.Vect(), fTime, fLength,
  63. fELoss);
  64. }
  65. return kTRUE;
  66. }
  67. void MpdMcord::EndOfEvent() {
  68. fPointCollection->Delete();
  69. }
  70. void MpdMcord::Register() {
  71. if ( ! gMC->IsMT() ) {
  72. FairRootManager::Instance()->Register("McordPoint", "Mcord",
  73. fPointCollection, kTRUE);
  74. } else {
  75. FairRootManager::Instance()->RegisterAny("McordPoint",
  76. fPointCollection, kTRUE);
  77. }
  78. }
  79. TClonesArray* MpdMcord::GetCollection(Int_t iColl) const {
  80. if (iColl == 0) { return fPointCollection; }
  81. else { return nullptr; }
  82. }
  83. void MpdMcord::Print() const {
  84. Int_t nHits = fPointCollection->GetEntriesFast();
  85. std::cout << "-I- MpdTof: " << nHits << " points registered in this event." << std::endl;
  86. }
  87. void MpdMcord::Reset() {
  88. fPointCollection->Clear();
  89. }
  90. void MpdMcord::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
  91. }
  92. void MpdMcord::ConstructGeometry() {
  93. TString fileName=GetGeometryFileName();
  94. if(fileName.EndsWith(".root"))
  95. {
  96. LOG(info)<<"Constructing MCORD geometry from ROOT file"<<fileName.Data();
  97. ConstructRootGeometry();
  98. return;
  99. }
  100. LOG(info)<<"Constructing MCORD geometry from ASCII file "<<fileName;
  101. FairGeoLoader* loader=FairGeoLoader::Instance();
  102. FairGeoInterface* GeoInterface =loader->getGeoInterface();
  103. MpdMcordGeo* MGeo=new MpdMcordGeo();
  104. MGeo->setGeomFile(GetGeometryFileName());
  105. GeoInterface->addGeoModule(MGeo);
  106. Bool_t rc = GeoInterface->readSet(MGeo);
  107. if ( rc ) { MGeo->create(loader->getGeoBuilder()); }
  108. TList* volList = MGeo->getListOfVolumes();
  109. // store geo parameter
  110. //FairRun* fRun = FairRun::Instance();
  111. FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
  112. MpdMcordGeoPar* par=static_cast<MpdMcordGeoPar*>(rtdb->getContainer("MpdMcordGeoPar"));
  113. TObjArray* fSensNodes = par->GetGeoSensitiveNodes();
  114. TObjArray* fPassNodes = par->GetGeoPassiveNodes();
  115. TListIter iter(volList);
  116. FairGeoNode *node = nullptr;
  117. FairGeoVolume *aVol = nullptr;
  118. while((node = (FairGeoNode*)iter.Next()))
  119. {
  120. aVol = dynamic_cast<FairGeoVolume*> (node);
  121. if(node->isSensitive()) fSensNodes->AddLast(aVol);
  122. else fPassNodes->AddLast(aVol);
  123. }
  124. par->setChanged();
  125. par->setInputVersion(FairRun::Instance()->GetRunId(), 1);
  126. ProcessNodes(volList);
  127. }
  128. Bool_t MpdMcord::CheckIfSensitive(std::string name){
  129. TString tsname = name;
  130. if(tsname.BeginsWith("md01scintVol")){
  131. return kTRUE;
  132. }else{
  133. return kFALSE;
  134. }
  135. }
  136. MpdMcordPoint* MpdMcord::AddHit(Int_t trackID, Int_t detId, TVector3 pos,
  137. TVector3 mom, Double_t time, Double_t length, Double_t eloss) {
  138. TClonesArray &clref = *fPointCollection;
  139. Int_t size = clref.GetEntriesFast();
  140. MpdStack* stack = static_cast<MpdStack*>(TVirtualMC::GetMC()->GetStack());
  141. stack->AddPoint(kMCORD);
  142. return new(clref[size]) MpdMcordPoint(trackID, detId, pos, mom,
  143. time, length, eloss);
  144. }