CMS 3D CMS Logo

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 
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
84 
85  // in case we are by-value
86  const std::string& inst_name = contentTags_.find(anyPFIsoWithEA_)->second.instance();
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  const 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  const double eA = _effectiveAreas.getEffectiveArea( absEta );
115  const double rho = _rhoHandle.isValid() ? *_rhoHandle : 0;
116  const float anyPFIsoWithEA = std::max(0.0, anyPFIso - rho * eA);
117 
118  // Apply the cut and return the result
119  // Scale by pT if the relative isolation is requested but avoid division by 0
120  return anyPFIsoWithEA < anyPFIsoWithEACutValue*(_useRelativeIso ? cand->pt() : 1.);
121 }
122 
125  reco::PhotonPtr pho(cand);
126 
127  // in case we are by-value
128  const std::string& inst_name = contentTags_.find(anyPFIsoWithEA_)->second.instance();
130  float anyisoval = -1.0;
131  if( _anyPFIsoMap.isValid() && _anyPFIsoMap->contains( cand.id() ) ) {
132  anyisoval = (*_anyPFIsoMap)[cand];
133  } else if ( _anyPFIsoMap.isValid() && _anyPFIsoMap->idSize() == 1 &&
134  cand.id() == edm::ProductID() ) {
135  // in case we have spoofed a ptr
136  //note this must be a 1:1 valuemap (only one product input)
137  anyisoval = _anyPFIsoMap->begin()[cand.key()];
138  } else if ( _anyPFIsoMap.isValid() ){ // throw an exception
139  anyisoval = (*_anyPFIsoMap)[cand];
140  }
141 
142  // Figure out the cut value
143  // The value is generally pt-dependent: C1 + pt * C2
144  double absEta = std::abs(pho->superCluster()->eta());
145 
146  // Retrieve the variable value for this particle
147  float anyPFIso = _anyPFIsoMap.isValid() ? anyisoval : pat->userFloat(inst_name);
148 
149  // Apply pile-up correction
150  double eA = _effectiveAreas.getEffectiveArea( absEta );
151  double rho = *_rhoHandle;
152  float anyPFIsoWithEA = std::max(0.0, anyPFIso - rho * eA);
153 
154  // Divide by pT if the relative isolation is requested
155  if( _useRelativeIso )
156  anyPFIsoWithEA /= pho->pt();
157 
158  // Apply the cut and return the result
159  return anyPFIsoWithEA;
160 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
void setConsumes(edm::ConsumesCollector &) override final
result_type operator()(const reco::PhotonPtr &) const override final
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
key_type key() const
Definition: Ptr.h:185
CandidateType candidateType() const override final
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
bool ev
const float getEffectiveArea(float eta) const
#define constexpr
std::unordered_map< std::string, edm::InputTag > contentTags_
void getEventContent(const edm::EventBase &) override final
float userFloat(const std::string &key) const
Definition: PATObject.h:791
Definition: HeavyIon.h:7
bool contains(ProductID id) const
Definition: ValueMap.h:155
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
double value(const reco::CandidatePtr &cand) const override final
size_t idSize() const
Definition: ValueMap.h:159
const_iterator begin() const
Definition: ValueMap.h:208
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
HLT enums.
edm::Handle< edm::ValueMap< float > > _anyPFIsoMap
edm::Handle< double > _rhoHandle
#define DEFINE_EDM_PLUGIN(factory, type, name)
EffectiveAreas _effectiveAreas
PhoAnyPFIsoWithEACut(const edm::ParameterSet &c)