CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

KinematicTree Class Reference

#include <KinematicTree.h>

Inheritance diagram for KinematicTree:
ReferenceCounted

List of all members.

Public Member Functions

void addParticle (RefCountedKinematicVertex prodVtx, RefCountedKinematicVertex decVtx, RefCountedKinematicParticle part)
void addTree (RefCountedKinematicVertex vtx, KinematicTree *tr)
RefCountedKinematicVertex currentDecayVertex () const
RefCountedKinematicParticle currentParticle () const
RefCountedKinematicVertex currentProductionVertex () const
std::vector
< RefCountedKinematicParticle
daughterParticles () const
std::vector
< RefCountedKinematicParticle
finalStateParticles () const
bool findDecayVertex (const RefCountedKinematicVertex vert) const
bool findDecayVertex (KinematicVertex *vert) const
bool findParticle (const RefCountedKinematicParticle part) const
bool isConsistent () const
bool isEmpty () const
bool isValid () const
 KinematicTree ()
std::pair< bool,
RefCountedKinematicParticle
motherParticle () const
bool movePointerToTheFirstChild () const
bool movePointerToTheMother () const
bool movePointerToTheNextChild () const
void movePointerToTheTop () const
void replaceCurrentParticle (RefCountedKinematicParticle newPart) const
void replaceCurrentVertex (RefCountedKinematicVertex newVert) const
RefCountedKinematicParticle topParticle () const
virtual ~KinematicTree ()

Private Member Functions

void leftBranchAdd (KinematicTree *otherTree, RefCountedKinematicVertex vtx)
bool leftBranchSearch (RefCountedKinematicParticle part) const
bool leftBranchVertexSearch (RefCountedKinematicVertex vtx) const
bool leftFinalParticle () const

Private Attributes

bool empt
graph
< RefCountedKinematicVertex,
RefCountedKinematicParticle
treeGraph
graphwalker
< RefCountedKinematicVertex,
RefCountedKinematicParticle > * 
treeWalker

Detailed Description

Class describing the decay chain inside the kinematic fit. Uses the boost graph based DDD library. KinematicVertices are vertices, kinemtaic particles become nodes.

Kirill Prokofiev, April 2003 WARNING: before using any of these methods please make sure you _understand correctly_ what part of tree are you looking at now and where the pointer will be after the desiring operation.

"Left" and "Right" notation reflects the order of creating a three: from bottom to top, from left to right EXAMPLE: Bs->J/Psi Phi -> mumu KK First creating a mumu branch, fit it to J/Psi, Then adding Phi->KK and reconstructing a Bs will look like: left bottom particle: muon, top of the tree is Bs, right bottom is K.

Definition at line 36 of file KinematicTree.h.


Constructor & Destructor Documentation

KinematicTree::KinematicTree ( )

Constructor initializing everything and setting all values to 0

Definition at line 3 of file KinematicTree.cc.

References empt, and treeWalker.

{
 empt = true;
 treeWalker = 0;
}
KinematicTree::~KinematicTree ( ) [virtual]

Definition at line 9 of file KinematicTree.cc.

References treeWalker.

{
 delete treeWalker;
}

Member Function Documentation

void KinematicTree::addParticle ( RefCountedKinematicVertex  prodVtx,
RefCountedKinematicVertex  decVtx,
RefCountedKinematicParticle  part 
)

Methods adding nodes and edges to the graph representation of the Kinematic Tree

Definition at line 26 of file KinematicTree.cc.

References graph< N, E >::addEdge(), empt, movePointerToTheTop(), and treeGraph.

Referenced by addTree(), and leftBranchAdd().

{
 part->setTreePointer(this);
 treeGraph.addEdge(prodVtx,decVtx,part);
 empt = false;
 movePointerToTheTop();
 prodVtx->setTreePointer(this);
 decVtx->setTreePointer(this);
}
void KinematicTree::addTree ( RefCountedKinematicVertex  vtx,
KinematicTree tr 
)

