]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFRoc.cxx
Functions renamed to get a prefix PHOS
[u/mrichter/AliRoot.git] / TOF / AliTOFRoc.cxx
1 ////////////////////////////////////////////////
2 //  Digitization class for set: TOF           //
3 //  AliTOFRoc  class                          //
4 //  Member variables                          //
5 //   fItems :  number of items                //
6 //   fSize  :  size                           //
7 //   fNRoc  :  Roc number                     //
8 //   fHeader:  Roc header number              //
9 //   fChrgRow[1024]; // adc values            //
10 //   fTimeRow[1024]; // tdc values            //
11 //                                            //
12 //  Member functions implemented here         //
13 //                                            //
14 //*-- Authors: Pierella, Seganti, Vicinanza   //
15 //    (Bologna and Salerno University)        //
16 ////////////////////////////////////////////////
17
18
19 /**************************************************************************
20  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
21  *                                                                        *
22  * Author: The ALICE Off-line Project.                                    *
23  * Contributors are mentioned in the code where appropriate.              *
24  *                                                                        *
25  * Permission to use, copy, modify and distribute this software and its   *
26  * documentation strictly for non-commercial purposes is hereby granted   *
27  * without fee, provided that the above copyright notice appears in all   *
28  * copies and that both the copyright notice and this permission notice   *
29  * appear in the supporting documentation. The authors make no claims     *
30  * about the suitability of this software for any purpose. It is          *
31  * provided "as is" without express or implied warranty.                  *
32  **************************************************************************/
33
34 #include <iostream.h>
35 #include <assert.h>
36
37 #include "AliTOFRoc.h"
38
39
40 ClassImp(AliTOFRoc)
41
42 //______________________________________________________________________________
43 AliTOFRoc::AliTOFRoc()
44 {
45 //
46 // Constructor of AliTOFRoc class
47 // The class represents a ROC in the TARODA system
48 // here we make the initialization of the member variables
49   fItems = 0;
50   fSize  = 0;
51   fNRoc  = 0;
52   fHeader= 0;
53 // initialization of fChrgRow[1024] and fTimeRow[1024]
54   for(Int_t i=0; i < 1024; i++){
55      fChrgRow[i] = 0;
56      fTimeRow[i] = 0;
57   } // end loop
58 }
59
60 //______________________________________________________________________________
61 AliTOFRoc::AliTOFRoc(const AliTOFRoc& tofroc)
62  : fItems(tofroc.fItems), fSize(tofroc.fSize), fNRoc(tofroc.fNRoc), fHeader(tofroc.fHeader) 
63
64 //
65 // copy ctor for AliTOFRoc class 
66 //
67    assert(tofroc.fItems >= 0); // check for number of items
68    assert(tofroc.fSize  >= 0); // check for roc size
69 // making a copy of adc and tdc vectors
70    for(Int_t i=0; i < 1024; i++){
71       fChrgRow[i] = tofroc.fChrgRow[i]; // coping adc values
72       fTimeRow[i] = tofroc.fTimeRow[i]; // coping tdc values
73    } // end loop
74 }
75
76 //______________________________________________________________________________
77 AliTOFRoc& AliTOFRoc::operator=(const AliTOFRoc& tofroc)
78 {
79 //
80 // Assignment operator for AliTOFRoc
81 // (used by copy ctor of AliTOFRawSector)
82 //
83    if (this !=&tofroc) { // do nothing if assigned to self
84      // setting head member data
85      SetHeadVar(tofroc.fItems,tofroc.fSize,tofroc.fNRoc,tofroc.fHeader);
86      // loop on adc and tdc values
87      for(Int_t i=0; i < 1024; i++){
88       fChrgRow[i] = tofroc.fChrgRow[i]; // coping adc values
89       fTimeRow[i] = tofroc.fTimeRow[i]; // coping tdc values
90      } // end loop
91    }
92    return *this;
93 }
94
95 //______________________________________________________________________________
96 AliTOFRoc::~AliTOFRoc(){}
97
98 //______________________________________________________________________________
99 Int_t AliTOFRoc::AddItem(Int_t Fec, Int_t Tdc, Int_t Error,
100                          Float_t Charge, Float_t Time)
101 {
102 //
103 // Adds an item (i.e. the charge, the TOF and the 
104 // cohordinates of a hit pad) to the ROC class.
105 //
106    fItems++;
107    SetCharge(fItems,Fec,Tdc,Charge);
108    SetTime  (fItems,Error,Time);
109    return fItems; // return the number of current items   
110 }
111
112 //______________________________________________________________________________
113 void AliTOFRoc::SetHeadVar(Int_t items, Int_t size, Int_t nroc, UInt_t header)
114 {
115 //
116 // set header member variables for AliTOFRoc 
117 //
118   fItems = items;
119   fSize  = size ;
120   fNRoc  = nroc ;
121   fHeader= header ;
122 }
123
124 //______________________________________________________________________________
125 void AliTOFRoc::SetHeader()
126 {
127 //
128 // Calculate the header line of the ROC in the raw data file
129 //
130
131    fHeader  = fNRoc<<28;
132    fHeader += fSize;
133 }
134
135
136 //______________________________________________________________________________
137 void AliTOFRoc::SetTime(UInt_t Item, UInt_t Error, Float_t RealTime)
138 {
139 //
140 // Calculate the raw data line relative to the TDC
141 // output of a pad in the current ROC.
142 //
143
144    UInt_t itime;
145    itime = (UInt_t)(RealTime/50.);
146    if (itime >= TMath::Power(2,24)) itime = 2^24-1;
147    Error <<= 24;
148    fTimeRow[Item]= Error+itime;
149 }
150
151 //______________________________________________________________________________
152 void AliTOFRoc::SetCharge(UInt_t Item, UInt_t Fec, UInt_t Tdc, Float_t RealCharge)
153 {
154 //
155 // Calculate the raw data line relative to the ADC 
156 // output of a pad in the current ROC.
157 //
158
159    UInt_t iCharge;
160    if (fNRoc>=TMath::Power(2,4)) fNRoc = 0;
161    fNRoc <<= 28;
162    if (Fec >=TMath::Power(2,6))  Fec = 0;
163    Fec  <<= 22;
164    if (Tdc >=TMath::Power(2,6))  Tdc = 0;
165    Tdc  <<= 16;
166    iCharge = (UInt_t)(RealCharge/50.); // 50 ps (TDC bin value)
167    if(iCharge>=TMath::Power(2,16)) iCharge = (UInt_t)TMath::Power(2,16)-1;
168    fChrgRow[Item] = iCharge+fNRoc+Fec+Tdc;
169 }
170
171 //______________________________________________________________________________
172 void AliTOFRoc::SetTime(UInt_t Item, UInt_t tir)
173 {
174 //
175 // Writes the raw data line relative to the TDC
176 //
177
178    fChrgRow[Item]=tir;
179 }
180
181 //______________________________________________________________________________
182 void AliTOFRoc::SetCharge(UInt_t Item, UInt_t chr)
183 {
184 //
185 // Writes the raw data line relative to the ADC
186 //
187
188    fChrgRow[Item]=chr;
189 }
190
191 //______________________________________________________________________________
192 Float_t AliTOFRoc::GetCharge(Int_t Item) const
193 {
194 //
195 // Reads the effective value of the charge starting
196 // from the line of the raw data
197 //
198
199    UInt_t  icharge  = fChrgRow[Item]&0x0000ffff;
200    Float_t charge = (Float_t)icharge*50.;
201    return charge;
202 }
203
204 //______________________________________________________________________________
205 Float_t AliTOFRoc::GetTime(Int_t Item, UInt_t& Error) 
206 {
207 //
208 // Reads the effective value of the time of flight starting
209 // from the line of the raw data
210 //
211
212    UInt_t  itime  = fTimeRow[Item]&0x00ffffff;
213    Float_t time = (Float_t)itime*50.;
214    Error = fTimeRow[Item]>>24; // the same as Error = fTimeRow[Item] / 24;
215    return time; 
216 }
217
218 //______________________________________________________________________________
219 Int_t AliTOFRoc::GetTotPad(Int_t Item) const
220 {
221 //
222 // Reads the cohordinates of the pad starting
223 // from the line of the raw data
224 //
225
226    UInt_t nRoc = (fChrgRow[Item]&0xf0000000)>>28; // >> the same as / (division by)
227    UInt_t nFec = (fChrgRow[Item]&0x0fc00000)>>22;
228    UInt_t nTdc = (fChrgRow[Item]&0x003f0000)>>16;
229    UInt_t pad = nRoc*32*32+nFec*32+nTdc;
230    return pad; 
231 }
232
233 //______________________________________________________________________________
234 UInt_t AliTOFRoc::GetCheckSum()
235 {
236 //
237 // Calculate the checksum word of the current ROC
238 // 
239
240    UInt_t checkSum=0;
241    for(Int_t i=0; i<fItems; i++){
242       checkSum += BitCount(GetChrgRow(i));
243       checkSum += BitCount(GetTimeRow(i));
244    }
245    return checkSum;
246 }
247
248 //______________________________________________________________________________
249 UInt_t AliTOFRoc::BitCount(UInt_t x) const
250 {
251 //
252 // Count the "1" bit in the current word
253 //
254
255    UInt_t count=0;
256    for (count=0; x!=0; x>>=1){
257       if(x&0x00000001) count++;
258    }
259    return count;
260 }
261
262 //______________________________________________________________________________
263 UInt_t AliTOFRoc::SetSize()
264 {
265 //
266 // Reads the size of data from current ROC starting
267 // from the header line of the raw data
268 //
269
270    fSize = fHeader&0x0000ffff;
271    fItems = (fSize-4)/4;
272    return fSize;
273 }
274
275
276