MpdBbc.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //------------------------------------------------------------------------------------------------------------------------
  2. // -------------------------------------------------------------------------
  3. // ----- MpdBbc source file -----
  4. // -------------------------------------------------------------------------
  5. #include <iostream>
  6. #include "TClonesArray.h"
  7. #include "TLorentzVector.h"
  8. #include "TParticle.h"
  9. #include "TVirtualMC.h"
  10. #include "FairGeoInterface.h"
  11. #include "FairGeoLoader.h"
  12. #include "FairGeoNode.h"
  13. #include "FairGeoRootBuilder.h"
  14. #include "FairRootManager.h"
  15. #include "FairStack.h"
  16. #include "FairRuntimeDb.h"
  17. #include "TObjArray.h"
  18. #include "FairRun.h"
  19. #include "FairVolume.h"
  20. #include "MpdBbc.h"
  21. #include "MpdBbcGeo.h"
  22. #include "MpdBbcPoint.h"
  23. #include "MpdBbcGeoPar.h"
  24. class FairVolume;
  25. //------------------------------------------------------------------------------------------------------------------------
  26. MpdBbc::MpdBbc()
  27. : FairDetector("BBC", kTRUE)
  28. {
  29. fBbcCollection = new TClonesArray("MpdBbcPoint");
  30. fPosIndex = 0;
  31. fVerboseLevel = 1;
  32. }
  33. //------------------------------------------------------------------------------------------------------------------------
  34. MpdBbc::MpdBbc(const char* name, Bool_t active)
  35. : FairDetector(name, active)
  36. {
  37. fBbcCollection = new TClonesArray("MpdBbcPoint");
  38. fPosIndex = 0;
  39. fVerboseLevel = 1;
  40. }
  41. //------------------------------------------------------------------------------------------------------------------------
  42. MpdBbc::~MpdBbc()
  43. {
  44. if(fBbcCollection){ fBbcCollection->Delete(); delete fBbcCollection; }
  45. }
  46. //------------------------------------------------------------------------------------------------------------------------
  47. Bool_t MpdBbc::ProcessHits(FairVolume* vol)
  48. {
  49. Int_t gap, cell, module, region;
  50. TString Volname;
  51. // Set parameters at entrance of volume. Reset ELoss.
  52. if(gMC->IsTrackEntering())
  53. {
  54. fELoss = 0.;
  55. fTime = gMC->TrackTime() * 1.0e09;
  56. fLength = gMC->TrackLength();
  57. gMC->TrackPosition(fPos);
  58. gMC->TrackMomentum(fMom);
  59. }
  60. // Sum energy loss for all steps in the active volume
  61. fELoss += gMC->Edep();
  62. // Create MpdBbcPoint at exit of active volume
  63. // if(gMC->TrackCharge() != 0 && (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) )
  64. // Create MpdBbcPoint at ENTER of active volume; fELoss INVALID!!!
  65. if(gMC->IsTrackEntering())
  66. {
  67. fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
  68. Volname = vol->getRealName();
  69. region = Volname[5] - '0'; //?????????????????????????
  70. gMC->CurrentVolID(gap);
  71. gMC->CurrentVolOffID(1, cell);
  72. gMC->CurrentVolOffID(2, module);
  73. fVolumeID = ((region-1)<<24);////////////// + ((module-1)<<14) + ((cell-1)<<4) + (gap-1);
  74. AddHit(fTrackID, fVolumeID, TVector3(fPos.X(), fPos.Y(), fPos.Z()),
  75. TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss);
  76. ((FairStack*)gMC->GetStack())->AddPoint(kBBC);
  77. ResetParameters();
  78. }
  79. return kTRUE;
  80. }
  81. //------------------------------------------------------------------------------------------------------------------------
  82. void MpdBbc::EndOfEvent()
  83. {
  84. if(fVerboseLevel) Print();
  85. fBbcCollection->Clear();
  86. fPosIndex = 0;
  87. }
  88. //------------------------------------------------------------------------------------------------------------------------
  89. void MpdBbc::Register(){ FairRootManager::Instance()->Register("BBCPoint", "Bbc", fBbcCollection, kTRUE); }
  90. //------------------------------------------------------------------------------------------------------------------------
  91. TClonesArray* MpdBbc::GetCollection(Int_t iColl) const
  92. {
  93. if(iColl == 0) return fBbcCollection;
  94. return NULL;
  95. }
  96. //------------------------------------------------------------------------------------------------------------------------
  97. void MpdBbc::Print() const
  98. {
  99. Int_t nHits = fBbcCollection->GetEntriesFast();
  100. cout << "-I- MpdBbc: " << nHits << " points registered in this event." << endl;
  101. if(fVerboseLevel > 1)
  102. for(Int_t i=0; i<nHits; i++) (*fBbcCollection)[i]->Print();
  103. }
  104. //------------------------------------------------------------------------------------------------------------------------
  105. void MpdBbc::Reset(){ fBbcCollection->Clear(); ResetParameters(); }
  106. //------------------------------------------------------------------------------------------------------------------------
  107. void MpdBbc::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
  108. {
  109. Int_t nEntries = cl1->GetEntriesFast();
  110. cout << "-I- MpdBbc: " << nEntries << " entries to add." << endl;
  111. TClonesArray& clref = *cl2;
  112. MpdBbcPoint* oldpoint = NULL;
  113. for(Int_t i=0; i<nEntries; i++)
  114. {
  115. oldpoint = (MpdBbcPoint*) cl1->At(i);
  116. Int_t index = oldpoint->GetTrackID() + offset;
  117. oldpoint->SetTrackID(index);
  118. new (clref[fPosIndex]) MpdBbcPoint(*oldpoint);
  119. fPosIndex++;
  120. }
  121. cout << "-I- MpdBbc: " << cl2->GetEntriesFast() << " merged entries." << endl;
  122. }
  123. //------------------------------------------------------------------------------------------------------------------------
  124. void MpdBbc::ConstructGeometry()
  125. {
  126. Int_t count=0;
  127. Int_t count_tot=0;
  128. FairGeoLoader* geoLoad = FairGeoLoader::Instance();
  129. FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  130. MpdBbcGeo* bbcGeo = new MpdBbcGeo();
  131. bbcGeo->setGeomFile(GetGeometryFileName());
  132. geoFace->addGeoModule(bbcGeo);
  133. Bool_t rc = geoFace->readSet(bbcGeo);
  134. if(rc) bbcGeo->create(geoLoad->getGeoBuilder());
  135. TList* volList = bbcGeo->getListOfVolumes();
  136. // store geo parameter
  137. FairRun *fRun = FairRun::Instance();
  138. FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
  139. MpdBbcGeoPar* par =(MpdBbcGeoPar*)(rtdb->getContainer("MpdBbcGeoPar"));
  140. TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
  141. TObjArray *fPassNodes = par->GetGeoPassiveNodes();
  142. FairGeoNode *node = NULL;
  143. FairGeoVolume *aVol = NULL;
  144. TListIter iter(volList);
  145. while((node = (FairGeoNode*)iter.Next()))
  146. {
  147. aVol = dynamic_cast<FairGeoVolume*> (node);
  148. if(node->isSensitive()){ fSensNodes->AddLast(aVol); count++; }
  149. else fPassNodes->AddLast(aVol);
  150. count_tot++;
  151. }
  152. par->setChanged();
  153. par->setInputVersion(fRun->GetRunId(), 1);
  154. ProcessNodes(volList);
  155. }
  156. //------------------------------------------------------------------------------------------------------------------------
  157. MpdBbcPoint* MpdBbc::AddHit(Int_t trackID, Int_t detID, TVector3 pos,
  158. TVector3 mom, Double_t time, Double_t length,
  159. Double_t eLoss)
  160. {
  161. TClonesArray& clref = *fBbcCollection;
  162. Int_t size = clref.GetEntriesFast();
  163. return new(clref[size]) MpdBbcPoint(trackID, detID, pos, mom, time, length, eLoss);
  164. }
  165. //------------------------------------------------------------------------------------------------------------------------
  166. ClassImp(MpdBbc)