FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutorialDet1.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 "FairTutorialDet1.h"
9 
10 #include "FairDetectorList.h" // for DetectorId::kTutDet
11 #include "FairLogger.h" // for logging
12 #include "FairRootManager.h" // for FairRootManager
13 #include "FairStack.h" // for FairStack
14 #include "FairTutorialDet1Geo.h" // for FairTutorialDet1Geo
15 #include "FairTutorialDet1GeoPar.h" // for FairTutorialDet1GeoPar
16 #include "FairTutorialDet1Point.h" // for FairTutorialDet1Point
17 #include "FairVolume.h" // for FairVolume
18 
19 #include <TClonesArray.h> // for TClonesArray
20 #include <TVirtualMC.h> // for TVirtualMC
21 #include <TVirtualMCStack.h> // for TVirtualMCStack
22 
23 FairTutorialDet1Geo* FairTutorialDet1::fgGeo = nullptr;
24 
26  : FairDetector("TutorialDet", kTRUE, kTutDet)
27  , fTrackID(-1)
28  , fVolumeID(-1)
29  , fPos()
30  , fMom()
31  , fTime(-1.)
32  , fLength(-1.)
33  , fELoss(-1)
34  , fFairTutorialDet1PointCollection(new TClonesArray("FairTutorialDet1Point"))
35 {}
36 
37 FairTutorialDet1::FairTutorialDet1(const char* name, Bool_t active)
38  : FairDetector(name, active, kTutDet)
39  , fTrackID(-1)
40  , fVolumeID(-1)
41  , fPos()
42  , fMom()
43  , fTime(-1.)
44  , fLength(-1.)
45  , fELoss(-1)
46  , fFairTutorialDet1PointCollection(new TClonesArray("FairTutorialDet1Point"))
47 {}
48 
50  : FairDetector(rhs)
51  , fTrackID(-1)
52  , fVolumeID(-1)
53  , fPos()
54  , fMom()
55  , fTime(-1.)
56  , fLength(-1.)
57  , fELoss(-1)
58  , fFairTutorialDet1PointCollection(new TClonesArray("FairTutorialDet1Point"))
59 {}
60 
62 {
63  if (fFairTutorialDet1PointCollection) {
64  fFairTutorialDet1PointCollection->Delete();
65  delete fFairTutorialDet1PointCollection;
66  }
67 }
68 
70 {
72  /*
73  FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
74  FairTutorialDet1GeoPar* par=(FairTutorialDet1GeoPar*)(rtdb->getContainer("FairTutorialDet1GeoPar"));
75 */
76 }
77 
79 {
82  LOG(debug) << "In FairTutorialDet1::ProcessHits";
83  // Set parameters at entrance of volume. Reset ELoss.
84  if (TVirtualMC::GetMC()->IsTrackEntering()) {
85  fELoss = 0.;
86  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
87  fLength = TVirtualMC::GetMC()->TrackLength();
88  TVirtualMC::GetMC()->TrackPosition(fPos);
89  TVirtualMC::GetMC()->TrackMomentum(fMom);
90  }
91 
92  // Sum energy loss for all steps in the active volume
93  fELoss += TVirtualMC::GetMC()->Edep();
94 
95  // Create FairTutorialDet1Point at exit of active volume
96  if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
97  || TVirtualMC::GetMC()->IsTrackDisappeared()) {
98  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
99  fVolumeID = vol->getMCid();
100  if (fELoss == 0.) {
101  return kFALSE;
102  }
103  AddHit(fTrackID,
104  fVolumeID,
105  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
106  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
107  fTime,
108  fLength,
109  fELoss);
110 
111  // Increment number of tutorial det points in TParticle
112  FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
113  stack->AddPoint(kTutDet);
114  }
115 
116  return kTRUE;
117 }
118 
119 void FairTutorialDet1::EndOfEvent() { fFairTutorialDet1PointCollection->Clear(); }
120 
122 {
129  FairRootManager::Instance()->Register("TutorialDetPoint", "TutorialDet", fFairTutorialDet1PointCollection, kTRUE);
130 }
131 
132 TClonesArray* FairTutorialDet1::GetCollection(Int_t iColl) const
133 {
134  if (iColl == 0) {
135  return fFairTutorialDet1PointCollection;
136  } else {
137  return nullptr;
138  }
139 }
140 
141 void FairTutorialDet1::Reset() { fFairTutorialDet1PointCollection->Clear(); }
142 
143 Bool_t FairTutorialDet1::IsSensitive(const std::string& name)
144 {
145  if (name.find("tutdet") != std::string::npos) {
146  return kTRUE;
147  }
148  return kFALSE;
149 }
150 
152 {
157  ConstructASCIIGeometry<FairTutorialDet1Geo, FairTutorialDet1GeoPar>(fgGeo, "FairTutorialDet1GeoPar");
158 }
159 
161  Int_t detID,
162  TVector3 pos,
163  TVector3 mom,
164  Double_t time,
165  Double_t length,
166  Double_t eLoss)
167 {
168  TClonesArray& clref = *fFairTutorialDet1PointCollection;
169  Int_t size = clref.GetEntriesFast();
170  return new (clref[size]) FairTutorialDet1Point(trackID, detID, pos, mom, time, length, eLoss);
171 }
172 
174 
virtual void see Tutorial4 for examples LOG(warn)<< "This function is deprecated. Use FairAlignmentHandler instead
virtual void Initialize()
virtual TClonesArray * GetCollection(Int_t iColl) const
virtual FairModule * CloneModule() const
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void Initialize()
Int_t getMCid()
Definition: FairVolume.h:57
virtual Bool_t ProcessHits(FairVolume *v=0)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
FairTutorialDet1Point * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
virtual void EndOfEvent()
virtual void Register()
void AddPoint(DetectorId iDet)
Definition: FairStack.cxx:344
virtual Bool_t IsSensitive(const std::string &name)
virtual void Reset()
virtual ~FairTutorialDet1()