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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.23