Rivet  1.8.0
AnalysisHandler.hh
1 // -*- C++ -*-
2 #ifndef RIVET_RivetHandler_HH
3 #define RIVET_RivetHandler_HH
4 
5 #include "Rivet/Rivet.hh"
6 #include "Rivet/RivetBoost.hh"
7 #include "Rivet/Tools/Logging.fhh"
8 #include "Rivet/AnalysisHandler.fhh"
9 #include "Rivet/Analysis.fhh"
10 #include "Rivet/Event.fhh"
11 #include "Rivet/AnalysisLoader.hh"
12 
13 namespace Rivet {
14 
16  typedef shared_ptr<Analysis> AnaHandle;
17 
18  // Needed to make smart pointers compare equivalent in the STL set
19  struct AnaHandleLess {
20  bool operator()(const AnaHandle& a, const AnaHandle& b) {
21  return a.get() < b.get();
22  }
23  };
24 
25 
30  public:
31 
33 
34 
36  AnalysisHandler(const string& runname="");
37 
38 
51  AnalysisHandler(const string& basefilename, const string& runname, HistoFormat storetype=AIDAML);
52 
53 
57 
59 
60 
61  private:
62 
65  void _setupFactories(const string& basefilename, HistoFormat storetype);
66 
69  void _setupFactories();
70 
73  void _normalizeTree(AIDA::ITree& tree);
74 
76  Log& getLog() const;
77 
78 
79  public:
80 
82 
83 
85  string runName() const;
86 
87 
90  size_t numEvents() const;
91 
95  double sumOfWeights() const;
96 
100  void setSumOfWeights(const double& sum);
101 
102 
104  bool needCrossSection() const;
105 
107  AnalysisHandler& setCrossSection(double xs);
108 
110  double crossSection() const {
111  return _xs;
112  }
113 
115  bool hasCrossSection() const;
116 
117 
120  _beams = beams;
121  MSG_DEBUG("Setting run beams = " << beams << " @ " << sqrtS()/GeV << " GeV");
122  return *this;
123  }
124 
126  const ParticlePair& beams() const {
127  return _beams;
128  }
129 
131  PdgIdPair beamIds() const;
132 
134  double sqrtS() const;
135 
137  void setIgnoreBeams(bool ignore=true);
138 
140 
141 
143 
144 
146  std::vector<std::string> analysisNames() const;
147 
149  const std::set<AnaHandle, AnaHandleLess>& analyses() const {
150  return _analyses;
151  }
152 
157  AnalysisHandler& addAnalysis(const std::string& analysisname);
158 
160  AnalysisHandler& removeAnalysis(const std::string& analysisname);
161 
162 
168  AnalysisHandler& addAnalyses(const std::vector<std::string>& analysisnames);
169 
171  AnalysisHandler& removeAnalyses(const std::vector<std::string>& analysisnames);
172 
173 
176 
178 
179 
181 
182 
184  void init() {}
185 
186 
188  void init(const GenEvent& event);
189 
190 
193  void analyze(const GenEvent& event);
194 
195 
200  void finalize();
201 
203 
204 
207 
208 
211  AIDA::IAnalysisFactory& analysisFactory();
212 
213 
216  void commitData();
217 
218 
221  void writeData(const std::string& filename);
222 
223 
226  AIDA::ITree& tree();
227 
228 
231  AIDA::IHistogramFactory& histogramFactory();
232 
233 
236  AIDA::IDataPointSetFactory& datapointsetFactory();
237 
239 
240 
241  private:
242 
244  set<AnaHandle, AnaHandleLess> _analyses;
245 
246 
248 
249 
251  std::string _runname;
252 
254  size_t _numEvents;
255 
257  double _sumOfWeights;
258 
260  double _xs;
261 
263  ParticlePair _beams;
264 
266  bool _initialised;
267 
269  bool _ignoreBeams;
270 
272 
273 
276 
277 
279  shared_ptr<AIDA::IAnalysisFactory> _theAnalysisFactory;
280 
282  AIDA::ITreeFactory* _theTreeFactory;
283 
285  AIDA::ITree* _theTree;
286 
288  AIDA::IHistogramFactory* _theHistogramFactory;
289 
291  AIDA::IDataPointSetFactory* _theDataPointSetFactory;
292 
294 
295 
296  private:
297 
300  AnalysisHandler& operator=(const AnalysisHandler&);
301 
305 
306  };
307 
308 
309 }
310 
311 #endif