Updated QA version (Sylwester)
[u/mrichter/AliRoot.git] / TRD / AliTRDqaBlackEvents.cxx
CommitLineData
0f772b9f 1/**************************************************************************\r
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
3 * *\r
4 * Author: The ALICE Off-line Project. *\r
5 * Contributors are mentioned in the code where appropriate. *\r
6 * *\r
7 * Permission to use, copy, modify and distribute this software and its *\r
8 * documentation strictly for non-commercial purposes is hereby granted *\r
9b99c029 9 * withount fee, provided that the abovĂ…\9be copyright notice appears in all *\r
0f772b9f 10 * copies and that both the copyright notice and this permission notice *\r
11 * appear in the supporting documentation. The authors make no claims *\r
12 * about the suitability of this software for any purpose. It is *\r
13 * provided "as is" without express or implied warranty. *\r
14 **************************************************************************/\r
15\r
16/* $Id: AliTRDqaBlackEvents.cxx 23387 2008-01-17 17:25:16Z cblume $ */\r
17\r
18////////////////////////////////////////////////////////////////////////////\r
19// //\r
20// QA of black events //\r
21// //\r
22// Author: //\r
23// Sylwester Radomski (radomski@physi.uni-heidelberg.de) //\r
24// //\r
25////////////////////////////////////////////////////////////////////////////\r
26\r
27#include "TH1D.h"\r
28#include "TH2D.h"\r
29#include "TH3D.h"\r
30#include "TF1.h"\r
31#include "TFile.h"\r
32#include "TCanvas.h"\r
33#include "TPad.h"\r
34#include "TLatex.h"\r
35#include "TStyle.h"\r
36\r
37#include "AliTRDgeometry.h"\r
38#include "AliTRDrawStreamTB.h"\r
39#include "AliTRDqaBlackEvents.h"\r
40\r
41ClassImp(AliTRDqaBlackEvents)\r
42\r
43\r
44///////////////////////////////////////////////////////////////////////////////////////////////////\r
45\r
46AliTRDqaBlackEvents::AliTRDqaBlackEvents() \r
47 :TObject() \r
48 ,fMinNoise(0.5)\r
49 ,fMaxNoise(2) \r
9b99c029 50 ,fFitType(0)\r
51 ,fnEvents(0)\r
0f772b9f 52{\r
53 //\r
54 // Constructor \r
55 // to create the histograms call Init()\r
56 //\r
57}\r
58\r
59///////////////////////////////////////////////////////////////////////////////////////////////////\r
60\r
61AliTRDqaBlackEvents::AliTRDqaBlackEvents(const AliTRDqaBlackEvents &qa) \r
62 :TObject(qa) \r
63 ,fMinNoise(0.5)\r
64 ,fMaxNoise(2) \r
9b99c029 65 ,fFitType(0)\r
66 ,fnEvents(0)\r
0f772b9f 67{\r
68 //\r
69 // Copy constructor \r
70 // to create the histograms call Init()\r
71 //\r
72}\r
73\r
74///////////////////////////////////////////////////////////////////////////////////////////////////\r
75\r
76void AliTRDqaBlackEvents::Init() \r
77{\r
78 //\r
79 // creates histograms \r
80 // \r
81\r
82 //TFile *file = new \r
83 //Info("Init", "Statring");\r
84\r
9b99c029 85 fnEvents = 0;\r
86\r
0f772b9f 87 for(Int_t i=0; i<540; i++) {\r
9b99c029 88 fNPoint[i] = new TH2D(Form("entries_%d", i), "", 16, -0.5, 15.5, 144, -0.5, 143.5);\r
0f772b9f 89 fData[i] = new TH3D(Form("data_%d", i), "", 16, -0.5, 15.5, 144, -0.5, 143.5, 50, -0.5, 49.5);\r
9b99c029 90 fChPed[i] = new TH2D(Form("ped_%d", i), "", 16, -0.5, 15.5, 144, -0.5, 143.5);\r
0f772b9f 91 fChNoise[i] = new TH2D(Form("noise_%d", i), "", 16, -0.5, 15.5, 144, -0.5, 143.5);\r
9b99c029 92 fPed[i] = new TH1D(Form("pedDist_%d", i), ";pedestals (ADC counts)", 100, 5, 15);\r
93 fNoise[i] = new TH1D(Form("noiseDist_%d", i), ";noise (ADC counts)", 100, 0, 5); \r
94 fSignal[i] = new TH1D(Form("signal_%d", i), "signal (ADC counts)", 100, -0.5, 99.5);\r
0f772b9f 95 }\r
96\r
9b99c029 97 fOccupancy = new TH1D("occupancy", "", 20, -0.5, 19.5);\r
98\r
0f772b9f 99 //Info("Init", "Done");\r
100}\r
101\r
102\r
103///////////////////////////////////////////////////////////////////////////////////////////////////\r
104\r
105void AliTRDqaBlackEvents::Reset() \r
106{\r
107 //\r
108 // Resets the histograms\r
109 //\r
110\r
111 for(Int_t i=0; i<540; i++) {\r
112 fData[i]->Reset();\r
113 fChPed[i]->Reset();\r
114 fChNoise[i]->Reset();\r
115 }\r
116}\r
117\r
118///////////////////////////////////////////////////////////////////////////////////////////////////\r
119\r
120Int_t AliTRDqaBlackEvents::AddEvent(AliTRDrawStreamTB *data) \r
121{\r
122 //\r
123 // Add an event\r
124 //\r
125\r
9b99c029 126 \r
127 Char_t isUsed[540][16][144]; \r
128 for(Int_t i=0; i<540; i++)\r
129 for(Int_t j=0; j<16; j++)\r
130 for(Int_t k=0; k<144; k++)\r
131 isUsed[i][j][k] = 0;\r
132 \r
0f772b9f 133 Int_t nb = 0;\r
134 while (data->Next()) {\r
135\r
136 Int_t det = data->GetDet();\r
9b99c029 137 Int_t row = data->GetRow();\r
138 Int_t col = data->GetCol();\r
0f772b9f 139 Int_t *sig = data->GetSignals();\r
140 nb++;\r
141\r
9b99c029 142 //printf("det = %d\n", det);\r
143 \r
0f772b9f 144 if (det<0 || det>=540) continue;\r
9b99c029 145 isUsed[det][row][col]++;\r
146\r
147 // if (!isUsed[det][data->GetRow()][data->GetCol()]) {\r
148 // isUsed[det][data->GetRow()][data->GetCol()] = 1;\r
149 // continue;\r
150 // }\r
151\r
152 fNPoint[det]->Fill(row, col);\r
0f772b9f 153 \r
9b99c029 154 for(Int_t k=0; k<30; k++) { /// to be corrected\r
0f772b9f 155 fSignal[det]->Fill(sig[k]);\r
9b99c029 156 fData[det]->Fill(row, col, sig[k]);\r
0f772b9f 157 }\r
158 }\r
9b99c029 159 \r
160 for(Int_t i=0; i<540; i++) {\r
161 if (i != 0 && i != 8) continue;\r
162 for(Int_t j=0; j<16; j++)\r
163 for(Int_t k=0; k<144; k++)\r
164 fOccupancy->Fill(isUsed[i][j][k]);\r
165 }\r
0f772b9f 166\r
9b99c029 167 \r
168 fnEvents++;\r
0f772b9f 169 return nb;\r
170}\r
171\r
172///////////////////////////////////////////////////////////////////////////////////////////////////\r
173\r
174void AliTRDqaBlackEvents::Process(const char *filename) \r
175{\r
176 //\r
177 // Process something\r
178 //\r
179\r
180 Int_t map[540];\r
181 \r
182 TH1D *hist = new TH1D("fitSignal", "", 50, -0.5, 49.5);\r
183 TF1 *fit = new TF1("fit", "gaus(0)", 0, 20);\r
184 fit->SetParameters(1e3, 10, 1);\r
185 \r
186 for(Int_t i=0; i<540; i++) {\r
9b99c029 187 \r
0f772b9f 188 map[i] = 0;\r
9b99c029 189 if (fData[i]->GetSum() < 10) continue;\r
0f772b9f 190 map[i] = 1;\r
191\r
192 Info("process", "processing chamber %d", i);\r
193\r
194 for(Int_t j=0; j<fData[i]->GetXaxis()->GetNbins(); j++) {\r
195 for(Int_t k=0; k<fData[i]->GetYaxis()->GetNbins(); k++) {\r
196 \r
197 // project the histogramm\r
198 hist->Reset();\r
199 for(Int_t bb=0; bb<50; bb++) {\r
200 Int_t dataBin = fData[i]->FindBin(j, k, bb);\r
201 Double_t v = fData[i]->GetBinContent(dataBin);\r
202 hist->SetBinContent(bb+1, v);\r
203 }\r
204\r
205 //TH1D *hist = fData[i]->ProjectionZ(Form("pad_%_%d_%d", i, j, k), j+1, j+1, k+1, k+1);\r
206 \r
207 Int_t bin = fChPed[i]->FindBin(j, k);\r
208\r
9b99c029 209 if (hist->GetSum() > 1) {\r
210 \r
211 Double_t ped = 0, noise = 0;\r
212\r
213 if (fFitType == 0) {\r
214 fit->SetParameters(1e3, 10, 1);\r
215 hist->Fit(fit, "q0", "goff", 0, 20);\r
216 TF1 *f = hist->GetFunction("fit");\r
217 ped = TMath::Abs(f->GetParameter(1));\r
218 noise = TMath::Abs(f->GetParameter(2));\r
219 } else {\r
220 ped = hist->GetMean();\r
221 noise = hist->GetRMS();\r
222 }\r
0f772b9f 223\r
224 fChPed[i]->SetBinContent(bin, ped);\r
225 fChNoise[i]->SetBinContent(bin, noise);\r
226 \r
227 fPed[i]->Fill(ped);\r
228 fNoise[i]->Fill(noise);\r
229\r
230 } else {\r
9b99c029 231 fChPed[i]->SetBinContent(bin, 0);\r
232 fChNoise[i]->SetBinContent(bin, 0);\r
0f772b9f 233 }\r
234 \r
235 //delete hist;\r
236 }\r
237 }\r
238 }\r
239\r
9b99c029 240 // normalize number of entries histos\r
241\r
242 \r
243 Int_t max = 0;\r
244 for(Int_t i=0; i<540; i++) { \r
245 if (!map[i]) continue;\r
246 for(Int_t j=0; j<fNPoint[i]->GetXaxis()->GetNbins(); j++) {\r
247 for(Int_t k=0; k<fNPoint[i]->GetYaxis()->GetNbins(); k++) {\r
248 Int_t dataBin = fNPoint[i]->FindBin(j, k);\r
249 Double_t v = fNPoint[i]->GetBinContent(dataBin);\r
250 if (v > max) max = (Int_t)v;\r
251 }\r
252 }\r
253 }\r
254 \r
255 for(Int_t i=0; i<540; i++) {\r
256 \r
257 if (!map[i]) continue;\r
258 \r
259 fNPointDist[i] = new TH1D(Form("entriesDist_%d", i), ";number of events", max+2, -0.5, max+1.5);\r
260 \r
261 for(Int_t j=0; j<fNPoint[i]->GetXaxis()->GetNbins(); j++) {\r
262 for(Int_t k=0; k<fNPoint[i]->GetYaxis()->GetNbins(); k++) {\r
263 Int_t dataBin = fNPoint[i]->FindBin(j, k);\r
264 Double_t v = fNPoint[i]->GetBinContent(dataBin);\r
265 //if (v > fnEvents) printf("N = %d V = %lf\n", fnEvents, v);\r
266 fNPointDist[i]->Fill(v); \r
267 }\r
268 }\r
269 \r
270 fNPoint[i]->Scale(1./fnEvents);\r
271 }\r
272 \r
273 \r
0f772b9f 274 TFile *file = new TFile(filename, "UPDATE");\r
275 for(Int_t i=0; i<540; i++) {\r
276 if (!map[i]) continue; \r
277 fChPed[i]->Write();\r
278 fChNoise[i]->Write();\r
9b99c029 279 fNPoint[i]->Write();\r
280 fNPointDist[i]->Write();\r
0f772b9f 281 fPed[i]->Write();\r
282 fNoise[i]->Write();\r
283 fSignal[i]->Write();\r
284 }\r
9b99c029 285 fOccupancy->Write();\r
0f772b9f 286 file->Close();\r
287 delete file;\r
288}\r
289\r
290///////////////////////////////////////////////////////////////////////////////////////////////////\r
291\r
292void AliTRDqaBlackEvents::DrawChamber(const char *filename, Int_t det, Int_t w, Int_t h) \r
293{\r
294 //\r
295 // Draw raport for one chamber: \r
296 // pedestal map, noise map, distribution of pedestal and noise\r
297 // \r
298 // input:\r
299 // name of the file with histograms (created with Process())\r
300 // detector Id (0 - 539)\r
301 // \r
302\r
303 // setup global style\r
304 gStyle->SetPalette(1);\r
305 gStyle->SetOptStat(0);\r
306 gStyle->SetPadTopMargin(0.02);\r
307 gStyle->SetPadBottomMargin(0.05);\r
308\r
309 TFile *file = new TFile(filename, "READ");\r
310\r
311 TCanvas *c = new TCanvas("blackEvents",Form("blackEvents %d",det), w, h);\r
312 c->SetVertical(kFALSE);\r
313 c->Divide(3,1, 0.01, 0.01);\r
314 c->cd(3);\r
315 \r
316 TPad *mPad = (TPad*) gPad;\r
317 mPad->Divide(1,2,0.01,0.01);\r
318 \r
319 c->cd(1);\r
320 TH2D *h2 = (TH2D*)file->Get(Form("ped_%d",det));\r
321 h2->SetMinimum(5);\r
322 h2->SetMaximum(15);\r
323 h2->SetTitle(";Z direction;#phi direction");\r
324 h2->Draw("colz");\r
325 \r
326 c->cd(2);\r
327 h2 = (TH2D*)file->Get(Form("noise_%d",det));\r
328 h2->SetMinimum(fMinNoise);\r
329 h2->SetMaximum(fMaxNoise);\r
330 h2->SetTitle(";Z direction;#phi direction");\r
331 h2->Draw("colz");\r
332 \r
333 mPad->cd(1);\r
334 //gPad->SetLogy();\r
335 TH1D *h1 = (TH1D*)file->Get(Form("pedDist_%d", det));\r
336 h1->Draw();\r
337 \r
338 mPad->cd(2);\r
339 gPad->SetLogy();\r
340 h1 = (TH1D*)file->Get(Form("noiseDist_%d", det));\r
341 h1->Draw(); \r
342 \r
343 h1->Fit("gaus");\r
344 TF1 *f = h1->GetFunction("gaus");\r
345 const char *tt = Form("#mu = %.2f #sigma = %0.2f ", f->GetParameter(1),f->GetParameter(2));\r
346 TLatex *ll = new TLatex(2, 100, tt);\r
347 ll->SetTextSize(0.06);\r
348 ll->Draw();\r
349}\r
350\r
351///////////////////////////////////////////////////////////////////////////////////////////////////\r
352\r
353void AliTRDqaBlackEvents::DrawSm(const char *filename, Int_t sm, Int_t w, Int_t h) \r
354{\r
355 //\r
356 // ????????????\r
357 //\r
358 \r
359 gStyle->SetPalette(1);\r
360 gStyle->SetOptStat(0);\r
361 \r
362 gStyle->SetPadTopMargin(0.02);\r
363 //gStyle->SetPadBottomMargin(0.05); \r
364 //gStyle->SetPadLeftMargin(0.02); \r
365 //gStyle->SetPadRightMargin(0.02);\r
366\r
367 TFile *file = new TFile(filename, "READ");\r
368\r
369 TCanvas *c = new TCanvas("blackEventsSM",Form("blackEvents SM %d",sm), w, h);\r
370 c->SetVertical(kFALSE);\r
371 c->Divide(5, 6, 0.001, 0.01);\r
372 \r
373 for(Int_t i=0; i<30; i++) {\r
374 \r
375 TH2D *h2 = (TH2D*)file->Get(Form("noise_%d",i+30*sm));\r
376 if (!h2) continue;\r
377 h2->SetMinimum(fMinNoise);\r
378 h2->SetMaximum(fMaxNoise);\r
379\r
380 // to be replaced by the official calculation\r
381 Int_t stack = i/6;\r
382 Int_t layer = i%6;\r
383 Int_t index = (5-layer)*5 + stack + 1;\r
384 //printf("%d %d %d %d\n", i, stack, layer, index);\r
385 c->cd(index);\r
386 gPad->SetBottomMargin(0.02);\r
387 gPad->SetTopMargin(0.02);\r
388\r
389 h2->Draw("col");\r
390 }\r
391}\r
392\r
393///////////////////////////////////////////////////////////////////////////////////////////////////\r