30 const std::string& title,
38 std::unique_ptr<TH1F> hist;
41 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have max <= min or bins == 0");
45 hist = std::make_unique<TH1F>(hisSvcName.c_str(), title.c_str(),
bins,
min,
max);
46 }
else if (xaxis ==
kLog) {
48 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have min <= 0 with log binning");
50 std::unique_ptr<double[]> xbins = std::make_unique<double[]>(
bins+1);
51 const double xlogmin = log10(
min);
52 const double xlogmax = log10(
max);
53 const double dlogx = (xlogmax-xlogmin)/((
double)
bins);
54 for (
size_t i = 0; i <=
bins; ++i) {
55 const double xlog = xlogmin + i*dlogx;
56 xbins[i] = exp( log(10) * xlog );
58 hist = std::make_unique<TH1F>(hisSvcName.c_str(), title.c_str(),
bins, xbins.get());
60 throw std::runtime_error(
"CounterBase::regHistogram: Unknown logarithm flag");
64 std::forward_as_tuple(name),
71 const std::string& title,
79 std::unique_ptr<TProfile> hist;
82 throw std::runtime_error(
"CounterBase::regTProfile: Cannot have max <= min or bins == 0");
86 hist = std::make_unique<TProfile>(hisSvcName.c_str(), title.c_str(),
bins,
min,
max);
87 }
else if (xaxis ==
kLog) {
89 throw std::runtime_error(
"CounterBase::regTProfile: Cannot have min <= 0 with log binning");
91 std::unique_ptr<double[]> xbins = std::make_unique<double[]>(
bins+1);
92 const double xlogmin = log10(
min);
93 const double xlogmax = log10(
max);
94 const double dlogx = (xlogmax-xlogmin)/((
double)
bins);
95 for (
size_t i = 0; i <=
bins; ++i) {
96 const double xlog = xlogmin + i*dlogx;
97 xbins[i] = exp( log(10) * xlog );
99 hist = std::make_unique<TProfile>(hisSvcName.c_str(), title.c_str(),
bins, xbins.get());
101 throw std::runtime_error(
"CounterBase::regTProfile: Unknown logarithm flag");
105 std::forward_as_tuple(name),
112 const std::string& title,
124 std::unique_ptr<TH2F> hist;
127 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have max <= min or bins == 0");
131 hist = std::make_unique<TH2F>(hisSvcName.c_str(), title.c_str(), xbins,
xmin,
xmax, ybins,
ymin,
ymax);
132 }
else if (xaxis ==
kLog || yaxis ==
kLog) {
134 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have min <= 0 with log binning");
136 std::unique_ptr<double[]> xlogbins = std::make_unique<double[]>(xbins+1);
137 std::unique_ptr<double[]> ylogbins = std::make_unique<double[]>(ybins+1);
139 const double xlogmin = log10(
xmin);
140 const double xlogmax = log10(
xmax);
141 const double dlogx = (xlogmax-xlogmin)/((
double)xbins);
142 for (
size_t i = 0; i <= xbins; ++i) {
143 const double xlog = xlogmin + i*dlogx;
144 xlogbins[i] = exp( log(10) * xlog );
147 const double dx = (
xmax-
xmin)/((
double)xbins);
148 for (
size_t i = 0; i <= xbins; ++i) {
149 xlogbins[i] =
xmin + i*dx;
154 const double ylogmin = log10(
ymin);
155 const double ylogmax = log10(
ymax);
156 const double dlogy = (ylogmax-ylogmin)/((
double)ybins);
157 for (
size_t i = 0; i <= ybins; ++i) {
158 const double ylog = ylogmin + i*dlogy;
159 ylogbins[i] = exp( log(10) * ylog );
162 const double dy = (
ymax-
ymin)/((
double)ybins);
163 for (
size_t i = 0; i <= ybins; ++i) {
164 ylogbins[i] =
ymin + i*dy;
168 hist = std::make_unique<TH2F>(hisSvcName.c_str(), title.c_str(), xbins, xlogbins.get(), ybins, ylogbins.get());
170 throw std::runtime_error(
"CounterBase::regHistogram: Unknown logarithm flag");
174 std::forward_as_tuple(name),
187 throw std::runtime_error( std::format(
"CounterBase::getVariable: No variable with name {}", name) );
196 return StatusCode::FAILURE;
198 ATH_CHECK( it->second.fill(value, weight) );
199 return StatusCode::SUCCESS;
205 return StatusCode::FAILURE;
207 ATH_CHECK( it->second.fill(xvalue, yvalue, weight) );
208 return StatusCode::SUCCESS;
215 return StatusCode::FAILURE;
217 it->second.setDenominator(value);
218 return StatusCode::SUCCESS;
223 return fill(name, 1.0, weight);
229 ATH_CHECK( nameVariablePair.second.endEvent() );
231 return StatusCode::SUCCESS;
247 throw std::runtime_error(
"Asked for a stop time " + std::to_string(stop) +
" which is before the start time " + std::to_string(start));
249 const uint64_t difference = stop - start;
250 return (difference * 1e-3);
#define ATH_CHECK
Evaluate an expression and check for errors.
static const std::vector< std::string > bins
VariableType
Behaviour of Variable.
LogType
Histogram x-axis type flag.
@ kLinear
Linear x-binning.
@ kLog
Logarithmic x-binning.
float timeToMilliSec(const uint64_t start, const uint64_t stop) const
Helper function.
CounterBase()=delete
Forbid default constructor.
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Counter name (to histogram path) and forwards histogram book request to parent Monitor.
StatusCode increment(std::string_view name, float weight=1.0)
Convenience function.
const MonitorBase * getParent() const
Return cached non-owning const ptr to this Counter's parent Monitor.
void regTProfile(const std::string &name, const std::string &title, const VariableType type=VariableType::kPerCall, const LogType xaxis=kLog, const float min=0.1, const float max=1000000., const size_t bins=70)
Book a TProfile for this Counter, to be filled in per-event monitoring.
void regHistogram(const std::string &name, const std::string &title, const VariableType type=VariableType::kPerCall, const LogType xaxis=kLog, const float min=0.1, const float max=1000000., const size_t bins=70)
Book a histogram for this Counter, to be filled in per-event monitoring.
const std::string & getName() const
Getter for Counter's name.
virtual StatusCode endEvent(float weight=1.0)
Called by the framework.
bool variableExists(const std::string &name) const
Check if a variable of a given name exists.
const MonitorBase * m_parent
Counter's parent Monitor.
Variable & getVariable(std::string_view name)
Returns a mutable reference to a named Variable.
StatusCode fill(std::string_view name, float value, float weight=1.0)
Fill (for per-Call) or accumulate in a buffer (for per-Event) a quantity histogrammed by a named Vari...
std::unordered_map< std::string, Variable, CxxUtils::TransparentStringHash, std::equal_to<> > m_variables
Store of Counter's Variables.
const std::string m_name
Counter's name.
StatusCode setDenominator(const std::string &name, float value)
Optional for per-Event Variables.
const MonitoredRange * getParent() const
Return cached non-owning const ptr to this Monitor's parent Range.
const std::string & getName() const
Getter for Monitor's name.
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Monitor name (to histogram path) and forwards histogram book request to parent Range.
const std::string & getName() const
Getter for Range's name.
Wrapper around a histogram which allows for some additional filling patterns and data manipulation.