/[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.14 by pam-fi, Fri Oct 27 16:59:20 2006 UTC revision 1.16 by pam-fi, Wed Nov 8 16:42:28 2006 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*);
15      int  readb_(const char*);  //    int  readb_(const char*);
16        int  readb_();
17      void mini2_(int*,int*,int*);      void mini2_(int*,int*,int*);
18        void guess_();
19  }  }
20  //--------------------------------------  //--------------------------------------
21  //  //
# Line 248  void TrkTrack::SetGood(int *xg, int *yg) Line 250  void TrkTrack::SetGood(int *xg, int *yg)
250  /**  /**
251   * Load the magnetic field   * Load the magnetic field
252   */   */
253  void TrkTrack::LoadField(TString s){  void TrkTrack::LoadField(TString path){
254      readb_(s.Data());      
255        strcpy(path_.path,path.Data());
256        path_.pathlen = path.Length();
257        path_.error   = 0;
258        readb_();
259    
260  };  };
261  /**  /**
262   * Tracking method. It calls F77 mini routine.   * Tracking method. It calls F77 mini routine.
263   */   */
264  void TrkTrack::Fit(double pfixed, int& fail, int iprint){  void TrkTrack::Fit(double pfixed, int& fail, int iprint){
265    
266        float al_ini[] = {0.,0.,0.,0.,0.};
267    
268      extern cMini2track track_;      extern cMini2track track_;
269      fail = 0;      fail = 0;
270  //    extern cMini2fitinfo fit_info_;  
 //    extern void mini_2_(int*,int*);  
 //    track_.xm[0]=1.0;  
271      for(int i=0; i<6; i++) track_.xm[i]=xm[i];      for(int i=0; i<6; i++) track_.xm[i]=xm[i];
272      for(int i=0; i<6; i++) track_.ym[i]=ym[i];      for(int i=0; i<6; i++) track_.ym[i]=ym[i];
273      for(int i=0; i<6; i++) track_.zm[i]=zm[i];      for(int i=0; i<6; i++) track_.zm[i]=zm[i];
# Line 267  void TrkTrack::Fit(double pfixed, int& f Line 275  void TrkTrack::Fit(double pfixed, int& f
275      for(int i=0; i<6; i++) track_.resy[i]=resy[i];      for(int i=0; i<6; i++) track_.resy[i]=resy[i];
276      for(int i=0; i<6; i++) track_.xgood[i]=xgood[i];      for(int i=0; i<6; i++) track_.xgood[i]=xgood[i];
277      for(int i=0; i<6; i++) track_.ygood[i]=ygood[i];      for(int i=0; i<6; i++) track_.ygood[i]=ygood[i];
278    
279  // initial guess of "al" with linear fit  // initial guess of "al" with linear fit
280      if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){  //     if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){
281          double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.;  //      cout << "initial guess "<<endl;
282          double det, ax, ay, bx, by;  //      double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.;
283          for(int i=0; i<NPLANE; i++) {  //      double det, ax, ay, bx, by;
284              szz=szz+zm[i]*zm[i];  //      for(int i=0; i<NPLANE; i++) {
285              szx=szx+zm[i]*xm[i];  //          szz=szz+zm[i]*zm[i];
286              szy=szy+zm[i]*ym[i];  //          szx=szx+zm[i]*xm[i];
287              ssx=ssx+xm[i];  //          szy=szy+zm[i]*ym[i];
288              ssy=ssy+ym[i];  //          ssx=ssx+xm[i];
289              sz=sz+zm[i];  //          ssy=ssy+ym[i];
290              s1=s1+1.;  //          sz=sz+zm[i];
291          }  //          s1=s1+1.;
292          det=szz*s1-sz*sz;  //      }
293          ax=(szx*s1-sz*ssx)/det;  //      det=szz*s1-sz*sz;
294          bx=(szz*ssx-szx*sz)/det;  //      ax=(szx*s1-sz*ssx)/det;
295          ay=(szy*s1-sz*ssy)/det;  //      bx=(szz*ssx-szx*sz)/det;
296          by=(szz*ssy-szy*sz)/det;  //      ay=(szy*s1-sz*ssy)/det;
297          al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes  //      by=(szz*ssy-szy*sz)/det;
298          al[1]=ay*23.5+by; //  "    //      al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes
299          al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.);  //      al[1]=ay*23.5+by; //  "  
300          al[3]=0.;  //      al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.);
301          if( (ax!=0.)||(ay!=0.) ) {  //      al[3]=0.;
302              al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2)));  //      if( (ax!=0.)||(ay!=0.) ) {
303              if(ax<0.) al[3]=acos(-1.)-al[3];  //          al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2)));
304          }  //          if(ax<0.) al[3]=acos(-1.)-al[3];
305          al[4]=0.;  //      }
306      }  //      al[4]=0.;
307    //     }
308  // end guess  // end guess
309    
310        for(int i=0; i<5; i++) track_.al[i]=al[i];
311        track_.zini = 23.5;
312    // ZINI = 23.5 !!! it should be the same parameter in all codes
313    
314        if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
315    
316        // --------------------- free momentum
317      if(pfixed==0.) {      if(pfixed==0.) {
318          al[4]=0.;         // free momentum  //      al[4]=0.;         // free momentum
319          track_.pfixed=0.; //         "          track_.pfixed=0.; //         "
320      }      }
321        // --------------------- fixed momentum
322      if(pfixed!=0.) {      if(pfixed!=0.) {
323          al[4]=1./pfixed;      // to fix the momentum          al[4]=1./pfixed;      // to fix the momentum
324          track_.pfixed=pfixed; //         "          track_.pfixed=pfixed; //         "
325      }      }
326      track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes  
327      for(int i=0; i<5; i++) track_.al[i]=al[i];  //  store temporarily the initial guess
328        for(int i=0; i<5; i++) al_ini[i]=track_.al[i];
329    
330    
331      int istep=0;      int istep=0;
332      int ifail=0;      int ifail=0;
333      mini2_(&istep,&ifail, &iprint);      mini2_(&istep,&ifail, &iprint);
# Line 314  void TrkTrack::Fit(double pfixed, int& f Line 336  void TrkTrack::Fit(double pfixed, int& f
336          fail = 1;          fail = 1;
337  //      return;  //      return;
338      }      }
339        
340    
341  //    cout << endl << "eta ===> " << track_.al[4] << endl;  //    cout << endl << "eta ===> " << track_.al[4] << endl;
342    
# Line 328  void TrkTrack::Fit(double pfixed, int& f Line 351  void TrkTrack::Fit(double pfixed, int& f
351      for(int i=0; i<5; i++) {      for(int i=0; i<5; i++) {
352          for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];          for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];
353      }      }
354    
355        if(fail){
356            cout << " >>>> fit failed >>>> drawing initial par"<<endl;
357            for(int i=0; i<5; i++) al[i]=al_ini[i];
358        }
359    
360  };  };
361  /*  /*
362   * Reset the parameters fit   * Reset the fit parameters
363   */   */
364  void TrkTrack::FitReset(){  void TrkTrack::FitReset(){
365      for(int i=0; i<5; i++) al[i]=-9999.;      for(int i=0; i<5; i++) al[i]=-9999.;
# Line 914  TrkTrack *TrkLevel2::GetTrackImage(int i Line 943  TrkTrack *TrkLevel2::GetTrackImage(int i
943   * Loads the magnetic field.   * Loads the magnetic field.
944   * @param s Path of the magnetic-field files.   * @param s Path of the magnetic-field files.
945   */   */
946  void TrkLevel2::LoadField(TString s){  void TrkLevel2::LoadField(TString path){
947      readb_(s.Data());  //
948        strcpy(path_.path,path.Data());
949        path_.pathlen = path.Length();
950        path_.error   = 0;
951        readb_();
952    //
953  };  };
954  //--------------------------------------  //--------------------------------------
955  //  //

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.23