CMS 3D CMS Logo

HoverEValueMapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: HoverEValueMapProducer
5 //
14 //
15 // Author: Shubham Dutta
16 // Created: Tue, 01 Nov 2022 07:45 IST
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
34 
39 
40 //
41 // class declaration
42 //
43 
44 template <typename T>
46 public:
47  explicit HoverEValueMapProducer(const edm::ParameterSet& iConfig)
48  : src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
49  relative_(iConfig.getParameter<bool>("relative")) {
50  if ((typeid(T) == typeid(pat::Photon))) {
51  produces<edm::ValueMap<float>>("HoEForPhoEACorr");
52 
53  rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
54 
55  quadratic_ea_hOverE_ = std::make_unique<EffectiveAreas>(
56  (iConfig.getParameter<edm::FileInPath>("QuadraticEAFile_HoverE")).fullPath(), true);
57  }
58  }
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
64  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
65 
66  // ----------member data ---------------------------
67 
69  bool relative_;
71  std::unique_ptr<EffectiveAreas> quadratic_ea_hOverE_;
72  float getEtaForEA(const T*) const;
73  void doHoverEPho(edm::Event&) const;
74 };
75 
76 //
77 // constants, enums and typedefs
78 //
79 
80 //
81 // static data member definitions
82 //
83 
84 template <typename T>
86  return obj->eta();
87 }
88 
89 template <>
91  return ph->superCluster()->eta();
92 }
93 
94 template <typename T>
97  const edm::EventSetup& iSetup) const {
98  if ((typeid(T) == typeid(pat::Photon))) {
99  doHoverEPho(iEvent);
100  }
101 }
102 
103 template <typename T>
105 
106 template <>
108  auto src = iEvent.getHandle(src_);
109  const auto& rho = iEvent.get(rho_);
110 
111  unsigned int nInput = src->size();
112 
113  std::vector<float> HoverEQuadratic;
114  HoverEQuadratic.reserve(nInput);
115 
116  for (const auto& obj : *src) {
117  auto hOverE = obj.hcalOverEcal();
118 
119  auto quadratic_ea_hOverE = quadratic_ea_hOverE_->getQuadraticEA(fabs(getEtaForEA(&obj)));
120  auto linear_ea_hOverE = quadratic_ea_hOverE_->getLinearEA(fabs(getEtaForEA(&obj)));
121 
122  float scale = relative_ ? 1.0 / obj.pt() : 1;
123 
124  HoverEQuadratic.push_back(scale *
125  (std::max(0.0, hOverE - (quadratic_ea_hOverE * rho * rho + linear_ea_hOverE * rho))));
126  }
127 
128  std::unique_ptr<edm::ValueMap<float>> HoverEQuadraticV(new edm::ValueMap<float>());
129  edm::ValueMap<float>::Filler fillerHoverEQuadratic(*HoverEQuadraticV);
130  fillerHoverEQuadratic.insert(src, HoverEQuadratic.begin(), HoverEQuadratic.end());
131  fillerHoverEQuadratic.fill();
132 
133  iEvent.put(std::move(HoverEQuadraticV), "HoEForPhoEACorr");
134 }
135 
136 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
137 template <typename T>
140  desc.add<edm::InputTag>("src")->setComment("input physics object collection");
141  desc.add<bool>("relative")->setComment("compute relative HoverE instead of absolute one");
142  if ((typeid(T) == typeid(pat::Photon))) {
143  desc.add<edm::FileInPath>("QuadraticEAFile_HoverE")
144  ->setComment("txt file containing quadratic effective areas to be used for H/E pileup subtraction for photons");
145 
146  desc.add<edm::InputTag>("rho")->setComment(
147  "rho to be used for effective-area based H/E pileup subtraction for photons");
148  }
149 
150  // std::string modname;
151  // if (typeid(T) == typeid(pat::Photon))
152  // modname += "Pho";
153  // modname += "HoverEValueMapProducer";
154  descriptions.addWithDefaultLabel(desc);
155 }
156 
158 
159 //define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Analysis-level Photon class.
Definition: Photon.h:46
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void doHoverEPho(edm::Event &) const
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
HoverEValueMapProducer< pat::Photon > PhoHoverEValueMapProducer
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
float getEtaForEA(const T *) const
edm::EDGetTokenT< double > rho_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< EffectiveAreas > quadratic_ea_hOverE_
edm::EDGetTokenT< edm::View< T > > src_
HoverEValueMapProducer(const edm::ParameterSet &iConfig)
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T
def move(src, dest)
Definition: eostools.py:511