Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWeightGSeaGen.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JWEIGHTGSEAGEN__
2 #define __JAANET__JWEIGHTGSEAGEN__
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/JWeightEvent.hh"
13 
14 /**
15  * \author bjung
16  */
17 
18 namespace JAANET {
19 
20  using JLANG::JClonable;
23 
24 
25  /**
26  * Implementation of event weighing for GSeaGen data.
27  */
28  struct JWeightGSeaGen :
29  public JClonable<JWeightEvent, JWeightGSeaGen>
30  {
31  /**
32  * Default Constructor.
33  */
34  JWeightGSeaGen() : W(0.0)
35  {}
36 
37 
38  /**
39  * Constructor.
40  *
41  * \param header header
42  */
43  JWeightGSeaGen(const JHead& header)
44  {
45  configure(header);
46  }
47 
48 
49  /**
50  * Configuration.
51  *
52  * \param header header
53  */
54  virtual void configure(const JHead& header) override
55  {
56  if (check(header) && (header.tgen.numberOfSeconds > 0.0 &&
57  header.genvol.numberOfEvents > 0.0)) {
58 
59  W = 1.0 / header.genvol.numberOfEvents / header.tgen.numberOfSeconds;
60 
61  } else {
62 
63  THROW(JValueOutOfRange, "JWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
64  }
65  }
66 
67 
68  /**
69  * Check whether header is consistent with this event weighter.
70  *
71  * \param header header
72  * \return true if consistent; else false
73  */
74  virtual bool check(const JHead& header) const override
75  {
76  return is_gseagen(header);
77  }
78 
79 
80  /**
81  * Get weight of given event.
82  *
83  * \param evt event
84  * \return weight [Hz]
85  */
86  virtual double getWeight(const Evt& evt) const override
87  {
88  if (evt.w.size() > 2 && !(evt.w[2] < 0.0)) {
89 
90  return W * evt.w[2];
91 
92  } else {
93 
94  if (evt.w.size() < 3) {
95  THROW(JIndexOutOfRange, "JWeightGSeaGen::getWeight(): w3-weight is empty.");
96  } else {
97  THROW(JValueOutOfRange, "JWeightGSeaGen::getWeight(): w3-weight is negative.");
98  }
99  }
100  }
101 
102 
103  /**
104  * Get weight of given event.
105  *
106  * \param evt event
107  * \param flux neutrino flux [m^-2 s^-1 sr^-1 GeV^-1]
108  * \return weight [Hz]
109  */
110  virtual double getWeight(const Evt& evt,
111  const double flux) const override
112  {
113  if (evt.w.size() > 1 && !(evt.w[1] < 0.0 || flux < 0.0)) {
114 
115  return W * evt.w[1] * flux;
116 
117  } else {
118 
119  if (evt.w.size() < 2) {
120  THROW(JIndexOutOfRange, "JWeightGSeaGen::getWeight(): w2-weight is empty.");
121  } else {
122  THROW(JValueOutOfRange, "JWeightGSeaGen::getWeight(): w2-weight or flux is negative");
123  }
124  }
125  }
126 
127  private:
128  double W;
129  };
130 }
131 
132 #endif
JAANET::genvol genvol
Definition: JHead.hh:1384
Exceptions.
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:60
double numberOfEvents
Number of events.
Definition: JHead.hh:654
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
virtual bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
virtual double getWeight(const Evt &evt, const double flux) const override
Get weight of given event.
Neutrino flux.
Definition: JHead.hh:839
virtual double getWeight(const Evt &evt) const override
Get weight of given event.
Template class for object cloning.
Definition: JClonable.hh:20
Implementation of event weighing for GSeaGen data.
Monte Carlo run header.
Definition: JHead.hh:1091
JWeightGSeaGen()
Default Constructor.
JAANET::tgen tgen
Definition: JHead.hh:1392
JWeightGSeaGen(const JHead &header)
Constructor.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
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:992
virtual void configure(const JHead &header) override
Configuration.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19