Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFactorTriggerEfficiencyRatio.hh
Go to the documentation of this file.
1#ifndef __JAANET__JEVTWEIGHTFACTORTRIGGEREFFICIENCYRATIO__
2#define __JAANET__JEVTWEIGHTFACTORTRIGGEREFFICIENCYRATIO__
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 trigger efficiency ratios.
68 */
70 public JClonable<JEvtWeightFactor, JEvtWeightFactorTriggerEfficiencyRatio>
71 {
73
74 /**
75 * Indices of options for calculating trigger efficiency ratios.\n
76 * The option names correspond to the variable which is used to compute the trigger efficiency ratio.
77 */
79 ENERGY_INITIAL_STATE, //!< Compute trigger efficiency ratio based on scaling of the initial state energy
80 ENERGY_NEUTRINO, //!< Compute trigger efficiency ratio based on scaling of theprimary neutrino energy
81 EVIS, //!< Compute trigger efficiency ratio based on scaling of the total visible energy
82 EVIS_LEADING_LEPTON_CONTR, //!< Compute trigger efficiency ratio based on scaling of the visible energy contribution of the leading lepton
83 EVIS_HADRONIC_CONTR, //!< Compute trigger efficiency 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 pTE (),
93 hTE ("", "default"),
95 ratio (0.0),
96 range (0.0, 4.0),
97 fiducialVolume(getMaximumContainmentVolume()),
98 logE (true)
99 {
100 pTE = std::make_unique<TH1D>(hTE.getObjectName(), "", 10, range.getLowerLimit(), range.getUpperLimit());
101
102 for (Int_t i = 1; i <= pTE->GetNbinsX(); ++i) {
103 pTE->SetBinContent(i, 1.0);
104 }
105
106 pTE->SetDirectory(0);
107
108 check_validity();
109 configure();
110 }
111
112
113 /**
114 * Constructor.
115 *
116 * \param objectID trigger efficiency histogram OID
117 * \param option option
118 * \param ratio abscissa ratio
119 * \param range applicable (logarithmic) energy range [GeV]
120 * \param logE toggle logarithmic energies
121 * \param fiducialVolume fiducial volume
122 */
125 const double ratio,
126 const JRange_t& range,
127 const bool logE,
129 pTE (),
130 hTE (objectID),
131 option (option),
132 ratio (ratio),
133 range (range),
135 logE (logE)
136 {
137 check_validity();
138 configure();
139 }
140
141
142 /**
143 * Copy constructor.
144 *
145 * \param factor trigger efficiency ratio factor
146 */
148 pTE (),
149 hTE (factor.hTE),
150 option (factor.option),
151 ratio (factor.ratio),
152 range (factor.range),
154 logE (factor.logE)
155 {
156 pTE.reset((TH1*) factor.pTE->Clone());
157
158 pTE->SetDirectory(0);
159
160 check_validity();
161 configure();
162 }
163
164
165 /**
166 * Configure trigger efficiency ratio factor.
167 */
169 {
170 using namespace std;
171 using namespace JPP;
172
173 if (hTE.is_valid() && (!pTE || hTE.getObjectName() != string(pTE->GetName()))) {
174
175 if (!getFileStatus(hTE.getFilename().c_str())) {
176 THROW(JFileOpenException, "JEvtWeightFactorTriggerEfficiencyRatio::configure(): Could not open file " << hTE.getFilename());
177 }
178
179 TFile f(hTE.getFilename().c_str(), "read");
180
181 TH1* h = (TH1*) f.Get(hTE.getObjectName());
182
183 if (h != NULL) {
184 pTE.reset(h);
185 pTE->SetDirectory(0);
186 } else {
187 THROW(JNullPointerException, "JEvtWeightFactorTriggerEfficiencyRatio::configure(): Could not extract histogram " << hTE);
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 trigger efficiency histogram.
217 *
218 * \return trigger efficiency histogram
219 */
220 const TH1& getHistogram() const
221 {
222 if (pTE) {
223 return *pTE;
224 } else {
225 THROW(JLANG::JNullPointerException, "JEvtWeightFactorTriggerEfficiencyRatio::getHistogram(): Trigger efficiency 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 trigger efficiency ratio weight factor is valid.
256 *
257 * \return true if valid; else false
258 */
259 bool is_valid() const override final
260 {
261 return (pTE &&
264 ratio >= 0.0 &&
265 range.is_valid() &&
266 fiducialVolume.getVolume() >= 0.0);
267 }
268
269
270 /**
271 * Perform linear inter- or extrapolation of trigger efficiency for given abscissa value.
272 *
273 * \param x abscissa value
274 * \return trigger efficiency
275 */
276 inline double interpolate(const double x) const
277 {
278 using namespace std;
279
280 const Int_t Nbins = pTE->GetNbinsX();
281
282 //!< Ensure that only given user-range is used for interpolation
283 const Double_t X = range.constrain(x);
284
285 const Int_t i0 = max(1, min(Nbins, pTE->FindBin(X)));
286
287 const Double_t x0 = pTE->GetBinCenter (i0);
288 const Double_t y0 = pTE->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 = pTE->GetBinCenter (i1);
293 const Double_t y1 = pTE->GetBinContent(i1);
294
295 return max(0.0, y0 + (x-x0) * (y1-y0)/(x1-x0));
296 }
297
298
299 /**
300 * Get trigger efficiency 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 trigger efficiency ratio
305 */
306 inline double getTriggerEfficiencyRatio(const double x1,
307 const double x2) const
308 {
309 static const double Xmin = -3.0; //!< Minimum logarithmic energy (= 1 MeV)
310
311 double X1 = x1;
312 double X2 = x2;
313
314 if (logE) {
315 X1 = x1 > 0.0 ? log10(x1) : Xmin;
316 X2 = x2 > 0.0 ? log10(x2) : Xmin;
317 }
318
319 const double M1 = interpolate(X1);
320 const double M2 = interpolate(X2);
321
322 return M2 > 0.0 ? M1/M2 : 1.0;
323 }
324
325
326 /**
327 * Get trigger efficiency ratio based on a scaling of the initial state energy.
328 *
329 * \param E0 initial state energy [GeV]
330 * \return trigger efficiency ratio
331 */
332 inline double getTriggerEfficiencyRatio1(const double E0) const
333 {
334 return getTriggerEfficiencyRatio(ratio * E0, E0);
335 }
336
337
338 /**
339 * Get trigger efficiency ratio based on a scaling of the initial state energy.
340 *
341 * \param event event
342 * \return trigger efficiency ratio
343 */
344 inline double getTriggerEfficiencyRatio1(const Evt& event) const
345 {
346 const double E0 = getE0(event);
347
349 }
350
351
352 /**
353 * Get trigger efficiency ratio based on a scaling of the primary neutrino energy.
354 *
355 * \param Enu primary neutrino energy [GeV]
356 * \return trigger efficiency ratio
357 */
358 inline double getTriggerEfficiencyRatio2(const double Enu) const
359 {
360 return getTriggerEfficiencyRatio(ratio * Enu, Enu);
361 }
362
363
364 /**
365 * Get trigger efficiency ratio based on a scaling of the primary neutrino energy.
366 *
367 * \param event event
368 * \return trigger efficiency ratio
369 */
370 inline double getTriggerEfficiencyRatio2(const Evt& event) const
371 {
372 const Trk& primary = get_neutrino(event);
373
374 const double Enu = primary.E;
375
376 return getTriggerEfficiencyRatio2(Enu);
377 }
378
379
380 /**
381 * Get trigger efficiency ratio based on a scaling of the total visible energy.
382 *
383 * \param Evis total visible energy [GeV]
384 * \return trigger efficiency ratio
385 */
386 inline double getTriggerEfficiencyRatio3(const double Evis) const
387 {
388 return getTriggerEfficiencyRatio(ratio * Evis, Evis);
389 }
390
391
392 /**
393 * Get trigger efficiency ratio based on a scaling of the total visible energy.
394 *
395 * \param event event
396 * \return trigger efficiency ratio
397 */
398 inline double getTriggerEfficiencyRatio3(const Evt& event) const
399 {
400 const double Evis = JSIRENE::getVisibleEnergy(event, fiducialVolume);
401
402 return getTriggerEfficiencyRatio3(Evis);
403 }
404
405
406 /**
407 * Get trigger efficiency ratio based on a scaling of the leading leptonic contribution to the total visible energy.
408 *
409 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
410 * minus the leading leptonic contribution.
411 *
412 * \param Evis total visible energy [GeV]
413 * \param EvisLL leading lepton visible energy [GeV]
414 * \return trigger efficiency ratio
415 */
416 inline double getTriggerEfficiencyRatio4(const double Evis,
417 const double EvisLL) const
418 {
419 return getTriggerEfficiencyRatio(Evis - (1-ratio)*EvisLL, Evis);
420 }
421
422
423 /**
424 * Get trigger efficiency ratio based on a scaling of the leading leptonic contribution to the total visible energy.
425 *
426 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
427 * minus the leading leptonic contribution.
428 *
429 * \param event event
430 * \return trigger efficiency ratio
431 */
432 inline double getTriggerEfficiencyRatio4(const Evt& event) const
433 {
434 const double Evis = JSIRENE::getVisibleEnergy (event, fiducialVolume);
435 const double EvisLL = JSIRENE::getVisibleEnergyLeadingLepton(event, fiducialVolume);
436
437 return getTriggerEfficiencyRatio4(Evis, EvisLL);
438 }
439
440
441 /**
442 * Get trigger efficiency ratio based on a scaling of the hadronic contribution to the total visible energy.
443 *
444 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
445 * minus the leading leptonic contribution.
446 *
447 * \param Evis total visible energy [GeV]
448 * \param EvisLL leading lepton visible energy [GeV]
449 * \return trigger efficiency ratio
450 */
451 inline double getTriggerEfficiencyRatio5(const double Evis,
452 const double EvisLL) const
453 {
454 return getTriggerEfficiencyRatio(ratio*Evis + (1-ratio)*EvisLL, Evis);
455 }
456
457
458 /**
459 * Get trigger efficiency ratio based on a scaling of the hadronic contribution to the total visible energy.
460 *
461 * This function assumes that the hadronic component in the visible energy corresponds to the total visible energy\n
462 * minus the leading leptonic contribution.
463 *
464 * \param event event
465 * \return trigger efficiency ratio
466 */
467 inline double getTriggerEfficiencyRatio5(const Evt& event) const
468 {
469 const double Evis = JSIRENE::getVisibleEnergy (event, fiducialVolume);
470 const double EvisLL = JSIRENE::getVisibleEnergyLeadingLepton(event, fiducialVolume);
471
472 return getTriggerEfficiencyRatio5(Evis, EvisLL);
473 }
474
475
476 /**
477 * Get weighting factor for given event.
478 *
479 * \param evt event
480 * \return weighting factor
481 */
482 double getFactor(const Evt& evt) const override final
483 {
484 return (this->*mfp)(evt);
485 }
486
487
488 /**
489 * Get properties of this class.
490 *
491 * \param eqpars equation parameters
492 */
497
498
499 /**
500 * Get properties of this class.
501 *
502 * \param eqpars equation parameters
503 */
508
509
510 /**
511 * Read event-weight factor from input.
512 *
513 * \param in input stream
514 * \return input stream
515 */
516 std::istream& read(std::istream& in) override final
517 {
518 using namespace std;
519 using namespace JPP;
520
521 JStringStream is(in);
522
523 if (getFileStatus(is.str().c_str())) {
524 is.load();
525 }
526
527 JProperties properties = getProperties();
528 is >> properties;
529
530 check_validity();
531
532 configure();
533
534 return in;
535 }
536
537
538 private:
539
540
541 /** Type definition of pointer to member function for calculating trigger efficiency ratios **/
542 typedef double (JEvtWeightFactorTriggerEfficiencyRatio::*pFunction)(const Evt&) const;
543
544
545 /**
546 * Auxiliary class for I/O of trigger efficiency ratio factor.
547 */
549 public JProperties
550 {
551 /**
552 * Constructor.
553 *
554 * \param factor constant event-weight factor
555 * \param eqpars equation parameters
556 */
557 template<class JEvtWeightFactorTriggerEfficiencyRatio_t>
558 JEvtWeightFactorTriggerEfficiencyRatioHelper(JEvtWeightFactorTriggerEfficiencyRatio_t& factor,
559 const JEquationParameters& eqpars) :
560 JProperties(eqpars, 1)
561 {
562 (*this)[JEvtWeightFactor::getTypeKey()] = "trigger efficiency ratio";
563
564 this->insert(gmake_property(factor.hTE));
565 this->insert(gmake_property(factor.option));
566 this->insert(gmake_property(factor.ratio));
567 this->insert(gmake_property(factor.range));
568 this->insert(gmake_property(factor.fiducialVolume));
569 this->insert(gmake_property(factor.logE));
570 }
571 };
572
573
574 pFunction mfp; //!< Pointer to member method for calculating trigger efficiency ratios
575
576 std::unique_ptr<TH1> pTE; //!< Unique pointer to trigger efficiency ratio histogram
577
578 JRootObjectID hTE; //!< Trigger efficiency histogram OID
579 int option; //!< Trigger efficiency ratio option
580 double ratio; //!< Abscissa ratio
581 JRange_t range; //!< Applicable range
582 JCylinder3D fiducialVolume; //!< Fiducial volume (for visible energy computation)
583 bool logE; //!< Toggle logarithmic abscissa
584 };
585}
586
587#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 constrain(argument_type x) const
Constrain value to range.
Definition JRange.hh:350
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).
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
JEvtWeightFactorTriggerEfficiencyRatioHelper(JEvtWeightFactorTriggerEfficiencyRatio_t &factor, const JEquationParameters &eqpars)
Constructor.
Implementation of reweighting factor for trigger efficiency ratios.
JTriggerEfficiencyRatioOption
Indices of options for calculating trigger efficiency ratios.
@ EVIS_HADRONIC_CONTR
Compute trigger efficiency ratio based on scaling of the visible energy contribution of the hadronic ...
@ ENERGY_NEUTRINO
Compute trigger efficiency ratio based on scaling of theprimary neutrino energy.
@ EVIS
Compute trigger efficiency ratio based on scaling of the total visible energy.
@ EVIS_LEADING_LEPTON_CONTR
Compute trigger efficiency ratio based on scaling of the visible energy contribution of the leading l...
@ ENERGY_INITIAL_STATE
Compute trigger efficiency ratio based on scaling of the initial state energy.
@ NUMBER_OF_OPTIONS
N.B.: This enum value needs to be specified last!
double getTriggerEfficiencyRatio5(const Evt &event) const
Get trigger efficiency ratio based on a scaling of the hadronic contribution to the total visible ene...
double getFactor(const Evt &evt) const override final
Get weighting factor for given event.
void setFiducialVolume(const JCylinder3D &fiducialVolume)
Set fiducial volume.
double getTriggerEfficiencyRatio1(const Evt &event) const
Get trigger efficiency ratio based on a scaling of the initial state energy.
JEvtWeightFactorTriggerEfficiencyRatio(const JRootObjectID &objectID, const JTriggerEfficiencyRatioOption option, const double ratio, const JRange_t &range, const bool logE, const JCylinder3D &fiducialVolume)
Constructor.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) override final
Get properties of this class.
pFunction mfp
Pointer to member method for calculating trigger efficiency ratios.
double getTriggerEfficiencyRatio(const double x1, const double x2) const
Get trigger efficiency ratio based on a scaling of the initial state energy.
bool is_valid() const override final
Check if this trigger efficiency ratio weight factor is valid.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const override final
Get properties of this class.
void configure()
Configure trigger efficiency ratio factor.
JCylinder3D fiducialVolume
Fiducial volume (for visible energy computation)
double getTriggerEfficiencyRatio3(const Evt &event) const
Get trigger efficiency ratio based on a scaling of the total visible energy.
double getTriggerEfficiencyRatio2(const double Enu) const
Get trigger efficiency ratio based on a scaling of the primary neutrino energy.
double getTriggerEfficiencyRatio4(const Evt &event) const
Get trigger efficiency ratio based on a scaling of the leading leptonic contribution to the total vis...
double getTriggerEfficiencyRatio3(const double Evis) const
Get trigger efficiency ratio based on a scaling of the total visible energy.
std::istream & read(std::istream &in) override final
Read event-weight factor from input.
double getTriggerEfficiencyRatio5(const double Evis, const double EvisLL) const
Get trigger efficiency ratio based on a scaling of the hadronic contribution to the total visible ene...
JEvtWeightFactorTriggerEfficiencyRatio(const JEvtWeightFactorTriggerEfficiencyRatio &factor)
Copy constructor.
double(JEvtWeightFactorTriggerEfficiencyRatio::*) pFunction(const Evt &) const
Type definition of pointer to member function for calculating trigger efficiency ratios.
double interpolate(const double x) const
Perform linear inter- or extrapolation of trigger efficiency for given abscissa value.
double getTriggerEfficiencyRatio1(const double E0) const
Get trigger efficiency ratio based on a scaling of the initial state energy.
double getTriggerEfficiencyRatio4(const double Evis, const double EvisLL) const
Get trigger efficiency ratio based on a scaling of the leading leptonic contribution to the total vis...
double getTriggerEfficiencyRatio2(const Evt &event) const
Get trigger efficiency ratio based on a scaling of the primary neutrino energy.
const TH1 & getHistogram() const
Retrieve trigger efficiency histogram.
std::unique_ptr< TH1 > pTE
Unique pointer to trigger efficiency ratio histogram.
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