ATLAS Offline Software
Loading...
Searching...
No Matches
ManagedMonitorToolTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// **********************************************************************
7
8#include <sstream>
9
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/StatusCode.h"
12
15
16#include "TH1.h"
17#include "TH2.h"
18#include "TGraph.h"
19#include "TTree.h"
20#include "TMath.h"
21
25
26
27// *********************************************************************
28// Public Methods
29// *********************************************************************
30
32ManagedMonitorToolTest( const std::string & type, const std::string & name,
33 const IInterface* parent )
34 : ManagedMonitorToolBase( type, name, parent )
35 , m_generatorIsInit(false)
36 , m_generatorSeedProp(65539)
38 , m_ensembleRMS(0)
47 , m_Lumi(0)
48 , m_graph(0)
50 , m_ntuple(0)
52 , m_counter(0)
53 , m_variable1(0)
54 , m_variable2(0)
55 , m_offset(0)
56 , m_gen(65539)
57 , m_efficiency(0)
61{
62 declareProperty( "GeneratorSeed", m_generatorSeedProp );
63}
64
65
70
71// Description: Used for rebooking unmanaged histograms
72StatusCode
75{
76
78 // book histograms that are only made in the online environment...
79 }
80
82 // book histograms that are only relevant for cosmics data...
83 }
84
85 if( !m_generatorIsInit ) {
86 m_gen.SetSeed( m_generatorSeedProp );
87 m_generatorIsInit = true;
88 }
89
90
91 MonGroup gaussian_ensemble( this, "Stats/Gaussian", lumiBlock, ATTRIB_UNMANAGED );
92 MonGroup gaussian_summary( this, "Stats/Gaussian", lumiBlock, ATTRIB_UNMANAGED );
93
94 if( newLowStatIntervalFlag() ) { }
95
96 if( newLumiBlockFlag() ) {
97 m_ensembles.clear();
98
99 for( int i = 0; i < s_nEnsembles; ++i ) {
100 std::ostringstream hName;
101 std::ostringstream hTitle;
102
103 hName << "gaus_" << i;
104 hTitle << "A Gaussian Distribution (" << i << ", "
105 << s_ensembleGenMean << ", " << s_ensembleGenSigma << ")";
106 TH1* h = new TH1F( hName.str().c_str(), hTitle.str().c_str(),
109 gaussian_ensemble.regHist( h ).ignore();
110 m_ensembles.push_back( h );
111 }
112
113
114 m_ensembleMean = new TH1F( "nthMean", "Means of the Ensembles",
116 gaussian_summary.regHist( m_ensembleMean ).ignore();
117
118
119 m_ensembleRMS = new TH1F( "nthRMS", "RMSs of the Ensembles",
121 gaussian_summary.regHist( m_ensembleRMS ).ignore();
122
123
124 m_ensembleMeanPull = new TH1F( "nthMeanPull", "Pulls of the Means of the Ensembles",
126 gaussian_summary.regHist( m_ensembleMeanPull ).ignore();
127
128
129 m_ensembleMeanPullDist = new TH1F( "meanPull", "Pull Distribution of Means",
130 50, -5.0, 5.0 );
131 gaussian_summary.regHist( m_ensembleMeanPullDist ).ignore();
132
133 }
134
135 if( newRunFlag() ) {
136
137 // Example for TGraph
138 MonGroup space_point( this, "SpacePoint", run, ATTRIB_UNMANAGED );
139 m_graph = new TGraph();
140 m_graph->SetNameTitle("spacepointVsEvent","Space-point vs Event");
141 space_point.regGraph( m_graph ).ignore();
142
143 // Example for ntuple
144 MonGroup group_ntuple( this, "Ntuple", run, ATTRIB_UNMANAGED );
145 m_ntuple = new TTree("ntupleName","ntupleTitle");
146 m_ntuple->Branch("var1",&m_variable1,"var1/I");
147 m_ntuple->Branch("var2",&m_variable2,"var2/I");
148 group_ntuple.regTree( m_ntuple ).ignore();
149
150 // Example for TEfficiency
151 MonGroup efficiency( this, "Efficiency", run, ATTRIB_UNMANAGED );
152 m_efficiency = new TEfficiency("Efficiency","Efficiency (Unmanaged)",10,0,10);
153 efficiency.regEfficiency( m_efficiency ).ignore();
154
155 }
156
157 return StatusCode::SUCCESS;
158}
159
160// Description: Used for re-booking managed histograms
161StatusCode
164{
165
167 // book histograms that are only made in the online environment...
168 }
169
171 // book histograms that are only relevant for cosmics data...
172 }
173
174 if( !m_generatorIsInit ) {
175 m_gen.SetSeed( m_generatorSeedProp );
176 m_generatorIsInit = true;
177 }
178
179 // Example for histograms
180 // Create managed histograms ()
181 m_managedHist0_lowStat = new TH1F( "managedHist0_lowStat", "Managed Histogram, regHist Example 0; interval: lowStat", 5, 0.0, 5.0 );
182 m_managedHist1_lowStat = new TH1F ( "managedHist1_lowStat", "Managed Histogram, regHist Example 1; interval: lowStat", 5, 0.0, 5.0 );
183 m_managedHist2_lowStat = new TH1F ( "managedHist2_lowStat", "Managed Histogram, regHist Example 2; interval: lowStat", 5, 0.0, 5.0 );
184
185 m_managedHist_lumiBlock = new TH1F( "managedHist_lumiBlock", "Managed Histogram; interval: lumiBlock", 5, 0.0, 5.0 );
186 m_managedHist_eventsBlock = new TH1F( "managedHist_eventsBlock", "Managed Histogram; interval: eventBlock", 5, 0.0, 5.0 );
187 m_managedHist_run = new TH1F( "managedHist0_run", "Managed Histogram; interval: run", 5, 0.0, 5.0 );
188
189 // Create luminosity histogram
190 m_Lumi = new TH1F( "Avg_mu", "Average number of interactions", 100, 0, 100 );
191
192 // Create MonGroup object for managing managed histograns from same group
193 MonGroup managed_booking_lowStat( this, "Managed/Histograms", lowStat ); // to be re-booked every lowStat interval
194
195 // Case 1. Use the tool regHist method and pass MonGroup instance.
196 regHist( m_managedHist0_lowStat, managed_booking_lowStat ).ignore();
197
198 // Case 2. Use the tool regHist method and pass parameters manually.
199 regHist( m_managedHist1_lowStat, "Managed/Histograms", lowStat ).ignore();
200
201 // Case 3. Use regHist method of the MonGroup instance.
202 managed_booking_lowStat.regHist(m_managedHist2_lowStat).ignore();
203
204
205 // Some more histogram examples
206 MonGroup managed_booking_lumiBlock( this, "Managed/Histograms", lumiBlock); // to re-booked every luminosity block
207 regHist( m_managedHist_lumiBlock, managed_booking_lumiBlock ).ignore();
208
209 MonGroup managed_eventsBlock(this, "Managed/Histograms", eventsBlock); // to re-booked every eventsBlock
210 regHist( m_managedHist_eventsBlock, managed_eventsBlock ).ignore();
211
212 // Register luminosity histogram
213 regHist( m_Lumi, managed_eventsBlock).ignore();
214
215 MonGroup managed_booking_run( this, "Managed/Histograms", run); // to be re-booked every run
216 regHist( m_managedHist_run, managed_booking_run ).ignore();
217
218 // Example for the managed TGraph
219 MonGroup managed_space_point( this, "Managed/SpacePoint", lumiBlock );
220 m_managedGraph = new TGraph();
221 m_managedGraph->SetNameTitle("spacepointVsEvent_managed","Space-point vs Event (Managed)");
222 managed_space_point.regGraph( m_managedGraph ).ignore();
223
224 // Example for the managed ntuple
225 MonGroup managed_group_ntuple( this, "Managed/managed_Ntuple", lumiBlock );
226 m_managedNtuple = new TTree("managedNtupleName","managedNtupleTitle");
227 m_managedNtuple->Branch("var1",&m_variable1,"var1/I");
228 m_managedNtuple->Branch("var2",&m_variable2,"var2/I");
229 managed_group_ntuple.regTree( m_managedNtuple ).ignore();
230
231 // Example for the managed TEffficiency
232 MonGroup managed_efficiency( this, "Managed/Efficiency", lumiBlock );
233 m_managedEfficiency = new TEfficiency("ManagedEfficiency","Efficiency (Managed)",10,0,10);
234 managed_efficiency.regEfficiency( m_managedEfficiency ).ignore();
235
236 // Example for the managed TEfficiency across lumiblocks
237 MonGroup managed_efficiency_xlb( this, "Managed/EfficiencyXLB", run, ATTRIB_X_VS_LB, "", "merge");
238 m_managedEfficiencyXLB = new TEfficiency("ManagedEfficiencyXLB","EfficiencyXLB (Managed)",1200,0,1200);
239 managed_efficiency_xlb.regEfficiency( m_managedEfficiencyXLB ).ignore();
240
241 // Example for the managed TGraph across lumiblocks
242 MonGroup managed_graph_xlb( this, "Managed/GraphXLB", run, ATTRIB_X_VS_LB, "", "merge");
243 m_managedGraphXLB = new TGraph();
244 m_managedGraphXLB->SetNameTitle("ManagedGraphXLB","GraphXLB (Managed)");
245 managed_graph_xlb.regGraph( m_managedGraphXLB ).ignore();
246
247 return StatusCode::SUCCESS;
248}
249
250
251StatusCode
254{
255 // Fill average mu per bunch crossing
256 double lumiPerBCID = lbAverageInteractionsPerCrossing();
257 if (lumiPerBCID < 0) {
258 // no luminosity information or EnableLumi is set to False in the config
259 ATH_MSG_INFO("No luminosity information available or EnableLumi = False");
260 } else {
261 m_Lumi->Fill(lumiPerBCID);
262 }
263
264
265 std::vector<TH1*>::const_iterator ensembleEnd = m_ensembles.end();
266 for( std::vector<TH1*>::const_iterator i = m_ensembles.begin(); i != ensembleEnd; ++i ) {
267 TH1* h = *i;
269 }
270
271 // TGraph
272 m_counter++;
273 m_event.push_back(m_counter);
274 m_spacepoint.push_back(m_counter%10);
275
276 // TGraph (managed-rebooking)
277 // Use GetN() method. Otherwise need to handle manually in procHistograms
279
280 // Ntuple
283 m_ntuple->Fill();
284
285 // Ntuple (managed-rebooking)
286 m_managedNtuple->SetBranchAddress("var1",&m_variable1);
287 m_managedNtuple->SetBranchAddress("var2",&m_variable2);
288 m_managedNtuple->Fill();
289
290 // Fill managed-rebooking histograms
291 m_managedHist0_lowStat->Fill(0);
292 m_managedHist1_lowStat->Fill(1);
293 m_managedHist2_lowStat->Fill(2);
294
295 // newEventsBlock is a static variable.
296 // It is true when eventsBlock changed.
297 if (newEventsBlockFlag())
298 m_offset += 1;
299
300 // Fill out different histograms bins
302
304 m_managedHist_run->Fill(0);
305
306 double a = m_gen.Uniform(10);
307 bool b = m_gen.Rndm() < TMath::Gaus(a,5,4);
308 m_efficiency->Fill(b,a);
309 m_managedEfficiency->Fill(b,a);
310
312 m_managedEfficiencyXLB->Fill(b,lb);
313
314 m_managedGraphXLB->SetPoint(m_managedGraphXLB->GetN(), lb, lb);
315
316 return StatusCode::SUCCESS;
317}
318
319
320StatusCode
323{
324
326 for( int i = 0; i < s_nEnsembles; ++i ) {
327 TH1* h = m_ensembles[i];
328
329 double mean = h->GetMean();
330 double mean_err = h->GetMeanError();
331 double rms = h->GetRMS();
332 double rms_err = h->GetRMSError();
333
334 m_ensembleMean->SetBinContent( i+1, mean );
335 m_ensembleMean->SetBinError( i+1, mean_err );
336
337 m_ensembleRMS->SetBinContent( i+1, rms );
338 m_ensembleRMS->SetBinError( i+1, rms_err );
339
340 double meanPull = mean_err > 0 ? (mean-s_ensembleGenMean)/mean_err : 0;
341 m_ensembleMeanPull->SetBinContent( i+1, meanPull );
342 m_ensembleMeanPull->SetBinError( i+1, 1.0 );
343
344 m_ensembleMeanPullDist->Fill( meanPull );
345 }
346 }
347
348
349 if( endOfRunFlag() ) {
350 // fill vectors to TGraph
351 for(unsigned int i=0; i<m_event.size(); i++)
352 m_graph->SetPoint(i, m_event[i], m_spacepoint[i]);
353 }
354
355 return StatusCode::SUCCESS;
356}
357
#define ATH_MSG_INFO(x)
static Double_t a
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Header file for AthHistogramAlgorithm.
static unsigned int lumiBlockNumber()
A container of information describing a monitoring object.
StatusCode regHist(TH1 *h)
Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream using logical ...
StatusCode regEfficiency(TEfficiency *e)
Registers a TEfficiency to be included in the output stream.
StatusCode regGraph(TGraph *g)
Registers a TGraph to be included in the output stream using logical parameters that describe the his...
StatusCode regTree(TTree *t)
Registers a TTree to be included in the output stream using logical parameters that describe the hist...
virtual StatusCode regHist(TH1 *h, const std::string &system, Interval_t interval, MgmtAttr_t histo_mgmt=ATTRIB_MANAGED, const std::string &chain="", const std::string &merge="")
Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream using logical ...
bool newLowStatIntervalFlag() const
Flag functions allowing clients to determine when to book new and process old histograms; values are ...
ManagedMonitorToolBase(const std::string &type, const std::string &name, const IInterface *parent)
AthenaMonManager::Environment_t m_environment
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx=Gaudi::Hive::currentContext()) const
Average mu, i.e.
AthenaMonManager::DataType_t m_dataType
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
virtual StatusCode bookHistogramsRecurrent()
An inheriting class should either override this function, bookHists() or bookHistograms().
std::vector< TH1 * > m_ensembles
static const double s_ensembleGenSigma
static const double s_ensembleGenMean
std::vector< int > m_spacepoint
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
ManagedMonitorToolTest(const std::string &type, const std::string &name, const IInterface *parent)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
int lb
Definition globals.cxx:23
Definition run.py:1