Jpp  18.6.0-rc.1
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 namespace JPP { using namespace JAANET; }
25 
26 namespace JAANET {
27 
28  using JLANG::JClonable;
29 
30 
31  /**
32  * Implementation of event weighting for GSeaGen data.
33  */
35  public JFluxHelper,
36  public JClonable<JEvtWeight, JEvtWeightGSeaGen>
37  {
38  /**
39  * Default Constructor.
40  */
42  JFluxHelper()
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  JFluxHelper()
67  {
68  configure(header);
70  }
71 
72 
73  /**
74  * Copy constructor.
75  *
76  * \param object original object
77  */
79  {
80  setNormalisation(object.getNormalisation());
81 
82  if (static_cast<const JFluxHelper&>(object)) {
83  JFluxHelper::configure(*(object.get()));
84  }
85  }
86 
87 
88  /**
89  * Get name.
90  *
91  * \return name
92  */
93  virtual const char* const getName() const override
94  {
95  return "gSeaGen";
96  }
97 
98 
99  /**
100  * Weight normalisation configuration.
101  *
102  * \param header header
103  */
104  void configure(const JHead& header) override
105  {
106  using namespace JPP;
107 
108  if (check(header)) {
109 
110  const double Nevents = header.genvol.numberOfEvents;
111  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
112  header.tgen.numberOfSeconds : 1.0);
113 
114  setNormalisation(1.0 / Nevents / dt);
115 
116  } else {
117 
118  THROW(JValueOutOfRange, "JEvtWeightGSeaGen::configure(): Provided header is inconsistent with GSeaGen.");
119  }
120  }
121 
122 
123  /**
124  * Check whether header is consistent with this event weighter.
125  *
126  * \param header header
127  * \return true if consistent; else false
128  */
129  bool check(const JHead& header) const override
130  {
131  return is_gseagen(header);
132  }
133 
134 
135  /**
136  * Get weight of given event.
137  *
138  * \param evt event
139  * \return weight [Hz]
140  */
141  double getWeight(const Evt& evt) const override
142  {
143  using namespace JPP;
144 
145  if (static_cast<const JFluxHelper&>(*this) &&
146  evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
147 
148  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt);
149 
150  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
151 
152  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
153 
154  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
155 
156  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt);
157 
158  } else {
159 
160  if (!static_cast<const JFluxHelper&>(*this)) {
161  THROW(JNullPointerException, "JEvtWeightGSeaGen::getWeight(): Unspecified flux function.");
162  } else {
163  THROW(JIndexOutOfRange, "JEvtWeightGSeaGen::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
164  }
165  }
166  }
167  };
168 }
169 
170 #endif
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:721
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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
JAANET::tgen tgen
Definition: JHead.hh:1608
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Monte Carlo run header.
Definition: JHead.hh:1234
Neutrino flux.
Definition: JHead.hh:906
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:21
JAANET::genvol genvol
Definition: JHead.hh:1599
JEvtWeightGSeaGen(const JEvtWeightGSeaGen &object)
Copy constructor.
virtual const char *const getName() const override
Get name.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
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:178
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:106
double numberOfSeconds
Time in seconds.
Definition: JHead.hh:1135
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