Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:13

0001 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicVertex.h"
0002 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicParticle.h"
0003 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicTree.h"
0004 #include "RecoVertex/KinematicFitPrimitives/interface/TransientTrackKinematicParticle.h"
0005 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
0006 #include "TrackingTools/TransientTrack/interface/GsfTransientTrack.h"
0007 
0008 KinematicVertex::KinematicVertex() { vl = false; }
0009 
0010 KinematicVertex::KinematicVertex(const VertexState state, float totalChiSq, float degreesOfFr)
0011     : theState(state),
0012       theChiSquared(totalChiSq),
0013       theNDF(degreesOfFr)
0014 
0015 {
0016   vl = true;
0017   tree = nullptr;
0018   pVertex = nullptr;
0019 }
0020 
0021 KinematicVertex::KinematicVertex(const CachingVertex<6>& vertex) {
0022   // theVertexPosition = vertex.position();
0023   // theVPositionError = vertex.error();
0024   vl = true;
0025   theState = VertexState(vertex.position(), vertex.error());
0026   theChiSquared = vertex.totalChiSquared();
0027   theNDF = vertex.degreesOfFreedom();
0028   tree = nullptr;
0029   pVertex = nullptr;
0030 }
0031 
0032 KinematicVertex::KinematicVertex(const VertexState state,
0033                                  const ReferenceCountingPointer<KinematicVertex> prVertex,
0034                                  float totalChiSq,
0035                                  float degreesOfFr)
0036     : theState(state), theChiSquared(totalChiSq), theNDF(degreesOfFr), pVertex(prVertex) {
0037   vl = true;
0038   tree = nullptr;
0039 }
0040 
0041 bool KinematicVertex::operator==(const KinematicVertex& other) const {
0042   bool res = false;
0043   if (vertexIsValid() && other.vertexIsValid()) {
0044     GlobalPoint cPos = this->position();
0045     GlobalPoint oPos = other.position();
0046     AlgebraicMatrix33 const& cCov = this->error().matrix();
0047     AlgebraicMatrix33 const& oCov = other.error().matrix();
0048     if ((cPos.x() == oPos.x()) && (cPos.y() == oPos.y()) && (cPos.z() == oPos.z()) && (cCov == oCov))
0049       res = true;
0050   } else if (!(vertexIsValid()) && !(other.vertexIsValid())) {
0051     if (this == &other)
0052       res = true;
0053   }
0054   return res;
0055 }
0056 
0057 bool KinematicVertex::operator==(const ReferenceCountingPointer<KinematicVertex> other) const {
0058   bool res = false;
0059   if (*this == *other)
0060     res = true;
0061   return res;
0062 }
0063 
0064 bool KinematicVertex::operator<(const KinematicVertex& other) const {
0065   bool res = false;
0066   if (this < &other)
0067     res = true;
0068   return res;
0069 }
0070 
0071 bool KinematicVertex::vertexIsValid() const { return vl; }
0072 
0073 KinematicVertex::~KinematicVertex() {}
0074 
0075 GlobalPoint KinematicVertex::position() const { return theState.position(); }
0076 
0077 GlobalError KinematicVertex::error() const { return theState.error(); }
0078 
0079 float KinematicVertex::chiSquared() const { return theChiSquared; }
0080 
0081 float KinematicVertex::degreesOfFreedom() const { return theNDF; }
0082 
0083 KinematicTree* KinematicVertex::correspondingTree() const { return tree; }
0084 
0085 void KinematicVertex::setTreePointer(KinematicTree* tr) const { tree = tr; }
0086 
0087 ReferenceCountingPointer<KinematicVertex> KinematicVertex::vertexBeforeConstraint() const { return pVertex; }
0088 
0089 VertexState KinematicVertex::vertexState() const { return theState; }
0090 
0091 KinematicVertex::operator reco::Vertex() {
0092   //If the vertex is invalid, return an invalid TV !
0093   if (!vertexIsValid() || tree == nullptr)
0094     return reco::Vertex();
0095 
0096   //accessing the tree components, move pointer to top
0097   if (!tree->findDecayVertex(this))
0098     return reco::Vertex();
0099   std::vector<RefCountedKinematicParticle> daughters = tree->daughterParticles();
0100 
0101   reco::Vertex vertex(reco::Vertex::Point(theState.position()),
0102                       //    RecoVertex::convertError(theVertexState.error()),
0103                       theState.error().matrix(),
0104                       chiSquared(),
0105                       degreesOfFreedom(),
0106                       daughters.size());
0107 
0108   for (std::vector<RefCountedKinematicParticle>::const_iterator i = daughters.begin(); i != daughters.end(); ++i) {
0109     const TransientTrackKinematicParticle* ttkp = dynamic_cast<const TransientTrackKinematicParticle*>(&(**i));
0110     if (ttkp != nullptr) {
0111       const reco::TrackTransientTrack* ttt =
0112           dynamic_cast<const reco::TrackTransientTrack*>(ttkp->initialTransientTrack()->basicTransientTrack());
0113       if ((ttt != nullptr) && (ttt->persistentTrackRef().isNonnull())) {
0114         reco::TrackRef tr = ttt->persistentTrackRef();
0115         vertex.add(reco::TrackBaseRef(tr), ttkp->refittedTransientTrack().track(), 1.);
0116       } else {
0117         const reco::GsfTransientTrack* ttt =
0118             dynamic_cast<const reco::GsfTransientTrack*>(ttkp->initialTransientTrack()->basicTransientTrack());
0119         if ((ttt != nullptr) && (ttt->persistentTrackRef().isNonnull())) {
0120           reco::GsfTrackRef tr = ttt->persistentTrackRef();
0121           vertex.add(reco::TrackBaseRef(tr), ttkp->refittedTransientTrack().track(), 1.);
0122         }
0123       }
0124     }
0125   }
0126   return vertex;
0127 }