CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KinematicTree.cc
Go to the documentation of this file.
2 
4 {
5  empt = true;
6  treeWalker = 0;
7 }
8 
10 {
11  delete treeWalker;
12 }
13 
14 
16  {return empt;}
17 
19 {
21  bool des = false;
22  if(!treeWalker->nextSibling()) des = true;
23  return des;
24 }
25 
29 {
30  part->setTreePointer(this);
31  treeGraph.addEdge(prodVtx,decVtx,part);
32  empt = false;
34  prodVtx->setTreePointer(this);
35  decVtx->setTreePointer(this);
36 }
37 
38 std::vector<RefCountedKinematicParticle> KinematicTree::finalStateParticles() const
39 {
40  if(isEmpty() || !(isConsistent()))
41  {
42  throw VertexException("KinematicTree::finalStateParticles; tree is empty or not consistent");
43  }else{
45  std::vector<RefCountedKinematicParticle> rs;
47  if(!(leftFinalParticle()))
48  {
49  std::cout<<"top particle has no daughters, empty vector returned"<<std::endl;
50  }else{
51 //now pointer is at the most left final particle
52  rs.push_back(currentParticle());
53  bool next_right = true;
54  bool up = true;
55  do
56  {
57  next_right = movePointerToTheNextChild();
58  if(next_right)
59  {
60 //if there's a way to the right,
61 //we go right and down possible
63  rs.push_back(currentParticle());
64  }else{
65 //once there's no way to right anymore
66 //trying to find a way upper
68  }
69 //loop stops when we are at the top:
70 //no way up, no way to the right
71  }while(up);
72  }
73 //getting the pointer back
74  bool back = findParticle(initial);
75  if(!back) throw VertexException("KinematicTree::FinalStateParticles; error occured while getting back");
76  return rs;
77  }
78 }
79 
81 {
82  bool res = false;
84  {
85  res = true;
86  bool next = true;
87  do
88  {
90  }while(next);
91  }else{
92  res =false;
93  }
94  return res;
95 }
96 
97 
99  {
100  if(isEmpty()) throw VertexException("KinematicTree::topParticle; tree is empty!");
101 //putting pointer to the top of the tree
103  return treeWalker->current().second;
104  }
105 
106 
108  {
109  if(isEmpty()) throw VertexException("KinematicTree::currentDecayVertex; tree is empty!");
110  return treeWalker->current().first;
111  }
112 
113  std::pair<bool,RefCountedKinematicParticle> KinematicTree::motherParticle() const
114  {
115  if(isEmpty()) throw VertexException("KinematicTree::motherParticle; tree is empty!");
116  bool top = currentProductionVertex()->vertexIsValid();
117  RefCountedKinematicParticle cr = treeWalker->current().second;
118  bool up = treeWalker->parent();
119  std::pair<bool,RefCountedKinematicParticle> res;
120  if(up && top){
121  RefCountedKinematicParticle pr = treeWalker->current().second;
122 
123 //now putting the pointer back
124  bool fc = treeWalker->firstChild();
125  if(!fc) throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
126  if(*(treeWalker->current().second) != *cr)
127  {
128  do{
129  bool nx = treeWalker->nextSibling();
130  if(!nx) throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
131  }while(*(treeWalker->current().second) != *cr);
132  }
133  res = std::pair<bool,RefCountedKinematicParticle>(true,pr);
134  return res;
135  }else{
137  return std::pair<bool,RefCountedKinematicParticle>(false,fk);
138  }
139  }
140 
141  std::vector<RefCountedKinematicParticle> KinematicTree::daughterParticles() const
142  {
143  if(isEmpty()) throw VertexException("KinematicTree::daughterParticles; tree is empty!");
144  std::vector<RefCountedKinematicParticle> sResult;
146  bool down = treeWalker->firstChild();
147  if(down)
148  {
149  sResult.push_back(treeWalker->current().second);
150  bool sibling = true;
151  do
152  {
153  sibling = treeWalker->nextSibling();
154  if(sibling) sResult.push_back(treeWalker->current().second);
155  }while(sibling);
156  }
157 
158 //getting the pointer back to the mother
159  bool back = findParticle(initial);
160  if(!back) throw VertexException("KinematicTree::daughterParticles; error occured while getting back");
161  return sResult;
162  }
163 
165 {
166  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheTop; tree is empty!");
167  delete treeWalker;
170 //now pointer is a pair: fake vertex and
171 //icoming 0 pointer to the particle
172 //moving it to decayed particle
173  bool move = treeWalker->firstChild();
174  if(!move) throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
175 }
176 
178 {
179  if(isEmpty()) throw VertexException("KinematicTree::currentProductionVertex; tree is empty!");
180 //current particle
182 
183  bool up;
184  bool down;
186  up = movePointerToTheMother();
187 
188  if(up)
189  {
190  res = treeWalker->current().first;
191 
192 //pointer moved so we going back
193  down = treeWalker->firstChild();
194 
195 //_down_ variable is always TRUE here, if
196 //the tree is valid.
197  if(down){
198  if(initial == treeWalker->current().second)
199  {
200  return res;
201  }else{
202  bool next = true;
203  do
204  {
205  next = treeWalker->nextSibling();
206  if(treeWalker->current().second == initial) next = false;
207  }while(next);
208  return res;
209  }
210  }else{throw VertexException("KinematicTree::Navigation failed, tree invalid?");}
211  }else
212  {
213 //very unprobable case. This efectively means that user is
214 //already out of the tree. Moving back to the top
215  delete treeWalker;
218  (treeGraph);
219  res = treeWalker->current().first;
220 //now pointer is a pair: fake vertex and
221 //icoming 0 pointer to the particle
222 //moving it to decayed particle
223  bool move = treeWalker->firstChild();
224  if(!move) throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
225  return res;
226  }
227 }
228 
230 {
231  if(isEmpty()) throw VertexException("KinematicTree::currentParticle; tree is empty!");
232  return treeWalker->current().second;
233 }
234 
236 {
237  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheMother; tree is empty!");
238  bool up = treeWalker->parent();
239  bool cr = treeWalker->current().first->vertexIsValid();
240  return (up && cr);
241 }
242 
244 {
245  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheFirstChild; tree is empty!");
246  return treeWalker->firstChild();
247 }
248 
250 {
251  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheNextChild; tree is empty!");
252  bool res = treeWalker->nextSibling();
253  return res;
254 }
255 
257 {
258  if(isEmpty() || !(isConsistent()))
259  {
260  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
261  }else{
262  bool res = false;
264  if(currentParticle() == part)
265  {
266  res = true;
267  }else if(leftBranchSearch(part)){
268  res = true;
269  }else{
270  bool found = false;
271  bool up = true;
272  bool next_right = false;
273  do
274  {
275 // if(*(currentParticle()) == *part) found = true;
276  next_right = movePointerToTheNextChild();
277  if(next_right)
278  {
279  found = leftBranchSearch(part);
280  }else{
281  up = movePointerToTheMother();
282  if(currentParticle() == part) found = true;
283  }
284  }while(up && !found);
285  res = found;
286  }
287  return res;
288  }
289 }
290 
291 
293 {
294  bool found = false;
295  bool next = true;
296  if(currentParticle() == part)
297  {
298  found = true;
299  }else{
300  do
301  {
303  if(currentParticle() == part)
304  {
305  found = true;
306  }
307  }while(next && !found);
308  }
309  return found;
310 }
311 
313 {
314  if(isEmpty() || !(isConsistent()))
315  {
316  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
317  }else{
318  bool res = false;
320  if(currentDecayVertex() == vert)
321  {
322  res = true;
323  }else if(leftBranchVertexSearch(vert)){
324  res = true;
325  }else{
326  bool up = true;
327  bool fnd = false;
328  do
329  {
331  {
332  fnd = leftBranchVertexSearch(vert);
333  }else{
335  if(currentDecayVertex() == vert) fnd = true;
336  }
337  }while(up && !fnd);
338  res = fnd;
339  }
340  return res;
341  }
342 }
343 
345 {
346  if(isEmpty() || !(isConsistent()))
347  {
348  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
349  }else{
350  bool res = false;
352  if(*currentDecayVertex() == vert)
353  {
354  res = true;
355  }else if(leftBranchVertexSearch(vert)){
356  res = true;
357  }else{
358  bool up = true;
359  bool fnd = false;
360  do
361  {
363  {
364  fnd = leftBranchVertexSearch(vert);
365  }else{
367  if(currentDecayVertex() == vert) fnd = true;
368  }
369  }while(up && !fnd);
370  res = fnd;
371  }
372  return res;
373  }
374 }
375 
376 
378 {
379  bool found = false;
380  if(currentDecayVertex() == vtx)
381  {
382  found = true;
383  }else{
384  bool next = true;
385  bool res = false;
386  do
387  {
389  if(currentDecayVertex() == vtx) res = true;
390  }while(next && !res);
391  found = res;
392  }
393  return found;
394 }
395 
397 {
398  RefCountedKinematicVertex previous_decay = otherTree->currentDecayVertex();
399 
400 //children of current particle of the
401 //other tree: in the end the whole
402 //left branch should be added.
403  bool next = true;
404  do
405  {
406  next = otherTree->movePointerToTheFirstChild();
407  if(next)
408  {
409  RefCountedKinematicParticle par = otherTree->currentParticle();
410  RefCountedKinematicVertex current_decay = otherTree->currentDecayVertex();
411  addParticle(previous_decay, current_decay, par);
412  previous_decay = current_decay;
413  }
414  }while(next);
415 }
416 
418 {
420  bool replace = treeGraph.replaceEdge(cDParticle,newPart);
421  if(!replace) throw VertexException("KinematicTree::Particle To Replace not found");
422 }
423 
425 {
427  bool replace = treeGraph.replace(cDVertex,newVert);
428  if(! replace) throw VertexException("KinematicTree::Vertex To Replace not found");
429 }
430 
431 
433 {
434 //adding new tree to the existing one:
435  bool fnd = findDecayVertex(vtx);
436  if(!fnd) throw VertexException("KinematicTree::addTree; Current tree does not contain the vertex passed");
437  tr->movePointerToTheTop();
438 
439 // adding the root of the tree:
442  addParticle(vtx,dec_vertex,mP);
443 
444 // adding the left branch if any
445  leftBranchAdd(tr,dec_vertex);
446 
447 //now the pointer is at the left down
448 //edge of the otherTree.
449 //current tree pointer is where the
450 //add operation was stoped last time.
451  bool right = true;
452  bool up = true;
453  do
454  {
455  right = tr->movePointerToTheNextChild();
456  if(right)
457  {
458 
459 //production vertex is already at the current tree
460 //adding current partilce
464  addParticle(prodVertex, decVertex, cPart);
465 
466 //adding the rest of the branch
467  leftBranchAdd(tr,decVertex);
468  }else{
469  up = tr->movePointerToTheMother();
470  }
471  }while(up);
472 }
473 
void replaceCurrentParticle(RefCountedKinematicParticle newPart) const
RefCountedKinematicVertex currentDecayVertex() const
bool movePointerToTheFirstChild() const
bool movePointerToTheNextChild() const
bool leftBranchVertexSearch(RefCountedKinematicVertex vtx) const
Common base class.
std::pair< bool, RefCountedKinematicParticle > motherParticle() const
bool leftFinalParticle() const
void leftBranchAdd(KinematicTree *otherTree, RefCountedKinematicVertex vtx)
RefCountedKinematicParticle topParticle() const
RefCountedKinematicVertex currentProductionVertex() const
bool leftBranchSearch(RefCountedKinematicParticle part) const
bool findParticle(const RefCountedKinematicParticle part) const
bool movePointerToTheMother() const
bool findDecayVertex(const RefCountedKinematicVertex vert) const
std::vector< RefCountedKinematicParticle > finalStateParticles() const
virtual ~KinematicTree()
Definition: KinematicTree.cc:9
graphwalker< RefCountedKinematicVertex, RefCountedKinematicParticle > * treeWalker
void replaceCurrentVertex(RefCountedKinematicVertex newVert) const
void movePointerToTheTop() const
graph< RefCountedKinematicVertex, RefCountedKinematicParticle > treeGraph
bool isConsistent() const
std::vector< RefCountedKinematicParticle > daughterParticles() const
ReferenceCountingPointer< KinematicVertex > RefCountedKinematicVertex
RefCountedKinematicParticle currentParticle() const
part
Definition: HCALResponse.h:21
void addParticle(RefCountedKinematicVertex prodVtx, RefCountedKinematicVertex decVtx, RefCountedKinematicParticle part)
tuple cout
Definition: gather_cfg.py:121
void addTree(RefCountedKinematicVertex vtx, KinematicTree *tr)
bool isEmpty() const