Method adding a tree _tr_ to the vertex vtx of current tree in such a way, that vtx become a production vertex for the top particle of the _tr_. The whole contetnts of _tr_ is the rewritten to current tree. This method is purely technical and contains no mathematics. To be used by KinematicParticleVertexFitter after the corresponding fit.

Definition at line 433 of file KinematicTree.cc.

References addParticle(), currentDecayVertex(), currentParticle(), currentProductionVertex(), findDecayVertex(), leftBranchAdd(), movePointerToTheMother(), movePointerToTheNextChild(), and movePointerToTheTop().

{
//adding new tree to the existing one:
 bool fnd = findDecayVertex(vtx);
 if(!fnd) throw VertexException("KinematicTree::addTree; Current tree does not contain the vertex passed");
 tr->movePointerToTheTop();
 
// adding the root of the tree: 
 RefCountedKinematicParticle mP = tr->currentParticle(); 
 RefCountedKinematicVertex   dec_vertex = tr->currentDecayVertex();
 addParticle(vtx,dec_vertex,mP);

// adding the left branch if any 
 leftBranchAdd(tr,dec_vertex);

//now the pointer is at the left down
//edge of the otherTree.
//current tree pointer is where the
//add operation was stoped last time.
 bool right = true;
 bool up = true;
 do
 {
  right = tr->movePointerToTheNextChild();
  if(right)
  {

//production vertex is already at the current tree  
//adding current partilce
   RefCountedKinematicVertex prodVertex = tr->currentProductionVertex();
   RefCountedKinematicParticle cPart = tr->currentParticle();
   RefCountedKinematicVertex decVertex = tr->currentDecayVertex();
   addParticle(prodVertex, decVertex, cPart);
   
//adding the rest of the branch   
   leftBranchAdd(tr,decVertex);
  }else{
   up = tr->movePointerToTheMother(); 
  }
 }while(up);
}                       
RefCountedKinematicVertex KinematicTree::currentDecayVertex ( ) const

Returns a current decay vertex pointer is NOT moved

Definition at line 108 of file KinematicTree.cc.

References graphwalker< N, E >::current(), isEmpty(), and treeWalker.

Referenced by addTree(), findDecayVertex(), leftBranchAdd(), leftBranchVertexSearch(), and replaceCurrentVertex().

 {
   if(isEmpty()) throw VertexException("KinematicTree::currentDecayVertex; tree is empty!");
   return treeWalker->current().first;
 }
RefCountedKinematicParticle KinematicTree::currentParticle ( ) const

Returns a current particle pointer is NOT moved

Definition at line 230 of file KinematicTree.cc.

References graphwalker< N, E >::current(), isEmpty(), and treeWalker.

Referenced by addTree(), currentProductionVertex(), daughterParticles(), finalStateParticles(), findParticle(), leftBranchAdd(), leftBranchSearch(), and replaceCurrentParticle().

{
 if(isEmpty()) throw VertexException("KinematicTree::currentParticle; tree is empty!");
 return treeWalker->current().second;
}
RefCountedKinematicVertex KinematicTree::currentProductionVertex ( ) const

Returns a current production vertex pointer is NOT moved

Definition at line 178 of file KinematicTree.cc.

References graphwalker< N, E >::current(), currentParticle(), graphwalker< N, E >::firstChild(), isEmpty(), movePointerToTheMother(), graphwalker< N, E >::nextSibling(), treeGraph, and treeWalker.

Referenced by addTree(), and motherParticle().

{
  if(isEmpty()) throw VertexException("KinematicTree::currentProductionVertex; tree is empty!");
//current particle
  RefCountedKinematicParticle initial = currentParticle();
  
  bool up;
  bool down;
  RefCountedKinematicVertex res;
  up = movePointerToTheMother();
  
 if(up)
 { 
  res = treeWalker->current().first;
                                               
//pointer moved so we going back
  down = treeWalker->firstChild();
   
//_down_ variable is always TRUE here, if
//the tree is valid.
  if(down){
   if(initial == treeWalker->current().second)
   {
    return res;
   }else{
    bool next = true;
    do
    {
     next = treeWalker->nextSibling();
     if(treeWalker->current().second == initial) next = false;
    }while(next);
    return res;
   }
  }else{throw VertexException("KinematicTree::Navigation failed, tree invalid?");}                      
 }else
 { 
//very unprobable case. This efectively means that user is
//already out of the tree. Moving back to the top
 delete treeWalker;
 treeWalker = new graphwalker<RefCountedKinematicVertex,
                              RefCountedKinematicParticle>
                                              (treeGraph);
 res = treeWalker->current().first;                                           
//now pointer is a pair: fake vertex and 
//icoming 0 pointer to the particle
//moving it to decayed particle
 bool move = treeWalker->firstChild();
 if(!move) throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
 return res;
 } 
}
std::vector< RefCountedKinematicParticle > KinematicTree::daughterParticles ( ) const

