FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutPropHitProducer.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2020 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  ********************************************************************************/
9 
10 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
11 #include "FairMCTrack.h" // for FairMCTrack
12 #include "FairRootManager.h" // for FairRootManager
13 #include "FairTutPropHit.h" // for FairTutPropHit
14 #include "FairTutPropPoint.h" // for FairTutPropPoint
15 
16 #include <TClonesArray.h> // for TClonesArray
17 #include <TDatabasePDG.h> // for TDatabase
18 #include <TRandom.h> // for TRandom, gRandom
19 #include <TVector3.h> // for TVector3
20 
22  : FairTask("FairTutPropHitProducer")
23  , fPointsArrayName("FairTutPropPoint")
24  , fHitsArrayName("FairTutPropHits")
25  , fPointsArray(nullptr)
26  , fTracksArray(nullptr)
27  , fHitsArray(new TClonesArray("FairTutPropHit", 100))
28 {
29  LOG(debug) << "Default Constructor of FairTutPropHitProducer";
30 }
31 
33 {
34  LOG(debug) << "Destructor of FairTutPropHitProducer";
35  fHitsArray->Delete();
36  delete fHitsArray;
37 }
38 
40 {
41  LOG(debug) << "SetParContainers of FairTutPropHitProducer";
42  // Load all necessary parameter containers from the runtime data base
43  /*
44  FairRunAna* ana = FairRunAna::Instance();
45  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
46 
47  <FairTutPropHitProducerDataMember> = (<ClassPointer>*)
48  (rtdb->getContainer("<ContainerName>"));
49  */
50 }
51 
53 {
54  LOG(debug) << "Initilization of FairTutPropHitProducer";
55 
56  // Get a handle from the IO manager
58 
59  // Get a pointer to the previous already existing data level
60  fPointsArray = static_cast<TClonesArray*>(ioman->GetObject(fPointsArrayName.data()));
61  fTracksArray = static_cast<TClonesArray*>(ioman->GetObject("MCTrack"));
62  if (!fPointsArray || !fTracksArray) {
63  LOG(error) << "No InputDataLevelName array!";
64  LOG(error) << "FairTutPropHitProducer will be inactive";
65  return kERROR;
66  }
67 
68  // Create the TClonesArray for the output data and register
69  // it in the IO manager
70  ioman->Register(fHitsArrayName.data(), "TutProp", fHitsArray, kTRUE);
71 
72  // Do whatever else is needed at the initilization stage
73  // Create histograms to be filled
74  // initialize variables
75 
76  return kSUCCESS;
77 }
78 
80 {
81  LOG(debug) << "Reinitilization of FairTutPropHitProducer";
82  return kSUCCESS;
83 }
84 
85 void FairTutPropHitProducer::Exec(Option_t* /*option*/)
86 {
87  LOG(debug) << "Exec of FairTutPropHitProducer";
88 
89  fHitsArray->Delete();
90 
91  // fill the map
92  FairTutPropPoint* point = nullptr;
93  // FairTutPropHit* hit = nullptr;
94  for (int iPoint = 0; iPoint < fPointsArray->GetEntriesFast(); iPoint++) {
95  point = static_cast<FairTutPropPoint*>(fPointsArray->At(iPoint));
96  if (!point) {
97  continue;
98  }
99 
100  TVector3 position;
101  TVector3 momentum;
102  point->Position(position);
103  point->Momentum(momentum);
104 
105  TVector3 dposition;
106  TVector3 dmomentum;
107 
108  // simulate the detector response: smear position with gaussians
109  dposition.SetXYZ(0.05, 0.05, 0.);
110  position.SetXYZ(gRandom->Gaus(position.X(), 0.05), gRandom->Gaus(position.Y(), 0.05), position.Z());
111  dmomentum.SetXYZ(0.05, 0.05, 0.05);
112  momentum.SetXYZ(
113  gRandom->Gaus(momentum.X(), 0.05), gRandom->Gaus(momentum.Y(), 0.05), gRandom->Gaus(momentum.Z(), 0.05));
114  // position.SetXYZ(position.X(), position.Y(), position.Z());
115 
116  FairMCTrack* track = static_cast<FairMCTrack*>(fTracksArray->At(point->GetTrackID()));
117  TDatabasePDG* dbPDG = TDatabasePDG::Instance();
118  TParticlePDG* particle = dbPDG->GetParticle(track->GetPdgCode());
119  double charge = 0;
120  if (particle)
121  charge = particle->Charge();
122 
123  // hit = new ((*fHitsArray)[iPoint]) FairTutPropHit(point->GetDetectorID(), iPoint, position, dposition);
124  new ((*fHitsArray)[iPoint]) FairTutPropHit(point->GetDetectorID(),
125  iPoint,
126  position,
127  dposition,
128  point->GetTrackID(),
129  track->GetPdgCode(),
130  charge,
131  momentum,
132  dmomentum);
133  }
134 }
135 
136 void FairTutPropHitProducer::Finish() { LOG(debug) << "Finish of FairTutPropHitProducer"; }
137 
InitStatus
Definition: FairTask.h:33
void Momentum(TVector3 &mom) const
Definition: FairMCPoint.h:65
virtual void Exec(Option_t *opt)
void Position(TVector3 &pos) const
Definition: FairMCPoint.h:70
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
Int_t GetTrackID() const
event identifier
Definition: FairMCPoint.h:58
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
Int_t GetPdgCode() const
Definition: FairMCTrack.h:73
Int_t GetDetectorID() const
Definition: FairMCPoint.h:66