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
JEvtWeightGenhen.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTGENHEN__
2 #define __JAANET__JEVTWEIGHTGENHEN__
3 
5 
8 
9 #include "JLang/JException.hh"
10 #include "JLang/JClonable.hh"
11 
12 #include "JAAnet/JHead.hh"
13 #include "JAAnet/JHeadToolkit.hh"
14 #include "JAAnet/JEvtWeight.hh"
16 #include "JAAnet/JFlux.hh"
17 
18 
19 /**
20  * \author bjung
21  */
22 
23 namespace JAANET {}
24 namespace JPP { using namespace JAANET; }
25 
26 namespace JAANET {
27 
28  using JLANG::JClonable;
29 
30 
31  /**
32  * Implementation of event weighting for Genhen data.
33  */
35  public JFluxHelper,
36  public JClonable<JEvtWeight, JEvtWeightGenhen>
37  {
38  /**
39  * Default Constructor.
40  */
42  JFluxHelper()
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param header header
50  */
51  JEvtWeightGenhen(const JHead& header) :
52  JFluxHelper()
53  {
54  configure(header);
55  }
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param header header
62  * \param flux flux
63  */
64  JEvtWeightGenhen(const JHead& header,
65  const JFlux& flux) :
66  JFluxHelper()
67  {
68  configure(header);
70  }
71 
72 
73  /**
74  * Copy constructor.
75  *
76  * \param object original object
77  */
79  {
80  setNormalisation(object.getNormalisation());
81 
82  if (static_cast<const JFluxHelper&>(object)) {
83  JFluxHelper::configure(*(object.get()));
84  }
85  }
86 
87 
88  /**
89  * Get name.
90  *
91  * \return name
92  */
93  virtual const char* const getName() const override
94  {
95  return "Genhen";
96  }
97 
98 
99  /**
100  * Weight normalisation configuration.
101  *
102  * \param header header
103  */
104  void configure(const JHead& header) override
105  {
106  using namespace JPP;
107 
108  if (check(header)) {
109 
110  const double Nevents = header.genvol.numberOfEvents;
111 
112  setNormalisation(1.0 / Nevents / (60*60*24*365));
113 
114  } else {
115 
116  THROW(JValueOutOfRange, "JEvtWeightGenhen::configure(): Provided header is inconsistent with Genhen.");
117  }
118  }
119 
120 
121  /**
122  * Check whether header is consistent with this event weighter.
123  *
124  * \param header header
125  * \return true if consistent; else false
126  */
127  bool check(const JHead& header) const override
128  {
129  return is_genhen(header);
130  }
131 
132 
133  /**
134  * Get weight of given event.
135  *
136  * \param evt event
137  * \return weight [Hz]
138  */
139  double getWeight(const Evt& evt) const override
140  {
141  using namespace JPP;
142 
143  if (static_cast<const JFluxHelper&>(*this) &&
144  evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
145 
146  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt);
147 
148  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
149 
150  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
151 
152  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
153 
154  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt);
155 
156  } else {
157 
158  if (!static_cast<const JFluxHelper&>(*this)) {
159  THROW(JNullPointerException, "JEvtWeightGenhen::getWeight(): Unspecified flux function.");
160  } else {
161  THROW(JIndexOutOfRange, "JEvtWeightGenhen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
162  }
163  }
164  }
165  };
166 }
167 
168 #endif
void configure(const JHead &header) override
Weight normalisation configuration.
Exceptions.
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
Implementation of event weighting for Genhen data.
virtual const char *const getName() const override
Get name.
double numberOfEvents
Number of events.
Definition: JHead.hh:721
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
static const int WEIGHTLIST_EVENT_RATE
Event rate [s-1].
Definition: weightlist.hh:15
JEvtWeightGenhen()
Default Constructor.
JEvtWeightGenhen(const JHead &header)
Constructor.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Monte Carlo run header.
Definition: JHead.hh:1234
double getWeight(const Evt &evt) const override
Get weight of given event.
Neutrino flux.
Definition: JHead.hh:906
Template class for object cloning.
Definition: JClonable.hh:20
Helper class for event-weight factor.
void configure(const JEvtWeightFactor_t &factor)
Configure event-weight factor.
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:21
JAANET::genvol genvol
Definition: JHead.hh:1599
bool is_genhen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:37
JEvtWeightGenhen(const JHead &header, const JFlux &flux)
Constructor.
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition: weightlist.hh:14
JEvtWeightGenhen(const JEvtWeightGenhen &object)
Copy constructor.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:106
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20