]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliMonitorTrend.cxx
fWSN->Eval(0.001) to avoid fpe.
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorTrend.cxx
CommitLineData
04fa961a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// This class maintains a plot for the evolution of a value that is used //
21// tomonitor the quality of the recorded data. //
22// The trendgram is created and filled by a sub class of AliMonitor. //
23// It can be compared to a reference trendgram. For the comparison a //
24// maximal deviation (in standard deviations) can be specified. //
25// The bins where the maximal deviation is exceeded are drawn in red. //
26// //
27///////////////////////////////////////////////////////////////////////////////
28
29
30#include "AliMonitorTrend.h"
31#include <TVirtualPad.h>
32#include <TLine.h>
33
34
35ClassImp(AliMonitorTrend)
36
37
38Int_t AliMonitorTrend::fgIncSize = 10;
39
40
41//_____________________________________________________________________________
42AliMonitorTrend::AliMonitorTrend()
43{
44// default contructor
45
46 fMin = fMax = 0;
47 fHistoDraw = NULL;
48 fRefMean = 0;
49 fRefSigma = -1;
50 fHistoCompare = NULL;
51}
52
53//_____________________________________________________________________________
54AliMonitorTrend::AliMonitorTrend(const AliMonitorTrend& trend) :
55 AliMonitorPlot(trend)
56{
57// copy constructor
58
59 fLabel = trend.fLabel;
60 fMin = trend.fMin;
61 fMax = trend.fMax;
62 trend.fData.Copy(fData);
63
64 fHistoDraw = NULL;
65 fRefMean = trend.fRefMean;
66 fRefSigma = trend.fRefSigma;
67 fHistoCompare = NULL;
68}
69
70//_____________________________________________________________________________
71AliMonitorTrend::AliMonitorTrend(const char* name, const char* title,
72 const char* label, Double_t min, Double_t max) :
73 AliMonitorPlot(name, title)
74{
75// create a monitor trend
76
77 fLabel = label;
78 fMin = min;
79 fMax = max;
80
81 fHistoDraw = NULL;
82 fRefMean = fRefSigma = 0;
83 fHistoCompare = NULL;
84}
85
86//_____________________________________________________________________________
87AliMonitorTrend::~AliMonitorTrend()
88{
89// delete all histograms
90
91 if (fHistoDraw) delete fHistoDraw;
92 if (fHistoCompare) delete fHistoCompare;
93}
94
95
96//_____________________________________________________________________________
97void AliMonitorTrend::SetReference(TH1* ref)
98{
99// set the reference trend for comparison
100
101 Int_t n = ref->GetXaxis()->GetNbins();
102 if (n <= 0) return;
103
104 Double_t sum = 0;
105 Double_t sum2 = 0;
106 for (Int_t i = 1; i <= n; i++) {
107 sum += ref->GetBinContent(i);
108 sum2 += ref->GetBinContent(i) * ref->GetBinContent(i);
109 }
110
111 fRefMean = sum / n;
112 fRefSigma = TMath::Sqrt(sum2 - sum*sum/n) / n;
113}
114
115//_____________________________________________________________________________
116void AliMonitorTrend::SetReference(AliMonitorPlot* ref)
117{
118// set the reference trendgram for comparison
119
120 if (!ref->InheritsFrom(AliMonitorTrend::Class())) return;
121 fRefMean = ((AliMonitorTrend*)ref)->GetMean();
122 fRefSigma = ((AliMonitorTrend*)ref)->GetSigma();
123}
124
125
126//_____________________________________________________________________________
127void AliMonitorTrend::Fill(Double_t x)
128{
129// add a value to the monitor trend
130
131 if (fNumberOfEvents >= fData.GetSize()) {
132 fData.Set(fNumberOfEvents + fgIncSize);
133 }
134 fData[fNumberOfEvents] = x;
135}
136
137
138//_____________________________________________________________________________
139void AliMonitorTrend::Update()
140{
141// update
142
143 fNumberOfEvents++;
144}
145
146//_____________________________________________________________________________
147void AliMonitorTrend::Add(AliMonitorPlot* plot)
148{
149// merge the given trend to this one
150
151 if (!plot->InheritsFrom(AliMonitorTrend::Class())) return;
152 AliMonitorTrend* trend = (AliMonitorTrend*) plot;
153
154 Int_t numberOfEvents = fNumberOfEvents + trend->fNumberOfEvents;
155 if (numberOfEvents >= fData.GetSize()) {
156 fData.Set(numberOfEvents + fgIncSize);
157 }
158 for (Int_t i = 0; i < trend->fNumberOfEvents; i++) {
159 fData[fNumberOfEvents + i] = trend->fData[i];
160 }
161 fNumberOfEvents = numberOfEvents;
162}
163
164//_____________________________________________________________________________
165void AliMonitorTrend::Reset()
166{
167// reset the monitor trend for a new run
168
169 fData.Set(fgIncSize);
170 if (fHistoDraw) delete fHistoDraw;
171 fHistoDraw = NULL;
172 if (fHistoCompare) delete fHistoCompare;
173 fHistoCompare = NULL;
174 fNumberOfEvents = 0;
175}
176
177//_____________________________________________________________________________
178void AliMonitorTrend::ResetList()
179{
180// reset the the list of monitor histograms
181// (not applicable for trend)
182
183}
184
185
186//_____________________________________________________________________________
187Bool_t AliMonitorTrend::ComparePlot()
188{
189// compare the data trend to the reference
190// if they deviate by more than fgThreshold standard deviations in a bin,
191// this bin is set in fHistoCompare and kFALSE is returned
192
193 if (fRefSigma < 0) return kTRUE;
194 if (fgThreshold <= 0) return kTRUE;
195 if (!fHistoDraw) {
196 Info("Compare", "no data trend available for comparison\ncall DrawSum or DrawRaw before calling Compare");
197 return kTRUE;
198 }
199
200 Int_t nBins = fHistoDraw->GetXaxis()->GetNbins();
201 if (fHistoCompare) delete fHistoCompare;
202 fHistoCompare = CreateHisto(nBins);
203 fHistoCompare->Reset();
204 fHistoCompare->SetOption("P");
205 fHistoCompare->SetMarkerStyle(kFullCircle);
206 fHistoCompare->SetFillStyle(0);
207 Bool_t result = kTRUE;
208
209 for (Int_t iBin = 1; iBin <= nBins; iBin++) {
210 Double_t delta = TMath::Abs(fHistoDraw->GetBinContent(iBin) - fRefMean);
211 if (delta > fgThreshold*fRefSigma) {
212 fHistoCompare->SetBinContent(iBin, fHistoDraw->GetBinContent(iBin));
213 result = kFALSE;
214 }
215 }
216
217 return result;
218}
219
220//_____________________________________________________________________________
221Bool_t AliMonitorTrend::GetEvent(Int_t)
222{
223// there is no single event trend
224
97d6eb66 225// Info("GetEvent", "there is no trend for single events available");
04fa961a 226 return kFALSE;
227}
228
229//_____________________________________________________________________________
230Bool_t AliMonitorTrend::GetSum(Int_t number)
231{
232// get the monitor trend for the last "number" events
233
234 if (number > fNumberOfEvents) {
235 Info("GetSum", "requested number of events (%d) exceeds range of available events (%d)\nusing last %d event(s)",
236 number, fNumberOfEvents, fNumberOfEvents);
237 number = fNumberOfEvents;
238 }
239 if (number <= 0) return kFALSE;
240
241 if (fHistoDraw) delete fHistoDraw;
242 if (fHistoCompare) delete fHistoCompare;
243 fHistoCompare = NULL;
244
245 fHistoDraw = CreateHisto(number);
246 return kTRUE;
247}
248
249//_____________________________________________________________________________
250Bool_t AliMonitorTrend::GetRun()
251{
252// get the monitor trend for all monitored events of the current run
253
254 if (fHistoDraw) delete fHistoDraw;
255 if (fHistoCompare) delete fHistoCompare;
256 fHistoCompare = NULL;
257 if (fNumberOfEvents <= 0) return kFALSE;
258
259 fHistoDraw = CreateHisto(fNumberOfEvents);
260 return kTRUE;
261}
262
263//_____________________________________________________________________________
264void AliMonitorTrend::DrawPlot()
265{
266// draw the trendgrams
267
268 fHistoDraw->SetMarkerColor(fgColorData);
269 fHistoDraw->SetLineColor(fgColorData);
270 fHistoDraw->SetLineWidth(2);
271 fHistoDraw->DrawCopy();
272
273 if ((fRefSigma > 0) && fgDrawRef) {
274 if ((fRefMean+fRefSigma > fHistoDraw->GetMaximum()) && !(fMax > fMin)) {
275 fHistoDraw->SetMaximum(fRefMean+fRefSigma * 1.1);
276 }
277
278 Double_t xMin = fHistoDraw->GetXaxis()->GetXmin();
279 Double_t xMax = fHistoDraw->GetXaxis()->GetXmax();
280 TLine* mean = new TLine(xMin, fRefMean, xMax, fRefMean);
281 mean->SetLineColor(fgColorRef);
282 mean->SetLineWidth(2);
283 mean->Draw();
284 TLine* high = new TLine(xMin, fRefMean+fRefSigma,
285 xMax, fRefMean+fRefSigma);
286 high->SetLineColor(fgColorRef);
287 high->SetLineWidth(2);
288 high->SetLineStyle(2);
289 high->Draw();
290 TLine* low = new TLine(xMin, fRefMean-fRefSigma,
291 xMax, fRefMean-fRefSigma);
292 low->SetLineColor(fgColorRef);
293 low->SetLineWidth(2);
294 low->SetLineStyle(2);
295 low->Draw();
296
297// char option[256];
298// sprintf(option, "%sSAME", fHistoDraw->GetOption());
299// fHistoDraw->DrawCopy(option);
300
301 if (fHistoCompare && (fgThreshold > 0)) {
302 char option[256];
303 sprintf(option, "%sSAME", fHistoCompare->GetOption());
304 fHistoCompare->SetMarkerColor(fgColorCompare);
305 fHistoCompare->SetLineColor(fgColorCompare);
306 fHistoCompare->SetLineWidth(2);
307 fHistoCompare->DrawCopy(option);
308 }
309 }
310
311 gPad->Update();
312}
313
314
315//_____________________________________________________________________________
316TH1* AliMonitorTrend::CreateHisto(Int_t nBins)
317{
318// create a histogram for a trend plot with the last nBin entries
319
320 TH1* result = new TH1D(GetName(), GetTitle(), nBins, -nBins-0.5, -0.5);
321 result->GetXaxis()->SetTitle("N_{event}");
322 result->GetYaxis()->SetTitle(fLabel.Data());
323 if (fMax > fMin) {
324 result->SetMinimum(fMin);
325 result->SetMaximum(fMax);
326 }
327 result->SetOption("L");
328
329 Double_t sum = 0;
330 Double_t sum2 = 0;
331 for (Int_t i = 0; i < nBins; i++) {
332 Double_t data = fData[fNumberOfEvents-1-i];
333 sum += data;
334 sum2 += data * data;
335 result->SetBinContent(nBins-i, data);
336 }
337 Stat_t stats[4];
338 stats[0] = nBins;
339 stats[1] = nBins * nBins;
340 stats[2] = sum;
341 stats[3] = sum2;
342 result->PutStats(stats);
343
344 return result;
345}
346
347//_____________________________________________________________________________
348Double_t AliMonitorTrend::GetMean()
349{
350// get the mean value
351
352 if (fNumberOfEvents <= 0) return 0;
353
354 Double_t sum = 0;
355 for (Int_t i = 0; i < fNumberOfEvents; i++) {
356 sum += fData[i];
357 }
358 return sum / fNumberOfEvents;
359}
360
361//_____________________________________________________________________________
362Double_t AliMonitorTrend::GetSigma()
363{
364// get the rms value
365
366 if (fNumberOfEvents <= 0) return 0;
367
368 Double_t sum = 0;
369 Double_t sum2 = 0;
370 for (Int_t i = 0; i < fNumberOfEvents; i++) {
371 sum += fData[i];
372 sum2 += fData[i] * fData[i];
373 }
374 return TMath::Sqrt(sum2 - sum*sum/fNumberOfEvents) / fNumberOfEvents;
375}
376