MpdStsNew2.cxx 8.6 KB

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