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():
61 //_____________________________________________________________________________
62 AliMonitorTrend::AliMonitorTrend(const AliMonitorTrend& trend) :
63 AliMonitorPlot(trend),
69 fRefMean(trend.fRefMean),
70 fRefSigma(trend.fRefSigma),
77 //_____________________________________________________________________________
78 AliMonitorTrend& AliMonitorTrend::operator =(const AliMonitorTrend& trend)
80 // assignment operator
82 AliMonitorPlot::operator =(trend);
84 fLabel = trend.fLabel;
87 trend.fData.Copy(fData);
90 fRefMean = trend.fRefMean;
91 fRefSigma = trend.fRefSigma;
97 //_____________________________________________________________________________
98 AliMonitorTrend::AliMonitorTrend(const char* name, const char* title,
99 const char* label, Double_t min, Double_t max) :
100 AliMonitorPlot(name, title),
110 // create a monitor trend
114 //_____________________________________________________________________________
115 AliMonitorTrend::~AliMonitorTrend()
117 // delete all histograms
119 if (fHistoDraw) delete fHistoDraw;
120 if (fHistoCompare) delete fHistoCompare;
124 //_____________________________________________________________________________
125 void AliMonitorTrend::SetReference(TH1* ref)
127 // set the reference trend for comparison
129 Int_t n = ref->GetXaxis()->GetNbins();
134 for (Int_t i = 1; i <= n; i++) {
135 sum += ref->GetBinContent(i);
136 sum2 += ref->GetBinContent(i) * ref->GetBinContent(i);
140 fRefSigma = TMath::Sqrt(sum2 - sum*sum/n) / n;
143 //_____________________________________________________________________________
144 void AliMonitorTrend::SetReference(AliMonitorPlot* ref)
146 // set the reference trendgram for comparison
148 if (!ref->InheritsFrom(AliMonitorTrend::Class())) return;
149 fRefMean = ((AliMonitorTrend*)ref)->GetMean();
150 fRefSigma = ((AliMonitorTrend*)ref)->GetSigma();
154 //_____________________________________________________________________________
155 void AliMonitorTrend::Fill(Double_t x)
157 // add a value to the monitor trend
159 if (fNumberOfEvents >= fData.GetSize()) {
160 fData.Set(fNumberOfEvents + fgIncSize);
162 fData[fNumberOfEvents] = x;
166 //_____________________________________________________________________________
167 void AliMonitorTrend::Update()
174 //_____________________________________________________________________________
175 void AliMonitorTrend::Add(AliMonitorPlot* plot)
177 // merge the given trend to this one
179 if (!plot->InheritsFrom(AliMonitorTrend::Class())) return;
180 AliMonitorTrend* trend = (AliMonitorTrend*) plot;
182 Int_t numberOfEvents = fNumberOfEvents + trend->fNumberOfEvents;
183 if (numberOfEvents >= fData.GetSize()) {
184 fData.Set(numberOfEvents + fgIncSize);
186 for (Int_t i = 0; i < trend->fNumberOfEvents; i++) {
187 fData[fNumberOfEvents + i] = trend->fData[i];
189 fNumberOfEvents = numberOfEvents;
192 //_____________________________________________________________________________
193 void AliMonitorTrend::Reset()
195 // reset the monitor trend for a new run
197 fData.Set(fgIncSize);
198 if (fHistoDraw) delete fHistoDraw;
200 if (fHistoCompare) delete fHistoCompare;
201 fHistoCompare = NULL;
205 //_____________________________________________________________________________
206 void AliMonitorTrend::ResetList()
208 // reset the the list of monitor histograms
209 // (not applicable for trend)
214 //_____________________________________________________________________________
215 Bool_t AliMonitorTrend::ComparePlot()
217 // compare the data trend to the reference
218 // if they deviate by more than fgThreshold standard deviations in a bin,
219 // this bin is set in fHistoCompare and kFALSE is returned
221 if (fRefSigma < 0) return kTRUE;
222 if (fgThreshold <= 0) return kTRUE;
224 AliWarning("no data trend available for comparison\ncall DrawSum or DrawRaw before calling Compare");
228 Int_t nBins = fHistoDraw->GetXaxis()->GetNbins();
229 if (fHistoCompare) delete fHistoCompare;
230 fHistoCompare = CreateHisto(nBins);
231 fHistoCompare->Reset();
232 fHistoCompare->SetOption("P");
233 fHistoCompare->SetMarkerStyle(kFullCircle);
234 fHistoCompare->SetFillStyle(0);
235 Bool_t result = kTRUE;
237 for (Int_t iBin = 1; iBin <= nBins; iBin++) {
238 Double_t delta = TMath::Abs(fHistoDraw->GetBinContent(iBin) - fRefMean);
239 if (delta > fgThreshold*fRefSigma) {
240 fHistoCompare->SetBinContent(iBin, fHistoDraw->GetBinContent(iBin));
248 //_____________________________________________________________________________
249 Bool_t AliMonitorTrend::GetEvent(Int_t)
251 // there is no single event trend
253 // Info("GetEvent", "there is no trend for single events available");
257 //_____________________________________________________________________________
258 Bool_t AliMonitorTrend::GetSum(Int_t number)
260 // get the monitor trend for the last "number" events
262 if (number > fNumberOfEvents) {
263 AliError(Form("requested number of events (%d) exceeds range of available events (%d)\nusing last %d event(s)",
264 number, fNumberOfEvents, fNumberOfEvents));
265 number = fNumberOfEvents;
267 if (number <= 0) return kFALSE;
269 if (fHistoDraw) delete fHistoDraw;
270 if (fHistoCompare) delete fHistoCompare;
271 fHistoCompare = NULL;
273 fHistoDraw = CreateHisto(number);
277 //_____________________________________________________________________________
278 Bool_t AliMonitorTrend::GetRun()
280 // get the monitor trend for all monitored events of the current run
282 if (fHistoDraw) delete fHistoDraw;
283 if (fHistoCompare) delete fHistoCompare;
284 fHistoCompare = NULL;
285 if (fNumberOfEvents <= 0) return kFALSE;
287 fHistoDraw = CreateHisto(fNumberOfEvents);
291 //_____________________________________________________________________________
292 void AliMonitorTrend::DrawPlot()
294 // draw the trendgrams
296 fHistoDraw->SetMarkerColor(fgColorData);
297 fHistoDraw->SetLineColor(fgColorData);
298 fHistoDraw->SetLineWidth(2);
299 fHistoDraw->DrawCopy();
301 if ((fRefSigma > 0) && fgDrawRef) {
302 if ((fRefMean+fRefSigma > fHistoDraw->GetMaximum()) && !(fMax > fMin)) {
303 fHistoDraw->SetMaximum(fRefMean+fRefSigma * 1.1);
306 Double_t xMin = fHistoDraw->GetXaxis()->GetXmin();
307 Double_t xMax = fHistoDraw->GetXaxis()->GetXmax();
308 TLine* mean = new TLine(xMin, fRefMean, xMax, fRefMean);
309 mean->SetLineColor(fgColorRef);
310 mean->SetLineWidth(2);
312 TLine* high = new TLine(xMin, fRefMean+fRefSigma,
313 xMax, fRefMean+fRefSigma);
314 high->SetLineColor(fgColorRef);
315 high->SetLineWidth(2);
316 high->SetLineStyle(2);
318 TLine* low = new TLine(xMin, fRefMean-fRefSigma,
319 xMax, fRefMean-fRefSigma);
320 low->SetLineColor(fgColorRef);
321 low->SetLineWidth(2);
322 low->SetLineStyle(2);
326 // sprintf(option, "%sSAME", fHistoDraw->GetOption());
327 // fHistoDraw->DrawCopy(option);
329 if (fHistoCompare && (fgThreshold > 0)) {
331 sprintf(option, "%sSAME", fHistoCompare->GetOption());
332 fHistoCompare->SetMarkerColor(fgColorCompare);
333 fHistoCompare->SetLineColor(fgColorCompare);
334 fHistoCompare->SetLineWidth(2);
335 fHistoCompare->DrawCopy(option);
343 //_____________________________________________________________________________
344 TH1* AliMonitorTrend::CreateHisto(Int_t nBins)
346 // create a histogram for a trend plot with the last nBin entries
348 TH1* result = new TH1D(GetName(), GetTitle(), nBins, -nBins-0.5, -0.5);
349 result->GetXaxis()->SetTitle("N_{event}");
350 result->GetYaxis()->SetTitle(fLabel.Data());
352 result->SetMinimum(fMin);
353 result->SetMaximum(fMax);
355 result->SetOption("L");
359 for (Int_t i = 0; i < nBins; i++) {
360 Double_t data = fData[fNumberOfEvents-1-i];
363 result->SetBinContent(nBins-i, data);
367 stats[1] = nBins * nBins;
370 result->PutStats(stats);
375 //_____________________________________________________________________________
376 Double_t AliMonitorTrend::GetMean() const
378 // get the mean value
380 if (fNumberOfEvents <= 0) return 0;
383 for (Int_t i = 0; i < fNumberOfEvents; i++) {
386 return sum / fNumberOfEvents;
389 //_____________________________________________________________________________
390 Double_t AliMonitorTrend::GetSigma() const
394 if (fNumberOfEvents <= 0) return 0;
398 for (Int_t i = 0; i < fNumberOfEvents; i++) {
400 sum2 += fData[i] * fData[i];
402 return TMath::Sqrt(sum2 - sum*sum/fNumberOfEvents) / fNumberOfEvents;