File indexing completed on 2024-04-06 12:23:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/global/EDProducer.h"
0026
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/StreamID.h"
0032
0033 #include "CommonTools/Egamma/interface/EffectiveAreas.h"
0034
0035 #include "DataFormats/PatCandidates/interface/Muon.h"
0036 #include "DataFormats/PatCandidates/interface/Electron.h"
0037 #include "DataFormats/PatCandidates/interface/Photon.h"
0038 #include "DataFormats/PatCandidates/interface/IsolatedTrack.h"
0039
0040
0041
0042
0043
0044 template <typename T>
0045 class HoverEValueMapProducer : public edm::global::EDProducer<> {
0046 public:
0047 explicit HoverEValueMapProducer(const edm::ParameterSet& iConfig)
0048 : src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
0049 relative_(iConfig.getParameter<bool>("relative")) {
0050 if ((typeid(T) == typeid(pat::Photon))) {
0051 produces<edm::ValueMap<float>>("HoEForPhoEACorr");
0052
0053 rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
0054
0055 quadratic_ea_hOverE_ = std::make_unique<EffectiveAreas>(
0056 (iConfig.getParameter<edm::FileInPath>("QuadraticEAFile_HoverE")).fullPath(), true);
0057 }
0058 }
0059 ~HoverEValueMapProducer() override {}
0060
0061 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0062
0063 private:
0064 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0065
0066
0067
0068 edm::EDGetTokenT<edm::View<T>> src_;
0069 bool relative_;
0070 edm::EDGetTokenT<double> rho_;
0071 std::unique_ptr<EffectiveAreas> quadratic_ea_hOverE_;
0072 float getEtaForEA(const T*) const;
0073 void doHoverEPho(edm::Event&) const;
0074 };
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 template <typename T>
0085 float HoverEValueMapProducer<T>::getEtaForEA(const T* obj) const {
0086 return obj->eta();
0087 }
0088
0089 template <>
0090 float HoverEValueMapProducer<pat::Photon>::getEtaForEA(const pat::Photon* ph) const {
0091 return ph->superCluster()->eta();
0092 }
0093
0094 template <typename T>
0095 void HoverEValueMapProducer<T>::produce(edm::StreamID streamID,
0096 edm::Event& iEvent,
0097 const edm::EventSetup& iSetup) const {
0098 if ((typeid(T) == typeid(pat::Photon))) {
0099 doHoverEPho(iEvent);
0100 }
0101 }
0102
0103 template <typename T>
0104 void HoverEValueMapProducer<T>::doHoverEPho(edm::Event& iEvent) const {}
0105
0106 template <>
0107 void HoverEValueMapProducer<pat::Photon>::doHoverEPho(edm::Event& iEvent) const {
0108 auto src = iEvent.getHandle(src_);
0109 const auto& rho = iEvent.get(rho_);
0110
0111 unsigned int nInput = src->size();
0112
0113 std::vector<float> HoverEQuadratic;
0114 HoverEQuadratic.reserve(nInput);
0115
0116 for (const auto& obj : *src) {
0117 auto hOverE = obj.hcalOverEcal();
0118
0119 auto quadratic_ea_hOverE = quadratic_ea_hOverE_->getQuadraticEA(fabs(getEtaForEA(&obj)));
0120 auto linear_ea_hOverE = quadratic_ea_hOverE_->getLinearEA(fabs(getEtaForEA(&obj)));
0121
0122 float scale = relative_ ? 1.0 / obj.pt() : 1;
0123
0124 HoverEQuadratic.push_back(scale *
0125 (std::max(0.0, hOverE - (quadratic_ea_hOverE * rho * rho + linear_ea_hOverE * rho))));
0126 }
0127
0128 std::unique_ptr<edm::ValueMap<float>> HoverEQuadraticV(new edm::ValueMap<float>());
0129 edm::ValueMap<float>::Filler fillerHoverEQuadratic(*HoverEQuadraticV);
0130 fillerHoverEQuadratic.insert(src, HoverEQuadratic.begin(), HoverEQuadratic.end());
0131 fillerHoverEQuadratic.fill();
0132
0133 iEvent.put(std::move(HoverEQuadraticV), "HoEForPhoEACorr");
0134 }
0135
0136
0137 template <typename T>
0138 void HoverEValueMapProducer<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0139 edm::ParameterSetDescription desc;
0140 desc.add<edm::InputTag>("src")->setComment("input physics object collection");
0141 desc.add<bool>("relative")->setComment("compute relative HoverE instead of absolute one");
0142 if ((typeid(T) == typeid(pat::Photon))) {
0143 desc.add<edm::FileInPath>("QuadraticEAFile_HoverE")
0144 ->setComment("txt file containing quadratic effective areas to be used for H/E pileup subtraction for photons");
0145
0146 desc.add<edm::InputTag>("rho")->setComment(
0147 "rho to be used for effective-area based H/E pileup subtraction for photons");
0148 }
0149
0150
0151
0152
0153
0154 descriptions.addWithDefaultLabel(desc);
0155 }
0156
0157 typedef HoverEValueMapProducer<pat::Photon> PhoHoverEValueMapProducer;
0158
0159
0160 DEFINE_FWK_MODULE(PhoHoverEValueMapProducer);