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