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