/[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.22 by pam-fi, Mon Jan 15 12:49:05 2007 UTC revision 1.43 by pam-fi, Tue Jan 22 08:55:07 2008 UTC
# Line 12  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*);
 //    int  readb_(const char*);  
     int  readb_();  
15      void mini2_(int*,int*,int*);      void mini2_(int*,int*,int*);
16      void guess_();      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  //  //
# Line 39  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 46  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      clx = 0;  
64      cly = 0;  //     TrkParams::SetTrackingMode();
65    //     TrkParams::SetPrecisionFactor();
66    //     TrkParams::SetStepMin();
67        TrkParams::SetMiniDefault();
68        TrkParams::SetPFA();
69    
70  };  };
71  //--------------------------------------  //--------------------------------------
72  //  //
# Line 71  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 78  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      clx = 0;  
109      cly = 0;  //     TrkParams::SetTrackingMode();
110      if(t.clx)clx = new TRefArray(*(t.clx));  //     TrkParams::SetPrecisionFactor();
111      if(t.cly)cly = new TRefArray(*(t.cly));  //     TrkParams::SetStepMin();  
112                TrkParams::SetMiniDefault();
113        TrkParams::SetPFA();
114    
115  };  };
116  //--------------------------------------  //--------------------------------------
117  //  //
# Line 107  void TrkTrack::Copy(TrkTrack& t){ Line 135  void TrkTrack::Copy(TrkTrack& t){
135          t.zm[ip]     = zm[ip];          t.zm[ip]     = zm[ip];
136          t.resx[ip]   = resx[ip];          t.resx[ip]   = resx[ip];
137          t.resy[ip]   = resy[ip];          t.resy[ip]   = resy[ip];
138            t.tailx[ip]  = tailx[ip];
139            t.taily[ip]  = taily[ip];
140          t.xv[ip]     = xv[ip];          t.xv[ip]     = xv[ip];
141          t.yv[ip]     = yv[ip];          t.yv[ip]     = yv[ip];
142          t.zv[ip]     = zv[ip];          t.zv[ip]     = zv[ip];
# Line 114  void TrkTrack::Copy(TrkTrack& t){ Line 144  void TrkTrack::Copy(TrkTrack& t){
144          t.ayv[ip]    = ayv[ip];          t.ayv[ip]    = ayv[ip];
145          t.dedx_x[ip] = dedx_x[ip];          t.dedx_x[ip] = dedx_x[ip];
146          t.dedx_y[ip] = dedx_y[ip];          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  //--------------------------------------  //--------------------------------------
# Line 141  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 180  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 219  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 237  void TrkTrack::Dump(){ Line 480  void TrkTrack::Dump(){
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 << "n.step   : "<< nstep;      cout << endl << "n.step   : "<< nstep;
483      cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << xgood[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] ;      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] << " ";
# Line 247  void TrkTrack::Dump(){ Line 490  void TrkTrack::Dump(){
490      cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " ";      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] << " ";      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] << " ";      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]<<" ";      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]<<" ";      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]<<" ";      cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
# Line 254  void TrkTrack::Dump(){ Line 499  void TrkTrack::Dump(){
499      cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";      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;      cout << endl;
512  }  }
513  /**  /**
# Line 272  void TrkTrack::SetResolution(double *rx, Line 526  void TrkTrack::SetResolution(double *rx,
526      for(int i=0; i<6; i++) resy[i]=*ry++;      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   * Set the TrkTrack good measurement
609   */   */
610  void TrkTrack::SetGood(int *xg, int *yg){  void TrkTrack::SetGood(int *xg, int *yg){
611    
612      for(int i=0; i<6; i++) xgood[i]=*xg++;      for(int i=0; i<6; i++) xgood[i]=*xg++;
613      for(int i=0; i<6; i++) ygood[i]=*yg++;      for(int i=0; i<6; i++) ygood[i]=*yg++;
614  }  }
# Line 284  void TrkTrack::SetGood(int *xg, int *yg) Line 618  void TrkTrack::SetGood(int *xg, int *yg)
618   */   */
619  void TrkTrack::LoadField(TString path){  void TrkTrack::LoadField(TString path){
620            
621      strcpy(path_.path,path.Data());  //     strcpy(path_.path,path.Data());
622      path_.pathlen = path.Length();  //     path_.pathlen = path.Length();
623      path_.error   = 0;  //     path_.error   = 0;
624      readb_();  //     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   * Method to fill minimization-routine common
639   */   */
# Line 298  void TrkTrack::FillMiniStruct(cMini2trac Line 641  void TrkTrack::FillMiniStruct(cMini2trac
641    
642      for(int i=0; i<6; i++){      for(int i=0; i<6; i++){
643    
644          track.xgood[i]=xgood[i];  //      cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl;
645          track.ygood[i]=ygood[i];  //      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];          track.xm[i]=xm[i];
650          track.ym[i]=ym[i];          track.ym[i]=ym[i];
# Line 312  void TrkTrack::FillMiniStruct(cMini2trac Line 657  void TrkTrack::FillMiniStruct(cMini2trac
657          track.xm_b[i]=xm[i];          track.xm_b[i]=xm[i];
658          track.ym_a[i]=ym[i];          track.ym_a[i]=ym[i];
659          track.ym_b[i]=ym[i];          track.ym_b[i]=ym[i];
660          if(       xgood[i] && !ygood[i] ){          if(       XGood(i) && !YGood(i) ){
661              track.ym_a[i] = track.ym_a[i]+segment;              track.ym_a[i] = track.ym_a[i]+segment;
662              track.ym_b[i] = track.ym_b[i]-segment;              track.ym_b[i] = track.ym_b[i]-segment;
663          }else if( !xgood[i] && ygood[i]){          }else if( !XGood(i) && YGood(i)){
664              track.xm_a[i] = track.xm_a[i]+segment;              track.xm_a[i] = track.xm_a[i]+segment;
665              track.xm_b[i] = track.xm_b[i]-segment;              track.xm_b[i] = track.xm_b[i]-segment;
666          }          }
# Line 323  void TrkTrack::FillMiniStruct(cMini2trac Line 668  void TrkTrack::FillMiniStruct(cMini2trac
668                    
669          track.resx[i]=resx[i];          track.resx[i]=resx[i];
670          track.resy[i]=resy[i];          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];      for(int i=0; i<5; i++) track.al[i]=al[i];
# Line 351  void TrkTrack::SetFromMiniStruct(cMini2t Line 698  void TrkTrack::SetFromMiniStruct(cMini2t
698          axv[i] = track->axv[i];          axv[i] = track->axv[i];
699          ayv[i] = track->ayv[i];          ayv[i] = track->ayv[i];
700      }      }
   
701            
702  }  }
703  /**  /**
704   * Tracking method. It calls F77 mini routine.   * \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::GetClusterositions() "<<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){  void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
785    
786      float al_ini[] = {0.,0.,0.,0.,0.};      float al_ini[] = {0.,0.,0.,0.,0.};
787    
788        TrkParams::Load( );
789        if( !TrkParams::IsLoaded() )return;
790    
791      extern cMini2track track_;      extern cMini2track track_;
792      fail = 0;      fail = 0;
     FillMiniStruct(track_);  
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      // 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_();      if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
809    
# Line 383  void TrkTrack::Fit(double pfixed, int& f Line 822  void TrkTrack::Fit(double pfixed, int& f
822    
823      //  ------------------------------------------      //  ------------------------------------------
824      //  call mini routine      //  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;      int istep=0;
831      int ifail=0;      int ifail=0;
832      mini2_(&istep,&ifail, &iprint);      mini2_(&istep,&ifail, &iprint);
# Line 393  void TrkTrack::Fit(double pfixed, int& f Line 837  void TrkTrack::Fit(double pfixed, int& f
837      //  ------------------------------------------      //  ------------------------------------------
838            
839      SetFromMiniStruct(&track_);      SetFromMiniStruct(&track_);
 //    cout << endl << "eta ===> " << track_.al[4] << endl;  
   
 //     for(int i=0; i<5; i++) al[i]=track_.al[i];  
 //     chi2=track_.chi2;  
 //     nstep=track_.nstep;  
 //     for(int i=0; i<6; i++) xv[i]=track_.xv[i];  
 //     for(int i=0; i<6; i++) yv[i]=track_.yv[i];  
 //     for(int i=0; i<6; i++) zv[i]=track_.zv[i];  
 //     for(int i=0; i<6; i++) axv[i]=track_.axv[i];  
 //     for(int i=0; i<6; i++) ayv[i]=track_.ayv[i];  
 //     for(int i=0; i<5; i++) {  
 //      for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];  
 //     }  
840    
841      if(fail){      if(fail){
842          if(iprint)cout << " >>>> fit failed >>>> drawing initial par"<<endl;          if(iprint)cout << " >>>> fit failed "<<endl;
843          for(int i=0; i<5; i++) al[i]=al_ini[i];          for(int i=0; i<5; i++) al[i]=al_ini[i];
844      }      }
845    
846  };  };
847  /*  /**
848   * Reset the fit parameters   * Reset the fit parameters
849   */   */
850  void TrkTrack::FitReset(){  void TrkTrack::FitReset(){
851      for(int i=0; i<5; i++) al[i]=-9999.;      for(int i=0; i<5; i++) al[i]=-9999.;
852      chi2=0.;      chi2=0.;
853      nstep=0;      nstep=0;
854      for(int i=0; i<6; i++) xv[i]=0.;  //     for(int i=0; i<6; i++) xv[i]=0.;
855      for(int i=0; i<6; i++) yv[i]=0.;  //     for(int i=0; i<6; i++) yv[i]=0.;
856      for(int i=0; i<6; i++) zv[i]=0.;  //     for(int i=0; i<6; i++) zv[i]=0.;
857      for(int i=0; i<6; i++) axv[i]=0.;  //     for(int i=0; i<6; i++) axv[i]=0.;
858      for(int i=0; i<6; i++) ayv[i]=0.;  //     for(int i=0; i<6; i++) ayv[i]=0.;
859      for(int i=0; i<5; i++) {      for(int i=0; i<5; i++) {
860          for(int j=0; j<5; j++) coval[i][j]=0.;          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(acos(-1.0)*axv[0]/180.);
899        ymagntop = yv[0] + (ZMAGNHIGH-zv[0])*tan(acos(-1.0)*ayv[0]/180.);
900        xmagnbottom = xv[5] + (ZMAGNLOW-zv[5])*tan(acos(-1.0)*axv[5]/180.);
901        ymagnbottom = yv[5] + (ZMAGNLOW-zv[5])*tan(acos(-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     * \brief Average X
975     * Average value of <xv>, evaluated from the first to the last hit x view.
976     */
977    Float_t TrkTrack::GetXav(){
978    
979        int first_plane = -1;
980        int last_plane  = -1;
981        for(Int_t ip=0; ip<6; ip++){
982            if( XGood(ip) && first_plane == -1 )first_plane = ip;
983            if( XGood(ip) && first_plane != -1 )last_plane = ip;
984        }
985        if( first_plane == -1 || last_plane == -1){
986            return -100;
987        }
988        if( last_plane-first_plane+1 ==0 )return -100;
989    
990        Float_t av = 0;    
991        for(int ip=first_plane; ip<=last_plane; ip++)av+=xv[ip];
992        
993        return (av/(last_plane-first_plane+1));    
994    }
995    /**
996     * \brief Average Y
997     * Average value of <yv>, evaluated from the first to the last hit x view.
998     */
999    Float_t TrkTrack::GetYav(){
1000    
1001        int first_plane = -1;
1002        int last_plane  = -1;
1003        for(Int_t ip=0; ip<6; ip++){
1004            if( XGood(ip) && first_plane == -1 )first_plane = ip;
1005            if( XGood(ip) && first_plane != -1 )last_plane = ip;
1006        }
1007        if( first_plane == -1 || last_plane == -1){
1008            return -100;
1009        }
1010        if( last_plane-first_plane+1 ==0 )return -100;
1011    
1012        Float_t av = 0;    
1013        for(int ip=first_plane; ip<=last_plane; ip++)av+=yv[ip];
1014    
1015        return (av/(last_plane-first_plane+1));    
1016    }
1017    /**
1018     * \brief Average Z
1019     * Average value of <zv>, evaluated from the first to the last hit x view.
1020     */
1021    Float_t TrkTrack::GetZav(){
1022    
1023        int first_plane = -1;
1024        int last_plane  = -1;
1025        for(Int_t ip=0; ip<6; ip++){
1026            if( XGood(ip) && first_plane == -1 )first_plane = ip;
1027            if( XGood(ip) && first_plane != -1 )last_plane = ip;
1028        }
1029        if( first_plane == -1 || last_plane == -1){
1030            return -100;
1031        }
1032        if( last_plane-first_plane+1 ==0 )return -100;
1033    
1034        Float_t av = 0;    
1035        for(int ip=first_plane; ip<=last_plane; ip++)av+=zv[ip];
1036        
1037        return (av/(last_plane-first_plane+1));    
1038    }
1039    
1040    /**
1041     * \brief Number of column traversed
1042     */
1043    Int_t TrkTrack::GetNColumns(){
1044        int sensors[] = {0,0,0,0,0,0};
1045        for(int ip=0; ip<6; ip++){
1046            int sensorid = GetLadder(ip)+3*GetSensor(ip);    
1047            if(XGood(ip)||YGood(ip))
1048                if(sensorid>=0 && sensorid<6)sensors[sensorid]=1;
1049        }
1050        int nsensors=0;
1051        for(int is=0; is<6; is++)nsensors += sensors[is];
1052        return nsensors;
1053    };
1054    /**
1055     * \brief Give the maximum energy release
1056     */
1057    Float_t TrkTrack::GetDEDX_max(int ip, int iv){
1058        Float_t max=0;
1059        int pfrom = 0;
1060        int pto   = 6;
1061        int vfrom = 0;
1062        int vto   = 2;
1063        if(ip>=0&&ip<6){
1064            pfrom = ip;
1065            pto   = ip+1;
1066        }
1067        if(iv>=0&&iv<2){
1068            vfrom = iv;
1069            vto   = iv+1;
1070        }
1071        for(int i=pfrom; i<pto; i++)
1072            for(int j=0; j<vto; j++)
1073                if(GetDEDX(i,j)>max)max=GetDEDX(i,j);
1074    
1075        return max;
1076    
1077    };
1078    
1079    /**
1080     * \brief Give the minimum energy release
1081     */
1082    Float_t TrkTrack::GetDEDX_min(int ip, int iv){
1083        Float_t min=100000000;
1084        int pfrom = 0;
1085        int pto   = 6;
1086        int vfrom = 0;
1087        int vto   = 2;
1088        if(ip>=0&&ip<6){
1089            pfrom = ip;
1090            pto   = ip+1;
1091        }
1092        if(iv>=0&&iv<2){
1093            vfrom = iv;
1094            vto   = iv+1;
1095        }
1096        for(int i=pfrom; i<pto; i++)
1097            for(int j=0; j<vto; j++)
1098                if(GetDEDX(i,j)<min)min=GetDEDX(i,j);
1099    
1100        return min;
1101    
1102    };
1103    
1104    /**
1105     * \brief Give the maximum spatial residual release
1106     */
1107    Float_t TrkTrack::GetResidual_max(int ip, int iv){
1108        Float_t max=0;
1109        int pfrom = 0;
1110        int pto   = 6;
1111        int vfrom = 0;
1112        int vto   = 2;
1113        if(ip>=0&&ip<6){
1114            pfrom = ip;
1115            pto   = ip+1;
1116        }
1117        if(iv>=0&&iv<2){
1118            vfrom = iv;
1119            vto   = iv+1;
1120        }
1121        for(int i=pfrom; i<pto; i++){
1122            for(int j=0; j<vto; j++){
1123                if(j==0 && XGood(i) && fabs(xm[i]-xv[i])>fabs(max))max=xv[i]-xm[i];
1124                if(j==1 && YGood(i) && fabs(ym[i]-yv[i])>fabs(max))max=yv[i]-ym[i];
1125            }
1126        }
1127        return max;
1128    
1129    };
1130    
1131    
1132    /**
1133     * \brief Give the maximum multiplicity on the x view
1134     */
1135    Int_t TrkTrack::GetClusterX_Multiplicity_max(){
1136        int max=0;
1137        for(int ip=0; ip<6; ip++)
1138            if(GetClusterX_Multiplicity(ip)>max)max=GetClusterX_Multiplicity(ip);
1139        return max;
1140    };
1141    /**
1142     * \brief Give the minimum multiplicity on the x view
1143     */
1144    Int_t TrkTrack::GetClusterX_Multiplicity_min(){
1145        int min=50;
1146        for(int ip=0; ip<6; ip++)
1147            if(GetClusterX_Multiplicity(ip)<min)min=GetClusterX_Multiplicity(ip);
1148        return min;
1149    };
1150    /**
1151     * \brief Give the maximum multiplicity on the x view
1152     */
1153    Int_t TrkTrack::GetClusterY_Multiplicity_max(){
1154        int max=0;
1155        for(int ip=0; ip<6; ip++)
1156            if(GetClusterY_Multiplicity(ip)>max)max=GetClusterY_Multiplicity(ip);
1157        return max;
1158    };
1159    /**
1160     * \brief Give the minimum multiplicity on the x view
1161     */
1162    Int_t TrkTrack::GetClusterY_Multiplicity_min(){
1163        int min=50;
1164        for(int ip=0; ip<6; ip++)
1165            if(GetClusterY_Multiplicity(ip)<min)min=GetClusterY_Multiplicity(ip);
1166        return min;
1167    };
1168    
1169    /**
1170     * \brief Give the minimum seed on the x view
1171     */
1172    Float_t TrkTrack::GetClusterX_Seed_min(){
1173        Float_t min=100000;
1174        for(int ip=0; ip<6; ip++)
1175            if(XGood(ip) && GetClusterX_Seed(ip)<min)min=GetClusterX_Seed(ip);
1176        return min;
1177    };
1178    /**
1179     * \brief Give the minimum seed on the x view
1180     */
1181    Float_t TrkTrack::GetClusterY_Seed_min(){
1182        Float_t min=100000;
1183        for(int ip=0; ip<6; ip++)
1184            if(YGood(ip) && GetClusterY_Seed(ip)<min)min=GetClusterY_Seed(ip);
1185        return min;
1186    };
1187    
1188    
1189  //--------------------------------------  //--------------------------------------
1190  //  //
# Line 452  void TrkTrack::Clear(){ Line 1208  void TrkTrack::Clear(){
1208          zm[ip]     = 0;          zm[ip]     = 0;
1209          resx[ip]   = 0;          resx[ip]   = 0;
1210          resy[ip]   = 0;          resy[ip]   = 0;
1211            tailx[ip]  = 0;
1212            taily[ip]  = 0;
1213          xv[ip]     = 0;          xv[ip]     = 0;
1214          yv[ip]     = 0;          yv[ip]     = 0;
1215          zv[ip]     = 0;          zv[ip]     = 0;
# Line 461  void TrkTrack::Clear(){ Line 1219  void TrkTrack::Clear(){
1219          dedx_y[ip] = 0;          dedx_y[ip] = 0;
1220    
1221      };      };
1222      if(clx)clx->Clear();  //     if(clx)clx->Clear();
1223      if(cly)cly->Clear();  //     if(cly)cly->Clear();
1224    //    clx.Clear();
1225    //    cly.Clear();
1226  };  };
1227  //--------------------------------------  //--------------------------------------
1228  //  //
# Line 470  void TrkTrack::Clear(){ Line 1230  void TrkTrack::Clear(){
1230  //--------------------------------------  //--------------------------------------
1231  void TrkTrack::Delete(){  void TrkTrack::Delete(){
1232  //    cout << "TrkTrack::Delete()"<<endl;  //    cout << "TrkTrack::Delete()"<<endl;
1233  //    Clear();      Clear();
1234      if(clx)delete clx;  //    if(clx)delete clx;
1235      if(cly)delete cly;  //    if(cly)delete cly;
1236  };  };
1237  //--------------------------------------  //--------------------------------------
1238  //  //
# Line 502  TrkSinglet::TrkSinglet(const TrkSinglet& Line 1262  TrkSinglet::TrkSinglet(const TrkSinglet&
1262      coord[1] = s.coord[1];      coord[1] = s.coord[1];
1263      sgnl     = s.sgnl;      sgnl     = s.sgnl;
1264  //      cls      = 0;//<<<<pointer  //      cls      = 0;//<<<<pointer
1265      cls      = TRef(s.cls);  //    cls      = TRef(s.cls);
1266  };  };
1267  //--------------------------------------  //--------------------------------------
1268  //  //
# Line 533  void TrkSinglet::Clear(){ Line 1293  void TrkSinglet::Clear(){
1293  //  //
1294  //--------------------------------------  //--------------------------------------
1295  TrkLevel2::TrkLevel2(){  TrkLevel2::TrkLevel2(){
1296  //    cout <<"TrkLevel2::TrkLevel2()"<<endl;    //    cout <<"TrkLevel2::TrkLevel2()"<<endl;
1297      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1298                  good[i] = -1;          good[i] = -1;
1299          };          VKmask[i] = 0;
1300  //    Track    = new TClonesArray("TrkTrack");          VKflag[i] = 0;  
1301  //    SingletX = new TClonesArray("TrkSinglet");      };
 //    SingletY = new TClonesArray("TrkSinglet");  
1302      Track    = 0;      Track    = 0;
1303      SingletX = 0;      SingletX = 0;
1304      SingletY = 0;      SingletY = 0;
# Line 549  TrkLevel2::TrkLevel2(){ Line 1308  TrkLevel2::TrkLevel2(){
1308  //  //
1309  //  //
1310  //--------------------------------------  //--------------------------------------
1311    void TrkLevel2::Set(){
1312        if(!Track)Track    = new TClonesArray("TrkTrack");
1313        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1314        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1315    }
1316    //--------------------------------------
1317    //
1318    //
1319    //--------------------------------------
1320  void TrkLevel2::Dump(){  void TrkLevel2::Dump(){
1321                    
1322          //          //
1323      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
1324      cout << endl << "good     : "; for(int i=0; i<12; i++) cout << good[i]<<" ";      cout << endl << "good     : "; for(int i=0; i<12; i++) cout << hex <<" 0x"<< good[i]<<dec;
1325      cout << endl << "ntrk()   : " << this->ntrk() ;      cout << endl << "ntrk()   : " << ntrk() ;
1326      cout << endl << "nclsx()  : " << this->nclsx();      cout << endl << "nclsx()  : " << nclsx();
1327      cout << endl << "nclsy()  : " << this->nclsy();      cout << endl << "nclsy()  : " << nclsy();
 //     TClonesArray &t  = *Track;  
 //     TClonesArray &sx = *SingletX;  
 //     TClonesArray &sy = *SingletY;  
 //     for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();  
 //     for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();  
 //     for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();  
1328      if(Track){      if(Track){
1329          TClonesArray &t  = *Track;          TClonesArray &t  = *Track;
1330          for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();          for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();
1331      }            }      
1332      if(SingletX){  //     if(SingletX){
1333          TClonesArray &sx = *SingletX;  //      TClonesArray &sx = *SingletX;
1334          for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();  //      for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
1335      }  //     }
1336      if(SingletY){  //     if(SingletY){
1337          TClonesArray &sy = *SingletY;  //      TClonesArray &sy = *SingletY;
1338          for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();  //      for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
1339      }  //     }
1340        cout << endl;
1341  }  }
1342    /**
1343     * \brief Dump processing status
1344     */
1345    void TrkLevel2::StatusDump(int view){
1346        cout << "DSP n. "<<view+1<<" status: "<<hex<<good[view]<<endl;    
1347    };
1348    /**
1349     * \brief Check event status
1350     *
1351     * Check the event status, according to a flag-mask given as input.
1352     * Return true if the view passes the check.
1353     *
1354     * @param view View number (0-11)
1355     * @param flagmask Mask of flags to check (eg. flagmask=0x111 no missing packet,
1356     *  no crc error, no software alarm)
1357     *
1358     * @see TrkLevel2 class definition to know how the status flag is defined
1359     *
1360     */
1361    Bool_t TrkLevel2::StatusCheck(int view, int flagmask){
1362    
1363        if( view<0 || view >= 12)return false;
1364        return !(good[view]&flagmask);
1365    
1366    };
1367    
1368    
1369    //--------------------------------------
1370    //
1371    //
1372    //--------------------------------------
1373    /**
1374     * The method returns false if the viking-chip was masked  
1375     * either apriori ,on the basis of the mask read from the DB,
1376     * or run-by-run, on the basis of the calibration parameters)
1377     * @param iv Tracker view (0-11)
1378     * @param ivk Viking-chip number (0-23)
1379     */
1380    Bool_t TrkLevel2::GetVKMask(int iv, int ivk){
1381        Int_t whichbit = (Int_t)pow(2,ivk);
1382        return (whichbit&VKmask[iv])!=0;    
1383    }
1384    /**
1385     * The method returns false if the viking-chip was masked  
1386     * for this event due to common-noise computation failure.
1387     * @param iv Tracker view (0-11)
1388     * @param ivk Viking-chip number (0-23)
1389     */
1390    Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){
1391        Int_t whichbit = (Int_t)pow(2,ivk);
1392        return (whichbit&VKflag[iv])!=0;    
1393    }
1394    /**
1395     * The method returns true if the viking-chip was masked, either
1396     * forced (see TrkLevel2::GetVKMask(int,int)) or
1397     * for this event only (TrkLevel2::GetVKFlag(int,int)).
1398     * @param iv Tracker view (0-11)
1399     * @param ivk Viking-chip number (0-23)
1400     */
1401    Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){
1402        return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) );
1403    };
1404    
1405  //--------------------------------------  //--------------------------------------
1406  //  //
1407  //  //
1408  //--------------------------------------  //--------------------------------------
1409  /**  /**
1410   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
1411     * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set.
1412     * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch)
1413   */   */
1414  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
1415    
1416    //    cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl;
1417        Clear();
1418    
1419          //  temporary objects:  //  temporary objects:
1420      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
1421      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
1422    
1423          //  **** general variables ****  //  -----------------
1424  //    good2 = l2->good2;  //  general variables
1425    //  -----------------
1426      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1427  //              crc[i] = l2->crc[i];          good[i] = l2->good[i];
1428                  good[i] = l2->good[i];          VKmask[i]=0;
1429            VKflag[i]=0;
1430            for(Int_t ii=0; ii<24 ; ii++){
1431                Int_t setbit = (Int_t)pow(2,ii);
1432                if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit;
1433                if( l2->vkflag[ii][i]!=0  )VKflag[i]=VKflag[i]|setbit;
1434          };          };
1435          //  *** TRACKS ***      };
1436    //  --------------
1437    //  *** TRACKS ***
1438    //  --------------
1439      if(!Track) Track = new TClonesArray("TrkTrack");      if(!Track) Track = new TClonesArray("TrkTrack");
1440      TClonesArray &t = *Track;      TClonesArray &t = *Track;
1441    
1442      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
1443          t_track->seqno = i;// NBNBNBNB deve sempre essere = i          t_track->seqno = i;// NBNBNBNB deve sempre essere = i
1444          t_track->image = l2->image[i]-1;          t_track->image = l2->image[i]-1;
         //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;  
