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()
84 //create ESDs histograms in ESDs subdir
85 const Int_t nhist = 19;
88 hist[0] = new TH1D("qaTRD_esd_ntracks", ":Number of tracks", 300, -0.5, 299.5);
89 hist[1] = new TH1D("qaTRD_esd_sector", ":Sector", 18, -0.5, 17.7);
90 hist[2] = new TH1D("qaTRD_esd_bits", ";Bits", 64, -0.5, 63.5);
92 const Int_t knbits = 6;
93 const char *suf[knbits] = {"TPCi", "TPCo", "TPCz", "TRDo", "TRDr", "TRDz"};
96 for(Int_t i=0; i<knbits; i++) {
97 hist[2*i+3] = new TH1D(Form("qaTRD_esd_pt%s",suf[i]), ";p_{T} (GeV/c);", 50, 0, 10);
98 hist[2*i+4] = new TH1D(Form("qaTRD_esd_trdz%s", suf[i]), ";z (cm)", 200, -400, 400);
102 hist[15] = new TH1D("qaTRD_esd_clsTRDo", "TRDo;number of clusters", 130, -0.5, 129.5);;
103 hist[16] = new TH1D("qaTRD_esd_clsTRDr", "TRDr;number of clusters", 130, -0.5, 129.5);;
104 hist[17] = new TH1D("qaTRD_esd_clsTRDz", "TRDz;number of clusters", 130, -0.5, 129.5);;
105 // hist[18] = new TH1D("qaTRD_esd_clsRatio", ";cluster ratio", 100, 0., 1.3);;
107 hist[18] = new TH2D("qaTRD_esd_sigMom", ";momentum (GeV/c);signal", 100, 0, 5, 200, 0, 1e3);
109 for(Int_t i=0; i<nhist; i++) {
111 Add2ESDsList(hist[i], i);
115 //____________________________________________________________________________
116 void AliTRDQADataMaker::InitHits()
118 // create Hits histograms in Hits subdir
119 const Int_t nhist = 4;
122 hist[0] = new TH1D("qaTRD_hits_det", ";Detector Id of the hit", 540, -0.5, 539.5) ;
124 hist[1] = new TH1D("qaTRD_hist_Qdrift", ";Charge from tracks", 100, 0, 100);
125 hist[2] = new TH1D("qaTRD_hist_Qamp", ";Charge from TRD photon", 100, 0, 100);
126 hist[3] = new TH1D("qaTRD_hist_Qphoton", ";Charge from TRD photon", 100, 0, 100);
128 for(Int_t i=0; i<nhist; i++) {
130 Add2HitsList(hist[i], i);
134 //____________________________________________________________________________
135 void AliTRDQADataMaker::InitDigits()
137 // create Digits histograms in Digits subdir
139 const Int_t nhist = 3;
142 hist[0] = new TH1D("qaTRD_digits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
143 hist[1] = new TH1D("qaTRD_digits_time", ";Time bin", 40, -0.5, 39.5);
144 hist[2] = new TH1D("qaTRD_digits_amp", ";Amplitude", 100, 0, 100.);
146 for(Int_t i=0; i<nhist; i++) {
148 Add2DigitsList(hist[i], i);
153 //____________________________________________________________________________
154 void AliTRDQADataMaker::InitRecPoints()
156 // create Reconstructed Points histograms in RecPoints subdir
157 const Int_t nhist = 12;
160 hist[0] = new TH1D("qaTRD_recPoints_det", ";Detector ID of the cluster", 540, -0.5, 539.5);
161 hist[1] = new TH2D("qaTRD_recPoints_amp", ";Amplitude", 540, -0.5, 539, 200, -0.5, 199.5);
162 hist[2] = new TH1D("qaTRD_recPoints_npad", ";Number of Pads", 12, -0.5, 11.5);
164 hist[3] = new TH1D("qaTRD_recPoints_dist2", ";residuals [2pad]", 100, -1, 1);
165 hist[4] = new TH1D("qaTRD_recPoints_dist3", ";residuals [3pad]", 100, -1, 1);
166 hist[5] = new TH1D("qaTRD_recPoints_dist4", ";residuals [4pad]", 100, -1, 1);
167 hist[6] = new TH1D("qaTRD_recPoints_dist5", ";residuals [5pad]", 100, -1, 1);
169 hist[7] = new TH2D("qaTRD_recPoints_rowCol", ";row;col", 16, -0.5, 15.5, 145, -0.5, 144.5);
170 hist[8] = new TH1D("qaTRD_recPoints_time", ";time bin", 35, -0.5, 34.5);
171 hist[9] = new TH1D("qaTRD_recPoints_nCls", ";number of clusters", 500, -0.5, 499.5);
173 hist[10] = new TProfile("qaTRD_recPoints_sigTime", ";time bin;signal", 35, -0.5, 34.5, 0, 200, "");
174 hist[11] = new TProfile("qaTRD_recPoints_prf", ";distance;center of gravity", 120, -0.6, 0.6, -1.2, 1.2, "");
176 hist[12] = new TH1D("qaTRD_recPoints_ampDist", ";amplitude MPV", 100, 0, 100);
179 for(Int_t i=0; i<nhist; i++) {
181 Add2RecPointsList(hist[i], i);
185 //____________________________________________________________________________
186 void AliTRDQADataMaker::InitRaws()
188 // create Raws histograms in Raws subdir
189 const Int_t kSM = 18;
190 const Int_t nhist = 6+kSM;
193 hist[0] = new TH1D("qaTRD_raws_det", ";detector", 540, -0.5, 539.5);
194 hist[1] = new TH1D("qaTRD_raws_sig", ";signal", 100, -0.5, 99.5);
195 hist[2] = new TH1D("qaTRD_raws_sigCentral", "; signal central bin", 100, -0.5, 99.5);
196 hist[3] = new TH1D("qaTRD_raws_sigTail", ";signal cluster", 100, -0.5, 99.5);
197 hist[4] = new TH1D("qaTRD_raws_tiemBin", ";time bin", 40, -0.5, 39.5);
198 hist[5] = new TH1D("qaTRD_rows_smId", ";supermodule", 18, -0.5, 17.5);
200 // one char per ADC chanell
201 const Int_t nADC = 30 * 8 * 16 * 22;
202 for(Int_t i=0; i<kSM; i++)
203 hist[6+i] = new TH1D(Form("qaTRD_raws_sm%d",i),"",nADC, -0.5, nADC-0.5);
205 for(Int_t i=0; i<nhist; i++) {
207 Add2RawsList(hist[i], i);
211 //____________________________________________________________________________
212 void AliTRDQADataMaker::InitSDigits()
214 // create SDigits histograms in SDigits subdir
216 const Int_t nhist = 3;
219 hist[0] = new TH1D("qaTRD_sdigits_det", ";Detector Id of the digit", 540, -0.5, 539.5);
220 hist[1] = new TH1D("qaTRD_sdigits_time", ";Time bin", 40, -0.5, 39.5);
221 hist[2] = new TH1D("qaTRD_sdigits_amp", ";Amplitude", 100, 0, 1e7);
223 for(Int_t i=0; i<nhist; i++) {
225 Add2SDigitsList(hist[i], i);
229 //____________________________________________________________________________
230 void AliTRDQADataMaker::MakeESDs(AliESDEvent * esd)
232 // make QA data from ESDs
233 Int_t nTracks = esd->GetNumberOfTracks();
234 GetESDsData(0)->Fill(nTracks);
237 for(Int_t i=0; i<nTracks; i++) {
239 AliESDtrack *track = esd->GetTrack(i);
240 const AliExternalTrackParam *paramOut = track->GetOuterParam();
241 const AliExternalTrackParam *paramIn = track->GetInnerParam();
244 if (!paramIn) continue;
245 if (!paramOut) continue;
248 if (track->GetKinkIndex(0) > 0) continue;
250 Double_t extZ = GetExtZ(paramIn);
251 if (TMath::Abs(extZ) > 320) continue; // acceptance cut
253 // .. in the acceptance
254 Int_t sector = GetSector(paramOut->GetAlpha());
255 GetESDsData(1)->Fill(sector);
258 UInt_t status = track->GetStatus();
259 for(Int_t bit=0; bit<32; bit++)
260 if (u<<bit & status) GetESDsData(2)->Fill(bit);
262 const Int_t knbits = 6;
263 Int_t bit[6] = {0,0,0,0,0,0};
264 bit[0] = status & AliESDtrack::kTPCin;
265 bit[1] = status & AliESDtrack::kTPCout;
266 bit[2] = (status & AliESDtrack::kTPCout) && !(status & AliESDtrack::kTRDout);
267 bit[3] = status & AliESDtrack::kTRDout;
268 bit[4] = status & AliESDtrack::kTRDrefit;
269 bit[5] = (status & AliESDtrack::kTRDout) && !(status & AliESDtrack::kTRDrefit);
271 // transverse momentum
272 //const Double_t *val = paramOut->GetParameter(); // parameters at the Outer plane
273 Double_t pt = paramOut->Pt(); //1./TMath::Abs(val[4]);
275 for(Int_t b=0; b<knbits; b++) {
277 GetESDsData(2*b+3)->Fill(pt);
278 GetESDsData(2*b+4)->Fill(extZ);
283 for(Int_t b=0; b<3; b++)
284 if (bit[3+b]) GetESDsData(b+15)->Fill(track->GetTRDncls());
287 if (!bit[4]) continue;
289 //fQuality->Fill(track->GetTRDQuality());
290 //fBudget->Fill(track->GetTRDBudget());
291 //fSignal->Fill(track->GetTRDsignal());
293 GetESDsData(18)->Fill(track->GetP(), track->GetTRDsignal());
297 if (status & AliESDtrack::kTRDpid) {
299 for(Int_t l=0; l<6; l++) fTime->Fill(track->GetTRDTimBin(l));
301 // fill pid histograms
302 Double_t trdr0 = 0; //, tpcr0 = 0;
303 Int_t trdBestPid = 5; //, tpcBestPid = 5; // charged
304 const Double_t kminPidValue = 0.9;
307 //track->GetTPCpid(pp); // ESD inconsequence
309 for(Int_t pid=0; pid<5; pid++) {
311 trdr0 += track->GetTRDpid(pid);
314 fTrdPID[pid]->Fill(track->GetTRDpid(pid));
315 //fTpcPID[pid]->Fill(pp[pid]);
317 if (track->GetTRDpid(pid) > kminPidValue) trdBestPid = pid;
318 //if (pp[pid] > kminPidValue) tpcBestPid = pid;
321 fTrdPID[5]->Fill(trdr0); // check unitarity
322 fTrdSigMomPID[trdBestPid]->Fill(track->GetP(), track->GetTRDsignal());
324 //fTpcPID[5]->Fill(tpcr0); // check unitarity
325 //fTpcSigMomPID[tpcBestPid]->Fill(track->GetP(), track->GetTPCsignal());
335 //______________________________________________________________________________
336 Int_t AliTRDQADataMaker::GetSector(const Double_t alpha) const {
337 // Gets the sector number
339 Double_t size = TMath::DegToRad() * 20.; // shall use TRDgeo
340 Int_t sector = (Int_t)((alpha + TMath::Pi())/size);
344 //______________________________________________________________________________
345 Double_t AliTRDQADataMaker::GetExtZ(const AliExternalTrackParam *in) const {
347 // returns the Z position at the entry to TRD
348 // using parameters from the TPC in
351 const Double_t x0 = 300;
353 Double_t x = in->GetX();
354 const Double_t *par = in->GetParameter();
355 Double_t theta = par[3];
356 Double_t z = in->GetZ();
358 Double_t zz = z + (x0-x) * TMath::Tan(theta);
362 //____________________________________________________________________________
363 void AliTRDQADataMaker::MakeHits(TClonesArray * hits)
365 //make QA data from Hits
366 //printf("making QA for TRD hits from an array %d\n", hits->GetEntriesFast());
371 while ( (hit = dynamic_cast<AliTRDhit *>(next())) ) {
372 GetHitsData(0)->Fill(hit->GetDetector());
373 Double_t q = TMath::Abs(hit->GetCharge());
375 if (hit->FromDrift()) GetHitsData(1)->Fill(q);
376 if (hit->FromAmplification()) GetHitsData(2)->Fill(q);
377 if (hit->FromTRphoton()) GetHitsData(3)->Fill(q);
382 //____________________________________________________________________________
383 void AliTRDQADataMaker::MakeHits(TTree * hitTree)
385 //make QA data from Hits
386 //printf("making QA for TRD hits from a tree\n");
388 if (!CheckPointer(hitTree, "TRD hits tree")) return;
390 TBranch *branch = hitTree->GetBranch("TRD");
391 if (!CheckPointer(branch, "TRD hits branch")) return;
393 Int_t nhits = (Int_t)(hitTree->GetTotBytes()/sizeof(AliTRDhit));
394 TClonesArray *hits = new TClonesArray("AliTRDhit", nhits+1000);
395 TClonesArray *tmp = new TClonesArray("AliTRDhit", 1000);
396 branch->SetAddress(&tmp);
399 Int_t nEntries = (Int_t)branch->GetEntries();
400 for(Int_t i = 0; i < nEntries; i++) {
402 Int_t nHits = (Int_t)tmp->GetEntries();
403 for(Int_t j=0; j<nHits; j++) {
404 AliTRDhit *hit = (AliTRDhit*)tmp->At(j);
405 new((*hits)[index++]) AliTRDhit(*hit);
414 //____________________________________________________________________________
415 void AliTRDQADataMaker::MakeDigits(TClonesArray * digits)
417 // makes data from Digits
420 AliTRDdigit * digit ;
421 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
422 GetDigitsData(0)->Fill(digit->GetDetector());
423 GetDigitsData(1)->Fill(digit->GetTime());
424 GetDigitsData(2)->Fill(digit->GetAmp());
428 //____________________________________________________________________________
429 void AliTRDQADataMaker::MakeDigits(TTree * digits)
432 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
433 digitsManager->CreateArrays();
434 digitsManager->ReadDigits(digits);
436 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
438 AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i);
440 // This is to take care of switched off super modules
441 if (digitsIn->GetNtime() == 0) continue;
445 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
446 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
448 Int_t nRows = digitsIn->GetNrow();
449 Int_t nCols = digitsIn->GetNcol();
450 Int_t nTbins = digitsIn->GetNtime();
452 for(Int_t row = 0; row < nRows; row++)
453 for(Int_t col = 0; col < nCols; col++)
454 for(Int_t time = 0; time < nTbins; time++) {
456 Float_t signal = digitsIn->GetDataUnchecked(row,col,time);
457 GetDigitsData(0)->Fill(i);
458 GetDigitsData(1)->Fill(time);
459 GetDigitsData(2)->Fill(signal);
464 delete digitsManager;
467 //____________________________________________________________________________
468 void AliTRDQADataMaker::MakeSDigits(TClonesArray * sdigits)
470 // makes data from Digits
472 TIter next(sdigits) ;
473 AliTRDdigit * digit ;
474 while ( (digit = dynamic_cast<AliTRDdigit *>(next())) ) {
475 GetDigitsData(0)->Fill(digit->GetDetector());
476 GetDigitsData(1)->Fill(digit->GetTime());
477 GetDigitsData(2)->Fill(digit->GetAmp());
481 //____________________________________________________________________________
482 void AliTRDQADataMaker::MakeSDigits(TTree * digits)
485 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
486 digitsManager->CreateArrays();
487 digitsManager->ReadDigits(digits);
489 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) {
491 AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i);
493 // This is to take care of switched off super modules
494 if (digitsIn->GetNtime() == 0) continue;
498 //AliTRDSignalIndex* indexes = digitsManager->GetIndexes(i);
499 //if (indexes->IsAllocated() == kFALSE) digitsManager->BuildIndexes(i);
501 Int_t nRows = digitsIn->GetNrow();
502 Int_t nCols = digitsIn->GetNcol();
503 Int_t nTbins = digitsIn->GetNtime();
505 for(Int_t row = 0; row < nRows; row++)
506 for(Int_t col = 0; col < nCols; col++)
507 for(Int_t time = 0; time < nTbins; time++) {
509 Float_t signal = digitsIn->GetDataUnchecked(row,col,time);
510 if (signal <= 0) continue;
511 GetSDigitsData(0)->Fill(i);
512 GetSDigitsData(1)->Fill(time);
513 GetSDigitsData(2)->Fill(signal);
519 delete digitsManager;
522 //____________________________________________________________________________
523 void AliTRDQADataMaker::MakeRaws(AliRawReader* rawReader)
528 //const Int_t kSM = 18;
529 //const Int_t kROC = 30;
530 //const Int_t kLayer = 6;
531 //const Int_t kStack = 5;
532 const Int_t kROB = 8;
533 const Int_t kMCM = 16;
534 const Int_t kADC = 22;
536 AliTRDRawStreamV2 *raw = new AliTRDRawStreamV2(rawReader);
538 raw->SetRawVersion(3);
541 while (raw->Next()) {
543 GetRawsData(0)->Fill(raw->GetDet());
545 Int_t *sig = raw->GetSignals();
546 for(Int_t i=0; i<3; i++) GetRawsData(1)->Fill(sig[i]);
548 GetRawsData(2)->Fill(sig[1]);
549 GetRawsData(3)->Fill(sig[0]);
550 GetRawsData(3)->Fill(sig[2]);
552 GetRawsData(4)->Fill(raw->GetTimeBin());
554 // calculate the index;
555 Int_t sm = raw->GetSM();
556 Int_t roc = raw->GetROC();
557 Int_t rob = raw->GetROB();
558 Int_t mcm = raw->GetMCM();
559 Int_t adc = raw->GetADC();
561 Int_t index = roc * (kROB*kMCM*kADC) + rob * (kMCM*kADC) + mcm * kADC + adc;
562 GetRawsData(5)->Fill(sm);
563 //printf("SM = %d\n", sm);
564 GetRawsData(6+sm)->Fill(index);
568 //____________________________________________________________________________
569 void AliTRDQADataMaker::MakeRecPoints(TTree * clustersTree)
572 // makes data from RecPoints
575 Int_t nsize = Int_t(clustersTree->GetTotBytes() / (sizeof(AliTRDcluster)));
576 TObjArray *clusterArray = new TObjArray(nsize+1000);
578 TBranch *branch = clustersTree->GetBranch("TRDcluster");
580 AliError("Can't get the branch !");
583 branch->SetAddress(&clusterArray);
585 // Loop through all entries in the tree
586 Int_t nEntries = (Int_t) clustersTree->GetEntries();
588 AliTRDcluster *c = 0;
590 for (Int_t i=0; i<540; i++) nDet[i] = 0;
592 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
595 nbytes += clustersTree->GetEvent(iEntry);
597 // Get the number of points in the detector
598 Int_t nCluster = clusterArray->GetEntriesFast();
600 // Loop through all TRD digits
601 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
602 c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
604 Int_t iDet = c->GetDetector();
606 GetRecPointsData(0)->Fill(iDet);
607 GetRecPointsData(1)->Fill(iDet, c->GetQ());
608 GetRecPointsData(2)->Fill(c->GetNPads());
609 if (c->GetNPads() < 6)
610 GetRecPointsData(1+c->GetNPads())->Fill(c->GetCenter());
612 //if (c->GetPadTime() < 5)
613 ((TH2D*)GetRecPointsData(7))->Fill(c->GetPadRow(), c->GetPadCol());
614 GetRecPointsData(8)->Fill(c->GetPadTime());
616 ((TProfile*)GetRecPointsData(10))->Fill(c->GetPadTime(), c->GetQ());
619 //if (c->GetNPads() == 2) {
620 Short_t *sig = c->GetSignals();
623 if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0 && sig[5] == 0 && sig[6] == 0)
624 frac = 1. * sig[4] / (sig[3] + sig[4]);
627 if (sig[0] == 0 && sig[1] == 0 && sig[4] == 0 && sig[5] == 0 && sig[6] == 0)
628 frac = -1. * sig[2] / (sig[2] + sig[3]);
630 if (frac > -10) ((TProfile*)GetRecPointsData(11))->Fill(c->GetCenter(), frac);
636 for(Int_t i=0; i<540; i++)
637 if (nDet[i] > 0) GetRecPointsData(9)->Fill(nDet[i]);
643 //____________________________________________________________________________
644 void AliTRDQADataMaker::StartOfDetectorCycle()
646 //Detector specific actions at start of cycle
650 //__________________________________________________________________________
651 Int_t AliTRDQADataMaker::CheckPointer(TObject *obj, const char *name) {
653 if (!obj) AliWarning(Form("null pointer: %s", name));
656 //__________________________________________________________________________