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) :
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 ;
86 //____________________________________________________________________________
87 AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
88 TNamed(qac.GetName(), qac.GetTitle()),
89 fDataSubDir(qac.fDataSubDir),
90 fRefSubDir(qac.fRefSubDir),
91 fRefOCDBSubDir(qac.fRefOCDBSubDir),
92 fLowTestValue(qac.fLowTestValue),
93 fUpTestValue(qac.fLowTestValue),
98 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
99 fLowTestValue[index] = qac.fLowTestValue[index] ;
100 fUpTestValue[index] = qac.fUpTestValue[index] ;
102 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
103 fImage[specie] = qac.fImage[specie] ;
106 //____________________________________________________________________________
107 AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qac )
110 this->~AliQACheckerBase();
111 new(this) AliQACheckerBase(qac);
115 //____________________________________________________________________________
116 AliQACheckerBase::~AliQACheckerBase()
118 delete [] fLowTestValue ;
119 delete [] fUpTestValue ;
120 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
121 if ( fImage[esIndex] )
122 delete fImage[esIndex] ;
127 //____________________________________________________________________________
128 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/)
130 // Performs a basic checking
131 // Compares all the histograms stored in the directory
132 // With reference histograms either in a file of in OCDB
134 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
135 Int_t count[AliRecoParam::kNSpecies] = { 0 };
137 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
139 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
142 test[specie] = 0. ; // nothing to check
143 } else if (!fRefSubDir && !fRefOCDBSubDir) {
144 test[specie] = -1 ; // no reference data
146 TList * keyList = fDataSubDir->GetListOfKeys() ;
147 TIter next(keyList) ;
150 while ( (key = static_cast<TKey *>(next())) ) {
151 TObject * odata = fRefSubDir->Get(key->GetName()) ;
152 if ( odata->IsA()->InheritsFrom("TH1") ) {
153 TH1 * hdata = static_cast<TH1*>(odata) ;
156 href = static_cast<TH1*>(fRefSubDir->Get(key->GetName())) ;
157 else if (fRefOCDBSubDir[specie]) {
158 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(key->GetName())) ;
161 test[specie] = -1 ; // no reference data ;
163 Double_t rv = DiffK(hdata, href) ;
164 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
169 AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
171 if (count[specie] != 0)
172 test[specie] /= count[specie] ;
178 //____________________________________________________________________________
179 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list)
181 // Performs a basic checking
182 // Compares all the histograms in the list
184 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
185 Int_t count[AliRecoParam::kNSpecies] = { 0 };
187 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
189 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
191 if (list[specie]->GetEntries() == 0)
192 test[specie] = 0. ; // nothing to check
194 if (!fRefSubDir && !fRefOCDBSubDir)
195 test[specie] = -1 ; // no reference data
197 TIter next(list[specie]) ;
200 while ( (hdata = static_cast<TH1 *>(next())) ) {
201 TString cln(hdata->ClassName()) ;
202 if ( ! cln.Contains("TH1") )
205 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
209 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
210 else if (fRefOCDBSubDir[specie])
211 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
213 test[specie] = -1 ; // no reference data ;
215 Double_t rv = DiffK(hdata, href) ;
216 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
222 AliError("Data type cannot be processed") ;
224 if (count[specie] != 0)
225 test[specie] /= count[specie] ;
233 //____________________________________________________________________________
234 Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
236 // compares two histograms using the Chi2 test
237 if ( hin->Integral() == 0 ) {
238 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
242 return hin->Chi2Test(href) ;
245 //____________________________________________________________________________
246 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
248 // compares two histograms using the Kolmogorov test
249 if ( hin->Integral() == 0 || href->Integral() == 0) {
250 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
254 return hin->KolmogorovTest(href) ;
257 //____________________________________________________________________________
258 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list)
260 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
262 Double_t * rv = NULL ;
266 rv = Check(index, list) ;
269 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
276 //____________________________________________________________________________
277 void AliQACheckerBase::Finish() const
279 // wrap up and save QA in proper file
280 AliQAv1 * qa = AliQAv1::Instance() ;
282 AliQAv1::GetQAResultFile()->cd() ;
283 qa->Write(qa->GetName(), kWriteDelete) ;
284 AliQAv1::GetQAResultFile()->Close() ;
287 //____________________________________________________________________________
288 void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
290 // makes the QA image for sim and rec
292 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
293 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
295 TIter next(list[esIndex]) ;
297 while ( (hdata=static_cast<TH1 *>(next())) ) {
298 TString cln(hdata->ClassName()) ;
299 if ( ! cln.Contains("TH") )
301 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
306 if ( nImages == 0 ) {
307 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
309 AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;
310 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
311 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
313 const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ;
314 if ( !fImage[esIndex] ) {
315 fImage[esIndex] = new TCanvas(title, title) ;
317 fImage[esIndex]->Clear() ;
318 fImage[esIndex]->SetTitle(title) ;
319 fImage[esIndex]->cd() ;
320 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
321 someText.AddText(title) ;
323 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
324 fImage[esIndex]->Clear() ;
325 Int_t nx = TMath::Sqrt(nImages) ;
327 while ( nx*ny <= nImages)
330 fImage[esIndex]->Divide(nx, ny) ;
331 TIter nexthist(list[esIndex]) ;
334 fImage[esIndex]->cd(npad) ;
335 while ( (hist=static_cast<TH1*>(nexthist())) ) {
336 TString cln(hist->ClassName()) ;
337 if ( ! cln.Contains("TH") )
339 if(hist->TestBit(AliQAv1::GetImageBit())) {
341 fImage[esIndex]->cd(++npad) ;
344 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
349 //____________________________________________________________________________
350 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
352 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
353 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
354 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",
355 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
356 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
357 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
358 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
359 AliInfo(Form("%s", text)) ;
362 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
363 fLowTestValue[index] = lowValue[index] ;
364 fUpTestValue[index] = hiValue[index] ;
366 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
367 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
368 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",
369 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
370 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
371 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
372 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; AliInfo(Form("%s", text)) ;
376 //____________________________________________________________________________
377 void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
379 // sets the QA according the return value of the Check
381 AliQAv1 * qa = AliQAv1::Instance(index) ;
382 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
383 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
384 qa->Set(AliQAv1::kFATAL, specie) ;
386 if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] )
387 qa->Set(AliQAv1::kFATAL, specie) ;
388 else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR] )
389 qa->Set(AliQAv1::kERROR, specie) ;
390 else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING] )
391 qa->Set(AliQAv1::kWARNING, specie) ;
392 else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] )
393 qa->Set(AliQAv1::kINFO, specie) ;