]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFRawStream.cxx
New TOF geometry description (V5) -G. Cara Romeo and A. De Caro
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.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 /*
17 Revision 0.02  2005/07/28 A. De Caro:
18         Update format TOF raw data
19                (temporary solution) 
20         Correction of few wrong corrispondences
21                between 'software' and 'hardware' numberings
22
23 Revision 0.01  2005/07/22 A. De Caro
24         Implement methods Next()
25                           GetSector(),
26                           GetPlate(),
27                           GetStrip(),
28                           GetPadZ(),
29                           GetPadX()
30 */
31
32 ///////////////////////////////////////////////////////////////////////////////
33 //
34 // This class provides access to TOF raw data in DDL files.
35 //
36 // It loops over all TOF raw data given by the AliRawReader.
37 //
38 ///////////////////////////////////////////////////////////////////////////////
39
40 #include "AliLog.h"
41 #include "AliRawReader.h"
42
43 #include "AliTOFGeometry.h"
44 #include "AliTOFGeometryV5.h"
45 #include "AliTOFRawStream.h"
46
47 ClassImp(AliTOFRawStream)
48
49
50 //_____________________________________________________________________________
51 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader)
52 {
53   //
54   // create an object to read TOF raw digits
55   //
56
57   fRawReader = rawReader;
58   fDDL = -1;
59   fTRM = -1;
60   fTDC = -1;
61   fTDCChannel = -1;
62   fTof = -1;
63   fADC = -1;
64   fErrorFlag = -1;
65   //fCounter = -1; // v0.01
66
67   fTOFGeometry = new AliTOFGeometryV5();
68
69   fRawReader->Select(5);
70
71 }
72
73 //_____________________________________________________________________________
74 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
75   TObject(stream)
76 {
77   //
78   // copy constructor
79   //
80
81   fRawReader = NULL;
82   fDDL = -1;
83   fTRM = -1;
84   fTDC = -1;
85   fTDCChannel = -1;
86   fTof = -1;
87   fADC = -1;
88   fErrorFlag = -1;
89   //fCounter = -1; // v0.01
90
91   fTOFGeometry = new AliTOFGeometryV5();
92
93 }
94
95 //_____________________________________________________________________________
96 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
97 {
98   //
99   // assignment operator
100   //
101
102   fRawReader = stream.fRawReader;
103   fDDL = stream.fDDL;
104   fTRM = stream.fTRM;
105   fTDC = stream.fTDC;
106   fTDCChannel = stream.fTDCChannel;
107   fTof = stream.fTof;
108   fADC = stream.fADC;
109   fErrorFlag = stream.fErrorFlag;
110   //fCounter = stream.fCounter; // v0.01
111
112   fTOFGeometry = stream.fTOFGeometry;
113
114   return *this;
115
116 }
117
118 //_____________________________________________________________________________
119 AliTOFRawStream::~AliTOFRawStream()
120 {
121 // destructor
122
123   delete fTOFGeometry;
124
125 }
126
127
128 //_____________________________________________________________________________
129 Bool_t AliTOFRawStream::Next()
130 {
131 // read the next raw digit
132 // returns kFALSE if there is no digit left
133
134   //fCounter++; // v0.01
135
136   UInt_t data;
137
138   /*
139   // v0.01
140   if (fCounter==0) {
141     if (!fRawReader->ReadNextInt(data)) return kFALSE;
142     Int_t dummy = data & 0x007F; // first  7 bits
143     AliInfo(Form("This is the number of the current DDL file %2i",dummy));
144   }
145   */
146
147   if (!fRawReader->ReadNextInt(data)) return kFALSE;
148
149   fTRM         =  data        & 0x000F; // first  4 bits
150   fTDC         = (data >>  4) & 0x001F; // next   5 bits
151   fTDCChannel  = (data >>  9) & 0x0007; // next   3 bits
152   fADC         = (data >> 12) & 0x000FFFFF; // last  20 bits // v0.01
153   //fADC         = (data >> 12) & 0x00FF; // next   8 bits // v0.02
154
155   if (!fRawReader->ReadNextInt(data)) return kFALSE;
156
157   fErrorFlag   =  data        & 0x00FF; // first 8 bits
158   fTof         = (data >>  8) & 0x00FFFFFF; // last 24 bits // v0.01
159   //fTof         = (data >>  8) & 0x0FFF; // next 12 bits // v0.02
160
161   fDDL  = fRawReader->GetDDLID();
162
163   //AliInfo(Form("fDDL  %2i,fTRM %2i, fTDC %2i, fTDCChannel %1i",fDDL,fTRM,fTDC,fTDCChannel));
164
165   return kTRUE;
166 }
167 //_____________________________________________________________________________
168
169 Int_t AliTOFRawStream::GetSector() const
170 {
171   //
172   // Transform the Hardware coordinate to Software coordinate
173   // and also write it in the digit form
174   //
175
176   Int_t iSector = -1;
177   iSector = (Int_t)((Float_t)fDDL/AliTOFGeometry::NDDL());
178
179   return iSector;
180
181 }
182 //_____________________________________________________________________________
183
184 Int_t AliTOFRawStream::GetPlate() const
185 {
186   //
187   // Transform the Hardware coordinate to Software coordinate
188   // and also write it in the digit form
189   //
190
191   Int_t iPlate = -1;
192
193   Int_t localDDL = fDDL%AliTOFGeometry::NDDL();
194   
195   Int_t iPadPerSector = fTDCChannel + AliTOFGeometry::NCh()*(fTDC + AliTOFGeometry::NTdc()*(fTRM + AliTOFGeometry::NTRM()*localDDL));
196
197   Int_t iStripPerSector = (Int_t)(iPadPerSector/(Float_t)AliTOFGeometry::NpadX()/(Float_t)AliTOFGeometry::NpadZ());
198
199   if (iStripPerSector     < fTOFGeometry->NStripC())
200     iPlate = 0;
201   else if (iStripPerSector>=fTOFGeometry->NStripC() &&
202            iStripPerSector< fTOFGeometry->NStripC()+AliTOFGeometry::NStripB())
203     iPlate = 1;
204   else if (iStripPerSector>=fTOFGeometry->NStripC()+AliTOFGeometry::NStripB() &&
205            iStripPerSector< fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA())
206     iPlate = 2;
207   else if (iStripPerSector>=fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA() &&
208            iStripPerSector< fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()+AliTOFGeometry::NStripB())
209     iPlate = 3;
210   else if (iStripPerSector>=fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()+AliTOFGeometry::NStripB() &&
211            iStripPerSector< fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()+AliTOFGeometry::NStripB()+fTOFGeometry->NStripC())
212     iPlate = 4;
213   else
214     iPlate = -1;
215
216   return iPlate;
217
218 }
219 //_____________________________________________________________________________
220
221 Int_t AliTOFRawStream::GetStrip() const
222 {
223   //
224   // Transform the Hardware coordinate to Software coordinate
225   // and also write it in the digit form
226   //
227
228   Int_t iStrip = -1;
229
230   Int_t localDDL = fDDL%AliTOFGeometry::NDDL();
231
232   Int_t iPadPerSector = fTDCChannel + AliTOFGeometry::NCh()*(fTDC + AliTOFGeometry::NTdc()*(fTRM + AliTOFGeometry::NTRM()*localDDL));
233
234   Int_t iStripPerSector = (Int_t)(iPadPerSector/(Float_t)AliTOFGeometry::NpadX()/(Float_t)AliTOFGeometry::NpadZ());
235
236   if (iStripPerSector      < fTOFGeometry->NStripC())
237     iStrip = iStripPerSector;
238   else if (iStripPerSector >=fTOFGeometry->NStripC() &&
239            iStripPerSector < fTOFGeometry->NStripC()+AliTOFGeometry::NStripB())
240     iStrip = iStripPerSector-fTOFGeometry->NStripC();
241   else if (iStripPerSector >=fTOFGeometry->NStripC()+AliTOFGeometry::NStripB() &&
242            iStripPerSector < fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()) 
243     iStrip = iStripPerSector-fTOFGeometry->NStripC()-AliTOFGeometry::NStripB();
244   else if (iStripPerSector >=fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA() &&
245            iStripPerSector < fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()+AliTOFGeometry::NStripB())
246     iStrip = iStripPerSector-fTOFGeometry->NStripC()-AliTOFGeometry::NStripB()-AliTOFGeometry::NStripA();
247   else if (iStripPerSector >=fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()+AliTOFGeometry::NStripB() &&
248            iStripPerSector < fTOFGeometry->NStripC()+AliTOFGeometry::NStripB()+AliTOFGeometry::NStripA()+AliTOFGeometry::NStripB()+fTOFGeometry->NStripC())
249     iStrip = iStripPerSector-fTOFGeometry->NStripC()-AliTOFGeometry::NStripB()-AliTOFGeometry::NStripA()-AliTOFGeometry::NStripB();
250   else
251     iStrip = -1;
252
253   return iStrip;
254
255 }
256 //_____________________________________________________________________________
257
258 Int_t AliTOFRawStream::GetPadZ() const
259 {
260   //
261   // Transform the Hardware coordinate to Software coordinate
262   // and also write it in the digit form
263   //
264
265   Int_t iPadZ = -1;
266
267   Int_t localDDL = fDDL%AliTOFGeometry::NDDL();
268
269   Int_t iPadPerSector = fTDCChannel + AliTOFGeometry::NCh()*(fTDC + AliTOFGeometry::NTdc()*(fTRM + AliTOFGeometry::NTRM()*localDDL));
270   
271   Int_t iStripPerSector = (Int_t)(iPadPerSector/(Float_t)AliTOFGeometry::NpadX()/(Float_t)AliTOFGeometry::NpadZ());
272
273   Int_t iPadPerStrip = iPadPerSector-AliTOFGeometry::NpadX()*AliTOFGeometry::NpadZ()*iStripPerSector;
274
275   iPadZ = iPadPerStrip%AliTOFGeometry::NpadZ();
276
277   return iPadZ;
278
279 }
280 //_____________________________________________________________________________
281
282 Int_t AliTOFRawStream::GetPadX() const
283 {
284   //
285   // Transform the Hardware coordinate to Software coordinate
286   // and also write it in the digit form
287   //
288
289   Int_t iPadX = -1;
290
291   Int_t localDDL = fDDL%AliTOFGeometry::NDDL();
292
293   Int_t iPadPerSector = fTDCChannel + AliTOFGeometry::NCh()*(fTDC + AliTOFGeometry::NTdc()*(fTRM + AliTOFGeometry::NTRM()*localDDL));
294
295   Int_t iStripPerSector = (Int_t)(iPadPerSector/(Float_t)AliTOFGeometry::NpadX()/(Float_t)AliTOFGeometry::NpadZ());
296
297   Int_t iPadPerStrip = iPadPerSector-AliTOFGeometry::NpadX()*AliTOFGeometry::NpadZ()*iStripPerSector;
298
299   iPadX = (Int_t)(iPadPerStrip/(Float_t)AliTOFGeometry::NpadZ());
300
301   return iPadX;
302
303 }
304 //_____________________________________________________________________________