CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoMuon/MuonIsolation/plugins/TrackExtractor.cc

Go to the documentation of this file.
00001 #include "TrackExtractor.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 using namespace edm;
00014 using namespace std;
00015 using namespace reco;
00016 using namespace muonisolation;
00017 using reco::isodeposit::Direction;
00018 
00019 TrackExtractor::TrackExtractor( const ParameterSet& par ) :
00020   theTrackCollectionTag(par.getParameter<edm::InputTag>("inputTrackCollection")),
00021   theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
00022   theDiff_r(par.getParameter<double>("Diff_r")),
00023   theDiff_z(par.getParameter<double>("Diff_z")),
00024   theDR_Max(par.getParameter<double>("DR_Max")),
00025   theDR_Veto(par.getParameter<double>("DR_Veto")),
00026   theBeamlineOption(par.getParameter<string>("BeamlineOption")),
00027   theBeamSpotLabel(par.getParameter<edm::InputTag>("BeamSpotLabel")),
00028   theNHits_Min(par.getParameter<unsigned int>("NHits_Min")),
00029   theChi2Ndof_Max(par.getParameter<double>("Chi2Ndof_Max")),
00030   theChi2Prob_Min(par.getParameter<double>("Chi2Prob_Min")),
00031   thePt_Min(par.getParameter<double>("Pt_Min"))
00032 {
00033 }
00034 
00035 reco::IsoDeposit::Vetos TrackExtractor::vetos(const edm::Event & ev,
00036       const edm::EventSetup & evSetup, const reco::Track & track) const
00037 {
00038   reco::isodeposit::Direction dir(track.eta(),track.phi());
00039   return reco::IsoDeposit::Vetos(1,veto(dir));
00040 }
00041 
00042 reco::IsoDeposit::Veto TrackExtractor::veto(const reco::IsoDeposit::Direction & dir) const
00043 {
00044   reco::IsoDeposit::Veto result;
00045   result.vetoDir = dir;
00046   result.dR = theDR_Veto;
00047   return result;
00048 }
00049 
00050 IsoDeposit TrackExtractor::deposit(const Event & event, const EventSetup & eventSetup, const Track & muon) const
00051 {
00052   static std::string metname = "MuonIsolation|TrackExtractor";
00053 
00054   reco::isodeposit::Direction muonDir(muon.eta(), muon.phi());
00055   IsoDeposit deposit(muonDir );
00056   deposit.setVeto( veto(muonDir) );
00057   deposit.addCandEnergy(muon.pt());
00058 
00059   Handle<View<Track> > tracksH;
00060   event.getByLabel(theTrackCollectionTag, tracksH);
00061   //  const TrackCollection tracks = *(tracksH.product());
00062   LogTrace(metname)<<"***** TRACK COLLECTION SIZE: "<<tracksH->size();
00063 
00064   double vtx_z = muon.vz();
00065   LogTrace(metname)<<"***** Muon vz: "<<vtx_z;
00066   reco::TrackBase::Point beamPoint(0,0, 0);
00067 
00068   if (theBeamlineOption.compare("BeamSpotFromEvent") == 0){
00069     //pick beamSpot
00070     reco::BeamSpot beamSpot;
00071     edm::Handle<reco::BeamSpot> beamSpotH;
00072 
00073     event.getByLabel(theBeamSpotLabel,beamSpotH);
00074 
00075     if (beamSpotH.isValid()){
00076       beamPoint = beamSpotH->position();
00077       LogTrace(metname)<<"Extracted beam point at "<<beamPoint<<std::endl;
00078     }
00079   }
00080 
00081   LogTrace(metname)<<"Using beam point at "<<beamPoint<<std::endl;
00082 
00083   TrackSelector::Parameters pars(TrackSelector::Range(vtx_z-theDiff_z, vtx_z+theDiff_z),
00084                                  theDiff_r, muonDir, theDR_Max, beamPoint);
00085 
00086   pars.nHitsMin = theNHits_Min;
00087   pars.chi2NdofMax = theChi2Ndof_Max;
00088   pars.chi2ProbMin = theChi2Prob_Min;
00089   pars.ptMin = thePt_Min;
00090 
00091   TrackSelector selection(pars);
00092   TrackSelector::result_type sel_tracks = selection(*tracksH);
00093   LogTrace(metname)<<"all tracks: "<<tracksH->size()<<" selected: "<<sel_tracks.size();
00094 
00095   
00096   TrackSelector::result_type::const_iterator tkI = sel_tracks.begin();
00097   for (; tkI != sel_tracks.end(); ++tkI) {
00098     const reco::Track* tk = *tkI;
00099     LogTrace(metname) << "This track has: pt= " << tk->pt() << ", eta= " 
00100         << tk->eta() <<", phi= "<<tk->phi();
00101     reco::isodeposit::Direction dirTrk(tk->eta(), tk->phi());
00102     deposit.addDeposit(dirTrk, tk->pt());
00103   }
00104 
00105   return deposit;
00106 }