ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Variable Class Reference

Wrapper around a histogram which allows for some additional filling patterns and data manipulation. More...

#include <Variable.h>

Collaboration diagram for Variable:

Public Member Functions

 Variable ()=delete
 Forbid default constructor. More...
 
 Variable (const std::string &name, TH1 *cacheHistoPtr, VariableType type=kPerCall)
 Construct Variable. More...
 
 ~Variable ()=default
 Default destructor. More...
 
Variableoperator= (const Variable &)=delete
 Forbid copy. More...
 
 Variable (const Variable &)=delete
 Forbid copy. More...
 
const std::string & getName () const
 Getter for Variable's name. More...
 
size_t getCalls () const
 Getter for how many times fill() has already been called on this Variable in this event. More...
 
float getAccumulator () const
 Getter for accumulated value of a kPerEvent Variable. More...
 
StatusCode fill (float value, float weight=1.0)
 Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be filled at the end of the event. More...
 
StatusCode fill (float xvalue, float yvalue, float weight)
 Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be filled at the end of the event. More...
 
StatusCode fill (const std::string &label, float weight=1.0)
 Fill histogram's bin (per-Call Variable) with given label. More...
 
StatusCode increment (float weight=1.0)
 Convenience function. More...
 
StatusCode setBinLabel (int bin, const std::string &label)
 Set label on given bin in cached histogram. More...
 
StatusCode setYBinLabel (int bin, const std::string &label)
 Set label on given bin in cached histogram on y axis. More...
 
void setDenominator (float value)
 Sets, until the end of the event, a denominator which will be used to normalise every Fill. More...
 
StatusCode endEvent ()
 Called by the framework. More...
 

Private Attributes

const std::string m_name
 
const VariableType m_variableType
 
TH1m_cacheHistoPtr
 
size_t m_calls
 
float m_xaccumulator
 
float m_yaccumulator
 
float m_weight
 Cache of the event weight. More...
 
float m_oneOverDenominator
 Cache of the reciprocal of the denominator used to normalise when filling the histogram. More...
 

Detailed Description

Wrapper around a histogram which allows for some additional filling patterns and data manipulation.

Behaviour based on type parameter. per-Call directly fills underlying histogram for each call of fill. per-Event fills the underlying histogram exactly once in events where fill was called one or more times. The filled value is accumulated from all calls to fill during the event in per-Event mode.

Definition at line 39 of file Trigger/TrigCost/TrigCostAnalysis/src/Variable.h.

Constructor & Destructor Documentation

◆ Variable() [1/3]

Variable::Variable ( )
delete

Forbid default constructor.

◆ Variable() [2/3]

Variable::Variable ( const std::string &  name,
TH1 cacheHistoPtr,
VariableType  type = kPerCall 
)

Construct Variable.

Parameters
[in]nameVariable's name
[in]cacheHistoPtrCached non-owning pointer to the histogram which this Variable wraps.
[in]typeIf the Variable should operate in per-Call mode (direct fill) or per-Event mode (accumulate and fill at the end of the event).

Definition at line 12 of file Variable.cxx.

12  :
13  m_name(name),
15  m_cacheHistoPtr(cacheHistoPtr),
16  m_calls(0),
17  m_xaccumulator(0.),
18  m_yaccumulator(0.),
19  m_weight(0.),
21 }

◆ ~Variable()

Variable::~Variable ( )
default

Default destructor.

◆ Variable() [3/3]

Variable::Variable ( const Variable )
delete

Forbid copy.

Member Function Documentation

◆ endEvent()

StatusCode Variable::endEvent ( )

Called by the framework.

Triggers actual histogram fill for a per-Event variable. Resets internals.

Definition at line 120 of file Variable.cxx.

120  {
121  if (m_variableType == kPerEvent && m_calls > 0) {
122  ATH_CHECK(m_cacheHistoPtr != nullptr);
123  // 2D histogram
124  if (m_yaccumulator > 0){
125  TH2F* th2f = dynamic_cast<TH2F*>(m_cacheHistoPtr);
126  if (th2f == nullptr){
127  // Cast failed - should be TProfile
129  } else {
131  }
132  } else {
134  }
135 
136  }
137  m_calls = 0;
138  m_xaccumulator = 0.0;
139  m_yaccumulator = 0.0;
140  m_weight = 0.0;
141  m_oneOverDenominator = 1.0;
142  return StatusCode::SUCCESS;
143 }

◆ fill() [1/3]

StatusCode Variable::fill ( const std::string &  label,
float  weight = 1.0 
)

Fill histogram's bin (per-Call Variable) with given label.

Parameters
[in]labelLabel of bin to fill
[in]weightGlobal event weight

Definition at line 96 of file Variable.cxx.

96  {
97  m_cacheHistoPtr->Fill(label.c_str(), weight);
98  return StatusCode::SUCCESS;
99 }

◆ fill() [2/3]

StatusCode Variable::fill ( float  value,
float  weight = 1.0 
)

Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be filled at the end of the event.

Parameters
[in]valueThe payload.
[in]weightGlobal event weight

Definition at line 49 of file Variable.cxx.

49  {
50  switch(m_variableType) {
51  case kPerCall:
52  ATH_CHECK(m_cacheHistoPtr != nullptr);
54  break;
55  case kPerEvent:
56  ++m_calls;
58  m_weight = weight;
59  break;
60  default:
61  return StatusCode::FAILURE;
62  break;
63  }
64  return StatusCode::SUCCESS;
65 }

◆ fill() [3/3]

StatusCode Variable::fill ( float  xvalue,
float  yvalue,
float  weight 
)

Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be filled at the end of the event.

Parameters
[in]xvalueThe x-axis payload.
[in]yvalueThe y-axis payload.
[in]weightGlobal event weight

