KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVGeoDetectorNode.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Fri Apr 26 12:45:15 2013
2 //Author: John Frankland,,,
3 
4 #include "KVGeoDetectorNode.h"
5 #include "KVGeoDNTrajectory.h"
6 #include "KVDetector.h"
7 #include "KVUniqueNameList.h"
8 #include "TList.h"
9 
11 
12 
13 
15 void KVGeoDetectorNode::init()
16 {
17  fInFront = nullptr;
18  fBehind = nullptr;
19  fDetector = nullptr;
20  fTraj = nullptr;
21  fNTrajForwards = -1;
22  fNTrajBackwards = -1;
23  fNTraj = -1;
24  fTrajF = nullptr;
25  fTrajB = nullptr;
26 }
27 
28 
29 
32 
34 {
35  // Fill list with all trajectories going forwards from this node
36 
37  fNTrajForwards = 0;
38  if (GetNTraj()) {
39  TIter next(GetTrajectories());
41  while ((t = (KVGeoDNTrajectory*)next())) {
42  if (!t->EndsAt(this)) {
44  if (!fTrajF) fTrajF = new KVUniqueNameList;
45  fTrajF->Add(t);
46  }
47  }
48  }
49 }
50 
51 
52 
55 
57 {
58  // Fill list with all trajectories going backwards from this node
59 
60  fNTrajBackwards = 0;
61  if (GetNTraj()) {
62  TIter next(GetTrajectories());
64  while ((t = (KVGeoDNTrajectory*)next())) {
65  if (!t->BeginsAt(this)) {
67  if (!fTrajB) fTrajB = new KVUniqueNameList;
68  fTrajB->Add(t);
69  }
70  }
71  }
72 
73 }
74 
75 
76 
79 
81 {
82  // Default constructor
83  init();
84 }
85 
86 
87 
88 
91 
92 KVGeoDetectorNode::KVGeoDetectorNode(const Char_t* name) : KVBase(name, "/FULL/PATH/TO/NODE")
93 {
94  // Named node constructor
95  init();
96 }
97 
98 
99 
102 
104 {
105  // Destructor
108  SafeDelete(fTraj);
110 }
111 
112 
113 
115 
117 {
118  fDetector = d;
119 }
120 
121 
122 
124 
126 {
127  return fDetector;
128 }
129 
130 
131 
134 
136 {
137  // Name of node is same as name of associated detector
138  return (fDetector ? fDetector->GetName() : KVBase::GetName());
139 }
140 
141 
142 
144 
146 {
147  std::cout << "Detector Node " << GetName() << std::endl;
148  if (fInFront) {
149  std::cout << "In front:" << std::endl;
150  fInFront->Print();
151  }
152  if (fBehind) {
153  std::cout << "Behind:" << std::endl;
154  fBehind->Print();
155  }
156  if (fTraj) {
157  std::cout << "Trajectories:" << std::endl;
158  fTraj->R__FOR_EACH(KVGeoDNTrajectory, ls)();
159  }
160 }
161 
162 
163 
165 
167 {
168  if (!fTraj) {
169  fTraj = new KVUniqueNameList;
170  fTraj->SetCleanup();
171  }
172  fTraj->Add(t);
173 }
174 
175 
176 
178 
180 {
181  if (!fInFront) fInFront = new KVUniqueNameList;
182  fInFront->Add(d);
183 }
184 
185 
186 
188 
190 {
191  if (!fBehind) fBehind = new KVUniqueNameList;
192  fBehind->Add(d);
193 }
194 
195 
198 
200 {
201  // return true if this node is directly in front of the detector
202  return (fBehind && fBehind->FindObject(d) != 0);
203 }
204 
205 
208 
210 {
211  // return true if this node is directly behind the detector
212  return (fInFront && fInFront->FindObject(d) != 0);
213 }
214 
215 
216 
220 
222 {
223  // Return list of all trajectories going forwards from this node
224  // Returns 0x0 if there are no forwards trajectories
225 
226  if (fNTrajForwards < 0) const_cast<KVGeoDetectorNode*>(this)->CalculateForwardsTrajectories();
227  return fTrajF;
228 }
229 
230 
231 
235 
237 {
238  // Return list of all trajectories going backwards from this node
239  // Returns 0x0 if there are no backwards trajectories
240 
242  return fTrajB;
243 }
244 
245 
246 
249 
251 {
252  // Returns number of detectors directly in front of this one
253  return (fInFront ? fInFront->GetEntries() : 0);
254 }
255 
256 
257 
260 
262 {
263  // Returns number of detectors directly behind this one
264  return (fBehind ? fBehind->GetEntries() : 0);
265 }
266 
267 
268 
271 
273 {
274  // Returns number of trajectories passing through this node
275  if (fNTraj < 0) {
276  const_cast<KVGeoDetectorNode*>(this)->fNTraj = (fTraj ? fTraj->GetEntries() : 0);
277  }
278  return fNTraj;
279 }
280 
281 
282 
288 
290 {
291  // Returns number of trajectories which go forwards (towards the target)
292  // from this node, i.e. the number of trajectories of which this is not the
293  // end-point node
294  // If not already done, this sets up the list of forwards trajectories
295 
296  if (fNTrajForwards < 0) const_cast<KVGeoDetectorNode*>(this)->CalculateForwardsTrajectories();
297  return fNTrajForwards;
298 }
299 
300 
301 
307 
309 {
310  // Returns number of trajectories which go backwards (away from the target)
311  // from this node, i.e. the number of trajectories of which this is not the
312  // start-point node
313  // If not already done, this sets up the list of backwards trajectories
314 
316  return fNTrajBackwards;
317 }
318 
319 
320 
325 
327 {
328  // Call this method if detector names change after lists are filled
329  // (they are hash lists, if names of objects change, strange behaviour
330  // will occur: you could put the same object in a list twice)
331 
332  if (fInFront) dynamic_cast<KVUniqueNameList*>(fInFront)->Rehash();
333  if (fBehind) dynamic_cast<KVUniqueNameList*>(fBehind)->Rehash();
334 }
335 
336 
337 
342 
344 {
345  // Return pointer to trajectory passing through this node with given title
346  // The title is of the form "DET1/DET2/DET3/" made of the names of the
347  // detectors/nodes on the trajectory
348 
349  return (KVGeoDNTrajectory*)fTraj->FindObjectByTitle(title);
350 }
351 
352 
353 
356 
358 {
359  // Return pointer to trajectory passing through this node with given number
360 
361  return (KVGeoDNTrajectory*)fTraj->FindObjectByNumber(number);
362 }
363 
364 
365 
376 
378 {
379  // Add this node to each trajectory in list
380  // Then continue trajectories for each node in front of this one
381  // If more than one node is in front, a new trajectory is created
382  // and added to the list for each extra node
383  //
384  // N.B. we are building trajectories starting from nodes furthest from
385  // target and moving towards it. Trajectories always go from the stopping
386  // detector towards the target.
387  // Therefore we add each new node to the end of each trajectory.
388 
389  if (!list->GetEntries()) {
390  // no trajectories in list
391  // add new trajectory starting here
392  list->Add(new KVGeoDNTrajectory(this));
393  }
394  else {
395  // add this node to each trajectory in list
396  list->R__FOR_EACH(KVGeoDNTrajectory, AddLast)(this);
397  }
398  // add each trajectory to list of trajectories through this node
399  TIter nextT(list);
400  KVGeoDNTrajectory* traj;
401 
402 
403  // if no nodes in front of this one, stop
404  if (!GetNDetsInFront()) return;
405 
406  nextT.Reset();
407  TList newTrajectories;
408  while ((traj = (KVGeoDNTrajectory*)nextT())) {
409  KVGeoDNTrajectory baseTraj(*traj);
410  // for each trajectory in list
411  // for first node in front of this one, continue existing trajectory
412  // for each subsequent node in front, create new copy of existing trajectory
413  // and continue it
414  TIter nextN(fInFront);
415  KVGeoDetectorNode* node;
416  KVDetector* det;
417  Int_t node_num = 1;
418  while ((det = (KVDetector*)nextN())) {
419  node = det->GetNode();
420  if (node_num == 1) node->BuildTrajectoriesForwards(list);
421  else {
422  KVGeoDNTrajectory* newTraj = new KVGeoDNTrajectory(baseTraj);
423  newTrajectories.Add(newTraj);
424  node->BuildTrajectoriesForwards(&newTrajectories);
425  }
426  node_num++;
427  }
428  }
429  if (newTrajectories.GetEntries()) {
430  list->AddAll(&newTrajectories);
431  }
432 }
433 
434 
int Int_t
unsigned int UInt_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define SafeDelete(p)
#define d(i)
char Char_t
bool Bool_t
const char Option_t
Base class for KaliVeda framework.
Definition: KVBase.h:135
Base class for detector geometry description, interface to energy-loss calculations.
Definition: KVDetector.h:121
KVGeoDetectorNode * GetNode()
Definition: KVDetector.h:285
Path taken by particles through multidetector geometry.
Bool_t EndsAt(const Char_t *node_name) const
Bool_t BeginsAt(const Char_t *node_name) const
Information on relative positions of detectors & particle trajectories.
Bool_t IsInFrontOf(KVDetector *)
return true if this node is directly in front of the detector
void CalculateForwardsTrajectories()
Fill list with all trajectories going forwards from this node.
void BuildTrajectoriesForwards(TSeqCollection *)
void AddTrajectory(KVGeoDNTrajectory *)
void AddInFront(KVDetector *)
KVGeoDetectorNode()
Default constructor.
KVSeqCollection * fTrajB
list of trajectories passing through this node going backwards
const Char_t * GetName() const
Name of node is same as name of associated detector.
KVGeoDNTrajectory * FindTrajectory(const char *title) const
KVSeqCollection * GetTrajectories() const
KVSeqCollection * GetForwardTrajectories() const
KVDetector * fDetector
associated detector
KVDetector * GetDetector() const
Int_t fNTraj
number of trajectories passing through this node
Int_t fNTrajForwards
number of trajectories going forwards from this node
void ls(Option_t *option="") const
Int_t GetNTrajBackwards() const
Int_t fNTrajBackwards
number of trajectories going backwards from this node
KVSeqCollection * fBehind
list of detectors behind
Int_t GetNTraj() const
Returns number of trajectories passing through this node.
KVSeqCollection * GetBackwardTrajectories() const
Int_t GetNDetsBehind() const
Returns number of detectors directly behind this one.
Int_t GetNDetsInFront() const
Returns number of detectors directly in front of this one.
KVSeqCollection * fInFront
list of detectors in front
virtual ~KVGeoDetectorNode()
Destructor.
Int_t GetNTrajForwards() const
void SetDetector(KVDetector *)
void AddBehind(KVDetector *)
KVSeqCollection * fTrajF
list of trajectories passing through this node going forwards
Bool_t IsBehind(KVDetector *)
return true if this node is directly behind the detector
void CalculateBackwardsTrajectories()
Fill list with all trajectories going backwards from this node.
KVSeqCollection * fTraj
list of trajectories passing through this node
KaliVeda extensions to ROOT collection classes.
virtual void SetCleanup(Bool_t enable=kTRUE)
virtual TObject * FindObjectByNumber(UInt_t num) const
virtual TObject * FindObjectByTitle(const Char_t *) const
Will return object with given title (value of TObject::GetTitle() method).
virtual void Add(TObject *obj)
virtual TObject * FindObject(const char *name) const
Optimised list in which named objects can only be placed once.
virtual void Print(Option_t *option, const char *wildcard, Int_t recurse=1) const
virtual void AddAll(const TCollection *col)
virtual Int_t GetEntries() const
void Reset()
virtual void Add(TObject *obj)
virtual const char * GetName() const
virtual void Add(TObject *obj)