]>
Commit | Line | Data |
---|---|---|
c9dd1c4d | 1 | /************************************************************************** |
2 | * Copyright(c) 2004, 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 | // Yves? | |
18 | // What | |
19 | // is | |
20 | // this | |
21 | // class | |
22 | // supposed | |
23 | // to | |
24 | // do? | |
25 | //__________________________________________________________________ | |
26 | // | |
27 | // --- ROOT system --- | |
28 | #include <TClass.h> | |
29 | #include <TH1F.h> | |
1306ba55 | 30 | #include <TF1.h> |
9eb9c521 | 31 | #include <TH2.h> |
c9dd1c4d | 32 | #include <TH1I.h> |
33 | #include <TIterator.h> | |
34 | #include <TKey.h> | |
35 | #include <TFile.h> | |
6ceca4ef | 36 | #include <iostream> |
1706c710 | 37 | #include <TCanvas.h> |
05e5e0c1 | 38 | #include <TStyle.h> |
9eb9c521 | 39 | #include <TLatex.h> |
1306ba55 | 40 | #include <TFitResult.h> |
41 | #include <TParameter.h> | |
42 | #include <TMacro.h> | |
a3e1fdcc | 43 | #include <TPaveText.h> |
550157b2 | 44 | #include <TVirtualFitter.h> |
c9dd1c4d | 45 | |
46 | // --- AliRoot header files --- | |
47 | #include "AliLog.h" | |
4e25ac79 | 48 | #include "AliQAv1.h" |
c9dd1c4d | 49 | #include "AliQAChecker.h" |
50 | #include "AliFMDQAChecker.h" | |
a3e1fdcc | 51 | #include "AliFMDQADataMakerRec.h" |
6ceca4ef | 52 | #include "AliRecoParam.h" |
1306ba55 | 53 | #include <AliCDBManager.h> |
54 | #include <AliCDBEntry.h> | |
55 | #include <AliCDBId.h> | |
56 | #include <AliQAThresholds.h> | |
c9dd1c4d | 57 | |
58 | ClassImp(AliFMDQAChecker) | |
59 | #if 0 | |
60 | ; // This is for Emacs! - do not delete | |
61 | #endif | |
05e5e0c1 | 62 | |
1306ba55 | 63 | namespace { |
64 | void addFitsMacro(TList* l) { | |
65 | TMacro* m = new TMacro("fits"); | |
66 | m->AddLine("void fits() {"); | |
67 | m->AddLine(" if (!gPad) { Printf(\"No gPad\"); return; }"); | |
68 | m->AddLine(" TList* lp = gPad->GetListOfPrimitives();"); | |
69 | m->AddLine(" if (!lp) return;"); | |
70 | m->AddLine(" TObject* po = 0;"); | |
71 | m->AddLine(" TIter next(lp);"); | |
72 | m->AddLine(" while ((po = next())) {"); | |
73 | m->AddLine(" if (!po->IsA()->InheritsFrom(TH1::Class())) continue;"); | |
74 | m->AddLine(" TH1* htmp = dynamic_cast<TH1*>(po);"); | |
75 | m->AddLine(" TList* lf = htmp->GetListOfFunctions();"); | |
76 | m->AddLine(" TObject* pso = (lf ? lf->FindObject(\"stats\") : 0);"); | |
77 | m->AddLine(" if (!pso) continue;"); | |
78 | m->AddLine(" TPaveStats* ps = static_cast<TPaveStats*>(pso);"); | |
79 | m->AddLine(" ps->SetOptFit(111);"); | |
80 | m->AddLine(" UShort_t qual = htmp->GetUniqueID();"); | |
81 | m->AddLine(" ps->SetFillColor(qual >= 3 ? kRed-4 : qual >= 2 ? kOrange-4 : qual >= 1 ? kYellow-4 : kGreen-4);"); | |
82 | // m->AddLine(" lf->Remove(lf->FindObject(\"fits\"));"); | |
83 | // m->AddLine(" ps->Paint();"); | |
84 | m->AddLine(" break;"); | |
85 | m->AddLine(" }"); | |
86 | // m->AddLine(" gPad->Modified(); gPad->Update(); gPad->cd();"); | |
87 | m->AddLine("}"); | |
88 | ||
89 | TObject* old = l->FindObject(m->GetName()); | |
90 | if (old) l->Remove(old); | |
91 | l->Add(m); | |
92 | } | |
93 | ||
e0c60e77 | 94 | const Double_t kROErrorsLabelY = .30; |
1306ba55 | 95 | |
96 | const Int_t kConvolutionSteps = 100; | |
97 | const Double_t kConvolutionNSigma = 5; | |
98 | ||
99 | // | |
100 | // The shift of the most probable value for the ROOT function TMath::Landau | |
101 | // | |
102 | const Double_t kMpShift = -0.22278298; | |
103 | // | |
104 | // Integration normalisation | |
105 | // | |
106 | const Double_t kInvSq2Pi = 1. / TMath::Sqrt(2*TMath::Pi()); | |
107 | ||
108 | Double_t landau(Double_t x, Double_t delta, Double_t xi) | |
109 | { | |
110 | // | |
111 | // Calculate the shifted Landau | |
112 | // @f[ | |
113 | // f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi) | |
114 | // @f] | |
115 | // | |
116 | // where @f$ f_{L}@f$ is the ROOT implementation of the Landau | |
117 | // distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for | |
118 | // @f$\Delta=0,\xi=1@f$. | |
119 | // | |
120 | // Parameters: | |
121 | // x Where to evaluate @f$ f'_{L}@f$ | |
122 | // delta Most probable value | |
123 | // xi The 'width' of the distribution | |
124 | // | |
125 | // Return: | |
126 | // @f$ f'_{L}(x;\Delta,\xi) @f$ | |
127 | // | |
128 | return TMath::Landau(x, delta - xi * kMpShift, xi); | |
129 | } | |
130 | Double_t landauGaus(Double_t x, Double_t delta, Double_t xi, | |
131 | Double_t sigma, Double_t sigmaN) | |
132 | { | |
133 | // | |
134 | // Calculate the value of a Landau convolved with a Gaussian | |
135 | // | |
136 | // @f[ | |
137 | // f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}} | |
138 | // \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi) | |
139 | // \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}} | |
140 | // @f] | |
141 | // | |
142 | // where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ | |
143 | // the energy loss, @f$ \xi@f$ the width of the Landau, and @f$ | |
144 | // \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the | |
145 | // variance of the Gaussian, and @f$\sigma_n@f$ is a parameter | |
146 | // modelling noise in the detector. | |
147 | // | |
148 | // Note that this function uses the constants kConvolutionSteps and | |
149 | // kConvolutionNSigma | |
150 | // | |
151 | // References: | |
152 | // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a> | |
153 | // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a> | |
154 | // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a> | |
155 | // | |
156 | // Parameters: | |
157 | // x where to evaluate @f$ f@f$ | |
158 | // delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$ | |
159 | // xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$ | |
160 | // sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$ | |
161 | // sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$ | |
162 | // | |
163 | // Return: | |
164 | // @f$ f@f$ evaluated at @f$ x@f$. | |
165 | // | |
166 | Double_t deltap = delta - xi * kMpShift; | |
167 | Double_t sigma2 = sigmaN*sigmaN + sigma*sigma; | |
168 | Double_t sigma1 = sigmaN == 0 ? sigma : TMath::Sqrt(sigma2); | |
169 | Double_t xlow = x - kConvolutionNSigma * sigma1; | |
170 | Double_t xhigh = x + kConvolutionNSigma * sigma1; | |
171 | Double_t step = (xhigh - xlow) / kConvolutionSteps; | |
172 | Double_t sum = 0; | |
173 | ||
174 | for (Int_t i = 0; i <= kConvolutionSteps/2; i++) { | |
175 | Double_t x1 = xlow + (i - .5) * step; | |
176 | Double_t x2 = xhigh - (i - .5) * step; | |
177 | ||
178 | sum += TMath::Landau(x1, deltap, xi, kTRUE) * TMath::Gaus(x, x1, sigma1); | |
179 | sum += TMath::Landau(x2, deltap, xi, kTRUE) * TMath::Gaus(x, x2, sigma1); | |
180 | } | |
181 | return step * sum * kInvSq2Pi / sigma1; | |
182 | } | |
183 | ||
184 | // | |
185 | // Utility function to use in TF1 defintition | |
186 | // | |
187 | Double_t landauGaus1(Double_t* xp, Double_t* pp) | |
188 | { | |
189 | Double_t x = xp[0]; | |
190 | Double_t constant = pp[0]; | |
191 | Double_t delta = pp[1]; | |
192 | Double_t xi = pp[2]; | |
193 | Double_t sigma = pp[3]; | |
194 | Double_t sigmaN = pp[4]; | |
195 | ||
196 | return constant * landauGaus(x, delta, xi, sigma, sigmaN); | |
197 | } | |
198 | ||
199 | //____________________________________________________________________ | |
200 | TF1* makeLandauGaus(const char* , | |
201 | Double_t c=1, | |
202 | Double_t delta=.5, Double_t xi=0.07, | |
203 | Double_t sigma=.1, Double_t sigmaN=-1, | |
204 | Double_t xmin=0, Double_t xmax=15) | |
205 | { | |
206 | // | |
207 | // Generate a TF1 object of @f$ f_I@f$ | |
208 | // | |
209 | // Parameters: | |
210 | // c Constant | |
211 | // delta @f$ \Delta@f$ | |
212 | // xi @f$ \xi_1@f$ | |
213 | // sigma @f$ \sigma_1@f$ | |
214 | // sigma_n @f$ \sigma_n@f$ | |
215 | // xmin Least value of range | |
216 | // xmax Largest value of range | |
217 | // | |
218 | // Return: | |
219 | // Newly allocated TF1 object | |
220 | // | |
221 | Int_t npar = 5; | |
222 | TF1* func = new TF1("landauGaus", | |
223 | &landauGaus1,xmin,xmax,npar); | |
224 | // func->SetLineStyle(((i-2) % 10)+2); // start at dashed | |
225 | func->SetLineColor(kBlack); | |
226 | func->SetLineWidth(2); | |
227 | func->SetNpx(500); | |
228 | func->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}"); | |
229 | ||
230 | // Set the initial parameters from the seed fit | |
231 | func->SetParameter(0, c); | |
232 | func->SetParameter(1, delta); | |
233 | func->SetParameter(2, xi); | |
234 | func->SetParameter(3, sigma); | |
235 | func->SetParameter(4, sigmaN); | |
236 | ||
237 | func->SetParLimits(1, 0, xmax); | |
238 | func->SetParLimits(2, 0, xmax); | |
550157b2 | 239 | func->SetParLimits(3, 0.01, 1); |
1306ba55 | 240 | |
241 | if (sigmaN < 0) func->FixParameter(4, 0); | |
242 | else func->SetParLimits(4, 0, xmax); | |
243 | ||
244 | return func; | |
245 | } | |
246 | } | |
247 | ||
248 | //__________________________________________________________________ | |
249 | AliFMDQAChecker::AliFMDQAChecker() | |
250 | : AliQACheckerBase("FMD","FMD Quality Assurance Checker") , | |
251 | fDoScale(false), | |
252 | fDidExternal(false), | |
253 | fShowFitResults(true), | |
254 | fELossLowCut(0.2), | |
255 | fELossNRMS(3), | |
256 | fELossBadChi2Nu(10), | |
257 | fELossFkupChi2Nu(100), | |
258 | fELossMinEntries(1000), | |
e0c60e77 | 259 | fELossMaxEntries(-1), |
1306ba55 | 260 | fELossGoodParError(0.1), |
550157b2 | 261 | fELossMinSharing(0.1), |
1306ba55 | 262 | fROErrorsBad(0.3), |
550157b2 | 263 | fROErrorsFkup(0.5), |
264 | fMaxNProblem(10), | |
265 | fMaxNBad(10), | |
266 | fNoFits(false) | |
1306ba55 | 267 | { |
268 | } | |
269 | ||
270 | //__________________________________________________________________ | |
271 | void | |
272 | AliFMDQAChecker::ProcessExternalParams() | |
273 | { | |
274 | ProcessExternalParam("ELossLowCut", fELossLowCut); | |
275 | ProcessExternalParam("ELossNRMS", fELossNRMS); | |
276 | ProcessExternalParam("ELossBadChi2Nu", fELossBadChi2Nu); | |
277 | ProcessExternalParam("ELossFkupChi2Nu", fELossFkupChi2Nu); | |
278 | ProcessExternalParam("ELossGoodParError", fELossGoodParError); | |
279 | ProcessExternalParam("ROErrorsBad", fROErrorsBad); | |
280 | ProcessExternalParam("ROErrorsFkup", fROErrorsFkup); | |
550157b2 | 281 | ProcessExternalParam("ELossMinSharing", fELossMinSharing); |
1306ba55 | 282 | Double_t tmp = 0; |
550157b2 | 283 | ProcessExternalParam("CommonScale", tmp); |
284 | fDoScale = tmp > 0; tmp = fELossMinEntries; | |
285 | ProcessExternalParam("ELossMinEntries", tmp); | |
286 | fELossMinEntries = tmp; tmp = fELossMaxEntries; | |
287 | ProcessExternalParam("ELossMaxEntries", tmp); | |
288 | fELossMaxEntries = tmp; tmp = fMaxNProblem; | |
289 | ProcessExternalParam("MaxNProblem", tmp); | |
290 | fMaxNProblem = tmp; tmp = 0; | |
291 | fELossMaxEntries = tmp; tmp = fMaxNBad; | |
292 | ProcessExternalParam("MaxNBad", tmp); | |
293 | fMaxNBad = tmp; tmp = 0; | |
294 | ProcessExternalParam("NoFits", tmp); | |
295 | fNoFits = tmp > 0; tmp = 0; | |
1306ba55 | 296 | |
297 | GetThresholds(); | |
298 | ||
299 | fDidExternal = true; | |
300 | } | |
301 | //__________________________________________________________________ | |
302 | void | |
303 | AliFMDQAChecker::ProcessExternalParam(const char* name, Double_t& v) | |
304 | { | |
305 | TObject* o = fExternParamList->FindObject(name); | |
306 | if (!o) return; | |
307 | TParameter<double>* p = static_cast<TParameter<double>*>(o); | |
308 | v = p->GetVal(); | |
309 | AliDebugF(3, "External parameter: %-20s=%lf", name, v); | |
310 | } | |
311 | ||
312 | //__________________________________________________________________ | |
313 | void | |
314 | AliFMDQAChecker::GetThresholds() | |
315 | { | |
316 | const char* path = "GRP/Calib/QAThresholds"; | |
317 | AliCDBManager* cdbMan = AliCDBManager::Instance(); | |
318 | AliCDBEntry* cdbEnt = cdbMan->Get(path); | |
319 | if (!cdbEnt) { | |
320 | AliWarningF("Failed to get CDB entry at %s", path); | |
321 | return; | |
322 | } | |
323 | ||
324 | TObjArray* cdbObj = static_cast<TObjArray*>(cdbEnt->GetObject()); | |
325 | if (!cdbObj) { | |
326 | AliWarningF("Failed to get CDB object at %s", path); | |
327 | return; | |
328 | } | |
329 | ||
330 | TObject* fmdObj = cdbObj->FindObject("FMD"); | |
331 | if (!fmdObj) { | |
332 | AliWarningF("Failed to get FMD object at from CDB %s", path); | |
333 | return; | |
334 | } | |
335 | ||
336 | AliQAThresholds* qaThr = static_cast<AliQAThresholds*>(fmdObj); | |
337 | Int_t nThr = qaThr->GetSize(); | |
338 | for (Int_t i = 0; i < nThr; i++) { | |
339 | TObject* thr = qaThr->GetThreshold(i); | |
340 | if (!thr) continue; | |
341 | ||
342 | TParameter<double>* d = dynamic_cast<TParameter<double>*>(thr); | |
343 | if (!d) { | |
344 | AliWarningF("Parameter %s not of type double", thr->GetName()); | |
345 | continue; | |
346 | } | |
347 | Double_t val = d->GetVal(); | |
348 | TString name(thr->GetName()); | |
349 | if (name.EqualTo("ELossBadChi2Nu")) fELossBadChi2Nu = val; | |
350 | else if (name.EqualTo("ELossFkupChi2Nu")) fELossFkupChi2Nu = val; | |
351 | else if (name.EqualTo("ELossGoodParError")) fELossGoodParError = val; | |
352 | else if (name.EqualTo("ROErrorsBad")) fROErrorsBad = val; | |
353 | else if (name.EqualTo("ROErrorsFkup")) fROErrorsFkup = val; | |
550157b2 | 354 | else if (name.EqualTo("MaxNProblem")) fMaxNProblem = val; |
355 | else if (name.EqualTo("MaxNBad")) fMaxNBad = val; | |
1306ba55 | 356 | AliDebugF(3, "Threshold %s=%f", name.Data(), val); |
357 | } | |
358 | } | |
359 | ||
360 | //__________________________________________________________________ | |
361 | AliQAv1::QABIT_t | |
362 | AliFMDQAChecker::Quality2Bit(UShort_t value) const | |
363 | { | |
364 | AliQAv1::QABIT_t ret = AliQAv1::kINFO; // Assume success | |
365 | if (value >= kWhatTheFk) ret = AliQAv1::kFATAL; | |
366 | else if (value >= kBad) ret = AliQAv1::kERROR; | |
367 | else if (value >= kProblem) ret = AliQAv1::kWARNING; | |
368 | ||
369 | return ret; | |
370 | } | |
371 | ||
372 | //__________________________________________________________________ | |
373 | void | |
374 | AliFMDQAChecker::SetQA(AliQAv1::ALITASK_t index, Double_t* values) const | |
375 | { | |
376 | AliQAv1 * qa = AliQAv1::Instance(index) ; | |
377 | ||
378 | for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { | |
379 | // Check if specie is defined | |
380 | if (!qa->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie))) | |
381 | continue ; | |
382 | ||
383 | // No checker is implemented, set all QA to Fatal | |
384 | if (!values) { | |
385 | qa->Set(AliQAv1::kFATAL, specie) ; | |
386 | continue; | |
387 | } | |
388 | ||
389 | UShort_t value = values[specie]; | |
390 | AliQAv1::QABIT_t ret = Quality2Bit(value); | |
391 | ||
392 | qa->Set(ret, AliRecoParam::ConvertIndex(specie)); | |
393 | AliDebugF(3, "Quality of %s: %d -> %d", | |
394 | AliRecoParam::GetEventSpecieName(specie), value, ret); | |
395 | } | |
396 | } | |
397 | ||
398 | //__________________________________________________________________ | |
399 | UShort_t | |
400 | AliFMDQAChecker::BasicCheck(TH1* hist) const | |
401 | { | |
402 | if (hist->GetEntries() <= 0) return kOK; | |
403 | return (hist->GetMean() > 0 ? kOK : kProblem); | |
404 | } | |
405 | ||
05e5e0c1 | 406 | //__________________________________________________________________ |
1306ba55 | 407 | UShort_t |
05e5e0c1 | 408 | AliFMDQAChecker::CheckOne(AliQAv1::ALITASK_t what, |
409 | AliRecoParam::EventSpecie_t specie, | |
410 | TH1* hist) const | |
411 | { | |
412 | if(what == AliQAv1::kESD) return CheckESD(specie, hist); | |
413 | if(what == AliQAv1::kRAW) return CheckRaw(specie, hist); | |
414 | if(what == AliQAv1::kSIM) return CheckSim(specie, hist); | |
415 | if(what == AliQAv1::kREC) return CheckRec(specie, hist); | |
416 | return 0; | |
417 | } | |
418 | //__________________________________________________________________ | |
1306ba55 | 419 | UShort_t |
05e5e0c1 | 420 | AliFMDQAChecker::CheckESD(AliRecoParam::EventSpecie_t /* specie*/, |
421 | TH1* hist) const | |
422 | { | |
1306ba55 | 423 | return BasicCheck(hist); |
424 | } | |
550157b2 | 425 | namespace { |
426 | Double_t Chi2Scale(TH1* h, Double_t base=10000) | |
427 | { | |
428 | return 1. / TMath::Max(1., h->GetEntries() / base); | |
429 | } | |
430 | void AddLine(TObjArray* lines, | |
431 | Double_t x1, Double_t x2, Double_t x3, | |
432 | Double_t y, Double_t dy, | |
433 | const char* name, Double_t val, Double_t lim, | |
434 | Bool_t ok, Int_t color) | |
435 | { | |
436 | TString n; n.Form("%s:", name); | |
437 | TLatex* ltx = new TLatex(x1, y, n); | |
438 | ltx->SetNDC(true); | |
439 | ltx->SetTextSize(dy-0.01); | |
440 | ltx->SetTextColor(color); | |
441 | lines->Add(ltx); | |
442 | ||
443 | n.Form("%7.3f", val); | |
444 | ltx = new TLatex(x2, y, n); | |
445 | ltx->SetNDC(true); | |
446 | ltx->SetTextSize(dy-0.01); | |
447 | ltx->SetTextColor(color); | |
448 | lines->Add(ltx); | |
449 | ||
450 | if (lim < 0) n = "(ignored)"; | |
451 | else n.Form("%c %4.2f", ok ? '<' : '>', lim); | |
452 | ltx = new TLatex(x3, y, n); | |
453 | ltx->SetNDC(true); | |
454 | ltx->SetTextSize(dy-0.01); | |
455 | ltx->SetTextColor(color); | |
456 | lines->Add(ltx); | |
457 | } | |
458 | } | |
459 | ||
1306ba55 | 460 | //__________________________________________________________________ |
461 | UShort_t | |
462 | AliFMDQAChecker::CheckFit(TH1* hist, const TFitResultPtr& res, | |
463 | Double_t low, Double_t high, Int_t& color) const | |
464 | { | |
465 | color = kGreen+4; | |
466 | ||
300e2129 | 467 | // Check if there's indeed a result - if not, flag as OK |
468 | if (!res.Get()) return 0; | |
469 | ||
1306ba55 | 470 | UShort_t ret = 0; |
471 | Int_t nPar = res->NPar(); | |
472 | Double_t dy = .06; | |
473 | Double_t x = .2; | |
550157b2 | 474 | Double_t x2 = .3; |
475 | Double_t x3 = .4; | |
1306ba55 | 476 | Double_t y = .9-dy; |
477 | Double_t chi2 = res->Chi2(); | |
478 | Int_t nu = res->Ndf(); | |
550157b2 | 479 | Double_t s = Chi2Scale(hist,fELossMinEntries); |
1306ba55 | 480 | Double_t red = (nu == 0 ? fELossFkupChi2Nu : chi2 / nu); |
481 | TObjArray* lines = 0; | |
e0c60e77 | 482 | // TLatex* lRed = 0; |
1306ba55 | 483 | TLatex* ltx = 0; |
e0c60e77 | 484 | Int_t chi2Check = 0; |
485 | Double_t chi2Lim = fELossBadChi2Nu; | |
550157b2 | 486 | if (AliDebugLevel() > 0) |
487 | printf("FIT: %s, 1, %d, %f, %f\n", hist->GetName(), | |
488 | Int_t(hist->GetEntries()), red, s * red); | |
489 | red *= s; | |
e0c60e77 | 490 | if (red > fELossBadChi2Nu) { // || res->Prob() < .01) { |
491 | // AliWarningF("Fit gave chi^2/nu=%f/%d=%f>%f (%f)", | |
492 | // res->Chi2(), res->Ndf(), red, fELossBadChi2Nu, | |
493 | // fELossFkupChi2Nu); | |
494 | // res->Print(); | |
495 | chi2Check++; | |
496 | if (red > fELossFkupChi2Nu) { | |
497 | chi2Check++; | |
498 | chi2Lim = fELossFkupChi2Nu; | |
499 | } | |
500 | } | |
501 | ret += chi2Check; | |
502 | ||
1306ba55 | 503 | if (fShowFitResults) { |
504 | lines = new TObjArray(nPar+3); | |
505 | lines->SetName("lines"); | |
506 | lines->SetOwner(true); | |
550157b2 | 507 | |
508 | AddLine(lines, x, x2, x3, y, dy, "#chi^{2}/#nu", red, chi2Lim, | |
509 | chi2Check < 1, chi2Check < 1 ? color : | |
510 | chi2Check < 2 ? kOrange+2 : kRed+2); | |
1306ba55 | 511 | |
512 | Double_t x1 = .85; | |
513 | Double_t y1 = .5; | |
1306ba55 | 514 | |
e0c60e77 | 515 | // y1 -= dy; |
1306ba55 | 516 | ltx = new TLatex(x1, y1, Form("Fit range: [%6.2f,%6.2f]", low, high)); |
517 | ltx->SetTextColor(kGray+3); | |
518 | ltx->SetTextSize(dy-.01); | |
519 | ltx->SetTextAlign(31); | |
520 | ltx->SetNDC(true); | |
521 | lines->Add(ltx); | |
522 | ||
523 | y1 -= dy; | |
e0c60e77 | 524 | ltx = new TLatex(x1, y1, Form("Entries: %d (%d)", |
525 | Int_t(hist->GetEffectiveEntries()), | |
526 | fELossMaxEntries)); | |
1306ba55 | 527 | ltx->SetTextColor(kGray+3); |
528 | ltx->SetTextSize(dy-.01); | |
529 | ltx->SetTextAlign(31); | |
530 | ltx->SetNDC(true); | |
531 | lines->Add(ltx); | |
550157b2 | 532 | |
533 | y1 -= dy; | |
534 | ltx = new TLatex(x1, y1, Form("%s: %f #pm %f", | |
535 | res->ParName(1).c_str(), | |
536 | res->Parameter(1), | |
537 | res->ParError(1))); | |
538 | ltx->SetTextColor(kGray+3); | |
539 | ltx->SetTextSize(dy-.01); | |
540 | ltx->SetTextAlign(31); | |
541 | ltx->SetNDC(true); | |
542 | lines->Add(ltx); | |
1306ba55 | 543 | } |
544 | ||
1306ba55 | 545 | // Now check the relative error on the fit parameters |
546 | Int_t parsOk = 0; | |
547 | for (Int_t i = 0; i < nPar; i++) { | |
548 | if (res->IsParameterFixed(i)) continue; | |
e0c60e77 | 549 | Double_t thr = fELossGoodParError; |
1306ba55 | 550 | Double_t pv = res->Parameter(i); |
551 | Double_t pe = res->ParError(i); | |
552 | Double_t rel = (pv == 0 ? 100 : pe / pv); | |
e0c60e77 | 553 | Bool_t ok = (i == 3) || (rel < thr); |
1306ba55 | 554 | if (lines) { |
555 | y -= dy; | |
550157b2 | 556 | AddLine(lines, x, x2, x3, y, dy,Form("#delta%s/%s", |
557 | res->ParName(i).c_str(), | |
558 | res->ParName(i).c_str()), | |
559 | rel, (i == 3 ? -1 : thr), ok, ok ? color : kOrange+2); | |
1306ba55 | 560 | } |
561 | if (i == 3) continue; // Skip sigma | |
e0c60e77 | 562 | if (ok) parsOk++; |
1306ba55 | 563 | } |
564 | if (parsOk > 0) | |
565 | ret = TMath::Max(ret-(parsOk-1),0); | |
566 | if (ret > 1) color = kRed+2; | |
567 | if (ret > 0) color = kOrange+2; | |
568 | ||
550157b2 | 569 | if (lines) { |
570 | TList* lf = hist->GetListOfFunctions(); | |
571 | TObject* old = lf->FindObject(lines->GetName()); | |
572 | if (old) { | |
573 | lf->Remove(old); | |
574 | delete old; | |
575 | } | |
576 | lf->Add(lines); | |
1306ba55 | 577 | } |
1306ba55 | 578 | hist->SetStats(false); |
579 | ||
580 | return ret; | |
581 | } | |
582 | ||
05e5e0c1 | 583 | //__________________________________________________________________ |
1306ba55 | 584 | UShort_t |
e0c60e77 | 585 | AliFMDQAChecker::CheckRaw(AliRecoParam::EventSpecie_t specie, |
05e5e0c1 | 586 | TH1* hist) const |
587 | { | |
1306ba55 | 588 | Int_t ret = BasicCheck(hist); |
589 | TString name(hist->GetName()); | |
590 | if (name.Contains("readouterrors", TString::kIgnoreCase)) { | |
591 | // Check the mean number of errors per event | |
592 | TH2* roErrors = static_cast<TH2*>(hist); | |
593 | Int_t nY = roErrors->GetNbinsY(); | |
594 | ||
e0c60e77 | 595 | TLatex* ltx = new TLatex(.15, .9, Form("Thresholds: %5.2f,%5.2f", |
1306ba55 | 596 | fROErrorsBad, fROErrorsFkup)); |
597 | ltx->SetName("thresholds"); | |
598 | ltx->SetTextColor(kGray+3); | |
599 | ltx->SetNDC(); | |
600 | ||
601 | TList* ll = hist->GetListOfFunctions(); | |
602 | TObject* old = ll->FindObject(ltx->GetName()); | |
603 | if (old) { | |
604 | ll->Remove(old); | |
605 | delete old; | |
606 | } | |
607 | ll->Add(ltx); | |
608 | ||
609 | for (Int_t i = 1; i <= 3; i++) { | |
610 | Double_t sum = 0; | |
611 | Int_t cnt = 0; | |
612 | for (Int_t j = 1; j <= nY; j++) { | |
613 | Int_t n = roErrors->GetBinContent(i, j); | |
614 | sum += n * roErrors->GetYaxis()->GetBinCenter(j); | |
615 | cnt += n; | |
616 | } | |
550157b2 | 617 | Double_t mean = (cnt <= 0 ? 0 : sum / cnt); |
e0c60e77 | 618 | Double_t x = ((i-.5) * (1-0.1-0.1) / 3 + 0.1); |
619 | ||
620 | ltx = new TLatex(x, kROErrorsLabelY, Form("Mean: %6.3f", mean)); | |
1306ba55 | 621 | ltx->SetName(Form("FMD%d", i)); |
e0c60e77 | 622 | ltx->SetNDC(); |
1306ba55 | 623 | ltx->SetTextAngle(90); |
624 | ltx->SetTextColor(kGreen+4); | |
625 | old = ll->FindObject(ltx->GetName()); | |
626 | if (old) { | |
627 | ll->Remove(old); | |
628 | delete old; | |
629 | } | |
630 | ll->Add(ltx); | |
631 | ||
632 | if (mean > fROErrorsBad) { | |
633 | AliWarningF("Mean of readout errors for FMD%d = %f > %f (%f)", | |
634 | i, mean, fROErrorsBad, fROErrorsFkup); | |
635 | ret++; | |
636 | ltx->SetTextColor(kOrange+2); | |
637 | if (mean > fROErrorsFkup) { | |
638 | ret++; | |
639 | ltx->SetTextColor(kRed+2); | |
640 | } | |
641 | } | |
642 | } | |
643 | } | |
644 | else if (name.Contains("eloss",TString::kIgnoreCase)) { | |
550157b2 | 645 | // If we' asked to not fit the data, return immediately |
646 | if (fNoFits) return ret; | |
647 | // Do not fit cosmic or calibration data | |
e0c60e77 | 648 | if (specie == AliRecoParam::kCosmic || |
649 | specie == AliRecoParam::kCalib) return ret; | |
550157b2 | 650 | // Do not fit `expert' histograms |
651 | if (hist->TestBit(AliQAv1::GetExpertBit())) return ret; | |
652 | // Do not fit histograms with too little data | |
653 | if (hist->GetEntries() < fELossMinEntries) return ret; | |
1306ba55 | 654 | |
550157b2 | 655 | // Try to fit a function to the histogram |
1306ba55 | 656 | Double_t xMin = hist->GetXaxis()->GetXmin(); |
657 | Double_t xMax = hist->GetXaxis()->GetXmax(); | |
658 | ||
659 | hist->GetXaxis()->SetRangeUser(fELossLowCut, xMax); | |
660 | Int_t bMaxY = hist->GetMaximumBin(); | |
661 | Double_t xMaxY = hist->GetXaxis()->GetBinCenter(bMaxY); | |
662 | Double_t rms = hist->GetRMS(); | |
663 | Double_t low = hist->GetXaxis()->GetBinCenter(bMaxY-4); | |
664 | hist->GetXaxis()->SetRangeUser(0.2, xMaxY+(fELossNRMS+1)*rms); | |
665 | rms = hist->GetRMS(); | |
666 | hist->GetXaxis()->SetRange(0,-1); | |
667 | TF1* func = makeLandauGaus(name); | |
668 | func->SetParameter(1, xMaxY); | |
669 | func->SetLineColor(kGreen+4); | |
670 | // func->SetLineStyle(2); | |
671 | Double_t high = xMax; // xMaxY+fELossNRMS*rms; | |
550157b2 | 672 | if (fELossNRMS > 0) high = xMaxY+fELossNRMS*rms; |
1306ba55 | 673 | |
550157b2 | 674 | // Set our fit function |
675 | TString fitOpt("QS"); | |
300e2129 | 676 | TFitResultPtr res = hist->Fit(func, fitOpt, "", low, high); |
677 | Int_t color = func->GetLineColor(); | |
678 | UShort_t qual = CheckFit(hist, res, low, high, color); | |
1306ba55 | 679 | |
680 | // Make sure we save the function in the full range of the histogram | |
681 | func = hist->GetFunction("landauGaus"); | |
550157b2 | 682 | if (fELossNRMS <= 0) func->SetRange(xMin, xMax); |
1306ba55 | 683 | // func->SetParent(hist); |
684 | func->Save(xMin, xMax, 0, 0, 0, 0); | |
685 | func->SetLineColor(color); | |
e0c60e77 | 686 | |
550157b2 | 687 | fitOpt.Append("+"); |
688 | res = hist->Fit("pol2", fitOpt, "", fELossMinSharing, low-0.05); | |
689 | func = hist->GetFunction("pol2"); | |
690 | Double_t s = Chi2Scale(hist,fELossMinEntries*100); | |
691 | Double_t chi2 = res->Chi2(); | |
692 | Int_t nu = res->Ndf(); | |
693 | Double_t red = s * (nu == 0 ? fELossFkupChi2Nu : chi2 / nu); | |
694 | if (AliDebugLevel()) | |
695 | printf("FIT: %s, 2, %d, %f, %f\n", hist->GetName(), | |
696 | Int_t(hist->GetEntries()), red, s * red); | |
697 | red *= s; | |
698 | if (red > fELossFkupChi2Nu) func->SetLineColor(kRed); | |
699 | else func->SetLineColor(kGreen+4); | |
700 | ||
e0c60e77 | 701 | // Now check if this histogram should be cleared or not |
702 | if (fELossMaxEntries > 0 && hist->GetEntries() > fELossMaxEntries) | |
550157b2 | 703 | hist->SetBit(AliFMDQADataMakerRec::kResetBit); |
1306ba55 | 704 | if (qual > 0) { |
705 | func->SetLineWidth(3); | |
706 | func->SetLineStyle(1); | |
707 | if (qual > 1) | |
708 | func->SetLineWidth(4); | |
709 | } | |
710 | ret += qual; | |
711 | } | |
712 | ||
713 | return ret; | |
05e5e0c1 | 714 | } |
715 | //__________________________________________________________________ | |
1306ba55 | 716 | UShort_t |
05e5e0c1 | 717 | AliFMDQAChecker::CheckSim(AliRecoParam::EventSpecie_t /* specie*/, |
718 | TH1* hist) const | |
719 | { | |
1d65d916 | 720 | // |
721 | // Check simulated hits | |
722 | // | |
1306ba55 | 723 | return BasicCheck(hist); |
05e5e0c1 | 724 | } |
725 | //__________________________________________________________________ | |
1306ba55 | 726 | UShort_t |
05e5e0c1 | 727 | AliFMDQAChecker::CheckRec(AliRecoParam::EventSpecie_t /* specie*/, |
728 | TH1* hist) const | |
729 | { | |
1d65d916 | 730 | // |
731 | // Check reconstructed data | |
732 | // | |
1306ba55 | 733 | return BasicCheck(hist); |
05e5e0c1 | 734 | } |
735 | ||
1d65d916 | 736 | //__________________________________________________________________ |
737 | void AliFMDQAChecker::AddStatusPave(TH1* hist, Int_t qual, | |
738 | Double_t xl, Double_t yl, | |
739 | Double_t xh, Double_t yh) const | |
740 | { | |
741 | // | |
742 | // Add a status pave to a plot | |
743 | // | |
744 | if (xh < 0) xh = gStyle->GetStatX(); | |
745 | if (xl < 0) xl = xh - gStyle->GetStatW(); | |
746 | if (yh < 0) yh = gStyle->GetStatY(); | |
747 | if (yl < 0) yl = xl - gStyle->GetStatH(); | |
748 | ||
749 | TPaveText* text = new TPaveText(xl, yl, xh, yh, "brNDC"); | |
750 | Int_t bg = kGreen-10; | |
751 | Int_t fg = kBlack; | |
752 | TString msg = "OK"; | |
753 | if (qual >= kWhatTheFk) { bg = kRed+1; fg = kWhite; msg = "Argh!"; } | |
754 | else if (qual >= kBad) { bg = kRed-3; fg = kWhite; msg = "Bad"; } | |
755 | else if (qual >= kProblem) { bg = kOrange-4; msg = "Warning"; } | |
756 | text->AddText(msg); | |
757 | text->SetTextFont(62); | |
758 | text->SetTextColor(fg); | |
759 | text->SetFillColor(bg); | |
760 | ||
761 | TList* ll = hist->GetListOfFunctions(); | |
762 | TObject* old = ll->FindObject(text->GetName()); | |
763 | if (old) { | |
764 | ll->Remove(old); | |
765 | delete old; | |
766 | } | |
767 | ll->Add(text); | |
768 | } | |
769 | ||
c9dd1c4d | 770 | //__________________________________________________________________ |
fa5a224b | 771 | void AliFMDQAChecker::Check(Double_t* rv, |
772 | AliQAv1::ALITASK_t what, | |
773 | TObjArray** list, | |
774 | const AliDetectorRecoParam* /*t*/) | |
775 | { | |
776 | // | |
777 | // Member function called to do the actual checking | |
778 | // | |
779 | // Parameters: | |
780 | // rv Array of return values. | |
781 | // what What to check | |
782 | // list Array of arrays of histograms. There's one arrat for | |
783 | // each 'specie' | |
784 | // t Reconstruction parameters - not used. | |
785 | // | |
1306ba55 | 786 | // The bounds defined for RV are |
787 | // | |
788 | // FATAL: [-1, 0.0] | |
789 | // ERROR: (0.0, 0.002] | |
790 | // WARNING: (0.002,0.5] | |
791 | // INFO: (0.5, 1.0] | |
792 | // | |
fa5a224b | 793 | // Double_t* rv = new Double_t[AliRecoParam::kNSpecies] ; |
1306ba55 | 794 | |
795 | if (!fDidExternal) ProcessExternalParams(); | |
796 | ||
6ceca4ef | 797 | for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { |
83dbc5b8 | 798 | // Int_t count = 0; |
fa5a224b | 799 | rv[specie] = 0.; |
800 | ||
1706c710 | 801 | if (!AliQAv1::Instance()->IsEventSpecieSet(specie) ) |
6ceca4ef | 802 | continue ; |
803 | ||
804 | if(!list[specie]) continue; | |
805 | ||
a3e1fdcc | 806 | TH1* hist = 0; |
807 | Int_t nHist = list[specie]->GetEntriesFast(); | |
808 | ||
809 | // Find the status histogram if any | |
810 | TH2* status = 0; | |
811 | Int_t istatus = AliFMDQADataMakerRec::GetHalfringIndex(4, 'i', 0, 0); | |
812 | if (istatus < nHist) | |
813 | status = dynamic_cast<TH2*>(list[specie]->At(istatus)); | |
814 | ||
815 | UShort_t ret = 0; | |
584d4c54 | 816 | for(Int_t i= 0; i< nHist; i++) { |
05e5e0c1 | 817 | if (!(hist = static_cast<TH1*>(list[specie]->At(i)))) continue; |
a3e1fdcc | 818 | if (hist == status) continue; |
819 | ||
1306ba55 | 820 | Int_t qual = CheckOne(what, AliRecoParam::ConvertIndex(specie), hist); |
821 | hist->SetUniqueID(Quality2Bit(qual)); | |
1d65d916 | 822 | hist->SetStats(0); |
823 | AddStatusPave(hist, qual); | |
1306ba55 | 824 | ret += qual; |
a3e1fdcc | 825 | |
826 | if (!status) continue; | |
827 | ||
1d65d916 | 828 | // Parse out the detector and ring, calculate the bin, and fill |
829 | // status histogram. | |
a3e1fdcc | 830 | TString nme(hist->GetName()); |
831 | Char_t cD = nme[nme.Length()-2]; | |
832 | Char_t cR = nme[nme.Length()-1]; | |
833 | Int_t xbin = 0; | |
834 | switch (cD) { | |
835 | case '1': xbin = 1; break; | |
836 | case '2': xbin = 2 + ((cR == 'i' || cR == 'I') ? 0 : 1); break; | |
837 | case '3': xbin = 4 + ((cR == 'i' || cR == 'I') ? 0 : 1); break; | |
838 | } | |
839 | if (xbin == 0) continue; | |
840 | status->Fill(xbin, qual); | |
841 | ||
fa5a224b | 842 | } // for (int i ...) |
1306ba55 | 843 | rv[specie] = ret; |
844 | // if (ret > kWhatTheFk) rv[specie] = fLowTestValue[AliQAv1::kFATAL]; | |
845 | // else if (ret > kBad) rv[specie] = fUpTestValue[AliQAv1::kERROR]; | |
846 | // else if (ret > kProblem) rv[specie] = fUpTestValue[AliQAv1::kWARNING]; | |
847 | // else rv[specie] = fUpTestValue[AliQAv1::kINFO]; | |
848 | AliDebugF(3, "Combined sum is %d -> %f", ret, rv[specie]); | |
849 | ||
a3e1fdcc | 850 | if (status) { |
550157b2 | 851 | Int_t nProblem = 0; |
852 | Int_t nBad = 0; | |
a3e1fdcc | 853 | for (Int_t i = 1; i < status->GetXaxis()->GetNbins(); i++) { |
550157b2 | 854 | nProblem += status->GetBinContent(i, 3); |
855 | nBad += status->GetBinContent(i, 4); | |
a3e1fdcc | 856 | } |
550157b2 | 857 | Int_t qual = 0; |
858 | if (nProblem > fMaxNProblem) qual++; | |
859 | if (nBad > fMaxNBad) qual += 2; | |
a3e1fdcc | 860 | status->SetUniqueID(Quality2Bit(qual)); |
1d65d916 | 861 | AddStatusPave(status, qual); |
a3e1fdcc | 862 | } |
83dbc5b8 | 863 | // if (count != 0) rv[specie] /= count; |
6ceca4ef | 864 | } |
fa5a224b | 865 | // return rv; |
6ceca4ef | 866 | } |
867 | ||
05e5e0c1 | 868 | namespace { |
869 | Int_t CheckForLog(TAxis* axis, | |
870 | TVirtualPad* pad, | |
871 | Int_t xyz) | |
872 | { | |
873 | Int_t ret = 0; | |
874 | TString t(axis->GetTitle()); | |
875 | if (!t.Contains("[log]", TString::kIgnoreCase)) return 0; | |
876 | t.ReplaceAll("[log]", ""); | |
877 | switch (xyz) { | |
878 | case 1: pad->SetLogx(); ret |= 0x1; break; | |
879 | case 2: pad->SetLogy(); ret |= 0x2; break; | |
880 | case 3: pad->SetLogz(); ret |= 0x4; break; | |
881 | } | |
882 | axis->SetTitle(t); | |
883 | return ret; | |
884 | } | |
9eb9c521 | 885 | void RestoreLog(TAxis* axis, Bool_t log) |
886 | { | |
887 | if (!log) return; | |
888 | TString t(axis->GetTitle()); | |
889 | t.Append("[log]"); | |
890 | axis->SetTitle(t); | |
891 | } | |
05e5e0c1 | 892 | } |
6ceca4ef | 893 | |
0f666f27 | 894 | namespace { |
895 | void FindMinMax(TH1* h, Double_t& min, Double_t& max) | |
896 | { | |
897 | Double_t tmin = 1e9; | |
898 | Double_t tmax = 0; | |
899 | for (Int_t i = 1; i <= h->GetNbinsX(); i++) { | |
900 | Double_t c = h->GetBinContent(i); | |
901 | if (c < 1e-8) continue; | |
902 | tmin = TMath::Min(tmin, c); | |
903 | tmax = TMath::Max(tmax, c); | |
904 | } | |
905 | min = tmin; | |
906 | max = tmax; | |
907 | } | |
908 | } | |
a3e1fdcc | 909 | |
910 | namespace { | |
911 | Int_t GetHalfringPad(TH1* h) { | |
912 | TString nme(h->GetName()); | |
913 | Char_t cD = nme[nme.Length()-2]; | |
914 | Char_t cR = nme[nme.Length()-1]; | |
915 | Int_t xbin = 0; | |
916 | switch (cD) { | |
917 | case '1': xbin = 1; break; | |
918 | case '2': xbin = ((cR == 'i' || cR == 'I') ? 2 : 5); break; | |
919 | case '3': xbin = ((cR == 'i' || cR == 'I') ? 3 : 6); break; | |
920 | } | |
921 | return xbin; | |
922 | } | |
923 | } | |
924 | ||
1706c710 | 925 | //____________________________________________________________________________ |
926 | void | |
927 | AliFMDQAChecker::MakeImage(TObjArray** list, | |
928 | AliQAv1::TASKINDEX_t task, | |
929 | AliQAv1::MODE_t mode) | |
930 | { | |
931 | // makes the QA image for sim and rec | |
932 | // | |
933 | // Parameters: | |
934 | // task What to check | |
935 | // list Array of arrays of histograms. There's one array for | |
936 | // each 'specie' | |
937 | // t Reconstruction parameters - not used. | |
938 | // | |
939 | Int_t nImages = 0 ; | |
940 | Double_t max = 0; | |
941 | Double_t min = 10000; | |
9eb9c521 | 942 | |
943 | // Loop over all species | |
1706c710 | 944 | for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { |
05e5e0c1 | 945 | AliRecoParam::EventSpecie_t spe = AliRecoParam::ConvertIndex(specie); |
946 | if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) | |
947 | ->IsEventSpecieSet(spe)) | |
544ed74f | 948 | continue; |
9eb9c521 | 949 | |
950 | // If nothing is defined for this specie, go on. | |
05e5e0c1 | 951 | if(!list[specie] || list[specie]->GetEntriesFast() == 0) continue; |
1706c710 | 952 | |
9eb9c521 | 953 | // Loop over the histograms and figure out how many histograms we |
954 | // have and the min/max | |
05e5e0c1 | 955 | TH1* hist = 0; |
1706c710 | 956 | Int_t nHist = list[specie]->GetEntriesFast(); |
957 | for(Int_t i= 0; i< nHist; i++) { | |
958 | hist = static_cast<TH1F*>(list[specie]->At(i)); | |
ae559def | 959 | if (hist && hist->TestBit(AliQAv1::GetImageBit())) { |
1706c710 | 960 | nImages++; |
05e5e0c1 | 961 | TString name(hist->GetName()); |
a3e1fdcc | 962 | if (name.Contains("readouterrors", TString::kIgnoreCase) || |
963 | name.Contains("status", TString::kIgnoreCase)) continue; | |
0f666f27 | 964 | |
965 | // Double_t hMax = hist->GetMaximum(); | |
05e5e0c1 | 966 | // hist->GetBinContent(hist->GetMaximumBin()); |
0f666f27 | 967 | // Double_t hMin = hist->GetMinimum(); |
05e5e0c1 | 968 | // hist->GetBinContent(hist->GetMinimumBin()); |
0f666f27 | 969 | Double_t hMax, hMin; |
970 | FindMinMax(hist, hMin, hMax); | |
05e5e0c1 | 971 | max = TMath::Max(max, hMax); |
972 | min = TMath::Min(min, hMin); | |
1306ba55 | 973 | // AliInfoF("Min/max of %40s: %f/%f, global -> %f/%f", |
974 | // hist->GetName(), hMin, hMax, min, max); | |
1706c710 | 975 | } |
976 | } | |
977 | break ; | |
978 | } | |
1306ba55 | 979 | // AliInfoF("Global min/max=%f/%f", min, max); |
9558fc76 | 980 | min = TMath::Max(1e-1, min); |
981 | max = TMath::Max(1e5, max); | |
1706c710 | 982 | |
9eb9c521 | 983 | // IF no images, go on. |
1706c710 | 984 | if (nImages == 0) { |
985 | AliDebug(AliQAv1::GetQADebugLevel(), | |
986 | Form("No histogram will be plotted for %s %s\n", GetName(), | |
987 | AliQAv1::GetTaskName(task).Data())); | |
988 | return; | |
989 | } | |
990 | ||
991 | AliDebug(AliQAv1::GetQADebugLevel(), | |
992 | Form("%d histograms will be plotted for %s %s\n", | |
993 | nImages, GetName(), AliQAv1::GetTaskName(task).Data())); | |
05e5e0c1 | 994 | gStyle->SetOptStat(0); |
9eb9c521 | 995 | |
996 | // Again loop over species and draw a canvas | |
1706c710 | 997 | for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { |
05e5e0c1 | 998 | if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) |
999 | ->IsEventSpecieSet(specie)) continue; | |
1706c710 | 1000 | |
9eb9c521 | 1001 | // if Nothing here, go on |
1002 | if(!list[specie] || list[specie]->GetEntries() <= 0 || | |
1003 | nImages <= 0) continue; | |
1004 | ||
9558fc76 | 1005 | // Form the title |
1706c710 | 1006 | const Char_t * title = Form("QA_%s_%s_%s", GetName(), |
1007 | AliQAv1::GetTaskName(task).Data(), | |
1008 | AliRecoParam::GetEventSpecieName(specie)); | |
9eb9c521 | 1009 | if (!fImage[specie]) fImage[specie] = new TCanvas(title, title) ; |
1706c710 | 1010 | fImage[specie]->Clear() ; |
1011 | fImage[specie]->SetTitle(title) ; | |
1012 | fImage[specie]->cd() ; | |
1013 | ||
9eb9c521 | 1014 | // Put something in the canvas - even if empty |
1706c710 | 1015 | TPaveText someText(0.015, 0.015, 0.98, 0.98) ; |
1016 | someText.AddText(title) ; | |
9eb9c521 | 1017 | someText.SetFillColor(0); |
1018 | someText.SetFillStyle(0); | |
1019 | someText.SetBorderSize(0); | |
1020 | someText.SetTextColor(kRed+1); | |
1706c710 | 1021 | someText.Draw() ; |
05e5e0c1 | 1022 | TString outName(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), |
1023 | AliQAv1::GetModeName(mode), | |
1024 | AliQAChecker::Instance()->GetRunNumber(), | |
1025 | AliQAv1::GetImageFileFormat())); | |
1026 | fImage[specie]->Print(outName, "ps") ; | |
1706c710 | 1027 | |
9eb9c521 | 1028 | // Now set some parameters on the canvas |
1029 | fImage[specie]->Clear(); | |
1030 | fImage[specie]->SetTopMargin(0.10); | |
1031 | fImage[specie]->SetBottomMargin(0.15); | |
1032 | fImage[specie]->SetLeftMargin(0.15); | |
1033 | fImage[specie]->SetRightMargin(0.05); | |
1034 | ||
1035 | // Put title on top | |
1036 | const char* topT = Form("Mode: %s, Task: %s, Specie: %s, Run: %d", | |
1037 | AliQAv1::GetModeName(mode), | |
1038 | AliQAv1::GetTaskName(task).Data(), | |
1039 | AliRecoParam::GetEventSpecieName(specie), | |
1040 | AliQAChecker::Instance()->GetRunNumber()); | |
1041 | TLatex* topText = new TLatex(.5, .99, topT); | |
1042 | topText->SetTextAlign(23); | |
1043 | topText->SetTextSize(.038); | |
1044 | topText->SetTextFont(42); | |
1045 | topText->SetTextColor(kBlue+3); | |
1046 | topText->SetNDC(); | |
1047 | topText->Draw(); | |
a3e1fdcc | 1048 | |
1049 | // Find the status histogram if any | |
1050 | TH2* status = 0; | |
1051 | Int_t istatus = AliFMDQADataMakerRec::GetHalfringIndex(4, 'i', 0, 0); | |
1052 | if (istatus < list[specie]->GetEntriesFast()) | |
1053 | status = dynamic_cast<TH2*>(list[specie]->At(istatus)); | |
1054 | ||
9eb9c521 | 1055 | // Divide canvas |
9558fc76 | 1056 | // if (fDoScale) |
a3e1fdcc | 1057 | TVirtualPad* plots = fImage[specie]; |
1058 | TVirtualPad* stat = 0; | |
1059 | if (status) { | |
1060 | // AliWarning("Drawing plots sub-pad"); | |
1061 | TPad* pM = new TPad("plots", "Plots Pad", 0, .2, 1., .9, 0, 0); | |
1062 | fImage[specie]->cd(); | |
1063 | pM->Draw(); | |
1064 | plots = pM; | |
1065 | // AliWarning("Drawing status sub-pad"); | |
1066 | TPad* pS = new TPad("status", "Status Pad", 0, 0, 1., .2, 0, 0); | |
1067 | fImage[specie]->cd(); | |
1068 | pS->Draw(); | |
1069 | pS->SetLogz(); | |
1070 | stat = pS; | |
1071 | // status->DrawCopy("colz"); | |
1072 | } | |
1073 | // AliWarningF("fImage[specie]=%p, plots=%p", fImage[specie], plots); | |
1074 | // plots->cd(); | |
1075 | Int_t nx = 3; | |
1076 | Int_t ny = (nImages + .5) / nx; | |
1077 | plots->Divide(nx, ny, 0, 0); | |
9558fc76 | 1078 | // else fImage[specie]->Divide(nx, ny); |
1706c710 | 1079 | |
1080 | ||
9eb9c521 | 1081 | // Loop over histograms |
05e5e0c1 | 1082 | TH1* hist = 0; |
1706c710 | 1083 | Int_t nHist = list[specie]->GetEntriesFast(); |
1706c710 | 1084 | for (Int_t i = 0; i < nHist; i++) { |
05e5e0c1 | 1085 | hist = static_cast<TH1*>(list[specie]->At(i)); |
1086 | if (!hist || !hist->TestBit(AliQAv1::GetImageBit())) continue; | |
a3e1fdcc | 1087 | if (hist == status) continue; |
1088 | TString name(hist->GetName()); | |
1089 | Bool_t isROE = name.Contains("readouterrors", TString::kIgnoreCase); | |
9eb9c521 | 1090 | |
1091 | // Go to sub-pad | |
a3e1fdcc | 1092 | TVirtualPad* pad = 0; |
1093 | if (isROE) pad = plots->cd(4); | |
1094 | else pad = plots->cd(GetHalfringPad(hist)); | |
1095 | ||
9eb9c521 | 1096 | pad->SetRightMargin(0.01); |
9558fc76 | 1097 | if (!fDoScale) { |
1098 | pad->SetLeftMargin(0.10); | |
1099 | pad->SetBottomMargin(0.10); | |
1100 | } | |
9eb9c521 | 1101 | |
1102 | // Check for log scale | |
05e5e0c1 | 1103 | Int_t logOpts = 0; |
1104 | logOpts |= CheckForLog(hist->GetXaxis(), pad, 1); | |
1105 | logOpts |= CheckForLog(hist->GetYaxis(), pad, 2); | |
1106 | logOpts |= CheckForLog(hist->GetZaxis(), pad, 3); | |
05e5e0c1 | 1107 | |
9eb9c521 | 1108 | // Figure out special cases |
1306ba55 | 1109 | TString opt(""); |
a3e1fdcc | 1110 | if (isROE) { |
05e5e0c1 | 1111 | pad->SetRightMargin(0.15); |
1112 | pad->SetBottomMargin(0.10); | |
9558fc76 | 1113 | // pad->SetTopMargin(0.02); |
05e5e0c1 | 1114 | opt="COLZ"; |
1115 | } | |
1116 | else { | |
9eb9c521 | 1117 | pad->SetGridx(); |
1118 | pad->SetGridy(); | |
9558fc76 | 1119 | if (fDoScale) { |
1120 | hist->SetMinimum(min); | |
1121 | hist->SetMaximum(max); | |
1122 | } | |
1123 | else { | |
1124 | hist->SetMinimum(); | |
1125 | hist->SetMaximum(); | |
1126 | } | |
05e5e0c1 | 1127 | } |
9eb9c521 | 1128 | // Draw (As a copy) |
05e5e0c1 | 1129 | hist->DrawCopy(opt); |
1306ba55 | 1130 | |
9eb9c521 | 1131 | // Special cases |
550157b2 | 1132 | if (!name.Contains("readouterrors", TString::kIgnoreCase)) { |
9eb9c521 | 1133 | gStyle->SetOptTitle(0); |
1134 | TPad* insert = new TPad("insert", "Zoom", | |
a3e1fdcc | 1135 | .5,.5, .99, .95, 0, 0, 0); |
9eb9c521 | 1136 | insert->SetTopMargin(0.01); |
1137 | insert->SetRightMargin(0.01); | |
1138 | insert->SetFillColor(0); | |
1139 | insert->SetBorderSize(1); | |
1140 | insert->SetBorderMode(0); | |
1141 | insert->Draw(); | |
1142 | insert->cd(); | |
1143 | if (logOpts & 0x1) insert->SetLogx(); | |
1144 | if (logOpts & 0x2) insert->SetLogy(); | |
1145 | if (logOpts & 0x4) insert->SetLogz(); | |
0f666f27 | 1146 | hist->GetXaxis()->SetRange(1, hist->GetNbinsX()/8); |
1147 | TH1* copy = hist->DrawCopy(opt); | |
1148 | copy->GetXaxis()->SetNdivisions(408, false); | |
9eb9c521 | 1149 | // Restore full range |
0f666f27 | 1150 | hist->GetXaxis()->SetRange(0, 0); |
9eb9c521 | 1151 | gStyle->SetOptTitle(1); |
1152 | } | |
05e5e0c1 | 1153 | pad->cd(); |
9eb9c521 | 1154 | // Possibly restore the log options |
1155 | RestoreLog(hist->GetXaxis(), logOpts & 0x1); | |
1156 | RestoreLog(hist->GetYaxis(), logOpts & 0x2); | |
1157 | RestoreLog(hist->GetZaxis(), logOpts & 0x4); | |
1706c710 | 1158 | } |
a3e1fdcc | 1159 | if (status && stat) { |
1160 | stat->cd(); | |
1161 | status->DrawCopy("BOX TEXT"); | |
1162 | } | |
0f666f27 | 1163 | // Print to a post-script file |
05e5e0c1 | 1164 | fImage[specie]->Print(outName, "ps"); |
550157b2 | 1165 | if (AliDebugLevel() > 0) |
a3e1fdcc | 1166 | fImage[specie]->Print(Form("%s_%d.png", |
1167 | AliRecoParam::GetEventSpecieName(specie), | |
1168 | AliQAChecker::Instance()->GetRunNumber())); | |
1706c710 | 1169 | } |
1170 | } | |
c9dd1c4d | 1171 | |
1172 | //__________________________________________________________________ | |
1173 | // | |
1174 | // EOF | |
1175 | // |