]>
Commit | Line | Data |
---|---|---|
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 | ||
202374b1 | 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 | // | |
421ab0fb | 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> |
a2b64fbd | 33 | #include <TNtupleD.h> |
421ab0fb | 34 | |
35 | // --- Standard library --- | |
36 | ||
37 | // --- AliRoot header files --- | |
38 | #include "AliLog.h" | |
2e42b4d4 | 39 | #include "AliQA.h" |
40 | #include "AliQAChecker.h" | |
41 | #include "AliQACheckerBase.h" | |
42 | #include "AliQADataMaker.h" | |
421ab0fb | 43 | |
2e42b4d4 | 44 | ClassImp(AliQACheckerBase) |
421ab0fb | 45 | |
46 | ||
47 | //____________________________________________________________________________ | |
2e42b4d4 | 48 | AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) : |
421ab0fb | 49 | TNamed(name, title), |
a5fa6165 | 50 | fDataSubDir(0x0), |
4edbc5bc | 51 | fRefSubDir(0x0), |
52 | fRefOCDBSubDir(0x0) | |
421ab0fb | 53 | { |
54 | // ctor | |
421ab0fb | 55 | } |
56 | ||
57 | //____________________________________________________________________________ | |
4edbc5bc | 58 | AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) : |
59 | TNamed(qac.GetName(), qac.GetTitle()), | |
60 | fDataSubDir(qac.fDataSubDir), | |
61 | fRefSubDir(qac.fRefSubDir), | |
62 | fRefOCDBSubDir(qac.fRefOCDBSubDir) | |
421ab0fb | 63 | { |
64 | //copy ctor | |
65 | ||
66 | } | |
67 | ||
68 | //____________________________________________________________________________ | |
2e42b4d4 | 69 | AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm ) |
421ab0fb | 70 | { |
71 | // Equal operator. | |
2e42b4d4 | 72 | this->~AliQACheckerBase(); |
73 | new(this) AliQACheckerBase(qadm); | |
421ab0fb | 74 | return *this; |
75 | } | |
76 | ||
a5fa6165 | 77 | //____________________________________________________________________________ |
f12d42ce | 78 | Double_t AliQACheckerBase::Check(AliQA::ALITASK_t /*index*/) |
a5fa6165 | 79 | { |
80 | // Performs a basic checking | |
81 | // Compares all the histograms stored in the directory | |
4edbc5bc | 82 | // With reference histograms either in a file of in OCDB |
a5fa6165 | 83 | |
96d67a8d | 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 | } | |
4edbc5bc | 119 | |
96d67a8d | 120 | if (count != 0) |
121 | test /= count ; | |
a5fa6165 | 122 | |
96d67a8d | 123 | return test ; |
a5fa6165 | 124 | } |
125 | ||
a4976ef3 | 126 | //____________________________________________________________________________ |
f12d42ce | 127 | Double_t AliQACheckerBase::Check(AliQA::ALITASK_t /*index*/, TObjArray * list) |
a4976ef3 | 128 | { |
129 | // Performs a basic checking | |
130 | // Compares all the histograms in the list | |
131 | ||
96d67a8d | 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 | } | |
4edbc5bc | 165 | if (count != 0) |
166 | test /= count ; | |
167 | return test ; | |
a4976ef3 | 168 | } |
169 | ||
421ab0fb | 170 | //____________________________________________________________________________ |
f12d42ce | 171 | Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const |
421ab0fb | 172 | { |
173 | // compares two histograms using the Chi2 test | |
174 | if ( hin->Integral() == 0 ) { | |
8bea2de0 | 175 | AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; |
421ab0fb | 176 | return 0. ; |
177 | } | |
178 | ||
179 | return hin->Chi2Test(href) ; | |
180 | } | |
181 | ||
182 | //____________________________________________________________________________ | |
f12d42ce | 183 | Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const |
421ab0fb | 184 | { |
185 | // compares two histograms using the Kolmogorov test | |
186 | if ( hin->Integral() == 0 ) { | |
8bea2de0 | 187 | AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; |
421ab0fb | 188 | return 0. ; |
189 | } | |
190 | ||
191 | return hin->KolmogorovTest(href) ; | |
192 | } | |
193 | ||
194 | //____________________________________________________________________________ | |
96d67a8d | 195 | void AliQACheckerBase::Init(const AliQA::DETECTORINDEX_t det) |
421ab0fb | 196 | { |
2e42b4d4 | 197 | AliQA::Instance(det) ; |
421ab0fb | 198 | } |
199 | ||
a2b64fbd | 200 | |
421ab0fb | 201 | //____________________________________________________________________________ |
a2b64fbd | 202 | void AliQACheckerBase::Run(AliQA::ALITASK_t index, TObject * obj) |
421ab0fb | 203 | { |
46b8a84d | 204 | AliDebug(1, Form("Processing %s", AliQA::GetAliTaskName(index))) ; |
a2b64fbd | 205 | |
46b8a84d | 206 | Double_t rv = -1 ; |
a2b64fbd | 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) ; | |
46b8a84d | 221 | |
a2b64fbd | 222 | AliDebug(1, Form("Test result of %s", AliQA::GetAliTaskName(index))) ; |
46b8a84d | 223 | |
a2b64fbd | 224 | Finish() ; |
421ab0fb | 225 | } |
226 | ||
227 | //____________________________________________________________________________ | |
2e42b4d4 | 228 | void AliQACheckerBase::Finish() const |
421ab0fb | 229 | { |
54a7f3ac | 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() ; | |
421ab0fb | 236 | } |
46b8a84d | 237 | |
238 | //____________________________________________________________________________ | |
8368e0ee | 239 | void AliQACheckerBase::SetQA(AliQA::ALITASK_t index, Double_t value) const |
46b8a84d | 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 | } |