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