ATLAS Offline Software
Loading...
Searching...
No Matches
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.
void touch () const
 Ensure histogram exists.
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.
template<class H>
Hhistogram () 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.

Generic filler for 2D histogram.
HistogramFiller(const HistogramDef &histDef, std::shared_ptr< IHistogramProvider > histogramProvider)
Default constructor.

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.

Reimplemented in Monitored::HistogramFillerRebinableAxis< HistogramFiller2D, Axis::X >, Monitored::HistogramFillerRebinableAxis< HistogramFiller2D, Axis::Y >, Monitored::HistogramFillerRebinableAxis< HistogramFillerProfile, Axis::X >, and Monitored::HistogramFillerRebinableAxis< HistogramFillerRebinable2DX, Axis::Y >.

Definition at line 28 of file HistogramFiller2D.h.

28 {
29 if (ATH_UNLIKELY(vars.size()!=2 or vars[0] == nullptr or vars[1] == nullptr )) return 0;
30
31 const size_t size0 = vars[0]->size();
32 const size_t size1 = vars[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 if (vars.cut) {
47 const size_t maskSize = vars.cut->size();
48 // Abort if no cut entries or first (and only) entry is false
49 if (maskSize == 0 || (maskSize == 1 && !vars.cut->get(0))) { return 0; }
50 if (ATH_UNLIKELY(size0 > 1 && size1 > 1 &&
51 maskSize > 1 && size0 != maskSize)) {
52 MsgStream log(Athena::getMessageSvc(), "HistogramFiller2D");
53 log << MSG::ERROR << "CutMask does not match the size of plotted variable: "
54 << maskSize << " " << size0 << endmsg;
55 return 0;
56 }
57 }
58
59 // Accessor for cut mask in case one is defined
60 auto cutMaskAccessor = [&](size_t i) { return static_cast<bool>(vars.cut->get(i)); };
61
62 if (vars.weight) {
63 auto weightAccessor = [&](size_t i){ return vars.weight->get(i); };
64 if (ATH_UNLIKELY(size0 > 1 && size1 > 1 &&
65 vars.weight->size() > 1 && size0 != vars.weight->size())) {
66 MsgStream log(Athena::getMessageSvc(), "HistogramFiller2D");
67 log << MSG::ERROR << "Weight does not match the size of plotted variable: "
68 << vars.weight->size() << " " << size0 << endmsg;
69 return 0;
70 }
71 // Need to fill here while weightVector is still in scope
74 }
75
78 }
#define ATH_UNLIKELY(x)
std::shared_ptr< HistogramDef > m_histDef
virtual unsigned fill(const VariablesPack &) const =0
Method that actually fills the ROOT object.

◆ fill() [2/2]

template<class H, typename W, typename C, typename ... Ms>
unsigned Monitored::HistogramFiller::fill ( W weight,
C 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 168 of file HistogramFiller.h.

168 {
169 auto hist = this->histogram<H>();
170
171 size_t i = 0;
172 for (; i < std::max({m.size()...}); ++i ) {
173 if ( cut(i) ) {
174 detail::doFill(hist, weight, i, m...);
175 }
176 }
177 return i;
178 }
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
void doFill(H *hist, W weight, size_t i, const M &m1, const Ms &... m)
Perform (arbitrary dimension) histogram fill with weight.

◆ getLock()

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

Definition at line 147 of file HistogramFiller.h.

147 {
148 return std::unique_lock(m_lock);
149 }

◆ histogram()

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

Definition at line 153 of file HistogramFiller.h.

153 {
154 return static_cast<H*>(m_histogramProvider->histogram());
155 }
#define H(x, y, z)
Definition MD5.cxx:114
std::shared_ptr< IHistogramProvider > m_histogramProvider

◆ histogramCutMaskName()

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

Definition at line 143 of file HistogramFiller.h.

143 {
144 return m_histDef->cutMask;
145 }

◆ histogramVariablesNames()

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

Definition at line 135 of file HistogramFiller.h.

135 {
136 return m_histDef->name;
137 }

◆ histogramWeightName()

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

Definition at line 139 of file HistogramFiller.h.

139 {
140 return m_histDef->weight;
141 }

◆ touch()

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

Ensure histogram exists.

Definition at line 130 of file HistogramFiller.h.

130 {
132 }

Member Data Documentation

◆ m_histDef

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

Definition at line 180 of file HistogramFiller.h.

◆ m_histogramProvider

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

Definition at line 181 of file HistogramFiller.h.

◆ m_lock

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

Definition at line 182 of file HistogramFiller.h.


The documentation for this class was generated from the following file: