Jpp  17.3.0
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 
6 
7 #include "JLang/JException.hh"
8 #include "JLang/JClonable.hh"
9 
10 #include "JAAnet/JHead.hh"
11 #include "JAAnet/JHeadToolkit.hh"
12 #include "JAAnet/JEvtWeight.hh"
14 #include "JAAnet/JFlux.hh"
15 
16 
17 /**
18  * \author bjung
19  */
20 
21 namespace JAANET {
22 
23  using JLANG::JClonable;
26 
27 
28  /**
29  * Implementation of event weighting for GSeaGen data.
30  */
32  public JClonable<JEvtWeight, JEvtWeightGSeaGen>,
33  public JEvtWeightFactorHelper<JFlux>
34  {
36 
37 
38  /**
39  * Default Constructor.
40  */
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param header header
50  */
51  JEvtWeightGSeaGen(const JHead& header) :
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) :
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 (object.is_valid()) {
83  JFluxHelper_t::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  const double Nevents = header.genvol.numberOfEvents;
96  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
97  header.tgen.numberOfSeconds : 1.0);
98 
99  if (check(header) && Nevents > 0.0 && dt > 0.0) {
100 
101  norm = 1.0 / Nevents / dt;
102 
103  } else {
104 
105  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
106  }
107  }
108 
109 
110  /**
111  * Check whether header is consistent with this event weighter.
112  *
113  * \param header header
114  * \return true if consistent; else false
115  */
116  bool check(const JHead& header) const override
117  {
118  return is_gseagen(header);
119  }
120 
121 
122  /**
123  * Get weight of given event.
124  *
125  * \param evt event
126  * \return weight [Hz]
127  */
128  double getWeight(const Evt& evt) const override
129  {
130  if (is_valid() && evt.w.size() > 1) {
131 
132  return evt.w[1] * getFactor(evt) * norm;
133 
134  } else if (evt.w.size() > 2) {
135 
136  return evt.w[2] * norm;
137 
138  } else {
139 
140  if (!is_valid()) {
141  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
142  } else {
143  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
144  }
145  }
146  }
147  };
148 }
149 
150 #endif
JEvtWeightFactorHelper< JFlux > JFluxHelper_t
JAANET::genvol genvol
Definition: JHead.hh:1525
Exceptions.
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:60
double numberOfEvents
Number of events.
Definition: JHead.hh:708
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
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
bool is_valid() const
Check validity of pointer.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:893
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 JFlux &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:18
Monte Carlo run header.
Definition: JHead.hh:1167
JEvtWeightGSeaGen(const JEvtWeightGSeaGen &object)
Copy constructor.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
JAANET::tgen tgen
Definition: JHead.hh:1533
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
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:90
double numberOfSeconds
Time in seconds.
Definition: JHead.hh:1068
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