/[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.21 by pam-fi, Thu Jan 11 10:20:58 2007 UTC revision 1.35 by pam-fi, Thu May 24 14:32:14 2007 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 47  TrkTrack::TrkTrack(){ Line 53  TrkTrack::TrkTrack(){
53          dedx_x[ip] = 0;          dedx_x[ip] = 0;
54          dedx_y[ip] = 0;          dedx_y[ip] = 0;
55      };      };
56      clx = 0;  //    clx = 0;
57      cly = 0;  //    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  //  //
# Line 71  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 79  TrkTrack::TrkTrack(const TrkTrack& t){ Line 97  TrkTrack::TrkTrack(const TrkTrack& t){
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 = new TRefArray(*(t.clx));  //    clx = 0;
101      cly = new TRefArray(*(t.cly));  //    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  //  //
# Line 105  void TrkTrack::Copy(TrkTrack& t){ Line 132  void TrkTrack::Copy(TrkTrack& t){
132          t.zm[ip]     = zm[ip];          t.zm[ip]     = zm[ip];
133          t.resx[ip]   = resx[ip];          t.resx[ip]   = resx[ip];
134          t.resy[ip]   = resy[ip];          t.resy[ip]   = resy[ip];
135            t.tailx[ip]  = tailx[ip];
136            t.taily[ip]  = taily[ip];
137          t.xv[ip]     = xv[ip];          t.xv[ip]     = xv[ip];
138          t.yv[ip]     = yv[ip];          t.yv[ip]     = yv[ip];
139          t.zv[ip]     = zv[ip];          t.zv[ip]     = zv[ip];
# Line 114  void TrkTrack::Copy(TrkTrack& t){ Line 143  void TrkTrack::Copy(TrkTrack& t){
143          t.dedx_y[ip] = dedx_y[ip];          t.dedx_y[ip] = dedx_y[ip];
144                            
145      };      };
146    
147    //    t.clx = TRefArray(clx);
148    //    t.cly = TRefArray(cly);
149            
150  };  };
151  //--------------------------------------  //--------------------------------------
# Line 139  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 178  int TrkTrack::DoTrack2(Trajectory* t){ Line 215  int TrkTrack::DoTrack2(Trajectory* t){
215      for (int i=0; i<5; i++)         dal[i]  = (double)al[i];      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];      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);      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
224            
225      for (int i=0; i<t->npoint; i++){      for (int i=0; i<t->npoint; i++){
# Line 217  Float_t TrkTrack::GetDeflection(){ Line 259  Float_t TrkTrack::GetDeflection(){
259          return def;          return def;
260  };  };
261  //  //
262  Float_t TrkTrack::GetDEDX(){  /**
263          Float_t dedx=0;   * Method to retrieve the dE/dx measured on a tracker view.
264          for(Int_t i=0; i<6; i++)dedx+=dedx_x[i]*xgood[i]+dedx_y[i]*ygood[i];   * @param ip plane (0-5)
265          dedx = dedx/(this->GetNX()+this->GetNY());   * @param iv view (0=x 1=y)
266          return dedx;   */
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(){
289        Float_t dedx=0;
290        for(Int_t ip=0; ip<6; ip++)dedx+=GetDEDX(ip,0)*XGood(ip)+GetDEDX(ip,1)*YGood(ip);
291        dedx = dedx/(GetNX()+GetNY());
292        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  //  //
370  //  //
# Line 235  void TrkTrack::Dump(){ Line 376  void TrkTrack::Dump(){
376      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] << " ";
377      cout << endl << "chi^2    : "<< chi2;      cout << endl << "chi^2    : "<< chi2;
378      cout << endl << "n.step   : "<< nstep;      cout << endl << "n.step   : "<< nstep;
379      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) ;
380      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) ;
381      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] << " ";
382      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] << " ";
383      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 245  void TrkTrack::Dump(){ Line 386  void TrkTrack::Dump(){
386      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] << " ";
387      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] << " ";
388      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] << " ";
389        cout << endl << "tailx    : "; for(int i=0; i<6; i++)cout << tailx[i] << " ";
390        cout << endl << "taily    : "; for(int i=0; i<6; i++)cout << taily[i] << " ";
391      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]<<" ";
392      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]<<" ";
393      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 270  void TrkTrack::SetResolution(double *rx, Line 413  void TrkTrack::SetResolution(double *rx,
413      for(int i=0; i<6; i++) resy[i]=*ry++;      for(int i=0; i<6; i++) resy[i]=*ry++;
414  }  }
415  /**  /**
416     * Set the TrkTrack tails position resolution
417     */
418    void TrkTrack::SetTail(double *tx, double *ty, double factor){
419        for(int i=0; i<6; i++) tailx[i]=factor*(*tx++);
420        for(int i=0; i<6; i++) taily[i]=factor*(*ty++);
421    }
422    /**
423     * Set the TrkTrack Student parameter (resx,resy,tailx,taily)
424     * from previous gausian fit
425     *@param flag =0 standard, =1 with noise correction
426     */
427    void TrkTrack::SetStudentParam(int flag){
428        float sx[11]={0.000128242,
429                       0.000136942,
430                       0.000162718,
431                       0.000202644,
432                       0.00025597,
433                       0.000317456,
434                       0.000349048,
435                       0.000384638,
436                       0.000457295,
437                       0.000512319,
438                       0.000538573};
439        float tx[11]={1.79402,
440                       2.04876,
441                       2.88376,
442                       3.3,
443                       3.14084,
444                       4.07686,
445                       4.44736,
446                       3.5179,
447                       3.38697,
448                       3.45739,
449                       3.18627};
450        float sy[11]={0.000483075,
451                       0.000466925,
452                       0.000431658,
453                       0.000428317,
454                       0.000433854,
455                       0.000444044,
456                       0.000482098,
457                       0.000537579,
458                       0.000636279,
459                       0.000741998,
460                       0.000864261};
461        float ty[11]={0.997032,
462                       1.11147,
463                       1.18526,
464                       1.61404,
465                       2.21908,
466                       3.08959,
467                       4.48833,
468                       4.42687,
469                       4.65253,
470                       4.52043,
471                       4.29926};
472        int index;
473        float fact;
474        for(int i=0; i<6; i++) {
475            index = int((fabs(axv[i])+1.)/2.);
476            if(index>10) index=10;
477            tailx[i]=tx[index];
478            if(flag==1) {
479                if(fabs(axv[i])<=10.) fact = resx[i]/risxeta2_(&(axv[i]));
480                if(fabs(axv[i])>10.&&fabs(axv[i])<=15.) fact = resx[i]/risxeta3_(&(axv[i]));
481                if(fabs(axv[i])>15.) fact = resx[i]/risxeta4_(&(axv[i]));
482            } else fact = 1.;
483            resx[i] = sx[index]*fact;
484        }
485        for(int i=0; i<6; i++) {
486            index = int((fabs(ayv[i])+1.)/2.);
487            if(index>10) index=10;
488            taily[i]=ty[index];
489            if(flag==1) fact = resy[i]/risyeta2_(&(ayv[i]));
490            else fact = 1.;
491            resy[i] = sy[index]*fact;
492        }
493    }
494    /**
495   * Set the TrkTrack good measurement   * Set the TrkTrack good measurement
496   */   */
497  void TrkTrack::SetGood(int *xg, int *yg){  void TrkTrack::SetGood(int *xg, int *yg){
498    
499      for(int i=0; i<6; i++) xgood[i]=*xg++;      for(int i=0; i<6; i++) xgood[i]=*xg++;
500      for(int i=0; i<6; i++) ygood[i]=*yg++;      for(int i=0; i<6; i++) ygood[i]=*yg++;
501  }  }
# Line 282  void TrkTrack::SetGood(int *xg, int *yg) Line 505  void TrkTrack::SetGood(int *xg, int *yg)
505   */   */
506  void TrkTrack::LoadField(TString path){  void TrkTrack::LoadField(TString path){
507            
508      strcpy(path_.path,path.Data());  //     strcpy(path_.path,path.Data());
509      path_.pathlen = path.Length();  //     path_.pathlen = path.Length();
510      path_.error   = 0;  //     path_.error   = 0;
511      readb_();  //     readb_();
512    
513        TrkParams::SetTrackingMode();
514        TrkParams::SetPrecisionFactor();
515        TrkParams::SetStepMin();
516    
517        TrkParams::Set(path,1);
518        TrkParams::Load(1);
519    
520  };  };
521    
522    
523  /**  /**
524   * Method to fill minimization-routine common   * Method to fill minimization-routine common
525   */   */
# Line 296  void TrkTrack::FillMiniStruct(cMini2trac Line 527  void TrkTrack::FillMiniStruct(cMini2trac
527    
528      for(int i=0; i<6; i++){      for(int i=0; i<6; i++){
529    
530          track.xgood[i]=xgood[i];  //      cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl;
531          track.ygood[i]=ygood[i];  //      cout << i<<" - "<<ygood[i]<<" "<<YGood(i)<<endl;
532            track.xgood[i]=XGood(i);
533            track.ygood[i]=YGood(i);
534                    
535          track.xm[i]=xm[i];          track.xm[i]=xm[i];
536          track.ym[i]=ym[i];          track.ym[i]=ym[i];
# Line 310  void TrkTrack::FillMiniStruct(cMini2trac Line 543  void TrkTrack::FillMiniStruct(cMini2trac
543          track.xm_b[i]=xm[i];          track.xm_b[i]=xm[i];
544          track.ym_a[i]=ym[i];          track.ym_a[i]=ym[i];
545          track.ym_b[i]=ym[i];          track.ym_b[i]=ym[i];
546          if(       xgood[i] && !ygood[i] ){          if(       XGood(i) && !YGood(i) ){
547              track.ym_a[i] = track.ym_a[i]+segment;              track.ym_a[i] = track.ym_a[i]+segment;
548              track.ym_b[i] = track.ym_b[i]-segment;              track.ym_b[i] = track.ym_b[i]-segment;
549          }else if( !xgood[i] && ygood[i]){          }else if( !XGood(i) && YGood(i)){
550              track.xm_a[i] = track.xm_a[i]+segment;              track.xm_a[i] = track.xm_a[i]+segment;
551              track.xm_b[i] = track.xm_b[i]-segment;              track.xm_b[i] = track.xm_b[i]-segment;
552          }          }
# Line 321  void TrkTrack::FillMiniStruct(cMini2trac Line 554  void TrkTrack::FillMiniStruct(cMini2trac
554                    
555          track.resx[i]=resx[i];          track.resx[i]=resx[i];
556          track.resy[i]=resy[i];          track.resy[i]=resy[i];
557            track.tailx[i]=tailx[i];
558            track.taily[i]=taily[i];
559      }      }
560    
561      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 349  void TrkTrack::SetFromMiniStruct(cMini2t Line 584  void TrkTrack::SetFromMiniStruct(cMini2t
584          axv[i] = track->axv[i];          axv[i] = track->axv[i];
585          ayv[i] = track->ayv[i];          ayv[i] = track->ayv[i];
586      }      }
587        
588    }
589    /**
590     * \brief Method to re-evaluate coordinates of clusters associated with a track.
591     *
592     * The method can be applied only after recovering level1 information
593     * (either by reprocessing single events from level0 or from  
594     * the TrkLevel1 branch, if present); it calls F77 subroutines that
595     * read the level1 common and fill the minimization-routine common.
596     * Some clusters can be excluded or added by means of the methods:
597     *
598     * TrkTrack::ResetXGood(int ip)
599     * TrkTrack::ResetYGood(int ip)
600     * TrkTrack::SetXGood(int ip, int cid, int is)
601     * TrkTrack::SetYGood(int ip, int cid, int is)
602     *
603     * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1)
604     * for the minimization-routine common. It deletes the cluster information
605     * (at least for the moment...) thus cannot be applied before
606     * TrkTrack::EvaluateClusterPositions().  
607     *
608     * Different p.f.a. can be applied by calling (once) the method:
609     *
610     * TrkParams::SetPFA(0); //Set ETA p.f.a.
611     *
612     * @see TrkParams::SetPFA(int)
613     */
614    void TrkTrack::EvaluateClusterPositions(){
615        
616    //     cout << "void TrkTrack::GetClusterPositions() "<<endl;
617    
618        TrkParams::Load( );
619        if( !TrkParams::IsLoaded() )return;
620            
621        for(int ip=0; ip<6; ip++){
622    //      cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;
623            int icx = GetClusterX_ID(ip)+1;
624            int icy = GetClusterY_ID(ip)+1;
625            int sensor = GetSensor(ip)+1;//<< convenzione "Paolo"
626            if(ip==5 && sensor!=0)sensor=3-sensor;//<< convenzione "Elena"
627            int ladder = GetLadder(ip)+1;
628            float ax = axv[ip];
629            float ay = ayv[ip];
630            float v[3];
631            v[0]=xv[ip];
632            v[1]=yv[ip];
633            v[2]=zv[ip];
634            float bfx = 10*TrkParams::GetBX(v);//Tesla
635            float bfy = 10*TrkParams::GetBY(v);//Tesla
636            int ipp=ip+1;
637            xyzpam_(&ipp,&icx,&icy,&ladder,&sensor,&ax,&ay,&bfx,&bfy);
638        }
639  }  }
640  /**  /**
641   * Tracking method. It calls F77 mini routine.   * \brief Tracking method. It calls F77 mini routine.
642     *
643     * @param pfixed Particle momentum. If pfixed=0 the momentum
644     * is left as a free parameter, otherwise it is fixed to the input value.
645     * @param fail Output flag (!=0 if the fit failed).
646     * @param iprint Flag to set debug mode ( 0 = no output; 1 = verbose; 2 = debug).
647     * @param froml1 Flag to re-evaluate positions (see TrkTrack::GetClusterPositions()).
648     *
649     * The option to re-evaluate positions can be used only after recovering
650     * level1 information, eg. by reprocessing the single event.
651     *
652     * Example:
653     *
654     * if( !event->GetTrkLevel0() )return false;
655     * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1
656     * int fail=0;
657     * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1);
658     *
659     * @see EvaluateClusterPositions()
660     *
661     * The fitting procedure can be varied by changing the tracking mode,
662     * the fit-precision factor and the minimum number of step.
663     * @see SetTrackingMode(int)
664     * @see SetPrecisionFactor(double)
665     * @see SetStepMin(int)
666   */   */
667  void TrkTrack::Fit(double pfixed, int& fail, int iprint){  void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
668    
669      float al_ini[] = {0.,0.,0.,0.,0.};      float al_ini[] = {0.,0.,0.,0.,0.};
670    
671        TrkParams::Load( );
672        if( !TrkParams::IsLoaded() )return;
673    
674      extern cMini2track track_;      extern cMini2track track_;
675      fail = 0;      fail = 0;
676      FillMiniStruct(track_);      FillMiniStruct(track_);
677        
678        if(froml1!=0)EvaluateClusterPositions();
679        
680      // if fit variables have been reset, evaluate the initial guess      // if fit variables have been reset, evaluate the initial guess
681      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_();
682    
# Line 381  void TrkTrack::Fit(double pfixed, int& f Line 695  void TrkTrack::Fit(double pfixed, int& f
695    
696      //  ------------------------------------------      //  ------------------------------------------
697      //  call mini routine      //  call mini routine
698    //     TrkParams::Load(1);
699    //     if( !TrkParams::IsLoaded(1) ){
700    //      cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl;
701    //      return;
702    //     }
703      int istep=0;      int istep=0;
704      int ifail=0;      int ifail=0;
705      mini2_(&istep,&ifail, &iprint);      mini2_(&istep,&ifail, &iprint);
# Line 391  void TrkTrack::Fit(double pfixed, int& f Line 710  void TrkTrack::Fit(double pfixed, int& f
710      //  ------------------------------------------      //  ------------------------------------------
711            
712      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];  
 //     }  
