CMS 3D CMS Logo

TrackExtrapolator.cc
Go to the documentation of this file.
2 
3 #include <vector>
4 
5 //
6 // constructors and destructor
7 //
9  : tracksSrc_(consumes(iConfig.getParameter<edm::InputTag>("trackSrc"))),
10  fieldToken_(esConsumes()),
11  propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAlong"))),
12  ecalDetIdAssociatorToken_(esConsumes(edm::ESInputTag("", "EcalDetIdAssociator"))),
13  trackQuality_(reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("trackQuality"))) {
14  if (trackQuality_ == reco::TrackBase::undefQuality) { // we have a problem
15  throw cms::Exception("InvalidInput") << "Unknown trackQuality value '"
16  << iConfig.getParameter<std::string>("trackQuality")
17  << "'. See possible values in 'reco::TrackBase::qualityByName'";
18  }
19 
20  produces<std::vector<reco::TrackExtrapolation>>();
21 }
22 
24 
25 //
26 // member functions
27 //
28 
29 // ------------ method called on each new Event ------------
31  // get stuff from Event Setup
32  auto const& field = iSetup.getData(fieldToken_);
33  auto const& propagator = iSetup.getData(propagatorToken_);
34  FiducialVolume const& ecalvolume = iSetup.getData(ecalDetIdAssociatorToken_).volume();
35 
36  // get stuff from Event
38  iEvent.getByToken(tracksSrc_, tracks_h);
39 
40  auto extrapolations = std::make_unique<std::vector<reco::TrackExtrapolation>>();
41 
42  // Get list of tracks we want to extrapolate
43  std::vector<reco::TrackRef> goodTracks;
44  for (reco::TrackCollection::const_iterator trkBegin = tracks_h->begin(), trkEnd = tracks_h->end(), itrk = trkBegin;
45  itrk != trkEnd;
46  ++itrk) {
48 
49  // Cut on track quality
50  if (itrk->quality(trackQuality)) {
51  goodTracks.push_back(reco::TrackRef(tracks_h, itrk - trkBegin));
52  }
53  }
54  std::vector<reco::TrackBase::Point> vresultPos(1);
55  std::vector<reco::TrackBase::Vector> vresultMom(1);
56 
57  // Now loop through the list of tracks and extrapolate them
58  for (std::vector<reco::TrackRef>::const_iterator trkBegin = goodTracks.begin(),
59  trkEnd = goodTracks.end(),
60  itrk = trkBegin;
61  itrk != trkEnd;
62  ++itrk) {
63  if (propagateTrackToVolume(**itrk, field, propagator, ecalvolume, vresultPos[0], vresultMom[0])) {
64  extrapolations->push_back(reco::TrackExtrapolation(*itrk, vresultPos, vresultMom));
65  }
66  }
68 }
69 
70 // -----------------------------------------------------------------------------
71 //
73  const MagneticField& fField,
74  const Propagator& fPropagator,
75  const FiducialVolume& volume,
76  reco::TrackBase::Point& resultPos,
77  reco::TrackBase::Vector& resultMom) {
78  GlobalPoint trackPosition(fTrack.vx(), fTrack.vy(), fTrack.vz()); // reference point
79  GlobalVector trackMomentum(fTrack.px(), fTrack.py(), fTrack.pz()); // reference momentum
80  if (fTrack.extra().isAvailable()) { // use outer point information, if available
81  trackPosition = GlobalPoint(fTrack.outerX(), fTrack.outerY(), fTrack.outerZ());
82  trackMomentum = GlobalVector(fTrack.outerPx(), fTrack.outerPy(), fTrack.outerPz());
83  }
84 
85  GlobalTrajectoryParameters trackParams(trackPosition, trackMomentum, fTrack.charge(), &fField);
86  FreeTrajectoryState trackState(trackParams);
87 
88  TrajectoryStateOnSurface propagatedInfo = fPropagator.propagate(
89  trackState, *Cylinder::build(volume.minR(), Surface::PositionType(0, 0, 0), Surface::RotationType()));
90 
91  // if the track went through either side of the endcaps, repropagate the track
92  double minz = volume.minZ();
93  if (propagatedInfo.isValid() && propagatedInfo.globalPosition().z() > minz) {
94  propagatedInfo =
95  fPropagator.propagate(trackState, *Plane::build(Surface::PositionType(0, 0, minz), Surface::RotationType()));
96 
97  } else if (propagatedInfo.isValid() && propagatedInfo.globalPosition().z() < -minz) {
98  propagatedInfo =
99  fPropagator.propagate(trackState, *Plane::build(Surface::PositionType(0, 0, -minz), Surface::RotationType()));
100  }
101 
102  if (propagatedInfo.isValid()) {
103  resultPos = propagatedInfo.globalPosition();
104  resultMom = propagatedInfo.globalMomentum();
105  return true;
106  } else {
107  return false;
108  }
109 }
110 
111 //define this as a plug-in
double outerY() const
y coordinate of the outermost hit position
Definition: Track.h:112
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > fieldToken_
Input tracks.
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
TrackExtrapolator(const edm::ParameterSet &)
double outerX() const
x coordinate of the outermost hit position
Definition: Track.h:109
double outerPy() const
y coordinate of momentum vector at the outermost hit position
Definition: Track.h:103
Quality qualityByName(std::string const &name)
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:655
T z() const
Definition: PV3DBase.h:61
TrackQuality
track quality
Definition: TrackBase.h:150
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:640
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:643
bool propagateTrackToVolume(const reco::Track &fTrack, const MagneticField &fField, const Propagator &fPropagator, const FiducialVolume &volume, reco::TrackBase::Point &resultPos, reco::TrackBase::Vector &resultMom)
track quality of the tracks we care about
const edm::EDGetTokenT< reco::TrackCollection > tracksSrc_
double outerZ() const
z coordinate of the outermost hit position
Definition: Track.h:115
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
static PlanePointer build(Args &&... args)
Definition: Plane.h:33
const edm::ESGetToken< DetIdAssociator, DetIdAssociatorRecord > ecalDetIdAssociatorToken_
int charge() const
track electric charge
Definition: TrackBase.h:596
int iEvent
Definition: GenABIO.cc:224
GlobalPoint globalPosition() const
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:661
bool isAvailable() const
Definition: Ref.h:535
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
Point3DBase< float, GlobalTag > PositionType
double outerPz() const
z coordinate of momentum vector at the outermost hit position
Definition: Track.h:106
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, Bounds *bounds=nullptr)
Definition: Cylinder.h:45
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:646
~TrackExtrapolator() override
constexpr float minz[nPairs]
GlobalVector globalMomentum() const
fixed size matrix
HLT enums.
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:658
TkRotation< float > RotationType
double outerPx() const
x coordinate of momentum vector at the outermost hit position
Definition: Track.h:100
double minR(bool withTolerance=true) const
void produce(edm::Event &, const edm::EventSetup &) override
const reco::TrackBase::TrackQuality trackQuality_
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:77
def move(src, dest)
Definition: eostools.py:511
double minZ(bool withTolerance=true) const
Global3DVector GlobalVector
Definition: GlobalVector.h:10
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:139