FairRoot/PandaRoot
PndMdt.cxx
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "TClonesArray.h"
4 #include "TLorentzVector.h"
5 #include "TMath.h"
6 #include "TFile.h"
7 #include "TSystem.h"
8 #include "TParticle.h"
9 #include "TGeoMaterial.h"
10 #include "TGeoMedium.h"
11 #include "TGeoArb8.h"
12 #include "TGeoTrd2.h"
13 #include "TGeoMatrix.h"
14 #include "TGeoManager.h"
15 #include "TVirtualMC.h"
16 
17 #include "FairVolume.h"
18 // add on for debug
19 #include "FairRuntimeDb.h"
20 #include "FairRun.h"
21 #include "FairModule.h"
22 #include "PndDetectorList.h"
23 #include "PndStack.h"
24 
25 #include "PndMdt.h"
26 #include "PndMdtID.h"
27 #include "PndMdtPoint.h"
28 
29 
30 using namespace std;
31 
32 // ----- Default constructor -------------------------------------------
34  : FairDetector(), fMdtCollection(0), fTrkIn(-1),
35  fELoss(0), fTime(0), fPos_In(), fMom_In(),
36  fVerboseLevel(0),mdtMagnet(0), mdtCoil(0), mdtMFI(0),
37  fBarrel(""), fEndcap(""), fMuonFilter(""), fForward("")
38 {
39  fMdtCollection = new TClonesArray("PndMdtPoint");
40 }
41 // -------------------------------------------------------------------------
42 
43 
44 // ----- Inherited constructor -----------------------------------------
45 PndMdt::PndMdt(const char* name, Bool_t active)
46  : FairDetector(name,active), fMdtCollection(0), fTrkIn(-1),
47  fELoss(0), fTime(0), fPos_In(), fMom_In(),
48  fVerboseLevel(0),mdtMagnet(0), mdtCoil(0), mdtMFI(0),
49  fBarrel(""), fEndcap(""), fMuonFilter(""), fForward("")
50 {
51  fMdtCollection = new TClonesArray("PndMdtPoint");
52 }
53 // -------------------------------------------------------------------------
54 
55 
56 // ----- Destructor ----------------------------------------------------
58 {
59  if (fMdtCollection) {
60  fMdtCollection->Delete();
61  delete fMdtCollection;
62  };
63 }
64 // -------------------------------------------------------------------------
65 
66 
67 // ----- Public method Print ----------------------------------------------
68 void PndMdt::Print() const
69 {
70  Int_t nHits = fMdtCollection->GetEntriesFast();
71  for (Int_t i=0; i<nHits; i++) (*fMdtCollection)[i]->Print();
72 }
73 // ----------------------------------------------------------------------------
74 
75 
76 // ----- Public method Reset ----------------------------------------------
78 {
79  if (fMdtCollection) fMdtCollection->Delete();
80 }
81 // ----------------------------------------------------------------------------
82 
83 // ----- Public method ResetParameters ------------------------------------
85 {
86  fELoss = 0.;
87  fTime = 0.;
88 }
89 // ----------------------------------------------------------------------------
90 
91 // ----- Public method ConstructGeometry ----------------------------------
93 {
94  TString sysFile = gSystem->Getenv("VMCWORKDIR");
95  if (fBarrel!="")
96  {
97  if (fBarrel=="fast" || fBarrel =="Fast")
98  {
100  }
101  else if (fBarrel.EndsWith(".root"))
102  {
104  std::cout<<"======= MDT:: ConstructGeometry() ========"<<endl;
105  std::cout<<"File name, "<<fBarrel<<endl;
106  std::cout<<"============================================="<<endl;
107  ConstructRootGeometry();
108  }
109  else
110  {
111  std::cout<< "PndMdt::ConstructGeometry : No good MDT Barrel definition " <<std::endl;
112  exit(0);
113  }
114  }
115 
116  if (fEndcap!="")
117  {
118  if (fEndcap.EndsWith(".root"))
119  {
121  ConstructRootGeometry();
122  }
123  else if (fBarrel!="fast" && fBarrel !="Fast")
124  {
125  std::cout<< "PndMdt::ConstructGeometry : No good MDT Endcap definition " <<std::endl;
126  exit(0);
127  }
128  }
129 
130  if (fMuonFilter!="")
131  {
132  if (fMuonFilter=="fast" || fMuonFilter=="Fast")
133  {
135  }
136  else if (fMuonFilter.EndsWith(".root"))
137  {
139  ConstructRootGeometry();
140  }
141  else
142  {
143  std::cout<< "PndMdt::ConstructGeometry : No good MDT Muon Filter definition " <<std::endl;
144  exit(0);
145  }
146  }
147 
148  if (fForward!="")
149  {
150  if (fForward=="fast" || fForward =="Fast")
151  {
152  PndMdtForward();
153  }
154  else if (fForward.EndsWith(".root"))
155  {
157  ConstructRootGeometry();
158  }
159  else
160  {
161  std::cout<< "PndMdt::ConstructGeometry : No good MDT Forward definition " <<std::endl;
162  exit(0);
163  }
164  }
165 
166  if(mdtMagnet) PndMdtMagnet();
167  if(mdtMFI) PndMdtMFIron();
168  if(mdtCoil) PndMdtCoil();
169 
170  return;
171 }
172 // ----------------------------------------------------------------------------
173 
174 
175 // ----- Public method Intialize ---------------------------------------
177 {
179  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
180  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
181  //PndGeoMdtPar* par=(PndGeoMdtPar*)(rtdb->getContainer("PndGeoMdtPar"));
182 
183  //TObjArray *fSensNodes = par->GetSensitiveNodes();
184 }
185 // -------------------------------------------------------------------------
186 
187 
188 // ----- Public method BeginEvent --------------------------------------
190 {
191 }
192 // -------------------------------------------------------------------------
193 
194 
195 // ----- Public method ProcessHits --------------------------------------
196 Bool_t PndMdt::ProcessHits(FairVolume* vol)
197 {
198  TString name = gMC->CurrentVolOffName(1);
199  if (name.Contains("BA") || name.Contains("Cell")) ProcessHitsRoot(vol);
200  else ProcessHitsFast(vol);
201 
202  // if (gMC->IsTrackEntering() || gMC->IsNewTrack() )
203  return kTRUE;
204 }
205 
206 // ----- Public method ProcessHitsFast --------------------------------------
208 {
209  if (gMC->TrackCharge()==0) return kTRUE; // skip neutrals
210 
211  TString name = vol->GetName();
212 
213  if (gMC->IsTrackEntering() || gMC->IsNewTrack() )
214  {
215  fPos_In.SetXYZM(0.,0.,0.,0.);
216  fMom_In.SetXYZM(0.,0.,0.,0.);
217  gMC->TrackPosition(fPos_In);
218  gMC->TrackMomentum(fMom_In);
219  fTrkIn = gMC->GetStack()->GetCurrentTrackNumber();
220  fTime = gMC->TrackTime()*1e9;
221  }; // end entering
222 
223  fELoss += gMC->Edep();
224 
225  if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() )
226  {
227  Int_t TrNo=gMC->GetStack()->GetCurrentTrackNumber();
228  //Int_t pdg= gMC->TrackPid(); //[R.K. 01/2017] unused variable?
229  if ( (TrNo == fTrkIn) && (fELoss >0.) )
230  {
231  TLorentzVector lPos, lMom;
232  Int_t iMod;
233  Int_t iOct;
234  Int_t iLayer;
235  Int_t iBox;
236  Int_t iWire;
237  sscanf(name,"MDT%is%il%ib%iw%i", &iMod, &iOct, &iLayer, &iBox, &iWire);
238 
239  Int_t detectorId = PndMdtID::Identifier(iMod, iOct, iLayer, iBox, iWire);
240  gMC->TrackPosition(lPos); // cm
241  gMC->TrackMomentum(lMom); // GeV
242  TClonesArray& clref = *fMdtCollection;
243  Int_t size = fMdtCollection->GetEntriesFast();
244  PndMdtPoint *P= new(clref[size]) PndMdtPoint (TrNo,detectorId, lPos.Vect(), lMom.Vect(), fTime,
245  gMC->TrackLength(), fELoss,
246  fPos_In.Vect(), fMom_In.Vect());
247  if(P) {
249  PndStack* stack = (PndStack*) gMC->GetStack();
250  stack->AddPoint(kMDT);
251  }
252  };
253 
254  ResetParameters();
255  };
256 
257  return kTRUE;
258 }
259 
260 // ----- Public method ProcessHitsRoot --------------------------------------
261 Bool_t PndMdt::ProcessHitsRoot(FairVolume* ) // vol //[R.K.03/2017] unused variable(s)
262 {
263  if (gMC->TrackCharge()==0) return kTRUE; // skip neutrals
264 
265  TString name = gMC->CurrentVolName();
266  TString path = gMC->CurrentVolPath();
267  if (fVerboseLevel) std::cout << "Path: " << path << std::endl;
268 
269  if (gMC->IsTrackEntering() || gMC->IsNewTrack() )
270  {
271  fELoss = 0.;
272  gMC->TrackPosition(fPos_In);
273  gMC->TrackMomentum(fMom_In);
274  fTrkIn = gMC->GetStack()->GetCurrentTrackNumber();
275  fTime = gMC->TrackTime()*1e9;
276  }; // end entering
277 
278  fELoss += gMC->Edep();
279 
280  if (fVerboseLevel) cout << "pdg: " << gMC->TrackPid() << "\teloss: " << fELoss
281  <<", name"<<gMC->ParticleName(gMC->TrackPid())<< endl;
282 
283  if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() )
284  {
285  Int_t TrNo=gMC->GetStack()->GetCurrentTrackNumber();
286  //Int_t pdg= gMC->TrackPid(); //[R.K. 01/2017] unused variable?
287  if ( (TrNo == fTrkIn) && (fELoss >0.) )
288  {
289  TLorentzVector lPos, lMom;
290  Int_t iMod = -1;
291  Int_t iOct;
292  Int_t iLayer;
293  Int_t iBox;
294  Int_t iWire;
295  gMC->CurrentVolID(iWire);
296  gMC->CurrentVolOffID(2,iBox);
297  gMC->CurrentVolOffID(3,iLayer);
298  gMC->CurrentVolOffID(4,iOct);
299  if (path.Contains("Barrel") ) iMod = 1;
300  if (path.Contains("Endcap")) iMod = 2;
301  if (path.Contains("MF")) iMod = 3;
302  if (path.Contains("Forward")) iMod = 4;
303 
304  if (fVerboseLevel) cout << iMod << "\t" << iOct << "\t" << iLayer << "\t" << iBox << "\t" << iWire;
305  Int_t detectorId = PndMdtID::Identifier(iMod, iOct, iLayer, iBox, iWire);
306 
307  if (fVerboseLevel) cout << "\t" << detectorId << endl;
308  gMC->TrackPosition(lPos); // cm
309  gMC->TrackMomentum(lMom); // GeV
310  TClonesArray& clref = *fMdtCollection;
311  Int_t size = fMdtCollection->GetEntriesFast();
312  PndMdtPoint *P= new(clref[size]) PndMdtPoint (TrNo,detectorId, lPos.Vect(), lMom.Vect(), fTime,
313  gMC->TrackLength(), fELoss,
314  fPos_In.Vect(), fMom_In.Vect());
315  if(P){
317  PndStack* stack = (PndStack*) gMC->GetStack();
318  stack->AddPoint(kMDT);
319  }
320  };
321 
322  ResetParameters();
323  };
324 
325  return kTRUE;
326 }
327 
328 // -------------------------------------------------------------------------
330 {
331  if ((name.find("MDT") != std::string::npos) || name.find("GasCell") != std::string::npos)
332  {
333  return kTRUE;
334  }
335 
336  return kFALSE;
337 }
338 
339 // ----------------------------------------------------------------------------
340 
341 TClonesArray* PndMdt::GetCollection(Int_t iColl) const
342 {
343 
344  if(iColl==0) {
345  return fMdtCollection;
346  }else{
347  return NULL;
348  }
349 
350 }
351 Int_t PndMdt::PdgToIndex(Int_t pdg)
352 {
353  Int_t abspdg = abs(pdg);
354  if(abspdg == 11) return 0;
355  else if(abspdg == 211) return 2;
356  else if(abspdg == 13) return 1;
357  else if(abspdg == 2212) return 4;
358  else if(abspdg == 321) return 3;
359  else return 1;
360 }
361 
362 
363 // ----- Public method EndOfEvent -----------------------------------------
365 {
366  if (fVerboseLevel) Print();
367  Reset();
368 }
369 // ----------------------------------------------------------------------------
370 
371 
373 
TString fForward
Definition: PndMdt.h:89
void Initialize()
Definition: PndMdt.cxx:176
TString fBarrel
Definition: PndMdt.h:86
TString fEndcap
Definition: PndMdt.h:87
Int_t i
Definition: run_full.C:25
exit(0)
TClonesArray * fMdtCollection
Definition: PndMdt.h:72
Bool_t ProcessHitsFast(FairVolume *vol)
Definition: PndMdt.cxx:207
bool mdtMFI
Definition: PndMdt.h:84
Bool_t fVerboseLevel
Definition: PndMdt.h:80
TString fMuonFilter
Definition: PndMdt.h:88
void ResetParameters()
Definition: PndMdt.cxx:84
void BeginEvent()
Definition: PndMdt.cxx:189
void PndMdtMFIron()
void Reset()
Definition: PndMdt.cxx:77
void Print() const
Definition: PndMdt.cxx:68
static Int_t Identifier(Int_t iMod, Int_t iOct, Int_t iLayer, Int_t iBox, Int_t iWire)
Definition: PndMdtID.h:10
void AddPoint(DetectorId iDet)
Definition: PndStack.cxx:408
Int_t PdgToIndex(Int_t pdg)
Definition: PndMdt.cxx:351
void PndMdtMagnet()
TLorentzVector fMom_In
Definition: PndMdt.h:77
TLorentzVector fPos_In
Definition: PndMdt.h:76
TString sysFile
int nHits
Definition: RiemannTest.C:16
Cave SetGeometryFileName("pndcave.geo")
PndMdt()
Definition: PndMdt.cxx:33
Bool_t ProcessHits(FairVolume *vol)
Definition: PndMdt.cxx:196
bool mdtCoil
Definition: PndMdt.h:83
void EndOfEvent()
Definition: PndMdt.cxx:364
Float_t fTime
Definition: PndMdt.h:75
TString name
Bool_t ProcessHitsRoot(FairVolume *vol)
Definition: PndMdt.cxx:261
~PndMdt()
Definition: PndMdt.cxx:57
Float_t fELoss
Definition: PndMdt.h:74
GeV c P
Bool_t CheckIfSensitive(std::string name)
Definition: PndMdt.cxx:329
void PndMdtForward()
void ConstructGeometryFast()
Int_t fTrkIn
Definition: PndMdt.h:73
Definition: PndMdt.h:20
ClassImp(PndAnaContFact)
void ConstructGeometry()
Definition: PndMdt.cxx:92
void PndMdtCoil()
Definition: PndMdtCoil.cxx:33
bool mdtMagnet
Definition: PndMdt.h:82
Mvd Initialize()
void PndMdtMuonFilter()
TClonesArray * GetCollection(Int_t iColl) const
Definition: PndMdt.cxx:341