File indexing completed on 2024-04-06 12:25:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "TFile.h"
0031 #include "FWCore/ServiceRegistry/interface/Service.h"
0032
0033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0034 #include "FWCore/Framework/interface/ESHandle.h"
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
0037 #include "RecoEgamma/EgammaTools/interface/EGEnergyCorrector.h"
0038 #include "RecoEgamma/EgammaTools/interface/EGEnergyCorrectorFactoryFromEventSetup.h"
0039 #include "RecoEgamma/EgammaTools/interface/egEnergyCorrectorFactoryFromRootFile.h"
0040 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0041
0042
0043
0044
0045
0046 class EGEnergyAnalyzer : public edm::one::EDAnalyzer<> {
0047 public:
0048 explicit EGEnergyAnalyzer(const edm::ParameterSet&);
0049 ~EGEnergyAnalyzer() override;
0050
0051 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052
0053 private:
0054 void beginJob() override;
0055 void analyze(const edm::Event&, const edm::EventSetup&) override;
0056 void endJob() override;
0057
0058 EGEnergyCorrectorFactoryFromEventSetup corddbFactory_;
0059 EGEnergyCorrector corfile;
0060 std::optional<EGEnergyCorrector> cordb;
0061
0062 edm::EDGetTokenT<EcalRecHitCollection> ebRHToken_, eeRHToken_;
0063 const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_;
0064 };
0065
0066 EGEnergyAnalyzer::EGEnergyAnalyzer(const edm::ParameterSet& iConfig)
0067 : corddbFactory_(consumesCollector(), "wgbrph"),
0068 corfile(egEnergyCorrectorFactoryFromRootFile("/afs/cern.ch/user/b/bendavid/cmspublic/gbrv3ph.root")),
0069 ecalClusterToolsESGetTokens_{consumesCollector()} {
0070 ebRHToken_ = consumes(edm::InputTag("reducedEcalRecHitsEB"));
0071 eeRHToken_ = consumes(edm::InputTag("reducedEcalRecHitsEE"));
0072 }
0073
0074 EGEnergyAnalyzer::~EGEnergyAnalyzer() {
0075
0076
0077 }
0078
0079
0080
0081
0082
0083
0084 void EGEnergyAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0085 using namespace edm;
0086
0087 if (!cordb) {
0088 cordb = EGEnergyCorrector(corddbFactory_.build(iSetup));
0089 }
0090
0091
0092 Handle<reco::PhotonCollection> hPhotonProduct;
0093 iEvent.getByLabel("photons", hPhotonProduct);
0094
0095 auto const& ecalClusterToolsESData = ecalClusterToolsESGetTokens_.get(iSetup);
0096 auto const& caloGeometry = ecalClusterToolsESData.caloGeometry;
0097 EcalClusterLazyTools lazyTools(iEvent, ecalClusterToolsESData, ebRHToken_, eeRHToken_);
0098
0099 Handle<reco::VertexCollection> hVertexProduct;
0100 iEvent.getByLabel("offlinePrimaryVerticesWithBS", hVertexProduct);
0101
0102 for (auto const& it : *hPhotonProduct) {
0103 std::pair<double, double> corsfile = corfile.CorrectedEnergyWithError(it, *hVertexProduct, lazyTools, caloGeometry);
0104 std::pair<double, double> corsdb = cordb->CorrectedEnergyWithError(it, *hVertexProduct, lazyTools, caloGeometry);
0105
0106 printf("file: default = %5f, correction = %5f, uncertainty = %5f\n", it.energy(), corsfile.first, corsfile.second);
0107 printf("db: default = %5f, correction = %5f, uncertainty = %5f\n", it.energy(), corsdb.first, corsdb.second);
0108 }
0109 }
0110
0111
0112 void EGEnergyAnalyzer::beginJob() {}
0113
0114
0115 void EGEnergyAnalyzer::endJob() {}
0116
0117
0118 void EGEnergyAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0119
0120
0121 edm::ParameterSetDescription desc;
0122 desc.setUnknown();
0123 descriptions.addDefault(desc);
0124 }
0125
0126
0127 DEFINE_FWK_MODULE(EGEnergyAnalyzer);