4 // Test macro for the TRD code
9 // Initialize the test setup
10 gAlice->Init("$(ALICE_ROOT)/TRD/AliTRDconfig.C");
12 // Run one event and create the hits
16 if (gAlice) delete gAlice;
17 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
18 gAlice = (AliRun *) file->Get("gAlice");
20 // Analyze the TRD hits
21 if (rc = AliTRDanalyzeHits()) return rc;
23 // Run the digitization
24 if (rc = AliTRDcreateDigits()) return rc;
26 if (gAlice) delete gAlice;
27 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
28 gAlice = (AliRun *) file->Get("gAlice");
31 if (rc = AliTRDanalyzeDigits()) return rc;
34 if (rc = AliTRDcreateCluster()) return rc;
36 if (gAlice) delete gAlice;
37 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
38 gAlice = (AliRun *) file->Get("gAlice");
41 if (rc = AliTRDanalyzeCluster()) return rc;
47 //_____________________________________________________________________________
48 Int_t AliTRDanalyzeHits()
51 // Analyzes the hits and fills QA-histograms
57 cout << "<AliTRDanalyzeHits> No AliRun object found" << endl;
63 // Get the pointer to the TRD detector
64 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
66 cout << "<AliTRDanalyzeHits> No TRD detector found" << endl;
71 // Get the pointer to the geometry object
72 AliTRDgeometryFull *geo;
74 geo = (AliTRDgeometryFull *) trd->GetGeometry();
77 cout << "<AliTRDanalyzeHits> No TRD geometry found" << endl;
82 AliTRDparameter *par = new AliTRDparameter("TRDparameter","TRD parameter class");
84 // Define the histograms
85 TH1F *hQdedx = new TH1F("hQdedx","Charge dedx-hits",100,0.0,1000.0);
86 TH1F *hQtr = new TH1F("hQtr" ,"Charge TR-hits" ,100,0.0,1000.0);
88 Float_t rmin = geo->Rmin();
89 Float_t rmax = geo->Rmax();
90 Float_t length = geo->GetChamberLength(0,2);
91 Float_t width = geo->GetChamberWidth(0);
92 Int_t ncol = par->GetColMax(0);
93 Int_t nrow = par->GetRowMax(0,2,13);
94 Int_t ntime = ((Int_t) (rmax - rmin) / par->GetTimeBinSize());
96 TH2F *hZY = new TH2F("hZY" ,"Y vs Z (chamber 0)", nrow,-length/2.,length/2.
98 TH2F *hXZ = new TH2F("hXZ" ,"Z vs X (plane 0)" , ncol, -width/2., width/2.
99 , nrow,-length/2.,length/2.);
101 TH1F *hNprimP = new TH1F("hNprimP","Number of primary electrons per cm (MIP pion)"
103 TH1F *hNprimE = new TH1F("hNprimE","Number of primary electrons per cm (3GeV electron)"
105 TH1F *hNtotP = new TH1F("hNtotP" ,"Number of electrons per cm (MIP pion)"
107 TH1F *hNtotE = new TH1F("hNtotE" ,"Number of electrons per cm (3GeV electron)"
110 // Get the pointer hit tree
111 TTree *hitTree = gAlice->TreeH();
113 cout << "<AliTRDanalyzeHits> No hit tree found" << endl;
121 // Get the number of entries in the hit tree
122 // (Number of primary particles creating a hit somewhere)
123 Int_t nTrack = (Int_t) hitTree->GetEntries();
124 cout << "<AliTRDanalyzeHits> Found " << nTrack
125 << " primary particles with hits" << endl;
127 // Loop through all entries in the tree
128 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
131 nBytes += hitTree->GetEvent(iTrack);
138 // Loop through the TRD hits
140 AliTRDhit *hit = (AliTRDhit *) trd->FirstHit(-1);
146 Float_t x = hit->X();
147 Float_t y = hit->Y();
148 Float_t z = hit->Z();
149 Float_t q = hit->GetCharge();
150 Int_t track = hit->Track();
151 Int_t det = hit->GetDetector();
152 Int_t plane = geo->GetPlane(det);
162 hQtr->Fill(TMath::Abs(q));
165 TParticle *part = gAlice->Particle(track);
167 if ((plane == 0) && (q > 0)) {
170 if ((part->GetPdgCode() == 11) &&
173 nTotE += ((Int_t) q);
177 if ((part->GetPdgCode() == -211) &&
180 nTotP += ((Int_t) q);
185 hit = (AliTRDhit *) trd->NextHit();
189 if (nPrimE > 0) hNprimE->Fill(((Double_t) nPrimE)/3.7);
190 if (nPrimP > 0) hNprimP->Fill(((Double_t) nPrimP)/3.7);
191 if (nTotE > 0) hNtotE->Fill(((Double_t) nTotE)/3.7);
192 if (nTotP > 0) hNtotP->Fill(((Double_t) nTotP)/3.7);
196 cout << "<AliTRDanalyzeHits> Found " << countHits << " hits in total" << endl;
198 TCanvas *cHits = new TCanvas("cHits","AliTRDanalyzeHits",50,50,600,600);
211 TCanvas *cNel = new TCanvas("cNel","Ionization",50,50,600,600);
226 TFile *fout = new TFile("TRD_ionization.root","RECREATE");
237 //_____________________________________________________________________________
238 Int_t AliTRDcreateDigits()
241 // Creates the digits from the hits of the slow simulator
247 cout << "<AliTRDcreateDigits> No AliRun object found" << endl;
253 // Create the TRD digitzer
254 AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
255 ,"TRD digitizer class");
256 digitizer->InitDetector();
259 digitizer->SetDebug(1);
261 // Define the parameter object
262 // If no external parameter object is defined,
263 // default parameter will be used
264 AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
265 ,"TRD parameter class");
266 digitizer->SetParameter(parameter);
269 if (!(digitizer->MakeDigits())) {
274 // Write the digits into the input file
275 if (!(digitizer->MakeBranch())) {
280 // Write the digits into the input file
281 if (!(digitizer->WriteDigits())) {
286 // Save the parameter object in the AliROOT file
287 if (!(parameter->Write())) {
296 //_____________________________________________________________________________
297 Int_t AliTRDanalyzeDigits()
300 // Analyzes the digits
305 const Int_t kNpla = AliTRDgeometry::Nplan();
308 cout << "<AliTRDanalyzeDigits> No AliRun object found" << endl;
312 Int_t nPart = gAlice->GetEvent(0);
314 // Get the pointer to the TRD detector
315 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
317 cout << "<AliTRDanalyzeDigits> No TRD detector found" << endl;
322 // Get the digitizer object
323 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
324 AliTRDparameter *parameter = (AliTRDparameter *) file->Get("TRDparameter");
326 cout << "<AliTRDanalyzeDigits> No parameter object found" << endl;
331 // Define the histograms
332 Int_t adcRange = ((Int_t) parameter->GetADCoutRange());
333 TH1F *hAmpAll = new TH1F("hAmpAll" ,"Amplitude of the digits (all)"
334 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
335 TH1F *hAmpEl = new TH1F("hAmpEl" ,"Amplitude of the digits (electrons)"
336 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
337 TH1F *hAmpPi = new TH1F("hAmpPi" ,"Amplitude of the digits (pions)"
338 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
339 TH1F *hAmpNoise = new TH1F("hAmpNoise","Amplitude of the digits (noise)"
342 // Get the pointer to the geometry object
345 geo = trd->GetGeometry();
348 cout << "<AliTRDanalyzeDigits> No TRD geometry found" << endl;
353 // Create the digits manager
354 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
356 digitsManager->Open("TRD_test.root");
358 // Read the digits from the file
359 if (!(digitsManager->ReadDigits())) {
360 cout << "<AliTRDanalyzeDigits> Cannot read the digits" << endl;
365 AliTRDmatrix *matrix;
367 Int_t countDigits = 0;
368 Int_t iSec = trd->GetSensSector();
369 Int_t iCha = trd->GetSensChamber();
370 Int_t timeMax = geo->GetTimeTotal();
372 TProfile *hAmpTimeEl = new TProfile("hAmpTimeEl","Amplitude of the digits (electrons)"
373 ,timeMax,-0.5,((Double_t) timeMax)-0.5);
374 TProfile *hAmpTimePi = new TProfile("hAmpTimePi","Amplitude of the digits (pions)"
375 ,timeMax,-0.5,((Double_t) timeMax)-0.5);
377 // Loop over all planes
378 for (Int_t iPla = 0; iPla < kNpla; iPla++) {
380 Int_t iDet = geo->GetDetector(iPla,iCha,iSec);
381 Int_t rowMax = parameter->GetRowMax(iPla,iCha,iSec);
382 Int_t colMax = parameter->GetColMax(iPla);
385 matrix = new AliTRDmatrix(rowMax,colMax,timeMax,iSec,iCha,iPla);
388 // Loop through the detector pixel
389 for (Int_t time = 0; time < timeMax; time++) {
390 for (Int_t col = 0; col < colMax; col++) {
391 for (Int_t row = 0; row < rowMax; row++) {
393 AliTRDdigit *digit = digitsManager->GetDigit(row,col,time,iDet);
394 Int_t amp = digit->GetAmp();
395 Int_t track0 = digitsManager->GetTrack(0,row,col,time,iDet);
396 Int_t track1 = digitsManager->GetTrack(1,row,col,time,iDet);
397 TParticle *particle = 0;
399 particle = gAlice->Particle(track0);
405 matrix->SetSignal(row,col,time,amp);
414 hAmpNoise->Fill(amp);
418 if ((particle) && (particle->GetPdgCode() == 11) && (track1 < 0)) {
420 hAmpTimeEl->Fill(time,amp);
424 if ((particle) && (particle->GetPdgCode() == -211) && (track1 < 0)) {
426 hAmpTimePi->Fill(time,amp);
437 cout << "<AliTRDanalyzeDigits> Found " << countDigits << " digits in total" << endl;
439 // Display the detector matrix
442 TCanvas *cDigits = new TCanvas("cDigits","AliTRDanalyzeDigits",50,50,600,800);
443 cDigits->Divide(2,3);
446 hAmpAll->SetXTitle("Amplitude (ADC-channels)");
447 hAmpAll->SetYTitle("Entries");
451 hAmpNoise->SetXTitle("Amplitude (ADC-channels)");
452 hAmpNoise->SetYTitle("Entries");
456 hAmpEl->SetXTitle("Amplitude (ADC-channels)");
457 hAmpEl->SetYTitle("Entries");
461 hAmpPi->SetXTitle("Amplitude (ADC-channels)");
462 hAmpPi->SetYTitle("Entries");
465 hAmpTimeEl->SetXTitle("Timebin number");
466 hAmpTimeEl->SetYTitle("Mean amplitude");
467 hAmpTimeEl->Draw("HIST");
469 hAmpTimePi->SetXTitle("Timebin number");
470 hAmpTimePi->SetYTitle("Mean amplitude");
471 hAmpTimePi->Draw("HIST");
473 TFile *fileOut = new TFile("digits_test.root","RECREATE");
486 //_____________________________________________________________________________
487 Int_t AliTRDcreateCluster()
490 // Creates the cluster from the digits
495 // Create the clusterizer
496 AliTRDclusterizerV1 *clusterizer = new AliTRDclusterizerV1("TRDclusterizer"
497 ,"TRD clusterizer class");
498 clusterizer->SetVerbose(1);
500 // Define the parameter object
501 // If no external parameter object is defined,
502 // default parameter will be used
503 AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
504 ,"TRD parameter class");
505 parameter->SetClusMaxThresh(0);
506 parameter->SetClusSigThresh(0);
507 clusterizer->SetParameter(parameter);
510 if (!(clusterizer->Open("TRD_test.root",0))) {
516 if (!(clusterizer->ReadDigits())) {
522 if (!(clusterizer->MakeClusters())) {
527 // Write the cluster tree into the file
528 if (!(clusterizer->WriteClusters(-1))) {
533 // Save the clusterizer class in the file
534 if (!(clusterizer->Write())) {
543 //_____________________________________________________________________________
544 Int_t AliTRDanalyzeCluster()
547 // Analyzes the cluster
553 cout << "<AliTRDanalyzeCluster> No AliRun object found" << endl;
559 // Get the pointer to the TRD detector
560 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
562 cout << "<AliTRDanalyzeCluster> No TRD detector found" << endl;
567 // Define the histograms
568 TH1F *hClusAll = new TH1F("hClusAll" ,"Amplitude of the cluster (all)"
570 TH1F *hClusNoise = new TH1F("hClusNoise","Amplitude of the cluster (noise)"
572 TH1F *hClusEl = new TH1F("hClusEl" ,"Amplitude of the cluster (electron)"
574 TH1F *hClusPi = new TH1F("hClusPi" ,"Amplitude of the cluster (pion)"
577 // Get the pointer to the geometry object
580 geo = trd->GetGeometry();
583 cout << "<AliTRDanalyzeCluster> No TRD geometry found" << endl;
588 // Get the pointer to the hit-tree
589 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
590 TTree *clusterTree = (TTree *) file->Get("TreeR0_TRD");
591 if (!(clusterTree)) {
592 cout << "<AliTRDanalyzeCluster> No tree with clusters found" << endl;
597 // Get the pointer to the hit container
598 TObjArray *clusterArray = trd->RecPoints();
599 if (!(clusterArray)) {
600 cout << "<AliTRDanalyzeCluster> No clusterArray found" << endl;
605 // Set the branch address
606 clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray);
607 Int_t nEntries = clusterTree->GetEntries();
608 cout << "<AliTRDanalyzeCluster> Number of entries in the cluster tree = "
612 Int_t countCluster = 0;
613 Int_t countOverlap = 0;
615 // Loop through all entries in the tree
617 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
620 nbytes += clusterTree->GetEvent(iEntry);
622 // Get the number of points in the detector
623 Int_t nCluster = clusterArray->GetEntriesFast();
625 // Loop through all TRD digits
626 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
628 // Get the information for this digit
629 AliTRDcluster *cluster = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
630 Int_t detector = cluster->GetDetector();
631 Int_t sector = geo->GetSector(detector);
632 Int_t plane = geo->GetPlane(detector);
633 Int_t chamber = geo->GetChamber(detector);
634 Float_t energy = cluster->GetQ();
635 Int_t track0 = cluster->GetTrackIndex(0);
636 Int_t track1 = cluster->GetTrackIndex(1);
637 Int_t track2 = cluster->GetTrackIndex(2);
638 TParticle *particle = 0;
640 particle = gAlice->Particle(track0);
644 if (!cluster->Isolated()) countOverlap++;
647 hClusAll->Fill(energy);
649 if (cluster->Isolated()) {
653 hClusNoise->Fill(energy);
657 if ((particle) && (particle->GetPdgCode() == 11) && (track1 < 0)) {
658 hClusEl->Fill(energy);
662 if ((particle) && (particle->GetPdgCode() == -211) && (track1 < 0)) {
663 hClusPi->Fill(energy);
672 cout << "<AliTRDanalyzeCluster> Found " << countCluster << " cluster in total" << endl;
673 cout << "<AliTRDanalyzeCluster> Found " << countOverlap << " overlapping cluster" << endl;
676 TCanvas *cCluster = new TCanvas("cCluster","AliTRDanalyzeCluster",50,50,600,600);
677 cCluster->Divide(2,2);
682 hClusAll->Fit("landau","0");
683 fun = (TF1 *) hClusAll->GetListOfFunctions()->First();
684 Float_t meanAll = fun->GetParameter(1);
686 fun->SetLineColor(2);
691 Float_t meanNoise = hClusNoise->GetMean();
692 //hClusNoise->Draw();
696 hClusEl->Fit("landau","0");
697 fun = (TF1 *) hClusEl->GetListOfFunctions()->First();
698 fun->SetLineColor(2);
699 Float_t meanEl = fun->GetParameter(1);
705 hClusPi->Fit("landau","0");
706 fun = (TF1 *) hClusPi->GetListOfFunctions()->First();
707 fun->SetLineColor(2);
708 Float_t meanPi = fun->GetParameter(1);
713 cout << "##################################################################" << endl;
714 cout << " Mean all = " << meanAll << endl;
715 cout << " Mean noise = " << meanNoise << endl;
716 cout << " Mean electrons = " << meanEl << endl;
717 cout << " Mean pions = " << meanPi << endl;
718 cout << "##################################################################" << endl;