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 down = true;
55  bool up = true;
56  do
57  {
58  next_right = movePointerToTheNextChild();
59  if(next_right)
60  {
61 //if there's a way to the right,
62 //we go right and down possible
63  down = leftFinalParticle();
64  rs.push_back(currentParticle());
65  }else{
66 //once there's no way to right anymore
67 //trying to find a way upper
69  }
70 //loop stops when we are at the top:
71 //no way up, no way to the right
72  }while(up);
73  }
74 //getting the pointer back
75  bool back = findParticle(initial);
76  if(!back) throw VertexException("KinematicTree::FinalStateParticles; error occured while getting back");
77  return rs;
78  }
79 }
80 
82 {
83  bool res = false;
85  {
86  res = true;
87  bool next = true;
88  do
89  {
91  }while(next);
92  }else{
93  res =false;
94  }
95  return res;
96 }
97 
98 
100  {
101  if(isEmpty()) throw VertexException("KinematicTree::topParticle; tree is empty!");
102 //putting pointer to the top of the tree
104  return treeWalker->current().second;
105  }
106 
107 
109  {
110  if(isEmpty()) throw VertexException("KinematicTree::currentDecayVertex; tree is empty!");
111  return treeWalker->current().first;
112  }
113 
114  std::pair<bool,RefCountedKinematicParticle> KinematicTree::motherParticle() const
115  {
116  if(isEmpty()) throw VertexException("KinematicTree::motherParticle; tree is empty!");
117  bool top = currentProductionVertex()->vertexIsValid();
118  RefCountedKinematicParticle cr = treeWalker->current().second;
119  bool up = treeWalker->parent();
120  std::pair<bool,RefCountedKinematicParticle> res;
121  if(up && top){
122  RefCountedKinematicParticle pr = treeWalker->current().second;
123 
124 //now putting the pointer back
125  bool fc = treeWalker->firstChild();
126  if(!fc) throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
127  if(*(treeWalker->current().second) != *cr)
128  {
129  do{
130  bool nx = treeWalker->nextSibling();
131  if(!nx) throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
132  }while(*(treeWalker->current().second) != *cr);
133  }
134  res = std::pair<bool,RefCountedKinematicParticle>(true,pr);
135  return res;
136  }else{
138  return std::pair<bool,RefCountedKinematicParticle>(false,fk);
139  }
140  }
141 
142  std::vector<RefCountedKinematicParticle> KinematicTree::daughterParticles() const
143  {
144  if(isEmpty()) throw VertexException("KinematicTree::daughterParticles; tree is empty!");
145  std::vector<RefCountedKinematicParticle> sResult;
147  bool down = treeWalker->firstChild();
148  if(down)
149  {
150  sResult.push_back(treeWalker->current().second);
151  bool sibling = true;
152  do
153  {
154  sibling = treeWalker->nextSibling();
155  if(sibling) sResult.push_back(treeWalker->current().second);
156  }while(sibling);
157  }
158 
159 //getting the pointer back to the mother
160  bool back = findParticle(initial);
161  if(!back) throw VertexException("KinematicTree::daughterParticles; error occured while getting back");
162  return sResult;
163  }
164 
166 {
167  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheTop; tree is empty!");
168  delete treeWalker;
171 //now pointer is a pair: fake vertex and
172 //icoming 0 pointer to the particle
173 //moving it to decayed particle
174  bool move = treeWalker->firstChild();
175  if(!move) throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
176 }
177 
179 {
180  if(isEmpty()) throw VertexException("KinematicTree::currentProductionVertex; tree is empty!");
181 //current particle
183 
184  bool up;
185  bool down;
187  up = movePointerToTheMother();
188 
189  if(up)
190  {
191  res = treeWalker->current().first;
192 
193 //pointer moved so we going back
194  down = treeWalker->firstChild();
195 
196 //_down_ variable is always TRUE here, if
197 //the tree is valid.
198  if(down){
199  if(initial == treeWalker->current().second)
200  {
201  return res;
202  }else{
203  bool next = true;
204  do
205  {
206  next = treeWalker->nextSibling();
207  if(treeWalker->current().second == initial) next = false;
208  }while(next);
209  return res;
210  }
211  }else{throw VertexException("KinematicTree::Navigation failed, tree invalid?");}
212  }else
213  {
214 //very unprobable case. This efectively means that user is
215 //already out of the tree. Moving back to the top
216  delete treeWalker;
219  (treeGraph);
220  res = treeWalker->current().first;
221 //now pointer is a pair: fake vertex and
222 //icoming 0 pointer to the particle
223 //moving it to decayed particle
224  bool move = treeWalker->firstChild();
225  if(!move) throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
226  return res;
227  }
228 }
229 
231 {
232  if(isEmpty()) throw VertexException("KinematicTree::currentParticle; tree is empty!");
233  return treeWalker->current().second;
234 }
235 
237 {
238  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheMother; tree is empty!");
239  bool up = treeWalker->parent();
240  bool cr = treeWalker->current().first->vertexIsValid();
241  return (up && cr);
242 }
243 
245 {
246  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheFirstChild; tree is empty!");
247  return treeWalker->firstChild();
248 }
249 
251 {
252  if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheNextChild; tree is empty!");
253  bool res = treeWalker->nextSibling();
254  return res;
255 }
256 
258 {
259  if(isEmpty() || !(isConsistent()))
260  {
261  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
262  }else{
263  bool res = false;
265  if(currentParticle() == part)
266  {
267  res = true;
268  }else if(leftBranchSearch(part)){
269  res = true;
270  }else{
271  bool found = false;
272  bool up = true;
273  bool next_right = false;
274  do
275  {
276 // if(*(currentParticle()) == *part) found = true;
277  next_right = movePointerToTheNextChild();
278  if(next_right)
279  {
280  found = leftBranchSearch(part);
281  }else{
282  up = movePointerToTheMother();
283  if(currentParticle() == part) found = true;
284  }
285  }while(up && !found);
286  res = found;
287  }
288  return res;
289  }
290 }
291 
292 
294 {
295  bool found = false;
296  bool next = true;
297  if(currentParticle() == part)
298  {
299  found = true;
300  }else{
301  do
302  {
304  if(currentParticle() == part)
305  {
306  found = true;
307  }
308  }while(next && !found);
309  }
310  return found;
311 }
312 
314 {
315  if(isEmpty() || !(isConsistent()))
316  {
317  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
318  }else{
319  bool res = false;
321  if(currentDecayVertex() == vert)
322  {
323  res = true;
324  }else if(leftBranchVertexSearch(vert)){
325  res = true;
326  }else{
327  bool up = true;
328  bool fnd = false;
329  do
330  {
332  {
333  fnd = leftBranchVertexSearch(vert);
334  }else{
336  if(currentDecayVertex() == vert) fnd = true;
337  }
338  }while(up && !fnd);
339  res = fnd;
340  }
341  return res;
342  }
343 }
344 
346 {
347  if(isEmpty() || !(isConsistent()))
348  {
349  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
350  }else{
351  bool res = false;
353  if(*currentDecayVertex() == vert)
354  {
355  res = true;
356  }else if(leftBranchVertexSearch(vert)){
357  res = true;
358  }else{
359  bool up = true;
360  bool fnd = false;
361  do
362  {
364  {
365  fnd = leftBranchVertexSearch(vert);
366  }else{
368  if(currentDecayVertex() == vert) fnd = true;
369  }
370  }while(up && !fnd);
371  res = fnd;
372  }
373  return res;
374  }
375 }
376 
377 
379 {
380  bool found = false;
381  if(currentDecayVertex() == vtx)
382  {
383  found = true;
384  }else{
385  bool next = true;
386  bool res = false;
387  do
388  {
390  if(currentDecayVertex() == vtx) res = true;
391  }while(next && !res);
392  found = res;
393  }
394  return found;
395 }
396 
398 {
399  RefCountedKinematicVertex previous_decay = otherTree->currentDecayVertex();
400 
401 //children of current particle of the
402 //other tree: in the end the whole
403 //left branch should be added.
404  bool next = true;
405  do
406  {
407  next = otherTree->movePointerToTheFirstChild();
408  if(next)
409  {
411  RefCountedKinematicVertex current_decay = otherTree->currentDecayVertex();
412  addParticle(previous_decay, current_decay, par);
413  previous_decay = current_decay;
414  }
415  }while(next);
416 }
417 
419 {
421  bool replace = treeGraph.replaceEdge(cDParticle,newPart);
422  if(!replace) throw VertexException("KinematicTree::Particle To Replace not found");
423 }
424 
426 {
428  bool replace = treeGraph.replace(cDVertex,newVert);
429  if(! replace) throw VertexException("KinematicTree::Vertex To Replace not found");
430 }
431 
432 
434 {
435 //adding new tree to the existing one:
436  bool fnd = findDecayVertex(vtx);
437  if(!fnd) throw VertexException("KinematicTree::addTree; Current tree does not contain the vertex passed");
438  tr->movePointerToTheTop();
439 
440 // adding the root of the tree:
443  addParticle(vtx,dec_vertex,mP);
444 
445 // adding the left branch if any
446  leftBranchAdd(tr,dec_vertex);
447 
448 //now the pointer is at the left down
449 //edge of the otherTree.
450 //current tree pointer is where the
451 //add operation was stoped last time.
452  bool right = true;
453  bool up = true;
454  do
455  {
456  right = tr->movePointerToTheNextChild();
457  if(right)
458  {
459 
460 //production vertex is already at the current tree
461 //adding current partilce
465  addParticle(prodVertex, decVertex, cPart);
466 
467 //adding the rest of the branch
468  leftBranchAdd(tr,decVertex);
469  }else{
470  up = tr->movePointerToTheMother();
471  }
472  }while(up);
473 }
474 
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:41
void addTree(RefCountedKinematicVertex vtx, KinematicTree *tr)
bool isEmpty() const
const double par[8 *NPar][4]