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