Rivet  1.8.3
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
AnalysisHandler & addAnalyses(const std::vector< std::string > &analysisnames)
Definition: AnalysisHandler.cc:328
HistoFormat
Enumeration of available histogram output formats.
Definition: HistoFormat.hh:11
double crossSection() const
Get the cross-section known to the handler.
Definition: AnalysisHandler.hh:110
double sqrtS() const
Get energy for this run, usually determined from the first event.
Definition: AnalysisHandler.cc:402
bool needCrossSection() const
Is cross-section information required by at least one child analysis?
Definition: AnalysisHandler.cc:366
const std::set< AnaHandle, AnaHandleLess > & analyses() const
Get the collection of currently registered analyses.
Definition: AnalysisHandler.hh:149
AIDA::IDataPointSetFactory & datapointsetFactory()
Definition: AnalysisHandler.cc:361
AIDA::ITree & tree()
Definition: AnalysisHandler.cc:351
const ParticlePair & beams() const
Get beam IDs for this run, usually determined from the first event.
Definition: AnalysisHandler.hh:126
void analyze(const GenEvent &event)
Definition: AnalysisHandler.cc:106
void setSumOfWeights(const double &sum)
Definition: AnalysisHandler.cc:314
Definition: AnalysisHandler.hh:19
AnalysisHandler(const string &runname="")
Preferred constructor, with optional run name.
Definition: AnalysisHandler.cc:17
bool hasCrossSection() const
Whether the handler knows about a cross-section.
Definition: AnalysisHandler.cc:385
AnalysisHandler & setCrossSection(double xs)
Set the cross-section for the process being generated.
Definition: AnalysisHandler.cc:376
void finalize()
Definition: AnalysisHandler.cc:150
Definition: Logging.hh:9
~AnalysisHandler()
Destructor The destructor is not virtual, as this class should not be inherited from.
Definition: AnalysisHandler.cc:40
string runName() const
Get the name of this run.
Definition: AnalysisHandler.cc:309
This is the base class of all analysis classes in Rivet.
Definition: Analysis.hh:51
AnalysisHandler & removeAnalyses(const std::vector< std::string > &analysisnames)
Remove analyses from the run list using their names.
Definition: AnalysisHandler.cc:337
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition: Particle.fhh:20
void writeData(const std::string &filename)
Definition: AnalysisHandler.cc:252
std::vector< std::string > analysisNames() const
Get a list of the currently registered analyses&#39; names.
Definition: AnalysisHandler.cc:319
void init()
Definition: AnalysisHandler.hh:184
double sumOfWeights() const
Definition: AnalysisHandler.cc:311
std::pair< PdgId, PdgId > PdgIdPair
Typedef for a pair of particle names.
Definition: Particle.fhh:32
Definition: AnalysisHandler.hh:29
size_t numEvents() const
Definition: AnalysisHandler.cc:310
AnalysisHandler & addAnalysis(const std::string &analysisname)
Definition: AnalysisHandler.cc:182
AnalysisHandler & removeAnalysis(const std::string &analysisname)
Remove an analysis from the run list using its name.
Definition: AnalysisHandler.cc:204
AIDA::IHistogramFactory & histogramFactory()
Definition: AnalysisHandler.cc:356
shared_ptr< Analysis > AnaHandle
Typedef for Analysis (smart) pointer.
Definition: AnalysisHandler.hh:16
void setIgnoreBeams(bool ignore=true)
Setter for _ignoreBeams.
Definition: AnalysisHandler.cc:406
void commitData()
Definition: AnalysisHandler.cc:247
AIDA::IAnalysisFactory & analysisFactory()
Definition: AnalysisHandler.cc:346
PdgIdPair beamIds() const
Get beam IDs for this run, usually determined from the first event.
Definition: AnalysisHandler.cc:397
AnalysisHandler & setRunBeams(const ParticlePair &beams)
Set beams for this run.
Definition: AnalysisHandler.hh:119