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

Diff of /DarthVader/TrackerLevel2/src/TrkLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by pam-fi, Fri Jun 30 09:48:15 2006 UTC revision 1.40 by pam-fi, Fri Aug 31 14:56:51 2007 UTC
# Line 4  Line 4 
4   */   */
5  #include <TrkLevel2.h>  #include <TrkLevel2.h>
6  #include <iostream>  #include <iostream>
7    #include <math.h>
8  using namespace std;  using namespace std;
9  //......................................  //......................................
10  // F77 routines  // F77 routines
# Line 11  using namespace std; Line 12  using namespace std;
12  extern "C" {      extern "C" {    
13      void dotrack_(int*, double*, double*, double*, double*, int*);      void dotrack_(int*, double*, double*, double*, double*, int*);
14      void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);      void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);
15      int  readb_(const char*);      void mini2_(int*,int*,int*);
16        void guess_();
17        void gufld_(float*, float*);
18        float risxeta2_(float *);
19        float risxeta3_(float *);
20        float risxeta4_(float *);
21        float risyeta2_(float *);
22  }  }
23    
24  //--------------------------------------  //--------------------------------------
25  //  //
26  //  //
27  //--------------------------------------  //--------------------------------------
28  TrkTrack::TrkTrack(){  TrkTrack::TrkTrack(){
29    //    cout << "TrkTrack::TrkTrack()" << endl;
30      seqno = -1;      seqno = -1;
31      image = -1;      image = -1;
32      chi2  = 0;      chi2  = 0;
33        nstep = 0;
34      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
35          al[it1] = 0;          al[it1] = 0;
36          for(int it2=0;it2<5;it2++)          for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
             coval[it1][it2] = 0;  
37      };      };
38      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
39          xgood[ip]  = 0;          xgood[ip]  = 0;
# Line 34  TrkTrack::TrkTrack(){ Line 43  TrkTrack::TrkTrack(){
43          zm[ip]     = 0;          zm[ip]     = 0;
44          resx[ip]   = 0;          resx[ip]   = 0;
45          resy[ip]   = 0;          resy[ip]   = 0;
46            tailx[ip]   = 0;
47            taily[ip]   = 0;
48          xv[ip]     = 0;          xv[ip]     = 0;
49          yv[ip]     = 0;          yv[ip]     = 0;
50          zv[ip]     = 0;          zv[ip]     = 0;
# Line 41  TrkTrack::TrkTrack(){ Line 52  TrkTrack::TrkTrack(){
52          ayv[ip]    = 0;          ayv[ip]    = 0;
53          dedx_x[ip] = 0;          dedx_x[ip] = 0;
54          dedx_y[ip] = 0;          dedx_y[ip] = 0;
55      };              multmaxx[ip] = 0;
56            multmaxy[ip] = 0;
57            seedx[ip]  = 0;  
58            seedy[ip]  = 0;
59            xpu[ip]    = 0;  
60            ypu[ip]    = 0;  
61    
62        };
63    
64        TrkParams::SetTrackingMode();
65        TrkParams::SetPrecisionFactor();
66        TrkParams::SetStepMin();
67        TrkParams::SetPFA();
68    
69  };  };
70  //--------------------------------------  //--------------------------------------
71  //  //
# Line 51  TrkTrack::TrkTrack(const TrkTrack& t){ Line 75  TrkTrack::TrkTrack(const TrkTrack& t){
75      seqno = t.seqno;      seqno = t.seqno;
76      image = t.image;      image = t.image;
77      chi2  = t.chi2;      chi2  = t.chi2;
78        nstep = t.nstep;
79      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
80          al[it1] = t.al[it1];          al[it1] = t.al[it1];
81          for(int it2=0;it2<5;it2++)          for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
             coval[it1][it2] = t.coval[it1][it2];  
