FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutorialDet2.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 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 "FairTutorialDet2.h"
9 
10 #include "FairDetectorList.h"
11 #include "FairRootManager.h"
12 #include "FairStack.h"
13 #include "FairTutorialDet2Geo.h"
14 #include "FairTutorialDet2GeoPar.h"
15 #include "FairTutorialDet2Point.h"
16 #include "FairVolume.h"
17 
18 #include <TClonesArray.h>
19 #include <TVirtualMC.h>
20 #include <TVirtualMCStack.h>
21 
22 #ifdef NDEBUG
23 #undef NDEBUG
24 #endif
25 
26 FairTutorialDet2Geo* FairTutorialDet2::fgGeo;
27 
29  : FairDetector("TutorialDet", kTRUE, kTutDet)
30  , fTrackID(-1)
31  , fVolumeID(-1)
32  , fPos()
33  , fMom()
34  , fTime(-1.)
35  , fLength(-1.)
36  , fELoss(-1)
37  , fFairTutorialDet2PointCollection(new TClonesArray("FairTutorialDet2Point"))
38  , fCustomData(new Det2PointContainer())
39 {}
40 
41 FairTutorialDet2::FairTutorialDet2(const char* name, Bool_t active)
42  : FairDetector(name, active, kTutDet)
43  , fTrackID(-1)
44  , fVolumeID(-1)
45  , fPos()
46  , fMom()
47  , fTime(-1.)
48  , fLength(-1.)
49  , fELoss(-1)
50  , fFairTutorialDet2PointCollection(new TClonesArray("FairTutorialDet2Point"))
51  , fCustomData(new Det2PointContainer())
52 {}
53 
55  : FairDetector(rhs)
56  , fTrackID(-1)
57  , fVolumeID(-1)
58  , fPos()
59  , fMom()
60  , fTime(-1.)
61  , fLength(-1.)
62  , fELoss(-1)
63  , fFairTutorialDet2PointCollection(new TClonesArray("FairTutorialDet2Point"))
64  , fCustomData(new Det2PointContainer())
65 {}
66 
68 {
69  if (fFairTutorialDet2PointCollection) {
70  fFairTutorialDet2PointCollection->Delete();
71  delete fFairTutorialDet2PointCollection;
72  }
73 }
74 
76 {
78  /*
79  FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
80  FairTutorialDet2GeoPar* par=(FairTutorialDet2GeoPar*)(rtdb->getContainer("FairTutorialDet2GeoPar"));
81 */
82 }
83 
85 {
88  // Set parameters at entrance of volume. Reset ELoss.
89  if (TVirtualMC::GetMC()->IsTrackEntering()) {
90  fELoss = 0.;
91  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
92  fLength = TVirtualMC::GetMC()->TrackLength();
93  TVirtualMC::GetMC()->TrackPosition(fPos);
94  TVirtualMC::GetMC()->TrackMomentum(fMom);
95  }
96 
97  // Sum energy loss for all steps in the active volume
98  fELoss += TVirtualMC::GetMC()->Edep();
99 
100  // Create FairTutorialDet2Point at exit of active volume
101  if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
102  || TVirtualMC::GetMC()->IsTrackDisappeared()) {
103  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
104  fVolumeID = vol->getMCid();
105  if (fELoss == 0.) {
106  return kFALSE;
107  }
108  AddHit(fTrackID,
109  fVolumeID,
110  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
111  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
112  fTime,
113  fLength,
114  fELoss);
115 
116  // Increment number of tutorial det points in TParticle
117  FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
118  stack->AddPoint(kTutDet);
119  }
120 
121  return kTRUE;
122 }
123 
125 
127 {
133  auto mgr = FairRootManager::Instance();
134 
135  mgr->Register("TutorialDetPoint", "TutorialDet", fFairTutorialDet2PointCollection, kTRUE);
136 
137  // example how to register any type T
138  mgr->RegisterAny("TutorialCustomData", fCustomData, kTRUE);
139 }
140 
141 TClonesArray* FairTutorialDet2::GetCollection(Int_t iColl) const
142 {
143  if (iColl == 0) {
144  return fFairTutorialDet2PointCollection;
145  } else {
146  return nullptr;
147  }
148 }
149 
151 {
152  fFairTutorialDet2PointCollection->Clear();
153  fCustomData->clear();
154 }
155 
157 {
162  ConstructASCIIGeometry<FairTutorialDet2Geo, FairTutorialDet2GeoPar>(fgGeo, "FairTutorialDet2GeoPar");
163 }
164 
166  Int_t detID,
167  TVector3 pos,
168  TVector3 mom,
169  Double_t time,
170  Double_t length,
171  Double_t eLoss)
172 {
173  TClonesArray& clref = *fFairTutorialDet2PointCollection;
174  Int_t size = clref.GetEntriesFast();
175 
176  // fill this with some (meaningless) data
177  fCustomData->emplace_back(pos.X(), size);
178 
179  return new (clref[size]) FairTutorialDet2Point(trackID, detID, pos, mom, time, length, eLoss);
180 }
181 
183 
virtual void Register()
virtual FairModule * CloneModule() const
static FairRootManager * Instance()
virtual ~FairTutorialDet2()
virtual void EndOfEvent()
ClassImp(FairEventBuilder)
virtual void Initialize()
Int_t getMCid()
Definition: FairVolume.h:57
virtual TClonesArray * GetCollection(Int_t iColl) const
FairTutorialDet2Point * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
virtual void Reset()
void AddPoint(DetectorId iDet)
Definition: FairStack.cxx:344
virtual Bool_t ProcessHits(FairVolume *v=0)
virtual void Initialize()