]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQACheckerBase.cxx
Bug fix in copy constructor and assignement operator (Matthias + me)
[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 ;
5d1a2a7d 133 AliQAv1::GetQAResultFile()->Close() ;
57acd2d2 134}
135
a5fa6165 136//____________________________________________________________________________
c26cb20d 137Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam)
a5fa6165 138{
139 // Performs a basic checking
140 // Compares all the histograms stored in the directory
4edbc5bc 141 // With reference histograms either in a file of in OCDB
a5fa6165 142
ed448a70 143 TObjArray ** list = new TObjArray *[AliRecoParam::kNSpecies] ;
c39ee44c 144 Int_t specie ;
145 for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
ed448a70 146 list[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 147 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
57acd2d2 148 continue ;
c39ee44c 149 if (fDataSubDir) {
ed448a70 150 TList * keyList = fDataSubDir->GetListOfKeys() ;
151 TIter next(keyList) ;
152 TKey * key ;
153 while ( (key = static_cast<TKey *>(next())) ) {
154 TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ;
155 TList * keykeyList = specieDir->GetListOfKeys() ;
156 TIter next2(keykeyList) ;
157 TKey * keykey ;
158 while ( (keykey = static_cast<TKey *>(next2())) ) {
159 TObject * odata = specieDir->Get(keykey->GetName()) ;
160 if ( odata->IsA()->InheritsFrom("TH1") ) {
161 TH1 * hdata = static_cast<TH1*>(odata) ;
162 list[specie]->Add(hdata) ;
163 } else if (!odata->IsA()->InheritsFrom("TDirectory")) // skip the expert directory
164 AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
c39ee44c 165 }
57acd2d2 166 }
57acd2d2 167 }
168 }
ed448a70 169
c26cb20d 170 Double_t * test = Check(index, list, recoParam) ;
ed448a70 171
172 delete[] list ;
173
c39ee44c 174 return test ;
a5fa6165 175}
176
a4976ef3 177//____________________________________________________________________________
0f0c06de 178Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list, AliDetectorRecoParam * /*recoParam*/)
a4976ef3 179{
180 // Performs a basic checking
181 // Compares all the histograms in the list
182
57acd2d2 183 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
184 Int_t count[AliRecoParam::kNSpecies] = { 0 };
185
186 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
187 test[specie] = 1.0 ;
6252ceeb 188 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
57acd2d2 189 continue ;
190 if (list[specie]->GetEntries() == 0)
191 test[specie] = 0. ; // nothing to check
192 else {
193 if (!fRefSubDir && !fRefOCDBSubDir)
194 test[specie] = -1 ; // no reference data
195 else {
196 TIter next(list[specie]) ;
197 TH1 * hdata ;
198 count[specie] = 0 ;
eca4fa66 199 while ( (hdata = static_cast<TH1 *>(next())) ) {
ab1bb842 200 if ( hdata->IsA()->InheritsFrom("TH1") ) {
7775195b 201 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
202 continue ;
203 TH1 * href = NULL ;
204 if (fRefSubDir)
205 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
206 else if (fRefOCDBSubDir[specie])
207 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
208 if (!href)
209 test[specie] = -1 ; // no reference data ;
210 else {
211 Double_t rv = DiffK(hdata, href) ;
212 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
213 test[specie] += rv ;
214 count[specie]++ ;
57acd2d2 215 }
c39ee44c 216 } else
57acd2d2 217 AliError("Data type cannot be processed") ;
c39ee44c 218 if (count[specie] != 0)
219 test[specie] /= count[specie] ;
57acd2d2 220 }
57acd2d2 221 }
222 }
223 }
c39ee44c 224 return test ;
a4976ef3 225}
226
57acd2d2 227
421ab0fb 228//____________________________________________________________________________
f12d42ce 229Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
421ab0fb 230{
231 // compares two histograms using the Chi2 test
232 if ( hin->Integral() == 0 ) {
5379c4a3 233 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
421ab0fb 234 return 0. ;
235 }
236
237 return hin->Chi2Test(href) ;
238}
239
240//____________________________________________________________________________
f12d42ce 241Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
421ab0fb 242{
243 // compares two histograms using the Kolmogorov test
6252ceeb 244 if ( hin->Integral() == 0 || href->Integral() == 0) {
245 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ;
421ab0fb 246 return 0. ;
247 }
248
249 return hin->KolmogorovTest(href) ;
250}
251
c39ee44c 252//____________________________________________________________________________
c26cb20d 253void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam)
c39ee44c 254{
255 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
256
257 Double_t * rv = NULL ;
c26cb20d 258 rv = Check(index, recoParam) ;
c39ee44c 259 SetQA(index, rv) ;
260
261 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
262
263 if (rv)
264 delete [] rv ;
265 Finish() ;
266}
267
421ab0fb 268//____________________________________________________________________________
c26cb20d 269void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list, AliDetectorRecoParam * recoParam)
421ab0fb 270{
5379c4a3 271 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
a2b64fbd 272
57acd2d2 273 Double_t * rv = NULL ;
c26cb20d 274 rv = Check(index, list, recoParam) ;
a2b64fbd 275 SetQA(index, rv) ;
46b8a84d 276
5379c4a3 277 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
46b8a84d 278
57acd2d2 279 if (rv)
280 delete [] rv ;
a2b64fbd 281 Finish() ;
421ab0fb 282}
283
284//____________________________________________________________________________
2e42b4d4 285void AliQACheckerBase::Finish() const
421ab0fb 286{
54a7f3ac 287 // wrap up and save QA in proper file
5d1a2a7d 288 AliQAv1::GetQAResultFile() ;
4e25ac79 289 AliQAv1 * qa = AliQAv1::Instance() ;
5d1a2a7d 290 qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;
421ab0fb 291}
46b8a84d 292
634696f5 293//____________________________________________________________________________
294void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
295{
296 // makes the QA image for sim and rec
297 Int_t nImages = 0 ;
298 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
299 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) )
300 continue ;
301 TIter next(list[esIndex]) ;
302 TH1 * hdata = NULL ;
303 while ( (hdata=static_cast<TH1 *>(next())) ) {
304 TString cln(hdata->ClassName()) ;
df6856f0 305 if ( ! cln.Contains("TH") )
634696f5 306 continue ;
307 if ( hdata->TestBit(AliQAv1::GetImageBit()) )
308 nImages++;
309 }
310 break ;
311 }
312 if ( nImages == 0 ) {
313 AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;
314 } else {
315 AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;
316 for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
4851e489 317 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0)
634696f5 318 continue ;
319 const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ;
320 if ( !fImage[esIndex] ) {
321 fImage[esIndex] = new TCanvas(title, title) ;
322 }
323 fImage[esIndex]->Clear() ;
324 fImage[esIndex]->SetTitle(title) ;
325 fImage[esIndex]->cd() ;
326 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
327 someText.AddText(title) ;
328 someText.Draw() ;
329 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
330 fImage[esIndex]->Clear() ;
331 Int_t nx = TMath::Sqrt(nImages) ;
332 Int_t ny = nx ;
df6856f0 333 while ( nx*ny <= nImages)
634696f5 334 ny++ ;
df6856f0 335
634696f5 336 fImage[esIndex]->Divide(nx, ny) ;
337 TIter nexthist(list[esIndex]) ;
338 TH1* hist = NULL ;
339 Int_t npad = 1 ;
340 fImage[esIndex]->cd(npad) ;
341 while ( (hist=static_cast<TH1*>(nexthist())) ) {
342 TString cln(hist->ClassName()) ;
df6856f0 343 if ( ! cln.Contains("TH") )
634696f5 344 continue ;
345 if(hist->TestBit(AliQAv1::GetImageBit())) {
346 hist->Draw() ;
347 fImage[esIndex]->cd(++npad) ;
348 }
349 }
350 fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ;
351 }
352 }
353}
354
46b8a84d 355//____________________________________________________________________________
57acd2d2 356void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
46b8a84d 357{
5379c4a3 358 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
359 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 360 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",
361 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
362 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
363 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
364 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
365 AliInfo(Form("%s", text)) ;
5379c4a3 366 }
57acd2d2 367
4e25ac79 368 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 369 fLowTestValue[index] = lowValue[index] ;
eca4fa66 370 fUpTestValue[index] = hiValue[index] ;
57acd2d2 371 }
5379c4a3 372 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
373 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 374 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",
375 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
376 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
377 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
378 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; AliInfo(Form("%s", text)) ;
5379c4a3 379 }
57acd2d2 380}
46b8a84d 381
57acd2d2 382//____________________________________________________________________________
4e25ac79 383void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
57acd2d2 384{
385 // sets the QA according the return value of the Check
46b8a84d 386
4e25ac79 387 AliQAv1 * qa = AliQAv1::Instance(index) ;
d5b176f5 388
57acd2d2 389 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
d5b176f5 390 if (! qa->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)))
391 continue ;
57acd2d2 392 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
4e25ac79 393 qa->Set(AliQAv1::kFATAL, specie) ;
57acd2d2 394 } else {
4e25ac79 395 if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] )
b872fee3 396 qa->Set(AliQAv1::kFATAL, AliRecoParam::ConvertIndex(specie)) ;
4e25ac79 397 else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR] )
b872fee3 398 qa->Set(AliQAv1::kERROR, AliRecoParam::ConvertIndex(specie)) ;
4e25ac79 399 else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING] )
b872fee3 400 qa->Set(AliQAv1::kWARNING, AliRecoParam::ConvertIndex(specie)) ;
4e25ac79 401 else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] )
b872fee3 402 qa->Set(AliQAv1::kINFO, AliRecoParam::ConvertIndex(specie)) ;
57acd2d2 403 }
404 }
46b8a84d 405}