ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaMonitoringKernel
src
HistogramFiller
LiveHistogramProvider.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_LiveHistogramProvider_h
6
#define AthenaMonitoringKernel_HistogramFiller_LiveHistogramProvider_h
7
8
#include <memory>
9
10
#include "
AthenaMonitoringKernel/GenericMonitoringTool.h
"
11
#include "
AthenaMonitoringKernel/HistogramDef.h
"
12
#include "
AthenaMonitoringKernel/IHistogramProvider.h
"
13
14
#include "
HistogramFactory.h
"
15
16
namespace
Monitored
{
24
class
LiveHistogramProvider
:
public
IHistogramProvider
{
25
public
:
26
34
LiveHistogramProvider
(
35
GenericMonitoringTool
*
const
gmTool,
36
std::shared_ptr<HistogramFactory> factory,
37
const
HistogramDef
& histDef)
38
:
IHistogramProvider
()
39
,
m_gmTool
(gmTool)
40
,
m_factory
(
std
::move(factory))
41
,
m_histDef
(new
HistogramDef
(histDef))
42
{}
43
53
TNamed*
histogram
()
override
{
54
// Get the LB for this event.
55
const
int
lumiBlock =
m_gmTool
->lumiBlock();
56
57
if
(lumiBlock >
m_currentLumiBlock
) {
58
// Update the variable keeping track of the highest LB.
59
m_currentLumiBlock
= std::max((
float
) lumiBlock,
m_histDef
->xmax);
60
61
if
(!
m_currentHistogram
) {
62
// The histogram does not exist yet and must be created.
63
updateHistDef
();
64
m_currentHistogram
=
m_factory
->create(*
m_histDef
);
65
}
else
{
66
// The histogram exists and needs to be rolled
67
if
(
m_histDef
->type==
"TEfficiency"
) {
68
// Roll a TEfficiency (same process as the codeblock immediately above)
69
TH1* totalClone =
static_cast<
TEfficiency*
>
(
m_currentHistogram
)->GetCopyTotalHisto();
70
TH1* passedClone =
static_cast<
TEfficiency*
>
(
m_currentHistogram
)->GetCopyPassedHisto();
71
m_factory
->remove(*
m_histDef
);
72
updateHistDef
();
73
TEfficiency* eNew =
static_cast<
TEfficiency*
>
(
m_factory
->create(*
m_histDef
));
74
TH1* totalNew = eNew->GetCopyTotalHisto();
75
TH1* passedNew = eNew->GetCopyPassedHisto();
76
copyDataToNewHistogram
(totalClone, totalNew);
77
copyDataToNewHistogram
(passedClone, passedNew);
78
eNew->SetTotalHistogram(*totalNew,
""
);
79
eNew->SetPassedHistogram(*passedNew,
""
);
80
m_currentHistogram
= eNew;
81
delete
totalClone;
82
delete
totalNew;
83
delete
passedClone;
84
delete
passedNew;
85
}
else
if
(
m_histDef
->type==
"TProfile"
) {
86
// Store the data and deregister the old histogram.
87
TProfile* hClone =
static_cast<
TProfile*
>
(
m_currentHistogram
->Clone());
88
m_factory
->remove(*
m_histDef
);
89
// Update the bin ranges and register the new histogram.
90
updateHistDef
();
91
TProfile* hNew =
static_cast<
TProfile*
>
(
m_factory
->create(*
m_histDef
));
92
// Fill it with the old histogram's data and update pointer.
93
copyDataToNewHistogram
(hClone, hNew);
94
m_currentHistogram
= hNew;
95
// Free the memory used by the clone
96
delete
hClone;
97
}
else
{
98
// Store the data and deregister the old histogram.
99
TH1* hClone = (TH1*)
m_currentHistogram
->Clone();
100
m_factory
->remove(*
m_histDef
);
101
// Update the bin ranges and register the new histogram.
102
updateHistDef
();
103
TH1* hNew = (TH1*)
m_factory
->create(*
m_histDef
);
104
// Fill it with the old histogram's data and update pointer.
105
copyDataToNewHistogram
(hClone, hNew);
106
m_currentHistogram
= hNew;
107
// Free the memory used by the clone
108
delete
hClone;
109
}
110
}
111
}
112
return
m_currentHistogram
;
113
}
114
118
void
updateHistDef
() {
119
m_histDef
->xmax = std::max(
m_currentLumiBlock
+ 0.5f,
m_histDef
->xmax);
120
m_histDef
->xmin = std::max(
m_currentLumiBlock
+ 0.5f -
m_histDef
->kLive, 0.5f);
121
m_histDef
->xbins =
m_histDef
->xmax -
m_histDef
->xmin;
122
}
123
127
void
copyDataToNewHistogram
(TH1* hOld, TH1* hNew) {
128
int
offset = hNew->GetXaxis()->GetXmax() - hOld->GetXaxis()->GetXmax();
129
int
nNewEntries(0);
130
bool
sumw2Filled = (hOld->GetSumw2N()>0);
131
132
// Loop through the old histogram bins
133
for
(
int
oldBin=0; oldBin < hOld->GetNcells(); oldBin++) {
134
// Convert global bin number into x-y-z bin number
135
int
oldBinX, oldBinY, oldBinZ;
136
hOld->GetBinXYZ(oldBin, oldBinX, oldBinY, oldBinZ);
137
if
((oldBinX-offset < 1) || hOld->IsBinUnderflow(oldBin, 1) || hOld->IsBinOverflow(oldBin, 1)) {
138
// Overflow bins are ignored since their meaning has changed.
139
continue
;
140
}
else
{
141
// Get the global bin coordinate of this (x, y, z) bin coordinates.
142
int
newBin = hNew->GetBin(oldBinX-offset, oldBinY, oldBinZ);
143
if
(hOld->GetBinContent(oldBin)) hNew->SetBinContent(newBin, hOld->GetBinContent(oldBin));
144
if
(sumw2Filled) {
145
hNew->SetBinError(newBin, hOld->GetBinError(oldBin));
146
nNewEntries+=(*hOld->GetSumw2())[oldBin];
// works correctly only for weight=1
147
}
148
}
149
}
150
// Update the total number of entries member.
151
if
(sumw2Filled) hNew->SetEntries(nNewEntries);
152
else
hNew->SetEntries(hOld->GetEntries());
// a choice since there is no way to get it right.
153
}
154
155
void
copyDataToNewHistogram
(TProfile* hOld, TProfile* hNew) {
156
int
offset = hNew->GetXaxis()->GetXmax() - hOld->GetXaxis()->GetXmax();
157
int
nNewEntries(0);
158
bool
sumw2Filled = (hOld->GetSumw2N()>0);
159
160
// Loop through the old histogram bins
161
for
(
int
oldBin=0; oldBin < hOld->GetNcells(); oldBin++) {
162
// Convert global bin number into x-y-z bin number
163
int
oldBinX, oldBinY, oldBinZ;
164
hOld->GetBinXYZ(oldBin, oldBinX, oldBinY, oldBinZ);
165
if
((oldBinX-offset < 1) || hOld->IsBinUnderflow(oldBin, 1) || hOld->IsBinOverflow(oldBin, 1)) {
166
// Overflow bins are ignored since their meaning has changed.
167
continue
;
168
}
else
{
169
// Get the global bin coordinate of this (x, y, z) bin coordinates.
170
int
newBin = hNew->GetBin(oldBinX-offset, oldBinY, oldBinZ);
171
int
oldBinEntries = hOld->GetBinEntries(oldBin);
172
if
(oldBinEntries>0) {
173
nNewEntries += oldBinEntries;
174
hNew->SetBinEntries(newBin, oldBinEntries);
175
(*hNew)[newBin] = (*hOld)[oldBin];
176
(*hNew->GetSumw2())[newBin] = (*hOld->GetSumw2())[oldBin];
177
}
178
}
179
}
180
// Update the total number of entries member.
181
if
(sumw2Filled) hNew->SetEntries(nNewEntries);
182
else
hNew->SetEntries(hOld->GetEntries());
// a choice since there is no way to get it right.
183
}
184
185
private
:
186
GenericMonitoringTool
*
const
m_gmTool
;
187
std::shared_ptr<HistogramFactory>
m_factory
;
188
std::shared_ptr<HistogramDef>
m_histDef
;
189
TNamed *
m_currentHistogram
=
nullptr
;
190
int
m_currentLumiBlock
= 0;
191
};
192
}
193
194
#endif
/* AthenaMonitoringKernel_HistogramFiller_LiveHistogramProvider_h */
GenericMonitoringTool.h
HistogramDef.h
HistogramFactory.h
IHistogramProvider.h
Monitored::IHistogramProvider
Interface of the source of ROOT objects for HistogramFillers.
Definition
IHistogramProvider.h:14
Monitored::LiveHistogramProvider::m_histDef
std::shared_ptr< HistogramDef > m_histDef
Definition
LiveHistogramProvider.h:188
Monitored::LiveHistogramProvider::copyDataToNewHistogram
void copyDataToNewHistogram(TH1 *hOld, TH1 *hNew)
Copies bin contents from an old to a new histogram.
Definition
LiveHistogramProvider.h:127
Monitored::LiveHistogramProvider::m_currentHistogram
TNamed * m_currentHistogram
Definition
LiveHistogramProvider.h:189
Monitored::LiveHistogramProvider::m_gmTool
GenericMonitoringTool *const m_gmTool
Definition
LiveHistogramProvider.h:186
Monitored::LiveHistogramProvider::copyDataToNewHistogram
void copyDataToNewHistogram(TProfile *hOld, TProfile *hNew)
Definition
LiveHistogramProvider.h:155
Monitored::LiveHistogramProvider::updateHistDef
void updateHistDef()
Updates HistogramDef xmin, xmax and xbins members.
Definition
LiveHistogramProvider.h:118
Monitored::LiveHistogramProvider::m_factory
std::shared_ptr< HistogramFactory > m_factory
Definition
LiveHistogramProvider.h:187
Monitored::LiveHistogramProvider::LiveHistogramProvider
LiveHistogramProvider(GenericMonitoringTool *const gmTool, std::shared_ptr< HistogramFactory > factory, const HistogramDef &histDef)
Constructor.
Definition
LiveHistogramProvider.h:34
Monitored::LiveHistogramProvider::histogram
TNamed * histogram() override
Getter of ROOT histogram.
Definition
LiveHistogramProvider.h:53
Monitored::LiveHistogramProvider::m_currentLumiBlock
int m_currentLumiBlock
Definition
LiveHistogramProvider.h:190
GenericMonitoringTool
Definition
GenericMonitoringTool.py:1
Monitored
Generic monitoring tool for athena components.
Definition
GenericMonitoringTool.h:28
std
STL namespace.
Monitored::HistogramDef
the internal class used to keep parsed Filler properties
Definition
HistogramDef.h:15
Generated on
for ATLAS Offline Software by
1.17.0