CMS 3D CMS Logo

KinematicTree.cc
Go to the documentation of this file.
2 
4  empt = true;
5  treeWalker = nullptr;
6 }
7 
9 
10 bool KinematicTree::isEmpty() const { return empt; }
11 
14  bool des = false;
15  if (!treeWalker->nextSibling())
16  des = true;
17  return des;
18 }
19 
23  part->setTreePointer(this);
24  treeGraph.addEdge(prodVtx, decVtx, part);
25  empt = false;
27  prodVtx->setTreePointer(this);
28  decVtx->setTreePointer(this);
29 }
30 
31 std::vector<RefCountedKinematicParticle> KinematicTree::finalStateParticles() const {
32  if (isEmpty() || !(isConsistent())) {
33  throw VertexException("KinematicTree::finalStateParticles; tree is empty or not consistent");
34  } else {
36  std::vector<RefCountedKinematicParticle> rs;
38  if (!(leftFinalParticle())) {
39  std::cout << "top particle has no daughters, empty vector returned" << std::endl;
40  } else {
41  //now pointer is at the most left final particle
42  rs.push_back(currentParticle());
43  bool next_right = true;
44  bool up = true;
45  do {
46  next_right = movePointerToTheNextChild();
47  if (next_right) {
48  //if there's a way to the right,
49  //we go right and down possible
51  rs.push_back(currentParticle());
52  } else {
53  //once there's no way to right anymore
54  //trying to find a way upper
56  }
57  //loop stops when we are at the top:
58  //no way up, no way to the right
59  } while (up);
60  }
61  //getting the pointer back
62  bool back = findParticle(initial);
63  if (!back)
64  throw VertexException("KinematicTree::FinalStateParticles; error occured while getting back");
65  return rs;
66  }
67 }
68 
70  bool res = false;
72  res = true;
73  bool next = true;
74  do {
76  } while (next);
77  } else {
78  res = false;
79  }
80  return res;
81 }
82 
84  if (isEmpty())
85  throw VertexException("KinematicTree::topParticle; tree is empty!");
86  //putting pointer to the top of the tree
88  return treeWalker->current().second;
89 }
90 
92  if (isEmpty())
93  throw VertexException("KinematicTree::currentDecayVertex; tree is empty!");
94  return treeWalker->current().first;
95 }
96 
97 std::pair<bool, RefCountedKinematicParticle> KinematicTree::motherParticle() const {
98  if (isEmpty())
99  throw VertexException("KinematicTree::motherParticle; tree is empty!");
100  bool top = currentProductionVertex()->vertexIsValid();
101  RefCountedKinematicParticle cr = treeWalker->current().second;
102  bool up = treeWalker->parent();
103  std::pair<bool, RefCountedKinematicParticle> res;
104  if (up && top) {
105  RefCountedKinematicParticle pr = treeWalker->current().second;
106 
107  //now putting the pointer back
108  bool fc = treeWalker->firstChild();
109  if (!fc)
110  throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
111  if (*(treeWalker->current().second) != *cr) {
112  do {
113  bool nx = treeWalker->nextSibling();
114  if (!nx)
115  throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
116  } while (*(treeWalker->current().second) != *cr);
117  }
118  res = std::pair<bool, RefCountedKinematicParticle>(true, pr);
119  return res;
120  } else {
122  return std::pair<bool, RefCountedKinematicParticle>(false, fk);
123  }
124 }
125 
126 std::vector<RefCountedKinematicParticle> KinematicTree::daughterParticles() const {
127  if (isEmpty())
128  throw VertexException("KinematicTree::daughterParticles; tree is empty!");
129  std::vector<RefCountedKinematicParticle> sResult;
131  bool down = treeWalker->firstChild();
132  if (down) {
133  sResult.push_back(treeWalker->current().second);
134  bool sibling = true;
135  do {
136  sibling = treeWalker->nextSibling();
137  if (sibling)
138  sResult.push_back(treeWalker->current().second);
139  } while (sibling);
140  }
141 
142  //getting the pointer back to the mother
143  bool back = findParticle(initial);
144  if (!back)
145  throw VertexException("KinematicTree::daughterParticles; error occured while getting back");
146  return sResult;
147 }
148 
150  if (isEmpty())
151  throw VertexException("KinematicTree::movePointerToTheTop; tree is empty!");
152  delete treeWalker;
154  //now pointer is a pair: fake vertex and
155  //icoming 0 pointer to the particle
156  //moving it to decayed particle
157  bool move = treeWalker->firstChild();
158  if (!move)
159  throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
160 }
161 
163  if (isEmpty())
164  throw VertexException("KinematicTree::currentProductionVertex; tree is empty!");
165  //current particle
167 
168  bool up;
169  bool down;
172 
173  if (up) {
174  res = treeWalker->current().first;
175 
176  //pointer moved so we going back
177  down = treeWalker->firstChild();
178 
179  //_down_ variable is always TRUE here, if
180  //the tree is valid.
181  if (down) {
182  if (initial == treeWalker->current().second) {
183  return res;
184  } else {
185  bool next = true;
186  do {
187  next = treeWalker->nextSibling();
188  if (treeWalker->current().second == initial)
189  next = false;
190  } while (next);
191  return res;
192  }
193  } else {
194  throw VertexException("KinematicTree::Navigation failed, tree invalid?");
195  }
196  } else {
197  //very unprobable case. This efectively means that user is
198  //already out of the tree. Moving back to the top
199  delete treeWalker;
201  res = treeWalker->current().first;
202  //now pointer is a pair: fake vertex and
203  //icoming 0 pointer to the particle
204  //moving it to decayed particle
205  bool move = treeWalker->firstChild();
206  if (!move)
207  throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
208  return res;
209  }
210 }
211 
213  if (isEmpty())
214  throw VertexException("KinematicTree::currentParticle; tree is empty!");
215  return treeWalker->current().second;
216 }
217 
219  if (isEmpty())
220  throw VertexException("KinematicTree::movePointerToTheMother; tree is empty!");
221  bool up = treeWalker->parent();
222  bool cr = treeWalker->current().first->vertexIsValid();
223  return (up && cr);
224 }
225 
227  if (isEmpty())
228  throw VertexException("KinematicTree::movePointerToTheFirstChild; tree is empty!");
229  return treeWalker->firstChild();
230 }
231 
233  if (isEmpty())
234  throw VertexException("KinematicTree::movePointerToTheNextChild; tree is empty!");
235  bool res = treeWalker->nextSibling();
236  return res;
237 }
238 
240  if (isEmpty() || !(isConsistent())) {
241  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
242  } else {
243  bool res = false;
245  if (currentParticle() == part) {
246  res = true;
247  } else if (leftBranchSearch(part)) {
248  res = true;
249  } else {
250  bool found = false;
251  bool up = true;
252  bool next_right = false;
253  do {
254  // if(*(currentParticle()) == *part) found = true;
255  next_right = movePointerToTheNextChild();
256  if (next_right) {
258  } else {
260  if (currentParticle() == part)
261  found = true;
262  }
263  } while (up && !found);
264  res = found;
265  }
266  return res;
267  }
268 }
269 
271  bool found = false;
272  bool next = true;
273  if (currentParticle() == part) {
274  found = true;
275  } else {
276  do {
278  if (currentParticle() == part) {
279  found = true;
280  }
281  } while (next && !found);
282  }
283  return found;
284 }
285 
287  if (isEmpty() || !(isConsistent())) {
288  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
289  } else {
290  bool res = false;
292  if (currentDecayVertex() == vert) {
293  res = true;
294  } else if (leftBranchVertexSearch(vert)) {
295  res = true;
296  } else {
297  bool up = true;
298  bool fnd = false;
299  do {
301  fnd = leftBranchVertexSearch(vert);
302  } else {
304  if (currentDecayVertex() == vert)
305  fnd = true;
306  }
307  } while (up && !fnd);
308  res = fnd;
309  }
310  return res;
311  }
312 }
313 
315  if (isEmpty() || !(isConsistent())) {
316  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
317  } else {
318  bool res = false;
320  if (*currentDecayVertex() == vert) {
321  res = true;
322  } else if (leftBranchVertexSearch(vert)) {
323  res = true;
324  } else {
325  bool up = true;
326  bool fnd = false;
327  do {
329  fnd = leftBranchVertexSearch(vert);
330  } else {
332  if (currentDecayVertex() == vert)
333  fnd = true;
334  }
335  } while (up && !fnd);
336  res = fnd;
337  }
338  return res;
339  }
340 }
341 
343  bool found = false;
344  if (currentDecayVertex() == vtx) {
345  found = true;
346  } else {
347  bool next = true;
348  bool res = false;
349  do {
351  if (currentDecayVertex() == vtx)
352  res = true;
353  } while (next && !res);
354  found = res;
355  }
356  return found;
357 }
358 
360  RefCountedKinematicVertex previous_decay = otherTree->currentDecayVertex();
361 
362  //children of current particle of the
363  //other tree: in the end the whole
364  //left branch should be added.
365  bool next = true;
366  do {
367  next = otherTree->movePointerToTheFirstChild();
368  if (next) {
369  RefCountedKinematicParticle par = otherTree->currentParticle();
370  RefCountedKinematicVertex current_decay = otherTree->currentDecayVertex();
371  addParticle(previous_decay, current_decay, par);
372  previous_decay = current_decay;
373  }
374  } while (next);
375 }
376 
379  bool replace = treeGraph.replaceEdge(cDParticle, newPart);
380  if (!replace)
381  throw VertexException("KinematicTree::Particle To Replace not found");
382 }
383 
386  bool replace = treeGraph.replace(cDVertex, newVert);
387  if (!replace)
388  throw VertexException("KinematicTree::Vertex To Replace not found");
389 }
390 
392  //adding new tree to the existing one:
393  bool fnd = findDecayVertex(vtx);
394  if (!fnd)
395  throw VertexException("KinematicTree::addTree; Current tree does not contain the vertex passed");
396  tr->movePointerToTheTop();
397 
398  // adding the root of the tree:
401  addParticle(vtx, dec_vertex, mP);
402 
403  // adding the left branch if any
404  leftBranchAdd(tr, dec_vertex);
405 
406  //now the pointer is at the left down
407  //edge of the otherTree.
408  //current tree pointer is where the
409  //add operation was stoped last time.
410  bool right = true;
411  bool up = true;
412  do {
413  right = tr->movePointerToTheNextChild();
414  if (right) {
415  //production vertex is already at the current tree
416  //adding current partilce
420  addParticle(prodVertex, decVertex, cPart);
421 
422  //adding the rest of the branch
423  leftBranchAdd(tr, decVertex);
424  } else {
425  up = tr->movePointerToTheMother();
426  }
427  } while (up);
428 }
Definition: BitonicSort.h:7
std::vector< RefCountedKinematicParticle > finalStateParticles() const
RefCountedKinematicParticle topParticle() const
void replaceCurrentVertex(RefCountedKinematicVertex newVert) const
bool findDecayVertex(const RefCountedKinematicVertex vert) const
bool isEmpty() const
Common base class.
std::pair< bool, RefCountedKinematicParticle > motherParticle() const
void leftBranchAdd(KinematicTree *otherTree, RefCountedKinematicVertex vtx)
def replace(string, replacements)
math::GraphWalker< RefCountedKinematicVertex, RefCountedKinematicParticle > * treeWalker
~KinematicTree() override
Definition: KinematicTree.cc:8
void replaceCurrentParticle(RefCountedKinematicParticle newPart) const
bool movePointerToTheFirstChild() const
Definition: Electron.h:6
bool isConsistent() const
void movePointerToTheTop() const
bool movePointerToTheNextChild() const
math::Graph< RefCountedKinematicVertex, RefCountedKinematicParticle > treeGraph
RefCountedKinematicParticle currentParticle() const
RefCountedKinematicVertex currentDecayVertex() const
RefCountedKinematicVertex currentProductionVertex() const
bool findParticle(const RefCountedKinematicParticle part) const
part
Definition: HCALResponse.h:20
void addParticle(RefCountedKinematicVertex prodVtx, RefCountedKinematicVertex decVtx, RefCountedKinematicParticle part)
bool leftFinalParticle() const
bool leftBranchVertexSearch(RefCountedKinematicVertex vtx) const
bool movePointerToTheMother() const
void addTree(RefCountedKinematicVertex vtx, KinematicTree *tr)
def move(src, dest)
Definition: eostools.py:511
std::vector< RefCountedKinematicParticle > daughterParticles() const
bool leftBranchSearch(RefCountedKinematicParticle part) const