CMS 3D CMS Logo

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