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 {
23  public:
25 
26  ~RivetAnalyzer() override;
27 
28  void beginJob() override;
29 
30  void endJob() override;
31 
32  void analyze(const edm::Event&, const edm::EventSetup&) override;
33 
34  void beginRun(const edm::Run&, const edm::EventSetup&) override;
35 
36  void endRun(const edm::Run&, const edm::EventSetup&) override;
37 
38  private:
39 
40  void normalizeTree();
41 
50  Rivet::AnalysisHandler _analysisHandler;
55  double _xsection;
56 
58  std::vector<MonitorElement *> _mes;
59 };
60 
61 
62 /*
63 template<class YODATYPE, class ROOTTYPE>
64 ROOTTYPE*
65  RivetAnalyzer::prebook(const YODATYPE* yodah, const std::string& name){
66  ROOTTYPE* h = 0;
67  if (yodah->axis().isFixedBinning() ) {//equidistant binning (easier case)
68  int nbins = yodah->axis().bins();
69  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, yodah->axis().lowerEdge(), yodah->axis().upperEdge());
70  } else {
71  int nbins = yodah->axis().bins();
72  const YODA::Axis1D* vax = dynamic_cast<const YODA::Axis1D*>(&yodah->axis());
73  if (! vax ){
74  throw cms::Exception("RivetAnalyzer") << "Cannot dynamix cast an YODA axis to VariAxis ";
75  }
76  double* bins = new double[nbins+1];
77  for (int i=0; i<nbins; ++i) {
78  bins[i] = vax->binEdges(i).first;
79  }
80  bins[nbins] = vax->binEdges(nbins-1).second; //take last bin right border
81  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, bins);
82  delete bins;
83  }
84  return h;
85 }
86 
87 template<>
88 TH1F* RivetAnalyzer::yoda2root(const YODA::IHistogram1D* yodah, const std::string& name){
89  TH1F* h = prebook<YODA::Histo1D, TH1F>(yodah, name);
90  for (int i = 0; i < yodah->axis().bins(); ++i){
91  h->SetBinContent(i+1, yodah->binHeight(i));
92  h->SetBinError(i+1, yodah->binError(i));
93  }
94  return h;
95 }
96 
97 template<>
98 TProfile* RivetAnalyzer::yoda2root(const YODA::IProfile1D* yodah, const std::string& name){
99  TProfile* h = prebook<YODA::IProfile1D, TProfile>(yodah, name);
100  for (int i = 0; i < yodah->axis().bins(); ++i){
101  h->SetBinContent(i+1, yodah->binMean(i));
102  h->SetBinError(i+1, yodah->binRms(i));
103  }
104  return h;
105 }
106 */
107 
108 #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:50
void beginJob() override
void beginRun(const edm::Run &, const edm::EventSetup &) override
RivetAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
Definition: RivetAnalyzer.h:42
double _xsection
Definition: RivetAnalyzer.h:55
DQMStore * dbe
Definition: RivetAnalyzer.h:57
std::string _outFileName
Definition: RivetAnalyzer.h:52
void endJob() override
List of registered analysis data objects.
edm::EDGetTokenT< LHEEventProduct > _LHECollection
Definition: RivetAnalyzer.h:48
bool _useExternalWeight
Definition: RivetAnalyzer.h:43
edm::EDGetTokenT< GenEventInfoProduct > _genEventInfoCollection
Definition: RivetAnalyzer.h:49
void normalizeTree()
Definition: Run.h:44
std::vector< MonitorElement * > _mes
Definition: RivetAnalyzer.h:58
~RivetAnalyzer() override