CMS 3D CMS Logo

PhotonPFIsolationWithMapBasedVeto.cc
Go to the documentation of this file.
3 
6 
9 
12 
14 
17 
20 
23 
26 
28 
29 #include <unordered_map>
30 
31 namespace reco {
33 }
34 
35 namespace pat {
38 } // namespace pat
39 
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  template <class T, class U>
45  bool isInFootprint(const T& thefootprint, const U& theCandidate) {
46  for (auto itr = thefootprint.begin(); itr != thefootprint.end(); ++itr) {
47  if (itr->key() == theCandidate.key())
48  return true;
49  }
50  return false;
51  }
52 
53  //This function is needed because pfNoPileUpCandidates have changed keys,
54  //and thus the solution is to use sourceCandidatePtr(0)
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 } // namespace
65 
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  _vertexIndex(c.getParameter<int>("vertexIndex")), //vertex of interest
74  _particleBasedIsolation(c.getParameter<edm::InputTag>("particleBasedIsolation")) {}
75 
78 
79  bool isInIsolationCone(const reco::CandidatePtr& photon, const reco::CandidatePtr& pfCandidate) 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;
101  const unsigned _vertexIndex;
103 };
104 
107  "PhotonPFIsolationWithMapBasedVeto");
108 
109 //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!!! ***
110 
112  const reco::CandidatePtr& pfCandidate) const {
113  //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
114  pat::patPhotonPtr aspat_photonptr(photon);
115 
116  pat::PackedCandidatePtr aspacked(pfCandidate);
117  reco::PFCandidatePtr aspf(pfCandidate);
118 
119  bool inFootprint = false;
120  bool result = true;
121  const float deltar2 =
122  reco::deltaR2(*photon, *pfCandidate); //calculate deltaR2 distance between PFCandidate and photon
123 
124  // dealing here with patObjects: miniAOD case
125  if (aspacked.get()) {
126  inFootprint = isInFootprint(aspat_photonptr->associatedPackedPFCandidates(), aspacked);
127 
128  //checking if the charged candidates come from the appropriate vertex
129  if (aspacked->charge() != 0) {
130  bool is_vertex_allowed = false;
131  for (const unsigned vtxtype : _miniAODVertexCodes) {
132  if (vtxtype == aspacked->fromPV(_vertexIndex)) {
133  is_vertex_allowed = true;
134  break;
135  }
136  }
137 
138  result &= (is_vertex_allowed);
139  }
140  //return true if the candidate is inside the cone and not in the footprint
141  result &= deltar2 < _coneSize2 && (!inFootprint);
142 
143  }
144 
145  // dealing here with recoObjects: AOD case
146  else if (aspf.get() && aspf.isNonnull()) {
147  inFootprint = isInFootprintAlternative((*particleBasedIsolationMap)[photon], aspf);
148  result &= deltar2 < _coneSize2 && (!inFootprint);
149 
150  }
151 
152  // throw exception if it is not a patObject or recoObject
153  else {
154  throw cms::Exception("InvalidIsolationInput") << "The supplied candidate to be used as isolation "
155  << "was neither a reco::Photon nor a pat::Photon!";
156  }
157 
158  return result;
159 }
pat::PackedCandidatePtr
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: PATMuonMerger.cc:18
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
IsoDepositVetos.h
pat::patPhotonPtr
edm::Ptr< pat::Photon > patPhotonPtr
Definition: PhotonPFIsolationWithMapBasedVeto.cc:36
PhotonPFIsolationWithMapBasedVeto::operator=
PhotonPFIsolationWithMapBasedVeto & operator=(const PhotonPFIsolationWithMapBasedVeto &)=delete
PFCandidate.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
IsoDepositVetoFactory.h
edm
HLT enums.
Definition: AlignableModifier.h:19
Photon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
PhotonPFIsolationWithMapBasedVeto::_particleBasedIsolation
const edm::InputTag _particleBasedIsolation
Definition: PhotonPFIsolationWithMapBasedVeto.cc:102
PhotonFwd.h
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
citk
Definition: CITKIsolationConeDefinitionBase.h:16
CandidateFwd.h
citk::IsolationConeDefinitionBase
Definition: CITKIsolationConeDefinitionBase.h:17
Photon.h
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalSubdetector.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
CITKIsolationConeDefinitionBase.h
deltaR.h
reco::recoPhotonPtr
edm::Ptr< reco::Photon > recoPhotonPtr
Definition: PhotonPFIsolationWithConeVeto.cc:28
edmplugin::PluginFactory
Definition: PluginFactory.h:34
PackedCandidate.h
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
edm::ConsumesCollector::mayConsume
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Definition: ConsumesCollector.h:72
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
pat
Definition: HeavyIon.h:7
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
PhotonPFIsolationWithMapBasedVeto::isInIsolationCone
bool isInIsolationCone(const reco::CandidatePtr &photon, const reco::CandidatePtr &pfCandidate) const final
Definition: PhotonPFIsolationWithMapBasedVeto.cc:111
PhotonPFIsolationWithMapBasedVeto::particleBasedIsolationToken_
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
Definition: PhotonPFIsolationWithMapBasedVeto.cc:83
PhotonPFIsolationWithMapBasedVeto::_vertexIndex
const unsigned _vertexIndex
Definition: PhotonPFIsolationWithMapBasedVeto.cc:101
edm::Ptr
Definition: AssociationVector.h:31
PhotonPFIsolationWithMapBasedVeto::_miniAODVertexCodes
const std::vector< unsigned > _miniAODVertexCodes
Definition: PhotonPFIsolationWithMapBasedVeto.cc:100
ValueMap.h
citk::IsolationConeDefinitionBase::_coneSize2
const float _coneSize2
Definition: CITKIsolationConeDefinitionBase.h:36
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:246
PhotonPFIsolationWithMapBasedVeto::PhotonPFIsolationWithMapBasedVeto
PhotonPFIsolationWithMapBasedVeto(const edm::ParameterSet &c)
Definition: PhotonPFIsolationWithMapBasedVeto.cc:68
PhotonPFIsolationWithMapBasedVeto::particleBasedIsolationMap
edm::Handle< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationMap
Definition: PhotonPFIsolationWithMapBasedVeto.cc:82
EventSetup.h
PhotonPFIsolationWithMapBasedVeto::_isolateAgainst
const std::string _isolateAgainst
Definition: PhotonPFIsolationWithMapBasedVeto.cc:96
edm::Ptr::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
mps_fire.result
result
Definition: mps_fire.py:311
ConsumesCollector.h
Candidate.h
ParameterSet.h
PhotonPFIsolationWithMapBasedVeto::~PhotonPFIsolationWithMapBasedVeto
~PhotonPFIsolationWithMapBasedVeto() override
Destructor.
Definition: PhotonPFIsolationWithMapBasedVeto.cc:96
edm::Event
Definition: Event.h:73
PhotonPFIsolationWithMapBasedVeto::getEventInfo
void getEventInfo(const edm::Event &iEvent) override
Definition: PhotonPFIsolationWithMapBasedVeto.cc:85
PhotonPFIsolationWithMapBasedVeto::setConsumes
void setConsumes(edm::ConsumesCollector iC) override
Definition: PhotonPFIsolationWithMapBasedVeto.cc:90
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PhotonPFIsolationWithMapBasedVeto::_vertexCollection
const std::string _vertexCollection
Definition: PhotonPFIsolationWithMapBasedVeto.cc:96
PhotonPFIsolationWithMapBasedVeto
Definition: PhotonPFIsolationWithMapBasedVeto.cc:66
citk::IsolationConeDefinitionBase::IsolationConeDefinitionBase
IsolationConeDefinitionBase(const edm::ParameterSet &c)
Definition: CITKIsolationConeDefinitionBase.h:19