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

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.23