713    
714      if(fail){      if(fail){
715          if(iprint)cout << " >>>> fit failed >>>> drawing initial par"<<endl;          if(iprint)cout << " >>>> fit failed "<<endl;
716          for(int i=0; i<5; i++) al[i]=al_ini[i];          for(int i=0; i<5; i++) al[i]=al_ini[i];
717      }      }
718    
719  };  };
720  /*  /**
721   * Reset the fit parameters   * Reset the fit parameters
722   */   */
723  void TrkTrack::FitReset(){  void TrkTrack::FitReset(){
724      for(int i=0; i<5; i++) al[i]=-9999.;      for(int i=0; i<5; i++) al[i]=-9999.;
725      chi2=0.;      chi2=0.;
726      nstep=0;      nstep=0;
727      for(int i=0; i<6; i++) xv[i]=0.;  //     for(int i=0; i<6; i++) xv[i]=0.;
728      for(int i=0; i<6; i++) yv[i]=0.;  //     for(int i=0; i<6; i++) yv[i]=0.;
729      for(int i=0; i<6; i++) zv[i]=0.;  //     for(int i=0; i<6; i++) zv[i]=0.;
730      for(int i=0; i<6; i++) axv[i]=0.;  //     for(int i=0; i<6; i++) axv[i]=0.;
731      for(int i=0; i<6; i++) ayv[i]=0.;  //     for(int i=0; i<6; i++) ayv[i]=0.;
732      for(int i=0; i<5; i++) {      for(int i=0; i<5; i++) {
733          for(int j=0; j<5; j++) coval[i][j]=0.;          for(int j=0; j<5; j++) coval[i][j]=0.;
734      }      }
735  }  }
736    /**
737     * Set the tracking mode
738     */
739    void TrkTrack::SetTrackingMode(int trackmode){
740        extern cMini2track track_;
741        track_.trackmode = trackmode;
742    }
743    /**
744     * Set the factor scale for tracking precision
745     */
746    void TrkTrack::SetPrecisionFactor(double fact){
747        extern cMini2track track_;
748        track_.fact = fact;
749    }
750    /**
751     * Set the minimum number of steps for tracking precision
752     */
753    void TrkTrack::SetStepMin(int istepmin){
754        extern cMini2track track_;
755        track_.istepmin = istepmin;
756    }
757    /**
758     * Returns 1 if the track is inside the magnet cavity
759     * Set the minimum number of steps for tracking precision
760     */
761    Bool_t TrkTrack::IsInsideCavity(){
762        float xmagntop, ymagntop, xmagnbottom, ymagnbottom;
763        xmagntop = xv[0] + (ZMAGNHIGH-zv[0])*tan(cos(-1.0)*axv[0]/180.);
764        ymagntop = yv[0] + (ZMAGNHIGH-zv[0])*tan(cos(-1.0)*ayv[0]/180.);
765        xmagnbottom = xv[5] + (ZMAGNLOW-zv[5])*tan(cos(-1.0)*axv[5]/180.);
766        ymagnbottom = yv[5] + (ZMAGNLOW-zv[5])*tan(cos(-1.0)*ayv[5]/180.);
767        if( xmagntop>XMAGNLOW && xmagntop<XMAGNHIGH &&
768            ymagntop>YMAGNLOW && ymagntop<YMAGNHIGH &&
769            xmagnbottom>XMAGNLOW && xmagnbottom<XMAGNHIGH &&
770            ymagnbottom>YMAGNLOW && ymagnbottom<YMAGNHIGH ) return(true);
771        else return(false);
772    }
773    /**
774     * Method to retrieve ID (0,1,...) of x-cluster (if any) associated to this track.
775     * If no cluster is associated, ID=-1.
776     * @param ip Tracker plane (0-5)
777     */
778    Int_t TrkTrack::GetClusterX_ID(int ip){
779        return ((Int_t)fabs(xgood[ip]))%10000000-1;
780    };
781    /**
782     * Method to retrieve ID (0-xxx) of y-cluster (if any) associated to this track.
783     * If no cluster is associated, ID=-1.
784     * @param ip Tracker plane (0-5)
785     */
786    Int_t TrkTrack::GetClusterY_ID(int ip){
787        return ((Int_t)fabs(ygood[ip]))%10000000-1;
788    };
789    /**
790     * Method to retrieve the ladder (0-4, increasing x) traversed by the track on this plane.
791     * If no ladder is traversed (dead area) the metod retuns -1.
792     * @param ip Tracker plane (0-5)
793     */
794    Int_t TrkTrack::GetLadder(int ip){
795        if(XGood(ip))return (Int_t)fabs(xgood[ip]/100000000)-1;
796        if(YGood(ip))return (Int_t)fabs(ygood[ip]/100000000)-1;
797        return -1;
798    };
799    /**
800     * Method to retrieve the sensor (0-1, increasing y) traversed by the track on this plane.
801     * If no sensor is traversed (dead area) the metod retuns -1.
802     * @param ip Tracker plane (0-5)
803     */
804    Int_t TrkTrack::GetSensor(int ip){
805        if(XGood(ip))return (Int_t)((Int_t)fabs(xgood[ip]/10000000)%10)-1;
806        if(YGood(ip))return (Int_t)((Int_t)fabs(ygood[ip]/10000000)%10)-1;
807        return -1;
808    };
809    
810    /**
811     * \brief Method to include a x-cluster to the track.
812     * @param ip Tracker plane (0-5)
813     * @param clid Cluster ID (0,1,...)
814     * @param is Sensor (0-1, increasing y)
815     * @see Fit(double pfixed, int& fail, int iprint, int froml1)
816     */
817    void TrkTrack::SetXGood(int ip, int clid, int is){
818        int il=0;       //ladder (temporary)
819        bool bad=false; //ladder (temporary)
820        xgood[ip]=il*100000000+is*10000000+clid;
821        if(bad)xgood[ip]=-xgood[ip];
822    };
823    /**
824     * \brief Method to include a y-cluster to the track.
825     * @param ip Tracker plane (0-5)
826     * @param clid Cluster ID (0,1,...)
827     * @param is Sensor (0-1)
828     * @see Fit(double pfixed, int& fail, int iprint, int froml1)
829     */
830    void TrkTrack::SetYGood(int ip, int clid, int is){
831        int il=0;       //ladder (temporary)
832        bool bad=false; //ladder (temporary)
833        ygood[ip]=il*100000000+is*10000000+clid;
834        if(bad)ygood[ip]=-ygood[ip];
835    };
836    
837  //--------------------------------------  //--------------------------------------
838  //  //
# Line 450  void TrkTrack::Clear(){ Line 856  void TrkTrack::Clear(){
856          zm[ip]     = 0;          zm[ip]     = 0;
857          resx[ip]   = 0;          resx[ip]   = 0;
858          resy[ip]   = 0;          resy[ip]   = 0;
859            tailx[ip]  = 0;
860            taily[ip]  = 0;
861          xv[ip]     = 0;          xv[ip]     = 0;
862          yv[ip]     = 0;          yv[ip]     = 0;
863          zv[ip]     = 0;          zv[ip]     = 0;
# Line 459  void TrkTrack::Clear(){ Line 867  void TrkTrack::Clear(){
867          dedx_y[ip] = 0;          dedx_y[ip] = 0;
868    
869      };      };
870      if(clx)clx->Clear();  //     if(clx)clx->Clear();
871      if(cly)cly->Clear();  //     if(cly)cly->Clear();
872    //    clx.Clear();
873    //    cly.Clear();
874  };  };
875  //--------------------------------------  //--------------------------------------
876  //  //
# Line 468  void TrkTrack::Clear(){ Line 878  void TrkTrack::Clear(){
878  //--------------------------------------  //--------------------------------------
879  void TrkTrack::Delete(){  void TrkTrack::Delete(){
880  //    cout << "TrkTrack::Delete()"<<endl;  //    cout << "TrkTrack::Delete()"<<endl;
881  //    Clear();      Clear();
882      if(clx)delete clx;  //    if(clx)delete clx;
883      if(cly)delete cly;  //    if(cly)delete cly;
884  };  };
885  //--------------------------------------  //--------------------------------------
886  //  //
# Line 500  TrkSinglet::TrkSinglet(const TrkSinglet& Line 910  TrkSinglet::TrkSinglet(const TrkSinglet&
910      coord[1] = s.coord[1];      coord[1] = s.coord[1];
911      sgnl     = s.sgnl;      sgnl     = s.sgnl;
912  //      cls      = 0;//<<<<pointer  //      cls      = 0;//<<<<pointer
913      cls      = TRef(s.cls);  //    cls      = TRef(s.cls);
914  };  };
915  //--------------------------------------  //--------------------------------------
916  //  //
# Line 531  void TrkSinglet::Clear(){ Line 941  void TrkSinglet::Clear(){
941  //  //
942  //--------------------------------------  //--------------------------------------
943  TrkLevel2::TrkLevel2(){  TrkLevel2::TrkLevel2(){
944  //    cout <<"TrkLevel2::TrkLevel2()"<<endl;    //    cout <<"TrkLevel2::TrkLevel2()"<<endl;
945      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
946                  good[i] = -1;          good[i] = -1;
947          };          VKmask[i] = 0;
948  //    Track    = new TClonesArray("TrkTrack");          VKflag[i] = 0;  
949  //    SingletX = new TClonesArray("TrkSinglet");      };
 //    SingletY = new TClonesArray("TrkSinglet");  
950      Track    = 0;      Track    = 0;
951      SingletX = 0;      SingletX = 0;
952      SingletY = 0;      SingletY = 0;
# Line 547  TrkLevel2::TrkLevel2(){ Line 956  TrkLevel2::TrkLevel2(){
956  //  //
957  //  //
958  //--------------------------------------  //--------------------------------------
959    void TrkLevel2::Set(){
960        if(!Track)Track    = new TClonesArray("TrkTrack");
961        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
962        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
963    }
964    //--------------------------------------
965    //
966    //
967    //--------------------------------------
968  void TrkLevel2::Dump(){  void TrkLevel2::Dump(){
969                    
970          //          //
# Line 555  void TrkLevel2::Dump(){ Line 973  void TrkLevel2::Dump(){
973      cout << endl << "ntrk()   : " << this->ntrk() ;      cout << endl << "ntrk()   : " << this->ntrk() ;
974      cout << endl << "nclsx()  : " << this->nclsx();      cout << endl << "nclsx()  : " << this->nclsx();
975      cout << endl << "nclsy()  : " << this->nclsy();      cout << endl << "nclsy()  : " << this->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();  
976      if(Track){      if(Track){
977          TClonesArray &t  = *Track;          TClonesArray &t  = *Track;
978          for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();          for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();
# Line 579  void TrkLevel2::Dump(){ Line 991  void TrkLevel2::Dump(){
991  //  //
992  //--------------------------------------  //--------------------------------------
993  /**  /**
994   * 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  
995     * either apriori ,on the basis of the mask read from the DB,
996     * or run-by-run, on the basis of the calibration parameters)
997     * @param iv Tracker view (0-11)
998     * @param ivk Viking-chip number (0-23)
999     */
1000    Bool_t TrkLevel2::GetVKMask(int iv, int ivk){
1001        Int_t whichbit = (Int_t)pow(2,ivk);
1002        return (whichbit&VKmask[iv])!=0;    
1003    }
1004    /**
1005     * The method returns false if the viking-chip was masked  
1006     * for this event due to common-noise computation failure.
1007     * @param iv Tracker view (0-11)
1008     * @param ivk Viking-chip number (0-23)
1009     */
1010    Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){
1011        Int_t whichbit = (Int_t)pow(2,ivk);
1012        return (whichbit&VKflag[iv])!=0;    
1013    }
1014    /**
1015     * The method returns true if the viking-chip was masked, either
1016     * forced (see TrkLevel2::GetVKMask(int,int)) or
1017     * for this event only (TrkLevel2::GetVKFlag(int,int)).
1018     * @param iv Tracker view (0-11)
1019     * @param ivk Viking-chip number (0-23)
1020   */   */
1021  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){  Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){
1022        return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) );
1023    };
1024    
1025          //  temporary objects:  //--------------------------------------
1026    //
1027    //
1028    //--------------------------------------
1029    /**
1030     * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
1031     * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set.
1032     * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch)
1033     */
1034    void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
1035    
1036    //    cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl;
1037        Clear();
1038    
1039    //  temporary objects:
1040      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
1041      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
1042    
1043          //  **** general variables ****  //  -----------------
1044  //    good2 = l2->good2;  //  general variables
1045    //  -----------------
1046      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1047  //              crc[i] = l2->crc[i];          good[i] = l2->good[i];
1048                  good[i] = l2->good[i];          VKmask[i]=0;
1049            VKflag[i]=0;
1050            for(Int_t ii=0; ii<24 ; ii++){
1051                Int_t setbit = (Int_t)pow(2,ii);
1052                if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit;
1053                if( l2->vkflag[ii][i]!=0  )VKflag[i]=VKflag[i]|setbit;
1054          };          };
1055          //  *** TRACKS ***      };
1056    //  --------------
1057    //  *** TRACKS ***
1058    //  --------------
1059      if(!Track) Track = new TClonesArray("TrkTrack");      if(!Track) Track = new TClonesArray("TrkTrack");
1060      TClonesArray &t = *Track;      TClonesArray &t = *Track;
1061    
1062      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
1063          t_track->seqno = i;// NBNBNBNB deve sempre essere = i          t_track->seqno = i;// NBNBNBNB deve sempre essere = i
1064          t_track->image = l2->image[i]-1;          t_track->image = l2->image[i]-1;
         //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;  
