]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQACheckerBase.cxx
Enlarged range for the PHOS energy
[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 "AliQA.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 {
54   // ctor
55 }
56
57 //____________________________________________________________________________ 
58 AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
59   TNamed(qac.GetName(), qac.GetTitle()),
60   fDataSubDir(qac.fDataSubDir), 
61   fRefSubDir(qac.fRefSubDir), 
62   fRefOCDBSubDir(qac.fRefOCDBSubDir)
63 {
64   //copy ctor
65     
66 }
67
68 //____________________________________________________________________________
69 AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
70 {
71   // Equal operator.
72   this->~AliQACheckerBase();
73   new(this) AliQACheckerBase(qadm);
74   return *this;
75 }
76
77 //____________________________________________________________________________
78 const Double_t AliQACheckerBase::Check(AliQA::ALITASK_t /*index*/) 
79 {
80   // Performs a basic checking
81   // Compares all the histograms stored in the directory
82   // With reference histograms either in a file of in OCDB  
83
84         Double_t test = 0.0  ;
85         Int_t count = 0 ; 
86
87         if (!fDataSubDir)  
88                 test = 1. ; // nothing to check
89         else 
90                 if (!fRefSubDir && !fRefOCDBSubDir)
91                         test = -1 ; // no reference data
92                 else {
93                         TList * keyList = fDataSubDir->GetListOfKeys() ; 
94                         TIter next(keyList) ; 
95                         TKey * key ;
96                         count = 0 ; 
97                         while ( (key = static_cast<TKey *>(next())) ) {
98                                 TObject * odata = fRefSubDir->Get(key->GetName()) ; 
99                                 if ( odata->IsA()->InheritsFrom("TH1") ) {
100                                         TH1 * hdata = static_cast<TH1*>(odata) ;
101                                         TH1 * href = NULL ; 
102                                         if (fRefSubDir) 
103                                                 href  = static_cast<TH1*>(fRefSubDir->Get(key->GetName())) ;
104                                         else if (fRefOCDBSubDir) {
105                                                 href  = static_cast<TH1*>(fRefOCDBSubDir->FindObject(key->GetName())) ;
106                                         }
107                                         if (!href) 
108                                                 test = -1 ; // no reference data ; 
109                                         else {
110                                                 Double_t rv =  DiffK(hdata, href) ;
111                                                 AliInfo(Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
112                                                 test += rv ; 
113                                                 count++ ; 
114                                         }
115                                 } else
116                                         AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
117                         }
118                 } 
119         
120         if (count != 0) 
121                 test /= count ;
122    
123         return test ;
124 }  
125
126 //____________________________________________________________________________
127 const Double_t AliQACheckerBase::Check(AliQA::ALITASK_t /*index*/, TObjArray * list) 
128 {
129   // Performs a basic checking
130   // Compares all the histograms in the list
131
132         Double_t test = 0.0  ;
133         Int_t count = 0 ; 
134
135         if (list->GetEntries() == 0)  
136                 test = 1. ; // nothing to check
137         else {
138                 if (!fRefSubDir)
139                         test = -1 ; // no reference data
140                 else {
141                         TIter next(list) ; 
142                         TH1 * hdata ;
143                         count = 0 ; 
144                         while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
145                                 if ( hdata) { 
146                                         TH1 * href = NULL ; 
147                                         if (fRefSubDir) 
148                                                 href  = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName())) ;
149                                         else if (fRefOCDBSubDir)
150                                                 href  = static_cast<TH1*>(fRefOCDBSubDir->FindObject(hdata->GetName())) ;
151                                         if (!href) 
152                                                 test = -1 ; // no reference data ; 
153                                         else {
154                                                 Double_t rv =  DiffK(hdata, href) ;
155                                                 AliInfo(Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
156                                                 test += rv ; 
157                                                 count++ ; 
158                                         }
159                                 } 
160                                 else
161                                         AliError("Data type cannot be processed") ;
162                         }
163                 }
164         }
165         if (count != 0) 
166                 test /= count ;
167         return test ;
168 }  
169
170 //____________________________________________________________________________ 
171 const Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
172 {
173   // compares two histograms using the Chi2 test
174   if ( hin->Integral() == 0 ) {
175     AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; 
176     return 0. ;
177   }
178     
179   return hin->Chi2Test(href) ;  
180 }
181
182 //____________________________________________________________________________ 
183 const Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
184 {
185   // compares two histograms using the Kolmogorov test
186   if ( hin->Integral() == 0 ) {
187     AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; 
188     return 0. ;
189   }
190     
191   return hin->KolmogorovTest(href) ;  
192 }
193
194 //____________________________________________________________________________ 
195 void AliQACheckerBase::Init(const AliQA::DETECTORINDEX_t det)
196 {
197   AliQA::Instance(det) ; 
198 }
199  
200
201 //____________________________________________________________________________
202 void AliQACheckerBase::Run(AliQA::ALITASK_t index, TObject * obj) 
203
204         AliDebug(1, Form("Processing %s", AliQA::GetAliTaskName(index))) ; 
205   
206         Double_t rv = -1 ;      
207   if ( !obj ) {
208     rv = Check(index) ;
209   } else { 
210     TString className(obj->IsA()->GetName()) ; 
211     if (className.Contains("TObjArray")) {
212       rv = Check(index, static_cast<TObjArray *>(obj)) ;
213     } else if (className.Contains("TNtupleD")) { 
214       rv = Check(index, static_cast<TNtupleD *>(obj)) ;
215     }  else {
216       AliError(Form("%s class not implemented", className.Data())) ; 
217     }
218   }
219   
220         SetQA(index, rv) ;      
221         
222   AliDebug(1, Form("Test result of %s", AliQA::GetAliTaskName(index))) ;
223         
224   Finish() ; 
225 }
226
227 //____________________________________________________________________________
228 void AliQACheckerBase::Finish() const 
229 {
230         // wrap up and save QA in proper file
231         AliQA * qa = AliQA::Instance() ; 
232         qa->Show() ;
233         AliQA::GetQAResultFile()->cd() ; 
234         qa->Write(qa->GetName(), kWriteDelete) ;   
235         AliQA::GetQAResultFile()->Close() ; 
236 }
237
238 //____________________________________________________________________________
239 void AliQACheckerBase::SetQA(AliQA::ALITASK_t index, const Double_t value) const
240 {
241         // sets the QA according the return value of the Check
242
243         AliQA * qa = AliQA::Instance(index) ; 
244
245         if ( value <= 0.) 
246                 qa->Set(AliQA::kFATAL) ; 
247         else if ( value > 0 && value <= 0.0002 )
248                 qa->Set(AliQA::kERROR) ; 
249         else if ( value > 0.0002 && value <= 0.5 )
250                 qa->Set(AliQA::kWARNING) ;
251         else if ( value > 0.5 && value < 1 ) 
252                 qa->Set(AliQA::kINFO) ;                 
253 }