Definition at line 68 of file Variable.cxx.

68  {
69  switch(m_variableType) {
70  case kPerCall:
71  {
72  ATH_CHECK(m_cacheHistoPtr != nullptr);
73  TH2F* th2f = dynamic_cast<TH2F*>(m_cacheHistoPtr);
74  if (th2f == nullptr){
75  // Cast failed - should be TProfile
76  dynamic_cast<TProfile*>(m_cacheHistoPtr)->Fill(xvalue * m_oneOverDenominator, yvalue * m_oneOverDenominator, weight);
77  } else {
78  th2f->Fill(xvalue * m_oneOverDenominator, yvalue * m_oneOverDenominator, weight);
79  }
80  break;
81  }
82  case kPerEvent:
83  ++m_calls;
84  m_xaccumulator += xvalue;
85  m_yaccumulator += yvalue;
86  m_weight = weight;
87  break;
88  default:
89  return StatusCode::FAILURE;
90  break;
91  }
92  return StatusCode::SUCCESS;
93 }

◆ getAccumulator()

float Variable::getAccumulator ( ) const

Getter for accumulated value of a kPerEvent Variable.

Returns
Total accumulated payload

Definition at line 34 of file Variable.cxx.

34  {
35  return m_xaccumulator;
36 }

◆ getCalls()

size_t Variable::getCalls ( ) const

Getter for how many times fill() has already been called on this Variable in this event.

Returns
Number of fill calls this event.

Definition at line 29 of file Variable.cxx.

29  {
30  return m_calls;
31 }

◆ getName()

const std::string & Variable::getName ( ) const

Getter for Variable's name.

Returns
Variable's name const string reference.

Definition at line 24 of file Variable.cxx.

24  {
25  return m_name;
26 }

◆ increment()

StatusCode Variable::increment ( float  weight = 1.0)

Convenience function.

Equivalent of fill(1.0, weight). For use with per-Event counting type variables.

Parameters
[in]weightGlobal event weight

Definition at line 102 of file Variable.cxx.

102  {
103  ATH_CHECK(fill(1.0, weight));
104  return StatusCode::SUCCESS;
105 }

◆ operator=()

Variable& Variable::operator= ( const Variable )
delete

Forbid copy.

◆ setBinLabel()

StatusCode Variable::setBinLabel ( int  bin,
const std::string &  label 
)

Set label on given bin in cached histogram.

Parameters
[in]binBin number
[in]labelLabel to set

Definition at line 108 of file Variable.cxx.

108  {
109  m_cacheHistoPtr->GetXaxis()->SetBinLabel(bin, label.c_str());
110  return StatusCode::SUCCESS;
111 }

◆ setDenominator()

void Variable::setDenominator ( float  value)

Sets, until the end of the event, a denominator which will be used to normalise every Fill.

@pram[in] value The denominator to normalise Fill operations.

Definition at line 39 of file Variable.cxx.

39  {
40  // Stored as reciprocal so as to be able to check for /0 here
41  if (std::abs(value) < 1e-10) {
43  } else {
45  }
46 }

◆ setYBinLabel()

StatusCode Variable::setYBinLabel ( int  bin,
const std::string &  label 
)

Set label on given bin in cached histogram on y axis.

Parameters
[in]binBin number
[in]labelLabel to set

Definition at line 114 of file Variable.cxx.

114  {
115  m_cacheHistoPtr->GetYaxis()->SetBinLabel(bin, label.c_str());
116  return StatusCode::SUCCESS;
117 }

Member Data Documentation

◆ m_cacheHistoPtr

TH1* Variable::m_cacheHistoPtr
private

◆ m_calls

size_t Variable::m_calls
private

◆ m_name

const std::string Variable::m_name
private

◆ m_oneOverDenominator

float Variable::m_oneOverDenominator
private

Cache of the reciprocal of the denominator used to normalise when filling the histogram.

Definition at line 149 of file Trigger/TrigCost/TrigCostAnalysis/src/Variable.h.

◆ m_variableType

const VariableType Variable::m_variableType
private

◆ m_weight

float Variable::m_weight
private

Cache of the event weight.

Assumed to be the same for every call to fill with per-Event monitoring!

Definition at line 148 of file Trigger/TrigCost/TrigCostAnalysis/src/Variable.h.

◆ m_xaccumulator

float Variable::m_xaccumulator
private

◆ m_yaccumulator

float Variable::m_yaccumulator
private

The documentation for this class was generated from the following files:
Variable::m_calls
size_t m_calls
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:145
Variable::m_weight
float m_weight
Cache of the event weight.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:148
TH2F
Definition: rootspy.cxx:420
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
kPerEvent
@ kPerEvent
Variable should buffer fill calls in an accumulator and fill the underlying histogram once at the end...
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:19
bin
Definition: BinsDiffFromStripMedian.h:43
athena.value
value
Definition: athena.py:122
Variable::m_cacheHistoPtr
TH1 * m_cacheHistoPtr
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:144
Variable::m_yaccumulator
float m_yaccumulator
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:147
Variable::m_oneOverDenominator
float m_oneOverDenominator
Cache of the reciprocal of the denominator used to normalise when filling the histogram.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:149
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
Variable::m_variableType
const VariableType m_variableType
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:143
Variable::m_xaccumulator
float m_xaccumulator
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:146
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
Variable::m_name
const std::string m_name
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:142
kPerCall
@ kPerCall
Variable should fill underlying histogram on each fill.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/Variable.h:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TProfile
Definition: rootspy.cxx:515
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Variable::fill
StatusCode fill(float value, float weight=1.0)
Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be f...
Definition: Variable.cxx:49