Jpp - the software that should make you happy
 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/JFlux.hh"
12 #include "JAAnet/JFluxHelper.hh"
13 #include "JAAnet/JHeadToolkit.hh"
14 #include "JAAnet/JWeightEvent.hh"
15 
16 /**
17  * \author bjung
18  */
19 
20 namespace JAANET {
21 
22  using JLANG::JClonable;
25 
26 
27  /**
28  * Implementation of event weighting for GSeaGen data.
29  */
30  struct JWeightGSeaGen :
31  public JClonable<JWeightEvent, JWeightGSeaGen>,
32  public JFluxHelper
33  {
34  /**
35  * Default Constructor.
36  */
38  JFluxHelper(),
39  W(0.0)
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param header header
47  */
48  JWeightGSeaGen(const JHead& header) :
49  JFluxHelper()
50  {
51  configure(header);
52  }
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param header header
59  * \param flux flux
60  */
61  JWeightGSeaGen(const JHead& header,
62  const JFlux& flux)
63  {
64  configure(header);
66  }
67 
68 
69  /**
70  * Copy constructor.
71  *
72  * \param object original object
73  */
75  {
76  this->W = object.W;
77 
78  if (object.is_valid()) {
79  JFluxHelper::configure(*(object.get()));
80  }
81  }
82 
83 
84  /**
85  * Weight configuration.
86  *
87  * \param header header
88  */
89  void configure(const JHead& header) override
90  {
91  const double N = header.genvol.numberOfEvents;
92  const double dt = (header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
93  header.time_interval.t2 - header.time_interval.t1 :
94  header.tgen.numberOfSeconds);
95 
96  if (check(header) && N > 0.0 && dt > 0.0) {
97 
98  W = 1.0 / N / dt;
99 
100  } else {
101 
102  THROW(JValueOutOfRange, "JWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
103  }
104  }
105 
106 
107  /**
108  * Check whether header is consistent with this event weighter.
109  *
110  * \param header header
111  * \return true if consistent; else false
112  */
113  bool check(const JHead& header) const override
114  {
115  return is_gseagen(header);
116  }
117 
118 
119  /**
120  * Get weight of given event.
121  *
122  * \param evt event
123  * \return weight [Hz]
124  */
125  double getWeight(const Evt& evt) const override
126  {
127  if (is_valid() && evt.w.size() > 1) {
128 
129  return W * evt.w[1] * getFlux(evt);
130 
131  } else if (evt.w.size() > 2) {
132 
133  return W * evt.w[2];
134 
135  } else {
136 
137  if (!is_valid()) {
138  THROW(JNullPointerException, "JWeightGSeaGen::getWeight(): Unspecified flux function.");
139  } else {
140  THROW(JIndexOutOfRange, "JWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
141  }
142  }
143  }
144 
145 
146  private:
147 
148  double W;
149  };
150 }
151 
152 #endif
double getWeight(const Evt &evt) const override
Get weight of given event.
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
void configure(const JFlux &function)
Flux configuration.
Definition: JFluxHelper.hh:51
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
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.
void configure(const JHead &header) override
Weight configuration.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:839
Helper class for event weighing.
Definition: JFluxHelper.hh:23
Template class for object cloning.
Definition: JClonable.hh:20
double getFlux(const Evt &evt) const
Get flux of given event.
Definition: JFluxHelper.hh:63
Implementation of event weighting for GSeaGen data.
Low-level interface for retrieving flux corresponding to an event.
Definition: JFlux.hh:22
Monte Carlo run header.
Definition: JHead.hh:1113
JAANET::time_interval time_interval
Definition: JHead.hh:1417
JWeightGSeaGen()
Default Constructor.
JAANET::tgen tgen
Definition: JHead.hh:1416
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:1014
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:35
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JWeightGSeaGen(const JHead &header, const JFlux &flux)
Constructor.
JWeightGSeaGen(const JWeightGSeaGen &object)
Copy constructor.