File indexing completed on 2023-03-17 11:20:38
0001 #include "TrackExtractor.h"
0002
0003 #include "RecoMuon/MuonIsolation/interface/Range.h"
0004 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
0005 #include "TrackSelector.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008
0009 using namespace edm;
0010 using namespace std;
0011 using namespace reco;
0012 using namespace muonisolation;
0013 using reco::isodeposit::Direction;
0014
0015 TrackExtractor::TrackExtractor(const ParameterSet& par, edm::ConsumesCollector&& iC)
0016 : theTrackCollectionToken(iC.consumes<TrackCollection>(par.getParameter<edm::InputTag>("inputTrackCollection"))),
0017 theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
0018 theDiff_r(par.getParameter<double>("Diff_r")),
0019 theDiff_z(par.getParameter<double>("Diff_z")),
0020 theDR_Max(par.getParameter<double>("DR_Max")),
0021 theDR_Veto(par.getParameter<double>("DR_Veto")),
0022 theBeamlineOption(par.getParameter<string>("BeamlineOption")),
0023 theBeamSpotToken(iC.consumes<reco::BeamSpot>(par.getParameter<edm::InputTag>("BeamSpotLabel"))),
0024 theNHits_Min(par.getParameter<unsigned int>("NHits_Min")),
0025 theChi2Ndof_Max(par.getParameter<double>("Chi2Ndof_Max")),
0026 theChi2Prob_Min(par.getParameter<double>("Chi2Prob_Min")),
0027 thePt_Min(par.getParameter<double>("Pt_Min")) {}
0028
0029 reco::IsoDeposit::Vetos TrackExtractor::vetos(const edm::Event& ev,
0030 const edm::EventSetup& evSetup,
0031 const reco::Track& track) const {
0032 reco::isodeposit::Direction dir(track.eta(), track.phi());
0033 return reco::IsoDeposit::Vetos(1, veto(dir));
0034 }
0035
0036 reco::IsoDeposit::Veto TrackExtractor::veto(const reco::IsoDeposit::Direction& dir) const {
0037 reco::IsoDeposit::Veto result;
0038 result.vetoDir = dir;
0039 result.dR = theDR_Veto;
0040 return result;
0041 }
0042
0043 IsoDeposit TrackExtractor::deposit(const Event& event, const EventSetup& eventSetup, const Track& muon) const {
0044 static const std::string metname = "MuonIsolation|TrackExtractor";
0045
0046 reco::isodeposit::Direction muonDir(muon.eta(), muon.phi());
0047 IsoDeposit deposit(muonDir);
0048 deposit.setVeto(veto(muonDir));
0049 deposit.addCandEnergy(muon.pt());
0050
0051 Handle<TrackCollection> tracksH;
0052 event.getByToken(theTrackCollectionToken, tracksH);
0053
0054 LogTrace(metname) << "***** TRACK COLLECTION SIZE: " << tracksH->size();
0055
0056 double vtx_z = muon.vz();
0057 LogTrace(metname) << "***** Muon vz: " << vtx_z;
0058 reco::TrackBase::Point beamPoint(0, 0, 0);
0059
0060 if (theBeamlineOption == "BeamSpotFromEvent") {
0061
0062 reco::BeamSpot beamSpot;
0063 edm::Handle<reco::BeamSpot> beamSpotH;
0064
0065 event.getByToken(theBeamSpotToken, beamSpotH);
0066
0067 if (beamSpotH.isValid()) {
0068 beamPoint = beamSpotH->position();
0069 LogTrace(metname) << "Extracted beam point at " << beamPoint << std::endl;
0070 }
0071 }
0072
0073 LogTrace(metname) << "Using beam point at " << beamPoint << std::endl;
0074
0075 TrackSelector::Parameters pars(
0076 TrackSelector::Range(vtx_z - theDiff_z, vtx_z + theDiff_z), theDiff_r, muonDir, theDR_Max, beamPoint);
0077
0078 pars.nHitsMin = theNHits_Min;
0079 pars.chi2NdofMax = theChi2Ndof_Max;
0080 pars.chi2ProbMin = theChi2Prob_Min;
0081 pars.ptMin = thePt_Min;
0082
0083 TrackSelector selection(pars);
0084 TrackSelector::result_type sel_tracks = selection(*tracksH);
0085 LogTrace(metname) << "all tracks: " << tracksH->size() << " selected: " << sel_tracks.size();
0086
0087 TrackSelector::result_type::const_iterator tkI = sel_tracks.begin();
0088 for (; tkI != sel_tracks.end(); ++tkI) {
0089 const reco::Track* tk = *tkI;
0090 LogTrace(metname) << "This track has: pt= " << tk->pt() << ", eta= " << tk->eta() << ", phi= " << tk->phi();
0091 reco::isodeposit::Direction dirTrk(tk->eta(), tk->phi());
0092 deposit.addDeposit(dirTrk, tk->pt());
0093 }
0094
0095 return deposit;
0096 }