star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TGeaEvent.cxx
Go to the documentation of this file.
1 #include <boost/regex.hpp>
2 #include <string>
3 #include <set>
4 #include <unordered_map>
5 
6 #include "TGeaEvent.h"
7 
8 #include "TGiant3.h"
9 #include "TError.h"
10 
14 
15 void* TGeaEvent::fgHash2PathMap = nullptr;
16 TGiant3* TGeaEvent::geant3 = nullptr;
17 
18 
20  TObject(),
21  idEvent(-1),
22  nTracks(0),
23  nSteps(0),
24  tracks(new TClonesArray("TGeaTrack")),
25  steps(new TClonesArray("TGeaStep"))
26 {
27  Clear();
28 }
29 
30 
32 {
33  TLorentzVector p, x;
34 
35  if (TGeaEvent::geant3) {
36  TGeaEvent::geant3->TrackMomentum( p );
37  TGeaEvent::geant3->TrackPosition( x );
38  }
39 
40  TClonesArray &TRACKS = *tracks;
41 
42  TGeaTrack *t = new (TRACKS[nTracks++]) TGeaTrack(this);
43 
44  t->eta = p.Eta();
45  t->phi = p.Phi();
46 
47  t->px = p[0];
48  t->py = p[1];
49  t->pz = p[2];
50 
51  t->x = x[0];
52  t->y = x[1];
53  t->z = x[2];
54 
55  if (TGeaEvent::geant3) {
56  t->mass = TGeaEvent::geant3->TrackMass();
57  t->charge = TGeaEvent::geant3->TrackCharge();
58  }
59 
60  // tracks.Add( t );
61  return t;
62 }
63 
64 
65 void TGeaEvent::Clear( const Option_t *opts )
66 {
67  idEvent = -1;
68  nTracks = 0;
69  nSteps = 0;
70  tracks->Clear("C");
71 }
72 
73 
74 std::string TGeaEvent::DecodeHashedPath(size_t hashValue)
75 {
76  if (!fgHash2PathMap) return "";
77 
78  std::unordered_map<size_t, std::string>* hash2PathMap = static_cast<std::unordered_map<size_t, std::string>* >( fgHash2PathMap );
79 
80  auto hash2Path = hash2PathMap->find(hashValue);
81 
82  if (hash2Path != hash2PathMap->end()) {
83  return hash2Path->second;
84  }
85 
86  return "no_match";
87 }
88 
89 
90 TGeaTrack::TGeaTrack(TGeaEvent* parentEvent) : TObject(), mParentEvent(parentEvent), idTruth(-1), eta(0), phi(0), nSteps(0), steps() { Clear(); }
91 
92 
94 {
95  if (!mParentEvent) {
96  Error("TGeaTrack", "Parent event must be defined");
97  return nullptr;
98  }
99 
100  TLorentzVector x;
101  if (TGeaEvent::geant3) {
102  TGeaEvent::geant3->TrackPosition( x );
103  }
104 
105  Int_t &n = mParentEvent->nSteps;
106  TClonesArray &STEPS = *mParentEvent->steps;
107  TGeaStep *s = new (STEPS[n++]) TGeaStep();
108 
109  s->x = x[0];
110  s->y = x[1];
111  s->z = x[2];
112  s->r = x.Perp();
113  s->idStep = n; // ID of tracking step
114  s->idTruth = idTruth;
115  nSteps++; // Why is this not incremented in the track object?
116 
117  steps.Add(s);
118 
119  // LOG_INFO << " New TGeaStep at index: " << n << " nSteps=" << nSteps << endm;
120 
121  return s;
122 }
123 
124 
125 void TGeaTrack::Clear( const Option_t *opts )
126 {
127  idTruth = -1;
128  eta = 0;
129  phi = 0;
130  px = 0; py = 0; pz = 0;
131  x = 0; y = 0; z = 0; mass = 0; charge = 0;
132  nSteps=0;
133  steps.Clear("");
134 }
135 
136 
137 TGeaStep::TGeaStep() : TObject(),
138  idStep(-1),
139  x(0), y(0), z(0), r(0),
140  state(0),
141  dEstep(-1),
142  adEstep(-1),
143  step(-1) ,
144  dens(0),
145  relRadLength(0),
146  volNameHash(0)
147 {
148  Clear();
149 }
150 
151 void TGeaStep::Clear(Option_t *opts)
152 {
153  idStep=-1;
154  x=0; y=0; z=0; dEstep=-1; adEstep=-1; step=-1; state=0;
155 }
156 
157 
158 bool TGeaStep::MatchedVolName(const std::string & pattern) const
159 {
160  std::string volumeNamePath = TGeaEvent::DecodeHashedPath(volNameHash);
161 
162  if (volumeNamePath.empty()) return true;
163 
164  boost::regex r(pattern);
165  bool matched = boost::regex_match(volumeNamePath, r);
166 
167  return matched;
168 }
169 
170 
171 bool TGeaStep::MatchedVolName(const std::set<std::string> & patterns) const
172 {
173  std::string volumeNamePath = TGeaEvent::DecodeHashedPath(volNameHash);
174 
175  if (volumeNamePath.empty() || patterns.empty())
176  return true;
177 
178  if (volumeNamePath == "no_match")
179  return false;
180 
181  std::set<std::string>::const_iterator iPattern = patterns.begin();
182 
183  for( ; iPattern != patterns.end(); ++iPattern )
184  {
185  if ( MatchedVolName(*iPattern) )
186  return true;
187  }
188 
189  return false;
190 }
static std::string DecodeHashedPath(size_t hashValue)
Definition: TGeaEvent.cxx:74
gROOT Clear()
Int_t idEvent
Definition: TGeaEvent.h:27
Float_t dEstep
Definition: TGeaEvent.h:78
Int_t idTruth
Definition: TGeaEvent.h:75
static void * fgHash2PathMap
Definition: TGeaEvent.h:24
TGeaTrack * AddTrack()
Definition: TGeaEvent.cxx:31
ClassImp(AgUStep) extern"C"
Definition: AgUStep.cxx:8
Float_t pz
Definition: TGeaEvent.h:52
Float_t adEstep
Definition: TGeaEvent.h:79
TClonesArray * steps
Definition: TGeaEvent.h:31
void Clear(const Option_t *opts="")
Definition: TGeaEvent.cxx:65
void Clear(const Option_t *opts="")
Definition: TGeaEvent.cxx:125
size_t volNameHash
Definition: TGeaEvent.h:83
TClonesArray * tracks
Definition: TGeaEvent.h:30
Float_t phi
Definition: TGeaEvent.h:50
static TGiant3 * geant3
Pointer to all geant3 structures.
Definition: TGeaEvent.h:25
Float_t z
Definition: TGeaEvent.h:76
Int_t nSteps
Definition: TGeaEvent.h:29
Float_t step
Definition: TGeaEvent.h:80
Int_t nTracks
Definition: TGeaEvent.h:28
Int_t nSteps
Definition: TGeaEvent.h:54
TGeaEvent * mParentEvent
Transient pointer to parent event.
Definition: TGeaEvent.h:47
Float_t py
Definition: TGeaEvent.h:52
Float_t mass
Definition: TGeaEvent.h:53
Float_t eta
Definition: TGeaEvent.h:49
TGeaStep * AddStep()
Definition: TGeaEvent.cxx:93
Int_t idTruth
Definition: TGeaEvent.h:48
TRefArray steps
Definition: TGeaEvent.h:56
Int_t idStep
Definition: TGeaEvent.h:74
Float_t px
Definition: TGeaEvent.h:52
Float_t charge
Definition: TGeaEvent.h:53
bool MatchedVolName(const std::string &pattern) const
Definition: TGeaEvent.cxx:158
Float_t x
Definition: TGeaEvent.h:51
TGeaTrack(TGeaEvent *parentEvent=nullptr)
Definition: TGeaEvent.cxx:90
Float_t y
Definition: TGeaEvent.h:51
Float_t z
Definition: TGeaEvent.h:51
Int_t state
Definition: TGeaEvent.h:77
Float_t x
Definition: TGeaEvent.h:76
Float_t r
Definition: TGeaEvent.h:76
Float_t y
Definition: TGeaEvent.h:76
void Clear(const Option_t *opts="")
Definition: TGeaEvent.cxx:151