1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 //__________________________________________________________________
25 //__________________________________________________________________
27 // --- ROOT system ---
33 #include <TIterator.h>
38 #include <TPaveText.h>
41 #include <TFitResult.h>
42 #include <TParameter.h>
45 // --- AliRoot header files ---
48 #include "AliQAChecker.h"
49 #include "AliFMDQAChecker.h"
50 #include "AliRecoParam.h"
51 #include <AliCDBManager.h>
52 #include <AliCDBEntry.h>
54 #include <AliQAThresholds.h>
56 ClassImp(AliFMDQAChecker)
58 ; // This is for Emacs! - do not delete
62 void addFitsMacro(TList* l) {
63 TMacro* m = new TMacro("fits");
64 m->AddLine("void fits() {");
65 m->AddLine(" if (!gPad) { Printf(\"No gPad\"); return; }");
66 m->AddLine(" TList* lp = gPad->GetListOfPrimitives();");
67 m->AddLine(" if (!lp) return;");
68 m->AddLine(" TObject* po = 0;");
69 m->AddLine(" TIter next(lp);");
70 m->AddLine(" while ((po = next())) {");
71 m->AddLine(" if (!po->IsA()->InheritsFrom(TH1::Class())) continue;");
72 m->AddLine(" TH1* htmp = dynamic_cast<TH1*>(po);");
73 m->AddLine(" TList* lf = htmp->GetListOfFunctions();");
74 m->AddLine(" TObject* pso = (lf ? lf->FindObject(\"stats\") : 0);");
75 m->AddLine(" if (!pso) continue;");
76 m->AddLine(" TPaveStats* ps = static_cast<TPaveStats*>(pso);");
77 m->AddLine(" ps->SetOptFit(111);");
78 m->AddLine(" UShort_t qual = htmp->GetUniqueID();");
79 m->AddLine(" ps->SetFillColor(qual >= 3 ? kRed-4 : qual >= 2 ? kOrange-4 : qual >= 1 ? kYellow-4 : kGreen-4);");
80 // m->AddLine(" lf->Remove(lf->FindObject(\"fits\"));");
81 // m->AddLine(" ps->Paint();");
82 m->AddLine(" break;");
84 // m->AddLine(" gPad->Modified(); gPad->Update(); gPad->cd();");
87 TObject* old = l->FindObject(m->GetName());
88 if (old) l->Remove(old);
92 const Double_t kROErrorsLabelY = 30.;
94 const Int_t kConvolutionSteps = 100;
95 const Double_t kConvolutionNSigma = 5;
98 // The shift of the most probable value for the ROOT function TMath::Landau
100 const Double_t kMpShift = -0.22278298;
102 // Integration normalisation
104 const Double_t kInvSq2Pi = 1. / TMath::Sqrt(2*TMath::Pi());
106 Double_t landau(Double_t x, Double_t delta, Double_t xi)
109 // Calculate the shifted Landau
111 // f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
114 // where @f$ f_{L}@f$ is the ROOT implementation of the Landau
115 // distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
116 // @f$\Delta=0,\xi=1@f$.
119 // x Where to evaluate @f$ f'_{L}@f$
120 // delta Most probable value
121 // xi The 'width' of the distribution
124 // @f$ f'_{L}(x;\Delta,\xi) @f$
126 return TMath::Landau(x, delta - xi * kMpShift, xi);
128 Double_t landauGaus(Double_t x, Double_t delta, Double_t xi,
129 Double_t sigma, Double_t sigmaN)
132 // Calculate the value of a Landau convolved with a Gaussian
135 // f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
136 // \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
137 // \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
140 // where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$
141 // the energy loss, @f$ \xi@f$ the width of the Landau, and @f$
142 // \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
143 // variance of the Gaussian, and @f$\sigma_n@f$ is a parameter
144 // modelling noise in the detector.
146 // Note that this function uses the constants kConvolutionSteps and
147 // kConvolutionNSigma
150 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
151 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
152 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
155 // x where to evaluate @f$ f@f$
156 // delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
157 // xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
158 // sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
159 // sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
162 // @f$ f@f$ evaluated at @f$ x@f$.
164 Double_t deltap = delta - xi * kMpShift;
165 Double_t sigma2 = sigmaN*sigmaN + sigma*sigma;
166 Double_t sigma1 = sigmaN == 0 ? sigma : TMath::Sqrt(sigma2);
167 Double_t xlow = x - kConvolutionNSigma * sigma1;
168 Double_t xhigh = x + kConvolutionNSigma * sigma1;
169 Double_t step = (xhigh - xlow) / kConvolutionSteps;
172 for (Int_t i = 0; i <= kConvolutionSteps/2; i++) {
173 Double_t x1 = xlow + (i - .5) * step;
174 Double_t x2 = xhigh - (i - .5) * step;
176 sum += TMath::Landau(x1, deltap, xi, kTRUE) * TMath::Gaus(x, x1, sigma1);
177 sum += TMath::Landau(x2, deltap, xi, kTRUE) * TMath::Gaus(x, x2, sigma1);
179 return step * sum * kInvSq2Pi / sigma1;
183 // Utility function to use in TF1 defintition
185 Double_t landauGaus1(Double_t* xp, Double_t* pp)
188 Double_t constant = pp[0];
189 Double_t delta = pp[1];
191 Double_t sigma = pp[3];
192 Double_t sigmaN = pp[4];
194 return constant * landauGaus(x, delta, xi, sigma, sigmaN);
197 //____________________________________________________________________
198 TF1* makeLandauGaus(const char* ,
200 Double_t delta=.5, Double_t xi=0.07,
201 Double_t sigma=.1, Double_t sigmaN=-1,
202 Double_t xmin=0, Double_t xmax=15)
205 // Generate a TF1 object of @f$ f_I@f$
209 // delta @f$ \Delta@f$
211 // sigma @f$ \sigma_1@f$
212 // sigma_n @f$ \sigma_n@f$
213 // xmin Least value of range
214 // xmax Largest value of range
217 // Newly allocated TF1 object
220 TF1* func = new TF1("landauGaus",
221 &landauGaus1,xmin,xmax,npar);
222 // func->SetLineStyle(((i-2) % 10)+2); // start at dashed
223 func->SetLineColor(kBlack);
224 func->SetLineWidth(2);
226 func->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}");
228 // Set the initial parameters from the seed fit
229 func->SetParameter(0, c);
230 func->SetParameter(1, delta);
231 func->SetParameter(2, xi);
232 func->SetParameter(3, sigma);
233 func->SetParameter(4, sigmaN);
235 func->SetParLimits(1, 0, xmax);
236 func->SetParLimits(2, 0, xmax);
237 func->SetParLimits(3, 0.01, 0.4);
239 if (sigmaN < 0) func->FixParameter(4, 0);
240 else func->SetParLimits(4, 0, xmax);
246 //__________________________________________________________________
247 AliFMDQAChecker::AliFMDQAChecker()
248 : AliQACheckerBase("FMD","FMD Quality Assurance Checker") ,
251 fShowFitResults(true),
255 fELossFkupChi2Nu(100),
256 fELossMinEntries(1000),
257 fELossGoodParError(0.1),
263 //__________________________________________________________________
265 AliFMDQAChecker::ProcessExternalParams()
267 ProcessExternalParam("ELossLowCut", fELossLowCut);
268 ProcessExternalParam("ELossNRMS", fELossNRMS);
269 ProcessExternalParam("ELossBadChi2Nu", fELossBadChi2Nu);
270 ProcessExternalParam("ELossFkupChi2Nu", fELossFkupChi2Nu);
271 ProcessExternalParam("ELossGoodParError", fELossGoodParError);
272 ProcessExternalParam("ROErrorsBad", fROErrorsBad);
273 ProcessExternalParam("ROErrorsFkup", fROErrorsFkup);
275 ProcessExternalParam("CommonScale", tmp);
277 ProcessExternalParam("ELossMinEntries", tmp);
278 fELossMinEntries = tmp;
284 //__________________________________________________________________
286 AliFMDQAChecker::ProcessExternalParam(const char* name, Double_t& v)
288 TObject* o = fExternParamList->FindObject(name);
290 TParameter<double>* p = static_cast<TParameter<double>*>(o);
292 AliDebugF(3, "External parameter: %-20s=%lf", name, v);
295 //__________________________________________________________________
297 AliFMDQAChecker::GetThresholds()
299 const char* path = "GRP/Calib/QAThresholds";
300 AliCDBManager* cdbMan = AliCDBManager::Instance();
301 AliCDBEntry* cdbEnt = cdbMan->Get(path);
303 AliWarningF("Failed to get CDB entry at %s", path);
307 TObjArray* cdbObj = static_cast<TObjArray*>(cdbEnt->GetObject());
309 AliWarningF("Failed to get CDB object at %s", path);
313 TObject* fmdObj = cdbObj->FindObject("FMD");
315 AliWarningF("Failed to get FMD object at from CDB %s", path);
319 AliQAThresholds* qaThr = static_cast<AliQAThresholds*>(fmdObj);
320 Int_t nThr = qaThr->GetSize();
321 for (Int_t i = 0; i < nThr; i++) {
322 TObject* thr = qaThr->GetThreshold(i);
325 TParameter<double>* d = dynamic_cast<TParameter<double>*>(thr);
327 AliWarningF("Parameter %s not of type double", thr->GetName());
330 Double_t val = d->GetVal();
331 TString name(thr->GetName());
332 if (name.EqualTo("ELossBadChi2Nu")) fELossBadChi2Nu = val;
333 else if (name.EqualTo("ELossFkupChi2Nu")) fELossFkupChi2Nu = val;
334 else if (name.EqualTo("ELossGoodParError")) fELossGoodParError = val;
335 else if (name.EqualTo("ROErrorsBad")) fROErrorsBad = val;
336 else if (name.EqualTo("ROErrorsFkup")) fROErrorsFkup = val;
337 AliDebugF(3, "Threshold %s=%f", name.Data(), val);
341 //__________________________________________________________________
343 AliFMDQAChecker::Quality2Bit(UShort_t value) const
345 AliQAv1::QABIT_t ret = AliQAv1::kINFO; // Assume success
346 if (value >= kWhatTheFk) ret = AliQAv1::kFATAL;
347 else if (value >= kBad) ret = AliQAv1::kERROR;
348 else if (value >= kProblem) ret = AliQAv1::kWARNING;
353 //__________________________________________________________________
355 AliFMDQAChecker::SetQA(AliQAv1::ALITASK_t index, Double_t* values) const
357 AliQAv1 * qa = AliQAv1::Instance(index) ;
359 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
360 // Check if specie is defined
361 if (!qa->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)))
364 // No checker is implemented, set all QA to Fatal
366 qa->Set(AliQAv1::kFATAL, specie) ;
370 UShort_t value = values[specie];
371 AliQAv1::QABIT_t ret = Quality2Bit(value);
373 qa->Set(ret, AliRecoParam::ConvertIndex(specie));
374 AliDebugF(3, "Quality of %s: %d -> %d",
375 AliRecoParam::GetEventSpecieName(specie), value, ret);
379 //__________________________________________________________________
381 AliFMDQAChecker::BasicCheck(TH1* hist) const
383 if (hist->GetEntries() <= 0) return kOK;
384 return (hist->GetMean() > 0 ? kOK : kProblem);
387 //__________________________________________________________________
389 AliFMDQAChecker::CheckOne(AliQAv1::ALITASK_t what,
390 AliRecoParam::EventSpecie_t specie,
393 if(what == AliQAv1::kESD) return CheckESD(specie, hist);
394 if(what == AliQAv1::kRAW) return CheckRaw(specie, hist);
395 if(what == AliQAv1::kSIM) return CheckSim(specie, hist);
396 if(what == AliQAv1::kREC) return CheckRec(specie, hist);
399 //__________________________________________________________________
401 AliFMDQAChecker::CheckESD(AliRecoParam::EventSpecie_t /* specie*/,
404 return BasicCheck(hist);
406 //__________________________________________________________________
408 AliFMDQAChecker::CheckFit(TH1* hist, const TFitResultPtr& res,
409 Double_t low, Double_t high, Int_t& color) const
414 Int_t nPar = res->NPar();
418 Double_t chi2 = res->Chi2();
419 Int_t nu = res->Ndf();
420 Double_t red = (nu == 0 ? fELossFkupChi2Nu : chi2 / nu);
421 TObjArray* lines = 0;
424 if (fShowFitResults) {
425 lines = new TObjArray(nPar+3);
426 lines->SetName("lines");
427 lines->SetOwner(true);
429 ltx = new TLatex(x, y, Form("#chi^{2}/#nu: %7.3f",red));
431 ltx->SetTextColor(color);
432 ltx->SetTextSize(dy-.01);
438 ltx = new TLatex(x1, y1, Form("[thresholds: %6.2f, %6.2f]",
439 fELossBadChi2Nu, fELossFkupChi2Nu));
440 ltx->SetTextColor(kGray+3);
441 ltx->SetTextSize(dy-.01);
443 ltx->SetTextAlign(31);
447 ltx = new TLatex(x1, y1, Form("Fit range: [%6.2f,%6.2f]", low, high));
448 ltx->SetTextColor(kGray+3);
449 ltx->SetTextSize(dy-.01);
450 ltx->SetTextAlign(31);
455 ltx = new TLatex(x1, y1, Form("Entries: %d",
456 Int_t(hist->GetEffectiveEntries())));
457 ltx->SetTextColor(kGray+3);
458 ltx->SetTextSize(dy-.01);
459 ltx->SetTextAlign(31);
464 if (red > fELossBadChi2Nu) { // || res->Prob() < .01) {
465 AliWarningF("Fit gave chi^2/nu=%f/%d=%f>%f (%f)",
466 res->Chi2(), res->Ndf(), red, fELossBadChi2Nu,
468 if (lRed) lRed->SetTextColor(kOrange+2);
471 if (red > fELossFkupChi2Nu) {
472 if (lRed) lRed->SetTextColor(kRed+2);
476 // Now check the relative error on the fit parameters
478 for (Int_t i = 0; i < nPar; i++) {
479 if (res->IsParameterFixed(i)) continue;
480 Double_t pv = res->Parameter(i);
481 Double_t pe = res->ParError(i);
482 Double_t rel = (pv == 0 ? 100 : pe / pv);
485 ltx = new TLatex(x, y, Form("#delta%s/%s: %7.3f",
486 res->ParName(i).c_str(),
487 res->ParName(i).c_str(),
490 ltx->SetTextColor(color);
491 ltx->SetTextSize(dy-.01);
494 if (i == 3) continue; // Skip sigma
495 Double_t thr = fELossGoodParError;
496 if (rel < thr) parsOk++;
497 else if (ltx) ltx->SetLineColor(kOrange+2);
500 ret = TMath::Max(ret-(parsOk-1),0);
501 if (ret > 1) color = kRed+2;
502 if (ret > 0) color = kOrange+2;
504 TList* lf = hist->GetListOfFunctions();
505 TObject* old = lf->FindObject(lines->GetName());
511 hist->SetStats(false);
516 //__________________________________________________________________
518 AliFMDQAChecker::AddFitResults(TH1* hist, const TFitResultPtr& res,
519 Int_t color, Double_t low, Double_t high) const
521 if (!fShowFitResults) return;
523 Int_t nPar = res->NPar();
524 TObjArray* lines = new TObjArray(nPar+1);
525 lines->SetOwner(kTRUE);
526 lines->SetName("fitResults");
531 Double_t chi2 = res->Chi2();
532 Int_t nu = res->Ndf();
533 Double_t red = (nu == 0 ? fELossFkupChi2Nu : chi2 / nu);
535 TLatex* ltx = new TLatex(x, y, Form("#chi^{2}/#nu: %7.3f",red));
537 ltx->SetTextColor(color);
538 ltx->SetTextSize(dy-.01);
542 ltx = new TLatex(x, y, Form("[thresholds: %6.2f, %6.2f]",
543 fELossBadChi2Nu, fELossFkupChi2Nu));
544 ltx->SetTextColor(kGray+3);
545 ltx->SetTextSize(dy-.01);
550 ltx = new TLatex(x, y, Form("Fit range: [%6.2f,%6.2f]", low, high));
551 ltx->SetTextColor(kGray+3);
552 ltx->SetTextSize(dy-.01);
556 for (Int_t i = 0; i < nPar; i++) {
557 if (res->IsParameterFixed(i)) continue;
559 Double_t pv = res->Parameter(i);
560 Double_t pe = res->ParError(i);
561 Double_t rel = (pv == 0 ? 100 : pe / pv);
562 ltx = new TLatex(x, y, Form("#delta%s/%s: %7.3f",
563 res->ParName(i).c_str(),
564 res->ParName(i).c_str(),
567 ltx->SetTextColor(color);
568 ltx->SetTextSize(dy-.01);
571 TList* lf = hist->GetListOfFunctions();
572 TObject* old = lf->FindObject(lines->GetName());
578 hist->SetStats(false);
581 //__________________________________________________________________
583 AliFMDQAChecker::CheckRaw(AliRecoParam::EventSpecie_t /* specie*/,
586 Int_t ret = BasicCheck(hist);
587 TString name(hist->GetName());
588 if (name.Contains("readouterrors", TString::kIgnoreCase)) {
589 // Check the mean number of errors per event
590 TH2* roErrors = static_cast<TH2*>(hist);
591 Int_t nY = roErrors->GetNbinsY();
593 TLatex* ltx = new TLatex(.15, .8, Form("Thresholds: %5.2f,%5.2f",
594 fROErrorsBad, fROErrorsFkup));
595 ltx->SetName("thresholds");
596 ltx->SetTextColor(kGray+3);
599 TList* ll = hist->GetListOfFunctions();
600 TObject* old = ll->FindObject(ltx->GetName());
607 for (Int_t i = 1; i <= 3; i++) {
610 for (Int_t j = 1; j <= nY; j++) {
611 Int_t n = roErrors->GetBinContent(i, j);
612 sum += n * roErrors->GetYaxis()->GetBinCenter(j);
615 Double_t mean = sum / cnt;
617 ltx = new TLatex(i, kROErrorsLabelY, Form("Mean: %6.3f", mean));
618 ltx->SetName(Form("FMD%d", i));
619 ltx->SetTextAngle(90);
620 ltx->SetTextColor(kGreen+4);
621 old = ll->FindObject(ltx->GetName());
628 if (mean > fROErrorsBad) {
629 AliWarningF("Mean of readout errors for FMD%d = %f > %f (%f)",
630 i, mean, fROErrorsBad, fROErrorsFkup);
632 ltx->SetTextColor(kOrange+2);
633 if (mean > fROErrorsFkup) {
635 ltx->SetTextColor(kRed+2);
640 else if (name.Contains("eloss",TString::kIgnoreCase)) {
641 // Try to fit a function to the histogram
642 if (hist->GetEntries() < 1000) return ret;
644 Double_t xMin = hist->GetXaxis()->GetXmin();
645 Double_t xMax = hist->GetXaxis()->GetXmax();
647 hist->GetXaxis()->SetRangeUser(fELossLowCut, xMax);
648 Int_t bMaxY = hist->GetMaximumBin();
649 Double_t xMaxY = hist->GetXaxis()->GetBinCenter(bMaxY);
650 Double_t rms = hist->GetRMS();
651 Double_t low = hist->GetXaxis()->GetBinCenter(bMaxY-4);
652 hist->GetXaxis()->SetRangeUser(0.2, xMaxY+(fELossNRMS+1)*rms);
653 rms = hist->GetRMS();
654 hist->GetXaxis()->SetRange(0,-1);
655 TF1* func = makeLandauGaus(name);
656 func->SetParameter(1, xMaxY);
657 func->SetLineColor(kGreen+4);
658 // func->SetLineStyle(2);
659 Double_t high = xMax; // xMaxY+fELossNRMS*rms;
661 TFitResultPtr res = hist->Fit(func, "QS", "", low, high);
663 Int_t color = func->GetLineColor();
664 UShort_t qual = CheckFit(hist, res, low, high, color);
666 // Make sure we save the function in the full range of the histogram
667 func = hist->GetFunction("landauGaus");
668 func->SetRange(xMin, xMax);
669 // func->SetParent(hist);
670 func->Save(xMin, xMax, 0, 0, 0, 0);
671 func->SetLineColor(color);
674 func->SetLineWidth(3);
675 func->SetLineStyle(1);
677 func->SetLineWidth(4);
684 //__________________________________________________________________
686 AliFMDQAChecker::CheckSim(AliRecoParam::EventSpecie_t /* specie*/,
689 return BasicCheck(hist);
691 //__________________________________________________________________
693 AliFMDQAChecker::CheckRec(AliRecoParam::EventSpecie_t /* specie*/,
696 return BasicCheck(hist);
699 //__________________________________________________________________
700 void AliFMDQAChecker::Check(Double_t* rv,
701 AliQAv1::ALITASK_t what,
703 const AliDetectorRecoParam* /*t*/)
706 // Member function called to do the actual checking
709 // rv Array of return values.
710 // what What to check
711 // list Array of arrays of histograms. There's one arrat for
713 // t Reconstruction parameters - not used.
715 // The bounds defined for RV are
718 // ERROR: (0.0, 0.002]
719 // WARNING: (0.002,0.5]
722 // Double_t* rv = new Double_t[AliRecoParam::kNSpecies] ;
724 if (!fDidExternal) ProcessExternalParams();
726 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
730 if (!AliQAv1::Instance()->IsEventSpecieSet(specie) )
733 if(!list[specie]) continue;
736 Int_t nHist = list[specie]->GetEntriesFast();
738 for(Int_t i= 0; i< nHist; i++) {
739 if (!(hist = static_cast<TH1*>(list[specie]->At(i)))) continue;
740 Int_t qual = CheckOne(what, AliRecoParam::ConvertIndex(specie), hist);
741 hist->SetUniqueID(Quality2Bit(qual));
745 // if (ret > kWhatTheFk) rv[specie] = fLowTestValue[AliQAv1::kFATAL];
746 // else if (ret > kBad) rv[specie] = fUpTestValue[AliQAv1::kERROR];
747 // else if (ret > kProblem) rv[specie] = fUpTestValue[AliQAv1::kWARNING];
748 // else rv[specie] = fUpTestValue[AliQAv1::kINFO];
749 AliDebugF(3, "Combined sum is %d -> %f", ret, rv[specie]);
751 // if (count != 0) rv[specie] /= count;
757 Int_t CheckForLog(TAxis* axis,
762 TString t(axis->GetTitle());
763 if (!t.Contains("[log]", TString::kIgnoreCase)) return 0;
764 t.ReplaceAll("[log]", "");
766 case 1: pad->SetLogx(); ret |= 0x1; break;
767 case 2: pad->SetLogy(); ret |= 0x2; break;
768 case 3: pad->SetLogz(); ret |= 0x4; break;
773 void RestoreLog(TAxis* axis, Bool_t log)
776 TString t(axis->GetTitle());
783 void FindMinMax(TH1* h, Double_t& min, Double_t& max)
787 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
788 Double_t c = h->GetBinContent(i);
789 if (c < 1e-8) continue;
790 tmin = TMath::Min(tmin, c);
791 tmax = TMath::Max(tmax, c);
797 //____________________________________________________________________________
799 AliFMDQAChecker::MakeImage(TObjArray** list,
800 AliQAv1::TASKINDEX_t task,
801 AliQAv1::MODE_t mode)
803 // makes the QA image for sim and rec
806 // task What to check
807 // list Array of arrays of histograms. There's one array for
809 // t Reconstruction parameters - not used.
813 Double_t min = 10000;
815 // Loop over all species
816 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
817 AliRecoParam::EventSpecie_t spe = AliRecoParam::ConvertIndex(specie);
818 if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
819 ->IsEventSpecieSet(spe))
822 // If nothing is defined for this specie, go on.
823 if(!list[specie] || list[specie]->GetEntriesFast() == 0) continue;
825 // Loop over the histograms and figure out how many histograms we
826 // have and the min/max
828 Int_t nHist = list[specie]->GetEntriesFast();
829 for(Int_t i= 0; i< nHist; i++) {
830 hist = static_cast<TH1F*>(list[specie]->At(i));
831 if (hist && hist->TestBit(AliQAv1::GetImageBit())) {
833 TString name(hist->GetName());
834 if (name.Contains("readouterrors", TString::kIgnoreCase)) continue;
836 // Double_t hMax = hist->GetMaximum();
837 // hist->GetBinContent(hist->GetMaximumBin());
838 // Double_t hMin = hist->GetMinimum();
839 // hist->GetBinContent(hist->GetMinimumBin());
841 FindMinMax(hist, hMin, hMax);
842 max = TMath::Max(max, hMax);
843 min = TMath::Min(min, hMin);
844 // AliInfoF("Min/max of %40s: %f/%f, global -> %f/%f",
845 // hist->GetName(), hMin, hMax, min, max);
850 // AliInfoF("Global min/max=%f/%f", min, max);
851 min = TMath::Max(1e-1, min);
852 max = TMath::Max(1e5, max);
854 // IF no images, go on.
856 AliDebug(AliQAv1::GetQADebugLevel(),
857 Form("No histogram will be plotted for %s %s\n", GetName(),
858 AliQAv1::GetTaskName(task).Data()));
862 AliDebug(AliQAv1::GetQADebugLevel(),
863 Form("%d histograms will be plotted for %s %s\n",
864 nImages, GetName(), AliQAv1::GetTaskName(task).Data()));
865 gStyle->SetOptStat(0);
867 // Again loop over species and draw a canvas
868 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
869 if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
870 ->IsEventSpecieSet(specie)) continue;
872 // if Nothing here, go on
873 if(!list[specie] || list[specie]->GetEntries() <= 0 ||
874 nImages <= 0) continue;
877 const Char_t * title = Form("QA_%s_%s_%s", GetName(),
878 AliQAv1::GetTaskName(task).Data(),
879 AliRecoParam::GetEventSpecieName(specie));
880 if (!fImage[specie]) fImage[specie] = new TCanvas(title, title) ;
881 fImage[specie]->Clear() ;
882 fImage[specie]->SetTitle(title) ;
883 fImage[specie]->cd() ;
885 // Put something in the canvas - even if empty
886 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
887 someText.AddText(title) ;
888 someText.SetFillColor(0);
889 someText.SetFillStyle(0);
890 someText.SetBorderSize(0);
891 someText.SetTextColor(kRed+1);
893 TString outName(Form("%s%s%d.%s", AliQAv1::GetImageFileName(),
894 AliQAv1::GetModeName(mode),
895 AliQAChecker::Instance()->GetRunNumber(),
896 AliQAv1::GetImageFileFormat()));
897 fImage[specie]->Print(outName, "ps") ;
899 // Now set some parameters on the canvas
900 fImage[specie]->Clear();
901 fImage[specie]->SetTopMargin(0.10);
902 fImage[specie]->SetBottomMargin(0.15);
903 fImage[specie]->SetLeftMargin(0.15);
904 fImage[specie]->SetRightMargin(0.05);
907 const char* topT = Form("Mode: %s, Task: %s, Specie: %s, Run: %d",
908 AliQAv1::GetModeName(mode),
909 AliQAv1::GetTaskName(task).Data(),
910 AliRecoParam::GetEventSpecieName(specie),
911 AliQAChecker::Instance()->GetRunNumber());
912 TLatex* topText = new TLatex(.5, .99, topT);
913 topText->SetTextAlign(23);
914 topText->SetTextSize(.038);
915 topText->SetTextFont(42);
916 topText->SetTextColor(kBlue+3);
921 Int_t nx = int(nImages + .5) / 2;
924 fImage[specie]->Divide(nx, ny, 0, 0);
925 // else fImage[specie]->Divide(nx, ny);
928 // Loop over histograms
930 Int_t nHist = list[specie]->GetEntriesFast();
932 for (Int_t i = 0; i < nHist; i++) {
933 hist = static_cast<TH1*>(list[specie]->At(i));
934 if (!hist || !hist->TestBit(AliQAv1::GetImageBit())) continue;
937 TVirtualPad* pad = fImage[specie]->cd(++j);
938 pad->SetRightMargin(0.01);
940 pad->SetLeftMargin(0.10);
941 pad->SetBottomMargin(0.10);
944 // Check for log scale
946 logOpts |= CheckForLog(hist->GetXaxis(), pad, 1);
947 logOpts |= CheckForLog(hist->GetYaxis(), pad, 2);
948 logOpts |= CheckForLog(hist->GetZaxis(), pad, 3);
950 // Figure out special cases
952 TString name(hist->GetName());
953 if (name.Contains("readouterrors", TString::kIgnoreCase)) {
954 pad->SetRightMargin(0.15);
955 pad->SetBottomMargin(0.10);
956 // pad->SetTopMargin(0.02);
963 hist->SetMinimum(min);
964 hist->SetMaximum(max);
975 if (name.Contains("readouterrors", TString::kIgnoreCase)) {
977 for (Int_t kk = 1; kk <= 3; kk++) {
978 TH1* proj = static_cast<TH2*>(hist)->ProjectionY("",kk,kk);
979 Double_t m = proj->GetMean();
980 TLatex* l = new TLatex(kk, 30, Form("Mean: %f", m));
982 l->SetTextColor(m > 10 ? kRed+1 : m > .7 ? kOrange+2 :kGreen+2);
988 gStyle->SetOptTitle(0);
989 TPad* insert = new TPad("insert", "Zoom",
990 .4,.4, .99, .95, 0, 0, 0);
991 insert->SetTopMargin(0.01);
992 insert->SetRightMargin(0.01);
993 insert->SetFillColor(0);
994 insert->SetBorderSize(1);
995 insert->SetBorderMode(0);
998 if (logOpts & 0x1) insert->SetLogx();
999 if (logOpts & 0x2) insert->SetLogy();
1000 if (logOpts & 0x4) insert->SetLogz();
1001 hist->GetXaxis()->SetRange(1, hist->GetNbinsX()/8);
1002 TH1* copy = hist->DrawCopy(opt);
1003 copy->GetXaxis()->SetNdivisions(408, false);
1004 // Restore full range
1005 hist->GetXaxis()->SetRange(0, 0);
1006 gStyle->SetOptTitle(1);
1009 // Possibly restore the log options
1010 RestoreLog(hist->GetXaxis(), logOpts & 0x1);
1011 RestoreLog(hist->GetYaxis(), logOpts & 0x2);
1012 RestoreLog(hist->GetZaxis(), logOpts & 0x4);
1014 // Print to a post-script file
1015 fImage[specie]->Print(outName, "ps");
1017 fImage[specie]->Print(Form("%s_%d.png",
1018 AliRecoParam::GetEventSpecieName(specie),
1019 AliQAChecker::Instance()->GetRunNumber()));
1024 //__________________________________________________________________