1.The QA data created on demand according to the event species at filling time. 2...
[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 ---
26#include <TClass.h>
27#include <TH1F.h>
28#include <TH1I.h>
29#include <TIterator.h>
30#include <TKey.h>
31#include <TFile.h>
a4976ef3 32#include <TList.h>
a2b64fbd 33#include <TNtupleD.h>
421ab0fb 34
35// --- Standard library ---
36
37// --- AliRoot header files ---
38#include "AliLog.h"
4e25ac79 39#include "AliQAv1.h"
2e42b4d4 40#include "AliQAChecker.h"
41#include "AliQACheckerBase.h"
42#include "AliQADataMaker.h"
421ab0fb 43
2e42b4d4 44ClassImp(AliQACheckerBase)
421ab0fb 45
46
47//____________________________________________________________________________
2e42b4d4 48AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
421ab0fb 49 TNamed(name, title),
a5fa6165 50 fDataSubDir(0x0),
4edbc5bc 51 fRefSubDir(0x0),
57acd2d2 52 fRefOCDBSubDir(0x0),
53 fLowTestValue(0x0),
54 fUpTestValue(0x0)
421ab0fb 55{
56 // ctor
4e25ac79 57 fLowTestValue = new Float_t[AliQAv1::kNBIT] ;
58 fUpTestValue = new Float_t[AliQAv1::kNBIT] ;
59 fLowTestValue[AliQAv1::kINFO] = 0.5 ;
60 fUpTestValue[AliQAv1::kINFO] = 1.0 ;
61 fLowTestValue[AliQAv1::kWARNING] = 0.002 ;
62 fUpTestValue[AliQAv1::kWARNING] = 0.5 ;
63 fLowTestValue[AliQAv1::kERROR] = 0.0 ;
64 fUpTestValue[AliQAv1::kERROR] = 0.002 ;
65 fLowTestValue[AliQAv1::kFATAL] = -1.0 ;
66 fUpTestValue[AliQAv1::kFATAL] = 0.0 ;
57acd2d2 67
5379c4a3 68 AliDebug(AliQAv1::GetQADebugLevel(), "Default setting is:") ;
69 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 70 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",
71 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
72 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
73 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
74 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
75 AliInfo(Form("%s", text)) ;
5379c4a3 76 }
421ab0fb 77}
78
79//____________________________________________________________________________
4edbc5bc 80AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
81 TNamed(qac.GetName(), qac.GetTitle()),
82 fDataSubDir(qac.fDataSubDir),
83 fRefSubDir(qac.fRefSubDir),
57acd2d2 84 fRefOCDBSubDir(qac.fRefOCDBSubDir),
85 fLowTestValue(qac.fLowTestValue),
86 fUpTestValue(qac.fLowTestValue)
421ab0fb 87{
88 //copy ctor
4e25ac79 89 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 90 fLowTestValue[index] = qac.fLowTestValue[index] ;
91 fUpTestValue[index] = qac.fUpTestValue[index] ;
92 }
421ab0fb 93
94}
95
96//____________________________________________________________________________
2e42b4d4 97AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
421ab0fb 98{
99 // Equal operator.
2e42b4d4 100 this->~AliQACheckerBase();
101 new(this) AliQACheckerBase(qadm);
421ab0fb 102 return *this;
103}
104
57acd2d2 105//____________________________________________________________________________
106AliQACheckerBase::~AliQACheckerBase()
107{
108 delete [] fLowTestValue ;
109 delete [] fUpTestValue ;
110}
111
a5fa6165 112//____________________________________________________________________________
4e25ac79 113Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/)
a5fa6165 114{
115 // Performs a basic checking
116 // Compares all the histograms stored in the directory
4edbc5bc 117 // With reference histograms either in a file of in OCDB
a5fa6165 118
57acd2d2 119 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
120 Int_t count[AliRecoParam::kNSpecies] = { 0 };
121
122 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
123 test[specie] = 1.0 ;
4e25ac79 124 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
57acd2d2 125 continue ;
126 if (!fDataSubDir) {
127 test[specie] = 0. ; // nothing to check
128 } else if (!fRefSubDir && !fRefOCDBSubDir) {
129 test[specie] = -1 ; // no reference data
130 } else {
131 TList * keyList = fDataSubDir->GetListOfKeys() ;
132 TIter next(keyList) ;
133 TKey * key ;
134 count[specie] = 0 ;
135 while ( (key = static_cast<TKey *>(next())) ) {
136 TObject * odata = fRefSubDir->Get(key->GetName()) ;
137 if ( odata->IsA()->InheritsFrom("TH1") ) {
138 TH1 * hdata = static_cast<TH1*>(odata) ;
139 TH1 * href = NULL ;
140 if (fRefSubDir)
141 href = static_cast<TH1*>(fRefSubDir->Get(key->GetName())) ;
142 else if (fRefOCDBSubDir[specie]) {
143 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(key->GetName())) ;
144 }
145 if (!href)
146 test[specie] = -1 ; // no reference data ;
147 else {
148 Double_t rv = DiffK(hdata, href) ;
5379c4a3 149 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
57acd2d2 150 test[specie] += rv ;
151 count[specie]++ ;
152 }
153 } else
154 AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
155 }
156 if (count[specie] != 0)
157 test[specie] /= count[specie] ;
158 }
159 }
160 return test ;
a5fa6165 161}
162
a4976ef3 163//____________________________________________________________________________
4e25ac79 164Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list)
a4976ef3 165{
166 // Performs a basic checking
167 // Compares all the histograms in the list
168
57acd2d2 169 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
170 Int_t count[AliRecoParam::kNSpecies] = { 0 };
171
172 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
173 test[specie] = 1.0 ;
4e25ac79 174 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
57acd2d2 175 continue ;
176 if (list[specie]->GetEntries() == 0)
177 test[specie] = 0. ; // nothing to check
178 else {
179 if (!fRefSubDir && !fRefOCDBSubDir)
180 test[specie] = -1 ; // no reference data
181 else {
182 TIter next(list[specie]) ;
183 TH1 * hdata ;
184 count[specie] = 0 ;
eca4fa66 185 while ( (hdata = static_cast<TH1 *>(next())) ) {
186 TString cln(hdata->ClassName()) ;
187 if ( ! cln.Contains("TH1") )
188 continue ;
57acd2d2 189 if ( hdata) {
4e25ac79 190 if ( hdata->TestBit(AliQAv1::GetExpertBit()) ) // does not perform the test for expert data
57acd2d2 191 continue ;
192 TH1 * href = NULL ;
193 if (fRefSubDir)
194 href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
195 else if (fRefOCDBSubDir[specie])
196 href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ;
197 if (!href)
198 test[specie] = -1 ; // no reference data ;
199 else {
200 Double_t rv = DiffK(hdata, href) ;
5379c4a3 201 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ;
57acd2d2 202 test[specie] += rv ;
203 count[specie]++ ;
204 }
205 }
206 else
207 AliError("Data type cannot be processed") ;
208 }
209 if (count[specie] != 0)
210 test[specie] /= count[specie] ;
211 }
212 }
213 }
4edbc5bc 214 return test ;
a4976ef3 215}
216
57acd2d2 217
421ab0fb 218//____________________________________________________________________________
f12d42ce 219Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
421ab0fb 220{
221 // compares two histograms using the Chi2 test
222 if ( hin->Integral() == 0 ) {
5379c4a3 223 AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ;
421ab0fb 224 return 0. ;
225 }
226
227 return hin->Chi2Test(href) ;
228}
229
230//____________________________________________________________________________
f12d42ce 231Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
421ab0fb 232{
233 // compares two histograms using the Kolmogorov 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->KolmogorovTest(href) ;
240}
241
421ab0fb 242//____________________________________________________________________________
4e25ac79 243void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list)
421ab0fb 244{
5379c4a3 245 AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ;
a2b64fbd 246
57acd2d2 247 Double_t * rv = NULL ;
248 if ( !list)
a2b64fbd 249 rv = Check(index) ;
57acd2d2 250 else
251 rv = Check(index, list) ;
a2b64fbd 252 SetQA(index, rv) ;
46b8a84d 253
5379c4a3 254 AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
46b8a84d 255
57acd2d2 256 if (rv)
257 delete [] rv ;
a2b64fbd 258 Finish() ;
421ab0fb 259}
260
261//____________________________________________________________________________
2e42b4d4 262void AliQACheckerBase::Finish() const
421ab0fb 263{
54a7f3ac 264 // wrap up and save QA in proper file
4e25ac79 265 AliQAv1 * qa = AliQAv1::Instance() ;
54a7f3ac 266 qa->Show() ;
4e25ac79 267 AliQAv1::GetQAResultFile()->cd() ;
54a7f3ac 268 qa->Write(qa->GetName(), kWriteDelete) ;
4e25ac79 269 AliQAv1::GetQAResultFile()->Close() ;
421ab0fb 270}
46b8a84d 271
272//____________________________________________________________________________
57acd2d2 273void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue)
46b8a84d 274{
5379c4a3 275 AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
276 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 277 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",
278 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
279 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
280 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
281 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;
282 AliInfo(Form("%s", text)) ;
5379c4a3 283 }
57acd2d2 284
4e25ac79 285 for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
57acd2d2 286 fLowTestValue[index] = lowValue[index] ;
eca4fa66 287 fUpTestValue[index] = hiValue[index] ;
57acd2d2 288 }
5379c4a3 289 AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
290 if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
eca4fa66 291 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",
292 fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO],
293 fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING],
294 fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR],
295 fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; AliInfo(Form("%s", text)) ;
5379c4a3 296 }
57acd2d2 297}
46b8a84d 298
57acd2d2 299//____________________________________________________________________________
4e25ac79 300void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
57acd2d2 301{
302 // sets the QA according the return value of the Check
46b8a84d 303
4e25ac79 304 AliQAv1 * qa = AliQAv1::Instance(index) ;
57acd2d2 305 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
306 if ( value == NULL ) { // No checker is implemented, set all QA to Fatal
4e25ac79 307 qa->Set(AliQAv1::kFATAL, specie) ;
57acd2d2 308 } else {
4e25ac79 309 if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] )
310 qa->Set(AliQAv1::kFATAL, specie) ;
311 else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR] )
312 qa->Set(AliQAv1::kERROR, specie) ;
313 else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING] )
314 qa->Set(AliQAv1::kWARNING, specie) ;
315 else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] )
316 qa->Set(AliQAv1::kINFO, specie) ;
57acd2d2 317 }
318 }
46b8a84d 319}