]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDQAChecker.cxx
Fix a but - initialise fBad array
[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 <TH1I.h> 
31 #include <TIterator.h> 
32 #include <TKey.h> 
33 #include <TFile.h> 
34 #include <iostream>
35 #include <TCanvas.h>
36 #include <TPaveText.h>
37 #include <TStyle.h>
38
39 // --- AliRoot header files ---
40 #include "AliLog.h"
41 #include "AliQAv1.h"
42 #include "AliQAChecker.h"
43 #include "AliFMDQAChecker.h"
44 #include "AliRecoParam.h"
45
46 ClassImp(AliFMDQAChecker)
47 #if 0
48 ; // This is for Emacs! - do not delete
49 #endif
50
51 //__________________________________________________________________
52 Double_t 
53 AliFMDQAChecker::CheckOne(AliQAv1::ALITASK_t          what,
54                           AliRecoParam::EventSpecie_t specie, 
55                           TH1*                        hist) const
56 {
57   if(what == AliQAv1::kESD) return CheckESD(specie, hist);
58   if(what == AliQAv1::kRAW) return CheckRaw(specie, hist);
59   if(what == AliQAv1::kSIM) return CheckSim(specie, hist);
60   if(what == AliQAv1::kREC) return CheckRec(specie, hist);
61   return 0;
62 }
63 //__________________________________________________________________
64 Double_t 
65 AliFMDQAChecker::CheckESD(AliRecoParam::EventSpecie_t /* specie*/, 
66                           TH1*                        hist) const
67 {
68   return (hist->GetMean() > 0 ? 1 : 0);
69 }
70 //__________________________________________________________________
71 Double_t 
72 AliFMDQAChecker::CheckRaw(AliRecoParam::EventSpecie_t /* specie*/, 
73                           TH1*                        hist) const
74 {
75   return (hist->GetMean() > 0 ? 1 : 0);
76 }
77 //__________________________________________________________________
78 Double_t 
79 AliFMDQAChecker::CheckSim(AliRecoParam::EventSpecie_t /* specie*/, 
80                           TH1*                        hist) const
81 {
82   return (hist->GetMean() > 0 ? 1 : 0);
83 }
84 //__________________________________________________________________
85 Double_t 
86 AliFMDQAChecker::CheckRec(AliRecoParam::EventSpecie_t /* specie*/, 
87                           TH1*                        hist) const
88 {
89   return (hist->GetMean() > 0 ? 1 : 0);
90 }
91
92 //__________________________________________________________________
93 void AliFMDQAChecker::Check(Double_t*                   rv, 
94                             AliQAv1::ALITASK_t          what, 
95                             TObjArray**                 list, 
96                             const AliDetectorRecoParam* /*t*/) 
97 {
98   // 
99   // Member function called to do the actual checking
100   //
101   // Parameters: 
102   //    rv   Array of return values. 
103   //    what What to check 
104   //    list Array of arrays of histograms.  There's one arrat for
105   //         each 'specie'
106   //    t    Reconstruction parameters - not used. 
107   //
108   
109   // Double_t* rv = new Double_t[AliRecoParam::kNSpecies] ; 
110   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
111     // Int_t count   = 0;
112     rv[specie]    = 0.; 
113
114     if (!AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
115       continue ;
116     
117     if(!list[specie]) continue;
118     
119     TH1* hist  = 0;
120     Int_t nHist = list[specie]->GetEntriesFast();
121     for(Int_t i= 0; i< nHist; i++) {
122       
123       if (!(hist = static_cast<TH1*>(list[specie]->At(i)))) continue;
124       
125       rv[specie] += CheckOne(what, AliRecoParam::ConvertIndex(specie), hist);
126     } // for (int i ...)
127     // if (count != 0) rv[specie] /= count;
128   }
129   // return rv;
130 }
131
132 namespace {
133   Int_t CheckForLog(TAxis*       axis,
134                     TVirtualPad* pad, 
135                     Int_t        xyz)
136   {
137     Int_t ret = 0;
138     TString t(axis->GetTitle());
139     if (!t.Contains("[log]", TString::kIgnoreCase)) return 0;
140     t.ReplaceAll("[log]", "");
141     switch (xyz) { 
142     case 1: pad->SetLogx(); ret |= 0x1; break;
143     case 2: pad->SetLogy(); ret |= 0x2; break;
144     case 3: pad->SetLogz(); ret |= 0x4; break;
145     }
146     axis->SetTitle(t);
147     return ret;
148   }
149 }
150
151 //____________________________________________________________________________ 
152 void 
153 AliFMDQAChecker::MakeImage(TObjArray** list, 
154                            AliQAv1::TASKINDEX_t task, 
155                            AliQAv1::MODE_t mode) 
156 {
157   // makes the QA image for sim and rec
158   // 
159   // Parameters: 
160   //    task What to check 
161   //    list Array of arrays of histograms.  There's one array for
162   //         each 'specie'
163   //    t    Reconstruction parameters - not used. 
164   // 
165   Int_t    nImages = 0 ;
166   Double_t max     = 0;
167   Double_t min     = 10000;
168   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
169     AliRecoParam::EventSpecie_t spe = AliRecoParam::ConvertIndex(specie);
170     if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
171         ->IsEventSpecieSet(spe)) 
172       continue;
173     // if (!AliQAv1::Instance()->IsEventSpecieSet(specie)) continue ;
174     
175     if(!list[specie] || list[specie]->GetEntriesFast() == 0) continue;
176
177     TH1* hist  = 0;
178     Int_t nHist = list[specie]->GetEntriesFast();
179     for(Int_t i= 0; i< nHist; i++) {
180       hist = static_cast<TH1F*>(list[specie]->At(i));
181       if (hist && hist->TestBit(AliQAv1::GetImageBit())) {
182         nImages++; 
183         TString name(hist->GetName());
184         if (name.Contains("readouterrors", TString::kIgnoreCase)) continue;
185         Double_t hMax = hist->GetMaximum(); 
186         // hist->GetBinContent(hist->GetMaximumBin());
187         Double_t hMin = hist->GetMinimum();
188         // hist->GetBinContent(hist->GetMinimumBin());
189         max = TMath::Max(max, hMax);
190         min = TMath::Min(min, hMin);
191         AliInfo(Form("Histogram %30s min=%f, max=%f (min=%f,max=%f)",
192                      name.Data(), hMin, hMax, min, max));
193       }
194     }
195     break ; 
196   }
197   min = TMath::Max(0.1, min);
198   max = TMath::Max(1.0, max);
199
200   if (nImages == 0) {
201     AliDebug(AliQAv1::GetQADebugLevel(), 
202              Form("No histogram will be plotted for %s %s\n", GetName(), 
203                   AliQAv1::GetTaskName(task).Data()));
204     return;
205   }
206
207   AliDebug(AliQAv1::GetQADebugLevel(), 
208            Form("%d histograms will be plotted for %s %s\n", 
209                 nImages, GetName(), AliQAv1::GetTaskName(task).Data()));  
210   gStyle->SetOptStat(0);
211   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
212     if (!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))
213         ->IsEventSpecieSet(specie)) continue;
214     
215     if(!list[specie] || list[specie]->GetEntries() <= 0) continue;
216
217     const Char_t * title = Form("QA_%s_%s_%s", GetName(), 
218                                 AliQAv1::GetTaskName(task).Data(), 
219                                 AliRecoParam::GetEventSpecieName(specie)); 
220     if (!fImage[specie]) 
221       fImage[specie] = new TCanvas(title, title) ;
222     fImage[specie]->Clear() ; 
223     fImage[specie]->SetTitle(title) ; 
224     fImage[specie]->cd() ; 
225
226     TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
227     someText.AddText(title) ;
228     someText.Draw() ; 
229     TString outName(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), 
230                          AliQAv1::GetModeName(mode), 
231                          AliQAChecker::Instance()->GetRunNumber(), 
232                          AliQAv1::GetImageFileFormat()));
233     fImage[specie]->Print(outName, "ps") ; 
234     fImage[specie]->Clear(); 
235
236     Int_t nx = int(nImages + .5) / 2;
237     Int_t ny = 2;
238     fImage[specie]->Divide(nx, ny, 0, 0);
239     
240     
241     TH1*  hist  = 0;
242     Int_t nHist = list[specie]->GetEntriesFast();
243     // list[specie]->Print();
244     Int_t j     = 0;
245     for (Int_t i = 0; i < nHist; i++) { 
246       hist = static_cast<TH1*>(list[specie]->At(i));
247       if (!hist || !hist->TestBit(AliQAv1::GetImageBit())) continue;
248       
249       TVirtualPad* pad = fImage[specie]->cd(++j);
250       pad->SetRightMargin(0.001);
251       Int_t logOpts = 0;
252       logOpts |= CheckForLog(hist->GetXaxis(), pad, 1);
253       logOpts |= CheckForLog(hist->GetYaxis(), pad, 2);
254       logOpts |= CheckForLog(hist->GetZaxis(), pad, 3);
255       if (hist->GetEntries() > 0)
256         AliInfo(Form("Drawing %30s (min=%f, max=%f) in pad %d",
257                      hist->GetName(), min, max, j));
258
259       TString opt;
260       TString name(hist->GetName());
261       if (name.Contains("readouterrors", TString::kIgnoreCase)) {
262         pad->SetRightMargin(0.15);
263         pad->SetBottomMargin(0.10);
264         pad->SetTopMargin(0.02);
265         opt="COLZ";
266       }
267       else {
268         hist->SetMinimum(min);
269         hist->SetMaximum(max);
270
271       }
272       hist->DrawCopy(opt);
273
274       if (name.Contains("readouterrors", TString::kIgnoreCase)) 
275         continue;
276
277       TPad* insert = new TPad("insert", "Zoom", 
278                               .4,.4, .99, .95, 0, 0, 0);
279       insert->SetTopMargin(0);
280       insert->SetRightMargin(0.001);
281       insert->SetFillColor(0);
282       insert->SetBorderSize(1);
283       insert->SetBorderMode(0);
284       insert->Draw();
285       insert->cd();
286       if (logOpts & 0x1) insert->SetLogx();
287       if (logOpts & 0x2) insert->SetLogy();
288       if (logOpts & 0x4) insert->SetLogz();
289       hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), 
290                                      hist->GetXaxis()->GetXmax()/8);
291       hist->DrawCopy(opt);
292       pad->cd();
293     }
294
295     fImage[specie]->Print(outName, "ps");
296   }
297 }
298
299 //__________________________________________________________________
300 //
301 // EOF
302 //