CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/RecoJets/JetAssociationProducers/src/TrackExtrapolator.cc

Go to the documentation of this file.
00001 #include "RecoJets/JetAssociationProducers/interface/TrackExtrapolator.h"
00002 #include "TrackingTools/TrackAssociator/interface/DetIdAssociator.h"
00003 
00004 
00005 #include <vector>
00006 
00007 
00008 //
00009 // constructors and destructor
00010 //
00011 TrackExtrapolator::TrackExtrapolator(const edm::ParameterSet& iConfig) :
00012   tracksSrc_(iConfig.getParameter<edm::InputTag> ("trackSrc"))
00013 {
00014   trackQuality_ = 
00015     reco::TrackBase::qualityByName (iConfig.getParameter<std::string> ("trackQuality"));
00016   if (trackQuality_ == reco::TrackBase::undefQuality) { // we have a problem
00017     throw cms::Exception("InvalidInput") << "Unknown trackQuality value '" 
00018                                          << iConfig.getParameter<std::string> ("trackQuality")
00019                                          << "'. See possible values in 'reco::TrackBase::qualityByName'";
00020   }
00021 
00022   produces< std::vector<reco::TrackExtrapolation> > ();
00023 }
00024 
00025 
00026 TrackExtrapolator::~TrackExtrapolator()
00027 {
00028 }
00029 
00030 
00031 //
00032 // member functions
00033 //
00034 
00035 // ------------ method called on each new Event  ------------
00036 void
00037 TrackExtrapolator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00038 {
00039 
00040   // get stuff from Event Setup
00041   edm::ESHandle<MagneticField> field_h;
00042   iSetup.get<IdealMagneticFieldRecord>().get(field_h);
00043   edm::ESHandle<Propagator> propagator_h;
00044   iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", propagator_h);
00045   edm::ESHandle<DetIdAssociator> ecalDetIdAssociator_h;
00046   iSetup.get<DetIdAssociatorRecord>().get("EcalDetIdAssociator", ecalDetIdAssociator_h);
00047   FiducialVolume const & ecalvolume = ecalDetIdAssociator_h->volume();
00048 
00049   // get stuff from Event
00050   edm::Handle <reco::TrackCollection> tracks_h;
00051   iEvent.getByLabel (tracksSrc_, tracks_h);
00052 
00053   std::auto_ptr< std::vector<reco::TrackExtrapolation> > extrapolations( new std::vector<reco::TrackExtrapolation>() );
00054 
00055   // Get list of tracks we want to extrapolate
00056   std::vector <reco::TrackRef> goodTracks;
00057   for ( reco::TrackCollection::const_iterator trkBegin = tracks_h->begin(),
00058           trkEnd = tracks_h->end(), itrk = trkBegin;
00059         itrk != trkEnd; ++itrk ) {
00060     reco::TrackBase::TrackQuality trackQuality = reco::TrackBase::TrackQuality (trackQuality_);
00061 
00062     // Cut on track quality
00063     if (itrk->quality (trackQuality)) {
00064       goodTracks.push_back (reco::TrackRef (tracks_h, itrk - trkBegin));
00065     }
00066   }
00067   std::vector<reco::TrackBase::Point>  vresultPos(1);
00068   std::vector<reco::TrackBase::Vector> vresultMom(1);
00069   
00070 
00071   // Now loop through the list of tracks and extrapolate them
00072   for ( std::vector<reco::TrackRef>::const_iterator trkBegin = goodTracks.begin(),
00073           trkEnd = goodTracks.end(), itrk = trkBegin; 
00074         itrk != trkEnd; ++itrk ) {
00075     if( propagateTrackToVolume( **itrk, *field_h, *propagator_h, ecalvolume,
00076                                 vresultPos[0], vresultMom[0]) ) {
00077       extrapolations->push_back( reco::TrackExtrapolation( *itrk, 
00078                                                            vresultPos, 
00079                                                            vresultMom ) );
00080     }
00081   }
00082   iEvent.put( extrapolations );
00083 }
00084 
00085 // ------------ method called once each job just before starting event loop  ------------
00086 void 
00087 TrackExtrapolator::beginJob()
00088 {
00089 }
00090 
00091 // ------------ method called once each job just after ending the event loop  ------------
00092 void 
00093 TrackExtrapolator::endJob() {
00094 }
00095 
00096 
00097 
00098 
00099 // -----------------------------------------------------------------------------
00100 //
00101 bool TrackExtrapolator::propagateTrackToVolume( const reco::Track& fTrack,
00102                                                 const MagneticField& fField,
00103                                                 const Propagator& fPropagator,
00104                                                 const FiducialVolume& volume,
00105                                                 reco::TrackBase::Point & resultPos,
00106                                                 reco::TrackBase::Vector & resultMom
00107                                                 )
00108 {
00109   GlobalPoint trackPosition (fTrack.vx(), fTrack.vy(), fTrack.vz()); // reference point
00110   GlobalVector trackMomentum (fTrack.px(), fTrack.py(), fTrack.pz()); // reference momentum
00111   if (fTrack.extra().isAvailable() ) { // use outer point information, if available
00112     trackPosition =  GlobalPoint (fTrack.outerX(), fTrack.outerY(), fTrack.outerZ());
00113     trackMomentum = GlobalVector (fTrack.outerPx(), fTrack.outerPy(), fTrack.outerPz());
00114   }
00115 
00116   GlobalTrajectoryParameters trackParams(trackPosition, trackMomentum, fTrack.charge(), &fField);
00117   FreeTrajectoryState trackState (trackParams);
00118 
00119   TrajectoryStateOnSurface 
00120     propagatedInfo = fPropagator.propagate (trackState, 
00121                                             *Cylinder::build (Surface::PositionType (0,0,0),
00122                                                               Surface::RotationType(),
00123                                                               volume.minR())
00124                                             );
00125 
00126   // if the track went through either side of the endcaps, repropagate the track
00127   double minz=volume.minZ();
00128   if(propagatedInfo.isValid() && propagatedInfo.globalPosition().z()>minz) {
00129     propagatedInfo = fPropagator.propagate (trackState, 
00130                                             *Plane::build (Surface::PositionType (0,0,minz),
00131                                                            Surface::RotationType())
00132                                             );
00133 
00134   } else if(propagatedInfo.isValid() && propagatedInfo.globalPosition().z()<-minz) {
00135     propagatedInfo = fPropagator.propagate (trackState, 
00136                                             *Plane::build (Surface::PositionType (0,0,-minz),
00137                                                            Surface::RotationType())
00138                                             );
00139   }
00140   
00141 
00142   if (propagatedInfo.isValid()) {
00143     resultPos = propagatedInfo.globalPosition ();
00144     resultMom = propagatedInfo.globalMomentum ();
00145     return true;
00146   }
00147   else { 
00148     return false;
00149   }
00150 }
00151 
00152 
00153 
00154 
00155 //define this as a plug-in
00156 DEFINE_FWK_MODULE(TrackExtrapolator);