ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Monitored::HistogramFiller2DGeneric< H > Class Template Reference

Generic filler for 2D histogram. More...

#include <HistogramFiller2D.h>

Inheritance diagram for Monitored::HistogramFiller2DGeneric< H >:
Collaboration diagram for Monitored::HistogramFiller2DGeneric< H >:

Public Member Functions

 HistogramFiller2DGeneric (const HistogramDef &definition, std::shared_ptr< IHistogramProvider > provider)
 
virtual unsigned fill (const HistogramFiller::VariablesPack &vars) const override
 Method that actually fills the ROOT object. More...
 
void touch () const
 Ensure histogram exists. More...
 
const std::vector< std::string > & histogramVariablesNames () const
 
const std::string & histogramWeightName () const
 
const std::string & histogramCutMaskName () const
 
const std::unique_lock< std::mutex > getLock () const
 

Protected Member Functions

template<class H , typename W , typename C , typename ... Ms>
unsigned fill (W weight, C cut, const Ms &... m) const
 Fill histogram from IMonitoredVariable. More...
 
template<class H >
H * histogram () const
 
std::pair< size_t, std::function< bool(size_t)> > getCutMaskFunc (const Monitored::IMonitoredVariable *mask) const
 

Protected Attributes

std::shared_ptr< HistogramDefm_histDef
 
std::shared_ptr< IHistogramProviderm_histogramProvider
 
std::mutex m_lock
 

Detailed Description

template<typename H>
class Monitored::HistogramFiller2DGeneric< H >

Generic filler for 2D histogram.

Template Parameters
HType of 2D histogram (TH2, TProfile)

Definition at line 23 of file HistogramFiller2D.h.

Constructor & Destructor Documentation

◆ HistogramFiller2DGeneric()

template<typename H >
Monitored::HistogramFiller2DGeneric< H >::HistogramFiller2DGeneric ( const HistogramDef definition,
std::shared_ptr< IHistogramProvider provider 
)
inline

Definition at line 25 of file HistogramFiller2D.h.

26  : HistogramFiller(definition, provider) {}

Member Function Documentation

◆ fill() [1/2]

template<typename H >
virtual unsigned Monitored::HistogramFiller2DGeneric< H >::fill ( const HistogramFiller::VariablesPack ) const
inlineoverridevirtual

Method that actually fills the ROOT object.

Returns
number of fills performed

Implements Monitored::HistogramFiller.

Definition at line 28 of file HistogramFiller2D.h.

28  {
29  if (ATH_UNLIKELY(vars.var[0] == nullptr or vars.var[1] == nullptr )) return 0;
30 
31  const size_t size0 = vars.var[0]->size();
32  const size_t size1 = vars.var[1]->size();
33 
34  if (ATH_UNLIKELY(size0 == 0 || size1 == 0)) {
35  // nothing to do
36  return 0;
37  }
38 
39  if (ATH_UNLIKELY(size0 > 1 && size1 > 1 && size0 != size1)) {
40  MsgStream log(Athena::getMessageSvc(), "HistogramFiller2D");
41  log << MSG::ERROR << "Mismatch of provided vector sizes "
42  << size0 << "," << size1 << " for " << m_histDef->alias << endmsg;
43  return 0;
44  }
45 
46  std::function<bool(size_t)> cutMaskAccessor;
47  if (vars.cut) {
48  // handling of the cutmask
49  auto cutMaskValuePair = getCutMaskFunc(vars.cut);
50  if (cutMaskValuePair.first == 0) { return 0; }
51  if (ATH_UNLIKELY(size0 > 1 && size1 > 1 &&
52  cutMaskValuePair.first > 1 && size0 != cutMaskValuePair.first)) {
53  MsgStream log(Athena::getMessageSvc(), "HistogramFiller2D");
54  log << MSG::ERROR << "CutMask does not match the size of plotted variable: "
55  << cutMaskValuePair.first << " " << size0 << endmsg;
56  return 0;
57  }
58  cutMaskAccessor = cutMaskValuePair.second;
59  }
60 
61  if (vars.weight) {
62  auto weightAccessor = [&](size_t i){ return vars.weight->get(i); };
63  if (ATH_UNLIKELY(size0 > 1 && size1 > 1 &&
64  vars.weight->size() > 1 && size0 != vars.weight->size())) {
65  MsgStream log(Athena::getMessageSvc(), "HistogramFiller2D");
66  log << MSG::ERROR << "Weight does not match the size of plotted variable: "
67  << vars.weight->size() << " " << size0 << endmsg;
68  return 0;
69  }
70  // Need to fill here while weightVector is still in scope
71  if (not vars.cut) return HistogramFiller::fill<H>(weightAccessor, detail::noCut, *vars.var[0], *vars.var[1]);
72  else return HistogramFiller::fill<H>(weightAccessor, cutMaskAccessor, *vars.var[0], *vars.var[1]);
73  }
74 
75  if (not vars.cut) return HistogramFiller::fill<H>(detail::noWeight, detail::noCut, *vars.var[0], *vars.var[1]);
76  else return HistogramFiller::fill<H>(detail::noWeight, cutMaskAccessor, *vars.var[0], *vars.var[1]);
77  }

◆ fill() [2/2]

template<class H , typename W , typename C , typename ... Ms>
unsigned Monitored::HistogramFiller::fill ( weight,
cut,
const Ms &...  m 
) const
inlineprotectedinherited