1065          t_track->chi2  = l2->chi2_nt[i];          t_track->chi2  = l2->chi2_nt[i];
1066          t_track->nstep = l2->nstep_nt[i];          t_track->nstep = l2->nstep_nt[i];
1067          for(int it1=0;it1<5;it1++){          for(int it1=0;it1<5;it1++){
# Line 608  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1070  void TrkLevel2::SetFromLevel2Struct(cTrk
1070                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];
1071          };          };
1072          for(int ip=0;ip<6;ip++){          for(int ip=0;ip<6;ip++){
1073              t_track->xgood[ip]  = l2->xgood_nt[i][ip];              // ---------------------------------
1074              t_track->ygood[ip]  = l2->ygood_nt[i][ip];              // new implementation of xgood/ygood
1075                // ---------------------------------
1076                t_track->xgood[ip]  = l2->cltrx[i][ip]; //cluster ID
1077                t_track->ygood[ip]  = l2->cltry[i][ip]; //cluster ID
1078                t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1079                t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1080                if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip];
1081                if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip];
1082    //          if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){
1083    //          if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){
1084    //              cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl;
1085    //              cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl;
1086    //              cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl;
1087    //              cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl;
1088    //              cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl;
1089    //          }
1090              t_track->xm[ip]     = l2->xm_nt[i][ip];              t_track->xm[ip]     = l2->xm_nt[i][ip];
1091              t_track->ym[ip]     = l2->ym_nt[i][ip];              t_track->ym[ip]     = l2->ym_nt[i][ip];
1092              t_track->zm[ip]     = l2->zm_nt[i][ip];              t_track->zm[ip]     = l2->zm_nt[i][ip];
1093              t_track->resx[ip]   = l2->resx_nt[i][ip];              t_track->resx[ip]   = l2->resx_nt[i][ip];
1094              t_track->resy[ip]   = l2->resy_nt[i][ip];              t_track->resy[ip]   = l2->resy_nt[i][ip];
1095                t_track->tailx[ip]  = l2->tailx[i][ip];
1096                t_track->taily[ip]  = l2->taily[i][ip];
1097              t_track->xv[ip]     = l2->xv_nt[i][ip];              t_track->xv[ip]     = l2->xv_nt[i][ip];
1098              t_track->yv[ip]     = l2->yv_nt[i][ip];              t_track->yv[ip]     = l2->yv_nt[i][ip];
1099              t_track->zv[ip]     = l2->zv_nt[i][ip];              t_track->zv[ip]     = l2->zv_nt[i][ip];
# Line 622  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1101  void TrkLevel2::SetFromLevel2Struct(cTrk
1101              t_track->ayv[ip]    = l2->ayv_nt[i][ip];              t_track->ayv[ip]    = l2->ayv_nt[i][ip];
1102              t_track->dedx_x[ip] = l2->dedx_x[i][ip];              t_track->dedx_x[ip] = l2->dedx_x[i][ip];
1103              t_track->dedx_y[ip] = l2->dedx_y[i][ip];              t_track->dedx_y[ip] = l2->dedx_y[i][ip];
1104  //                      t_track->clx[ip] = 0;              //-----------------------------------------------------
1105  //                      t_track->cly[ip] = 0;              //-----------------------------------------------------
1106                //-----------------------------------------------------
1107                //-----------------------------------------------------
1108          };          };
1109    //      if(t_track->IsSaturated())t_track->Dump();
1110          new(t[i]) TrkTrack(*t_track);          new(t[i]) TrkTrack(*t_track);
1111          t_track->Clear();          t_track->Clear();
1112      };      };
1113    
1114    //  ----------------
1115  //  *** SINGLETS ***  //  *** SINGLETS ***
1116    //  ----------------
1117      if(!SingletX)SingletX = new TClonesArray("TrkSinglet");      if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1118      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
1119      for(int i=0; i<l2->nclsx; i++){      for(int i=0; i<l2->nclsx; i++){
# Line 636  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1121  void TrkLevel2::SetFromLevel2Struct(cTrk
1121          t_singlet->coord[0] = l2->xs[i][0];          t_singlet->coord[0] = l2->xs[i][0];
1122          t_singlet->coord[1] = l2->xs[i][1];          t_singlet->coord[1] = l2->xs[i][1];
1123          t_singlet->sgnl     = l2->signlxs[i];          t_singlet->sgnl     = l2->signlxs[i];
1124  //              t_singlet->cls      = 0;          //-----------------------------------------------------
1125    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);
1126            //-----------------------------------------------------
1127          new(sx[i]) TrkSinglet(*t_singlet);          new(sx[i]) TrkSinglet(*t_singlet);
1128          t_singlet->Clear();          t_singlet->Clear();
1129      }      }
# Line 647  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1134  void TrkLevel2::SetFromLevel2Struct(cTrk
1134          t_singlet->coord[0] = l2->ys[i][0];          t_singlet->coord[0] = l2->ys[i][0];
1135          t_singlet->coord[1] = l2->ys[i][1];          t_singlet->coord[1] = l2->ys[i][1];
1136          t_singlet->sgnl     = l2->signlys[i];          t_singlet->sgnl     = l2->signlys[i];
1137  //              t_singlet->cls      = 0;          //-----------------------------------------------------
1138    //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);
1139            //-----------------------------------------------------
1140          new(sy[i]) TrkSinglet(*t_singlet);          new(sy[i]) TrkSinglet(*t_singlet);
1141          t_singlet->Clear();          t_singlet->Clear();
1142      };      };
# Line 655  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1144  void TrkLevel2::SetFromLevel2Struct(cTrk
1144      delete t_track;      delete t_track;
1145      delete t_singlet;      delete t_singlet;
1146  }  }
 //--------------------------------------  
 //  
 //  
 //--------------------------------------  
 /**  
  * 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;  
 }  
1147  /**  /**
1148   * 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).
1149   */   */
# Line 779  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 1170  void TrkLevel2::GetLevel2Struct(cTrkLeve
1170                      l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];                      l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
1171              };              };
1172              for(int ip=0;ip<6;ip++){              for(int ip=0;ip<6;ip++){
1173                  l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip];                  l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip);
1174                  l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip];                  l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip);
1175                  l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];                  l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];
1176                  l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];                  l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];
1177                  l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];                  l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];
1178                  l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];                  l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];
1179                  l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];                  l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];
1180                    l2->tailx[i][ip]  = ((TrkTrack *)Track->At(i))->tailx[ip];
1181                    l2->taily[i][ip]  = ((TrkTrack *)Track->At(i))->taily[ip];
1182                  l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];                  l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];
1183                  l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];                  l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];
1184                  l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];                  l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];
# Line 824  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 1217  void TrkLevel2::GetLevel2Struct(cTrkLeve
1217  void TrkLevel2::Clear(){  void TrkLevel2::Clear(){
1218      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
1219          good[i] = -1;          good[i] = -1;
1220            VKflag[i] = 0;
1221            VKmask[i] = 0;
1222      };      };
1223  //    if(Track)Track->Clear("C");  //    if(Track)Track->Clear("C");
1224  //    if(SingletX)SingletX->Clear("C");  //    if(SingletX)SingletX->Clear("C");
# Line 867  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1262  TRefArray *TrkLevel2::GetTracks_NFitSort
1262                    
1263      int indo=0;      int indo=0;
1264      int indi=0;      int indi=0;
1265      while(N != 0){      while(N > 0){
1266    //    while(N != 0){
1267          int nfit =0;          int nfit =0;
1268          float chi2ref = numeric_limits<float>::max();          float chi2ref = numeric_limits<float>::max();
1269                                    
# Line 878  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1274  TRefArray *TrkLevel2::GetTracks_NFitSort
1274              }              }
1275          }          }
1276          //second loop to search minimum chi2 among selected          //second loop to search minimum chi2 among selected
1277          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i<ntrk(); i++){
1278              Float_t chi2 = ((TrkTrack *)t[i])->chi2;              Float_t chi2 = ((TrkTrack *)t[i])->chi2;
1279              if(chi2 < 0) chi2 = chi2*1000;              if(chi2 < 0) chi2 = -chi2*1000;
1280              if(    chi2 < chi2ref              if(    chi2 < chi2ref
1281                     && ((TrkTrack *)t[i])->GetNtot() == nfit                     && ((TrkTrack *)t[i])->GetNtot() == nfit
1282                     && m[i]==1){                     && m[i]==1){
# Line 892  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1288  TRefArray *TrkLevel2::GetTracks_NFitSort
1288              m[((TrkTrack *)t[indi])->image] = 0;              m[((TrkTrack *)t[indi])->image] = 0;
1289              N--;              N--;
1290                    
1291              //      cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1292          };          };
1293          sorted->Add( (TrkTrack*)t[indi] );                sorted->Add( (TrkTrack*)t[indi] );      
1294                                    
1295          m[indi] = 0;          m[indi] = 0;
1296  //              cout << "SORTED "<< indo << " "<< indi << " "<< N << endl;  //      cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl;
1297          N--;              N--;    
1298          indo++;          indo++;
1299      }      }
1300      m.clear();      m.clear();
1301  //      cout << "GetTracks_NFitSorted(it): Done"<< endl;  //    cout << "GetTracks_NFitSorted(it): Done"<< endl;
1302    
1303      return sorted;      return sorted;
1304  //    return PhysicalTrack;  //    return PhysicalTrack;
# Line 1052  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1448  TrkTrack *TrkLevel2::GetTrackImage(int i
1448   */   */
1449  void TrkLevel2::LoadField(TString path){  void TrkLevel2::LoadField(TString path){
1450  //  //
1451      strcpy(path_.path,path.Data());  //     strcpy(path_.path,path.Data());
1452      path_.pathlen = path.Length();  //     path_.pathlen = path.Length();
1453      path_.error   = 0;  //     path_.error   = 0;
1454      readb_();  //     readb_();
1455    
1456        TrkParams::SetTrackingMode();
1457        TrkParams::SetPrecisionFactor();
1458        TrkParams::SetStepMin();
1459    
1460        TrkParams::Set(path,1);
1461        TrkParams::Load(1);
1462    
1463  //  //
1464  };  };
1465    // /**
1466    //  * Get BY (kGauss)
1467    //  * @param v (x,y,z) coordinates in cm
1468    //  */
1469    // float TrkLevel2::GetBX(float* v){
1470    //     float b[3];
1471    //     gufld_(v,b);
1472    //     return b[0]/10.;
1473    // }
1474    // /**
1475    //  * Get BY (kGauss)
1476    //  * @param v (x,y,z) coordinates in cm
1477    //  */
1478    // float TrkLevel2::GetBY(float* v){
1479    //     float b[3];
1480    //     gufld_(v,b);
1481    //     return b[1]/10.;
1482    // }
1483    // /**
1484    //  * Get BY (kGauss)
1485    //  * @param v (x,y,z) coordinates in cm
1486    //  */
1487    // float TrkLevel2::GetBZ(float* v){
1488    //     float b[3];
1489    //     gufld_(v,b);
1490    //     return b[2]/10.;
1491    // }
1492  //--------------------------------------  //--------------------------------------
1493  //  //
1494  //  //
# Line 1235  int Trajectory::DoTrack2(float* al){ Line 1666  int Trajectory::DoTrack2(float* al){
1666      for (int i=0; i<5; i++)      dal[i]  = (double)al[i];      for (int i=0; i<5; i++)      dal[i]  = (double)al[i];
1667      for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];      for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
1668    
1669        TrkParams::Load(1);
1670        if( !TrkParams::IsLoaded(1) ){
1671            cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;
1672            return 0;
1673        }
1674      dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);      dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
1675            
1676      for (int i=0; i<npoint; i++){      for (int i=0; i<npoint; i++){

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.23