MpdSts.cxx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //--------------------------------------------------------------------------
  2. // -------------------------------------------------------------------------
  3. // ----- MpdSts 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 "MpdStack.h"
  16. #include "FairRuntimeDb.h"
  17. #include "TObjArray.h"
  18. #include "FairRun.h"
  19. #include "FairVolume.h"
  20. #include "MpdSts.h"
  21. #include "MpdStsGeo.h"
  22. #include "MpdStsPoint.h"
  23. #include "MpdStsGeoPar.h"
  24. class FairVolume;
  25. //--------------------------------------------------------------------------
  26. MpdSts::MpdSts()
  27. : FairDetector("STS", kTRUE)
  28. {
  29. fStsCollection = new TClonesArray("MpdStsPoint");
  30. fPosIndex = 0;
  31. fVerboseLevel = 1;
  32. }
  33. //--------------------------------------------------------------------------
  34. MpdSts::MpdSts(const char* name, Bool_t active)
  35. : FairDetector(name, active)
  36. {
  37. fStsCollection = new TClonesArray("MpdStsPoint");
  38. fPosIndex = 0;
  39. fVerboseLevel = 1;
  40. }
  41. //--------------------------------------------------------------------------
  42. MpdSts::~MpdSts()
  43. {
  44. if(fStsCollection){ fStsCollection->Delete(); delete fStsCollection; }
  45. }
  46. //--------------------------------------------------------------------------
  47. Bool_t MpdSts::ProcessHits(FairVolume* vol)
  48. {
  49. Int_t sensor, detector, layer, ladder, side = 0;
  50. TString Volname;
  51. // Set parameters at entrance of volume. Reset ELoss.
  52. if (gMC->IsTrackEntering()) {
  53. fELoss = 0.;
  54. fTime = gMC->TrackTime() * 1.0e09;
  55. fLength = gMC->TrackLength();
  56. gMC->TrackPosition(fPos);
  57. gMC->TrackMomentum(fMom);
  58. }
  59. // Sum energy loss for all steps in the active volume
  60. try {
  61. fELoss += gMC->Edep();
  62. }
  63. catch (...) {
  64. cout << "-E- MpdSts::ProcessHits gMC->Edep() exception !!!" << ((UInt_t*)gMC) << endl;
  65. }
  66. // Create MpdStsPoint at exit of active volume
  67. //if (gMC->TrackCharge() != 0 && (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) )
  68. if ( (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) && fELoss > 0 ) {
  69. // Exiting volume or stopped track - save point
  70. fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
  71. Volname = vol->getRealName(); // EL
  72. if (Volname.Contains("sensor")) {
  73. // Modular geometry
  74. layer = Volname[11]-48; // Layer
  75. gMC->CurrentVolID(sensor); // CopyNo of sensor
  76. gMC->CurrentVolOffID(1,detector);// CopyNo of detector
  77. gMC->CurrentVolOffID(2,ladder); // CopyNo of ladder
  78. gMC->CurrentVolOffName(2); // name of ladder
  79. gMC->CurrentVolOffName(1); // name of detector
  80. gMC->CurrentVolOffName(0); // name of sensor
  81. gMC->CurrentVolPath(); // path from cave to sts01sensor
  82. fVolumeID = side; // side on bit 0 - 1 because number of sides=1 (0,1)
  83. fVolumeID |= (layer<<1); // layer on bit 1 - 4 because number of layers=4, 4(dec)->4(bin)=100 => num of bytes = 3
  84. fVolumeID |= (ladder<<5); // ladder on bit 5 - 9 because max number of ladders=18, 18(dec)->18(bin)=10010 => num of bytes = 5
  85. fVolumeID |= (detector<<10); // detector on bit 10 - 14 because max number of detectors=24, 24(dec)->24(bin)=11000 => num of bytes = 5
  86. //**************************************************************************************
  87. // cout << fTrackID << " " << Volname << " " << gMC->CurrentVolOffName(1) << " "
  88. // << gMC->CurrentVolOffName(0) << " " << gMC->CurrentVolPath() << " " << cell << " "
  89. // << gMC->CurrentVolOffID(1, ladder) << " " << endl;
  90. /*
  91. cout << fTrackID << " " << Volname << " " << gMC->CurrentVolPath() << endl;
  92. cout << layer << " " << ladder << " " << detector << " " << side << " " <<endl;
  93. cout << fVolumeID << endl;
  94. cout << (fVolumeID >> 10) << " " << ((fVolumeID >> 5) & 31) << " " << ((fVolumeID >> 1) & 15) << " " << (fVolumeID & 1) << endl;
  95. */
  96. //*************************************************************************************
  97. } else {
  98. // Simple "cylinder" geometry
  99. Int_t region = Volname[5] - 96;
  100. fVolumeID = (region<<1);
  101. }
  102. TVector3 vposIn = TVector3(fPos.X(), fPos.Y(), fPos.Z());
  103. TVector3 vmomIn = TVector3 (fMom.Px(), fMom.Py(), fMom.Pz());
  104. gMC->TrackPosition(fPos);
  105. TVector3 vposOut = TVector3(fPos.X(), fPos.Y(), fPos.Z());
  106. // AddHit(fTrackID, fVolumeID, TVector3(fPos.X(), fPos.Y(), fPos.Z()),
  107. // TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss);
  108. AddHit(fTrackID, fVolumeID, vposIn, vmomIn, vposOut, fTime, fLength, fELoss);
  109. ((MpdStack*)gMC->GetStack())->AddPoint(kSTS);
  110. ResetParameters();
  111. }
  112. return kTRUE;
  113. }
  114. //-------------------------------------------------------------------------------------------------------
  115. void MpdSts::EndOfEvent()
  116. {
  117. if(fVerboseLevel) Print();
  118. fStsCollection->Delete();
  119. fPosIndex = 0;
  120. }
  121. //------------------------------------------------------------------------------------------------------
  122. void MpdSts::Register(){ FairRootManager::Instance()->Register("StsPoint", "Sts", fStsCollection, kTRUE); }
  123. //-------------------------------------------------------------------------------------------------------
  124. TClonesArray* MpdSts::GetCollection(Int_t iColl) const
  125. {
  126. if(iColl == 0) return fStsCollection;
  127. return NULL;
  128. }
  129. //-------------------------------------------------------------------------------------------------------
  130. void MpdSts::Print() const
  131. {
  132. Int_t nHits = fStsCollection->GetEntriesFast();
  133. cout << "-I- MpdSts: " << nHits << " points registered in this event." << endl;
  134. if(fVerboseLevel > 1)
  135. for(Int_t i=0; i<nHits; i++) (*fStsCollection)[i]->Print();
  136. }
  137. //-------------------------------------------------------------------------------------------------------
  138. void MpdSts::Reset(){ fStsCollection->Delete(); ResetParameters(); }
  139. //-------------------------------------------------------------------------------------------------------
  140. void MpdSts::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
  141. {
  142. Int_t nEntries = cl1->GetEntriesFast();
  143. cout << "-I- MpdSts: " << nEntries << " entries to add." << endl;
  144. TClonesArray& clref = *cl2;
  145. MpdStsPoint* oldpoint = NULL;
  146. for(Int_t i=0; i<nEntries; i++)
  147. {
  148. oldpoint = (MpdStsPoint*) cl1->At(i);
  149. Int_t index = oldpoint->GetTrackID() + offset;
  150. oldpoint->SetTrackID(index);
  151. new (clref[fPosIndex]) MpdStsPoint(*oldpoint);
  152. fPosIndex++;
  153. }
  154. cout << "-I- MpdSts: " << cl2->GetEntriesFast() << " merged entries." << endl;
  155. }
  156. //-------------------------------------------------------------------------------------------------------
  157. void MpdSts::ConstructGeometry()
  158. {
  159. Int_t count=0;
  160. Int_t count_tot=0;
  161. FairGeoLoader* geoLoad = FairGeoLoader::Instance();
  162. FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  163. MpdStsGeo* stsGeo = new MpdStsGeo();
  164. stsGeo->setGeomFile(GetGeometryFileName());
  165. geoFace->addGeoModule(stsGeo);
  166. Bool_t rc = geoFace->readSet(stsGeo);
  167. if(rc) stsGeo->create(geoLoad->getGeoBuilder());
  168. TList* volList = stsGeo->getListOfVolumes();
  169. // store geo parameter
  170. FairRun *fRun = FairRun::Instance();
  171. FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
  172. MpdStsGeoPar* par =(MpdStsGeoPar*)(rtdb->getContainer("MpdStsGeoPar"));
  173. TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
  174. TObjArray *fPassNodes = par->GetGeoPassiveNodes();
  175. FairGeoNode *node = NULL;
  176. FairGeoVolume *aVol = NULL;
  177. TListIter iter(volList);
  178. while((node = (FairGeoNode*)iter.Next()))
  179. {
  180. aVol = dynamic_cast<FairGeoVolume*> (node);
  181. if(node->isSensitive()){ fSensNodes->AddLast(aVol); count++; }
  182. else fPassNodes->AddLast(aVol);
  183. count_tot++;
  184. }
  185. par->setChanged();
  186. par->setInputVersion(fRun->GetRunId(), 1);
  187. ProcessNodes(volList);
  188. }
  189. //--------------------------------------------------------------------------------------------------------
  190. MpdStsPoint* MpdSts::AddHit(Int_t trackID, Int_t detID, TVector3 posIn,
  191. TVector3 momIn, TVector3 posOut,
  192. Double_t time, Double_t length, Double_t eLoss)
  193. {
  194. TClonesArray& clref = *fStsCollection;
  195. Int_t size = clref.GetEntriesFast();
  196. return new(clref[size]) MpdStsPoint(trackID, detID, posIn, momIn,
  197. posOut, time, length, eLoss);
  198. }
  199. //--------------------------------------------------------------------------------------------------------
  200. ClassImp(MpdSts)