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