/[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.10 by pam-fi, Thu Sep 28 14:04:39 2006 UTC revision 1.14 by pam-fi, Fri Oct 27 16:59:20 2006 UTC
# Line 4  Line 4 
4   */   */
5  #include <TrkLevel2.h>  #include <TrkLevel2.h>
6  #include <iostream>  #include <iostream>
7    #include <math.h>
8  using namespace std;  using namespace std;
9  //......................................  //......................................
10  // F77 routines  // F77 routines
# Line 11  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        void mini2_(int*,int*,int*);
17  }  }
18  //--------------------------------------  //--------------------------------------
19  //  //
# Line 21  TrkTrack::TrkTrack(){ Line 23  TrkTrack::TrkTrack(){
23      seqno = -1;      seqno = -1;
24      image = -1;      image = -1;
25      chi2  = 0;      chi2  = 0;
26          nstep = 0;      nstep = 0;
27          for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
28                  al[it1] = 0;          al[it1] = 0;
29                  for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;          for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
30      };      };
31      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
32                  xgood[ip]  = 0;                  xgood[ip]  = 0;
# Line 55  TrkTrack::TrkTrack(const TrkTrack& t){ Line 57  TrkTrack::TrkTrack(const TrkTrack& t){
57      seqno = t.seqno;      seqno = t.seqno;
58      image = t.image;      image = t.image;
59      chi2  = t.chi2;      chi2  = t.chi2;
60          nstep = t.nstep;      nstep = t.nstep;
61          for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
62                  al[it1] = t.al[it1];          al[it1] = t.al[it1];
63                  for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];          for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
64      };      };
65      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
66                  xgood[ip]  = t.xgood[ip];                  xgood[ip]  = t.xgood[ip];
# Line 196  Float_t TrkTrack::GetDEDX(){ Line 198  Float_t TrkTrack::GetDEDX(){
198  //--------------------------------------  //--------------------------------------
199  void TrkTrack::Dump(){  void TrkTrack::Dump(){
200      cout << endl << "========== Track " ;      cout << endl << "========== Track " ;
201          cout << endl << "seq.  n. : "<< seqno;      cout << endl << "seq.  n. : "<< seqno;
202          cout << endl << "image n. : "<< image;      cout << endl << "image n. : "<< image;
203          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] << " ";
204      cout << endl << "chi^2    : "<< chi2;      cout << endl << "chi^2    : "<< chi2;
205          cout << endl << "n.step   : "<< nstep;      cout << endl << "n.step   : "<< nstep;
206          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] ;
207      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] ;
208      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] << " ";
209      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] << " ";
210      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] << " ";
211        cout << endl << "xv       : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
212        cout << endl << "yv       : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
213        cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
214        cout << endl << "resx     : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
215        cout << endl << "resy     : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
216        cout << endl << "coval    : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
217        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
218        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
219        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
220        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
221      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] << " ";
222      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] << " ";
223        cout << endl;
224    }
225    /**
226     * Set the TrkTrack position measurements
227     */
228    void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
229        for(int i=0; i<6; i++) xm[i]=*xmeas++;
230        for(int i=0; i<6; i++) ym[i]=*ymeas++;
231        for(int i=0; i<6; i++) zm[i]=*zmeas++;
232    }
233    /**
234     * Set the TrkTrack position resolution
235     */
236    void TrkTrack::SetResolution(double *rx, double *ry){
237        for(int i=0; i<6; i++) resx[i]=*rx++;
238        for(int i=0; i<6; i++) resy[i]=*ry++;
239  }  }
240    /**
241     * Set the TrkTrack good measurement
242     */
243    void TrkTrack::SetGood(int *xg, int *yg){
244        for(int i=0; i<6; i++) xgood[i]=*xg++;
245        for(int i=0; i<6; i++) ygood[i]=*yg++;
246    }
247    
248    /**
249     * Load the magnetic field
250     */
251    void TrkTrack::LoadField(TString s){
252        readb_(s.Data());
253    };
254    /**
255     * Tracking method. It calls F77 mini routine.
256     */
257    void TrkTrack::Fit(double pfixed, int& fail, int iprint){
258        extern cMini2track track_;
259        fail = 0;
260    //    extern cMini2fitinfo fit_info_;
261    //    extern void mini_2_(int*,int*);
262    //    track_.xm[0]=1.0;
263        for(int i=0; i<6; i++) track_.xm[i]=xm[i];
264        for(int i=0; i<6; i++) track_.ym[i]=ym[i];
265        for(int i=0; i<6; i++) track_.zm[i]=zm[i];
266        for(int i=0; i<6; i++) track_.resx[i]=resx[i];
267        for(int i=0; i<6; i++) track_.resy[i]=resy[i];
268        for(int i=0; i<6; i++) track_.xgood[i]=xgood[i];
269        for(int i=0; i<6; i++) track_.ygood[i]=ygood[i];
270    // initial guess of "al" with linear fit
271        if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){
272            double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.;
273            double det, ax, ay, bx, by;
274            for(int i=0; i<NPLANE; i++) {
275                szz=szz+zm[i]*zm[i];
276                szx=szx+zm[i]*xm[i];
277                szy=szy+zm[i]*ym[i];
278                ssx=ssx+xm[i];
279                ssy=ssy+ym[i];
280                sz=sz+zm[i];
281                s1=s1+1.;
282            }
283            det=szz*s1-sz*sz;
284            ax=(szx*s1-sz*ssx)/det;
285            bx=(szz*ssx-szx*sz)/det;
286            ay=(szy*s1-sz*ssy)/det;
287            by=(szz*ssy-szy*sz)/det;
288            al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes
289            al[1]=ay*23.5+by; //  "  
290            al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.);
291            al[3]=0.;
292            if( (ax!=0.)||(ay!=0.) ) {
293                al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2)));
294                if(ax<0.) al[3]=acos(-1.)-al[3];
295            }
296            al[4]=0.;
297        }
298    // end guess
299        if(pfixed==0.) {
300            al[4]=0.;         // free momentum
301            track_.pfixed=0.; //         "
302        }
303        if(pfixed!=0.) {
304            al[4]=1./pfixed;      // to fix the momentum
305            track_.pfixed=pfixed; //         "
306        }
307        track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes
308        for(int i=0; i<5; i++) track_.al[i]=al[i];
309        int istep=0;
310        int ifail=0;
311        mini2_(&istep,&ifail, &iprint);
312        if(ifail!=0) {
313            if(iprint==1)cout << "ERROR: ifail= " << ifail << endl;
314            fail = 1;
315    //      return;
316        }
317    
318    //    cout << endl << "eta ===> " << track_.al[4] << endl;
319    
320        for(int i=0; i<5; i++) al[i]=track_.al[i];
321        chi2=track_.chi2;
322        nstep=track_.nstep;
323        for(int i=0; i<6; i++) xv[i]=track_.xv[i];
324        for(int i=0; i<6; i++) yv[i]=track_.yv[i];
325        for(int i=0; i<6; i++) zv[i]=track_.zv[i];
326        for(int i=0; i<6; i++) axv[i]=track_.axv[i];
327        for(int i=0; i<6; i++) ayv[i]=track_.ayv[i];
328        for(int i=0; i<5; i++) {
329            for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];
330        }
331    };
332    /*
333     * Reset the parameters fit
334     */
335    void TrkTrack::FitReset(){
336        for(int i=0; i<5; i++) al[i]=-9999.;
337        chi2=0.;
338        nstep=0;
339        for(int i=0; i<6; i++) xv[i]=0.;
340        for(int i=0; i<6; i++) yv[i]=0.;
341        for(int i=0; i<6; i++) zv[i]=0.;
342        for(int i=0; i<6; i++) axv[i]=0.;
343        for(int i=0; i<6; i++) ayv[i]=0.;
344        for(int i=0; i<5; i++) {
345            for(int j=0; j<5; j++) coval[i][j]=0.;
346        }
347    }
348    
349  //--------------------------------------  //--------------------------------------
350  //  //
351  //  //
# Line 247  void TrkTrack::Clear(){ Line 384  void TrkTrack::Clear(){
384  //  //
385  //  //
386  //--------------------------------------  //--------------------------------------
387    void TrkTrack::Delete(){
388            Clear();
389            clx->Delete();
390            cly->Delete();
391    };
392            //--------------------------------------
393    //
394    //
395    //--------------------------------------
396    
397  //--------------------------------------  //--------------------------------------
398  //  //
# Line 569  void TrkLevel2::Clear(){ Line 715  void TrkLevel2::Clear(){
715  //  //
716  //  //
717  //--------------------------------------  //--------------------------------------
718    void TrkLevel2::Delete(){
719            
720            Clear();
721            Track->Delete();
722            SingletX->Delete();
723            SingletY->Delete();
724    }
725    //--------------------------------------
726    //
727    //
728    //--------------------------------------
729  /**  /**
730   * Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).   * Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).
731   * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.   * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.
# Line 712  Int_t TrkLevel2::GetNTracks(){ Line 869  Int_t TrkLevel2::GetNTracks(){
869                                    
870          Float_t ntot=0;          Float_t ntot=0;
871          TClonesArray &t = *Track;          TClonesArray &t = *Track;
872          for(int i=0; i<ntrk(); i++) {          for(int i=0; i<ntrk(); i++) {    
873                  if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;                  if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
874                  else ntot+=0.5;                  else ntot+=0.5;
875          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.23