/[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.3 by pam-fi, Wed Jun 14 10:01:44 2006 UTC revision 1.44 by pam-fi, Wed Mar 5 17:00:19 2008 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::SetMiniDefault();
68        TrkParams::SetPFA();
69    
70        int ngf = TrkParams::nGF;
71        for(int i=0; i<ngf; i++){
72            xGF[i] = 0.;
73            yGF[i] = 0.;
74        }
75    
76    
77  };  };
78  //--------------------------------------  //--------------------------------------
79  //  //
# Line 51  TrkTrack::TrkTrack(const TrkTrack& t){ Line 83  TrkTrack::TrkTrack(const TrkTrack& t){
83      seqno = t.seqno;      seqno = t.seqno;
84      image = t.image;      image = t.image;
85      chi2  = t.chi2;      chi2  = t.chi2;
86        nstep = t.nstep;
87      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
88          al[it1] = t.al[it1];          al[it1] = t.al[it1];
89          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];  
90      };      };
91      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
92          xgood[ip]  = t.xgood[ip];          xgood[ip]  = t.xgood[ip];
# Line 64  TrkTrack::TrkTrack(const TrkTrack& t){ Line 96  TrkTrack::TrkTrack(const TrkTrack& t){
96          zm[ip]     = t.zm[ip];          zm[ip]     = t.zm[ip];
97          resx[ip]   = t.resx[ip];          resx[ip]   = t.resx[ip];
98          resy[ip]   = t.resy[ip];          resy[ip]   = t.resy[ip];
99            tailx[ip]  = t.tailx[ip];
100            taily[ip]  = t.taily[ip];
101          xv[ip]     = t.xv[ip];          xv[ip]     = t.xv[ip];
102          yv[ip]     = t.yv[ip];          yv[ip]     = t.yv[ip];
103          zv[ip]     = t.zv[ip];          zv[ip]     = t.zv[ip];
# Line 71  TrkTrack::TrkTrack(const TrkTrack& t){ Line 105  TrkTrack::TrkTrack(const TrkTrack& t){
105          ayv[ip]    = t.ayv[ip];          ayv[ip]    = t.ayv[ip];
106          dedx_x[ip] = t.dedx_x[ip];          dedx_x[ip] = t.dedx_x[ip];
107          dedx_y[ip] = t.dedx_y[ip];          dedx_y[ip] = t.dedx_y[ip];
108      };              multmaxx[ip] = t.multmaxx[ip];
109            multmaxy[ip] = t.multmaxy[ip];
110            seedx[ip]    = t.seedx[ip];  
111            seedy[ip]    = t.seedy[ip];
112            xpu[ip]      = t.xpu[ip];  
113            ypu[ip]      = t.ypu[ip];  
114        };
115    
116    //     TrkParams::SetTrackingMode();
117    //     TrkParams::SetPrecisionFactor();
118    //     TrkParams::SetStepMin();  
119        TrkParams::SetMiniDefault();
120        TrkParams::SetPFA();
121    
122        int ngf = TrkParams::nGF;
123        for(int i=0; i<ngf; i++){
124            xGF[i] = t.xGF[i];
125            yGF[i] = t.yGF[i];
126        }
127    };
128    //--------------------------------------
129    //
130    //
131    //--------------------------------------
132    void TrkTrack::Copy(TrkTrack& t){
133    
134        t.seqno = seqno;
135        t.image = image;
136        t.chi2  = chi2;
137        t.nstep = nstep;
138        for(int it1=0;it1<5;it1++){
139            t.al[it1] = al[it1];
140            for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2];
141        };
142        for(int ip=0;ip<6;ip++){
143            t.xgood[ip]  = xgood[ip];
144            t.ygood[ip]  = ygood[ip];
145            t.xm[ip]     = xm[ip];
146            t.ym[ip]     = ym[ip];
147            t.zm[ip]     = zm[ip];
148            t.resx[ip]   = resx[ip];
149            t.resy[ip]   = resy[ip];
150            t.tailx[ip]  = tailx[ip];
151            t.taily[ip]  = taily[ip];
152            t.xv[ip]     = xv[ip];
153            t.yv[ip]     = yv[ip];
154            t.zv[ip]     = zv[ip];
155            t.axv[ip]    = axv[ip];
156            t.ayv[ip]    = ayv[ip];
157            t.dedx_x[ip] = dedx_x[ip];
158            t.dedx_y[ip] = dedx_y[ip];
159            t.multmaxx[ip] = multmaxx[ip];
160            t.multmaxy[ip] = multmaxy[ip];
161            t.seedx[ip]    = seedx[ip];  
162            t.seedy[ip]    = seedy[ip];
163            t.xpu[ip]      = xpu[ip];  
164            t.ypu[ip]      = ypu[ip];  
165                
166        };
167        int ngf = TrkParams::nGF;
168        for(int i=0; i<ngf; i++){
169            t.xGF[i] = xGF[i];
170            t.yGF[i] = yGF[i];
171        }
172    
173        
174  };  };
175  //--------------------------------------  //--------------------------------------
176  //  //
# Line 83  TrkTrack::TrkTrack(const TrkTrack& t){ Line 182  TrkTrack::TrkTrack(const TrkTrack& t){
182   * @param t pointer to an object of the class Trajectory,   * @param t pointer to an object of the class Trajectory,
183   * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).   * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
184   * @return error flag.   * @return error flag.
185     *
186     * >>> OBSOLETE !!! use TrkTrack::DoTrack2(Trajectory* t) instead
187     *
188   */   */
189  int TrkTrack::DoTrack(Trajectory* t){  int TrkTrack::DoTrack(Trajectory* t){
190    
191        cout << " int TrkTrack::DoTrack(Trajectory* t) --->> OBSOLETE !!! "<<endl;
192        cout << " use int TrkTrack::DoTrack2(Trajectory* t)"<<endl;
193    
194      double *dxout = new double[t->npoint];      double *dxout = new double[t->npoint];
195      double *dyout = new double[t->npoint];      double *dyout = new double[t->npoint];
196      double *dzin = new double[t->npoint];      double *dzin = new double[t->npoint];
# Line 96  int TrkTrack::DoTrack(Trajectory* t){ Line 201  int TrkTrack::DoTrack(Trajectory* t){
201      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];
202      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];
203    
204        TrkParams::Load(1);
205        if( !TrkParams::IsLoaded(1) ){
206            cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
207            return 0;
208        }
209      dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);      dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);
210            
211      for (int i=0; i<t->npoint; i++){      for (int i=0; i<t->npoint; i++){
# Line 135  int TrkTrack::DoTrack2(Trajectory* t){ Line 245  int TrkTrack::DoTrack2(Trajectory* t){
245      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];
246      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];
247    
248        TrkParams::Load(1);
249        if( !TrkParams::IsLoaded(1) ){
250            cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
251            return 0;
252        }
253      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
254            
255      for (int i=0; i<t->npoint; i++){      for (int i=0; i<t->npoint; i++){
# Line 174  Float_t TrkTrack::GetDeflection(){ Line 289  Float_t TrkTrack::GetDeflection(){
289          return def;          return def;
290  };  };
291  //  //
292    /**
293     * Method to retrieve the dE/dx measured on a tracker view.
294     * @param ip plane (0-5)
295     * @param iv view (0=x 1=y)
296     */
297    Float_t TrkTrack::GetDEDX(int ip, int iv){
298        if(iv==0 && ip>=0 && ip<6)return fabs(dedx_x[ip]);
299        else if(iv==1 && ip>=0 && ip<6)return fabs(dedx_y[ip]);
300        else {
301            cout << "TrkTrack::GetDEDX(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
302            return 0.;
303        }
304    }
305    /**
306     * Method to evaluate the dE/dx measured on a tracker plane.
307     * The two measurements on x- and y-view are averaged.
308     * @param ip plane (0-5)
309     */
310    Float_t TrkTrack::GetDEDX(int ip){
311        if( (Int_t)XGood(ip)+(Int_t)YGood(ip) == 0 ) return 0;
312        return (GetDEDX(ip,0)+GetDEDX(ip,1))/((Int_t)XGood(ip)+(Int_t)YGood(ip));
313    };
314    
315    /**
316     * Method to evaluate the dE/dx averaged over all planes.
317     */
318  Float_t TrkTrack::GetDEDX(){  Float_t TrkTrack::GetDEDX(){
319          Float_t dedx=0;      Float_t dedx=0;
320          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);
321          dedx = dedx/(this->GetNX()+this->GetNY());      dedx = dedx/(GetNX()+GetNY());
322          return dedx;      return dedx;
323    };
324    /**
325     * Returns 1 if the cluster on a tracker view includes bad strips
326     * (at least one bad strip among the four strip used by p.f.a.)
327     * @param ip plane (0-5)
328     * @param iv view (0=x 1=y)
329     */
330    Bool_t TrkTrack::IsBad(int ip,int iv){
331        if(iv==0 && ip>=0 && ip<6)return (xgood[ip]<0) ;
332        else if(iv==1 && ip>=0 && ip<6)return (ygood[ip]<0) ;
333        else {
334            cout << "TrkTrack::IsBad(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
335            return 0.;
336        }
337    };
338    /**
339     * Returns 1 if the signal on a tracker view is saturated.
340     * @param ip plane (0-5)
341     * @param iv view (0=x 1=y)
342     */
343    Bool_t TrkTrack::IsSaturated(int ip,int iv){
344        if(iv==0 && ip>=0 && ip<6)return (dedx_x[ip]<0) ;
345        else if(iv==1 && ip>=0 && ip<6)return (dedx_y[ip]<0) ;
346        else {
347            cout << "TrkTrack::IsSaturated(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
348            return 0.;
349        }
350    };
351    /**
352     * Returns 1 if either the x or the y signal on a tracker plane is saturated.
353     * @param ip plane (0-5)
354     */
355    Bool_t TrkTrack::IsSaturated(int ip){
356        return (IsSaturated(ip,0)||IsSaturated(ip,1));
357    };
358    /**
359     * Returns 1 if there is at least a saturated signal along the track.
360     */
361    Bool_t TrkTrack::IsSaturated(){
362        for(int ip=0; ip<6; ip++)for(int iv=0; iv<2; iv++)if(IsSaturated(ip,iv))return true;
363        return false;
364    }
365    /**
366     * Returns the track "lever-arm" on the x view, defined as the distance (in planes) between
367     * the upper and lower x measurements (the maximum value of lever-arm is 6).
368     */
369    Int_t TrkTrack::GetLeverArmX(){
370        int first_plane = -1;
371        int last_plane  = -1;
372        for(Int_t ip=0; ip<6; ip++){
373            if( XGood(ip) && first_plane == -1 )first_plane = ip;
374            if( XGood(ip) && first_plane != -1 )last_plane = ip;
375        }
376        if( first_plane == -1 || last_plane == -1){
377            cout<< "Int_t TrkTrack::GetLeverArmX() -- XGood(ip) always false ??? "<<endl;
378            return 0;
379        }
380        return (last_plane-first_plane+1);
381    }
382    /**
383     * Returns the track "lever-arm" on the y view, defined as the distance (in planes) between
384     * the upper and lower y measurements (the maximum value of lever-arm is 6).
385     */
386    Int_t TrkTrack::GetLeverArmY(){
387        int first_plane = -1;
388        int last_plane  = -1;
389        for(Int_t ip=0; ip<6; ip++){
390            if( YGood(ip) && first_plane == -1 )first_plane = ip;
391            if( YGood(ip) && first_plane != -1 )last_plane = ip;
392        }
393        if( first_plane == -1 || last_plane == -1){
394            cout<< "Int_t TrkTrack::GetLeverArmY() -- YGood(ip) always false ??? "<<endl;
395            return 0;
396        }
397        return (last_plane-first_plane+1);
398    }
399    /**
400     * Returns the reduced chi-square of track x-projection
401     */
402    Float_t  TrkTrack::GetChi2X(){
403        float chiq=0;
404        for(int ip=0; ip<6; ip++)if(XGood(ip))chiq+= pow((xv[ip]-xm[ip])/resx[ip],2.);
405        if(GetNX()>3)chiq=chiq/(GetNX()-3);
406        else chiq=0;
407        if(chiq==0)cout << " Float_t  TrkTrack::GetChi2X() -- WARNING -- value not defined "<<chiq<<endl;
408        return chiq;
409    }
410    /**
411     * Returns the reduced chi-square of track y-projection
412     */
413    Float_t  TrkTrack::GetChi2Y(){
414        float chiq=0;
415        for(int ip=0; ip<6; ip++)if(YGood(ip))chiq+= pow((yv[ip]-ym[ip])/resy[ip],2.);
416        if(GetNY()>2)chiq=chiq/(GetNY()-2);
417        else chiq=0;
418        if(chiq==0)cout << " Float_t  TrkTrack::GetChi2Y() -- WARNING -- value not defined "<<chiq<<endl;
419        return chiq;
420    }
421    /**
422     * Returns the logarythm of the likeliwood-function of  track x-projection
423     */
424    Float_t TrkTrack::GetLnLX(){
425        float lnl=0;
426        for(int ip=0; ip<6; ip++)
427            if( XGood(ip) && tailx[ip]!=0 )
428                lnl += (tailx[ip]+1.) * log( (tailx[ip]*pow(resx[ip],2.) + pow(xv[ip]-xm[ip],2.)) / (tailx[ip]*pow(resx[ip],2)) );
429        if(GetNX()>3)lnl=lnl/(GetNX()-3);
430        else lnl=0;
431        if(lnl==0){
432            cout << " Float_t  TrkTrack::GetLnLX() -- WARNING -- value not defined "<<lnl<<endl;
433            Dump();
434        }
435        return lnl;
436        
437    }
438    /**
439     * Returns the logarythm of the likeliwood-function of  track y-projection
440     */
441    Float_t TrkTrack::GetLnLY(){
442        float lnl=0;
443        for(int ip=0; ip<6; ip++)
444            if( YGood(ip) && taily[ip]!=0 )
445                lnl += (taily[ip]+1.) * log( (taily[ip]*pow(resy[ip],2.) + pow(yv[ip]-ym[ip],2.)) / (taily[ip]*pow(resy[ip],2)) );
446        if(GetNY()>2)lnl=lnl/(GetNY()-2);
447        else lnl=0;
448        if(lnl==0){
449            cout << " Float_t  TrkTrack::GetLnLY() -- WARNING -- value not defined "<<lnl<<endl;
450            Dump();
451        }
452        return lnl;
453        
454    }
455    /**
456     * Returns the effective angle, relative to the sensor, on each plane.
457     * @param ip plane (0-5)
458     * @param iv view (0=x 1=y)
459     */
460    Float_t TrkTrack::GetEffectiveAngle(int ip, int iv){
461    
462        if(ip<0 || ip>5){
463            cout << "Float_t TrkTrack::GetEffectiveAngle(int "<<ip<<", int "<<iv<<") ==> wrong input"<<endl;
464            return 0.;
465        }
466    
467        float v[3]={xv[ip],yv[ip],zv[ip]};
468        //-----------------------------------------
469        // effective angle (relative to the sensor)
470        //-----------------------------------------
471        float axv_geo  = axv[ip];
472        float muhall_h = 297.61; //cm**2/Vs
473        float BY = TrkParams::GetBY(v);
474        float axv_eff = 0;
475        if(ip==5) axv_geo = -1*axv_geo;
476        if(ip==5) BY      = -1*BY;
477        axv_eff = 180.*atan( tan(axv_geo*acos(-1.)/180.) + muhall_h * BY * 0.0001)/acos(-1.);
478        //-----------------------------------------
479        // effective angle (relative to the sensor)
480        //-----------------------------------------
481        float ayv_geo = ayv[ip];
482        float muhall_e = 1258.18; //cm**2/Vs
483        float BX = TrkParams::GetBX(v);
484        float ayv_eff = 0;
485        ayv_eff = 180.*atan( tan(ayv_geo*acos(-1.)/180.) + muhall_e * BX * 0.0001)/acos(-1.);
486      
487        if     (iv==0)return axv_eff;
488        else if(iv==1)return ayv_eff;
489        else{
490            cout << "Float_t TrkTrack::GetEffectiveAngle(int "<<ip<<", int "<<iv<<") ==> wrong input"<<endl;
491            return 0.;
492        }
493      
494  };  };
495    
496  //--------------------------------------  //--------------------------------------
# Line 187  Float_t TrkTrack::GetDEDX(){ Line 499  Float_t TrkTrack::GetDEDX(){
499  //--------------------------------------  //--------------------------------------
500  void TrkTrack::Dump(){  void TrkTrack::Dump(){
501      cout << endl << "========== Track " ;      cout << endl << "========== Track " ;
502        cout << endl << "seq.  n. : "<< seqno;
503        cout << endl << "image n. : "<< image;
504      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] << " ";
505      cout << endl << "chi^2    : "<< chi2;      cout << endl << "chi^2    : "<< chi2;
506      cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << xgood[i] ;      cout << endl << "n.step   : "<< nstep;
507      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) ;
508        cout << endl << "ygood    : "; for(int i=0; i<6; i++)cout << YGood(i) ;
509      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] << " ";
510      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] << " ";
511      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] << " ";
512        cout << endl << "xv       : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
513        cout << endl << "yv       : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
514        cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
515        cout << endl << "resx     : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
516        cout << endl << "resy     : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
517        cout << endl << "tailx    : "; for(int i=0; i<6; i++)cout << tailx[i] << " ";
518        cout << endl << "taily    : "; for(int i=0; i<6; i++)cout << taily[i] << " ";
519        cout << endl << "coval    : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
520        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
521        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
522        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
523        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
524      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] << " ";
525      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] << " ";
526        cout << endl << "maxs x   : "; for(int i=0; i<6; i++)cout << GetClusterX_MaxStrip(i) << " ";
527        cout << endl << "maxs y   : "; for(int i=0; i<6; i++)cout << GetClusterY_MaxStrip(i) << " ";
528        cout << endl << "mult x   : "; for(int i=0; i<6; i++)cout << GetClusterX_Multiplicity(i) << " ";
529        cout << endl << "mult y   : "; for(int i=0; i<6; i++)cout << GetClusterY_Multiplicity(i) << " ";
530        cout << endl << "seed x   : "; for(int i=0; i<6; i++)cout << GetClusterX_Seed(i) << " ";
531        cout << endl << "seed y   : "; for(int i=0; i<6; i++)cout << GetClusterY_Seed(i) << " ";
532        cout << endl << "xpu      : "; for(int i=0; i<6; i++)cout << xpu[i] << " ";
533        cout << endl << "ypu      : "; for(int i=0; i<6; i++)cout << ypu[i] << " ";
534    
535        cout << endl;
536    }
537    /**
538     * Set the TrkTrack position measurements
539     */
540    void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
541        for(int i=0; i<6; i++) xm[i]=*xmeas++;
542        for(int i=0; i<6; i++) ym[i]=*ymeas++;
543        for(int i=0; i<6; i++) zm[i]=*zmeas++;
544    }
545    /**
546     * Set the TrkTrack position resolution
547     */
548    void TrkTrack::SetResolution(double *rx, double *ry){
549        for(int i=0; i<6; i++) resx[i]=*rx++;
550        for(int i=0; i<6; i++) resy[i]=*ry++;
551    }
552    /**
553     * Set the TrkTrack tails position resolution
554     */
555    void TrkTrack::SetTail(double *tx, double *ty, double factor){
556        for(int i=0; i<6; i++) tailx[i]=factor*(*tx++);
557        for(int i=0; i<6; i++) taily[i]=factor*(*ty++);
558    }
559    /**
560     * Set the TrkTrack Student parameter (resx,resy,tailx,taily)
561     * from previous gausian fit
562     *@param flag =0 standard, =1 with noise correction
563     */
564    void TrkTrack::SetStudentParam(int flag){
565        float sx[11]={0.000128242,
566                       0.000136942,
567                       0.000162718,
568                       0.000202644,
569                       0.00025597,
570                       0.000317456,
571                       0.000349048,
572                       0.000384638,
573                       0.000457295,
574                       0.000512319,
575                       0.000538573};
576        float tx[11]={1.79402,
577                       2.04876,
578                       2.88376,
579                       3.3,
580                       3.14084,
581                       4.07686,
582                       4.44736,
583                       3.5179,
584                       3.38697,
585                       3.45739,
586                       3.18627};
587        float sy[11]={0.000483075,
588                       0.000466925,
589                       0.000431658,
590                       0.000428317,
591                       0.000433854,
592                       0.000444044,
593                       0.000482098,
594                       0.000537579,
595                       0.000636279,
596                       0.000741998,
597                       0.000864261};
598        float ty[11]={0.997032,
599                       1.11147,
600                       1.18526,
601                       1.61404,
602                       2.21908,
603                       3.08959,
604                       4.48833,
605                       4.42687,
606                       4.65253,
607                       4.52043,
608                       4.29926};
609        int index;
610        float fact;
611        for(int i=0; i<6; i++) {
612            index = int((fabs(axv[i])+1.)/2.);
613            if(index>10) index=10;
614            tailx[i]=tx[index];
615            if(flag==1) {
616                if(fabs(axv[i])<=10.) fact = resx[i]/risxeta2_(&(axv[i]));
617                if(fabs(axv[i])>10.&&fabs(axv[i])<=15.) fact = resx[i]/risxeta3_(&(axv[i]));
618                if(fabs(axv[i])>15.) fact = resx[i]/risxeta4_(&(axv[i]));
619            } else fact = 1.;
620            resx[i] = sx[index]*fact;
621        }
622        for(int i=0; i<6; i++) {
623            index = int((fabs(ayv[i])+1.)/2.);
624            if(index>10) index=10;
625            taily[i]=ty[index];
626            if(flag==1) fact = resy[i]/risyeta2_(&(ayv[i]));
627            else fact = 1.;
628            resy[i] = sy[index]*fact;
629        }
630    }
631    /**
632     * Set the TrkTrack good measurement
633     */
634    void TrkTrack::SetGood(int *xg, int *yg){
635    
636        for(int i=0; i<6; i++) xgood[i]=*xg++;
637        for(int i=0; i<6; i++) ygood[i]=*yg++;
638    }
639    
640    /**
641     * Load the magnetic field
642     */
643    void TrkTrack::LoadField(TString path){
644        
645    //     strcpy(path_.path,path.Data());
646    //     path_.pathlen = path.Length();
647    //     path_.error   = 0;
648    //     readb_();
649    
650    //     TrkParams::SetTrackingMode();
651    //     TrkParams::SetPrecisionFactor();
652    //     TrkParams::SetStepMin();
653        TrkParams::SetMiniDefault();
654    
655        TrkParams::Set(path,1);
656        TrkParams::Load(1);
657    
658    };
659    
660    
661    /**
662     * Method to fill minimization-routine common
663     */
664    void TrkTrack::FillMiniStruct(cMini2track& track){
665    
666        for(int i=0; i<6; i++){
667    
668    //      cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl;
669    //      cout << i<<" - "<<ygood[i]<<" "<<YGood(i)<<endl;
670            track.xgood[i]=XGood(i);
671            track.ygood[i]=YGood(i);
672            
673            track.xm[i]=xm[i];
674            track.ym[i]=ym[i];
675            track.zm[i]=zm[i];
676            
677    //      --- temporaneo ----------------------------
678    //      andrebbe inserita la dimensione del sensore
679            float segment = 100.;
680            track.xm_a[i]=xm[i];
681            track.xm_b[i]=xm[i];
682            track.ym_a[i]=ym[i];
683            track.ym_b[i]=ym[i];
684            if(       XGood(i) && !YGood(i) ){
685                track.ym_a[i] = track.ym_a[i]+segment;
686                track.ym_b[i] = track.ym_b[i]-segment;
687            }else if( !XGood(i) && YGood(i)){
688                track.xm_a[i] = track.xm_a[i]+segment;
689                track.xm_b[i] = track.xm_b[i]-segment;
690            }
691    //      --- temporaneo ----------------------------
692            
693            track.resx[i]=resx[i];
694            track.resy[i]=resy[i];
695            track.tailx[i]=tailx[i];
696            track.taily[i]=taily[i];
697        }
698    
699        for(int i=0; i<5; i++) track.al[i]=al[i];
700        track.zini = 23.5;
701    // ZINI = 23.5 !!! it should be the same parameter in all codes
702        
703  }  }
704    /**
705     * Method to set values from  minimization-routine common
706     */
707    void TrkTrack::SetFromMiniStruct(cMini2track *track){
708    
709        for(int i=0; i<5; i++) {
710            al[i]=track->al[i];
711            for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j];
712        }
713        chi2  = track->chi2;
714        nstep = track->nstep;
715        for(int i=0; i<6; i++){
716            xv[i]  = track->xv[i];
717            yv[i]  = track->yv[i];
718            zv[i]  = track->zv[i];
719            xm[i]  = track->xm[i];
720            ym[i]  = track->ym[i];
721            zm[i]  = track->zm[i];
722            axv[i] = track->axv[i];
723            ayv[i] = track->ayv[i];
724        }
725        
726    }
727    /**
728     * \brief Method to re-evaluate coordinates of clusters associated with a track.
729     *
730     * The method can be applied only after recovering level1 information
731     * (either by reprocessing single events from level0 or from  
732     * the TrkLevel1 branch, if present); it calls F77 subroutines that
733     * read the level1 common and fill the minimization-routine common.
734     * Some clusters can be excluded or added by means of the methods:
735     *
736     * TrkTrack::ResetXGood(int ip)
737     * TrkTrack::ResetYGood(int ip)
738     * TrkTrack::SetXGood(int ip, int cid, int is)
739     * TrkTrack::SetYGood(int ip, int cid, int is)
740     *
741     * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1)
742     * for the minimization-routine common. It deletes the cluster information
743     * (at least for the moment...) thus cannot be applied before
744     * TrkTrack::EvaluateClusterPositions().  
745     *
746     * Different p.f.a. can be applied by calling (once) the method:
747     *
748     * TrkParams::SetPFA(0); //Set ETA p.f.a.
749     *
750     * @see TrkParams::SetPFA(int)
751     */
752    Bool_t TrkTrack::EvaluateClusterPositions(){
753        
754    //     cout << "void TrkTrack::GetClusterositions() "<<endl;
755    
756        TrkParams::Load( );
757        if( !TrkParams::IsLoaded() )return false;
758        
759        for(int ip=0; ip<6; ip++){
760    //      cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;
761            int icx = GetClusterX_ID(ip)+1;
762            int icy = GetClusterY_ID(ip)+1;
763            int sensor = GetSensor(ip)+1;//<< convenzione "Paolo"
764            if(ip==5 && sensor!=0)sensor=3-sensor;//<< convenzione "Elena"
765            int ladder = GetLadder(ip)+1;
766            float ax = axv[ip];
767            float ay = ayv[ip];
768            float v[3];
769            v[0]=xv[ip];
770            v[1]=yv[ip];
771            v[2]=zv[ip];
772            float bfx = 10*TrkParams::GetBX(v);//Tesla
773            float bfy = 10*TrkParams::GetBY(v);//Tesla
774            int ipp=ip+1;
775            xyzpam_(&ipp,&icx,&icy,&ladder,&sensor,&ax,&ay,&bfx,&bfy);
776            if(icx<0 || icy<0)return false;
777        }
778        return true;
779    }
780    /**
781     * \brief Tracking method. It calls F77 mini routine.
782     *
783     * @param pfixed Particle momentum. If pfixed=0 the momentum
784     * is left as a free parameter, otherwise it is fixed to the input value.
785     * @param fail Output flag (!=0 if the fit failed).
786     * @param iprint Flag to set debug mode ( 0 = no output; 1 = verbose; 2 = debug).
787     * @param froml1 Flag to re-evaluate positions (see TrkTrack::GetClusterPositions()).
788     *
789     * The option to re-evaluate positions can be used only after recovering
790     * level1 information, eg. by reprocessing the single event.
791     *
792     * Example:
793     *
794     * if( !event->GetTrkLevel0() )return false;
795     * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1
796     * int fail=0;
797     * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1);
798     *
799     * @see EvaluateClusterPositions()
800     *
801     * The fitting procedure can be varied by changing the tracking mode,
802     * the fit-precision factor, the minimum number of step, etc.
803     * @see SetTrackingMode(int)
804     * @see SetPrecisionFactor(double)
805     * @see SetStepMin(int)
806     * @see SetDeltaB(int,double)
807     */
808    void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
809    
810        float al_ini[] = {0.,0.,0.,0.,0.};
811    
812        TrkParams::Load( );
813        if( !TrkParams::IsLoaded() )return;
814    
815        extern cMini2track track_;
816        fail = 0;
817    
818        FillMiniStruct(track_);
819            
820        if(froml1!=0){
821            if( !EvaluateClusterPositions() ){
822                cout << "void TrkTrack::Fit("<<pfixed<<","<<fail<<","<<iprint<<","<<froml1<<") --- ERROR evaluating cluster positions "<<endl;
823                FillMiniStruct(track_) ;
824                fail = 1;
825                return;
826            }
827        }else{
828            FillMiniStruct(track_);
829        }
830        
831        // if fit variables have been reset, evaluate the initial guess
832        if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
833    
834        // --------------------- free momentum
835        if(pfixed==0.) {
836            track_.pfixed=0.;
837        }
838        // --------------------- fixed momentum
839        if(pfixed!=0.) {
840            al[4]=1./pfixed;    
841            track_.pfixed=pfixed;
842        }
843    
844        //  store temporarily the initial guess
845        for(int i=0; i<5; i++) al_ini[i]=track_.al[i];
846    
847        //  ------------------------------------------
848        //  call mini routine
849    //     TrkParams::Load(1);
850    //     if( !TrkParams::IsLoaded(1) ){
851    //      cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl;
852    //      return;
853    //     }
854        int istep=0;
855        int ifail=0;
856        mini2_(&istep,&ifail, &iprint);
857        if(ifail!=0) {
858            if(iprint)cout << "ERROR: ifail= " << ifail << endl;
859            fail = 1;
860        }
861        //  ------------------------------------------
862        
863        SetFromMiniStruct(&track_);
864    
865        if(fail){
866            if(iprint)cout << " >>>> fit failed "<<endl;
867            for(int i=0; i<5; i++) al[i]=al_ini[i];
868        }
869    
870    };
871    /**
872     * Reset the fit parameters
873     */
874    void TrkTrack::FitReset(){
875        for(int i=0; i<5; i++) al[i]=-9999.;
876        chi2=0.;
877        nstep=0;
878    //     for(int i=0; i<6; i++) xv[i]=0.;
879    //     for(int i=0; i<6; i++) yv[i]=0.;
880    //     for(int i=0; i<6; i++) zv[i]=0.;
881    //     for(int i=0; i<6; i++) axv[i]=0.;
882    //     for(int i=0; i<6; i++) ayv[i]=0.;
883        for(int i=0; i<5; i++) {
884            for(int j=0; j<5; j++) coval[i][j]=0.;
885        }
886    }
887    /**
888     * Set the tracking mode
889     */
890    void TrkTrack::SetTrackingMode(int trackmode){
891        extern cMini2track track_;
892        track_.trackmode = trackmode;
893    }
894    /**
895     * Set the factor scale for tracking precision
896     */
897    void TrkTrack::SetPrecisionFactor(double fact){
898        extern cMini2track track_;
899        track_.fact = fact;
900    }
901    /**
902     * Set the minimum number of steps for tracking precision
903     */
904    void TrkTrack::SetStepMin(int istepmin){
905        extern cMini2track track_;
906        track_.istepmin = istepmin;
907    }
908    /**
909     * Set deltaB parameters (id=0,1). By default they are set to zero.
910     */
911    void TrkTrack::SetDeltaB(int id, double db){
912        if(id!=0 && id!=1)cout << "void TrkTrack::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl;
913        TrkParams::SetDeltaB(id,db);
914    }
915    
916    /**
917     * Returns true if the track is inside the magnet cavity.
918     * @param toll Tolerance around the nominal volume (toll>0 define an inner fiducial volume)
919     */
920    Bool_t TrkTrack::IsInsideCavity(float toll){
921    
922    //     float xmagntop, ymagntop, xmagnbottom, ymagnbottom;
923    //     xmagntop = xv[0] + (ZMAGNHIGH-zv[0])*tan(acos(-1.0)*axv[0]/180.);
924    //     ymagntop = yv[0] + (ZMAGNHIGH-zv[0])*tan(acos(-1.0)*ayv[0]/180.);
925    //     xmagnbottom = xv[5] + (ZMAGNLOW-zv[5])*tan(acos(-1.0)*axv[5]/180.);
926    //     ymagnbottom = yv[5] + (ZMAGNLOW-zv[5])*tan(acos(-1.0)*ayv[5]/180.);
927    //     if( xmagntop>XMAGNLOW && xmagntop<XMAGNHIGH &&
928    //      ymagntop>YMAGNLOW && ymagntop<YMAGNHIGH &&
929    //      xmagnbottom>XMAGNLOW && xmagnbottom<XMAGNHIGH &&
930    //      ymagnbottom>YMAGNLOW && ymagnbottom<YMAGNHIGH ) return(true);
931    //     else return(false);
932    
933        int ngf = TrkParams::nGF;
934        for(int i=0; i<ngf; i++){
935            //
936    //      cout << endl << TrkParams::GF_element[i];
937            if(
938                TrkParams::GF_element[i].CompareTo("CUF") &&
939                TrkParams::GF_element[i].CompareTo("T2")  &&
940                TrkParams::GF_element[i].CompareTo("T3")  &&
941                TrkParams::GF_element[i].CompareTo("T4")  &&
942                TrkParams::GF_element[i].CompareTo("T5")  &&
943                TrkParams::GF_element[i].CompareTo("CLF") &&
944                true)continue;
945            // apply condition only within the cavity
946    //      cout << " -- "<<xGF[i]<<" "<<yGF[i];
947            if(
948                xGF[i] <= TrkParams::xGF_min[i] + toll ||
949                xGF[i] >= TrkParams::xGF_max[i] - toll ||
950                yGF[i] <= TrkParams::yGF_min[i] + toll ||
951                yGF[i] >= TrkParams::yGF_max[i] - toll ||
952                false){
953                
954                return false;
955            }
956        }
957        return true;
958    
959    
960    }
961    /**
962     * Returns true if the track is inside the nominal acceptance, which is defined
963     * by the intersection among magnet cavity, silicon-plane sensitive area and
964     * ToF sensitive area (nominal values from the official document used to
965     * calculate the geometrical factor)
966     */
967    Bool_t TrkTrack::IsInsideAcceptance(){
968    
969        int ngf = TrkParams::nGF;
970        for(int i=0; i<ngf; i++){
971            if(
972                xGF[i] <= TrkParams::xGF_min[i] ||
973                xGF[i] >= TrkParams::xGF_max[i] ||
974                yGF[i] <= TrkParams::yGF_min[i] ||
975                yGF[i] >= TrkParams::yGF_max[i] ||
976                false)return false;
977        }
978        return true;
979    
980    }
981    /**
982     * Method to retrieve ID (0,1,...) of x-cluster (if any) associated to this track.
983     * If no cluster is associated, ID=-1.
984     * @param ip Tracker plane (0-5)
985     */
986    Int_t TrkTrack::GetClusterX_ID(int ip){
987        return ((Int_t)fabs(xgood[ip]))%10000000-1;
988    };
989    /**
990     * Method to retrieve ID (0-xxx) of y-cluster (if any) associated to this track.
991     * If no cluster is associated, ID=-1.
992     * @param ip Tracker plane (0-5)
993     */
994    Int_t TrkTrack::GetClusterY_ID(int ip){
995        return ((Int_t)fabs(ygood[ip]))%10000000-1;
996    };
997    
998    /**
999     * Method to retrieve the ladder (0-4, increasing x) traversed by the track on this plane.
1000     * If no ladder is traversed (dead area) the metod retuns -1.
1001     * @param ip Tracker plane (0-5)
1002     */
1003    Int_t TrkTrack::GetLadder(int ip){
1004        if(XGood(ip))return (Int_t)fabs(xgood[ip]/100000000)-1;
1005        if(YGood(ip))return (Int_t)fabs(ygood[ip]/100000000)-1;
1006        return -1;
1007    };
1008    /**
1009     * Method to retrieve the sensor (0-1, increasing y) traversed by the track on this plane.
1010     * If no sensor is traversed (dead area) the metod retuns -1.
1011     * @param ip Tracker plane (0-5)
1012     */
1013    Int_t TrkTrack::GetSensor(int ip){
1014        if(XGood(ip))return (Int_t)((Int_t)fabs(xgood[ip]/10000000)%10)-1;
1015        if(YGood(ip))return (Int_t)((Int_t)fabs(ygood[ip]/10000000)%10)-1;
1016        return -1;
1017    };
1018    
1019    /**
1020     * \brief Method to include a x-cluster to the track.
1021     * @param ip Tracker plane (0-5)
1022     * @param clid Cluster ID (0,1,...)
1023     * @param is Sensor (0-1, increasing y)
1024     * @see Fit(double pfixed, int& fail, int iprint, int froml1)
1025     */
1026    void TrkTrack::SetXGood(int ip, int clid, int is){
1027        int il=0;       //ladder (temporary)
1028        bool bad=false; //ladder (temporary)
1029        xgood[ip]=il*100000000+is*10000000+clid;
1030        if(bad)xgood[ip]=-xgood[ip];
1031    };
1032    /**
1033     * \brief Method to include a y-cluster to the track.
1034     * @param ip Tracker plane (0-5)
1035     * @param clid Cluster ID (0,1,...)
1036     * @param is Sensor (0-1)
1037     * @see Fit(double pfixed, int& fail, int iprint, int froml1)
1038     */
1039    void TrkTrack::SetYGood(int ip, int clid, int is){
1040        int il=0;       //ladder (temporary)
1041        bool bad=false; //ladder (temporary)
1042        ygood[ip]=il*100000000+is*10000000+clid;
1043        if(bad)ygood[ip]=-ygood[ip];
1044    };
1045    
1046    /**
1047     * \brief Average X
1048     * Average value of <xv>, evaluated from the first to the last hit x view.
1049     */
1050    Float_t TrkTrack::GetXav(){
1051    
1052        int first_plane = -1;
1053        int last_plane  = -1;
1054        for(Int_t ip=0; ip<6; ip++){
1055            if( XGood(ip) && first_plane == -1 )first_plane = ip;
1056            if( XGood(ip) && first_plane != -1 )last_plane = ip;
1057        }
1058        if( first_plane == -1 || last_plane == -1){
1059            return -100;
1060        }
1061        if( last_plane-first_plane+1 ==0 )return -100;
1062    
1063        Float_t av = 0;    
1064        for(int ip=first_plane; ip<=last_plane; ip++)av+=xv[ip];
1065        
1066        return (av/(last_plane-first_plane+1));    
1067    }
1068    /**
1069     * \brief Average Y
1070     * Average value of <yv>, evaluated from the first to the last hit x view.
1071     */
1072    Float_t TrkTrack::GetYav(){
1073    
1074        int first_plane = -1;
1075        int last_plane  = -1;
1076        for(Int_t ip=0; ip<6; ip++){
1077            if( XGood(ip) && first_plane == -1 )first_plane = ip;
1078            if( XGood(ip) && first_plane != -1 )last_plane = ip;
1079        }
1080        if( first_plane == -1 || last_plane == -1){
1081            return -100;
1082        }
1083        if( last_plane-first_plane+1 ==0 )return -100;
1084    
1085        Float_t av = 0;    
1086        for(int ip=first_plane; ip<=last_plane; ip++)av+=yv[ip];
1087    
1088        return (av/(last_plane-first_plane+1));    
1089    }
1090    /**
1091     * \brief Average Z
1092     * Average value of <zv>, evaluated from the first to the last hit x view.
1093     */
1094    Float_t TrkTrack::GetZav(){
1095    
1096        int first_plane = -1;
1097        int last_plane  = -1;
1098        for(Int_t ip=0; ip<6; ip++){
1099            if( XGood(ip) && first_plane == -1 )first_plane = ip;
1100            if( XGood(ip) && first_plane != -1 )last_plane = ip;
1101        }
1102        if( first_plane == -1 || last_plane == -1){
1103            return -100;
1104        }
1105        if( last_plane-first_plane+1 ==0 )return -100;
1106    
1107        Float_t av = 0;    
1108        for(int ip=first_plane; ip<=last_plane; ip++)av+=zv[ip];
1109        
1110        return (av/(last_plane-first_plane+1));    
1111    }
1112    
1113    /**
1114     * \brief Number of column traversed
1115     */
1116    Int_t TrkTrack::GetNColumns(){
1117        int sensors[] = {0,0,0,0,0,0};
1118        for(int ip=0; ip<6; ip++){
1119            int sensorid = GetLadder(ip)+3*GetSensor(ip);    
1120            if(XGood(ip)||YGood(ip))
1121                if(sensorid>=0 && sensorid<6)sensors[sensorid]=1;
1122        }
1123        int nsensors=0;
1124        for(int is=0; is<6; is++)nsensors += sensors[is];
1125        return nsensors;
1126    };
1127    /**
1128     * \brief Give the maximum energy release
1129     */
1130    Float_t TrkTrack::GetDEDX_max(int ip, int iv){
1131        Float_t max=0;
1132        int pfrom = 0;
1133        int pto   = 6;
1134        int vfrom = 0;
1135        int vto   = 2;
1136        if(ip>=0&&ip<6){
1137            pfrom = ip;
1138            pto   = ip+1;
1139        }
1140        if(iv>=0&&iv<2){
1141            vfrom = iv;
1142            vto   = iv+1;
1143        }
1144        for(int i=pfrom; i<pto; i++)
1145            for(int j=0; j<vto; j++)
1146                if(GetDEDX(i,j)>max)max=GetDEDX(i,j);
1147    
1148        return max;
1149    
1150    };
1151    
1152    /**
1153     * \brief Give the minimum energy release
1154     */
1155    Float_t TrkTrack::GetDEDX_min(int ip, int iv){
1156        Float_t min=100000000;
1157        int pfrom = 0;
1158        int pto   = 6;
1159        int vfrom = 0;
1160        int vto   = 2;
1161        if(ip>=0&&ip<6){
1162            pfrom = ip;
1163            pto   = ip+1;
1164        }
1165        if(iv>=0&&iv<2){
1166            vfrom = iv;
1167            vto   = iv+1;
1168        }
1169        for(int i=pfrom; i<pto; i++)
1170            for(int j=0; j<vto; j++)
1171                if(GetDEDX(i,j)<min)min=GetDEDX(i,j);
1172    
1173        return min;
1174    
1175    };
1176    
1177    /**
1178     * \brief Give the maximum spatial residual release
1179     */
1180    Float_t TrkTrack::GetResidual_max(int ip, int iv){
1181        Float_t max=0;
1182        int pfrom = 0;
1183        int pto   = 6;
1184        int vfrom = 0;
1185        int vto   = 2;
1186        if(ip>=0&&ip<6){
1187            pfrom = ip;
1188            pto   = ip+1;
1189        }
1190        if(iv>=0&&iv<2){
1191            vfrom = iv;
1192            vto   = iv+1;
1193        }
1194        for(int i=pfrom; i<pto; i++){
1195            for(int j=0; j<vto; j++){
1196                if(j==0 && XGood(i) && fabs(xm[i]-xv[i])>fabs(max))max=xv[i]-xm[i];
1197                if(j==1 && YGood(i) && fabs(ym[i]-yv[i])>fabs(max))max=yv[i]-ym[i];
1198            }
1199        }
1200        return max;
1201    
1202    };
1203    
1204    
1205    /**
1206     * \brief Give the maximum multiplicity on the x view
1207     */
1208    Int_t TrkTrack::GetClusterX_Multiplicity_max(){
1209        int max=0;
1210        for(int ip=0; ip<6; ip++)
1211            if(GetClusterX_Multiplicity(ip)>max)max=GetClusterX_Multiplicity(ip);
1212        return max;
1213    };
1214    /**
1215     * \brief Give the minimum multiplicity on the x view
1216     */
1217    Int_t TrkTrack::GetClusterX_Multiplicity_min(){
1218        int min=50;
1219        for(int ip=0; ip<6; ip++)
1220            if(GetClusterX_Multiplicity(ip)<min)min=GetClusterX_Multiplicity(ip);
1221        return min;
1222    };
1223    /**
1224     * \brief Give the maximum multiplicity on the x view
1225     */
1226    Int_t TrkTrack::GetClusterY_Multiplicity_max(){
1227        int max=0;
1228        for(int ip=0; ip<6; ip++)
1229            if(GetClusterY_Multiplicity(ip)>max)max=GetClusterY_Multiplicity(ip);
1230        return max;
1231    };
1232    /**
1233     * \brief Give the minimum multiplicity on the x view
1234     */
1235    Int_t TrkTrack::GetClusterY_Multiplicity_min(){
1236        int min=50;
1237        for(int ip=0; ip<6; ip++)
1238            if(GetClusterY_Multiplicity(ip)<min)min=GetClusterY_Multiplicity(ip);
1239        return min;
1240    };
1241    
1242    /**
1243     * \brief Give the minimum seed on the x view
1244     */
1245    Float_t TrkTrack::GetClusterX_Seed_min(){
1246        Float_t min=100000;
1247        for(int ip=0; ip<6; ip++)
1248            if(XGood(ip) && GetClusterX_Seed(ip)<min)min=GetClusterX_Seed(ip);
1249        return min;
1250    };
1251    /**
1252     * \brief Give the minimum seed on the x view
1253     */
1254    Float_t TrkTrack::GetClusterY_Seed_min(){
1255        Float_t min=100000;
1256        for(int ip=0; ip<6; ip++)
1257            if(YGood(ip) && GetClusterY_Seed(ip)<min)min=GetClusterY_Seed(ip);
1258        return min;
1259    };
1260    
1261    
1262    //--------------------------------------
1263    //
1264    //
1265    //--------------------------------------
1266    void TrkTrack::Clear(){
1267    //    cout << "TrkTrack::Clear()"<<endl;
1268        seqno = -1;
1269        image = -1;
1270        chi2  = 0;
1271        nstep = 0;
1272        for(int it1=0;it1<5;it1++){
1273            al[it1] = 0;
1274            for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
1275        };
1276        for(int ip=0;ip<6;ip++){
1277            xgood[ip]  = 0;
1278            ygood[ip]  = 0;
1279            xm[ip]     = 0;
1280            ym[ip]     = 0;
1281            zm[ip]     = 0;
1282            resx[ip]   = 0;
1283            resy[ip]   = 0;
1284            tailx[ip]  = 0;
1285            taily[ip]  = 0;
1286            xv[ip]     = 0;
1287            yv[ip]     = 0;
1288            zv[ip]     = 0;
1289            axv[ip]    = 0;
1290            ayv[ip]    = 0;
1291            dedx_x[ip] = 0;
1292            dedx_y[ip] = 0;
1293    
1294        };
1295        int ngf = TrkParams::nGF;
1296        for(int i=0; i<ngf; i++){
1297            xGF[i] = 0.;
1298            yGF[i] = 0.;
1299        }
1300    //     if(clx)clx->Clear();
1301    //     if(cly)cly->Clear();
1302    //    clx.Clear();
1303    //    cly.Clear();
1304    };
1305    //--------------------------------------
1306    //
1307    //
1308    //--------------------------------------
1309    void TrkTrack::Delete(){
1310    //    cout << "TrkTrack::Delete()"<<endl;
1311        Clear();
1312    //    if(clx)delete clx;
1313    //    if(cly)delete cly;
1314    };
1315    //--------------------------------------
1316    //
1317    //
1318    //--------------------------------------
1319    
1320  //--------------------------------------  //--------------------------------------
1321  //  //
1322  //  //
1323  //--------------------------------------  //--------------------------------------
1324  TrkSinglet::TrkSinglet(){  TrkSinglet::TrkSinglet(){
1325      plane    = 0;  //    cout << "TrkSinglet::TrkSinglet() " << GetUniqueID()<<endl;
1326      coord[0] = 0;  //     plane    = 0;
1327      coord[1] = 0;  //     coord[0] = 0;
1328      sgnl     = 0;  //     coord[1] = 0;
1329    //     sgnl     = 0;
1330    //     multmax  = 0;
1331    //    cls      = 0;
1332        Clear();
1333  };  };
1334  //--------------------------------------  //--------------------------------------
1335  //  //
1336  //  //
1337  //--------------------------------------  //--------------------------------------
1338  TrkSinglet::TrkSinglet(const TrkSinglet& s){  TrkSinglet::TrkSinglet(const TrkSinglet& s){
1339    //    cout << "TrkSinglet::TrkSinglet(const TrkSinglet& s) " << GetUniqueID()<<endl;
1340      plane    = s.plane;      plane    = s.plane;
1341      coord[0] = s.coord[0];      coord[0] = s.coord[0];
1342      coord[1] = s.coord[1];      coord[1] = s.coord[1];
1343      sgnl     = s.sgnl;      sgnl     = s.sgnl;
1344        multmax  = s.multmax;
1345    //      cls      = 0;//<<<<pointer
1346    //    cls      = TRef(s.cls);
1347  };  };
1348  //--------------------------------------  //--------------------------------------
1349  //  //
# Line 224  TrkSinglet::TrkSinglet(const TrkSinglet& Line 1352  TrkSinglet::TrkSinglet(const TrkSinglet&
1352  void TrkSinglet::Dump(){  void TrkSinglet::Dump(){
1353      int i=0;      int i=0;
1354      cout << endl << "========== Singlet " ;      cout << endl << "========== Singlet " ;
1355      cout << endl << "plane    : " << plane;      cout << endl << "plane        : " << plane;
1356      cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++;      cout << endl << "coord[2]     : "; while( i<2 && cout << coord[i] << " ") i++;
1357      cout << endl << "sgnl     : " << sgnl;      cout << endl << "sgnl         : " << sgnl;
1358        cout << endl << "max.strip    : ";
1359        cout << endl << "multiplicity : ";
1360    }
1361    //--------------------------------------
1362    //
1363    //
1364    //--------------------------------------
1365    void TrkSinglet::Clear(){
1366    //    cout << "TrkSinglet::Clear() " << GetUniqueID()<<endl;
1367    //    cls=0;
1368        plane=-1;
1369        coord[0]=-999;
1370        coord[1]=-999;
1371        sgnl=0;
1372        multmax  = 0;
1373        
1374  }  }
1375  //--------------------------------------  //--------------------------------------
1376  //  //
1377  //  //
1378  //--------------------------------------  //--------------------------------------
1379  TrkLevel2::TrkLevel2(){  TrkLevel2::TrkLevel2(){
1380      good2    = -1;    //    cout <<"TrkLevel2::TrkLevel2()"<<endl;
1381      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1382          crc[i] = -1;          good[i] = -1;
1383            VKmask[i] = 0;
1384            VKflag[i] = 0;  
1385      };      };
1386      Track    = new TClonesArray("TrkTrack");      Track    = 0;
1387      SingletX = new TClonesArray("TrkSinglet");      SingletX = 0;
1388      SingletY = new TClonesArray("TrkSinglet");      SingletY = 0;
1389  //    Track    = 0;  
1390  //    Singlet = 0;  }
1391  //    SingletY = 0;  //--------------------------------------
1392    //
1393    //
1394    //--------------------------------------
1395    void TrkLevel2::Set(){
1396        if(!Track)Track    = new TClonesArray("TrkTrack");
1397        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1398        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1399  }  }
1400  //--------------------------------------  //--------------------------------------
1401  //  //
1402  //  //
1403  //--------------------------------------  //--------------------------------------
1404  void TrkLevel2::Dump(){  void TrkLevel2::Dump(){
1405      TClonesArray &t  = *Track;          
1406      TClonesArray &sx = *SingletX;          //
     TClonesArray &sy = *SingletY;  
   
1407      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
1408      cout << endl << "good2    : " << good2;      cout << endl << "good     : "; for(int i=0; i<12; i++) cout << hex <<" 0x"<< good[i]<<dec;
1409      cout << endl << "crc      : "; for(int i=0; i<12; i++) cout << crc[i];      cout << endl << "ntrk()   : " << ntrk() ;
1410      cout << endl << "ntrk()   : " << this->ntrk() ;      cout << endl << "nclsx()  : " << nclsx();
1411      cout << endl << "nclsx()  : " << this->nclsx();      cout << endl << "nclsy()  : " << nclsy();
1412      cout << endl << "nclsy()  : " << this->nclsy();      if(Track){
1413      for(int i=0; i<this->ntrk(); i++)     ((TrkTrack *)t[i])->Dump();          TClonesArray &t  = *Track;
1414      for(int i=0; i<this->nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();          for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();
1415      for(int i=0; i<this->nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();      }      
1416    //     if(SingletX){
1417    //      TClonesArray &sx = *SingletX;
1418    //      for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
1419    //     }
1420    //     if(SingletY){
1421    //      TClonesArray &sy = *SingletY;
1422    //      for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
1423    //     }
1424        cout << endl;
1425    }
1426    /**
1427     * \brief Dump processing status
1428     */
1429    void TrkLevel2::StatusDump(int view){
1430        cout << "DSP n. "<<view+1<<" status: "<<hex<<good[view]<<endl;    
1431    };
1432    /**
1433     * \brief Check event status
1434     *
1435     * Check the event status, according to a flag-mask given as input.
1436     * Return true if the view passes the check.
1437     *
1438     * @param view View number (0-11)
1439     * @param flagmask Mask of flags to check (eg. flagmask=0x111 no missing packet,
1440     *  no crc error, no software alarm)
1441     *
1442     * @see TrkLevel2 class definition to know how the status flag is defined
1443     *
1444     */
1445    Bool_t TrkLevel2::StatusCheck(int view, int flagmask){
1446    
1447        if( view<0 || view >= 12)return false;
1448        return !(good[view]&flagmask);
1449    
1450    };
1451    
1452    
1453    //--------------------------------------
1454    //
1455    //
1456    //--------------------------------------
1457    /**
1458     * The method returns false if the viking-chip was masked  
1459     * either apriori ,on the basis of the mask read from the DB,
1460     * or run-by-run, on the basis of the calibration parameters)
1461     * @param iv Tracker view (0-11)
1462     * @param ivk Viking-chip number (0-23)
1463     */
1464    Bool_t TrkLevel2::GetVKMask(int iv, int ivk){
1465        Int_t whichbit = (Int_t)pow(2,ivk);
1466        return (whichbit&VKmask[iv])!=0;    
1467  }  }
1468    /**
1469     * The method returns false if the viking-chip was masked  
1470     * for this event due to common-noise computation failure.
1471     * @param iv Tracker view (0-11)
1472     * @param ivk Viking-chip number (0-23)
1473     */
1474    Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){
1475        Int_t whichbit = (Int_t)pow(2,ivk);
1476        return (whichbit&VKflag[iv])!=0;    
1477    }
1478    /**
1479     * The method returns true if the viking-chip was masked, either
1480     * forced (see TrkLevel2::GetVKMask(int,int)) or
1481     * for this event only (TrkLevel2::GetVKFlag(int,int)).
1482     * @param iv Tracker view (0-11)
1483     * @param ivk Viking-chip number (0-23)
1484     */
1485    Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){
1486        return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) );
1487    };
1488    
1489  //--------------------------------------  //--------------------------------------
1490  //  //
1491  //  //
1492  //--------------------------------------  //--------------------------------------
1493  /**  /**
1494   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
1495     * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set.
1496     * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch)
1497   */   */
1498  void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
1499      //  
1500  //    Track    = new TClonesArray("TrkTrack");  //    cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl;
1501  //    SingletX = new TClonesArray("TrkSinglet");      Clear();
1502  //    SingletY = new TClonesArray("TrkSinglet");  
1503  //  temporary objects:  //  temporary objects:
1504      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
1505      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
1506    
1507    //  -----------------
1508  //  general variables  //  general variables
1509      good2 = l2->good2;  //  -----------------
1510      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1511          crc[i] = l2->crc[i];          good[i] = l2->good[i];
1512            VKmask[i]=0;
1513            VKflag[i]=0;
1514            for(Int_t ii=0; ii<24 ; ii++){
1515                Int_t setbit = (Int_t)pow(2,ii);
1516                if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit;
1517                if( l2->vkflag[ii][i]!=0  )VKflag[i]=VKflag[i]|setbit;
1518            };
1519      };      };
1520    //  --------------
1521  //  *** TRACKS ***  //  *** TRACKS ***
1522    //  --------------
1523        if(!Track) Track = new TClonesArray("TrkTrack");
1524      TClonesArray &t = *Track;      TClonesArray &t = *Track;
1525    
1526      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
1527          t_track->seqno = i;          t_track->seqno = i;// NBNBNBNB deve sempre essere = i
1528          t_track->image = l2->image[i]-1;          t_track->image = l2->image[i]-1;
 //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;  
