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