ATLAS Offline Software
Loading...
Searching...
No Matches
HistogramFiller2D.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef AthenaMonitoringKernel_HistogramFiller_HistogramFiller2D_h
6#define AthenaMonitoringKernel_HistogramFiller_HistogramFiller2D_h
7
8#include "TH2.h"
9
10#include "HistogramFiller.h"
13#include "GaudiKernel/MsgStream.h"
14
15namespace Monitored {
16
22 template<typename H>
24 public:
25 HistogramFiller2DGeneric(const HistogramDef& definition, std::shared_ptr<IHistogramProvider> provider)
26 : HistogramFiller(definition, std::move(provider)) {}
27
28 virtual unsigned fill( const HistogramFiller::VariablesPack& vars) const override {
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
72 if (not vars.cut) return HistogramFiller::fill<H>(weightAccessor, detail::noCut, *vars[0], *vars[1]);
73 else return HistogramFiller::fill<H>(weightAccessor, cutMaskAccessor, *vars[0], *vars[1]);
74 }
75
76 if (not vars.cut) return HistogramFiller::fill<H>(detail::noWeight, detail::noCut, *vars[0], *vars[1]);
77 else return HistogramFiller::fill<H>(detail::noWeight, cutMaskAccessor, *vars[0], *vars[1]);
78 }
79 };
80
82}
83
84#endif /* AthenaMonitoringKernel_HistogramFiller_HistogramFiller2D_h */
85
#define endmsg
#define ATH_UNLIKELY(x)
Generic filler for 2D histogram.
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.
HistogramFiller(const HistogramDef &histDef, std::shared_ptr< IHistogramProvider > histogramProvider)
Default constructor.
std::shared_ptr< HistogramDef > m_histDef
virtual unsigned fill(const VariablesPack &) const =0
Method that actually fills the ROOT object.
virtual double get(size_t) const =0
virtual size_t size() const =0
gives size of vector representation
IMessageSvc * getMessageSvc(bool quiet=false)
auto noWeight
no weight for filling
auto noCut
no cut for filling
Generic monitoring tool for athena components.
HistogramFiller2DGeneric< TH2 > HistogramFiller2D
STL namespace.
the internal class used to keep parsed Filler properties
helper class to pass variables to fillers
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
size_t size() const
number of variables in the pack ( not counting the weight and mask )
const Monitored::IMonitoredVariable * weight
pointer to weight variable, typically absent