ATLAS Offline Software
Loading...
Searching...
No Matches
Monitored::LiveHistogramProvider Class Reference

Provides latest-N-lumiblock histograms to be filled. More...

#include <LiveHistogramProvider.h>

Inheritance diagram for Monitored::LiveHistogramProvider:
Collaboration diagram for Monitored::LiveHistogramProvider:

Public Member Functions

 LiveHistogramProvider (GenericMonitoringTool *const gmTool, std::shared_ptr< HistogramFactory > factory, const HistogramDef &histDef)
 Constructor.
TNamed * histogram () override
 Getter of ROOT histogram.
void updateHistDef ()
 Updates HistogramDef xmin, xmax and xbins members.
void copyDataToNewHistogram (TH1 *hOld, TH1 *hNew)
 Copies bin contents from an old to a new histogram.
void copyDataToNewHistogram (TProfile *hOld, TProfile *hNew)

Private Attributes

GenericMonitoringTool *const m_gmTool
std::shared_ptr< HistogramFactorym_factory
std::shared_ptr< HistogramDefm_histDef
TNamed * m_currentHistogram = nullptr
int m_currentLumiBlock = 0

Detailed Description

Provides latest-N-lumiblock histograms to be filled.

Provides histograms which shows only information from the last N lumiblocks. The highest encountered lumiblock is calculated, and only data from Max-N to N is shown. Note: kLBNLive must be defined in histogram definition options.

Definition at line 24 of file LiveHistogramProvider.h.

Constructor & Destructor Documentation

◆ LiveHistogramProvider()

Monitored::LiveHistogramProvider::LiveHistogramProvider ( GenericMonitoringTool *const gmTool,
std::shared_ptr< HistogramFactory > factory,
const HistogramDef & histDef )
inline

Constructor.

Parameters
gmToolSource of the lumi block info.
factoryROOT object factory.
defDefinition of the histogram.

Definition at line 34 of file LiveHistogramProvider.h.

38 : IHistogramProvider()
39 , m_gmTool(gmTool)
40 , m_factory(std::move(factory))
41 , m_histDef(new HistogramDef(histDef))
42 {}
std::shared_ptr< HistogramDef > m_histDef
GenericMonitoringTool *const m_gmTool
std::shared_ptr< HistogramFactory > m_factory

Member Function Documentation

◆ copyDataToNewHistogram() [1/2]

void Monitored::LiveHistogramProvider::copyDataToNewHistogram ( TH1 * hOld,
TH1 * hNew )
inline

Copies bin contents from an old to a new histogram.

Definition at line 127 of file LiveHistogramProvider.h.

127 {
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 }

◆ copyDataToNewHistogram() [2/2]

void Monitored::LiveHistogramProvider::copyDataToNewHistogram ( TProfile * hOld,
TProfile * hNew )
inline

Definition at line 155 of file LiveHistogramProvider.h.

155 {
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 }

◆ histogram()

TNamed * Monitored::LiveHistogramProvider::histogram ( )
inlineoverridevirtual

Getter of ROOT histogram.

Each time the method is called, factory produces ROOT object based on the current lumi block. Note: ROOT objects are cached at the factory. Nevertheless, it is recommended to call this method as rarely as possible.

Returns
ROOT object

Implements Monitored::IHistogramProvider.

Definition at line 53 of file LiveHistogramProvider.h.

53 {
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.
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);
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.
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.
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 }
void copyDataToNewHistogram(TH1 *hOld, TH1 *hNew)
Copies bin contents from an old to a new histogram.
void updateHistDef()
Updates HistogramDef xmin, xmax and xbins members.
setTeId lumiBlock

◆ updateHistDef()

void Monitored::LiveHistogramProvider::updateHistDef ( )
inline

Updates HistogramDef xmin, xmax and xbins members.

Definition at line 118 of file LiveHistogramProvider.h.

118 {
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 }

Member Data Documentation

◆ m_currentHistogram

TNamed* Monitored::LiveHistogramProvider::m_currentHistogram = nullptr
private

Definition at line 189 of file LiveHistogramProvider.h.

◆ m_currentLumiBlock

int Monitored::LiveHistogramProvider::m_currentLumiBlock = 0
private

Definition at line 190 of file LiveHistogramProvider.h.

◆ m_factory

std::shared_ptr<HistogramFactory> Monitored::LiveHistogramProvider::m_factory
private

Definition at line 187 of file LiveHistogramProvider.h.

◆ m_gmTool

GenericMonitoringTool* const Monitored::LiveHistogramProvider::m_gmTool
private

Definition at line 186 of file LiveHistogramProvider.h.

◆ m_histDef

std::shared_ptr<HistogramDef> Monitored::LiveHistogramProvider::m_histDef
private

Definition at line 188 of file LiveHistogramProvider.h.


The documentation for this class was generated from the following file: