CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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  std::optional<EGEnergyCorrector> cordb;
61 
64 };
65 
67  : corddbFactory_(consumesCollector(), "wgbrph"),
68  corfile(egEnergyCorrectorFactoryFromRootFile("/afs/cern.ch/user/b/bendavid/cmspublic/gbrv3ph.root")),
69  ecalClusterToolsESGetTokens_{consumesCollector()} {
70  ebRHToken_ = consumes(edm::InputTag("reducedEcalRecHitsEB"));
71  eeRHToken_ = consumes(edm::InputTag("reducedEcalRecHitsEE"));
72 }
73 
75  // do anything here that needs to be done at desctruction time
76  // (e.g. close files, deallocate resources etc.)
77 }
78 
79 //
80 // member functions
81 //
82 
83 // ------------ method called for each event ------------
85  using namespace edm;
86 
87  if (!cordb) {
89  }
90 
91  // get photon collection
92  Handle<reco::PhotonCollection> hPhotonProduct;
93  iEvent.getByLabel("photons", hPhotonProduct);
94 
95  auto const& ecalClusterToolsESData = ecalClusterToolsESGetTokens_.get(iSetup);
96  auto const& caloGeometry = ecalClusterToolsESData.caloGeometry;
97  EcalClusterLazyTools lazyTools(iEvent, ecalClusterToolsESData, ebRHToken_, eeRHToken_);
98 
99  Handle<reco::VertexCollection> hVertexProduct;
100  iEvent.getByLabel("offlinePrimaryVerticesWithBS", hVertexProduct);
101 
102  for (auto const& it : *hPhotonProduct) {
103  std::pair<double, double> corsfile = corfile.CorrectedEnergyWithError(it, *hVertexProduct, lazyTools, caloGeometry);
104  std::pair<double, double> corsdb = cordb->CorrectedEnergyWithError(it, *hVertexProduct, lazyTools, caloGeometry);
105 
106  printf("file: default = %5f, correction = %5f, uncertainty = %5f\n", it.energy(), corsfile.first, corsfile.second);
107  printf("db: default = %5f, correction = %5f, uncertainty = %5f\n", it.energy(), corsdb.first, corsdb.second);
108  }
109 }
110 
111 // ------------ method called once each job just before starting event loop ------------
113 
114 // ------------ method called once each job just after ending the event loop ------------
116 
117 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
119  //The following says we do not know what parameters are allowed so do no validation
120  // Please change this to state exactly what you do use, even if it is no parameters
122  desc.setUnknown();
123  descriptions.addDefault(desc);
124 }
125 
126 //define this as a plug-in
std::pair< double, double > CorrectedEnergyWithError(const reco::Photon &p, const reco::VertexCollection &vtxcol, EcalClusterLazyTools &clustertools, CaloGeometry const &caloGeometry)
EGEnergyAnalyzer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endJob() override
EGEnergyCorrector corfile
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< EcalRecHitCollection > ebRHToken_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
EGEnergyCorrector::Initializer build(edm::EventSetup const &) const
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
~EGEnergyAnalyzer() override
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
ESData get(edm::EventSetup const &eventSetup) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< EcalRecHitCollection > eeRHToken_
EGEnergyCorrectorFactoryFromEventSetup corddbFactory_
void beginJob() override
std::optional< EGEnergyCorrector > cordb