Rivet Analyses Reference

MC_OPTIONS


Experiment: ()
Status: VALIDATED
Authors:
  • Christian Bierlich
No references listed
Beams: * *
Beam energies: ANY
    No run details listed

Just an example of the options system in action.

Source code: MC_OPTIONS.cc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// -*- C++ -*-
#include "Rivet/Analysis.hh"

namespace Rivet {
  using std::istream;
  using std::ostream;

  // Example analysis to show how to use options in an analysis
  // Example of a custom class to be read in from an option.
  class A {
  public:
    A() : a(-1.0) {}
  private:
    double a;
    // Custom class must be streamable.
    friend istream& operator>> (istream& is, A& a);
    friend ostream& operator<< (ostream& os, const A& a);
  };
  
  // Custom class must be streamable.
  istream& operator>> (istream& is, A& a) {
    is >> a.a;
    return is;
  }
  ostream& operator<< (ostream& os, const A& a) {
    os << a.a;
    return os;
  }

  class MC_OPTIONS : public Analysis {
  public:

    /// Constructor
    RIVET_DEFAULT_ANALYSIS_CTOR(MC_OPTIONS);

    /// @name Analysis methods
    //@{

    /// Book histograms and initialise projections before the run
    void init() {


      // Parameters read in.
      // A double.
      double f = getOption<double>("foo", 1.0);
      // A string.
      string s = getOption<string>("bar", "");
      // A custom object. 
      A a = getOption<A>("baz", A());

      cout << "foo = " << f << endl;
      cout << "bar = " << s << endl;
      cout << "baz = " << a << endl;
      value = f;
      book(h, "hist",10,0,10);
    }

    // Perform the per-event analysis
    void analyze(const Event& event) {
      h->fill(value);

    }


    /// Finalize
    void finalize() {
    
    }

    //@}


  private:

    /// @name Histograms
    //@{
    Histo1DPtr h;
    //@}
    double value;
    
  };


  // The hook for the plugin system
  RIVET_DECLARE_PLUGIN(MC_OPTIONS);

}