ATLAS Offline Software
HistogramFiller2D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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 
11 #include "HistogramFillerUtils.h"
13 #include "GaudiKernel/MsgStream.h"
14 
15 namespace Monitored {
16 
22  template<typename H>
24  public:
25  HistogramFiller2DGeneric(const HistogramDef& definition, std::shared_ptr<IHistogramProvider> provider)
26  : HistogramFiller(definition, provider) {}
27 
28  virtual unsigned fill( const HistogramFiller::VariablesPack& vars) const override {
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  }
78  };
79 
81 }
82 
83 #endif /* AthenaMonitoringKernel_HistogramFiller_HistogramFiller2D_h */
84 
Monitored::IMonitoredVariable::size
virtual size_t size() const =0
gives size of vector representation
Monitored::HistogramFiller::m_histDef
std::shared_ptr< HistogramDef > m_histDef
Definition: HistogramFiller.h:196
Monitored::HistogramFiller::VariablesPack::cut
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
Definition: HistogramFiller.h:115
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:114
Monitored::HistogramFiller::VariablesPack
helper class to pass variables to fillers
Definition: HistogramFiller.h:71
Monitored::detail::noCut
auto noCut
no cut for filling
Definition: HistogramFillerUtils.h:29
Monitored::HistogramFiller2DGeneric
Generic filler for 2D histogram.
Definition: HistogramFiller2D.h:23
Monitored::IMonitoredVariable::get
virtual double get(size_t) const =0
lumiFormat.i
int i
Definition: lumiFormat.py:92
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Monitored::HistogramFiller2DGeneric::HistogramFiller2DGeneric
HistogramFiller2DGeneric(const HistogramDef &definition, std::shared_ptr< IHistogramProvider > provider)
Definition: HistogramFiller2D.h:25
Monitored::HistogramFiller2DGeneric::fill
virtual unsigned fill(const HistogramFiller::VariablesPack &vars) const override
Method that actually fills the ROOT object.
Definition: HistogramFiller2D.h:28
HistogramFiller.h
Monitored::HistogramFiller
Base class for all histogram fillers.
Definition: HistogramFiller.h:43
Monitored::detail::noWeight
auto noWeight
no weight for filling
Definition: HistogramFillerUtils.h:28
Monitored::HistogramFiller2D
HistogramFiller2DGeneric< TH2 > HistogramFiller2D
Definition: HistogramFiller2D.h:80
Monitored::HistogramFiller::VariablesPack::var
std::vector< const Monitored::IMonitoredVariable * > var
storage for variables, default size of 4, serves all histograming uses
Definition: HistogramFiller.h:113
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
HistogramFillerUtils.h