Returns a non-zero vector in case of success and 0 vector in case of failure Pointer is NOT moved

Definition at line 142 of file KinematicTree.cc.

References prof2calltree::back, graphwalker< N, E >::current(), currentParticle(), findParticle(), graphwalker< N, E >::firstChild(), isEmpty(), graphwalker< N, E >::nextSibling(), and treeWalker.

 {
  if(isEmpty()) throw VertexException("KinematicTree::daughterParticles; tree is empty!");
  std::vector<RefCountedKinematicParticle> sResult;
  RefCountedKinematicParticle initial = currentParticle();
  bool down  = treeWalker->firstChild();
  if(down)
  {
    sResult.push_back(treeWalker->current().second);
    bool sibling = true;
    do
    {
     sibling = treeWalker->nextSibling();
     if(sibling) sResult.push_back(treeWalker->current().second); 
    }while(sibling);
  }

//getting the pointer back to the mother  
  bool back = findParticle(initial);
  if(!back) throw VertexException("KinematicTree::daughterParticles; error occured while getting back");
  return sResult;
 }
std::vector< RefCountedKinematicParticle > KinematicTree::finalStateParticles ( ) const

Kinematic Tree navigation methods Returns the complete vector of final state particles for the whole decay tree. Pointer is NOT moved after this operation

Definition at line 38 of file KinematicTree.cc.

References prof2calltree::back, gather_cfg::cout, currentParticle(), findParticle(), isConsistent(), isEmpty(), leftFinalParticle(), movePointerToTheMother(), movePointerToTheNextChild(), and movePointerToTheTop().

{
 if(isEmpty() || !(isConsistent()))
 {
  throw VertexException("KinematicTree::finalStateParticles; tree is empty or not consistent");
 }else{
  RefCountedKinematicParticle initial = currentParticle();
  std::vector<RefCountedKinematicParticle> rs;
  movePointerToTheTop();
  if(!(leftFinalParticle()))
  {
   std::cout<<"top particle has no daughters, empty vector returned"<<std::endl;
  }else{
//now pointer is at the  most left final particle
   rs.push_back(currentParticle()); 
   bool next_right = true; 
   bool down = true;   
   bool up = true;
   do
   {
    next_right = movePointerToTheNextChild();
    if(next_right)
    {
//if there's a way to the right,
//we go right and down possible    
     down = leftFinalParticle();
     rs.push_back(currentParticle()); 
    }else{
//once there's no way to right anymore
//trying to find a way upper    
     up = movePointerToTheMother();
    }
//loop stops when we are at the top:
//no way up, no way to the right    
   }while(up);   
  } 
//getting the pointer back  
  bool back = findParticle(initial);
  if(!back) throw VertexException("KinematicTree::FinalStateParticles; error occured while getting back");
  return rs;
 }
}
bool KinematicTree::findDecayVertex ( const RefCountedKinematicVertex  vert) const

Pointer goes to the particle for which the neede vertex will be the decay one (true case) Or pointer stays at the top of teh tree if search is unsuccessfull (false case).

Definition at line 313 of file KinematicTree.cc.

References currentDecayVertex(), isConsistent(), isEmpty(), leftBranchVertexSearch(), movePointerToTheMother(), movePointerToTheNextChild(), and movePointerToTheTop().

Referenced by addTree().

