Jpp  18.2.1-ARCA-DF-PATCH
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 namespace JPP { using namespace JAANET; }
19 
20 namespace JAANET {
21 
23 
24 
25  /**
26  * Helper class for event weighing.
27  */
29  public JSharedPointer<JEvtWeight>,
30  public JHead
31  {
33 
34  /**
35  * Default constructor.
36  */
38  counter(0)
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param weighter event weighter
46  */
47  JEvtWeightHelper(const JEvtWeight& weighter) :
48  counter(0)
49  {
50  this->configure(weighter);
51  }
52 
53 
54  /**
55  * Configuration.
56  *
57  * \param weighter event weighter
58  */
59  void configure(const JEvtWeight& weighter)
60  {
61  counter = 0;
62 
63  reset(weighter.clone());
64  }
65 
66 
67  /**
68  * Check if a given header is consistent with this event weighter.
69  *
70  * \param header header
71  * \return true if header is consistent with this event weighter; else false.
72  */
73  bool check(const JHead& header) const
74  {
75  return (is_valid() ? get()->check(header) : false);
76  }
77 
78 
79  /**
80  * Add header.
81  *
82  * \param header header
83  */
84  void add(const JHead& header)
85  {
86  using namespace JPP;
87 
88  if (check(header)) {
89 
90  if (counter == 0) {
91  JHead::setHeader(header);
92  } else {
93  JHead::add(header);
94  }
95 
96  ++counter;
97 
98  get()->configure(getHeader());
99 
100  } else {
101 
102  THROW(JNullPointerException, "JEvtWeightHelper::add(): headers do not match.");
103  }
104  }
105 
106 
107  /**
108  * Get weight of given event.
109  *
110  * \param evt event
111  * \return weight [Hz]
112  */
113  double getWeight(const Evt& evt) const
114  {
115  using namespace JPP;
116 
117  if (is_valid()) {
118  return get()->getWeight(evt);
119  } else {
120  THROW(JNullPointerException, "JEvtWeightHelper::getWeight(): Event weighter is null.");
121  }
122  }
123 
124 
125  /**
126  * Get event-weight normalisation.
127  *
128  * \return event-weight normalisation
129  */
130  double getNormalisation() const
131  {
132  using namespace JPP;
133 
134  if (is_valid()) {
135  return get()->getNormalisation();
136  } else {
137  THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null.");
138  }
139  }
140 
141 
142  /**
143  * Get event-weight normalisation.
144  *
145  * \param evt event
146  * \return event-weight normalisation
147  */
148  double getNormalisation(const Evt& evt) const
149  {
150  using namespace JPP;
151 
152  if (is_valid()) {
153  return get()->getNormalisation(evt);
154  } else {
155  THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null.");
156  }
157  }
158 
159 
160  private:
161  int counter;
162  };
163 }
164 
165 #endif
void configure(const JEvtWeight &weighter)
Configuration.
#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.
bool is_valid() const
Check validity of pointer.
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
The template JSharedPointer class can be used to share a pointer to an object.
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.
JEvtWeightHelper(const JEvtWeight &weighter)
Constructor.
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1292
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
double getNormalisation() const
Get event-weight normalisation.
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