Fill histogram from IMonitoredVariable.

Supports arbitrary dimensions and double/string representation.

Template Parameters
Hhistogram type (TH1, TH2, ...)
Parameters
weightweight accessor (use detail::noWeight if not needed)
cutcut mask accessor (use detail::noCut if not needed)
m...IMonitoredVariable list to fill from

Definition at line 184 of file HistogramFiller.h.

184  {
185  auto hist = this->histogram<H>();
186 
187  size_t i = 0;
188  for (; i < std::max({m.size()...}); ++i ) {
189  if ( cut(i) ) {
190  detail::doFill(hist, weight, i, m...);
191  }
192  }
193  return i;
194  }

◆ getCutMaskFunc()

std::pair<size_t, std::function<bool(size_t)> > Monitored::HistogramFiller::getCutMaskFunc ( const Monitored::IMonitoredVariable mask) const
inlineprotectedinherited

Definition at line 155 of file HistogramFiller.h.

155  {
156  std::function<bool(size_t)> cutMaskValue = [] (size_t){ return true; }; // default is true
157  size_t maskSize = 1;
158  if ( mask != nullptr ) {
159  maskSize = mask->size();
160  if (maskSize == 1) {
161  if (!mask->get(0)) {
162  // globally fails cut; zero first argument is a signal that one can abort
163  return std::make_pair(0, [](size_t){ return false; });
164  // otherwise, default cutMaskValue is sufficient
165  }
166  } else {
167  return std::make_pair(maskSize, [mask](size_t i){ return static_cast<bool>(mask->get(i)); });
168  }
169  }
170  return std::make_pair(maskSize, cutMaskValue);
171  }

◆ getLock()

const std::unique_lock<std::mutex> Monitored::HistogramFiller::getLock ( ) const
inlineinherited

Definition at line 144 of file HistogramFiller.h.

144  {
145  return std::unique_lock(m_lock);
146  }

◆ histogram()

template<class H >
H* Monitored::HistogramFiller::histogram ( ) const
inlineprotectedinherited

Definition at line 150 of file HistogramFiller.h.

150  {
151  return static_cast<H*>(m_histogramProvider->histogram());
152  }

◆ histogramCutMaskName()

const std::string& Monitored::HistogramFiller::histogramCutMaskName ( ) const
inlineinherited

Definition at line 140 of file HistogramFiller.h.

140  {
141  return m_histDef->cutMask;
142  }

◆ histogramVariablesNames()

const std::vector<std::string>& Monitored::HistogramFiller::histogramVariablesNames ( ) const
inlineinherited

Definition at line 132 of file HistogramFiller.h.

132  {
133  return m_histDef->name;
134  }

◆ histogramWeightName()

const std::string& Monitored::HistogramFiller::histogramWeightName ( ) const
inlineinherited

Definition at line 136 of file HistogramFiller.h.

136  {
137  return m_histDef->weight;
138  }

◆ touch()

void Monitored::HistogramFiller::touch ( ) const
inlineinherited

Ensure histogram exists.

Definition at line 127 of file HistogramFiller.h.

127  {
128  histogram<void>();
129  }

Member Data Documentation

◆ m_histDef

std::shared_ptr<HistogramDef> Monitored::HistogramFiller::m_histDef
protectedinherited

Definition at line 196 of file HistogramFiller.h.

◆ m_histogramProvider

std::shared_ptr<IHistogramProvider> Monitored::HistogramFiller::m_histogramProvider
protectedinherited

Definition at line 197 of file HistogramFiller.h.

◆ m_lock

std::mutex Monitored::HistogramFiller::m_lock
mutableprotectedinherited

Definition at line 198 of file HistogramFiller.h.


The documentation for this class was generated from the following file:
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
max
#define max(a, b)
Definition: cfImp.cxx:41
Monitored::HistogramFiller::m_histDef
std::shared_ptr< HistogramDef > m_histDef
Definition: HistogramFiller.h:196
Monitored::HistogramFiller::m_histogramProvider
std::shared_ptr< IHistogramProvider > m_histogramProvider
Definition: HistogramFiller.h:197
plotmaker.hist
hist
Definition: plotmaker.py:148
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
Monitored::detail::noCut
auto noCut
no cut for filling
Definition: HistogramFillerUtils.h:29
Monitored::detail::doFill
void doFill(H *hist, W weight, size_t i, const M &m1, const Ms &... m)
Perform (arbitrary dimension) histogram fill with weight.
Definition: HistogramFillerUtils.h:164
H
#define H(x, y, z)
Definition: MD5.cxx:114
ROBbits::maskSize
const uint32_t maskSize
Definition: TrigMonROBData.cxx:17
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
Monitored::HistogramFiller::m_lock
std::mutex m_lock
Definition: HistogramFiller.h:198
Monitored::detail::noWeight
auto noWeight
no weight for filling
Definition: HistogramFillerUtils.h:28
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Monitored::HistogramFiller::getCutMaskFunc
std::pair< size_t, std::function< bool(size_t)> > getCutMaskFunc(const Monitored::IMonitoredVariable *mask) const
Definition: HistogramFiller.h:155
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
Monitored::HistogramFiller::HistogramFiller
HistogramFiller(const HistogramDef &histDef, std::shared_ptr< IHistogramProvider > histogramProvider)
Default constructor.
Definition: HistogramFiller.h:50