/[PAMELA software]/DarthVader/TrackerLevel2/src/TrkLevel0.cpp
ViewVC logotype

Annotation of /DarthVader/TrackerLevel2/src/TrkLevel0.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Wed Oct 22 15:17:36 2008 UTC (16 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.3: +323 -0 lines
fixed bug in TrkHough track + new method UnpackError()

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     */
215     bool TrkLevel0::GetCalibratedEvent(int iview, TGraph* graph){
216    
217     if ( iview<1 || iview>12 )return false;
218     if ( !FillADC() ) return false;
219     evaluatecn_(&iview);
220     subtractped_(&iview);
221    
222     if(graph){
223     graph->Set(NSTRIP);
224     for(int i=0; i<NSTRIP; i++)graph->SetPoint(i,(float)i,calibratedsignal_.value[i]);
225     }
226    
227    
228     return true;
229    
230     }
231     /**
232     * extract compressed/full data for a subset of channels
233     *
234     */
235     void TrkLevel0::Decode(int from,int to,bool& COMPRESSED,bool& FULL, int* datacomp, int* datafull){
236     //
237     int address = 0;
238     int ladder = 1;
239     Int_t whisto[3072]; for(int i=0; i<3072; i++)whisto[i] = -200;
240     //
241     COMPRESSED=false;
242     FULL=false;
243    
244     for(Int_t vi = from ; vi < to ; vi++){
245     int word = yodaobj->TrackerData.At(vi);
246     trkword thisword = datadecode(word);
247     switch (thisword.type){
248    
249     case 0: //ADC value
250     whisto[address] = thisword.decode;
251     // cout << vi<<" data " << thisword.decode << " @ "<<address << "\n";
252     address++;
253     break;
254    
255     case 1: //address
256     address = 1024*(ladder-1) + thisword.decode;
257     // cout << vi<<" adr " << address << "\n";
258     break;
259    
260     case 2: //end-of-ladder
261     ladder = thisword.decode;
262     // cout << vi<<" Ladder " << ladder << "\n";
263     if(ladder==3){
264     // end of compressed data - FILL HISTO
265     // cout << ">>> COMPRESSED data" << "\n";
266     COMPRESSED=true;
267     for(int ii = 0; ii < 3072; ii++){
268     *(datacomp+ii) = whisto[ii];
269     whisto[ii] = -200;
270     }
271     address = 0;
272     ladder = 1;
273     }else if(ladder==6){
274     // end of full data - FILL HISTO
275     // cout << ">>> FULL data" << "\n";
276     FULL=true;
277     for(int ii = 0; ii < 3072; ii++){
278     *(datafull+ii) = whisto[ii];
279     whisto[ii] = -200;
280     }
281     address = 0;
282     ladder = 1;
283     }else{
284     if(ladder>3) ladder=ladder-3;
285     address= ladder*1024;
286     ladder = ladder + 1;
287     }
288     }
289     }
290    
291     }
292    
293     /**
294     * Retrieve full event
295     *
296     */
297     bool TrkLevel0::GetFullEvent(int iview, TGraph* graph){
298    
299    
300     // retrieve the index of the dsp
301     int idsp=0;
302     do{
303     if ( yodaobj->DSPnumber[idsp] == iview )break;
304     idsp++;
305     }while(idsp<12);
306     if(idsp==12)return false;
307     //
308     // check DAQ mode:
309     // 9 full
310     // 10 compressed
311     // 11 compressed+full
312     // 8 special: compressed+full <--> compressed alternati
313     //
314     if( yodaobj->DAQmode[idsp] == 10 )return false;//compressed only
315     //
316     int offset =0;
317     for(int i=0; i<idsp; i++)offset+=yodaobj->DATAlength[i];
318     //
319     // decode data
320     //
321     Int_t whistocomp[3072];
322     Int_t whistofull[3072];
323     bool COMPRESSED=false;
324     bool FULL=false;
325     Decode(offset,offset+yodaobj->DATAlength[idsp],COMPRESSED,FULL,whistocomp,whistofull);
326     if(!FULL) return false;
327    
328     if(!graph)graph=new TGraph(3072);
329     for(int i=0; i<3072; i++)graph->SetPoint(i,(double)i,(double)whistofull[i]);
330     return true;
331    
332     }
333    
334     /**
335     * Retrieve compressed event
336     *
337     */
338     bool TrkLevel0::GetCompressedEvent(int iview, TGraph* graph){
339    
340    
341     // retrieve the index of the dsp
342     int idsp=0;
343     do{
344     if ( yodaobj->DSPnumber[idsp] == iview )break;
345     idsp++;
346     }while(idsp<12);
347     if(idsp==12)return false;
348     //
349     // check DAQ mode:
350     // 9 full
351     // 10 compressed
352     // 11 compressed+full
353     // 8 special: compressed+full <--> compressed alternati
354     //
355     if( yodaobj->DAQmode[idsp] == 9 )return false;
356     //
357     int offset =0;
358     for(int i=0; i<idsp; i++)offset+=yodaobj->DATAlength[i];
359     //
360     // decode data
361     //
362     Int_t whistocomp[3072];
363     Int_t whistofull[3072];
364     bool COMPRESSED=false;
365     bool FULL=false;
366     Decode(offset,offset+yodaobj->DATAlength[idsp],COMPRESSED,FULL,whistocomp,whistofull);
367     if(!COMPRESSED) return false;
368    
369     if(!graph)graph=new TGraph(3072);
370     for(int i=0; i<3072; i++)graph->SetPoint(i,(double)i,(double)whistocomp[i]);
371     return true;
372    
373     }
374     /**
375     * Retrieve uncompressed event event
376     */
377     bool TrkLevel0::GetUnCompressedEvent(int iview, TGraph* graph){
378    
379     if(!graph)graph=new TGraph(3072);
380     //
381     if( !GetCompressedEvent(iview,graph) )return false;
382     //
383     double* adc;
384     double last;
385     adc = graph->GetY();
386     for(int i=0; i<3072; i++){
387     int ivk = (int)((float)i/128.);
388     int is = i%128;
389     if(*(adc+i)>0)last = adc[i] - (double)pedsigbad_.pedestal_t[is][ivk][iview-1];
390     else{
391     *(adc+i) = last + (double)pedsigbad_.pedestal_t[is][ivk][iview-1];
392     }
393     graph->SetPoint(i,(double)i,*(adc+i));
394     }
395    
396     return true;
397    
398     }
399     /**
400     * Retrieve sigmas
401     */
402     bool TrkLevel0::GetSigma(int iview, TGraph* graph){
403    
404     if(!graph)graph=new TGraph(3072);
405     //
406     for(int i=0; i<3072; i++){
407     int ivk = (int)((float)i/128.);
408     int is = i%128;
409     graph->SetPoint(i,(double)i,(double)pedsigbad_.sigma[is][ivk][iview-1]);
410     }
411    
412     return true;
413    
414     }
415 mocchiut 1.1
416 pam-fi 1.2 ClassImp(TrkLevel0);

  ViewVC Help
Powered by ViewVC 1.1.23