CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhoAnyPFIsoWithEACut.cc
Go to the documentation of this file.
4 
5 
7 public:
9 
10  result_type operator()(const reco::PhotonPtr&) const override final;
11 
12  void setConsumes(edm::ConsumesCollector&) override final;
13  void getEventContent(const edm::EventBase&) override final;
14 
15  double value(const reco::CandidatePtr& cand) const override final;
16 
17  CandidateType candidateType() const override final {
18  return PHOTON;
19  }
20 
21 private:
22  // Cut values
23  float _C1_EB;
24  float _C2_EB;
25  float _C1_EE;
26  float _C2_EE;
27  // Configuration
30  // Effective area constants
32  // The isolations computed upstream
34  // The rho
36 
37  constexpr static char anyPFIsoWithEA_[] = "anyPFIsoWithEA";
38  constexpr static char rhoString_ [] = "rho";
39 };
40 
43 
46  "PhoAnyPFIsoWithEACut");
47 
50  _C1_EB(c.getParameter<double>("C1_EB")),
51  _C2_EB(c.getParameter<double>("C2_EB")),
52  _C1_EE(c.getParameter<double>("C1_EE")),
53  _C2_EE(c.getParameter<double>("C2_EE")),
54  _barrelCutOff(c.getParameter<double>("barrelCutOff")),
55  _useRelativeIso(c.getParameter<bool>("useRelativeIso")),
56  _effectiveAreas( (c.getParameter<edm::FileInPath>("effAreasConfigFile")).fullPath())
57 {
58 
59  edm::InputTag maptag = c.getParameter<edm::InputTag>("anyPFIsoMap");
60  contentTags_.emplace(anyPFIsoWithEA_,maptag);
61 
62  edm::InputTag rhoTag = c.getParameter<edm::InputTag>("rho");
63  contentTags_.emplace(rhoString_,rhoTag);
64 
65 }
66 
68  auto anyPFIsoWithEA =
70  contentTokens_.emplace(anyPFIsoWithEA_,anyPFIsoWithEA);
71 
72  auto rho = cc.consumes<double>(contentTags_[rhoString_]);
73  contentTokens_.emplace(rhoString_, rho);
74 }
75 
79 }
80 
81 CutApplicatorBase::result_type
83 operator()(const reco::PhotonPtr& cand) const{
84 
85  // in case we are by-value
86  const std::string& inst_name = contentTags_.find(anyPFIsoWithEA_)->second.instance();
87  edm::Ptr<pat::Photon> pat(cand);
88  float anyisoval = -1.0;
89  if( _anyPFIsoMap.isValid() && _anyPFIsoMap->contains( cand.id() ) ) {
90  anyisoval = (*_anyPFIsoMap)[cand];
91  } else if ( _anyPFIsoMap.isValid() && _anyPFIsoMap->idSize() == 1 &&
92  cand.id() == edm::ProductID() ) {
93  // in case we have spoofed a ptr
94  //note this must be a 1:1 valuemap (only one product input)
95  anyisoval = _anyPFIsoMap->begin()[cand.key()];
96  } else if ( _anyPFIsoMap.isValid() ){ // throw an exception
97  anyisoval = (*_anyPFIsoMap)[cand];
98  }
99 
100  // Figure out the cut value
101  // The value is generally pt-dependent: C1 + pt * C2
102  double absEta = std::abs(cand->superCluster()->eta());
103  const float anyPFIsoWithEACutValue =
104  ( absEta < _barrelCutOff ?
105  _C1_EB + cand->pt() * _C2_EB
106  :
107  _C1_EE + cand->pt() * _C2_EE
108  );
109 
110  // Retrieve the variable value for this particle
111  float anyPFIso = _anyPFIsoMap.isValid() ? anyisoval : pat->userFloat(inst_name);
112 
113  // Apply pile-up correction
114  double eA = _effectiveAreas.getEffectiveArea( absEta );
115  double rho = *_rhoHandle;
116  float anyPFIsoWithEA = std::max(0.0, anyPFIso - rho * eA);
117 
118  // Divide by pT if the relative isolation is requested
119  if( _useRelativeIso )
120  anyPFIsoWithEA /= cand->pt();
121 
122  // Apply the cut and return the result
123  return anyPFIsoWithEA < anyPFIsoWithEACutValue;
124 }
125 
127 value(const reco::CandidatePtr& cand) const {
128  reco::PhotonPtr pho(cand);
129 
130  // in case we are by-value
131  const std::string& inst_name = contentTags_.find(anyPFIsoWithEA_)->second.instance();
132  edm::Ptr<pat::Photon> pat(cand);
133  float anyisoval = -1.0;
134  if( _anyPFIsoMap.isValid() && _anyPFIsoMap->contains( cand.id() ) ) {
135  anyisoval = (*_anyPFIsoMap)[cand];
136  } else if ( _anyPFIsoMap.isValid() && _anyPFIsoMap->idSize() == 1 &&
137  cand.id() == edm::ProductID() ) {
138  // in case we have spoofed a ptr
139  //note this must be a 1:1 valuemap (only one product input)
140  anyisoval = _anyPFIsoMap->begin()[cand.key()];
141  } else if ( _anyPFIsoMap.isValid() ){ // throw an exception
142  anyisoval = (*_anyPFIsoMap)[cand];
143  }
144 
145  // Figure out the cut value
146  // The value is generally pt-dependent: C1 + pt * C2
147  double absEta = std::abs(pho->superCluster()->eta());
148 
149  // Retrieve the variable value for this particle
150  float anyPFIso = _anyPFIsoMap.isValid() ? anyisoval : pat->userFloat(inst_name);
151 
152  // Apply pile-up correction
153  double eA = _effectiveAreas.getEffectiveArea( absEta );
154  double rho = *_rhoHandle;
155  float anyPFIsoWithEA = std::max(0.0, anyPFIso - rho * eA);
156 
157  // Divide by pT if the relative isolation is requested
158  if( _useRelativeIso )
159  anyPFIsoWithEA /= pho->pt();
160 
161  // Apply the cut and return the result
162  return anyPFIsoWithEA;
163 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
void setConsumes(edm::ConsumesCollector &) overridefinal
key_type key() const
Definition: Ptr.h:169
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
Definition: DDAxes.h:10
bool ev
const float getEffectiveArea(float eta) const
CandidateType candidateType() const overridefinal
#define constexpr
std::unordered_map< std::string, edm::InputTag > contentTags_
bool contains(ProductID id) const
Definition: ValueMap.h:154
double value(const reco::CandidatePtr &cand) const overridefinal
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:75
result_type operator()(const reco::PhotonPtr &) const overridefinal
size_t idSize() const
Definition: ValueMap.h:158
void getEventContent(const edm::EventBase &) overridefinal
const_iterator begin() const
Definition: ValueMap.h:209
string const
Definition: compareJSON.py:14
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:164
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
edm::Handle< edm::ValueMap< float > > _anyPFIsoMap
edm::Handle< double > _rhoHandle
#define DEFINE_EDM_PLUGIN(factory, type, name)
EffectiveAreas _effectiveAreas
PhoAnyPFIsoWithEACut(const edm::ParameterSet &c)