]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQACheckerBase.cxx
Fixes for bug #49914: Compilation breaks in trunk, and bug #48629: Trunk cannot read...
[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   AliInfo("Default setting is:") ;
69   printf( "                      INFO    -> %1.5f <  value <  %1.5f \n", fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO]) ; 
70   printf( "                      WARNING -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING]) ; 
71   printf( "                      ERROR   -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR]) ; 
72   printf( "                      FATAL   -> %1.5f <= value <  %1.5f \n", fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
73   
74 }
75
76 //____________________________________________________________________________ 
77 AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
78   TNamed(qac.GetName(), qac.GetTitle()),
79   fDataSubDir(qac.fDataSubDir), 
80   fRefSubDir(qac.fRefSubDir), 
81   fRefOCDBSubDir(qac.fRefOCDBSubDir), 
82   fLowTestValue(qac.fLowTestValue),
83   fUpTestValue(qac.fLowTestValue)
84 {
85   //copy ctor
86   for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
87     fLowTestValue[index]  = qac.fLowTestValue[index] ; 
88     fUpTestValue[index] = qac.fUpTestValue[index] ; 
89   }
90     
91 }
92
93 //____________________________________________________________________________
94 AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
95 {
96   // Equal operator.
97   this->~AliQACheckerBase();
98   new(this) AliQACheckerBase(qadm);
99   return *this;
100 }
101
102 //____________________________________________________________________________ 
103 AliQACheckerBase::~AliQACheckerBase()
104 {
105   delete [] fLowTestValue ; 
106   delete [] fUpTestValue ; 
107 }
108
109 //____________________________________________________________________________
110 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/) 
111 {
112   // Performs a basic checking
113   // Compares all the histograms stored in the directory
114   // With reference histograms either in a file of in OCDB  
115
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 ( !AliQAv1::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 ;
158 }  
159
160 //____________________________________________________________________________
161 Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list) 
162 {
163   // Performs a basic checking
164   // Compares all the histograms in the list
165
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 ( !AliQAv1::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(AliQAv1::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   }
208         return test ;
209 }  
210
211
212 //____________________________________________________________________________ 
213 Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
214 {
215   // compares two histograms using the Chi2 test
216   if ( hin->Integral() == 0 ) {
217     AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; 
218     return 0. ;
219   }
220     
221   return hin->Chi2Test(href) ;  
222 }
223
224 //____________________________________________________________________________ 
225 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
226 {
227   // compares two histograms using the Kolmogorov test
228   if ( hin->Integral() == 0 ) {
229     AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; 
230     return 0. ;
231   }
232     
233   return hin->KolmogorovTest(href) ;  
234 }
235
236 //____________________________________________________________________________
237 void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list) 
238
239         AliDebug(1, Form("Processing %s", AliQAv1::GetAliTaskName(index))) ; 
240   
241         Double_t * rv = NULL ;
242   if ( !list) 
243     rv = Check(index) ;
244   else 
245     rv = Check(index, list) ;
246         SetQA(index, rv) ;      
247         
248   AliDebug(1, Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
249         
250   if (rv) 
251     delete [] rv ; 
252   Finish() ; 
253 }
254
255 //____________________________________________________________________________
256 void AliQACheckerBase::Finish() const 
257 {
258         // wrap up and save QA in proper file
259         AliQAv1 * qa = AliQAv1::Instance() ; 
260         qa->Show() ;
261         AliQAv1::GetQAResultFile()->cd() ; 
262         qa->Write(qa->GetName(), kWriteDelete) ;   
263         AliQAv1::GetQAResultFile()->Close() ; 
264 }
265
266 //____________________________________________________________________________
267 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue) 
268 {
269   AliInfo("Previous setting was:") ;
270   printf( "                      INFO    -> %1.5f <  value <  %1.5f \n", fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO]) ; 
271   printf( "                      WARNING -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING]) ; 
272   printf( "                      ERROR   -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR]) ; 
273   printf( "                      FATAL   -> %1.5f <= value <  %1.5f \n", fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
274   
275   for (Int_t index = 0 ; index < AliQAv1::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[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO]) ; 
281   printf( "                      WARNING -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING]) ; 
282   printf( "                      ERROR   -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR]) ; 
283   printf( "                      FATAL   -> %1.5f <= value <  %1.5f \n", fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
284 }
285
286 //____________________________________________________________________________
287 void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
288 {
289         // sets the QA according the return value of the Check
290
291   AliQAv1 * qa = AliQAv1::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(AliQAv1::kFATAL, specie) ; 
295     } else {
296       if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] ) 
297         qa->Set(AliQAv1::kFATAL, specie) ; 
298       else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR]  )
299         qa->Set(AliQAv1::kERROR, specie) ; 
300       else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING]  )
301         qa->Set(AliQAv1::kWARNING, specie) ;
302       else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] ) 
303         qa->Set(AliQAv1::kINFO, specie) ;       
304     }
305   }
306 }