{
 if(isEmpty() || !(isConsistent()))
 {
  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
 }else{
 bool res = false;
 movePointerToTheTop();
 if(currentDecayVertex() == vert)
 {
  res = true;
 }else if(leftBranchVertexSearch(vert)){
  res = true;
 }else{
  bool up = true;
  bool fnd = false;
  do
  {
   if(movePointerToTheNextChild())
   {
    fnd = leftBranchVertexSearch(vert);
   }else{
    up=movePointerToTheMother();
    if(currentDecayVertex() == vert) fnd = true;
   }   
  }while(up && !fnd);
  res = fnd;
 }
 return res;
 }
}
bool KinematicTree::findDecayVertex ( KinematicVertex vert) const

Definition at line 345 of file KinematicTree.cc.

References currentDecayVertex(), isConsistent(), isEmpty(), leftBranchVertexSearch(), movePointerToTheMother(), movePointerToTheNextChild(), and movePointerToTheTop().

{
 if(isEmpty() || !(isConsistent()))
 {
  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
 }else{
 bool res = false;
 movePointerToTheTop();
 if(*currentDecayVertex() == vert)
 {
  res = true;
 }else if(leftBranchVertexSearch(vert)){
  res = true;
 }else{
  bool up = true;
  bool fnd = false;
  do
  {
   if(movePointerToTheNextChild())
   {
    fnd = leftBranchVertexSearch(vert);
   }else{
    up=movePointerToTheMother();
    if(currentDecayVertex() == vert) fnd = true;
   }   
  }while(up && !fnd);
  res = fnd;
 }
 return res;
 }
}
bool KinematicTree::findParticle ( const RefCountedKinematicParticle  part) const

Pointer goes to the needed particle inside the tree if found (true). Pointer goes to the top of the tree if not found (false)

Definition at line 257 of file KinematicTree.cc.

References currentParticle(), newFWLiteAna::found, isConsistent(), isEmpty(), leftBranchSearch(), movePointerToTheMother(), movePointerToTheNextChild(), and movePointerToTheTop().

Referenced by daughterParticles(), and finalStateParticles().

{
 if(isEmpty() || !(isConsistent()))
 {
  throw VertexException("KinematicTree::findParticle; tree is empty or not consistent");
 }else{
  bool res = false;
  movePointerToTheTop();
  if(currentParticle() == part)
  {
   res = true;
  }else if(leftBranchSearch(part)){
   res = true;
  }else{
   bool found = false;
   bool up = true;
   bool next_right = false;
   do
   {
//    if(*(currentParticle()) == *part) found = true;
    next_right = movePointerToTheNextChild();
    if(next_right)
    {
     found = leftBranchSearch(part);
    }else{
     up = movePointerToTheMother();
     if(currentParticle() == part) found = true;
    }
   }while(up && !found);
   res = found;
  } 
  return res;
 }
}
bool KinematicTree::isConsistent ( ) const

This method checks if the tree is consistent, i.e. the top vertex is only one.

Definition at line 18 of file KinematicTree.cc.

References movePointerToTheTop(), graphwalker< N, E >::nextSibling(), and treeWalker.

Referenced by finalStateParticles(), findDecayVertex(), and findParticle().

{
 movePointerToTheTop();
 bool des = false;
 if(!treeWalker->nextSibling()) des = true;
 return des;
}
bool KinematicTree::isEmpty ( void  ) const
bool KinematicTree::isValid ( void  ) const [inline]

Definition at line 53 of file KinematicTree.h.

References empt.

{return !empt;}
void KinematicTree::leftBranchAdd ( KinematicTree otherTree,
RefCountedKinematicVertex  vtx 
) [private]

Definition at line 397 of file KinematicTree.cc.

References addParticle(), currentDecayVertex(), currentParticle(), movePointerToTheFirstChild(), and Gflash::par.

Referenced by addTree().

{
  RefCountedKinematicVertex previous_decay = otherTree->currentDecayVertex(); 
 
//children of current particle of the
//other tree: in the end the whole 
//left branch should be added. 
  bool next = true;
  do
  {
   next = otherTree->movePointerToTheFirstChild();
   if(next)
   {
    RefCountedKinematicParticle par = otherTree->currentParticle();
    RefCountedKinematicVertex current_decay = otherTree->currentDecayVertex();
    addParticle(previous_decay, current_decay, par);
    previous_decay = current_decay;
   }
  }while(next);
}
bool KinematicTree::leftBranchSearch ( RefCountedKinematicParticle  part) const [private]