1529          t_track->chi2  = l2->chi2_nt[i];          t_track->chi2  = l2->chi2_nt[i];
1530            t_track->nstep = l2->nstep_nt[i];
1531          for(int it1=0;it1<5;it1++){          for(int it1=0;it1<5;it1++){
1532              t_track->al[it1] = l2->al_nt[i][it1];              t_track->al[it1] = l2->al_nt[i][it1];
1533              for(int it2=0;it2<5;it2++)              for(int it2=0;it2<5;it2++)
1534                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];
1535          };          };
1536          for(int ip=0;ip<6;ip++){          for(int ip=0;ip<6;ip++){
1537              t_track->xgood[ip]  = l2->xgood_nt[i][ip];              // ---------------------------------
1538              t_track->ygood[ip]  = l2->ygood_nt[i][ip];              // new implementation of xgood/ygood
1539                // ---------------------------------
1540                t_track->xgood[ip]  = l2->cltrx[i][ip]; //cluster ID
1541                t_track->ygood[ip]  = l2->cltry[i][ip]; //cluster ID
1542                t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1543                t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1544                if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip];
1545                if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip];
1546    //          if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){
1547    //          if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){
1548    //              cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl;
1549    //              cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl;
1550    //              cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl;
1551    //              cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl;
1552    //              cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl;
1553    //          }
1554              t_track->xm[ip]     = l2->xm_nt[i][ip];              t_track->xm[ip]     = l2->xm_nt[i][ip];
1555              t_track->ym[ip]     = l2->ym_nt[i][ip];              t_track->ym[ip]     = l2->ym_nt[i][ip];
1556              t_track->zm[ip]     = l2->zm_nt[i][ip];              t_track->zm[ip]     = l2->zm_nt[i][ip];
1557              t_track->resx[ip]   = l2->resx_nt[i][ip];              t_track->resx[ip]   = l2->resx_nt[i][ip];
1558              t_track->resy[ip]   = l2->resy_nt[i][ip];              t_track->resy[ip]   = l2->resy_nt[i][ip];
1559                t_track->tailx[ip]  = l2->tailx[i][ip];
1560                t_track->taily[ip]  = l2->taily[i][ip];
1561              t_track->xv[ip]     = l2->xv_nt[i][ip];              t_track->xv[ip]     = l2->xv_nt[i][ip];
1562              t_track->yv[ip]     = l2->yv_nt[i][ip];              t_track->yv[ip]     = l2->yv_nt[i][ip];
1563              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 1565  void TrkLevel2::FillCommonVar(cTrkLevel2
1565              t_track->ayv[ip]    = l2->ayv_nt[i][ip];              t_track->ayv[ip]    = l2->ayv_nt[i][ip];
1566              t_track->dedx_x[ip] = l2->dedx_x[i][ip];              t_track->dedx_x[ip] = l2->dedx_x[i][ip];
1567              t_track->dedx_y[ip] = l2->dedx_y[i][ip];              t_track->dedx_y[ip] = l2->dedx_y[i][ip];
1568                t_track->multmaxx[ip] = l2->multmaxx[i][ip];
1569                t_track->multmaxy[ip] = l2->multmaxy[i][ip];
1570                t_track->seedx[ip]  = l2->seedx[i][ip];  
1571                t_track->seedy[ip]  = l2->seedy[i][ip];
1572                t_track->xpu[ip]    = l2->xpu[i][ip];  
1573                t_track->ypu[ip]    = l2->ypu[i][ip];  
1574                //-----------------------------------------------------
1575                //-----------------------------------------------------
1576                //-----------------------------------------------------
1577                //-----------------------------------------------------
1578          };          };
1579            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1580            // evaluated coordinates (to define GF)
1581            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1582            int    ngf = TrkParams::nGF;
1583            float *zgf = TrkParams::zGF;
1584            Trajectory tgf = Trajectory(ngf,zgf);
1585            tgf.DoTrack2(t_track->al);//<<<< integrate the trajectory
1586            for(int ip=0; ip<ngf; ip++){
1587                t_track->xGF[ip] = tgf.x[ip];
1588                t_track->yGF[ip] = tgf.y[ip];
1589            }
1590            
1591    //      if(t_track->IsSaturated())t_track->Dump();
1592          new(t[i]) TrkTrack(*t_track);          new(t[i]) TrkTrack(*t_track);
1593          t_track->Clear();          t_track->Clear();
1594      };      };//end loop over track
1595    
1596    //  ----------------
1597  //  *** SINGLETS ***  //  *** SINGLETS ***
1598    //  ----------------
1599        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1600      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
1601      for(int i=0; i<l2->nclsx; i++){      for(int i=0; i<l2->nclsx; i++){
1602          t_singlet->plane    = l2->planex[i];          t_singlet->plane    = l2->planex[i];
1603          t_singlet->coord[0] = l2->xs[i][0];          t_singlet->coord[0] = l2->xs[i][0];
1604          t_singlet->coord[1] = l2->xs[i][1];          t_singlet->coord[1] = l2->xs[i][1];
1605          t_singlet->sgnl     = l2->signlxs[i];          t_singlet->sgnl     = l2->signlxs[i];
1606            t_singlet->multmax = l2->multmaxsx[i];
1607            if(l2->sxbad[i]>0) t_singlet->multmax = -1*t_singlet->multmax;
1608            //-----------------------------------------------------
1609    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);
1610            //-----------------------------------------------------
1611          new(sx[i]) TrkSinglet(*t_singlet);          new(sx[i]) TrkSinglet(*t_singlet);
1612          t_singlet->Clear();          t_singlet->Clear();
1613      }      }
1614        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1615      TClonesArray &sy = *SingletY;      TClonesArray &sy = *SingletY;
1616      for(int i=0; i<l2->nclsy; i++){      for(int i=0; i<l2->nclsy; i++){
1617          t_singlet->plane    = l2->planey[i];          t_singlet->plane    = l2->planey[i];
1618          t_singlet->coord[0] = l2->ys[i][0];          t_singlet->coord[0] = l2->ys[i][0];
1619          t_singlet->coord[1] = l2->ys[i][1];          t_singlet->coord[1] = l2->ys[i][1];
1620          t_singlet->sgnl     = l2->signlys[i];          t_singlet->sgnl     = l2->signlys[i];
1621            t_singlet->multmax  = l2->multmaxsy[i];
1622            if(l2->sybad[i]>0) t_singlet->multmax = -1*t_singlet->multmax;
1623            //-----------------------------------------------------
1624    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);
1625            //-----------------------------------------------------
1626          new(sy[i]) TrkSinglet(*t_singlet);          new(sy[i]) TrkSinglet(*t_singlet);
1627          t_singlet->Clear();          t_singlet->Clear();
1628          };      };
1629    
1630    
1631            
1632        delete t_track;
1633        delete t_singlet;
1634    }
1635    /**
1636     * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
1637     */
1638    
1639    void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
1640      
1641    //  general variables
1642    //    l2->good2 = good2 ;
1643        for(Int_t i=0; i<12 ; i++){
1644    //      l2->crc[i] = crc[i];
1645                    l2->good[i] = good[i];
1646        };
1647    //  *** TRACKS ***
1648    
1649        if(Track){
1650            l2->ntrk              =  Track->GetEntries();    
1651            for(Int_t i=0;i<l2->ntrk;i++){
1652                l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
1653                l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;
1654                l2->nstep_nt[i] =  ((TrkTrack *)Track->At(i))->nstep;
1655                for(int it1=0;it1<5;it1++){
1656                    l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
1657                    for(int it2=0;it2<5;it2++)
1658                        l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
1659                };
1660                for(int ip=0;ip<6;ip++){
1661                    l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip);
1662                    l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip);
1663                    l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];
1664                    l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];
1665                    l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];
1666                    l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];
1667                    l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];
1668                    l2->tailx[i][ip]  = ((TrkTrack *)Track->At(i))->tailx[ip];
1669                    l2->taily[i][ip]  = ((TrkTrack *)Track->At(i))->taily[ip];
1670                    l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];
1671                    l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];
1672                    l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];
1673                    l2->axv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->axv[ip];
1674                    l2->ayv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->ayv[ip];
1675                    l2->dedx_x[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_x[ip];
1676                    l2->dedx_y[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_y[ip];
1677                };
1678            }
1679        }
1680    //  *** SINGLETS ***    
1681        if(SingletX){
1682            l2->nclsx              = SingletX->GetEntries();
1683            for(Int_t i=0;i<l2->nclsx;i++){
1684                l2->planex[i]  = ((TrkSinglet *)SingletX->At(i))->plane;
1685                l2->xs[i][0]   = ((TrkSinglet *)SingletX->At(i))->coord[0];
1686                l2->xs[i][1]   = ((TrkSinglet *)SingletX->At(i))->coord[1];
1687                l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
1688            }
1689        }
1690    
1691        if(SingletY){
1692            l2->nclsy              = SingletY->GetEntries();
1693            for(Int_t i=0;i<l2->nclsy;i++){
1694                l2->planey[i]  = ((TrkSinglet *)SingletY->At(i))->plane;
1695                l2->ys[i][0]   = ((TrkSinglet *)SingletY->At(i))->coord[0];
1696                l2->ys[i][1]   = ((TrkSinglet *)SingletY->At(i))->coord[1];
1697                l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
1698            }
1699        }
1700  }  }
1701  //--------------------------------------  //--------------------------------------
1702  //  //
1703  //  //
1704  //--------------------------------------  //--------------------------------------
1705  void TrkLevel2::Clear(){  void TrkLevel2::Clear(){
     good2    = -1;  
1706      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1707          crc[i] = -1;          good[i] = -1;
1708            VKflag[i] = 0;
1709            VKmask[i] = 0;
1710      };      };
1711      Track->RemoveAll();  //    if(Track)Track->Clear("C");
1712      SingletX->RemoveAll();  //    if(SingletX)SingletX->Clear("C");
1713      SingletY->RemoveAll();  //    if(SingletY)SingletY->Clear("C");
1714        if(Track)Track->Delete();
1715        if(SingletX)SingletX->Delete();
1716        if(SingletY)SingletY->Delete();
1717    }
1718    // //--------------------------------------
1719    // //
1720    // //
1721    // //--------------------------------------
1722    void TrkLevel2::Delete(){
1723            
1724    //    cout << "void TrkLevel2::Delete()"<<endl;
1725        Clear();
1726        if(Track)delete Track;
1727        if(SingletX)delete SingletX;
1728        if(SingletY)delete SingletY;
1729    
1730  }  }
1731  //--------------------------------------  //--------------------------------------
1732  //  //
# Line 355  void TrkLevel2::Clear(){ Line 1736  void TrkLevel2::Clear(){
1736   * 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).
1737   * 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.
1738   */   */
1739  TClonesArray *TrkLevel2::GetTracks(){  TRefArray *TrkLevel2::GetTracks_NFitSorted(){
     TClonesArray *sorted = GetTracks_NFitSorted();  
     return sorted;  
 };  
 TClonesArray *TrkLevel2::GetTracks_Chi2Sorted(){  
1740    
1741      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;  
   
     int indo=0;  
     int indi=0;  
     while(N != 0){  
         float chi2ref=1000000;  
         for(int i=0; i<this->ntrk(); i++){  
             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(){  
1742    
1743      TClonesArray *sorted = new TClonesArray("TrkTrack");      TRefArray *sorted = new TRefArray();
1744      TClonesArray &t = *Track;          
1745      TClonesArray &ts = *sorted;      TClonesArray &t  = *Track;
1746      int N=this->ntrk();  //    TClonesArray &ts = *PhysicalTrack;
1747        int N = ntrk();
1748      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;
1749    //      int m[50]; for(int i=0; i<N; i++)m[i]=1;
1750            
1751      int indo=0;      int indo=0;
1752      int indi=0;      int indi=0;
1753      while(N != 0){      while(N > 0){
1754    //    while(N != 0){
1755          int nfit =0;          int nfit =0;
1756          float chi2ref=1000000;          float chi2ref = numeric_limits<float>::max();
1757                    
1758          // first loop to search maximum num. of fit points          // first loop to search maximum num. of fit points
1759          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i < ntrk(); i++){
1760              if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){              if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
1761                  nfit =    ((TrkTrack *)t[i])->GetNtot();                  nfit =    ((TrkTrack *)t[i])->GetNtot();
 //              cout << "1** "<<i<< " " << nfit<<endl;  
1762              }              }
1763          }          }
1764          //second loop to search minimum chi2 among selected          //second loop to search minimum chi2 among selected
1765          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i<ntrk(); i++){
1766              if(    ((TrkTrack *)t[i])->chi2 < chi2ref              Float_t chi2 = ((TrkTrack *)t[i])->chi2;
1767                  && ((TrkTrack *)t[i])->GetNtot()== nfit              if(chi2 < 0) chi2 = -chi2*1000;
1768                  && m[i]==1){              if(    chi2 < chi2ref
1769                       && ((TrkTrack *)t[i])->GetNtot() == nfit
1770                       && m[i]==1){
1771                  chi2ref = ((TrkTrack *)t[i])->chi2;                  chi2ref = ((TrkTrack *)t[i])->chi2;
1772                  indi = i;                  indi = i;
1773  //              cout << "2** "<<i<< " " << nfit <<" "<<chi2ref<<endl;              };
1774              }          };
         }  
1775          if( ((TrkTrack *)t[indi])->HasImage() ){          if( ((TrkTrack *)t[indi])->HasImage() ){
1776              m[((TrkTrack *)t[indi])->image] = 0;              m[((TrkTrack *)t[indi])->image] = 0;
1777              N--;              N--;
1778            
 //          Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->GetNtot();  
 //          Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->chi2;  
                   
1779  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1780          }          };
1781          new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);          sorted->Add( (TrkTrack*)t[indi] );      
1782                    
1783          m[indi] = 0;          m[indi] = 0;
1784    //      cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl;
1785          N--;              N--;    
1786          indo++;          indo++;
1787      }      }
1788        m.clear();
1789    //    cout << "GetTracks_NFitSorted(it): Done"<< endl;
1790    
1791      return sorted;      return sorted;
1792    //    return PhysicalTrack;
1793  }  }
1794  //--------------------------------------  //--------------------------------------
1795  //  //
# Line 446  TClonesArray *TrkLevel2::GetTracks_NFitS Line 1803  TClonesArray *TrkLevel2::GetTracks_NFitS
1803  TrkTrack *TrkLevel2::GetStoredTrack(int is){  TrkTrack *TrkLevel2::GetStoredTrack(int is){
1804    
1805      if(is >= this->ntrk()){      if(is >= this->ntrk()){
1806          cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl;          cout << "TrkTrack *TrkLevel2::GetStoredTrack(int) >> Track "<< is << "doen not exits! " << endl;
1807          cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl;          cout << "Stored tracks ntrk() = "<< this->ntrk() << endl;
1808          return 0;          return 0;
1809      }      }
1810        if(!Track){
1811            cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (TClonesArray*) Track ==0 "<<endl;
1812        };
1813      TClonesArray &t = *(Track);      TClonesArray &t = *(Track);
1814      TrkTrack *track = (TrkTrack*)t[is];      TrkTrack *track = (TrkTrack*)t[is];
1815      return track;      return track;
# Line 459  TrkTrack *TrkLevel2::GetStoredTrack(int Line 1819  TrkTrack *TrkLevel2::GetStoredTrack(int
1819  //  //
1820  //--------------------------------------  //--------------------------------------
1821  /**  /**
1822     * Retrieves the is-th stored X singlet.
1823     * @param it Singlet number, ranging from 0 to nclsx().
1824     */
1825    TrkSinglet *TrkLevel2::GetSingletX(int is){
1826    
1827            if(is >= this->nclsx()){
1828                    cout << "TrkSinglet *TrkLevel2::GetSingletX(int) >> Singlet "<< is << "doen not exits! " << endl;
1829                    cout << "Stored x-singlets nclsx() = "<< this->nclsx() << endl;
1830                    return 0;
1831            }
1832            if(!SingletX)return 0;
1833            TClonesArray &t = *(SingletX);
1834            TrkSinglet *singlet = (TrkSinglet*)t[is];
1835            return singlet;
1836    }
1837    //--------------------------------------
1838    //
1839    //
1840    //--------------------------------------
1841    /**
1842     * Retrieves the is-th stored Y singlet.
1843     * @param it Singlet number, ranging from 0 to nclsx().
1844     */
1845    TrkSinglet *TrkLevel2::GetSingletY(int is){
1846    
1847            if(is >= this->nclsy()){
1848                    cout << "TrkSinglet *TrkLevel2::GetSingletY(int) >> Singlet "<< is << "doen not exits! " << endl;
1849                    cout << "Stored y-singlets nclsx() = "<< this->nclsx() << endl;
1850                    return 0;
1851            }
1852            if(!SingletY)return 0;
1853            TClonesArray &t = *(SingletY);
1854            TrkSinglet *singlet = (TrkSinglet*)t[is];
1855            return singlet;
1856    }
1857    //--------------------------------------
1858    //
1859    //
1860    //--------------------------------------
1861    /**
1862   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
1863   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1864   */   */
1865    
1866  TrkTrack *TrkLevel2::GetTrack(int it){  TrkTrack *TrkLevel2::GetTrack(int it){
1867            
1868      if(it >= this->GetNTracks()){          if(it >= this->GetNTracks()){
1869          cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;                  cout << "TrkTrack *TrkLevel2::GetTrack(int) >> Track "<< it << "does not exits! " << endl;
1870          cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;                  cout << "Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1871          return 0;                  return 0;
1872      }          }
1873      TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];          
1874      return track;          TRefArray *sorted = GetTracks();  //TEMPORANEO  
1875            if(!sorted)return 0;
1876            TrkTrack *track = (TrkTrack*)sorted->At(it);
1877            sorted->Clear();
1878            delete sorted;
1879            return track;
1880  }  }
1881    /**
1882     * Give the number of "physical" tracks, sorted by the method GetTracks().
1883     */
1884    Int_t TrkLevel2::GetNTracks(){
1885                    
1886            Float_t ntot=0;
1887            if(!Track)return 0;
1888            TClonesArray &t = *Track;
1889            for(int i=0; i<ntrk(); i++) {    
1890                    if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
1891                    else ntot+=0.5;
1892            }
1893            return (Int_t)ntot;
1894    
1895    };
1896  //--------------------------------------  //--------------------------------------
1897  //  //
1898  //  //
# Line 483  TrkTrack *TrkLevel2::GetTrack(int it){ Line 1904  TrkTrack *TrkLevel2::GetTrack(int it){
1904  TrkTrack *TrkLevel2::GetTrackImage(int it){  TrkTrack *TrkLevel2::GetTrackImage(int it){
1905    
1906      if(it >= this->GetNTracks()){      if(it >= this->GetNTracks()){
1907          cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;          cout << "TrkTrack *TrkLevel2::GetTrackImage(int) >> Track "<< it << "does not exits! " << endl;
1908          cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;          cout << "Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1909          return 0;          return 0;
1910      }      }
1911      TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];          
1912        TRefArray* sorted = GetTracks(); //TEMPORANEO
1913        if(!sorted)return 0;
1914        TrkTrack *track = (TrkTrack*)sorted->At(it);
1915            
1916      if(!track->HasImage()){      if(!track->HasImage()){
1917          cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;          cout << "TrkTrack *TrkLevel2::GetTrackImage(int) >> Track "<< it << "does not have image! " << endl;
1918          return 0;          return 0;
1919      }      }
1920        if(!Track)return 0;
1921      TrkTrack *image = (TrkTrack*)(*Track)[track->image];      TrkTrack *image = (TrkTrack*)(*Track)[track->image];
1922    
1923        sorted->Delete();
1924        delete sorted;
1925    
1926      return image;      return image;
1927            
1928  }  }
# Line 504  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1934  TrkTrack *TrkLevel2::GetTrackImage(int i
1934   * Loads the magnetic field.   * Loads the magnetic field.
1935   * @param s Path of the magnetic-field files.   * @param s Path of the magnetic-field files.
1936   */   */
1937  void TrkLevel2::LoadField(TString s){  void TrkLevel2::LoadField(TString path){
1938      readb_(s.Data());  //
1939    //     strcpy(path_.path,path.Data());
1940    //     path_.pathlen = path.Length();
1941    //     path_.error   = 0;
1942    //     readb_();
1943    
1944    //     TrkParams::SetTrackingMode();
1945    //     TrkParams::SetPrecisionFactor();
1946    //     TrkParams::SetStepMin();
1947        TrkParams::SetMiniDefault();
1948    
1949        TrkParams::Set(path,1);
1950        TrkParams::Load(1);
1951    
1952    //
1953    };
1954    // /**
1955    //  * Get BY (kGauss)
1956    //  * @param v (x,y,z) coordinates in cm
1957    //  */
1958    // float TrkLevel2::GetBX(float* v){
1959    //     float b[3];
1960    //     gufld_(v,b);
1961    //     return b[0]/10.;
1962    // }
1963    // /**
1964    //  * Get BY (kGauss)
1965    //  * @param v (x,y,z) coordinates in cm
1966    //  */
1967    // float TrkLevel2::GetBY(float* v){
1968    //     float b[3];
1969    //     gufld_(v,b);
1970    //     return b[1]/10.;
1971    // }
1972    // /**
1973    //  * Get BY (kGauss)
1974    //  * @param v (x,y,z) coordinates in cm
1975    //  */
1976    // float TrkLevel2::GetBZ(float* v){
1977    //     float b[3];
1978    //     gufld_(v,b);
1979    //     return b[2]/10.;
1980    // }
1981    //--------------------------------------
1982    //
1983    //
1984    //--------------------------------------
1985    /**
1986     * Get tracker-plane (mechanical) z-coordinate
1987     * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM)
1988     */
1989    Float_t TrkLevel2::GetZTrk(Int_t plane_id){
1990            switch(plane_id){
1991                    case 1: return ZTRK1;
1992                    case 2: return ZTRK2;
1993                    case 3: return ZTRK3;
1994                    case 4: return ZTRK4;
1995                    case 5: return ZTRK5;
1996                    case 6: return ZTRK6;
1997                    default: return 0.;
1998            };
1999  };  };
2000  //--------------------------------------  //--------------------------------------
2001  //  //
# Line 523  Trajectory::Trajectory(){ Line 2013  Trajectory::Trajectory(){
2013      thx = new float[npoint];      thx = new float[npoint];
2014      thy = new float[npoint];      thy = new float[npoint];
2015      tl = new float[npoint];      tl = new float[npoint];
2016      float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1);      float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
2017      for(int i=0; i<npoint; i++){      for(int i=0; i<npoint; i++){
2018          x[i] = 0;          x[i] = 0;
2019          y[i] = 0;          y[i] = 0;
2020          z[i] = (ZTRKUP) - i*dz;          z[i] = (ZTRK1) - i*dz;
2021          thx[i] = 0;          thx[i] = 0;
2022          thy[i] = 0;          thy[i] = 0;
2023          tl[i] = 0;          tl[i] = 0;
# Line 554  Trajectory::Trajectory(int n){ Line 2044  Trajectory::Trajectory(int n){
2044      thx = new float[npoint];      thx = new float[npoint];
2045      thy = new float[npoint];      thy = new float[npoint];
2046      tl = new float[npoint];      tl = new float[npoint];
2047      float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1);      float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
2048      for(int i=0; i<npoint; i++){      for(int i=0; i<npoint; i++){
2049          x[i] = 0;          x[i] = 0;
2050          y[i] = 0;          y[i] = 0;
2051          z[i] = (ZTRKUP) - i*dz;          z[i] = (ZTRK1) - i*dz;
2052          thx[i] = 0;          thx[i] = 0;
2053          thy[i] = 0;          thy[i] = 0;
2054          tl[i] = 0;          tl[i] = 0;
# Line 595  Trajectory::Trajectory(int n, float* zin Line 2085  Trajectory::Trajectory(int n, float* zin
2085      npoint=i;      npoint=i;
2086      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
2087  }  }
2088    void Trajectory::Delete(){
2089        
2090        if(x) delete [] x;
2091        if(y) delete [] y;
2092        if(z) delete [] z;
2093        if(thx) delete [] thx;
2094        if(thy) delete [] thy;
2095        if(tl) delete [] tl;
2096    
2097    }
2098  //--------------------------------------  //--------------------------------------
2099  //  //
2100  //  //
# Line 632  float Trajectory::GetLength(int ifirst, Line 2132  float Trajectory::GetLength(int ifirst,
2132      return l;      return l;
2133    
2134  }  }
2135    
2136    /**
2137     * Evaluates the trajectory in the apparatus associated to the track.
2138     * 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.  
2139     * @param t pointer to an object of the class Trajectory,
2140     * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
2141     * @return error flag.
2142     */
2143    int Trajectory::DoTrack2(float* al){
2144    
2145        double *dxout   = new double[npoint];
2146        double *dyout   = new double[npoint];
2147        double *dthxout = new double[npoint];
2148        double *dthyout = new double[npoint];
2149        double *dtlout  = new double[npoint];
2150        double *dzin    = new double[npoint];
2151        double dal[5];
2152    
2153        int ifail = 0;
2154    
2155        for (int i=0; i<5; i++)      dal[i]  = (double)al[i];
2156        for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
2157    
2158        TrkParams::Load(1);
2159        if( !TrkParams::IsLoaded(1) ){
2160            cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;
2161            return 0;
2162        }
2163        dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
2164        
2165        for (int i=0; i<npoint; i++){
2166            x[i]   = (float)*dxout++;
2167            y[i]   = (float)*dyout++;
2168            thx[i] = (float)*dthxout++;
2169            thy[i] = (float)*dthyout++;
2170            tl[i]  = (float)*dtlout++;
2171        }
2172    
2173        return ifail;
2174    };
2175    
2176  ClassImp(TrkLevel2);  ClassImp(TrkLevel2);
2177  ClassImp(TrkSinglet);  ClassImp(TrkSinglet);
2178  ClassImp(TrkTrack);  ClassImp(TrkTrack);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.44

  ViewVC Help
Powered by ViewVC 1.1.23