Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightGSeaGen.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTGSEAGEN__
2 #define __JAANET__JEVTWEIGHTGSEAGEN__
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 GSeaGen data.
33  */
35  public JFluxHelper,
36  public JClonable<JEvtWeight, JEvtWeightGSeaGen>
37  {
38  /**
39  * Default Constructor.
40  */
42  JFluxHelper()
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param header header
50  */
51  JEvtWeightGSeaGen(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  JEvtWeightGSeaGen(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  this->norm = object.norm;
81 
82  if (static_cast<const JFluxHelper&>(object)) {
83  JFluxHelper::configure(*(object.get()));
84  }
85  }
86 
87 
88  /**
89  * Weight normalisation configuration.
90  *
91  * \param header header
92  */
93  void configure(const JHead& header) override
94  {
95  using namespace JPP;
96 
97  if (check(header)) {
98 
99  const double Nevents = header.genvol.numberOfEvents;
100  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
101  header.tgen.numberOfSeconds : 1.0);
102 
103  norm = 1.0 / Nevents / dt;
104 
105  } else {
106 
107  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
108  }
109  }
110 
111 
112  /**
113  * Check whether header is consistent with this event weighter.
114  *
115  * \param header header
116  * \return true if consistent; else false
117  */
118  bool check(const JHead& header) const override
119  {
120  return is_gseagen(header);
121  }
122 
123 
124  /**
125  * Get weight of given event.
126  *
127  * \param evt event
128  * \return weight [Hz]
129  */
130  double getWeight(const Evt& evt) const override
131  {
132  using namespace JPP;
133 
134  if (static_cast<const JFluxHelper&>(*this) &&
135  evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
136 
137  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt);
138 
139  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
140 
141  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
142 
143  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
144 
145  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt);
146 
147  } else {
148 
149  if (!static_cast<const JFluxHelper&>(*this)) {
150  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
151  } else {
152  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
153  }
154  }
155  }
156  };
157 }
158 
159 #endif
Exceptions.
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
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
void configure(const JHead &header) override
Weight normalisation configuration.
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
JAANET::tgen tgen
Definition: JHead.hh:1606
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Monte Carlo run header.
Definition: JHead.hh:1234
Neutrino flux.
Definition: JHead.hh:906
Implementation of event weighting for GSeaGen data.
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.
JEvtWeightGSeaGen(const JHead &header, const JFlux &flux)
Constructor.
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:21
JAANET::genvol genvol
Definition: JHead.hh:1597
JEvtWeightGSeaGen(const JEvtWeightGSeaGen &object)
Copy constructor.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition: weightlist.hh:14
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
double getWeight(const Evt &evt) const override
Get weight of given event.
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:106
double numberOfSeconds
Time in seconds.
Definition: JHead.hh:1135
JEvtWeightGSeaGen(const JHead &header)
Constructor.
JEvtWeightGSeaGen()
Default Constructor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20