82      };      };
83      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
84          xgood[ip]  = t.xgood[ip];          xgood[ip]  = t.xgood[ip];
# Line 64  TrkTrack::TrkTrack(const TrkTrack& t){ Line 88  TrkTrack::TrkTrack(const TrkTrack& t){
88          zm[ip]     = t.zm[ip];          zm[ip]     = t.zm[ip];
89          resx[ip]   = t.resx[ip];          resx[ip]   = t.resx[ip];
90          resy[ip]   = t.resy[ip];          resy[ip]   = t.resy[ip];
91            tailx[ip]  = t.tailx[ip];
92            taily[ip]  = t.taily[ip];
93          xv[ip]     = t.xv[ip];          xv[ip]     = t.xv[ip];
94          yv[ip]     = t.yv[ip];          yv[ip]     = t.yv[ip];
95          zv[ip]     = t.zv[ip];          zv[ip]     = t.zv[ip];
# Line 71  TrkTrack::TrkTrack(const TrkTrack& t){ Line 97  TrkTrack::TrkTrack(const TrkTrack& t){
97          ayv[ip]    = t.ayv[ip];          ayv[ip]    = t.ayv[ip];
98          dedx_x[ip] = t.dedx_x[ip];          dedx_x[ip] = t.dedx_x[ip];
99          dedx_y[ip] = t.dedx_y[ip];          dedx_y[ip] = t.dedx_y[ip];
100      };              multmaxx[ip] = t.multmaxx[ip];
101            multmaxy[ip] = t.multmaxy[ip];
102            seedx[ip]    = t.seedx[ip];  
103            seedy[ip]    = t.seedy[ip];
104            xpu[ip]      = t.xpu[ip];  
105            ypu[ip]      = t.ypu[ip];  
106        };
107    
108        TrkParams::SetTrackingMode();
109        TrkParams::SetPrecisionFactor();
110        TrkParams::SetStepMin();  
111        TrkParams::SetPFA();
112    
113    };
114    //--------------------------------------
115    //
116    //
117    //--------------------------------------
118    void TrkTrack::Copy(TrkTrack& t){
119    
120        t.seqno = seqno;
121        t.image = image;
122        t.chi2  = chi2;
123        t.nstep = nstep;
124        for(int it1=0;it1<5;it1++){
125            t.al[it1] = al[it1];
126            for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2];
127        };
128        for(int ip=0;ip<6;ip++){
129            t.xgood[ip]  = xgood[ip];
130            t.ygood[ip]  = ygood[ip];
131            t.xm[ip]     = xm[ip];
132            t.ym[ip]     = ym[ip];
133            t.zm[ip]     = zm[ip];
134            t.resx[ip]   = resx[ip];
135            t.resy[ip]   = resy[ip];
136            t.tailx[ip]  = tailx[ip];
137            t.taily[ip]  = taily[ip];
138            t.xv[ip]     = xv[ip];
139            t.yv[ip]     = yv[ip];
140            t.zv[ip]     = zv[ip];
141            t.axv[ip]    = axv[ip];
142            t.ayv[ip]    = ayv[ip];
143            t.dedx_x[ip] = dedx_x[ip];
144            t.dedx_y[ip] = dedx_y[ip];
145            t.multmaxx[ip] = multmaxx[ip];
146            t.multmaxy[ip] = multmaxy[ip];
147            t.seedx[ip]    = seedx[ip];  
148            t.seedy[ip]    = seedy[ip];
149            t.xpu[ip]      = xpu[ip];  
150            t.ypu[ip]      = ypu[ip];  
151                
152        };
153    
154        
155  };  };
156  //--------------------------------------  //--------------------------------------
157  //  //
# Line 96  int TrkTrack::DoTrack(Trajectory* t){ Line 176  int TrkTrack::DoTrack(Trajectory* t){
176      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];
177      for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];      for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
178    
179        TrkParams::Load(1);
180        if( !TrkParams::IsLoaded(1) ){
181            cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
182            return 0;
183        }
184      dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);      dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);
185            
186      for (int i=0; i<t->npoint; i++){      for (int i=0; i<t->npoint; i++){
# Line 135  int TrkTrack::DoTrack2(Trajectory* t){ Line 220  int TrkTrack::DoTrack2(Trajectory* t){
220      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];
221      for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];      for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
222    
223        TrkParams::Load(1);
224        if( !TrkParams::IsLoaded(1) ){
225            cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
226            return 0;
227        }
228      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
229            
230      for (int i=0; i<t->npoint; i++){      for (int i=0; i<t->npoint; i++){
# Line 174  Float_t TrkTrack::GetDeflection(){ Line 264  Float_t TrkTrack::GetDeflection(){
264          return def;          return def;
265  };  };
266  //  //
267    /**
268     * Method to retrieve the dE/dx measured on a tracker view.
269     * @param ip plane (0-5)
270     * @param iv view (0=x 1=y)
271     */
272    Float_t TrkTrack::GetDEDX(int ip, int iv){
273        if(iv==0 && ip>=0 && ip<6)return fabs(dedx_x[ip]);
274        else if(iv==1 && ip>=0 && ip<6)return fabs(dedx_y[ip]);
275        else {
276            cout << "TrkTrack::GetDEDX(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
277            return 0.;
278        }
279    }
280    /**
281     * Method to evaluate the dE/dx measured on a tracker plane.
282     * The two measurements on x- and y-view are averaged.
283     * @param ip plane (0-5)
284     */
285    Float_t TrkTrack::GetDEDX(int ip){
286        if( (Int_t)XGood(ip)+(Int_t)YGood(ip) == 0 ) return 0;
287        return (GetDEDX(ip,0)+GetDEDX(ip,1))/((Int_t)XGood(ip)+(Int_t)YGood(ip));
288    };
289    
290    /**
291     * Method to evaluate the dE/dx averaged over all planes.
292     */
293  Float_t TrkTrack::GetDEDX(){  Float_t TrkTrack::GetDEDX(){
294          Float_t dedx=0;      Float_t dedx=0;
295          for(Int_t i=0; i<6; i++)dedx+=dedx_x[i]*xgood[i]+dedx_y[i]*ygood[i];      for(Int_t ip=0; ip<6; ip++)dedx+=GetDEDX(ip,0)*XGood(ip)+GetDEDX(ip,1)*YGood(ip);
296          dedx = dedx/(this->GetNX()+this->GetNY());      dedx = dedx/(GetNX()+GetNY());
297          return dedx;      return dedx;
298    };
299    /**
300     * Returns 1 if the cluster on a tracker view includes bad strips.
301     * @param ip plane (0-5)
302     * @param iv view (0=x 1=y)
303     */
304    Bool_t TrkTrack::IsBad(int ip,int iv){
305        if(iv==0 && ip>=0 && ip<6)return (xgood[ip]<0) ;
306        else if(iv==1 && ip>=0 && ip<6)return (ygood[ip]<0) ;
307        else {
308            cout << "TrkTrack::IsBad(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
309            return 0.;
310        }
311    };
312    /**
313     * Returns 1 if the signal on a tracker view is saturated.
314     * @param ip plane (0-5)
315     * @param iv view (0=x 1=y)
316     */
317    Bool_t TrkTrack::IsSaturated(int ip,int iv){
318        if(iv==0 && ip>=0 && ip<6)return (dedx_x[ip]<0) ;
319        else if(iv==1 && ip>=0 && ip<6)return (dedx_y[ip]<0) ;
320        else {
321            cout << "TrkTrack::IsSaturated(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
322            return 0.;
323        }
324    };
325    /**
326     * Returns 1 if either the x or the y signal on a tracker plane is saturated.
327     * @param ip plane (0-5)
328     */
329    Bool_t TrkTrack::IsSaturated(int ip){
330        return (IsSaturated(ip,0)||IsSaturated(ip,1));
331    };
332    /**
333     * Returns 1 if there is at least a saturated signal along the track.
334     */
335    Bool_t TrkTrack::IsSaturated(){
336        for(int ip=0; ip<6; ip++)for(int iv=0; iv<2; iv++)if(IsSaturated(ip,iv))return true;
337        return false;
338    }
339    /**
340     * Returns the track "lever-arm" on the x view, defined as the distance (in planes) between
341     * the upper and lower x measurements (the maximum value of lever-arm is 6).
342     */
343    Int_t TrkTrack::GetLeverArmX(){
344        int first_plane = -1;
345        int last_plane  = -1;
346        for(Int_t ip=0; ip<6; ip++){
347            if( XGood(ip) && first_plane == -1 )first_plane = ip;
348            if( XGood(ip) && first_plane != -1 )last_plane = ip;
349        }
350        if( first_plane == -1 || last_plane == -1){
351            cout<< "Int_t TrkTrack::GetLeverArmX() -- XGood(ip) always false ??? "<<endl;
352            return 0;
353        }
354        return (last_plane-first_plane+1);
355    }
356    /**
357     * Returns the track "lever-arm" on the y view, defined as the distance (in planes) between
358     * the upper and lower y measurements (the maximum value of lever-arm is 6).
359     */
360    Int_t TrkTrack::GetLeverArmY(){
361        int first_plane = -1;
362        int last_plane  = -1;
363        for(Int_t ip=0; ip<6; ip++){
364            if( YGood(ip) && first_plane == -1 )first_plane = ip;
365            if( YGood(ip) && first_plane != -1 )last_plane = ip;
366        }
367        if( first_plane == -1 || last_plane == -1){
368            cout<< "Int_t TrkTrack::GetLeverArmY() -- YGood(ip) always false ??? "<<endl;
369            return 0;
370        }
371        return (last_plane-first_plane+1);
372    }
373    /**
374     * Returns the reduced chi-square of track x-projection
375     */
376    Float_t  TrkTrack::GetChi2X(){
377        float chiq=0;
378        for(int ip=0; ip<6; ip++)if(XGood(ip))chiq+= pow((xv[ip]-xm[ip])/resx[ip],2.);
379        if(GetNX()>3)chiq=chiq/(GetNX()-3);
380        else chiq=0;
381        if(chiq==0)cout << " Float_t  TrkTrack::GetChi2X() -- WARNING -- value not defined "<<chiq<<endl;
382        return chiq;
383    }
384    /**
385     * Returns the reduced chi-square of track y-projection
386     */
387    Float_t  TrkTrack::GetChi2Y(){
388        float chiq=0;
389        for(int ip=0; ip<6; ip++)if(YGood(ip))chiq+= pow((yv[ip]-ym[ip])/resy[ip],2.);
390        if(GetNY()>2)chiq=chiq/(GetNY()-2);
391        else chiq=0;
392        if(chiq==0)cout << " Float_t  TrkTrack::GetChi2Y() -- WARNING -- value not defined "<<chiq<<endl;
393        return chiq;
394    }
395    /**
396     * Returns the logarythm of the likeliwood-function of  track x-projection
397     */
398    Float_t TrkTrack::GetLnLX(){
399        float lnl=0;
400        for(int ip=0; ip<6; ip++)
401            if( XGood(ip) && tailx[ip]!=0 )
402                lnl += (tailx[ip]+1.) * log( (tailx[ip]*pow(resx[ip],2.) + pow(xv[ip]-xm[ip],2.)) / (tailx[ip]*pow(resx[ip],2)) );
403        if(GetNX()>3)lnl=lnl/(GetNX()-3);
404        else lnl=0;
405        if(lnl==0){
406            cout << " Float_t  TrkTrack::GetLnLX() -- WARNING -- value not defined "<<lnl<<endl;
407            Dump();
408        }
409        return lnl;
410        
411    }
412    /**
413     * Returns the logarythm of the likeliwood-function of  track y-projection
414     */
415    Float_t TrkTrack::GetLnLY(){
416        float lnl=0;
417        for(int ip=0; ip<6; ip++)
418            if( YGood(ip) && taily[ip]!=0 )
419                lnl += (taily[ip]+1.) * log( (taily[ip]*pow(resy[ip],2.) + pow(yv[ip]-ym[ip],2.)) / (taily[ip]*pow(resy[ip],2)) );
420        if(GetNY()>2)lnl=lnl/(GetNY()-2);
421        else lnl=0;
422        if(lnl==0){
423            cout << " Float_t  TrkTrack::GetLnLY() -- WARNING -- value not defined "<<lnl<<endl;
424            Dump();
425        }
426        return lnl;
427        
428    }
429    /**
430     * Returns the effective angle, relative to the sensor, on each plane.
431     * @param ip plane (0-5)
432     * @param iv view (0=x 1=y)
433     */
434    Float_t TrkTrack::GetEffectiveAngle(int ip, int iv){
435    
436        if(ip<0 || ip>5){
437            cout << "Float_t TrkTrack::GetEffectiveAngle(int "<<ip<<", int "<<iv<<") ==> wrong input"<<endl;
438            return 0.;
439        }
440    
441        float v[3]={xv[ip],yv[ip],zv[ip]};
442        //-----------------------------------------
443        // effective angle (relative to the sensor)
444        //-----------------------------------------
445        float axv_geo  = axv[ip];
446        float muhall_h = 297.61; //cm**2/Vs
447        float BY = TrkParams::GetBY(v);
448        float axv_eff = 0;
449        if(ip==5) axv_geo = -1*axv_geo;
450        if(ip==5) BY      = -1*BY;
451        axv_eff = 180.*atan( tan(axv_geo*acos(-1.)/180.) + muhall_h * BY * 0.0001)/acos(-1.);
452        //-----------------------------------------
453        // effective angle (relative to the sensor)
454        //-----------------------------------------
455        float ayv_geo = ayv[ip];
456        float muhall_e = 1258.18; //cm**2/Vs
457        float BX = TrkParams::GetBX(v);
458        float ayv_eff = 0;
459        ayv_eff = 180.*atan( tan(ayv_geo*acos(-1.)/180.) + muhall_e * BX * 0.0001)/acos(-1.);
460      
461        if     (iv==0)return axv_eff;
462        else if(iv==1)return ayv_eff;
463        else{
464            cout << "Float_t TrkTrack::GetEffectiveAngle(int "<<ip<<", int "<<iv<<") ==> wrong input"<<endl;
465            return 0.;
466        }
467      
468  };  };
469    
470  //--------------------------------------  //--------------------------------------
# Line 187  Float_t TrkTrack::GetDEDX(){ Line 473  Float_t TrkTrack::GetDEDX(){
473  //--------------------------------------  //--------------------------------------
474  void TrkTrack::Dump(){  void TrkTrack::Dump(){
475      cout << endl << "========== Track " ;      cout << endl << "========== Track " ;
476        cout << endl << "seq.  n. : "<< seqno;
477        cout << endl << "image n. : "<< image;
478      cout << endl << "al       : "; for(int i=0; i<5; i++)cout << al[i] << " ";      cout << endl << "al       : "; for(int i=0; i<5; i++)cout << al[i] << " ";
479      cout << endl << "chi^2    : "<< chi2;      cout << endl << "chi^2    : "<< chi2;
480      cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << xgood[i] ;      cout << endl << "n.step   : "<< nstep;
481      cout << endl << "ygood    : "; for(int i=0; i<6; i++)cout << ygood[i] ;      cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << XGood(i) ;
482        cout << endl << "ygood    : "; for(int i=0; i<6; i++)cout << YGood(i) ;
483      cout << endl << "xm       : "; for(int i=0; i<6; i++)cout << xm[i] << " ";      cout << endl << "xm       : "; for(int i=0; i<6; i++)cout << xm[i] << " ";
484      cout << endl << "ym       : "; for(int i=0; i<6; i++)cout << ym[i] << " ";      cout << endl << "ym       : "; for(int i=0; i<6; i++)cout << ym[i] << " ";
485      cout << endl << "zm       : "; for(int i=0; i<6; i++)cout << zm[i] << " ";      cout << endl << "zm       : "; for(int i=0; i<6; i++)cout << zm[i] << " ";
486        cout << endl << "xv       : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
487        cout << endl << "yv       : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
488        cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
489        cout << endl << "resx     : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
490        cout << endl << "resy     : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
491        cout << endl << "tailx    : "; for(int i=0; i<6; i++)cout << tailx[i] << " ";
492        cout << endl << "taily    : "; for(int i=0; i<6; i++)cout << taily[i] << " ";
493        cout << endl << "coval    : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
494        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
495        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
496        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
497        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
498      cout << endl << "dedx_x   : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";      cout << endl << "dedx_x   : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";
499      cout << endl << "dedx_y   : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";      cout << endl << "dedx_y   : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";
500        cout << endl << "maxs x   : "; for(int i=0; i<6; i++)cout << GetClusterX_MaxStrip(i) << " ";
501        cout << endl << "maxs y   : "; for(int i=0; i<6; i++)cout << GetClusterY_MaxStrip(i) << " ";
502        cout << endl << "mult x   : "; for(int i=0; i<6; i++)cout << GetClusterX_Multiplicity(i) << " ";
503        cout << endl << "mult y   : "; for(int i=0; i<6; i++)cout << GetClusterY_Multiplicity(i) << " ";
504        cout << endl << "seed x   : "; for(int i=0; i<6; i++)cout << GetClusterX_Seed(i) << " ";
505        cout << endl << "seed y   : "; for(int i=0; i<6; i++)cout << GetClusterY_Seed(i) << " ";
506        cout << endl << "xpu      : "; for(int i=0; i<6; i++)cout << xpu[i] << " ";
507        cout << endl << "ypu      : "; for(int i=0; i<6; i++)cout << ypu[i] << " ";
508    
509        cout << endl;
510    }
511    /**
512     * Set the TrkTrack position measurements
513     */
514    void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
515        for(int i=0; i<6; i++) xm[i]=*xmeas++;
516        for(int i=0; i<6; i++) ym[i]=*ymeas++;
517        for(int i=0; i<6; i++) zm[i]=*zmeas++;
518    }
519    /**
520     * Set the TrkTrack position resolution
521     */
522    void TrkTrack::SetResolution(double *rx, double *ry){
523        for(int i=0; i<6; i++) resx[i]=*rx++;
524        for(int i=0; i<6; i++) resy[i]=*ry++;
525    }
526    /**
527     * Set the TrkTrack tails position resolution
528     */
529    void TrkTrack::SetTail(double *tx, double *ty, double factor){
530        for(int i=0; i<6; i++) tailx[i]=factor*(*tx++);
531        for(int i=0; i<6; i++) taily[i]=factor*(*ty++);
532    }
533    /**
534     * Set the TrkTrack Student parameter (resx,resy,tailx,taily)
535     * from previous gausian fit
536     *@param flag =0 standard, =1 with noise correction
537     */
538    void TrkTrack::SetStudentParam(int flag){
539        float sx[11]={0.000128242,
540                       0.000136942,
541                       0.000162718,
542                       0.000202644,
543                       0.00025597,
544                       0.000317456,
545                       0.000349048,
546                       0.000384638,
547                       0.000457295,
548                       0.000512319,
549                       0.000538573};
550        float tx[11]={1.79402,
551                       2.04876,
552                       2.88376,
553                       3.3,
554                       3.14084,
555                       4.07686,
556                       4.44736,
557                       3.5179,
558                       3.38697,
559                       3.45739,
560                       3.18627};
561        float sy[11]={0.000483075,
562                       0.000466925,
563                       0.000431658,
564                       0.000428317,
565                       0.000433854,
566                       0.000444044,
567                       0.000482098,
568                       0.000537579,
569                       0.000636279,
570                       0.000741998,
571                       0.000864261};
572        float ty[11]={0.997032,
573                       1.11147,
574                       1.18526,
575                       1.61404,
576                       2.21908,
577                       3.08959,
578                       4.48833,
579                       4.42687,
580                       4.65253,
581                       4.52043,
582                       4.29926};
583        int index;
584        float fact;
585        for(int i=0; i<6; i++) {
586            index = int((fabs(axv[i])+1.)/2.);
587            if(index>10) index=10;
588            tailx[i]=tx[index];
589            if(flag==1) {
590                if(fabs(axv[i])<=10.) fact = resx[i]/risxeta2_(&(axv[i]));
591                if(fabs(axv[i])>10.&&fabs(axv[i])<=15.) fact = resx[i]/risxeta3_(&(axv[i]));
592                if(fabs(axv[i])>15.) fact = resx[i]/risxeta4_(&(axv[i]));
593            } else fact = 1.;
594            resx[i] = sx[index]*fact;
595        }
596        for(int i=0; i<6; i++) {
597            index = int((fabs(ayv[i])+1.)/2.);
598            if(index>10) index=10;
599            taily[i]=ty[index];
600            if(flag==1) fact = resy[i]/risyeta2_(&(ayv[i]));
601            else fact = 1.;
602            resy[i] = sy[index]*fact;
603        }
604    }
605    /**
606     * Set the TrkTrack good measurement
607     */
608    void TrkTrack::SetGood(int *xg, int *yg){
609    
610        for(int i=0; i<6; i++) xgood[i]=*xg++;
611        for(int i=0; i<6; i++) ygood[i]=*yg++;
612    }
613    
614    /**
615     * Load the magnetic field
616     */
617    void TrkTrack::LoadField(TString path){
618        
619    //     strcpy(path_.path,path.Data());
620    //     path_.pathlen = path.Length();
621    //     path_.error   = 0;
622    //     readb_();
623    
624        TrkParams::SetTrackingMode();
625        TrkParams::SetPrecisionFactor();
626        TrkParams::SetStepMin();
627    
628        TrkParams::Set(path,1);
629        TrkParams::Load(1);
630    
631    };
632    
633    
634    /**
635     * Method to fill minimization-routine common
636     */
637    void TrkTrack::FillMiniStruct(cMini2track& track){
638    
639        for(int i=0; i<6; i++){
640    
641    //      cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl;
642    //      cout << i<<" - "<<ygood[i]<<" "<<YGood(i)<<endl;
643            track.xgood[i]=XGood(i);
644            track.ygood[i]=YGood(i);
645            
646            track.xm[i]=xm[i];
647            track.ym[i]=ym[i];
648            track.zm[i]=zm[i];
649            
650    //      --- temporaneo ----------------------------
651    //      andrebbe inserita la dimensione del sensore
652            float segment = 100.;
653            track.xm_a[i]=xm[i];
654            track.xm_b[i]=xm[i];
655            track.ym_a[i]=ym[i];
656            track.ym_b[i]=ym[i];
657            if(       XGood(i) && !YGood(i) ){
658                track.ym_a[i] = track.ym_a[i]+segment;
659                track.ym_b[i] = track.ym_b[i]-segment;
660            }else if( !XGood(i) && YGood(i)){
661                track.xm_a[i] = track.xm_a[i]+segment;
662                track.xm_b[i] = track.xm_b[i]-segment;
663            }
664    //      --- temporaneo ----------------------------
665            
666            track.resx[i]=resx[i];
667            track.resy[i]=resy[i];
668            track.tailx[i]=tailx[i];
669            track.taily[i]=taily[i];
670        }
671    
672        for(int i=0; i<5; i++) track.al[i]=al[i];
673        track.zini = 23.5;
674    // ZINI = 23.5 !!! it should be the same parameter in all codes
675        
676    }
677    /**
678     * Method to set values from  minimization-routine common
679     */
680    void TrkTrack::SetFromMiniStruct(cMini2track *track){
681    
682        for(int i=0; i<5; i++) {
683            al[i]=track->al[i];
684            for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j];
685        }
686        chi2  = track->chi2;
687        nstep = track->nstep;
688        for(int i=0; i<6; i++){
689            xv[i]  = track->xv[i];
690            yv[i]  = track->yv[i];
691            zv[i]  = track->zv[i];
692            xm[i]  = track->xm[i];
693            ym[i]  = track->ym[i];
694            zm[i]  = track->zm[i];
695            axv[i] = track->axv[i];
696            ayv[i] = track->ayv[i];
697        }
698        
699  }  }
700    /**
701     * \brief Method to re-evaluate coordinates of clusters associated with a track.
702     *
703     * The method can be applied only after recovering level1 information
704     * (either by reprocessing single events from level0 or from  
705     * the TrkLevel1 branch, if present); it calls F77 subroutines that
706     * read the level1 common and fill the minimization-routine common.
707     * Some clusters can be excluded or added by means of the methods:
708     *
709     * TrkTrack::ResetXGood(int ip)
710     * TrkTrack::ResetYGood(int ip)
711     * TrkTrack::SetXGood(int ip, int cid, int is)
712     * TrkTrack::SetYGood(int ip, int cid, int is)
713     *
714     * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1)
715     * for the minimization-routine common. It deletes the cluster information
716     * (at least for the moment...) thus cannot be applied before
717     * TrkTrack::EvaluateClusterPositions().  
718     *
719     * Different p.f.a. can be applied by calling (once) the method:
720     *
721     * TrkParams::SetPFA(0); //Set ETA p.f.a.
722     *
723     * @see TrkParams::SetPFA(int)
724     */
725    Bool_t TrkTrack::EvaluateClusterPositions(){
726        
727    //     cout << "void TrkTrack::GetClusterPositions() "<<endl;
728    
729        TrkParams::Load( );
730        if( !TrkParams::IsLoaded() )return false;
731        
732        for(int ip=0; ip<6; ip++){
733    //      cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;
734            int icx = GetClusterX_ID(ip)+1;
735            int icy = GetClusterY_ID(ip)+1;
736            int sensor = GetSensor(ip)+1;//<< convenzione "Paolo"
737            if(ip==5 && sensor!=0)sensor=3-sensor;//<< convenzione "Elena"
738            int ladder = GetLadder(ip)+1;
739            float ax = axv[ip];
740            float ay = ayv[ip];
741            float v[3];
742            v[0]=xv[ip];
743            v[1]=yv[ip];
744            v[2]=zv[ip];
745            float bfx = 10*TrkParams::GetBX(v);//Tesla
746            float bfy = 10*TrkParams::GetBY(v);//Tesla
747            int ipp=ip+1;
748            xyzpam_(&ipp,&icx,&icy,&ladder,&sensor,&ax,&ay,&bfx,&bfy);
749            if(icx<0 || icy<0)return false;
750        }
751        return true;
752    }
753    /**
754     * \brief Tracking method. It calls F77 mini routine.
755     *
756     * @param pfixed Particle momentum. If pfixed=0 the momentum
757     * is left as a free parameter, otherwise it is fixed to the input value.
758     * @param fail Output flag (!=0 if the fit failed).
759     * @param iprint Flag to set debug mode ( 0 = no output; 1 = verbose; 2 = debug).
760     * @param froml1 Flag to re-evaluate positions (see TrkTrack::GetClusterPositions()).
761     *
762     * The option to re-evaluate positions can be used only after recovering
763     * level1 information, eg. by reprocessing the single event.
764     *
765     * Example:
766     *
767     * if( !event->GetTrkLevel0() )return false;
768     * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1
769     * int fail=0;
770     * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1);
771     *
772     * @see EvaluateClusterPositions()
773     *
774     * The fitting procedure can be varied by changing the tracking mode,
775     * the fit-precision factor and the minimum number of step.
776     * @see SetTrackingMode(int)
777     * @see SetPrecisionFactor(double)
778     * @see SetStepMin(int)
779     */
780    void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
781    
782        float al_ini[] = {0.,0.,0.,0.,0.};
783    
784        TrkParams::Load( );
785        if( !TrkParams::IsLoaded() )return;
786    
787        extern cMini2track track_;
788        fail = 0;
789    
790        FillMiniStruct(track_);
791            
792        if(froml1!=0){
793            if( !EvaluateClusterPositions() ){
794                cout << "void TrkTrack::Fit("<<pfixed<<","<<fail<<","<<iprint<<","<<froml1<<") --- ERROR evaluating cluster positions "<<endl;
795                FillMiniStruct(track_) ;
796                fail = 1;
797                return;
798            }
799        }else{
800            FillMiniStruct(track_);
801        }
802        
803        // if fit variables have been reset, evaluate the initial guess
804        if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
805    
806        // --------------------- free momentum
807        if(pfixed==0.) {
808            track_.pfixed=0.;
809        }
810        // --------------------- fixed momentum
811        if(pfixed!=0.) {
812            al[4]=1./pfixed;    
813            track_.pfixed=pfixed;
814        }
815    
816        //  store temporarily the initial guess
817        for(int i=0; i<5; i++) al_ini[i]=track_.al[i];
818    
819        //  ------------------------------------------
820        //  call mini routine
821    //     TrkParams::Load(1);
822    //     if( !TrkParams::IsLoaded(1) ){
823    //      cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl;
824    //      return;
825    //     }
826        int istep=0;
827        int ifail=0;
828        mini2_(&istep,&ifail, &iprint);
829        if(ifail!=0) {
830            if(iprint)cout << "ERROR: ifail= " << ifail << endl;
831            fail = 1;
832        }
833        //  ------------------------------------------
834        
835        SetFromMiniStruct(&track_);
836    
837        if(fail){
838            if(iprint)cout << " >>>> fit failed "<<endl;
839            for(int i=0; i<5; i++) al[i]=al_ini[i];
840        }
841    
842    };
843    /**
844     * Reset the fit parameters
845     */
846    void TrkTrack::FitReset(){
847        for(int i=0; i<5; i++) al[i]=-9999.;
848        chi2=0.;
849        nstep=0;
850    //     for(int i=0; i<6; i++) xv[i]=0.;
851    //     for(int i=0; i<6; i++) yv[i]=0.;
852    //     for(int i=0; i<6; i++) zv[i]=0.;
853    //     for(int i=0; i<6; i++) axv[i]=0.;
854    //     for(int i=0; i<6; i++) ayv[i]=0.;
855        for(int i=0; i<5; i++) {
856            for(int j=0; j<5; j++) coval[i][j]=0.;
857        }
858    }
859    /**
860     * Set the tracking mode
861     */
862    void TrkTrack::SetTrackingMode(int trackmode){
863        extern cMini2track track_;
864        track_.trackmode = trackmode;
865    }
866    /**
867     * Set the factor scale for tracking precision
868     */
869    void TrkTrack::SetPrecisionFactor(double fact){
870        extern cMini2track track_;
871        track_.fact = fact;
872    }
873    /**
874     * Set the minimum number of steps for tracking precision
875     */
876    void TrkTrack::SetStepMin(int istepmin){
877        extern cMini2track track_;
878        track_.istepmin = istepmin;
879    }
880    /**
881     * Returns 1 if the track is inside the magnet cavity
882     * Set the minimum number of steps for tracking precision
883     */
884    Bool_t TrkTrack::IsInsideCavity(){
885        float xmagntop, ymagntop, xmagnbottom, ymagnbottom;
886        xmagntop = xv[0] + (ZMAGNHIGH-zv[0])*tan(cos(-1.0)*axv[0]/180.);
887        ymagntop = yv[0] + (ZMAGNHIGH-zv[0])*tan(cos(-1.0)*ayv[0]/180.);
888        xmagnbottom = xv[5] + (ZMAGNLOW-zv[5])*tan(cos(-1.0)*axv[5]/180.);
889        ymagnbottom = yv[5] + (ZMAGNLOW-zv[5])*tan(cos(-1.0)*ayv[5]/180.);
890        if( xmagntop>XMAGNLOW && xmagntop<XMAGNHIGH &&
891            ymagntop>YMAGNLOW && ymagntop<YMAGNHIGH &&
892            xmagnbottom>XMAGNLOW && xmagnbottom<XMAGNHIGH &&
893            ymagnbottom>YMAGNLOW && ymagnbottom<YMAGNHIGH ) return(true);
894        else return(false);
895    }
896    /**
897     * Method to retrieve ID (0,1,...) of x-cluster (if any) associated to this track.
898     * If no cluster is associated, ID=-1.
899     * @param ip Tracker plane (0-5)
900     */
901    Int_t TrkTrack::GetClusterX_ID(int ip){
902        return ((Int_t)fabs(xgood[ip]))%10000000-1;
903    };
904    /**
905     * Method to retrieve ID (0-xxx) of y-cluster (if any) associated to this track.
906     * If no cluster is associated, ID=-1.
907     * @param ip Tracker plane (0-5)
908     */
909    Int_t TrkTrack::GetClusterY_ID(int ip){
910        return ((Int_t)fabs(ygood[ip]))%10000000-1;
911    };
912    
913    /**
914     * Method to retrieve the ladder (0-4, increasing x) traversed by the track on this plane.
915     * If no ladder is traversed (dead area) the metod retuns -1.
916     * @param ip Tracker plane (0-5)
917     */
918    Int_t TrkTrack::GetLadder(int ip){
919        if(XGood(ip))return (Int_t)fabs(xgood[ip]/100000000)-1;
920        if(YGood(ip))return (Int_t)fabs(ygood[ip]/100000000)-1;
921        return -1;
922    };
923    /**
924     * Method to retrieve the sensor (0-1, increasing y) traversed by the track on this plane.
925     * If no sensor is traversed (dead area) the metod retuns -1.
926     * @param ip Tracker plane (0-5)
927     */
928    Int_t TrkTrack::GetSensor(int ip){
929        if(XGood(ip))return (Int_t)((Int_t)fabs(xgood[ip]/10000000)%10)-1;
930        if(YGood(ip))return (Int_t)((Int_t)fabs(ygood[ip]/10000000)%10)-1;
931        return -1;
932    };
933    
934    /**
935     * \brief Method to include a x-cluster to the track.
936     * @param ip Tracker plane (0-5)
937     * @param clid Cluster ID (0,1,...)
938     * @param is Sensor (0-1, increasing y)
939     * @see Fit(double pfixed, int& fail, int iprint, int froml1)
940     */
941    void TrkTrack::SetXGood(int ip, int clid, int is){
942        int il=0;       //ladder (temporary)
943        bool bad=false; //ladder (temporary)
944        xgood[ip]=il*100000000+is*10000000+clid;
945        if(bad)xgood[ip]=-xgood[ip];
946    };
947    /**
948     * \brief Method to include a y-cluster to the track.
949     * @param ip Tracker plane (0-5)
950     * @param clid Cluster ID (0,1,...)
951     * @param is Sensor (0-1)
952     * @see Fit(double pfixed, int& fail, int iprint, int froml1)
953     */
954    void TrkTrack::SetYGood(int ip, int clid, int is){
955        int il=0;       //ladder (temporary)
956        bool bad=false; //ladder (temporary)
957        ygood[ip]=il*100000000+is*10000000+clid;
958        if(bad)ygood[ip]=-ygood[ip];
959    };
960    
961    //--------------------------------------
962    //
963    //
964    //--------------------------------------
965    void TrkTrack::Clear(){
966    //    cout << "TrkTrack::Clear()"<<endl;
967        seqno = -1;
968        image = -1;
969        chi2  = 0;
970        nstep = 0;
971        for(int it1=0;it1<5;it1++){
972            al[it1] = 0;
973            for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
974        };
975        for(int ip=0;ip<6;ip++){
976            xgood[ip]  = 0;
977            ygood[ip]  = 0;
978            xm[ip]     = 0;
979            ym[ip]     = 0;
980            zm[ip]     = 0;
981            resx[ip]   = 0;
982            resy[ip]   = 0;
983            tailx[ip]  = 0;
984            taily[ip]  = 0;
985            xv[ip]     = 0;
986            yv[ip]     = 0;
987            zv[ip]     = 0;
988            axv[ip]    = 0;
989            ayv[ip]    = 0;
990            dedx_x[ip] = 0;
991            dedx_y[ip] = 0;
992    
993        };
994    //     if(clx)clx->Clear();
995    //     if(cly)cly->Clear();
996    //    clx.Clear();
997    //    cly.Clear();
998    };
999    //--------------------------------------
1000    //
1001    //
1002    //--------------------------------------
1003    void TrkTrack::Delete(){
1004    //    cout << "TrkTrack::Delete()"<<endl;
1005        Clear();
1006    //    if(clx)delete clx;
1007    //    if(cly)delete cly;
1008    };
1009    //--------------------------------------
1010    //
1011    //
1012    //--------------------------------------
1013    
1014  //--------------------------------------  //--------------------------------------
1015  //  //
1016  //  //
1017  //--------------------------------------  //--------------------------------------
1018  TrkSinglet::TrkSinglet(){  TrkSinglet::TrkSinglet(){
1019    //    cout << "TrkSinglet::TrkSinglet() " << GetUniqueID()<<endl;
1020      plane    = 0;      plane    = 0;
1021      coord[0] = 0;      coord[0] = 0;
1022      coord[1] = 0;      coord[1] = 0;
1023      sgnl     = 0;      sgnl     = 0;
1024    //    cls      = 0;
1025  };  };
1026  //--------------------------------------  //--------------------------------------
1027  //  //
1028  //  //
1029  //--------------------------------------  //--------------------------------------
1030  TrkSinglet::TrkSinglet(const TrkSinglet& s){  TrkSinglet::TrkSinglet(const TrkSinglet& s){
1031    //    cout << "TrkSinglet::TrkSinglet(const TrkSinglet& s) " << GetUniqueID()<<endl;
1032      plane    = s.plane;      plane    = s.plane;
1033      coord[0] = s.coord[0];      coord[0] = s.coord[0];
1034      coord[1] = s.coord[1];      coord[1] = s.coord[1];
1035      sgnl     = s.sgnl;      sgnl     = s.sgnl;
1036    //      cls      = 0;//<<<<pointer
1037    //    cls      = TRef(s.cls);
1038  };  };
1039  //--------------------------------------  //--------------------------------------
1040  //  //
# Line 232  void TrkSinglet::Dump(){ Line 1051  void TrkSinglet::Dump(){
1051  //  //
1052  //  //
1053  //--------------------------------------  //--------------------------------------
1054    void TrkSinglet::Clear(){
1055    //    cout << "TrkSinglet::Clear() " << GetUniqueID()<<endl;
1056    //    cls=0;
1057        plane=-1;
1058        coord[0]=-999;
1059        coord[1]=-999;
1060        sgnl=0;
1061        
1062    }
1063    //--------------------------------------
1064    //
1065    //
1066    //--------------------------------------
1067  TrkLevel2::TrkLevel2(){  TrkLevel2::TrkLevel2(){
1068      good2    = -1;    //    cout <<"TrkLevel2::TrkLevel2()"<<endl;
1069      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1070          crc[i] = -1;          good[i] = -1;
1071            VKmask[i] = 0;
1072            VKflag[i] = 0;  
1073      };      };
1074      Track    = new TClonesArray("TrkTrack");      Track    = 0;
1075      SingletX = new TClonesArray("TrkSinglet");      SingletX = 0;
1076      SingletY = new TClonesArray("TrkSinglet");      SingletY = 0;
1077  //    Track    = 0;  
1078  //    Singlet = 0;  }
1079  //    SingletY = 0;  //--------------------------------------
1080    //
1081    //
1082    //--------------------------------------
1083    void TrkLevel2::Set(){
1084        if(!Track)Track    = new TClonesArray("TrkTrack");
1085        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1086        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1087  }  }
1088  //--------------------------------------  //--------------------------------------
1089  //  //
1090  //  //
1091  //--------------------------------------  //--------------------------------------
1092  void TrkLevel2::Dump(){  void TrkLevel2::Dump(){
1093      TClonesArray &t  = *Track;          
1094      TClonesArray &sx = *SingletX;          //
     TClonesArray &sy = *SingletY;  
   
1095      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
1096      cout << endl << "good2    : " << good2;      cout << endl << "good     : "; for(int i=0; i<12; i++) cout << hex <<" 0x"<< good[i]<<dec;
1097      cout << endl << "crc      : "; for(int i=0; i<12; i++) cout << crc[i];      cout << endl << "ntrk()   : " << ntrk() ;
1098      cout << endl << "ntrk()   : " << this->ntrk() ;      cout << endl << "nclsx()  : " << nclsx();
1099      cout << endl << "nclsx()  : " << this->nclsx();      cout << endl << "nclsy()  : " << nclsy();
1100      cout << endl << "nclsy()  : " << this->nclsy();      if(Track){
1101      for(int i=0; i<this->ntrk(); i++)     ((TrkTrack *)t[i])->Dump();          TClonesArray &t  = *Track;
1102      for(int i=0; i<this->nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();          for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();
1103      for(int i=0; i<this->nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();      }      
1104    //     if(SingletX){
1105    //      TClonesArray &sx = *SingletX;
1106    //      for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
1107    //     }
1108    //     if(SingletY){
1109    //      TClonesArray &sy = *SingletY;
1110    //      for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
1111    //     }
1112        cout << endl;
1113  }  }
1114    /**
1115     * \brief Dump processing status
1116     */
1117    void TrkLevel2::StatusDump(int view){
1118        cout << "DSP n. "<<view+1<<" status: "<<hex<<good[view]<<endl;    
1119    };
1120    /**
1121     * \brief Check event status
1122     *
1123     * Check the event status, according to a flag-mask given as input.
1124     * Return true if the view passes the check.
1125     *
1126     * @param view View number (0-11)
1127     * @param flagmask Mask of flags to check (eg. flagmask=0x111 no missing packet,
1128     *  no crc error, no software alarm)
1129     *
1130     * @see TrkLevel2 class definition to know how the status flag is defined
1131     *
1132     */
1133    Bool_t TrkLevel2::StatusCheck(int view, int flagmask){
1134    
1135        if( view<0 || view >= 12)return false;
1136        return !(good[view]&flagmask);
1137    
1138    };
1139    
1140    
1141  //--------------------------------------  //--------------------------------------
1142  //  //
1143  //  //
1144  //--------------------------------------  //--------------------------------------
1145  /**  /**
1146   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).   * The method returns false if the viking-chip was masked  
1147     * either apriori ,on the basis of the mask read from the DB,
1148     * or run-by-run, on the basis of the calibration parameters)
1149     * @param iv Tracker view (0-11)
1150     * @param ivk Viking-chip number (0-23)
1151   */   */
1152  void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){  Bool_t TrkLevel2::GetVKMask(int iv, int ivk){
1153      //      Int_t whichbit = (Int_t)pow(2,ivk);
1154  //    Track    = new TClonesArray("TrkTrack");      return (whichbit&VKmask[iv])!=0;    
1155  //    SingletX = new TClonesArray("TrkSinglet");  }
1156  //    SingletY = new TClonesArray("TrkSinglet");  /**
1157     * The method returns false if the viking-chip was masked  
1158     * for this event due to common-noise computation failure.
1159     * @param iv Tracker view (0-11)
1160     * @param ivk Viking-chip number (0-23)
1161     */
1162    Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){
1163        Int_t whichbit = (Int_t)pow(2,ivk);
1164        return (whichbit&VKflag[iv])!=0;    
1165    }
1166    /**
1167     * The method returns true if the viking-chip was masked, either
1168     * forced (see TrkLevel2::GetVKMask(int,int)) or
1169     * for this event only (TrkLevel2::GetVKFlag(int,int)).
1170     * @param iv Tracker view (0-11)
1171     * @param ivk Viking-chip number (0-23)
1172     */
1173    Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){
1174        return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) );
1175    };
1176    
1177    //--------------------------------------
1178    //
1179    //
1180    //--------------------------------------
1181    /**
1182     * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
1183     * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set.
1184     * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch)
1185     */
1186    void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
1187    
1188    //    cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl;
1189        Clear();
1190    
1191  //  temporary objects:  //  temporary objects:
1192      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
1193      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
1194    
1195    //  -----------------
1196  //  general variables  //  general variables
1197      good2 = l2->good2;  //  -----------------
1198      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1199          crc[i] = l2->crc[i];          good[i] = l2->good[i];
1200            VKmask[i]=0;
1201            VKflag[i]=0;
1202            for(Int_t ii=0; ii<24 ; ii++){
1203                Int_t setbit = (Int_t)pow(2,ii);
1204                if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit;
1205                if( l2->vkflag[ii][i]!=0  )VKflag[i]=VKflag[i]|setbit;
1206            };
1207      };      };
1208    //  --------------
1209  //  *** TRACKS ***  //  *** TRACKS ***
1210    //  --------------
1211        if(!Track) Track = new TClonesArray("TrkTrack");
1212      TClonesArray &t = *Track;      TClonesArray &t = *Track;
1213    
1214      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
1215          t_track->seqno = i;          t_track->seqno = i;// NBNBNBNB deve sempre essere = i
1216          t_track->image = l2->image[i]-1;          t_track->image = l2->image[i]-1;
 //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;  
