]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQACheckerBase.cxx
change TH1 status bit for expert, QA and image that were overlapping with other TH1...
[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"
c26cb20d 45#include "AliDetectorRecoParam.h"
421ab0fb 46
2e42b4d4 47ClassImp(AliQACheckerBase)
421ab0fb 48
49
50//____________________________________________________________________________
2e42b4d4 51AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
421ab0fb 52 TNamed(name, title),
a5fa6165 53 fDataSubDir(0x0),
4edbc5bc 54 fRefSubDir(0x0),
aa2beccb 55 fRefOCDBSubDir(new TObjArray*[AliRecoParam::kNSpecies]),
57acd2d2 56 fLowTestValue(0x0),
634696f5 57 fUpTestValue(0x0),
58 fImage(new TCanvas*[AliRecoParam::kNSpecies]),
59 fPrintImage(kTRUE)
421ab0fb 60{
61 // ctor
4e25ac79 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 ;
57acd2d2 72
5379c4a3 73 AliDebug(AliQAv1::GetQADebugLevel(), "Default setting is:") ;
74 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 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)) ;
5379c4a3 81 }
634696f5 82
aa2beccb 83 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
634696f5 84 fImage[specie] = NULL ;
aa2beccb 85 fRefOCDBSubDir[specie] = NULL ;
86 }
421ab0fb 87}
88
89//____________________________________________________________________________
4edbc5bc 90AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
91 TNamed(qac.GetName(), qac.GetTitle()),
92 fDataSubDir(qac.fDataSubDir),
93 fRefSubDir(qac.fRefSubDir),
57acd2d2 94 fRefOCDBSubDir(qac.fRefOCDBSubDir),
95 fLowTestValue(qac.fLowTestValue),
634696f5 96 fUpTestValue(qac.fLowTestValue),
97 fImage(NULL),
98 fPrintImage(kTRUE)
421ab0fb 99{
100 //copy ctor
4e25ac79 101 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 102 fLowTestValue[index] = qac.fLowTestValue[index] ;
103 fUpTestValue[index] = qac.fUpTestValue[index] ;
104 }
aa2beccb 105 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
106 fImage[specie] = qac.fImage[specie] ;
107 fRefOCDBSubDir[specie] = qac.fRefOCDBSubDir[specie] ;
108 }
421ab0fb 109}
110
111//____________________________________________________________________________
634696f5 112AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qac )
421ab0fb 113{
114 // Equal operator.
2e42b4d4 115 this->~AliQACheckerBase();
634696f5 116 new(this) AliQACheckerBase(qac);
421ab0fb 117 return *this;
118}
119
57acd2d2 120//____________________________________________________________________________
121AliQACheckerBase::~AliQACheckerBase()
122{
123 delete [] fLowTestValue ;
124 delete [] fUpTestValue ;
634696f5 125 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
126 if ( fImage[esIndex] )
127 delete fImage[esIndex] ;
aa2beccb 128 if ( fRefOCDBSubDir[esIndex] )
129 delete fRefOCDBSubDir[esIndex] ;
634696f5 130 }
131 delete[] fImage ;
aa2beccb 132 delete[] fRefOCDBSubDir ;
57acd2d2 133}
134
a5fa6165 135//____________________________________________________________________________
c26cb20d 136Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam)
a5fa6165 137{
138 // Performs a basic checking
139 // Compares all the histograms stored in the directory
4edbc5bc 140 // With reference histograms either in a file of in OCDB
a5fa6165 141
ed448a70 142 TObjArray ** list = new TObjArray *[AliRecoParam::kNSpecies] ;
c39ee44c 143 Int_t specie ;
144 for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
ed448a70 145 list[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 146 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
57acd2d2 147 continue ;
c39ee44c 148 if (fDataSubDir) {
ed448a70 149 TList * keyList = fDataSubDir->GetListOfKeys() ;
150 TIter next(keyList) ;
151 TKey * key ;
152 while ( (key = static_cast<TKey *>(next())) ) {
153 TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ;
154 TList * keykeyList = specieDir->GetListOfKeys() ;
155 TIter next2(keykeyList) ;
156 TKey * keykey ;
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())) ;
c39ee44c 164 }
57acd2d2 165 }
57acd2d2 166 }
167 }
ed448a70 168
c26cb20d 169 Double_t * test = Check(index, list, recoParam) ;
ed448a70 170
171 delete[] list ;
172
c39ee44c 173 return test ;
a5fa6165 174}
175
a4976ef3 176//____________________________________________________________________________
0f0c06de 177Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list, AliDetectorRecoParam * /*recoParam*/)
a4976ef3 178{
179 // Performs a basic checking
180 // Compares all the histograms in the list
181
57acd2d2 182 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
183 Int_t count[AliRecoParam::kNSpecies] = { 0 };
184
185 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
186 test[specie] = 1.0 ;
6252ceeb 187 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
57acd2d2 188 continue ;
189 if (list[specie]->GetEntries() == 0)
190 test[specie] = 0. ; // nothing to check
191 else {
192 if (!fRefSubDir && !fRefOCDBSubDir)
193 test[specie] = -1 ; // no reference data
194 else {
195 TIter next(list[specie]) ;
196 TH1 * hdata ;
197 count[specie] = 0 ;
eca4fa66 198 while ( (hdata = static_cast<TH1 *>(next())) ) {
199 TString cln(hdata->ClassName()) ;
c39ee44c 200 if ( cln.Contains("TH1") ) {
201 if ( hdata) {
202 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
203 continue ;
204 TH1 * href = NULL ;
205 if (fRefSubDir)
206 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
207 else if (fRefOCDBSubDir[specie])
208 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
209 if (!href)
210 test[specie] = -1 ; // no reference data ;
211 else {
212 Double_t rv = DiffK(hdata, href) ;
213 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
214 test[specie] += rv ;
215 count[specie]++ ;
216 }
57acd2d2 217 }
c39ee44c 218 } else
57acd2d2 219 AliError("Data type cannot be processed") ;
c39ee44c 220 if (count[specie] != 0)
221 test[specie] /= count[specie] ;
57acd2d2 222 }
57acd2d2 223 }
224 }
225 }
c39ee44c 226 return test ;
a4976ef3 227}
228
57acd2d2 229
421ab0fb 230//____________________________________________________________________________
f12d42ce 231Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
421ab0fb 232{
233 // compares two histograms using the Chi2 test
234 if ( hin->Integral() == 0 ) {
5379c4a3 235 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
421ab0fb 236 return 0. ;
237 }
238
239 return hin->Chi2Test(href) ;
240}
241
242//____________________________________________________________________________
f12d42ce 243Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
421ab0fb 244{
245 // compares two histograms using the Kolmogorov test
6252ceeb 246 if ( hin->Integral() == 0 || href->Integral() == 0) {
247 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
421ab0fb 248 return 0. ;
249 }
250
251 return hin->KolmogorovTest(href) ;
252}
253
c39ee44c 254//____________________________________________________________________________
c26cb20d 255void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam)
c39ee44c 256{
257 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
258
259 Double_t * rv = NULL ;
c26cb20d 260 rv = Check(index, recoParam) ;
c39ee44c 261 SetQA(index, rv) ;
262
263 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
264
265 if (rv)
266 delete [] rv ;
267 Finish() ;
268}
269
421ab0fb 270//____________________________________________________________________________
c26cb20d 271void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list, AliDetectorRecoParam * recoParam)
421ab0fb 272{
5379c4a3 273 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
a2b64fbd 274
57acd2d2 275 Double_t * rv = NULL ;
c26cb20d 276 rv = Check(index, list, recoParam) ;
a2b64fbd 277 SetQA(index, rv) ;
46b8a84d 278
5379c4a3 279 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
46b8a84d 280
57acd2d2 281 if (rv)
282 delete [] rv ;
a2b64fbd 283 Finish() ;
421ab0fb 284}
285
286//____________________________________________________________________________
2e42b4d4 287void AliQACheckerBase::Finish() const
421ab0fb 288{
54a7f3ac 289 // wrap up and save QA in proper file
4e25ac79 290 AliQAv1 * qa = AliQAv1::Instance() ;
bf76b847 291 //qa->Show() ;
4e25ac79 292 AliQAv1::GetQAResultFile()->cd() ;
54a7f3ac 293 qa->Write(qa->GetName(), kWriteDelete) ;
4e25ac79 294 AliQAv1::GetQAResultFile()->Close() ;
421ab0fb 295}
46b8a84d 296
634696f5 297//____________________________________________________________________________
298void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
299{
300 // makes the QA image for sim and rec
301 Int_t nImages = 0 ;
302 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
303 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
304 continue ;
305 TIter next(list[esIndex]) ;
306 TH1 * hdata = NULL ;
307 while ( (hdata=static_cast<TH1 *>(next())) ) {
308 TString cln(hdata->ClassName()) ;
df6856f0 309 if ( ! cln.Contains("TH") )
634696f5 310 continue ;
311 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
312 nImages++;
313 }
314 break ;
315 }
316 if ( nImages == 0 ) {
317 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
318 } else {
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++) {
4851e489 321 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0)
634696f5 322 continue ;
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) ;
326 }
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) ;
332 someText.Draw() ;
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) ;
336 Int_t ny = nx ;
df6856f0 337 while ( nx*ny <= nImages)
634696f5 338 ny++ ;
df6856f0 339
634696f5 340 fImage[esIndex]->Divide(nx, ny) ;
341 TIter nexthist(list[esIndex]) ;
342 TH1* hist = NULL ;
343 Int_t npad = 1 ;
344 fImage[esIndex]->cd(npad) ;
345 while ( (hist=static_cast<TH1*>(nexthist())) ) {
346 TString cln(hist->ClassName()) ;
df6856f0 347 if ( ! cln.Contains("TH") )
634696f5 348 continue ;
349 if(hist->TestBit(AliQAv1::GetImageBit())) {
350 hist->Draw() ;
351 fImage[esIndex]->cd(++npad) ;
352 }
353 }
354 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
355 }
356 }
357}
358
46b8a84d 359//____________________________________________________________________________
57acd2d2 360void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
46b8a84d 361{
5379c4a3 362 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
363 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 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)) ;
5379c4a3 370 }
57acd2d2 371
4e25ac79 372 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 373 fLowTestValue[index] = lowValue[index] ;
eca4fa66 374 fUpTestValue[index] = hiValue[index] ;
57acd2d2 375 }
5379c4a3 376 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
377 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 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)) ;
5379c4a3 383 }
57acd2d2 384}
46b8a84d 385
57acd2d2 386//____________________________________________________________________________
4e25ac79 387void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
57acd2d2 388{
389 // sets the QA according the return value of the Check
46b8a84d 390
4e25ac79 391 AliQAv1 * qa = AliQAv1::Instance(index) ;
57acd2d2 392 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
393 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
4e25ac79 394 qa->Set(AliQAv1::kFATAL, specie) ;
57acd2d2 395 } else {
4e25ac79 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) ;
57acd2d2 404 }
405 }
46b8a84d 406}