Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWeightEventHelper.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JWEIGHTEVENTHELPER__
2 #define __JAANET__JWEIGHTEVENTHELPER__
3 
6 
8 
9 #include "JAAnet/JHead.hh"
10 #include "JAAnet/JWeightEvent.hh"
11 #include "JAAnet/JWeightDAQ.hh"
12 #include "JAAnet/JWeightMupage.hh"
13 #include "JAAnet/JWeightGSeaGen.hh"
14 #include "JAAnet/JWeightKM3BUU.hh"
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JAANET {
21 
25 
26 
27  /**
28  * Helper class for event weighing.
29  */
31  public JSharedPointer<JWeightEvent>,
32  public JHead
33  {
35 
36  /**
37  * Default constructor.
38  */
40  counter(0)
41  {}
42 
43 
44  /**
45  * Constructor.
46  *
47  * \param weighter event weighter
48  */
49  JWeightEventHelper(const JWeightEvent& weighter) :
50  counter(0)
51  {
52  this->configure(weighter);
53  }
54 
55 
56  /**
57  * Configuration.
58  *
59  * \param weighter event weighter
60  */
61  void configure(const JWeightEvent& weighter)
62  {
63  counter = 0;
64 
65  reset(weighter.clone());
66  }
67 
68 
69  /**
70  * Check if a given header is consistent with this event weighter.
71  *
72  * \param header header
73  * \return true if header is consistent with this event weighter; else false.
74  */
75  bool check(const JHead& header) const
76  {
77  return (is_valid() ? get()->check(header) : false);
78  }
79 
80 
81  /**
82  * Add header.
83  *
84  * \param header header
85  */
86  void add(const JHead& header)
87  {
88  if (check(header)) {
89 
90  if (counter == 0)
91  setHeader(header);
92  else
93  add(header);
94 
95  ++counter;
96 
97  get()->configure(getHeader());
98 
99  } else {
100 
101  THROW(JNullPointerException, "JWeightEventHelper::add(): headers do not match.");
102  }
103  }
104 
105 
106  /**
107  * Get weight of given event.
108  *
109  * \param evt event
110  * \return weight [Hz]
111  */
112  double getWeight(const Evt& evt) const
113  {
114  if (is_valid()) {
115  return get()->getWeight(evt);
116  } else {
117  THROW(JNullPointerException, "JWeightEventHelper::getWeight(): Event weighter is null.");
118  }
119  }
120 
121  private:
122  int counter;
123  };
124 }
125 
126 #endif
JWeightEventHelper()
Default constructor.
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1146
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1124
void add(const JHead &header)
Add header.
double getWeight(const Evt &evt) const
Get weight of given event.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
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.
Helper class for event weighing.
Exception for null pointer operation.
Definition: JException.hh:216
Low-level interface for event weighing.
Definition: JWeightEvent.hh:23
Monte Carlo run header.
Definition: JHead.hh:1091
void configure(const JWeightEvent &weighter)
Configuration.
JWeightEventHelper(const JWeightEvent &weighter)
Constructor.
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
virtual void reset() override
Reset pointer.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19