]>
Commit | Line | Data |
---|---|---|
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 | ||
c4bd737c | 30 | #include <TH1.h> |
04fa961a | 31 | #include <TVirtualPad.h> |
32 | #include <TLine.h> | |
33 | ||
7ba8900c | 34 | #include "AliLog.h" |
35 | ||
36 | #include "AliMonitorTrend.h" | |
37 | ||
04fa961a | 38 | |
39 | ClassImp(AliMonitorTrend) | |
40 | ||
41 | ||
42 | Int_t AliMonitorTrend::fgIncSize = 10; | |
43 | ||
44 | ||
45 | //_____________________________________________________________________________ | |
46 | AliMonitorTrend::AliMonitorTrend() | |
47 | { | |
48 | // default contructor | |
49 | ||
50 | fMin = fMax = 0; | |
51 | fHistoDraw = NULL; | |
52 | fRefMean = 0; | |
53 | fRefSigma = -1; | |
54 | fHistoCompare = NULL; | |
55 | } | |
56 | ||
57 | //_____________________________________________________________________________ | |
58 | AliMonitorTrend::AliMonitorTrend(const AliMonitorTrend& trend) : | |
59 | AliMonitorPlot(trend) | |
60 | { | |
61 | // copy constructor | |
62 | ||
63 | fLabel = trend.fLabel; | |
64 | fMin = trend.fMin; | |
65 | fMax = trend.fMax; | |
66 | trend.fData.Copy(fData); | |
67 | ||
68 | fHistoDraw = NULL; | |
69 | fRefMean = trend.fRefMean; | |
70 | fRefSigma = trend.fRefSigma; | |
71 | fHistoCompare = NULL; | |
72 | } | |
73 | ||
c4bd737c | 74 | //_____________________________________________________________________________ |
75 | AliMonitorTrend& AliMonitorTrend::operator =(const AliMonitorTrend& trend) | |
76 | { | |
77 | // assignment operator | |
78 | ||
79 | AliMonitorPlot::operator =(trend); | |
80 | ||
81 | fLabel = trend.fLabel; | |
82 | fMin = trend.fMin; | |
83 | fMax = trend.fMax; | |
84 | trend.fData.Copy(fData); | |
85 | ||
86 | fHistoDraw = NULL; | |
87 | fRefMean = trend.fRefMean; | |
88 | fRefSigma = trend.fRefSigma; | |
89 | fHistoCompare = NULL; | |
90 | ||
91 | return *this; | |
92 | } | |
93 | ||
04fa961a | 94 | //_____________________________________________________________________________ |
95 | AliMonitorTrend::AliMonitorTrend(const char* name, const char* title, | |
96 | const char* label, Double_t min, Double_t max) : | |
97 | AliMonitorPlot(name, title) | |
98 | { | |
99 | // create a monitor trend | |
100 | ||
101 | fLabel = label; | |
102 | fMin = min; | |
103 | fMax = max; | |
104 | ||
105 | fHistoDraw = NULL; | |
106 | fRefMean = fRefSigma = 0; | |
107 | fHistoCompare = NULL; | |
108 | } | |
109 | ||
110 | //_____________________________________________________________________________ | |
111 | AliMonitorTrend::~AliMonitorTrend() | |
112 | { | |
113 | // delete all histograms | |
114 | ||
115 | if (fHistoDraw) delete fHistoDraw; | |
116 | if (fHistoCompare) delete fHistoCompare; | |
117 | } | |
118 | ||
119 | ||
120 | //_____________________________________________________________________________ | |
121 | void AliMonitorTrend::SetReference(TH1* ref) | |
122 | { | |
123 | // set the reference trend for comparison | |
124 | ||
125 | Int_t n = ref->GetXaxis()->GetNbins(); | |
126 | if (n <= 0) return; | |
127 | ||
128 | Double_t sum = 0; | |
129 | Double_t sum2 = 0; | |
130 | for (Int_t i = 1; i <= n; i++) { | |
131 | sum += ref->GetBinContent(i); | |
132 | sum2 += ref->GetBinContent(i) * ref->GetBinContent(i); | |
133 | } | |
134 | ||
135 | fRefMean = sum / n; | |
136 | fRefSigma = TMath::Sqrt(sum2 - sum*sum/n) / n; | |
137 | } | |
138 | ||
139 | //_____________________________________________________________________________ | |
140 | void AliMonitorTrend::SetReference(AliMonitorPlot* ref) | |
141 | { | |
142 | // set the reference trendgram for comparison | |
143 | ||
144 | if (!ref->InheritsFrom(AliMonitorTrend::Class())) return; | |
145 | fRefMean = ((AliMonitorTrend*)ref)->GetMean(); | |
146 | fRefSigma = ((AliMonitorTrend*)ref)->GetSigma(); | |
147 | } | |
148 | ||
149 | ||
150 | //_____________________________________________________________________________ | |
151 | void AliMonitorTrend::Fill(Double_t x) | |
152 | { | |
153 | // add a value to the monitor trend | |
154 | ||
155 | if (fNumberOfEvents >= fData.GetSize()) { | |
156 | fData.Set(fNumberOfEvents + fgIncSize); | |
157 | } | |
158 | fData[fNumberOfEvents] = x; | |
159 | } | |
160 | ||
161 | ||
162 | //_____________________________________________________________________________ | |
163 | void AliMonitorTrend::Update() | |
164 | { | |
165 | // update | |
166 | ||
167 | fNumberOfEvents++; | |
168 | } | |
169 | ||
170 | //_____________________________________________________________________________ | |
171 | void AliMonitorTrend::Add(AliMonitorPlot* plot) | |
172 | { | |
173 | // merge the given trend to this one | |
174 | ||
175 | if (!plot->InheritsFrom(AliMonitorTrend::Class())) return; | |
176 | AliMonitorTrend* trend = (AliMonitorTrend*) plot; | |
177 | ||
178 | Int_t numberOfEvents = fNumberOfEvents + trend->fNumberOfEvents; | |
179 | if (numberOfEvents >= fData.GetSize()) { | |
180 | fData.Set(numberOfEvents + fgIncSize); | |
181 | } | |
182 | for (Int_t i = 0; i < trend->fNumberOfEvents; i++) { | |
183 | fData[fNumberOfEvents + i] = trend->fData[i]; | |
184 | } | |
185 | fNumberOfEvents = numberOfEvents; | |
186 | } | |
187 | ||
188 | //_____________________________________________________________________________ | |
189 | void AliMonitorTrend::Reset() | |
190 | { | |
191 | // reset the monitor trend for a new run | |
192 | ||
193 | fData.Set(fgIncSize); | |
194 | if (fHistoDraw) delete fHistoDraw; | |
195 | fHistoDraw = NULL; | |
196 | if (fHistoCompare) delete fHistoCompare; | |
197 | fHistoCompare = NULL; | |
198 | fNumberOfEvents = 0; | |
199 | } | |
200 | ||
201 | //_____________________________________________________________________________ | |
202 | void AliMonitorTrend::ResetList() | |
203 | { | |
204 | // reset the the list of monitor histograms | |
205 | // (not applicable for trend) | |
206 | ||
207 | } | |
208 | ||
209 | ||
210 | //_____________________________________________________________________________ | |
211 | Bool_t AliMonitorTrend::ComparePlot() | |
212 | { | |
213 | // compare the data trend to the reference | |
214 | // if they deviate by more than fgThreshold standard deviations in a bin, | |
215 | // this bin is set in fHistoCompare and kFALSE is returned | |
216 | ||
217 | if (fRefSigma < 0) return kTRUE; | |
218 | if (fgThreshold <= 0) return kTRUE; | |
219 | if (!fHistoDraw) { | |
7ba8900c | 220 | AliWarning("no data trend available for comparison\ncall DrawSum or DrawRaw before calling Compare"); |
04fa961a | 221 | return kTRUE; |
222 | } | |
223 | ||
224 | Int_t nBins = fHistoDraw->GetXaxis()->GetNbins(); | |
225 | if (fHistoCompare) delete fHistoCompare; | |
226 | fHistoCompare = CreateHisto(nBins); | |
227 | fHistoCompare->Reset(); | |
228 | fHistoCompare->SetOption("P"); | |
229 | fHistoCompare->SetMarkerStyle(kFullCircle); | |
230 | fHistoCompare->SetFillStyle(0); | |
231 | Bool_t result = kTRUE; | |
232 | ||
233 | for (Int_t iBin = 1; iBin <= nBins; iBin++) { | |
234 | Double_t delta = TMath::Abs(fHistoDraw->GetBinContent(iBin) - fRefMean); | |
235 | if (delta > fgThreshold*fRefSigma) { | |
236 | fHistoCompare->SetBinContent(iBin, fHistoDraw->GetBinContent(iBin)); | |
237 | result = kFALSE; | |
238 | } | |
239 | } | |
240 | ||
241 | return result; | |
242 | } | |
243 | ||
244 | //_____________________________________________________________________________ | |
245 | Bool_t AliMonitorTrend::GetEvent(Int_t) | |
246 | { | |
247 | // there is no single event trend | |
248 | ||
97d6eb66 | 249 | // Info("GetEvent", "there is no trend for single events available"); |
04fa961a | 250 | return kFALSE; |
251 | } | |
252 | ||
253 | //_____________________________________________________________________________ | |
254 | Bool_t AliMonitorTrend::GetSum(Int_t number) | |
255 | { | |
256 | // get the monitor trend for the last "number" events | |
257 | ||
258 | if (number > fNumberOfEvents) { | |
7ba8900c | 259 | AliError(Form("requested number of events (%d) exceeds range of available events (%d)\nusing last %d event(s)", |
260 | number, fNumberOfEvents, fNumberOfEvents)); | |
04fa961a | 261 | number = fNumberOfEvents; |
262 | } | |
263 | if (number <= 0) return kFALSE; | |
264 | ||
265 | if (fHistoDraw) delete fHistoDraw; | |
266 | if (fHistoCompare) delete fHistoCompare; | |
267 | fHistoCompare = NULL; | |
268 | ||
269 | fHistoDraw = CreateHisto(number); | |
270 | return kTRUE; | |
271 | } | |
272 | ||
273 | //_____________________________________________________________________________ | |
274 | Bool_t AliMonitorTrend::GetRun() | |
275 | { | |
276 | // get the monitor trend for all monitored events of the current run | |
277 | ||
278 | if (fHistoDraw) delete fHistoDraw; | |
279 | if (fHistoCompare) delete fHistoCompare; | |
280 | fHistoCompare = NULL; | |
281 | if (fNumberOfEvents <= 0) return kFALSE; | |
282 | ||
283 | fHistoDraw = CreateHisto(fNumberOfEvents); | |
284 | return kTRUE; | |
285 | } | |
286 | ||
287 | //_____________________________________________________________________________ | |
288 | void AliMonitorTrend::DrawPlot() | |
289 | { | |
290 | // draw the trendgrams | |
291 | ||
292 | fHistoDraw->SetMarkerColor(fgColorData); | |
293 | fHistoDraw->SetLineColor(fgColorData); | |
294 | fHistoDraw->SetLineWidth(2); | |
295 | fHistoDraw->DrawCopy(); | |
296 | ||
297 | if ((fRefSigma > 0) && fgDrawRef) { | |
298 | if ((fRefMean+fRefSigma > fHistoDraw->GetMaximum()) && !(fMax > fMin)) { | |
299 | fHistoDraw->SetMaximum(fRefMean+fRefSigma * 1.1); | |
300 | } | |
301 | ||
302 | Double_t xMin = fHistoDraw->GetXaxis()->GetXmin(); | |
303 | Double_t xMax = fHistoDraw->GetXaxis()->GetXmax(); | |
304 | TLine* mean = new TLine(xMin, fRefMean, xMax, fRefMean); | |
305 | mean->SetLineColor(fgColorRef); | |
306 | mean->SetLineWidth(2); | |
307 | mean->Draw(); | |
308 | TLine* high = new TLine(xMin, fRefMean+fRefSigma, | |
309 | xMax, fRefMean+fRefSigma); | |
310 | high->SetLineColor(fgColorRef); | |
311 | high->SetLineWidth(2); | |
312 | high->SetLineStyle(2); | |
313 | high->Draw(); | |
314 | TLine* low = new TLine(xMin, fRefMean-fRefSigma, | |
315 | xMax, fRefMean-fRefSigma); | |
316 | low->SetLineColor(fgColorRef); | |
317 | low->SetLineWidth(2); | |
318 | low->SetLineStyle(2); | |
319 | low->Draw(); | |
320 | ||
321 | // char option[256]; | |
322 | // sprintf(option, "%sSAME", fHistoDraw->GetOption()); | |
323 | // fHistoDraw->DrawCopy(option); | |
324 | ||
325 | if (fHistoCompare && (fgThreshold > 0)) { | |
326 | char option[256]; | |
327 | sprintf(option, "%sSAME", fHistoCompare->GetOption()); | |
328 | fHistoCompare->SetMarkerColor(fgColorCompare); | |
329 | fHistoCompare->SetLineColor(fgColorCompare); | |
330 | fHistoCompare->SetLineWidth(2); | |
331 | fHistoCompare->DrawCopy(option); | |
332 | } | |
333 | } | |
334 | ||
335 | gPad->Update(); | |
336 | } | |
337 | ||
338 | ||
339 | //_____________________________________________________________________________ | |
340 | TH1* AliMonitorTrend::CreateHisto(Int_t nBins) | |
341 | { | |
342 | // create a histogram for a trend plot with the last nBin entries | |
343 | ||
344 | TH1* result = new TH1D(GetName(), GetTitle(), nBins, -nBins-0.5, -0.5); | |
345 | result->GetXaxis()->SetTitle("N_{event}"); | |
346 | result->GetYaxis()->SetTitle(fLabel.Data()); | |
347 | if (fMax > fMin) { | |
348 | result->SetMinimum(fMin); | |
349 | result->SetMaximum(fMax); | |
350 | } | |
351 | result->SetOption("L"); | |
352 | ||
353 | Double_t sum = 0; | |
354 | Double_t sum2 = 0; | |
355 | for (Int_t i = 0; i < nBins; i++) { | |
356 | Double_t data = fData[fNumberOfEvents-1-i]; | |
357 | sum += data; | |
358 | sum2 += data * data; | |
359 | result->SetBinContent(nBins-i, data); | |
360 | } | |
361 | Stat_t stats[4]; | |
362 | stats[0] = nBins; | |
363 | stats[1] = nBins * nBins; | |
364 | stats[2] = sum; | |
365 | stats[3] = sum2; | |
366 | result->PutStats(stats); | |
367 | ||
368 | return result; | |
369 | } | |
370 | ||
371 | //_____________________________________________________________________________ | |
c4bd737c | 372 | Double_t AliMonitorTrend::GetMean() const |
04fa961a | 373 | { |
374 | // get the mean value | |
375 | ||
376 | if (fNumberOfEvents <= 0) return 0; | |
377 | ||
378 | Double_t sum = 0; | |
379 | for (Int_t i = 0; i < fNumberOfEvents; i++) { | |
380 | sum += fData[i]; | |
381 | } | |
382 | return sum / fNumberOfEvents; | |
383 | } | |
384 | ||
385 | //_____________________________________________________________________________ | |
c4bd737c | 386 | Double_t AliMonitorTrend::GetSigma() const |
04fa961a | 387 | { |
388 | // get the rms value | |
389 | ||
390 | if (fNumberOfEvents <= 0) return 0; | |
391 | ||
392 | Double_t sum = 0; | |
393 | Double_t sum2 = 0; | |
394 | for (Int_t i = 0; i < fNumberOfEvents; i++) { | |
395 | sum += fData[i]; | |
396 | sum2 += fData[i] * fData[i]; | |
397 | } | |
398 | return TMath::Sqrt(sum2 - sum*sum/fNumberOfEvents) / fNumberOfEvents; | |
399 | } | |
400 |