CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RivetAnalyzer.h
Go to the documentation of this file.
1 #ifndef GeneratorInterface_RivetInterface_RivetAnalyzer
2 #define GeneratorInterface_RivetInterface_RivetAnalyzer
3 
6 #include "Rivet/RivetAIDA.fhh"
7 #include "Rivet/AnalysisHandler.hh"
8 
9 //DQM services
13 
14 #include "Rivet/RivetAIDA.hh"
15 #include "LWH/AIHistogramFactory.h"
16 #include "LWH/VariAxis.h"
17 
18 #include <vector>
19 #include <string>
20 
21 namespace edm{
22  class ParameterSet;
23  class Event;
24  class EventSetup;
25  class InputTag;
26 }
27 
29 {
30  public:
32 
33  virtual ~RivetAnalyzer();
34 
35  virtual void beginJob();
36 
37  virtual void endJob();
38 
39  virtual void analyze(const edm::Event&, const edm::EventSetup&);
40 
41  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
42 
43  virtual void endRun(const edm::Run&, const edm::EventSetup&);
44 
45  private:
46 
47  void normalizeTree(AIDA::ITree& tree);
48  template<class AIDATYPE, class ROOTTYPE> ROOTTYPE* prebook(const AIDATYPE*, const std::string&);
49  template<class AIDATYPE, class ROOTTYPE> ROOTTYPE* aida2root(const AIDATYPE*, const std::string&);
50 
51 
55  Rivet::AnalysisHandler _analysisHandler;
57  std::string _outFileName;
60 
62  std::vector<MonitorElement *> _mes;
63 };
64 
65 template<class AIDATYPE, class ROOTTYPE>
66 ROOTTYPE*
67 RivetAnalyzer::prebook(const AIDATYPE* aidah, const std::string& name){
68  ROOTTYPE* h = 0;
69  if (aidah->axis().isFixedBinning() ) {//equidistant binning (easier case)
70  int nbins = aidah->axis().bins();
71  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, aidah->axis().lowerEdge(), aidah->axis().upperEdge());
72  } else {
73  int nbins = aidah->axis().bins();
74  //need to dyn cast, IAxis lacks polymorfism
75  const LWH::VariAxis* vax = dynamic_cast<const LWH::VariAxis*>(&aidah->axis());
76  if (! vax ){
77  throw cms::Exception("RivetAnalyzer") << "Cannot dynamix cast an AIDA axis to VariAxis ";
78  }
79  double* bins = new double[nbins+1];
80  for (int i=0; i<nbins; ++i) {
81  bins[i] = vax->binEdges(i).first;
82  }
83  bins[nbins] = vax->binEdges(nbins-1).second; //take last bin right border
84  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, bins);
85  delete bins;
86  }
87  return h;
88 }
89 
90 template<>
91 TH1F* RivetAnalyzer::aida2root(const AIDA::IHistogram1D* aidah, const std::string& name){
92  /*TH1F* h = 0;
93  if (aidah->axis().isFixedBinning() ) {//equidistant binning (easier case)
94  int nbins = aidah->axis().bins();
95  h = new TH1F(name.c_str(), name.c_str(), nbins, aidah->axis().lowerEdge(), aidah->axis().upperEdge());
96  } else {
97  int nbins = aidah->axis().bins();
98  //need to dyn cast, IAxis lacks polymorfism
99  const LWH::VariAxis* vax = dynamic_cast<const LWH::VariAxis*>(&aidah->axis());
100  if (! vax ){
101  throw cms::Exception("RivetAnalyzer") << "Cannot dynamix cast an AIDA axis to VariAxis ";
102  }
103  double* bins = new double[nbins+1];
104  for (int i=0; i<nbins; ++i) {
105  bins[i] = vax->binEdges(i).first;
106  }
107  bins[nbins] = vax->binEdges(nbins-1).second; //take last bin right border
108  h = new TH1F(name.c_str(), name.c_str(), nbins, bins);
109  delete bins;
110  }
111  */
112  TH1F* h = prebook<AIDA::IHistogram1D, TH1F>(aidah, name);
113  for (int i = 0; i < aidah->axis().bins(); ++i){
114  h->SetBinContent(i+1, aidah->binHeight(i));
115  h->SetBinError(i+1, aidah->binError(i));
116  }
117  return h;
118 }
119 
120 template<>
121 TProfile* RivetAnalyzer::aida2root(const AIDA::IProfile1D* aidah, const std::string& name){
122  TProfile* h = prebook<AIDA::IProfile1D, TProfile>(aidah, name);
123  for (int i = 0; i < aidah->axis().bins(); ++i){
124  h->SetBinContent(i+1, aidah->binMean(i));
125  h->SetBinError(i+1, aidah->binRms(i));
126  }
127  return h;
128 }
129 
130 
131 #endif
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
int i
Definition: DBlmapReader.cc:9
virtual void endRun(const edm::Run &, const edm::EventSetup &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
ROOTTYPE * prebook(const AIDATYPE *, const std::string &)
Definition: RivetAnalyzer.h:67
edm::InputTag _hepmcCollection
Definition: RivetAnalyzer.h:52
ROOTTYPE * aida2root(const AIDATYPE *, const std::string &)
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:55
RivetAnalyzer(const edm::ParameterSet &)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
DQMStore * dbe
Definition: RivetAnalyzer.h:61
std::string _outFileName
Definition: RivetAnalyzer.h:57
void normalizeTree(AIDA::ITree &tree)
bool _useExternalWeight
Definition: RivetAnalyzer.h:53
edm::InputTag _genEventInfoCollection
Definition: RivetAnalyzer.h:54
virtual ~RivetAnalyzer()
virtual void beginJob()
Definition: Run.h:33
virtual void endJob()
std::vector< MonitorElement * > _mes
Definition: RivetAnalyzer.h:62