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