Jpp  18.6.0-rc.1
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  * Get name.
51  *
52  * \return name
53  */
54  const char* const getName() const
55  {
56  return getEvtWeighter().getName();
57  }
58 
59 
60  /**
61  * Configuration.
62  *
63  * \param weighter event weighter
64  */
65  void configure(const JEvtWeight& weighter)
66  {
67  counter = 0;
68 
69  reset(weighter.clone());
70  }
71 
72 
73  /**
74  * Check if a given header is consistent with this event weighter.
75  *
76  * \param header header
77  * \return true if header is consistent with this event weighter; else false.
78  */
79  bool check(const JHead& header) const
80  {
81  const JEvtWeight& weighter = getEvtWeighter();
82 
83  return weighter.check(header);
84  }
85 
86 
87  /**
88  * Get reference to event-weighter.
89  *
90  * \return reference to event-weighter
91  */
93  {
94  using namespace JPP;
95 
96  if (static_cast<const JEvtWeightHelper&>(*this)) {
97  return *(this->get());
98  } else {
99  THROW(JNullPointerException, "JEvtWeightHelper::getEvtWeighter(): Event-weighter is not set.");
100  }
101  }
102 
103 
104  /**
105  * Add header.
106  *
107  * \param header header
108  */
109  void add(const JHead& header)
110  {
111  using namespace JPP;
112 
113  JEvtWeight& weighter = getEvtWeighter();
114 
115  if (check(header)) {
116 
117  if (counter == 0) {
118  JHead::setHeader(header);
119  } else {
120  JHead::add(header);
121  }
122 
123  ++counter;
124 
125  weighter.configure(getHeader());
126 
127  } else {
128 
129  THROW(JValueOutOfRange, "JEvtWeightHelper::add(): headers do not match.");
130  }
131  }
132 
133 
134  /**
135  * Get weight of given event.
136  *
137  * \param evt event
138  * \return weight [Hz]
139  */
140  double getWeight(const Evt& evt) const
141  {
142  const JEvtWeight& weighter = getEvtWeighter();
143 
144  return weighter.getWeight(evt);
145  }
146 
147 
148  /**
149  * Get event-weight normalisation.
150  *
151  * \return event-weight normalisation
152  */
153  double getNormalisation() const
154  {
155  const JEvtWeight& weighter = getEvtWeighter();
156 
157  return weighter.getNormalisation();
158  }
159 
160 
161  /**
162  * Get event-weight normalisation.
163  *
164  * \param evt event
165  * \return event-weight normalisation
166  */
167  double getNormalisation(const Evt& evt) const
168  {
169  const JEvtWeight& weighter = getEvtWeighter();
170 
171  return weighter.getNormalisation(evt);
172  }
173 
174 
175  private:
176 
177  int counter; //!< Counter to check how many headers have been added
178  };
179 }
180 
181 #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.
const char *const getName() const
Get name.
virtual const char *const getName() const =0
Get name.
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:1531
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