Jpp 19.3.0-rc.5
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
44 double getVisibleEnergy (const Trk&, const JCylinder3D&);
45 double getVisibleEnergy (const Evt&, const JCylinder3D&);
47 double getVisibleEnergyLeadingLepton(const Evt&, const JCylinder3D&);
48}
49
50namespace JAANET {}
51namespace JPP { using namespace JAANET; }
52
53namespace JAANET {
54
55 using JLANG::JClonable;
56
57 using JTOOLS::JRange;
58
60
62
64
65
66 /**
67 * Implementation of reweighting factor for effective mass ratios.
68 */
70 public JClonable<JEvtWeightFactor, JEvtWeightFactorMeffRatio>
71 {
73
74 /**
75 * Indices of options for calculating effective mass ratios.\n
76 * The option names correspond to the variable which is used to compute the effective mass ratio.
77 */
79 ENERGY_INITIAL_STATE, //!< Compute effective mass ratio based on scaling of the initial state energy
80 ENERGY_NEUTRINO, //!< Compute effective mass ratio based on scaling of theprimary neutrino energy
81 EVIS, //!< Compute effective mass ratio based on scaling of the total visible energy
82 EVIS_LEADING_LEPTON_CONTR, //!< Compute effective mass ratio based on scaling of the visible energy contribution of the leading lepton
83 EVIS_HADRONIC_CONTR, //!< Compute effective mass ratio based on scaling of the visible energy contribution of the hadronic shower
84 NUMBER_OF_OPTIONS //!< N.B.: This enum value needs to be specified last!
85 };
86
87
88 /**
89 * Default constructor.
90 */
92 pMeff (),
93 hMeff ("", "default"),
95 ratio (0.0),
96 range (0.0, 4.0),
97 fiducialVolume(getMaximumContainmentVolume()),
98 logE (true),
99 MeffMin (1.0e-9)
100 {
101 pMeff = std::make_unique<TH1D>(hMeff.getObjectName(), "", 10, range.getLowerLimit(), range.getUpperLimit());
102
103 for (Int_t i = 1; i <= pMeff->GetNbinsX(); ++i) {
104 pMeff->SetBinContent(i, 1.0);
105 }
106
107 pMeff->SetDirectory(0);
108
109 check_validity();
110 configure();
111 }
112
113
114 /**
115 * Constructor.
116 *
117 * \param objectID effective mass histogram OID
118 * \param option option
119 * \param ratio abscissa ratio
120 * \param range applicable (logarithmic) energy range [GeV]
121 * \param logE toggle logarithmic energies
122 * \param fiducialVolume fiducial volume
123 */
126 const double ratio,
127 const JRange_t& range,
128 const bool logE,
130 pMeff (),
131 hMeff (objectID),
132 option (option),
133 ratio (ratio),
134 range (range),
136 logE (logE),
137 MeffMin (1.0e-9)
138 {
139 check_validity();
140 configure();
141 }
142
143
144 /**
145 * Copy constructor.
146 *
147 * \param factor effective mass ratio factor
148 */
150 pMeff (),
151 hMeff (factor.hMeff),
152 option (factor.option),
153 ratio (factor.ratio),
154 range (factor.range),
156 logE (factor.logE),
157 MeffMin (1.0e-9)
158 {
159 pMeff.reset((TH1*) factor.pMeff->Clone());
160
161 pMeff->SetDirectory(0);
162
163 check_validity();
164 configure();
165 }
166
167
168 /**
169 * Configure effective mass ratio factor.
170 */
172 {
173 using namespace std;
174 using namespace JPP;
175
176 if (hMeff.is_valid() && (!pMeff || hMeff.getObjectName() != string(pMeff->GetName()))) {
177
178 if (!getFileStatus(hMeff.getFilename().c_str())) {
179 THROW(JFileOpenException, "JEvtWeightFactorMeffRatio::configure(): Could not open file " << hMeff.getFilename());
180 }
181
182 TFile f(hMeff.getFilename().c_str(), "read");
183
184 TH1* h = (TH1*) f.Get(hMeff.getObjectName());
185
186 if (h != NULL) {
187 pMeff.reset(h);
188 pMeff->SetDirectory(0);
189 } else {
190 THROW(JNullPointerException, "JEvtWeightFactorMeffRatio::configure(): Could not extract histogram " << hMeff);
191 }
192
193 f.Close();
194 }
195
196 switch (option) {
197 case (int) ENERGY_INITIAL_STATE :
199 break;
200 case (int) ENERGY_NEUTRINO:
202 break;
203 case (int) EVIS:
205 break;
206 case (int) EVIS_LEADING_LEPTON_CONTR:
208 break;
209 case (int) EVIS_HADRONIC_CONTR:
211 break;
212 default:
213 THROW(JValueOutOfRange, "JEvtWeightFactorRatio::configure(): Invalid option " << option);
214 }
215 }
216
217
218 /**
219 * Retrieve effective mass histogram.
220 *
221 * \return effective mass histogram
222 */
223 const TH1& getHistogram() const
224 {
225 if (pMeff) {
226 return *pMeff;
227 } else {
228 THROW(JLANG::JNullPointerException, "JEvtWeightFactorMeffRatio::getHistogram(): Effective mass histogram is not set.");
229 }
230 }
231
232
233 /**
234 * Retrieve fiducial volume.
235 *
236 * \return fiducial volume
237 */
239 {
240 return fiducialVolume;
241 }
242
243
244 /**
245 * Set fiducial volume.
246 *
247 * \param fiducialVolume fiducial volume
248 */
250 {
251 this->fiducialVolume = fiducialVolume;
252
253 check_validity();
254 }
255
256
257 /**
258 * Check if this effective mass ratio weight factor is valid.
259 *
260 * \return true if valid; else false
261 */
262 bool is_valid() const override final
263 {
264 return (pMeff &&
267 ratio >= 0.0 &&
268 range.is_valid() &&
269 fiducialVolume.getVolume() >= 0.0);
270 }
271
272
273 /**
274 * Perform linear inter- or extrapolation of effective mass for given abscissa value.
275 *
276 * \param x abscissa value
277 * \return effective mass
278 */
279 inline double interpolate(const double x) const
280 {
281 using namespace std;
282
283 const Int_t Nbins = pMeff->GetNbinsX();
284
285 const Int_t i0 = max(1, min(Nbins, pMeff->FindBin(x)));
286
287 const Double_t x0 = pMeff->GetBinCenter (i0);
288 const Double_t y0 = pMeff->GetBinContent(i0);
289
290 const Int_t i1 = max(2, min(Nbins-1, (x > x0 ? i0+1 : i0-1)));
291
292 const Double_t x1 = pMeff->GetBinCenter(i1);
293 const Double_t y1 = pMeff->GetBinCenter(i1);
294
295 return y0 + (x-x0) * (y1-y0)/(x1-x0);
296 }
297
298
299 /**
300 * Get effective mass ratio based on a scaling of the initial state energy.
301 *
302 * \param x1 first abscissa value
303 * \param x2 second abscissa value
304 * \return effective mass ratio
305 */
306 inline double getMeffRatio(const double x1,
307 const double x2) const
308 {
309 const double M1 = interpolate(x1);
310 const double M2 = interpolate(x2);
311
312 const double ratio = M1 / (M2 > 0.0 ? M2 : MeffMin);
313
314 return (range(x2) ? ratio : 1.0);
315 }
316
317
318 /**
319 * Get effective mass ratio based on a scaling of the initial state energy.
320 *
321 * \param E0 initial state energy [GeV]
322 * \return effective mass ratio
323 */
324 inline double getMeffRatio1(const double E0) const
325 {
326 if (logE) {
327 const double X = log10(E0);
328 return getMeffRatio(log10(ratio) + X, X);
329 } else {
330 return getMeffRatio(ratio * E0, E0);
331 }
332 }
333
334
335 /**
336 * Get effective mass ratio based on a scaling of the initial state energy.
337 *
338 * \param event event
339 * \return effective mass ratio
340 */
341 inline double getMeffRatio1(const Evt& event) const
342 {
343 const double E0 = getE0(event);
344
345 return getMeffRatio1(E0);
346 }
347
348
349 /**
350 * Get effective mass ratio based on a scaling of the primary neutrino energy.
351 *
352 * \param Enu primary neutrino energy [GeV]
353 * \return effective mass ratio
354 */
355 inline double getMeffRatio2(const double Enu) const
356 {
357 if (logE) {
358 const double X = log10(Enu);
359 return getMeffRatio(log10(ratio) + X, X);
360 } else {
361 return getMeffRatio(ratio * Enu, Enu);
362 }
363 }
364
365
366 /**
367 * Get effective mass ratio based on a scaling of the primary neutrino energy.
368 *
369 * \param event event
370 * \return effective mass ratio
371 */
372 inline double getMeffRatio2(const Evt& event) const
373 {
374 const Trk& primary = get_neutrino(event);
375
376 const double Enu = primary.E;
377
378 return getMeffRatio2(Enu);
379 }
380
381
382 /**
383 * Get effective mass ratio based on a scaling of the total visible energy.
384 *
385 * \param Evis total visible energy [GeV]
386 * \return effective mass ratio
387 */
388 inline double getMeffRatio3(const double Evis) const
389 {
390 if (logE) {
391 const double X = log10(Evis);
392 return getMeffRatio(log10(ratio) + X, X);
393 } else {
394 return getMeffRatio(ratio * Evis, Evis);
395 }
396 }
397
398
399 /**
400 * Get effective mass ratio based on a scaling of the total visible energy.
401 *
402 * \param event event
403 * \return effective mass ratio
404 */
405 inline double getMeffRatio3(const Evt& event) const
406 {
407 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
408
409 return getMeffRatio3(Evis);
410 }
411
412
413 /**
414 * Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible energy.
415 *
416 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
417 * minus the leading leptonic contribution.
418 *
419 * \param Evis total visible energy [GeV]
420 * \param EvisLL leading lepton visible energy [GeV]
421 * \return effective mass ratio
422 */
423 inline double getMeffRatio4(const double Evis,
424 const double EvisLL) const
425 {
426 if (logE) {
427 return getMeffRatio(log10(Evis - (1-ratio) * EvisLL), log10(Evis));
428 } else {
429 return getMeffRatio( Evis - (1-ratio) * EvisLL, Evis);
430 }
431 }
432
433
434 /**
435 * Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible energy.
436 *
437 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
438 * minus the leading leptonic contribution.
439 *
440 * \param event event
441 * \return effective mass ratio
442 */
443 inline double getMeffRatio4(const Evt& event) const
444 {
445 const double Evis = JSIRENE::getVisibleEnergy (event, fiducialVolume);
446 const double EvisLL = JSIRENE::getVisibleEnergyLeadingLepton(event, fiducialVolume);
447
448 return getMeffRatio4(Evis, EvisLL);
449 }
450
451
452 /**
453 * Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
454 *
455 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
456 * minus the leading leptonic contribution.
457 *
458 * \param Evis total visible energy [GeV]
459 * \param EvisLL leading lepton visible energy [GeV]
460 * \return effective mass ratio
461 */
462 inline double getMeffRatio5(const double Evis,
463 const double EvisLL) const
464 {
465 if (logE) {
466 return getMeffRatio(log10(ratio * Evis + (1-ratio) * EvisLL), log10(Evis));
467 } else {
468 return getMeffRatio( ratio * Evis + (1-ratio) * EvisLL, Evis);
469 }
470 }
471
472
473 /**
474 * Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
475 *
476 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
477 * minus the leading leptonic contribution.
478 *
479 * \param event event
480 * \return effective mass ratio
481 */
482 inline double getMeffRatio5(const Evt& event) const
483 {
484 const double Evis = JSIRENE::getVisibleEnergy (event, fiducialVolume);
485 const double EvisLL = JSIRENE::getVisibleEnergyLeadingLepton(event, fiducialVolume);
486
487 return getMeffRatio5(Evis, EvisLL);
488 }
489
490
491 /**
492 * Get weighting factor for given event.
493 *
494 * \param evt event
495 * \return weighting factor
496 */
497 double getFactor(const Evt& evt) const override final
498 {
499 return (this->*mfp)(evt);
500 }
501
502
503 /**
504 * Get properties of this class.
505 *
506 * \param eqpars equation parameters
507 */
509 {
510 return JEvtWeightFactorMeffRatioHelper(*this, eqpars);
511 }
512
513
514 /**
515 * Get properties of this class.
516 *
517 * \param eqpars equation parameters
518 */
520 {
521 return JEvtWeightFactorMeffRatioHelper(*this, eqpars);
522 }
523
524
525 /**
526 * Read event-weight factor from input.
527 *
528 * \param in input stream
529 * \return input stream
530 */
531 std::istream& read(std::istream& in) override final
532 {
533 using namespace std;
534 using namespace JPP;
535
536 JStringStream is(in);
537
538 if (getFileStatus(is.str().c_str())) {
539 is.load();
540 }
541
542 JProperties properties = getProperties();
543 is >> properties;
544
545 check_validity();
546
547 configure();
548
549 return in;
550 }
551
552
553 private:
554
555
556 /** Type definition of pointer to member function for calculating effective mass ratios **/
557 typedef double (JEvtWeightFactorMeffRatio::*pFunction)(const Evt&) const;
558
559
560 /**
561 * Auxiliary class for I/O of effective mass ratio factor.
562 */
564 public JProperties
565 {
566 /**
567 * Constructor.
568 *
569 * \param factor constant event-weight factor
570 * \param eqpars equation parameters
571 */
572 template<class JEvtWeightFactorMeffRatio_t>
573 JEvtWeightFactorMeffRatioHelper(JEvtWeightFactorMeffRatio_t& factor,
574 const JEquationParameters& eqpars) :
575 JProperties(eqpars, 1)
576 {
577 (*this)[JEvtWeightFactor::getTypeKey()] = "effective mass ratio";
578
579 this->insert(gmake_property(factor.hMeff));
580 this->insert(gmake_property(factor.option));
581 this->insert(gmake_property(factor.ratio));
582 this->insert(gmake_property(factor.range));
583 this->insert(gmake_property(factor.fiducialVolume));
584 this->insert(gmake_property(factor.logE));
585 }
586 };
587
588
589 pFunction mfp; //!< Pointer to member method for calculating effective mass ratios
590
591 std::unique_ptr<TH1> pMeff; //!< Unique pointer to effective mass ratio histogram
592
593 JRootObjectID hMeff; //!< Effective mass histogram OID
594 int option; //!< Effective mass ratio option
595 double ratio; //!< Abscissa ratio
596 JRange_t range; //!< Applicable range
597 JCylinder3D fiducialVolume; //!< Fiducial volume (for visible energy computation)
598 bool logE; //!< Toggle logarithmic abscissa
599
600 const double MeffMin; //!< Minimum effective mass
601 };
602}
603
604#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.
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 getVisibleEnergyLeadingLepton(const Trk &, const JCylinder3D &)
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.
double interpolate(const double x) const
Perform linear inter- or extrapolation of effective mass for given abscissa value.
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