CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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/EcalDetIdAssociator.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 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   
00068   // Now loop through the list of tracks and extrapolate them
00069   for ( std::vector<reco::TrackRef>::const_iterator trkBegin = goodTracks.begin(),
00070           trkEnd = goodTracks.end(), itrk = trkBegin; 
00071         itrk != trkEnd; ++itrk ) {
00072     std::vector<reco::TrackBase::Point>  vresultPos;
00073     std::vector<reco::TrackBase::Vector> vresultMom;
00074     std::vector<reco::TrackBase::Vector> vresultDir;
00075     std::vector<bool> visValid;
00076 
00077     reco::TrackBase::Point resultPos;
00078     reco::TrackBase::Vector resultMom;
00079     reco::TrackBase::Vector resultDir;
00080     bool isValid = propagateTrackToVolume( **itrk, *field_h, *propagator_h, ecalvolume,
00081                                            resultPos, resultMom, resultDir );
00082     visValid.push_back(isValid);
00083     vresultPos.push_back( resultPos );
00084     vresultMom.push_back( resultMom );
00085     vresultDir.push_back( resultDir );
00086 
00087     extrapolations->push_back( reco::TrackExtrapolation( *itrk, 
00088                                                          visValid, 
00089                                                          vresultPos, 
00090                                                          vresultMom, 
00091                                                          vresultDir ) );
00092   }
00093 
00094   iEvent.put( extrapolations );
00095 }
00096 
00097 // ------------ method called once each job just before starting event loop  ------------
00098 void 
00099 TrackExtrapolator::beginJob()
00100 {
00101 }
00102 
00103 // ------------ method called once each job just after ending the event loop  ------------
00104 void 
00105 TrackExtrapolator::endJob() {
00106 }
00107 
00108 
00109 
00110 
00111 // -----------------------------------------------------------------------------
00112 //
00113 bool TrackExtrapolator::propagateTrackToVolume( const reco::Track& fTrack,
00114                                                 const MagneticField& fField,
00115                                                 const Propagator& fPropagator,
00116                                                 const FiducialVolume& volume,
00117                                                 reco::TrackBase::Point & resultPos,
00118                                                 reco::TrackBase::Vector & resultMom,
00119                                                 reco::TrackBase::Vector & resultDir
00120                                                 )
00121 {
00122   GlobalPoint trackPosition (fTrack.vx(), fTrack.vy(), fTrack.vz()); // reference point
00123   GlobalVector trackMomentum (fTrack.px(), fTrack.py(), fTrack.pz()); // reference momentum
00124   if (fTrack.extra().isAvailable() ) { // use outer point information, if available
00125     trackPosition =  GlobalPoint (fTrack.outerX(), fTrack.outerY(), fTrack.outerZ());
00126     trackMomentum = GlobalVector (fTrack.outerPx(), fTrack.outerPy(), fTrack.outerPz());
00127   }
00128 
00129   GlobalTrajectoryParameters trackParams(trackPosition, trackMomentum, fTrack.charge(), &fField);
00130   FreeTrajectoryState trackState (trackParams);
00131 
00132   TrajectoryStateOnSurface 
00133     propagatedInfo = fPropagator.propagate (trackState, 
00134                                             *Cylinder::build (Surface::PositionType (0,0,0),
00135                                                               Surface::RotationType(),
00136                                                               volume.minR())
00137                                             );
00138 
00139   // if the track went through either side of the endcaps, repropagate the track
00140   double minz=volume.minZ();
00141   if(propagatedInfo.isValid() && propagatedInfo.globalPosition().z()>minz) {
00142     propagatedInfo = fPropagator.propagate (trackState, 
00143                                             *Plane::build (Surface::PositionType (0,0,minz),
00144                                                            Surface::RotationType())
00145                                             );
00146 
00147   } else if(propagatedInfo.isValid() && propagatedInfo.globalPosition().z()<-minz) {
00148     propagatedInfo = fPropagator.propagate (trackState, 
00149                                             *Plane::build (Surface::PositionType (0,0,-minz),
00150                                                            Surface::RotationType())
00151                                             );
00152   }
00153   
00154 
00155   if (propagatedInfo.isValid()) {
00156     resultPos = propagatedInfo.globalPosition ();
00157     resultMom = propagatedInfo.globalMomentum ();
00158     resultDir = propagatedInfo.globalDirection(); 
00159     return true;
00160   }
00161   else { 
00162     return false;
00163   }
00164 }
00165 
00166 
00167 
00168 
00169 //define this as a plug-in
00170 DEFINE_FWK_MODULE(TrackExtrapolator);