CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackExtrapolator.cc
Go to the documentation of this file.
3 
4 
5 #include <vector>
6 
7 
8 //
9 // constructors and destructor
10 //
12 {
13  tracksSrc_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackSrc"));
14  trackQuality_ =
15  reco::TrackBase::qualityByName (iConfig.getParameter<std::string> ("trackQuality"));
16  if (trackQuality_ == reco::TrackBase::undefQuality) { // we have a problem
17  throw cms::Exception("InvalidInput") << "Unknown trackQuality value '"
18  << iConfig.getParameter<std::string> ("trackQuality")
19  << "'. See possible values in 'reco::TrackBase::qualityByName'";
20  }
21 
22  produces< std::vector<reco::TrackExtrapolation> > ();
23 }
24 
25 
27 {
28 }
29 
30 
31 //
32 // member functions
33 //
34 
35 // ------------ method called on each new Event ------------
36 void
38 {
39 
40  // get stuff from Event Setup
42  iSetup.get<IdealMagneticFieldRecord>().get(field_h);
43  edm::ESHandle<Propagator> propagator_h;
44  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", propagator_h);
45  edm::ESHandle<DetIdAssociator> ecalDetIdAssociator_h;
46  iSetup.get<DetIdAssociatorRecord>().get("EcalDetIdAssociator", ecalDetIdAssociator_h);
47  FiducialVolume const & ecalvolume = ecalDetIdAssociator_h->volume();
48 
49  // get stuff from Event
51  iEvent.getByToken (tracksSrc_, tracks_h);
52 
53  std::auto_ptr< std::vector<reco::TrackExtrapolation> > extrapolations( new std::vector<reco::TrackExtrapolation>() );
54 
55  // Get list of tracks we want to extrapolate
56  std::vector <reco::TrackRef> goodTracks;
57  for ( reco::TrackCollection::const_iterator trkBegin = tracks_h->begin(),
58  trkEnd = tracks_h->end(), itrk = trkBegin;
59  itrk != trkEnd; ++itrk ) {
61 
62  // Cut on track quality
63  if (itrk->quality (trackQuality)) {
64  goodTracks.push_back (reco::TrackRef (tracks_h, itrk - trkBegin));
65  }
66  }
67  std::vector<reco::TrackBase::Point> vresultPos(1);
68  std::vector<reco::TrackBase::Vector> vresultMom(1);
69 
70 
71  // Now loop through the list of tracks and extrapolate them
72  for ( std::vector<reco::TrackRef>::const_iterator trkBegin = goodTracks.begin(),
73  trkEnd = goodTracks.end(), itrk = trkBegin;
74  itrk != trkEnd; ++itrk ) {
75  if( propagateTrackToVolume( **itrk, *field_h, *propagator_h, ecalvolume,
76  vresultPos[0], vresultMom[0]) ) {
77  extrapolations->push_back( reco::TrackExtrapolation( *itrk,
78  vresultPos,
79  vresultMom ) );
80  }
81  }
82  iEvent.put( extrapolations );
83 }
84 
85 // -----------------------------------------------------------------------------
86 //
88  const MagneticField& fField,
89  const Propagator& fPropagator,
90  const FiducialVolume& volume,
91  reco::TrackBase::Point & resultPos,
92  reco::TrackBase::Vector & resultMom
93  )
94 {
95  GlobalPoint trackPosition (fTrack.vx(), fTrack.vy(), fTrack.vz()); // reference point
96  GlobalVector trackMomentum (fTrack.px(), fTrack.py(), fTrack.pz()); // reference momentum
97  if (fTrack.extra().isAvailable() ) { // use outer point information, if available
98  trackPosition = GlobalPoint (fTrack.outerX(), fTrack.outerY(), fTrack.outerZ());
99  trackMomentum = GlobalVector (fTrack.outerPx(), fTrack.outerPy(), fTrack.outerPz());
100  }
101 
102  GlobalTrajectoryParameters trackParams(trackPosition, trackMomentum, fTrack.charge(), &fField);
103  FreeTrajectoryState trackState (trackParams);
104 
106  propagatedInfo = fPropagator.propagate (trackState,
107  *Cylinder::build (volume.minR(), Surface::PositionType (0,0,0),
109  )
110  );
111 
112  // if the track went through either side of the endcaps, repropagate the track
113  double minz=volume.minZ();
114  if(propagatedInfo.isValid() && propagatedInfo.globalPosition().z()>minz) {
115  propagatedInfo = fPropagator.propagate (trackState,
116  *Plane::build (Surface::PositionType (0,0,minz),
118  );
119 
120  } else if(propagatedInfo.isValid() && propagatedInfo.globalPosition().z()<-minz) {
121  propagatedInfo = fPropagator.propagate (trackState,
122  *Plane::build (Surface::PositionType (0,0,-minz),
124  );
125  }
126 
127 
128  if (propagatedInfo.isValid()) {
129  resultPos = propagatedInfo.globalPosition ();
130  resultMom = propagatedInfo.globalMomentum ();
131  return true;
132  }
133  else {
134  return false;
135  }
136 }
137 
138 
139 
140 
141 //define this as a plug-in
bool isAvailable() const
Definition: Ref.h:576
T getParameter(std::string const &) const
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
TrackExtrapolator(const edm::ParameterSet &)
double outerPy() const
y coordinate of momentum vector at the outermost hit position
Definition: Track.h:129
const TrackExtraRef & extra() const
reference to &quot;extra&quot; object
Definition: Track.h:189
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
TrackQuality
track quality
Definition: TrackBase.h:149
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
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
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:614
double minZ(bool withTolerance=true) const
double outerZ() const
z coordinate of the outermost hit position
Definition: Track.h:149
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, Bounds *bounds=0)
Definition: Cylinder.h:51
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
T z() const
Definition: PV3DBase.h:64
double outerX() const
x coordinate of the outermost hit position
Definition: Track.h:139
math::XYZPoint Point
point in the space
Definition: TrackBase.h:83
double outerPz() const
z coordinate of momentum vector at the outermost hit position
Definition: Track.h:134
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:626
double minR(bool withTolerance=true) const
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:656
reco::TrackBase::TrackQuality trackQuality_
Input tracks.
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:123
const T & get() const
Definition: EventSetup.h:56
Point3DBase< float, GlobalTag > PositionType
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:650
GlobalVector globalMomentum() const
TkRotation< float > RotationType
double outerY() const
y coordinate of the outermost hit position
Definition: Track.h:144
int charge() const
track electric charge
Definition: TrackBase.h:554
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::TrackCollection > tracksSrc_
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:80
double outerPx() const
x coordinate of momentum vector at the outermost hit position
Definition: Track.h:124
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:620
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:644
Global3DVector GlobalVector
Definition: GlobalVector.h:10