ATLAS Offline Software
HistogramFillerRebinable.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_HistogramFillerRebinable1D_h
6 #define AthenaMonitoringKernel_HistogramFiller_HistogramFillerRebinable1D_h
7 
9 #include "HistogramFiller1D.h"
10 #include "HistogramFiller2D.h"
11 #include "HistogramFillerUtils.h"
12 
13 #include <cmath>
14 
15 namespace Monitored {
16 
23  template<typename BASE, Monitored::Axis AXIS>
24  class HistogramFillerRebinableAxis : public BASE {
25  public:
26 
27  HistogramFillerRebinableAxis(const HistogramDef& definition, std::shared_ptr<IHistogramProvider> provider)
28  : BASE(definition, std::move(provider)) {
29  if (definition.kAddBinsDynamically) {
31  } else {
33  }
34  }
35 
36  virtual unsigned fill( const HistogramFiller::VariablesPack& vars ) const override {
37  if (AXIS >= vars.size() ) { return 0; }
38  if (vars[AXIS]->size()==0) { return 0; }
39 
40  // check if any of the cutmasks are non-zero before attempting any rebinning
41  if (vars.cut) {
42  bool anyTrue = false;
43  for(size_t i=0; i<vars.cut->size(); i++) {
44  anyTrue |= static_cast<bool>(vars.cut->get(i));
45  }
46  if(!anyTrue) { return 0; }
47  }
48 
51  const IMonitoredVariable& var = *vars[AXIS];
52  for (size_t i = 0; i < var.size(); i++) {
53  const double v = var.get(i);
54  if (v < min) min = v;
55  if (v > max) max = v;
56  }
57 
58  TH1* hist = this->template histogram<TH1>();
59  TAxis* axis = detail::getAxis<AXIS>(hist);
62  Monitored::detail::rebinHistogram<AXIS>(hist, max);
63  }
64  } else {
65  hist->SetCanExtend(detail::axis_bit[AXIS]);
66  // ExtendAxis is an extremely expensive operation; only call if necessary
67  // Rebinning requires a lock on the global ROOT directory state
68  std::scoped_lock<std::mutex> dirLock(HistogramFactory::globalROOTMutex());
69  if (max >= axis->GetXmax()) hist->ExtendAxis(max, axis);
70  if (min < axis->GetXmin()) hist->ExtendAxis(min, axis);
71  }
72  return BASE::fill( vars );
73  }
74 
75  private:
76  enum class RebinMode { AddBins, ExtendAxes };
78  };
79 
88 }
89 
90 #endif /* AthenaMonitoringKernel_HistogramFiller_HistogramFillerRebinable1D_h */
OHLockedHist.h
OH histogram lock header file.
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
HistogramFiller2D.h
Monitored::HistogramDef::kAddBinsDynamically
bool kAddBinsDynamically
add new bins outside the existing range
Definition: HistogramDef.h:45
Monitored::IMonitoredVariable::size
virtual size_t size() const =0
gives size of vector representation
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
plotmaker.hist
hist
Definition: plotmaker.py:148
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
Monitored::HistogramFillerRebinableAxis::RebinMode::AddBins
@ AddBins
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
Monitored::HistogramFiller::VariablesPack::cut
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
Definition: HistogramFiller.h:113
Monitored::HistogramFillerRebinableAxis::fill
virtual unsigned fill(const HistogramFiller::VariablesPack &vars) const override
Definition: HistogramFillerRebinable.h:36
Monitored::HistogramFillerRebinableAxis::RebinMode::ExtendAxes
@ ExtendAxes
Monitored::HistogramFillerRebinableAxis::RebinMode
RebinMode
Definition: HistogramFillerRebinable.h:76
Monitored::HistogramDef
the internal class used to keep parsed Filler properties
Definition: HistogramDef.h:15
Monitored::HistogramFillerRebinableAxis
Mixin class for rebinning of histogram axis.
Definition: HistogramFillerRebinable.h:24
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Monitored::HistogramFiller::VariablesPack
helper class to pass variables to fillers
Definition: HistogramFiller.h:72
Monitored::IMonitoredVariable
Definition: IMonitoredVariable.h:14
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:28
Monitored::HistogramFiller::VariablesPack::size
size_t size() const
number of variables in the pack ( not counting the weight and mask )
Definition: HistogramFiller.h:87
Monitored::HistogramFillerRebinable2DX
HistogramFillerRebinableAxis< HistogramFiller2D, Axis::X > HistogramFillerRebinable2DX
Rebinable 2D histogram (x-axis only)
Definition: HistogramFillerRebinable.h:83
Monitored::HistogramFillerRebinable2DY
HistogramFillerRebinableAxis< HistogramFiller2D, Axis::Y > HistogramFillerRebinable2DY
Rebinable 2D histogram (y-axis only)
Definition: HistogramFillerRebinable.h:85
HistogramFiller1D.h
Monitored::HistogramFactory::globalROOTMutex
static std::mutex & globalROOTMutex()
Definition: HistogramFactory.h:68
python.PyAthena.v
v
Definition: PyAthena.py:154
Monitored::HistogramFillerRebinableAxis::m_rebinMode
RebinMode m_rebinMode
Definition: HistogramFillerRebinable.h:77
lumiFormat.fill
fill
Definition: lumiFormat.py:104
Monitored::detail::axis_bit
constexpr std::array axis_bit
Definition: HistogramFillerUtils.h:33
Monitored::HistogramFillerRebinable2D
HistogramFillerRebinableAxis< HistogramFillerRebinable2DX, Axis::Y > HistogramFillerRebinable2D
Rebinable 2D histogram (both axes)
Definition: HistogramFillerRebinable.h:87
Monitored::HistogramFillerRebinableAxis::HistogramFillerRebinableAxis
HistogramFillerRebinableAxis(const HistogramDef &definition, std::shared_ptr< IHistogramProvider > provider)
Definition: HistogramFillerRebinable.h:27
Monitored::detail::shouldRebinHistogram
bool shouldRebinHistogram(const TAxis *axis, const double value)
Method checks if histogram should be rebinned.
Definition: HistogramFillerUtils.h:70
HistogramFillerUtils.h
Monitored::HistogramFillerRebinable1D
HistogramFillerRebinableAxis< HistogramFiller1D, Axis::X > HistogramFillerRebinable1D
Rebinable 1D histogram.
Definition: HistogramFillerRebinable.h:81