Rivet analyses referenceMC_OPTIONSExperiment: () Status: VALIDATED Authors:
Beams: * * Beam energies: ANY
Just an example of the options system in action. Source code: MC_OPTIONS.cc 1// -*- C++ -*-
2#include "Rivet/Analysis.hh"
3
4namespace Rivet {
5 using std::istream;
6 using std::ostream;
7
8 // Example analysis to show how to use options in an analysis
9 // Example of a custom class to be read in from an option.
10 class A {
11 public:
12 A() : a(-1.0) {}
13 private:
14 double a;
15 // Custom class must be streamable.
16 friend istream& operator>> (istream& is, A& a);
17 friend ostream& operator<< (ostream& os, const A& a);
18 };
19
20 // Custom class must be streamable.
21 istream& operator>> (istream& is, A& a) {
22 is >> a.a;
23 return is;
24 }
25 ostream& operator<< (ostream& os, const A& a) {
26 os << a.a;
27 return os;
28 }
29
30 class MC_OPTIONS : public Analysis {
31 public:
32
33 /// Constructor
34 RIVET_DEFAULT_ANALYSIS_CTOR(MC_OPTIONS);
35
36 /// @name Analysis methods
37 /// @{
38
39 /// Book histograms and initialise projections before the run
40 void init() {
41
42
43 // Parameters read in.
44 // A double.
45 double f = getOption<double>("foo", 1.0);
46 // A string.
47 string s = getOption<string>("bar", "");
48 // A custom object.
49 A a = getOption<A>("baz", A());
50
51 cout << "foo = " << f << endl;
52 cout << "bar = " << s << endl;
53 cout << "baz = " << a << endl;
54 value = f;
55 book(h, "hist",10,0,10);
56 }
57
58 // Perform the per-event analysis
59 void analyze(const Event&) {
60 h->fill(value);
61
62 }
63
64
65 /// Finalize
66 void finalize() {
67
68 }
69
70 /// @}
71
72
73 private:
74
75 /// @name Histograms
76 /// @{
77 Histo1DPtr h;
78 /// @}
79 double value;
80
81 };
82
83
84 RIVET_DECLARE_PLUGIN(MC_OPTIONS);
85
86}
|