]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDQAChecker.cxx
Printf replacing AliInfo to solve savannah ticket #93800
[u/mrichter/AliRoot.git] / FMD / AliFMDQAChecker.cxx
CommitLineData
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>
9eb9c521 30#include <TH2.h>
c9dd1c4d 31#include <TH1I.h>
32#include <TIterator.h>
33#include <TKey.h>
34#include <TFile.h>
6ceca4ef 35#include <iostream>
1706c710 36#include <TCanvas.h>
37#include <TPaveText.h>
05e5e0c1 38#include <TStyle.h>
9eb9c521 39#include <TLatex.h>
c9dd1c4d 40
41// --- AliRoot header files ---
42#include "AliLog.h"
4e25ac79 43#include "AliQAv1.h"
c9dd1c4d 44#include "AliQAChecker.h"
45#include "AliFMDQAChecker.h"
6ceca4ef 46#include "AliRecoParam.h"
c9dd1c4d 47
48ClassImp(AliFMDQAChecker)
49#if 0
50; // This is for Emacs! - do not delete
51#endif
05e5e0c1 52
53//__________________________________________________________________
54Double_t
55AliFMDQAChecker::CheckOne(AliQAv1::ALITASK_t what,
56 AliRecoParam::EventSpecie_t specie,
57 TH1* hist) const
58{
59 if(what == AliQAv1::kESD) return CheckESD(specie, hist);
60 if(what == AliQAv1::kRAW) return CheckRaw(specie, hist);
61 if(what == AliQAv1::kSIM) return CheckSim(specie, hist);
62 if(what == AliQAv1::kREC) return CheckRec(specie, hist);
63 return 0;
64}
65//__________________________________________________________________
66Double_t
67AliFMDQAChecker::CheckESD(AliRecoParam::EventSpecie_t /* specie*/,
68 TH1* hist) const
69{
70 return (hist->GetMean() > 0 ? 1 : 0);
71}
72//__________________________________________________________________
73Double_t
74AliFMDQAChecker::CheckRaw(AliRecoParam::EventSpecie_t /* specie*/,
75 TH1* hist) const
76{
77 return (hist->GetMean() > 0 ? 1 : 0);
78}
79//__________________________________________________________________
80Double_t
81AliFMDQAChecker::CheckSim(AliRecoParam::EventSpecie_t /* specie*/,
82 TH1* hist) const
83{
84 return (hist->GetMean() > 0 ? 1 : 0);
85}
86//__________________________________________________________________
87Double_t
88AliFMDQAChecker::CheckRec(AliRecoParam::EventSpecie_t /* specie*/,
89 TH1* hist) const
90{
91 return (hist->GetMean() > 0 ? 1 : 0);
92}
93
c9dd1c4d 94//__________________________________________________________________
fa5a224b 95void AliFMDQAChecker::Check(Double_t* rv,
96 AliQAv1::ALITASK_t what,
97 TObjArray** list,
98 const AliDetectorRecoParam* /*t*/)
99{
100 //
101 // Member function called to do the actual checking
102 //
103 // Parameters:
104 // rv Array of return values.
105 // what What to check
106 // list Array of arrays of histograms. There's one arrat for
107 // each 'specie'
108 // t Reconstruction parameters - not used.
109 //
6ceca4ef 110
fa5a224b 111 // Double_t* rv = new Double_t[AliRecoParam::kNSpecies] ;
6ceca4ef 112 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
83dbc5b8 113 // Int_t count = 0;
fa5a224b 114 rv[specie] = 0.;
115
1706c710 116 if (!AliQAv1::Instance()->IsEventSpecieSet(specie) )
6ceca4ef 117 continue ;
118
119 if(!list[specie]) continue;
120
05e5e0c1 121 TH1* hist = 0;
584d4c54 122 Int_t nHist = list[specie]->GetEntriesFast();
123 for(Int_t i= 0; i< nHist; i++) {
6ceca4ef 124
05e5e0c1 125 if (!(hist = static_cast<TH1*>(list[specie]->At(i)))) continue;
6ceca4ef 126
05e5e0c1 127 rv[specie] += CheckOne(what, AliRecoParam::ConvertIndex(specie), hist);
fa5a224b 128 } // for (int i ...)
83dbc5b8 129 // if (count != 0) rv[specie] /= count;
6ceca4ef 130 }
fa5a224b 131 // return rv;
6ceca4ef 132}
133
05e5e0c1 134namespace {
135 Int_t CheckForLog(TAxis* axis,
136 TVirtualPad* pad,
137 Int_t xyz)
138 {
139 Int_t ret = 0;
140 TString t(axis->GetTitle());
141 if (!t.Contains("[log]", TString::kIgnoreCase)) return 0;
142 t.ReplaceAll("[log]", "");
143 switch (xyz) {
144 case 1: pad->SetLogx(); ret |= 0x1; break;
145 case 2: pad->SetLogy(); ret |= 0x2; break;
146 case 3: pad->SetLogz(); ret |= 0x4; break;
147 }
148 axis->SetTitle(t);
149 return ret;
150 }
9eb9c521 151 void RestoreLog(TAxis* axis, Bool_t log)
152 {
153 if (!log) return;
154 TString t(axis->GetTitle());
155 t.Append("[log]");
156 axis->SetTitle(t);
157 }
05e5e0c1 158}
6ceca4ef 159
0f666f27 160namespace {
161 void FindMinMax(TH1* h, Double_t& min, Double_t& max)
162 {
163 Double_t tmin = 1e9;
164 Double_t tmax = 0;
165 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
166 Double_t c = h->GetBinContent(i);
167 if (c < 1e-8) continue;
168 tmin = TMath::Min(tmin, c);
169 tmax = TMath::Max(tmax, c);
170 }
171 min = tmin;
172 max = tmax;
173 }
174}
1706c710 175//____________________________________________________________________________
176void
177AliFMDQAChecker::MakeImage(TObjArray** list,
178 AliQAv1::TASKINDEX_t task,
179 AliQAv1::MODE_t mode)
180{
181 // makes the QA image for sim and rec
182 //
183 // Parameters:
184 // task What to check
185 // list Array of arrays of histograms. There's one array for
186 // each 'specie'
187 // t Reconstruction parameters - not used.
188 //
189 Int_t nImages = 0 ;
190 Double_t max = 0;
191 Double_t min = 10000;
9eb9c521 192
193 // Loop over all species
1706c710 194 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
05e5e0c1 195 AliRecoParam::EventSpecie_t spe = AliRecoParam::ConvertIndex(specie);
196 if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
197 ->IsEventSpecieSet(spe))
544ed74f 198 continue;
9eb9c521 199
200 // If nothing is defined for this specie, go on.
05e5e0c1 201 if(!list[specie] || list[specie]->GetEntriesFast() == 0) continue;
1706c710 202
9eb9c521 203 // Loop over the histograms and figure out how many histograms we
204 // have and the min/max
05e5e0c1 205 TH1* hist = 0;
1706c710 206 Int_t nHist = list[specie]->GetEntriesFast();
207 for(Int_t i= 0; i< nHist; i++) {
208 hist = static_cast<TH1F*>(list[specie]->At(i));
ae559def 209 if (hist && hist->TestBit(AliQAv1::GetImageBit())) {
1706c710 210 nImages++;
05e5e0c1 211 TString name(hist->GetName());
212 if (name.Contains("readouterrors", TString::kIgnoreCase)) continue;
0f666f27 213
214 // Double_t hMax = hist->GetMaximum();
05e5e0c1 215 // hist->GetBinContent(hist->GetMaximumBin());
0f666f27 216 // Double_t hMin = hist->GetMinimum();
05e5e0c1 217 // hist->GetBinContent(hist->GetMinimumBin());
0f666f27 218 Double_t hMax, hMin;
219 FindMinMax(hist, hMin, hMax);
05e5e0c1 220 max = TMath::Max(max, hMax);
221 min = TMath::Min(min, hMin);
9558fc76 222 AliInfoF("Min/max of %40s: %f/%f, global -> %f/%f",
223 hist->GetName(), hMin, hMax, min, max);
1706c710 224 }
225 }
226 break ;
227 }
9558fc76 228 AliInfoF("Global min/max=%f/%f", min, max);
229 min = TMath::Max(1e-1, min);
230 max = TMath::Max(1e5, max);
1706c710 231
9eb9c521 232 // IF no images, go on.
1706c710 233 if (nImages == 0) {
234 AliDebug(AliQAv1::GetQADebugLevel(),
235 Form("No histogram will be plotted for %s %s\n", GetName(),
236 AliQAv1::GetTaskName(task).Data()));
237 return;
238 }
239
240 AliDebug(AliQAv1::GetQADebugLevel(),
241 Form("%d histograms will be plotted for %s %s\n",
242 nImages, GetName(), AliQAv1::GetTaskName(task).Data()));
05e5e0c1 243 gStyle->SetOptStat(0);
9eb9c521 244
245 // Again loop over species and draw a canvas
1706c710 246 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
05e5e0c1 247 if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
248 ->IsEventSpecieSet(specie)) continue;
1706c710 249
9eb9c521 250 // if Nothing here, go on
251 if(!list[specie] || list[specie]->GetEntries() <= 0 ||
252 nImages <= 0) continue;
253
9558fc76 254 // Form the title
1706c710 255 const Char_t * title = Form("QA_%s_%s_%s", GetName(),
256 AliQAv1::GetTaskName(task).Data(),
257 AliRecoParam::GetEventSpecieName(specie));
9eb9c521 258 if (!fImage[specie]) fImage[specie] = new TCanvas(title, title) ;
1706c710 259 fImage[specie]->Clear() ;
260 fImage[specie]->SetTitle(title) ;
261 fImage[specie]->cd() ;
262
9eb9c521 263 // Put something in the canvas - even if empty
1706c710 264 TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
265 someText.AddText(title) ;
9eb9c521 266 someText.SetFillColor(0);
267 someText.SetFillStyle(0);
268 someText.SetBorderSize(0);
269 someText.SetTextColor(kRed+1);
1706c710 270 someText.Draw() ;
05e5e0c1 271 TString outName(Form("%s%s%d.%s", AliQAv1::GetImageFileName(),
272 AliQAv1::GetModeName(mode),
273 AliQAChecker::Instance()->GetRunNumber(),
274 AliQAv1::GetImageFileFormat()));
275 fImage[specie]->Print(outName, "ps") ;
1706c710 276
9eb9c521 277
278 // Now set some parameters on the canvas
279 fImage[specie]->Clear();
280 fImage[specie]->SetTopMargin(0.10);
281 fImage[specie]->SetBottomMargin(0.15);
282 fImage[specie]->SetLeftMargin(0.15);
283 fImage[specie]->SetRightMargin(0.05);
284
285 // Put title on top
286 const char* topT = Form("Mode: %s, Task: %s, Specie: %s, Run: %d",
287 AliQAv1::GetModeName(mode),
288 AliQAv1::GetTaskName(task).Data(),
289 AliRecoParam::GetEventSpecieName(specie),
290 AliQAChecker::Instance()->GetRunNumber());
291 TLatex* topText = new TLatex(.5, .99, topT);
292 topText->SetTextAlign(23);
293 topText->SetTextSize(.038);
294 topText->SetTextFont(42);
295 topText->SetTextColor(kBlue+3);
296 topText->SetNDC();
297 topText->Draw();
298
299 // Divide canvas
dbac3484 300 Int_t nx = int(nImages + .5) / 2;
1706c710 301 Int_t ny = 2;
9558fc76 302 // if (fDoScale)
1706c710 303 fImage[specie]->Divide(nx, ny, 0, 0);
9558fc76 304 // else fImage[specie]->Divide(nx, ny);
1706c710 305
306
9eb9c521 307 // Loop over histograms
05e5e0c1 308 TH1* hist = 0;
1706c710 309 Int_t nHist = list[specie]->GetEntriesFast();
310 Int_t j = 0;
311 for (Int_t i = 0; i < nHist; i++) {
05e5e0c1 312 hist = static_cast<TH1*>(list[specie]->At(i));
313 if (!hist || !hist->TestBit(AliQAv1::GetImageBit())) continue;
9eb9c521 314
315 // Go to sub-pad
1706c710 316 TVirtualPad* pad = fImage[specie]->cd(++j);
9eb9c521 317 pad->SetRightMargin(0.01);
9558fc76 318 if (!fDoScale) {
319 pad->SetLeftMargin(0.10);
320 pad->SetBottomMargin(0.10);
321 }
9eb9c521 322
323 // Check for log scale
05e5e0c1 324 Int_t logOpts = 0;
325 logOpts |= CheckForLog(hist->GetXaxis(), pad, 1);
326 logOpts |= CheckForLog(hist->GetYaxis(), pad, 2);
327 logOpts |= CheckForLog(hist->GetZaxis(), pad, 3);
05e5e0c1 328
9eb9c521 329 // Figure out special cases
05e5e0c1 330 TString opt;
331 TString name(hist->GetName());
332 if (name.Contains("readouterrors", TString::kIgnoreCase)) {
333 pad->SetRightMargin(0.15);
334 pad->SetBottomMargin(0.10);
9558fc76 335 // pad->SetTopMargin(0.02);
05e5e0c1 336 opt="COLZ";
337 }
338 else {
9eb9c521 339 pad->SetGridx();
340 pad->SetGridy();
9558fc76 341 if (fDoScale) {
342 hist->SetMinimum(min);
343 hist->SetMaximum(max);
344 }
345 else {
346 hist->SetMinimum();
347 hist->SetMaximum();
348 }
05e5e0c1 349 }
9eb9c521 350 // Draw (As a copy)
05e5e0c1 351 hist->DrawCopy(opt);
352
9eb9c521 353 // Special cases
354 if (name.Contains("readouterrors", TString::kIgnoreCase)) {
355 for (Int_t kk = 1; kk <= 3; kk++) {
356 TH1* proj = static_cast<TH2*>(hist)->ProjectionY("",kk,kk);
357 Double_t m = proj->GetMean();
358 TLatex* l = new TLatex(kk, 30, Form("Mean: %f", m));
359 l->SetTextAngle(90);
0f666f27 360 l->SetTextColor(m > 10 ? kRed+1 : m > .7 ? kOrange+2 :kGreen+2);
9eb9c521 361 l->Draw();
362 }
363 }
364 else {
365 gStyle->SetOptTitle(0);
366 TPad* insert = new TPad("insert", "Zoom",
367 .4,.4, .99, .95, 0, 0, 0);
368 insert->SetTopMargin(0.01);
369 insert->SetRightMargin(0.01);
370 insert->SetFillColor(0);
371 insert->SetBorderSize(1);
372 insert->SetBorderMode(0);
373 insert->Draw();
374 insert->cd();
375 if (logOpts & 0x1) insert->SetLogx();
376 if (logOpts & 0x2) insert->SetLogy();
377 if (logOpts & 0x4) insert->SetLogz();
0f666f27 378 hist->GetXaxis()->SetRange(1, hist->GetNbinsX()/8);
379 TH1* copy = hist->DrawCopy(opt);
380 copy->GetXaxis()->SetNdivisions(408, false);
9eb9c521 381 // Restore full range
0f666f27 382 hist->GetXaxis()->SetRange(0, 0);
9eb9c521 383 gStyle->SetOptTitle(1);
384 }
05e5e0c1 385 pad->cd();
9eb9c521 386 // Possibly restore the log options
387 RestoreLog(hist->GetXaxis(), logOpts & 0x1);
388 RestoreLog(hist->GetYaxis(), logOpts & 0x2);
389 RestoreLog(hist->GetZaxis(), logOpts & 0x4);
1706c710 390 }
0f666f27 391 // Print to a post-script file
05e5e0c1 392 fImage[specie]->Print(outName, "ps");
1706c710 393 }
394}
c9dd1c4d 395
396//__________________________________________________________________
397//
398// EOF
399//