]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDqaRecPoints.cxx
propagate cluster error parametrization
[u/mrichter/AliRoot.git] / TRD / AliTRDqaRecPoints.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: AliTRDqaRecPoints.cxx 23387 2008-01-17 17:25:16Z cblume $ */
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 "AliTRDcluster.h"
42 #include "AliTRDqaRecPoints.h"
43 #include "AliTRDgeometry.h"
44 #include "AliTRDdataArrayI.h"
45
46 #include "AliQAChecker.h"
47
48 ClassImp(AliTRDqaRecPoints)
49
50 //____________________________________________________________________________ 
51
52 AliTRDqaRecPoints::AliTRDqaRecPoints() : 
53   TObject(),
54   fnEvents(0),
55   fHist(0),
56   fnPad(0),
57   fRef(0)
58 {
59   //
60   // Default constructor
61   //
62
63 }
64
65 //____________________________________________________________________________ 
66
67 AliTRDqaRecPoints::AliTRDqaRecPoints(const AliTRDqaRecPoints &/*qa*/) : 
68   TObject(),
69   fnEvents(0),
70   fHist(0),
71   fnPad(0),
72   fRef(0)
73 {
74   //
75   // Copy constructor
76   //
77
78 }
79
80 //____________________________________________________________________________ 
81 void AliTRDqaRecPoints::Process(const char* filename)
82 {
83   //
84   // Detector specific actions at end of cycle
85   //
86   //TStopwatch watch;
87   //watch.Start();
88   
89   AliInfo("End of TRD cycle");
90   
91   //if (task == AliQA::kRECPOINTS) {
92   
93   TH1D *hist = new TH1D("fitHist", "", 200, -0.5, 199.5);
94   //fHist->Print();
95   
96   // fill detector map;
97   for(int i=0; i<540; i++) {
98     Double_t v = ((TH1D*)fHist->At(0))->GetBinContent(i+1);
99     Int_t sm = i/30;
100     Int_t det = i%30;
101     
102     TH2D *detMap = (TH2D*)fHist->At(87);
103     Int_t bin = detMap->FindBin(sm, det);
104     detMap->SetBinContent(bin, v);
105   }
106   
107   
108   // Rec points full chambers
109   for (Int_t i=0; i<540; i++) {
110     
111     //AliInfo(Form("I = %d", i));
112     
113     //TH1D *h = ((TH2D*)fHist->At(1))->ProjectionY(Form("qaTRD_recPoints_amp_%d",i), i+1, i+1);
114     hist->Reset();
115     for(Int_t b=1; b<hist->GetXaxis()->GetNbins()-1; b++) {
116       Double_t xvalue = hist->GetBinCenter(b);
117       Int_t bin = ((TH2D*)fHist->At(1))->FindBin(i,xvalue);
118       Double_t value =  ((TH2D*)fHist->At(1))->GetBinContent(bin);
119       hist->SetBinContent(b, value);
120     }
121     
122     //printf("Sum = %d %f\n", i, hist->GetSum());
123     if (hist->GetSum() < 100) continue; // chamber not present
124     
125     hist->Fit("landau", "q0", "goff", 10, 180);
126     TF1 *fit = hist->GetFunction("landau");
127     ((TH1D*)fHist->At(12))->Fill(fit->GetParameter(1));
128     ((TH1D*)fHist->At(13))->Fill(fit->GetParameter(2));
129   }
130   
131   // time-bin by time-bin sm by sm
132   for(Int_t i=0; i<18; i++) { // loop over super-modules
133     
134     for(Int_t j=0; j<35; j++) { // loop over time bins
135       
136       //TH1D *h =  ((TH3D*)fHist->At(10))->ProjectionZ(Form("ampTime_%d",i), i+1, i+1, j+1, j+1);     
137       hist->Reset();
138       for(Int_t b=1; b<hist->GetXaxis()->GetNbins()-1; b++) {
139         Double_t xvalue = hist->GetBinCenter(b);
140         Double_t svalue = 0;
141         
142         for(Int_t det=i*30; det<(i+1)*30; det++) { // loop over detectors
143           Int_t bin = ((TH3D*)fHist->At(10))->FindBin(det,j,xvalue);
144           Double_t value =  ((TH3D*)fHist->At(10))->GetBinContent(bin);
145           svalue += value;
146         }
147         //printf("v = %f\n", value);
148         hist->SetBinContent(b, svalue);
149       }
150       
151       if (hist->GetSum() < 100) continue;
152       //printf("fitting %d %d %f\n", i, j, hist->GetSum());
153       
154       hist->Fit("landau", "q0", "goff", 10, 180);
155       TF1 *fit = hist->GetFunction("landau");
156       
157       TH1D *h1 = (TH1D*)fHist->At(14+18+i);
158       Int_t bin = h1->FindBin(j);
159       // printf("%d %d %d\n", det, j, bin);
160       h1->SetBinContent(bin, TMath::Abs(fit->GetParameter(1)));
161     }
162   }
163   
164
165   // time-bin by time-bin chamber by chamber
166
167   for (Int_t i=0; i<540; i++) {
168     
169     //TH1D *test = ((TH3D*)fHist->At(10))->ProjectionZ(Form("ampTime_%d",i), i+1, i+1, 0, 35);     
170     //if (test->GetSum() < 100) continue;
171     
172     //AliInfo(Form("fitting det = %d", i));
173     
174     for(Int_t j=0; j<35; j++) {
175       
176       //TH1D *h =  ((TH3D*)fHist->At(10))->ProjectionZ(Form("ampTime_%d",i), i+1, i+1, j+1, j+1);     
177       hist->Reset();
178       for(Int_t b=1; b<hist->GetXaxis()->GetNbins()-1; b++) {
179         Double_t xvalue = hist->GetBinCenter(b);
180         Int_t bin = ((TH3D*)fHist->At(10))->FindBin(i,j,xvalue);
181         Double_t value =  ((TH3D*)fHist->At(10))->GetBinContent(bin);
182         //printf("v = %f\n", value);
183         hist->SetBinContent(b, value);
184       }
185       
186       if (hist->GetSum() < 100) continue;
187       //printf("fitting %d %d %f\n", i, j, hist->GetSum());
188       
189       hist->Fit("landau", "q0", "goff", 10, 180);
190       TF1 *fit = hist->GetFunction("landau");
191       
192       Int_t sm = i/30;
193       Int_t det = i%30;
194       TH2D *h2 = (TH2D*)fHist->At(14+sm);
195       Int_t bin = h2->FindBin(det,j);
196       // printf("%d %d %d\n", det, j, bin);
197       h2->SetBinContent(bin, TMath::Abs(fit->GetParameter(1)));
198       h2->SetBinError(bin,fit->GetParError(1));
199     }
200   }
201     
202   if (hist) delete hist;
203     
204   
205   TFile *outFile = new TFile(filename, "RECREATE");
206   outFile->mkdir("TRD");
207   gDirectory->cd("TRD");
208   gDirectory->mkdir("RecPoints");
209   gDirectory->cd("RecPoints");
210   fHist->Write();
211
212   if (fRef) {
213     for(Int_t i=0; i<540; i++) {
214       //fRefHist[i]->Scale(1./fnEvents);
215       fRefHist[i]->Write();
216     }
217   }
218
219   outFile->Close();
220
221 }
222
223 //____________________________________________________________________________ 
224
225 void AliTRDqaRecPoints::Init()
226 {
227   //
228   // Create Reconstructed Points histograms in RecPoints subdir
229   //
230
231   //const Int_t kNhist = 14 + 4 * 18 + 2;
232   const Int_t kNhist = 88+2*18+1;
233   TH1 *hist[kNhist];
234
235   hist[0] = new TH1D("qaTRD_recPoints_det", ";Detector ID of the cluster", 540, -0.5, 539.5);
236   hist[1] = new TH2D("qaTRD_recPoints_amp", ";Amplitude", 540, -0.5, 539, 200, -0.5, 199.5);
237   hist[2] = new TH1D("qaTRD_recPoints_npad", ";Number of Pads", 12, -0.5, 11.5);
238
239   hist[3] = new TH1D("qaTRD_recPoints_dist2", ";residuals [2pad]", 100, -1, 1);
240   hist[4] = new TH1D("qaTRD_recPoints_dist3", ";residuals [3pad]", 100, -1, 1);
241   hist[5] = new TH1D("qaTRD_recPoints_dist4", ";residuals [4pad]", 100, -1, 1);
242   hist[6] = new TH1D("qaTRD_recPoints_dist5", ";residuals [5pad]", 100, -1, 1);
243
244   hist[7] = new TH2D("qaTRD_recPoints_rowCol", ";row;col", 16, -0.5, 15.5, 145, -0.5, 144.5);
245   hist[8] = new TH1D("qaTRD_recPoints_time", ";time bin", 35, -0.5, 34.5);
246   hist[9] = new TH1D("qaTRD_recPoints_nCls", ";number of clusters", 500, -0.5, 499.5);
247
248   hist[10] = new TH3D("qaTRD_recPoints_sigTime", ";chamber;time bin;signal", 
249                       540, -0.5, 539.5, 35, -0.5, 34.5, 200, -0.5, 199.5);
250   hist[11] = new TProfile("qaTRD_recPoints_prf", ";distance;center of gravity"
251                          , 120, -0.6, 0.6, -1.2, 1.2, "");
252
253   hist[12] = new TH1D("qaTRD_recPoints_ampMPV", ";amplitude MPV", 150, 0, 150);
254   hist[13] = new TH1D("qaTRD_recPoints_ampSigma", ";amplitude Sigma", 200, 0, 200); 
255   
256   // chamber by chamber
257   for(Int_t i=0; i<18; i++) {
258     hist[14+i] = new TH2D(Form("qaTRD_recPoints_sigTime_sm%d",i), Form("sm%d;det;time bin"), 
259                         30, -0.5, 29.5, 35, -0.5, 34.5);
260     hist[14+i]->SetMinimum(20);
261     hist[14+i]->SetMaximum(40);
262   }
263  
264   // time bin by time bin sm-by-sm
265   for(Int_t i=0; i<18; i++) {
266     hist[14+18+i] = new TH1D(Form("qaTRD_recPoints_sigTimeShape_sm%d", i), 
267                              Form("sm%d;time bin;signal"),
268                              35, -0.5, 34.5);
269
270     hist[14+18+i]->SetMaximum(120);    
271   }
272
273   // str = 50
274   for(Int_t i=0; i<18; i++) {
275     hist[50+i] = new TH1D(Form("qaTRD_recPoints_nCls_sm%d",i),
276                           Form("sm%d;time bin;number of clusters",i),
277                           35, -0.5, 34.5);
278   }
279
280   // str = 68
281   for(Int_t i=0; i<18; i++) {
282     hist[68+i] = new TH1D(Form("qaTRD_recPoints_totalCharge_sm%d", i),
283                           Form("sm%d;time bin;total charge", i),
284                           35, -0.5, 34.5);
285   }
286
287   hist[86] = new TH1D("qaTRD_recPoints_signal", ";amplitude", 200, -0.5, 199.5);
288   hist[87] = new TH2D("qaTRD_recPoints_detMap", ";sm;chamber", 18, -0.5, 17.5, 30, -0.5, 29.5);
289
290   for(Int_t i=0; i<18; i++)
291     hist[88+i] = new TH2D(Form("qaTRD_recPoints_XY_sm%d", i), 
292                           Form("SM%d;Y;X",i), 240, -60, 60, 200, 290, 370);
293
294   for(Int_t i=0; i<18; i++)
295     hist[106+i] = new TH2D(Form("qaTRD_recPoints_XPad_sm%d", i), 
296                           Form("SM%d;Y;X",i), 144, -0.5, 143.5, 200, 290, 370);
297
298  
299   hist[124] = new TH1D("qRef", "ref", 100, 0, 1e4);
300
301   fHist = new TObjArray(200);
302   for(Int_t i=0; i<kNhist; i++) {
303     //hist[i]->Sumw2();
304     fHist->AddAt(hist[i], i);
305   }
306
307   // reference histograms
308   if (fRef) {
309     for(Int_t i=0; i<540; i++) {
310       fRefHist[i] = new TH2D(Form("refRecPoints_sm%d", i), "",
311                              16, -0.5, 15.5, 144, -0.5, 143.5); //, 30, -0.5, 29.5);
312     }
313   } else {
314     
315     TFile *refFile = new TFile("outRef.root");
316     refFile->cd("TRD/RecPoints");
317
318     for(Int_t i=0; i<540; i++) {
319       fRefHist[i] = (TH2D*)gDirectory->Get(Form("refRecPoints_sm%d", i));
320     }
321   }
322 }
323
324 //____________________________________________________________________________ 
325
326 void AliTRDqaRecPoints::AddEvent(TTree * clustersTree)
327 {
328   //  
329   // Makes data from RecPoints
330   // 
331   
332   //  Info("MakeRecPoints", "making");
333
334   Int_t nsize = Int_t(clustersTree->GetTotBytes() / (sizeof(AliTRDcluster))); 
335   TObjArray *clusterArray = new TObjArray(nsize+1000); 
336
337   TBranch *branch = clustersTree->GetBranch("TRDcluster");
338   if (!branch) {
339     AliError("Can't get the branch !");
340     return;
341   }
342   branch->SetAddress(&clusterArray); 
343
344   // Loop through all entries in the tree
345   Int_t nEntries   = (Int_t) clustersTree->GetEntries();
346   Int_t nbytes     = 0;
347   AliTRDcluster *c = 0;
348   Int_t nDet[540];
349   for (Int_t i=0; i<540; i++) nDet[i] = 0;
350
351   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {    
352
353     //printf("Entry = %d\n", iEntry);
354
355     // Import the tree
356     nbytes += clustersTree->GetEvent(iEntry);  
357
358     // Get the number of points in the detector
359     Int_t nCluster = clusterArray->GetEntriesFast();  
360
361     // Loop through all TRD digits
362     for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) { 
363       c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
364
365       Int_t iDet = c->GetDetector();
366       if (iDet < 0 || iDet > 539) continue;
367
368       
369       Int_t iSM = iDet / 30;
370       //Int_t iStack = iDet % 30;
371       Int_t nPad = c->GetNPads();
372
373       if (fnPad && nPad != fnPad) continue;
374       
375       //if (iSM == 0 && iStack == 29) continue;
376       //if (iSM == 8 && iStack == 11) continue;
377       //if (iSM == 8 && iStack == 7)  continue;      
378       
379       Int_t padRow = c->GetPadRow();
380       Int_t padCol = c->GetPadCol();
381       //Int_t timeBin = c->GetPadTime();
382
383       Double_t refQ = 0;
384
385       if (fRef) {
386         fRefHist[iDet]->Fill(padRow, padCol, c->GetQ());
387       } else {
388         Int_t bin = fRefHist[iDet]->FindBin(padRow, padCol);
389         refQ = fRefHist[iDet]->GetBinContent(bin);
390         //printf("bin = %d\n", bin);
391       }
392
393       ((TH1D*)fHist->At(124))->Fill(refQ);
394       //printf("ref Q = %lf\n", refQ);
395       
396       Double_t charge = c->GetQ() - (refQ / (490. * 30));
397       if (charge < 0) continue;
398
399       if (charge > 20) {
400         ((TH2D*)fHist->At(88+iSM))->Fill(c->GetY(), c->GetX());
401         ((TH2D*)fHist->At(106+iSM))->Fill(c->GetPadCol(), c->GetX());
402       }
403
404       nDet[iDet]++;
405       ((TH1D*)fHist->At(0))->Fill(iDet);
406       ((TH1D*)fHist->At(86))->Fill(charge);
407       ((TH1D*)fHist->At(1))->Fill(iDet, charge);
408       ((TH1D*)fHist->At(2))->Fill(c->GetNPads());
409       if (c->GetNPads() < 6)
410         ((TH1D*)fHist->At(1+c->GetNPads()))->Fill(c->GetCenter());
411       
412       //if (c->GetPadTime() < 5)
413       ((TH2D*)fHist->At(7))->Fill(padRow, c->GetPadCol());
414       ((TH1D*)fHist->At(8))->Fill(c->GetPadTime());
415
416       ((TH3D*)fHist->At(10))->Fill(iDet, c->GetPadTime(), charge);
417    
418       ((TH1D*)fHist->At(50+iSM))->Fill(c->GetPadTime());
419       ((TH1D*)fHist->At(68+iSM))->Fill(c->GetPadTime(), charge);
420
421       // PRF for 2pad
422       //if (c->GetNPads() == 2) {
423       Short_t *sig = c->GetSignals();
424       Double_t frac = -10;
425
426       if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0 && sig[5] == 0 && sig[6] == 0) 
427         frac = 1. * sig[4] / (sig[3] + sig[4]);
428
429       if (sig[0] == 0 && sig[1] == 0 && sig[4] == 0 && sig[5] == 0 && sig[6] == 0)
430         frac = -1. * sig[2] / (sig[2] + sig[3]);
431
432       if (frac > -10)  ((TProfile*)fHist->At(11))->Fill(c->GetCenter(), frac);
433         
434       //}
435     }
436   }
437
438   for(Int_t i=0; i<540; i++) 
439     if (nDet[i] > 0) ((TH1D*)fHist->At(9))->Fill(nDet[i]);
440
441   delete clusterArray;
442
443   /*
444   TFile *outFile = new TFile("outQA.root", "RECREATE");
445   outFile->mkdir("TRD");
446   gDirectory->cd("TRD");
447   gDirectory->mkdir("RecPoints");
448   gDirectory->cd("RecPoints");
449   fHist->Write();
450   outFile->Close();
451   */
452 }
453
454 //____________________________________________________________________________