1445          t_track->chi2  = l2->chi2_nt[i];          t_track->chi2  = l2->chi2_nt[i];
1446          t_track->nstep = l2->nstep_nt[i];          t_track->nstep = l2->nstep_nt[i];
1447          for(int it1=0;it1<5;it1++){          for(int it1=0;it1<5;it1++){
# Line 610  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1450  void TrkLevel2::SetFromLevel2Struct(cTrk
1450                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];
1451          };          };
1452          for(int ip=0;ip<6;ip++){          for(int ip=0;ip<6;ip++){
1453              t_track->xgood[ip]  = l2->xgood_nt[i][ip];              // ---------------------------------
1454              t_track->ygood[ip]  = l2->ygood_nt[i][ip];              // new implementation of xgood/ygood
1455                // ---------------------------------
1456                t_track->xgood[ip]  = l2->cltrx[i][ip]; //cluster ID
1457                t_track->ygood[ip]  = l2->cltry[i][ip]; //cluster ID
1458                t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1459                t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1460                if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip];
1461                if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip];
1462    //          if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){
1463    //          if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){
1464    //              cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl;
1465    //              cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl;
1466    //              cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl;
1467    //              cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl;
1468    //              cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl;
1469    //          }
1470              t_track->xm[ip]     = l2->xm_nt[i][ip];              t_track->xm[ip]     = l2->xm_nt[i][ip];
1471              t_track->ym[ip]     = l2->ym_nt[i][ip];              t_track->ym[ip]     = l2->ym_nt[i][ip];
1472              t_track->zm[ip]     = l2->zm_nt[i][ip];              t_track->zm[ip]     = l2->zm_nt[i][ip];
1473              t_track->resx[ip]   = l2->resx_nt[i][ip];              t_track->resx[ip]   = l2->resx_nt[i][ip];
1474              t_track->resy[ip]   = l2->resy_nt[i][ip];              t_track->resy[ip]   = l2->resy_nt[i][ip];
1475                t_track->tailx[ip]  = l2->tailx[i][ip];
1476                t_track->taily[ip]  = l2->taily[i][ip];
1477              t_track->xv[ip]     = l2->xv_nt[i][ip];              t_track->xv[ip]     = l2->xv_nt[i][ip];
1478              t_track->yv[ip]     = l2->yv_nt[i][ip];              t_track->yv[ip]     = l2->yv_nt[i][ip];
1479              t_track->zv[ip]     = l2->zv_nt[i][ip];              t_track->zv[ip]     = l2->zv_nt[i][ip];
# Line 624  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1481  void TrkLevel2::SetFromLevel2Struct(cTrk
1481              t_track->ayv[ip]    = l2->ayv_nt[i][ip];              t_track->ayv[ip]    = l2->ayv_nt[i][ip];
1482              t_track->dedx_x[ip] = l2->dedx_x[i][ip];              t_track->dedx_x[ip] = l2->dedx_x[i][ip];
1483              t_track->dedx_y[ip] = l2->dedx_y[i][ip];              t_track->dedx_y[ip] = l2->dedx_y[i][ip];
1484  //                      t_track->clx[ip] = 0;              t_track->multmaxx[ip] = l2->multmaxx[i][ip];
1485  //                      t_track->cly[ip] = 0;              t_track->multmaxy[ip] = l2->multmaxy[i][ip];
1486                t_track->seedx[ip]  = l2->seedx[i][ip];  
1487                t_track->seedy[ip]  = l2->seedy[i][ip];
1488                t_track->xpu[ip]    = l2->xpu[i][ip];  
1489                t_track->ypu[ip]    = l2->ypu[i][ip];  
1490                //-----------------------------------------------------
1491                //-----------------------------------------------------
1492                //-----------------------------------------------------
1493                //-----------------------------------------------------
1494          };          };
1495    //      if(t_track->IsSaturated())t_track->Dump();
1496          new(t[i]) TrkTrack(*t_track);          new(t[i]) TrkTrack(*t_track);
1497          t_track->Clear();          t_track->Clear();
1498      };      };
1499    
1500    //  ----------------
1501  //  *** SINGLETS ***  //  *** SINGLETS ***
1502    //  ----------------
1503      if(!SingletX)SingletX = new TClonesArray("TrkSinglet");      if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1504      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
1505      for(int i=0; i<l2->nclsx; i++){      for(int i=0; i<l2->nclsx; i++){
# Line 638  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1507  void TrkLevel2::SetFromLevel2Struct(cTrk
1507          t_singlet->coord[0] = l2->xs[i][0];          t_singlet->coord[0] = l2->xs[i][0];
1508          t_singlet->coord[1] = l2->xs[i][1];          t_singlet->coord[1] = l2->xs[i][1];
1509          t_singlet->sgnl     = l2->signlxs[i];          t_singlet->sgnl     = l2->signlxs[i];
1510  //              t_singlet->cls      = 0;          //-----------------------------------------------------
1511    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);
1512            //-----------------------------------------------------
1513          new(sx[i]) TrkSinglet(*t_singlet);          new(sx[i]) TrkSinglet(*t_singlet);
1514          t_singlet->Clear();          t_singlet->Clear();
1515      }      }
# Line 649  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1520  void TrkLevel2::SetFromLevel2Struct(cTrk
1520          t_singlet->coord[0] = l2->ys[i][0];          t_singlet->coord[0] = l2->ys[i][0];
1521          t_singlet->coord[1] = l2->ys[i][1];          t_singlet->coord[1] = l2->ys[i][1];
1522          t_singlet->sgnl     = l2->signlys[i];          t_singlet->sgnl     = l2->signlys[i];
1523  //              t_singlet->cls      = 0;          //-----------------------------------------------------
1524    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);
1525            //-----------------------------------------------------
1526          new(sy[i]) TrkSinglet(*t_singlet);          new(sy[i]) TrkSinglet(*t_singlet);
1527          t_singlet->Clear();          t_singlet->Clear();
1528      };      };
# Line 657  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1530  void TrkLevel2::SetFromLevel2Struct(cTrk
1530      delete t_track;      delete t_track;
1531      delete t_singlet;      delete t_singlet;
1532  }  }
 //--------------------------------------  
 //  
 //  
 //--------------------------------------  
 /**  
  * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).  
  * Ref to Level1 data (clusters) is also set.  
  */  
 void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){  
   
 //  temporary objects:  
         TrkSinglet* t_singlet = new TrkSinglet();  
         TrkTrack*   t_track   = new TrkTrack();  
 // general variables  
 //      good2 = l2->good2;  
         for(Int_t i=0; i<12 ; i++){  
 //              crc[i] = l2->crc[i];  
                 good[i] = l2->good[i];  
         };  
 // *** TRACKS ***  
         if(!Track) Track = new TClonesArray("TrkTrack");  
         TClonesArray &t = *Track;  
         if(!t_track->clx)t_track->clx = new TRefArray(6,0);  
         if(!t_track->cly)t_track->cly = new TRefArray(6,0);  
         for(int i=0; i<l2->ntrk; i++){  
                 t_track->seqno = i;// NBNBNBNB deve sempre essere = i  
                 t_track->image = l2->image[i]-1;  
 //              cout << "track "<<i<<t_track->seqno << t_track->image<<endl;  
                 t_track->chi2  = l2->chi2_nt[i];  
                 t_track->nstep = l2->nstep_nt[i];  
                 for(int it1=0;it1<5;it1++){  
                         t_track->al[it1] = l2->al_nt[i][it1];  
                         for(int it2=0;it2<5;it2++)  
                                 t_track->coval[it1][it2] = l2->coval[i][it2][it1];  
                 };  
                 for(int ip=0;ip<6;ip++){  
                         t_track->xgood[ip]  = l2->xgood_nt[i][ip];  
                         t_track->ygood[ip]  = l2->ygood_nt[i][ip];  
                         t_track->xm[ip]     = l2->xm_nt[i][ip];  
                         t_track->ym[ip]     = l2->ym_nt[i][ip];  
                         t_track->zm[ip]     = l2->zm_nt[i][ip];  
                         t_track->resx[ip]   = l2->resx_nt[i][ip];  
                         t_track->resy[ip]   = l2->resy_nt[i][ip];  
                         t_track->xv[ip]     = l2->xv_nt[i][ip];  
                         t_track->yv[ip]     = l2->yv_nt[i][ip];  
                         t_track->zv[ip]     = l2->zv_nt[i][ip];  
                         t_track->axv[ip]    = l2->axv_nt[i][ip];  
                         t_track->ayv[ip]    = l2->ayv_nt[i][ip];  
                         t_track->dedx_x[ip] = l2->dedx_x[i][ip];  
                         t_track->dedx_y[ip] = l2->dedx_y[i][ip];  
 //                      cout << "traccia "<<i<<"  --  "<< ip << " "<< l2->cltrx[i][ip] <<" "<< l2->cltry[i][ip] <<" "<< t_track->xgood[ip] << t_track->ygood[ip]<<endl;  
                         //-----------------------------------------------------  
                         //-----------------------------------------------------  
                         if(t_track->xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip);  
                         if(t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip);  
 //                      if(t_track->ygood[ip])cout<<" i "<<i<<" ip "<<ip<<" l2->cltry[i][ip] "<<l2->cltry[i][ip]<< " l1->GetCluster(l2->cltry[i][ip]-1) "<<l1->GetCluster(l2->cltry[i][ip]-1)<<endl;  
 //                      if(t_track->xgood[ip])cout<<" i "<<i<<" ip "<<ip<<" l2->cltrx[i][ip] "<<l2->cltrx[i][ip]<< " l1->GetCluster(l2->cltrx[i][ip]-1) "<<l1->GetCluster(l2->cltrx[i][ip]-1)<<endl;  
                         //-----------------------------------------------------  
                         //-----------------------------------------------------  
                 };  
                 new(t[i]) TrkTrack(*t_track);  
                 t_track->Clear();  
         };  
 // *** SINGLETS ***  
         if(!SingletX)SingletX = new TClonesArray("TrkSinglet");  
         TClonesArray &sx = *SingletX;  
         for(int i=0; i<l2->nclsx; i++){  
                 t_singlet->plane    = l2->planex[i];  
                 t_singlet->coord[0] = l2->xs[i][0];  
                 t_singlet->coord[1] = l2->xs[i][1];  
                 t_singlet->sgnl     = l2->signlxs[i];  
                 //-----------------------------------------------------  
 //              cout << "singolo x "<<i<<"  --  "<<  l2->clsx[i] <<endl;  
                 t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);  
 //              cout<<" i "<<i<<" l2->clsx[i] "<<l2->clsx[i]<< " l1->GetCluster(l2->clsx[i]-1) "<<l1->GetCluster(l2->clsx[i]-1)<<endl;            
                 //-----------------------------------------------------  
                 new(sx[i]) TrkSinglet(*t_singlet);  
                 t_singlet->Clear();  
         }  
         if(!SingletY)SingletY = new TClonesArray("TrkSinglet");  
         TClonesArray &sy = *SingletY;  
         for(int i=0; i<l2->nclsy; i++){  
                 t_singlet->plane    = l2->planey[i];  
                 t_singlet->coord[0] = l2->ys[i][0];  
                 t_singlet->coord[1] = l2->ys[i][1];  
                 t_singlet->sgnl     = l2->signlys[i];  
                 //-----------------------------------------------------  
 //              cout << "singolo y "<<i<<"  --  "<<  l2->clsy[i] <<endl;  
                 t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);  
 //              cout<<" i "<<i<<" l2->clsy[i] "<<l2->clsy[i]<< " l1->GetCluster(l2->clsy[i]-1) "<<l1->GetCluster(l2->clsy[i]-1)<<endl;            
                 //-----------------------------------------------------  
                 new(sy[i]) TrkSinglet(*t_singlet);  
                 t_singlet->Clear();  
         };  
           
         delete t_track;  
         delete t_singlet;  
 }  
