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"
45 #include "AliDetectorRecoParam.h"
47 ClassImp(AliQACheckerBase)
50 //____________________________________________________________________________
51 AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
55 fRefOCDBSubDir(new TObjArray*[AliRecoParam::kNSpecies]),
58 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
62 fLowTestValue = new Float_t[AliQAv1::kNBIT] ;
63 fUpTestValue = new Float_t[AliQAv1::kNBIT] ;
64 fLowTestValue[AliQAv1::kINFO] = 0.5 ;
65 fUpTestValue[AliQAv1::kINFO] = 1.0 ;
66 fLowTestValue[AliQAv1::kWARNING] = 0.002 ;
67 fUpTestValue[AliQAv1::kWARNING] = 0.5 ;
68 fLowTestValue[AliQAv1::kERROR] = 0.0 ;
69 fUpTestValue[AliQAv1::kERROR] = 0.002 ;
70 fLowTestValue[AliQAv1::kFATAL] = -1.0 ;
71 fUpTestValue[AliQAv1::kFATAL] = 0.0 ;
73 AliDebug(AliQAv1::GetQADebugLevel(), "Default setting is:") ;
74 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
75 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",
76 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
77 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
78 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
79 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
80 AliInfo(Form("%s", text)) ;
83 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
84 fImage[specie] = NULL ;
85 fRefOCDBSubDir[specie] = NULL ;
89 //____________________________________________________________________________
90 AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
91 TNamed(qac.GetName(), qac.GetTitle()),
92 fDataSubDir(qac.fDataSubDir),
93 fRefSubDir(qac.fRefSubDir),
94 fRefOCDBSubDir(qac.fRefOCDBSubDir),
95 fLowTestValue(qac.fLowTestValue),
96 fUpTestValue(qac.fLowTestValue),
101 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
102 fLowTestValue[index] = qac.fLowTestValue[index] ;
103 fUpTestValue[index] = qac.fUpTestValue[index] ;
105 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
106 fImage[specie] = qac.fImage[specie] ;
107 fRefOCDBSubDir[specie] = qac.fRefOCDBSubDir[specie] ;
111 //____________________________________________________________________________
112 AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qac )
115 this->~AliQACheckerBase();
116 new(this) AliQACheckerBase(qac);
120 //____________________________________________________________________________
121 AliQACheckerBase::~AliQACheckerBase()
123 delete [] fLowTestValue ;
124 delete [] fUpTestValue ;
125 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
126 if ( fImage[esIndex] )
127 delete fImage[esIndex] ;
128 if ( fRefOCDBSubDir[esIndex] )
129 delete fRefOCDBSubDir[esIndex] ;
132 delete[] fRefOCDBSubDir ;
135 //____________________________________________________________________________
136 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam)
138 // Performs a basic checking
139 // Compares all the histograms stored in the directory
140 // With reference histograms either in a file of in OCDB
142 TObjArray ** list = new TObjArray *[AliRecoParam::kNSpecies] ;
144 for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
145 list[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
146 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
149 TList * keyList = fDataSubDir->GetListOfKeys() ;
150 TIter next(keyList) ;
152 while ( (key = static_cast<TKey *>(next())) ) {
153 TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ;
154 TList * keykeyList = specieDir->GetListOfKeys() ;
155 TIter next2(keykeyList) ;
157 while ( (keykey = static_cast<TKey *>(next2())) ) {
158 TObject * odata = specieDir->Get(keykey->GetName()) ;
159 if ( odata->IsA()->InheritsFrom("TH1") ) {
160 TH1 * hdata = static_cast<TH1*>(odata) ;
161 list[specie]->Add(hdata) ;
162 } else if (!odata->IsA()->InheritsFrom("TDirectory")) // skip the expert directory
163 AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
169 Double_t * test = Check(index, list, recoParam) ;
176 //____________________________________________________________________________
177 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list, AliDetectorRecoParam * recoParam)
179 // Performs a basic checking
180 // Compares all the histograms in the list
182 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
183 Int_t count[AliRecoParam::kNSpecies] = { 0 };
185 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
187 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
189 if (list[specie]->GetEntries() == 0)
190 test[specie] = 0. ; // nothing to check
192 if (!fRefSubDir && !fRefOCDBSubDir)
193 test[specie] = -1 ; // no reference data
195 TIter next(list[specie]) ;
198 while ( (hdata = static_cast<TH1 *>(next())) ) {
199 TString cln(hdata->ClassName()) ;
200 if ( cln.Contains("TH1") ) {
202 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
206 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
207 else if (fRefOCDBSubDir[specie])
208 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
210 test[specie] = -1 ; // no reference data ;
212 Double_t rv = DiffK(hdata, href) ;
213 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
219 AliError("Data type cannot be processed") ;
220 if (count[specie] != 0)
221 test[specie] /= count[specie] ;
230 //____________________________________________________________________________
231 Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
233 // compares two histograms using the Chi2 test
234 if ( hin->Integral() == 0 ) {
235 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
239 return hin->Chi2Test(href) ;
242 //____________________________________________________________________________
243 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
245 // compares two histograms using the Kolmogorov test
246 if ( hin->Integral() == 0 || href->Integral() == 0) {
247 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
251 return hin->KolmogorovTest(href) ;
254 //____________________________________________________________________________
255 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam)
257 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
259 Double_t * rv = NULL ;
260 rv = Check(index, recoParam) ;
263 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
270 //____________________________________________________________________________
271 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list, AliDetectorRecoParam * recoParam)
273 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
275 Double_t * rv = NULL ;
276 rv = Check(index, list, recoParam) ;
279 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
286 //____________________________________________________________________________
287 void AliQACheckerBase::Finish() const
289 // wrap up and save QA in proper file
290 AliQAv1 * qa = AliQAv1::Instance() ;
292 AliQAv1::GetQAResultFile()->cd() ;
293 qa->Write(qa->GetName(), kWriteDelete) ;
294 AliQAv1::GetQAResultFile()->Close() ;
297 //____________________________________________________________________________
298 void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
300 // makes the QA image for sim and rec
302 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
303 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
305 TIter next(list[esIndex]) ;
307 while ( (hdata=static_cast<TH1 *>(next())) ) {
308 TString cln(hdata->ClassName()) ;
309 if ( ! cln.Contains("TH") )
311 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
316 if ( nImages == 0 ) {
317 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
319 AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;
320 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
321 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0)
323 const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ;
324 if ( !fImage[esIndex] ) {
325 fImage[esIndex] = new TCanvas(title, title) ;
327 fImage[esIndex]->Clear() ;
328 fImage[esIndex]->SetTitle(title) ;
329 fImage[esIndex]->cd() ;
330 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
331 someText.AddText(title) ;
333 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
334 fImage[esIndex]->Clear() ;
335 Int_t nx = TMath::Sqrt(nImages) ;
337 while ( nx*ny <= nImages)
340 fImage[esIndex]->Divide(nx, ny) ;
341 TIter nexthist(list[esIndex]) ;
344 fImage[esIndex]->cd(npad) ;
345 while ( (hist=static_cast<TH1*>(nexthist())) ) {
346 TString cln(hist->ClassName()) ;
347 if ( ! cln.Contains("TH") )
349 if(hist->TestBit(AliQAv1::GetImageBit())) {
351 fImage[esIndex]->cd(++npad) ;
354 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
359 //____________________________________________________________________________
360 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
362 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
363 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
364 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",
365 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
366 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
367 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
368 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
369 AliInfo(Form("%s", text)) ;
372 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
373 fLowTestValue[index] = lowValue[index] ;
374 fUpTestValue[index] = hiValue[index] ;
376 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
377 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
378 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",
379 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
380 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
381 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
382 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; AliInfo(Form("%s", text)) ;
386 //____________________________________________________________________________
387 void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
389 // sets the QA according the return value of the Check
391 AliQAv1 * qa = AliQAv1::Instance(index) ;
392 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
393 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
394 qa->Set(AliQAv1::kFATAL, specie) ;
396 if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] )
397 qa->Set(AliQAv1::kFATAL, specie) ;
398 else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR] )
399 qa->Set(AliQAv1::kERROR, specie) ;
400 else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING] )
401 qa->Set(AliQAv1::kWARNING, specie) ;
402 else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] )
403 qa->Set(AliQAv1::kINFO, specie) ;