CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoMuon/MuonIsolation/plugins/PixelTrackExtractor.cc

Go to the documentation of this file.
00001 #include "PixelTrackExtractor.h"
00002 
00003 #include "RecoMuon/MuonIsolation/interface/Range.h"
00004 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00005 #include "TrackSelector.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "DataFormats/Common/interface/View.h"
00008 #include "DataFormats/TrackReco/interface/Track.h"
00009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00012 
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "MagneticField/Engine/interface/MagneticField.h"
00015 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00016 
00017 
00018 using namespace edm;
00019 using namespace std;
00020 using namespace reco;
00021 using namespace muonisolation;
00022 using reco::isodeposit::Direction;
00023 
00024 PixelTrackExtractor::PixelTrackExtractor( const ParameterSet& par ) :
00025   theTrackCollectionTag(par.getParameter<edm::InputTag>("inputTrackCollection")),
00026   theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
00027   theDiff_r(par.getParameter<double>("Diff_r")),
00028   theDiff_z(par.getParameter<double>("Diff_z")),
00029   theDR_Max(par.getParameter<double>("DR_Max")),
00030   theDR_Veto(par.getParameter<double>("DR_Veto")),
00031   theBeamlineOption(par.getParameter<string>("BeamlineOption")),
00032   theBeamSpotLabel(par.getParameter<edm::InputTag>("BeamSpotLabel")),
00033   theNHits_Min(par.getParameter<unsigned int>("NHits_Min")),
00034   theChi2Ndof_Max(par.getParameter<double>("Chi2Ndof_Max")),
00035   theChi2Prob_Min(par.getParameter<double>("Chi2Prob_Min")),
00036   thePt_Min(par.getParameter<double>("Pt_Min")),
00037   thePropagateTracksToRadius(par.getParameter<bool>("PropagateTracksToRadius")),
00038   theReferenceRadius(par.getParameter<double>("ReferenceRadius")),
00039   theVetoLeadingTrack(par.getParameter<bool>("VetoLeadingTrack")), 
00040   thePtVeto_Min(par.getParameter<double>("PtVeto_Min")),           
00041   theDR_VetoPt(par.getParameter<double>("DR_VetoPt"))              
00042 {
00043 }
00044 
00045 reco::IsoDeposit::Vetos PixelTrackExtractor::vetos(const edm::Event & ev,
00046       const edm::EventSetup & evSetup, const reco::Track & track) const
00047 {
00048   Direction dir(track.eta(),track.phi());
00049   return reco::IsoDeposit::Vetos(1,veto(dir));
00050 }
00051 
00052 reco::IsoDeposit::Veto PixelTrackExtractor::veto(const Direction & dir) const
00053 {
00054   reco::IsoDeposit::Veto result;
00055   result.vetoDir = dir;
00056   result.dR = theDR_Veto;
00057   return result;
00058 }
00059 
00060 Direction PixelTrackExtractor::directionAtPresetRadius(const Track& tk, double bz) const {
00061   if (! thePropagateTracksToRadius ){
00062     return Direction(tk.eta(), tk.phi());
00063   }
00064 
00065   // this should represent a cylinder in global frame at R=refRadius cm, roughly where mid-layer of pixels is
00066   double psRadius = theReferenceRadius;
00067   double tkDxy = tk.dxy();
00068   double s2D = fabs(tk.dxy()) < psRadius ? sqrt(psRadius*psRadius - tkDxy*tkDxy) : 0;
00069 
00070   // the field we get from the caller is already in units of GeV/cm
00071   double dPhi = -s2D*tk.charge()*bz/tk.pt();
00072 
00073   return Direction(tk.eta(), tk.phi()+dPhi);
00074 }
00075 
00076 IsoDeposit PixelTrackExtractor::deposit(const Event & event, const EventSetup & eventSetup, const Track & muon) const
00077 {
00078   static std::string metname = "MuonIsolation|PixelTrackExtractor";
00079 
00080   edm::ESHandle<MagneticField> bField;
00081   eventSetup.get<IdealMagneticFieldRecord>().get(bField);
00082   double bz = bField->inInverseGeV(GlobalPoint(0.,0.,0.)).z();
00083 
00084   Direction muonDir(directionAtPresetRadius(muon, bz));
00085   IsoDeposit deposit(muonDir );
00087   deposit.setVeto( veto(muonDir) );
00088 
00089   deposit.addCandEnergy(muon.pt());
00090 
00091   Handle<View<Track> > tracksH;
00092   event.getByLabel(theTrackCollectionTag, tracksH);
00093   //  const TrackCollection tracks = *(tracksH.product());
00094   LogTrace(metname)<<"***** TRACK COLLECTION SIZE: "<<tracksH->size();
00095 
00096   double vtx_z = muon.vz();
00097   LogTrace(metname)<<"***** Muon vz: "<<vtx_z;
00098   reco::TrackBase::Point beamPoint(0,0, 0);
00099 
00100   if (theBeamlineOption.compare("BeamSpotFromEvent") == 0){
00101     //pick beamSpot
00102     reco::BeamSpot beamSpot;
00103     edm::Handle<reco::BeamSpot> beamSpotH;
00104 
00105     event.getByLabel(theBeamSpotLabel,beamSpotH);
00106 
00107     if (beamSpotH.isValid()){
00108       beamPoint = beamSpotH->position();
00109       LogTrace(metname)<<"Extracted beam point at "<<beamPoint<<std::endl;
00110     }
00111   }
00112 
00113   LogTrace(metname)<<"Using beam point at "<<beamPoint<<std::endl;
00114 
00115   TrackSelector::Parameters pars(TrackSelector::Range(vtx_z-theDiff_z, vtx_z+theDiff_z),
00116                                  theDiff_r, muonDir, theDR_Max, beamPoint);
00117 
00118   pars.nHitsMin = theNHits_Min;
00119   pars.chi2NdofMax = theChi2Ndof_Max;
00120   pars.chi2ProbMin = theChi2Prob_Min;
00121   pars.ptMin = thePt_Min;
00122 
00123   TrackSelector selection(pars);
00124   TrackSelector::result_type sel_tracks = selection(*tracksH);
00125   LogTrace(metname)<<"all tracks: "<<tracksH->size()<<" selected: "<<sel_tracks.size();
00126 
00127   
00128   double maxPt = -1;
00129   Direction maxPtDir;
00130   TrackSelector::result_type::const_iterator tkI = sel_tracks.begin();
00131   for (; tkI != sel_tracks.end(); ++tkI) {
00132     const reco::Track* tk = *tkI;
00133     LogTrace(metname) << "This track has: pt= " << tk->pt() << ", eta= " 
00134         << tk->eta() <<", phi= "<<tk->phi();
00135     Direction dirTrk(directionAtPresetRadius(*tk, bz));
00136     deposit.addDeposit(dirTrk, tk->pt());
00137     double tkDr = (muonDir-dirTrk).deltaR;
00138     double tkPt = tk->pt();
00139     if (theVetoLeadingTrack && tkPt > thePtVeto_Min 
00140         && tkDr < theDR_VetoPt  
00141         && maxPt < tkPt ){
00142       maxPt = tkPt;
00143       maxPtDir = dirTrk;
00144     }
00145   }
00146   if (maxPt > 0){
00147     deposit.setVeto(veto(maxPtDir));
00148     LogTrace(metname)<<" Set track veto the leading track with pt "
00149                      <<maxPt<<" in direction  (eta,phi) "
00150                      <<maxPtDir.eta()<<", "<<maxPtDir.phi();
00151   }
00152 
00153   return deposit;
00154 }