5 // Test macro for the TRD code
12 // Initialize the test setup
13 gAlice->Init("$(ALICE_ROOT)/TRD/AliTRDconfig.C");
15 // Run one event and create the hits
19 if (gAlice) delete gAlice;
20 file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
21 gAlice = (AliRun *) file->Get("gAlice");
23 // Analyze the TRD hits
24 if (rc = AliTRDanalyzeHits()) return rc;
26 // Run the digitization
27 if (rc = AliTRDcreateDigits()) return rc;
29 if (gAlice) delete gAlice;
30 file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
31 gAlice = (AliRun *) file->Get("gAlice");
34 if (rc = AliTRDanalyzeDigits()) return rc;
37 if (rc = AliTRDcreateCluster()) return rc;
39 if (gAlice) delete gAlice;
40 file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
41 gAlice = (AliRun *) file->Get("gAlice");
43 // Analyze the cluster
44 if (rc = AliTRDanalyzeCluster()) return rc;
46 //file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
50 //if (rc = AliTRDcreateTracks()) return rc;
56 //_____________________________________________________________________________
57 Int_t AliTRDanalyzeHits()
60 // Analyzes the hits and fills QA-histograms
66 cout << "<AliTRDanalyzeHits> No AliRun object found" << endl;
72 // Get the pointer to the TRD detector
73 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
75 cout << "<AliTRDanalyzeHits> No TRD detector found" << endl;
80 // Get the pointer to the geometry object
81 AliTRDgeometryFull *geo;
83 geo = (AliTRDgeometryFull *) trd->GetGeometry();
86 cout << "<AliTRDanalyzeHits> No TRD geometry found" << endl;
91 AliTRDparameter *par = new AliTRDparameter("TRDparameter","TRD parameter class");
93 // Define the histograms
94 TH1F *hQdedx = new TH1F("hQdedx","Charge dedx-hits",100,0.0,1000.0);
95 TH1F *hQtr = new TH1F("hQtr" ,"Charge TR-hits" ,100,0.0,1000.0);
97 Float_t rmin = geo->Rmin();
98 Float_t rmax = geo->Rmax();
99 Float_t length = geo->GetChamberLength(0,2);
100 Float_t width = geo->GetChamberWidth(0);
101 Int_t ncol = par->GetColMax(0);
102 Int_t nrow = par->GetRowMax(0,2,13);
103 Int_t ntime = ((Int_t) (rmax - rmin) / par->GetTimeBinSize());
105 TH2F *hZY = new TH2F("hZY" ,"Y vs Z (chamber 0)", nrow,-length/2.,length/2.
107 TH2F *hXZ = new TH2F("hXZ" ,"Z vs X (plane 0)" , ncol, -width/2., width/2.
108 , nrow,-length/2.,length/2.);
110 TH1F *hNprimP = new TH1F("hNprimP","Number of primary electrons per cm (MIP pion)"
112 TH1F *hNprimE = new TH1F("hNprimE","Number of primary electrons per cm (3GeV electron)"
114 TH1F *hNtotP = new TH1F("hNtotP" ,"Number of electrons per cm (MIP pion)"
116 TH1F *hNtotE = new TH1F("hNtotE" ,"Number of electrons per cm (3GeV electron)"
119 // Get the pointer hit tree
120 TTree *hitTree = gAlice->TreeH();
122 cout << "<AliTRDanalyzeHits> No hit tree found" << endl;
130 // Get the number of entries in the hit tree
131 // (Number of primary particles creating a hit somewhere)
132 Int_t nTrack = (Int_t) hitTree->GetEntries();
133 cout << "<AliTRDanalyzeHits> Found " << nTrack
134 << " primary particles with hits" << endl;
136 // Loop through all entries in the tree
137 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
140 nBytes += hitTree->GetEvent(iTrack);
147 // Loop through the TRD hits
149 AliTRDhit *hit = (AliTRDhit *) trd->FirstHit(-1);
155 Float_t x = hit->X();
156 Float_t y = hit->Y();
157 Float_t z = hit->Z();
158 Float_t q = hit->GetCharge();
159 Int_t track = hit->Track();
160 Int_t det = hit->GetDetector();
161 Int_t plane = geo->GetPlane(det);
171 hQtr->Fill(TMath::Abs(q));
174 TParticle *part = gAlice->Particle(track);
176 if ((plane == 0) && (q > 0)) {
179 if ((part->GetPdgCode() == 11) &&
182 nTotE += ((Int_t) q);
186 if ((part->GetPdgCode() == -211) &&
189 nTotP += ((Int_t) q);
194 hit = (AliTRDhit *) trd->NextHit();
198 if (nPrimE > 0) hNprimE->Fill(((Double_t) nPrimE)/3.7);
199 if (nPrimP > 0) hNprimP->Fill(((Double_t) nPrimP)/3.7);
200 if (nTotE > 0) hNtotE->Fill(((Double_t) nTotE)/3.7);
201 if (nTotP > 0) hNtotP->Fill(((Double_t) nTotP)/3.7);
205 cout << "<AliTRDanalyzeHits> Found " << countHits << " hits in total" << endl;
207 TCanvas *cHits = new TCanvas("cHits","AliTRDanalyzeHits",50,50,600,600);
220 TCanvas *cNel = new TCanvas("cNel","Ionization",50,50,600,600);
235 TFile *fout = new TFile("TRD_ionization.root","RECREATE");
246 //_____________________________________________________________________________
247 Int_t AliTRDcreateDigits()
250 // Creates the digits from the hits of the slow simulator
256 cout << "<AliTRDcreateDigits> No AliRun object found" << endl;
262 // Create the TRD digitzer
263 AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
264 ,"TRD digitizer class");
265 digitizer->InitDetector();
268 digitizer->SetDebug(1);
270 // Define the parameter object
271 // If no external parameter object is defined,
272 // default parameter will be used
273 AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
274 ,"TRD parameter class");
275 digitizer->SetParameter(parameter);
278 if (!(digitizer->MakeDigits())) {
283 // Write the digits into the input file
284 if (!(digitizer->MakeBranch())) {
289 // Write the digits into the input file
290 if (!(digitizer->WriteDigits())) {
295 // Save the parameter object in the AliROOT file
296 if (!(parameter->Write())) {
305 //_____________________________________________________________________________
306 Int_t AliTRDanalyzeDigits()
309 // Analyzes the digits
314 const Int_t kNpla = AliTRDgeometry::Nplan();
317 cout << "<AliTRDanalyzeDigits> No AliRun object found" << endl;
321 Int_t nPart = gAlice->GetEvent(0);
323 // Get the pointer to the TRD detector
324 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
326 cout << "<AliTRDanalyzeDigits> No TRD detector found" << endl;
331 // Get the digitizer object
332 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
333 AliTRDparameter *parameter = (AliTRDparameter *) file->Get("TRDparameter");
335 cout << "<AliTRDanalyzeDigits> No parameter object found" << endl;
340 // Define the histograms
341 Int_t adcRange = ((Int_t) parameter->GetADCoutRange());
342 TH1F *hAmpAll = new TH1F("hAmpAll" ,"Amplitude of the digits (all)"
343 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
344 TH1F *hAmpEl = new TH1F("hAmpEl" ,"Amplitude of the digits (electrons)"
345 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
346 TH1F *hAmpPi = new TH1F("hAmpPi" ,"Amplitude of the digits (pions)"
347 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
348 TH1F *hAmpNoise = new TH1F("hAmpNoise","Amplitude of the digits (noise)"
351 // Get the pointer to the geometry object
354 geo = trd->GetGeometry();
357 cout << "<AliTRDanalyzeDigits> No TRD geometry found" << endl;
362 // Create the digits manager
363 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
364 digitsManager->SetDebug(1);
366 digitsManager->Open("TRD_test.root");
368 // Read the digits from the file
369 if (!(digitsManager->ReadDigits())) {
370 cout << "<AliTRDanalyzeDigits> Cannot read the digits" << endl;
375 AliTRDmatrix *matrix;
377 Int_t countDigits = 0;
378 Int_t iSec = trd->GetSensSector();
379 Int_t iCha = trd->GetSensChamber();
380 Int_t timeMax = parameter->GetTimeTotal();
382 TProfile *hAmpTimeEl = new TProfile("hAmpTimeEl","Amplitude of the digits (electrons)"
383 ,timeMax,-0.5,((Double_t) timeMax)-0.5);
384 TProfile *hAmpTimePi = new TProfile("hAmpTimePi","Amplitude of the digits (pions)"
385 ,timeMax,-0.5,((Double_t) timeMax)-0.5);
387 // Loop over all planes
388 for (Int_t iPla = 0; iPla < kNpla; iPla++) {
390 Int_t iDet = geo->GetDetector(iPla,iCha,iSec);
391 Int_t rowMax = parameter->GetRowMax(iPla,iCha,iSec);
392 Int_t colMax = parameter->GetColMax(iPla);
395 matrix = new AliTRDmatrix(rowMax,colMax,timeMax,iSec,iCha,iPla);
398 // Loop through the detector pixel
399 for (Int_t time = 0; time < timeMax; time++) {
400 for (Int_t col = 0; col < colMax; col++) {
401 for (Int_t row = 0; row < rowMax; row++) {
403 AliTRDdigit *digit = digitsManager->GetDigit(row,col,time,iDet);
404 Int_t amp = digit->GetAmp();
405 Int_t track0 = digitsManager->GetTrack(0,row,col,time,iDet);
406 Int_t track1 = digitsManager->GetTrack(1,row,col,time,iDet);
407 TParticle *particle = 0;
409 particle = gAlice->Particle(track0);
415 matrix->SetSignal(row,col,time,amp);
424 hAmpNoise->Fill(amp);
428 if ((particle) && (particle->GetPdgCode() == 11) && (track1 < 0)) {
430 hAmpTimeEl->Fill(time,amp);
434 if ((particle) && (particle->GetPdgCode() == -211) && (track1 < 0)) {
436 hAmpTimePi->Fill(time,amp);
447 cout << "<AliTRDanalyzeDigits> Found " << countDigits << " digits in total" << endl;
449 // Display the detector matrix
452 TCanvas *cDigits = new TCanvas("cDigits","AliTRDanalyzeDigits",50,50,600,800);
453 cDigits->Divide(2,3);
456 hAmpAll->SetXTitle("Amplitude (ADC-channels)");
457 hAmpAll->SetYTitle("Entries");
461 hAmpNoise->SetXTitle("Amplitude (ADC-channels)");
462 hAmpNoise->SetYTitle("Entries");
466 hAmpEl->SetXTitle("Amplitude (ADC-channels)");
467 hAmpEl->SetYTitle("Entries");
471 hAmpPi->SetXTitle("Amplitude (ADC-channels)");
472 hAmpPi->SetYTitle("Entries");
475 hAmpTimeEl->SetXTitle("Timebin number");
476 hAmpTimeEl->SetYTitle("Mean amplitude");
477 hAmpTimeEl->Draw("HIST");
479 hAmpTimePi->SetXTitle("Timebin number");
480 hAmpTimePi->SetYTitle("Mean amplitude");
481 hAmpTimePi->Draw("HIST");
483 TFile *fileOut = new TFile("digits_test.root","RECREATE");
496 //_____________________________________________________________________________
497 Int_t AliTRDcreateCluster()
500 // Creates the cluster from the digits
505 // Create the clusterizer
506 AliTRDclusterizerV1 *clusterizer = new AliTRDclusterizerV1("TRDclusterizer"
507 ,"TRD clusterizer class");
508 clusterizer->SetVerbose(1);
510 // Define the parameter object
511 // If no external parameter object is defined,
512 // default parameter will be used
513 AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
514 ,"TRD parameter class");
515 parameter->SetClusMaxThresh(0);
516 parameter->SetClusSigThresh(0);
517 clusterizer->SetParameter(parameter);
520 if (!(clusterizer->Open("TRD_test.root",0))) {
526 if (!(clusterizer->ReadDigits())) {
532 if (!(clusterizer->MakeClusters())) {
537 // Write the cluster tree into the file
538 if (!(clusterizer->WriteClusters(-1))) {
543 // Save the clusterizer class in the file
544 if (!(clusterizer->Write())) {
553 //_____________________________________________________________________________
554 Int_t AliTRDanalyzeCluster()
557 // Analyzes the cluster
563 cout << "<AliTRDanalyzeCluster> No AliRun object found" << endl;
569 // Get the pointer to the TRD detector
570 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
572 cout << "<AliTRDanalyzeCluster> No TRD detector found" << endl;
577 // Define the histograms
578 TH1F *hClusAll = new TH1F("hClusAll" ,"Amplitude of the cluster (all)"
580 TH1F *hClusNoise = new TH1F("hClusNoise","Amplitude of the cluster (noise)"
582 TH1F *hClusEl = new TH1F("hClusEl" ,"Amplitude of the cluster (electron)"
584 TH1F *hClusPi = new TH1F("hClusPi" ,"Amplitude of the cluster (pion)"
587 // Get the pointer to the geometry object
590 geo = trd->GetGeometry();
593 cout << "<AliTRDanalyzeCluster> No TRD geometry found" << endl;
598 // Get the pointer to the hit-tree
599 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
600 TTree *clusterTree = (TTree *) file->Get("TreeR0_TRD");
601 if (!(clusterTree)) {
602 cout << "<AliTRDanalyzeCluster> No tree with clusters found" << endl;
607 // Get the pointer to the hit container
608 TObjArray *clusterArray = trd->RecPoints();
609 if (!(clusterArray)) {
610 cout << "<AliTRDanalyzeCluster> No clusterArray found" << endl;
615 // Set the branch address
616 clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray);
617 Int_t nEntries = clusterTree->GetEntries();
618 cout << "<AliTRDanalyzeCluster> Number of entries in the cluster tree = "
622 Int_t countCluster = 0;
623 Int_t countOverlap = 0;
625 // Loop through all entries in the tree
627 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
630 nbytes += clusterTree->GetEvent(iEntry);
632 // Get the number of points in the detector
633 Int_t nCluster = clusterArray->GetEntriesFast();
635 // Loop through all TRD digits
636 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
638 // Get the information for this digit
639 AliTRDcluster *cluster = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
640 Int_t detector = cluster->GetDetector();
641 Int_t sector = geo->GetSector(detector);
642 Int_t plane = geo->GetPlane(detector);
643 Int_t chamber = geo->GetChamber(detector);
644 Float_t energy = cluster->GetQ();
645 Int_t track0 = cluster->GetLabel(0);
646 Int_t track1 = cluster->GetLabel(1);
647 Int_t track2 = cluster->GetLabel(2);
648 TParticle *particle = 0;
650 particle = gAlice->Particle(track0);
654 if (!cluster->Isolated()) countOverlap++;
657 hClusAll->Fill(energy);
659 if (cluster->Isolated()) {
663 hClusNoise->Fill(energy);
667 if ((particle) && (particle->GetPdgCode() == 11) && (track1 < 0)) {
668 hClusEl->Fill(energy);
672 if ((particle) && (particle->GetPdgCode() == -211) && (track1 < 0)) {
673 hClusPi->Fill(energy);
682 cout << "<AliTRDanalyzeCluster> Found " << countCluster << " cluster in total" << endl;
683 cout << "<AliTRDanalyzeCluster> Found " << countOverlap << " overlapping cluster" << endl;
686 TCanvas *cCluster = new TCanvas("cCluster","AliTRDanalyzeCluster",50,50,600,600);
687 cCluster->Divide(2,2);
692 hClusAll->Fit("landau","0");
693 fun = (TF1 *) hClusAll->GetListOfFunctions()->First();
694 Float_t meanAll = fun->GetParameter(1);
696 fun->SetLineColor(2);
701 Float_t meanNoise = hClusNoise->GetMean();
706 hClusEl->Fit("landau","0");
707 fun = (TF1 *) hClusEl->GetListOfFunctions()->First();
708 fun->SetLineColor(2);
709 Float_t meanEl = fun->GetParameter(1);
715 hClusPi->Fit("landau","0");
716 fun = (TF1 *) hClusPi->GetListOfFunctions()->First();
717 fun->SetLineColor(2);
718 Float_t meanPi = fun->GetParameter(1);
723 cout << "##################################################################" << endl;
724 cout << " Mean all = " << meanAll << endl;
725 cout << " Mean noise = " << meanNoise << endl;
726 cout << " Mean electrons = " << meanEl << endl;
727 cout << " Mean pions = " << meanPi << endl;
728 cout << "##################################################################" << endl;
735 //_____________________________________________________________________________
736 Int_t AliTRDcreateTracks()
739 // Creates the tracks
744 // Create the tracker
745 AliTRDtracker *tracker = new AliTRDtracker("TRDtracker","TRD tracker");
747 // Read in the kine tree and the cluster
748 tracker->GetEvent("TRD_test.root","TRD_test.root");
751 TH1F *hs = new TH1F("hs","hs",100,0.0,1.0);
752 TH1F *hd = new TH1F("hd","hd",100,0.0,1.0);
753 tracker->Clusters2Tracks(hs,hd);
756 tracker->WriteTracks("TRD_test.root");