Private methods to walk around the tree: Needed to collect final state or particle search.

Definition at line 293 of file KinematicTree.cc.

References currentParticle(), newFWLiteAna::found, and movePointerToTheFirstChild().

Referenced by findParticle().

{
 bool found = false;
 bool next = true;
 if(currentParticle() == part)
 {
  found = true;
 }else{
  do
  {
   next = movePointerToTheFirstChild();
   if(currentParticle() == part)
   {
    found = true;
   }
  }while(next && !found);
  }
 return found;
}
bool KinematicTree::leftBranchVertexSearch ( RefCountedKinematicVertex  vtx) const [private]

Definition at line 378 of file KinematicTree.cc.

References currentDecayVertex(), newFWLiteAna::found, and movePointerToTheFirstChild().

Referenced by findDecayVertex().

{
 bool found = false;
 if(currentDecayVertex() == vtx)
 {
  found = true;
 }else{
  bool next = true;
  bool res = false;
  do
  {
   next = movePointerToTheFirstChild();
   if(currentDecayVertex() == vtx) res = true;
  }while(next && !res); 
  found  = res;
 }
 return found;
}
bool KinematicTree::leftFinalParticle ( ) const [private]

Definition at line 81 of file KinematicTree.cc.

References movePointerToTheFirstChild().

Referenced by finalStateParticles().

{
 bool res = false;
 if(movePointerToTheFirstChild())
 {
  res = true;
  bool next = true;
  do
  {
    next = movePointerToTheFirstChild(); 
  }while(next);
 }else{
  res =false;
 }
 return res;
}
std::pair< bool, RefCountedKinematicParticle > KinematicTree::motherParticle ( ) const

Returns _true_ and state of mother particle if successfull, _false_ and state of current particle in case of failure Pointer is NOT moved.

Definition at line 114 of file KinematicTree.cc.

References graphwalker< N, E >::current(), currentProductionVertex(), benchmark_cfg::fc, graphwalker< N, E >::firstChild(), isEmpty(), graphwalker< N, E >::nextSibling(), graphwalker< N, E >::parent(), and treeWalker.

 {
  if(isEmpty()) throw VertexException("KinematicTree::motherParticle; tree is empty!");
  bool top = currentProductionVertex()->vertexIsValid();
   RefCountedKinematicParticle cr  = treeWalker->current().second;
   bool up = treeWalker->parent();
   std::pair<bool,RefCountedKinematicParticle> res; 
   if(up && top){
    RefCountedKinematicParticle pr = treeWalker->current().second;
    
//now putting the pointer back   
    bool fc = treeWalker->firstChild();
    if(!fc) throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
    if(*(treeWalker->current().second) != *cr)
    {
     do{
      bool nx = treeWalker->nextSibling();
      if(!nx) throw VertexException("KinematicTree::motherParticle; tree is incorrect!");
     }while(*(treeWalker->current().second) != *cr);
    }
    res = std::pair<bool,RefCountedKinematicParticle>(true,pr);
    return res;
   }else{
    RefCountedKinematicParticle fk;
    return std::pair<bool,RefCountedKinematicParticle>(false,fk);
   }
 }
bool KinematicTree::movePointerToTheFirstChild ( ) const

Pointer goes to the first child(if any) in the list

Definition at line 244 of file KinematicTree.cc.

References graphwalker< N, E >::firstChild(), isEmpty(), and treeWalker.

Referenced by leftBranchAdd(), leftBranchSearch(), leftBranchVertexSearch(), and leftFinalParticle().

{
 if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheFirstChild; tree is empty!");
 return treeWalker->firstChild();
}
bool KinematicTree::movePointerToTheMother ( ) const

Pointer goes to the mother particle (if any) with respest to the current one

Definition at line 236 of file KinematicTree.cc.

