CMS 3D CMS Logo

ElectronPFIsolationWithMapBasedVeto.cc
Go to the documentation of this file.
3 
6 
9 
12 
14 
16 
19 
22 
25 
28 
30 
31 #include <unordered_map>
32 namespace reco {
34 }
35 
36 namespace pat {
39 } // namespace pat
40 namespace {
41  // This template function finds whether theCandidate is in thefootprint
42  // // collection. It is templated to be able to handle both reco and pat
43  // // photons (from AOD and miniAOD, respectively).
44  //
45  template <class T, class U>
46  bool isInFootprint(const T& thefootprint, const U& theCandidate) {
47  for (auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr) {
48  if (itr->key() == theCandidate.key())
49  return true;
50  }
51  return false;
52  }
53  //This function is needed because pfNoPileUpCandidates have changed keys,
55  // // This function *shouldn't be used for packedCandidate*
56  template <class T, class U>
57  bool isInFootprintAlternative(const T& thefootprint, const U& theCandidate) {
58  for (auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr) {
59  if (itr->key() == theCandidate->sourceCandidatePtr(0).key())
60  return true;
61  }
62  return false;
63  }
64 
65 } // namespace
67 public:
70  _isolateAgainst(c.getParameter<std::string>("isolateAgainst")), //isolate against either h+, h0 or gamma
71  _miniAODVertexCodes(c.getParameter<std::vector<unsigned> >(
72  "miniAODVertexCodes")), //quality flags to be used for association with the vertex configurable, the vertex can be chosen
73  _particleBasedIsolation(c.getParameter<edm::InputTag>("particleBasedIsolation")) {
74  } // particle based isolation map (used for footprint removal)
75 
78 
79  bool isInIsolationCone(const reco::CandidatePtr& photon, const reco::CandidatePtr& other) const final;
80 
81  // this object is needed for reco case
84 
85  void getEventInfo(const edm::Event& iEvent) override {
87  };
88 
89  //As far as I understand now, the object particleBasedIsolationMap should be fixed, so we don't configure the name
90  void setConsumes(edm::ConsumesCollector iC) override {
93  }
94 
97 
98 private:
100  const std::vector<unsigned> _miniAODVertexCodes;
102 };
103 
106  "ElectronPFIsolationWithMapBasedVeto");
107 
108 //This function defines whether particular PFCandidate is inside of isolation cone of photon or not by checking deltaR and whether footprint removal for this candidate should be done. Additionally, for miniAOD charged hadrons from the PV are considered. *** For AOD this should be done by the corresponding sequence beforehand!!! ***
109 
111  const reco::CandidatePtr& pfCandidate) const {
112  //convert the electron and candidate objects to the corresponding pat or reco objects. What is used depends on what is user running on: miniAOD or AOD
113  pat::patElectronPtr aspat_electronptr(electron);
114 
115  pat::PackedCandidatePtr aspacked(pfCandidate);
116  reco::PFCandidatePtr aspf(pfCandidate);
117 
118  bool inFootprint = false;
119  bool result = true;
120  const float deltar2 =
121  reco::deltaR2(*electron, *pfCandidate); //calculate deltaR2 distance between PFCandidate and photon
122 
123  // dealing here with patObjects: miniAOD case
124  if (aspacked.get()) {
125  inFootprint = isInFootprint(aspat_electronptr->associatedPackedPFCandidates(), aspacked);
126 
127  //checking if the charged candidates come from the appropriate vertex
128  if (aspacked->charge() != 0) {
129  bool is_vertex_allowed = false;
130  for (const unsigned vtxtype : _miniAODVertexCodes) {
131  if (vtxtype == aspacked->fromPV()) {
132  is_vertex_allowed = true;
133  break;
134  }
135  }
136 
137  result &= (is_vertex_allowed);
138  }
139  //return true if the candidate is inside the cone and not in the footprint
140  result &= deltar2 < _coneSize2 && (!inFootprint);
141  }
142 
143  // dealing here with recoObjects: AOD case
144  else if (aspf.get()) {
145  inFootprint = isInFootprintAlternative((*particleBasedIsolationMap)[electron], pfCandidate);
146  //return true if the candidate is inside the cone and not in the footprint
147  result &= deltar2 < _coneSize2 && (!inFootprint);
148  }
149 
150  // throw exception if it is not a patObject or recoObject
151  else {
152  throw cms::Exception("InvalidIsolationInput") << "The supplied candidate to be used as isolation "
153  << "was neither a reco::Photon nor a pat::Photon!";
154  }
155 
156  return result;
157 }
IsolationConeDefinitionBase(const edm::ParameterSet &c)
bool isInIsolationCone(const reco::CandidatePtr &photon, const reco::CandidatePtr &other) const final
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
edm::Handle< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationMap
edm::Ptr< reco::GsfElectron > GsfElectronPtr
edm::RefVector< pat::PackedCandidateCollection > associatedPackedPFCandidates() const
References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet recl...
edm::Ptr< pat::Electron > patElectronPtr
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
void setConsumes(edm::ConsumesCollector iC) override
ElectronPFIsolationWithMapBasedVeto & operator=(const ElectronPFIsolationWithMapBasedVeto &)=delete
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void getEventInfo(const edm::Event &iEvent) override
fixed size matrix
HLT enums.
#define DEFINE_EDM_PLUGIN(factory, type, name)
long double T