Jpp  18.0.1-rc.2
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 
5 
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/JEvtWeight.hh"
16 #include "JAAnet/JFlux.hh"
17 
18 
19 /**
20  * \author bjung
21  */
22 
23 namespace JAANET {
24 
25  using JLANG::JClonable;
28 
29 
30  /**
31  * Implementation of event weighting for GSeaGen data.
32  */
34  public JFluxHelper,
35  public JClonable<JEvtWeight, JEvtWeightGSeaGen>
36  {
37  /**
38  * Default Constructor.
39  */
41  JFluxHelper()
42  {}
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param header header
49  */
50  JEvtWeightGSeaGen(const JHead& header) :
51  JFluxHelper()
52  {
53  configure(header);
54  }
55 
56 
57  /**
58  * Constructor.
59  *
60  * \param header header
61  * \param flux flux
62  */
63  JEvtWeightGSeaGen(const JHead& header,
64  const JFlux& flux) :
65  JFluxHelper()
66  {
67  configure(header);
69  }
70 
71 
72  /**
73  * Copy constructor.
74  *
75  * \param object original object
76  */
78  {
79  this->norm = object.norm;
80 
81  if (object.is_valid()) {
82  JFluxHelper::configure(*(object.get()));
83  }
84  }
85 
86 
87  /**
88  * Weight normalisation configuration.
89  *
90  * \param header header
91  */
92  void configure(const JHead& header) override
93  {
94  const double Nevents = header.genvol.numberOfEvents;
95  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
96  header.tgen.numberOfSeconds : 1.0);
97 
98  if (check(header) && Nevents > 0.0 && dt > 0.0) {
99 
100  norm = 1.0 / Nevents / dt;
101 
102  } else {
103 
104  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
105  }
106  }
107 
108 
109  /**
110  * Check whether header is consistent with this event weighter.
111  *
112  * \param header header
113  * \return true if consistent; else false
114  */
115  bool check(const JHead& header) const override
116  {
117  return is_gseagen(header);
118  }
119 
120 
121  /**
122  * Get weight of given event.
123  *
124  * \param evt event
125  * \return weight [Hz]
126  */
127  double getWeight(const Evt& evt) const override
128  {
129  if (is_valid() && evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
130 
131  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt);
132 
133  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
134 
135  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
136 
137  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
138 
139  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt);
140 
141  } else {
142 
143  if (!is_valid()) {
144  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
145  } else {
146  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
147  }
148  }
149  }
150  };
151 }
152 
153 #endif
JAANET::genvol genvol
Definition: JHead.hh:1582
Exceptions.
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
double numberOfEvents
Number of events.
Definition: JHead.hh:708
#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 normalisation configuration.
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
static const int WEIGHTLIST_EVENT_RATE
Event rate [s-1].
Definition: weightlist.hh:15
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:893
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 JEvtWeightFactor_t &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:1221
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:1591
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition: weightlist.hh:14
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:1122
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:20