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 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliMonitorTrend.h"
31 #include <TVirtualPad.h>
35 ClassImp(AliMonitorTrend)
38 Int_t AliMonitorTrend::fgIncSize = 10;
41 //_____________________________________________________________________________
42 AliMonitorTrend::AliMonitorTrend()
53 //_____________________________________________________________________________
54 AliMonitorTrend::AliMonitorTrend(const AliMonitorTrend& trend) :
59 fLabel = trend.fLabel;
62 trend.fData.Copy(fData);
65 fRefMean = trend.fRefMean;
66 fRefSigma = trend.fRefSigma;
70 //_____________________________________________________________________________
71 AliMonitorTrend::AliMonitorTrend(const char* name, const char* title,
72 const char* label, Double_t min, Double_t max) :
73 AliMonitorPlot(name, title)
75 // create a monitor trend
82 fRefMean = fRefSigma = 0;
86 //_____________________________________________________________________________
87 AliMonitorTrend::~AliMonitorTrend()
89 // delete all histograms
91 if (fHistoDraw) delete fHistoDraw;
92 if (fHistoCompare) delete fHistoCompare;
96 //_____________________________________________________________________________
97 void AliMonitorTrend::SetReference(TH1* ref)
99 // set the reference trend for comparison
101 Int_t n = ref->GetXaxis()->GetNbins();
106 for (Int_t i = 1; i <= n; i++) {
107 sum += ref->GetBinContent(i);
108 sum2 += ref->GetBinContent(i) * ref->GetBinContent(i);
112 fRefSigma = TMath::Sqrt(sum2 - sum*sum/n) / n;
115 //_____________________________________________________________________________
116 void AliMonitorTrend::SetReference(AliMonitorPlot* ref)
118 // set the reference trendgram for comparison
120 if (!ref->InheritsFrom(AliMonitorTrend::Class())) return;
121 fRefMean = ((AliMonitorTrend*)ref)->GetMean();
122 fRefSigma = ((AliMonitorTrend*)ref)->GetSigma();
126 //_____________________________________________________________________________
127 void AliMonitorTrend::Fill(Double_t x)
129 // add a value to the monitor trend
131 if (fNumberOfEvents >= fData.GetSize()) {
132 fData.Set(fNumberOfEvents + fgIncSize);
134 fData[fNumberOfEvents] = x;
138 //_____________________________________________________________________________
139 void AliMonitorTrend::Update()
146 //_____________________________________________________________________________
147 void AliMonitorTrend::Add(AliMonitorPlot* plot)
149 // merge the given trend to this one
151 if (!plot->InheritsFrom(AliMonitorTrend::Class())) return;
152 AliMonitorTrend* trend = (AliMonitorTrend*) plot;
154 Int_t numberOfEvents = fNumberOfEvents + trend->fNumberOfEvents;
155 if (numberOfEvents >= fData.GetSize()) {
156 fData.Set(numberOfEvents + fgIncSize);
158 for (Int_t i = 0; i < trend->fNumberOfEvents; i++) {
159 fData[fNumberOfEvents + i] = trend->fData[i];
161 fNumberOfEvents = numberOfEvents;
164 //_____________________________________________________________________________
165 void AliMonitorTrend::Reset()
167 // reset the monitor trend for a new run
169 fData.Set(fgIncSize);
170 if (fHistoDraw) delete fHistoDraw;
172 if (fHistoCompare) delete fHistoCompare;
173 fHistoCompare = NULL;
177 //_____________________________________________________________________________
178 void AliMonitorTrend::ResetList()
180 // reset the the list of monitor histograms
181 // (not applicable for trend)
186 //_____________________________________________________________________________
187 Bool_t AliMonitorTrend::ComparePlot()
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
193 if (fRefSigma < 0) return kTRUE;
194 if (fgThreshold <= 0) return kTRUE;
196 Info("Compare", "no data trend available for comparison\ncall DrawSum or DrawRaw before calling Compare");
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;
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));
220 //_____________________________________________________________________________
221 Bool_t AliMonitorTrend::GetEvent(Int_t)
223 // there is no single event trend
225 // Info("GetEvent", "there is no trend for single events available");
229 //_____________________________________________________________________________
230 Bool_t AliMonitorTrend::GetSum(Int_t number)
232 // get the monitor trend for the last "number" events
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;
239 if (number <= 0) return kFALSE;
241 if (fHistoDraw) delete fHistoDraw;
242 if (fHistoCompare) delete fHistoCompare;
243 fHistoCompare = NULL;
245 fHistoDraw = CreateHisto(number);
249 //_____________________________________________________________________________
250 Bool_t AliMonitorTrend::GetRun()
252 // get the monitor trend for all monitored events of the current run
254 if (fHistoDraw) delete fHistoDraw;
255 if (fHistoCompare) delete fHistoCompare;
256 fHistoCompare = NULL;
257 if (fNumberOfEvents <= 0) return kFALSE;
259 fHistoDraw = CreateHisto(fNumberOfEvents);
263 //_____________________________________________________________________________
264 void AliMonitorTrend::DrawPlot()
266 // draw the trendgrams
268 fHistoDraw->SetMarkerColor(fgColorData);
269 fHistoDraw->SetLineColor(fgColorData);
270 fHistoDraw->SetLineWidth(2);
271 fHistoDraw->DrawCopy();
273 if ((fRefSigma > 0) && fgDrawRef) {
274 if ((fRefMean+fRefSigma > fHistoDraw->GetMaximum()) && !(fMax > fMin)) {
275 fHistoDraw->SetMaximum(fRefMean+fRefSigma * 1.1);
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);
284 TLine* high = new TLine(xMin, fRefMean+fRefSigma,
285 xMax, fRefMean+fRefSigma);
286 high->SetLineColor(fgColorRef);
287 high->SetLineWidth(2);
288 high->SetLineStyle(2);
290 TLine* low = new TLine(xMin, fRefMean-fRefSigma,
291 xMax, fRefMean-fRefSigma);
292 low->SetLineColor(fgColorRef);
293 low->SetLineWidth(2);
294 low->SetLineStyle(2);
298 // sprintf(option, "%sSAME", fHistoDraw->GetOption());
299 // fHistoDraw->DrawCopy(option);
301 if (fHistoCompare && (fgThreshold > 0)) {
303 sprintf(option, "%sSAME", fHistoCompare->GetOption());
304 fHistoCompare->SetMarkerColor(fgColorCompare);
305 fHistoCompare->SetLineColor(fgColorCompare);
306 fHistoCompare->SetLineWidth(2);
307 fHistoCompare->DrawCopy(option);
315 //_____________________________________________________________________________
316 TH1* AliMonitorTrend::CreateHisto(Int_t nBins)
318 // create a histogram for a trend plot with the last nBin entries
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());
324 result->SetMinimum(fMin);
325 result->SetMaximum(fMax);
327 result->SetOption("L");
331 for (Int_t i = 0; i < nBins; i++) {
332 Double_t data = fData[fNumberOfEvents-1-i];
335 result->SetBinContent(nBins-i, data);
339 stats[1] = nBins * nBins;
342 result->PutStats(stats);
347 //_____________________________________________________________________________
348 Double_t AliMonitorTrend::GetMean()
350 // get the mean value
352 if (fNumberOfEvents <= 0) return 0;
355 for (Int_t i = 0; i < fNumberOfEvents; i++) {
358 return sum / fNumberOfEvents;
361 //_____________________________________________________________________________
362 Double_t AliMonitorTrend::GetSigma()
366 if (fNumberOfEvents <= 0) return 0;
370 for (Int_t i = 0; i < fNumberOfEvents; i++) {
372 sum2 += fData[i] * fData[i];
374 return TMath::Sqrt(sum2 - sum*sum/fNumberOfEvents) / fNumberOfEvents;