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 TObjArray ** list = new TObjArray *[AliRecoParam::kNSpecies] ;
143 for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
144 list[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
145 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
148 TList * keyList = fDataSubDir->GetListOfKeys() ;
149 TIter next(keyList) ;
151 while ( (key = static_cast<TKey *>(next())) ) {
152 TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ;
153 TList * keykeyList = specieDir->GetListOfKeys() ;
154 TIter next2(keykeyList) ;
156 while ( (keykey = static_cast<TKey *>(next2())) ) {
157 TObject * odata = specieDir->Get(keykey->GetName()) ;
158 if ( odata->IsA()->InheritsFrom("TH1") ) {
159 TH1 * hdata = static_cast<TH1*>(odata) ;
160 list[specie]->Add(hdata) ;
161 } else if (!odata->IsA()->InheritsFrom("TDirectory")) // skip the expert directory
162 AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
168 Double_t * test = AliQACheckerBase::Check(index, list) ;
175 //____________________________________________________________________________
176 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list)
178 // Performs a basic checking
179 // Compares all the histograms in the list
181 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
182 Int_t count[AliRecoParam::kNSpecies] = { 0 };
184 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
186 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
188 if (list[specie]->GetEntries() == 0)
189 test[specie] = 0. ; // nothing to check
191 if (!fRefSubDir && !fRefOCDBSubDir)
192 test[specie] = -1 ; // no reference data
194 TIter next(list[specie]) ;
197 while ( (hdata = static_cast<TH1 *>(next())) ) {
198 TString cln(hdata->ClassName()) ;
199 if ( cln.Contains("TH1") ) {
201 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
205 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
206 else if (fRefOCDBSubDir[specie])
207 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
209 test[specie] = -1 ; // no reference data ;
211 Double_t rv = DiffK(hdata, href) ;
212 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
218 AliError("Data type cannot be processed") ;
219 if (count[specie] != 0)
220 test[specie] /= count[specie] ;
229 //____________________________________________________________________________
230 Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
232 // compares two histograms using the Chi2 test
233 if ( hin->Integral() == 0 ) {
234 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
238 return hin->Chi2Test(href) ;
241 //____________________________________________________________________________
242 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
244 // compares two histograms using the Kolmogorov test
245 if ( hin->Integral() == 0 || href->Integral() == 0) {
246 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
250 return hin->KolmogorovTest(href) ;
253 //____________________________________________________________________________
254 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index)
256 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
258 Double_t * rv = NULL ;
262 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
269 //____________________________________________________________________________
270 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list)
272 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
274 Double_t * rv = NULL ;
275 rv = Check(index, list) ;
278 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
285 //____________________________________________________________________________
286 void AliQACheckerBase::Finish() const
288 // wrap up and save QA in proper file
289 AliQAv1 * qa = AliQAv1::Instance() ;
291 AliQAv1::GetQAResultFile()->cd() ;
292 qa->Write(qa->GetName(), kWriteDelete) ;
293 AliQAv1::GetQAResultFile()->Close() ;
296 //____________________________________________________________________________
297 void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
299 // makes the QA image for sim and rec
301 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
302 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
304 TIter next(list[esIndex]) ;
306 while ( (hdata=static_cast<TH1 *>(next())) ) {
307 TString cln(hdata->ClassName()) ;
308 if ( ! cln.Contains("TH") )
310 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
315 if ( nImages == 0 ) {
316 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
318 AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;
319 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
320 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0)
322 const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ;
323 if ( !fImage[esIndex] ) {
324 fImage[esIndex] = new TCanvas(title, title) ;
326 fImage[esIndex]->Clear() ;
327 fImage[esIndex]->SetTitle(title) ;
328 fImage[esIndex]->cd() ;
329 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
330 someText.AddText(title) ;
332 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
333 fImage[esIndex]->Clear() ;
334 Int_t nx = TMath::Sqrt(nImages) ;
336 while ( nx*ny <= nImages)
339 fImage[esIndex]->Divide(nx, ny) ;
340 TIter nexthist(list[esIndex]) ;
343 fImage[esIndex]->cd(npad) ;
344 while ( (hist=static_cast<TH1*>(nexthist())) ) {
345 TString cln(hist->ClassName()) ;
346 if ( ! cln.Contains("TH") )
348 if(hist->TestBit(AliQAv1::GetImageBit())) {
350 fImage[esIndex]->cd(++npad) ;
353 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
358 //____________________________________________________________________________
359 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
361 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
362 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
363 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",
364 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
365 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
366 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
367 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
368 AliInfo(Form("%s", text)) ;
371 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
372 fLowTestValue[index] = lowValue[index] ;
373 fUpTestValue[index] = hiValue[index] ;
375 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
376 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
377 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",
378 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
379 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
380 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
381 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; AliInfo(Form("%s", text)) ;
385 //____________________________________________________________________________
386 void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
388 // sets the QA according the return value of the Check
390 AliQAv1 * qa = AliQAv1::Instance(index) ;
391 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
392 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
393 qa->Set(AliQAv1::kFATAL, specie) ;
395 if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] )
396 qa->Set(AliQAv1::kFATAL, specie) ;
397 else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR] )
398 qa->Set(AliQAv1::kERROR, specie) ;
399 else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING] )
400 qa->Set(AliQAv1::kWARNING, specie) ;
401 else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] )
402 qa->Set(AliQAv1::kINFO, specie) ;