CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DataFormats/ParticleFlowReco/src/PFTrack.cc

Go to the documentation of this file.
00001 #include "DataFormats/ParticleFlowReco/interface/PFTrack.h"
00002 #include "Math/GenVector/PositionVector3D.h" 
00003 #include "DataFormats/Math/interface/Point3D.h" 
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 
00006 using namespace reco;
00007 using namespace std;
00008 
00009 const unsigned PFTrack::nMaxTrackingLayers_ = 17;
00010 
00011 PFTrack::PFTrack() :
00012   charge_(0.),
00013   indexInnermost_(0),
00014   indexOutermost_(0),
00015   color_(1) {
00016 
00017   // prepare vector of trajectory points for propagated positions
00018   trajectoryPoints_.reserve(PFTrajectoryPoint::NLayers + nMaxTrackingLayers_);
00019 }
00020 
00021 
00022 PFTrack::PFTrack(double charge) : 
00023   charge_(charge), 
00024   indexInnermost_(0),
00025   indexOutermost_(0),
00026   color_(1) {
00027 
00028   // prepare vector of trajectory points for propagated positions
00029   trajectoryPoints_.reserve(PFTrajectoryPoint::NLayers + nMaxTrackingLayers_);
00030 }
00031   
00032 
00033 PFTrack::PFTrack(const PFTrack& other) :
00034   charge_(other.charge_), 
00035   trajectoryPoints_(other.trajectoryPoints_),
00036   indexInnermost_(other.indexInnermost_),
00037   indexOutermost_(other.indexOutermost_),
00038   color_(other.color_)
00039 {}
00040 
00041 
00042 void PFTrack::addPoint(const PFTrajectoryPoint& trajPt) {
00043   
00044   //   cout<<"adding "<<trajPt<<endl;
00045 
00046   if (trajPt.isTrackerLayer()) {
00047     if (!indexOutermost_) { // first time a measurement is added
00048       if (trajectoryPoints_.size() < PFTrajectoryPoint::BeamPipeOrEndVertex + 1) {
00049         PFTrajectoryPoint dummyPt;
00050         for (unsigned iPt = trajectoryPoints_.size(); iPt < PFTrajectoryPoint::BeamPipeOrEndVertex + 1; iPt++)
00051           trajectoryPoints_.push_back(dummyPt);
00052       } else if (trajectoryPoints_.size() > PFTrajectoryPoint::BeamPipeOrEndVertex + 1) {
00053         // throw an exception here
00054         //      edm::LogError("PFTrack")<<"trajectoryPoints_.size() is too large = " 
00055         //                              <<trajectoryPoints_.size()<<"\n";
00056       }
00057       indexOutermost_ = indexInnermost_ = PFTrajectoryPoint::BeamPipeOrEndVertex + 1;
00058     } else 
00059       indexOutermost_++;
00060   }
00061   // Use push_back instead of insert in order to gain time
00062   trajectoryPoints_.push_back(trajPt);
00063 
00064   //   cout<<"adding point "<<*this<<endl;
00065 }
00066 
00067 
00068 void PFTrack::calculatePositionREP() {
00069   
00070   //for(unsigned i=0; i<trajectoryPoints_.size(); i++) {
00071   //  trajectoryPoints_[i].calculatePositionREP();
00072   //}
00073 }
00074 
00075  
00076 const reco::PFTrajectoryPoint& PFTrack::extrapolatedPoint(unsigned layerid) const {
00077   
00078   if( layerid >= reco::PFTrajectoryPoint::NLayers ||
00079       nTrajectoryMeasurements() + layerid >= trajectoryPoints_.size() ) {
00080 
00081     // cout<<(*this)<<endl;
00082     // cout<<"lid "<<layerid<<" "<<nTrajectoryMeasurements()<<" "<<trajectoryPoints_.size()<<endl;
00083     
00084     throw cms::Exception("SizeError")<<"PFRecTrack::extrapolatedPoint: cannot access "
00085                                      <<layerid
00086                                      <<" #traj meas = "<<nTrajectoryMeasurements()
00087                                      <<" #traj points = "<<trajectoryPoints_.size()
00088                                      <<endl
00089                                      <<(*this);
00090     // assert(0);
00091   }
00092   if (layerid < indexInnermost_)
00093     return trajectoryPoints_[ layerid ];
00094   else
00095     return trajectoryPoints_[ nTrajectoryMeasurements() + layerid ];  
00096 }
00097 
00098 
00099 ostream& reco::operator<<(ostream& out, 
00100                           const PFTrack& track) {  
00101   if (!out) return out;  
00102 
00103   const reco::PFTrajectoryPoint& closestApproach = 
00104     track.trajectoryPoint(reco::PFTrajectoryPoint::ClosestApproach);
00105 
00106   out<<"Track charge = "<<track.charge() 
00107      <<", Pt = "<<closestApproach.momentum().Pt() 
00108      <<", P = "<<closestApproach.momentum().P()<<endl
00109      <<"\tR0 = "<<closestApproach.position().Rho()
00110      <<" Z0 = "<<closestApproach.position().Z()<<endl
00111      <<"\tnumber of tracker measurements = " 
00112      <<track.nTrajectoryMeasurements()<<endl;
00113   for(unsigned i=0; i<track.trajectoryPoints_.size(); i++) 
00114     out<<track.trajectoryPoints_[i]<<endl;
00115   
00116 
00117   return out;
00118 }