1533  /**  /**
1534   * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).   * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
1535   */   */
# Line 781  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 1556  void TrkLevel2::GetLevel2Struct(cTrkLeve
1556                      l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];                      l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
1557              };              };
1558              for(int ip=0;ip<6;ip++){              for(int ip=0;ip<6;ip++){
1559                  l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip];                  l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip);
1560                  l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip];                  l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip);
1561                  l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];                  l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];
1562                  l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];                  l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];
1563                  l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];                  l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];
1564                  l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];                  l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];
1565                  l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];                  l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];
1566                    l2->tailx[i][ip]  = ((TrkTrack *)Track->At(i))->tailx[ip];
1567                    l2->taily[i][ip]  = ((TrkTrack *)Track->At(i))->taily[ip];
1568                  l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];                  l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];
1569                  l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];                  l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];
1570                  l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];                  l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];
# Line 826  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 1603  void TrkLevel2::GetLevel2Struct(cTrkLeve
1603  void TrkLevel2::Clear(){  void TrkLevel2::Clear(){
1604      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1605          good[i] = -1;          good[i] = -1;
1606            VKflag[i] = 0;
1607            VKmask[i] = 0;
1608      };      };
1609  //    if(Track)Track->Clear("C");  //    if(Track)Track->Clear("C");
1610  //    if(SingletX)SingletX->Clear("C");  //    if(SingletX)SingletX->Clear("C");
# Line 869  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1648  TRefArray *TrkLevel2::GetTracks_NFitSort
1648                    
1649      int indo=0;      int indo=0;
1650      int indi=0;      int indi=0;
1651      while(N != 0){      while(N > 0){
1652    //    while(N != 0){
1653          int nfit =0;          int nfit =0;
1654          float chi2ref = numeric_limits<float>::max();          float chi2ref = numeric_limits<float>::max();
1655                                    
# Line 880  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1660  TRefArray *TrkLevel2::GetTracks_NFitSort
1660              }              }
1661          }          }
1662          //second loop to search minimum chi2 among selected          //second loop to search minimum chi2 among selected
1663          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i<ntrk(); i++){
1664              Float_t chi2 = ((TrkTrack *)t[i])->chi2;              Float_t chi2 = ((TrkTrack *)t[i])->chi2;
1665              if(chi2 < 0) chi2 = chi2*1000;              if(chi2 < 0) chi2 = -chi2*1000;
1666              if(    chi2 < chi2ref              if(    chi2 < chi2ref
1667                     && ((TrkTrack *)t[i])->GetNtot() == nfit                     && ((TrkTrack *)t[i])->GetNtot() == nfit
1668                     && m[i]==1){                     && m[i]==1){
# Line 894  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1674  TRefArray *TrkLevel2::GetTracks_NFitSort
1674              m[((TrkTrack *)t[indi])->image] = 0;              m[((TrkTrack *)t[indi])->image] = 0;
1675              N--;              N--;
1676                    
1677              //      cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1678          };          };
1679          sorted->Add( (TrkTrack*)t[indi] );                sorted->Add( (TrkTrack*)t[indi] );      
1680                                    
1681          m[indi] = 0;          m[indi] = 0;
1682  //              cout << "SORTED "<< indo << " "<< indi << " "<< N << endl;  //      cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl;
1683          N--;              N--;    
1684          indo++;          indo++;
1685      }      }
1686      m.clear();      m.clear();
1687  //      cout << "GetTracks_NFitSorted(it): Done"<< endl;  //    cout << "GetTracks_NFitSorted(it): Done"<< endl;
1688    
1689      return sorted;      return sorted;
1690  //    return PhysicalTrack;  //    return PhysicalTrack;
# Line 921  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1701  TRefArray *TrkLevel2::GetTracks_NFitSort
1701  TrkTrack *TrkLevel2::GetStoredTrack(int is){  TrkTrack *TrkLevel2::GetStoredTrack(int is){
1702    
1703      if(is >= this->ntrk()){      if(is >= this->ntrk()){
1704          cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl;          cout << "TrkTrack *TrkLevel2::GetStoredTrack(int) >> Track "<< is << "doen not exits! " << endl;
1705          cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl;          cout << "Stored tracks ntrk() = "<< this->ntrk() << endl;
1706          return 0;          return 0;
1707      }      }
1708      if(!Track){      if(!Track){
# Line 943  TrkTrack *TrkLevel2::GetStoredTrack(int Line 1723  TrkTrack *TrkLevel2::GetStoredTrack(int
1723  TrkSinglet *TrkLevel2::GetSingletX(int is){  TrkSinglet *TrkLevel2::GetSingletX(int is){
1724    
1725          if(is >= this->nclsx()){          if(is >= this->nclsx()){
1726                  cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;                  cout << "TrkSinglet *TrkLevel2::GetSingletX(int) >> Singlet "<< is << "doen not exits! " << endl;
1727                  cout << "                Stored x-singlets nclsx() = "<< this->nclsx() << endl;                  cout << "Stored x-singlets nclsx() = "<< this->nclsx() << endl;
1728                  return 0;                  return 0;
1729          }          }
1730          if(!SingletX)return 0;          if(!SingletX)return 0;
# Line 963  TrkSinglet *TrkLevel2::GetSingletX(int i Line 1743  TrkSinglet *TrkLevel2::GetSingletX(int i
1743  TrkSinglet *TrkLevel2::GetSingletY(int is){  TrkSinglet *TrkLevel2::GetSingletY(int is){
1744    
1745          if(is >= this->nclsy()){          if(is >= this->nclsy()){
1746                  cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;                  cout << "TrkSinglet *TrkLevel2::GetSingletY(int) >> Singlet "<< is << "doen not exits! " << endl;
1747                  cout << "                Stored y-singlets nclsy() = "<< this->nclsx() << endl;                  cout << "Stored y-singlets nclsx() = "<< this->nclsx() << endl;
1748                  return 0;                  return 0;
1749          }          }
1750          if(!SingletY)return 0;          if(!SingletY)return 0;
# Line 984  TrkSinglet *TrkLevel2::GetSingletY(int i Line 1764  TrkSinglet *TrkLevel2::GetSingletY(int i
1764  TrkTrack *TrkLevel2::GetTrack(int it){  TrkTrack *TrkLevel2::GetTrack(int it){
1765            
1766          if(it >= this->GetNTracks()){          if(it >= this->GetNTracks()){
1767                  cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;                  cout << "TrkTrack *TrkLevel2::GetTrack(int) >> Track "<< it << "does not exits! " << endl;
1768                  cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;                  cout << "Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1769                  return 0;                  return 0;
1770          }          }
1771                    
# Line 1022  Int_t TrkLevel2::GetNTracks(){ Line 1802  Int_t TrkLevel2::GetNTracks(){
1802  TrkTrack *TrkLevel2::GetTrackImage(int it){  TrkTrack *TrkLevel2::GetTrackImage(int it){
1803    
1804      if(it >= this->GetNTracks()){      if(it >= this->GetNTracks()){
1805          cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;          cout << "TrkTrack *TrkLevel2::GetTrackImage(int) >> Track "<< it << "does not exits! " << endl;
1806          cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;          cout << "Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1807          return 0;          return 0;
1808      }      }
1809                    
# Line 1032  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1812  TrkTrack *TrkLevel2::GetTrackImage(int i
1812      TrkTrack *track = (TrkTrack*)sorted->At(it);      TrkTrack *track = (TrkTrack*)sorted->At(it);
1813                    
1814      if(!track->HasImage()){      if(!track->HasImage()){
1815          cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;          cout << "TrkTrack *TrkLevel2::GetTrackImage(int) >> Track "<< it << "does not have image! " << endl;
1816          return 0;          return 0;
1817      }      }
1818      if(!Track)return 0;      if(!Track)return 0;
# Line 1054  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1834  TrkTrack *TrkLevel2::GetTrackImage(int i
1834   */   */
1835  void TrkLevel2::LoadField(TString path){  void TrkLevel2::LoadField(TString path){
1836  //  //
1837      strcpy(path_.path,path.Data());  //     strcpy(path_.path,path.Data());
1838      path_.pathlen = path.Length();  //     path_.pathlen = path.Length();
1839      path_.error   = 0;  //     path_.error   = 0;
1840      readb_();  //     readb_();
1841    
1842    //     TrkParams::SetTrackingMode();
1843    //     TrkParams::SetPrecisionFactor();
1844    //     TrkParams::SetStepMin();
1845        TrkParams::SetMiniDefault();
1846    
1847        TrkParams::Set(path,1);
1848        TrkParams::Load(1);
1849    
1850  //  //
1851  };  };
1852    // /**
1853    //  * Get BY (kGauss)
1854    //  * @param v (x,y,z) coordinates in cm
1855    //  */
1856    // float TrkLevel2::GetBX(float* v){
1857    //     float b[3];
1858    //     gufld_(v,b);
1859    //     return b[0]/10.;
1860    // }
1861    // /**
1862    //  * Get BY (kGauss)
1863    //  * @param v (x,y,z) coordinates in cm
1864    //  */
1865    // float TrkLevel2::GetBY(float* v){
1866    //     float b[3];
1867    //     gufld_(v,b);
1868    //     return b[1]/10.;
1869    // }
1870    // /**
1871    //  * Get BY (kGauss)
1872    //  * @param v (x,y,z) coordinates in cm
1873    //  */
1874    // float TrkLevel2::GetBZ(float* v){
1875    //     float b[3];
1876    //     gufld_(v,b);
1877    //     return b[2]/10.;
1878    // }
1879  //--------------------------------------  //--------------------------------------
1880  //  //
1881  //  //
# Line 1237  int Trajectory::DoTrack2(float* al){ Line 2053  int Trajectory::DoTrack2(float* al){
2053      for (int i=0; i<5; i++)      dal[i]  = (double)al[i];      for (int i=0; i<5; i++)      dal[i]  = (double)al[i];
2054      for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];      for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
2055    
2056        TrkParams::Load(1);
2057        if( !TrkParams::IsLoaded(1) ){
2058            cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;
2059            return 0;
2060        }
2061      dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);      dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
2062            
2063      for (int i=0; i<npoint; i++){      for (int i=0; i<npoint; i++){

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.43

  ViewVC Help
Powered by ViewVC 1.1.23