Jpp  16.0.3
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  */
42  JFluxHelper_t(),
43  W(0.0)
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param header header
51  */
52  JEvtWeightGSeaGen(const JHead& header) :
53  JFluxHelper_t(),
54  W(0.0)
55  {
56  configure(header);
57  }
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param header header
64  * \param flux flux
65  */
66  JEvtWeightGSeaGen(const JHead& header,
67  const JFlux& flux) :
68  JFluxHelper_t(),
69  W(0.0)
70  {
71  configure(header);
73  }
74 
75 
76  /**
77  * Copy constructor.
78  *
79  * \param object original object
80  */
82  {
83  this->W = object.W;
84 
85  if (object.is_valid()) {
86  JFluxHelper_t::configure(*(object.get()));
87  }
88  }
89 
90 
91  /**
92  * Weight configuration.
93  *
94  * \param header header
95  */
96  void configure(const JHead& header) override
97  {
98  const size_t Ntypes = header.flux.size();
99  const double Nevents = header.genvol.numberOfEvents / ((double) Ntypes);
100  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
101  header.tgen.numberOfSeconds : 1.0);
102 
103  if (check(header) && Nevents > 0.0 && dt > 0.0) {
104 
105  W = 1.0 / Nevents / dt;
106 
107  } else {
108 
109  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
110  }
111  }
112 
113 
114  /**
115  * Check whether header is consistent with this event weighter.
116  *
117  * \param header header
118  * \return true if consistent; else false
119  */
120  bool check(const JHead& header) const override
121  {
122  return is_gseagen(header);
123  }
124 
125 
126  /**
127  * Get weight of given event.
128  *
129  * \param evt event
130  * \return weight [Hz]
131  */
132  double getWeight(const Evt& evt) const override
133  {
134  if (is_valid() && evt.w.size() > 1) {
135 
136  return W * evt.w[1] * getFactor(evt);
137 
138  } else if (evt.w.size() > 2) {
139 
140  return W * evt.w[2];
141 
142  } else {
143 
144  if (!is_valid()) {
145  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
146  } else {
147  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
148  }
149  }
150  }
151 
152 
153  private:
154 
155  double W;
156  };
157 }
158 
159 #endif
JEvtWeightFactorHelper< JFlux > JFluxHelper_t
JAANET::genvol genvol
Definition: JHead.hh:1469
Exceptions.
std::vector< JAANET::flux > flux
Definition: JHead.hh:1480
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:60
double numberOfEvents
Number of events.
Definition: JHead.hh:705
#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 configuration.
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
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:890
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:1164
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:1477
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:1065
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:19