File indexing completed on 2024-04-06 12:04:53
0001 #include "DataFormats/ParticleFlowReco/interface/PFTrack.h"
0002 #include "Math/GenVector/PositionVector3D.h"
0003 #include "DataFormats/Math/interface/Point3D.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007 using namespace reco;
0008 using namespace std;
0009
0010 const unsigned PFTrack::nMaxTrackingLayers_ = 17;
0011
0012 PFTrack::PFTrack() : charge_(0.), indexInnermost_(0), indexOutermost_(0) {
0013
0014 trajectoryPoints_.reserve(PFTrajectoryPoint::NLayers + nMaxTrackingLayers_);
0015 }
0016
0017 PFTrack::PFTrack(double charge) : charge_(charge), indexInnermost_(0), indexOutermost_(0) {
0018
0019 trajectoryPoints_.reserve(PFTrajectoryPoint::NLayers + nMaxTrackingLayers_);
0020 }
0021
0022 PFTrack::PFTrack(const PFTrack& other)
0023 : charge_(other.charge_),
0024 trajectoryPoints_(other.trajectoryPoints_),
0025 indexInnermost_(other.indexInnermost_),
0026 indexOutermost_(other.indexOutermost_) {}
0027
0028 void PFTrack::addPoint(const PFTrajectoryPoint& trajPt) {
0029 if (trajPt.isTrackerLayer()) {
0030 if (!indexOutermost_) {
0031 if (trajectoryPoints_.size() < PFTrajectoryPoint::BeamPipeOrEndVertex + 1) {
0032 PFTrajectoryPoint dummyPt;
0033 for (unsigned iPt = trajectoryPoints_.size(); iPt < PFTrajectoryPoint::BeamPipeOrEndVertex + 1; iPt++)
0034 trajectoryPoints_.push_back(dummyPt);
0035 } else if (trajectoryPoints_.size() > PFTrajectoryPoint::BeamPipeOrEndVertex + 1) {
0036 edm::LogWarning("PFTrack") << "trajectoryPoints_.size() is too large = " << trajectoryPoints_.size();
0037 }
0038 indexOutermost_ = indexInnermost_ = PFTrajectoryPoint::BeamPipeOrEndVertex + 1;
0039 } else
0040 indexOutermost_++;
0041 }
0042
0043 trajectoryPoints_.push_back(trajPt);
0044 }
0045
0046 const reco::PFTrajectoryPoint& PFTrack::extrapolatedPoint(unsigned layerid) const {
0047 const unsigned offset_layerid = nTrajectoryMeasurements() + layerid;
0048 if (layerid >= reco::PFTrajectoryPoint::NLayers || offset_layerid >= trajectoryPoints_.size()) {
0049 throw cms::Exception("SizeError") << "PFRecTrack::extrapolatedPoint: cannot access " << layerid
0050 << " #traj meas = " << nTrajectoryMeasurements()
0051 << " #traj points = " << trajectoryPoints_.size() << endl
0052 << (*this);
0053 }
0054 if (layerid < indexInnermost_)
0055 return trajectoryPoints_[layerid];
0056 else
0057 return trajectoryPoints_[offset_layerid];
0058 }
0059
0060 ostream& reco::operator<<(ostream& out, const PFTrack& track) {
0061 if (!out)
0062 return out;
0063
0064 const reco::PFTrajectoryPoint& closestApproach = track.trajectoryPoint(reco::PFTrajectoryPoint::ClosestApproach);
0065
0066 out << "Track charge = " << track.charge() << ", Pt = " << closestApproach.momentum().Pt()
0067 << ", P = " << closestApproach.momentum().P() << endl
0068 << "\tR0 = " << closestApproach.position().Rho() << " Z0 = " << closestApproach.position().Z() << endl
0069 << "\tnumber of tracker measurements = " << track.nTrajectoryMeasurements() << endl;
0070 for (unsigned i = 0; i < track.trajectoryPoints().size(); i++)
0071 out << track.trajectoryPoints()[i] << endl;
0072
0073 return out;
0074 }