]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFSDigit.cxx
New t_zero macro added to repository
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigit.cxx
1 //_________________________________________________________________________
2 //  TOF digit: member variables 
3 //  fSector  : TOF sector
4 //  fPlate   : TOF plate
5 //  fStrip   : strips number
6 //  fPadx    : pad number along x
7 //  fPadz    : pad number along z
8 //  fTdc     : TArrayF of TDC values
9 //  fAdc     : TArrayF of ADC values
10 //              
11 //  Getters, setters and member functions  defined here
12 //
13 //*-- Authors: F. Pierella, A. Seganti, D. Vicinanza
14
15  
16 /**************************************************************************
17  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
18  *                                                                        *
19  * Author: The ALICE Off-line Project.                                    *
20  * Contributors are mentioned in the code where appropriate.              *
21  *                                                                        *    
22  * Permission to use, copy, modify and distribute this software and its   *
23  * documentation strictly for non-commercial purposes is hereby granted   *
24  * without fee, provided that the above copyright notice appears in all   *
25  * copies and that both the copyright notice and this permission notice   *
26  * appear in the supporting documentation. The authors make no claims     *
27  * about the suitability of this software for any purpose. It is          *
28  * provided "as is" without express or implied warranty.                  * 
29  **************************************************************************/
30
31 #include <iostream.h>
32
33 #include "TArrayF.h"
34 #include "TArrayI.h"
35
36 #include "AliTOF.h"
37 #include "AliTOFSDigit.h"
38 #include "AliTOFConstants.h"
39 #include "AliRun.h"
40 #include "AliMC.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 {
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 {
82   // 
83   // copy ctor for AliTOFSDigit object
84   //
85   fSector = digit.fSector;
86   fPlate  = digit.fPlate;
87   fStrip  = digit.fStrip;
88   fPadx   = digit.fPadx;
89   fPadz   = digit.fPadz;
90   fNDigits = digit.fNDigits;
91   fTdc = new TArrayF(*digit.fTdc);  
92   fAdc = new TArrayF(*digit.fAdc);
93   fTracks = new TArrayI(*digit.fTracks);
94 }
95
96 ////////////////////////////////////////////////////////////////////////
97 AliTOFSDigit::AliTOFSDigit(Int_t sector, Int_t plate, Int_t strip, Int_t padx,
98 Int_t padz, Float_t tdc, Float_t adc)
99 {
100 //
101 // Constructor for sdigit
102 //
103   fSector = sector;
104   fPlate  = plate;
105   fStrip  = strip;
106   fPadx   = padx;
107   fPadz   = padz;  
108   fNDigits = 1;
109   fTdc = new TArrayF(fNDigits);
110   (*fTdc)[0] = tdc;   
111   fAdc = new TArrayF(fNDigits);
112   (*fAdc)[0] = tdc;   
113 // no tracks were specified, set them to -1
114   fTracks = new TArrayI(kMAXDIGITS*fNDigits);
115   for (Int_t i = 0; i <kMAXDIGITS*fNDigits; i++) {
116     (*fTracks)[i] = -1;
117   }
118 }
119    
120 ////////////////////////////////////////////////////////////////////////
121 void AliTOFSDigit::GetLocation(Int_t *Loc) const
122 {
123 //
124 // Get the coordinates of the digit
125 // in terms of Sector - Plate - Strip - Pad
126 //
127
128    Loc[0]=fSector;
129    Loc[1]=fPlate;
130    Loc[2]=fStrip;
131    Loc[3]=fPadx;
132    Loc[4]=fPadz;
133 }
134
135 ////////////////////////////////////////////////////////////////////////
136 void AliTOFSDigit::Update(Int_t tdc, Int_t adc, Int_t track)
137 {
138 //
139 // Add charge and track
140 //
141
142   Int_t sameTime = -1;
143
144   for (Int_t i = 0; i < fNDigits; i++) {
145     if (TMath::Abs(tdc-fTdc->At(i)) < AliTOFConstants::fgkTimeDiff) {
146       sameTime = i;
147       break;
148     }
149   }
150
151   if (sameTime >= 0) {
152     (*fAdc)[sameTime] += static_cast<Float_t>(adc);
153 // update track - find the first -1  value and replace it by the
154 // track number
155     for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
156       if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
157         (*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
158         break;
159       }
160 // write warning about many tracks going to this pad
161       if (iTrack == kMAXDIGITS) {
162         cerr<<"WARNING: AliTOFSDigit::Update  Many hits in the padhit"<<endl;
163         cerr<<"         ";
164 //      PrintPad();
165       }
166     }
167   } else {
168 // add new time slot
169     fNDigits++;
170     fTdc->Set(fNDigits);
171     (*fTdc)[fNDigits-1] = tdc;
172     fAdc->Set(fNDigits);
173     (*fAdc)[fNDigits-1] = adc;
174     fTracks->Set(fNDigits*kMAXDIGITS);
175     (*fTracks)[(fNDigits-1)*kMAXDIGITS] = track;
176     for (Int_t i = 1; i <kMAXDIGITS; i++) {
177       (*fTracks)[(fNDigits-1)*kMAXDIGITS+i] = -1;
178     }
179   }
180
181 }
182 ////////////////////////////////////////////////////////////////////////
183 AliTOFSDigit::~AliTOFSDigit()
184 {
185 //
186 // dtor
187 //
188   delete fTdc;
189   delete fAdc;
190   delete fTracks;
191 }
192
193 ////////////////////////////////////////////////////////////////////////
194
195 Int_t AliTOFSDigit::GetTotPad() const
196 {
197 //
198 // Get the "total" index of the pad inside a Sector
199 // starting from the digits data.
200 //
201
202   AliTOF* tof;
203   
204   if(gAlice){
205      tof =(AliTOF*) gAlice->GetDetector("TOF");
206   }else{
207      printf("AliTOFSDigit::GetTotPad - No AliRun object present, exiting");
208      return 0;
209   }
210   
211   Int_t pad = fPadx+tof->GetNpadX()*(fPadz-1);
212   Int_t before=0;
213
214   switch(fPlate){ 
215   case 1: before = 0;
216           break;
217   case 2: before = tof->GetNStripC();
218           break;
219   case 3: before = tof->GetNStripB() + tof->GetNStripC();
220           break;
221   case 4: before = tof->GetNStripA() + tof->GetNStripB() + tof->GetNStripC();
222           break;
223   case 5: before = tof->GetNStripA() + 2*tof->GetNStripB() + tof->GetNStripC();
224           break;
225   }
226   
227   Int_t strip = fStrip+before;
228   Int_t padTot = tof->GetPadXStr()*(strip-1)+pad;
229   return padTot;
230 }
231
232 ////////////////////////////////////////////////////////////////////////
233 //void AliTOFSDigit::AddTrack(Int_t track)
234 //{
235 //
236 // Add a new and different track to the digit -- but to which digit??
237 // do not implemet this function
238 //
239 ////////////////////////////////////////////////////////////////////////
240
241 // Overloading of Streaming, Sum and Comparison operators
242
243 ////////////////////////////////////////////////////////////////////////
244 /*
245 Bool_t AliTOFSDigit::operator==(AliTOFSDigit const &digit) const
246 {
247 //
248 // Overloading of Comparison operator
249 //   
250  if (fSector==digit.fSector &&
251      fPlate==digit.fPlate &&
252      fStrip==digit.fStrip &&
253      fPadx==digit.fPadx &&
254      fPadz==digit.fPadz &&
255      fTdc==digit.fTdc &&
256      fAdc==digit.fAdc) return kTRUE;
257      else return kFALSE;
258 }
259 */
260 ////////////////////////////////////////////////////////////////////////
261 /*
262 ostream& operator << (ostream& out, const AliTOFSDigit &digit)
263 {
264 //
265 // Output streamer: output of the digit data
266 //
267 out << "Sector " << digit.fSector << ", Plate " << digit.fPlate << ", Strip " << digit.fStrip << endl;
268 out << "Padx" << digit.fPadx << ", Padz " << digit.fPadz << endl;
269 out << "TDC " << digit.fTdc->At(0) << ", ADC "<< digit.fAdc->At(0) << endl;
270 return out;
271 }
272 */