Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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
17namespace JAANET {}
18namespace JPP { using namespace JAANET; }
19
20namespace JAANET {
21
22 /**
23 * Helper class for event weighing.
24 */
26 public JHead,
27 public std::shared_ptr<JEvtWeight>
28 {
29 typedef std::shared_ptr<JEvtWeight> pointer_type;
30
31 /**
32 * Default constructor.
33 */
35 counter(0)
36 {}
37
38
39 /**
40 * Constructor.
41 *
42 * \param weighter event weighter
43 */
44 JEvtWeightHelper(const JEvtWeight& weighter) :
45 counter(0)
46 {
47 this->configure(weighter);
48 }
49
50
51 /**
52 * Get name.
53 *
54 * \return name
55 */
56 const char* const getName() const
57 {
58 return getEvtWeighter().getName();
59 }
60
61
62 /**
63 * Configuration.
64 *
65 * \param weighter event weighter
66 */
67 void configure(const JEvtWeight& weighter)
68 {
69 counter = 0;
70
71 reset(weighter.clone());
72 }
73
74
75 /**
76 * Check if a given header is consistent with this event weighter.
77 *
78 * \param header header
79 * \return true if header is consistent with this event weighter; else false.
80 */
81 bool check(const JHead& header) const
82 {
83 const JEvtWeight& weighter = getEvtWeighter();
84
85 return weighter.check(header);
86 }
87
88
89 /**
90 * Get reference to event-weighter.
91 *
92 * \return reference to event-weighter
93 */
95 {
96 using namespace JPP;
97
98 if (static_cast<const JEvtWeightHelper&>(*this)) {
99 return *(this->get());
100 } else {
101 THROW(JNullPointerException, "JEvtWeightHelper::getEvtWeighter(): Event-weighter is not set.");
102 }
103 }
104
105
106 /**
107 * Add header.
108 *
109 * \param header header
110 */
111 void add(const JHead& header)
112 {
113 using namespace JPP;
114
115 JEvtWeight& weighter = getEvtWeighter();
116
117 if (check(header)) {
118
119 if (counter == 0) {
120 JHead::setHeader(header);
121 } else {
122 JHead::add(header);
123 }
124
125 ++counter;
126
127 weighter.configure(getHeader());
128
129 } else {
130
131 THROW(JValueOutOfRange, "JEvtWeightHelper::add(): headers do not match.");
132 }
133 }
134
135
136 /**
137 * Get weight of given event.
138 *
139 * \param evt event
140 * \return weight [Hz]
141 */
142 double getWeight(const Evt& evt) const
143 {
144 const JEvtWeight& weighter = getEvtWeighter();
145
146 return weighter.getWeight(evt);
147 }
148
149
150 /**
151 * Get event-weight normalisation.
152 *
153 * \return event-weight normalisation
154 */
155 double getNormalisation() const
156 {
157 const JEvtWeight& weighter = getEvtWeighter();
158
159 return weighter.getNormalisation();
160 }
161
162
163 /**
164 * Get event-weight normalisation.
165 *
166 * \param evt event
167 * \return event-weight normalisation
168 */
169 double getNormalisation(const Evt& evt) const
170 {
171 const JEvtWeight& weighter = getEvtWeighter();
172
173 return weighter.getNormalisation(evt);
174 }
175
176
177 private:
178
179 int counter; //!< Counter to check how many headers have been added
180 };
181}
182
183#endif
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Monte Carlo run header.
Definition JHead.hh:1236
JHead & add(const JHead &header)
Addition of headers.
Definition JHead.hh:1532
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
void setHeader(const JHead &header)
Set header.
Definition JHead.hh:1292
Exception for null pointer operation.
Exception for accessing a value in a collection that is outside of its range.
Extensions to Evt data format.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Helper class for event weighing.
std::shared_ptr< JEvtWeight > pointer_type
void configure(const JEvtWeight &weighter)
Configuration.
double getNormalisation() const
Get event-weight normalisation.
double getWeight(const Evt &evt) const
Get weight of given event.
const char *const getName() const
Get name.
JEvtWeight & getEvtWeighter() const
Get reference to event-weighter.
void add(const JHead &header)
Add header.
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.
JEvtWeightHelper()
Default constructor.
JEvtWeightHelper(const JEvtWeight &weighter)
Constructor.
virtual bool check(const JHead &header) const =0
Check whether header is consistent with this event weighter.
virtual double getWeight(const Evt &evt) const =0
Get weight of given event.
virtual void configure(const JHead &header)=0
Configuration.
virtual const char *const getName() const =0
Get name.
Abstract base class for event weighing.
Definition JEvtWeight.hh:31
virtual double getNormalisation() const override
Get event-weight normalisation.
Definition JEvtWeight.hh:52
virtual clone_type clone() const override
Get clone of this object.
Definition JClonable.hh:69