FairRoot/PandaRoot
PndStt.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndStt source file -----
3 // -------------------------------------------------------------------------
4 
5 #include "PndStt.h"
6 
7 #include "PndGeoSttPar.h"
8 #include "PndGeoStt.h"
9 #include "PndSttPoint.h"
10 #include "PndDetectorList.h"
11 #include "PndStack.h"
12 #include "PndSttMapCreator.h"
13 #include "PndGeoHandling.h"
14 
15 #include "FairRun.h"
16 #include "FairGeoInterface.h"
17 #include "FairGeoLoader.h"
18 #include "FairGeoNode.h"
19 #include "FairGeoRootBuilder.h"
20 #include "FairRootManager.h"
21 #include "FairRuntimeDb.h"
22 #include "FairVolume.h"
23 
24 #include "TClonesArray.h"
25 #include "TLorentzVector.h"
26 #include "TParticle.h"
27 #include "TVirtualMC.h"
28 #include "TGeoMatrix.h"
29 #include "TObjArray.h"
30 #include "TGeoTube.h"
31 #include "TGeoMedium.h"
32 #include "TGeoVolume.h"
33 
34 #include <iostream>
35 #include <math.h>
36 
37 using std::cout;
38 using std::endl;
39 using std::string;
40 
41 // TODO: read this from geant initialization
42 #define innerStrawDiameter 1.
43 //#define redefineLambdaChargedDecay 0
44 
45 // ----- Default constructor -------------------------------------------
47 : fTrackID(0), fVolumeID(0), fPosInLocal(0,0,0), fPosOutLocal(0,0,0),
48  fMomIn(0,0,0), fMomOut(0,0,0), fTime(0), fLength(0), fELoss(0), fMass(0), fIsInitialized(kFALSE), fPosIndex(0),
49  fSttCollection(0), fpostot(0,0,0), fpostotin(0,0,0), fpostotout(0,0,0), fPassNodes(new TObjArray()), fGeoType(0), fInFlag(0)
50 {
51  fSttCollection = new TClonesArray("PndSttPoint");
52  fVerboseLevel = 0;
53 }
54 // -------------------------------------------------------------------------
55 
56 
57 
58 // ----- Standard constructor ------------------------------------------
59 PndStt::PndStt(const char* name, Bool_t active)
60  : FairDetector(name, active),
61  fTrackID(0), fVolumeID(0), fPosInLocal(0,0,0), fPosOutLocal(0,0,0),
62  fMomIn(0,0,0), fMomOut(0,0,0), fTime(0), fLength(0), fELoss(0), fMass(0), fIsInitialized(kFALSE), fPosIndex(0),
63  fSttCollection(0), fpostot(0,0,0), fpostotin(0,0,0), fpostotout(0,0,0), fPassNodes(new TObjArray()), fGeoType(0), fInFlag(0)
64 {
65  fSttCollection = new TClonesArray("PndSttPoint");
66  fVerboseLevel = 0;
67 }
68 // -------------------------------------------------------------------------
69 
70 
71 
72 
73 // ----- Destructor ----------------------------------------------------
75 {
76  if (fSttCollection)
77  {
78  fSttCollection->Delete();
79  delete fSttCollection;
80  }
81 }
82 // -------------------------------------------------------------------------
83 
84 
85 
87 {
88  std::cout << "-I- Initializing PndStt()" << std::endl;
89 
91  if(0==gGeoManager){
92  std::cout << " -E- No gGeoManager in PndStt::Initialize()! aborting" << std::endl;
93  abort();
94  }
95 }
96 
97 // ----- Private method GetSquaredDistanceFromWire -----------------------
99 {
100  TLorentzVector
101  entryPosition;
102 
103  float
104  positionInMother[3],
105  positionInStraw[3];
106 
107  gMC->TrackPosition(entryPosition);
108  positionInMother[0] = entryPosition.X();
109  positionInMother[1] = entryPosition.Y();
110  positionInMother[2] = entryPosition.Z();
111  gMC->Gmtod(positionInMother, positionInStraw, 1);
112 
113  return positionInStraw[0] * positionInStraw[0] +
114  positionInStraw[1] * positionInStraw[1];
115 }
116 // -------------------------------------------------------------------------
117 
118 bool PndStt::Split(string &aDest, string &aSrc, char aDelim)
119 {
120  if(aSrc.empty())
121  return false;
122 
123  string::size_type
124  pos = aSrc.find(aDelim);
125 
126  aDest = aSrc.substr(0, pos);
127 
128  if(pos != string::npos)
129  aSrc = aSrc.substr(pos + 1);
130  else
131  aSrc = "";
132 
133  return true;
134 }
135 
136 string PndStt::GetStringPart(string &aSrc, Int_t part, char aDelim)
137 {
138  string
139  retval = "",
140  sub;
141 
142  int
143  counter = 0;
144 
145  while(Split(sub, aSrc, aDelim))
146  {
147  if (counter == part)
148  {
149  retval = sub;
150  break;
151  }
152  counter++;
153  }
154 
155  return retval;
156 }
157 
158 // ----- Public method ProcessHits --------------------------------------
159 Bool_t PndStt::ProcessHits(FairVolume* vol)
160 {
161  //new>>>>>>>>>>>>>>>>>>
162 
163  TString vol_name(gMC->CurrentVolName());
164  TGeoHMatrix M;
165  gMC->GetTransformation(gMC->CurrentVolPath(), M);
166  TString name(gMC->CurrentVolName());
167  //Bool_t skew = kFALSE; //[R.K. 01/2017] Unused variable.
168  //if(name.Contains("skew")) skew = kTRUE; //[R.K. 01/2017] Unused variable.
169  //new>>>>>>>>>>>>>>>>>>
170 
171 // TGeoMedium *medium = (TGeoMedium*) vol->getGeoNode()->getRootVolume()->GetMedium();
172 // Double_t epsil = medium->GetParam(6);
173 
174  Double_t globalPos[3] = { 0., 0., 0.};
175  Double_t localPos[3] = { 0., 0., 0. };
176  TLorentzVector mom;
177 
178  if (gMC->TrackCharge() != 0.)
179  {
180  if ( gMC->IsTrackEntering()) //not sure why this was here: && fabs(sqrt(GetSquaredDistanceFromWire()) - (innerStrawDiameter / 2.)) < epsil)
181  {
182  fInFlag = kTRUE;
183  // Set parameters at entrance of volume. Reset ELoss.
184  fELoss = 0.;
185  fTime = gMC->TrackTime() * 1.0e09;
186  fLength = gMC->TrackLength();
187  gMC->TrackPosition(globalPos[0], globalPos[1], globalPos[2]);
188  gMC->TrackMomentum(mom);
189 
190  fpostotin.SetXYZ(globalPos[0], globalPos[1], globalPos[2]);
191  fMomIn.SetXYZ(mom.X(), mom.Y(), mom.Z());
192 
193  gMC->Gmtod(globalPos, localPos, 1);
194  fPosInLocal.SetXYZ(localPos[0], localPos[1], localPos[2]);
195  }
196 
197  // Sum energy loss for all steps in the active volume
198  fELoss += gMC->Edep();
199 
200  // Create PndSttPoint at exit of active volume -- but not into the wire -- with eloss in the tube (to make it work with TGeant4)
201  if ( (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared())
202  && fInFlag == kTRUE // not sure why this was here: fabs(sqrt(GetSquaredDistanceFromWire()) - (innerStrawDiameter / 2.)) < epsil
203  && fELoss != 0)
204  {
205  fInFlag = kFALSE;
206  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
207  fVolumeID = kSTT; // vol->getMCid();
208  fMass = gMC->TrackMass(); // mass (GeV)
209  gMC->TrackPosition(globalPos[0], globalPos[1], globalPos[2]);
210  gMC->TrackMomentum(mom);
211 
212  fpostotout.SetXYZ(globalPos[0], globalPos[1], globalPos[2]);
213  fMomOut.SetXYZ(mom.X(), mom.Y(), mom.Z());
214 
215  gMC->Gmtod(globalPos, localPos, 1);
216  fPosOutLocal.SetXYZ(localPos[0], localPos[1], localPos[2]);
217 
218 
219  fpostot.SetXYZ((fpostotin.X() + fpostotout.X()) / 2., (fpostotin.Y() + fpostotout.Y()) / 2.,
220  (fpostotin.Z() + fpostotout.Z()) / 2.); // CHECK (delete this?)
221 
222  Int_t tubeID = -1;
223 
224  // CHECK -----------------------------------------------------------
225  if (fGeoType == 1){
226  PndSttMapCreator mapper(fGeoType);
227  tubeID = mapper.GetTubeIDFromPath(gMC->CurrentVolPath());
228  } else if (fGeoType == 2) {
229  tubeID = PndGeoHandling::Instance()->GetShortID(gMC->CurrentVolPath());
230  }
231  // -----------------------------------------------------------------
232 
233 // std::cout << "SttPoint: " << gMC->CurrentVolPath() << std::endl;
234 // std::cout << "PosIn: " << fpostotin.X() << "/" << fpostotin.Y() << "/" << fpostotin.Z() << std::endl;
235 // std::cout << "PosOut: " << fpostotout.X() << "/" << fpostotout.Y() << "/" << fpostotout.Z() << std::endl;
236 // std::cout << "PosToT: " << fpostot.X() << "/" << fpostot.Y() << "/" << fpostot.Z() << std::endl;
237 // std::cout << "PosInLoc: " << fPosInLocal.X() << "/" << fPosInLocal.Y() << "/" << fPosInLocal.Z() << std::endl;
238 // std::cout << "PosOutLoc: " << fPosOutLocal.X() << "/" << fPosOutLocal.Y() << "/" << fPosOutLocal.Z() << std::endl;
239 
240  AddHit(fTrackID, fVolumeID, tubeID, fpostot,
243 
244  // Increment number of stt points for TParticle
245  PndStack* stack = (PndStack*) gMC->GetStack();
246  stack->AddPoint(kSTT);
247  ResetParameters();
248  }
249  }
250 
251  return kTRUE;
252 }
253 // -------------------------------------------------------------------------
254 
255 
256 
257 // ----- Public method EndOfEvent --------------------------------------
259 {
260  if (fVerboseLevel)
261  Print();
262  fSttCollection->Delete();
263  fPosIndex = 0;
264 }
265 // -------------------------------------------------------------------------
266 
267 
268 
269 // ----- Public method Register ----------------------------------------
271 {
272  FairRootManager::Instance()->Register("STTPoint", "Stt", fSttCollection, kTRUE);
273 }
274 // -------------------------------------------------------------------------
275 
276 
277 
278 // ----- Public method GetCollection -----------------------------------
279 TClonesArray* PndStt::GetCollection(Int_t iColl) const
280 {
281  if (iColl == 0)
282  return fSttCollection;
283  else
284  return NULL;
285 }
286 // -------------------------------------------------------------------------
287 
288 
289 
290 // ----- Public method Print -------------------------------------------
291 void PndStt::Print() const
292 {
293  Int_t
294  nHits = fSttCollection->GetEntriesFast();
295 
296  cout << "-I- PndStt: " << nHits << " points registered in this event." << endl;
297 
298  if (fVerboseLevel>1)
299  for (Int_t i=0; i<nHits; i++)
300  (*fSttCollection)[i]->Print();
301 }
302 // -------------------------------------------------------------------------
303 
304 
305 
306 // ----- Public method Reset -------------------------------------------
308 {
309  fSttCollection->Delete();
310  ResetParameters();
311 }
312 // -------------------------------------------------------------------------
313 
314 
315 
316 // ----- Public method CopyClones --------------------------------------
317 void PndStt::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
318 {
319  Int_t
320  nEntries = cl1->GetEntriesFast();
321 
322  cout << "-I- PndStt: " << nEntries << " entries to add." << endl;
323 
324  TClonesArray& clref = *cl2;
325 
327  *oldpoint = NULL;
328  for (Int_t i=0; i<nEntries; i++)
329  {
330  oldpoint = (PndSttPoint*) cl1->At(i);
331 
332  Int_t
333  index = oldpoint->GetTrackID() + offset;
334 
335  oldpoint->SetTrackID(index);
336  new (clref[fPosIndex]) PndSttPoint(*oldpoint);
337  fPosIndex++;
338  }
339  cout << "-I- PndStt: " << cl2->GetEntriesFast() << " merged entries."
340  << endl;
341 }
342 // -------------------------------------------------------------------------
343 
344 
345 
346 // ----- Public method ConstructGeometry -------------------------------
348 {
349  TString fileName = GetGeometryFileName();
350  if (fileName.EndsWith(".root"))
351  {
352  fGeoType = 2;
353  } else if (fileName.Contains("straws_skewed_blocks_35cm_pipe.geo"))
354  {
355  fGeoType = 1;
356  } else
357  {
358  cout << "-E- STT: this geometry is not supported now" << endl;
359  return;
360  }
361 
362  FairRun *fRun = FairRun::Instance();
363  FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
364  PndGeoSttPar* par = (PndGeoSttPar*) (rtdb->getContainer("PndGeoSttPar"));
365  PndSttMapCreator mapper(fGeoType);
366  int tubecounter = 0;
367 
368  if (fGeoType == 2)
369  {
370  // Set what is sensitive before creating geometry
371  if (fListOfSensitives.size() == 0) SetDefaultSensorNames();
372  ConstructRootGeometry();
374  // if(fVerboseLevel>0)
376  // std::cout << "Inside fGeoType 2" << std::endl;
377  tubecounter = mapper.FillSttTubeParametersType2(par);
378 
379  } else if (fGeoType == 1)
380  {
381 
382  FairGeoLoader* geoLoad = FairGeoLoader::Instance();
383  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
384  PndGeoStt* Geo = new PndGeoStt();
385  Geo->setGeomFile(GetGeometryFileName());
386  geoFace->addGeoModule(Geo);
387 
388  Bool_t rc = geoFace->readSet(Geo);
389  if (rc) Geo->create(geoLoad->getGeoBuilder());
390 
391  // store geo parameter with PndSttMapCreator
392  TList* volList = Geo->getListOfVolumes();
393  FairRun *fRun = FairRun::Instance();
394  FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
395  PndGeoSttPar* par = (PndGeoSttPar*) (rtdb->getContainer("PndGeoSttPar"));
396  TListIter iter(volList);
397  // CHECK
398  if (GetGeometryFileName().Contains("straws_skewed_blocks_35cm_pipe.geo"))
399  fGeoType = 1;
400  else
401  cout << "-E- STT: this geometry is not supported now" << endl;
402 
403  PndSttMapCreator mapper(fGeoType);
404  int tubecounter = mapper.FillSttTubeParameters(par, volList);
405  cout << "-I- STT total number of tubes: " << tubecounter << endl;
406  par->setChanged();
407  par->setInputVersion(fRun->GetRunId(), 1);
408 
409  ProcessNodes(volList);
410  }
411  cout << "-I- PndStt::ConstructGeometry : STT total number of tubes: " << tubecounter << endl;
412  par->setChanged();
413  par->setInputVersion(fRun->GetRunId(), 1);
414 
415 }
416 // -------------------------------------------------------------------------
417 
418 
419 
420 
421 // ----- Private method AddHit -----------------------------------------
422 PndSttPoint* PndStt::AddHit(Int_t trackID, Int_t detID, Int_t tubeID,
423  TVector3 pos, TVector3 posInLocal, TVector3 posOutLocal,
424  TVector3 momIn, TVector3 momOut,
425  Double_t time, Double_t length, Double_t eLoss, Double_t mass)
426 {
427  TClonesArray&
428  clref = *fSttCollection;
429 
430  Int_t
431  size = clref.GetEntriesFast();
432 
433  PndSttPoint *pointnew = new(clref[size]) PndSttPoint(trackID, detID, pos, posInLocal, posOutLocal,
434  momIn, momOut, time,
435  length, eLoss, mass);
436  pointnew->SetTubeID(tubeID);
437  return pointnew;
438 }
439 // -------------------------------------------------------------------------
441 {
442  for (UInt_t i = 0; i < fListOfSensitives.size(); i++){
443  if (name.find(fListOfSensitives[i]) != std::string::npos)
444  return true;
445  }
446  return false;
447 }
449  fListOfSensitives.push_back("ArCO2Sensitive");//Root_Test.root
450 
451  if (fVerboseLevel>0) {
452  std::cout<<"- I - PndSTTDetector: fListOfSensitives contains:";
453  for(UInt_t k=0;k<fListOfSensitives.size();k++)
454  std::cout<<"\n\t"<<fListOfSensitives[k];
455  std::cout<<std::endl;
456  }
457 }
458 
459 
460 
462 
TVector3 pos
virtual void Reset()
Definition: PndStt.cxx:307
virtual ~PndStt()
Definition: PndStt.cxx:74
virtual void Register()
Definition: PndStt.cxx:270
Int_t fPosIndex
Definition: PndStt.h:138
Int_t FillSttTubeParametersType2(PndGeoSttPar *par)
Int_t fGeoType
Definition: PndStt.h:147
FairGeoLoader * geoLoad
Int_t i
Definition: run_full.C:25
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: PndStt.cxx:317
virtual void Initialize()
Definition: PndStt.cxx:86
virtual void Print() const
Definition: PndStt.cxx:291
void SetDefaultSensorNames()
Definition: PndStt.cxx:448
Double_t fELoss
length
Definition: PndStt.h:134
void CreateUniqueSensorId(TString startName, std::vector< std::string > listOfSensitives)
Has to be called during simulation to create unique sensor id.
Double_t par[3]
TVector3 fMomOut
momentum
Definition: PndStt.h:131
Double_t mom
Definition: plot_dirc.C:14
TVector3 offset(2, 0, 0)
void ResetParameters()
Definition: PndStt.h:186
Int_t fVolumeID
track index
Definition: PndStt.h:127
TGeoManager * gGeoManager
Int_t FillSttTubeParameters(PndGeoSttPar *par, TList *volList)
void AddPoint(DetectorId iDet)
Definition: PndStack.cxx:408
Int_t GetTubeIDFromPath(TString path)
std::vector< std::string > fListOfSensitives
Definition: PndStt.h:117
FairRunAna * fRun
Definition: hit_dirc.C:58
Double_t fMass
energy loss
Definition: PndStt.h:135
Int_t fTrackID
Definition: PndStt.h:126
void PrintSensorNames()
PndSttPoint * AddHit(Int_t trackID, Int_t detID, Int_t tubeID, TVector3 pos, TVector3 posInLocal, TVector3 posOutLocal, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t mass)
Definition: PndStt.cxx:422
int counter
Definition: ZeeAnalysis.C:59
int nHits
Definition: RiemannTest.C:16
Double_t
TVector3 fpostot
Hit collection.
Definition: PndStt.h:140
virtual void EndOfEvent()
Definition: PndStt.cxx:258
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
bool Split(std::string &aDest, std::string &aSrc, char aDelim)
Definition: PndStt.cxx:118
float GetSquaredDistanceFromWire()
Definition: PndStt.cxx:98
void SetTubeID(Int_t tubeid)
Definition: PndSttPoint.h:76
Double_t fTime
momentum
Definition: PndStt.h:132
TVector3 fPosInLocal
volume id
Definition: PndStt.h:128
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
static PndGeoHandling * Instance()
TString name
bool CheckIfSensitive(std::string name)
Definition: PndStt.cxx:440
TVector3 fpostotout
Definition: PndStt.h:142
TClonesArray * fSttCollection
Definition: PndStt.h:139
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: PndStt.cxx:159
virtual void ConstructGeometry()
Definition: PndStt.cxx:347
TVector3 fpostotin
Definition: PndStt.h:141
PndStt()
Definition: PndStt.cxx:46
Definition: PndStt.h:34
Bool_t fInFlag
Definition: PndStt.h:150
ClassImp(PndAnaContFact)
Double_t fLength
time
Definition: PndStt.h:133
std::string GetStringPart(std::string &aSrc, Int_t part, char aDelim)
Definition: PndStt.cxx:136
TVector3 fMomIn
exit position in straw frame
Definition: PndStt.h:130
TVector3 fPosOutLocal
entry position in straw frame
Definition: PndStt.h:129
FairGeoInterface * geoFace
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: PndStt.cxx:279
Mvd Initialize()