Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-02 03:45:56

0001 #include "DataFormats/Candidate/interface/Candidate.h"
0002 #include "DataFormats/Common/interface/Handle.h"
0003 #include "DataFormats/Math/interface/deltaR.h"
0004 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0005 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
0006 #include "DataFormats/TrackReco/interface/Track.h"
0007 #include "FWCore/Framework/interface/ConsumesCollector.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0010 
0011 #include <string>
0012 #include <vector>
0013 
0014 namespace muonisolation {
0015 
0016   class CandViewExtractor : public reco::isodeposit::IsoDepositExtractor {
0017   public:
0018     CandViewExtractor(){};
0019     CandViewExtractor(const edm::ParameterSet& par, edm::ConsumesCollector&& iC);
0020 
0021     ~CandViewExtractor() override {}
0022 
0023     void fillVetos(const edm::Event& ev, const edm::EventSetup& evSetup, const reco::TrackCollection& cand) override {}
0024 
0025     /*  virtual reco::IsoDeposit::Vetos vetos(const edm::Event & ev,
0026       const edm::EventSetup & evSetup, const reco::Candidate & cand) const;
0027 
0028   virtual reco::IsoDeposit::Vetos vetos(const edm::Event & ev,
0029       const edm::EventSetup & evSetup, const reco::Track & cand) const;
0030 */
0031 
0032     void initEvent(const edm::Event& ev, const edm::EventSetup& evSetup) override;
0033 
0034     reco::IsoDeposit deposit(const edm::Event& ev,
0035                              const edm::EventSetup& evSetup,
0036                              const reco::Track& muon) const override {
0037       return depositFromObject(ev, evSetup, muon);
0038     }
0039 
0040     reco::IsoDeposit deposit(const edm::Event& ev,
0041                              const edm::EventSetup& evSetup,
0042                              const reco::Candidate& muon) const override {
0043       return depositFromObject(ev, evSetup, muon);
0044     }
0045 
0046   private:
0047     reco::IsoDeposit::Veto veto(const reco::IsoDeposit::Direction& dir) const;
0048 
0049     template <typename T>
0050     reco::IsoDeposit depositFromObject(const edm::Event& ev, const edm::EventSetup& evSetup, const T& cand) const;
0051 
0052     // Parameter set
0053     edm::EDGetTokenT<edm::View<reco::Candidate> > theCandViewToken;  // Track Collection Label
0054     std::string theDepositLabel;                                     // name for deposit
0055     edm::Handle<edm::View<reco::Candidate> > theCandViewH;           //cached handle
0056     edm::Event::CacheIdentifier_t theCacheID;                        //event cacheID
0057     double theDiff_r;                                                // transverse distance to vertex
0058     double theDiff_z;                                                // z distance to vertex
0059     double theDR_Max;                                                // Maximum cone angle for deposits
0060     double theDR_Veto;                                               // Veto cone angle
0061   };
0062 
0063 }  // namespace muonisolation
0064 
0065 using namespace edm;
0066 using namespace reco;
0067 using namespace muonisolation;
0068 
0069 template <typename T>
0070 IsoDeposit CandViewExtractor::depositFromObject(const Event& event, const EventSetup& eventSetup, const T& cand) const {
0071   static const std::string metname = "MuonIsolation|CandViewExtractor";
0072 
0073   reco::isodeposit::Direction candDir(cand.eta(), cand.phi());
0074   IsoDeposit deposit(candDir);
0075   deposit.setVeto(veto(candDir));
0076   deposit.addCandEnergy(cand.pt());
0077 
0078   Handle<View<Candidate> > candViewH;
0079   if (theCacheID != event.cacheIdentifier()) {
0080     event.getByToken(theCandViewToken, candViewH);
0081   } else {
0082     candViewH = theCandViewH;
0083   }
0084 
0085   double eta = cand.eta(), phi = cand.phi();
0086   const reco::Particle::Point& vtx = cand.vertex();
0087   LogDebug(metname) << "cand eta=" << eta << " phi=" << phi << " vtx=" << vtx;
0088   for (View<Candidate>::const_iterator it = candViewH->begin(), ed = candViewH->end(); it != ed; ++it) {
0089     double dR = deltaR(it->eta(), it->phi(), eta, phi);
0090     LogDebug(metname) << "pdgid=" << it->pdgId() << " vtx=" << it->vertex() << " dR=" << dR
0091                       << " dvz=" << it->vz() - cand.vz() << " drho=" << (it->vertex() - vtx).Rho();
0092     if ((dR < theDR_Max) && (dR > theDR_Veto) && (std::abs(it->vz() - cand.vz()) < theDiff_z) &&
0093         ((it->vertex() - vtx).Rho() < theDiff_r)) {
0094       // ok
0095       reco::isodeposit::Direction dirTrk(it->eta(), it->phi());
0096       deposit.addDeposit(dirTrk, it->pt());
0097       LogDebug(metname) << "pt=" << it->pt();
0098     }
0099   }
0100 
0101   return deposit;
0102 }
0103 
0104 CandViewExtractor::CandViewExtractor(const ParameterSet& par, edm::ConsumesCollector&& iC)
0105     : theCandViewToken(iC.consumes<View<Candidate> >(par.getParameter<edm::InputTag>("inputCandView"))),
0106       theDepositLabel(par.getUntrackedParameter<std::string>("DepositLabel")),
0107       theDiff_r(par.getParameter<double>("Diff_r")),
0108       theDiff_z(par.getParameter<double>("Diff_z")),
0109       theDR_Max(par.getParameter<double>("DR_Max")),
0110       theDR_Veto(par.getParameter<double>("DR_Veto")) {}
0111 /*
0112 reco::IsoDeposit::Vetos CandViewExtractor::vetos(const edm::Event & ev,
0113       const edm::EventSetup & evSetup, const reco::Candidate & cand) const
0114 {
0115   reco::isodeposit::Direction dir(cand.eta(),cand.phi());
0116   return reco::IsoDeposit::Vetos(1,veto(dir));
0117 }
0118 */
0119 
0120 reco::IsoDeposit::Veto CandViewExtractor::veto(const reco::IsoDeposit::Direction& dir) const {
0121   reco::IsoDeposit::Veto result;
0122   result.vetoDir = dir;
0123   result.dR = theDR_Veto;
0124   return result;
0125 }
0126 
0127 void CandViewExtractor::initEvent(const edm::Event& ev, const edm::EventSetup& evSetup) {
0128   ev.getByToken(theCandViewToken, theCandViewH);
0129   theCacheID = ev.cacheIdentifier();
0130 }
0131 
0132 #include "FWCore/PluginManager/interface/ModuleDef.h"
0133 #include "FWCore/Framework/interface/MakerMacros.h"
0134 
0135 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0136 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
0137 DEFINE_EDM_PLUGIN(IsoDepositExtractorFactory, muonisolation::CandViewExtractor, "CandViewExtractor");