Jpp  18.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightFactorGSeaGen.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORGSEAGEN__
2 #define __JAANET__JEVTWEIGHTFACTORGSEAGEN__
3 
5 
8 
9 #include "JLang/JManip.hh"
10 #include "JLang/JToken.hh"
11 #include "JLang/JException.hh"
12 
13 #include "JAAnet/JFlux.hh"
15 
16 #include "JGizmo/JGizmoToolkit.hh"
17 
18 #include "TFormula.h"
19 
20 
21 /**
22  * \author bjung
23  */
24 
25 namespace JAANET {}
26 namespace JPP { using namespace JAANET; }
27 
28 namespace JAANET {
29 
30  /**
31  * Implementation of reweighting factor for simulated neutrino interactions according to a specifiable ROOT TFormula.
32  *
33  * Note: The ROOT TFormula may assume any number of parameters, but should be restricted to\n
34  * the physical variables listed among `JEvtWeightFactorGSeaGen::variables`.\n
35  * These variables may be specified within the ROOT TFormula as 'x[<index>]',\n
36  * where <index> corresponds to the index of the desired physical variable within `JEvtWeightFactorGSeaGen::variables`.
37  */
39  public JFluxHelper,
40  public TFormula
41  {
42  /**
43  * Indices of reweighting variables for GSeaGen.
44  */
45  enum variables {
46  COSTH, //!< Cosine zenith angle
47  ENERGY, //!< Initial state energy
48  BJORKEN_X, //!< Björken-x (= fractional momentum carried by the struck nucleon)
49  INELASTICITY, //!< Inelasticity (= Björken-y)
50  NUMBER_OF_VARIABLES //!< Number of reweighting variables; \n
51  //!< N.B.\ This enum value needs to be specified last!
52  };
53 
54 
55  /**
56  * Default constructor.
57  */
59  JFluxHelper(),
60  TFormula()
61  {}
62 
63 
64  /**
65  * Constructor.
66  *
67  * \param flux flux function
68  * \param name name
69  * \param formula formula
70  */
72  const char* name,
73  const char* formula) :
74  JFluxHelper(flux),
75  TFormula(name, formula)
76  {}
77 
78 
79  /**
80  * Get weighting factor for given event.
81  *
82  * \param evt event
83  * \return weighting factor
84  */
85  double operator()(const Evt& evt) const
86  {
87  using namespace std;
88  using namespace JPP;
89 
90  if (is_valid()) {
91 
92  Double_t vars[NUMBER_OF_VARIABLES] = { 0.0 };
93 
94  const Trk& neutrino = get_neutrino(evt);
95  const double flux = getFactor(evt);
96 
97  vars[COSTH] = neutrino.dir.z;
98  vars[ENERGY] = getE0(evt);
99  vars[BJORKEN_X] = evt.w2list[W2LIST_GSEAGEN_BX];
101 
102  return this->DoEval(&vars[0]) * flux;
103 
104  } else {
105 
106  THROW(JNullPointerException, "JEvtWeightFactorGSeaGen::operator(): Unspecified flux function.");
107  }
108  }
109 
110 
111  /**
112  * Stream input.
113  *
114  * \param in input stream
115  * \param object gSeaGen event-weight factor
116  * \return input stream
117  */
118  inline friend std::istream& operator>>(std::istream& in,
119  JEvtWeightFactorGSeaGen& object)
120  {
121  using namespace std;
122  using namespace JPP;
123 
124  typedef JToken<';'> JToken_t;
125 
126  JToken_t formula;
127  JToken_t equation;
128 
129  in >> formula;
130 
131  object.Clear();
132  object.Compile(formula.c_str());
133 
134  for (int count = 0; count < object.GetNpar() && in >> equation; ++count) {
135 
136  const int index = getParameter(equation);
137  const double value = getValue(equation, 0);
138 
139  object.SetParameter(index, value);
140  }
141 
142  return in;
143  }
144 
145 
146  /**
147  * Stream output.
148  *
149  * \param out output stream
150  * \param object gSeaGen event-weight factor
151  * \return output stream
152  */
153  inline friend std::ostream& operator<<(std::ostream& out,
154  const JEvtWeightFactorGSeaGen& object)
155  {
156  using namespace std;
157  using namespace JPP;
158 
159  out << object.GetExpFormula() << ';';
160 
161  for (int i = 0; i < object.GetNpar(); ++i) {
162  out << " p" << i << " = " << SCIENTIFIC(6,3) << object.GetParameter(i) << ';';
163  }
164 
165  return out;
166  }
167  };
168 }
169 
170 #endif
static const int W2LIST_GSEAGEN_BX
Bjorken x.
Exceptions.
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
int getParameter(const std::string &text)
Get parameter number from text string.
double z
Definition: Vec.hh:14
double getE0(const Evt &evt)
Get initial state energy of a neutrino interaction.
friend std::ostream & operator<<(std::ostream &out, const JEvtWeightFactorGSeaGen &object)
Stream output.
Vec dir
track direction
Definition: Trk.hh:18
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
variables
Indices of reweighting variables for GSeaGen.
friend std::istream & operator>>(std::istream &in, JEvtWeightFactorGSeaGen &object)
Stream input.
bool is_valid() const
Check validity of pointer.
Number of reweighting variables; N.B. This enum value needs to be specified last! ...
JEvtWeightFactorGSeaGen(const JFlux &flux, const char *name, const char *formula)
Constructor.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Neutrino flux.
Definition: JHead.hh:906
Helper class for event-weight factor.
Björken-x (= fractional momentum carried by the struck nucleon)
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:21
I/O manipulators.
JEvtWeightFactorGSeaGen()
Default constructor.
Implementation of reweighting factor for simulated neutrino interactions according to a specifiable R...
static const int W2LIST_GSEAGEN_BY
Bjorken y.
double operator()(const Evt &evt) const
Get weighting factor for given event.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:43
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20