28 const std::string& title,
36 std::unique_ptr<TH1F> hist;
39 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have max <= min or bins == 0");
43 hist = std::make_unique<TH1F>(hisSvcName.c_str(), title.c_str(),
bins,
min,
max);
44 }
else if (xaxis ==
kLog) {
46 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have min <= 0 with log binning");
48 std::unique_ptr<double[]> xbins = std::make_unique<double[]>(
bins+1);
49 const double xlogmin = log10(
min);
50 const double xlogmax = log10(
max);
51 const double dlogx = (xlogmax-xlogmin)/((
double)
bins);
52 for (
size_t i = 0; i <=
bins; ++i) {
53 const double xlog = xlogmin + i*dlogx;
54 xbins[i] = exp( log(10) * xlog );
56 hist = std::make_unique<TH1F>(hisSvcName.c_str(), title.c_str(),
bins, xbins.get());
58 throw std::runtime_error(
"CounterBase::regHistogram: Unknown logarithm flag");
62 std::forward_as_tuple(name),
69 const std::string& title,
77 std::unique_ptr<TProfile> hist;
80 throw std::runtime_error(
"CounterBase::regTProfile: Cannot have max <= min or bins == 0");
84 hist = std::make_unique<TProfile>(hisSvcName.c_str(), title.c_str(),
bins,
min,
max);
85 }
else if (xaxis ==
kLog) {
87 throw std::runtime_error(
"CounterBase::regTProfile: Cannot have min <= 0 with log binning");
89 std::unique_ptr<double[]> xbins = std::make_unique<double[]>(
bins+1);
90 const double xlogmin = log10(
min);
91 const double xlogmax = log10(
max);
92 const double dlogx = (xlogmax-xlogmin)/((
double)
bins);
93 for (
size_t i = 0; i <=
bins; ++i) {
94 const double xlog = xlogmin + i*dlogx;
95 xbins[i] = exp( log(10) * xlog );
97 hist = std::make_unique<TProfile>(hisSvcName.c_str(), title.c_str(),
bins, xbins.get());
99 throw std::runtime_error(
"CounterBase::regTProfile: Unknown logarithm flag");
103 std::forward_as_tuple(name),
110 const std::string& title,
122 std::unique_ptr<TH2F> hist;
125 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have max <= min or bins == 0");
129 hist = std::make_unique<TH2F>(hisSvcName.c_str(), title.c_str(), xbins,
xmin,
xmax, ybins,
ymin,
ymax);
130 }
else if (xaxis ==
kLog || yaxis ==
kLog) {
132 throw std::runtime_error(
"CounterBase::regHistogram: Cannot have min <= 0 with log binning");
134 std::unique_ptr<double[]> xlogbins = std::make_unique<double[]>(xbins+1);
135 std::unique_ptr<double[]> ylogbins = std::make_unique<double[]>(ybins+1);
137 const double xlogmin = log10(
xmin);
138 const double xlogmax = log10(
xmax);
139 const double dlogx = (xlogmax-xlogmin)/((
double)xbins);
140 for (
size_t i = 0; i <= xbins; ++i) {
141 const double xlog = xlogmin + i*dlogx;
142 xlogbins[i] = exp( log(10) * xlog );
145 const double dx = (
xmax-
xmin)/((
double)xbins);
146 for (
size_t i = 0; i <= xbins; ++i) {
147 xlogbins[i] =
xmin + i*dx;
152 const double ylogmin = log10(
ymin);
153 const double ylogmax = log10(
ymax);
154 const double dlogy = (ylogmax-ylogmin)/((
double)ybins);
155 for (
size_t i = 0; i <= ybins; ++i) {
156 const double ylog = ylogmin + i*dlogy;
157 ylogbins[i] = exp( log(10) * ylog );
160 const double dy = (
ymax-
ymin)/((
double)ybins);
161 for (
size_t i = 0; i <= ybins; ++i) {
162 ylogbins[i] =
ymin + i*dy;
166 hist = std::make_unique<TH2F>(hisSvcName.c_str(), title.c_str(), xbins, xlogbins.get(), ybins, ylogbins.get());
168 throw std::runtime_error(
"CounterBase::regHistogram: Unknown logarithm flag");
172 std::forward_as_tuple(name),
185 throw std::runtime_error(
"CounterBase::getVariable: No varialbe with name " + name );
194 return StatusCode::FAILURE;
196 ATH_CHECK( it->second.fill(value, weight) );
197 return StatusCode::SUCCESS;
200StatusCode
CounterBase::fill(
const std::string& name,
float xvalue,
float yvalue,
float weight) {
203 return StatusCode::FAILURE;
205 ATH_CHECK( it->second.fill(xvalue, yvalue, weight) );
206 return StatusCode::SUCCESS;
213 return StatusCode::FAILURE;
215 it->second.setDenominator(value);
216 return StatusCode::SUCCESS;
221 return fill(name, 1.0, weight);
227 ATH_CHECK( nameVariablePair.second.endEvent() );
229 return StatusCode::SUCCESS;
245 throw std::runtime_error(
"Asked for a stop time " + std::to_string(stop) +
" which is before the start time " + std::to_string(start));
247 const uint64_t difference = stop - start;
248 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.
StatusCode fill(const std::string &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...
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.
const MonitorBase * getParent() const
Return cached non-owning const ptr to this Counter's parent Monitor.
std::unordered_map< std::string, Variable > m_variables
Store of Counter's Variables.
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.
const std::string m_name
Counter's name.
Variable & getVariable(const std::string &name)
Returns a mutable reference to a named Variable.
StatusCode setDenominator(const std::string &name, float value)
Optional for per-Event Variables.
StatusCode increment(const std::string &name, float weight=1.0)
Convenience function.
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.