]> git.uio.no Git - u/mrichter/AliRoot.git/blob - START/AliSTARTRawReader.cxx
small fix
[u/mrichter/AliRoot.git] / START / AliSTARTRawReader.cxx
1 #include "AliSTARTRawReader.h"
2 #include "AliSTARTRawData.h"
3 #include "AliSTARTdigit.h"
4 #include "AliBitPacking.h"
5 #include "TBits.h"
6
7 #include <Riostream.h>
8 #include "TMath.h"
9 #include "TH1F.h"
10 #include "TArrayI.h"
11 #include "AliLog.h"
12  
13 ClassImp(AliSTARTRawReader)
14   
15   AliSTARTRawReader::AliSTARTRawReader (AliRawReader *rawReader, TTree* tree)
16     :  TTask("STARTRawReader","read raw START data"),
17        fDigits(NULL),
18        fTree(tree),
19        fRawReader(rawReader)
20 {
21   //
22 // create an object to read STARTraw digits
23   AliDebug(1,"Start ");
24   if (fDigits == 0x0) fDigits = new AliSTARTdigit(); 
25   fTree->Branch("START","AliSTARTdigit",&fDigits,405,1);
26  
27   fRawReader->Reset();
28   fRawReader->Select(13,0,1);
29  
30  
31 }
32  AliSTARTRawReader::~AliSTARTRawReader ()
33 {
34   // 
35 }
36
37 Bool_t  AliSTARTRawReader::Next()
38 {
39 // read the next raw digit
40 // returns kFALSE if there is no digit left
41
42   UInt_t word, unpackword;
43   Int_t time,  pmt;
44   TArrayI *timeTDC1 = new TArrayI(24);
45   TArrayI * chargeTDC1 = new TArrayI(24);
46   TArrayI *timeTDC2 = new TArrayI(24);
47   TArrayI *chargeTDC2 = new TArrayI(24);
48
49   do {
50     if (!fRawReader->ReadNextData(fData)) return kFALSE;
51   } while (fRawReader->GetDataSize() == 0);
52   
53   fPosition = GetPosition();
54  //  trigger 
55    word=0;
56    unpackword=0;
57    word = GetNextWord();
58    unpackword=AliBitPacking::UnpackWord(word,8,31);
59    time=unpackword;
60    word=0;
61    unpackword=0;
62    word = GetNextWord();
63    unpackword=AliBitPacking::UnpackWord(word,0,8);
64    pmt=unpackword;
65
66    word=0;
67    unpackword=0;
68    word = GetNextWord();
69    unpackword=AliBitPacking::UnpackWord(word,8,31);
70    time=unpackword;
71    word=0;
72    unpackword=0;
73    word = GetNextWord();
74    unpackword=AliBitPacking::UnpackWord(word,0,8);
75    pmt=unpackword;
76
77    word=0;
78    unpackword=0;
79    word = GetNextWord();
80    unpackword=AliBitPacking::UnpackWord(word,8,31);
81    time=unpackword;
82    word=0;
83    unpackword=0;
84    word = GetNextWord();
85     unpackword=AliBitPacking::UnpackWord(word,0,8);
86    pmt=unpackword;
87
88    word=0;
89    unpackword=0;
90    word = GetNextWord();
91    unpackword=AliBitPacking::UnpackWord(word,8,31);
92    time=unpackword;
93    word=0;
94    unpackword=0;
95    word = GetNextWord();
96    unpackword=AliBitPacking::UnpackWord(word,0,8);
97    pmt=unpackword;
98
99    word=0;
100    unpackword=0;
101    word = GetNextWord();
102    unpackword=AliBitPacking::UnpackWord(word,8,31);
103    time=unpackword;
104    word=0;
105    unpackword=0;
106    word = GetNextWord();
107    unpackword=AliBitPacking::UnpackWord(word,0,8);
108    pmt=unpackword;
109
110
111 //multiplicity
112    word=0;
113    unpackword=0;
114    word = GetNextWord();
115    unpackword=AliBitPacking::UnpackWord(word,8,31);
116    time=unpackword;
117    word=0;
118    unpackword=0;
119    word = GetNextWord();
120    unpackword=AliBitPacking::UnpackWord(word,0,8);
121    pmt=unpackword;
122    fDigits->SetSumMult(time);   
123
124    // best time differece  
125    word=0;
126    unpackword=0;
127    word = GetNextWord();
128    unpackword=AliBitPacking::UnpackWord(word,8,31);
129    time=unpackword;
130
131    word=0;
132    unpackword=0;
133    word = GetNextWord();
134    unpackword=AliBitPacking::UnpackWord(word,0,8);
135    pmt=unpackword;
136    fDigits->SetDiffTime(time);   
137   // best time left 
138    word=0;
139    unpackword=0;
140    word = GetNextWord();
141    unpackword=AliBitPacking::UnpackWord(word,8,31);
142    time=unpackword;
143    word=0;
144    unpackword=0;
145    word = GetNextWord();
146    unpackword=AliBitPacking::UnpackWord(word,0,8);
147    pmt=unpackword;
148    fDigits->SetTimeBestLeft(time);   
149    
150   // Best time right &left  
151    word=0;
152    unpackword=0;
153    word = GetNextWord();
154    unpackword=AliBitPacking::UnpackWord(word,8,31);
155    time=unpackword;
156  
157    word=0;
158    unpackword=0;
159    
160    word = GetNextWord();
161    unpackword=AliBitPacking::UnpackWord(word,0,8);
162    pmt=unpackword;
163    fDigits->SetTimeBestRight(time);  
164   // mean 
165    word=0;
166    unpackword=0;
167    word = GetNextWord();
168    unpackword=AliBitPacking::UnpackWord(word,8,31);
169    time=unpackword;
170  
171    word=0;
172    unpackword=0;
173    
174    word = GetNextWord();
175    unpackword=AliBitPacking::UnpackWord(word,0,8);
176    pmt=unpackword;
177    fDigits->SetMeanTime(time);  
178
179    for (Int_t i=0; i<24; i++)   //QTC amplified
180      {
181       word=0;
182       unpackword=0;
183     
184       word = GetNextWord();
185       unpackword=AliBitPacking::UnpackWord(word,8,31);
186       time=unpackword;
187       word=0;
188       unpackword=0;
189       word = GetNextWord();
190       unpackword= AliBitPacking::UnpackWord(word,0,8);
191       pmt=unpackword;  
192       chargeTDC2->AddAt(time,pmt-72);
193      }
194
195   for (Int_t i=0; i<24; i++)
196     {
197       //  QTC
198       word=0;
199       unpackword=0;
200       word = GetNextWord();
201       unpackword=AliBitPacking::UnpackWord(word,8,31);
202       time=unpackword;
203       word=0;
204       unpackword=0;
205       word = GetNextWord();
206       unpackword= AliBitPacking::UnpackWord(word,0,8);
207       pmt=unpackword; //
208       chargeTDC1->AddAt(time,pmt-48);
209     }
210   
211   for (Int_t i=0; i<24; i++) //time CFD
212     {
213       word=0;
214       unpackword=0;
215       word = GetNextWord();
216       unpackword=AliBitPacking::UnpackWord(word,8,31);
217       time=unpackword;
218       word=0;
219       unpackword=0;
220       word = GetNextWord();
221        unpackword=AliBitPacking::UnpackWord(word,0,8);
222       pmt=unpackword;
223       timeTDC2->AddAt(time,pmt-24);
224     } 
225
226   
227   for (Int_t i=0; i<24; i++) //time LED
228     {
229       word=0;
230       unpackword=0;
231       word = GetNextWord();
232       unpackword=AliBitPacking::UnpackWord(word,8,31);
233       time=unpackword; 
234       
235       word=0;
236       unpackword=0;
237       word = GetNextWord();
238       unpackword=AliBitPacking::UnpackWord(word,0,8);
239       pmt=unpackword;
240       timeTDC1->AddAt(time,pmt);
241     }
242  
243   
244   fDigits->SetTime(*timeTDC2);
245   fDigits->SetADC(*chargeTDC1);
246   
247   fDigits->SetTimeAmp(*timeTDC1);
248   fDigits->SetADCAmp(*chargeTDC2);
249     fTree->Fill();
250
251     delete timeTDC1 ;
252     delete chargeTDC1;
253     delete timeTDC2 ;
254     delete chargeTDC2;
255   
256     return kTRUE;
257 }
258  
259 //_____________________________________________________________________________
260 Int_t AliSTARTRawReader::GetPosition()
261 {
262   // Sets the position in the
263   // input stream
264   if (((fRawReader->GetDataSize() * 8) % 32) != 0)
265     AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
266   return (fRawReader->GetDataSize() * 8) / 32;
267 }
268 //_____________________________________________________________________________
269 UInt_t AliSTARTRawReader::GetNextWord()
270 {
271   // Read the next 32 bit word in backward direction
272   // The input stream access is given by fData and fPosition
273
274    fPosition--;
275   Int_t iBit = fPosition * 32;
276   Int_t iByte = iBit / 8;
277
278   UInt_t word = 0;
279   word  = fData[iByte+3]<<24;
280   word |= fData[iByte+2]<<16;
281   word |= fData[iByte+1]<<8;
282   word |= fData[iByte];
283 // fPosition--;
284   return word;
285
286 }
287