]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDQADataMakerRec.cxx
1.The QA data created on demand according to the event species at filling time. 2...
[u/mrichter/AliRoot.git] / TRD / AliTRDQADataMakerRec.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //
20 //  Produces the data needed to calculate the quality assurance.          //
21 //  All data must be mergeable objects.                                   //
22 //                                                                        //
23 //  Author:                                                               //
24 //    Sylwester Radomski (radomski@physi.uni-heidelberg.de)               //
25 //                                                                        //
26 ////////////////////////////////////////////////////////////////////////////
27
28 // --- ROOT system ---
29 #include <TClonesArray.h>
30 #include <TFile.h> 
31 #include <TH1D.h> 
32 #include <TH2D.h>
33 #include <TH3D.h>
34 #include <TProfile.h>
35 #include <TF1.h>
36 #include <TCanvas.h>
37
38 // --- AliRoot header files ---
39 #include "AliESDEvent.h"
40 #include "AliLog.h"
41 #include "AliRawReader.h"
42 #include "AliTRDcluster.h"
43 #include "AliTRDQADataMakerRec.h"
44 #include "AliTRDgeometry.h"
45 //#include "AliTRDdataArrayI.h"
46 #include "AliTRDrawStream.h"
47
48 #include "AliQAChecker.h"
49
50 ClassImp(AliTRDQADataMakerRec)
51
52 //____________________________________________________________________________ 
53   AliTRDQADataMakerRec::AliTRDQADataMakerRec() : 
54   AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kTRD), "TRD Quality Assurance Data Maker")
55 {
56   //
57   // Default constructor
58 }
59
60 //____________________________________________________________________________ 
61 AliTRDQADataMakerRec::AliTRDQADataMakerRec(const AliTRDQADataMakerRec& qadm) :
62   AliQADataMakerRec()
63 {
64   //
65   // Copy constructor 
66   //
67
68   SetName((const char*)qadm.GetName()) ; 
69   SetTitle((const char*)qadm.GetTitle()); 
70
71 }
72
73 //__________________________________________________________________
74 AliTRDQADataMakerRec& AliTRDQADataMakerRec::operator=(const AliTRDQADataMakerRec& qadm)
75 {
76   //
77   // Equal operator.
78   //
79
80   this->~AliTRDQADataMakerRec();
81   new(this) AliTRDQADataMakerRec(qadm);
82   return *this;
83
84 }
85
86 //____________________________________________________________________________ 
87 void AliTRDQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
88 {
89   //
90   // Detector specific actions at end of cycle
91   //
92   //TStopwatch watch;
93   //watch.Start();
94   /**/
95   AliDebug(AliQAv1::GetQADebugLevel(), "End of TRD cycle");
96   
97   if (task == AliQAv1::kRECPOINTS) {
98     
99     TH1D * hist = new TH1D("fitHist", "", 200, -0.5, 199.5);
100
101     // loop over event types
102     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
103       if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) ) 
104         continue ;
105       //list[specie]->Print();
106       
107       // fill detector map;
108       for(Int_t i = 0 ; i < 540 ; i++) {
109         Double_t v = ((TH1D*)list[specie]->At(0))->GetBinContent(i+1);
110         Int_t sm = i/30;
111         Int_t det = i%30;
112         TH2D *detMap = (TH2D*)list[specie]->At(87);
113         Int_t bin = detMap->FindBin(sm, det);
114         detMap->SetBinContent(bin, v);
115       }
116       
117       // Rec points full chambers
118       for (Int_t i = 0 ; i < 540 ; i++) {
119         //AliDebug(AliQAv1::GetQADebugLevel(), Form("I = %d", i));
120         //TH1D *h = ((TH2D*)list[specie]->At(1))->ProjectionY(Form("qaTRD_recPoints_amp_%d",i), i+1, i+1);
121         hist->Reset();
122         
123         // project TH2D into TH1D 
124         for(Int_t b = 1 ; b < hist->GetXaxis()->GetNbins()-1 ; b++) {
125           Double_t xvalue = hist->GetBinCenter(b);
126           Int_t bin = ((TH2D*)list[specie]->At(1))->FindBin(i,xvalue);
127           Double_t value =  ((TH2D*)list[specie]->At(1))->GetBinContent(bin);
128           hist->SetBinContent(b, value);
129         }
130         //AliDebug(AliQAv1::GetQADebugLevel(), Form("Sum = %d %f\n", i, hist->GetSum()));
131         if (hist->GetSum() < 100) 
132           continue; // not enougth data in a chamber
133         
134         hist->Fit("landau", "q0", "goff", 10, 180);
135         TF1 *fit = hist->GetFunction("landau");
136         ((TH1D*)list[specie]->At(12))->Fill(fit->GetParameter(1));
137         ((TH1D*)list[specie]->At(13))->Fill(fit->GetParameter(2));
138       }
139
140
141       // time-bin by time-bin sm by sm
142       for(Int_t i=0; i<18; i++) { // loop over super-modules      
143         for(Int_t j=0; j<kTimeBin; j++) { // loop over time bins
144           
145           hist->Reset();
146           for(Int_t b = 1 ; b < hist->GetXaxis()->GetNbins()-1 ; b++) {
147             Double_t xvalue = hist->GetBinCenter(b);
148             Double_t svalue = 0.0;
149             for(Int_t det = i*30 ; det < (i+1)*30 ; det++) { // loop over detectors
150               Int_t bin = ((TH3D*)list[specie]->At(10))->FindBin(det,j,xvalue);
151               Double_t value =  ((TH3D*)list[specie]->At(10))->GetBinContent(bin);
152               svalue += value;
153             }
154             //AliDebug(AliQAv1::GetQADebugLevel(), Form("v = %f\n", value));
155             hist->SetBinContent(b, svalue);
156           }
157           
158           if (hist->GetSum() < 100) 
159             continue;
160           
161           hist->Fit("landau", "q0", "goff", 10, 180);
162           TF1 *fit = hist->GetFunction("landau");
163           
164           TH1D *h1 = (TH1D*)list[specie]->At(14+18+i);
165           h1->SetMarkerStyle(20);
166           Int_t bin = h1->FindBin(j);
167           // printf("%d %d %d\n", det, j, bin);
168           
169           Double_t value = TMath::Abs(fit->GetParameter(1));
170           Double_t error = TMath::Abs(fit->GetParError(1));
171          
172           if (value/error < 3) continue; // insuficient statistics
173           
174           h1->SetBinContent(bin, value);
175           h1->SetBinError(bin, error);  
176         }
177       }
178         
179       // for numerical convergence
180       TF1 *form = new TF1("formLandau", "landau", 0, 200);
181         
182       // time-bin by time-bin chamber by chamber
183       for (Int_t i=0; i<540; i++) {
184         for(Int_t j=0; j<kTimeBin; j++) {
185             
186           hist->Reset();
187           for(Int_t b = 1 ; b < hist->GetXaxis()->GetNbins()-1 ; b++) {
188             Double_t xvalue = hist->GetBinCenter(b);
189             Int_t bin = ((TH3D*)list[specie]->At(10))->FindBin(i,j,xvalue);
190             Double_t value =  ((TH3D*)list[specie]->At(10))->GetBinContent(bin);
191             //AliDebug(AliQAv1::GetQADebugLevel(), Form("v = %f\n", value));
192             hist->SetBinContent(b, value);
193           }
194           
195           if (hist->GetSum() < 100) 
196             continue;
197           
198           form->SetParameters(1000, 60, 20);
199           hist->Fit(form, "q0", "goff", 20, 180);
200           
201           Int_t sm = i/30;
202           Int_t det = i%30;
203           TH2D *h2 = (TH2D*)list[specie]->At(14+sm);
204           Int_t bin = h2->FindBin(det,j);
205           // printf("%d %d %d\n", det, j, bin);
206           
207           Double_t value = TMath::Abs(form->GetParameter(1));
208           Double_t error = TMath::Abs(form->GetParError(1));
209           
210           if (value/error < 3) continue;
211           
212           h2->SetBinContent(bin, value);
213           h2->SetBinError(bin, error);
214         }
215       }
216     }
217     if (hist) 
218       delete hist;
219   }
220   //////////////////////////
221   // const Int_t knbits = 6;
222   // const char *suf[knbits] = {"TPCi", "TPCo", "TPCz", "TRDo", "TRDr", "TRDz"};
223   //const char *sufRatio[4] = {"TRDrTRDo", "TRDoTPCo", "TRDrTPCo", "TRDzTPCo"};
224
225   if (task == AliQAv1::kESDS) {
226     
227     const Int_t knRatio = 4;
228     const Int_t kN[knRatio] = {4,3,4,5};
229     const Int_t kD[knRatio] = {3,1,1,3}; 
230     
231     // create ratios
232     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
233       if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) ) 
234         continue ;
235       for(Int_t type = 0 ; type < 2 ; type++) {
236         for(Int_t i = 0 ; i < knRatio ; i++) {
237           TH1D *ratio = (TH1D*)list[specie]->At(19 + 2*i + type);
238           TH1D *histN = (TH1D*)list[specie]->At(3 + 2*kN[i] + type);
239           TH1D *histD = (TH1D*)list[specie]->At(3 + 2*kD[i] + type);
240           BuildRatio(ratio, histN, histD);
241           //ratio->Reset();
242           //ratio->Add(histN);
243           //ratio->Divide(histD);
244         }
245       }
246       // ratio for the fraction of electrons per stack
247       TH1D *histN = (TH1D*)list[specie]->At(33);
248       TH1D *histD = (TH1D*)list[specie]->At(32);
249       TH1D *ratio = (TH1D*)list[specie]->At(34);
250       BuildRatio(ratio, histN, histD);
251     }
252   }
253   // call the checker
254   AliQAChecker::Instance()->Run(AliQAv1::kTRD, task, list) ;    
255
256 }
257
258 //____________________________________________________________________________ 
259 void AliTRDQADataMakerRec::InitESDs()
260 {
261   //
262   // Create ESDs histograms in ESDs subdir
263   //
264   const Bool_t expert   = kTRUE ; 
265   const Bool_t image    = kTRUE ; 
266   
267   const Int_t kNhist = 36+5+4;
268
269   TH1 *hist[kNhist];
270   Int_t histoCounter = -1 ;
271
272   hist[++histoCounter] = new TH1D("qaTRD_esd_ntracks", "TRD esd ntracks;Number of tracks;Counts", 300, -0.5, 299.5);
273   hist[++histoCounter] = new TH1D("qaTRD_esd_sector", "TRD esd sector;Sector;Counts", 18, -0.5, 17.7);
274   hist[++histoCounter] = new TH1D("qaTRD_esd_bits", "TRD esd bits;Bits;Counts", 64, -0.5, 63.5);
275
276   const Int_t knbits = 6;
277   const char *suf[knbits] = {"TPCi", "TPCo", "TPCz", "TRDo", "TRDr", "TRDz"};
278
279   // histo = 3
280   for(Int_t i=0; i<knbits; i++) { 
281     hist[++histoCounter] = new TH1D(Form("qaTRD_esd_pt%s",suf[i]), Form("qaTRD_esd_pt%s;p_{T} (GeV/c);Counts",suf[i]), 100, 0, 10);
282     hist[++histoCounter] = new TH1D(Form("qaTRD_esd_trdz%s", suf[i]), ";z (cm)", 200, -400, 400); 
283   }
284
285   hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDo", "TRDo;number of clusters;Counts", 180, -0.5, 179.5);;
286   hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDr", "TRDr;number of clusters;Counts", 180, -0.5, 179.5);;
287   hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDz", "TRDz;number of clusters;Counts", 180, -0.5, 179.5);;
288   //hist[++histoCounter] = new TH1D("qaTRD_esd_clsRatio", ";cluster ratio", 100, 0., 1.3);;
289
290   hist[++histoCounter] = new TH2D("qaTRD_esd_sigMom", "TRD esd sig Mom;momentum (GeV/c);signal", 100, 0, 5, 200, 0, 1e3);
291
292   // end of cycle plots (hist 19)
293   const char *sufRatio[4] = {"TRDrTRDo", "TRDoTPCo", "TRDrTPCo", "TRDzTPCo"};
294
295   for(int i=0; i<4; i++) {
296     hist[++histoCounter] = new TH1D(Form("qaTRD_esd_pt%s",sufRatio[i]), 
297                                     Form("Efficiency in Pt %s;p_{T};eff", sufRatio[i]),
298                                     100, 0, 10);
299
300     hist[++histoCounter] = new TH1D(Form("qaTRD_esd_trdz%s",sufRatio[i]), 
301                                     Form("Efficiency in Z %s;z (cm);eff", sufRatio[i]),
302                                     200, -400, 400);
303   }
304
305   // 27 - 31
306   hist[27] = new TH1D("qaTRD_esd_quality", "TRD esd quality;quality;Counts", 120, 0, 12);
307   hist[28] = new TH1D("qaTRD_esd_budget", "TRD esd budget;NN;Counts", 110, -1000, 100);
308   hist[29] = new TH1D("qaTRD_esd_chi2", "TRD esd chi2;chi2;Counts", 200, 0, 100);
309   hist[30] = new TH1D("qaTRD_esd_timeBin", "TRD esd timeBin;time bin;Counts", 7, -0.5, 6.5);
310   hist[31] = new TH1D("qaTRD_esd_pidQuality", "pid Quality;quality;;Counts", 7, -0.5, 6.5);
311
312   // stack by stack electron identyfication
313   hist[32] = new TH1D("qaTRD_esd_tracksStack", "number of all tracks;stack;Counts", 90, -0.5, 89.5);
314   hist[33] = new TH1D("qaTRD_esd_electronStack", "number of electron tracks;stack;Counts", 90, -0.5, 89.5);
315   hist[34] = new TH1D("qaTRD_esd_elRatioStack", "fraction of electron tracks;stack;Counts", 90, -0.5, 89.5);
316   hist[35] = new TH1D("qaTRD_esd_thetaOut", ";tan(theta);", 100, -1, 1);
317   
318   const char *partType[5] = {"Electron", "Muon", "Pion", "Kaon", "Proton"}; 
319
320   for(Int_t i=0; i<AliPID::kSPECIES; i++)
321     hist[36+i] = new TH1D(Form("qaTRD_esd_pid%d",i),
322                           Form("%s;probability;Counts",partType[i]), 100, 0, 1);
323  
324   // dE/dX vs momentum in three regions
325   const char *zoneName[4] = {"total charge", "ampilification range", "plateau", "TR range"};
326  
327   // prepare the scale from 0.1 to 10 GeV
328   const Int_t nscalex= 50;
329   Double_t scalex[nscalex+1];
330   Double_t dd = (TMath::Log(10) - TMath::Log(0.5)) / nscalex;
331   for(Int_t ix=0; ix<nscalex+1; ix++) {
332     scalex[ix] = 0.5 * TMath::Exp(dd * ix);
333   }
334
335   const Int_t nscaley = 50;
336   Double_t scaley[nscaley+1];
337   for(Int_t iy=0; iy<nscaley+1; iy++) {
338     scaley[iy] = iy * (3e3/nscaley);
339   }
340     
341
342   for(Int_t i=0; i<4; i++) {
343     hist[41+i] = new TH2D(Form("qaTRD_esd_signalPzone_%d",i), 
344                           Form("%s;momentum (GeV/c);signal (a.u.)", zoneName[i]),
345                           nscalex, scalex, nscaley, scaley);
346   }
347
348   for(Int_t i=0; i<kNhist; i++) {
349     //hist[i]->Sumw2();
350     Add2ESDsList(hist[i], i, !expert, image);
351   }
352
353 }
354
355 //____________________________________________________________________________ 
356 void AliTRDQADataMakerRec::InitRecPoints()
357 {
358   //
359   // Create Reconstructed Points histograms in RecPoints subdir
360   //
361   const Bool_t expert   = kTRUE ; 
362   const Bool_t image    = kTRUE ; 
363   
364   //printf("Helo from Init rec points\n");
365
366   const Int_t kNhist = 14 + 4 * 18 + 2 + 9;// + 540;
367   TH1 *hist[kNhist];
368
369   hist[0] = new TH1D("qaTRD_recPoints_det", "RRD recPoints det;Detector ID of the cluster;Counts", 540, -0.5, 539.5);
370   hist[1] = new TH2D("qaTRD_recPoints_amp", "TRD recPoints amp;Amplitude;??", 540, -0.5, 539, 200, -0.5, 199.5);
371   hist[2] = new TH1D("qaTRD_recPoints_npad", "TRD recPoints npad;Number of Pads;Counts", 12, -0.5, 11.5);
372
373   hist[3] = new TH1D("qaTRD_recPoints_dist2", "TRD recPoints dist2;residuals [2pad];Counts", 100, -1, 1);
374   hist[4] = new TH1D("qaTRD_recPoints_dist3", "TRD recPoints dist3;residuals [3pad];Counts", 100, -1, 1);
375   hist[5] = new TH1D("qaTRD_recPoints_dist4", "TRD recPoints dist4;residuals [4pad];Counts", 100, -1, 1);
376   hist[6] = new TH1D("qaTRD_recPoints_dist5", "TRD recPoints dist5;residuals [5pad];Counts", 100, -1, 1);
377
378   hist[7] = new TH2D("qaTRD_recPoints_rowCol", "TRDrecPointsrowCol;row;col", 16, -0.5, 15.5, 145, -0.5, 144.5);
379   hist[8] = new TH1D("qaTRD_recPoints_time", "TRDrecPoints time;time bin;Counts", kTimeBin, -0.5, kTimeBin-0.5);
380   hist[9] = new TH1D("qaTRD_recPoints_nCls", "TRD recPoints nCls;number of clusters;Counts", 500, -0.5, 499.5);
381
382   hist[10] = new TH3D("qaTRD_recPoints_sigTime", "TRD recPoints sigTime;chamber;time bin;signal", 
383                       540, -0.5, 539.5, kTimeBin, -0.5, kTimeBin-0.5, 200, -0.5, 199.5);
384   hist[11] = new TProfile("qaTRD_recPoints_prf", "TRD recPoints prf;distance;center of gravity;Counts"
385                          , 120, -0.6, 0.6, -1.2, 1.2, "");
386
387   hist[12] = new TH1D("qaTRD_recPoints_ampMPV", "TRD recPoints ampMPV;amplitude MPV;Counts", 150, 0, 150);
388   hist[13] = new TH1D("qaTRD_recPoints_ampSigma", "TRD recPoints ampSigma;amplitude Sigma;Counts", 200, 0, 200); 
389   
390   // chamber by chamber
391   for(Int_t i=0; i<18; i++) {
392     hist[14+i] = new TH2D(Form("qaTRD_recPoints_sigTime_sm%d",i), Form("sm%d;det;time bin"), 
393                         30, -0.5, 29.5, kTimeBin, -0.5, kTimeBin-0.5);
394     hist[14+i]->SetMinimum(0);
395     hist[14+i]->SetMaximum(150);
396   }
397  
398   // time bin by time bin sm-by-sm
399   for(Int_t i=0; i<18; i++) {
400     hist[14+18+i] = new TH1D(Form("qaTRD_recPoints_sigTimeShape_sm%d", i), 
401                              Form("sm%d;time bin;signal"),
402                              kTimeBin, -0.5, kTimeBin-0.5);
403
404     hist[14+18+i]->SetMaximum(150);    
405   }
406
407   // str = 50
408   for(Int_t i=0; i<18; i++) {
409     hist[50+i] = new TH1D(Form("qaTRD_recPoints_nCls_sm%d",i),
410                           Form("sm%d;time bin;number of clusters",i),
411                           kTimeBin, -0.5, kTimeBin-0.5);
412   }
413
414   // str = 68
415   for(Int_t i=0; i<18; i++) {
416     hist[68+i] = new TH1D(Form("qaTRD_recPoints_totalCharge_sm%d", i),
417                           Form("sm%d;time bin;total charge", i),
418                           kTimeBin, -0.5, kTimeBin-0.5);
419   }
420
421   hist[86] = new TH1D("qaTRD_recPoints_signal", "TRD recPoints signal;amplitude;Counts", 400, -0.5, 399.5);
422   hist[87] = new TH2D("qaTRD_recPoints_detMap", "TRD recPoints detMap;sm;chamber;Counts", 18, -0.5, 17.5, 30, -0.5, 29.5);
423
424   
425   // amplitude as a function of the pad size
426   for(Int_t i=0; i<9; i++) {
427     hist[88+i] = new TH1D(Form("qaTRD_recPoints_signalNpad_%d", i+2), Form("qaTRD_recPoints_signalNpad_%d;amplitude, ADC", i+2), 400, -0.5, 399.5); 
428   }
429   
430   // one 2D histogram per chamber
431   //  for(Int_t i=0; i<540; i++) {
432   //  hist[88+i] = new TH2D(Form("qaTRD_recPoints_map%d", i), ";col;row", 16, -0.5, 15.5, 144, -0.5, 143.5);
433   //}
434
435
436   for(Int_t i=0; i<kNhist; i++) {
437     //hist[i]->Sumw2();
438     Add2RecPointsList(hist[i], i, !expert, image);
439   }
440 }
441
442 //____________________________________________________________________________ 
443 void AliTRDQADataMakerRec::InitRaws()
444 {
445   //
446   // create Raws histograms in Raws subdir
447   //
448   const Bool_t expert   = kTRUE ; 
449   const Bool_t saveCorr = kTRUE ; 
450   const Bool_t image    = kTRUE ; 
451   
452   AliInfo("Initialization of QA for Raw Data");
453
454   //const Int_t kSM = 18;
455   //const Int_t kNCh = 540;
456   const Int_t kNhist = 6;
457   TH1 *hist[kNhist];
458
459   // link monitor
460   const char *linkName[3] = {"smLink", "smBeaf", "smData"};
461   for(Int_t i=0; i<3; i++) {
462     hist[i] = new TH2D(Form("qaTRD_raws_%s", linkName[i]), 
463                        ";super module;link", 
464                        18, -0.5, 17.5, 60, -0.5, 59.5);
465   }
466
467   hist[3] = new TH1D("qaTRD_raws_errorHC", "TRD raws error HC;error ID;Counts", 18, -3.5, 14.5);
468   hist[4] = new TH1D("qaTRD_raws_errorMCM", "TRD raws error MCM;error ID;Counts", 18, -3.5, 14.5);
469   hist[5] = new TH1D("qaTRD_raws_errorADC", "TRD raws errorADC;error ID;Counts", 18, -3.5, 14.5);
470
471   /*
472   // four histograms to be published
473   hist[0] = new TH1D("qaTRD_raws_det", ";detector", 540, -0.5, 539.5);
474   hist[1] = new TH1D("qaTRD_raws_sig", ";signal", 100, -0.5, 99.5);
475   hist[2] = new TH1D("qaTRD_raws_timeBin", ";time bin", 40, -0.5, 39.5); 
476   hist[3] = new TH1D("qaTRD_raws_smId", ";supermodule", 18, -0.5, 17.5);
477   //
478   
479   // one double per MCM (not published)
480   const Int_t kNMCM = 30 * 8 * 16;
481   for(Int_t i=0; i<kSM; i++)
482     hist[4+i] = new TH1D(Form("qaTRD_raws_sm%d",i),"",kNMCM, -0.5, kNMCM-0.5); 
483   */
484
485   // register
486   for(Int_t i=0; i<kNhist; i++) {
487     //hist[i]->Sumw2();
488     Add2RawsList(hist[i], i, !expert, image, !saveCorr);
489   }
490
491 }
492
493 //____________________________________________________________________________
494 void AliTRDQADataMakerRec::MakeESDs(AliESDEvent * esd)
495 {
496   //
497   // Make QA data from ESDs
498   //
499
500   // Check id histograms already created for this Event Specie
501   if ( ! GetESDsData(0) )
502     InitESDs() ;
503   
504   Int_t nTracks = esd->GetNumberOfTracks();
505   GetESDsData(0)->Fill(nTracks);
506
507   // track loop
508   for (Int_t iTrack = 0; iTrack<nTracks; iTrack++) {
509
510     AliESDtrack *track = esd->GetTrack(iTrack);
511     const AliExternalTrackParam *paramOut = track->GetOuterParam();
512     const AliExternalTrackParam *paramIn = track->GetInnerParam();
513
514     // long track ..
515     if (!paramIn) continue;
516     if (!paramOut) continue;
517
518     // not a kink
519     if (track->GetKinkIndex(0) > 0) continue; 
520
521     Double_t extZ = GetExtZ(paramIn);
522     if (TMath::Abs(extZ) > 320) continue; // acceptance cut
523
524     // .. in the acceptance
525     Int_t sector = GetSector(paramOut->GetAlpha());
526     Int_t stack = GetStack(paramOut);
527
528     UInt_t u = 1;
529     UInt_t status = track->GetStatus();
530     for(Int_t bit=0; bit<32; bit++) 
531       if (u<<bit & status) GetESDsData(2)->Fill(bit);
532
533     const Int_t knbits = 6; 
534     Int_t bit[6] = {0,0,0,0,0,0};    
535     bit[0] = status & AliESDtrack::kTPCin;
536     bit[1] = status & AliESDtrack::kTPCout;
537     bit[2] = (status & AliESDtrack::kTPCout) && !(status & AliESDtrack::kTRDout);
538     bit[3] = status & AliESDtrack::kTRDout;
539     bit[4] = status & AliESDtrack::kTRDrefit;
540     bit[5] = (status & AliESDtrack::kTRDout) && !(status & AliESDtrack::kTRDrefit);
541
542     // transverse momentum
543     //const Double_t *val = paramOut->GetParameter(); // parameters at the Outer plane
544     Double_t pt = paramOut->Pt(); //1./TMath::Abs(val[4]);
545
546     for(Int_t b=0; b<knbits; b++) {
547       if (bit[b]) {
548         GetESDsData(2*b+3)->Fill(pt); 
549         GetESDsData(2*b+4)->Fill(extZ);
550       }
551     }
552
553     // clusters
554     for(Int_t b=0; b<3; b++) 
555       if (bit[3+b]) GetESDsData(b+15)->Fill(track->GetTRDncls0());
556
557     // refitted only
558     if (!bit[4]) continue;
559
560     //fQuality->Fill(track->GetTRDQuality());
561     //fBudget->Fill(track->GetTRDBudget());
562     //fSignal->Fill(track->GetTRDsignal());
563
564     GetESDsData(1)->Fill(sector);
565     GetESDsData(18)->Fill(track->GetP(), track->GetTRDsignal());
566
567     GetESDsData(27)->Fill(track->GetTRDQuality());
568     GetESDsData(28)->Fill(track->GetTRDBudget());
569     GetESDsData(29)->Fill(track->GetTRDchi2());
570     GetESDsData(30)->Fill(track->GetTRDTimBin(0));
571     GetESDsData(31)->Fill(track->GetTRDntrackletsPID());
572     
573     
574     // dedx
575     for(Int_t k=0; k<4; ++k) {
576       Double_t dedx = 0;
577       for(Int_t j=0; j<6; j++) {
578         dedx += track->GetTRDslice(j, k-1);
579       }
580       GetESDsData(41+k)->Fill(paramOut->GetP(), dedx/6.);
581     }
582
583     // probabilities
584     if (status & AliESDtrack::kTRDpid) {
585       for(Int_t k=0; k<AliPID::kSPECIES; ++k) 
586         GetESDsData(36+k)->Fill(track->GetTRDpid(k));
587     }
588
589     // probabilities uniformity
590     if (track->GetTRDntrackletsPID() < 6) continue;
591     GetESDsData(35)->Fill(paramOut->GetZ()/paramOut->GetX());
592     
593     Int_t idx = 5 * sector + stack;
594     GetESDsData(32)->Fill(idx); // all tracks
595     if (track->GetTRDpid(AliPID::kElectron) > 0.9) 
596       GetESDsData(33)->Fill(idx); // electrons only
597
598     
599
600     /*
601     hist[27] = new TH1D("qaTRD_esd_quality", ";quality", 120, 0, 12);
602     hist[28] = new TH1D("qaTRD_esd_budget", ";NN", 110, -1000, 100);
603     hist[29] = new TH1D("qaTRD_esd_chi2", ";chi2", 300, 0, 100);
604     hist[30] = new TH1D("qaTRD_esd_timeBin", 7, -0.5, 6.5);
605     hist[31] = new TH1D("qaTRD_esd_pidQuality", 7, -0.5, 6.5);
606     */
607
608     /*
609     // PID only
610     if (status & AliESDtrack::kTRDpid) {
611
612       for(Int_t l=0; l<6; l++) fTime->Fill(track->GetTRDTimBin(l));
613
614       // fill pid histograms
615       Double_t trdr0 = 0; //, tpcr0 = 0;
616       Int_t trdBestPid = 5; //, tpcBestPid = 5;  // charged
617       const Double_t kminPidValue = 0.9;
618
619       //Double_t pp[5];
620       //track->GetTPCpid(pp); // ESD inconsequence
621
622       for(Int_t pid=0; pid<5; pid++) {
623         
624         trdr0 += track->GetTRDpid(pid);
625         //tpcr0 += pp[pid];
626         
627         fTrdPID[pid]->Fill(track->GetTRDpid(pid));
628         //fTpcPID[pid]->Fill(pp[pid]);
629         
630         if (track->GetTRDpid(pid) > kminPidValue) trdBestPid = pid;
631         //if (pp[pid] > kminPidValue) tpcBestPid = pid;
632       }
633
634       fTrdPID[5]->Fill(trdr0); // check unitarity
635       fTrdSigMomPID[trdBestPid]->Fill(track->GetP(), track->GetTRDsignal());
636
637       //fTpcPID[5]->Fill(tpcr0); // check unitarity
638       //fTpcSigMomPID[tpcBestPid]->Fill(track->GetP(), track->GetTPCsignal());
639     }
640     */
641
642   }
643
644 }
645
646 //______________________________________________________________________________
647 Int_t AliTRDQADataMakerRec::GetSector(Double_t alpha) const 
648 {
649   //
650   // Gets the sector number 
651   //
652
653   Double_t size = TMath::DegToRad() * 20.; // shall use TRDgeo
654   if (alpha < 0) alpha += 2*TMath::Pi();
655   Int_t sector = (Int_t)(alpha/size);
656   return sector;
657
658 }
659 //______________________________________________________________________________
660
661 Int_t AliTRDQADataMakerRec::GetStack(const AliExternalTrackParam *paramOut) const
662 {
663   //
664   // calculates the stack the track is in
665   //
666   
667   const Double_t L = -0.9;
668   const Double_t W = (2*L)/5;
669
670   Double_t tan = paramOut->GetZ() / paramOut->GetX();
671   Double_t pos = (tan - L) / W;
672   return (Int_t) pos;
673 }
674
675 //______________________________________________________________________________
676 Double_t AliTRDQADataMakerRec::GetExtZ(const AliExternalTrackParam *in) const 
677 {
678   //
679   // Returns the Z position at the entry to TRD
680   // using parameters from the TPC in
681   //
682
683   const Double_t kX0 = 300;
684
685   Double_t x = in->GetX();
686   const Double_t *par = in->GetParameter();
687   Double_t theta = par[3];
688   Double_t z = in->GetZ();
689
690   Double_t zz = z + (kX0-x) * TMath::Tan(theta);
691   return zz;
692
693 }
694
695 //____________________________________________________________________________
696 void AliTRDQADataMakerRec::MakeRaws(AliRawReader* rawReader)
697 {
698   //
699   // Makes QA data from raw data
700   //
701   
702   AliInfo("Execution of QA for Raw data");
703   
704   // Check id histograms already created for this Event Specie
705   if ( ! GetRawsData(0) )
706     InitRaws() ;
707   
708   //printf("Execution of QA for Raw data\n");
709
710   // create raw reader TB
711   rawReader->Reset();
712   rawReader->SelectEquipment(0, 1024, 1041);
713   rawReader->Select("TRD");
714   
715   // AliTRDrawStreamTB::AllowCorruptedData();
716   // AliTRDrawStreamTB::DisableStackNumberChecker();
717   // AliTRDrawStreamTB::DisableStackLinkNumberChecker();
718   // AliTRDrawStreamTB::DisableSkipData();
719
720   //AliTRDrawStreamTB *data = (AliTRDrawStreamTB*)AliTRDrawStreamBase::GetRawStream(rawReader);
721   AliTRDrawStream *data = (AliTRDrawStream *)AliTRDrawStreamBase::GetRawStream(rawReader);  
722
723   //if (raw->IsA()->GetName())
724
725
726   // import the histograms
727   TH2D *fSMLink[3];
728   for(Int_t i=0; i<3; i++) {
729     fSMLink[i] = (TH2D*)GetRawsData(i);
730     //printf("address = %d\n", fSMLink[i]);
731   }
732     
733   TH1D *fErrorHC =  (TH1D*)GetRawsData(3);
734   TH1D *fErrorMCM = (TH1D*)GetRawsData(4);
735   TH1D *fErrorADC = (TH1D*)GetRawsData(5);
736
737
738   // loop over super-modules
739   while (data->NextBuffer()) {
740     
741     //printf("processing next buffer\n");
742     // check sm
743     Int_t sm = rawReader->GetEquipmentId() - 1024;
744     if (sm < 0 || sm > 18) return;
745     
746     // loop over links
747     for (Int_t istack = 0; istack < 5; istack++) {      
748       for (Int_t ilink = 0; ilink < 12; ilink++) {
749         
750         //Int_t det = sm * 30 + istack * 6 + ilink/2;   
751       
752         // check if data delivered
753         if (!(data->IsLinkActiveInStack(istack, ilink))) continue;
754         fSMLink[0]->Fill(sm, istack * 12 + ilink);
755         
756         // check if beaf-beaf
757         if (data->GetLinkMonitorError(istack, ilink)) {
758           fSMLink[1]->Fill(sm, istack * 12 + ilink);
759           continue;
760         }
761         
762         // fill histogram with HC header errors
763         Int_t nErrHc = 0;
764         
765         nErrHc = FillBits(fErrorHC, data->GetH0ErrorCode(istack, ilink), 0);
766         if (!nErrHc) fErrorHC->Fill(-3);
767               
768         nErrHc = FillBits(fErrorHC, data->GetH1ErrorCode(istack, ilink), 2);
769         if (!nErrHc) fErrorHC->Fill(-2);
770               
771         nErrHc = FillBits(fErrorHC, data->GetHCErrorCode(istack, ilink), 4);
772         if (!nErrHc) fErrorHC->Fill(-1);
773         
774         // data integrity protection 
775         if (data->GetH0ErrorCode(istack, ilink) > 0) continue;
776         if (data->GetH1ErrorCode(istack, ilink) > 0) continue;
777         
778         fSMLink[2]->Fill(sm, istack * 12 + ilink);      
779
780         // loop over MCMs
781         for (Int_t imcm = 0; imcm < data->GetHCMCMmax(istack, ilink); imcm++ ){
782           
783           Int_t nErrMcm = 0;
784         
785           nErrMcm = FillBits(fErrorMCM, data->GetMCMhdErrorCode(istack, ilink, imcm), 0);
786           if (!nErrMcm) fErrorMCM->Fill(-3);
787         
788           nErrMcm = FillBits(fErrorMCM, data->GetMCMADCMaskErrorCode(istack, ilink, imcm), 5);
789           if (!nErrMcm) fErrorMCM->Fill(-2);
790         
791           nErrMcm = FillBits(fErrorMCM, data->GetMCMErrorCode(istack, ilink, imcm), 10);
792           if (!nErrMcm) fErrorMCM->Fill(-1);
793         
794           // MCM protection
795           if ( (data->GetMCMhdErrorCode(istack,ilink,imcm)) & 2 ) continue;
796
797           // loop over ADC chanels      
798           for (Int_t iadc=0; iadc < data->GetADCcount(istack, ilink, imcm); iadc++) {
799           
800             // fill ADC error bits
801             Int_t nErrAdc = FillBits(fErrorADC, data->GetADCErrorCode(), 0);
802             if (!nErrAdc) fErrorADC->Fill(-1);
803           }
804         } // mcm 
805       }
806     } // link
807
808     //printf("buffer analyzed\n");
809   }
810   
811   // clean up
812
813   AliInfo("sucessfull execution of QA for TRD raw data");
814   //printf("sucessfull execution of QA for TRD raw data\n");
815   
816
817   /*
818   // 157
819   // T9 -- T10
820
821   //const Int_t kSM = 18;
822   //const Int_t kROC = 30;
823   const Int_t kROB = 8;
824   //const Int_t kLayer = 6;
825   //const Int_t kStack = 5;
826   const Int_t kMCM = 16;
827   //  const Int_t kADC = 22;
828
829   rawReader->Reset() ; 
830   //AliTRDrawStreamBase::SetRawStreamVersion("TB");
831   AliTRDrawStreamBase *raw = AliTRDrawStreamBase::GetRawStream(rawReader);
832   AliDebug(2,Form("Stream version: %s", raw->IsA()->GetName()));
833
834   while (raw->Next()) {
835
836     GetRawsData(0)->Fill(raw->GetDet());
837
838     // possibly needs changes with the new reader !!
839     Int_t *sig = raw->GetSignals();
840     for(Int_t i=0; i<3; i++) GetRawsData(1)->Fill(sig[i]);
841     // ---
842
843     GetRawsData(2)->Fill(raw->GetTimeBin());
844
845     // calculate the index;
846     Int_t sm = raw->GetSM();
847     Int_t roc = raw->GetROC();
848     Int_t rob = raw->GetROB();
849     Int_t mcm = raw->GetMCM();
850     //Int_t adc = raw->GetADC();
851
852     //Int_t index = roc * (kROB*kMCM*kADC) + rob * (kMCM*kADC) + mcm * kADC + adc;
853     Int_t  index = roc * (kROB*kMCM) + rob * kMCM + mcm;
854     GetRawsData(3)->Fill(sm);
855     GetRawsData(4+sm)->Fill(index);
856   }
857
858   delete raw;
859   */
860 }
861
862 //____________________________________________________________________________
863 void AliTRDQADataMakerRec::MakeRecPoints(TTree * clustersTree)
864 {
865   //  
866   // Makes data from RecPoints
867   // 
868   
869   //  Info("MakeRecPoints", "making");
870
871   // Check id histograms already created for this Event Specie
872   if ( ! GetRecPointsData(0) )
873     InitRecPoints() ;
874   
875   Int_t nsize = Int_t(clustersTree->GetTotBytes() / (sizeof(AliTRDcluster))); 
876   TObjArray *clusterArray = new TObjArray(nsize+1000); 
877
878   TBranch *branch = clustersTree->GetBranch("TRDcluster");
879   if (!branch) {
880     AliError("Can't get the branch !");
881     return;
882   }
883   branch->SetAddress(&clusterArray); 
884
885   // Loop through all entries in the tree
886   Int_t nEntries   = (Int_t)TMath::Ceil( clustersTree->GetEntries() );
887   Int_t nbytes     = 0;
888   AliTRDcluster *c = 0;
889   Int_t nDet[540];
890   for (Int_t i=0; i<540; i++) nDet[i] = 0;
891
892   Int_t nCls = 0;
893   
894   //printf("nEntries = %d\n", nEntries);
895   //nEntries++;
896   
897   /*
898   // select the event 
899   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {    
900
901     // Import the tree
902     nbytes += clustersTree->GetEvent(iEntry);  
903     Int_t nCluster = clusterArray->GetEntries();  
904     
905     for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) { 
906       c = (AliTRDcluster *) clusterArray->At(iCluster);
907       nCls++;
908     }
909   }
910
911   if (nCls < 100) {
912     delete clusterArray;
913     return;
914   }
915   */
916
917   /////
918
919   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {    
920
921     // Import the tree
922     nbytes += clustersTree->GetEvent(iEntry);  
923
924     // Get the number of points in the detector
925     Int_t nCluster = clusterArray->GetEntries();  
926
927   
928     // Loop through all TRD digits
929     for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) { 
930
931       nCls++;
932       c = (AliTRDcluster *) clusterArray->At(iCluster);
933
934       Int_t iDet = c->GetDetector();
935       Int_t nPads = c->GetNPads();
936
937       nDet[iDet]++;
938       GetRecPointsData(0)->Fill(iDet);
939       GetRecPointsData(86)->Fill(c->GetQ());
940       GetRecPointsData(1)->Fill(iDet, c->GetQ());
941       GetRecPointsData(2)->Fill(nPads);
942       if (nPads < 6)
943         GetRecPointsData(1+c->GetNPads())->Fill(c->GetCenter());
944       
945       if (nPads < 10)
946         GetRecPointsData(88+nPads-2)->Fill(c->GetQ());
947       else GetRecPointsData(96)->Fill(c->GetQ());
948
949       //if (c->GetPadTime() < 5)
950       ((TH2D*)GetRecPointsData(7))->Fill(c->GetPadRow(), c->GetPadCol());
951       GetRecPointsData(8)->Fill(c->GetPadTime());
952
953       ((TH3D*)GetRecPointsData(10))->Fill(iDet, c->GetPadTime(), c->GetQ());
954       
955       Int_t iSM = iDet / 30;
956       GetRecPointsData(50+iSM)->Fill(c->GetPadTime());
957       GetRecPointsData(68+iSM)->Fill(c->GetPadTime(), c->GetQ());
958       
959       // total charge sm / det / timeBin
960       //((TH2D*)GetRecPointsData(14+iSM))->Fill(iDet-iSM*30, c->GetPadTime(), c->GetQ());
961
962
963       // PRF for 2pad
964       //if (c->GetNPads() == 2) {
965       Short_t *sig = c->GetSignals();
966       Double_t frac = -10;
967
968       if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0 && sig[5] == 0 && sig[6] == 0) 
969         frac = 1. * sig[4] / (sig[3] + sig[4]);
970
971       if (sig[0] == 0 && sig[1] == 0 && sig[4] == 0 && sig[5] == 0 && sig[6] == 0)
972         frac = -1. * sig[2] / (sig[2] + sig[3]);
973
974       if (frac > -10)  ((TProfile*)GetRecPointsData(11))->Fill(c->GetCenter(), frac);
975         
976       //}
977     }
978   }
979
980   /*
981   for(Int_t i=0; i<540; i++) 
982     if (nDet[i] > 0) GetRecPointsData(9)->Fill(nDet[i]);
983   */
984   GetRecPointsData(9)->Fill(nCls);
985   
986   delete clusterArray;
987
988 }
989
990 //____________________________________________________________________________ 
991 void AliTRDQADataMakerRec::StartOfDetectorCycle()
992 {
993   //
994   // Detector specific actions at start of cycle
995   //
996
997 }
998
999 //__________________________________________________________________________
1000 Int_t AliTRDQADataMakerRec::CheckPointer(TObject *obj, const char *name) 
1001 {
1002   //
1003   // Checks initialization of pointers
1004   //
1005
1006   if (!obj) AliWarning(Form("null pointer: %s", name));
1007   return !!obj;
1008 }
1009 //__________________________________________________________________________
1010 void AliTRDQADataMakerRec::BuildRatio(TH1D *ratio, TH1D *histN, TH1D*histD) {
1011   //
1012   // Calculate the ratio of two histograms 
1013   // error are calculated assuming the histos have the same counts
1014   //
1015
1016   // calclate
1017
1018   Int_t nbins = histN->GetXaxis()->GetNbins();
1019   for(Int_t i=1; i<nbins+2; i++) {
1020     
1021     Double_t valueN = histN->GetBinContent(i);
1022     Double_t valueD = histD->GetBinContent(i);
1023     
1024     if (valueD < 1) {
1025       ratio->SetBinContent(i, 0);
1026       ratio->SetBinError(i, 0);
1027       continue;
1028     }
1029
1030     Double_t eps = (valueN < valueD-valueN)? valueN : valueD-valueN;
1031     
1032     ratio->SetBinContent(i, valueN/valueD);
1033     ratio->SetBinError(i, TMath::Sqrt(eps)/valueD);
1034   }
1035
1036   // style
1037   ratio->SetMinimum(-0.1);
1038   ratio->SetMaximum(1.1);
1039   ratio->SetMarkerStyle(20);
1040 }
1041 //__________________________________________________________________________
1042
1043 Int_t AliTRDQADataMakerRec::FillBits(TH1D *hist, Int_t code, Int_t offset) {
1044
1045   Int_t nb = 0;
1046   UInt_t test = 1;
1047   for(Int_t i=0; i<8; i++) {
1048     if (code & test) {
1049       hist->Fill(i+offset);
1050       nb++;
1051     }
1052     test *= 2;       
1053   }
1054   
1055   return nb;
1056 }
1057
1058 //__________________________________________________________________________