]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDQAChecker.cxx
Fix range and binning on histograms
[u/mrichter/AliRoot.git] / FMD / AliFMDQAChecker.cxx
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> 
30 #include <TH2.h> 
31 #include <TH1I.h> 
32 #include <TIterator.h> 
33 #include <TKey.h> 
34 #include <TFile.h> 
35 #include <iostream>
36 #include <TCanvas.h>
37 #include <TPaveText.h>
38 #include <TStyle.h>
39 #include <TLatex.h>
40
41 // --- AliRoot header files ---
42 #include "AliLog.h"
43 #include "AliQAv1.h"
44 #include "AliQAChecker.h"
45 #include "AliFMDQAChecker.h"
46 #include "AliRecoParam.h"
47
48 ClassImp(AliFMDQAChecker)
49 #if 0
50 ; // This is for Emacs! - do not delete
51 #endif
52
53 //__________________________________________________________________
54 Double_t 
55 AliFMDQAChecker::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 //__________________________________________________________________
66 Double_t 
67 AliFMDQAChecker::CheckESD(AliRecoParam::EventSpecie_t /* specie*/, 
68                           TH1*                        hist) const
69 {
70   return (hist->GetMean() > 0 ? 1 : 0);
71 }
72 //__________________________________________________________________
73 Double_t 
74 AliFMDQAChecker::CheckRaw(AliRecoParam::EventSpecie_t /* specie*/, 
75                           TH1*                        hist) const
76 {
77   return (hist->GetMean() > 0 ? 1 : 0);
78 }
79 //__________________________________________________________________
80 Double_t 
81 AliFMDQAChecker::CheckSim(AliRecoParam::EventSpecie_t /* specie*/, 
82                           TH1*                        hist) const
83 {
84   return (hist->GetMean() > 0 ? 1 : 0);
85 }
86 //__________________________________________________________________
87 Double_t 
88 AliFMDQAChecker::CheckRec(AliRecoParam::EventSpecie_t /* specie*/, 
89                           TH1*                        hist) const
90 {
91   return (hist->GetMean() > 0 ? 1 : 0);
92 }
93
94 //__________________________________________________________________
95 void 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   //
110   
111   // Double_t* rv = new Double_t[AliRecoParam::kNSpecies] ; 
112   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
113     // Int_t count   = 0;
114     rv[specie]    = 0.; 
115
116     if (!AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
117       continue ;
118     
119     if(!list[specie]) continue;
120     
121     TH1* hist  = 0;
122     Int_t nHist = list[specie]->GetEntriesFast();
123     for(Int_t i= 0; i< nHist; i++) {
124       
125       if (!(hist = static_cast<TH1*>(list[specie]->At(i)))) continue;
126       
127       rv[specie] += CheckOne(what, AliRecoParam::ConvertIndex(specie), hist);
128     } // for (int i ...)
129     // if (count != 0) rv[specie] /= count;
130   }
131   // return rv;
132 }
133
134 namespace {
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   }
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   }
158 }
159
160 namespace {
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 }
175 //____________________________________________________________________________ 
176 void 
177 AliFMDQAChecker::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;
192
193   // Loop over all species 
194   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
195     AliRecoParam::EventSpecie_t spe = AliRecoParam::ConvertIndex(specie);
196     if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
197         ->IsEventSpecieSet(spe)) 
198       continue;
199                                                                         
200     // If nothing is defined for this specie, go on. 
201     if(!list[specie] || list[specie]->GetEntriesFast() == 0) continue;
202
203     // Loop over the histograms and figure out how many histograms we
204     // have and the min/max 
205     TH1* hist  = 0;
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));
209       if (hist && hist->TestBit(AliQAv1::GetImageBit())) {
210         nImages++; 
211         TString name(hist->GetName());
212         if (name.Contains("readouterrors", TString::kIgnoreCase)) continue;
213
214         // Double_t hMax = hist->GetMaximum(); 
215         // hist->GetBinContent(hist->GetMaximumBin());
216         // Double_t hMin = hist->GetMinimum();
217         // hist->GetBinContent(hist->GetMinimumBin());
218         Double_t hMax, hMin;
219         FindMinMax(hist, hMin, hMax);
220         max = TMath::Max(max, hMax);
221         min = TMath::Min(min, hMin);
222       }
223     }
224     break ; 
225   }
226   min = TMath::Max(1e-6, min);
227   max = TMath::Max(1.0,  max);
228
229   // IF no images, go on. 
230   if (nImages == 0) {
231     AliDebug(AliQAv1::GetQADebugLevel(), 
232              Form("No histogram will be plotted for %s %s\n", GetName(), 
233                   AliQAv1::GetTaskName(task).Data()));
234     return;
235   }
236
237   AliDebug(AliQAv1::GetQADebugLevel(), 
238            Form("%d histograms will be plotted for %s %s\n", 
239                 nImages, GetName(), AliQAv1::GetTaskName(task).Data()));  
240   gStyle->SetOptStat(0);
241   
242   // Again loop over species and draw a canvas 
243   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
244     if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
245         ->IsEventSpecieSet(specie)) continue;
246
247     // if Nothing here, go on
248     if(!list[specie] || list[specie]->GetEntries() <= 0 || 
249        nImages <= 0) continue;
250
251     // Form the title 
252     const Char_t * title = Form("QA_%s_%s_%s", GetName(), 
253                                 AliQAv1::GetTaskName(task).Data(), 
254                                 AliRecoParam::GetEventSpecieName(specie)); 
255     if (!fImage[specie]) fImage[specie] = new TCanvas(title, title) ;
256     fImage[specie]->Clear() ; 
257     fImage[specie]->SetTitle(title) ; 
258     fImage[specie]->cd() ; 
259
260     // Put something in the canvas - even if empty 
261     TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
262     someText.AddText(title) ;
263     someText.SetFillColor(0);
264     someText.SetFillStyle(0);
265     someText.SetBorderSize(0);
266     someText.SetTextColor(kRed+1);
267     someText.Draw() ; 
268     TString outName(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), 
269                          AliQAv1::GetModeName(mode), 
270                          AliQAChecker::Instance()->GetRunNumber(), 
271                          AliQAv1::GetImageFileFormat()));
272     fImage[specie]->Print(outName, "ps") ; 
273
274
275     // Now set some parameters on the canvas 
276     fImage[specie]->Clear(); 
277     fImage[specie]->SetTopMargin(0.10);
278     fImage[specie]->SetBottomMargin(0.15);
279     fImage[specie]->SetLeftMargin(0.15);
280     fImage[specie]->SetRightMargin(0.05);
281     
282     // Put title on top 
283     const char* topT = Form("Mode: %s, Task: %s, Specie: %s, Run: %d",
284                             AliQAv1::GetModeName(mode), 
285                             AliQAv1::GetTaskName(task).Data(), 
286                             AliRecoParam::GetEventSpecieName(specie),
287                             AliQAChecker::Instance()->GetRunNumber());
288     TLatex* topText = new TLatex(.5, .99, topT);
289     topText->SetTextAlign(23);
290     topText->SetTextSize(.038);
291     topText->SetTextFont(42);
292     topText->SetTextColor(kBlue+3);
293     topText->SetNDC();
294     topText->Draw();
295                                  
296     // Divide canvas 
297     Int_t nx = int(nImages + .5) / 2;
298     Int_t ny = 2;
299     fImage[specie]->Divide(nx, ny, 0, 0);
300     
301     
302     // Loop over histograms 
303     TH1*  hist  = 0;
304     Int_t nHist = list[specie]->GetEntriesFast();
305     Int_t j     = 0;
306     for (Int_t i = 0; i < nHist; i++) { 
307       hist = static_cast<TH1*>(list[specie]->At(i));
308       if (!hist || !hist->TestBit(AliQAv1::GetImageBit())) continue;
309
310       // Go to sub-pad 
311       TVirtualPad* pad = fImage[specie]->cd(++j);
312       pad->SetRightMargin(0.01);
313
314       // Check for log scale 
315       Int_t logOpts = 0;
316       logOpts |= CheckForLog(hist->GetXaxis(), pad, 1);
317       logOpts |= CheckForLog(hist->GetYaxis(), pad, 2);
318       logOpts |= CheckForLog(hist->GetZaxis(), pad, 3);
319
320       // Figure out special cases 
321       TString opt;
322       TString name(hist->GetName());
323       if (name.Contains("readouterrors", TString::kIgnoreCase)) {
324         pad->SetRightMargin(0.15);
325         pad->SetBottomMargin(0.10);
326         pad->SetTopMargin(0.02);
327         opt="COLZ";
328       }
329       else {
330         pad->SetGridx();
331         pad->SetGridy();
332         hist->SetMinimum(min);
333         hist->SetMaximum(max);
334
335       }
336       // Draw (As a copy)
337       hist->DrawCopy(opt);
338
339       // Special cases 
340       if (name.Contains("readouterrors", TString::kIgnoreCase)) {
341         for (Int_t kk = 1; kk <= 3; kk++) {
342           TH1* proj = static_cast<TH2*>(hist)->ProjectionY("",kk,kk);
343         Double_t m = proj->GetMean(); 
344         TLatex* l = new TLatex(kk, 30, Form("Mean: %f", m));
345         l->SetTextAngle(90);
346         l->SetTextColor(m > 10 ? kRed+1 : m > .7 ? kOrange+2 :kGreen+2);
347         l->Draw();
348       }
349       }
350       else {
351         gStyle->SetOptTitle(0);
352         TPad* insert = new TPad("insert", "Zoom", 
353                                 .4,.4, .99, .95, 0, 0, 0);
354         insert->SetTopMargin(0.01);
355         insert->SetRightMargin(0.01);
356         insert->SetFillColor(0);
357         insert->SetBorderSize(1);
358         insert->SetBorderMode(0);
359         insert->Draw();
360         insert->cd();
361         if (logOpts & 0x1) insert->SetLogx();
362         if (logOpts & 0x2) insert->SetLogy();
363         if (logOpts & 0x4) insert->SetLogz();
364         hist->GetXaxis()->SetRange(1, hist->GetNbinsX()/8);
365         TH1* copy = hist->DrawCopy(opt);
366         copy->GetXaxis()->SetNdivisions(408, false);
367         // Restore full range 
368         hist->GetXaxis()->SetRange(0, 0);
369         gStyle->SetOptTitle(1);
370       }
371       pad->cd();
372       // Possibly restore the log options 
373       RestoreLog(hist->GetXaxis(), logOpts & 0x1);
374       RestoreLog(hist->GetYaxis(), logOpts & 0x2);
375       RestoreLog(hist->GetZaxis(), logOpts & 0x4);
376     }
377     // Print to a post-script file 
378     fImage[specie]->Print(outName, "ps");
379   }
380 }
381
382 //__________________________________________________________________
383 //
384 // EOF
385 //