]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDmatrix.cxx
Cleaned up code for coding conventions.
[u/mrichter/AliRoot.git] / TRD / AliTRDmatrix.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Contains the pixel information for one TRD chamber                       //
21 //                                                                           //
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include <TObjArray.h>
26 #include <TH2.h>
27 #include <TH3.h>
28 #include <TStyle.h>
29 #include <TCanvas.h>
30
31 #include "AliTRDmatrix.h"
32 #include "AliTRDpixel.h"
33
34 ClassImp(AliTRDmatrix)
35
36 //_____________________________________________________________________________
37 AliTRDmatrix::AliTRDmatrix():TObject()
38 {
39   //
40   // Create a TRD detector matrix
41   // 
42  
43   fRow        = 0;
44   fCol        = 0;
45   fTime       = 0;
46   fPixel      = 0;
47   fSector     = 0;
48   fChamber    = 0;
49   fPlane      = 0;
50   fPixelArray = NULL;
51
52 }
53
54 //_____________________________________________________________________________
55 AliTRDmatrix::AliTRDmatrix(Int_t nRow, Int_t nCol, Int_t nTime
56                          , Int_t iSec, Int_t iCha, Int_t iPla)
57              :TObject()
58 {
59   //
60   // Create a TRD detector matrix with a given size
61   // 
62
63   fRow        = nRow;
64   fCol        = nCol;
65   fTime       = nTime;
66   fPixel      = nRow * nCol * nTime;
67   fSector     = iSec;
68   fChamber    = iCha;
69   fPlane      = iPla;
70   fPixelArray = new TObjArray(fPixel);
71   for (Int_t iPixel = 0; iPixel < fPixel; iPixel++) {
72     AliTRDpixel *pixel = new AliTRDpixel();
73     fPixelArray->Add(pixel);
74   }
75
76 }
77
78 //_____________________________________________________________________________
79 AliTRDmatrix::AliTRDmatrix(const AliTRDmatrix &m):TObject(m)
80 {
81   //
82   // AliTRDmatrix copy constructor
83   //
84
85   ((AliTRDmatrix &) m).Copy(*this);
86
87 }
88
89 //_____________________________________________________________________________
90 AliTRDmatrix::~AliTRDmatrix()
91 {
92   //
93   // AliTRDmatrix destructor
94   //
95
96   if (fPixelArray) {
97     fPixelArray->Delete();
98     delete fPixelArray;
99   }
100
101 }
102
103 //_____________________________________________________________________________
104 AliTRDmatrix &AliTRDmatrix::operator=(const AliTRDmatrix &m)
105 {
106   //
107   // Assignment operator
108   //
109
110   if (this != &m) ((AliTRDmatrix &) m).Copy(*this);
111   return *this;
112
113 }
114
115 //_____________________________________________________________________________
116 void AliTRDmatrix::AddSignal(Int_t iRow, Int_t iCol, Int_t iTime, Float_t signal)
117 {
118   //
119   // Add a value to the amplitude of the signal for one specific pixel
120   //
121
122   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
123   if (pixel) {
124     signal += pixel->GetSignal();
125     pixel->SetSignal(signal);
126   }
127
128 }
129
130 //_____________________________________________________________________________
131 void AliTRDmatrix::Copy(TObject &m)
132 {
133   //
134   // Copy function
135   //
136
137   ((AliTRDmatrix &) m).fRow        = fRow;
138   ((AliTRDmatrix &) m).fCol        = fCol;
139   ((AliTRDmatrix &) m).fTime       = fTime;
140   ((AliTRDmatrix &) m).fPixel      = fPixel;
141   ((AliTRDmatrix &) m).fSector     = fSector;
142   ((AliTRDmatrix &) m).fChamber    = fChamber;
143   ((AliTRDmatrix &) m).fPlane      = fPlane;
144
145   ((AliTRDmatrix &) m).fPixelArray = new TObjArray(*fPixelArray);
146
147 }
148
149 //_____________________________________________________________________________
150 void AliTRDmatrix::Draw(Option_t *)
151 {
152   //
153   // Draws a 3D view of the detector matrix
154   //
155
156   Char_t ctitle[50];
157   sprintf(ctitle,"Matrix (Sector:%d Chamber:%d Plane:%d)"
158                 ,fSector,fChamber,fPlane);
159   TH3F *hMatrix = new TH3F("hMatrix",ctitle,fRow ,-0.5,fRow -0.5
160                                            ,fCol ,-0.5,fCol -0.5
161                                            ,fTime,-0.5,fTime-0.5);
162
163   for (Int_t iRow  = 0; iRow  < fRow;  iRow++ ) {
164     for (Int_t iCol  = 0; iCol  < fCol;  iCol++ ) {
165       for (Int_t iTime = 0; iTime < fTime; iTime++) {
166         AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
167         if (pixel) hMatrix->Fill(iRow,iCol,iTime,pixel->GetSignal());
168       }
169     }
170   }
171
172   gStyle->SetOptStat(0);
173   TCanvas *cMatrix = new TCanvas("cMatrix","Detector matrix 3D-view"
174                                           ,50,50,600,400);
175   cMatrix->ToggleEventStatus();
176   hMatrix->SetXTitle("Pad-row (z)");
177   hMatrix->SetYTitle("Pad-column (rphi)");
178   hMatrix->SetZTitle("Timebucket");
179   hMatrix->Draw("BOX");
180
181 }
182
183 //_____________________________________________________________________________
184 void AliTRDmatrix::DrawRow(Int_t iRow)
185 {
186   //
187   // Draws a 2D slice of the detector matrix along one row
188   //
189
190   if ((iRow < 0) || (iRow >= fRow)) {
191     printf("AliTRDmatrix::DrawRow -- ");
192     printf("Index out of bounds (%d/%d)\n",iRow,fRow);
193     return;
194   }
195
196   Char_t ctitle[50];
197   sprintf(ctitle,"Pad-row %d (Sector:%d Chamber:%d Plane:%d)"
198                 ,iRow,fSector,fChamber,fPlane);
199   TH2F *hSliceRow = new TH2F("hSliceRow",ctitle,fCol ,-0.5,fCol -0.5
200                                                ,fTime,-0.5,fTime-0.5);
201
202   for (Int_t iCol  = 0; iCol  < fCol;  iCol++ ) {
203     for (Int_t iTime = 0; iTime < fTime; iTime++) {
204       AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
205       if (pixel) hSliceRow->Fill(iCol,iTime,pixel->GetSignal());
206     }
207   }
208
209   gStyle->SetOptStat(0);
210   TCanvas *cSliceRow = new TCanvas("cSliceRow","Detector matrix 2D-slice"
211                                               ,50,50,600,400);
212   cSliceRow->ToggleEventStatus();
213   hSliceRow->SetXTitle("Pad-column (rphi)");
214   hSliceRow->SetYTitle("Timebucket");
215   hSliceRow->Draw("COLZ");
216
217 }
218
219 //_____________________________________________________________________________
220 void AliTRDmatrix::DrawCol(Int_t iCol)
221 {
222   //
223   // Draws a 2D slice of the detector matrix along one column
224   //
225
226   if ((iCol < 0) || (iCol >= fCol)) {
227     printf("AliTRDmatrix::DrawCol -- ");
228     printf("Index out of bounds (%d/%d)\n",iCol,fCol);
229     return;
230   }
231
232   Char_t ctitle[50];
233   sprintf(ctitle,"Pad-column %d (Sector:%d Chamber:%d Plane:%d)"
234                 ,iCol,fSector,fChamber,fPlane);
235   TH2F *hSliceCol = new TH2F("hSliceCol",ctitle,fRow ,-0.5,fRow -0.5
236                                                ,fTime,-0.5,fTime-0.5);
237
238   for (Int_t iRow  = 0; iRow  < fRow;  iRow++ ) {
239     for (Int_t iTime = 0; iTime < fTime; iTime++) {
240       AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
241       if (pixel) hSliceCol->Fill(iRow,iTime,pixel->GetSignal());
242     }
243   }
244
245   gStyle->SetOptStat(0);
246   TCanvas *cSliceCol = new TCanvas("cSliceCol","Detector matrix 2D-slice"
247                                               ,50,50,600,400);
248   cSliceCol->ToggleEventStatus();
249   hSliceCol->SetXTitle("Pad-row (z)");
250   hSliceCol->SetYTitle("Timebucket");
251   hSliceCol->Draw("COLZ");
252
253 }
254
255 //_____________________________________________________________________________
256 void AliTRDmatrix::DrawTime(Int_t iTime)
257 {
258   //
259   // Draws a 2D slice of the detector matrix along one time slice
260   //
261
262   if ((iTime < 0) || (iTime >= fTime)) {
263     printf("AliTRDmatrix::DrawTime -- ");
264     printf("Index out of bounds (%d/%d)\n",iTime,fTime);
265     return;
266   }
267
268   Char_t ctitle[50];
269   sprintf(ctitle,"Time-slice %d (Sector:%d Chamber:%d Plane:%d)"
270                 ,iTime,fSector,fChamber,fPlane);
271   TH2F *hSliceTime = new TH2F("hSliceTime",ctitle,fRow,-0.5,fRow-0.5
272                                                  ,fCol,-0.5,fCol-0.5);
273
274   for (Int_t iRow = 0; iRow < fRow; iRow++) {
275     for (Int_t iCol = 0; iCol < fCol; iCol++) {
276       AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
277       if (pixel) hSliceTime->Fill(iRow,iCol,pixel->GetSignal());
278     }
279   }
280
281   gStyle->SetOptStat(0);
282   TCanvas *cSliceTime = new TCanvas("cSliceTime","Detector matrix 2D-slice"
283                                                 ,50,50,600,400);
284   cSliceTime->ToggleEventStatus();
285   hSliceTime->SetXTitle("Pad-row (z)");
286   hSliceTime->SetYTitle("Pad-column (rphi)");
287   hSliceTime->Draw("COLZ");
288
289 }
290
291 //_____________________________________________________________________________
292 void AliTRDmatrix::ProjRow()
293 {
294   //
295   // Projects the detector matrix along the row-axis
296   //
297
298   Char_t ctitle[60];
299   sprintf(ctitle,"Row-projection (Sector:%d Chamber:%d Plane:%d)"
300                 ,fSector,fChamber,fPlane);
301   TH2F *hProjRow = new TH2F("hProjRow",ctitle,fCol ,-0.5,fCol -0.5
302                                              ,fTime,-0.5,fTime-0.5);
303
304   for (Int_t iRow  = 0; iRow  < fRow;  iRow++ ) {
305     for (Int_t iCol  = 0; iCol  < fCol;  iCol++ ) {
306       for (Int_t iTime = 0; iTime < fTime; iTime++) {
307         AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
308         if (pixel) hProjRow->Fill(iCol,iTime,pixel->GetSignal());
309       }
310     }
311   }
312
313   gStyle->SetOptStat(0);
314   TCanvas *cProjRow = new TCanvas("cProjRow","Detector matrix 2D-projection"
315                                             ,50,50,600,400);
316   cProjRow->ToggleEventStatus();
317   hProjRow->SetXTitle("Pad-column (rphi)");
318   hProjRow->SetYTitle("Timebucket");
319   hProjRow->Draw("COLZ");
320
321 }
322
323 //_____________________________________________________________________________
324 void AliTRDmatrix::ProjCol()
325 {
326   //
327   // Projects the detector matrix along the column-axis
328   //
329
330   Char_t ctitle[60];
331   sprintf(ctitle,"Column-projection (Sector:%d Chamber:%d Plane:%d)"
332                 ,fSector,fChamber,fPlane);
333   TH2F *hProjCol = new TH2F("hProjCol",ctitle,fRow ,-0.5,fRow -0.5
334                                              ,fTime,-0.5,fTime-0.5);
335
336   for (Int_t iRow  = 0; iRow  < fRow;  iRow++ ) {
337     for (Int_t iCol  = 0; iCol  < fCol;  iCol++ ) {
338       for (Int_t iTime = 0; iTime < fTime; iTime++) {
339         AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
340         if (pixel) hProjCol->Fill(iRow,iTime,pixel->GetSignal());
341       }
342     }
343   }
344
345   gStyle->SetOptStat(0);
346   TCanvas *cProjCol = new TCanvas("cProjCol","Detector matrix 2D-projection"
347                                             ,50,50,600,400);
348   cProjCol->ToggleEventStatus();
349   hProjCol->SetXTitle("Pad-row (z)");
350   hProjCol->SetYTitle("Timebucket");
351   hProjCol->Draw("COLZ");
352
353 }
354
355 //_____________________________________________________________________________
356 void AliTRDmatrix::ProjTime()
357 {
358   //
359   // Projects the detector matrix along the time-axis
360   //
361
362   Char_t ctitle[60];
363   sprintf(ctitle,"Time-projection (Sector:%d Chamber:%d Plane:%d)"
364                 ,fSector,fChamber,fPlane);
365   TH2F *hProjTime = new TH2F("hProjTime",ctitle,fRow,-0.5,fRow-0.5
366                                                ,fCol,-0.5,fCol-0.5);
367
368   for (Int_t iRow = 0; iRow < fRow; iRow++) {
369     for (Int_t iCol = 0; iCol < fCol; iCol++) {
370       for (Int_t iTime = 0; iTime < fTime; iTime++) {
371         AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
372         if (pixel) hProjTime->Fill(iRow,iCol,pixel->GetSignal());
373       }
374     }
375   }
376
377   gStyle->SetOptStat(0);
378   TCanvas *cProjTime = new TCanvas("cProjTime","Detector matrix 2D-projection"
379                                               ,50,50,600,400);
380   cProjTime->ToggleEventStatus();
381   hProjTime->SetXTitle("Pad-row (z)");
382   hProjTime->SetYTitle("Pad-column (rphi)");
383   hProjTime->Draw("COLZ");
384
385 }
386
387 //_____________________________________________________________________________
388 void AliTRDmatrix::SetSignal(Int_t iRow, Int_t iCol, Int_t iTime, Float_t signal)
389 {
390   //
391   // Set the amplitude of the signal for one specific pixel
392   //
393
394   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
395   if (pixel) {
396     pixel->SetSignal(signal);
397   }
398
399 }
400
401 //_____________________________________________________________________________
402 Bool_t AliTRDmatrix::AddTrack(Int_t iRow, Int_t iCol, Int_t iTime, Int_t track)
403 {
404   // 
405   // Add this track number to the stored tracks passing through this pixel. 
406   // If there are already three stored the return status is FALSE.  
407   //
408
409   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
410   if (!(pixel)) return kTRUE;
411
412   Bool_t trackSet = kFALSE;
413   for (Int_t i = 0; i < AliTRDpixel::NTrackPixel(); i++) {
414     if (pixel->GetTrack(i) == track) {
415       trackSet = kTRUE;
416       break;
417     }
418     if (pixel->GetTrack(i) ==    -1) {
419       pixel->SetTrack(i,track);
420       trackSet = kTRUE;
421       break;
422     }
423   }    
424
425   return trackSet;
426
427 }
428
429 //_____________________________________________________________________________
430 void AliTRDmatrix::SetTrack(Int_t iRow, Int_t iCol, Int_t iTime
431                           , Int_t iTrack, Int_t track)
432 {
433   //
434   // Store the number of a track which is passing through this pixel
435   //
436
437   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
438   if (pixel) {
439     pixel->SetTrack(iTrack,track);
440   }
441
442 }
443
444 //_____________________________________________________________________________
445 Float_t AliTRDmatrix::GetSignal(Int_t iRow, Int_t iCol, Int_t iTime) const
446 {
447   //
448   // Returns the amplitude of the signal for one specific pixel
449   //
450
451   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
452   if (pixel) {
453     return (pixel->GetSignal());
454   }
455   else {
456     return 0;
457   }
458
459 }
460
461 //_____________________________________________________________________________
462 Int_t AliTRDmatrix::GetTrack(Int_t iRow, Int_t iCol, Int_t iTime
463                            , Int_t iTrack) const 
464 {
465   //
466   // Returns the numbers of the tracks passing through one specific pixel
467   //
468
469   if ((iTrack < 0) || (iTrack >= AliTRDpixel::NTrackPixel())) {
470     printf("AliTRDmatrix::GetTrack -- ");
471     printf("Index out of bounds (%d)\n",iTrack);
472     return -1;
473   }
474
475   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
476   if (pixel) {
477     return (pixel->GetTrack(iTrack));
478   }
479   else {
480     return -1;
481   }
482
483 }
484
485 //_____________________________________________________________________________
486 Int_t AliTRDmatrix::GetIndex(Int_t iRow, Int_t iCol, Int_t iTime) const
487 {
488   //
489   // Get the index of a given pixel
490   //
491
492   if ((iRow  >= 0) && (iRow  < fRow ) &&
493       (iCol  >= 0) && (iCol  < fCol ) &&
494       (iTime >= 0) && (iTime < fTime)) {
495     return (iTime + iCol * fTime + iRow * fTime * fCol);
496   }
497   else {
498     return -1;
499   }
500
501 }
502
503 //_____________________________________________________________________________
504 AliTRDpixel *AliTRDmatrix::GetPixel(Int_t iRow, Int_t iCol, Int_t iTime) const
505 {
506   //
507   // Get one pixel
508   //
509
510   Int_t iPixel = GetIndex(iRow,iCol,iTime);
511   if (iPixel < 0) {
512     return NULL;
513   }
514   else {
515     return ((AliTRDpixel *) fPixelArray->At(iPixel));
516   }
517
518 }