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