]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQACheckerBase.cxx
fix
[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     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)) ; 
76   }
77 }
78
79 //____________________________________________________________________________ 
80 AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
81   TNamed(qac.GetName(), qac.GetTitle()),
82   fDataSubDir(qac.fDataSubDir), 
83   fRefSubDir(qac.fRefSubDir), 
84   fRefOCDBSubDir(qac.fRefOCDBSubDir), 
85   fLowTestValue(qac.fLowTestValue),
86   fUpTestValue(qac.fLowTestValue)
87 {
88   //copy ctor
89   for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
90     fLowTestValue[index]  = qac.fLowTestValue[index] ; 
91     fUpTestValue[index] = qac.fUpTestValue[index] ; 
92   }
93     
94 }
95
96 //____________________________________________________________________________
97 AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
98 {
99   // Equal operator.
100   this->~AliQACheckerBase();
101   new(this) AliQACheckerBase(qadm);
102   return *this;
103 }
104
105 //____________________________________________________________________________ 
106 AliQACheckerBase::~AliQACheckerBase()
107 {
108   delete [] fLowTestValue ; 
109   delete [] fUpTestValue ; 
110 }
111
112 //____________________________________________________________________________
113 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/) 
114 {
115   // Performs a basic checking
116   // Compares all the histograms stored in the directory
117   // With reference histograms either in a file of in OCDB  
118
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 ; 
124     if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
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) ;
149             AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
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 ;
161 }  
162
163 //____________________________________________________________________________
164 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list) 
165 {
166   // Performs a basic checking
167   // Compares all the histograms in the list
168
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 ; 
174     if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
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 ; 
185         while ( (hdata = static_cast<TH1 *>(next())) ) {
186           TString cln(hdata->ClassName()) ; 
187           if ( ! cln.Contains("TH1") )
188             continue ;           
189           if ( hdata) { 
190             if ( hdata->TestBit(AliQAv1::GetExpertBit()) )  // does not perform the test for expert data
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) ;
201               AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
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   }
214         return test ;
215 }  
216
217
218 //____________________________________________________________________________ 
219 Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
220 {
221   // compares two histograms using the Chi2 test
222   if ( hin->Integral() == 0 ) {
223     AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ; 
224     return 0. ;
225   }
226     
227   return hin->Chi2Test(href) ;  
228 }
229
230 //____________________________________________________________________________ 
231 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
232 {
233   // compares two histograms using the Kolmogorov test
234   if ( hin->Integral() == 0 ) {
235     AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ; 
236     return 0. ;
237   }
238     
239   return hin->KolmogorovTest(href) ;  
240 }
241
242 //____________________________________________________________________________
243 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list) 
244
245         AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ; 
246   
247         Double_t * rv = NULL ;
248   if ( !list) 
249     rv = Check(index) ;
250   else 
251     rv = Check(index, list) ;
252         SetQA(index, rv) ;      
253         
254   AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
255         
256   if (rv) 
257     delete [] rv ; 
258   Finish() ; 
259 }
260
261 //____________________________________________________________________________
262 void AliQACheckerBase::Finish() const 
263 {
264         // wrap up and save QA in proper file
265         AliQAv1 * qa = AliQAv1::Instance() ; 
266         qa->Show() ;
267         AliQAv1::GetQAResultFile()->cd() ; 
268         qa->Write(qa->GetName(), kWriteDelete) ;   
269         AliQAv1::GetQAResultFile()->Close() ; 
270 }
271
272 //____________________________________________________________________________
273 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue) 
274 {
275   AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
276   if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
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)) ; 
283   }
284   
285   for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
286     fLowTestValue[index]  = lowValue[index] ; 
287     fUpTestValue[index]   = hiValue[index] ; 
288   }
289   AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
290   if ( AliDebugLevel()  == AliQAv1::GetQADebugLevel() ) {
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)) ; 
296   }
297 }
298
299 //____________________________________________________________________________
300 void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
301 {
302         // sets the QA according the return value of the Check
303
304   AliQAv1 * qa = AliQAv1::Instance(index) ;
305   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
306     if (  value == NULL ) { // No checker is implemented, set all QA to Fatal
307       qa->Set(AliQAv1::kFATAL, specie) ; 
308     } else {
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) ;       
317     }
318   }
319 }