CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoEgamma/EgammaTools/plugins/EGEnergyAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EGEnergyAnalyzer
00004 // Class:      EGEnergyAnalyzer
00005 // 
00013 //
00014 // Original Author:  Josh Bendavid
00015 //         Created:  Tue Nov  8 22:26:45 CET 2011
00016 // $Id: EGEnergyAnalyzer.cc,v 1.3 2011/12/14 21:08:11 bendavid Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "TFile.h"
00033 #include "FWCore/ServiceRegistry/interface/Service.h"
00034 //#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00035 //#include "CondCore/DBCommon/interface/CoralServiceManager.h"
00036 
00037 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039 #include "FWCore/Framework/interface/EventSetup.h"
00040 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
00041 #include "RecoEgamma/EgammaTools/interface/EGEnergyCorrector.h"
00042 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00043 
00044 
00045 //
00046 // class declaration
00047 //
00048 
00049 class EGEnergyAnalyzer : public edm::EDAnalyzer {
00050    public:
00051       explicit EGEnergyAnalyzer(const edm::ParameterSet&);
00052       ~EGEnergyAnalyzer();
00053 
00054       static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00055 
00056 
00057    private:
00058       virtual void beginJob() ;
00059       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00060       virtual void endJob() ;
00061 
00062       virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00063       virtual void endRun(edm::Run const&, edm::EventSetup const&);
00064       virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00065       virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00066 
00067       EGEnergyCorrector corfile;
00068       EGEnergyCorrector cordb;
00069 
00070       // ----------member data ---------------------------
00071 };
00072 
00073 //
00074 // constants, enums and typedefs
00075 //
00076 
00077 //
00078 // static data member definitions
00079 //
00080 
00081 //
00082 // constructors and destructor
00083 //
00084 EGEnergyAnalyzer::EGEnergyAnalyzer(const edm::ParameterSet& iConfig)
00085 
00086 {
00087    //now do what ever initialization is needed
00088 
00089 }
00090 
00091 
00092 EGEnergyAnalyzer::~EGEnergyAnalyzer()
00093 {
00094  
00095    // do anything here that needs to be done at desctruction time
00096    // (e.g. close files, deallocate resources etc.)
00097 
00098 }
00099 
00100 
00101 //
00102 // member functions
00103 //
00104 
00105 // ------------ method called for each event  ------------
00106 void
00107 EGEnergyAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00108 {
00109    using namespace edm;
00110 
00111   if (!corfile.IsInitialized()) {
00112     corfile.Initialize(iSetup,"/afs/cern.ch/user/b/bendavid/cmspublic/gbrv3ph.root");
00113     //corfile.Initialize(iSetup,"wgbrph",true);
00114   }
00115 
00116   if (!cordb.IsInitialized()) {
00117     //cordb.Initialize(iSetup,"/afs/cern.ch/user/b/bendavid/cmspublic/regweights/gbrph.root");
00118     cordb.Initialize(iSetup,"wgbrph",true);
00119   }
00120 
00121   // get photon collection
00122   Handle<reco::PhotonCollection> hPhotonProduct;
00123   iEvent.getByLabel("photons",hPhotonProduct);
00124   
00125   EcalClusterLazyTools lazyTools(iEvent, iSetup, edm::InputTag("reducedEcalRecHitsEB"), 
00126                                  edm::InputTag("reducedEcalRecHitsEE"));  
00127   
00128   Handle<reco::VertexCollection> hVertexProduct;
00129   iEvent.getByLabel("offlinePrimaryVerticesWithBS", hVertexProduct);      
00130   
00131   for (reco::PhotonCollection::const_iterator it = hPhotonProduct->begin(); it!=hPhotonProduct->end(); ++it) {
00132     std::pair<double,double> corsfile = corfile.CorrectedEnergyWithError(*it, *hVertexProduct, lazyTools, iSetup);
00133     std::pair<double,double> corsdb = cordb.CorrectedEnergyWithError(*it, *hVertexProduct, lazyTools, iSetup);
00134 
00135 
00136     printf("file: default = %5f, correction = %5f, uncertainty = %5f\n", it->energy(),corsfile.first,corsfile.second);
00137     printf("db:   default = %5f, correction = %5f, uncertainty = %5f\n", it->energy(),corsdb.first,corsdb.second);
00138 
00139   }  
00140 
00141 
00142 
00143 
00144 }
00145 
00146 
00147 // ------------ method called once each job just before starting event loop  ------------
00148 void 
00149 EGEnergyAnalyzer::beginJob()
00150 {
00151 
00152 
00153 
00154 }
00155 
00156 // ------------ method called once each job just after ending the event loop  ------------
00157 void 
00158 EGEnergyAnalyzer::endJob() 
00159 {
00160 }
00161 
00162 // ------------ method called when starting to processes a run  ------------
00163 void 
00164 EGEnergyAnalyzer::beginRun(edm::Run const&, edm::EventSetup const&)
00165 {
00166 }
00167 
00168 // ------------ method called when ending the processing of a run  ------------
00169 void 
00170 EGEnergyAnalyzer::endRun(edm::Run const&, edm::EventSetup const&)
00171 {
00172 }
00173 
00174 // ------------ method called when starting to processes a luminosity block  ------------
00175 void 
00176 EGEnergyAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00177 {
00178 }
00179 
00180 // ------------ method called when ending the processing of a luminosity block  ------------
00181 void 
00182 EGEnergyAnalyzer::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00183 {
00184 }
00185 
00186 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00187 void
00188 EGEnergyAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00189   //The following says we do not know what parameters are allowed so do no validation
00190   // Please change this to state exactly what you do use, even if it is no parameters
00191   edm::ParameterSetDescription desc;
00192   desc.setUnknown();
00193   descriptions.addDefault(desc);
00194 }
00195 
00196 //define this as a plug-in
00197 DEFINE_FWK_MODULE(EGEnergyAnalyzer);