]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFSDigit.cxx
Code Optimization, Review on SDigitization, Test macro to run SDigitization, QA macro...
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigit.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 //_________________________________________________________________________
18 //  TOF sdigit: member variables 
19 //  fSector  : TOF sector
20 //  fPlate   : TOF plate
21 //  fStrip   : strips number
22 //  fPadx    : pad number along x
23 //  fPadz    : pad number along z
24 //  fTdc     : TArrayF of TDC values
25 //  fAdc     : TArrayF of ADC values
26 //              
27 //  Getters, setters and member functions  defined here
28 //
29 //*-- Authors: F. Pierella, A. Seganti, D. Vicinanza
30
31 #include <iostream.h>
32 #include "TArrayF.h"
33 #include "TArrayI.h"
34
35 #include "AliTOF.h"
36 #include "AliTOFSDigit.h"
37 #include "AliTOFConstants.h"
38 #include "AliRun.h"
39 #include "AliMC.h"
40
41 ClassImp(AliTOFSDigit)
42
43 ////////////////////////////////////////////////////////////////////////
44   AliTOFSDigit::AliTOFSDigit()
45 {
46   //
47   // default ctor
48   //
49   fNDigits = 0;
50   fTdc = 0;
51   fAdc = 0;
52   fTracks = 0;
53 }
54
55 ////////////////////////////////////////////////////////////////////////
56 AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t *vol,Float_t *digit)
57 {
58   //
59   // Constructor of digit object
60   //
61   fSector = vol[0];
62   fPlate  = vol[1];
63   fStrip  = vol[2];
64   fPadx   = vol[3];
65   fPadz   = vol[4];
66   fNDigits = 1;
67   fTdc = new TArrayF(fNDigits);
68   (*fTdc)[0] = digit[0];
69   fAdc = new TArrayF(fNDigits);
70   (*fAdc)[0] = digit[1];
71   fTracks = new TArrayI(kMAXDIGITS*fNDigits);
72   (*fTracks)[0] = tracknum;
73   for (Int_t i = 1; i <kMAXDIGITS*fNDigits; i++) {
74     (*fTracks)[i] = -1;
75   }
76 }
77
78 ////////////////////////////////////////////////////////////////////////
79 AliTOFSDigit::AliTOFSDigit(const AliTOFSDigit & digit)
80 {
81   // 
82   // copy ctor for AliTOFSDigit object
83   //
84   fSector = digit.fSector;
85   fPlate  = digit.fPlate;
86   fStrip  = digit.fStrip;
87   fPadx   = digit.fPadx;
88   fPadz   = digit.fPadz;
89   fNDigits = digit.fNDigits;
90   fTdc = new TArrayF(*digit.fTdc);  
91   fAdc = new TArrayF(*digit.fAdc);
92   fTracks = new TArrayI(*digit.fTracks);
93 }
94
95 ////////////////////////////////////////////////////////////////////////
96 AliTOFSDigit::AliTOFSDigit(Int_t sector, Int_t plate, Int_t strip, Int_t padx,
97                            Int_t padz, Float_t tdc, Float_t adc)
98 {
99   //
100   // Constructor for sdigit
101   //
102   fSector = sector;
103   fPlate  = plate;
104   fStrip  = strip;
105   fPadx   = padx;
106   fPadz   = padz;  
107   fNDigits = 1;
108   fTdc = new TArrayF(fNDigits);
109   (*fTdc)[0] = tdc;   
110   fAdc = new TArrayF(fNDigits);
111   (*fAdc)[0] = adc;   
112   // no tracks were specified, set them to -1
113   fTracks = new TArrayI(kMAXDIGITS*fNDigits);
114   for (Int_t i = 0; i <kMAXDIGITS*fNDigits; i++) {
115     (*fTracks)[i] = -1;
116   }
117 }
118
119 ////////////////////////////////////////////////////////////////////////
120 void AliTOFSDigit::GetLocation(Int_t *Loc) const
121 {
122   //
123   // Get the coordinates of the digit
124   // in terms of Sector - Plate - Strip - Pad
125   //
126   
127   Loc[0]=fSector;
128   Loc[1]=fPlate;
129   Loc[2]=fStrip;
130   Loc[3]=fPadx;
131   Loc[4]=fPadz;
132 }
133
134 ////////////////////////////////////////////////////////////////////////
135 void AliTOFSDigit::Update(Int_t tdc, Int_t adc, Int_t track)
136 {
137   //
138   // Add charge and track
139   //
140   
141   Int_t sameTime = -1;
142   
143   for (Int_t i = 0; i < fNDigits; i++) {
144     if (TMath::Abs(tdc-fTdc->At(i)) < AliTOFConstants::fgkTimeDiff) {
145       sameTime = i;
146       break;
147     }
148   }
149   
150   if (sameTime >= 0) {
151     (*fAdc)[sameTime] += static_cast<Float_t>(adc);
152     // update track - find the first -1  value and replace it by the
153     // track number
154     for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
155       if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
156         (*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
157         break;
158       }
159       // write warning about many tracks going to this pad
160       if (iTrack == kMAXDIGITS) {
161         cerr<<"WARNING: AliTOFSDigit::Update  Many hits in the padhit"<<endl;
162         cerr<<"         ";
163         //      PrintPad();
164       }
165     }
166   } else {
167     // add new time slot
168     fNDigits++;
169     fTdc->Set(fNDigits);
170     (*fTdc)[fNDigits-1] = tdc;
171     fAdc->Set(fNDigits);
172     (*fAdc)[fNDigits-1] = adc;
173     fTracks->Set(fNDigits*kMAXDIGITS);
174     (*fTracks)[(fNDigits-1)*kMAXDIGITS] = track;
175     for (Int_t i = 1; i <kMAXDIGITS; i++) {
176       (*fTracks)[(fNDigits-1)*kMAXDIGITS+i] = -1;
177     }
178   }
179   
180 }
181 ////////////////////////////////////////////////////////////////////////
182 AliTOFSDigit::~AliTOFSDigit()
183 {
184   //
185   // dtor
186   //
187   delete fTdc;
188   delete fAdc;
189   delete fTracks;
190 }
191
192 ////////////////////////////////////////////////////////////////////////
193
194 Int_t AliTOFSDigit::GetTotPad() const
195 {
196   //
197   // Get the "total" index of the pad inside a Sector
198   // starting from the digits data.
199   //
200   
201   AliTOF* tof;
202   
203   if(gAlice){
204     tof =(AliTOF*) gAlice->GetDetector("TOF");
205   }else{
206     printf("AliTOFSDigit::GetTotPad - No AliRun object present, exiting");
207     return 0;
208   }
209   
210   Int_t pad = fPadx+tof->GetNpadX()*(fPadz-1);
211   Int_t before=0;
212   
213   switch(fPlate){ 
214   case 1: before = 0;
215     break;
216   case 2: before = tof->GetNStripC();
217     break;
218   case 3: before = tof->GetNStripB() + tof->GetNStripC();
219     break;
220   case 4: before = tof->GetNStripA() + tof->GetNStripB() + tof->GetNStripC();
221     break;
222   case 5: before = tof->GetNStripA() + 2*tof->GetNStripB() + tof->GetNStripC();
223     break;
224   }
225   
226   Int_t strip = fStrip+before;
227   Int_t padTot = tof->GetPadXStr()*(strip-1)+pad;
228   return padTot;
229 }
230