Jpp  15.0.5
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 "Jeep/JVersion.hh"
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/JFlux.hh"
15 #include "JAAnet/JEvtWeight.hh"
16 
17 /**
18  * \author bjung
19  */
20 
21 namespace JAANET {
22 
23  using JEEP::JVersion;
24 
25  using JLANG::JClonable;
28 
29 
30  /**
31  * Implementation of event weighting for GSeaGen data.
32  */
34  public JClonable<JEvtWeight, JEvtWeightGSeaGen>,
35  public JFluxHelper
36  {
37  /**
38  * Default Constructor.
39  */
41  JFluxHelper(),
42  W(0.0)
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  {
67  configure(header);
69  }
70 
71 
72  /**
73  * Copy constructor.
74  *
75  * \param object original object
76  */
78  {
79  this->W = object.W;
80 
81  if (object.is_valid()) {
82  JFluxHelper::configure(*(object.get()));
83  }
84  }
85 
86 
87  /**
88  * Weight configuration.
89  *
90  * \param header header
91  */
92  void configure(const JHead& header) override
93  {
94  double dt = 1.0;
95 
96  if (header.DAQ.livetime_s > 0.0) {
97  dt = header.DAQ.livetime_s;
98  } else if (header.time_interval.t2 - header.time_interval.t1 > 0.0) {
99  dt = header.time_interval.t2 - header.time_interval.t1;
100  } else if (header.tgen.numberOfSeconds > 0.0) {
101  dt = header.tgen.numberOfSeconds;
102  }
103 
104  const double N = header.genvol.numberOfEvents;
105 
106  if (check(header) && N > 0.0 && dt > 0.0) {
107 
108  W = 1.0 / N / dt;
109 
110  } else {
111 
112  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
113  }
114  }
115 
116 
117  /**
118  * Check whether header is consistent with this event weighter.
119  *
120  * \param header header
121  * \return true if consistent; else false
122  */
123  bool check(const JHead& header) const override
124  {
125  return is_gseagen(header);
126  }
127 
128 
129  /**
130  * Get weight of given event.
131  *
132  * \param evt event
133  * \return weight [Hz]
134  */
135  double getWeight(const Evt& evt) const override
136  {
137  if (is_valid() && evt.w.size() > 1) {
138 
139  return W * evt.w[1] * getFlux(evt);
140 
141  } else if (evt.w.size() > 2) {
142 
143  return W * evt.w[2];
144 
145  } else {
146 
147  if (!is_valid()) {
148  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
149  } else {
150  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
151  }
152  }
153  }
154 
155 
156  private:
157 
158  double W;
159  };
160 }
161 
162 #endif
JAANET::genvol genvol
Definition: JHead.hh:1408
Exceptions.
double t1
Start time in seconds.
Definition: JHead.hh:1043
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
double t2
Stop time in seconds.
Definition: JHead.hh:1044
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
double livetime_s
Live time [s].
Definition: JHead.hh:986
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:839
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:1113
double getFlux(const Evt &evt) const
Get flux of given event.
JAANET::time_interval time_interval
Definition: JHead.hh:1417
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:1416
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:1014
Auxiliary data structure for general purpose version number.
JAANET::DAQ DAQ
Definition: JHead.hh:1415
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