1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
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. //
27 ///////////////////////////////////////////////////////////////////////////////
31 #include <TVirtualPad.h>
36 #include "AliMonitorTrend.h"
39 ClassImp(AliMonitorTrend)
42 Int_t AliMonitorTrend::fgIncSize = 10;
45 //_____________________________________________________________________________
46 AliMonitorTrend::AliMonitorTrend()
57 //_____________________________________________________________________________
58 AliMonitorTrend::AliMonitorTrend(const AliMonitorTrend& trend) :
63 fLabel = trend.fLabel;
66 trend.fData.Copy(fData);
69 fRefMean = trend.fRefMean;
70 fRefSigma = trend.fRefSigma;
74 //_____________________________________________________________________________
75 AliMonitorTrend& AliMonitorTrend::operator =(const AliMonitorTrend& trend)
77 // assignment operator
79 AliMonitorPlot::operator =(trend);
81 fLabel = trend.fLabel;
84 trend.fData.Copy(fData);
87 fRefMean = trend.fRefMean;
88 fRefSigma = trend.fRefSigma;
94 //_____________________________________________________________________________
95 AliMonitorTrend::AliMonitorTrend(const char* name, const char* title,
96 const char* label, Double_t min, Double_t max) :
97 AliMonitorPlot(name, title)
99 // create a monitor trend
106 fRefMean = fRefSigma = 0;
107 fHistoCompare = NULL;
110 //_____________________________________________________________________________
111 AliMonitorTrend::~AliMonitorTrend()
113 // delete all histograms
115 if (fHistoDraw) delete fHistoDraw;
116 if (fHistoCompare) delete fHistoCompare;
120 //_____________________________________________________________________________
121 void AliMonitorTrend::SetReference(TH1* ref)
123 // set the reference trend for comparison
125 Int_t n = ref->GetXaxis()->GetNbins();
130 for (Int_t i = 1; i <= n; i++) {
131 sum += ref->GetBinContent(i);
132 sum2 += ref->GetBinContent(i) * ref->GetBinContent(i);
136 fRefSigma = TMath::Sqrt(sum2 - sum*sum/n) / n;
139 //_____________________________________________________________________________
140 void AliMonitorTrend::SetReference(AliMonitorPlot* ref)
142 // set the reference trendgram for comparison
144 if (!ref->InheritsFrom(AliMonitorTrend::Class())) return;
145 fRefMean = ((AliMonitorTrend*)ref)->GetMean();
146 fRefSigma = ((AliMonitorTrend*)ref)->GetSigma();
150 //_____________________________________________________________________________
151 void AliMonitorTrend::Fill(Double_t x)
153 // add a value to the monitor trend
155 if (fNumberOfEvents >= fData.GetSize()) {
156 fData.Set(fNumberOfEvents + fgIncSize);
158 fData[fNumberOfEvents] = x;
162 //_____________________________________________________________________________
163 void AliMonitorTrend::Update()
170 //_____________________________________________________________________________
171 void AliMonitorTrend::Add(AliMonitorPlot* plot)
173 // merge the given trend to this one
175 if (!plot->InheritsFrom(AliMonitorTrend::Class())) return;
176 AliMonitorTrend* trend = (AliMonitorTrend*) plot;
178 Int_t numberOfEvents = fNumberOfEvents + trend->fNumberOfEvents;
179 if (numberOfEvents >= fData.GetSize()) {
180 fData.Set(numberOfEvents + fgIncSize);
182 for (Int_t i = 0; i < trend->fNumberOfEvents; i++) {
183 fData[fNumberOfEvents + i] = trend->fData[i];
185 fNumberOfEvents = numberOfEvents;
188 //_____________________________________________________________________________
189 void AliMonitorTrend::Reset()
191 // reset the monitor trend for a new run
193 fData.Set(fgIncSize);
194 if (fHistoDraw) delete fHistoDraw;
196 if (fHistoCompare) delete fHistoCompare;
197 fHistoCompare = NULL;
201 //_____________________________________________________________________________
202 void AliMonitorTrend::ResetList()
204 // reset the the list of monitor histograms
205 // (not applicable for trend)
210 //_____________________________________________________________________________
211 Bool_t AliMonitorTrend::ComparePlot()
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
217 if (fRefSigma < 0) return kTRUE;
218 if (fgThreshold <= 0) return kTRUE;
220 AliWarning("no data trend available for comparison\ncall DrawSum or DrawRaw before calling Compare");
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;
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));
244 //_____________________________________________________________________________
245 Bool_t AliMonitorTrend::GetEvent(Int_t)
247 // there is no single event trend
249 // Info("GetEvent", "there is no trend for single events available");
253 //_____________________________________________________________________________
254 Bool_t AliMonitorTrend::GetSum(Int_t number)
256 // get the monitor trend for the last "number" events
258 if (number > fNumberOfEvents) {
259 AliError(Form("requested number of events (%d) exceeds range of available events (%d)\nusing last %d event(s)",
260 number, fNumberOfEvents, fNumberOfEvents));
261 number = fNumberOfEvents;
263 if (number <= 0) return kFALSE;
265 if (fHistoDraw) delete fHistoDraw;
266 if (fHistoCompare) delete fHistoCompare;
267 fHistoCompare = NULL;
269 fHistoDraw = CreateHisto(number);
273 //_____________________________________________________________________________
274 Bool_t AliMonitorTrend::GetRun()
276 // get the monitor trend for all monitored events of the current run
278 if (fHistoDraw) delete fHistoDraw;
279 if (fHistoCompare) delete fHistoCompare;
280 fHistoCompare = NULL;
281 if (fNumberOfEvents <= 0) return kFALSE;
283 fHistoDraw = CreateHisto(fNumberOfEvents);
287 //_____________________________________________________________________________
288 void AliMonitorTrend::DrawPlot()
290 // draw the trendgrams
292 fHistoDraw->SetMarkerColor(fgColorData);
293 fHistoDraw->SetLineColor(fgColorData);
294 fHistoDraw->SetLineWidth(2);
295 fHistoDraw->DrawCopy();
297 if ((fRefSigma > 0) && fgDrawRef) {
298 if ((fRefMean+fRefSigma > fHistoDraw->GetMaximum()) && !(fMax > fMin)) {
299 fHistoDraw->SetMaximum(fRefMean+fRefSigma * 1.1);
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);
308 TLine* high = new TLine(xMin, fRefMean+fRefSigma,
309 xMax, fRefMean+fRefSigma);
310 high->SetLineColor(fgColorRef);
311 high->SetLineWidth(2);
312 high->SetLineStyle(2);
314 TLine* low = new TLine(xMin, fRefMean-fRefSigma,
315 xMax, fRefMean-fRefSigma);
316 low->SetLineColor(fgColorRef);
317 low->SetLineWidth(2);
318 low->SetLineStyle(2);
322 // sprintf(option, "%sSAME", fHistoDraw->GetOption());
323 // fHistoDraw->DrawCopy(option);
325 if (fHistoCompare && (fgThreshold > 0)) {
327 sprintf(option, "%sSAME", fHistoCompare->GetOption());
328 fHistoCompare->SetMarkerColor(fgColorCompare);
329 fHistoCompare->SetLineColor(fgColorCompare);
330 fHistoCompare->SetLineWidth(2);
331 fHistoCompare->DrawCopy(option);
339 //_____________________________________________________________________________
340 TH1* AliMonitorTrend::CreateHisto(Int_t nBins)
342 // create a histogram for a trend plot with the last nBin entries
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());
348 result->SetMinimum(fMin);
349 result->SetMaximum(fMax);
351 result->SetOption("L");
355 for (Int_t i = 0; i < nBins; i++) {
356 Double_t data = fData[fNumberOfEvents-1-i];
359 result->SetBinContent(nBins-i, data);
363 stats[1] = nBins * nBins;
366 result->PutStats(stats);
371 //_____________________________________________________________________________
372 Double_t AliMonitorTrend::GetMean() const
374 // get the mean value
376 if (fNumberOfEvents <= 0) return 0;
379 for (Int_t i = 0; i < fNumberOfEvents; i++) {
382 return sum / fNumberOfEvents;
385 //_____________________________________________________________________________
386 Double_t AliMonitorTrend::GetSigma() const
390 if (fNumberOfEvents <= 0) return 0;
394 for (Int_t i = 0; i < fNumberOfEvents; i++) {
396 sum2 += fData[i] * fData[i];
398 return TMath::Sqrt(sum2 - sum*sum/fNumberOfEvents) / fNumberOfEvents;