1217          t_track->chi2  = l2->chi2_nt[i];          t_track->chi2  = l2->chi2_nt[i];
1218            t_track->nstep = l2->nstep_nt[i];
1219          for(int it1=0;it1<5;it1++){          for(int it1=0;it1<5;it1++){
1220              t_track->al[it1] = l2->al_nt[i][it1];              t_track->al[it1] = l2->al_nt[i][it1];
1221              for(int it2=0;it2<5;it2++)              for(int it2=0;it2<5;it2++)
1222                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];
1223          };          };
1224          for(int ip=0;ip<6;ip++){          for(int ip=0;ip<6;ip++){
1225              t_track->xgood[ip]  = l2->xgood_nt[i][ip];              // ---------------------------------
1226              t_track->ygood[ip]  = l2->ygood_nt[i][ip];              // new implementation of xgood/ygood
1227                // ---------------------------------
1228                t_track->xgood[ip]  = l2->cltrx[i][ip]; //cluster ID
1229                t_track->ygood[ip]  = l2->cltry[i][ip]; //cluster ID
1230                t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1231                t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1232                if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip];
1233                if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip];
1234    //          if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){
1235    //          if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){
1236    //              cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl;
1237    //              cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl;
1238    //              cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl;
1239    //              cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl;
1240    //              cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl;
1241    //          }
1242              t_track->xm[ip]     = l2->xm_nt[i][ip];              t_track->xm[ip]     = l2->xm_nt[i][ip];
1243              t_track->ym[ip]     = l2->ym_nt[i][ip];              t_track->ym[ip]     = l2->ym_nt[i][ip];
1244              t_track->zm[ip]     = l2->zm_nt[i][ip];              t_track->zm[ip]     = l2->zm_nt[i][ip];
1245              t_track->resx[ip]   = l2->resx_nt[i][ip];              t_track->resx[ip]   = l2->resx_nt[i][ip];
1246              t_track->resy[ip]   = l2->resy_nt[i][ip];              t_track->resy[ip]   = l2->resy_nt[i][ip];
1247                t_track->tailx[ip]  = l2->tailx[i][ip];
1248                t_track->taily[ip]  = l2->taily[i][ip];
1249              t_track->xv[ip]     = l2->xv_nt[i][ip];              t_track->xv[ip]     = l2->xv_nt[i][ip];
1250              t_track->yv[ip]     = l2->yv_nt[i][ip];              t_track->yv[ip]     = l2->yv_nt[i][ip];
1251              t_track->zv[ip]     = l2->zv_nt[i][ip];              t_track->zv[ip]     = l2->zv_nt[i][ip];
# Line 310  void TrkLevel2::FillCommonVar(cTrkLevel2 Line 1253  void TrkLevel2::FillCommonVar(cTrkLevel2
1253              t_track->ayv[ip]    = l2->ayv_nt[i][ip];              t_track->ayv[ip]    = l2->ayv_nt[i][ip];
1254              t_track->dedx_x[ip] = l2->dedx_x[i][ip];              t_track->dedx_x[ip] = l2->dedx_x[i][ip];
1255              t_track->dedx_y[ip] = l2->dedx_y[i][ip];              t_track->dedx_y[ip] = l2->dedx_y[i][ip];
1256                t_track->multmaxx[ip] = l2->multmaxx[i][ip];
1257                t_track->multmaxy[ip] = l2->multmaxy[i][ip];
1258                t_track->seedx[ip]  = l2->seedx[i][ip];  
1259                t_track->seedy[ip]  = l2->seedy[i][ip];
1260                t_track->xpu[ip]    = l2->xpu[i][ip];  
1261                t_track->ypu[ip]    = l2->ypu[i][ip];  
1262                //-----------------------------------------------------
1263                //-----------------------------------------------------
1264                //-----------------------------------------------------
1265                //-----------------------------------------------------
1266          };          };
1267    //      if(t_track->IsSaturated())t_track->Dump();
1268          new(t[i]) TrkTrack(*t_track);          new(t[i]) TrkTrack(*t_track);
1269          t_track->Clear();          t_track->Clear();
1270      };      };
1271    
1272    //  ----------------
1273  //  *** SINGLETS ***  //  *** SINGLETS ***
1274    //  ----------------
1275        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1276      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
1277      for(int i=0; i<l2->nclsx; i++){      for(int i=0; i<l2->nclsx; i++){
1278          t_singlet->plane    = l2->planex[i];          t_singlet->plane    = l2->planex[i];
1279          t_singlet->coord[0] = l2->xs[i][0];          t_singlet->coord[0] = l2->xs[i][0];
1280          t_singlet->coord[1] = l2->xs[i][1];          t_singlet->coord[1] = l2->xs[i][1];
1281          t_singlet->sgnl     = l2->signlxs[i];          t_singlet->sgnl     = l2->signlxs[i];
1282            //-----------------------------------------------------
1283    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);
1284            //-----------------------------------------------------
1285          new(sx[i]) TrkSinglet(*t_singlet);          new(sx[i]) TrkSinglet(*t_singlet);
1286          t_singlet->Clear();          t_singlet->Clear();
1287      }      }
1288        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1289      TClonesArray &sy = *SingletY;      TClonesArray &sy = *SingletY;
1290      for(int i=0; i<l2->nclsy; i++){      for(int i=0; i<l2->nclsy; i++){
1291          t_singlet->plane    = l2->planey[i];          t_singlet->plane    = l2->planey[i];
1292          t_singlet->coord[0] = l2->ys[i][0];          t_singlet->coord[0] = l2->ys[i][0];
1293          t_singlet->coord[1] = l2->ys[i][1];          t_singlet->coord[1] = l2->ys[i][1];
1294          t_singlet->sgnl     = l2->signlys[i];          t_singlet->sgnl     = l2->signlys[i];
1295            //-----------------------------------------------------
1296    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);
1297            //-----------------------------------------------------
1298          new(sy[i]) TrkSinglet(*t_singlet);          new(sy[i]) TrkSinglet(*t_singlet);
1299          t_singlet->Clear();          t_singlet->Clear();
1300          };      };
1301                    
1302          delete t_track;      delete t_track;
1303          delete t_singlet;      delete t_singlet;
1304    }
1305    /**
1306     * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
1307     */
1308    
1309    void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
1310      
1311    //  general variables
1312    //    l2->good2 = good2 ;
1313        for(Int_t i=0; i<12 ; i++){
1314    //      l2->crc[i] = crc[i];
1315                    l2->good[i] = good[i];
1316        };
1317    //  *** TRACKS ***
1318    
1319        if(Track){
1320            l2->ntrk              =  Track->GetEntries();    
1321            for(Int_t i=0;i<l2->ntrk;i++){
1322                l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
1323                l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;
1324                l2->nstep_nt[i] =  ((TrkTrack *)Track->At(i))->nstep;
1325                for(int it1=0;it1<5;it1++){
1326                    l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
1327                    for(int it2=0;it2<5;it2++)
1328                        l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
1329                };
1330                for(int ip=0;ip<6;ip++){
1331                    l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip);
1332                    l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip);
1333                    l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];
1334                    l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];
1335                    l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];
1336                    l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];
1337                    l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];
1338                    l2->tailx[i][ip]  = ((TrkTrack *)Track->At(i))->tailx[ip];
1339                    l2->taily[i][ip]  = ((TrkTrack *)Track->At(i))->taily[ip];
1340                    l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];
1341                    l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];
1342                    l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];
1343                    l2->axv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->axv[ip];
1344                    l2->ayv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->ayv[ip];
1345                    l2->dedx_x[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_x[ip];
1346                    l2->dedx_y[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_y[ip];
1347                };
1348            }
1349        }
1350    //  *** SINGLETS ***    
1351        if(SingletX){
1352            l2->nclsx              = SingletX->GetEntries();
1353            for(Int_t i=0;i<l2->nclsx;i++){
1354                l2->planex[i]  = ((TrkSinglet *)SingletX->At(i))->plane;
1355                l2->xs[i][0]   = ((TrkSinglet *)SingletX->At(i))->coord[0];
1356                l2->xs[i][1]   = ((TrkSinglet *)SingletX->At(i))->coord[1];
1357                l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
1358            }
1359        }
1360    
1361        if(SingletY){
1362            l2->nclsy              = SingletY->GetEntries();
1363            for(Int_t i=0;i<l2->nclsy;i++){
1364                l2->planey[i]  = ((TrkSinglet *)SingletY->At(i))->plane;
1365                l2->ys[i][0]   = ((TrkSinglet *)SingletY->At(i))->coord[0];
1366                l2->ys[i][1]   = ((TrkSinglet *)SingletY->At(i))->coord[1];
1367                l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
1368            }
1369        }
1370  }  }
1371  //--------------------------------------  //--------------------------------------
1372  //  //
1373  //  //
1374  //--------------------------------------  //--------------------------------------
1375  void TrkLevel2::Clear(){  void TrkLevel2::Clear(){
     good2    = -1;  
1376      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1377          crc[i] = -1;          good[i] = -1;
1378            VKflag[i] = 0;
1379            VKmask[i] = 0;
1380      };      };
1381  /*    Track->RemoveAll();  //    if(Track)Track->Clear("C");
1382      SingletX->RemoveAll();  //    if(SingletX)SingletX->Clear("C");
1383      SingletY->RemoveAll();*/  //    if(SingletY)SingletY->Clear("C");
1384          // modify to avoid memory leakage      if(Track)Track->Delete();
1385          Track->Clear();      if(SingletX)SingletX->Delete();
1386          SingletX->Clear();      if(SingletY)SingletY->Delete();
1387          SingletY->Clear();  }
1388    // //--------------------------------------
1389    // //
1390    // //
1391    // //--------------------------------------
1392    void TrkLevel2::Delete(){
1393            
1394    //    cout << "void TrkLevel2::Delete()"<<endl;
1395        Clear();
1396        if(Track)delete Track;
1397        if(SingletX)delete SingletX;
1398        if(SingletY)delete SingletY;
1399    
1400  }  }
1401  //--------------------------------------  //--------------------------------------
1402  //  //
# Line 362  void TrkLevel2::Clear(){ Line 1406  void TrkLevel2::Clear(){
1406   * Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).   * Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).
1407   * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.   * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.
1408   */   */
1409  TClonesArray *TrkLevel2::GetTracks(){  TRefArray *TrkLevel2::GetTracks_NFitSorted(){
     TClonesArray *sorted = GetTracks_NFitSorted();  
     return sorted;  
 };  
   
 TClonesArray *TrkLevel2::GetTracks_Chi2Sorted(){  
1410    
1411      TClonesArray *sorted = new TClonesArray("TrkTrack");      if(!Track)return 0;
     TClonesArray &t = *Track;  
     TClonesArray &ts = *sorted;  
     int N=this->ntrk();  
     vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;  
1412    
1413      int indo=0;      TRefArray *sorted = new TRefArray();
1414      int indi=0;          
1415      while(N != 0){      TClonesArray &t  = *Track;
1416          float chi2ref=1000000;  //    TClonesArray &ts = *PhysicalTrack;
1417          for(int i=0; i<this->ntrk(); i++){      int N = ntrk();
             if(((TrkTrack *)t[i])->chi2 < chi2ref && m[i]==1){  
                 chi2ref = ((TrkTrack *)t[i])->chi2;  
                 indi = i;  
             }  
         }  
         if( ((TrkTrack *)t[indi])->image != -1 ){  
             m[((TrkTrack *)t[indi])->image] = 0;  
             N--;  
         }  
         new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);  
         m[indi] = 0;  
         N--;      
         indo++;  
     }  
     return sorted;  
 }  
 TClonesArray *TrkLevel2::GetTracks_NFitSorted(){  
   
     TClonesArray *sorted = new TClonesArray("TrkTrack");  
     TClonesArray &t = *Track;  
     TClonesArray &ts = *sorted;  
     int N=this->ntrk();  
1418      vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;      vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;
1419    //      int m[50]; for(int i=0; i<N; i++)m[i]=1;
1420            
1421      int indo=0;      int indo=0;
1422      int indi=0;      int indi=0;
1423      while(N != 0){      while(N > 0){
1424    //    while(N != 0){
1425          int nfit =0;          int nfit =0;
1426          float chi2ref=1000000;          float chi2ref = numeric_limits<float>::max();
1427                    
1428          // first loop to search maximum num. of fit points          // first loop to search maximum num. of fit points
1429          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i < ntrk(); i++){
1430              if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){              if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
1431                  nfit =    ((TrkTrack *)t[i])->GetNtot();                  nfit =    ((TrkTrack *)t[i])->GetNtot();
 //              cout << "1** "<<i<< " " << nfit<<endl;  
1432              }              }
1433          }          }
1434          //second loop to search minimum chi2 among selected          //second loop to search minimum chi2 among selected
1435          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i<ntrk(); i++){
1436              if(    ((TrkTrack *)t[i])->chi2 < chi2ref              Float_t chi2 = ((TrkTrack *)t[i])->chi2;
1437                  && ((TrkTrack *)t[i])->GetNtot()== nfit              if(chi2 < 0) chi2 = -chi2*1000;
1438                  && m[i]==1){              if(    chi2 < chi2ref
1439                       && ((TrkTrack *)t[i])->GetNtot() == nfit
1440                       && m[i]==1){
1441                  chi2ref = ((TrkTrack *)t[i])->chi2;                  chi2ref = ((TrkTrack *)t[i])->chi2;
1442                  indi = i;                  indi = i;
1443  //              cout << "2** "<<i<< " " << nfit <<" "<<chi2ref<<endl;              };
1444              }          };
         }  
