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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Fri Aug 31 14:56:51 2007 UTC (17 years, 3 months ago) by pam-fi
Branch: MAIN
CVS Tags: v4r00
Changes since 1.22: +4 -1 lines
new variables added to TrkTrack + other changes

1 pam-fi 1.1 /**
2     * \file TrkLevel1.cpp
3     * \author Elena Vannuccini
4     */
5     #include <TrkLevel1.h>
6     #include <iostream>
7     using namespace std;
8 pam-fi 1.3 //......................................
9     // F77 routines
10     //......................................
11     extern "C" {
12    
13     // int readetaparam_();
14 pam-fi 1.11 float cog_(int*,int*);
15     float pfaeta_(int*,float*);
16     float pfaeta2_(int*,float*);
17     float pfaeta3_(int*,float*);
18     float pfaeta4_(int*,float*);
19 pam-fi 1.21 float pfaetal_(int*,float*);
20 pam-fi 1.22 int npfastrips_(int*,float*);
21 pam-fi 1.3
22     }
23 pam-fi 1.1 //--------------------------------------
24     //
25     //
26     //--------------------------------------
27     TrkCluster::TrkCluster(){
28    
29 pam-fi 1.11 // cout << "TrkCluster::TrkCluster()"<<endl;
30     view = -1;
31     maxs = -1;
32     indmax = -1;
33    
34     CLlength = 0;
35     clsignal = 0;
36     clsigma = 0;
37     cladc = 0;
38     clbad = 0;
39 pam-fi 1.1
40     };
41     //--------------------------------------
42     //
43     //
44     //--------------------------------------
45     TrkCluster::TrkCluster(const TrkCluster& t){
46    
47 pam-fi 1.11 view = t.view;
48     maxs = t.maxs;
49     indmax = t.indmax;
50    
51     CLlength = t.CLlength;
52     if(CLlength){
53     clsignal = new Float_t[CLlength];
54     clsigma = new Float_t[CLlength];
55     cladc = new Int_t[CLlength];
56     clbad = new Bool_t[CLlength];
57     for(Int_t i=0; i<CLlength;i++){
58     clsignal[i] = t.clsignal[i];
59     clsigma[i] = t.clsigma[i];
60     cladc[i] = t.cladc[i];
61     clbad[i] = t.clbad[i];
62 pam-fi 1.1 };
63 pam-fi 1.11 };
64 pam-fi 1.10 };
65     //--------------------------------------
66     //
67     //
68     //--------------------------------------
69     void TrkCluster::Clear(){
70 pam-fi 1.11
71     // cout << "void TrkCluster::Clear()"<<endl;
72     if(CLlength){
73     delete [] clsignal;
74     delete [] clsigma;
75     delete [] cladc;
76     delete [] clbad;
77     }
78    
79     view = 0;
80     maxs = 0;
81     indmax = 0;
82    
83     CLlength = 0;
84     clsignal = 0;
85     clsigma = 0;
86     cladc = 0;
87     clbad = 0;
88 pam-fi 1.1
89     };
90     //--------------------------------------
91     //
92     //
93     //--------------------------------------
94 pam-fi 1.2 /**
95 pam-fi 1.5 * Evaluate the cluster signal including a maximum number of adjacent
96     * strips, around maxs, having a significant signal.
97     * @param nstrip Maximum number of strips.
98     * @param cut Inclusion cut ( s > cut*sigma ).
99 pam-fi 1.22 * @param force Falg to force the PFA strip-inclusion pattern (nstrip>0)
100 pam-fi 1.5 * If nstrip<=0 only the inclusion cut is used to determine the cluster size.
101 pam-fi 1.2 */
102 pam-fi 1.22 Float_t TrkCluster::GetSignal(Int_t nstrip, Float_t cut, Bool_t force){
103 pam-fi 1.11
104     if(CLlength<=0)return 0;
105    
106 pam-fi 1.5 Float_t s = 0;
107    
108 pam-fi 1.22 //-----------------------------------
109     // inlcude strips with s > cut*sigma
110     //-----------------------------------
111    
112 pam-fi 1.5 if( nstrip<=0 ){
113     // for(Int_t is = 0; is < CLlength; is++){
114     // Float_t scut = cut*clsigma[is];
115     // if(clsignal[is] > scut) s += clsignal[is];
116     // };
117     for(Int_t is = indmax+1; is < CLlength; is++){
118     Float_t scut = cut*clsigma[is];
119     if(clsignal[is] > scut) s += clsignal[is];
120     else break;
121     };
122     for(Int_t is = indmax; is >=0; is--){
123     Float_t scut = cut*clsigma[is];
124     if(clsignal[is] > scut) s += clsignal[is];
125     else break;
126 pam-fi 1.2 };
127     return s;
128 pam-fi 1.5 };
129    
130 pam-fi 1.22 //---------------------------------------------------
131     // inlcude strips with s > cut*sigma, up to nstrip.
132     // strips are included in order of decreasing signal
133     //---------------------------------------------------
134     if( !force ){
135    
136     Int_t il = indmax;
137     Int_t ir = indmax;
138     Int_t inc = 0;
139    
140     if( clsignal[indmax] < cut*clsigma[indmax] ) return 0;
141    
142     while ( inc < nstrip ){
143     Float_t sl = -100000;
144     Float_t sr = -100000;
145     if( il >= 0 ) sl = clsignal[il];
146     if( ir < CLlength ) sr = clsignal[ir];
147     if( sl == sr && inc == 0 ){
148     s += clsignal[il]; //cout << inc<<" - "<< clsignal[il]<<" "<<s<<endl;
149     il--;
150     ir++;
151     }else if ( sl >= sr && sl > cut*clsigma[il] && inc !=0 ){
152     s += sl;//cout << inc<<" - "<< clsignal[il]<<" "<<s<<endl;
153     il--;
154     }else if ( sl < sr && sr > cut*clsigma[ir] ){
155     s += sr;//cout << inc<<" - " << clsignal[ir]<<" "<<s<<endl;
156     ir++;
157     }else break;
158    
159     inc++;
160     }
161     return s;
162    
163     }else{
164     //---------------------------------------------------
165     // evaluate signal using a fixed number of strips,
166     // following the PFA inclusion patters
167     //---------------------------------------------------
168     // --> signal of the central strip
169     Float_t sc = clsignal[indmax];
170     // signal of adjacent strips
171     Float_t sl1 = -9999.;
172     Float_t sl2 = -9999.;
173     Float_t sr1 = -9999.;
174     Float_t sr2 = -9999.;
175     if(indmax-1>=0) sl1 = clsignal[indmax-1];
176     if(indmax-2>=0) sl2 = clsignal[indmax-2];
177     if(indmax+1<CLlength) sr1 = clsignal[indmax+1];
178     if(indmax+2<CLlength) sr2 = clsignal[indmax+2];
179    
180     if(nstrip==1){
181     s = sc;
182     }else if(nstrip==2){
183     if( sl1>sr1 && sl1+sc!=0 )s = (sl1+sc);
184     if( sl1<sr1 && sr1+sc!=0 )s = (sc+sr1);
185     if( sl1==sr1 && sl1 != -9999.){
186     if( clsigma[indmax-1] < clsigma[indmax+1] && sl1+sc!=0 )s = (sl1+sc);
187     if( clsigma[indmax-1] > clsigma[indmax+1] && sc+sr1!=0 )s = (sc+sr1);
188     }
189     }else if(nstrip==3){
190     s = (sl1+sc+sr1);
191     }else if(nstrip==4){
192     if( sl2>sr2 && sl2+sl1+sc+sr1!=0 )s = (sl2+sl1+sc+sr1);
193     if( sl2<sr2 && sl1+sc+sr1+sr2!=0 )s = (sl1+sc+sr1+sr2);
194     if( sl2==sr2 && sl2 != -9999.){
195     if( clsigma[indmax-2] < clsigma[indmax+2] && sl2+sl1+sc+sr1!=0 )s = (sl2+sl1+sc+sr1);
196     if( clsigma[indmax-2] > clsigma[indmax+2] && sl1+sc+sr1+sr2!=0 )s = (sl1+sc+sr1+sr2);
197     }
198     }else if(nstrip==5){
199     s = (sl1+sc+sr1);
200     if(sl2 != -9999.)s += sl2;
201     if(sr2 != -9999.)s += sr2;
202     }else{
203     cout << "Float_t TrkCluster::GetSignal("<<nstrip<<","<<cut<<","<<force<<")- not implemented"<<endl;
204     }
205 pam-fi 1.5
206 pam-fi 1.22 }
207 pam-fi 1.5
208 pam-fi 1.22 return 0.;
209 pam-fi 1.5
210 pam-fi 1.2 };
211 pam-fi 1.5
212 pam-fi 1.11
213 pam-fi 1.2 /**
214 pam-fi 1.11 * Evaluate the cluster signal-to-noise, as defined by Turchetta, including a
215     * maximum number of adjacent strips, around maxs, having a significant signal.
216 pam-fi 1.5 * @param nstrip Maximum number of strips.
217     * @param cut Inclusion cut ( s > cut*sigma ).
218     * If nstrip<=0 only the inclusion cut is used to determine the cluster size.
219 pam-fi 1.3 */
220 pam-fi 1.5 Float_t TrkCluster::GetSignalToNoise(Int_t nstrip, Float_t cut){
221 pam-fi 1.3
222 pam-fi 1.11 if(CLlength<=0)return 0;
223    
224 pam-fi 1.5 Float_t sn = 0;
225    
226     if( nstrip<=0 ){
227     for(Int_t is = indmax+1; is < CLlength; is++){
228     Float_t scut = cut*clsigma[is];
229     if(clsignal[is] > scut) sn += clsignal[is]/clsigma[is];
230     else break;
231     };
232     for(Int_t is = indmax; is >=0; is--){
233     Float_t scut = cut*clsigma[is];
234     if(clsignal[is] > scut) sn += clsignal[is]/clsigma[is];
235     else break;
236     };
237 pam-fi 1.3 return sn;
238 pam-fi 1.5 };
239    
240    
241     Int_t il = indmax;
242     Int_t ir = indmax;
243     Int_t inc = 0;
244    
245     if( clsignal[indmax] < cut*clsigma[indmax] ) return 0;
246    
247     while ( inc < nstrip ){
248     Float_t sl = -100000;
249     Float_t sr = -100000;
250     if( il >= 0 ) sl = clsignal[il];
251     if( ir < CLlength ) sr = clsignal[ir];
252     if( sl == sr && inc == 0 ){
253     sn += clsignal[il]/clsigma[il];
254     il--;
255     ir++;
256     }else if ( sl >= sr && sl > cut*clsigma[il] && inc !=0 ){
257     sn += sl/clsigma[il];
258     il--;
259     }else if ( sl < sr && sr > cut*clsigma[ir] ){
260     sn += sr/clsigma[ir];
261     ir++;
262     }else break;
263    
264     inc++;
265     }
266     return sn;
267 pam-fi 1.3 };
268     /**
269 pam-fi 1.2 * Evaluate the cluster multiplicity.
270     * @param cut Inclusion cut.
271     */
272     Int_t TrkCluster::GetMultiplicity(Float_t cut){
273 pam-fi 1.11
274     if(CLlength<=0)return 0;
275    
276     Int_t m = 0;
277    
278     for(Int_t is = indmax+1; is < CLlength; is++){
279     Float_t scut = cut*clsigma[is];
280     if(clsignal[is] > scut) m++;
281     else break;
282     };
283     for(Int_t is = indmax; is >=0; is--){
284     Float_t scut = cut*clsigma[is];
285     if(clsignal[is] > scut) m++;
286     else break;
287     };
288     return m;
289 pam-fi 1.2 };
290     /**
291     * True if the cluster contains bad strips.
292     * @param nbad Number of strips around the maximum.
293     */
294     Bool_t TrkCluster::IsBad(Int_t nbad){
295 pam-fi 1.11
296     if(CLlength<=0)return 0;
297    
298     Int_t il,ir;
299     il = indmax;
300     ir = indmax;
301     for(Int_t i=1; i<nbad; i++){
302 pam-fi 1.18 if (ir == CLlength-1 && il == 0)break;
303     else if (ir == CLlength-1 && il != 0)il--;
304     else if (ir != CLlength-1 && il == 0)ir++;
305 pam-fi 1.11 else{
306     if(clsignal[il-1] > clsignal[ir+1])il--;
307     else ir++;
308 pam-fi 1.2 }
309 pam-fi 1.11 }
310     Int_t isbad = 0;
311     for(Int_t i=il; i<=ir; i++)isbad += clbad[i];
312    
313     return ( isbad != nbad );
314 pam-fi 1.2 };
315 pam-fi 1.11 /**
316     * True if the cluster contains saturated strips.
317     * @param nbad Number of strips around the maximum.
318     */
319     Bool_t TrkCluster::IsSaturated(Int_t nbad){
320    
321     if(CLlength<=0)return 0;
322    
323     Int_t il,ir;
324     il = indmax;
325     ir = indmax;
326     for(Int_t i=1; i<nbad; i++){
327 pam-fi 1.18 if (ir == CLlength-1 && il == 0)break;
328     else if (ir == CLlength-1 && il != 0)il--;
329     else if (ir != CLlength-1 && il == 0)ir++;
330 pam-fi 1.11 else{
331     if(clsignal[il-1] > clsignal[ir+1])il--;
332     else ir++;
333     }
334     }
335     Int_t isbad = 0;
336     for(Int_t i=il; i<=ir; i++){
337     if( IsX() && cladc[i] > 2980 )isbad++;
338     if( IsY() && cladc[i] < 80 )isbad++;
339     }
340     return ( isbad != 0 );
341    
342     }
343 pam-fi 1.2 //--------------------------------------
344     //
345     //
346     //--------------------------------------
347 pam-fi 1.1 void TrkCluster::Dump(){
348    
349 pam-fi 1.11 cout << "----- Cluster" << endl;
350     cout << "View "<<view << " - Ladder "<<GetLadder()<<endl;
351     cout << "Position of maximun "<< maxs <<endl;
352     cout << "Multiplicity "<< GetMultiplicity() <<endl;
353     cout << "Tot signal "<< GetSignal() << " (ADC channels)"<<endl ;
354 pam-fi 1.18 cout << "Signal/Noise "<< GetSignalToNoise()<<endl;
355     cout << "COG "<< GetCOG(0)<<endl;;
356     cout << "Strip signals ";
357 pam-fi 1.11 for(Int_t i =0; i<CLlength; i++)cout << " " <<clsignal[i];
358     cout <<endl<< "Strip sigmas ";
359     for(Int_t i =0; i<CLlength; i++)cout << " " <<clsigma[i];
360     cout <<endl<< "Strip ADC ";
361     for(Int_t i =0; i<CLlength; i++)cout << " " <<cladc[i];
362     cout <<endl<< "Strip BAD ";
363     for(Int_t i =0; i<CLlength; i++){
364     if(i==indmax)cout << " *" <<clbad[i]<<"*";
365     else cout << " " <<clbad[i];
366     }
367     cout << endl;
368 pam-fi 1.1
369     }
370     //--------------------------------------
371     //
372     //
373     //--------------------------------------
374 pam-fi 1.3 /**
375     * Method to fill a level1 struct with only one cluster (done to use F77 p.f.a. routines on a cluster basis).
376     */
377 pam-fi 1.14 void TrkCluster::GetLevel1Struct(cTrkLevel1* l1){
378 pam-fi 1.3
379 pam-fi 1.6 // cTrkLevel1* l1 = new cTrkLevel1;
380    
381 pam-fi 1.14 // cTrkLevel1* l1 = &level1event_ ;
382 pam-fi 1.3
383 pam-fi 1.6 l1->nclstr1 = 1;
384     l1->view[0] = view;
385     l1->ladder[0] = GetLadder();
386     l1->maxs[0] = maxs;
387     l1->mult[0] = GetMultiplicity();
388     l1->dedx[0] = GetSignal();
389     l1->indstart[0] = 1;
390     l1->indmax[0] = indmax+1;
391     l1->totCLlength = CLlength;
392     for(Int_t i=0; i<CLlength; i++){
393     l1->clsignal[i] = clsignal[i];
394     l1->clsigma[i] = clsigma[i];
395     l1->cladc[i] = cladc[i];
396     l1->clbad[i] = clbad[i];
397     };
398    
399 pam-fi 1.14 // return l1;
400 pam-fi 1.3 };
401     //--------------------------------------
402     //
403     //
404     //--------------------------------------
405     /**
406     * Evaluates the Center-Of-Gravity (COG) of the cluster, in strips, relative to the strip with the maximum signal (TrkCluster::maxs).
407     * @param ncog Number of strips to evaluate COG.
408     * If ncog=0, the COG of the cluster is evaluated according to the cluster multiplicity (defined by the inclusion cut).
409     * If ncog>0, the COG is evaluated using ncog strips, even if they have a negative signal (according to G.Landi)
410     */
411     Float_t TrkCluster::GetCOG(Int_t ncog){
412    
413 pam-fi 1.6 int ic = 1;
414     GetLevel1Struct();
415     return cog_(&ncog,&ic);
416    
417     };
418     /**
419     * Evaluates the Center-Of-Gravity (COG) of the cluster, in strips, relative to the strip with the maximum signal (TrkCluster::maxs),
420     * choosing the number of strips according to the angle, as implemented for the eta-algorythm .
421     * @param angle Projected angle in degree.
422     */
423     Float_t TrkCluster::GetCOG(Float_t angle){
424    
425     Int_t neta = 0;
426    
427     // Float_t eta = GetETA(0,angle);
428     // for(neta=2; neta<10; neta++) if( eta == GetETA(neta,angle) ) break;
429     // if(eta != GetETA(neta,angle) )cout << "Attenzione!! pasticcio "<<endl;
430    
431     if( view%2 ){ //Y
432     neta=2;
433     }else{ //X
434 pam-fi 1.7 if( fabs(angle) <= 10. ){
435 pam-fi 1.6 neta = 2;
436 pam-fi 1.7 }else if( fabs(angle) > 10. && fabs(angle) <= 15. ){
437 pam-fi 1.6 neta = 3;
438     }else{
439     neta = 4;
440     };
441     };
442    
443     return GetCOG(neta);
444 pam-fi 1.3
445     };
446     //--------------------------------------
447     //
448     //
449     //--------------------------------------
450     /**
451 pam-fi 1.23 * Evaluates the cluster position, in pitch units, relative to the strip
452     * with the maximum signal (TrkCluster::maxs), by applying the non-linear
453     * ETA-algorythm.
454 pam-fi 1.3 * @param neta Number of strips to evaluate ETA.
455 pam-fi 1.21 * @param angle Projected (effective) angle between particle track and detector plane.
456 pam-fi 1.23 * @landi flag to apply Landi correction
457 pam-fi 1.3 * Implemented values of neta are 2,3,4. If neta=0, ETA2, ETA3 and ETA4 are applied according to the angle.
458     */
459 pam-fi 1.21 Float_t TrkCluster::GetETA(Int_t neta, float angle, bool landi){
460 pam-fi 1.3
461 pam-fi 1.6 // cout << "GetETA(neta,angle) "<< neta << " "<< angle;
462 pam-fi 1.3 // LoadPfaParam();
463 pam-fi 1.6
464 pam-fi 1.14 TrkParams::Load(4);
465     if( !TrkParams::IsLoaded(4) ){
466 pam-fi 1.22 cout << "Float_t TrkCluster::GetETA(Int_t neta, float angle, bool landi) --- ERROR --- p.f.a. parameters not loaded"<<endl;
467 pam-fi 1.14 return 0;
468     }
469    
470 pam-fi 1.6 float ax = angle;
471     int ic = 1;
472     GetLevel1Struct();
473 pam-fi 1.21 if( neta == 0 && !landi) return pfaeta_(&ic,&ax);
474     else if(neta == 0 && landi ) return pfaetal_(&ic,&ax);
475     else if(neta == 2 ) return pfaeta2_(&ic,&ax);
476     else if(neta == 3 ) return pfaeta3_(&ic,&ax);
477     else if(neta == 4 ) return pfaeta4_(&ic,&ax);
478 pam-fi 1.22 else cout << "TrkCluster::GetETA("<<neta<<","<<angle<<","<<landi<<") not implemented\n";
479 pam-fi 1.6 return 0;
480    
481 pam-fi 1.3 };
482 pam-fi 1.21
483     /**
484 pam-fi 1.22 * Evaluates the cluster position, in pitch unit, relative to the strip with
485 pam-fi 1.21 * the maximum signal (TrkCluster::maxs), by applying the PFA set as default (see TrkParams).
486     * @param angle Projected (effective) angle between particle track and detector plane.
487     */
488     Float_t TrkCluster::GetPositionPU(float angle){
489    
490 pam-fi 1.22 if ( TrkParams::GetPFA() == 0 )return GetETA(0,angle,false);
491     else if( TrkParams::GetPFA() == 2 )return GetETA(2,angle,false);
492     else if( TrkParams::GetPFA() == 3 )return GetETA(3,angle,false);
493     else if( TrkParams::GetPFA() == 4 )return GetETA(4,angle,false);
494     else if( TrkParams::GetPFA() == 5 )return GetETA(0,angle,true);
495     else if( TrkParams::GetPFA() == 10 )return GetCOG(0);
496     else if( TrkParams::GetPFA() == 11 )return GetCOG(1);
497     else if( TrkParams::GetPFA() == 12 )return GetCOG(2);
498     else if( TrkParams::GetPFA() == 13 )return GetCOG(3);
499     else if( TrkParams::GetPFA() == 14 )return GetCOG(4);
500     else cout << " TrkCluster::GetPositionPU(float "<<angle<<") -- WARNING -- PFA="<<TrkParams::GetPFA()<<" not implemented"<<endl;
501 pam-fi 1.21
502     return 0.;
503    
504     }
505    
506 pam-fi 1.22 /**
507     * Give the number of strip used to evaluate the cluster coordinate
508     * according to the p.f.a.
509     * It returns 0 when the COG is used (in this case the number of strip used
510     * equals the multiplicity).
511     */
512     Int_t TrkCluster::GetPFAstrips(float angle){
513    
514     float ax = angle;
515     int ic = 1;
516     GetLevel1Struct();
517     return npfastrips_(&ic,&ax);
518    
519     }
520    
521 pam-fi 1.3 //--------------------------------------
522     //
523     //
524     //--------------------------------------
525 pam-fi 1.1 TrkLevel1::TrkLevel1(){
526 pam-fi 1.6
527 pam-fi 1.11 // cout << "TrkLevel1::TrkLevel1()"<<endl;
528     // Cluster = new TClonesArray("TrkCluster");
529     Cluster = 0;
530 pam-fi 1.6 for(Int_t i=0; i<12 ; i++){
531     good[i] = -1;
532     for(Int_t j=0; j<24 ; j++){
533     cn[j][i]=0;
534     cnn[j][i]=0;
535 pam-fi 1.1 };
536 pam-fi 1.6 };
537 pam-fi 1.17 TrkParams::SetTrackingMode();
538     TrkParams::SetPrecisionFactor();
539     TrkParams::SetStepMin();
540     TrkParams::SetPFA();
541 pam-fi 1.1 }
542     //--------------------------------------
543     //
544     //
545     //--------------------------------------
546 pam-fi 1.12 void TrkLevel1::Set(){
547     if(!Cluster)Cluster = new TClonesArray("TrkCluster");
548     }
549     //--------------------------------------
550     //
551     //
552     //--------------------------------------
553 pam-fi 1.1 void TrkLevel1::Dump(){
554    
555 pam-fi 1.6 cout<<"DSP status: ";
556     for(Int_t i=0; i<12 ; i++)cout<<good[i]<<" ";
557     cout<<endl;
558 pam-fi 1.9 cout<<"VA1 mask : "<<endl;
559     for(Int_t i=0; i<12 ; i++){
560     for(Int_t ii=0; ii<24 ; ii++){
561     Int_t mask = cnn[ii][i];
562     if(mask>0)mask=1;
563     cout<<mask<<" ";
564     }
565     cout <<endl;
566     }
567 pam-fi 1.6
568 pam-fi 1.11 if(!Cluster)return;
569 pam-fi 1.6 TClonesArray &t = *Cluster;
570     for(int i=0; i<this->nclstr(); i++) ((TrkCluster *)t[i])->Dump();
571    
572 pam-fi 1.1 }
573 pam-fi 1.18 /**
574     * \brief Dump processing status
575     */
576     void TrkLevel1::StatusDump(int view){
577     cout << "DSP n. "<<view+1<<" (level1-)status: "<<hex<<showbase<<good[view]<<dec<<endl;
578     };
579     /**
580     * \brief Check event status
581     *
582     * Check the event status, according to a flag-mask given as input.
583     * Return true if the view passes the check.
584     *
585     * @param view View number (0-11)
586     * @param flagmask Mask of flags to check (eg. flagmask=0x111 no missing packet,
587     * no crc error, no software alarm)
588     *
589     * @see TrkLevel2 class definition to know how the status flag is defined
590     *
591     */
592     Bool_t TrkLevel1::StatusCheck(int view, int flagmask){
593    
594     if( view<0 || view >= 12)return false;
595     return !(good[view]&flagmask);
596    
597     };
598    
599    
600 pam-fi 1.1 //--------------------------------------
601     //
602     //
603     //--------------------------------------
604     /**
605     * Fills a TrkLevel1 object with values from a struct cTrkLevel1 (to get data from F77 common).
606     */
607 pam-fi 1.10 void TrkLevel1::SetFromLevel1Struct(cTrkLevel1 *l1, Bool_t full){
608 pam-fi 1.1
609 pam-fi 1.15 // cout << "void TrkLevel1::SetFromLevel1Struct(cTrkLevel1 *l1, Bool_t full)"<<endl;
610    
611     Clear();
612 pam-fi 1.10 // ---------------
613 pam-fi 1.6 // *** CLUSTER ***
614 pam-fi 1.10 // ---------------
615 pam-fi 1.6 TrkCluster* t_cl = new TrkCluster();
616 pam-fi 1.11 if(!Cluster)Cluster = new TClonesArray("TrkCluster");
617 pam-fi 1.6 TClonesArray &t = *Cluster;
618     for(int i=0; i<l1->nclstr1; i++){
619 pam-fi 1.10
620     t_cl->Clear();
621 pam-fi 1.11 // if( full || (!full && l1->whichtrack[i]) ){
622    
623     t_cl->view = l1->view[i];
624     t_cl->maxs = l1->maxs[i];
625    
626 pam-fi 1.10 if( full || (!full && l1->whichtrack[i]) ){
627 pam-fi 1.11 t_cl->indmax = l1->indmax[i] - l1->indstart[i];
628 pam-fi 1.10 Int_t from = l1->indstart[i] -1;
629     Int_t to = l1->totCLlength ;
630     if(i != l1->nclstr1-1)to = l1->indstart[i+1] -1 ;
631     t_cl->CLlength = to - from ;
632    
633     t_cl->clsignal = new Float_t[t_cl->CLlength];
634     t_cl->clsigma = new Float_t[t_cl->CLlength];
635     t_cl->cladc = new Int_t[t_cl->CLlength];
636     t_cl->clbad = new Bool_t[t_cl->CLlength];
637 pam-fi 1.19
638 pam-fi 1.10 Int_t index = 0;
639     for(Int_t is = from; is < to; is++ ){
640     t_cl->clsignal[index] = (Float_t) l1->clsignal[is];
641     t_cl->clsigma[index] = (Float_t) l1->clsigma[is];
642     t_cl->cladc[index] = (Int_t) l1->cladc[is];
643     t_cl->clbad[index] = (Bool_t) l1->clbad[is];
644     index++;
645     };
646     }
647     new(t[i]) TrkCluster(*t_cl); // <<< store cluster
648 pam-fi 1.6 };
649    
650     delete t_cl;
651    
652 pam-fi 1.10 // -------------------------
653 pam-fi 1.6 // ****general variables****
654 pam-fi 1.10 // -------------------------
655 pam-fi 1.6 for(Int_t i=0; i<12 ; i++){
656     good[i] = l1->good[i];
657     for(Int_t j=0; j<24 ; j++){
658     cn[j][i] = l1->cnev[j][i];
659     // cnrms[j][i] = l1->cnrmsev[j][i];
660     cnn[j][i] = l1->cnnev[j][i];
661 pam-fi 1.1 };
662 pam-fi 1.6 };
663    
664 pam-fi 1.1 }
665     /**
666     * Fills a struct cTrkLevel1 with values from a TrkLevel1 object (to put data into a F77 common).
667     */
668    
669 pam-fi 1.14 void TrkLevel1::GetLevel1Struct(cTrkLevel1* l1) {
670    
671     // cTrkLevel1* l1 = &level1event_ ;
672    
673 pam-fi 1.6 for(Int_t i=0; i<12 ; i++){
674     l1->good[i] = good[i];
675     for(Int_t j=0; j<24 ; j++){
676 pam-fi 1.14 l1->cnev[j][i] = cn[j][i] ;
677     l1->cnnev[j][i] = cnn[j][i] ;
678     l1->cnrmsev[j][i] = 0. ;
679 pam-fi 1.1 };
680 pam-fi 1.14 l1->fshower[i] = 0;
681 pam-fi 1.6 };
682 pam-fi 1.14
683     l1->nclstr1=0;
684     l1->totCLlength=0;
685     Int_t index=0;
686 pam-fi 1.11 if(Cluster){
687 pam-fi 1.14 Int_t i=0;
688     for(Int_t ii=0;ii<Cluster->GetEntries();ii++){
689     TrkCluster *clu = GetCluster(ii);
690     // ----------------------------------------
691     // attenzione!!
692     // se il cluster non e` salvato (view = 0)
693     // DEVE essere escluso dal common F77
694     // ----------------------------------------
695     if(clu->view != 0 ){
696     l1->view[i] = clu->view;
697     l1->ladder[i] = clu->GetLadder();
698     l1->maxs[i] = clu->maxs;
699     l1->mult[i] = clu->GetMultiplicity();
700     l1->dedx[i] = clu->GetSignal();
701     l1->indstart[i] = index+1;
702     l1->indmax[i] = l1->indstart[i] + clu->indmax;
703     l1->totCLlength += clu->CLlength;
704     for(Int_t iw=0; iw < clu->CLlength; iw++){
705     l1->clsignal[index] = clu->clsignal[iw];
706     l1->clsigma[index] = clu->clsigma[iw];
707     l1->cladc[index] = clu->cladc[iw];
708     l1->clbad[index] = clu->clbad[iw];
709     index++;
710     }
711     i++;
712     }
713 pam-fi 1.11 }
714 pam-fi 1.14 l1->nclstr1 = i;
715 pam-fi 1.6 }
716 pam-fi 1.14
717     // return l1;
718 pam-fi 1.3 }
719     //--------------------------------------
720     //
721     //
722     //--------------------------------------
723     void TrkLevel1::Clear(){
724 pam-fi 1.6
725     for(Int_t i=0; i<12 ; i++){
726     good[i] = -1;
727     for(Int_t j=0; j<24 ; j++){
728     cn[j][i] = 0;
729     cnn[j][i] = 0;
730 pam-fi 1.3 };
731 pam-fi 1.6 };
732 pam-fi 1.11 // if(Cluster)Cluster->Clear("C");
733     if(Cluster)Cluster->Delete();
734 pam-fi 1.6
735 pam-fi 1.1 }
736     //--------------------------------------
737     //
738     //
739     //--------------------------------------
740 pam-fi 1.3 void TrkLevel1::Delete(){
741 pam-fi 1.11
742     // Clear();
743     if(Cluster)Cluster->Delete();
744     if(Cluster)delete Cluster;
745 pam-fi 1.6
746 pam-fi 1.1 }
747     //--------------------------------------
748     //
749     //
750     //--------------------------------------
751     TrkCluster *TrkLevel1::GetCluster(int is){
752    
753 pam-fi 1.11 if(!Cluster)return 0;
754     if(is >= nclstr()){
755     cout << "** TrkLevel1::GetCluster(int) ** Cluster "<< is << " does not exits! " << endl;
756     cout << "( Stored clusters nclstr() = "<< this->nclstr()<<" )" << endl;
757     return 0;
758     }
759    
760     TClonesArray &t = *(Cluster);
761     TrkCluster *cluster = (TrkCluster*)t[is];
762     return cluster;
763 pam-fi 1.1 }
764 pam-fi 1.3 //--------------------------------------
765     //
766     //
767     //--------------------------------------
768 pam-fi 1.14 // /**
769     // * Load Position-Finding-Algorythm parameters (call the F77 routine).
770     // *
771     // */
772     // int TrkLevel1::LoadPfaParam(TString path){
773    
774     // if( path.IsNull() ){
775     // path = gSystem->Getenv("PAM_CALIB");
776     // if(path.IsNull()){
777     // cout << " TrkLevel1::LoadPfaParam() ==> No PAMELA environment variables defined "<<endl;
778     // return 0;
779     // }
780     // path.Append("/trk-param/eta_param-0/");
781     // }
782    
783     // strcpy(path_.path,path.Data());
784     // path_.pathlen = path.Length();
785     // path_.error = 0;
786     // cout <<"Loading p.f.a. parameters: "<<path<<endl;
787     // return readetaparam_();
788     // }
789    
790     // /**
791     // * Load magnetic field parameters (call the F77 routine).
792     // *
793     // */
794     // int TrkLevel1::LoadFieldParam(TString path){
795    
796     // // if( strcmp(path_.path,path.Data()) ){
797     // if( path.IsNull() ){
798     // path = gSystem->Getenv("PAM_CALIB");
799     // if(path.IsNull()){
800     // cout << " TrkLevel1::LoadFieldParam() ==> No PAMELA environment variables defined "<<endl;
801     // return 0;
802     // }
803     // path.Append("/trk-param/field_param-0/");
804     // }
805     // cout <<"Loading magnetic field "<<path<<endl;
806     // strcpy(path_.path,path.Data());
807     // path_.pathlen = path.Length();
808     // path_.error = 0;
809     // return readb_();
810     // // }
811     // // return 0;
812     // }
813     // /**
814     // * Load magnetic field parameters (call the F77 routine).
815     // *
816     // */
817     // int TrkLevel1::LoadChargeParam(TString path){
818    
819     // // if( strcmp(path_.path,path.Data()) ){
820     // if( path.IsNull() ){
821     // path = gSystem->Getenv("PAM_CALIB");
822     // if(path.IsNull()){
823     // cout << " TrkLevel1::LoadChargeParam() ==> No PAMELA environment variables defined "<<endl;
824     // return 0;
825     // }
826     // path.Append("/trk-param/charge_param-1/");
827     // }
828     // cout <<"Loading charge-correlation parameters: "<<path<<endl;
829     // strcpy(path_.path,path.Data());
830     // path_.pathlen = path.Length();
831     // path_.error = 0;
832     // return readchargeparam_();
833     // // }
834     // // return 0;
835     // }
836     // /**
837     // * Load magnetic field parameters (call the F77 routine).
838     // *
839     // */
840     // int TrkLevel1::LoadAlignmentParam(TString path){
841    
842     // // if( strcmp(path_.path,path.Data()) ){
843     // if( path.IsNull() ){
844     // path = gSystem->Getenv("PAM_CALIB");
845     // if(path.IsNull()){
846     // cout << " TrkLevel1::LoadAlignmentParam() ==> No PAMELA environment variables defined "<<endl;
847     // return 0;
848     // }
849     // path.Append("/trk-param/align_param-0/");
850     // }
851     // cout <<"Loading alignment parameters: "<<path<<endl;
852     // strcpy(path_.path,path.Data());
853     // path_.pathlen = path.Length();
854     // path_.error = 0;
855     // return readalignparam_();
856     // // }
857     // // return 0;
858     // }
859     // /**
860     // * Load magnetic field parameters (call the F77 routine).
861     // *
862     // */
863     // int TrkLevel1::LoadMipParam(TString path){
864    
865     // // if( strcmp(path_.path,path.Data()) ){
866     // if( path.IsNull() ){
867     // path = gSystem->Getenv("PAM_CALIB");
868     // if(path.IsNull()){
869     // cout << " TrkLevel1::LoadMipParam() ==> No PAMELA environment variables defined "<<endl;
870     // return 0;
871     // }
872     // path.Append("/trk-param/mip_param-0/");
873     // }
874     // cout <<"Loading ADC-to-MIP conversion parameters: "<<path<<endl;
875     // strcpy(path_.path,path.Data());
876     // path_.pathlen = path.Length();
877     // path_.error = 0;
878     // return readmipparam_();
879     // // }
880     // // return 0;
881     // }
882     // /**
883     // * Load magnetic field parameters (call the F77 routine).
884     // *
885     // */
886     // int TrkLevel1::LoadVKMaskParam(TString path){
887 pam-fi 1.3
888 pam-fi 1.14 // // if( strcmp(path_.path,path.Data()) ){
889     // if( path.IsNull() ){
890     // path = gSystem->Getenv("PAM_CALIB");
891     // if(path.IsNull()){
892     // cout << " TrkLevel1::LoadVKMaskParam() ==> No PAMELA environment variables defined "<<endl;
893     // return 0;
894     // }
895     // path.Append("/trk-param/mask_param-1/");
896     // }
897     // cout <<"Loading VK-mask parameters: "<<path<<endl;
898     // strcpy(path_.path,path.Data());
899     // path_.pathlen = path.Length();
900     // path_.error = 0;
901     // return readvkmask_();
902     // // }
903     // // return 0;
904     // }
905    
906     // /**
907     // * Load all (default) parameters. Environment variable must be defined.
908     // *
909     // */
910     // int TrkLevel1::LoadParams(){
911    
912     // int result=0;
913    
914     // result = result * LoadFieldParam();
915     // result = result * LoadPfaParam();
916     // result = result * LoadChargeParam();
917     // result = result * LoadAlignmentParam();
918     // result = result * LoadMipParam();
919     // result = result * LoadVKMaskParam();
920    
921     // return result;
922     // }
923    
924    
925    
926     int TrkLevel1::GetPfaNbinsAngle(){
927     TrkParams::Load(4);
928     if( !TrkParams::IsLoaded(4) ){
929     cout << "int TrkLevel1::GetPfaNbinsAngle() --- ERROR --- p.f.a. parameters not loaded"<<endl;
930     return 0;
931     }
932     return pfa_.nangbin;
933     };
934    
935     int TrkLevel1::GetPfaNbinsETA(){
936     TrkParams::Load(4);
937     if( !TrkParams::IsLoaded(4) ){
938     cout << "int TrkLevel1::GetPfaNbinsETA() --- ERROR --- p.f.a. parameters not loaded"<<endl;
939     return 0;
940     }
941     return pfa_.netaval;
942     };
943 pam-fi 1.1
944 pam-fi 1.13 /**
945     *
946     *
947     */
948     float* TrkLevel1::GetPfaCoord(TString pfa, int nview, int nladder, int nang){
949 pam-fi 1.14
950     TrkParams::Load(4);
951     if( !TrkParams::IsLoaded(4) ){
952     cout << "float* TrkLevel1::GetPfaCoord(TString pfa, int nview, int nladder, int nang) --- ERROR --- p.f.a. parameters not loaded"<<endl;
953     return 0;
954     }
955 pam-fi 1.13
956     int nbins = GetPfaNbinsETA();
957     if(!nbins)return 0;
958    
959     float *fcorr = new float [nbins];
960    
961     if(!pfa.CompareTo("ETA2",TString::kIgnoreCase)){
962     for(int ib=0; ib<nbins; ib++){
963     fcorr[ib] = pfa_.feta2[nang][nladder][nview][ib];
964     cout << pfa_.eta2[nang][ib] << " - " << pfa_.feta2[nang][nladder][nview][ib]<<endl;;
965     }
966     }else if (!pfa.CompareTo("ETA3",TString::kIgnoreCase)){
967     for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.feta3[nang][nladder][nview][ib];
968     }else if (!pfa.CompareTo("ETA4",TString::kIgnoreCase)){
969     for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.feta4[nang][nladder][nview][ib];
970     }else{
971     cout << pfa<<" pfa parameters not implemented "<<endl;
972     return 0;
973     }
974    
975     return fcorr;
976    
977     };
978    
979     float* TrkLevel1::GetPfaAbs(TString pfa, int nang){
980    
981 pam-fi 1.14 TrkParams::Load(4);
982     if( !TrkParams::IsLoaded(4) ){
983     cout << "float* TrkLevel1::GetPfaAbs(TString pfa, int nang) --- ERROR --- p.f.a. parameters not loaded"<<endl;
984     return 0;
985     }
986    
987 pam-fi 1.13 int nbins = GetPfaNbinsETA();
988     if(!nbins)return 0;
989    
990     float *fcorr = new float [nbins];
991    
992     if(!pfa.CompareTo("ETA2",TString::kIgnoreCase)){
993     for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta2[nang][ib];
994     }else if (!pfa.CompareTo("ETA3",TString::kIgnoreCase)){
995     for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta3[nang][ib];
996     }else if (!pfa.CompareTo("ETA4",TString::kIgnoreCase)){
997     for(int ib=0; ib<nbins; ib++)fcorr[ib] = pfa_.eta4[nang][ib];
998     }else{
999     cout << pfa<<" pfa parameters not implemented "<<endl;
1000     return 0;
1001     }
1002    
1003     return fcorr;
1004    
1005 pam-fi 1.14 };
1006    
1007     /**
1008     * Method to call the F77 routine that performs level1->level2 processing.
1009     * The level2 output is stored in a common block, which can be retrieved
1010     * by mean of the method TrkLevel2::SetFromLevel2Struct().
1011     * NB If the TrkLevel1 object is readout from a tree, and the
1012     * TrkLevel1::ProcessEvent(int pfa) is used to reprocess the event, attention
1013     * should be payed to the fact that single clusters (clusters not associated
1014 pam-fi 1.20 * with any track) might not be stored. Full reprocessing should be done starting
1015     * from level0 data.
1016 pam-fi 1.14 */
1017 pam-fi 1.20 //int TrkLevel1::ProcessEvent(int pfa){
1018     int TrkLevel1::ProcessEvent(){
1019 pam-fi 1.14
1020     // cout << "int TrkLevel1::ProcessEvent()" << endl;
1021     TrkParams::Load( );
1022     if( !TrkParams::IsLoaded() )return 0;
1023 pam-fi 1.13
1024 pam-fi 1.14 GetLevel1Struct();
1025    
1026 pam-fi 1.17 // analysisflight_(&pfa);
1027 pam-fi 1.20 // TrkParams::SetPFA(pfa);
1028 pam-fi 1.17 analysisflight_();
1029 pam-fi 1.14
1030     return 1;
1031 pam-fi 1.13
1032 pam-fi 1.14 }
1033 pam-fi 1.13
1034 pam-fi 1.1
1035     ClassImp(TrkLevel1);
1036     ClassImp(TrkCluster);

  ViewVC Help
Powered by ViewVC 1.1.23