Making online tracklets usable in offline reconstruction
[u/mrichter/AliRoot.git] / TRD / AliTRDQADataMaker.cxx
CommitLineData
ffb5de4c 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
01abcaa3 16/* $Id$ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
c8ab4518 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) //
01abcaa3 25// //
26////////////////////////////////////////////////////////////////////////////
ffb5de4c 27
28// --- ROOT system ---
29#include <TClonesArray.h>
30#include <TFile.h>
31#include <TH1D.h>
01abcaa3 32#include <TH2D.h>
4e13cdf5 33#include <TH3D.h>
01abcaa3 34#include <TProfile.h>
4e13cdf5 35#include <TF1.h>
36#include <TCanvas.h>
8f3f00a4 37#include <TStopwatch.h>
ffb5de4c 38
39// --- AliRoot header files ---
40#include "AliESDEvent.h"
41#include "AliLog.h"
42#include "AliTRDdigit.h"
43#include "AliTRDhit.h"
44#include "AliTRDcluster.h"
45#include "AliTRDQADataMaker.h"
01abcaa3 46#include "AliTRDdigitsManager.h"
47#include "AliTRDgeometry.h"
b65e5048 48#include "AliTRDarrayADC.h"
987ba9a3 49#include "AliTRDrawStream.h"
4e13cdf5 50#include "AliQAChecker.h"
ffb5de4c 51
52ClassImp(AliTRDQADataMaker)
4e13cdf5 53
ffb5de4c 54//____________________________________________________________________________
4e13cdf5 55 AliTRDQADataMaker::AliTRDQADataMaker() :
4e25ac79 56 AliQADataMaker(AliQAv1::GetDetName(AliQAv1::kTRD), "TRD Quality Assurance Data Maker")
ffb5de4c 57{
c8ab4518 58 //
59 // Default constructor
ffb5de4c 60}
61
62//____________________________________________________________________________
4e13cdf5 63AliTRDQADataMaker::AliTRDQADataMaker(const AliTRDQADataMaker& qadm) :
64 AliQADataMaker()
ffb5de4c 65{
c8ab4518 66 //
4e13cdf5 67 // Copy constructor
c8ab4518 68 //
4e13cdf5 69
ffb5de4c 70 SetName((const char*)qadm.GetName()) ;
71 SetTitle((const char*)qadm.GetTitle());
c8ab4518 72
ffb5de4c 73}
74
75//__________________________________________________________________
4e13cdf5 76AliTRDQADataMaker& AliTRDQADataMaker::operator=(const AliTRDQADataMaker& qadm)
ffb5de4c 77{
c8ab4518 78 //
ffb5de4c 79 // Equal operator.
c8ab4518 80 //
81
ffb5de4c 82 this->~AliTRDQADataMaker();
83 new(this) AliTRDQADataMaker(qadm);
84 return *this;
c8ab4518 85
ffb5de4c 86}
4e13cdf5 87
ffb5de4c 88//____________________________________________________________________________
4e25ac79 89void AliTRDQADataMaker::EndOfDetectorCycle(AliQAv1::TASKINDEX task, TObjArray * list)
ffb5de4c 90{
c8ab4518 91 //
92 // Detector specific actions at end of cycle
93 //
8f3f00a4 94 //TStopwatch watch;
95 //watch.Start();
4e13cdf5 96
5379c4a3 97 //AliDebug(AliQAv1::GetQADebugLevel(), Form("EndOfCycle", "Fitting RecPoints %d", task))
8f3f00a4 98 TH1D *hist = new TH1D("fitHist", "", 200, -0.5, 199.5);
b6186d2c 99
4e25ac79 100 if (task == AliQAv1::kRECPOINTS) {
4e13cdf5 101
102 //list->Print();
4e13cdf5 103
b6186d2c 104 // Rec points full chambers
8f3f00a4 105 for (Int_t i=0; i<540; i++) {
4e13cdf5 106
8f3f00a4 107 //TH1D *h = ((TH2D*)list->At(1))->ProjectionY(Form("qaTRD_recPoints_amp_%d",i), i+1, i+1);
108 hist->Reset();
109 for(Int_t b=1; b<hist->GetXaxis()->GetNbins()-1; b++) {
110 Double_t xvalue = hist->GetBinCenter(b);
111 Int_t bin = ((TH2D*)list->At(1))->FindBin(i,xvalue);
112 Double_t value = ((TH2D*)list->At(1))->GetBinContent(bin);
113 hist->SetBinContent(b, value);
b6186d2c 114 }
8f3f00a4 115
116 //printf("Sum = %d %f\n", i, hist->GetSum());
117 if (hist->GetSum() < 100) continue; // chamber not present
118
119 hist->Fit("landau", "q0", "goff", 10, 180);
120 TF1 *fit = hist->GetFunction("landau");
121 ((TH1D*)list->At(12))->Fill(fit->GetParameter(1));
122 ((TH1D*)list->At(13))->Fill(fit->GetParameter(2));
b6186d2c 123 }
8f3f00a4 124
125 // time-bin by time-bin
126 for (Int_t i=0; i<540; i++) {
b6186d2c 127
8f3f00a4 128 //TH1D *test = ((TH3D*)list->At(10))->ProjectionZ(Form("ampTime_%d",i), i+1, i+1, 0, 35);
129 //if (test->GetSum() < 100) continue;
130
5379c4a3 131 //AliDebug(AliQAv1::GetQADebugLevel(), Form("fitting det = %d", i));
8f3f00a4 132
133 for(Int_t j=0; j<35; j++) {
4e13cdf5 134
8f3f00a4 135 //TH1D *h = ((TH3D*)list->At(10))->ProjectionZ(Form("ampTime_%d",i), i+1, i+1, j+1, j+1);
136 hist->Reset();
137 for(Int_t b=1; b<hist->GetXaxis()->GetNbins()-1; b++) {
138 Double_t xvalue = hist->GetBinCenter(b);
139 Int_t bin = ((TH3D*)list->At(10))->FindBin(i,j,xvalue);
140 Double_t value = ((TH3D*)list->At(10))->GetBinContent(bin);
141 //printf("v = %f\n", value);
142 hist->SetBinContent(b, value);
b6186d2c 143 }
8f3f00a4 144
145 if (hist->GetSum() < 100) continue;
146 //printf("fitting %d %d %f\n", i, j, hist->GetSum());
147
148 hist->Fit("landau", "q0", "goff", 10, 180);
149 TF1 *fit = hist->GetFunction("landau");
150
151 Int_t sm = i/18;
152 Int_t det = i%18;
153 TH2D *h2 = (TH2D*)list->At(14+sm);
154 Int_t bin = h2->FindBin(det,j);
155 // printf("%d %d %d\n", det, j, bin);
156 h2->SetBinContent(bin, fit->GetParameter(1));
4e13cdf5 157 }
158 }
159 }
01abcaa3 160
8f3f00a4 161 delete hist;
162
4e13cdf5 163 // call the checker
4e25ac79 164 AliQAChecker::Instance()->Run(AliQAv1::kTRD, task, list) ;
4e13cdf5 165
8f3f00a4 166 //watch.Stop();
167 //watch.Print();
ffb5de4c 168}
169
170//____________________________________________________________________________
171void AliTRDQADataMaker::InitESDs()
172{
b78bfa3c 173 //
c8ab4518 174 // Create ESDs histograms in ESDs subdir
b78bfa3c 175 //
176
4e13cdf5 177 const Int_t kNhist = 19;
c8ab4518 178 TH1 *hist[kNhist];
4e13cdf5 179 Int_t histoCounter = -1 ;
b78bfa3c 180
181 hist[++histoCounter] = new TH1D("qaTRD_esd_ntracks", ":Number of tracks", 300, -0.5, 299.5);
182 hist[++histoCounter] = new TH1D("qaTRD_esd_sector", ":Sector", 18, -0.5, 17.7);
183 hist[++histoCounter] = new TH1D("qaTRD_esd_bits", ";Bits", 64, -0.5, 63.5);
01abcaa3 184
185 const Int_t knbits = 6;
186 const char *suf[knbits] = {"TPCi", "TPCo", "TPCz", "TRDo", "TRDr", "TRDz"};
b78bfa3c 187
01abcaa3 188 for(Int_t i=0; i<knbits; i++) {
b78bfa3c 189 hist[++histoCounter] = new TH1D(Form("qaTRD_esd_pt%s",suf[i]), ";p_{T} (GeV/c);", 50, 0, 10);
190 hist[++histoCounter] = new TH1D(Form("qaTRD_esd_trdz%s", suf[i]), ";z (cm)", 200, -400, 400);
01abcaa3 191 }
01abcaa3 192
b78bfa3c 193 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDo", "TRDo;number of clusters", 130, -0.5, 129.5);;
194 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDr", "TRDr;number of clusters", 130, -0.5, 129.5);;
195 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDz", "TRDz;number of clusters", 130, -0.5, 129.5);;
4e13cdf5 196 //hist[++histoCounter] = new TH1D("qaTRD_esd_clsRatio", ";cluster ratio", 100, 0., 1.3);;
b78bfa3c 197
198 hist[++histoCounter] = new TH2D("qaTRD_esd_sigMom", ";momentum (GeV/c);signal", 100, 0, 5, 200, 0, 1e3);
ffb5de4c 199
b78bfa3c 200 for(Int_t i=0; i<=histoCounter; i++) {
ffb5de4c 201 //hist[i]->Sumw2();
202 Add2ESDsList(hist[i], i);
203 }
c8ab4518 204
ffb5de4c 205}
206
207//____________________________________________________________________________
208void AliTRDQADataMaker::InitHits()
209{
c8ab4518 210 //
211 // Create Hits histograms in Hits subdir
212 //
213
214 const Int_t kNhist = 4;
215 TH1D *hist[kNhist];
4e13cdf5 216
ffb5de4c 217 hist[0] = new TH1D("qaTRD_hits_det", ";Detector Id of the hit", 540, -0.5, 539.5) ;
4e13cdf5 218
ffb5de4c 219 hist[1] = new TH1D("qaTRD_hist_Qdrift", ";Charge from tracks", 100, 0, 100);
220 hist[2] = new TH1D("qaTRD_hist_Qamp", ";Charge from TRD photon", 100, 0, 100);
221 hist[3] = new TH1D("qaTRD_hist_Qphoton", ";Charge from TRD photon", 100, 0, 100);
222
c8ab4518 223 for(Int_t i=0; i<kNhist; i++) {
ffb5de4c 224 //hist[i]->Sumw2();
225 Add2HitsList(hist[i], i);
226 }
c8ab4518 227
ffb5de4c 228}
229
230//____________________________________________________________________________
231void AliTRDQADataMaker::InitDigits()
232{
c8ab4518 233 //
234 // Create Digits histograms in Digits subdir
235 //
236
237 const Int_t kNhist = 3;
238 TH1D *hist[kNhist];
4e13cdf5 239
ffb5de4c 240 hist[0] = new TH1D("qaTRD_digits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
241 hist[1] = new TH1D("qaTRD_digits_time", ";Time bin", 40, -0.5, 39.5);
242 hist[2] = new TH1D("qaTRD_digits_amp", ";Amplitude", 100, 0, 100.);
243
c8ab4518 244 for(Int_t i=0; i<kNhist; i++) {
ffb5de4c 245 hist[i]->Sumw2();
246 Add2DigitsList(hist[i], i);
247 }
ffb5de4c 248}
249
250//____________________________________________________________________________
251void AliTRDQADataMaker::InitRecPoints()
252{
c8ab4518 253 //
254 // Create Reconstructed Points histograms in RecPoints subdir
255 //
256
4e13cdf5 257 const Int_t kNhist = 14 + 18;
c8ab4518 258 TH1 *hist[kNhist];
ffb5de4c 259
260 hist[0] = new TH1D("qaTRD_recPoints_det", ";Detector ID of the cluster", 540, -0.5, 539.5);
01abcaa3 261 hist[1] = new TH2D("qaTRD_recPoints_amp", ";Amplitude", 540, -0.5, 539, 200, -0.5, 199.5);
ffb5de4c 262 hist[2] = new TH1D("qaTRD_recPoints_npad", ";Number of Pads", 12, -0.5, 11.5);
4e13cdf5 263
ffb5de4c 264 hist[3] = new TH1D("qaTRD_recPoints_dist2", ";residuals [2pad]", 100, -1, 1);
265 hist[4] = new TH1D("qaTRD_recPoints_dist3", ";residuals [3pad]", 100, -1, 1);
266 hist[5] = new TH1D("qaTRD_recPoints_dist4", ";residuals [4pad]", 100, -1, 1);
267 hist[6] = new TH1D("qaTRD_recPoints_dist5", ";residuals [5pad]", 100, -1, 1);
268
01abcaa3 269 hist[7] = new TH2D("qaTRD_recPoints_rowCol", ";row;col", 16, -0.5, 15.5, 145, -0.5, 144.5);
270 hist[8] = new TH1D("qaTRD_recPoints_time", ";time bin", 35, -0.5, 34.5);
271 hist[9] = new TH1D("qaTRD_recPoints_nCls", ";number of clusters", 500, -0.5, 499.5);
272
4e13cdf5 273 hist[10] = new TH3D("qaTRD_recPoints_sigTime", ";chamber;time bin;signal",
8f3f00a4 274 540, -0.5, 539.5, 35, -0.5, 34.5, 200, 0.5, 199.5);
4e13cdf5 275 hist[11] = new TProfile("qaTRD_recPoints_prf", ";distance;center of gravity"
276 , 120, -0.6, 0.6, -1.2, 1.2, "");
01abcaa3 277
4e13cdf5 278 hist[12] = new TH1D("qaTRD_recPoints_ampMPV", ";amplitude MPV", 100, 0, 100);
279 hist[13] = new TH1D("qaTRD_recPoints_ampSigma", ";amplitude Sigma", 100, 0, 100);
01abcaa3 280
4e13cdf5 281 for(Int_t i=0; i<18; i++) {
282 hist[14+i] = new TH2D(Form("qaTRD_recPoints_sigTime_sm%d",i), Form("sm%d;det;time bin"),
283 30, -0.5, 29.5, 35, -0.5, 34.5);
284 hist[14+i]->SetMinimum(20);
285 hist[14+i]->SetMaximum(40);
286 }
01abcaa3 287
c8ab4518 288 for(Int_t i=0; i<kNhist; i++) {
ffb5de4c 289 //hist[i]->Sumw2();
290 Add2RecPointsList(hist[i], i);
291 }
c8ab4518 292
ffb5de4c 293}
294
295//____________________________________________________________________________
296void AliTRDQADataMaker::InitRaws()
297{
c8ab4518 298 //
4e13cdf5 299 // create Raws histograms in Raws subdir
c8ab4518 300 //
301
ffb5de4c 302 const Int_t kSM = 18;
4e13cdf5 303 //const Int_t kNCh = 540;
304 const Int_t kNhist = 4+kSM;
c8ab4518 305 TH1D *hist[kNhist];
4e13cdf5 306
307 // four histograms to be published
ffb5de4c 308 hist[0] = new TH1D("qaTRD_raws_det", ";detector", 540, -0.5, 539.5);
309 hist[1] = new TH1D("qaTRD_raws_sig", ";signal", 100, -0.5, 99.5);
4e13cdf5 310 hist[2] = new TH1D("qaTRD_raws_timeBin", ";time bin", 40, -0.5, 39.5);
311 hist[3] = new TH1D("qaTRD_raws_smId", ";supermodule", 18, -0.5, 17.5);
312 //
313
314 // one double per MCM (not published)
315 const Int_t kNMCM = 30 * 8 * 16;
ffb5de4c 316 for(Int_t i=0; i<kSM; i++)
4e13cdf5 317 hist[4+i] = new TH1D(Form("qaTRD_raws_sm%d",i),"",kNMCM, -0.5, kNMCM-0.5);
318
319 // register
c8ab4518 320 for(Int_t i=0; i<kNhist; i++) {
ffb5de4c 321 //hist[i]->Sumw2();
322 Add2RawsList(hist[i], i);
323 }
c8ab4518 324
ffb5de4c 325}
326
327//____________________________________________________________________________
328void AliTRDQADataMaker::InitSDigits()
329{
c8ab4518 330 //
331 // Create SDigits histograms in SDigits subdir
332 //
333
334 const Int_t kNhist = 3;
335 TH1D *hist[kNhist];
4e13cdf5 336
01abcaa3 337 hist[0] = new TH1D("qaTRD_sdigits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
338 hist[1] = new TH1D("qaTRD_sdigits_time", ";Time bin", 40, -0.5, 39.5);
339 hist[2] = new TH1D("qaTRD_sdigits_amp", ";Amplitude", 100, 0, 1e7);
ffb5de4c 340
c8ab4518 341 for(Int_t i=0; i<kNhist; i++) {
ffb5de4c 342 hist[i]->Sumw2();
343 Add2SDigitsList(hist[i], i);
344 }
c8ab4518 345
ffb5de4c 346}
347
348//____________________________________________________________________________
349void AliTRDQADataMaker::MakeESDs(AliESDEvent * esd)
350{
c8ab4518 351 //
352 // Make QA data from ESDs
353 //
354
01abcaa3 355 Int_t nTracks = esd->GetNumberOfTracks();
356 GetESDsData(0)->Fill(nTracks);
4e13cdf5 357
01abcaa3 358 // track loop
4e13cdf5 359 for (Int_t i=0; i<nTracks; i++) {
360
01abcaa3 361 AliESDtrack *track = esd->GetTrack(i);
362 const AliExternalTrackParam *paramOut = track->GetOuterParam();
363 const AliExternalTrackParam *paramIn = track->GetInnerParam();
364
365 // long track ..
366 if (!paramIn) continue;
367 if (!paramOut) continue;
368
369 // not a kink
370 if (track->GetKinkIndex(0) > 0) continue;
371
372 Double_t extZ = GetExtZ(paramIn);
373 if (TMath::Abs(extZ) > 320) continue; // acceptance cut
374
375 // .. in the acceptance
376 Int_t sector = GetSector(paramOut->GetAlpha());
01abcaa3 377
378 UInt_t u = 1;
379 UInt_t status = track->GetStatus();
380 for(Int_t bit=0; bit<32; bit++)
381 if (u<<bit & status) GetESDsData(2)->Fill(bit);
382
383 const Int_t knbits = 6;
384 Int_t bit[6] = {0,0,0,0,0,0};
385 bit[0] = status & AliESDtrack::kTPCin;
386 bit[1] = status & AliESDtrack::kTPCout;
387 bit[2] = (status & AliESDtrack::kTPCout) && !(status & AliESDtrack::kTRDout);
388 bit[3] = status & AliESDtrack::kTRDout;
389 bit[4] = status & AliESDtrack::kTRDrefit;
390 bit[5] = (status & AliESDtrack::kTRDout) && !(status & AliESDtrack::kTRDrefit);
391
392 // transverse momentum
393 //const Double_t *val = paramOut->GetParameter(); // parameters at the Outer plane
394 Double_t pt = paramOut->Pt(); //1./TMath::Abs(val[4]);
395
396 for(Int_t b=0; b<knbits; b++) {
397 if (bit[b]) {
6b6b748d 398 GetESDsData(2*b+3)->Fill(pt);
399 GetESDsData(2*b+4)->Fill(extZ);
01abcaa3 400 }
401 }
402
403 // clusters
404 for(Int_t b=0; b<3; b++)
405 if (bit[3+b]) GetESDsData(b+15)->Fill(track->GetTRDncls());
406
407 // refitted only
408 if (!bit[4]) continue;
409
410 //fQuality->Fill(track->GetTRDQuality());
411 //fBudget->Fill(track->GetTRDBudget());
412 //fSignal->Fill(track->GetTRDsignal());
413
414 GetESDsData(18)->Fill(track->GetP(), track->GetTRDsignal());
c29b11ff 415 GetESDsData(1)->Fill(sector);
01abcaa3 416
417 /*
418 // PID only
419 if (status & AliESDtrack::kTRDpid) {
4e13cdf5 420
01abcaa3 421 for(Int_t l=0; l<6; l++) fTime->Fill(track->GetTRDTimBin(l));
422
423 // fill pid histograms
424 Double_t trdr0 = 0; //, tpcr0 = 0;
425 Int_t trdBestPid = 5; //, tpcBestPid = 5; // charged
426 const Double_t kminPidValue = 0.9;
427
428 //Double_t pp[5];
429 //track->GetTPCpid(pp); // ESD inconsequence
430
431 for(Int_t pid=0; pid<5; pid++) {
432
433 trdr0 += track->GetTRDpid(pid);
434 //tpcr0 += pp[pid];
435
436 fTrdPID[pid]->Fill(track->GetTRDpid(pid));
437 //fTpcPID[pid]->Fill(pp[pid]);
438
439 if (track->GetTRDpid(pid) > kminPidValue) trdBestPid = pid;
440 //if (pp[pid] > kminPidValue) tpcBestPid = pid;
441 }
4e13cdf5 442
01abcaa3 443 fTrdPID[5]->Fill(trdr0); // check unitarity
444 fTrdSigMomPID[trdBestPid]->Fill(track->GetP(), track->GetTRDsignal());
4e13cdf5 445
01abcaa3 446 //fTpcPID[5]->Fill(tpcr0); // check unitarity
447 //fTpcSigMomPID[tpcBestPid]->Fill(track->GetP(), track->GetTPCsignal());
448 }
449 */
4e13cdf5 450
01abcaa3 451 }
452
01abcaa3 453}
454
455//______________________________________________________________________________
c8ab4518 456Int_t AliTRDQADataMaker::GetSector(const Double_t alpha) const
457{
458 //
01abcaa3 459 // Gets the sector number
c8ab4518 460 //
01abcaa3 461
462 Double_t size = TMath::DegToRad() * 20.; // shall use TRDgeo
463 Int_t sector = (Int_t)((alpha + TMath::Pi())/size);
464 return sector;
c8ab4518 465
01abcaa3 466}
467
468//______________________________________________________________________________
c8ab4518 469Double_t AliTRDQADataMaker::GetExtZ(const AliExternalTrackParam *in) const
470{
01abcaa3 471 //
c8ab4518 472 // Returns the Z position at the entry to TRD
01abcaa3 473 // using parameters from the TPC in
474 //
475
c8ab4518 476 const Double_t kX0 = 300;
01abcaa3 477
478 Double_t x = in->GetX();
479 const Double_t *par = in->GetParameter();
480 Double_t theta = par[3];
481 Double_t z = in->GetZ();
4e13cdf5 482
c8ab4518 483 Double_t zz = z + (kX0-x) * TMath::Tan(theta);
01abcaa3 484 return zz;
4e13cdf5 485
ffb5de4c 486}
487
488//____________________________________________________________________________
489void AliTRDQADataMaker::MakeHits(TClonesArray * hits)
490{
c8ab4518 491 //
492 // Make QA data from Hits
493 //
ffb5de4c 494
495 TIter next(hits);
496 AliTRDhit * hit;
4e13cdf5 497
ffb5de4c 498 while ( (hit = dynamic_cast<AliTRDhit *>(next())) ) {
499 GetHitsData(0)->Fill(hit->GetDetector());
500 Double_t q = TMath::Abs(hit->GetCharge());
4e13cdf5 501
ffb5de4c 502 if (hit->FromDrift()) GetHitsData(1)->Fill(q);
503 if (hit->FromAmplification()) GetHitsData(2)->Fill(q);
504 if (hit->FromTRphoton()) GetHitsData(3)->Fill(q);
505 }
506
507}
01abcaa3 508
ffb5de4c 509//____________________________________________________________________________
510void AliTRDQADataMaker::MakeHits(TTree * hitTree)
511{
c8ab4518 512 //
513 // Make QA data from Hits
514 //
4e13cdf5 515
ffb5de4c 516 if (!CheckPointer(hitTree, "TRD hits tree")) return;
4e13cdf5 517
ffb5de4c 518 TBranch *branch = hitTree->GetBranch("TRD");
519 if (!CheckPointer(branch, "TRD hits branch")) return;
4e13cdf5 520
ffb5de4c 521 Int_t nhits = (Int_t)(hitTree->GetTotBytes()/sizeof(AliTRDhit));
522 TClonesArray *hits = new TClonesArray("AliTRDhit", nhits+1000);
523 TClonesArray *tmp = new TClonesArray("AliTRDhit", 1000);
524 branch->SetAddress(&tmp);
4e13cdf5 525
ffb5de4c 526 Int_t index = 0;
527 Int_t nEntries = (Int_t)branch->GetEntries();
528 for(Int_t i = 0; i < nEntries; i++) {
529 branch->GetEntry(i);
530 Int_t nHits = (Int_t)tmp->GetEntries();
531 for(Int_t j=0; j<nHits; j++) {
532 AliTRDhit *hit = (AliTRDhit*)tmp->At(j);
533 new((*hits)[index++]) AliTRDhit(*hit);
534 }
535 }
536
537 tmp->Delete();
538 delete tmp;
539 MakeHits(hits);
c8ab4518 540
ffb5de4c 541}
01abcaa3 542
ffb5de4c 543//____________________________________________________________________________
544void AliTRDQADataMaker::MakeDigits(TClonesArray * digits)
545{
c8ab4518 546 //
4e13cdf5 547 // Makes data from Digits
c8ab4518 548 //
549
ffb5de4c 550 TIter next(digits) ;
551 AliTRDdigit * digit ;
552 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
553 GetDigitsData(0)->Fill(digit->GetDetector());
554 GetDigitsData(1)->Fill(digit->GetTime());
555 GetDigitsData(2)->Fill(digit->GetAmp());
c8ab4518 556 }
557
ffb5de4c 558}
559
560//____________________________________________________________________________
01abcaa3 561void AliTRDQADataMaker::MakeDigits(TTree * digits)
562{
c8ab4518 563 //
564 // Makes data from digits tree
565 //
01abcaa3 566
567 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
568 digitsManager->CreateArrays();
569 digitsManager->ReadDigits(digits);
570
571 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
4e13cdf5 572
b65e5048 573 AliTRDarrayADC *digitsIn = (AliTRDarrayADC *) digitsManager->GetDigits(i);
4e13cdf5 574
01abcaa3 575 // This is to take care of switched off super modules
576 if (digitsIn->GetNtime() == 0) continue;
4e13cdf5 577
b65e5048 578 digitsIn->Expand();
4e13cdf5 579
01abcaa3 580 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
581 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
4e13cdf5 582
01abcaa3 583 Int_t nRows = digitsIn->GetNrow();
584 Int_t nCols = digitsIn->GetNcol();
585 Int_t nTbins = digitsIn->GetNtime();
586
587 for(Int_t row = 0; row < nRows; row++)
588 for(Int_t col = 0; col < nCols; col++)
b65e5048 589 for(Int_t time = 0; time < nTbins; time++)
590 {
591 Float_t signal = digitsIn->GetData(row,col,time);
592 GetDigitsData(0)->Fill(i);
593 GetDigitsData(1)->Fill(time);
594 GetDigitsData(2)->Fill(signal);
595 }
4e13cdf5 596
01abcaa3 597 //delete digitsIn;
598 }
c8ab4518 599
01abcaa3 600 delete digitsManager;
c8ab4518 601
01abcaa3 602}
603
604//____________________________________________________________________________
ffb5de4c 605void AliTRDQADataMaker::MakeSDigits(TClonesArray * sdigits)
606{
c8ab4518 607 //
4e13cdf5 608 // Makes data from Digits
c8ab4518 609 //
610
ffb5de4c 611 TIter next(sdigits) ;
612 AliTRDdigit * digit ;
613 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
614 GetDigitsData(0)->Fill(digit->GetDetector());
01abcaa3 615 GetDigitsData(1)->Fill(digit->GetTime());
616 GetDigitsData(2)->Fill(digit->GetAmp());
4e13cdf5 617 }
618
ffb5de4c 619}
620
621//____________________________________________________________________________
01abcaa3 622void AliTRDQADataMaker::MakeSDigits(TTree * digits)
623{
c8ab4518 624 //
4e13cdf5 625 // Makes data from SDigits
c8ab4518 626 //
01abcaa3 627
628 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
629 digitsManager->CreateArrays();
630 digitsManager->ReadDigits(digits);
631
b65e5048 632 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++)
633 {
634 AliTRDarrayADC *digitsIn = (AliTRDarrayADC *) digitsManager->GetDigits(i);
4e13cdf5 635
01abcaa3 636 // This is to take care of switched off super modules
637 if (digitsIn->GetNtime() == 0) continue;
4e13cdf5 638
b65e5048 639 digitsIn->Expand();
4e13cdf5 640
01abcaa3 641 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
642 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
4e13cdf5 643
01abcaa3 644 Int_t nRows = digitsIn->GetNrow();
645 Int_t nCols = digitsIn->GetNcol();
646 Int_t nTbins = digitsIn->GetNtime();
647
648 for(Int_t row = 0; row < nRows; row++)
649 for(Int_t col = 0; col < nCols; col++)
b65e5048 650 for(Int_t time = 0; time < nTbins; time++)
651 {
652 Float_t signal = digitsIn->GetData(row,col,time);
653 if (signal <= 0) continue;
654 GetSDigitsData(0)->Fill(i);
655 GetSDigitsData(1)->Fill(time);
656 GetSDigitsData(2)->Fill(signal);
657 }
658
01abcaa3 659 // delete digitsIn;
660 }
661
662 delete digitsManager;
c8ab4518 663
01abcaa3 664}
665
666//____________________________________________________________________________
ffb5de4c 667void AliTRDQADataMaker::MakeRaws(AliRawReader* rawReader)
668{
c8ab4518 669 //
4e13cdf5 670 // Makes QA data from raw data
671 //
672
ffb5de4c 673 // 157
674 // T9 -- T10
675
4e13cdf5 676 //const Int_t kSM = 18;
ffb5de4c 677 //const Int_t kROC = 30;
4e13cdf5 678 const Int_t kROB = 8;
ffb5de4c 679 //const Int_t kLayer = 6;
680 //const Int_t kStack = 5;
681 const Int_t kMCM = 16;
4e13cdf5 682 // const Int_t kADC = 22;
683
f3667dfd 684 AliTRDrawStream *raw = new AliTRDrawStream(rawReader);
8f3f00a4 685 raw->SetRawVersion(3);
882c8934 686 raw->Init();
4e13cdf5 687
ffb5de4c 688 while (raw->Next()) {
4e13cdf5 689
ffb5de4c 690 GetRawsData(0)->Fill(raw->GetDet());
4e13cdf5 691
692 // possibly needs changes with the new reader !!
ffb5de4c 693 Int_t *sig = raw->GetSignals();
694 for(Int_t i=0; i<3; i++) GetRawsData(1)->Fill(sig[i]);
4e13cdf5 695 // ---
696
697 GetRawsData(2)->Fill(raw->GetTimeBin());
698
ffb5de4c 699 // calculate the index;
700 Int_t sm = raw->GetSM();
701 Int_t roc = raw->GetROC();
702 Int_t rob = raw->GetROB();
703 Int_t mcm = raw->GetMCM();
4e13cdf5 704 //Int_t adc = raw->GetADC();
705
706 //Int_t index = roc * (kROB*kMCM*kADC) + rob * (kMCM*kADC) + mcm * kADC + adc;
707 Int_t index = roc * (kROB*kMCM) + rob * kMCM + mcm;
708 GetRawsData(3)->Fill(sm);
709 GetRawsData(4+sm)->Fill(index);
ffb5de4c 710 }
ad1b4ece 711
712 delete raw;
713
ffb5de4c 714}
715
716//____________________________________________________________________________
717void AliTRDQADataMaker::MakeRecPoints(TTree * clustersTree)
718{
c8ab4518 719 //
720 // Makes data from RecPoints
ffb5de4c 721 //
4e13cdf5 722
ffb5de4c 723 Int_t nsize = Int_t(clustersTree->GetTotBytes() / (sizeof(AliTRDcluster)));
724 TObjArray *clusterArray = new TObjArray(nsize+1000);
4e13cdf5 725
ffb5de4c 726 TBranch *branch = clustersTree->GetBranch("TRDcluster");
727 if (!branch) {
728 AliError("Can't get the branch !");
729 return;
730 }
731 branch->SetAddress(&clusterArray);
4e13cdf5 732
ffb5de4c 733 // Loop through all entries in the tree
734 Int_t nEntries = (Int_t) clustersTree->GetEntries();
735 Int_t nbytes = 0;
736 AliTRDcluster *c = 0;
01abcaa3 737 Int_t nDet[540];
738 for (Int_t i=0; i<540; i++) nDet[i] = 0;
4e13cdf5 739
ffb5de4c 740 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
4e13cdf5 741
ffb5de4c 742 // Import the tree
743 nbytes += clustersTree->GetEvent(iEntry);
4e13cdf5 744
ffb5de4c 745 // Get the number of points in the detector
746 Int_t nCluster = clusterArray->GetEntriesFast();
4e13cdf5 747
ffb5de4c 748 // Loop through all TRD digits
749 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
750 c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
4e13cdf5 751
01abcaa3 752 Int_t iDet = c->GetDetector();
753 nDet[iDet]++;
754 GetRecPointsData(0)->Fill(iDet);
755 GetRecPointsData(1)->Fill(iDet, c->GetQ());
ffb5de4c 756 GetRecPointsData(2)->Fill(c->GetNPads());
757 if (c->GetNPads() < 6)
758 GetRecPointsData(1+c->GetNPads())->Fill(c->GetCenter());
01abcaa3 759
760 //if (c->GetPadTime() < 5)
761 ((TH2D*)GetRecPointsData(7))->Fill(c->GetPadRow(), c->GetPadCol());
762 GetRecPointsData(8)->Fill(c->GetPadTime());
4e13cdf5 763
764 ((TH3D*)GetRecPointsData(10))->Fill(iDet, c->GetPadTime(), c->GetQ());
765
01abcaa3 766 // PRF for 2pad
767 //if (c->GetNPads() == 2) {
768 Short_t *sig = c->GetSignals();
769 Double_t frac = -10;
4e13cdf5 770
01abcaa3 771 if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0 && sig[5] == 0 && sig[6] == 0)
772 frac = 1. * sig[4] / (sig[3] + sig[4]);
4e13cdf5 773
01abcaa3 774 if (sig[0] == 0 && sig[1] == 0 && sig[4] == 0 && sig[5] == 0 && sig[6] == 0)
775 frac = -1. * sig[2] / (sig[2] + sig[3]);
4e13cdf5 776
01abcaa3 777 if (frac > -10) ((TProfile*)GetRecPointsData(11))->Fill(c->GetCenter(), frac);
778
779 //}
ffb5de4c 780 }
781 }
4e13cdf5 782
01abcaa3 783 for(Int_t i=0; i<540; i++)
784 if (nDet[i] > 0) GetRecPointsData(9)->Fill(nDet[i]);
785
ffb5de4c 786 delete clusterArray;
c8ab4518 787
ffb5de4c 788}
789
790//____________________________________________________________________________
791void AliTRDQADataMaker::StartOfDetectorCycle()
792{
c8ab4518 793 //
794 // Detector specific actions at start of cycle
795 //
ffb5de4c 796
797}
01abcaa3 798
ffb5de4c 799//__________________________________________________________________________
c8ab4518 800Int_t AliTRDQADataMaker::CheckPointer(TObject *obj, const char *name)
801{
802 //
803 // Checks initialization of pointers
804 //
ffb5de4c 805
806 if (!obj) AliWarning(Form("null pointer: %s", name));
807 return !!obj;
c8ab4518 808
ffb5de4c 809}