test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
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 
78 
79  bool isInIsolationCone(const reco::CandidatePtr& photon,
80  const reco::CandidatePtr& other) const override final;
81 
82 
83  // this object is needed for reco case
86 
87  virtual void getEventInfo(const edm::Event& iEvent)
88  {
90  };
91 
92 
93  //As far as I understand now, the object particleBasedIsolationMap should be fixed, so we don't configure the name
95  {
97  }
98 
101 
102 
103 private:
105  const std::vector<unsigned> _miniAODVertexCodes;
106 
107 
108 };
109 
112  "ElectronPFIsolationWithMapBasedVeto");
113 
114 
115 //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!!! ***
116 
118 
119  //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
120  pat::patElectronPtr aspat_electronptr(electron);
121 
122  pat::PackedCandidatePtr aspacked(pfCandidate);
123  reco::PFCandidatePtr aspf(pfCandidate);
124 
125 
126  bool inFootprint = false;
127  bool result = true;
128  const float deltar2 = reco::deltaR2(*electron,*pfCandidate); //calculate deltaR2 distance between PFCandidate and photon
129 
130  // dealing here with patObjects: miniAOD case
131  if ( aspacked.get() )
132  {
133  inFootprint = isInFootprint(aspat_electronptr ->associatedPackedPFCandidates(),aspacked);
134 
135  //checking if the charged candidates come from the appropriate vertex
136  if( aspacked->charge() != 0 )
137  {
138  bool is_vertex_allowed = false;
139  for( const unsigned vtxtype : _miniAODVertexCodes )
140  {
141  if( vtxtype == aspacked->fromPV() ) {
142  is_vertex_allowed = true;
143  break;
144  }
145  }
146 
147  result &= (is_vertex_allowed);
148  }
149  //return true if the candidate is inside the cone and not in the footprint
150  result &= deltar2 < _coneSize2 && (!inFootprint);
151  }
152 
153  // dealing here with recoObjects: AOD case
154  else if ( aspf.get())
155  {
156  inFootprint = isInFootprintAlternative((*particleBasedIsolationMap)[electron], pfCandidate);
157  //return true if the candidate is inside the cone and not in the footprint
158  result &= deltar2 < _coneSize2 && (!inFootprint);
159  }
160 
161  // throw exception if it is not a patObject or recoObject
162  else {
163  throw cms::Exception("InvalidIsolationInput")
164  << "The supplied candidate to be used as isolation "
165  << "was neither a reco::Photon nor a pat::Photon!";
166  }
167 
168  return result;
169 }
virtual void getEventInfo(const edm::Event &iEvent)
IsolationConeDefinitionBase(const edm::ParameterSet &c)
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
bool isInIsolationCone(const reco::CandidatePtr &photon, const reco::CandidatePtr &other) const overridefinal
edm::Handle< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationMap
edm::Ptr< reco::GsfElectron > GsfElectronPtr
edm::Ptr< pat::Electron > patElectronPtr
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
tuple result
Definition: mps_fire.py:83
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
int iEvent
Definition: GenABIO.cc:230
bool isInFootprint(const T &thefootprint, const U &theCandidate)
ElectronPFIsolationWithMapBasedVeto & operator=(const ElectronPFIsolationWithMapBasedVeto &)=delete
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
#define DEFINE_EDM_PLUGIN(factory, type, name)
long double T