FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutPropDet.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "FairTutPropDet.h"
9 
10 #include "FairDetectorList.h" // for DetectorId::kTutDet
11 #include "FairGeoInterface.h" // for FairGeoInterface
12 #include "FairGeoLoader.h" // for FairGeoLoader
13 #include "FairGeoNode.h" // for FairGeoNode
14 #include "FairGeoVolume.h" // for FairGeoVolume
15 #include "FairLogger.h" // for logging
16 #include "FairRootManager.h" // for FairRootManager
17 #include "FairRun.h" // for FairRun
18 #include "FairRuntimeDb.h" // for FairRuntimeDb
19 #include "FairStack.h" // for FairStack
20 #include "FairTutPropGeo.h"
21 #include "FairTutPropGeoPar.h"
22 #include "FairTutPropPoint.h"
23 #include "FairVolume.h" // for FairVolume
24 #include "TClonesArray.h" // for TClonesArray
25 #include "TGeoManager.h"
26 #include "TGeoMatrix.h"
27 #include "TGeoPhysicalNode.h"
28 #include "TList.h" // for TListIter, TList (ptr only)
29 #include "TObjArray.h" // for TObjArray
30 #include "TString.h" // for TString
31 #include "TVirtualMC.h" // for TVirtualMC
32 #include "TVirtualMCStack.h" // for TVirtualMCStack
33 
34 #include <iosfwd> // for ostream
35 #include <iostream>
36 #include <stddef.h> // for NULL
37 using std::cout;
38 using std::endl;
39 
41  : FairTutPropDet("FairTutPropDet", kTRUE)
42 {}
43 
44 FairTutPropDet::FairTutPropDet(const char* name, Bool_t active)
45  : FairDetector(name, active, kTutProp)
46  , fPointsArrayName("FairTutPropPoint")
47  , fTrackID(-1)
48  , fVolumeID(-1)
49  , fPos()
50  , fMom()
51  , fTime(-1.)
52  , fLength(-1.)
53  , fELoss(-1)
54  , fFairTutPropPointCollection(new TClonesArray("FairTutPropPoint"))
55 {}
56 
58 {
59  if (fFairTutPropPointCollection) {
60  fFairTutPropPointCollection->Delete();
61  delete fFairTutPropPointCollection;
62  }
63 }
64 
66 
68 {
69 
71  // Set parameters at entrance of volume. Reset ELoss.
72  if (TVirtualMC::GetMC()->IsTrackEntering()) {
73  fELoss = 0.;
74  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
75  fLength = TVirtualMC::GetMC()->TrackLength();
76  TVirtualMC::GetMC()->TrackPosition(fPos);
77  TVirtualMC::GetMC()->TrackMomentum(fMom);
78  }
79 
80  // Sum energy loss for all steps in the active volume
81  fELoss += TVirtualMC::GetMC()->Edep();
82 
83  // Create FairTutPropPoint at exit of active volume
84  if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
85  || TVirtualMC::GetMC()->IsTrackDisappeared()) {
86  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
87  fVolumeID = vol->getMCid();
88 
89  if (fELoss == 0.) {
90  return kFALSE;
91  }
92 
93  // Taking stationNr from string is almost effortless.
94  {
95  TString detPath = TVirtualMC::GetMC()->CurrentVolPath();
96  detPath.Remove(0, detPath.Last('/') + 1);
97  detPath.Remove(0, detPath.First("Pixel") + 5);
98  Int_t stationNr = detPath.Atoi();
99  fVolumeID = stationNr;
100  }
101 
102  AddHit(fTrackID,
103  fVolumeID,
104  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
105  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
106  fTime,
107  fLength,
108  fELoss);
109 
110  // Increment number of FairTutPropDet points in TParticle
111  FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
112  stack->AddPoint(kTutProp);
113  }
114 
115  return kTRUE;
116 }
117 
118 void FairTutPropDet::EndOfEvent() { fFairTutPropPointCollection->Clear(); }
119 
121 {
122 
130  fPointsArrayName.data(), "FairTutPropDet", fFairTutPropPointCollection, kTRUE);
131 }
132 
133 TClonesArray* FairTutPropDet::GetCollection(Int_t iColl) const
134 {
135  if (iColl == 0) {
136  return fFairTutPropPointCollection;
137  }
138  return NULL;
139 }
140 
141 void FairTutPropDet::Reset() { fFairTutPropPointCollection->Clear(); }
142 
144 {
149  FairTutPropGeo* Geo = new FairTutPropGeo();
150  ConstructASCIIGeometry<FairTutPropGeo, FairTutPropGeoPar>(Geo, "FairTutPropGeoPar");
151 }
152 
154  Int_t detID,
155  TVector3 pos,
156  TVector3 mom,
157  Double_t time,
158  Double_t length,
159  Double_t eLoss)
160 {
161  Int_t size = fFairTutPropPointCollection->GetEntriesFast();
162  return new ((*fFairTutPropPointCollection)[size]) FairTutPropPoint(trackID, detID, pos, mom, time, length, eLoss);
163 }
164 
virtual void Initialize()
virtual void Register()
virtual ~FairTutPropDet()
virtual void Reset()
virtual TClonesArray * GetCollection(Int_t iColl) const
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void EndOfEvent()
virtual void Initialize()
FairTutPropPoint * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
Int_t getMCid()
Definition: FairVolume.h:57
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void AddPoint(DetectorId iDet)
Definition: FairStack.cxx:344
virtual Bool_t ProcessHits(FairVolume *v=0)