References graphwalker< N, E >::current(), isEmpty(), graphwalker< N, E >::parent(), and treeWalker.

Referenced by addTree(), currentProductionVertex(), finalStateParticles(), findDecayVertex(), and findParticle().

{
 if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheMother; tree is empty!");
 bool up = treeWalker->parent();
 bool cr = treeWalker->current().first->vertexIsValid();
 return (up && cr);
}
bool KinematicTree::movePointerToTheNextChild ( ) const

Pointer goes to the next child in the list (if any)

Definition at line 250 of file KinematicTree.cc.

References isEmpty(), graphwalker< N, E >::nextSibling(), and treeWalker.

Referenced by addTree(), finalStateParticles(), findDecayVertex(), and findParticle().

{
 if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheNextChild; tree is empty!");
 bool res = treeWalker->nextSibling();
 return res;
}
void KinematicTree::movePointerToTheTop ( ) const

Puts the pointer to the top (root) of the tree. The Graph walker object gets recreated inside the tree.

Definition at line 165 of file KinematicTree.cc.

References graphwalker< N, E >::firstChild(), isEmpty(), treeGraph, and treeWalker.

Referenced by addParticle(), addTree(), ConstrainedTreeBuilderT::buildRealTree(), FinalTreeBuilder::buildTree(), ConstrainedTreeBuilder::buildTree(), finalStateParticles(), findDecayVertex(), findParticle(), isConsistent(), and topParticle().

{
 if(isEmpty()) throw VertexException("KinematicTree::movePointerToTheTop; tree is empty!");
 delete treeWalker;
 treeWalker = new graphwalker<RefCountedKinematicVertex,
                              RefCountedKinematicParticle>(treeGraph);
//now pointer is a pair: fake vertex and 
//icoming 0 pointer to the particle
//moving it to decayed particle
 bool move = treeWalker->firstChild();
 if(!move) throw VertexException("KinematicTree::movePointerToTheTop; non consistent tree?");
}
void KinematicTree::replaceCurrentParticle ( RefCountedKinematicParticle  newPart) const

Methods replacing Particles and Vertices inside the tree during the refit. Methods should used by corresponding KinematicFitter classe only. Replace the current track or current (decay) vertex WARNING: replace methods are not available at this version of KinematicFitPrimitives.

Definition at line 418 of file KinematicTree.cc.

References currentParticle(), linker::replace(), graph< N, E >::replaceEdge(), and treeGraph.

Referenced by ConstrainedTreeBuilderT::buildRealTree(), FinalTreeBuilder::buildTree(), and ConstrainedTreeBuilder::buildTree().

{
 RefCountedKinematicParticle cDParticle = currentParticle();
 bool replace = treeGraph.replaceEdge(cDParticle,newPart);
 if(!replace) throw VertexException("KinematicTree::Particle To Replace not found");
}
void KinematicTree::replaceCurrentVertex ( RefCountedKinematicVertex  newVert) const

Replaces _decay_ vertex of the current particle with the given value

Definition at line 425 of file KinematicTree.cc.

References currentDecayVertex(), linker::replace(), graph< N, E >::replace(), and treeGraph.

{
 RefCountedKinematicVertex cDVertex = currentDecayVertex();
 bool replace = treeGraph.replace(cDVertex,newVert);
 if(! replace) throw VertexException("KinematicTree::Vertex To Replace not found");
}
RefCountedKinematicParticle KinematicTree::topParticle ( ) const

Returns the top particle of decay. Pointer is moved to the TOP of the decay tree.

Definition at line 99 of file KinematicTree.cc.

References graphwalker< N, E >::current(), isEmpty(), movePointerToTheTop(), and treeWalker.

 {
   if(isEmpty()) throw VertexException("KinematicTree::topParticle; tree is empty!");
//putting pointer to the top of the tree 
   movePointerToTheTop();
   return treeWalker->current().second;                                     
 }

Member Data Documentation

bool KinematicTree::empt [mutable, private]

Definition at line 213 of file KinematicTree.h.

Referenced by addParticle(), isEmpty(), isValid(), and KinematicTree().