ATLAS Offline Software
HistogramFiller1D.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_HistogramFiller1D_h
6 #define AthenaMonitoringKernel_HistogramFiller_HistogramFiller1D_h
7 
8 #include "TH1.h"
9 
11 #include "HistogramFillerUtils.h"
12 
15 #include "GaudiKernel/MsgStream.h"
16 
17 namespace Monitored {
18 
23  public:
24  HistogramFiller1D(const HistogramDef& definition, std::shared_ptr<IHistogramProvider> provider)
25  : HistogramFiller(definition, provider) {
26  }
27 
28  virtual unsigned fill( const HistogramFiller::VariablesPack& vars ) const override {
29  std::function<bool(size_t)> cutMaskAccessor;
30  if ( vars.cut ) {
31  // handling of the cutmask
32  auto cutMaskValuePair = getCutMaskFunc(vars.cut);
33  if (cutMaskValuePair.first == 0) { return 0; }
34  if (ATH_UNLIKELY(cutMaskValuePair.first > 1 && cutMaskValuePair.first != vars.var[0]->size())) {
35  MsgStream log(Athena::getMessageSvc(), "HistogramFiller1D");
36  log << MSG::ERROR << "CutMask does not match the size of plotted variable: "
37  << cutMaskValuePair.first << " " << vars.var[0]->size() << endmsg;
38  }
39  cutMaskAccessor = cutMaskValuePair.second;
40  }
41 
42  if (vars.weight) {
43  auto weightAccessor = [&](size_t i){ return vars.weight->get(i); };
44 
45  if (ATH_UNLIKELY(vars.weight->size() != vars.var[0]->size())) {
46  MsgStream log(Athena::getMessageSvc(), "HistogramFiller1D");
47  log << MSG::ERROR << "Weight does not match the size of plotted variable: "
48  << vars.weight->size() << " " << vars.var[0]->size() << endmsg;
49  }
50  // Need to fill here while weightVector is still in scope
51  if (not vars.cut) return HistogramFiller::fill<TH1>(weightAccessor, detail::noCut, *vars.var[0]);
52  else return HistogramFiller::fill<TH1>(weightAccessor, cutMaskAccessor, *vars.var[0]);
53  }
54 
55  if (not vars.cut) return HistogramFiller::fill<TH1>(detail::noWeight, detail::noCut, *vars.var[0]);
56  else return HistogramFiller::fill<TH1>(detail::noWeight, cutMaskAccessor, *vars.var[0]);
57  }
58  };
59 }
60 
61 #endif /* AthenaMonitoringKernel_HistogramFiller_HistogramFiller1D_h */
Monitored::IMonitoredVariable::size
virtual size_t size() const =0
gives size of vector representation
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
Monitored::HistogramFiller1D
Filler for plain 1D histograms.
Definition: HistogramFiller1D.h:22
Monitored::HistogramFiller::VariablesPack::cut
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
Definition: HistogramFiller.h:116
Monitored::HistogramFiller1D::fill
virtual unsigned fill(const HistogramFiller::VariablesPack &vars) const override
Method that actually fills the ROOT object.
Definition: HistogramFiller1D.h:28
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
Monitored::HistogramDef
the internal class used to keep parsed Filler properties
Definition: HistogramDef.h:15
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthUnlikelyMacros.h
Monitored::HistogramFiller::VariablesPack::weight
const Monitored::IMonitoredVariable * weight
pointer to weight variable, typically absent
Definition: HistogramFiller.h:115
Monitored::HistogramFiller::VariablesPack
helper class to pass variables to fillers
Definition: HistogramFiller.h:72
Monitored::detail::noCut
auto noCut
no cut for filling
Definition: HistogramFillerUtils.h:29
Monitored::IMonitoredVariable::get
virtual double get(size_t) const =0
lumiFormat.i
int i
Definition: lumiFormat.py:85
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
HistogramFiller.h
Monitored::HistogramFiller
Base class for all histogram fillers.
Definition: HistogramFiller.h:44
Monitored::detail::noWeight
auto noWeight
no weight for filling
Definition: HistogramFillerUtils.h:28
Monitored::HistogramFiller1D::HistogramFiller1D
HistogramFiller1D(const HistogramDef &definition, std::shared_ptr< IHistogramProvider > provider)
Definition: HistogramFiller1D.h:24
Monitored::HistogramFiller::VariablesPack::var
std::vector< const Monitored::IMonitoredVariable * > var
storage for variables, default size of 4, serves all histograming uses
Definition: HistogramFiller.h:114
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:156
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
HistogramFillerUtils.h