1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Produces the data needed to calculate the quality assurance. //
21 // All data must be mergeable objects. //
22 // S.Radomski Uni-Heidelberg October 2007 //
24 ////////////////////////////////////////////////////////////////////////////
26 // --- ROOT system ---
27 #include <TClonesArray.h>
33 // --- AliRoot header files ---
34 #include "AliESDEvent.h"
36 #include "AliTRDdigit.h"
37 #include "AliTRDhit.h"
38 #include "AliTRDcluster.h"
39 #include "AliTRDQADataMaker.h"
40 #include "AliTRDdigitsManager.h"
41 #include "AliTRDgeometry.h"
42 #include "AliTRDdataArrayI.h"
43 #include "AliTRDRawStreamV2.h"
45 ClassImp(AliTRDQADataMaker)
47 //____________________________________________________________________________
48 AliTRDQADataMaker::AliTRDQADataMaker() :
49 AliQADataMaker(AliQA::GetDetName(AliQA::kTRD), "TRD Quality Assurance Data Maker")
54 //____________________________________________________________________________
55 AliTRDQADataMaker::AliTRDQADataMaker(const AliTRDQADataMaker& qadm) :
59 SetName((const char*)qadm.GetName()) ;
60 SetTitle((const char*)qadm.GetTitle());
63 //__________________________________________________________________
64 AliTRDQADataMaker& AliTRDQADataMaker::operator = (const AliTRDQADataMaker& qadm )
67 this->~AliTRDQADataMaker();
68 new(this) AliTRDQADataMaker(qadm);
72 //____________________________________________________________________________
73 void AliTRDQADataMaker::EndOfDetectorCycle()
75 //Detector specific actions at end of cycle
81 //____________________________________________________________________________
82 void AliTRDQADataMaker::InitESDs()
85 // create ESDs histograms in ESDs subdir
88 const Int_t nhist = 21;
90 Int_t histoCounter = -1 ;
92 hist[++histoCounter] = new TH1D("qaTRD_esd_ntracks", ":Number of tracks", 300, -0.5, 299.5);
93 hist[++histoCounter] = new TH1D("qaTRD_esd_sector", ":Sector", 18, -0.5, 17.7);
94 hist[++histoCounter] = new TH1D("qaTRD_esd_bits", ";Bits", 64, -0.5, 63.5);
96 const Int_t knbits = 6;
97 const char *suf[knbits] = {"TPCi", "TPCo", "TPCz", "TRDo", "TRDr", "TRDz"};
100 for(Int_t i=0; i<knbits; i++) {
101 hist[++histoCounter] = new TH1D(Form("qaTRD_esd_pt%s",suf[i]), ";p_{T} (GeV/c);", 50, 0, 10);
102 hist[++histoCounter] = new TH1D(Form("qaTRD_esd_trdz%s", suf[i]), ";z (cm)", 200, -400, 400);
106 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDo", "TRDo;number of clusters", 130, -0.5, 129.5);;
107 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDr", "TRDr;number of clusters", 130, -0.5, 129.5);;
108 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDz", "TRDz;number of clusters", 130, -0.5, 129.5);;
109 hist[++histoCounter] = new TH1D("qaTRD_esd_clsRatio", ";cluster ratio", 100, 0., 1.3);;
111 hist[++histoCounter] = new TH2D("qaTRD_esd_sigMom", ";momentum (GeV/c);signal", 100, 0, 5, 200, 0, 1e3);
113 for(Int_t i=0; i<=histoCounter; i++) {
115 Add2ESDsList(hist[i], i);
119 //____________________________________________________________________________
120 void AliTRDQADataMaker::InitHits()
122 // create Hits histograms in Hits subdir
123 const Int_t nhist = 4;
126 hist[0] = new TH1D("qaTRD_hits_det", ";Detector Id of the hit", 540, -0.5, 539.5) ;
128 hist[1] = new TH1D("qaTRD_hist_Qdrift", ";Charge from tracks", 100, 0, 100);
129 hist[2] = new TH1D("qaTRD_hist_Qamp", ";Charge from TRD photon", 100, 0, 100);
130 hist[3] = new TH1D("qaTRD_hist_Qphoton", ";Charge from TRD photon", 100, 0, 100);
132 for(Int_t i=0; i<nhist; i++) {
134 Add2HitsList(hist[i], i);
138 //____________________________________________________________________________
139 void AliTRDQADataMaker::InitDigits()
141 // create Digits histograms in Digits subdir
143 const Int_t nhist = 3;
146 hist[0] = new TH1D("qaTRD_digits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
147 hist[1] = new TH1D("qaTRD_digits_time", ";Time bin", 40, -0.5, 39.5);
148 hist[2] = new TH1D("qaTRD_digits_amp", ";Amplitude", 100, 0, 100.);
150 for(Int_t i=0; i<nhist; i++) {
152 Add2DigitsList(hist[i], i);
157 //____________________________________________________________________________
158 void AliTRDQADataMaker::InitRecPoints()
160 // create Reconstructed Points histograms in RecPoints subdir
161 const Int_t nhist = 12;
164 hist[0] = new TH1D("qaTRD_recPoints_det", ";Detector ID of the cluster", 540, -0.5, 539.5);
165 hist[1] = new TH2D("qaTRD_recPoints_amp", ";Amplitude", 540, -0.5, 539, 200, -0.5, 199.5);
166 hist[2] = new TH1D("qaTRD_recPoints_npad", ";Number of Pads", 12, -0.5, 11.5);
168 hist[3] = new TH1D("qaTRD_recPoints_dist2", ";residuals [2pad]", 100, -1, 1);
169 hist[4] = new TH1D("qaTRD_recPoints_dist3", ";residuals [3pad]", 100, -1, 1);
170 hist[5] = new TH1D("qaTRD_recPoints_dist4", ";residuals [4pad]", 100, -1, 1);
171 hist[6] = new TH1D("qaTRD_recPoints_dist5", ";residuals [5pad]", 100, -1, 1);
173 hist[7] = new TH2D("qaTRD_recPoints_rowCol", ";row;col", 16, -0.5, 15.5, 145, -0.5, 144.5);
174 hist[8] = new TH1D("qaTRD_recPoints_time", ";time bin", 35, -0.5, 34.5);
175 hist[9] = new TH1D("qaTRD_recPoints_nCls", ";number of clusters", 500, -0.5, 499.5);
177 hist[10] = new TProfile("qaTRD_recPoints_sigTime", ";time bin;signal", 35, -0.5, 34.5, 0, 200, "");
178 hist[11] = new TProfile("qaTRD_recPoints_prf", ";distance;center of gravity", 120, -0.6, 0.6, -1.2, 1.2, "");
180 hist[12] = new TH1D("qaTRD_recPoints_ampDist", ";amplitude MPV", 100, 0, 100);
183 for(Int_t i=0; i<nhist; i++) {
185 Add2RecPointsList(hist[i], i);
189 //____________________________________________________________________________
190 void AliTRDQADataMaker::InitRaws()
192 // create Raws histograms in Raws subdir
193 const Int_t kSM = 18;
194 const Int_t nhist = 6+kSM;
197 hist[0] = new TH1D("qaTRD_raws_det", ";detector", 540, -0.5, 539.5);
198 hist[1] = new TH1D("qaTRD_raws_sig", ";signal", 100, -0.5, 99.5);
199 hist[2] = new TH1D("qaTRD_raws_sigCentral", "; signal central bin", 100, -0.5, 99.5);
200 hist[3] = new TH1D("qaTRD_raws_sigTail", ";signal cluster", 100, -0.5, 99.5);
201 hist[4] = new TH1D("qaTRD_raws_tiemBin", ";time bin", 40, -0.5, 39.5);
202 hist[5] = new TH1D("qaTRD_rows_smId", ";supermodule", 18, -0.5, 17.5);
204 // one char per ADC chanell
205 const Int_t nADC = 30 * 8 * 16 * 22;
206 for(Int_t i=0; i<kSM; i++)
207 hist[6+i] = new TH1D(Form("qaTRD_raws_sm%d",i),"",nADC, -0.5, nADC-0.5);
209 for(Int_t i=0; i<nhist; i++) {
211 Add2RawsList(hist[i], i);
215 //____________________________________________________________________________
216 void AliTRDQADataMaker::InitSDigits()
218 // create SDigits histograms in SDigits subdir
220 const Int_t nhist = 3;
223 hist[0] = new TH1D("qaTRD_sdigits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
224 hist[1] = new TH1D("qaTRD_sdigits_time", ";Time bin", 40, -0.5, 39.5);
225 hist[2] = new TH1D("qaTRD_sdigits_amp", ";Amplitude", 100, 0, 1e7);
227 for(Int_t i=0; i<nhist; i++) {
229 Add2SDigitsList(hist[i], i);
233 //____________________________________________________________________________
234 void AliTRDQADataMaker::MakeESDs(AliESDEvent * esd)
236 // make QA data from ESDs
237 Int_t nTracks = esd->GetNumberOfTracks();
238 GetESDsData(0)->Fill(nTracks);
241 for(Int_t i=0; i<nTracks; i++) {
243 AliESDtrack *track = esd->GetTrack(i);
244 const AliExternalTrackParam *paramOut = track->GetOuterParam();
245 const AliExternalTrackParam *paramIn = track->GetInnerParam();
248 if (!paramIn) continue;
249 if (!paramOut) continue;
252 if (track->GetKinkIndex(0) > 0) continue;
254 Double_t extZ = GetExtZ(paramIn);
255 if (TMath::Abs(extZ) > 320) continue; // acceptance cut
257 // .. in the acceptance
258 Int_t sector = GetSector(paramOut->GetAlpha());
259 GetESDsData(1)->Fill(sector);
262 UInt_t status = track->GetStatus();
263 for(Int_t bit=0; bit<32; bit++)
264 if (u<<bit & status) GetESDsData(2)->Fill(bit);
266 const Int_t knbits = 6;
267 Int_t bit[6] = {0,0,0,0,0,0};
268 bit[0] = status & AliESDtrack::kTPCin;
269 bit[1] = status & AliESDtrack::kTPCout;
270 bit[2] = (status & AliESDtrack::kTPCout) && !(status & AliESDtrack::kTRDout);
271 bit[3] = status & AliESDtrack::kTRDout;
272 bit[4] = status & AliESDtrack::kTRDrefit;
273 bit[5] = (status & AliESDtrack::kTRDout) && !(status & AliESDtrack::kTRDrefit);
275 // transverse momentum
276 //const Double_t *val = paramOut->GetParameter(); // parameters at the Outer plane
277 Double_t pt = paramOut->Pt(); //1./TMath::Abs(val[4]);
279 for(Int_t b=0; b<knbits; b++) {
281 GetESDsData(2*b+3)->Fill(pt);
282 GetESDsData(2*b+4)->Fill(extZ);
287 for(Int_t b=0; b<3; b++)
288 if (bit[3+b]) GetESDsData(b+15)->Fill(track->GetTRDncls());
291 if (!bit[4]) continue;
293 //fQuality->Fill(track->GetTRDQuality());
294 //fBudget->Fill(track->GetTRDBudget());
295 //fSignal->Fill(track->GetTRDsignal());
297 GetESDsData(18)->Fill(track->GetP(), track->GetTRDsignal());
301 if (status & AliESDtrack::kTRDpid) {
303 for(Int_t l=0; l<6; l++) fTime->Fill(track->GetTRDTimBin(l));
305 // fill pid histograms
306 Double_t trdr0 = 0; //, tpcr0 = 0;
307 Int_t trdBestPid = 5; //, tpcBestPid = 5; // charged
308 const Double_t kminPidValue = 0.9;
311 //track->GetTPCpid(pp); // ESD inconsequence
313 for(Int_t pid=0; pid<5; pid++) {
315 trdr0 += track->GetTRDpid(pid);
318 fTrdPID[pid]->Fill(track->GetTRDpid(pid));
319 //fTpcPID[pid]->Fill(pp[pid]);
321 if (track->GetTRDpid(pid) > kminPidValue) trdBestPid = pid;
322 //if (pp[pid] > kminPidValue) tpcBestPid = pid;
325 fTrdPID[5]->Fill(trdr0); // check unitarity
326 fTrdSigMomPID[trdBestPid]->Fill(track->GetP(), track->GetTRDsignal());
328 //fTpcPID[5]->Fill(tpcr0); // check unitarity
329 //fTpcSigMomPID[tpcBestPid]->Fill(track->GetP(), track->GetTPCsignal());
339 //______________________________________________________________________________
340 Int_t AliTRDQADataMaker::GetSector(const Double_t alpha) const {
341 // Gets the sector number
343 Double_t size = TMath::DegToRad() * 20.; // shall use TRDgeo
344 Int_t sector = (Int_t)((alpha + TMath::Pi())/size);
348 //______________________________________________________________________________
349 Double_t AliTRDQADataMaker::GetExtZ(const AliExternalTrackParam *in) const {
351 // returns the Z position at the entry to TRD
352 // using parameters from the TPC in
355 const Double_t x0 = 300;
357 Double_t x = in->GetX();
358 const Double_t *par = in->GetParameter();
359 Double_t theta = par[3];
360 Double_t z = in->GetZ();
362 Double_t zz = z + (x0-x) * TMath::Tan(theta);
366 //____________________________________________________________________________
367 void AliTRDQADataMaker::MakeHits(TClonesArray * hits)
369 //make QA data from Hits
370 //printf("making QA for TRD hits from an array %d\n", hits->GetEntriesFast());
375 while ( (hit = dynamic_cast<AliTRDhit *>(next())) ) {
376 GetHitsData(0)->Fill(hit->GetDetector());
377 Double_t q = TMath::Abs(hit->GetCharge());
379 if (hit->FromDrift()) GetHitsData(1)->Fill(q);
380 if (hit->FromAmplification()) GetHitsData(2)->Fill(q);
381 if (hit->FromTRphoton()) GetHitsData(3)->Fill(q);
386 //____________________________________________________________________________
387 void AliTRDQADataMaker::MakeHits(TTree * hitTree)
389 //make QA data from Hits
390 //printf("making QA for TRD hits from a tree\n");
392 if (!CheckPointer(hitTree, "TRD hits tree")) return;
394 TBranch *branch = hitTree->GetBranch("TRD");
395 if (!CheckPointer(branch, "TRD hits branch")) return;
397 Int_t nhits = (Int_t)(hitTree->GetTotBytes()/sizeof(AliTRDhit));
398 TClonesArray *hits = new TClonesArray("AliTRDhit", nhits+1000);
399 TClonesArray *tmp = new TClonesArray("AliTRDhit", 1000);
400 branch->SetAddress(&tmp);
403 Int_t nEntries = (Int_t)branch->GetEntries();
404 for(Int_t i = 0; i < nEntries; i++) {
406 Int_t nHits = (Int_t)tmp->GetEntries();
407 for(Int_t j=0; j<nHits; j++) {
408 AliTRDhit *hit = (AliTRDhit*)tmp->At(j);
409 new((*hits)[index++]) AliTRDhit(*hit);
418 //____________________________________________________________________________
419 void AliTRDQADataMaker::MakeDigits(TClonesArray * digits)
421 // makes data from Digits
424 AliTRDdigit * digit ;
425 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
426 GetDigitsData(0)->Fill(digit->GetDetector());
427 GetDigitsData(1)->Fill(digit->GetTime());
428 GetDigitsData(2)->Fill(digit->GetAmp());
432 //____________________________________________________________________________
433 void AliTRDQADataMaker::MakeDigits(TTree * digits)
436 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
437 digitsManager->CreateArrays();
438 digitsManager->ReadDigits(digits);
440 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
442 AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i);
444 // This is to take care of switched off super modules
445 if (digitsIn->GetNtime() == 0) continue;
449 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
450 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
452 Int_t nRows = digitsIn->GetNrow();
453 Int_t nCols = digitsIn->GetNcol();
454 Int_t nTbins = digitsIn->GetNtime();
456 for(Int_t row = 0; row < nRows; row++)
457 for(Int_t col = 0; col < nCols; col++)
458 for(Int_t time = 0; time < nTbins; time++) {
460 Float_t signal = digitsIn->GetDataUnchecked(row,col,time);
461 GetDigitsData(0)->Fill(i);
462 GetDigitsData(1)->Fill(time);
463 GetDigitsData(2)->Fill(signal);
468 delete digitsManager;
471 //____________________________________________________________________________
472 void AliTRDQADataMaker::MakeSDigits(TClonesArray * sdigits)
474 // makes data from Digits
476 TIter next(sdigits) ;
477 AliTRDdigit * digit ;
478 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
479 GetDigitsData(0)->Fill(digit->GetDetector());
480 GetDigitsData(1)->Fill(digit->GetTime());
481 GetDigitsData(2)->Fill(digit->GetAmp());
485 //____________________________________________________________________________
486 void AliTRDQADataMaker::MakeSDigits(TTree * digits)
489 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
490 digitsManager->CreateArrays();
491 digitsManager->ReadDigits(digits);
493 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
495 AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i);
497 // This is to take care of switched off super modules
498 if (digitsIn->GetNtime() == 0) continue;
502 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
503 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
505 Int_t nRows = digitsIn->GetNrow();
506 Int_t nCols = digitsIn->GetNcol();
507 Int_t nTbins = digitsIn->GetNtime();
509 for(Int_t row = 0; row < nRows; row++)
510 for(Int_t col = 0; col < nCols; col++)
511 for(Int_t time = 0; time < nTbins; time++) {
513 Float_t signal = digitsIn->GetDataUnchecked(row,col,time);
514 if (signal <= 0) continue;
515 GetSDigitsData(0)->Fill(i);
516 GetSDigitsData(1)->Fill(time);
517 GetSDigitsData(2)->Fill(signal);
523 delete digitsManager;
526 //____________________________________________________________________________
527 void AliTRDQADataMaker::MakeRaws(AliRawReader* rawReader)
532 //const Int_t kSM = 18;
533 //const Int_t kROC = 30;
534 //const Int_t kLayer = 6;
535 //const Int_t kStack = 5;
536 const Int_t kROB = 8;
537 const Int_t kMCM = 16;
538 const Int_t kADC = 22;
540 AliTRDRawStreamV2 *raw = new AliTRDRawStreamV2(rawReader);
542 raw->SetRawVersion(3);
545 while (raw->Next()) {
547 GetRawsData(0)->Fill(raw->GetDet());
549 Int_t *sig = raw->GetSignals();
550 for(Int_t i=0; i<3; i++) GetRawsData(1)->Fill(sig[i]);
552 GetRawsData(2)->Fill(sig[1]);
553 GetRawsData(3)->Fill(sig[0]);
554 GetRawsData(3)->Fill(sig[2]);
556 GetRawsData(4)->Fill(raw->GetTimeBin());
558 // calculate the index;
559 Int_t sm = raw->GetSM();
560 Int_t roc = raw->GetROC();
561 Int_t rob = raw->GetROB();
562 Int_t mcm = raw->GetMCM();
563 Int_t adc = raw->GetADC();
565 Int_t index = roc * (kROB*kMCM*kADC) + rob * (kMCM*kADC) + mcm * kADC + adc;
566 GetRawsData(5)->Fill(sm);
567 //printf("SM = %d\n", sm);
568 GetRawsData(6+sm)->Fill(index);
572 //____________________________________________________________________________
573 void AliTRDQADataMaker::MakeRecPoints(TTree * clustersTree)
576 // makes data from RecPoints
579 Int_t nsize = Int_t(clustersTree->GetTotBytes() / (sizeof(AliTRDcluster)));
580 TObjArray *clusterArray = new TObjArray(nsize+1000);
582 TBranch *branch = clustersTree->GetBranch("TRDcluster");
584 AliError("Can't get the branch !");
587 branch->SetAddress(&clusterArray);
589 // Loop through all entries in the tree
590 Int_t nEntries = (Int_t) clustersTree->GetEntries();
592 AliTRDcluster *c = 0;
594 for (Int_t i=0; i<540; i++) nDet[i] = 0;
596 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
599 nbytes += clustersTree->GetEvent(iEntry);
601 // Get the number of points in the detector
602 Int_t nCluster = clusterArray->GetEntriesFast();
604 // Loop through all TRD digits
605 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
606 c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
608 Int_t iDet = c->GetDetector();
610 GetRecPointsData(0)->Fill(iDet);
611 GetRecPointsData(1)->Fill(iDet, c->GetQ());
612 GetRecPointsData(2)->Fill(c->GetNPads());
613 if (c->GetNPads() < 6)
614 GetRecPointsData(1+c->GetNPads())->Fill(c->GetCenter());
616 //if (c->GetPadTime() < 5)
617 ((TH2D*)GetRecPointsData(7))->Fill(c->GetPadRow(), c->GetPadCol());
618 GetRecPointsData(8)->Fill(c->GetPadTime());
620 ((TProfile*)GetRecPointsData(10))->Fill(c->GetPadTime(), c->GetQ());
623 //if (c->GetNPads() == 2) {
624 Short_t *sig = c->GetSignals();
627 if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0 && sig[5] == 0 && sig[6] == 0)
628 frac = 1. * sig[4] / (sig[3] + sig[4]);
631 if (sig[0] == 0 && sig[1] == 0 && sig[4] == 0 && sig[5] == 0 && sig[6] == 0)
632 frac = -1. * sig[2] / (sig[2] + sig[3]);
634 if (frac > -10) ((TProfile*)GetRecPointsData(11))->Fill(c->GetCenter(), frac);
640 for(Int_t i=0; i<540; i++)
641 if (nDet[i] > 0) GetRecPointsData(9)->Fill(nDet[i]);
647 //____________________________________________________________________________
648 void AliTRDQADataMaker::StartOfDetectorCycle()
650 //Detector specific actions at start of cycle
654 //__________________________________________________________________________
655 Int_t AliTRDQADataMaker::CheckPointer(TObject *obj, const char *name) {
657 if (!obj) AliWarning(Form("null pointer: %s", name));
660 //__________________________________________________________________________