]> git.uio.no Git - u/mrichter/AliRoot.git/blob - START/AliSTARTRawReader.cxx
Number of pads along z is corrected
[u/mrichter/AliRoot.git] / START / AliSTARTRawReader.cxx
1 #include "AliSTARTRawReader.h"
2 #include "AliSTARTRawData.h"
3 #include "AliSTARTdigit.h"
4
5 #include <Riostream.h>
6 #include "TMath.h"
7 #include "TH1F.h"
8 #include "TArrayI.h"
9 #include "AliLog.h"
10  
11 ClassImp(AliSTARTRawReader)
12   
13   AliSTARTRawReader::AliSTARTRawReader (AliRawReader *rawReader, TTree* tree)
14     :  TTask("STARTRawReader","read raw START data"),
15        fTree(tree),
16        fRawReader(rawReader)
17 {
18   //
19 // create an object to read STARTraw digits
20   AliDebug(1,"Start ");
21
22  
23 }
24  AliSTARTRawReader::~AliSTARTRawReader ()
25 {
26   // 
27 }
28 //------------------------------------------------------------------------------------------------
29
30 UInt_t AliSTARTRawReader::UnpackWord(UInt_t packedWord, Int_t startBit, Int_t stopBit)
31 {
32   //This method unpacks a words of StopBit-StartBit+1 bits starting from "StopBits"  
33   UInt_t word;
34   UInt_t offSet;
35   Int_t length;
36   length=stopBit-startBit+1;
37   offSet=(UInt_t)TMath::Power(2,length)-1;
38   offSet<<=startBit;
39   word=packedWord&offSet;
40   word>>=startBit;
41   return word;
42 }
43 //---------------------------------------------------------------------------------------
44 void AliSTARTRawReader::NextThing()
45 {
46 // read the next raw digit
47 // returns kFALSE if there is no digit left
48   UInt_t word, unpackword; 
49   Int_t time, adc, pmt;
50   TArrayI *timeTDC1 = new TArrayI(24);
51   TArrayI * chargeTDC1 = new TArrayI(24);
52   TArrayI *timeTDC2 = new TArrayI(24);
53   TArrayI *chargeTDC2 = new TArrayI(24);
54   TArrayI *sumMult = new TArrayI(6);
55
56   fRawReader->Reset();
57   fRawReader->Select(13);
58  
59   if (!fRawReader->ReadHeader()){
60     Error("ReadSTARTRaw","Couldn't read header");
61     return;
62   }
63   AliSTARTdigit *fDigits = new AliSTARTdigit(); 
64   fTree->Branch("START","AliSTARTdigit",&fDigits,400,1);
65
66   fRawReader->ReadNextInt(word);
67    for (Int_t i=0; i<24; i++)
68     {
69       word=0;
70       unpackword=0;
71       fRawReader->ReadNextInt(word);
72       unpackword=UnpackWord(word,0,5);
73       pmt=unpackword; 
74       word=0;
75       unpackword=0;
76       fRawReader->ReadNextInt(word);
77       unpackword=UnpackWord(word,8,31);
78       time=unpackword;
79       timeTDC1->AddAt(time,pmt);
80
81       word=0;
82       unpackword=0;
83       fRawReader->ReadNextInt(word);
84       unpackword=UnpackWord(word,0,5);
85       pmt=unpackword;
86       word=0;
87       unpackword=0;
88       fRawReader->ReadNextInt(word);
89       unpackword=UnpackWord(word,8,31);
90       time=unpackword;
91       timeTDC2->AddAt(time,pmt);
92  
93       //  QTC
94       word=0;
95       unpackword=0;
96       fRawReader->ReadNextInt(word);
97       unpackword=UnpackWord(word,0,5);
98       pmt=unpackword;
99       word=0;
100       unpackword=0;
101       fRawReader->ReadNextInt(word);
102       unpackword= UnpackWord(word,8,31);
103       time=unpackword; //T1
104   
105       word=0;
106       unpackword=0;
107
108       fRawReader->ReadNextInt(word);
109       unpackword=UnpackWord(word,0,5);
110       pmt=unpackword;
111       word=0;
112       unpackword=0;
113       fRawReader->ReadNextInt(word);
114       unpackword= UnpackWord(word,8,31);
115       adc=unpackword-time;  // T1+ T2 (A)
116       chargeTDC1->AddAt(adc,pmt);
117       //QTC amplified
118
119       word=0;
120       unpackword=0;
121       fRawReader->ReadNextInt(word);
122       unpackword=UnpackWord(word,0,5);
123       pmt=unpackword;
124       word=0;
125       unpackword=0;
126       fRawReader->ReadNextInt(word);
127       unpackword= UnpackWord(word,8,31);
128       time=unpackword; //T1
129   
130       word=0;
131       unpackword=0;
132
133       fRawReader->ReadNextInt(word);
134       unpackword=UnpackWord(word,0,5);
135       pmt=unpackword;
136       word=0;
137       unpackword=0;
138       fRawReader->ReadNextInt(word);
139       unpackword= UnpackWord(word,8,31);
140       adc=unpackword-time;  // T1+ T2 (A)
141       chargeTDC2->AddAt(adc,pmt);
142  
143
144     }
145    fDigits->SetTime(*timeTDC1);
146    fDigits->SetADC(*chargeTDC1);
147  
148
149    word=0;
150    unpackword=0;
151     
152    fRawReader->ReadNextInt(word);
153    unpackword=UnpackWord(word,0,5);
154    pmt=unpackword;
155
156    word=0;
157    unpackword=0;
158    
159    fRawReader->ReadNextInt(word);
160    unpackword=UnpackWord(word,8,31);
161    time=unpackword;
162    fDigits->SetMeanTime(time);   
163     
164    // Best time right &left  
165    word=0;
166    unpackword=0;
167    
168    fRawReader->ReadNextInt(word);
169    unpackword=UnpackWord(word,0,5);
170    pmt=unpackword;
171
172    word=0;
173    unpackword=0;
174
175    fRawReader->ReadNextInt(word);
176    unpackword=UnpackWord(word,8,31);
177    time=unpackword;
178    fDigits->SetTimeBestRight(time);   
179  
180
181    // best time left 
182    word=0;
183    unpackword=0;
184      
185    fRawReader->ReadNextInt(word);
186    unpackword=UnpackWord(word,0,5);
187    pmt=unpackword;
188
189    word=0;
190    unpackword=0;
191    
192    fRawReader->ReadNextInt(word);
193    unpackword=UnpackWord(word,8,31);
194    time=unpackword;
195    fDigits->SetTimeBestLeft(time);   
196    
197
198    // best time differece  
199     word=0;
200    unpackword=0;
201    
202    fRawReader->ReadNextInt(word);
203    unpackword=UnpackWord(word,0,5);
204    pmt=unpackword;
205
206    word=0;
207    unpackword=0;
208    
209    fRawReader->ReadNextInt(word);
210    unpackword=UnpackWord(word,8,31);
211    time=unpackword;
212    fDigits->SetDiffTime(time);   
213  
214  //  multiplicity 
215    for (Int_t im=0; im<6; im++)
216      {
217        word=0;
218        unpackword=0;
219        fRawReader->ReadNextInt(word);
220        unpackword=UnpackWord(word,0,5);
221        pmt=unpackword;
222        word=0;
223        unpackword=0;
224        fRawReader->ReadNextInt(word);
225        unpackword=UnpackWord(word,8,31);
226        time=unpackword;
227        sumMult->AddAt(time,im);
228      }
229         fDigits->SetSumMult(*sumMult);   
230
231     fTree->Fill();
232
233 }
234