CMS 3D CMS Logo

CandViewExtractor.cc
Go to the documentation of this file.
10 
11 #include <string>
12 #include <vector>
13 
14 namespace muonisolation {
15 
17  public:
20 
21  ~CandViewExtractor() override {}
22 
23  void fillVetos(const edm::Event& ev, const edm::EventSetup& evSetup, const reco::TrackCollection& cand) override {}
24 
25  /* virtual reco::IsoDeposit::Vetos vetos(const edm::Event & ev,
26  const edm::EventSetup & evSetup, const reco::Candidate & cand) const;
27 
28  virtual reco::IsoDeposit::Vetos vetos(const edm::Event & ev,
29  const edm::EventSetup & evSetup, const reco::Track & cand) const;
30 */
31 
32  void initEvent(const edm::Event& ev, const edm::EventSetup& evSetup) override;
33 
35  const edm::EventSetup& evSetup,
36  const reco::Track& muon) const override {
37  return depositFromObject(ev, evSetup, muon);
38  }
39 
41  const edm::EventSetup& evSetup,
42  const reco::Candidate& muon) const override {
43  return depositFromObject(ev, evSetup, muon);
44  }
45 
46  private:
48 
49  template <typename T>
50  reco::IsoDeposit depositFromObject(const edm::Event& ev, const edm::EventSetup& evSetup, const T& cand) const;
51 
52  // Parameter set
54  std::string theDepositLabel; // name for deposit
57  double theDiff_r; // transverse distance to vertex
58  double theDiff_z; // z distance to vertex
59  double theDR_Max; // Maximum cone angle for deposits
60  double theDR_Veto; // Veto cone angle
61  };
62 
63 } // namespace muonisolation
64 
65 using namespace edm;
66 using namespace reco;
67 using namespace muonisolation;
68 
69 template <typename T>
70 IsoDeposit CandViewExtractor::depositFromObject(const Event& event, const EventSetup& eventSetup, const T& cand) const {
71  static const std::string metname = "MuonIsolation|CandViewExtractor";
72 
73  reco::isodeposit::Direction candDir(cand.eta(), cand.phi());
74  IsoDeposit deposit(candDir);
75  deposit.setVeto(veto(candDir));
76  deposit.addCandEnergy(cand.pt());
77 
78  Handle<View<Candidate> > candViewH;
79  if (theCacheID != event.cacheIdentifier()) {
80  event.getByToken(theCandViewToken, candViewH);
81  } else {
82  candViewH = theCandViewH;
83  }
84 
85  double eta = cand.eta(), phi = cand.phi();
86  const reco::Particle::Point& vtx = cand.vertex();
87  LogDebug(metname) << "cand eta=" << eta << " phi=" << phi << " vtx=" << vtx;
88  for (View<Candidate>::const_iterator it = candViewH->begin(), ed = candViewH->end(); it != ed; ++it) {
89  double dR = deltaR(it->eta(), it->phi(), eta, phi);
90  LogDebug(metname) << "pdgid=" << it->pdgId() << " vtx=" << it->vertex() << " dR=" << dR
91  << " dvz=" << it->vz() - cand.vz() << " drho=" << (it->vertex() - vtx).Rho();
92  if ((dR < theDR_Max) && (dR > theDR_Veto) && (std::abs(it->vz() - cand.vz()) < theDiff_z) &&
93  ((it->vertex() - vtx).Rho() < theDiff_r)) {
94  // ok
95  reco::isodeposit::Direction dirTrk(it->eta(), it->phi());
96  deposit.addDeposit(dirTrk, it->pt());
97  LogDebug(metname) << "pt=" << it->pt();
98  }
99  }
100 
101  return deposit;
102 }
103 
104 CandViewExtractor::CandViewExtractor(const ParameterSet& par, edm::ConsumesCollector&& iC)
105  : theCandViewToken(iC.consumes<View<Candidate> >(par.getParameter<edm::InputTag>("inputCandView"))),
106  theDepositLabel(par.getUntrackedParameter<std::string>("DepositLabel")),
107  theDiff_r(par.getParameter<double>("Diff_r")),
108  theDiff_z(par.getParameter<double>("Diff_z")),
109  theDR_Max(par.getParameter<double>("DR_Max")),
110  theDR_Veto(par.getParameter<double>("DR_Veto")) {}
111 /*
112 reco::IsoDeposit::Vetos CandViewExtractor::vetos(const edm::Event & ev,
113  const edm::EventSetup & evSetup, const reco::Candidate & cand) const
114 {
115  reco::isodeposit::Direction dir(cand.eta(),cand.phi());
116  return reco::IsoDeposit::Vetos(1,veto(dir));
117 }
118 */
119 
122  result.vetoDir = dir;
123  result.dR = theDR_Veto;
124  return result;
125 }
126 
128  ev.getByToken(theCandViewToken, theCandViewH);
129  theCacheID = ev.cacheIdentifier();
130 }
131 
134 
unsigned long CacheIdentifier_t
Definition: Event.h:117
const std::string metname
edm::Event::CacheIdentifier_t theCacheID
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::EDGetTokenT< edm::View< reco::Candidate > > theCandViewToken
edm::Handle< edm::View< reco::Candidate > > theCandViewH
void initEvent(const edm::Event &ev, const edm::EventSetup &evSetup) override
perform some constly initialization
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Candidate &muon) const override
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &muon) const override
reco::IsoDeposit::Veto veto(const reco::IsoDeposit::Direction &dir) const
math::XYZPoint Point
point in the space
Definition: Particle.h:25
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::IsoDeposit depositFromObject(const edm::Event &ev, const edm::EventSetup &evSetup, const T &cand) const
void fillVetos(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::TrackCollection &cand) override
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
#define DEFINE_EDM_PLUGIN(factory, type, name)
long double T
Definition: event.py:1
#define LogDebug(id)