Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:03

0001 // -*- C++ -*-
0002 //
0003 // Package:    EGEnergyAnalyzer
0004 // Class:      EGEnergyAnalyzer
0005 //
0006 /**\class EGEnergyAnalyzer EGEnergyAnalyzer.cc GBRWrap/EGEnergyAnalyzer/src/EGEnergyAnalyzer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Josh Bendavid
0015 //         Created:  Tue Nov  8 22:26:45 CET 2011
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class declaration
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   // do anything here that needs to be done at desctruction time
0076   // (e.g. close files, deallocate resources etc.)
0077 }
0078 
0079 //
0080 // member functions
0081 //
0082 
0083 // ------------ method called for each event  ------------
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   // get photon collection
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 // ------------ method called once each job just before starting event loop  ------------
0112 void EGEnergyAnalyzer::beginJob() {}
0113 
0114 // ------------ method called once each job just after ending the event loop  ------------
0115 void EGEnergyAnalyzer::endJob() {}
0116 
0117 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0118 void EGEnergyAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0119   //The following says we do not know what parameters are allowed so do no validation
0120   // Please change this to state exactly what you do use, even if it is no parameters
0121   edm::ParameterSetDescription desc;
0122   desc.setUnknown();
0123   descriptions.addDefault(desc);
0124 }
0125 
0126 //define this as a plug-in
0127 DEFINE_FWK_MODULE(EGEnergyAnalyzer);