KaliVeda
Toolkit for HIC analysis
KVGeoDNTrajectory.h
1 #ifndef __KVGEODNTRAJECTORY_H
2 #define __KVGEODNTRAJECTORY_H
3 
4 #include "KVBase.h"
5 #include "KVUniqueNameList.h"
6 #include "TObjArray.h"
7 #include "KVGeoDetectorNode.h"
8 
42 
72 
77 class KVGeoDNTrajectory : public KVBase {
78 
79  friend class KVGroup;
80 
81  static KVGeoDNTrajectory* Factory(const char* plugin, const KVGeoDNTrajectory*, const KVGeoDetectorNode*);
82 
83  void init();
84 
87  mutable Int_t fIter_idx;
88  mutable Int_t fIter_limit;
89  mutable Int_t fIter_delta;
95 
96  void rebuild_title();
97 
98  void increment_identified_particle_counters(int identified, int unidentified) const;
99 
100 protected:
102 
103 public:
107  virtual ~KVGeoDNTrajectory();
108  void Copy(TObject& obj) const override;
110 
111  void Clear(Option_t* = "") override;
112 
113  void SetAddToNodes(Bool_t yes = kTRUE)
114  {
115  fAddToNodes = yes;
116  }
117 
118  KVGeoDetectorNode* GetNode(const Char_t* name) const
119  {
122  }
124  {
126  if (Contains(n) && !EndsAt(n)) {
127  return GetNodeAt(Index(n) + 1);
128  }
129  return nullptr;
130  }
131  Bool_t Contains(const Char_t* name) const
132  {
135  return GetNode(name) != nullptr;
136  }
137 
138  Int_t GetN() const
139  {
141  return fNodes.GetEntries();
142  }
143  Int_t Index(const TObject* node) const
144  {
146  return fNodes.IndexOf(node);
147  }
148 
150  {
152  fNodes.AddLast(n);
153  if (fAddToNodes) n->AddTrajectory(this);
154  rebuild_title();
155  }
156 
157  void ReverseOrder();
158  void AddToNodes();
159 
160  void ls(Option_t* = "") const override
161  {
162  std::cout << GetTrajectoryName() << " : " << GetPathString() << std::endl;
163  }
164 
165  Bool_t EndsAt(const Char_t* node_name) const
166  {
169 
170  return !strcmp(node_name, fNodes.Last()->GetName());
171  }
172 
173  Bool_t BeginsAt(const Char_t* node_name) const
174  {
177 
178  return !strcmp(node_name, fNodes.First()->GetName());
179  }
180 
182  {
185 
186  return (d == (KVGeoDetectorNode*)fNodes.Last());
187  }
188 
190  {
193 
194  return (d == (KVGeoDetectorNode*)fNodes.First());
195  }
196 
198  {
199  return (fNodes.FindObject(n) != NULL);
200  }
202  {
205  TIter next(l);
206  TObject* o;
207  while ((o = next())) {
208  if (!Contains(o->GetName())) return kFALSE;
209  }
210  return kTRUE;
211  }
213  {
216  TIter next(l);
217  TObject* o;
218  while ((o = next())) {
219  if (Contains(o->GetName())) return kTRUE;
220  }
221  return kFALSE;
222  }
223 
225  {
229  return (KVGeoDetectorNode*)fNodes[i];
230  }
231 
232  void SaveIterationState() const
233  {
240  }
242  {
244 
248  }
249  void IterateFrom(const KVGeoDetectorNode* node0 = nullptr) const
250  {
257 
258  fIter_idx = (node0 == nullptr ? 0 : Index(node0));
259  fIter_delta = 1;
260  fIter_limit = GetN() - 1;
261  }
262  void IterateBackFrom(const KVGeoDetectorNode* node0 = nullptr) const
263  {
270 
271  fIter_idx = (node0 == nullptr ? GetN() - 1 : Index(node0));
272  fIter_delta = -1;
273  fIter_limit = 0;
274  }
275 
277  {
280 
281  if (fIter_idx > -1) {
282  if (fIter_delta * (fIter_limit - fIter_idx) > 0) {
283  Int_t idx = fIter_idx;
285  return GetNodeAt(idx);
286  }
287  else {
289  fIter_idx = -1;
290  return GetNodeAt(fIter_limit);
291  }
292  }
293  return nullptr;
294  }
295 
297  {
299  return &fIDTelescopes;
300  }
302  {
304  return &fIDTelescopes;
305  }
307  {
308  return fIDTelescopes.GetEntries();
309  }
311  {
318  return (other ? GetPathString().Contains(other->GetPathString()) : kFALSE);
319  }
321  {
328 
329  if (!other) return kFALSE;
330 
331  auto other_path = other->GetPathString();
332  other_path.Begin("/");
333  auto this_path = GetPathString();
334  auto last_index = this_path.Index(other_path.Next());
335  if (last_index < 0) return kFALSE;
336  decltype(last_index) index;
337  while (!other_path.End()) {
338  if ((index = this_path.Index(other_path.Next())) < last_index)
339  return kFALSE;
340  last_index = index;
341  }
342  return kTRUE;
343  }
345  {
347  if (fPathInTitle) return GetTitle();
348  return GetName();
349  }
350  const Char_t* GetTrajectoryName() const
351  {
353  if (fPathInTitle) return GetName();
354  return GetTitle();
355  }
356  void SetPathInTitle(Bool_t intitle = kTRUE)
357  {
362 
363  if (intitle != fPathInTitle) {
364  TString s = GetName();
365  SetName(GetTitle());
366  SetTitle(s);
367  fPathInTitle = intitle;
368  }
369  }
371  {
373  return fPathInTitle;
374  }
375  void AddIdentifiedParticle(int modify_unidentified = -1) const
376  {
378  increment_identified_particle_counters(1, modify_unidentified);
379  }
380  void AddUnidentifiedParticle(int modify_identified = -1) const
381  {
383  increment_identified_particle_counters(modify_identified, 1);
384  }
385 
386  ClassDefOverride(KVGeoDNTrajectory, 1) //Path taken by particles through multidetector geometry
387 };
388 
389 #endif
int Int_t
#define d(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
#define ClassDefOverride(name, id)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Base class for KaliVeda framework.
Definition: KVBase.h:139
Path taken by particles through multidetector geometry.
void SaveIterationState() const
Bool_t ContainsAll(const TCollection *l) const
void ls(Option_t *="") const override
Bool_t fAddToNodes
if kTRUE, add trajectory to node's list
const Char_t * GetTrajectoryName() const
KVGeoDNTrajectory()
Default constructor.
Int_t fIter_delta_sav
increment/decrement for each iteration
KVGeoDetectorNode * GetNextNode() const
KVSeqCollection * AccessIDTelescopeList()
Bool_t EndsAt(const Char_t *node_name) const
static Int_t fGDNTrajNumber
KVString GetPathString() const
Int_t Index(const TObject *node) const
void AddUnidentifiedParticle(int modify_identified=-1) const
Bool_t Contains(const Char_t *name) const
void Clear(Option_t *="") override
Clear list of nodes in trajectory.
void increment_identified_particle_counters(int identified, int unidentified) const
increment counters in all detectors on trajectory
static KVGeoDNTrajectory * Factory(const char *plugin, const KVGeoDNTrajectory *, const KVGeoDetectorNode *)
Instantiate & return object of class corresponding to plugin.
void SetPathInTitle(Bool_t intitle=kTRUE)
Int_t fIter_delta
increment/decrement for each iteration
Bool_t Contains(const KVGeoDetectorNode *n) const
Bool_t BeginsAt(const KVGeoDetectorNode *d) const
void ReverseOrder()
Reverse the order of the nodes in the trajectory.
void AddLast(KVGeoDetectorNode *n)
void AddToNodes()
Add reference to this trajectory to all nodes on it.
Bool_t EndsAt(const KVGeoDetectorNode *d) const
void IterateFrom(const KVGeoDetectorNode *node0=nullptr) const
Int_t GetNumberOfIdentifications() const
Bool_t ContainsTrajectory(const KVGeoDNTrajectory *other) const
void Copy(TObject &obj) const override
void AddIdentifiedParticle(int modify_unidentified=-1) const
Bool_t BeginsAt(const Char_t *node_name) const
const KVSeqCollection * GetIDTelescopes() const
Int_t fIter_limit
last index for iteration
Bool_t ContainsAny(const TCollection *l) const
KVUniqueNameList fIDTelescopes
list of id telescopes on this trajectory
Int_t fIter_limit_sav
last index for iteration
Int_t fIter_idx_sav
index for iteration
Int_t fIter_idx
index for iteration
KVGeoDetectorNode * GetNodeInFront(const KVGeoDetectorNode *n) const
Bool_t ContainsPath(const KVGeoDNTrajectory *other) const
TObjArray fNodes
list of nodes on trajectory
void IterateBackFrom(const KVGeoDetectorNode *node0=nullptr) const
virtual ~KVGeoDNTrajectory()
Destructor.
void RestoreIterationState() const
Bool_t IsPathInTitle() const
Bool_t fPathInTitle
true if path is in title, false if path is in name
KVGeoDetectorNode * GetNode(const Char_t *name) const
KVGeoDNTrajectory & operator=(const KVGeoDNTrajectory &)
void SetAddToNodes(Bool_t yes=kTRUE)
KVGeoDetectorNode * GetNodeAt(Int_t i) const
Information on relative positions of detectors & particle trajectories.
Group of detectors which can be treated independently of all others in array.
Definition: KVGroup.h:19
KaliVeda extensions to ROOT collection classes.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Optimised list in which named objects can only be placed once.
virtual Int_t GetEntries() const
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
virtual void SetName(const char *name)
Int_t IndexOf(const TObject *obj) const override
TObject * Last() const override
Int_t GetEntries() const override
void AddLast(TObject *obj) override
TObject * First() const override
TObject * FindObject(const char *name) const override
virtual const char * GetName() const
const Int_t n
TLine l