Macro to Create pulser run data from an LDC
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigit.cxx
CommitLineData
5919c40c 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$ */
5919c40c 17
0e46b9ae 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 //
bf33f8f0 26// fTdc : TArrayI of TDC values //
27// fAdc : TArrayI of ADC values //
0e46b9ae 28// //
29// Getters, setters and member functions defined here //
30// //
31// -- Authors: F. Pierella, A. Seganti, D. Vicinanza //
32//_________________________________________________________________________//
ea7a588a 33
5919c40c 34#include "TArrayI.h"
35
d076c8d5 36#include "AliLog.h"
0e46b9ae 37
0f4a7374 38#include "AliTOFGeometry.h"
88cb7938 39#include "AliTOFSDigit.h"
5919c40c 40
41ClassImp(AliTOFSDigit)
42
43////////////////////////////////////////////////////////////////////////
655e379f 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)
5919c40c 54{
ea7a588a 55 //
56 // default ctor
57 //
5919c40c 58}
59
60////////////////////////////////////////////////////////////////////////
bf33f8f0 61AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t *vol,Int_t *digit):
655e379f 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)
5919c40c 72{
ea7a588a 73 //
74 // Constructor of digit object
75 //
0f4a7374 76
5919c40c 77 fSector = vol[0];
78 fPlate = vol[1];
79 fStrip = vol[2];
80 fPadx = vol[3];
81 fPadz = vol[4];
82 fNDigits = 1;
bf33f8f0 83 fTdc = new TArrayI(fNDigits);
5919c40c 84 (*fTdc)[0] = digit[0];
bf33f8f0 85 fAdc = new TArrayI(fNDigits);
5919c40c 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////////////////////////////////////////////////////////////////////////
655e379f 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)
5919c40c 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;
bf33f8f0 116 fTdc = new TArrayI(*digit.fTdc);
117 fAdc = new TArrayI(*digit.fAdc);
5919c40c 118 fTracks = new TArrayI(*digit.fTracks);
119}
120
121////////////////////////////////////////////////////////////////////////
7aeeaf38 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////////////////////////////////////////////////////////////////////////
5919c40c 141AliTOFSDigit::AliTOFSDigit(Int_t sector, Int_t plate, Int_t strip, Int_t padx,
bf33f8f0 142 Int_t padz, Int_t tdc, Int_t adc):
655e379f 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)
5919c40c 152{
ea7a588a 153 //
154 // Constructor for sdigit
155 //
bf33f8f0 156 fTdc = new TArrayI(fNDigits);
5919c40c 157 (*fTdc)[0] = tdc;
bf33f8f0 158 fAdc = new TArrayI(fNDigits);
ea7a588a 159 (*fAdc)[0] = adc;
160 // no tracks were specified, set them to -1
5919c40c 161 fTracks = new TArrayI(kMAXDIGITS*fNDigits);
162 for (Int_t i = 0; i <kMAXDIGITS*fNDigits; i++) {
163 (*fTracks)[i] = -1;
164 }
165}
ea7a588a 166
5919c40c 167////////////////////////////////////////////////////////////////////////
168void AliTOFSDigit::GetLocation(Int_t *Loc) const
169{
ea7a588a 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;
5919c40c 180}
181
182////////////////////////////////////////////////////////////////////////
b213b8bd 183void AliTOFSDigit::Update(Float_t tdcbin, Int_t tdc, Int_t adc, Int_t track)
5919c40c 184{
ea7a588a 185 //
186 // Add charge and track
187 //
188
5919c40c 189 Int_t sameTime = -1;
0f4a7374 190 Float_t tdcwindow=((Float_t)AliTOFGeometry::TimeDiff())/tdcbin;
5919c40c 191 for (Int_t i = 0; i < fNDigits; i++) {
b213b8bd 192 if (TMath::Abs(tdc-fTdc->At(i)) < tdcwindow) {
5919c40c 193 sameTime = i;
194 break;
195 }
196 }
ea7a588a 197
5919c40c 198 if (sameTime >= 0) {
7529e782 199 (*fAdc)[sameTime] += adc;
ea7a588a 200 // update track - find the first -1 value and replace it by the
201 // track number
5919c40c 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 }
ea7a588a 207 // write warning about many tracks going to this pad
5919c40c 208 if (iTrack == kMAXDIGITS) {
d076c8d5 209 AliWarning("Many hits in the padhit");
210 // ToAliWarning(PrintPad());
5919c40c 211 }
212 }
213 } else {
ea7a588a 214 // add new time slot
5919c40c 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 }
ea7a588a 226
5919c40c 227}
8e72349e 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++) {
d3c7bfac 241 Float_t tdcbin = AliTOFGeometry::TdcBinWidth();// [ps] hardwired for the time being
8e72349e 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;
0f4a7374 249 Float_t tdcwindow=((Float_t)AliTOFGeometry::TimeDiff())/tdcbin;
8e72349e 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) {
bf33f8f0 258 (*fAdc)[sameTime] += adc;
8e72349e 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) {
d076c8d5 268 AliWarning("Many hits in the padhit");
269 // ToAliWarning(PrintPad());
8e72349e 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
5919c40c 288////////////////////////////////////////////////////////////////////////
289AliTOFSDigit::~AliTOFSDigit()
290{
ea7a588a 291 //
292 // dtor
293 //
5919c40c 294 delete fTdc;
295 delete fAdc;
296 delete fTracks;
297}
298
299////////////////////////////////////////////////////////////////////////
300
96f01799 301Int_t AliTOFSDigit::GetTotPad() const
5919c40c 302{
ea7a588a 303 //
304 // Get the "total" index of the pad inside a Sector
305 // starting from the digits data.
306 //
307
7e6dce66 308 Int_t pad = 2*fPadx + fPadz;
309 //Int_t pad = fPadx+AliTOFGeometry::NpadX()*fPadz;
5919c40c 310 Int_t before=0;
ea7a588a 311
5919c40c 312 switch(fPlate){
7e6dce66 313 case 0:
314 //before = 0;
ea7a588a 315 break;
7e6dce66 316 case 1:
96f01799 317 before = AliTOFGeometry::NStripC();
ea7a588a 318 break;
7e6dce66 319 case 2:
96f01799 320 before = AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
ea7a588a 321 break;
7e6dce66 322 case 3:
96f01799 323 before = AliTOFGeometry::NStripA() + AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
ea7a588a 324 break;
7e6dce66 325 case 4:
96f01799 326 before = AliTOFGeometry::NStripA() + 2*AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
ea7a588a 327 break;
5919c40c 328 }
329
7e6dce66 330 Int_t strip = fStrip + before;
331 Int_t padTot = AliTOFGeometry::NpadXStrip()*strip + pad;
5919c40c 332 return padTot;
333}