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