Jpp  18.0.1-rc.1
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 
28 
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  const Trk& neutrino = get_neutrino(evt);
93 
94  const double flux = getFactor(evt);
95 
96  static Double_t vars[NUMBER_OF_VARIABLES];
97 
98  vars[COSTH] = neutrino.dir.z;
99  vars[ENERGY] = getE0(evt);
100 
101  vars[BJORKEN_X] = evt.w2list[W2LIST_GSEAGEN_BX];
103 
104  return this->DoEval(&vars[0]) * flux;
105 
106  } else {
107 
108  THROW(JNullPointerException, "JEvtWeightFactorGSeaGen::operator(): Unspecified flux function.");
109  }
110  }
111 
112 
113  /**
114  * Stream input.
115  *
116  * \param in input stream
117  * \param object gSeaGen event-weight factor
118  * \return input stream
119  */
120  inline friend std::istream& operator>>(std::istream& in,
121  JEvtWeightFactorGSeaGen& object)
122  {
123  using namespace std;
124  using namespace JPP;
125 
126  typedef JToken<';'> JToken_t;
127 
128  static struct {
129  Int_t count;
130  JToken_t equation;
131  } parameter;
132 
133  JToken_t formula;
134 
135  in >> formula;
136 
137  object.Clear();
138  object.Compile(formula.c_str());
139 
140  for (parameter.count = 0; parameter.count < object.GetNpar() && in >> parameter.equation; ++parameter.count) {
141 
142  const int index = getParameter(parameter.equation);
143  const double value = getValue(parameter.equation,0);
144 
145  object.SetParameter(index, value);
146  }
147 
148  return in;
149  }
150 
151 
152  /**
153  * Stream output.
154  *
155  * \param out output stream
156  * \param object gSeaGen event-weight factor
157  * \return output stream
158  */
159  inline friend std::ostream& operator<<(std::ostream& out,
160  const JEvtWeightFactorGSeaGen& object)
161  {
162  using namespace std;
163  using namespace JPP;
164 
165  out << object.GetExpFormula() << ';';
166 
167  for (int i = 0; i < object.GetNpar(); ++i) {
168  out << " p" << i << " = " << SCIENTIFIC(6,3) << object.GetParameter(i) << ';';
169  }
170 
171  return out;
172  }
173  };
174 }
175 
176 #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:696
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.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:893
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:18
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