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

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

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.23