Transition to NewIO
[u/mrichter/AliRoot.git] / TRD / AliTRDmatrix.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
4c039060 17
99d5402e 18///////////////////////////////////////////////////////////////////////////////
19// //
20// Contains the pixel information for one TRD chamber //
21// //
0a29d0f1 22// //
99d5402e 23///////////////////////////////////////////////////////////////////////////////
24
793ff80c 25#include <TObjArray.h>
26#include <TH2.h>
27#include <TH3.h>
28#include <TStyle.h>
29#include <TCanvas.h>
30
99d5402e 31#include "AliTRDmatrix.h"
793ff80c 32#include "AliTRDpixel.h"
99d5402e 33
34ClassImp(AliTRDmatrix)
35
36//_____________________________________________________________________________
37AliTRDmatrix::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//_____________________________________________________________________________
55AliTRDmatrix::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//_____________________________________________________________________________
dd9a6ee3 79AliTRDmatrix::AliTRDmatrix(const AliTRDmatrix &m)
8230f242 80{
81 //
82 // AliTRDmatrix copy constructor
83 //
84
dd9a6ee3 85 ((AliTRDmatrix &) m).Copy(*this);
8230f242 86
87}
88
89//_____________________________________________________________________________
99d5402e 90AliTRDmatrix::~AliTRDmatrix()
91{
8230f242 92 //
93 // AliTRDmatrix destructor
94 //
99d5402e 95
96 if (fPixelArray) {
97 fPixelArray->Delete();
98 delete fPixelArray;
99 }
100
101}
102
103//_____________________________________________________________________________
dd9a6ee3 104AliTRDmatrix &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//_____________________________________________________________________________
99d5402e 116void 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//_____________________________________________________________________________
dd9a6ee3 131void AliTRDmatrix::Copy(TObject &m)
8230f242 132{
133 //
134 // Copy function
135 //
136
dd9a6ee3 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;
8230f242 144
dd9a6ee3 145 ((AliTRDmatrix &) m).fPixelArray = new TObjArray(*fPixelArray);
8230f242 146
147}
148
149//_____________________________________________________________________________
7d83513f 150void AliTRDmatrix::Draw(Option_t *)
99d5402e 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);
580727b0 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);
99d5402e 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);
1befd3b2 167 if (pixel) hMatrix->Fill(iRow,iCol,iTime,pixel->GetSignal());
99d5402e 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//_____________________________________________________________________________
184void 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)) {
851d3db9 191 printf("AliTRDmatrix::DrawRow -- ");
99d5402e 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);
580727b0 199 TH2F *hSliceRow = new TH2F("hSliceRow",ctitle,fCol ,-0.5,fCol -0.5
200 ,fTime,-0.5,fTime-0.5);
99d5402e 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//_____________________________________________________________________________
220void 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)) {
851d3db9 227 printf("AliTRDmatrix::DrawCol -- ");
99d5402e 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);
580727b0 235 TH2F *hSliceCol = new TH2F("hSliceCol",ctitle,fRow ,-0.5,fRow -0.5
236 ,fTime,-0.5,fTime-0.5);
99d5402e 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//_____________________________________________________________________________
256void 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)) {
851d3db9 263 printf("AliTRDmatrix::DrawTime -- ");
99d5402e 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);
580727b0 271 TH2F *hSliceTime = new TH2F("hSliceTime",ctitle,fRow,-0.5,fRow-0.5
272 ,fCol,-0.5,fCol-0.5);
99d5402e 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//_____________________________________________________________________________
9583ab1c 292void 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);
580727b0 301 TH2F *hProjRow = new TH2F("hProjRow",ctitle,fCol ,-0.5,fCol -0.5
302 ,fTime,-0.5,fTime-0.5);
9583ab1c 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//_____________________________________________________________________________
324void 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);
580727b0 333 TH2F *hProjCol = new TH2F("hProjCol",ctitle,fRow ,-0.5,fRow -0.5
334 ,fTime,-0.5,fTime-0.5);
9583ab1c 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//_____________________________________________________________________________
356void 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);
580727b0 365 TH2F *hProjTime = new TH2F("hProjTime",ctitle,fRow,-0.5,fRow-0.5
366 ,fCol,-0.5,fCol-0.5);
9583ab1c 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//_____________________________________________________________________________
99d5402e 388void 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//_____________________________________________________________________________
402Bool_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;
793ff80c 413 for (Int_t i = 0; i < AliTRDpixel::NTrackPixel(); i++) {
99d5402e 414 if (pixel->GetTrack(i) == track) {
415 trackSet = kTRUE;
416 break;
417 }
851d3db9 418 if (pixel->GetTrack(i) == -1) {
99d5402e 419 pixel->SetTrack(i,track);
420 trackSet = kTRUE;
421 break;
422 }
423 }
424
425 return trackSet;
426
427}
428
429//_____________________________________________________________________________
430void 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//_____________________________________________________________________________
793ff80c 445Float_t AliTRDmatrix::GetSignal(Int_t iRow, Int_t iCol, Int_t iTime) const
99d5402e 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//_____________________________________________________________________________
793ff80c 462Int_t AliTRDmatrix::GetTrack(Int_t iRow, Int_t iCol, Int_t iTime
463 , Int_t iTrack) const
99d5402e 464{
465 //
466 // Returns the numbers of the tracks passing through one specific pixel
467 //
468
793ff80c 469 if ((iTrack < 0) || (iTrack >= AliTRDpixel::NTrackPixel())) {
851d3db9 470 printf("AliTRDmatrix::GetTrack -- ");
471 printf("Index out of bounds (%d)\n",iTrack);
472 return -1;
99d5402e 473 }
474
475 AliTRDpixel *pixel = GetPixel(iRow,iCol,iTime);
476 if (pixel) {
477 return (pixel->GetTrack(iTrack));
478 }
479 else {
851d3db9 480 return -1;
99d5402e 481 }
482
483}
484
485//_____________________________________________________________________________
793ff80c 486Int_t AliTRDmatrix::GetIndex(Int_t iRow, Int_t iCol, Int_t iTime) const
99d5402e 487{
0a29d0f1 488 //
489 // Get the index of a given pixel
490 //
99d5402e 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//_____________________________________________________________________________
793ff80c 504AliTRDpixel *AliTRDmatrix::GetPixel(Int_t iRow, Int_t iCol, Int_t iTime) const
99d5402e 505{
0a29d0f1 506 //
507 // Get one pixel
508 //
99d5402e 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}