1445          if( ((TrkTrack *)t[indi])->HasImage() ){          if( ((TrkTrack *)t[indi])->HasImage() ){
1446              m[((TrkTrack *)t[indi])->image] = 0;              m[((TrkTrack *)t[indi])->image] = 0;
1447              N--;              N--;
1448            
 //          Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->GetNtot();  
 //          Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->chi2;  
                   
1449  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1450          }          };
1451          new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);          sorted->Add( (TrkTrack*)t[indi] );      
1452                    
1453          m[indi] = 0;          m[indi] = 0;
1454    //      cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl;
1455          N--;              N--;    
1456          indo++;          indo++;
1457      }      }
1458        m.clear();
1459    //    cout << "GetTracks_NFitSorted(it): Done"<< endl;
1460    
1461      return sorted;      return sorted;
1462    //    return PhysicalTrack;
1463  }  }
1464  //--------------------------------------  //--------------------------------------
1465  //  //
# Line 458  TrkTrack *TrkLevel2::GetStoredTrack(int Line 1477  TrkTrack *TrkLevel2::GetStoredTrack(int
1477          cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl;          cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl;
1478          return 0;          return 0;
1479      }      }
1480        if(!Track){
1481            cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (TClonesArray*) Track ==0 "<<endl;
1482        };
1483      TClonesArray &t = *(Track);      TClonesArray &t = *(Track);
1484      TrkTrack *track = (TrkTrack*)t[is];      TrkTrack *track = (TrkTrack*)t[is];
1485      return track;      return track;
# Line 467  TrkTrack *TrkLevel2::GetStoredTrack(int Line 1489  TrkTrack *TrkLevel2::GetStoredTrack(int
1489  //  //
1490  //--------------------------------------  //--------------------------------------
1491  /**  /**
1492     * Retrieves the is-th stored X singlet.
1493     * @param it Singlet number, ranging from 0 to nclsx().
1494     */
1495    TrkSinglet *TrkLevel2::GetSingletX(int is){
1496    
1497            if(is >= this->nclsx()){
1498                    cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
1499                    cout << "                Stored x-singlets nclsx() = "<< this->nclsx() << endl;
1500                    return 0;
1501            }
1502            if(!SingletX)return 0;
1503            TClonesArray &t = *(SingletX);
1504            TrkSinglet *singlet = (TrkSinglet*)t[is];
1505            return singlet;
1506    }
1507    //--------------------------------------
1508    //
1509    //
1510    //--------------------------------------
1511    /**
1512     * Retrieves the is-th stored Y singlet.
1513     * @param it Singlet number, ranging from 0 to nclsx().
1514     */
1515    TrkSinglet *TrkLevel2::GetSingletY(int is){
1516    
1517            if(is >= this->nclsy()){
1518                    cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
1519                    cout << "                Stored y-singlets nclsy() = "<< this->nclsx() << endl;
1520                    return 0;
1521            }
1522            if(!SingletY)return 0;
1523            TClonesArray &t = *(SingletY);
1524            TrkSinglet *singlet = (TrkSinglet*)t[is];
1525            return singlet;
1526    }
1527    //--------------------------------------
1528    //
1529    //
1530    //--------------------------------------
1531    /**
1532   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
1533   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1534   */   */
1535    
1536  TrkTrack *TrkLevel2::GetTrack(int it){  TrkTrack *TrkLevel2::GetTrack(int it){
1537            
1538      if(it >= this->GetNTracks()){          if(it >= this->GetNTracks()){
1539          cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;                  cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;
1540          cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;                  cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1541          return 0;                  return 0;
1542      }          }
1543      TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];          
1544          GetTracks()->Delete();////TEMPORANEO          TRefArray *sorted = GetTracks();  //TEMPORANEO  
1545      return track;          if(!sorted)return 0;
1546            TrkTrack *track = (TrkTrack*)sorted->At(it);
1547            sorted->Clear();
1548            delete sorted;
1549            return track;
1550  }  }
1551    /**
1552     * Give the number of "physical" tracks, sorted by the method GetTracks().
1553     */
1554  Int_t TrkLevel2::GetNTracks(){  Int_t TrkLevel2::GetNTracks(){
1555          Int_t ntot=0;                  
1556          ntot = GetTracks()->GetEntries();          Float_t ntot=0;
1557          GetTracks()->Delete();////TEMPORANEO          if(!Track)return 0;
1558          return ntot;          TClonesArray &t = *Track;
1559            for(int i=0; i<ntrk(); i++) {    
1560                    if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
1561                    else ntot+=0.5;
1562            }
1563            return (Int_t)ntot;
1564    
1565  };  };
1566  //--------------------------------------  //--------------------------------------
1567  //  //
# Line 502  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1578  TrkTrack *TrkLevel2::GetTrackImage(int i
1578          cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;          cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1579          return 0;          return 0;
1580      }      }
1581      TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];          
1582        TRefArray* sorted = GetTracks(); //TEMPORANEO
1583        if(!sorted)return 0;
1584        TrkTrack *track = (TrkTrack*)sorted->At(it);
1585            
1586      if(!track->HasImage()){      if(!track->HasImage()){
1587          cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;          cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;
1588          return 0;          return 0;
1589      }      }
1590        if(!Track)return 0;
1591      TrkTrack *image = (TrkTrack*)(*Track)[track->image];      TrkTrack *image = (TrkTrack*)(*Track)[track->image];
1592    
1593        sorted->Delete();
1594        delete sorted;
1595    
1596      return image;      return image;
1597            
1598  }  }
# Line 519  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1604  TrkTrack *TrkLevel2::GetTrackImage(int i
1604   * Loads the magnetic field.   * Loads the magnetic field.
1605   * @param s Path of the magnetic-field files.   * @param s Path of the magnetic-field files.
1606   */   */
1607  void TrkLevel2::LoadField(TString s){  void TrkLevel2::LoadField(TString path){
1608      readb_(s.Data());  //
1609    //     strcpy(path_.path,path.Data());
1610    //     path_.pathlen = path.Length();
1611    //     path_.error   = 0;
1612    //     readb_();
1613    
1614        TrkParams::SetTrackingMode();
1615        TrkParams::SetPrecisionFactor();
1616        TrkParams::SetStepMin();
1617    
1618        TrkParams::Set(path,1);
1619        TrkParams::Load(1);
1620    
1621    //
1622    };
1623    // /**
1624    //  * Get BY (kGauss)
1625    //  * @param v (x,y,z) coordinates in cm
1626    //  */
1627    // float TrkLevel2::GetBX(float* v){
1628    //     float b[3];
1629    //     gufld_(v,b);
1630    //     return b[0]/10.;
1631    // }
1632    // /**
1633    //  * Get BY (kGauss)
1634    //  * @param v (x,y,z) coordinates in cm
1635    //  */
1636    // float TrkLevel2::GetBY(float* v){
1637    //     float b[3];
1638    //     gufld_(v,b);
1639    //     return b[1]/10.;
1640    // }
1641    // /**
1642    //  * Get BY (kGauss)
1643    //  * @param v (x,y,z) coordinates in cm
1644    //  */
1645    // float TrkLevel2::GetBZ(float* v){
1646    //     float b[3];
1647    //     gufld_(v,b);
1648    //     return b[2]/10.;
1649    // }
1650    //--------------------------------------
1651    //
1652    //
1653    //--------------------------------------
1654    /**
1655     * Get tracker-plane (mechanical) z-coordinate
1656     * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM)
1657     */
1658    Float_t TrkLevel2::GetZTrk(Int_t plane_id){
1659            switch(plane_id){
1660                    case 1: return ZTRK1;
1661                    case 2: return ZTRK2;
1662                    case 3: return ZTRK3;
1663                    case 4: return ZTRK4;
1664                    case 5: return ZTRK5;
1665                    case 6: return ZTRK6;
1666                    default: return 0.;
1667            };
1668  };  };
1669  //--------------------------------------  //--------------------------------------
1670  //  //
# Line 538  Trajectory::Trajectory(){ Line 1682  Trajectory::Trajectory(){
1682      thx = new float[npoint];      thx = new float[npoint];
1683      thy = new float[npoint];      thy = new float[npoint];
1684      tl = new float[npoint];      tl = new float[npoint];
1685      float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1);      float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
1686      for(int i=0; i<npoint; i++){      for(int i=0; i<npoint; i++){
1687          x[i] = 0;          x[i] = 0;
1688          y[i] = 0;          y[i] = 0;
1689          z[i] = (ZTRKUP) - i*dz;          z[i] = (ZTRK1) - i*dz;
1690          thx[i] = 0;          thx[i] = 0;
1691          thy[i] = 0;          thy[i] = 0;
1692          tl[i] = 0;          tl[i] = 0;
# Line 569  Trajectory::Trajectory(int n){ Line 1713  Trajectory::Trajectory(int n){
1713      thx = new float[npoint];      thx = new float[npoint];
1714      thy = new float[npoint];      thy = new float[npoint];
1715      tl = new float[npoint];      tl = new float[npoint];
1716      float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1);      float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
1717      for(int i=0; i<npoint; i++){      for(int i=0; i<npoint; i++){
1718          x[i] = 0;          x[i] = 0;
1719          y[i] = 0;          y[i] = 0;
1720          z[i] = (ZTRKUP) - i*dz;          z[i] = (ZTRK1) - i*dz;
1721          thx[i] = 0;          thx[i] = 0;
1722          thy[i] = 0;          thy[i] = 0;
1723          tl[i] = 0;          tl[i] = 0;
# Line 610  Trajectory::Trajectory(int n, float* zin Line 1754  Trajectory::Trajectory(int n, float* zin
1754      npoint=i;      npoint=i;
1755      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
1756  }  }
1757    void Trajectory::Delete(){
1758        
1759        if(x) delete [] x;
1760        if(y) delete [] y;
1761        if(z) delete [] z;
1762        if(thx) delete [] thx;
1763        if(thy) delete [] thy;
1764        if(tl) delete [] tl;
1765    
1766    }
1767  //--------------------------------------  //--------------------------------------
1768  //  //
1769  //  //
# Line 647  float Trajectory::GetLength(int ifirst, Line 1801  float Trajectory::GetLength(int ifirst,
1801      return l;      return l;
1802    
1803  }  }
1804    
1805    /**
1806     * Evaluates the trajectory in the apparatus associated to the track.
1807     * It integrates the equations of motion in the magnetic field. The magnetic field should be previously loaded ( by calling  TrkLevel2::LoadField() ), otherwise an error message is returned.  
1808     * @param t pointer to an object of the class Trajectory,
1809     * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
1810     * @return error flag.
1811     */
1812    int Trajectory::DoTrack2(float* al){
1813    
1814        double *dxout   = new double[npoint];
1815        double *dyout   = new double[npoint];
1816        double *dthxout = new double[npoint];
1817        double *dthyout = new double[npoint];
1818        double *dtlout  = new double[npoint];
1819        double *dzin    = new double[npoint];
1820        double dal[5];
1821    
1822        int ifail = 0;
1823    
1824        for (int i=0; i<5; i++)      dal[i]  = (double)al[i];
1825        for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
1826    
1827        TrkParams::Load(1);
1828        if( !TrkParams::IsLoaded(1) ){
1829            cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;
1830            return 0;
1831        }
1832        dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
1833        
1834        for (int i=0; i<npoint; i++){
1835            x[i]   = (float)*dxout++;
1836            y[i]   = (float)*dyout++;
1837            thx[i] = (float)*dthxout++;
1838            thy[i] = (float)*dthyout++;
1839            tl[i]  = (float)*dtlout++;
1840        }
1841    
1842        return ifail;
1843    };
1844    
1845  ClassImp(TrkLevel2);  ClassImp(TrkLevel2);
1846  ClassImp(TrkSinglet);  ClassImp(TrkSinglet);
1847  ClassImp(TrkTrack);  ClassImp(TrkTrack);

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.23