Jpp  17.1.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 
6 
8 
9 #include "JAAnet/JHead.hh"
10 #include "JAAnet/JEvtWeight.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JAANET {
18 
22 
23 
24  /**
25  * Helper class for event weighing.
26  */
28  public JSharedPointer<JEvtWeight>,
29  public JHead
30  {
32 
33  /**
34  * Default constructor.
35  */
37  counter(0)
38  {}
39 
40 
41  /**
42  * Constructor.
43  *
44  * \param weighter event weighter
45  */
46  JEvtWeightHelper(const JEvtWeight& weighter) :
47  counter(0)
48  {
49  this->configure(weighter);
50  }
51 
52 
53  /**
54  * Configuration.
55  *
56  * \param weighter event weighter
57  */
58  void configure(const JEvtWeight& weighter)
59  {
60  counter = 0;
61 
62  reset(weighter.clone());
63  }
64 
65 
66  /**
67  * Check if a given header is consistent with this event weighter.
68  *
69  * \param header header
70  * \return true if header is consistent with this event weighter; else false.
71  */
72  bool check(const JHead& header) const
73  {
74  return (is_valid() ? get()->check(header) : false);
75  }
76 
77 
78  /**
79  * Add header.
80  *
81  * \param header header
82  */
83  void add(const JHead& header)
84  {
85  if (check(header)) {
86 
87  if (counter == 0) {
88  JHead::setHeader(header);
89  } else {
90  JHead::add(header);
91  }
92 
93  ++counter;
94 
95  get()->configure(getHeader());
96 
97  } else {
98 
99  THROW(JNullPointerException, "JEvtWeightHelper::add(): headers do not match.");
100  }
101  }
102 
103 
104  /**
105  * Get weight of given event.
106  *
107  * \param evt event
108  * \return weight [Hz]
109  */
110  double getWeight(const Evt& evt) const
111  {
112  if (is_valid()) {
113  return get()->getWeight(evt);
114  } else {
115  THROW(JNullPointerException, "JEvtWeightHelper::getWeight(): Event weighter is null.");
116  }
117  }
118 
119 
120  /**
121  * Get event-weight normalisation.
122  *
123  * \return event-weight normalisation
124  */
125  double getNormalisation() const
126  {
127  if (is_valid()) {
128  return get()->getNormalisation();
129  } else {
130  THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null.");
131  }
132  }
133 
134  private:
135  int counter;
136  };
137 }
138 
139 #endif
void configure(const JEvtWeight &weighter)
Configuration.
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1224
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1202
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JEvtWeightHelper()
Default constructor.
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
JHead & add(const JHead &header)
Addition of headers.
Definition: JHead.hh:1445
bool is_valid() const
Check validity of pointer.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
The template JSharedPointer class can be used to share a pointer to an object.
Abstract base class for event weighing.
Definition: JEvtWeight.hh:21
Exception for null pointer operation.
Definition: JException.hh:216
Monte Carlo run header.
Definition: JHead.hh:1167
double getWeight(const Evt &evt) const
Get weight of given event.
JEvtWeightHelper(const JEvtWeight &weighter)
Constructor.
double getNormalisation() const
Get event-weight normalisation.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
virtual void reset() override
Reset pointer.
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