Jpp 19.3.0-rc.4
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 * Perform linear inter- or extrapolation of effective mass for given abscissa value.
272 *
273 * \param x abscissa value
274 * \return effective mass
275 */
276 inline double interpolate(const double x) const
277 {
278 using namespace std;
279
280 const Int_t Nbins = pMeff->GetNbinsX();
281
282 const Int_t i0 = max(1, min(Nbins, pMeff->FindBin(x)));
283
284 const Double_t x0 = pMeff->GetBinCenter (i0);
285 const Double_t y0 = pMeff->GetBinContent(i0);
286
287 const Int_t i1 = max(2, min(Nbins-1, (x > x0 ? i0+1 : i0-1)));
288
289 const Double_t x1 = pMeff->GetBinCenter(i1);
290 const Double_t y1 = pMeff->GetBinCenter(i1);
291
292 return y0 + (x-x0) * (y1-y0)/(x1-x0);
293 }
294
295
296 /**
297 * Get effective mass ratio based on a scaling of the initial state energy.
298 *
299 * \param x1 first abscissa value
300 * \param x2 second abscissa value
301 * \return effective mass ratio
302 */
303 inline double getMeffRatio(const double x1,
304 const double x2) const
305 {
306 const double M1 = interpolate(x1);
307 const double M2 = interpolate(x2);
308
309 const double ratio = M1 / (M2 > 0.0 ? M2 : MeffMin);
310
311 return (range(x2) ? ratio : 1.0);
312 }
313
314
315 /**
316 * Get effective mass ratio based on a scaling of the initial state energy.
317 *
318 * \param E0 initial state energy [GeV]
319 * \return effective mass ratio
320 */
321 inline double getMeffRatio1(const double E0) const
322 {
323 if (logE) {
324 const double X = log10(E0);
325 return getMeffRatio(log10(ratio) + X, X);
326 } else {
327 return getMeffRatio(ratio * E0, E0);
328 }
329 }
330
331
332 /**
333 * Get effective mass ratio based on a scaling of the initial state energy.
334 *
335 * \param event event
336 * \return effective mass ratio
337 */
338 inline double getMeffRatio1(const Evt& event) const
339 {
340 const double E0 = getE0(event);
341
342 return getMeffRatio1(E0);
343 }
344
345
346 /**
347 * Get effective mass ratio based on a scaling of the primary neutrino energy.
348 *
349 * \param Enu primary neutrino energy [GeV]
350 * \return effective mass ratio
351 */
352 inline double getMeffRatio2(const double Enu) const
353 {
354 if (logE) {
355 const double X = log10(Enu);
356 return getMeffRatio(log10(ratio) + X, X);
357 } else {
358 return getMeffRatio(ratio * Enu, Enu);
359 }
360 }
361
362
363 /**
364 * Get effective mass ratio based on a scaling of the primary neutrino energy.
365 *
366 * \param event event
367 * \return effective mass ratio
368 */
369 inline double getMeffRatio2(const Evt& event) const
370 {
371 const Trk& primary = get_neutrino(event);
372
373 const double Enu = primary.E;
374
375 return getMeffRatio2(Enu);
376 }
377
378
379 /**
380 * Get effective mass ratio based on a scaling of the total visible energy.
381 *
382 * \param Evis total visible energy [GeV]
383 * \return effective mass ratio
384 */
385 inline double getMeffRatio3(const double Evis) const
386 {
387 if (logE) {
388 const double X = log10(Evis);
389 return getMeffRatio(log10(ratio) + X, X);
390 } else {
391 return getMeffRatio(ratio * Evis, Evis);
392 }
393 }
394
395
396 /**
397 * Get effective mass ratio based on a scaling of the total visible energy.
398 *
399 * \param event event
400 * \return effective mass ratio
401 */
402 inline double getMeffRatio3(const Evt& event) const
403 {
404 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
405
406 return getMeffRatio3(Evis);
407 }
408
409
410 /**
411 * Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible energy.
412 *
413 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
414 * minus the leading leptonic contribution.
415 *
416 * \param Evis total visible energy [GeV]
417 * \param EvisLL leading lepton visible energy [GeV]
418 * \return effective mass ratio
419 */
420 inline double getMeffRatio4(const double Evis,
421 const double EvisLL) const
422 {
423 if (logE) {
424 return getMeffRatio(log10(Evis - (1-ratio) * EvisLL), log10(Evis));
425 } else {
426 return getMeffRatio( Evis - (1-ratio) * EvisLL, Evis);
427 }
428 }
429
430
431 /**
432 * Get effective mass ratio based on a scaling of the leading leptonic contribution to the total visible energy.
433 *
434 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
435 * minus the leading leptonic contribution.
436 *
437 * \param event event
438 * \return effective mass ratio
439 */
440 inline double getMeffRatio4(const Evt& event) const
441 {
442 const Trk& LL = get_leading_lepton(event);
443
444 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
445 const double EvisLL = JSIRENE::getVisibleEnergy(LL, fiducialVolume);
446
447 return getMeffRatio4(Evis, EvisLL);
448 }
449
450
451 /**
452 * Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
453 *
454 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
455 * minus the leading leptonic contribution.
456 *
457 * \param Evis total visible energy [GeV]
458 * \param EvisLL leading lepton visible energy [GeV]
459 * \return effective mass ratio
460 */
461 inline double getMeffRatio5(const double Evis,
462 const double EvisLL) const
463 {
464 if (logE) {
465 return getMeffRatio(log10(ratio * Evis + (1-ratio) * EvisLL), log10(Evis));
466 } else {
467 return getMeffRatio( ratio * Evis + (1-ratio) * EvisLL, Evis);
468 }
469 }
470
471
472 /**
473 * Get effective mass ratio based on a scaling of the hadronic contribution to the total visible energy.
474 *
475 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
476 * minus the leading leptonic contribution.
477 *
478 * \param event event
479 * \return effective mass ratio
480 */
481 inline double getMeffRatio5(const Evt& event) const
482 {
483 const Trk& LL = get_leading_lepton(event);
484
485 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
486 const double EvisLL = JSIRENE::getVisibleEnergy(LL, fiducialVolume);
487
488 return getMeffRatio5(Evis, EvisLL);
489 }
490
491
492 /**
493 * Get weighting factor for given event.
494 *
495 * \param evt event
496 * \return weighting factor
497 */
498 double getFactor(const Evt& evt) const override final
499 {
500 return (this->*mfp)(evt);
501 }
502
503
504 /**
505 * Get properties of this class.
506 *
507 * \param eqpars equation parameters
508 */
510 {
511 return JEvtWeightFactorMeffRatioHelper(*this, eqpars);
512 }
513
514
515 /**
516 * Get properties of this class.
517 *
518 * \param eqpars equation parameters
519 */
521 {
522 return JEvtWeightFactorMeffRatioHelper(*this, eqpars);
523 }
524
525
526 /**
527 * Read event-weight factor from input.
528 *
529 * \param in input stream
530 * \return input stream
531 */
532 std::istream& read(std::istream& in) override final
533 {
534 using namespace std;
535 using namespace JPP;
536
537 JStringStream is(in);
538
539 if (getFileStatus(is.str().c_str())) {
540 is.load();
541 }
542
543 JProperties properties = getProperties();
544 is >> properties;
545
546 check_validity();
547
548 configure();
549
550 return in;
551 }
552
553
554 private:
555
556
557 /** Type definition of pointer to member function for calculating effective mass ratios **/
558 typedef double (JEvtWeightFactorMeffRatio::*pFunction)(const Evt&) const;
559
560
561 /**
562 * Auxiliary class for I/O of effective mass ratio factor.
563 */
565 public JProperties
566 {
567 /**
568 * Constructor.
569 *
570 * \param factor constant event-weight factor
571 * \param eqpars equation parameters
572 */
573 template<class JEvtWeightFactorMeffRatio_t>
574 JEvtWeightFactorMeffRatioHelper(JEvtWeightFactorMeffRatio_t& factor,
575 const JEquationParameters& eqpars) :
576 JProperties(eqpars, 1)
577 {
578 (*this)[JEvtWeightFactor::getTypeKey()] = "effective mass ratio";
579
580 this->insert(gmake_property(factor.hMeff));
581 this->insert(gmake_property(factor.option));
582 this->insert(gmake_property(factor.ratio));
583 this->insert(gmake_property(factor.range));
584 this->insert(gmake_property(factor.fiducialVolume));
585 this->insert(gmake_property(factor.logE));
586 }
587 };
588
589
590 pFunction mfp; //!< Pointer to member method for calculating effective mass ratios
591
592 std::unique_ptr<TH1> pMeff; //!< Unique pointer to effective mass ratio histogram
593
594 JRootObjectID hMeff; //!< Effective mass histogram OID
595 int option; //!< Effective mass ratio option
596 double ratio; //!< Abscissa ratio
597 JRange_t range; //!< Applicable range
598 JCylinder3D fiducialVolume; //!< Fiducial volume (for visible energy computation)
599 bool logE; //!< Toggle logarithmic abscissa
600
601 const double MeffMin; //!< Minimum effective mass
602 };
603}
604
605#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.
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