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