]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TOF/AliTOFSDigit.cxx
Clearing SDigits TClonesArray instead of deleting it and recreating a new one.
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigit.cxx
... / ...
CommitLineData
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/* $Id$ */
17
18//_________________________________________________________________________//
19// //
20// TOF sdigit: member variables //
21// fSector : TOF sector //
22// fPlate : TOF plate //
23// fStrip : strips number //
24// fPadx : pad number along x //
25// fPadz : pad number along z //
26// fTdc : TArrayI of TDC values //
27// fAdc : TArrayI of ADC values //
28// //
29// Getters, setters and member functions defined here //
30// //
31// -- Authors: F. Pierella, A. Seganti, D. Vicinanza //
32//_________________________________________________________________________//
33
34//#include "TArrayI.h"
35
36#include "AliLog.h"
37
38#include "AliTOFGeometry.h"
39#include "AliTOFSDigit.h"
40
41ClassImp(AliTOFSDigit)
42
43////////////////////////////////////////////////////////////////////////
44AliTOFSDigit::AliTOFSDigit():
45 fSector(-1),
46 fPlate(-1),
47 fStrip(-1),
48 fPadx(-1),
49 fPadz(-1),
50 fNDigits(0),
51 fTdc(0x0),
52 fAdc(0x0),
53 fTracks(0x0)
54{
55 //
56 // default ctor
57 //
58}
59
60////////////////////////////////////////////////////////////////////////
61AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t *vol,Int_t *digit):
62 TObject(),
63 fSector(-1),
64 fPlate(-1),
65 fStrip(-1),
66 fPadx(-1),
67 fPadz(-1),
68 fNDigits(0),
69 fTdc(0x0),
70 fAdc(0x0),
71 fTracks(0x0)
72{
73 //
74 // Constructor of digit object
75 //
76
77 fSector = vol[0];
78 fPlate = vol[1];
79 fStrip = vol[2];
80 fPadx = vol[3];
81 fPadz = vol[4];
82 fNDigits = 1;
83 fTdc = new TArrayI(fNDigits);
84 (*fTdc)[0] = digit[0];
85 fAdc = new TArrayI(fNDigits);
86 (*fAdc)[0] = digit[1];
87 fTracks = new TArrayI(kMAXDIGITS*fNDigits);
88 (*fTracks)[0] = tracknum;
89 for (Int_t i = 1; i <kMAXDIGITS*fNDigits; i++) {
90 (*fTracks)[i] = -1;
91 }
92}
93
94////////////////////////////////////////////////////////////////////////
95AliTOFSDigit::AliTOFSDigit(const AliTOFSDigit & digit):
96 TObject(),
97 fSector(-1),
98 fPlate(-1),
99 fStrip(-1),
100 fPadx(-1),
101 fPadz(-1),
102 fNDigits(0),
103 fTdc(0x0),
104 fAdc(0x0),
105 fTracks(0x0)
106{
107 //
108 // copy ctor for AliTOFSDigit object
109 //
110 fSector = digit.fSector;
111 fPlate = digit.fPlate;
112 fStrip = digit.fStrip;
113 fPadx = digit.fPadx;
114 fPadz = digit.fPadz;
115 fNDigits = digit.fNDigits;
116 fTdc = new TArrayI(*digit.fTdc);
117 fAdc = new TArrayI(*digit.fAdc);
118 fTracks = new TArrayI(*digit.fTracks);
119}
120
121////////////////////////////////////////////////////////////////////////
122AliTOFSDigit& AliTOFSDigit::operator=(const AliTOFSDigit & digit)
123{
124 //
125 // copy ctor for AliTOFSDigit object
126 //
127 this->fSector = digit.fSector;
128 this->fPlate = digit.fPlate;
129 this->fStrip = digit.fStrip;
130 this->fPadx = digit.fPadx;
131 this->fPadz = digit.fPadz;
132 this->fNDigits = digit.fNDigits;
133 this->fTdc = digit.fTdc;
134 this->fAdc = digit.fAdc;
135 this->fTracks = digit.fTracks;
136 return *this;
137
138}
139
140////////////////////////////////////////////////////////////////////////
141AliTOFSDigit::AliTOFSDigit(Int_t sector, Int_t plate, Int_t strip, Int_t padx,
142 Int_t padz, Int_t tdc, Int_t adc):
143 fSector(sector),
144 fPlate(plate),
145 fStrip(strip),
146 fPadx(padx),
147 fPadz(padz),
148 fNDigits(1),
149 fTdc(0x0),
150 fAdc(0x0),
151 fTracks(0x0)
152{
153 //
154 // Constructor for sdigit
155 //
156 fTdc = new TArrayI(fNDigits);
157 (*fTdc)[0] = tdc;
158 fAdc = new TArrayI(fNDigits);
159 (*fAdc)[0] = adc;
160 // no tracks were specified, set them to -1
161 fTracks = new TArrayI(kMAXDIGITS*fNDigits);
162 for (Int_t i = 0; i <kMAXDIGITS*fNDigits; i++) {
163 (*fTracks)[i] = -1;
164 }
165}
166
167////////////////////////////////////////////////////////////////////////
168void AliTOFSDigit::GetLocation(Int_t *Loc) const
169{
170 //
171 // Get the coordinates of the digit
172 // in terms of Sector - Plate - Strip - Pad
173 //
174
175 Loc[0]=fSector;
176 Loc[1]=fPlate;
177 Loc[2]=fStrip;
178 Loc[3]=fPadx;
179 Loc[4]=fPadz;
180}
181
182////////////////////////////////////////////////////////////////////////
183void AliTOFSDigit::Update(Float_t tdcbin, Int_t tdc, Int_t adc, Int_t track)
184{
185 //
186 // Add charge and track
187 //
188
189 Int_t sameTime = -1;
190 Float_t tdcwindow=((Float_t)AliTOFGeometry::TimeDiff())/tdcbin;
191 for (Int_t i = 0; i < fNDigits; i++) {
192 if (TMath::Abs(tdc-fTdc->At(i)) < tdcwindow) {
193 sameTime = i;
194 break;
195 }
196 }
197
198 if (sameTime >= 0) {
199 (*fAdc)[sameTime] += adc;
200 // update track - find the first -1 value and replace it by the
201 // track number
202 for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
203 if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
204 (*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
205 break;
206 }
207 // write warning about many tracks going to this pad
208 if (iTrack == kMAXDIGITS) {
209 AliWarning("Many hits in the padhit");
210 // ToAliWarning(PrintPad());
211 }
212 }
213 } else {
214 // add new time slot
215 fNDigits++;
216 fTdc->Set(fNDigits);
217 (*fTdc)[fNDigits-1] = tdc;
218 fAdc->Set(fNDigits);
219 (*fAdc)[fNDigits-1] = adc;
220 fTracks->Set(fNDigits*kMAXDIGITS);
221 (*fTracks)[(fNDigits-1)*kMAXDIGITS] = track;
222 for (Int_t i = 1; i <kMAXDIGITS; i++) {
223 (*fTracks)[(fNDigits-1)*kMAXDIGITS+i] = -1;
224 }
225 }
226
227}
228
229////////////////////////////////////////////////////////////////////////
230void AliTOFSDigit::Update(AliTOFSDigit* sdig)
231{
232
233 //
234 // Perform the sum with sdig
235 //
236
237 // start loop on all sdig locations
238 Int_t nlocations=sdig->GetNDigits();
239
240 for (Int_t j = 0; j < nlocations; j++) {
241 Float_t tdcbin = AliTOFGeometry::TdcBinWidth();// [ps] hardwired for the time being
242 Int_t tdc=(Int_t)sdig->GetTdc(j);
243 Int_t adc=(Int_t)sdig->GetAdc(j);
244 // getting here only the first track number
245 Int_t track=GetTrack(j,0);
246
247
248 Int_t sameTime = -1;
249 Float_t tdcwindow=((Float_t)AliTOFGeometry::TimeDiff())/tdcbin;
250 for (Int_t i = 0; i < fNDigits; i++) {
251 if (TMath::Abs(tdc-fTdc->At(i)) < tdcwindow) {
252 sameTime = i;
253 break;
254 }
255 }
256
257 if (sameTime >= 0) {
258 (*fAdc)[sameTime] += adc;
259 // update track - find the first -1 value and replace it by the
260 // track number
261 for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
262 if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
263 (*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
264 break;
265 }
266 // write warning about many tracks going to this pad
267 if (iTrack == kMAXDIGITS) {
268 AliWarning("Many hits in the padhit");
269 // ToAliWarning(PrintPad());
270 }
271 }
272 } else {
273 // add new time slot
274 fNDigits++;
275 fTdc->Set(fNDigits);
276 (*fTdc)[fNDigits-1] = tdc;
277 fAdc->Set(fNDigits);
278 (*fAdc)[fNDigits-1] = adc;
279 fTracks->Set(fNDigits*kMAXDIGITS);
280 (*fTracks)[(fNDigits-1)*kMAXDIGITS] = track;
281 for (Int_t i = 1; i <kMAXDIGITS; i++) {
282 (*fTracks)[(fNDigits-1)*kMAXDIGITS+i] = -1;
283 } // for (Int_t i = 1; i <kMAXDIGITS; i++)
284 } // if (sameTime >= 0)
285 } // end loop on sdig locations
286}
287
288////////////////////////////////////////////////////////////////////////
289AliTOFSDigit::~AliTOFSDigit()
290{
291 //
292 // dtor
293 //
294 delete fTdc;
295 delete fAdc;
296 delete fTracks;
297}
298
299////////////////////////////////////////////////////////////////////////
300
301Int_t AliTOFSDigit::GetTotPad() const
302{
303 //
304 // Get the "total" index of the pad inside a Sector
305 // starting from the digits data.
306 //
307
308 Int_t pad = 2*fPadx + fPadz;
309 //Int_t pad = fPadx+AliTOFGeometry::NpadX()*fPadz;
310 Int_t before=0;
311
312 switch(fPlate){
313 case 0:
314 //before = 0;
315 break;
316 case 1:
317 before = AliTOFGeometry::NStripC();
318 break;
319 case 2:
320 before = AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
321 break;
322 case 3:
323 before = AliTOFGeometry::NStripA() + AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
324 break;
325 case 4:
326 before = AliTOFGeometry::NStripA() + 2*AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
327 break;
328 }
329
330 Int_t strip = fStrip + before;
331 Int_t padTot = AliTOFGeometry::NpadXStrip()*strip + pad;
332 return padTot;
333}