Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFactorMeffRatio.hh
Go to the documentation of this file.
1#ifndef __JAANET__JEVTWEIGHTFACTORMEFFRATIO__
2#define __JAANET__JEVTWEIGHTFACTORMEFFRATIO__
3
4#include <string>
5#include <memory>
6
7#include "TH1.h"
8#include "TH1D.h"
9#include "TFile.h"
10
13
14#include "JSystem/JStat.hh"
15
16#include "JLang/JClonable.hh"
17#include "JLang/JException.hh"
19
20#include "Jeep/JPrint.hh"
21#include "Jeep/JProperties.hh"
22
23#include "JTools/JRange.hh"
24
26
29
31
32
33/**
34 * \author bjung
35 */
36
37namespace JSIRENE {
38
40
41 /** Forward function declarations. **/
43 double getVisibleEnergy (const Trk&, const JCylinder3D&);
44 double getVisibleEnergy (const Evt&, const JCylinder3D&);
45}
46
47namespace JAANET {}
48namespace JPP { using namespace JAANET; }
49
50namespace JAANET {
51
52 using JLANG::JClonable;
53
54 using JTOOLS::JRange;
55
57
59
61
62
63 /**
64 * Implementation of reweighting factor for effective mass ratios.
65 */
67 public JClonable<JEvtWeightFactor, JEvtWeightFactorMeffRatio>
68 {
70
71 /**
72 * Indices of options for calculating effective mass ratios.\n
73 * The option names correspond to the variable which is used to compute the effective mass ratio.
74 */
76 ENERGY_INITIAL_STATE, //!< Compute effective mass ratio based on scaling of the initial state energy
77 ENERGY_NEUTRINO, //!< Compute effective mass ratio based on scaling of theprimary neutrino energy
78 EVIS, //!< Compute effective mass ratio based on scaling of the total visible energy
79 EVIS_LEADING_LEPTON_CONTR, //!< Compute effective mass ratio based on scaling of the visible energy contribution of the leading lepton
80 EVIS_HADRONIC_CONTR, //!< Compute effective mass ratio based on scaling of the visible energy contribution of the hadronic shower
81 NUMBER_OF_OPTIONS //!< N.B.: This enum value needs to be specified last!
82 };
83
84
85 /**
86 * Default constructor.
87 */
89 pMeff (),
90 hMeff ("", "default"),
92 ratio (0.0),
93 range (0.0, 4.0),
94 fiducialVolume(getMaximumContainmentVolume()),
95 logE (true),
96 MeffMin (1.0e-9)
97 {
98 pMeff = std::make_unique<TH1D>(hMeff.getObjectName(), "", 10, range.getLowerLimit(), range.getUpperLimit());
99
100 for (Int_t i = 1; i <= pMeff->GetNbinsX(); ++i) {
101 pMeff->SetBinContent(i, 1.0);
102 }
103
104 pMeff->SetDirectory(0);
105
106 check_validity();
107 configure();
108 }
109
110
111 /**
112 * Constructor.
113 *
114 * \param objectID effective mass histogram OID
115 * \param option option
116 * \param ratio abscissa ratio
117 * \param range applicable (logarithmic) energy range [GeV]
118 * \param logE toggle logarithmic energies
119 * \param fiducialVolume fiducial volume
120 */
123 const double ratio,
124 const JRange_t& range,
125 const bool logE,
127 pMeff (),
128 hMeff (objectID),
129 option (option),
130 ratio (ratio),
131 range (range),
133 logE (logE),
134 MeffMin (1.0e-9)
135 {
136 check_validity();
137 configure();
138 }
139
140
141 /**
142 * Copy constructor.
143 *
144 * \param factor effective mass ratio factor
145 */
147 pMeff (),
148 hMeff (factor.hMeff),
149 option (factor.option),
150 ratio (factor.ratio),
151 range (factor.range),
153 logE (factor.logE),
154 MeffMin (1.0e-9)
155 {
156 pMeff.reset((TH1*) factor.pMeff->Clone());
157
158 pMeff->SetDirectory(0);
159
160 check_validity();
161 configure();
162 }
163
164
165 /**
166 * Configure effective mass ratio factor.
167 */
169 {
170 using namespace std;
171 using namespace JPP;
172
173 if (hMeff.is_valid() && (!pMeff || hMeff.getObjectName() != string(pMeff->GetName()))) {
174
175 if (!getFileStatus(hMeff.getFilename().c_str())) {
176 THROW(JFileOpenException, "JEvtWeightFactorMeffRatio::configure(): Could not open file " << hMeff.getFilename());
177 }
178
179 TFile f(hMeff.getFilename().c_str(), "read");
180
181 TH1* h = (TH1*) f.Get(hMeff.getObjectName());
182
183 if (h != NULL) {
184 pMeff.reset(h);
185 pMeff->SetDirectory(0);
186 } else {
187 THROW(JNullPointerException, "JEvtWeightFactorMeffRatio::configure(): Could not extract histogram " << hMeff);
188 }
189
190 f.Close();
191 }
192
193 switch (option) {
194 case (int) ENERGY_INITIAL_STATE :
196 break;
197 case (int) ENERGY_NEUTRINO:
199 break;
200 case (int) EVIS:
202 break;
203 case (int) EVIS_LEADING_LEPTON_CONTR:
205 break;
206 case (int) EVIS_HADRONIC_CONTR:
208 break;
209 default:
210 THROW(JValueOutOfRange, "JEvtWeightFactorRatio::configure(): Invalid option " << option);
211 }
212 }
213
214
215 /**
216 * Retrieve effective mass histogram.
217 *
218 * \return effective mass histogram
219 */
220 const TH1& getHistogram() const
221 {
222 if (pMeff) {
223 return *pMeff;
224 } else {
225 THROW(JLANG::JNullPointerException, "JEvtWeightFactorMeffRatio::getHistogram(): Effective mass histogram is not set.");
226 }
227 }
228
229
230 /**
231 * Retrieve fiducial volume.
232 *
233 * \return fiducial volume
234 */
236 {
237 return fiducialVolume;
238 }
239
240
241 /**
242 * Set fiducial volume.
243 *
244 * \param fiducialVolume fiducial volume
245 */
247 {
248 this->fiducialVolume = fiducialVolume;
249
250 check_validity();
251 }
252
253
254 /**
255 * Check if this effective mass ratio weight factor is valid.
256 *
257 * \return true if valid; else false
258 */
259 bool is_valid() const override final
260 {
261 return (pMeff &&
264 ratio >= 0.0 &&
265 range.is_valid() &&
266 fiducialVolume.getVolume() >= 0.0);
267 }
268
269
270 /**
271 * Get effective mass ratio based on a scaling of the initial state energy.
272 *
273 * \param x1 first abscissa value
274 * \param x2 second abscissa value
275 * \return effective mass ratio
276 */
277 inline double getMeffRatio(const double x1,
278 const double x2) const
279 {
280 const double M1 = pMeff->Interpolate(x1);
281 const double M2 = pMeff->Interpolate(x2);
282
283 const double ratio = M1 / (M2 > 0.0 ? M2 : MeffMin);
284
285 return (range(x2) ? ratio : 1.0);
286 }
287
288
289 /**
290 * Get effective mass ratio based on a scaling of the initial state energy.
291 *
292 * \param E0 initial state energy [GeV]
293 * \return effective mass ratio
294 */
295 inline double getMeffRatio1(const double E0) const
296 {
297 if (logE) {
298 const double X = log10(E0);
299 return getMeffRatio(log10(ratio) + X, X);
300 } else {
301 return getMeffRatio(ratio * E0, E0);
302 }
303 }
304
305
306 /**
307 * Get effective mass ratio based on a scaling of the initial state energy.
308 *
309 * \param event event
310 * \return effective mass ratio
311 */
312 inline double getMeffRatio1(const Evt& event) const
313 {
314 const double E0 = getE0(event);
315
316 return getMeffRatio1(E0);
317 }
318
319
320 /**
321 * Get effective mass ratio based on a scaling of the primary neutrino energy.
322 *
323 * \param Enu primary neutrino energy [GeV]
324 * \return effective mass ratio
325 */
326 inline double getMeffRatio2(const double Enu) const
327 {
328 if (logE) {
329 const double X = log10(Enu);
330 return getMeffRatio(log10(ratio) + X, X);
331 } else {
332 return getMeffRatio(ratio * Enu, Enu);
333 }
334 }
335
336
337 /**
338 * Get effective mass ratio based on a scaling of the primary neutrino energy.
339 *
340 * \param event event
341 * \return effective mass ratio
342 */
343 inline double getMeffRatio2(const Evt& event) const
344 {
345 const Trk& primary = get_neutrino(event);
346
347 const double Enu = primary.E;
348
349 return getMeffRatio2(Enu);
350 }
351
352
353 /**
354 * Get effective mass ratio based on a scaling of the total visible energy.
355 *
356 * \param Evis total visible energy [GeV]
357 * \return effective mass ratio
358 */
359 inline double getMeffRatio3(const double Evis) const
360 {
361 if (logE) {
362 const double X = log10(Evis);
363 return getMeffRatio(log10(ratio) + X, X);
364 } else {
365 return getMeffRatio(ratio * Evis, Evis);
366 }
367 }
368
369
370 /**
371 * Get effective mass ratio based on a scaling of the total visible energy.
372 *
373 * \param event event
374 * \return effective mass ratio
375 */
376 inline double getMeffRatio3(const Evt& event) const
377 {
378 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
379
380 return getMeffRatio3(Evis);
381 }
382
383
384 /**
385 * Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible energy.
386 *
387 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
388 * minus the leading leptonic contribution.
389 *
390 * \param Evis total visible energy [GeV]
391 * \param EvisLL leading lepton visible energy [GeV]
392 * \return effective mass ratio
393 */
394 inline double getMeffRatio4(const double Evis,
395 const double EvisLL) const
396 {
397 if (logE) {
398 return getMeffRatio(log10(Evis - (1-ratio) * EvisLL), log10(Evis));
399 } else {
400 return getMeffRatio( Evis - (1-ratio) * EvisLL, Evis);
401 }
402 }
403
404
405 /**
406 * Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible energy.
407 *
408 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
409 * minus the leading leptonic contribution.
410 *
411 * \param event event
412 * \return effective mass ratio
413 */
414 inline double getMeffRatio4(const Evt& event) const
415 {
416 const Trk& LL = get_leading_lepton(event);
417
418 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
419 const double EvisLL = JSIRENE::getVisibleEnergy(LL, fiducialVolume);
420
421 return getMeffRatio4(Evis, EvisLL);
422 }
423
424
425 /**
426 * Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
427 *
428 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
429 * minus the leading leptonic contribution.
430 *
431 * \param Evis total visible energy [GeV]
432 * \param EvisLL leading lepton visible energy [GeV]
433 * \return effective mass ratio
434 */
435 inline double getMeffRatio5(const double Evis,
436 const double EvisLL) const
437 {
438 if (logE) {
439 return getMeffRatio(log10(ratio * Evis + (1-ratio) * EvisLL), log10(Evis));
440 } else {
441 return getMeffRatio( ratio * Evis + (1-ratio) * EvisLL, Evis);
442 }
443 }
444
445
446 /**
447 * Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
448 *
449 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
450 * minus the leading leptonic contribution.
451 *
452 * \param event event
453 * \return effective mass ratio
454 */
455 inline double getMeffRatio5(const Evt& event) const
456 {
457 const Trk& LL = get_leading_lepton(event);
458
459 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
460 const double EvisLL = JSIRENE::getVisibleEnergy(LL, fiducialVolume);
461
462 return getMeffRatio5(Evis, EvisLL);
463 }
464
465
466 /**
467 * Get weighting factor for given event.
468 *
469 * \param evt event
470 * \return weighting factor
471 */
472 double getFactor(const Evt& evt) const override final
473 {
474 return (this->*mfp)(evt);
475 }
476
477
478 /**
479 * Get properties of this class.
480 *
481 * \param eqpars equation parameters
482 */
484 {
485 return JEvtWeightFactorMeffRatioHelper(*this, eqpars);
486 }
487
488
489 /**
490 * Get properties of this class.
491 *
492 * \param eqpars equation parameters
493 */
495 {
496 return JEvtWeightFactorMeffRatioHelper(*this, eqpars);
497 }
498
499
500 /**
501 * Read event-weight factor from input.
502 *
503 * \param in input stream
504 * \return input stream
505 */
506 std::istream& read(std::istream& in) override final
507 {
508 using namespace std;
509 using namespace JPP;
510
511 JStringStream is(in);
512
513 if (getFileStatus(is.str().c_str())) {
514 is.load();
515 }
516
517 JProperties properties = getProperties();
518 is >> properties;
519
520 check_validity();
521
522 configure();
523
524 return in;
525 }
526
527
528 private:
529
530
531 /** Type definition of pointer to member function for calculating effective mass ratios **/
532 typedef double (JEvtWeightFactorMeffRatio::*pFunction)(const Evt&) const;
533
534
535 /**
536 * Auxiliary class for I/O of effective mass ratio factor.
537 */
539 public JProperties
540 {
541 /**
542 * Constructor.
543 *
544 * \param factor constant event-weight factor
545 * \param eqpars equation parameters
546 */
547 template<class JEvtWeightFactorMeffRatio_t>
548 JEvtWeightFactorMeffRatioHelper(JEvtWeightFactorMeffRatio_t& factor,
549 const JEquationParameters& eqpars) :
550 JProperties(eqpars, 1)
551 {
552 (*this)[JEvtWeightFactor::getTypeKey()] = "effective mass ratio";
553
554 this->insert(gmake_property(factor.hMeff));
555 this->insert(gmake_property(factor.option));
556 this->insert(gmake_property(factor.ratio));
557 this->insert(gmake_property(factor.range));
558 this->insert(gmake_property(factor.fiducialVolume));
559 this->insert(gmake_property(factor.logE));
560 }
561 };
562
563
564 pFunction mfp; //!< Pointer to member method for calculating effective mass ratios
565
566 std::unique_ptr<TH1> pMeff; //!< Unique pointer to effective mass ratio histogram
567
568 JRootObjectID hMeff; //!< Effective mass histogram OID
569 int option; //!< Effective mass ratio option
570 double ratio; //!< Abscissa ratio
571 JRange_t range; //!< Applicable range
572 JCylinder3D fiducialVolume; //!< Fiducial volume (for visible energy computation)
573 bool logE; //!< Toggle logarithmic abscissa
574
575 const double MeffMin; //!< Minimum effective mass
576 };
577}
578
579#endif
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
I/O formatting auxiliaries.
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Auxiliary class to define a range between two values.
File status.
Utility class to parse parameter values.
double getVolume() const
Get volume.
Auxiliary class to handle file name, ROOT directory and object name.
TString getObjectName() const
Get object name.
const std::string & getFilename() const
Get file name.
bool is_valid() const
Check validity.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Exception for opening of file.
Exception for null pointer operation.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
void load()
Load data from file with name corresponding to current contents.
Exception for accessing a value in a collection that is outside of its range.
Range of values.
Definition JRange.hh:42
bool is_valid() const
Check validity of range.
Definition JRange.hh:311
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
Extensions to Evt data format.
const Trk & get_leading_lepton(const Evt &event)
Auxiliary function to retrieve the leading lepton of a neutrino interaction.
double getE0(const Evt &evt)
Get initial state energy of a neutrino interaction.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector simulations.
const JCylinder3D getMaximumContainmentVolume()
Forward function declarations.
double getVisibleEnergy(const Trk &, const JCylinder3D &)
Get the visible energy of a track.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Auxiliary class for I/O of effective mass ratio factor.
JEvtWeightFactorMeffRatioHelper(JEvtWeightFactorMeffRatio_t &factor, const JEquationParameters &eqpars)
Constructor.
Implementation of reweighting factor for effective mass ratios.
double(JEvtWeightFactorMeffRatio::*) pFunction(const Evt &) const
Type definition of pointer to member function for calculating effective mass ratios.
void configure()
Configure effective mass ratio factor.
JRootObjectID hMeff
Effective mass histogram OID.
double getMeffRatio2(const Evt &event) const
Get effective mass ratio based on a scaling of the primary neutrino energy.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) override final
Get properties of this class.
std::istream & read(std::istream &in) override final
Read event-weight factor from input.
bool is_valid() const override final
Check if this effective mass ratio weight factor is valid.
JCylinder3D fiducialVolume
Fiducial volume (for visible energy computation)
JMeffRatioOption
Indices of options for calculating effective mass ratios.
@ ENERGY_INITIAL_STATE
Compute effective mass ratio based on scaling of the initial state energy.
@ EVIS
Compute effective mass ratio based on scaling of the total visible energy.
@ NUMBER_OF_OPTIONS
N.B.: This enum value needs to be specified last!
@ EVIS_HADRONIC_CONTR
Compute effective mass ratio based on scaling of the visible energy contribution of the hadronic show...
@ ENERGY_NEUTRINO
Compute effective mass ratio based on scaling of theprimary neutrino energy.
@ EVIS_LEADING_LEPTON_CONTR
Compute effective mass ratio based on scaling of the visible energy contribution of the leading lepto...
JCylinder3D getFiducialVolume() const
Retrieve fiducial volume.
JEvtWeightFactorMeffRatio(const JRootObjectID &objectID, const JMeffRatioOption option, const double ratio, const JRange_t &range, const bool logE, const JCylinder3D &fiducialVolume)
Constructor.
double getMeffRatio4(const Evt &event) const
Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible...
double getMeffRatio2(const double Enu) const
Get effective mass ratio based on a scaling of the primary neutrino energy.
double getFactor(const Evt &evt) const override final
Get weighting factor for given event.
JEvtWeightFactorMeffRatio(const JEvtWeightFactorMeffRatio &factor)
Copy constructor.
bool logE
Toggle logarithmic abscissa.
double getMeffRatio3(const Evt &event) const
Get effective mass ratio based on a scaling of the total visible energy.
int option
Effective mass ratio option.
double getMeffRatio1(const double E0) const
Get effective mass ratio based on a scaling of the initial state energy.
double getMeffRatio5(const Evt &event) const
Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
double getMeffRatio(const double x1, const double x2) const
Get effective mass ratio based on a scaling of the initial state energy.
void setFiducialVolume(const JCylinder3D &fiducialVolume)
Set fiducial volume.
const double MeffMin
Minimum effective mass.
std::unique_ptr< TH1 > pMeff
Unique pointer to effective mass ratio histogram.
double getMeffRatio5(const double Evis, const double EvisLL) const
Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
double getMeffRatio4(const double Evis, const double EvisLL) const
Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible...
double getMeffRatio3(const double Evis) const
Get effective mass ratio based on a scaling of the total visible energy.
const TH1 & getHistogram() const
Retrieve effective mass histogram.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const override final
Get properties of this class.
pFunction mfp
Pointer to member method for calculating effective mass ratios.
double getMeffRatio1(const Evt &event) const
Get effective mass ratio based on a scaling of the initial state energy.
static const char *const getTypeKey()
Get type keyword.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Primary particle.
Definition JHead.hh:1174
Template class for object cloning.
Definition JClonable.hh:59
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15