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");
33 // // Analyze the digits
34 // if (rc = AliTRDanalyzeDigits()) return rc;
36 // // Create the cluster
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
65 AliRunLoader *rl = gAlice->GetRunLoader();
67 cout << "<AliTRDanalyzeHits> No RunLoader found" << endl;
72 // Import the Trees for the event nEvent in the file
75 AliLoader* loader = rl->GetLoader("TRDLoader");
77 cout << "<AliTRDanalyzeHits> No TRDLoader found" << endl;
82 // Get the pointer to the TRD detector
83 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
85 cout << "<AliTRDanalyzeHits> No TRD detector found" << endl;
90 // Get the pointer to the geometry object
91 AliTRDgeometryFull *geo;
93 geo = (AliTRDgeometryFull *) trd->GetGeometry();
96 cout << "<AliTRDanalyzeHits> No TRD geometry found" << endl;
101 AliTRDparameter *par = new AliTRDparameter("TRDparameter","TRD parameter class");
103 // Define the histograms
104 TH1F *hQdedx = new TH1F("hQdedx","Charge dedx-hits",100,0.0,1000.0);
105 TH1F *hQtr = new TH1F("hQtr" ,"Charge TR-hits" ,100,0.0,1000.0);
107 Float_t rmin = geo->Rmin();
108 Float_t rmax = geo->Rmax();
109 Float_t length = geo->GetChamberLength(0,2);
110 Float_t width = geo->GetChamberWidth(0);
111 Int_t ncol = par->GetColMax(0);
112 Int_t nrow = par->GetRowMax(0,2,13);
113 Int_t ntime = ((Int_t) (rmax - rmin) / par->GetTimeBinSize());
115 TH2F *hZY = new TH2F("hZY" ,"Y vs Z (chamber 0)", nrow,-length/2.,length/2.
117 TH2F *hXZ = new TH2F("hXZ" ,"Z vs X (plane 0)" , ncol, -width/2., width/2.
118 , nrow,-length/2.,length/2.);
120 TH1F *hNprimP = new TH1F("hNprimP","Number of primary electrons per cm (MIP pion)"
122 TH1F *hNprimE = new TH1F("hNprimE","Number of primary electrons per cm (3GeV electron)"
124 TH1F *hNtotP = new TH1F("hNtotP" ,"Number of electrons per cm (MIP pion)"
126 TH1F *hNtotE = new TH1F("hNtotE" ,"Number of electrons per cm (3GeV electron)"
129 // Get the pointer hit tree
130 TTree *hitTree = loader->TreeH();
132 cout << "<AliTRDanalyzeHits> No hit tree found" << endl;
140 // Get the number of entries in the hit tree
141 // (Number of primary particles creating a hit somewhere)
142 Int_t nTrack = (Int_t) hitTree->GetEntries();
143 cout << "<AliTRDanalyzeHits> Found " << nTrack
144 << " primary particles with hits" << endl;
146 // Loop through all entries in the tree
147 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
150 nBytes += hitTree->GetEvent(iTrack);
157 // Loop through the TRD hits
159 AliTRDhit *hit = (AliTRDhit *) trd->FirstHit(-1);
165 Float_t x = hit->X();
166 Float_t y = hit->Y();
167 Float_t z = hit->Z();
168 Float_t q = hit->GetCharge();
169 Int_t track = hit->Track();
170 Int_t det = hit->GetDetector();
171 Int_t plane = geo->GetPlane(det);
181 hQtr->Fill(TMath::Abs(q));
184 // printf("Getting TParticle for track %d\n",track);
185 // TParticle *part = gAlice->Particle(track);
187 // if ((plane == 0) && (q > 0)) {
189 // // 3 GeV electrons
190 // if ((part->GetPdgCode() == 11) &&
191 // (part->P() > 2.9)) {
193 // nTotE += ((Int_t) q);
197 // if ((part->GetPdgCode() == -211) &&
198 // (part->P() > 0.5)) {
200 // nTotP += ((Int_t) q);
205 hit = (AliTRDhit *) trd->NextHit();
209 if (nPrimE > 0) hNprimE->Fill(((Double_t) nPrimE)/3.7);
210 if (nPrimP > 0) hNprimP->Fill(((Double_t) nPrimP)/3.7);
211 if (nTotE > 0) hNtotE->Fill(((Double_t) nTotE)/3.7);
212 if (nTotP > 0) hNtotP->Fill(((Double_t) nTotP)/3.7);
216 cout << "<AliTRDanalyzeHits> Found " << countHits << " hits in total" << endl;
218 TCanvas *cHits = new TCanvas("cHits","AliTRDanalyzeHits",50,50,600,600);
231 TCanvas *cNel = new TCanvas("cNel","Ionization",50,50,600,600);
246 TFile *fout = new TFile("TRD_ionization.root","RECREATE");
257 //_____________________________________________________________________________
258 Int_t AliTRDcreateDigits()
261 // Creates the digits from the hits of the slow simulator
267 cout << "<AliTRDcreateDigits> No AliRun object found" << endl;
273 // Create the TRD digitzer
274 AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
275 ,"TRD digitizer class");
276 digitizer->Open("TRD_test.root");
277 digitizer->InitDetector();
278 digitizer->InitOutput(0);
281 digitizer->SetDebug(1);
283 // Define the parameter object
284 // If no external parameter object is defined,
285 // default parameter will be used
286 AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
287 ,"TRD parameter class");
288 digitizer->SetParameter(parameter);
291 if (!(digitizer->MakeDigits())) {
296 // Write the digits into the input file
297 //if (!(digitizer->MakeBranch())) {
302 // Write the digits into the input file
303 if (!(digitizer->WriteDigits())) {
308 // Save the parameter object in the AliROOT file
309 if (!(parameter->Write())) {
318 //_____________________________________________________________________________
319 Int_t AliTRDanalyzeDigits()
322 // Analyzes the digits
327 const Int_t kNpla = AliTRDgeometry::Nplan();
330 cout << "<AliTRDanalyzeDigits> No AliRun object found" << endl;
334 Int_t nPart = gAlice->GetEvent(0);
336 // Get the pointer to the TRD detector
337 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
339 cout << "<AliTRDanalyzeDigits> No TRD detector found" << endl;
344 // Get the digitizer object
345 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
346 AliTRDparameter *parameter = (AliTRDparameter *) file->Get("TRDparameter");
348 cout << "<AliTRDanalyzeDigits> No parameter object found" << endl;
353 // Define the histograms
354 Int_t adcRange = ((Int_t) parameter->GetADCoutRange());
355 TH1F *hAmpAll = new TH1F("hAmpAll" ,"Amplitude of the digits (all)"
356 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
357 TH1F *hAmpEl = new TH1F("hAmpEl" ,"Amplitude of the digits (electrons)"
358 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
359 TH1F *hAmpPi = new TH1F("hAmpPi" ,"Amplitude of the digits (pions)"
360 ,adcRange+1,-0.5,((Float_t) adcRange)+0.5);
361 TH1F *hAmpNoise = new TH1F("hAmpNoise","Amplitude of the digits (noise)"
364 // Get the pointer to the geometry object
367 geo = trd->GetGeometry();
370 cout << "<AliTRDanalyzeDigits> No TRD geometry found" << endl;
375 // Create the digits manager
376 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
377 digitsManager->SetDebug(1);
379 digitsManager->Open("TRD_test.root");
381 // Read the digits from the file
382 if (!(digitsManager->ReadDigits())) {
383 cout << "<AliTRDanalyzeDigits> Cannot read the digits" << endl;
388 AliTRDmatrix *matrix;
390 Int_t countDigits = 0;
391 Int_t iSec = trd->GetSensSector();
392 Int_t iCha = trd->GetSensChamber();
393 Int_t timeMax = parameter->GetTimeTotal();
395 TProfile *hAmpTimeEl = new TProfile("hAmpTimeEl","Amplitude of the digits (electrons)"
396 ,timeMax,-0.5,((Double_t) timeMax)-0.5);
397 TProfile *hAmpTimePi = new TProfile("hAmpTimePi","Amplitude of the digits (pions)"
398 ,timeMax,-0.5,((Double_t) timeMax)-0.5);
400 // Loop over all planes
401 for (Int_t iPla = 0; iPla < kNpla; iPla++) {
403 Int_t iDet = geo->GetDetector(iPla,iCha,iSec);
404 Int_t rowMax = parameter->GetRowMax(iPla,iCha,iSec);
405 Int_t colMax = parameter->GetColMax(iPla);
408 matrix = new AliTRDmatrix(rowMax,colMax,timeMax,iSec,iCha,iPla);
411 // Loop through the detector pixel
412 for (Int_t time = 0; time < timeMax; time++) {
413 for (Int_t col = 0; col < colMax; col++) {
414 for (Int_t row = 0; row < rowMax; row++) {
416 AliTRDdigit *digit = digitsManager->GetDigit(row,col,time,iDet);
417 Int_t amp = digit->GetAmp();
418 Int_t track0 = digitsManager->GetTrack(0,row,col,time,iDet);
419 Int_t track1 = digitsManager->GetTrack(1,row,col,time,iDet);
420 TParticle *particle = 0;
422 particle = gAlice->Particle(track0);
428 matrix->SetSignal(row,col,time,amp);
437 hAmpNoise->Fill(amp);
441 if ((particle) && (particle->GetPdgCode() == 11) && (track1 < 0)) {
443 hAmpTimeEl->Fill(time,amp);
447 if ((particle) && (particle->GetPdgCode() == -211) && (track1 < 0)) {
449 hAmpTimePi->Fill(time,amp);
460 cout << "<AliTRDanalyzeDigits> Found " << countDigits << " digits in total" << endl;
462 // Display the detector matrix
465 TCanvas *cDigits = new TCanvas("cDigits","AliTRDanalyzeDigits",50,50,600,800);
466 cDigits->Divide(2,3);
469 hAmpAll->SetXTitle("Amplitude (ADC-channels)");
470 hAmpAll->SetYTitle("Entries");
474 hAmpNoise->SetXTitle("Amplitude (ADC-channels)");
475 hAmpNoise->SetYTitle("Entries");
479 hAmpEl->SetXTitle("Amplitude (ADC-channels)");
480 hAmpEl->SetYTitle("Entries");
484 hAmpPi->SetXTitle("Amplitude (ADC-channels)");
485 hAmpPi->SetYTitle("Entries");
488 hAmpTimeEl->SetXTitle("Timebin number");
489 hAmpTimeEl->SetYTitle("Mean amplitude");
490 hAmpTimeEl->Draw("HIST");
492 hAmpTimePi->SetXTitle("Timebin number");
493 hAmpTimePi->SetYTitle("Mean amplitude");
494 hAmpTimePi->Draw("HIST");
496 TFile *fileOut = new TFile("digits_test.root","RECREATE");
509 //_____________________________________________________________________________
510 Int_t AliTRDcreateCluster()
513 // Creates the cluster from the digits
518 // Create the clusterizer
519 AliTRDclusterizerV1 *clusterizer = new AliTRDclusterizerV1("TRDclusterizer"
520 ,"TRD clusterizer class");
521 clusterizer->SetVerbose(1);
523 // Define the parameter object
524 // If no external parameter object is defined,
525 // default parameter will be used
526 AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
527 ,"TRD parameter class");
528 parameter->SetClusMaxThresh(0);
529 parameter->SetClusSigThresh(0);
530 clusterizer->SetParameter(parameter);
533 if (!(clusterizer->Open("TRD_test.root",0))) {
539 if (!(clusterizer->ReadDigits())) {
545 if (!(clusterizer->MakeClusters())) {
550 // Write the cluster tree into the file
551 if (!(clusterizer->WriteClusters(-1))) {
556 // Save the clusterizer class in the file
557 if (!(clusterizer->Write())) {
566 //_____________________________________________________________________________
567 Int_t AliTRDanalyzeCluster()
570 // Analyzes the cluster
576 cout << "<AliTRDanalyzeCluster> No AliRun object found" << endl;
582 // Get the pointer to the TRD detector
583 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
585 cout << "<AliTRDanalyzeCluster> No TRD detector found" << endl;
590 // Define the histograms
591 TH1F *hClusAll = new TH1F("hClusAll" ,"Amplitude of the cluster (all)"
593 TH1F *hClusNoise = new TH1F("hClusNoise","Amplitude of the cluster (noise)"
595 TH1F *hClusEl = new TH1F("hClusEl" ,"Amplitude of the cluster (electron)"
597 TH1F *hClusPi = new TH1F("hClusPi" ,"Amplitude of the cluster (pion)"
600 // Get the pointer to the geometry object
603 geo = trd->GetGeometry();
606 cout << "<AliTRDanalyzeCluster> No TRD geometry found" << endl;
611 // Get the pointer to the hit-tree
612 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
613 TTree *clusterTree = (TTree *) file->Get("TreeR0_TRD");
614 if (!(clusterTree)) {
615 cout << "<AliTRDanalyzeCluster> No tree with clusters found" << endl;
620 // Get the pointer to the hit container
621 TObjArray *clusterArray = trd->RecPoints();
622 if (!(clusterArray)) {
623 cout << "<AliTRDanalyzeCluster> No clusterArray found" << endl;
628 // Set the branch address
629 clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray);
630 Int_t nEntries = clusterTree->GetEntries();
631 cout << "<AliTRDanalyzeCluster> Number of entries in the cluster tree = "
635 Int_t countCluster = 0;
636 Int_t countOverlap = 0;
638 // Loop through all entries in the tree
640 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
643 nbytes += clusterTree->GetEvent(iEntry);
645 // Get the number of points in the detector
646 Int_t nCluster = clusterArray->GetEntriesFast();
648 // Loop through all TRD digits
649 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
651 // Get the information for this digit
652 AliTRDcluster *cluster = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster);
653 Int_t detector = cluster->GetDetector();
654 Int_t sector = geo->GetSector(detector);
655 Int_t plane = geo->GetPlane(detector);
656 Int_t chamber = geo->GetChamber(detector);
657 Float_t energy = cluster->GetQ();
658 Int_t track0 = cluster->GetLabel(0);
659 Int_t track1 = cluster->GetLabel(1);
660 Int_t track2 = cluster->GetLabel(2);
661 TParticle *particle = 0;
663 particle = gAlice->Particle(track0);
667 if (!cluster->Isolated()) countOverlap++;
670 hClusAll->Fill(energy);
672 if (cluster->Isolated()) {
676 hClusNoise->Fill(energy);
680 if ((particle) && (particle->GetPdgCode() == 11) && (track1 < 0)) {
681 hClusEl->Fill(energy);
685 if ((particle) && (particle->GetPdgCode() == -211) && (track1 < 0)) {
686 hClusPi->Fill(energy);
695 cout << "<AliTRDanalyzeCluster> Found " << countCluster << " cluster in total" << endl;
696 cout << "<AliTRDanalyzeCluster> Found " << countOverlap << " overlapping cluster" << endl;
699 TCanvas *cCluster = new TCanvas("cCluster","AliTRDanalyzeCluster",50,50,600,600);
700 cCluster->Divide(2,2);
705 hClusAll->Fit("landau","0");
706 fun = (TF1 *) hClusAll->GetListOfFunctions()->First();
707 Float_t meanAll = fun->GetParameter(1);
709 fun->SetLineColor(2);
714 Float_t meanNoise = hClusNoise->GetMean();
719 hClusEl->Fit("landau","0");
720 fun = (TF1 *) hClusEl->GetListOfFunctions()->First();
721 fun->SetLineColor(2);
722 Float_t meanEl = fun->GetParameter(1);
728 hClusPi->Fit("landau","0");
729 fun = (TF1 *) hClusPi->GetListOfFunctions()->First();
730 fun->SetLineColor(2);
731 Float_t meanPi = fun->GetParameter(1);
736 cout << "##################################################################" << endl;
737 cout << " Mean all = " << meanAll << endl;
738 cout << " Mean noise = " << meanNoise << endl;
739 cout << " Mean electrons = " << meanEl << endl;
740 cout << " Mean pions = " << meanPi << endl;
741 cout << "##################################################################" << endl;
748 //_____________________________________________________________________________
749 Int_t AliTRDcreateTracks()
752 // Creates the tracks
757 // Create the tracker
758 AliTRDtracker *tracker = new AliTRDtracker("TRDtracker","TRD tracker");
760 // Read in the kine tree and the cluster
761 tracker->GetEvent("TRD_test.root","TRD_test.root");
764 TH1F *hs = new TH1F("hs","hs",100,0.0,1.0);
765 TH1F *hd = new TH1F("hd","hd",100,0.0,1.0);
766 tracker->Clusters2Tracks(hs,hd);
769 tracker->WriteTracks("TRD_test.root");