MpdSft.cxx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //------------------------------------------------------------------------------------------------------------------------
  2. // -------------------------------------------------------------------------
  3. // ----- MpdSft source file -----
  4. // ----- Created 28/07/04 by V. Friese -----
  5. // -------------------------------------------------------------------------
  6. #include "MpdSft.h"
  7. #include "MpdSftGeo.h"
  8. #include "MpdSftGeoPar.h"
  9. #include "MpdSftPoint.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 "FairRun.h"
  18. #include "FairVolume.h"
  19. #include "TClonesArray.h"
  20. #include "TLorentzVector.h"
  21. #include "TParticle.h"
  22. #include "TVirtualMC.h"
  23. #include "TObjArray.h"
  24. #include <iostream>
  25. //------------------------------------------------------------------------------------------------------------------------
  26. MpdSft::MpdSft()
  27. : FairDetector("SFT", kTRUE)
  28. {
  29. fTofCollection = new TClonesArray("MpdSftPoint");
  30. fPosIndex = 0;
  31. fVerboseLevel = 1;
  32. }
  33. //------------------------------------------------------------------------------------------------------------------------
  34. MpdSft::MpdSft(const char* name, Bool_t active)
  35. : FairDetector(name, active)
  36. {
  37. fTofCollection = new TClonesArray("MpdSftPoint");
  38. fPosIndex = 0;
  39. fVerboseLevel = 1;
  40. }
  41. //------------------------------------------------------------------------------------------------------------------------
  42. MpdSft::~MpdSft()
  43. {
  44. if(fTofCollection){ fTofCollection->Delete(); delete fTofCollection; }
  45. }
  46. //------------------------------------------------------------------------------------------------------------------------
  47. Bool_t MpdSft::ProcessHits(FairVolume* vol)
  48. {
  49. const Double_t pitch = 0.01; // strip pitch 100 um
  50. static Bool_t first = kTRUE;
  51. static Double_t dph[4] = {0}, radi[4] = {5., 12.5, 6., 13.}; // inner rad.
  52. if (first) {
  53. // Compute some parameters
  54. first = kFALSE;
  55. for (Int_t i = 0; i < 4; ++i) {
  56. dph[i] = TMath::TwoPi() * radi[i] / pitch;
  57. cout << " Inner radius: " << radi[i] << ", pitch number: " << dph[i] << endl;
  58. dph[i] = TMath::TwoPi() / dph[i]; // angular pitch
  59. }
  60. }
  61. //cout << "Got Hit!\n";
  62. Int_t module, strip;//, gap, cell;
  63. TString volname;
  64. // Set parameters at entrance of volume. Reset ELoss.
  65. if (gMC->IsTrackEntering()) {
  66. fELoss = 0.;
  67. fTime = gMC->TrackTime() * 1.0e09;
  68. fLength = gMC->TrackLength();
  69. gMC->TrackPosition(fPos);
  70. gMC->TrackMomentum(fMom);
  71. globalPos[0] = globalPos[1] = globalPos[2] = 0;
  72. localPos[0] = localPos[1] = localPos[2] = 0;
  73. gMC->Gdtom(localPos, globalPos, 1);
  74. }
  75. // Sum energy loss for all steps in the active volume
  76. fELoss += gMC->Edep();
  77. // Create MpdSftPoint at exit of active volume
  78. //if (gMC->TrackCharge() != 0 && (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared())) {
  79. if (fELoss != 0 && (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared())) {
  80. fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
  81. //gMC->CurrentVolOffID(1, strip);
  82. //gMC->CurrentVolOffID(3, module);
  83. gMC->CurrentVolOffID(1, module);
  84. volname = vol->getRealName();
  85. //fVolumeID = (module<<14) + (strip<<4);
  86. //sscanf(&(volname[11]),"%d",&fVolumeID);
  87. if (volname.Length() == 12) sscanf(&(volname[11]),"%d",&fVolumeID);
  88. else sscanf(&(volname[11]),"%d%d",&fVolumeID);
  89. fVolumeID |= (module<<5);
  90. //cout << volname << " " << fVolumeID << " " << module << " " << fPos.Z() << endl;
  91. MpdSftPoint *p = 0x0;
  92. //if (fELoss > 0) AddHit(fTrackID, fVolumeID, TVector3(globalPos[0], globalPos[1], globalPos[2]),
  93. // TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss);
  94. if (fELoss > 0) p = AddHit(fTrackID, fVolumeID, TVector3(fPos.X(),fPos.Y(),fPos.Z()),
  95. TVector3(fMom.X(),fMom.Y(),fMom.Z()), fTime, fLength, fELoss); //AZ
  96. Int_t i = 0, istrip, irad = 0;
  97. if (fVolumeID != 3) {
  98. if (fPos.Pt() > radi[1]) i = 1;
  99. } else {
  100. i = (fPos.Pt() > radi[3]) ? 3 : 2;
  101. }
  102. istrip = (Int_t) (fPos.Phi() / dph[i]);
  103. irad = i % 2;
  104. if (p) {
  105. p->SetStrip(istrip);
  106. p->SetRad(irad);
  107. ((FairStack*)gMC->GetStack())->AddPoint(kFSA);
  108. }
  109. ResetParameters();
  110. }
  111. return kTRUE;
  112. }
  113. //------------------------------------------------------------------------------------------------------------------------
  114. void MpdSft::EndOfEvent()
  115. {
  116. if(fVerboseLevel) Print();
  117. fTofCollection->Delete();
  118. fPosIndex = 0;
  119. }
  120. //------------------------------------------------------------------------------------------------------------------------
  121. void MpdSft::Register(){ FairRootManager::Instance()->Register("SftPoint", "Sft", fTofCollection, kTRUE); }
  122. //------------------------------------------------------------------------------------------------------------------------
  123. TClonesArray* MpdSft::GetCollection(Int_t iColl) const
  124. {
  125. if(iColl == 0) return fTofCollection;
  126. return NULL;
  127. }
  128. //------------------------------------------------------------------------------------------------------------------------
  129. void MpdSft::Print() const
  130. {
  131. Int_t nHits = fTofCollection->GetEntriesFast();
  132. cout << "-I- MpdSft: " << nHits << " points registered in this event." << endl;
  133. if(fVerboseLevel > 1)
  134. for(Int_t i=0; i<nHits; i++) (*fTofCollection)[i]->Print();
  135. }
  136. //------------------------------------------------------------------------------------------------------------------------
  137. void MpdSft::Reset(){ fTofCollection->Delete(); ResetParameters(); }
  138. //------------------------------------------------------------------------------------------------------------------------
  139. void MpdSft::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
  140. {
  141. Int_t nEntries = cl1->GetEntriesFast();
  142. cout << "-I- MpdSft: " << nEntries << " entries to add." << endl;
  143. TClonesArray& clref = *cl2;
  144. MpdSftPoint* oldpoint = NULL;
  145. for(Int_t i=0; i<nEntries; i++)
  146. {
  147. oldpoint = (MpdSftPoint*) cl1->At(i);
  148. Int_t index = oldpoint->GetTrackID() + offset;
  149. oldpoint->SetTrackID(index);
  150. new (clref[fPosIndex]) MpdSftPoint(*oldpoint);
  151. fPosIndex++;
  152. }
  153. cout << "-I- MpdSft: " << cl2->GetEntriesFast() << " merged entries." << endl;
  154. }
  155. //------------------------------------------------------------------------------------------------------------------------
  156. void MpdSft::ConstructGeometry()
  157. {
  158. Int_t count=0;
  159. Int_t count_tot=0;
  160. FairGeoLoader* geoLoad = FairGeoLoader::Instance();
  161. FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  162. MpdSftGeo* tofGeo = new MpdSftGeo();
  163. tofGeo->setGeomFile(GetGeometryFileName());
  164. geoFace->addGeoModule(tofGeo);
  165. Bool_t rc = geoFace->readSet(tofGeo);
  166. if(rc) tofGeo->create(geoLoad->getGeoBuilder());
  167. TList* volList = tofGeo->getListOfVolumes();
  168. // store geo parameter
  169. FairRun *fRun = FairRun::Instance();
  170. FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
  171. MpdSftGeoPar* par =(MpdSftGeoPar*)(rtdb->getContainer("MpdSftGeoPar"));
  172. TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
  173. TObjArray *fPassNodes = par->GetGeoPassiveNodes();
  174. FairGeoNode *node = NULL;
  175. FairGeoVolume *aVol = NULL;
  176. TListIter iter(volList);
  177. while((node = (FairGeoNode*)iter.Next()))
  178. {
  179. aVol = dynamic_cast<FairGeoVolume*> (node);
  180. if(node->isSensitive()){ fSensNodes->AddLast(aVol); count++; }
  181. else fPassNodes->AddLast(aVol);
  182. count_tot++;
  183. }
  184. par->setChanged();
  185. par->setInputVersion(fRun->GetRunId(), 1);
  186. ProcessNodes(volList);
  187. }
  188. //------------------------------------------------------------------------------------------------------------------------
  189. MpdSftPoint* MpdSft::AddHit(Int_t trackID, Int_t detID, TVector3 pos,
  190. TVector3 mom, Double_t time, Double_t length,
  191. Double_t eLoss)
  192. {
  193. TClonesArray& clref = *fTofCollection;
  194. Int_t size = clref.GetEntriesFast();
  195. return new(clref[size]) MpdSftPoint(trackID, detID, pos, mom, time, length, eLoss);
  196. }
  197. //------------------------------------------------------------------------------------------------------------------------
  198. ClassImp(MpdSft)