gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
EventCounter.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
16 
17 #pragma once
18 
19 #include <string>
20 #include "HEPUtils/Event.h"
21 
22 namespace Gambit {
23  namespace ColliderBit {
24 
27  {
28 
29  private:
30 
31  std::string _name;
32  int _sum;
33  double _weight_sum;
35 
36  public:
37 
38  // Constructors
40  _name(""),
41  _sum(0),
42  _weight_sum(0.0),
43  _weight_sum_err(0.0)
44  { }
45 
46  EventCounter(const std::string name) :
47  _name(name),
48  _sum(0),
49  _weight_sum(0.0),
50  _weight_sum_err(0.0)
51  { }
52 
53 
54  // Initialize
55  void init(const std::string name)
56  {
57  _name = name;
58  _sum = 0;
59  _weight_sum = 0;
60  _weight_sum_err = 0;
61  }
62 
63  // Reset
64  void reset()
65  {
66  _sum = 0;
67  _weight_sum = 0;
68  _weight_sum_err = 0;
69  }
70 
71  // Set name
72  void set_name(const std::string name) { _name = name; }
73  // Get name
74  std::string name() const { return _name; }
75 
76  // Set sum
77  void set_sum(int sum) { _sum = sum; }
78  // Get sum
79  int sum() const { return _sum; }
80 
81  // Set weight sum
82  void set_weight_sum(double weight_sum) { _weight_sum = weight_sum; }
83  // Get weight sum
84  double weight_sum() const { return _weight_sum; }
85 
86  // Set weight sum error
87  void set_weight_sum_err(double weight_sum_err) { _weight_sum_err = weight_sum_err; }
88  // Get weight sum error
89  double weight_sum_err() const { return _weight_sum_err; }
90 
91  // Increment event count directly, with optional weights arguments
92  void add_event(double w = 1.0, double werr = 0.0)
93  {
94  _sum++;
95  _weight_sum += w;
96  _weight_sum_err = sqrt((_weight_sum_err * _weight_sum_err) + (werr * werr));
97  }
98 
99  // Increment event count with weigths from an HEPUtils::Event
100  void add_event(const HEPUtils::Event& event)
101  {
102  add_event(event.weight(), event.weight_err());
103  }
104 
105  void add_event(const HEPUtils::Event* event_ptr)
106  {
107  add_event(*event_ptr);
108  }
109 
110  // Increment event count with the operator+= and HEPUtils::Event input
111  EventCounter& operator+=(const HEPUtils::Event& event)
112  {
113  add_event(event);
114  return *this;
115  }
116 
117  // Increment event count with the operator+= and EventCounter input
119  {
120  _sum += rhs.sum();
121  _weight_sum += rhs.weight_sum();
122  _weight_sum_err = sqrt( (_weight_sum_err * _weight_sum_err) + (rhs.weight_sum_err() * rhs.weight_sum_err()) );
123  return *this;
124  }
125 
126  // Add the content of another EventCounter to this one
128  {
129  _sum += other.sum();
130  _weight_sum += other.weight_sum();
131 
132  double other_weight_sum_err = other.weight_sum_err();
133  _weight_sum_err = sqrt((_weight_sum_err * _weight_sum_err) + (other_weight_sum_err * other_weight_sum_err));
134 
135  return *this;
136  }
137 
138  };
139 
140  }
141 }
void set_weight_sum(double weight_sum)
EventCounter & combine(const EventCounter &other)
void add_event(const HEPUtils::Event &event)
void init(const std::string name)
EventCounter & operator+=(const HEPUtils::Event &event)
EventCounter(const std::string name)
A simple class for counting events of type HEPUtils::Event.
void set_name(const std::string name)
void add_event(double w=1.0, double werr=0.0)
EventCounter & operator+=(const EventCounter &rhs)
void add_event(const HEPUtils::Event *event_ptr)
TODO: see if we can use this one:
Definition: Analysis.hpp:33
void set_weight_sum_err(double weight_sum_err)