]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDQAChecker.cxx
Fixes for building of DA (Anshul)
[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 //____________________________________________________________________________ 
161 void 
162 AliFMDQAChecker::MakeImage(TObjArray** list, 
163                            AliQAv1::TASKINDEX_t task, 
164                            AliQAv1::MODE_t mode) 
165 {
166   // makes the QA image for sim and rec
167   // 
168   // Parameters: 
169   //    task What to check 
170   //    list Array of arrays of histograms.  There's one array for
171   //         each 'specie'
172   //    t    Reconstruction parameters - not used. 
173   // 
174   Int_t    nImages = 0 ;
175   Double_t max     = 0;
176   Double_t min     = 10000;
177
178   // Loop over all species 
179   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
180     AliRecoParam::EventSpecie_t spe = AliRecoParam::ConvertIndex(specie);
181     if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
182         ->IsEventSpecieSet(spe)) 
183       continue;
184                                                                         
185     // If nothing is defined for this specie, go on. 
186     if(!list[specie] || list[specie]->GetEntriesFast() == 0) continue;
187
188     // Loop over the histograms and figure out how many histograms we
189     // have and the min/max 
190     TH1* hist  = 0;
191     Int_t nHist = list[specie]->GetEntriesFast();
192     for(Int_t i= 0; i< nHist; i++) {
193       hist = static_cast<TH1F*>(list[specie]->At(i));
194       if (hist && hist->TestBit(AliQAv1::GetImageBit())) {
195         nImages++; 
196         TString name(hist->GetName());
197         if (name.Contains("readouterrors", TString::kIgnoreCase)) continue;
198         Double_t hMax = hist->GetMaximum(); 
199         // hist->GetBinContent(hist->GetMaximumBin());
200         Double_t hMin = hist->GetMinimum();
201         // hist->GetBinContent(hist->GetMinimumBin());
202         max = TMath::Max(max, hMax);
203         min = TMath::Min(min, hMin);
204       }
205     }
206     break ; 
207   }
208   min = TMath::Max(0.1, min);
209   max = TMath::Max(1.0, max);
210
211   // IF no images, go on. 
212   if (nImages == 0) {
213     AliDebug(AliQAv1::GetQADebugLevel(), 
214              Form("No histogram will be plotted for %s %s\n", GetName(), 
215                   AliQAv1::GetTaskName(task).Data()));
216     return;
217   }
218
219   AliDebug(AliQAv1::GetQADebugLevel(), 
220            Form("%d histograms will be plotted for %s %s\n", 
221                 nImages, GetName(), AliQAv1::GetTaskName(task).Data()));  
222   gStyle->SetOptStat(0);
223   
224   // Again loop over species and draw a canvas 
225   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
226     if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
227         ->IsEventSpecieSet(specie)) continue;
228
229     // if Nothing here, go on
230     if(!list[specie] || list[specie]->GetEntries() <= 0 || 
231        nImages <= 0) continue;
232
233     // Form the title 
234     const Char_t * title = Form("QA_%s_%s_%s", GetName(), 
235                                 AliQAv1::GetTaskName(task).Data(), 
236                                 AliRecoParam::GetEventSpecieName(specie)); 
237     if (!fImage[specie]) fImage[specie] = new TCanvas(title, title) ;
238     fImage[specie]->Clear() ; 
239     fImage[specie]->SetTitle(title) ; 
240     fImage[specie]->cd() ; 
241
242     // Put something in the canvas - even if empty 
243     TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
244     someText.AddText(title) ;
245     someText.SetFillColor(0);
246     someText.SetFillStyle(0);
247     someText.SetBorderSize(0);
248     someText.SetTextColor(kRed+1);
249     someText.Draw() ; 
250     TString outName(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), 
251                          AliQAv1::GetModeName(mode), 
252                          AliQAChecker::Instance()->GetRunNumber(), 
253                          AliQAv1::GetImageFileFormat()));
254     fImage[specie]->Print(outName, "ps") ; 
255
256
257     // Now set some parameters on the canvas 
258     fImage[specie]->Clear(); 
259     fImage[specie]->SetTopMargin(0.10);
260     fImage[specie]->SetBottomMargin(0.15);
261     fImage[specie]->SetLeftMargin(0.15);
262     fImage[specie]->SetRightMargin(0.05);
263     
264     // Put title on top 
265     const char* topT = Form("Mode: %s, Task: %s, Specie: %s, Run: %d",
266                             AliQAv1::GetModeName(mode), 
267                             AliQAv1::GetTaskName(task).Data(), 
268                             AliRecoParam::GetEventSpecieName(specie),
269                             AliQAChecker::Instance()->GetRunNumber());
270     TLatex* topText = new TLatex(.5, .99, topT);
271     topText->SetTextAlign(23);
272     topText->SetTextSize(.038);
273     topText->SetTextFont(42);
274     topText->SetTextColor(kBlue+3);
275     topText->SetNDC();
276     topText->Draw();
277                                  
278     // Divide canvas 
279     Int_t nx = int(nImages + .5) / 2;
280     Int_t ny = 2;
281     fImage[specie]->Divide(nx, ny, 0, 0);
282     
283     
284     // Loop over histograms 
285     TH1*  hist  = 0;
286     Int_t nHist = list[specie]->GetEntriesFast();
287     Int_t j     = 0;
288     for (Int_t i = 0; i < nHist; i++) { 
289       hist = static_cast<TH1*>(list[specie]->At(i));
290       if (!hist || !hist->TestBit(AliQAv1::GetImageBit())) continue;
291
292       // Go to sub-pad 
293       TVirtualPad* pad = fImage[specie]->cd(++j);
294       pad->SetRightMargin(0.01);
295
296       // Check for log scale 
297       Int_t logOpts = 0;
298       logOpts |= CheckForLog(hist->GetXaxis(), pad, 1);
299       logOpts |= CheckForLog(hist->GetYaxis(), pad, 2);
300       logOpts |= CheckForLog(hist->GetZaxis(), pad, 3);
301
302       // Figure out special cases 
303       TString opt;
304       TString name(hist->GetName());
305       if (name.Contains("readouterrors", TString::kIgnoreCase)) {
306         pad->SetRightMargin(0.15);
307         pad->SetBottomMargin(0.10);
308         pad->SetTopMargin(0.02);
309         opt="COLZ";
310       }
311       else {
312         pad->SetGridx();
313         pad->SetGridy();
314         hist->SetMinimum(min);
315         hist->SetMaximum(max);
316
317       }
318       // Draw (As a copy)
319       hist->DrawCopy(opt);
320
321       // Special cases 
322       if (name.Contains("readouterrors", TString::kIgnoreCase)) {
323         for (Int_t kk = 1; kk <= 3; kk++) {
324           TH1* proj = static_cast<TH2*>(hist)->ProjectionY("",kk,kk);
325         Double_t m = proj->GetMean(); 
326         TLatex* l = new TLatex(kk, 30, Form("Mean: %f", m));
327         l->SetTextAngle(90);
328         l->SetTextColor(m > 10 ? kRed+1 : m > 1 ? kOrange+2 :kGreen+2);
329         l->Draw();
330       }
331       }
332       else {
333         gStyle->SetOptTitle(0);
334         TPad* insert = new TPad("insert", "Zoom", 
335                                 .4,.4, .99, .95, 0, 0, 0);
336         insert->SetTopMargin(0.01);
337         insert->SetRightMargin(0.01);
338         insert->SetFillColor(0);
339         insert->SetBorderSize(1);
340         insert->SetBorderMode(0);
341         insert->Draw();
342         insert->cd();
343         if (logOpts & 0x1) insert->SetLogx();
344         if (logOpts & 0x2) insert->SetLogy();
345         if (logOpts & 0x4) insert->SetLogz();
346         hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), 
347                                        hist->GetXaxis()->GetXmax()/8);
348         hist->DrawCopy(opt);
349         // Restore full range 
350         hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), 
351                                        hist->GetXaxis()->GetXmax());
352         gStyle->SetOptTitle(1);
353       }
354       pad->cd();
355       // Possibly restore the log options 
356       RestoreLog(hist->GetXaxis(), logOpts & 0x1);
357       RestoreLog(hist->GetYaxis(), logOpts & 0x2);
358       RestoreLog(hist->GetZaxis(), logOpts & 0x4);
359     }
360   // Print to a post-script file 
361     fImage[specie]->Print(outName, "ps");
362   }
363 }
364
365 //__________________________________________________________________
366 //
367 // EOF
368 //