KaliVeda
Toolkit for HIC analysis
KVGeoDetectorNode.cpp
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 "TList.h"
8 
10 
11 
12 
15 void KVGeoDetectorNode::CalculateForwardsTrajectories()
16 {
17  // Fill list with all trajectories going forwards from this node
18 
19  fNTrajForwards = 0;
20  if (GetNTraj()) {
21  TIter next(GetTrajectories());
23  while ((t = (KVGeoDNTrajectory*)next())) {
24  if (!t->EndsAt(this)) {
25  fNTrajForwards++;
26  fTrajF.Add(t);
27  }
28  }
29  }
30 }
31 
32 
33 
36 
38 {
39  // Fill list with all trajectories going backwards from this node
40 
41  fNTrajBackwards = 0;
42  if (GetNTraj()) {
43  TIter next(GetTrajectories());
45  while ((t = (KVGeoDNTrajectory*)next())) {
46  if (!t->BeginsAt(this)) {
48  fTrajB.Add(t);
49  }
50  }
51  }
52 
53 }
54 
55 
56 
58 
59 void KVGeoDetectorNode::SetDetector(KVDetector* d)
60 {
61  fDetector = d;
62 }
63 
64 
65 
67 
68 KVDetector* KVGeoDetectorNode::GetDetector() const
69 {
70  return fDetector;
71 }
72 
73 
74 
77 
79 {
80  // Name of node is same as name of associated detector
81  return (fDetector ? fDetector->GetName() : KVBase::GetName());
82 }
83 
84 
85 
87 
89 {
90  std::cout << "Detector Node " << GetName() << std::endl;
91  if (GetNDetsInFront()) {
92  std::cout << "In front:" << std::endl;
93  fInFront.Print();
94  }
95  if (GetNDetsBehind()) {
96  std::cout << "Behind:" << std::endl;
97  fBehind.Print();
98  }
99  if (GetNTraj()) {
100  std::cout << "Trajectories:" << std::endl;
101  for (auto p : fTraj) dynamic_cast<KVGeoDNTrajectory*>(p)->ls();
102  }
103 }
104 
105 
106 
108 
110 {
111  fTraj.Add(t);
112 }
113 
114 
115 
117 
118 void KVGeoDetectorNode::AddInFront(KVDetector* d)
119 {
120  fInFront.Add(d);
121 }
122 
123 
124 
126 
127 void KVGeoDetectorNode::AddBehind(KVDetector* d)
128 {
129  fBehind.Add(d);
130 }
131 
132 
135 
137 {
138  // return true if this node is directly in front of the detector
139  return fBehind.FindObject(d) != nullptr;
140 }
141 
142 
145 
147 {
148  // return true if this node is directly behind the detector
149  return fInFront.FindObject(d) != nullptr;
150 }
151 
152 
153 
158 
160 {
161  // Call this method if detector names change after lists are filled
162  // (they are hash lists, if names of objects change, strange behaviour
163  // will occur: you could put the same object in a list twice)
164 
166  if (GetNDetsBehind()) fBehind.Rehash();
167 }
168 
169 
170 
175 
177 {
178  // Return pointer to trajectory passing through this node with given title
179  // The title is of the form "DET1/DET2/DET3/" made of the names of the
180  // detectors/nodes on the trajectory
181 
182  return (KVGeoDNTrajectory*)fTraj.FindObjectByTitle(title);
183 }
184 
185 
186 
189 
191 {
192  // Return pointer to trajectory passing through this node with given number
193 
194  return (KVGeoDNTrajectory*)fTraj.FindObjectByNumber(number);
195 }
196 
197 
198 
209 
211 {
212  // Add this node to each trajectory in list
213  // Then continue trajectories for each node in front of this one
214  // If more than one node is in front, a new trajectory is created
215  // and added to the list for each extra node
216  //
217  // N.B. we are building trajectories starting from nodes furthest from
218  // target and moving towards it. Trajectories always go from the stopping
219  // detector towards the target.
220  // Therefore we add each new node to the end of each trajectory.
221 
222  if (!list->GetEntries()) {
223  // no trajectories in list
224  // add new trajectory starting here
225  list->Add(new KVGeoDNTrajectory(this));
226  }
227  else {
228  // add this node to each trajectory in list
229  list->R__FOR_EACH(KVGeoDNTrajectory, AddLast)(this);
230  }
231  // add each trajectory to list of trajectories through this node
232  TIter nextT(list);
233  KVGeoDNTrajectory* traj;
234 
235  // if no nodes in front of this one, stop
236  if (!GetNDetsInFront()) return;
237 
238  nextT.Reset();
239  TList newTrajectories;
240  while ((traj = (KVGeoDNTrajectory*)nextT())) {
241  KVGeoDNTrajectory baseTraj(*traj);
242  // for each trajectory in list
243  // for first node in front of this one, continue existing trajectory
244  // for each subsequent node in front, create new copy of existing trajectory
245  // and continue it
246  TIter nextN(&fInFront);
247  KVGeoDetectorNode* node;
248  KVDetector* det;
249  Int_t node_num = 1;
250  while ((det = (KVDetector*)nextN())) {
251  node = det->GetNode();
252  if (node_num == 1) node->BuildTrajectoriesForwards(list);
253  else {
254  KVGeoDNTrajectory* newTraj = new KVGeoDNTrajectory(baseTraj);
255  newTrajectories.Add(newTraj);
256  node->BuildTrajectoriesForwards(&newTrajectories);
257  }
258  node_num++;
259  }
260  }
261  if (newTrajectories.GetEntries()) {
262  list->AddAll(&newTrajectories);
263  }
264 }
265 
266 
int Int_t
unsigned int UInt_t
#define d(i)
bool Bool_t
char Char_t
const char Option_t
winID h TVirtualViewer3D TVirtualGLPainter p
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 BuildTrajectoriesForwards(TSeqCollection *)
void AddTrajectory(KVGeoDNTrajectory *)
void AddInFront(KVDetector *)
KVGeoDNTrajectory * FindTrajectory(const char *title) const
const KVSeqCollection * GetTrajectories() const
KVDetector * fDetector
associated detector
KVDetector * GetDetector() const
Int_t GetNTraj() const
const Char_t * GetName() const override
Name of node is same as name of associated detector.
Int_t GetNDetsBehind() const
void ls(Option_t *option="") const override
KVUniqueNameList fInFront
list of detectors in front
KVUniqueNameList fTraj
list of trajectories passing through this node
Int_t GetNDetsInFront() const
KVUniqueNameList fTrajB
list of trajectories passing through this node going backwards
void SetDetector(KVDetector *)
void AddBehind(KVDetector *)
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.
KVUniqueNameList fBehind
list of detectors behind
void Rehash(Int_t newCapacity=0)
Definition: KVHashList.cpp:92
TObject * FindObject(const char *name) const override
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).
void Add(TObject *obj) override
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()
void Add(TObject *obj) override
const char * GetName() const override
void Add(TObject *obj) override
ClassImp(TPyArg)