]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQACheckerBase.cxx
Removing newling
[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),
50 fRefSubDir(0x0)
421ab0fb 51{
52 // ctor
421ab0fb 53}
54
55//____________________________________________________________________________
2e42b4d4 56AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qadm) :
421ab0fb 57 TNamed(qadm.GetName(), qadm.GetTitle()),
a5fa6165 58 fDataSubDir(qadm.fDataSubDir),
59 fRefSubDir(qadm.fRefSubDir)
421ab0fb 60{
61 //copy ctor
62
63}
64
65//____________________________________________________________________________
2e42b4d4 66AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
421ab0fb 67{
68 // Equal operator.
2e42b4d4 69 this->~AliQACheckerBase();
70 new(this) AliQACheckerBase(qadm);
421ab0fb 71 return *this;
72}
73
a5fa6165 74//____________________________________________________________________________
2e42b4d4 75const Double_t AliQACheckerBase::Check()
a5fa6165 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())) ) {
d62f9368 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)
a5fa6165 99 test = -1 ; // no reference data ;
d62f9368 100 else {
a5fa6165 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
a4976ef3 118//____________________________________________________________________________
2e42b4d4 119const Double_t AliQACheckerBase::Check(TList * list)
a4976ef3 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
421ab0fb 158//____________________________________________________________________________
2e42b4d4 159const Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
421ab0fb 160{
161 // compares two histograms using the Chi2 test
162 if ( hin->Integral() == 0 ) {
2e42b4d4 163 AliWarning(Form("Spectrum %s in %s is empty", hin->GetName(), AliQA::GetDataName())) ;
421ab0fb 164 return 0. ;
165 }
166
167 return hin->Chi2Test(href) ;
168}
169
170//____________________________________________________________________________
2e42b4d4 171const Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
421ab0fb 172{
173 // compares two histograms using the Kolmogorov test
174 if ( hin->Integral() == 0 ) {
2e42b4d4 175 AliWarning(Form("Spectrum %s in %s is empty", hin->GetName(), AliQA::GetDataName())) ;
421ab0fb 176 return 0. ;
177 }
178
179 return hin->KolmogorovTest(href) ;
180}
181
182//____________________________________________________________________________
2e42b4d4 183void AliQACheckerBase::Init(const AliQA::DETECTORINDEX det)
421ab0fb 184{
2e42b4d4 185 AliQA::Instance(det) ;
421ab0fb 186}
187
188//____________________________________________________________________________
2e42b4d4 189void AliQACheckerBase::Run(AliQA::ALITASK index, TList * list)
421ab0fb 190{
2e42b4d4 191 AliInfo(Form("Processing %s", AliQA::GetAliTaskName(index))) ;
a5fa6165 192
2e42b4d4 193 AliQA * qa = AliQA::Instance(index) ;
a5fa6165 194
a4976ef3 195 Double_t rv = -1 ;
196 if (list)
197 rv = Check(list) ;
198 else
199 rv = Check() ;
200
a5fa6165 201 if ( rv <= 0.)
2e42b4d4 202 qa->Set(AliQA::kFATAL) ;
421ab0fb 203 else if ( rv > 0 && rv <= 0.2 )
2e42b4d4 204 qa->Set(AliQA::kERROR) ;
421ab0fb 205 else if ( rv > 0.2 && rv <= 0.5 )
2e42b4d4 206 qa->Set(AliQA::kWARNING) ;
421ab0fb 207 else if ( rv > 0.5 && rv < 1 )
2e42b4d4 208 qa->Set(AliQA::kINFO) ;
209 AliInfo(Form("Test result of %s", AliQA::GetAliTaskName(index))) ;
421ab0fb 210 Finish() ;
421ab0fb 211}
212
213//____________________________________________________________________________
2e42b4d4 214void AliQACheckerBase::Finish() const
421ab0fb 215{
216 // wrap up and save QA in proper file
217
2e42b4d4 218 AliQA * qa = AliQA::Instance() ;
421ab0fb 219 qa->Show() ;
2e42b4d4 220 AliQAChecker::GetQAResultFile()->cd() ;
421ab0fb 221 qa->Write(qa->GetName(), kWriteDelete) ;
2e42b4d4 222 AliQAChecker::GetQAResultFile()->Close() ;
421ab0fb 223}