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