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 **************************************************************************/
20 // Base class for detectors quality assurance checkers
21 // Compares Data made by QADataMakers with reference data
22 // Y. Schutz CERN August 2007
25 // --- ROOT system ---
30 #include <TIterator.h>
35 #include <TPaveText.h>
37 // --- Standard library ---
39 // --- AliRoot header files ---
42 #include "AliQAChecker.h"
43 #include "AliQACheckerBase.h"
44 #include "AliQADataMaker.h"
46 ClassImp(AliQACheckerBase)
49 //____________________________________________________________________________
50 AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
54 fRefOCDBSubDir(new TObjArray*[AliRecoParam::kNSpecies]),
57 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
61 fLowTestValue = new Float_t[AliQAv1::kNBIT] ;
62 fUpTestValue = new Float_t[AliQAv1::kNBIT] ;
63 fLowTestValue[AliQAv1::kINFO] = 0.5 ;
64 fUpTestValue[AliQAv1::kINFO] = 1.0 ;
65 fLowTestValue[AliQAv1::kWARNING] = 0.002 ;
66 fUpTestValue[AliQAv1::kWARNING] = 0.5 ;
67 fLowTestValue[AliQAv1::kERROR] = 0.0 ;
68 fUpTestValue[AliQAv1::kERROR] = 0.002 ;
69 fLowTestValue[AliQAv1::kFATAL] = -1.0 ;
70 fUpTestValue[AliQAv1::kFATAL] = 0.0 ;
72 AliDebug(AliQAv1::GetQADebugLevel(), "Default setting is:") ;
73 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
74 const Char_t * text= Form(" INFO -> %1.5f < value < %1.5f WARNING -> %1.5f < value <= %1.5f \n ERROR -> %1.5f < value <= %1.5f \n FATAL -> %1.5f <= value < %1.5f \n",
75 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
76 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
77 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
78 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
79 AliInfo(Form("%s", text)) ;
82 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
83 fImage[specie] = NULL ;
84 fRefOCDBSubDir[specie] = NULL ;
88 //____________________________________________________________________________
89 AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
90 TNamed(qac.GetName(), qac.GetTitle()),
91 fDataSubDir(qac.fDataSubDir),
92 fRefSubDir(qac.fRefSubDir),
93 fRefOCDBSubDir(qac.fRefOCDBSubDir),
94 fLowTestValue(qac.fLowTestValue),
95 fUpTestValue(qac.fLowTestValue),
100 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
101 fLowTestValue[index] = qac.fLowTestValue[index] ;
102 fUpTestValue[index] = qac.fUpTestValue[index] ;
104 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
105 fImage[specie] = qac.fImage[specie] ;
106 fRefOCDBSubDir[specie] = qac.fRefOCDBSubDir[specie] ;
110 //____________________________________________________________________________
111 AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qac )
114 this->~AliQACheckerBase();
115 new(this) AliQACheckerBase(qac);
119 //____________________________________________________________________________
120 AliQACheckerBase::~AliQACheckerBase()
122 delete [] fLowTestValue ;
123 delete [] fUpTestValue ;
124 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
125 if ( fImage[esIndex] )
126 delete fImage[esIndex] ;
127 if ( fRefOCDBSubDir[esIndex] )
128 delete fRefOCDBSubDir[esIndex] ;
131 delete[] fRefOCDBSubDir ;
134 //____________________________________________________________________________
135 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/)
137 // Performs a basic checking
138 // Compares all the histograms stored in the directory
139 // With reference histograms either in a file of in OCDB
141 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
142 Int_t count[AliRecoParam::kNSpecies] = { 0 };
145 for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
147 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
150 if (!fRefSubDir && !fRefOCDBSubDir) {
151 test[specie] = -1 ; // no reference data
153 TList * keyList = fDataSubDir->GetListOfKeys() ;
154 TIter next(keyList) ;
156 while ( (key = static_cast<TKey *>(next())) ) {
157 TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ;
158 TList * keykeyList = specieDir->GetListOfKeys() ;
159 TIter next2(keykeyList) ;
162 while ( (keykey = static_cast<TKey *>(next2())) ) {
163 TObject * odata = specieDir->Get(keykey->GetName()) ;
164 if ( odata->IsA()->InheritsFrom("TH1") ) {
165 TH1 * hdata = static_cast<TH1*>(odata) ;
168 TDirectory * subdir = fRefSubDir->GetDirectory(key->GetName()) ;
169 href = static_cast<TH1*>(subdir->Get(keykey->GetName())) ;
170 } else if (fRefOCDBSubDir[specie]) {
171 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(keykey->GetName())) ;
174 test[specie] = -1 ; // no reference data ;
176 Double_t rv = DiffK(hdata, href) ;
177 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
181 } else if (!odata->IsA()->InheritsFrom("TDirectory")) // skip the expert directory
182 AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
183 if (count[specie] != 0)
184 test[specie] /= count[specie] ;
193 //____________________________________________________________________________
194 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list)
196 // Performs a basic checking
197 // Compares all the histograms in the list
199 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
200 Int_t count[AliRecoParam::kNSpecies] = { 0 };
202 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
204 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
206 if (list[specie]->GetEntries() == 0)
207 test[specie] = 0. ; // nothing to check
209 if (!fRefSubDir && !fRefOCDBSubDir)
210 test[specie] = -1 ; // no reference data
212 TIter next(list[specie]) ;
215 while ( (hdata = static_cast<TH1 *>(next())) ) {
216 TString cln(hdata->ClassName()) ;
217 if ( cln.Contains("TH1") ) {
219 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
223 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
224 else if (fRefOCDBSubDir[specie])
225 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
227 test[specie] = -1 ; // no reference data ;
229 Double_t rv = DiffK(hdata, href) ;
230 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
236 AliError("Data type cannot be processed") ;
237 if (count[specie] != 0)
238 test[specie] /= count[specie] ;
247 //____________________________________________________________________________
248 Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
250 // compares two histograms using the Chi2 test
251 if ( hin->Integral() == 0 ) {
252 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
256 return hin->Chi2Test(href) ;
259 //____________________________________________________________________________
260 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
262 // compares two histograms using the Kolmogorov test
263 if ( hin->Integral() == 0 || href->Integral() == 0) {
264 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
268 return hin->KolmogorovTest(href) ;
271 //____________________________________________________________________________
272 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index)
274 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
276 Double_t * rv = NULL ;
280 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
287 //____________________________________________________________________________
288 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list)
290 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
292 Double_t * rv = NULL ;
293 rv = Check(index, list) ;
296 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
303 //____________________________________________________________________________
304 void AliQACheckerBase::Finish() const
306 // wrap up and save QA in proper file
307 AliQAv1 * qa = AliQAv1::Instance() ;
309 AliQAv1::GetQAResultFile()->cd() ;
310 qa->Write(qa->GetName(), kWriteDelete) ;
311 AliQAv1::GetQAResultFile()->Close() ;
314 //____________________________________________________________________________
315 void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
317 // makes the QA image for sim and rec
319 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
320 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
322 TIter next(list[esIndex]) ;
324 while ( (hdata=static_cast<TH1 *>(next())) ) {
325 TString cln(hdata->ClassName()) ;
326 if ( ! cln.Contains("TH") )
328 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
333 if ( nImages == 0 ) {
334 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
336 AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;
337 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
338 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0)
340 const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ;
341 if ( !fImage[esIndex] ) {
342 fImage[esIndex] = new TCanvas(title, title) ;
344 fImage[esIndex]->Clear() ;
345 fImage[esIndex]->SetTitle(title) ;
346 fImage[esIndex]->cd() ;
347 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
348 someText.AddText(title) ;
350 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
351 fImage[esIndex]->Clear() ;
352 Int_t nx = TMath::Sqrt(nImages) ;
354 while ( nx*ny <= nImages)
357 fImage[esIndex]->Divide(nx, ny) ;
358 TIter nexthist(list[esIndex]) ;
361 fImage[esIndex]->cd(npad) ;
362 while ( (hist=static_cast<TH1*>(nexthist())) ) {
363 TString cln(hist->ClassName()) ;
364 if ( ! cln.Contains("TH") )
366 if(hist->TestBit(AliQAv1::GetImageBit())) {
368 fImage[esIndex]->cd(++npad) ;
371 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
376 //____________________________________________________________________________
377 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
379 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
380 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
381 const Char_t * text= Form(" INFO -> %1.5f < value < %1.5f WARNING -> %1.5f < value <= %1.5f \n ERROR -> %1.5f < value <= %1.5f \n FATAL -> %1.5f <= value < %1.5f \n",
382 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
383 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
384 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
385 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
386 AliInfo(Form("%s", text)) ;
389 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
390 fLowTestValue[index] = lowValue[index] ;
391 fUpTestValue[index] = hiValue[index] ;
393 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
394 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
395 const Char_t * text= Form(" INFO -> %1.5f < value < %1.5f WARNING -> %1.5f < value <= %1.5f \n ERROR -> %1.5f < value <= %1.5f \n FATAL -> %1.5f <= value < %1.5f \n",
396 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
397 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
398 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
399 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; AliInfo(Form("%s", text)) ;
403 //____________________________________________________________________________
404 void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
406 // sets the QA according the return value of the Check
408 AliQAv1 * qa = AliQAv1::Instance(index) ;
409 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
410 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
411 qa->Set(AliQAv1::kFATAL, specie) ;
413 if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] )
414 qa->Set(AliQAv1::kFATAL, specie) ;
415 else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR] )
416 qa->Set(AliQAv1::kERROR, specie) ;
417 else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING] )
418 qa->Set(AliQAv1::kWARNING, specie) ;
419 else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] )
420 qa->Set(AliQAv1::kINFO, specie) ;