Completely Updated (Mario Sitta)
[u/mrichter/AliRoot.git] / STEER / AliQACheckerBase.cxx
CommitLineData
421ab0fb 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
2e42b4d4 21 Compares Data made by QADataMakers with reference data
421ab0fb 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>
a4976ef3 32#include <TList.h>
421ab0fb 33
34// --- Standard library ---
35
36// --- AliRoot header files ---
37#include "AliLog.h"
2e42b4d4 38#include "AliQA.h"
39#include "AliQAChecker.h"
40#include "AliQACheckerBase.h"
41#include "AliQADataMaker.h"
421ab0fb 42
2e42b4d4 43ClassImp(AliQACheckerBase)
421ab0fb 44
45
46//____________________________________________________________________________
2e42b4d4 47AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
421ab0fb 48 TNamed(name, title),
a5fa6165 49 fDataSubDir(0x0),
4edbc5bc 50 fRefSubDir(0x0),
51 fRefOCDBSubDir(0x0)
421ab0fb 52{
53 // ctor
421ab0fb 54}
55
56//____________________________________________________________________________
4edbc5bc 57AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
58 TNamed(qac.GetName(), qac.GetTitle()),
59 fDataSubDir(qac.fDataSubDir),
60 fRefSubDir(qac.fRefSubDir),
61 fRefOCDBSubDir(qac.fRefOCDBSubDir)
421ab0fb 62{
63 //copy ctor
64
65}
66
67//____________________________________________________________________________
2e42b4d4 68AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
421ab0fb 69{
70 // Equal operator.
2e42b4d4 71 this->~AliQACheckerBase();
72 new(this) AliQACheckerBase(qadm);
421ab0fb 73 return *this;
74}
75
a5fa6165 76//____________________________________________________________________________
2e42b4d4 77const Double_t AliQACheckerBase::Check()
a5fa6165 78{
79 // Performs a basic checking
80 // Compares all the histograms stored in the directory
4edbc5bc 81 // With reference histograms either in a file of in OCDB
a5fa6165 82
83 Double_t test = 0.0 ;
84 Int_t count = 0 ;
85
86 if (!fDataSubDir)
87 test = 1. ; // nothing to check
88 else
4edbc5bc 89 if (!fRefSubDir && !fRefOCDBSubDir)
a5fa6165 90 test = -1 ; // no reference data
91 else {
4edbc5bc 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
a5fa6165 119 if (count != 0)
120 test /= count ;
121
122 return test ;
123}
124
a4976ef3 125//____________________________________________________________________________
4edbc5bc 126const Double_t AliQACheckerBase::Check(TObjArray * list)
a4976ef3 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
4edbc5bc 136 else {
a4976ef3 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) {
4edbc5bc 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 ;
a4976ef3 167}
168
421ab0fb 169//____________________________________________________________________________
2e42b4d4 170const Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
421ab0fb 171{
172 // compares two histograms using the Chi2 test
173 if ( hin->Integral() == 0 ) {
8bea2de0 174 AliWarning(Form("Spectrum %s is empty", hin->GetName())) ;
421ab0fb 175 return 0. ;
176 }
177
178 return hin->Chi2Test(href) ;
179}
180
181//____________________________________________________________________________
2e42b4d4 182const Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
421ab0fb 183{
184 // compares two histograms using the Kolmogorov test
185 if ( hin->Integral() == 0 ) {
8bea2de0 186 AliWarning(Form("Spectrum %s is empty", hin->GetName())) ;
421ab0fb 187 return 0. ;
188 }
189
190 return hin->KolmogorovTest(href) ;
191}
192
193//____________________________________________________________________________
2e42b4d4 194void AliQACheckerBase::Init(const AliQA::DETECTORINDEX det)
421ab0fb 195{
2e42b4d4 196 AliQA::Instance(det) ;
421ab0fb 197}
198
199//____________________________________________________________________________
4edbc5bc 200void AliQACheckerBase::Run(AliQA::ALITASK index, TObjArray * list)
421ab0fb 201{
2e42b4d4 202 AliInfo(Form("Processing %s", AliQA::GetAliTaskName(index))) ;
a5fa6165 203
2e42b4d4 204 AliQA * qa = AliQA::Instance(index) ;
a5fa6165 205
a4976ef3 206 Double_t rv = -1 ;
207 if (list)
208 rv = Check(list) ;
209 else
210 rv = Check() ;
211
a5fa6165 212 if ( rv <= 0.)
2e42b4d4 213 qa->Set(AliQA::kFATAL) ;
ca36a0bf 214 else if ( rv > 0 && rv <= 0.0002 )
2e42b4d4 215 qa->Set(AliQA::kERROR) ;
ca36a0bf 216 else if ( rv > 0.0002 && rv <= 0.5 )
2e42b4d4 217 qa->Set(AliQA::kWARNING) ;
421ab0fb 218 else if ( rv > 0.5 && rv < 1 )
2e42b4d4 219 qa->Set(AliQA::kINFO) ;
220 AliInfo(Form("Test result of %s", AliQA::GetAliTaskName(index))) ;
421ab0fb 221 Finish() ;
421ab0fb 222}
223
224//____________________________________________________________________________
2e42b4d4 225void AliQACheckerBase::Finish() const
421ab0fb 226{
227 // wrap up and save QA in proper file
228
2e42b4d4 229 AliQA * qa = AliQA::Instance() ;
421ab0fb 230 qa->Show() ;
8bea2de0 231 AliQA::GetQAResultFile()->cd() ;
421ab0fb 232 qa->Write(qa->GetName(), kWriteDelete) ;
421ab0fb 233}