ATLAS Offline Software
Loading...
Searching...
No Matches
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"
12
13#include <cmath>
14
15namespace 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) {
30 m_rebinMode = RebinMode::AddBins;
31 } else {
32 m_rebinMode = RebinMode::ExtendAxes;
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
49 double min = std::numeric_limits<double>::max();
50 double max = std::numeric_limits<double>::min();
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);
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 */
OH histogram lock header file.
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
std::string histogram
Definition chains.cxx:52
static std::mutex & globalROOTMutex()
Mixin class for rebinning of histogram axis.
HistogramFillerRebinableAxis(const HistogramDef &definition, std::shared_ptr< IHistogramProvider > provider)
virtual unsigned fill(const HistogramFiller::VariablesPack &vars) const override
virtual double get(size_t) const =0
virtual size_t size() const =0
gives size of vector representation
constexpr auto getAxis(H *hist)
Helper to get corresponding TAxis selected by Monitored::Axis.
constexpr std::array axis_bit
bool shouldRebinHistogram(const TAxis *axis, const double value)
Method checks if histogram should be rebinned.
void rebinHistogram(H *hist, const double value)
Method that rebins a histogram.
Generic monitoring tool for athena components.
HistogramFillerRebinableAxis< HistogramFillerRebinable2DX, Axis::Y > HistogramFillerRebinable2D
Rebinable 2D histogram (both axes)
HistogramFillerRebinableAxis< HistogramFiller2D, Axis::Y > HistogramFillerRebinable2DY
Rebinable 2D histogram (y-axis only)
HistogramFillerRebinableAxis< HistogramFiller2D, Axis::X > HistogramFillerRebinable2DX
Rebinable 2D histogram (x-axis only)
HistogramFillerRebinableAxis< HistogramFiller1D, Axis::X > HistogramFillerRebinable1D
Rebinable 1D histogram.
STL namespace.
the internal class used to keep parsed Filler properties
bool kAddBinsDynamically
add new bins outside the existing range
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 )