Jpp  15.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/JFlux.hh"
13 #include "JAAnet/JEvtWeight.hh"
14 
15 /**
16  * \author bjung
17  */
18 
19 namespace JAANET {
20 
21  using JLANG::JClonable;
24 
25 
26  /**
27  * Implementation of event weighting for GSeaGen data.
28  */
30  public JClonable<JEvtWeight, JEvtWeightGSeaGen>,
31  public JFluxHelper
32  {
33  /**
34  * Default Constructor.
35  */
37  JFluxHelper(),
38  W(0.0)
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param header header
46  */
47  JEvtWeightGSeaGen(const JHead& header) :
48  JFluxHelper()
49  {
50  configure(header);
51  }
52 
53 
54  /**
55  * Constructor.
56  *
57  * \param header header
58  * \param flux flux
59  */
60  JEvtWeightGSeaGen(const JHead& header,
61  const JFlux& flux)
62  {
63  configure(header);
65  }
66 
67 
68  /**
69  * Copy constructor.
70  *
71  * \param object original object
72  */
74  {
75  this->W = object.W;
76 
77  if (object.is_valid()) {
78  JFluxHelper::configure(*(object.get()));
79  }
80  }
81 
82 
83  /**
84  * Weight configuration.
85  *
86  * \param header header
87  */
88  void configure(const JHead& header) override
89  {
90 
91  const double N = header.genvol.numberOfEvents;
92  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
93  header.tgen.numberOfSeconds : 1.0);
94 
95  if (check(header) && N > 0.0 && dt > 0.0) {
96 
97  W = 1.0 / N / dt;
98 
99  } else {
100 
101  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
102  }
103  }
104 
105 
106  /**
107  * Check whether header is consistent with this event weighter.
108  *
109  * \param header header
110  * \return true if consistent; else false
111  */
112  bool check(const JHead& header) const override
113  {
114  return is_gseagen(header);
115  }
116 
117 
118  /**
119  * Get weight of given event.
120  *
121  * \param evt event
122  * \return weight [Hz]
123  */
124  double getWeight(const Evt& evt) const override
125  {
126  if (is_valid() && evt.w.size() > 1) {
127 
128  return W * evt.w[1] * getFlux(evt);
129 
130  } else if (evt.w.size() > 2) {
131 
132  return W * evt.w[2];
133 
134  } else {
135 
136  if (!is_valid()) {
137  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
138  } else {
139  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
140  }
141  }
142  }
143 
144 
145  private:
146 
147  double W;
148  };
149 }
150 
151 #endif
JAANET::genvol genvol
Definition: JHead.hh:1469
Exceptions.
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.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
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.
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
void configure(const JEvtWeightFactor &factor)
Configure event-weight factor.
Helper class for event-weight factor.
JEvtWeightGSeaGen(const JHead &header, const JFlux &flux)
Constructor.
Monte Carlo run header.
Definition: JHead.hh:1164
double getFlux(const Evt &evt) const
Get flux of given event.
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
Low-level interface for retrieving a specifiable multiplication factor corresponding to a given event...
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