/[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.46 by pam-fi, Fri Apr 11 13:44:38 2008 UTC revision 1.53 by pam-fi, Tue Feb 3 13:57:15 2009 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        void dotrack3_(int*, double*, double*, double*, double*,double*, double*, double*,double*,int*);
16      void mini2_(int*,int*,int*);      void mini2_(int*,int*,int*);
17      void guess_();      void guess_();
18      void gufld_(float*, float*);      void gufld_(float*, float*);
# Line 177  void TrkTrack::Copy(TrkTrack& t){ Line 178  void TrkTrack::Copy(TrkTrack& t){
178  //  //
179  //--------------------------------------  //--------------------------------------
180  /**  /**
  * Evaluates the trajectory in the apparatus associated to the track.  
  * It integrates the equations of motion in the magnetic field. The magnetic field should be previously loaded ( by calling  TrkLevel2::LoadField() ), otherwise an error message is returned.    
  * @param t pointer to an object of the class Trajectory,  
  * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).  
  * @return error flag.  
181   *   *
182   * >>> OBSOLETE !!! use TrkTrack::DoTrack2(Trajectory* t) instead   * >>> OBSOLETE !!! use TrkTrack::DoTrack(Trajectory* t) instead
183   *   *
184   */   */
185  int TrkTrack::DoTrack(Trajectory* t){  int TrkTrack::DoTrack2(Trajectory* t){
   
     cout << " int TrkTrack::DoTrack(Trajectory* t) --->> OBSOLETE !!! "<<endl;  
     cout << " use int TrkTrack::DoTrack2(Trajectory* t)"<<endl;  
   
     double *dxout = new double[t->npoint];  
     double *dyout = new double[t->npoint];  
     double *dzin = new double[t->npoint];  
     double dal[5];  
   
     int ifail = 0;  
   
     for (int i=0; i<5; i++)         dal[i]  = (double)al[i];  
     for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];  
186    
187      TrkParams::Load(1);      cout << endl;
188      if( !TrkParams::IsLoaded(1) ){      cout << " int TrkTrack::DoTrack2(Trajectory* t) --->> NB NB !! this method is going to be eliminated !!! "<<endl;
189          cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;      cout << " >>>> replace it with TrkTrack::DoTrack(Trajectory* t) <<<<"<<endl;
190          return 0;      cout << " (Sorry Wolfgang!! Don't be totally confused!! By Elena)"<<endl;
191      }      cout << endl;
     dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);  
       
     for (int i=0; i<t->npoint; i++){  
         t->x[i] = (float)*(dxout+i);  
         t->y[i] = (float)*(dyout+i);  
     }  
192    
193      delete [] dxout;      return DoTrack(t);
     delete [] dyout;  
     delete [] dzin;  
194    
     return ifail;  
195  };  };
196  //--------------------------------------  //--------------------------------------
197  //  //
198  //  //
199  //--------------------------------------  //--------------------------------------
200  /**  /**
201   * Evaluates the trajectory in the apparatus associated to the track.   * Evaluates the trajectory in the apparatus associated to the track state-vector.
202   * It integrates the equations of motion in the magnetic field. The magnetic field should be previously loaded ( by calling  TrkLevel2::LoadField() ), otherwise an error message is returned.     * It integrates the equations of motion in the magnetic field.
203   * @param t pointer to an object of the class Trajectory,   * @param t pointer to an object of the class Trajectory,
204   * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).   * which z coordinates should be previously assigned.
205   * @return error flag.   * @return error flag.
206   */   */
207  int TrkTrack::DoTrack2(Trajectory* t){  int TrkTrack::DoTrack(Trajectory* t){
208    
209      double *dxout   = new double[t->npoint];      double *dxout   = new double[t->npoint];
210      double *dyout   = new double[t->npoint];      double *dyout   = new double[t->npoint];
# Line 247  int TrkTrack::DoTrack2(Trajectory* t){ Line 221  int TrkTrack::DoTrack2(Trajectory* t){
221    
222      TrkParams::Load(1);      TrkParams::Load(1);
223      if( !TrkParams::IsLoaded(1) ){      if( !TrkParams::IsLoaded(1) ){
224          cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;          cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
225          return 0;          return 0;
226      }      }
227      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);      dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
# Line 400  Int_t TrkTrack::GetLeverArmY(){ Line 374  Int_t TrkTrack::GetLeverArmY(){
374      return (last_plane-first_plane+1);      return (last_plane-first_plane+1);
375  }  }
376  /**  /**
377     * Returns the track "lever-arm" on the x+y view, defined as the distance (in planes) between
378     * the upper and lower x,y (couple) measurements (the maximum value of lever-arm is 6).
379     */
380    Int_t TrkTrack::GetLeverArmXY(){
381        int first_plane = -1;
382        int last_plane  = -1;
383        for(Int_t ip=0; ip<6; ip++){
384            if( XGood(ip)*YGood(ip) && first_plane == -1 )first_plane = ip;
385            if( XGood(ip)*YGood(ip) && first_plane != -1 )last_plane = ip;
386        }
387        if( first_plane == -1 || last_plane == -1){
388            cout<< "Int_t TrkTrack::GetLeverArmXY() -- XGood(ip)*YGood(ip) always false ??? "<<endl;
389            return 0;
390        }
391        return (last_plane-first_plane+1);
392    }
393    /**
394   * Returns the reduced chi-square of track x-projection   * Returns the reduced chi-square of track x-projection
395   */   */
396  Float_t  TrkTrack::GetChi2X(){  Float_t  TrkTrack::GetChi2X(){
# Line 610  void TrkTrack::SetStudentParam(int flag) Line 601  void TrkTrack::SetStudentParam(int flag)
601                     4.52043,                     4.52043,
602                     4.29926};                     4.29926};
603      int index;      int index;
604      float fact;      float fact=0.;
605      for(int i=0; i<6; i++) {      for(int i=0; i<6; i++) {
606          index = int((fabs(axv[i])+1.)/2.);          index = int((fabs(axv[i])+1.)/2.);
607          if(index>10) index=10;          if(index>10) index=10;
# Line 657  void TrkTrack::LoadField(TString path){ Line 648  void TrkTrack::LoadField(TString path){
648    
649      TrkParams::Set(path,1);      TrkParams::Set(path,1);
650      TrkParams::Load(1);      TrkParams::Load(1);
651        if( !TrkParams::IsLoaded(1) ){
652            cout << "void TrkTrack::LoadField(TString path) --- ERROR --- m.field not loaded"<<endl;
653        }
654    
655  };  };
656    
# Line 798  Bool_t TrkTrack::EvaluateClusterPosition Line 792  Bool_t TrkTrack::EvaluateClusterPosition
792            
793  //     cout << "void TrkTrack::GetClusterositions() "<<endl;  //     cout << "void TrkTrack::GetClusterositions() "<<endl;
794    
795      TrkParams::Load( );      TrkParams::Load(1);
796      if( !TrkParams::IsLoaded() )return false;      if( !TrkParams::IsLoaded(1) ){
797                cout << "Bool_t TrkTrack::EvaluateClusterPositions() ---ERROR--- m.field not loaded "<<endl;
798            return false;
799        }    
800        TrkParams::Load(4);
801        if( !TrkParams::IsLoaded(4) ){
802            cout << "Bool_t TrkTrack::EvaluateClusterPositions() ---ERROR--- p.f.a. par. not loaded "<<endl;
803            return false;
804        }
805        TrkParams::Load(5);
806        if( !TrkParams::IsLoaded(5) ){
807            cout << "Bool_t TrkTrack::EvaluateClusterPositions() ---ERROR--- alignment par. not loaded "<<endl;
808            return false;
809        }
810    
811      for(int ip=0; ip<6; ip++){      for(int ip=0; ip<6; ip++){
812  //      cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;  //      cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;
813          int icx = GetClusterX_ID(ip)+1;          int icx = GetClusterX_ID(ip)+1;
# Line 852  Bool_t TrkTrack::EvaluateClusterPosition Line 859  Bool_t TrkTrack::EvaluateClusterPosition
859   */   */
860  void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){  void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
861    
862      float al_ini[] = {0.,0.,0.,0.,0.};      TrkParams::Load(1);
863        if( !TrkParams::IsLoaded(1) ){
864            cout << "void TrkTrack::Fit(double,int&,int,int) ---ERROR--- m.field not loaded "<<endl;
865            return;
866        }
867        TrkParams::Load(5);
868        if( !TrkParams::IsLoaded(5) ){
869            cout << "void TrkTrack::Fit(double,int&,int,int) ---ERROR--- align.param. not loaded "<<endl;
870            return;
871        }
872    
873      TrkParams::Load( );      float al_ini[] = {0.,0.,0.,0.,0.};
     if( !TrkParams::IsLoaded() )return;  
874    
875      extern cMini2track track_;      extern cMini2track track_;
876      fail = 0;      fail = 0;
# Line 891  void TrkTrack::Fit(double pfixed, int& f Line 906  void TrkTrack::Fit(double pfixed, int& f
906    
907      //  ------------------------------------------      //  ------------------------------------------
908      //  call mini routine      //  call mini routine
909  //     TrkParams::Load(1);      //  ------------------------------------------
 //     if( !TrkParams::IsLoaded(1) ){  
 //      cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl;  
 //      return;  
 //     }  
910      int istep=0;      int istep=0;
911      int ifail=0;      int ifail=0;
912      mini2_(&istep,&ifail, &iprint);      mini2_(&istep,&ifail, &iprint);
# Line 1195  Float_t TrkTrack::GetDEDX_max(int ip, in Line 1206  Float_t TrkTrack::GetDEDX_max(int ip, in
1206          vto   = iv+1;          vto   = iv+1;
1207      }      }
1208      for(int i=pfrom; i<pto; i++)      for(int i=pfrom; i<pto; i++)
1209          for(int j=0; j<vto; j++)          for(int j=vfrom; j<vto; j++){
1210              if(GetDEDX(i,j)>max)max=GetDEDX(i,j);              if(j==0 && XGood(i) && GetDEDX(i,j)>max)max=GetDEDX(i,j);
1211                if(j==1 && YGood(i) && GetDEDX(i,j)>max)max=GetDEDX(i,j);
1212            }
1213      return max;      return max;
1214    
1215  };  };
# Line 1220  Float_t TrkTrack::GetDEDX_min(int ip, in Line 1232  Float_t TrkTrack::GetDEDX_min(int ip, in
1232          vto   = iv+1;          vto   = iv+1;
1233      }      }
1234      for(int i=pfrom; i<pto; i++)      for(int i=pfrom; i<pto; i++)
1235          for(int j=0; j<vto; j++)          for(int j=vfrom; j<vto; j++){
1236              if(GetDEDX(i,j)<min)min=GetDEDX(i,j);              if(j==0 && XGood(i) && GetDEDX(i,j)<min)min=GetDEDX(i,j);
1237                if(j==1 && YGood(i) && GetDEDX(i,j)<min)min=GetDEDX(i,j);
1238            }
1239      return min;      return min;
1240    
1241  };  };
1242    
1243  /**  /**
1244   * \brief Give the maximum spatial residual release   * \brief Give the maximum spatial residual  
1245   */   */
1246  Float_t TrkTrack::GetResidual_max(int ip, int iv){  Float_t TrkTrack::GetResidual_max(int ip, int iv){
1247      Float_t max=0;      Float_t max=0;
# Line 1245  Float_t TrkTrack::GetResidual_max(int ip Line 1258  Float_t TrkTrack::GetResidual_max(int ip
1258          vto   = iv+1;          vto   = iv+1;
1259      }      }
1260      for(int i=pfrom; i<pto; i++){      for(int i=pfrom; i<pto; i++){
1261          for(int j=0; j<vto; j++){          for(int j=vfrom; j<vto; j++){
1262              if(j==0 && XGood(i) && fabs(xm[i]-xv[i])>fabs(max))max=xv[i]-xm[i];              if(j==0 && XGood(i) && fabs(xm[i]-xv[i])>fabs(max))max=xm[i]-xv[i];
1263              if(j==1 && YGood(i) && fabs(ym[i]-yv[i])>fabs(max))max=yv[i]-ym[i];              if(j==1 && YGood(i) && fabs(ym[i]-yv[i])>fabs(max))max=ym[i]-yv[i];
1264          }          }
1265      }      }
1266      return max;      return max;
1267    
1268  };  };
1269    /**
1270     * \brief Give the anerage spatial residual
1271     */
1272    Float_t TrkTrack::GetResidual_av(int ip, int iv){
1273        //
1274    //Sum$((xm>-50)*(xm-xv)/resx)/sqrt(TrkTrack.GetNX()*TrkTrack.GetChi2X())<0.3
1275    
1276        Float_t av  = 0.;
1277        int     nav = 0;
1278        //
1279        int pfrom = 0;
1280        int pto   = 6;
1281        int vfrom = 0;
1282        int vto   = 2;
1283        if(ip>=0&&ip<6){
1284            pfrom = ip;
1285            pto   = ip+1;
1286        }
1287        if(iv>=0&&iv<2){
1288            vfrom = iv;
1289            vto   = iv+1;
1290        }
1291        for(int i=pfrom; i<pto; i++){
1292            for(int j=vfrom; j<vto; j++){
1293                nav++;
1294                if(j==0 && XGood(i)) av += (xm[i]-xv[i])/resx[i];
1295                if(j==1 && YGood(i)) av += (ym[i]-yv[i])/resy[i];
1296            }
1297        }
1298        if(nav==0)return -100.;
1299        return av/nav;
1300    
1301    };
1302    
1303    
1304  /**  /**
# Line 1635  void TrkLevel2::SetFromLevel2Struct(cTrk Line 1681  void TrkLevel2::SetFromLevel2Struct(cTrk
1681          int    ngf = TrkParams::nGF;          int    ngf = TrkParams::nGF;
1682          float *zgf = TrkParams::zGF;          float *zgf = TrkParams::zGF;
1683          Trajectory tgf = Trajectory(ngf,zgf);          Trajectory tgf = Trajectory(ngf,zgf);
1684          tgf.DoTrack2(t_track->al);//<<<< integrate the trajectory          tgf.DoTrack(t_track->al);//<<<< integrate the trajectory
1685          for(int ip=0; ip<ngf; ip++){          for(int ip=0; ip<ngf; ip++){
1686              t_track->xGF[ip] = tgf.x[ip];              t_track->xGF[ip] = tgf.x[ip];
1687              t_track->yGF[ip] = tgf.y[ip];              t_track->yGF[ip] = tgf.y[ip];
# Line 1793  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1839  TRefArray *TrkLevel2::GetTracks_NFitSort
1839    
1840      if(!Track)return 0;      if(!Track)return 0;
1841    
1842      TRefArray *sorted = new TRefArray();      //    TRefArray *sorted = new TRefArray();
1843        TRefArray *sorted = NULL;
1844                    
1845      TClonesArray &t  = *Track;      TClonesArray &t  = *Track;
1846  //    TClonesArray &ts = *PhysicalTrack;  //    TClonesArray &ts = *PhysicalTrack;
# Line 1831  TRefArray *TrkLevel2::GetTracks_NFitSort Line 1878  TRefArray *TrkLevel2::GetTracks_NFitSort
1878                    
1879  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;  //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1880          };          };
1881            if(!sorted)sorted = new TRefArray( TProcessID::GetProcessWithUID(t[indi]));
1882          sorted->Add( (TrkTrack*)t[indi] );                sorted->Add( (TrkTrack*)t[indi] );      
1883                                    
1884          m[indi] = 0;          m[indi] = 0;
# Line 2001  void TrkLevel2::LoadField(TString path){ Line 2049  void TrkLevel2::LoadField(TString path){
2049    
2050      TrkParams::Set(path,1);      TrkParams::Set(path,1);
2051      TrkParams::Load(1);      TrkParams::Load(1);
2052        if( !TrkParams::IsLoaded(1) ){
2053            cout << "void TrkLevel2::LoadField(TString path) --- ERROR --- m.field not loaded"<<endl;
2054        }
2055    
2056  //  //
2057  };  };
# Line 2188  float Trajectory::GetLength(int ifirst, Line 2239  float Trajectory::GetLength(int ifirst,
2239    
2240  /**  /**
2241   * Evaluates the trajectory in the apparatus associated to the track.   * Evaluates the trajectory in the apparatus associated to the track.
2242   * It integrates the equations of motion in the magnetic field. The magnetic field should be previously loaded ( by calling  TrkLevel2::LoadField() ), otherwise an error message is returned.     * It integrates the equations of motion in the magnetic field.
2243   * @param t pointer to an object of the class Trajectory,   * @param al Track state-vector (X0,Y0,sin(theta),phi,deflection).
2244   * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).   * @param zini z-coordinate of the reference plane (Z0).
2245   * @return error flag.   * @return error flag.
2246     *
2247     * This method is needed when you want to integrate the particle trajectory
2248     * starting from a track state-vector relative to an arbitrary reference plane.
2249     * The default reference plane, used by the tracker routines, is at zini=23.5.
2250     * If you give as input the track state-vector from a TrkTrack object,
2251     * you can use Trajectory::DoTrack(float* al) instead.
2252   */   */
2253  int Trajectory::DoTrack2(float* al){  int Trajectory::DoTrack(float* al, float zini){
2254    
2255  //      double *dxout   = new double[npoint];  //      double *dxout   = new double[npoint];
2256  //      double *dyout   = new double[npoint];  //      double *dyout   = new double[npoint];
# Line 2202  int Trajectory::DoTrack2(float* al){ Line 2259  int Trajectory::DoTrack2(float* al){
2259  //      double *dtlout  = new double[npoint];  //      double *dtlout  = new double[npoint];
2260  //      double *dzin    = new double[npoint];  //      double *dzin    = new double[npoint];
2261            
2262       double *dxout;      double *dxout;
2263       double *dyout;      double *dyout;
2264       double *dthxout;      double *dthxout;
2265       double *dthyout;      double *dthyout;
2266       double *dtlout;      double *dtlout;
2267       double *dzin;      double *dzin;
2268        
2269       dxout   = (double*) malloc(npoint*sizeof(double));      dxout   = (double*) malloc(npoint*sizeof(double));
2270       dyout   = (double*) malloc(npoint*sizeof(double));      dyout   = (double*) malloc(npoint*sizeof(double));
2271       dthxout = (double*) malloc(npoint*sizeof(double));      dthxout = (double*) malloc(npoint*sizeof(double));
2272       dthyout = (double*) malloc(npoint*sizeof(double));      dthyout = (double*) malloc(npoint*sizeof(double));
2273       dtlout  = (double*) malloc(npoint*sizeof(double));      dtlout  = (double*) malloc(npoint*sizeof(double));
2274       dzin    = (double*) malloc(npoint*sizeof(double));      dzin    = (double*) malloc(npoint*sizeof(double));
2275        
2276        double dal[5];
2277    
2278       double dal[5];      double dzini = (double)zini;
2279    
2280      int ifail = 0;      int ifail = 0;
2281        
2282      for (int i=0; i<5; i++)      dal[i]  = (double)al[i];      for (int i=0; i<5; i++)      dal[i]  = (double)al[i];
2283      for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];      for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
2284    
2285      TrkParams::Load(1);      TrkParams::Load(1);
2286      if( !TrkParams::IsLoaded(1) ){      if( !TrkParams::IsLoaded(1) ){
2287          cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;          cout << "int Trajectory::DoTrack(float* al) --- ERROR --- m.field not loaded"<<endl;
2288          return 0;          return 0;
2289      }      }
2290      dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);  //    dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
2291        dotrack3_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&dzini,&ifail);
2292            
2293      for (int i=0; i<npoint; i++){      for (int i=0; i<npoint; i++){
2294          x[i]   = (float)*(dxout+i);          x[i]   = (float)*(dxout+i);
# Line 2256  int Trajectory::DoTrack2(float* al){ Line 2316  int Trajectory::DoTrack2(float* al){
2316      return ifail;      return ifail;
2317  };  };
2318    
2319    /**
2320     *
2321     * >>> OBSOLETE !!! use Trajectory::DoTrack(float* al, float zini) instead
2322     *
2323     */
2324    int Trajectory::DoTrack2(float* al, float zini){
2325    
2326        cout << endl;
2327        cout << " int Trajectory::DoTrack2(float* al, float zini) --->> NB NB !! this method is going to be eliminated !!! "<<endl;
2328        cout << " >>>> replace it with TrkTrack::DoTrack(Trajectory* t) <<<<"<<endl;
2329        cout << " (Sorry Wolfgang!! Don't be totally confused!! By Elena)"<<endl;
2330        cout << endl;
2331    
2332        return DoTrack(al,zini);
2333    
2334    };
2335    
2336    
2337    
2338  ClassImp(TrkLevel2);  ClassImp(TrkLevel2);
2339  ClassImp(TrkSinglet);  ClassImp(TrkSinglet);
2340  ClassImp(TrkTrack);  ClassImp(TrkTrack);

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.53

  ViewVC Help
Powered by ViewVC 1.1.23