rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.0
AnalysisHandler.hh
1 // -*- C++ -*-
2 #ifndef RIVET_RivetHandler_HH
3 #define RIVET_RivetHandler_HH
4 
5 #include "Rivet/Config/RivetCommon.hh"
6 #include "Rivet/Particle.hh"
7 #include "Rivet/AnalysisLoader.hh"
8 #include "Rivet/Tools/RivetYODA.hh"
9 
10 namespace Rivet {
11 
12 
13  // Forward declaration and smart pointer for Analysis
14  class Analysis;
15  typedef std::shared_ptr<Analysis> AnaHandle;
16 
17 
18  // Needed to make smart pointers compare equivalent in the STL set
19  struct CmpAnaHandle {
20  bool operator() (const AnaHandle& a, const AnaHandle& b) const {
21  return a.get() < b.get();
22  }
23  };
24 
25 
30  public:
31 
33 
34 
36  AnalysisHandler(const string& runname="");
37 
40  ~AnalysisHandler();
41 
43 
44 
45  private:
46 
48  Log& getLog() const;
49 
50 
51  public:
52 
54 
55 
57  string runName() const { return _runname; }
58 
59 
62  size_t numEvents() const { return _eventcounter.numEntries(); }
63 
68  double sumW() const { return _eventcounter.sumW(); }
70  double sumW2() const { return _eventcounter.sumW2(); }
71 
75  double sumOfWeights() const { return sumW(); }
76 
88  void setSumOfWeights(const double& sum) {
89  //_sumOfWeights = sum;
90  throw Error("Can't set sum of weights independently, since it's now tracked by a Counter. "
91  "Please contact the Rivet authors if you need this.");
92  }
93 
94 
97  bool needCrossSection() const;
100  bool hasCrossSection() const;
101 
103  double crossSection() const { return _xs; }
104 
106  AnalysisHandler& setCrossSection(double xs, double xserr=0);
107 
108 
110  AnalysisHandler& setRunBeams(const ParticlePair& beams) {
111  _beams = beams;
112  MSG_DEBUG("Setting run beams = " << beams << " @ " << sqrtS()/GeV << " GeV");
113  return *this;
114  }
115 
117  const ParticlePair& beams() const { return _beams; }
118 
121  PdgIdPair beamIds() const;
122 
125  double sqrtS() const;
126 
128  void setIgnoreBeams(bool ignore=true);
129 
131 
132 
134 
135 
137  std::vector<std::string> analysisNames() const;
138 
140  const std::set<AnaHandle, CmpAnaHandle>& analyses() const {
141  return _analyses;
142  }
143 
145  const AnaHandle analysis(const std::string& analysisname) const;
146 
147 
149  AnalysisHandler& addAnalysis(Analysis* analysis);
150 
156  AnalysisHandler& addAnalysis(const std::string& analysisname);
157 
159  AnalysisHandler& addAnalysis(const std::string& analysisname, std::map<string, string> pars);
160 
167  AnalysisHandler& addAnalyses(const std::vector<std::string>& analysisnames);
168 
169 
171  AnalysisHandler& removeAnalysis(const std::string& analysisname);
172 
174  AnalysisHandler& removeAnalyses(const std::vector<std::string>& analysisnames);
175 
177 
178 
180 
181 
183  void init(const GenEvent& event);
184 
189  void analyze(const GenEvent& event);
190 
195  void analyze(const GenEvent* event);
196 
199  void finalize();
200 
202 
203 
205 
206 
208  void addData(const std::vector<AnalysisObjectPtr>& aos);
209 
211  void readData(const std::string& filename);
212 
214  std::vector<AnalysisObjectPtr> getData(bool includeorphans = false,
215  bool includetmps = false) const;
216 
218  void writeData(const std::string& filename) const;
219 
223  void dump(string dumpfile, int period) {
224  _dumpPeriod = period;
225  _dumpFile = dumpfile;
226  }
227 
242  void mergeYodas(const vector<string> & aofiles,
243  const vector<string> & delopts = vector<string>(),
244  bool equiv = false);
245 
247  void stripOptions(AnalysisObjectPtr ao,
248  const vector<string> & delopts) const;
249 
251 
252  private:
253 
255  set<AnaHandle, CmpAnaHandle> _analyses;
256 
259  vector<AnalysisObjectPtr> _orphanedPreloads;
260 
263  vector<AnalysisObjectPtr> _finalizedAOs;
264 
266 
267 
269  std::string _runname;
270 
272  Counter _eventcounter;
273 
275  double _xs, _xserr;
276 
278  ParticlePair _beams;
279 
281  bool _initialised;
282 
284  bool _ignoreBeams;
285 
288  int _dumpPeriod;
289 
292  string _dumpFile;
293 
295  bool _dumping;
296 
298 
299 
300  private:
301 
304  AnalysisHandler& operator=(const AnalysisHandler&);
305 
309 
310  };
311 
312 
313 }
314 
315 #endif
Definition: ALICE_2010_I880049.cc:13
const ParticlePair & beams() const
Get the beam particles for this run, usually determined from the first event.
Definition: AnalysisHandler.hh:117
ParticlePair beams(const Event &e)
Get beam particles from an event.
Definition: Beam.cc:9
double crossSection() const
Get the cross-section known to the handler.
Definition: AnalysisHandler.hh:103
void setSumOfWeights(const double &sum)
Set the sum of weights.
Definition: AnalysisHandler.hh:88
double sumW2() const
Access to the sum of squared-weights.
Definition: AnalysisHandler.hh:70
double sqrtS(const FourMomentum &pa, const FourMomentum &pb)
Get beam centre-of-mass energy from a pair of beam momenta.
Definition: Beam.cc:35
Definition: AnalysisHandler.hh:19
Definition: Logging.hh:9
Generic runtime Rivet error.
Definition: Exceptions.hh:12
double sumOfWeights() const
Compatibility alias for sumOfWeights.
Definition: AnalysisHandler.hh:75
This is the base class of all analysis classes in Rivet.
Definition: Analysis.hh:52
T sum(const CONTAINER &c, const T &start=T())
Generic sum function, adding x for all x in container c, starting with start.
Definition: Utils.hh:345
PdgIdPair beamIds(const ParticlePair &beams)
Definition: Beam.hh:21
Definition: AnalysisHandler.hh:29
void dump(string dumpfile, int period)
Definition: AnalysisHandler.hh:223
double sumW() const
Access the sum of the event weights seen.
Definition: AnalysisHandler.hh:68
const std::set< AnaHandle, CmpAnaHandle > & analyses() const
Get the collection of currently registered analyses.
Definition: AnalysisHandler.hh:140
size_t numEvents() const
Definition: AnalysisHandler.hh:62
string runName() const
Get the name of this run.
Definition: AnalysisHandler.hh:57
AnalysisHandler & setRunBeams(const ParticlePair &beams)
Set the beam particles for this run.
Definition: AnalysisHandler.hh:110