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 
32 #include <unordered_map>
33 namespace reco {
35 }
36 
37 namespace pat {
40 }
41 namespace{
42  // This template function finds whether theCandidate is in thefootprint
43  // // collection. It is templated to be able to handle both reco and pat
44  // // photons (from AOD and miniAOD, respectively).
45  //
46  template <class T, class U>
47  bool isInFootprint(const T& thefootprint, const U& theCandidate)
48  {
49  for ( auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr )
50  {
51  if( itr->key() == theCandidate.key() ) return true;
52  }
53  return false;
54  }
55  //This function is needed because pfNoPileUpCandidates have changed keys,
57  // // This function *shouldn't be used for packedCandidate*
58  template <class T, class U>
59  bool isInFootprintAlternative(const T& thefootprint, const U& theCandidate)
60  {
61  for ( auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr )
62  {
63  if( itr->key() == theCandidate->sourceCandidatePtr(0).key() ) return true;
64  }
65  return false;
66  }
67 
68 }
70 public:
72  citk::IsolationConeDefinitionBase(c),
73  _isolateAgainst(c.getParameter<std::string>("isolateAgainst")), //isolate against either h+, h0 or gamma
74  _miniAODVertexCodes(c.getParameter<std::vector<unsigned> >("miniAODVertexCodes")), //quality flags to be used for association with the vertex configurable, the vertex can be chosen
75  _particleBasedIsolation(c.getParameter<edm::InputTag>("particleBasedIsolation")){} // particle based isolation map (used for footprint removal)
76 
79 
80  bool isInIsolationCone(const reco::CandidatePtr& photon,
81  const reco::CandidatePtr& other) const final;
82 
83 
84  // this object is needed for reco case
87 
88  void getEventInfo(const edm::Event& iEvent) override
89  {
90  iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap);
91  };
92 
93 
94  //As far as I understand now, the object particleBasedIsolationMap should be fixed, so we don't configure the name
96  {
97  particleBasedIsolationToken_ = iC.mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef > > >(_particleBasedIsolation);
98  }
99 
102 
103 
104 private:
105  const std::string _isolateAgainst, _vertexCollection;
106  const std::vector<unsigned> _miniAODVertexCodes;
108 
109 
110 };
111 
114  "ElectronPFIsolationWithMapBasedVeto");
115 
116 
117 //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!!! ***
118 
120 
121  //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
122  pat::patElectronPtr aspat_electronptr(electron);
123 
124  pat::PackedCandidatePtr aspacked(pfCandidate);
125  reco::PFCandidatePtr aspf(pfCandidate);
126 
127 
128  bool inFootprint = false;
129  bool result = true;
130  const float deltar2 = reco::deltaR2(*electron,*pfCandidate); //calculate deltaR2 distance between PFCandidate and photon
131 
132  // dealing here with patObjects: miniAOD case
133  if ( aspacked.get() )
134  {
135  inFootprint = isInFootprint(aspat_electronptr ->associatedPackedPFCandidates(),aspacked);
136 
137  //checking if the charged candidates come from the appropriate vertex
138  if( aspacked->charge() != 0 )
139  {
140  bool is_vertex_allowed = false;
141  for( const unsigned vtxtype : _miniAODVertexCodes )
142  {
143  if( vtxtype == aspacked->fromPV() ) {
144  is_vertex_allowed = true;
145  break;
146  }
147  }
148 
149  result &= (is_vertex_allowed);
150  }
151  //return true if the candidate is inside the cone and not in the footprint
152  result &= deltar2 < _coneSize2 && (!inFootprint);
153  }
154 
155  // dealing here with recoObjects: AOD case
156  else if ( aspf.get())
157  {
158  inFootprint = isInFootprintAlternative((*particleBasedIsolationMap)[electron], pfCandidate);
159  //return true if the candidate is inside the cone and not in the footprint
160  result &= deltar2 < _coneSize2 && (!inFootprint);
161  }
162 
163  // throw exception if it is not a patObject or recoObject
164  else {
165  throw cms::Exception("InvalidIsolationInput")
166  << "The supplied candidate to be used as isolation "
167  << "was neither a reco::Photon nor a pat::Photon!";
168  }
169 
170  return result;
171 }
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
edm::Handle< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationMap
edm::Ptr< reco::GsfElectron > GsfElectronPtr
edm::Ptr< pat::Electron > patElectronPtr
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: HeavyIon.h:7
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
int iEvent
Definition: GenABIO.cc:224
void setConsumes(edm::ConsumesCollector iC) override
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
bool isInIsolationCone(const reco::CandidatePtr &photon, const reco::CandidatePtr &other) const final