CMS 3D CMS Logo

RivetAnalyzer.h
Go to the documentation of this file.
1 #ifndef GeneratorInterface_RivetInterface_RivetAnalyzer
2 #define GeneratorInterface_RivetInterface_RivetAnalyzer
3 
5 #include "Rivet/AnalysisHandler.hh"
6 
7 //DQM services
10 
14 
15 #include "Rivet/Tools/RivetYODA.hh"
16 //#include "YODA/ROOTCnv.h"
17 
18 #include <vector>
19 #include <string>
20 
21 class RivetAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
22 public:
24 
25  ~RivetAnalyzer() override;
26 
27  void beginJob() override;
28 
29  void endJob() override;
30 
31  void analyze(const edm::Event &, const edm::EventSetup &) override;
32 
33  void beginRun(const edm::Run &, const edm::EventSetup &) override;
34 
35  void endRun(const edm::Run &, const edm::EventSetup &) override;
36 
37 private:
38  void normalizeTree();
39 
48  Rivet::AnalysisHandler _analysisHandler;
53  double _xsection;
54 
56  std::vector<MonitorElement *> _mes;
57 };
58 
59 /*
60 template<class YODATYPE, class ROOTTYPE>
61 ROOTTYPE*
62  RivetAnalyzer::prebook(const YODATYPE* yodah, const std::string& name){
63  ROOTTYPE* h = 0;
64  if (yodah->axis().isFixedBinning() ) {//equidistant binning (easier case)
65  int nbins = yodah->axis().bins();
66  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, yodah->axis().lowerEdge(), yodah->axis().upperEdge());
67  } else {
68  int nbins = yodah->axis().bins();
69  const YODA::Axis1D* vax = dynamic_cast<const YODA::Axis1D*>(&yodah->axis());
70  if (! vax ){
71  throw cms::Exception("RivetAnalyzer") << "Cannot dynamix cast an YODA axis to VariAxis ";
72  }
73  double* bins = new double[nbins+1];
74  for (int i=0; i<nbins; ++i) {
75  bins[i] = vax->binEdges(i).first;
76  }
77  bins[nbins] = vax->binEdges(nbins-1).second; //take last bin right border
78  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, bins);
79  delete bins;
80  }
81  return h;
82 }
83 
84 template<>
85 TH1F* RivetAnalyzer::yoda2root(const YODA::IHistogram1D* yodah, const std::string& name){
86  TH1F* h = prebook<YODA::Histo1D, TH1F>(yodah, name);
87  for (int i = 0; i < yodah->axis().bins(); ++i){
88  h->SetBinContent(i+1, yodah->binHeight(i));
89  h->SetBinError(i+1, yodah->binError(i));
90  }
91  return h;
92 }
93 
94 template<>
95 TProfile* RivetAnalyzer::yoda2root(const YODA::IProfile1D* yodah, const std::string& name){
96  TProfile* h = prebook<YODA::IProfile1D, TProfile>(yodah, name);
97  for (int i = 0; i < yodah->axis().bins(); ++i){
98  h->SetBinContent(i+1, yodah->binMean(i));
99  h->SetBinError(i+1, yodah->binRms(i));
100  }
101  return h;
102 }
103 */
104 
105 #endif
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:48
void beginJob() override
void beginRun(const edm::Run &, const edm::EventSetup &) override
RivetAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
Definition: RivetAnalyzer.h:40
double _xsection
Definition: RivetAnalyzer.h:53
DQMStore * dbe
Definition: RivetAnalyzer.h:55
std::string _outFileName
Definition: RivetAnalyzer.h:50
void endJob() override
List of registered analysis data objects.
edm::EDGetTokenT< LHEEventProduct > _LHECollection
Definition: RivetAnalyzer.h:46
bool _useExternalWeight
Definition: RivetAnalyzer.h:41
edm::EDGetTokenT< GenEventInfoProduct > _genEventInfoCollection
Definition: RivetAnalyzer.h:47
void normalizeTree()
Definition: Run.h:45
std::vector< MonitorElement * > _mes
Definition: RivetAnalyzer.h:56
~RivetAnalyzer() override