]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDmatrix.cxx
Only one declaration of iDict in MakeDigits()
[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.4  2000/02/28 19:10:26  cblume
19 Include the new TRD classes
20
21 Revision 1.3.4.1  2000/02/28 17:57:47  cblume
22 GetTrack returns now -1 if no track is found
23
24 Revision 1.3  1999/10/04 14:48:07  fca
25 Avoid warnings on non-ansi compiler HP-UX CC
26
27 Revision 1.2  1999/09/29 09:24:35  fca
28 Introduction of the Copyright and cvs Log
29
30 */
31
32 ///////////////////////////////////////////////////////////////////////////////
33 //                                                                           //
34 //  Contains the pixel information for one TRD chamber                       //
35 //                                                                           //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include "AliTRDmatrix.h"
39
40 ClassImp(AliTRDmatrix)
41
42 //_____________________________________________________________________________
43 AliTRDmatrix::AliTRDmatrix():TObject()
44 {
45   //
46   // Create a TRD detector matrix
47   // 
48  
49   fRow        = 0;
50   fCol        = 0;
51   fTime       = 0;
52   fPixel      = 0;
53   fSector     = 0;
54   fChamber    = 0;
55   fPlane      = 0;
56   fPixelArray = NULL;
57
58 }
59
60 //_____________________________________________________________________________
61 AliTRDmatrix::AliTRDmatrix(Int_t nRow, Int_t nCol, Int_t nTime
62                          , Int_t iSec, Int_t iCha, Int_t iPla)
63              :TObject()
64 {
65   //
66   // Create a TRD detector matrix with a given size
67   // 
68
69   fRow        = nRow;
70   fCol        = nCol;
71   fTime       = nTime;
72   fPixel      = nRow * nCol * nTime;
73   fSector     = iSec;
74   fChamber    = iCha;
75   fPlane      = iPla;
76   fPixelArray = new TObjArray(fPixel);
77   for (Int_t iPixel = 0; iPixel < fPixel; iPixel++) {
78     AliTRDpixel *pixel = new AliTRDpixel();
79     fPixelArray->Add(pixel);
80   }
81
82 }
83
84 //_____________________________________________________________________________
85 AliTRDmatrix::~AliTRDmatrix()
86 {
87
88   if (fPixelArray) {
89     fPixelArray->Delete();
90     delete fPixelArray;
91   }
92
93 }
94
95 //_____________________________________________________________________________
96 void AliTRDmatrix::AddSignal(Int_t iRow, Int_t iCol, Int_t iTime, Float_t signal)
97 {
98   //
99   // Add a value to the amplitude of the signal for one specific pixel
100   //
101
102   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
103   if (pixel) {
104     signal += pixel->GetSignal();
105     pixel->SetSignal(signal);
106   }
107
108 }
109
110 //_____________________________________________________________________________
111 void AliTRDmatrix::Draw(Option_t *)
112 {
113   //
114   // Draws a 3D view of the detector matrix
115   //
116
117   Char_t ctitle[50];
118   sprintf(ctitle,"Matrix (Sector:%d Chamber:%d Plane:%d)"
119                 ,fSector,fChamber,fPlane);
120   TH3F *hMatrix = new TH3F("hMatrix",ctitle,fRow ,-0.5,fRow +0.5
121                                            ,fCol ,-0.5,fCol +0.5
122                                            ,fTime,-0.5,fTime+0.5);
123
124   for (Int_t iRow  = 0; iRow  < fRow;  iRow++ ) {
125     for (Int_t iCol  = 0; iCol  < fCol;  iCol++ ) {
126       for (Int_t iTime = 0; iTime < fTime; iTime++) {
127         AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
128         if (pixel) hMatrix->Fill(iRow,iCol,iTime,pixel->GetSignal());
129       }
130     }
131   }
132
133   gStyle->SetOptStat(0);
134   TCanvas *cMatrix = new TCanvas("cMatrix","Detector matrix 3D-view"
135                                           ,50,50,600,400);
136   cMatrix->ToggleEventStatus();
137   hMatrix->SetXTitle("Pad-row (z)");
138   hMatrix->SetYTitle("Pad-column (rphi)");
139   hMatrix->SetZTitle("Timebucket");
140   hMatrix->Draw("BOX");
141
142 }
143
144 //_____________________________________________________________________________
145 void AliTRDmatrix::DrawRow(Int_t iRow)
146 {
147   //
148   // Draws a 2D slice of the detector matrix along one row
149   //
150
151   if ((iRow < 0) || (iRow >= fRow)) {
152     printf("AliTRDmatrix::DrawRow -- ");
153     printf("Index out of bounds (%d/%d)\n",iRow,fRow);
154     return;
155   }
156
157   Char_t ctitle[50];
158   sprintf(ctitle,"Pad-row %d (Sector:%d Chamber:%d Plane:%d)"
159                 ,iRow,fSector,fChamber,fPlane);
160   TH2F *hSliceRow = new TH2F("hSliceRow",ctitle,fCol ,-0.5,fCol +0.5
161                                                ,fTime,-0.5,fTime+0.5);
162
163   for (Int_t iCol  = 0; iCol  < fCol;  iCol++ ) {
164     for (Int_t iTime = 0; iTime < fTime; iTime++) {
165       AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
166       if (pixel) hSliceRow->Fill(iCol,iTime,pixel->GetSignal());
167     }
168   }
169
170   gStyle->SetOptStat(0);
171   TCanvas *cSliceRow = new TCanvas("cSliceRow","Detector matrix 2D-slice"
172                                               ,50,50,600,400);
173   cSliceRow->ToggleEventStatus();
174   hSliceRow->SetXTitle("Pad-column (rphi)");
175   hSliceRow->SetYTitle("Timebucket");
176   hSliceRow->Draw("COLZ");
177
178 }
179
180 //_____________________________________________________________________________
181 void AliTRDmatrix::DrawCol(Int_t iCol)
182 {
183   //
184   // Draws a 2D slice of the detector matrix along one column
185   //
186
187   if ((iCol < 0) || (iCol >= fCol)) {
188     printf("AliTRDmatrix::DrawCol -- ");
189     printf("Index out of bounds (%d/%d)\n",iCol,fCol);
190     return;
191   }
192
193   Char_t ctitle[50];
194   sprintf(ctitle,"Pad-column %d (Sector:%d Chamber:%d Plane:%d)"
195                 ,iCol,fSector,fChamber,fPlane);
196   TH2F *hSliceCol = new TH2F("hSliceCol",ctitle,fRow ,-0.5,fRow +0.5
197                                                ,fTime,-0.5,fTime+0.5);
198
199   for (Int_t iRow  = 0; iRow  < fRow;  iRow++ ) {
200     for (Int_t iTime = 0; iTime < fTime; iTime++) {
201       AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
202       if (pixel) hSliceCol->Fill(iRow,iTime,pixel->GetSignal());
203     }
204   }
205
206   gStyle->SetOptStat(0);
207   TCanvas *cSliceCol = new TCanvas("cSliceCol","Detector matrix 2D-slice"
208                                               ,50,50,600,400);
209   cSliceCol->ToggleEventStatus();
210   hSliceCol->SetXTitle("Pad-row (z)");
211   hSliceCol->SetYTitle("Timebucket");
212   hSliceCol->Draw("COLZ");
213
214 }
215
216 //_____________________________________________________________________________
217 void AliTRDmatrix::DrawTime(Int_t iTime)
218 {
219   //
220   // Draws a 2D slice of the detector matrix along one time slice
221   //
222
223   if ((iTime < 0) || (iTime >= fTime)) {
224     printf("AliTRDmatrix::DrawTime -- ");
225     printf("Index out of bounds (%d/%d)\n",iTime,fTime);
226     return;
227   }
228
229   Char_t ctitle[50];
230   sprintf(ctitle,"Time-slice %d (Sector:%d Chamber:%d Plane:%d)"
231                 ,iTime,fSector,fChamber,fPlane);
232   TH2F *hSliceTime = new TH2F("hSliceTime",ctitle,fRow,-0.5,fRow+0.5
233                                                  ,fCol,-0.5,fCol+0.5);
234
235   for (Int_t iRow = 0; iRow < fRow; iRow++) {
236     for (Int_t iCol = 0; iCol < fCol; iCol++) {
237       AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
238       if (pixel) hSliceTime->Fill(iRow,iCol,pixel->GetSignal());
239     }
240   }
241
242   gStyle->SetOptStat(0);
243   TCanvas *cSliceTime = new TCanvas("cSliceTime","Detector matrix 2D-slice"
244                                                 ,50,50,600,400);
245   cSliceTime->ToggleEventStatus();
246   hSliceTime->SetXTitle("Pad-row (z)");
247   hSliceTime->SetYTitle("Pad-column (rphi)");
248   hSliceTime->Draw("COLZ");
249
250 }
251
252 //_____________________________________________________________________________
253 void AliTRDmatrix::SetSignal(Int_t iRow, Int_t iCol, Int_t iTime, Float_t signal)
254 {
255   //
256   // Set the amplitude of the signal for one specific pixel
257   //
258
259   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
260   if (pixel) {
261     pixel->SetSignal(signal);
262   }
263
264 }
265
266 //_____________________________________________________________________________
267 Bool_t AliTRDmatrix::AddTrack(Int_t iRow, Int_t iCol, Int_t iTime, Int_t track)
268 {
269   // 
270   // Add this track number to the stored tracks passing through this pixel. 
271   // If there are already three stored the return status is FALSE.  
272   //
273
274   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
275   if (!(pixel)) return kTRUE;
276
277   Bool_t trackSet = kFALSE;
278   for (Int_t i = 0; i < kTrackPixel; i++) {
279     if (pixel->GetTrack(i) == track) {
280       trackSet = kTRUE;
281       break;
282     }
283     if (pixel->GetTrack(i) ==    -1) {
284       pixel->SetTrack(i,track);
285       trackSet = kTRUE;
286       break;
287     }
288   }    
289
290   return trackSet;
291
292 }
293
294 //_____________________________________________________________________________
295 void AliTRDmatrix::SetTrack(Int_t iRow, Int_t iCol, Int_t iTime
296                           , Int_t iTrack, Int_t track)
297 {
298   //
299   // Store the number of a track which is passing through this pixel
300   //
301
302   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
303   if (pixel) {
304     pixel->SetTrack(iTrack,track);
305   }
306
307 }
308
309 //_____________________________________________________________________________
310 Float_t AliTRDmatrix::GetSignal(Int_t iRow, Int_t iCol, Int_t iTime)
311 {
312   //
313   // Returns the amplitude of the signal for one specific pixel
314   //
315
316   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
317   if (pixel) {
318     return (pixel->GetSignal());
319   }
320   else {
321     return 0;
322   }
323
324 }
325
326 //_____________________________________________________________________________
327 Int_t AliTRDmatrix::GetTrack(Int_t iRow, Int_t iCol, Int_t iTime, Int_t iTrack)
328 {
329   //
330   // Returns the numbers of the tracks passing through one specific pixel
331   //
332
333   if ((iTrack < 0) || (iTrack >= kTrackPixel)) {
334     printf("AliTRDmatrix::GetTrack -- ");
335     printf("Index out of bounds (%d)\n",iTrack);
336     return -1;
337   }
338
339   AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
340   if (pixel) {
341     return (pixel->GetTrack(iTrack));
342   }
343   else {
344     return -1;
345   }
346
347 }
348
349 //_____________________________________________________________________________
350 Int_t AliTRDmatrix::GetIndex(Int_t iRow, Int_t iCol, Int_t iTime)
351 {
352
353   if ((iRow  >= 0) && (iRow  < fRow ) &&
354       (iCol  >= 0) && (iCol  < fCol ) &&
355       (iTime >= 0) && (iTime < fTime)) {
356     return (iTime + iCol * fTime + iRow * fTime * fCol);
357   }
358   else {
359     return -1;
360   }
361
362 }
363
364 //_____________________________________________________________________________
365 AliTRDpixel *AliTRDmatrix::GetPixel(Int_t iRow, Int_t iCol, Int_t iTime)
366 {
367
368   Int_t iPixel = GetIndex(iRow,iCol,iTime);
369   if (iPixel < 0) {
370     return NULL;
371   }
372   else {
373     return ((AliTRDpixel *) fPixelArray->At(iPixel));
374   }
375
376 }