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