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