]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQACheckerBase.cxx
Moving the GRP reco-param object from the reconstruction macros to OCDB.
[u/mrichter/AliRoot.git] / STEER / AliQACheckerBase.cxx
CommitLineData
421ab0fb 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17/* $Id$ */
18
202374b1 19//
20// Base class for detectors quality assurance checkers
21// Compares Data made by QADataMakers with reference data
22// Y. Schutz CERN August 2007
23//
421ab0fb 24
25// --- ROOT system ---
634696f5 26#include <TCanvas.h>
421ab0fb 27#include <TClass.h>
28#include <TH1F.h>
29#include <TH1I.h>
30#include <TIterator.h>
31#include <TKey.h>
32#include <TFile.h>
a4976ef3 33#include <TList.h>
a2b64fbd 34#include <TNtupleD.h>
634696f5 35#include <TPaveText.h>
421ab0fb 36
37// --- Standard library ---
38
39// --- AliRoot header files ---
40#include "AliLog.h"
4e25ac79 41#include "AliQAv1.h"
2e42b4d4 42#include "AliQAChecker.h"
43#include "AliQACheckerBase.h"
44#include "AliQADataMaker.h"
421ab0fb 45
2e42b4d4 46ClassImp(AliQACheckerBase)
421ab0fb 47
48
49//____________________________________________________________________________
2e42b4d4 50AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
421ab0fb 51 TNamed(name, title),
a5fa6165 52 fDataSubDir(0x0),
4edbc5bc 53 fRefSubDir(0x0),
aa2beccb 54 fRefOCDBSubDir(new TObjArray*[AliRecoParam::kNSpecies]),
57acd2d2 55 fLowTestValue(0x0),
634696f5 56 fUpTestValue(0x0),
57 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
58 fPrintImage(kTRUE)
421ab0fb 59{
60 // ctor
4e25ac79 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 ;
57acd2d2 71
5379c4a3 72 AliDebug(AliQAv1::GetQADebugLevel(), "Default setting is:") ;
73 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 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)) ;
5379c4a3 80 }
634696f5 81
aa2beccb 82 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
634696f5 83 fImage[specie] = NULL ;
aa2beccb 84 fRefOCDBSubDir[specie] = NULL ;
85 }
421ab0fb 86}
87
88//____________________________________________________________________________
4edbc5bc 89AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
90 TNamed(qac.GetName(), qac.GetTitle()),
91 fDataSubDir(qac.fDataSubDir),
92 fRefSubDir(qac.fRefSubDir),
57acd2d2 93 fRefOCDBSubDir(qac.fRefOCDBSubDir),
94 fLowTestValue(qac.fLowTestValue),
634696f5 95 fUpTestValue(qac.fLowTestValue),
96 fImage(NULL),
97 fPrintImage(kTRUE)
421ab0fb 98{
99 //copy ctor
4e25ac79 100 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 101 fLowTestValue[index] = qac.fLowTestValue[index] ;
102 fUpTestValue[index] = qac.fUpTestValue[index] ;
103 }
aa2beccb 104 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
105 fImage[specie] = qac.fImage[specie] ;
106 fRefOCDBSubDir[specie] = qac.fRefOCDBSubDir[specie] ;
107 }
421ab0fb 108}
109
110//____________________________________________________________________________
634696f5 111AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qac )
421ab0fb 112{
113 // Equal operator.
2e42b4d4 114 this->~AliQACheckerBase();
634696f5 115 new(this) AliQACheckerBase(qac);
421ab0fb 116 return *this;
117}
118
57acd2d2 119//____________________________________________________________________________
120AliQACheckerBase::~AliQACheckerBase()
121{
122 delete [] fLowTestValue ;
123 delete [] fUpTestValue ;
634696f5 124 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
125 if ( fImage[esIndex] )
126 delete fImage[esIndex] ;
aa2beccb 127 if ( fRefOCDBSubDir[esIndex] )
128 delete fRefOCDBSubDir[esIndex] ;
634696f5 129 }
130 delete[] fImage ;
aa2beccb 131 delete[] fRefOCDBSubDir ;
57acd2d2 132}
133
a5fa6165 134//____________________________________________________________________________
4e25ac79 135Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/)
a5fa6165 136{
137 // Performs a basic checking
138 // Compares all the histograms stored in the directory
4edbc5bc 139 // With reference histograms either in a file of in OCDB
a5fa6165 140
57acd2d2 141 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
142 Int_t count[AliRecoParam::kNSpecies] = { 0 };
143
c39ee44c 144 Int_t specie ;
145 for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
57acd2d2 146 test[specie] = 1.0 ;
4e25ac79 147 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
57acd2d2 148 continue ;
c39ee44c 149 if (fDataSubDir) {
150 if (!fRefSubDir && !fRefOCDBSubDir) {
57acd2d2 151 test[specie] = -1 ; // no reference data
c39ee44c 152 } else {
153 TList * keyList = fDataSubDir->GetListOfKeys() ;
154 TIter next(keyList) ;
155 TKey * key ;
156 while ( (key = static_cast<TKey *>(next())) ) {
157 TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ;
158 TList * keykeyList = specieDir->GetListOfKeys() ;
159 TIter next2(keykeyList) ;
160 TKey * keykey ;
161 count[specie] = 0 ;
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) ;
166 TH1 * href = NULL ;
167 if (fRefSubDir) {
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())) ;
172 }
173 if (!href)
174 test[specie] = -1 ; // no reference data ;
175 else {
176 Double_t rv = DiffK(hdata, href) ;
177 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
178 test[specie] += rv ;
179 count[specie]++ ;
180 }
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] ;
57acd2d2 185 }
c39ee44c 186 }
57acd2d2 187 }
57acd2d2 188 }
189 }
c39ee44c 190 return test ;
a5fa6165 191}
192
a4976ef3 193//____________________________________________________________________________
4e25ac79 194Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list)
a4976ef3 195{
196 // Performs a basic checking
197 // Compares all the histograms in the list
198
57acd2d2 199 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
200 Int_t count[AliRecoParam::kNSpecies] = { 0 };
201
202 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
203 test[specie] = 1.0 ;
6252ceeb 204 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
57acd2d2 205 continue ;
206 if (list[specie]->GetEntries() == 0)
207 test[specie] = 0. ; // nothing to check
208 else {
209 if (!fRefSubDir && !fRefOCDBSubDir)
210 test[specie] = -1 ; // no reference data
211 else {
212 TIter next(list[specie]) ;
213 TH1 * hdata ;
214 count[specie] = 0 ;
eca4fa66 215 while ( (hdata = static_cast<TH1 *>(next())) ) {
216 TString cln(hdata->ClassName()) ;
c39ee44c 217 if ( cln.Contains("TH1") ) {
218 if ( hdata) {
219 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
220 continue ;
221 TH1 * href = NULL ;
222 if (fRefSubDir)
223 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
224 else if (fRefOCDBSubDir[specie])
225 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
226 if (!href)
227 test[specie] = -1 ; // no reference data ;
228 else {
229 Double_t rv = DiffK(hdata, href) ;
230 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
231 test[specie] += rv ;
232 count[specie]++ ;
233 }
57acd2d2 234 }
c39ee44c 235 } else
57acd2d2 236 AliError("Data type cannot be processed") ;
c39ee44c 237 if (count[specie] != 0)
238 test[specie] /= count[specie] ;
57acd2d2 239 }
57acd2d2 240 }
241 }
242 }
c39ee44c 243 return test ;
a4976ef3 244}
245
57acd2d2 246
421ab0fb 247//____________________________________________________________________________
f12d42ce 248Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
421ab0fb 249{
250 // compares two histograms using the Chi2 test
251 if ( hin->Integral() == 0 ) {
5379c4a3 252 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
421ab0fb 253 return 0. ;
254 }
255
256 return hin->Chi2Test(href) ;
257}
258
259//____________________________________________________________________________
f12d42ce 260Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
421ab0fb 261{
262 // compares two histograms using the Kolmogorov test
6252ceeb 263 if ( hin->Integral() == 0 || href->Integral() == 0) {
264 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
421ab0fb 265 return 0. ;
266 }
267
268 return hin->KolmogorovTest(href) ;
269}
270
c39ee44c 271//____________________________________________________________________________
272void AliQACheckerBase::Run(AliQAv1::ALITASK_t index)
273{
274 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
275
276 Double_t * rv = NULL ;
277 rv = Check(index) ;
278 SetQA(index, rv) ;
279
280 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
281
282 if (rv)
283 delete [] rv ;
284 Finish() ;
285}
286
421ab0fb 287//____________________________________________________________________________
4e25ac79 288void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list)
421ab0fb 289{
5379c4a3 290 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
a2b64fbd 291
57acd2d2 292 Double_t * rv = NULL ;
c39ee44c 293 rv = Check(index, list) ;
a2b64fbd 294 SetQA(index, rv) ;
46b8a84d 295
5379c4a3 296 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
46b8a84d 297
57acd2d2 298 if (rv)
299 delete [] rv ;
a2b64fbd 300 Finish() ;
421ab0fb 301}
302
303//____________________________________________________________________________
2e42b4d4 304void AliQACheckerBase::Finish() const
421ab0fb 305{
54a7f3ac 306 // wrap up and save QA in proper file
4e25ac79 307 AliQAv1 * qa = AliQAv1::Instance() ;
bf76b847 308 //qa->Show() ;
4e25ac79 309 AliQAv1::GetQAResultFile()->cd() ;
54a7f3ac 310 qa->Write(qa->GetName(), kWriteDelete) ;
4e25ac79 311 AliQAv1::GetQAResultFile()->Close() ;
421ab0fb 312}
46b8a84d 313
634696f5 314//____________________________________________________________________________
315void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
316{
317 // makes the QA image for sim and rec
318 Int_t nImages = 0 ;
319 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
320 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
321 continue ;
322 TIter next(list[esIndex]) ;
323 TH1 * hdata = NULL ;
324 while ( (hdata=static_cast<TH1 *>(next())) ) {
325 TString cln(hdata->ClassName()) ;
df6856f0 326 if ( ! cln.Contains("TH") )
634696f5 327 continue ;
328 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
329 nImages++;
330 }
331 break ;
332 }
333 if ( nImages == 0 ) {
334 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
335 } else {
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++) {
4851e489 338 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0)
634696f5 339 continue ;
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) ;
343 }
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) ;
349 someText.Draw() ;
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) ;
353 Int_t ny = nx ;
df6856f0 354 while ( nx*ny <= nImages)
634696f5 355 ny++ ;
df6856f0 356
634696f5 357 fImage[esIndex]->Divide(nx, ny) ;
358 TIter nexthist(list[esIndex]) ;
359 TH1* hist = NULL ;
360 Int_t npad = 1 ;
361 fImage[esIndex]->cd(npad) ;
362 while ( (hist=static_cast<TH1*>(nexthist())) ) {
363 TString cln(hist->ClassName()) ;
df6856f0 364 if ( ! cln.Contains("TH") )
634696f5 365 continue ;
366 if(hist->TestBit(AliQAv1::GetImageBit())) {
367 hist->Draw() ;
368 fImage[esIndex]->cd(++npad) ;
369 }
370 }
371 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
372 }
373 }
374}
375
46b8a84d 376//____________________________________________________________________________
57acd2d2 377void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
46b8a84d 378{
5379c4a3 379 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
380 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 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)) ;
5379c4a3 387 }
57acd2d2 388
4e25ac79 389 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 390 fLowTestValue[index] = lowValue[index] ;
eca4fa66 391 fUpTestValue[index] = hiValue[index] ;
57acd2d2 392 }
5379c4a3 393 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
394 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 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)) ;
5379c4a3 400 }
57acd2d2 401}
46b8a84d 402
57acd2d2 403//____________________________________________________________________________
4e25ac79 404void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
57acd2d2 405{
406 // sets the QA according the return value of the Check
46b8a84d 407
4e25ac79 408 AliQAv1 * qa = AliQAv1::Instance(index) ;
57acd2d2 409 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
410 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
4e25ac79 411 qa->Set(AliQAv1::kFATAL, specie) ;
57acd2d2 412 } else {
4e25ac79 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) ;
57acd2d2 421 }
422 }
46b8a84d 423}