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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // Class to process a tree and create alarms based on thresholds //
19 // origin: jens wiechula: jens.wiechula@cern.ch //
21 ///////////////////////////////////////////////////////////////////////////////
24 #include <TObjArray.h>
26 #include <TObjString.h>
30 #include <TIterator.h>
34 #include <TStopwatch.h>
38 #include "AliTPCCalibQAChecker.h"
42 AliTPCCalibQAChecker::AliTPCCalibQAChecker() :
43 TNamed("AliTPCCalibQAChecker","AliTPCCalibQAChecker"),
49 fIterSubCheckers(0x0),
51 fArrAlarmDescriptions(0x0),
64 ResetAlarmThresholds();
66 //_________________________________________________________________________
67 AliTPCCalibQAChecker::AliTPCCalibQAChecker(const char* name, const char *title) :
74 fIterSubCheckers(0x0),
76 fArrAlarmDescriptions(0x0),
89 ResetAlarmThresholds();
91 //_________________________________________________________________________
92 AliTPCCalibQAChecker::~AliTPCCalibQAChecker()
97 if (fHistRep) delete fHistRep;
98 if (fIterSubCheckers) delete fIterSubCheckers;
99 if (fArrAlarmDescriptions) delete fArrAlarmDescriptions;
101 //_________________________________________________________________________
102 void AliTPCCalibQAChecker::AddSubChecker(AliTPCCalibQAChecker *alarm)
105 // add a sub checker to this checker
108 if (!fArrSubCheckers) {
109 fArrSubCheckers=new TObjArray;
110 fArrSubCheckers->SetOwner();
112 fArrSubCheckers->Add(alarm);
114 //_________________________________________________________________________
115 void AliTPCCalibQAChecker::Process()
118 // Process the alarm thresholds, decide the alarm level, create the representation histogram
121 //reset quality level
126 //decide which type of checker to use
127 if (fArrSubCheckers && fArrSubCheckers->GetEntries()>0) ProcessSub();
128 else if (fTreePtr && *fTreePtr) ProcessTree();
129 else if (fHistPtr && *fHistPtr) ProcessHist();
130 else if (fGraphPtr && *fGraphPtr) ProcessGraph();
131 else if (fNumberPtr) ProcessNumber();
133 AliInfo(Form("Processing Time (%s): %fs",GetName(),s.RealTime()));
135 //_________________________________________________________________________
136 void AliTPCCalibQAChecker::ProcessSub()
139 // sub checker type checker
141 QualityFlag_t quality=kINFO;
142 if (fArrSubCheckers && fArrSubCheckers->GetEntries()>0){
143 TIter next(fArrSubCheckers);
145 while ( (o=next()) ) {
146 AliTPCCalibQAChecker *al=(AliTPCCalibQAChecker*)o;
148 QualityFlag_t subQuality=al->GetQuality();
149 if (subQuality>quality) quality=subQuality;
152 fQualityLevel=quality;
154 //_________________________________________________________________________
155 void AliTPCCalibQAChecker::ProcessTree()
158 // process tree type checker
161 //Create Representation Histogram
162 CreateRepresentationHist();
164 // if (!fTree) return;
165 //chek for the quality
181 //_________________________________________________________________________
182 void AliTPCCalibQAChecker::ProcessHist()
185 // process histogram type checker
188 if (!(fHistPtr && *fHistPtr)) return;
201 //_________________________________________________________________________
202 void AliTPCCalibQAChecker::ProcessGraph()
205 // process graph type checker
207 if (!(fGraphPtr && *fGraphPtr)) return;
208 Int_t npoints=(*fGraphPtr)->GetN();
209 fQualityLevel=GetQuality(npoints,(*fGraphPtr)->GetY());
211 //_________________________________________________________________________
212 void AliTPCCalibQAChecker::ProcessNumber()
215 // process number type checker
217 if (!fNumberPtr) return;
218 fQualityLevel=GetQuality(*fNumberPtr);
220 //_________________________________________________________________________
221 void AliTPCCalibQAChecker::ProcessEntries()
224 // Processing function which analyses the number of affected rows of a tree draw
226 TString draw=fStrDraw;
227 if (draw.IsNull()) return;
229 TString cuts=fStrCuts;
231 TString opt=fStrDrawOpt;
234 //draw and get the histogram
235 Int_t res=(*fTreePtr)->Draw(draw.Data(),cuts.Data(),opt.Data());
236 fQualityLevel=GetQuality(res);
238 //_________________________________________________________________________
239 void AliTPCCalibQAChecker::ProcessMean()
242 // Processing function which analyses the mean of the resulting histogram
246 Double_t value=h->GetMean();
247 if (fAlarmType==kNentries) value=h->GetEntries();
248 fQualityLevel=GetQuality(value);
250 //_________________________________________________________________________
251 void AliTPCCalibQAChecker::ProcessBin()
254 // Process a histogram bin by bin and check for thresholds
257 //bin quality counters
258 Int_t nquality[kNQualityFlags];
259 for (Int_t iquality=(Int_t)kINFO; iquality<kNQualityFlags; ++iquality) nquality[iquality]=0;
263 Int_t nbinsX=h->GetNbinsX();
264 Int_t nbinsY=h->GetNbinsY();
265 Int_t nbinsZ=h->GetNbinsZ();
266 Int_t nbinsTotal=nbinsX*nbinsY*nbinsZ;
269 for (Int_t ibinZ=1;ibinZ<nbinsZ+1;++ibinZ){
270 for (Int_t ibinY=1;ibinY<nbinsY+1;++ibinY){
271 for (Int_t ibinX=1;ibinX<nbinsX+1;++ibinX){
272 Double_t value = (*fHistPtr)->GetBinContent(ibinX, ibinY, ibinZ);
273 QualityFlag_t quality=GetQuality(value);
279 //loop over Quality levels and set quality
280 for (Int_t iquality=(Int_t)kINFO; iquality<kNQualityFlags; ++iquality){
281 if (fAlarmType==kBinAny){
282 if (nquality[iquality]) fQualityLevel=(QualityFlag_t)iquality;
283 } else if (fAlarmType==kBinAll){
284 if (nquality[iquality]==nbinsTotal) fQualityLevel=(QualityFlag_t)iquality;
288 //_________________________________________________________________________
289 void AliTPCCalibQAChecker::CreateRepresentationHist()
292 // Create the representation histogram which will be shown in the draw function
294 ResetRepresentationHist();
296 TString draw=fStrDrawRep;
299 fStrDrawRepOpt=fStrDrawOpt;
301 draw.ReplaceAll("%alarm%",fStrDraw.Data());
303 if (draw.IsNull()) return;
305 TString cuts=fStrCuts;
307 TString opt=fStrDrawRepOpt;
310 Int_t res=(*fTreePtr)->Draw(draw.Data(),cuts.Data(),opt.Data());
311 TH1 *hist=(*fTreePtr)->GetHistogram();
313 AliError(Form("Could not create representation histogram of alarm '%s'",GetName()));
316 fHistRep=(TH1*)hist->Clone();
317 fHistRep->SetDirectory(0);
319 //_________________________________________________________________________
320 void AliTPCCalibQAChecker::CreateAlarmHist()
323 // create alarm histogram from the tree
326 TString draw=fStrDraw;
327 if (draw.IsNull()) return;
329 TString cuts=fStrCuts;
331 TString opt=fStrDrawOpt;
334 //draw and get the histogram
335 Int_t res=(*fTreePtr)->Draw(draw.Data(),cuts.Data(),opt.Data());
336 fHist=(*fTreePtr)->GetHistogram();
337 if (res<0 || !fHist){
338 AliError(Form("Could not create alarm histogram of alarm '%s'",GetName()));
341 fHist->SetDirectory(0);
344 //_________________________________________________________________________
345 void AliTPCCalibQAChecker::ResetAlarmHist()
348 // delete the alarm histogram and reset the pointer
351 if (*fHistPtr) delete *fHistPtr;
355 //_________________________________________________________________________
356 void AliTPCCalibQAChecker::Draw(Option_t *option)
359 // object draw function
360 // by default the pad backgound color is set to the quality level color
361 // use 'nobc' to change this
364 if (!fHistRep) return;
366 Bool_t withBackColor=kTRUE;
371 if (opt.Contains("nobc")) withBackColor=kFALSE;
372 opt.ReplaceAll("nobc","");
374 if (opt.IsNull()) opt=fStrDrawRepOpt;
377 opt.ReplaceAll("prof","");
379 fHistRep->Draw(opt.Data());
383 if (withBackColor) gPad->SetFillColor(GetQualityColor());
384 TFrame* frame=(TFrame*)gPad->GetPrimitive("TFrame");
385 if (frame) frame->SetFillColor(kWhite);
390 //_________________________________________________________________________
391 void AliTPCCalibQAChecker::Print(Option_t *option) const
394 // print the quality status. If we have sub checkers print recursively
396 TString sOpt(option);
397 cout << sOpt << GetName() << ": " << GetQualityName() << endl;
398 if (fArrSubCheckers && fArrSubCheckers->GetEntries()>0){
399 sOpt.ReplaceAll("+-"," ");
401 TIter next(fArrSubCheckers);
403 while ( (o=next()) ) o->Print(sOpt.Data());
406 //_________________________________________________________________________
407 void AliTPCCalibQAChecker::SetAlarmThreshold(const Double_t min, const Double_t max, const QualityFlag_t quality)
410 //set the alarm thresholds for a specific quality level
412 if ((Int_t)quality<(Int_t)kINFO||(Int_t)quality>=kNQualityFlags) return;
413 fThresMin[quality]=min;
414 fThresMax[quality]=max;
416 //_________________________________________________________________________
417 void AliTPCCalibQAChecker::ResetAlarmThreshold(const QualityFlag_t quality)
420 //set the alarm thresholds for a specific quality level
422 if ((Int_t)quality<(Int_t)kINFO||(Int_t)quality>=kNQualityFlags) return;
423 fThresMin[quality]=0;
424 fThresMax[quality]=0;
426 //_________________________________________________________________________
427 void AliTPCCalibQAChecker::ResetAlarmThresholds()
430 //reset all the alarm thresholds
432 for (Int_t i=0;i<kNQualityFlags;++i){
437 //_________________________________________________________________________
438 void AliTPCCalibQAChecker::SetQualityDescription(const char* text, const QualityFlag_t quality)
441 // set an description for the quality level
442 // %min and %max will be replaced by the min and max values of the alarm, when the quality
443 // description is queried (see QualityDescription)
446 if (quality<kINFO||quality>kFATAL) return;
447 if (! fArrAlarmDescriptions ) fArrAlarmDescriptions=new TObjArray(kNQualityFlags);
448 TObjString *s=(TObjString*)fArrAlarmDescriptions->At(quality);
449 if (!s) fArrAlarmDescriptions->AddAt(s=new TObjString,quality);
453 //_________________________________________________________________________
454 const AliTPCCalibQAChecker* AliTPCCalibQAChecker::GetSubChecker(const char* name, Bool_t recursive) const
460 if (sname==GetName()) return this;
461 if (!fArrSubCheckers || !fArrSubCheckers->GetEntries()) return 0x0;
462 const AliTPCCalibQAChecker *al=0x0;
464 TIter next(fArrSubCheckers);
466 while ( (o=next()) ){
467 AliTPCCalibQAChecker *sal=(AliTPCCalibQAChecker*)o;
468 al=sal->GetSubChecker(name);
472 al=dynamic_cast<AliTPCCalibQAChecker*>(fArrSubCheckers->FindObject(name));
476 //_________________________________________________________________________
477 Int_t AliTPCCalibQAChecker::GetNumberOfSubCheckers(Bool_t recursive) const
480 // get the number of sub checkers
481 // if recursive get total number of non subchecker type sub checkers
485 if (!fArrSubCheckers) return 1;
486 if (!fArrSubCheckers->GetEntries()) return 0;
487 TIter next(fArrSubCheckers);
489 while ( (o=next()) ){
490 AliTPCCalibQAChecker *al=(AliTPCCalibQAChecker*)o;
491 nsub+=al->GetNumberOfSubCheckers();
494 if (fArrSubCheckers) nsub=fArrSubCheckers->GetEntries();
498 //_________________________________________________________________________
499 AliTPCCalibQAChecker* AliTPCCalibQAChecker::NextSubChecker()
502 // loop over sub checkers
503 // if recursive, recursively return the pointers of non subchecker type sub checkers
505 if (!fArrSubCheckers && !fArrSubCheckers->GetEntries()) return 0;
506 if (!fIterSubCheckers) fIterSubCheckers=fArrSubCheckers->MakeIterator();
507 AliTPCCalibQAChecker *al=(AliTPCCalibQAChecker*)fIterSubCheckers->Next();
509 delete fIterSubCheckers;
510 fIterSubCheckers=0x0;
512 // if (recursive && al->GetNumberOfSubCheckers(kFALSE)) al=al->NextSubChecker();
515 //_________________________________________________________________________
516 const char* AliTPCCalibQAChecker::QualityName(const AliTPCCalibQAChecker::QualityFlag_t quality)
519 // get quality name for quality
538 //_________________________________________________________________________
539 Color_t AliTPCCalibQAChecker::QualityColor(const AliTPCCalibQAChecker::QualityFlag_t quality)
542 // get quality color for quality
544 Color_t info = kSpring-8;
545 Color_t warning = kOrange;
546 Color_t error = kRed;
547 Color_t fatal = kRed+2;
548 Color_t none = kWhite;
569 //_________________________________________________________________________
570 const char* AliTPCCalibQAChecker::QualityDescription(const QualityFlag_t quality) const
573 // return description for quality
575 if (!fArrAlarmDescriptions || !fArrAlarmDescriptions->At(quality)) return "";
576 TString s(fArrAlarmDescriptions->At(quality)->GetName());
578 min+=fThresMin[quality];
579 max+=fThresMax[quality];
580 s.ReplaceAll("%min",min);
581 s.ReplaceAll("%max",max);
584 //_________________________________________________________________________
585 Int_t AliTPCCalibQAChecker::DrawInPad(TPad *pad, Int_t sub)
591 if (fArrSubCheckers){
592 if (fArrSubCheckers->GetEntries()>0){
593 TIter next(fArrSubCheckers);
595 while ( (o=next()) ) {
596 AliTPCCalibQAChecker *al=(AliTPCCalibQAChecker*)o;
597 sub=al->DrawInPad(pad,sub);