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