CMS 3D CMS Logo

EGEnergyAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EGEnergyAnalyzer
4 // Class: EGEnergyAnalyzer
5 //
13 //
14 // Original Author: Josh Bendavid
15 // Created: Tue Nov 8 22:26:45 CET 2011
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 #include "TFile.h"
32 //#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
33 //#include "CondCore/DBCommon/interface/CoralServiceManager.h"
34 
41 
42 //
43 // class declaration
44 //
45 
47 public:
48  explicit EGEnergyAnalyzer(const edm::ParameterSet&);
49  ~EGEnergyAnalyzer() override;
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void beginJob() override;
55  void analyze(const edm::Event&, const edm::EventSetup&) override;
56  void endJob() override;
57 
60 
62 };
63 
65  ebRHToken_ = consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEB"));
66  eeRHToken_ = consumes<EcalRecHitCollection>(edm::InputTag("reducedEcalRecHitsEE"));
67 }
68 
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72 }
73 
74 //
75 // member functions
76 //
77 
78 // ------------ method called for each event ------------
80  using namespace edm;
81 
82  if (!corfile.IsInitialized()) {
83  corfile.Initialize(iSetup, "/afs/cern.ch/user/b/bendavid/cmspublic/gbrv3ph.root");
84  //corfile.Initialize(iSetup,"wgbrph",true);
85  }
86 
87  if (!cordb.IsInitialized()) {
88  //cordb.Initialize(iSetup,"/afs/cern.ch/user/b/bendavid/cmspublic/regweights/gbrph.root");
89  cordb.Initialize(iSetup, "wgbrph", true);
90  }
91 
92  // get photon collection
93  Handle<reco::PhotonCollection> hPhotonProduct;
94  iEvent.getByLabel("photons", hPhotonProduct);
95 
96  EcalClusterLazyTools lazyTools(iEvent, iSetup, ebRHToken_, eeRHToken_);
97 
98  Handle<reco::VertexCollection> hVertexProduct;
99  iEvent.getByLabel("offlinePrimaryVerticesWithBS", hVertexProduct);
100 
101  for (reco::PhotonCollection::const_iterator it = hPhotonProduct->begin(); it != hPhotonProduct->end(); ++it) {
102  std::pair<double, double> corsfile = corfile.CorrectedEnergyWithError(*it, *hVertexProduct, lazyTools, iSetup);
103  std::pair<double, double> corsdb = cordb.CorrectedEnergyWithError(*it, *hVertexProduct, lazyTools, iSetup);
104 
105  printf("file: default = %5f, correction = %5f, uncertainty = %5f\n", it->energy(), corsfile.first, corsfile.second);
106  printf("db: default = %5f, correction = %5f, uncertainty = %5f\n", it->energy(), corsdb.first, corsdb.second);
107  }
108 }
109 
110 // ------------ method called once each job just before starting event loop ------------
112 
113 // ------------ method called once each job just after ending the event loop ------------
115 
116 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
118  //The following says we do not know what parameters are allowed so do no validation
119  // Please change this to state exactly what you do use, even if it is no parameters
121  desc.setUnknown();
122  descriptions.addDefault(desc);
123 }
124 
125 //define this as a plug-in
void Initialize(const edm::EventSetup &iSetup, std::string regweights, bool weightsFromDB=false)
EGEnergyAnalyzer(const edm::ParameterSet &)
void endJob() override
EGEnergyCorrector corfile
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< EcalRecHitCollection > ebRHToken_
EGEnergyCorrector cordb
std::pair< double, double > CorrectedEnergyWithError(const reco::Photon &p, const reco::VertexCollection &vtxcol, EcalClusterLazyTools &clustertools, const edm::EventSetup &es)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
~EGEnergyAnalyzer() override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
Bool_t IsInitialized() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
edm::EDGetTokenT< EcalRecHitCollection > eeRHToken_
void beginJob() override