1 |
mocchiut |
1.1 |
/** |
2 |
|
|
* \file TrkLevel0.cpp |
3 |
|
|
* \author Elena Vannuccini |
4 |
|
|
*/ |
5 |
|
|
#include <TrkLevel0.h> |
6 |
pam-fi |
1.2 |
|
7 |
pam-fi |
1.4 |
//...................................... |
8 |
|
|
// F77 routines |
9 |
|
|
//...................................... |
10 |
|
|
extern "C" { |
11 |
|
|
|
12 |
|
|
void filladc_(int*); |
13 |
|
|
void evaluatecn_(int*); |
14 |
|
|
void subtractped_(int*); |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
} |
18 |
mocchiut |
1.1 |
using namespace pamela::tracker; |
19 |
|
|
|
20 |
|
|
/** |
21 |
pam-fi |
1.4 |
* |
22 |
|
|
* Function to decode the tracker words. |
23 |
|
|
* |
24 |
|
|
* Tracker words are of three types: |
25 |
|
|
* - ADC data |
26 |
|
|
* - strip address |
27 |
|
|
* - end of ladder |
28 |
|
|
* |
29 |
|
|
* The function returns a struct variable (trkword) |
30 |
|
|
* that contains two quantities, type and decode, which are assigned |
31 |
|
|
* the following values: |
32 |
|
|
* |
33 |
|
|
* type decode |
34 |
|
|
* ---------------------------------------------------- |
35 |
|
|
* -1 error 0 |
36 |
|
|
* 0 data 0-4095 ADC values |
37 |
|
|
* 1 address 0-1023 strip address (relative to ladder) |
38 |
|
|
* 2 end-of-ladder 1,2,3 ladder number (compressed acq mode) |
39 |
|
|
* 4,5,6 ladder number + 3 (full acq mode) |
40 |
|
|
* |
41 |
|
|
**/ |
42 |
|
|
|
43 |
|
|
trkword datadecode(int word){ |
44 |
|
|
int type =0; |
45 |
|
|
int data =0; |
46 |
|
|
int nodata = word&0xf000; |
47 |
|
|
int zero = 0; |
48 |
|
|
|
49 |
|
|
trkword thisword; |
50 |
|
|
|
51 |
|
|
switch (nodata>>12){ |
52 |
|
|
|
53 |
|
|
case 0: |
54 |
|
|
|
55 |
|
|
thisword.decode = word; |
56 |
|
|
thisword.type = 0; |
57 |
|
|
// cout << thisword.decode << "\n"; |
58 |
|
|
return (thisword); //>>>>> ADC data (0) |
59 |
|
|
|
60 |
|
|
case 1: |
61 |
|
|
|
62 |
|
|
type = word&0xC00; |
63 |
|
|
data = word&0x3ff; |
64 |
|
|
|
65 |
|
|
switch(type>>10){ |
66 |
|
|
|
67 |
|
|
case 0: |
68 |
|
|
thisword.decode = data; |
69 |
|
|
thisword.type = 1; //>>> address (1) |
70 |
|
|
return (thisword); |
71 |
|
|
|
72 |
|
|
case 2: |
73 |
|
|
// if(data>=4)data = data-3; |
74 |
|
|
if(data>6){ |
75 |
|
|
printf("Error on data \n"); |
76 |
|
|
thisword.decode = zero; |
77 |
|
|
thisword.type = -1; |
78 |
|
|
return (thisword); //>>>>> error (-1) |
79 |
|
|
} |
80 |
|
|
thisword.decode = data; |
81 |
|
|
thisword.type = 2; |
82 |
|
|
return (thisword); //>>> end-of-ladder |
83 |
|
|
|
84 |
|
|
default: |
85 |
|
|
printf("Error on data \n"); |
86 |
|
|
thisword.decode = zero; |
87 |
|
|
thisword.type = -1; |
88 |
|
|
return (thisword); //>>>>> error (-1) |
89 |
|
|
|
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
default: |
93 |
|
|
|
94 |
|
|
printf("Error on data \n"); |
95 |
|
|
thisword.decode = zero; |
96 |
|
|
thisword.type = -1; |
97 |
|
|
return (thisword); //>>>>> error (-1) |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
|
102 |
|
|
/** |
103 |
mocchiut |
1.1 |
* Pass values from the TrkLevel0 object to a struct cTrkLevel0 (to put data in F77 common). |
104 |
|
|
*/ |
105 |
pam-fi |
1.2 |
//void TrkLevel0::GetCommonVar(cTrkLevel0 *l0) { |
106 |
|
|
void TrkLevel0::GetLevel0Struct(cTrkLevel0 *l0) { |
107 |
mocchiut |
1.1 |
|
108 |
|
|
Int_t countrk=0; |
109 |
|
|
|
110 |
pam-fi |
1.2 |
l0->good0 = yodaobj->good0; |
111 |
|
|
l0->TOTDATAlength = yodaobj->TOTDATAlength; |
112 |
mocchiut |
1.1 |
for(Int_t ii=0;ii<12;ii++){ |
113 |
pam-fi |
1.2 |
l0->DAQmode[ii] = yodaobj->DAQmode[ii]; |
114 |
|
|
l0->DSPnumber[ii] = yodaobj->DSPnumber[ii]; |
115 |
|
|
l0->DATAlength[ii] = yodaobj->DATAlength[ii]; |
116 |
|
|
l0->eventn[ii] = yodaobj->eventn[ii]; |
117 |
|
|
l0->nclust[ii] = yodaobj->nclust[ii]; |
118 |
|
|
l0->cutc[ii] = yodaobj->cutc[ii]; |
119 |
|
|
l0->cutcl[ii] = yodaobj->cutcl[ii]; |
120 |
mocchiut |
1.1 |
for(Int_t iii=0;iii<3;iii++){ |
121 |
pam-fi |
1.2 |
l0->addrcluster[iii][ii] = yodaobj->addrcluster[ii][iii]; |
122 |
|
|
l0->signcluster[iii][ii] = yodaobj->signcluster[ii][iii]; |
123 |
mocchiut |
1.1 |
}; |
124 |
pam-fi |
1.2 |
l0->fc[ii] = yodaobj->fc[ii]; |
125 |
|
|
l0->compressiontime[ii] = yodaobj->compressiontime[ii]; |
126 |
|
|
l0->fl5[ii] = yodaobj->fl5[ii]; |
127 |
|
|
l0->fl4[ii] = yodaobj->fl4[ii]; |
128 |
|
|
l0->fl3[ii] = yodaobj->fl3[ii]; |
129 |
|
|
l0->fl2[ii] = yodaobj->fl2[ii]; |
130 |
|
|
l0->fl1[ii] = yodaobj->fl1[ii]; |
131 |
|
|
l0->fl6[ii] = yodaobj->fl6[ii]; |
132 |
|
|
l0->checksum[ii] = yodaobj->checksum[ii]; |
133 |
|
|
for(Int_t j=0;j<yodaobj->DATAlength[ii];j++){ |
134 |
|
|
l0->datatracker[countrk] = yodaobj->TrackerData.At(countrk); |
135 |
mocchiut |
1.1 |
++countrk; |
136 |
|
|
}; |
137 |
pam-fi |
1.2 |
l0->pnum[ii] = yodaobj->pnum[ii]; |
138 |
|
|
l0->cmdnum[ii] = yodaobj->cmdnum[ii]; |
139 |
|
|
l0->bid[ii] = yodaobj->bid[ii]; |
140 |
|
|
l0->alarm[ii] = yodaobj->alarm[ii]; |
141 |
|
|
l0->aswr[ii] = yodaobj->aswr[ii]; |
142 |
mocchiut |
1.1 |
}; |
143 |
|
|
|
144 |
|
|
|
145 |
|
|
} |
146 |
pam-fi |
1.2 |
/** |
147 |
|
|
* Pass values from the TrkLevel0 object to a struct cTrkLevel0 (to put data in F77 common). |
148 |
|
|
*/ |
149 |
|
|
void TrkLevel0::SetFromLevel0Struct(cTrkLevel0 *){ |
150 |
|
|
|
151 |
|
|
cout<<"void TrkLevel0::SetFromLevel0Struct(cTrkLevel0 *) -- not implemented"<<endl; |
152 |
|
|
|
153 |
|
|
}; |
154 |
|
|
/** |
155 |
|
|
* Method to call the F77 routine that performs level0->level1 processing. |
156 |
|
|
* The level1 output is stored in a common block, which can be retrieved |
157 |
|
|
* by mean of the method TrkLevel1::SetFromLevel1Struct(). |
158 |
|
|
*/ |
159 |
|
|
int TrkLevel0::ProcessEvent(){ |
160 |
|
|
|
161 |
|
|
// cout << "int TrkLevel0::ProcessEvent()" << endl; |
162 |
pam-fi |
1.3 |
TrkParams::Load(6); |
163 |
|
|
if( !TrkParams::IsLoaded(6) ){ |
164 |
|
|
cout << "int TrkLevel0::ProcessEvent() -- ERROR -- VK-mask not loaded"<<endl; |
165 |
|
|
return 0; |
166 |
|
|
}; |
167 |
pam-fi |
1.2 |
TrkParams::LoadCalib( ); |
168 |
pam-fi |
1.3 |
if( !TrkParams::CalibIsLoaded() ){ |
169 |
|
|
cout << "int TrkLevel0::ProcessEvent() -- ERROR -- Calibration not loaded"<<endl; |
170 |
|
|
return 0; |
171 |
|
|
}; |
172 |
pam-fi |
1.2 |
|
173 |
|
|
GetLevel0Struct(); |
174 |
|
|
int F77err = 0; |
175 |
|
|
reductionflight_(&F77err); |
176 |
pam-fi |
1.3 |
if(F77err < 0){ |
177 |
|
|
cout << "int TrkLevel0::ProcessEvent() -- ERROR -- from F77 routine"<<endl; |
178 |
|
|
return 0; |
179 |
|
|
} |
180 |
|
|
// cout << "...done"<<endl; |
181 |
pam-fi |
1.2 |
|
182 |
|
|
return 1; |
183 |
|
|
|
184 |
|
|
} |
185 |
pam-fi |
1.4 |
/** |
186 |
|
|
* Method to evaluate the raw signal (ADC) of each strip (it performs uncompression). |
187 |
|
|
* (it calls F77 routine filladc ) |
188 |
|
|
*/ |
189 |
|
|
bool TrkLevel0::FillADC(){ |
190 |
|
|
|
191 |
|
|
// cout << "int TrkLevel0::ProcessEvent()" << endl; |
192 |
|
|
TrkParams::Load(6); |
193 |
|
|
if( !TrkParams::IsLoaded(6) ){ |
194 |
|
|
cout << "int TrkLevel0::FillADC() -- ERROR -- VK-mask not loaded"<<endl; |
195 |
|
|
return false; |
196 |
|
|
}; |
197 |
|
|
TrkParams::LoadCalib( ); |
198 |
|
|
if( !TrkParams::CalibIsLoaded() ){ |
199 |
|
|
cout << "int TrkLevel0::FillADC() -- ERROR -- Calibration not loaded"<<endl; |
200 |
|
|
return false; |
201 |
|
|
}; |
202 |
|
|
|
203 |
|
|
GetLevel0Struct(); |
204 |
|
|
int iflag=0; |
205 |
|
|
filladc_(&iflag); |
206 |
|
|
if(iflag!=0)return false; |
207 |
|
|
return true; |
208 |
|
|
|
209 |
|
|
} |
210 |
|
|
/** |
211 |
|
|
* Method to evaluate calibrated signal (ADC-CN-PED) of each view |
212 |
|
|
* (it calls F77 routines: filladc + evaluatecn + subtractped) |
213 |
|
|
* @param iview view number (1-12) |
214 |
pam-fi |
1.5 |
* @param graph pointer to a TGraph to retrieve the output |
215 |
|
|
* @param filladc if true calls F77 routine FillADC. otherwise must be called outside |
216 |
pam-fi |
1.4 |
*/ |
217 |
pam-fi |
1.5 |
bool TrkLevel0::GetCalibratedEvent(int iview, TGraph* graph, bool filladc){ |
218 |
pam-fi |
1.4 |
|
219 |
|
|
if ( iview<1 || iview>12 )return false; |
220 |
pam-fi |
1.5 |
if( filladc ){ |
221 |
|
|
if ( !FillADC() ) return false; |
222 |
|
|
} |
223 |
pam-fi |
1.4 |
evaluatecn_(&iview); |
224 |
|
|
subtractped_(&iview); |
225 |
|
|
|
226 |
|
|
if(graph){ |
227 |
|
|
graph->Set(NSTRIP); |
228 |
|
|
for(int i=0; i<NSTRIP; i++)graph->SetPoint(i,(float)i,calibratedsignal_.value[i]); |
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
return true; |
233 |
|
|
|
234 |
|
|
} |
235 |
|
|
/** |
236 |
|
|
* extract compressed/full data for a subset of channels |
237 |
|
|
* |
238 |
|
|
*/ |
239 |
|
|
void TrkLevel0::Decode(int from,int to,bool& COMPRESSED,bool& FULL, int* datacomp, int* datafull){ |
240 |
|
|
// |
241 |
|
|
int address = 0; |
242 |
|
|
int ladder = 1; |
243 |
|
|
Int_t whisto[3072]; for(int i=0; i<3072; i++)whisto[i] = -200; |
244 |
|
|
// |
245 |
|
|
COMPRESSED=false; |
246 |
|
|
FULL=false; |
247 |
|
|
|
248 |
|
|
for(Int_t vi = from ; vi < to ; vi++){ |
249 |
|
|
int word = yodaobj->TrackerData.At(vi); |
250 |
|
|
trkword thisword = datadecode(word); |
251 |
|
|
switch (thisword.type){ |
252 |
|
|
|
253 |
|
|
case 0: //ADC value |
254 |
|
|
whisto[address] = thisword.decode; |
255 |
|
|
// cout << vi<<" data " << thisword.decode << " @ "<<address << "\n"; |
256 |
|
|
address++; |
257 |
|
|
break; |
258 |
|
|
|
259 |
|
|
case 1: //address |
260 |
|
|
address = 1024*(ladder-1) + thisword.decode; |
261 |
|
|
// cout << vi<<" adr " << address << "\n"; |
262 |
|
|
break; |
263 |
|
|
|
264 |
|
|
case 2: //end-of-ladder |
265 |
|
|
ladder = thisword.decode; |
266 |
|
|
// cout << vi<<" Ladder " << ladder << "\n"; |
267 |
|
|
if(ladder==3){ |
268 |
|
|
// end of compressed data - FILL HISTO |
269 |
|
|
// cout << ">>> COMPRESSED data" << "\n"; |
270 |
|
|
COMPRESSED=true; |
271 |
|
|
for(int ii = 0; ii < 3072; ii++){ |
272 |
|
|
*(datacomp+ii) = whisto[ii]; |
273 |
|
|
whisto[ii] = -200; |
274 |
|
|
} |
275 |
|
|
address = 0; |
276 |
|
|
ladder = 1; |
277 |
|
|
}else if(ladder==6){ |
278 |
|
|
// end of full data - FILL HISTO |
279 |
|
|
// cout << ">>> FULL data" << "\n"; |
280 |
|
|
FULL=true; |
281 |
|
|
for(int ii = 0; ii < 3072; ii++){ |
282 |
|
|
*(datafull+ii) = whisto[ii]; |
283 |
|
|
whisto[ii] = -200; |
284 |
|
|
} |
285 |
|
|
address = 0; |
286 |
|
|
ladder = 1; |
287 |
|
|
}else{ |
288 |
|
|
if(ladder>3) ladder=ladder-3; |
289 |
|
|
address= ladder*1024; |
290 |
|
|
ladder = ladder + 1; |
291 |
|
|
} |
292 |
|
|
} |
293 |
|
|
} |
294 |
|
|
|
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
/** |
298 |
|
|
* Retrieve full event |
299 |
|
|
* |
300 |
|
|
*/ |
301 |
|
|
bool TrkLevel0::GetFullEvent(int iview, TGraph* graph){ |
302 |
|
|
|
303 |
|
|
|
304 |
|
|
// retrieve the index of the dsp |
305 |
|
|
int idsp=0; |
306 |
|
|
do{ |
307 |
|
|
if ( yodaobj->DSPnumber[idsp] == iview )break; |
308 |
|
|
idsp++; |
309 |
|
|
}while(idsp<12); |
310 |
|
|
if(idsp==12)return false; |
311 |
|
|
// |
312 |
|
|
// check DAQ mode: |
313 |
|
|
// 9 full |
314 |
|
|
// 10 compressed |
315 |
|
|
// 11 compressed+full |
316 |
|
|
// 8 special: compressed+full <--> compressed alternati |
317 |
|
|
// |
318 |
|
|
if( yodaobj->DAQmode[idsp] == 10 )return false;//compressed only |
319 |
|
|
// |
320 |
|
|
int offset =0; |
321 |
|
|
for(int i=0; i<idsp; i++)offset+=yodaobj->DATAlength[i]; |
322 |
|
|
// |
323 |
|
|
// decode data |
324 |
|
|
// |
325 |
|
|
Int_t whistocomp[3072]; |
326 |
|
|
Int_t whistofull[3072]; |
327 |
|
|
bool COMPRESSED=false; |
328 |
|
|
bool FULL=false; |
329 |
|
|
Decode(offset,offset+yodaobj->DATAlength[idsp],COMPRESSED,FULL,whistocomp,whistofull); |
330 |
|
|
if(!FULL) return false; |
331 |
|
|
|
332 |
|
|
if(!graph)graph=new TGraph(3072); |
333 |
|
|
for(int i=0; i<3072; i++)graph->SetPoint(i,(double)i,(double)whistofull[i]); |
334 |
|
|
return true; |
335 |
|
|
|
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
/** |
339 |
|
|
* Retrieve compressed event |
340 |
|
|
* |
341 |
|
|
*/ |
342 |
|
|
bool TrkLevel0::GetCompressedEvent(int iview, TGraph* graph){ |
343 |
|
|
|
344 |
|
|
|
345 |
|
|
// retrieve the index of the dsp |
346 |
|
|
int idsp=0; |
347 |
|
|
do{ |
348 |
|
|
if ( yodaobj->DSPnumber[idsp] == iview )break; |
349 |
|
|
idsp++; |
350 |
|
|
}while(idsp<12); |
351 |
|
|
if(idsp==12)return false; |
352 |
|
|
// |
353 |
|
|
// check DAQ mode: |
354 |
|
|
// 9 full |
355 |
|
|
// 10 compressed |
356 |
|
|
// 11 compressed+full |
357 |
|
|
// 8 special: compressed+full <--> compressed alternati |
358 |
|
|
// |
359 |
|
|
if( yodaobj->DAQmode[idsp] == 9 )return false; |
360 |
|
|
// |
361 |
|
|
int offset =0; |
362 |
|
|
for(int i=0; i<idsp; i++)offset+=yodaobj->DATAlength[i]; |
363 |
|
|
// |
364 |
|
|
// decode data |
365 |
|
|
// |
366 |
|
|
Int_t whistocomp[3072]; |
367 |
|
|
Int_t whistofull[3072]; |
368 |
|
|
bool COMPRESSED=false; |
369 |
|
|
bool FULL=false; |
370 |
|
|
Decode(offset,offset+yodaobj->DATAlength[idsp],COMPRESSED,FULL,whistocomp,whistofull); |
371 |
|
|
if(!COMPRESSED) return false; |
372 |
|
|
|
373 |
|
|
if(!graph)graph=new TGraph(3072); |
374 |
|
|
for(int i=0; i<3072; i++)graph->SetPoint(i,(double)i,(double)whistocomp[i]); |
375 |
|
|
return true; |
376 |
|
|
|
377 |
|
|
} |
378 |
|
|
/** |
379 |
|
|
* Retrieve uncompressed event event |
380 |
|
|
*/ |
381 |
|
|
bool TrkLevel0::GetUnCompressedEvent(int iview, TGraph* graph){ |
382 |
|
|
|
383 |
|
|
if(!graph)graph=new TGraph(3072); |
384 |
|
|
// |
385 |
|
|
if( !GetCompressedEvent(iview,graph) )return false; |
386 |
|
|
// |
387 |
|
|
double* adc; |
388 |
|
|
double last; |
389 |
|
|
adc = graph->GetY(); |
390 |
|
|
for(int i=0; i<3072; i++){ |
391 |
|
|
int ivk = (int)((float)i/128.); |
392 |
|
|
int is = i%128; |
393 |
|
|
if(*(adc+i)>0)last = adc[i] - (double)pedsigbad_.pedestal_t[is][ivk][iview-1]; |
394 |
|
|
else{ |
395 |
|
|
*(adc+i) = last + (double)pedsigbad_.pedestal_t[is][ivk][iview-1]; |
396 |
|
|
} |
397 |
|
|
graph->SetPoint(i,(double)i,*(adc+i)); |
398 |
|
|
} |
399 |
|
|
|
400 |
|
|
return true; |
401 |
|
|
|
402 |
|
|
} |
403 |
|
|
/** |
404 |
|
|
* Retrieve sigmas |
405 |
|
|
*/ |
406 |
|
|
bool TrkLevel0::GetSigma(int iview, TGraph* graph){ |
407 |
|
|
|
408 |
|
|
if(!graph)graph=new TGraph(3072); |
409 |
|
|
// |
410 |
|
|
for(int i=0; i<3072; i++){ |
411 |
|
|
int ivk = (int)((float)i/128.); |
412 |
|
|
int is = i%128; |
413 |
|
|
graph->SetPoint(i,(double)i,(double)pedsigbad_.sigma[is][ivk][iview-1]); |
414 |
|
|
} |
415 |
|
|
|
416 |
|
|
return true; |
417 |
|
|
|
418 |
|
|
} |
419 |
mocchiut |
1.1 |
|
420 |
pam-fi |
1.2 |
ClassImp(TrkLevel0); |