CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhotonPFIsolationWithMapBasedVeto.cc
Go to the documentation of this file.
3 
6 
9 
12 
14 
17 
20 
23 
26 
28 
29 
30 #include <unordered_map>
31 
32 namespace reco {
34 }
35 
36 namespace pat {
39 }
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  template <class T, class U>
46  bool isInFootprint(const T& thefootprint, const U& theCandidate)
47  {
48  for ( auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr )
49  {
50  if( itr->key() == theCandidate.key() ) return true;
51  }
52  return false;
53  }
54 
55  //This function is needed because pfNoPileUpCandidates have changed keys,
56  //and thus the solution is to use sourceCandidatePtr(0)
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  _vertexIndex(c.getParameter<int> ("vertexIndex")){} //vertex of interest
76 
79 
80  bool isInIsolationCone(const reco::CandidatePtr& photon,
81  const reco::CandidatePtr& pfCandidate) const override final;
82 
83 
84  // this object is needed for reco case
87 
88  virtual void getEventInfo(const edm::Event& iEvent)
89  {
91  };
92 
93 
94  //As far as I understand now, the object particleBasedIsolationMap should be fixed, so we don't configure the name
96  {
98  }
99 
102 
103 
104 private:
106  const std::vector<unsigned> _miniAODVertexCodes;
107  const unsigned _vertexIndex;
108 
109 
110 };
111 
114  "PhotonPFIsolationWithMapBasedVeto");
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 photon 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::patPhotonPtr aspat_photonptr(photon);
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(*photon,*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_photonptr ->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(_vertexIndex) ) {
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 
156  // dealing here with recoObjects: AOD case
157  else if ( aspf.get() && aspf.isNonnull())
158  {
159  inFootprint = isInFootprintAlternative((*particleBasedIsolationMap)[photon], aspf);
160  result &= deltar2 < _coneSize2 && (!inFootprint);
161 
162  }
163 
164  // throw exception if it is not a patObject or recoObject
165  else {
166  throw cms::Exception("InvalidIsolationInput")
167  << "The supplied candidate to be used as isolation "
168  << "was neither a reco::Photon nor a pat::Photon!";
169  }
170 
171  return result;
172 }
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 &pfCandidate) const overridefinal
edm::Handle< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationMap
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
tuple result
Definition: mps_fire.py:95
int iEvent
Definition: GenABIO.cc:230
virtual void getEventInfo(const edm::Event &iEvent)
bool isInFootprint(const T &thefootprint, const U &theCandidate)
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
PhotonPFIsolationWithMapBasedVeto & operator=(const PhotonPFIsolationWithMapBasedVeto &)=delete
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
edm::Ptr< reco::Photon > recoPhotonPtr
PhotonPFIsolationWithMapBasedVeto(const edm::ParameterSet &c)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
edm::Ptr< pat::Photon > patPhotonPtr
#define DEFINE_EDM_PLUGIN(factory, type, name)
long double T