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. //
24 // Sylwester Radomski (radomski@physi.uni-heidelberg.de) //
26 ////////////////////////////////////////////////////////////////////////////
28 // --- ROOT system ---
29 #include <TClonesArray.h>
35 // --- AliRoot header files ---
36 #include "AliESDEvent.h"
38 #include "AliTRDdigit.h"
39 #include "AliTRDhit.h"
40 #include "AliTRDcluster.h"
41 #include "AliTRDQADataMaker.h"
42 #include "AliTRDdigitsManager.h"
43 #include "AliTRDgeometry.h"
44 #include "AliTRDdataArrayI.h"
45 #include "AliTRDRawStreamV2.h"
47 ClassImp(AliTRDQADataMaker)
49 //____________________________________________________________________________
50 AliTRDQADataMaker::AliTRDQADataMaker()
51 :AliQADataMaker(AliQA::GetDetName(AliQA::kTRD), "TRD Quality Assurance Data Maker")
54 // Default constructor
59 //____________________________________________________________________________
60 AliTRDQADataMaker::AliTRDQADataMaker(const AliTRDQADataMaker& qadm)
67 SetName((const char*)qadm.GetName()) ;
68 SetTitle((const char*)qadm.GetTitle());
72 //__________________________________________________________________
73 AliTRDQADataMaker& AliTRDQADataMaker::operator = (const AliTRDQADataMaker& qadm )
79 this->~AliTRDQADataMaker();
80 new(this) AliTRDQADataMaker(qadm);
85 //____________________________________________________________________________
86 void AliTRDQADataMaker::EndOfDetectorCycle()
89 // Detector specific actions at end of cycle
94 //____________________________________________________________________________
95 void AliTRDQADataMaker::InitESDs()
98 // Create ESDs histograms in ESDs subdir
101 const Int_t kNhist = 21;
103 Int_t histoCounter = -1 ;
105 hist[++histoCounter] = new TH1D("qaTRD_esd_ntracks", ":Number of tracks", 300, -0.5, 299.5);
106 hist[++histoCounter] = new TH1D("qaTRD_esd_sector", ":Sector", 18, -0.5, 17.7);
107 hist[++histoCounter] = new TH1D("qaTRD_esd_bits", ";Bits", 64, -0.5, 63.5);
109 const Int_t knbits = 6;
110 const char *suf[knbits] = {"TPCi", "TPCo", "TPCz", "TRDo", "TRDr", "TRDz"};
113 for(Int_t i=0; i<knbits; i++) {
114 hist[++histoCounter] = new TH1D(Form("qaTRD_esd_pt%s",suf[i]), ";p_{T} (GeV/c);", 50, 0, 10);
115 hist[++histoCounter] = new TH1D(Form("qaTRD_esd_trdz%s", suf[i]), ";z (cm)", 200, -400, 400);
119 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDo", "TRDo;number of clusters", 130, -0.5, 129.5);;
120 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDr", "TRDr;number of clusters", 130, -0.5, 129.5);;
121 hist[++histoCounter] = new TH1D("qaTRD_esd_clsTRDz", "TRDz;number of clusters", 130, -0.5, 129.5);;
122 hist[++histoCounter] = new TH1D("qaTRD_esd_clsRatio", ";cluster ratio", 100, 0., 1.3);;
124 hist[++histoCounter] = new TH2D("qaTRD_esd_sigMom", ";momentum (GeV/c);signal", 100, 0, 5, 200, 0, 1e3);
126 for(Int_t i=0; i<=histoCounter; i++) {
128 Add2ESDsList(hist[i], i);
133 //____________________________________________________________________________
134 void AliTRDQADataMaker::InitHits()
137 // Create Hits histograms in Hits subdir
140 const Int_t kNhist = 4;
143 hist[0] = new TH1D("qaTRD_hits_det", ";Detector Id of the hit", 540, -0.5, 539.5) ;
145 hist[1] = new TH1D("qaTRD_hist_Qdrift", ";Charge from tracks", 100, 0, 100);
146 hist[2] = new TH1D("qaTRD_hist_Qamp", ";Charge from TRD photon", 100, 0, 100);
147 hist[3] = new TH1D("qaTRD_hist_Qphoton", ";Charge from TRD photon", 100, 0, 100);
149 for(Int_t i=0; i<kNhist; i++) {
151 Add2HitsList(hist[i], i);
156 //____________________________________________________________________________
157 void AliTRDQADataMaker::InitDigits()
160 // Create Digits histograms in Digits subdir
163 const Int_t kNhist = 3;
166 hist[0] = new TH1D("qaTRD_digits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
167 hist[1] = new TH1D("qaTRD_digits_time", ";Time bin", 40, -0.5, 39.5);
168 hist[2] = new TH1D("qaTRD_digits_amp", ";Amplitude", 100, 0, 100.);
170 for(Int_t i=0; i<kNhist; i++) {
172 Add2DigitsList(hist[i], i);
177 //____________________________________________________________________________
178 void AliTRDQADataMaker::InitRecPoints()
181 // Create Reconstructed Points histograms in RecPoints subdir
184 const Int_t kNhist = 12;
187 hist[0] = new TH1D("qaTRD_recPoints_det", ";Detector ID of the cluster", 540, -0.5, 539.5);
188 hist[1] = new TH2D("qaTRD_recPoints_amp", ";Amplitude", 540, -0.5, 539, 200, -0.5, 199.5);
189 hist[2] = new TH1D("qaTRD_recPoints_npad", ";Number of Pads", 12, -0.5, 11.5);
191 hist[3] = new TH1D("qaTRD_recPoints_dist2", ";residuals [2pad]", 100, -1, 1);
192 hist[4] = new TH1D("qaTRD_recPoints_dist3", ";residuals [3pad]", 100, -1, 1);
193 hist[5] = new TH1D("qaTRD_recPoints_dist4", ";residuals [4pad]", 100, -1, 1);
194 hist[6] = new TH1D("qaTRD_recPoints_dist5", ";residuals [5pad]", 100, -1, 1);
196 hist[7] = new TH2D("qaTRD_recPoints_rowCol", ";row;col", 16, -0.5, 15.5, 145, -0.5, 144.5);
197 hist[8] = new TH1D("qaTRD_recPoints_time", ";time bin", 35, -0.5, 34.5);
198 hist[9] = new TH1D("qaTRD_recPoints_nCls", ";number of clusters", 500, -0.5, 499.5);
200 hist[10] = new TProfile("qaTRD_recPoints_sigTime", ";time bin;signal", 35, -0.5, 34.5, 0, 200, "");
201 hist[11] = new TProfile("qaTRD_recPoints_prf", ";distance;center of gravity", 120, -0.6, 0.6, -1.2, 1.2, "");
203 hist[12] = new TH1D("qaTRD_recPoints_ampDist", ";amplitude MPV", 100, 0, 100);
206 for(Int_t i=0; i<kNhist; i++) {
208 Add2RecPointsList(hist[i], i);
213 //____________________________________________________________________________
214 void AliTRDQADataMaker::InitRaws()
217 // Create Raws histograms in Raws subdir
220 const Int_t kSM = 18;
221 const Int_t kNhist = 6+kSM;
224 hist[0] = new TH1D("qaTRD_raws_det", ";detector", 540, -0.5, 539.5);
225 hist[1] = new TH1D("qaTRD_raws_sig", ";signal", 100, -0.5, 99.5);
226 hist[2] = new TH1D("qaTRD_raws_sigCentral", "; signal central bin", 100, -0.5, 99.5);
227 hist[3] = new TH1D("qaTRD_raws_sigTail", ";signal cluster", 100, -0.5, 99.5);
228 hist[4] = new TH1D("qaTRD_raws_tiemBin", ";time bin", 40, -0.5, 39.5);
229 hist[5] = new TH1D("qaTRD_rows_smId", ";supermodule", 18, -0.5, 17.5);
231 // one char per ADC chanell
232 const Int_t kNADC = 30 * 8 * 16 * 22;
233 for(Int_t i=0; i<kSM; i++)
234 hist[6+i] = new TH1D(Form("qaTRD_raws_sm%d",i),"",kNADC, -0.5, kNADC-0.5);
236 for(Int_t i=0; i<kNhist; i++) {
238 Add2RawsList(hist[i], i);
243 //____________________________________________________________________________
244 void AliTRDQADataMaker::InitSDigits()
247 // Create SDigits histograms in SDigits subdir
250 const Int_t kNhist = 3;
253 hist[0] = new TH1D("qaTRD_sdigits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
254 hist[1] = new TH1D("qaTRD_sdigits_time", ";Time bin", 40, -0.5, 39.5);
255 hist[2] = new TH1D("qaTRD_sdigits_amp", ";Amplitude", 100, 0, 1e7);
257 for(Int_t i=0; i<kNhist; i++) {
259 Add2SDigitsList(hist[i], i);
264 //____________________________________________________________________________
265 void AliTRDQADataMaker::MakeESDs(AliESDEvent * esd)
268 // Make QA data from ESDs
271 Int_t nTracks = esd->GetNumberOfTracks();
272 GetESDsData(0)->Fill(nTracks);
275 for(Int_t i=0; i<nTracks; i++) {
277 AliESDtrack *track = esd->GetTrack(i);
278 const AliExternalTrackParam *paramOut = track->GetOuterParam();
279 const AliExternalTrackParam *paramIn = track->GetInnerParam();
282 if (!paramIn) continue;
283 if (!paramOut) continue;
286 if (track->GetKinkIndex(0) > 0) continue;
288 Double_t extZ = GetExtZ(paramIn);
289 if (TMath::Abs(extZ) > 320) continue; // acceptance cut
291 // .. in the acceptance
292 Int_t sector = GetSector(paramOut->GetAlpha());
293 GetESDsData(1)->Fill(sector);
296 UInt_t status = track->GetStatus();
297 for(Int_t bit=0; bit<32; bit++)
298 if (u<<bit & status) GetESDsData(2)->Fill(bit);
300 const Int_t knbits = 6;
301 Int_t bit[6] = {0,0,0,0,0,0};
302 bit[0] = status & AliESDtrack::kTPCin;
303 bit[1] = status & AliESDtrack::kTPCout;
304 bit[2] = (status & AliESDtrack::kTPCout) && !(status & AliESDtrack::kTRDout);
305 bit[3] = status & AliESDtrack::kTRDout;
306 bit[4] = status & AliESDtrack::kTRDrefit;
307 bit[5] = (status & AliESDtrack::kTRDout) && !(status & AliESDtrack::kTRDrefit);
309 // transverse momentum
310 //const Double_t *val = paramOut->GetParameter(); // parameters at the Outer plane
311 Double_t pt = paramOut->Pt(); //1./TMath::Abs(val[4]);
313 for(Int_t b=0; b<knbits; b++) {
315 GetESDsData(2*b+3)->Fill(pt);
316 GetESDsData(2*b+4)->Fill(extZ);
321 for(Int_t b=0; b<3; b++)
322 if (bit[3+b]) GetESDsData(b+15)->Fill(track->GetTRDncls());
325 if (!bit[4]) continue;
327 //fQuality->Fill(track->GetTRDQuality());
328 //fBudget->Fill(track->GetTRDBudget());
329 //fSignal->Fill(track->GetTRDsignal());
331 GetESDsData(18)->Fill(track->GetP(), track->GetTRDsignal());
335 if (status & AliESDtrack::kTRDpid) {
337 for(Int_t l=0; l<6; l++) fTime->Fill(track->GetTRDTimBin(l));
339 // fill pid histograms
340 Double_t trdr0 = 0; //, tpcr0 = 0;
341 Int_t trdBestPid = 5; //, tpcBestPid = 5; // charged
342 const Double_t kminPidValue = 0.9;
345 //track->GetTPCpid(pp); // ESD inconsequence
347 for(Int_t pid=0; pid<5; pid++) {
349 trdr0 += track->GetTRDpid(pid);
352 fTrdPID[pid]->Fill(track->GetTRDpid(pid));
353 //fTpcPID[pid]->Fill(pp[pid]);
355 if (track->GetTRDpid(pid) > kminPidValue) trdBestPid = pid;
356 //if (pp[pid] > kminPidValue) tpcBestPid = pid;
359 fTrdPID[5]->Fill(trdr0); // check unitarity
360 fTrdSigMomPID[trdBestPid]->Fill(track->GetP(), track->GetTRDsignal());
362 //fTpcPID[5]->Fill(tpcr0); // check unitarity
363 //fTpcSigMomPID[tpcBestPid]->Fill(track->GetP(), track->GetTPCsignal());
371 //______________________________________________________________________________
372 Int_t AliTRDQADataMaker::GetSector(const Double_t alpha) const
375 // Gets the sector number
378 Double_t size = TMath::DegToRad() * 20.; // shall use TRDgeo
379 Int_t sector = (Int_t)((alpha + TMath::Pi())/size);
384 //______________________________________________________________________________
385 Double_t AliTRDQADataMaker::GetExtZ(const AliExternalTrackParam *in) const
388 // Returns the Z position at the entry to TRD
389 // using parameters from the TPC in
392 const Double_t kX0 = 300;
394 Double_t x = in->GetX();
395 const Double_t *par = in->GetParameter();
396 Double_t theta = par[3];
397 Double_t z = in->GetZ();
399 Double_t zz = z + (kX0-x) * TMath::Tan(theta);
403 //____________________________________________________________________________
404 void AliTRDQADataMaker::MakeHits(TClonesArray * hits)
407 // Make QA data from Hits
413 while ( (hit = dynamic_cast<AliTRDhit *>(next())) ) {
414 GetHitsData(0)->Fill(hit->GetDetector());
415 Double_t q = TMath::Abs(hit->GetCharge());
417 if (hit->FromDrift()) GetHitsData(1)->Fill(q);
418 if (hit->FromAmplification()) GetHitsData(2)->Fill(q);
419 if (hit->FromTRphoton()) GetHitsData(3)->Fill(q);
424 //____________________________________________________________________________
425 void AliTRDQADataMaker::MakeHits(TTree * hitTree)
428 // Make QA data from Hits
431 if (!CheckPointer(hitTree, "TRD hits tree")) return;
433 TBranch *branch = hitTree->GetBranch("TRD");
434 if (!CheckPointer(branch, "TRD hits branch")) return;
436 Int_t nhits = (Int_t)(hitTree->GetTotBytes()/sizeof(AliTRDhit));
437 TClonesArray *hits = new TClonesArray("AliTRDhit", nhits+1000);
438 TClonesArray *tmp = new TClonesArray("AliTRDhit", 1000);
439 branch->SetAddress(&tmp);
442 Int_t nEntries = (Int_t)branch->GetEntries();
443 for(Int_t i = 0; i < nEntries; i++) {
445 Int_t nHits = (Int_t)tmp->GetEntries();
446 for(Int_t j=0; j<nHits; j++) {
447 AliTRDhit *hit = (AliTRDhit*)tmp->At(j);
448 new((*hits)[index++]) AliTRDhit(*hit);
458 //____________________________________________________________________________
459 void AliTRDQADataMaker::MakeDigits(TClonesArray * digits)
462 // Makes data from digits
466 AliTRDdigit * digit ;
467 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
468 GetDigitsData(0)->Fill(digit->GetDetector());
469 GetDigitsData(1)->Fill(digit->GetTime());
470 GetDigitsData(2)->Fill(digit->GetAmp());
475 //____________________________________________________________________________
476 void AliTRDQADataMaker::MakeDigits(TTree * digits)
479 // Makes data from digits tree
482 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
483 digitsManager->CreateArrays();
484 digitsManager->ReadDigits(digits);
486 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
488 AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i);
490 // This is to take care of switched off super modules
491 if (digitsIn->GetNtime() == 0) continue;
495 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
496 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
498 Int_t nRows = digitsIn->GetNrow();
499 Int_t nCols = digitsIn->GetNcol();
500 Int_t nTbins = digitsIn->GetNtime();
502 for(Int_t row = 0; row < nRows; row++)
503 for(Int_t col = 0; col < nCols; col++)
504 for(Int_t time = 0; time < nTbins; time++) {
506 Float_t signal = digitsIn->GetDataUnchecked(row,col,time);
507 GetDigitsData(0)->Fill(i);
508 GetDigitsData(1)->Fill(time);
509 GetDigitsData(2)->Fill(signal);
515 delete digitsManager;
519 //____________________________________________________________________________
520 void AliTRDQADataMaker::MakeSDigits(TClonesArray * sdigits)
523 // Makes data from digits
526 TIter next(sdigits) ;
527 AliTRDdigit * digit ;
528 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
529 GetDigitsData(0)->Fill(digit->GetDetector());
530 GetDigitsData(1)->Fill(digit->GetTime());
531 GetDigitsData(2)->Fill(digit->GetAmp());
536 //____________________________________________________________________________
537 void AliTRDQADataMaker::MakeSDigits(TTree * digits)
540 // Makes data from digits tree
543 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
544 digitsManager->CreateArrays();
545 digitsManager->ReadDigits(digits);
547 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
549 AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i);
551 // This is to take care of switched off super modules
552 if (digitsIn->GetNtime() == 0) continue;
556 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
557 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
559 Int_t nRows = digitsIn->GetNrow();
560 Int_t nCols = digitsIn->GetNcol();
561 Int_t nTbins = digitsIn->GetNtime();
563 for(Int_t row = 0; row < nRows; row++)
564 for(Int_t col = 0; col < nCols; col++)
565 for(Int_t time = 0; time < nTbins; time++) {
567 Float_t signal = digitsIn->GetDataUnchecked(row,col,time);
568 if (signal <= 0) continue;
569 GetSDigitsData(0)->Fill(i);
570 GetSDigitsData(1)->Fill(time);
571 GetSDigitsData(2)->Fill(signal);
577 delete digitsManager;
581 //____________________________________________________________________________
582 void AliTRDQADataMaker::MakeRaws(AliRawReader* rawReader)
589 //const Int_t kSM = 18;
590 //const Int_t kROC = 30;
591 //const Int_t kLayer = 6;
592 //const Int_t kStack = 5;
593 const Int_t kROB = 8;
594 const Int_t kMCM = 16;
595 const Int_t kADC = 22;
597 AliTRDRawStreamV2 *raw = new AliTRDRawStreamV2(rawReader);
599 raw->SetRawVersion(3);
602 while (raw->Next()) {
604 GetRawsData(0)->Fill(raw->GetDet());
606 Int_t *sig = raw->GetSignals();
607 for(Int_t i=0; i<3; i++) GetRawsData(1)->Fill(sig[i]);
609 GetRawsData(2)->Fill(sig[1]);
610 GetRawsData(3)->Fill(sig[0]);
611 GetRawsData(3)->Fill(sig[2]);
613 GetRawsData(4)->Fill(raw->GetTimeBin());
615 // calculate the index;
616 Int_t sm = raw->GetSM();
617 Int_t roc = raw->GetROC();
618 Int_t rob = raw->GetROB();
619 Int_t mcm = raw->GetMCM();
620 Int_t adc = raw->GetADC();
622 Int_t index = roc * (kROB*kMCM*kADC) + rob * (kMCM*kADC) + mcm * kADC + adc;
623 GetRawsData(5)->Fill(sm);
624 //printf("SM = %d\n", sm);
625 GetRawsData(6+sm)->Fill(index);
629 //____________________________________________________________________________
630 void AliTRDQADataMaker::MakeRecPoints(TTree * clustersTree)
633 // Makes data from RecPoints
636 Int_t nsize = Int_t(clustersTree->GetTotBytes() / (sizeof(AliTRDcluster)));
637 TObjArray *clusterArray = new TObjArray(nsize+1000);
639 TBranch *branch = clustersTree->GetBranch("TRDcluster");
641 AliError("Can't get the branch !");
644 branch->SetAddress(&clusterArray);
646 // Loop through all entries in the tree
647 Int_t nEntries = (Int_t) clustersTree->GetEntries();
649 AliTRDcluster *c = 0;
651 for (Int_t i=0; i<540; i++) nDet[i] = 0;
653 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
656 nbytes += clustersTree->GetEvent(iEntry);
658 // Get the number of points in the detector
659 Int_t nCluster = clusterArray->GetEntriesFast();
661 // Loop through all TRD digits
662 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
663 c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
665 Int_t iDet = c->GetDetector();
667 GetRecPointsData(0)->Fill(iDet);
668 GetRecPointsData(1)->Fill(iDet, c->GetQ());
669 GetRecPointsData(2)->Fill(c->GetNPads());
670 if (c->GetNPads() < 6)
671 GetRecPointsData(1+c->GetNPads())->Fill(c->GetCenter());
673 //if (c->GetPadTime() < 5)
674 ((TH2D*)GetRecPointsData(7))->Fill(c->GetPadRow(), c->GetPadCol());
675 GetRecPointsData(8)->Fill(c->GetPadTime());
677 ((TProfile*)GetRecPointsData(10))->Fill(c->GetPadTime(), c->GetQ());
680 //if (c->GetNPads() == 2) {
681 Short_t *sig = c->GetSignals();
684 if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0 && sig[5] == 0 && sig[6] == 0)
685 frac = 1. * sig[4] / (sig[3] + sig[4]);
688 if (sig[0] == 0 && sig[1] == 0 && sig[4] == 0 && sig[5] == 0 && sig[6] == 0)
689 frac = -1. * sig[2] / (sig[2] + sig[3]);
691 if (frac > -10) ((TProfile*)GetRecPointsData(11))->Fill(c->GetCenter(), frac);
697 for(Int_t i=0; i<540; i++)
698 if (nDet[i] > 0) GetRecPointsData(9)->Fill(nDet[i]);
704 //____________________________________________________________________________
705 void AliTRDQADataMaker::StartOfDetectorCycle()
708 // Detector specific actions at start of cycle
713 //__________________________________________________________________________
714 Int_t AliTRDQADataMaker::CheckPointer(TObject *obj, const char *name)
717 // Checks initialization of pointers
720 if (!obj) AliWarning(Form("null pointer: %s", name));