Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightHelper.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTHELPER__
2 #define __JAANET__JEVTWEIGHTHELPER__
3 
4 #include <memory>
5 
8 
9 #include "JAAnet/JHead.hh"
10 #include "JAAnet/JEvtWeight.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JAANET {}
18 namespace JPP { using namespace JAANET; }
19 
20 namespace JAANET {
21 
22  /**
23  * Helper class for event weighing.
24  */
26  public JHead,
27  public std::shared_ptr<JEvtWeight>
28  {
29  /**
30  * Default constructor.
31  */
33  counter(0)
34  {}
35 
36 
37  /**
38  * Constructor.
39  *
40  * \param weighter event weighter
41  */
42  JEvtWeightHelper(const JEvtWeight& weighter) :
43  counter(0)
44  {
45  this->configure(weighter);
46  }
47 
48 
49  /**
50  * Configuration.
51  *
52  * \param weighter event weighter
53  */
54  void configure(const JEvtWeight& weighter)
55  {
56  counter = 0;
57 
58  reset(weighter.clone());
59  }
60 
61 
62  /**
63  * Check if a given header is consistent with this event weighter.
64  *
65  * \param header header
66  * \return true if header is consistent with this event weighter; else false.
67  */
68  bool check(const JHead& header) const
69  {
70  const JEvtWeight& weighter = getEvtWeighter();
71 
72  return weighter.check(header);
73  }
74 
75 
76  /**
77  * Get reference to event-weighter.
78  *
79  * \return reference to event-weighter
80  */
82  {
83  using namespace JPP;
84 
85  if (static_cast<const JEvtWeightHelper&>(*this)) {
86  return *(this->get());
87  } else {
88  THROW(JNullPointerException, "JEvtWeightHelper::getEvtWeighter(): Event-weighter is not set.");
89  }
90  }
91 
92 
93  /**
94  * Add header.
95  *
96  * \param header header
97  */
98  void add(const JHead& header)
99  {
100  using namespace JPP;
101 
102  JEvtWeight& weighter = getEvtWeighter();
103 
104  if (check(header)) {
105 
106  if (counter == 0) {
107  JHead::setHeader(header);
108  } else {
109  JHead::add(header);
110  }
111 
112  ++counter;
113 
114  weighter.configure(getHeader());
115 
116  } else {
117 
118  THROW(JValueOutOfRange, "JEvtWeightHelper::add(): headers do not match.");
119  }
120  }
121 
122 
123  /**
124  * Get weight of given event.
125  *
126  * \param evt event
127  * \return weight [Hz]
128  */
129  double getWeight(const Evt& evt) const
130  {
131  const JEvtWeight& weighter = getEvtWeighter();
132 
133  return weighter.getWeight(evt);
134  }
135 
136 
137  /**
138  * Get event-weight normalisation.
139  *
140  * \return event-weight normalisation
141  */
142  double getNormalisation() const
143  {
144  const JEvtWeight& weighter = getEvtWeighter();
145 
146  return weighter.getNormalisation();
147  }
148 
149 
150  /**
151  * Get event-weight normalisation.
152  *
153  * \param evt event
154  * \return event-weight normalisation
155  */
156  double getNormalisation(const Evt& evt) const
157  {
158  const JEvtWeight& weighter = getEvtWeighter();
159 
160  return weighter.getNormalisation(evt);
161  }
162 
163 
164  private:
165 
166  int counter; //!< Counter to check how many headers have been added
167  };
168 }
169 
170 #endif
void configure(const JEvtWeight &weighter)
Configuration.
JEvtWeight & getEvtWeighter() const
Get reference to event-weighter.
virtual bool check(const JHead &header) const =0
Check whether header is consistent with this event weighter.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
JEvtWeightHelper()
Default constructor.
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
int counter
Counter to check how many headers have been added.
double getNormalisation(const Evt &evt) const
Get event-weight normalisation.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
Abstract base class for event weighing.
Definition: JEvtWeight.hh:28
Monte Carlo run header.
Definition: JHead.hh:1234
JHead & add(const JHead &header)
Addition of headers.
Definition: JHead.hh:1529
double getWeight(const Evt &evt) const
Get weight of given event.
void reset(T &value)
Reset value.
JEvtWeightHelper(const JEvtWeight &weighter)
Constructor.
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1292
virtual double getWeight(const Evt &evt) const =0
Get weight of given event.
virtual double getNormalisation() const override
Get event-weight normalisation.
Definition: JEvtWeight.hh:52
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
double getNormalisation() const
Get event-weight normalisation.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
Helper class for event weighing.
void add(const JHead &header)
Add header.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20