CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoVertex/KinematicFitPrimitives/src/KinematicVertex.cc

Go to the documentation of this file.
00001 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicVertex.h"
00002 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicParticle.h"
00003 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicTree.h"
00004 #include "RecoVertex/KinematicFitPrimitives/interface/TransientTrackKinematicParticle.h"
00005 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
00006 #include "TrackingTools/TransientTrack/interface/GsfTransientTrack.h"
00007 
00008 KinematicVertex::KinematicVertex()
00009 {vl = false;}
00010 
00011 KinematicVertex::KinematicVertex(const VertexState state, float totalChiSq, 
00012                                                              float degreesOfFr):
00013                   theState(state),theChiSquared(totalChiSq),theNDF(degreesOfFr)                
00014                                                                    
00015 {
00016  vl = true;
00017  tree = 0;
00018  pVertex = 0;
00019 }
00020 
00021 KinematicVertex::KinematicVertex(const CachingVertex<6>& vertex)                                              
00022 {
00023 // theVertexPosition = vertex.position();
00024 // theVPositionError = vertex.error();
00025  vl = true;
00026  theState = VertexState(vertex.position(), vertex.error());
00027  theChiSquared = vertex.totalChiSquared();
00028  theNDF = vertex.degreesOfFreedom();
00029  tree = 0;
00030  pVertex = 0;
00031 }                
00032 
00033 KinematicVertex::KinematicVertex(const VertexState state, 
00034                          const ReferenceCountingPointer<KinematicVertex> prVertex,
00035                                     float totalChiSq, float degreesOfFr):
00036                                     theState(state) ,
00037                                     theChiSquared(totalChiSq),theNDF(degreesOfFr) , pVertex(prVertex)
00038 {
00039  vl = true;
00040  tree = 0;
00041 }
00042 
00043 
00044 
00045 bool KinematicVertex::operator==(const KinematicVertex& other)const
00046 {
00047  bool res = false;
00048  if(vertexIsValid()&& other.vertexIsValid())
00049  {
00050   GlobalPoint cPos = this->position();
00051   GlobalPoint oPos = other.position();
00052   AlgebraicMatrix33 const & cCov = this->error().matrix();
00053   AlgebraicMatrix33 const & oCov = other.error().matrix();
00054   if((cPos.x()==oPos.x())&&(cPos.y()==oPos.y())&&(cPos.z()==oPos.z())
00055                                                       &&(cCov==oCov))
00056   res = true;
00057  }else if(!(vertexIsValid()) && !(other.vertexIsValid())){
00058   if(this == &other) res = true;
00059  } 
00060  return res;
00061 }
00062 
00063 bool KinematicVertex::operator==(const ReferenceCountingPointer<KinematicVertex> other)const
00064 {
00065  bool res = false;
00066  if(*this == *other) res = true;
00067  return res;
00068 }
00069 
00070 
00071 bool KinematicVertex::operator<(const KinematicVertex& other)const
00072 { 
00073  bool res = false;
00074  if(this < &other) res=true;
00075  return res;
00076 }       
00077 
00078 bool KinematicVertex::vertexIsValid() const
00079 {return vl;}
00080 
00081 KinematicVertex::~KinematicVertex()
00082 {}
00083 
00084 GlobalPoint KinematicVertex::position() const
00085 {
00086  return theState.position(); 
00087 }
00088  
00089 GlobalError KinematicVertex::error() const
00090 {
00091  return theState.error();
00092 }
00093  
00094 float  KinematicVertex::chiSquared() const
00095 {return theChiSquared;}
00096  
00097 float  KinematicVertex::degreesOfFreedom() const
00098 {return theNDF;}
00099 
00100 KinematicTree *  KinematicVertex::correspondingTree() const
00101 {return tree;}
00102 
00103 void KinematicVertex::setTreePointer(KinematicTree * tr) const
00104 { tree = tr;}
00105 
00106 ReferenceCountingPointer<KinematicVertex>  KinematicVertex::vertexBeforeConstraint() const
00107 {return pVertex;}
00108 
00109 VertexState KinematicVertex::vertexState() const
00110 {return theState;}
00111 
00112 KinematicVertex::operator reco::Vertex() 
00113 {
00114    //If the vertex is invalid, return an invalid TV !
00115   if (!vertexIsValid() || tree==0) return reco::Vertex();
00116 
00117 //accessing the tree components, move pointer to top
00118   if (!tree->findDecayVertex(this)) return reco::Vertex();
00119   std::vector<RefCountedKinematicParticle> daughters = tree->daughterParticles();
00120 
00121   reco::Vertex vertex(reco::Vertex::Point(theState.position()),
00122 //      RecoVertex::convertError(theVertexState.error()), 
00123         theState.error().matrix_new(), 
00124         chiSquared(), degreesOfFreedom(), daughters.size() );
00125 
00126   for (std::vector<RefCountedKinematicParticle>::const_iterator i = daughters.begin();
00127        i != daughters.end(); ++i) {
00128 
00129     const TransientTrackKinematicParticle * ttkp = dynamic_cast<const TransientTrackKinematicParticle * >(&(**i));
00130     if(ttkp != 0) {
00131       const reco::TrackTransientTrack * ttt = dynamic_cast<const reco::TrackTransientTrack*>(ttkp->initialTransientTrack()->basicTransientTrack());
00132       if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull())) {
00133         reco::TrackRef tr = ttt->persistentTrackRef();
00134         vertex.add(reco::TrackBaseRef(tr), ttkp->refittedTransientTrack().track(), 1.);
00135       } else {
00136         const reco::GsfTransientTrack * ttt = dynamic_cast<const reco::GsfTransientTrack*>(ttkp->initialTransientTrack()->basicTransientTrack());
00137         if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull())) {
00138           reco::GsfTrackRef tr = ttt->persistentTrackRef();
00139           vertex.add(reco::TrackBaseRef(tr), ttkp->refittedTransientTrack().track(), 1.);
00140         }
00141       }
00142     }
00143   }
00144   return vertex;
00145 }
00146