--- DarthVader/TrackerLevel2/src/TrkLevel2.cpp 2006/06/30 09:48:15 1.5 +++ DarthVader/TrackerLevel2/src/TrkLevel2.cpp 2007/03/15 12:17:10 1.29 @@ -4,6 +4,7 @@ */ #include #include +#include using namespace std; //...................................... // F77 routines @@ -11,20 +12,26 @@ extern "C" { void dotrack_(int*, double*, double*, double*, double*, int*); void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*); - int readb_(const char*); +// int readb_(const char*); +// int readb_(); + void mini2_(int*,int*,int*); + void guess_(); + void gufld_(float*, float*); } + //-------------------------------------- // // //-------------------------------------- TrkTrack::TrkTrack(){ +// cout << "TrkTrack::TrkTrack()" << endl; seqno = -1; image = -1; chi2 = 0; + nstep = 0; for(int it1=0;it1<5;it1++){ al[it1] = 0; - for(int it2=0;it2<5;it2++) - coval[it1][it2] = 0; + for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; }; for(int ip=0;ip<6;ip++){ xgood[ip] = 0; @@ -41,7 +48,11 @@ ayv[ip] = 0; dedx_x[ip] = 0; dedx_y[ip] = 0; - }; + }; + clx = 0; + cly = 0; +// clx = new TRefArray(6,0); //forse causa memory leak??? +// cly = new TRefArray(6,0); //forse causa memory leak??? }; //-------------------------------------- // @@ -51,10 +62,10 @@ seqno = t.seqno; image = t.image; chi2 = t.chi2; + nstep = t.nstep; for(int it1=0;it1<5;it1++){ al[it1] = t.al[it1]; - 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]; }; for(int ip=0;ip<6;ip++){ xgood[ip] = t.xgood[ip]; @@ -71,7 +82,45 @@ ayv[ip] = t.ayv[ip]; dedx_x[ip] = t.dedx_x[ip]; dedx_y[ip] = t.dedx_y[ip]; - }; + }; + clx = 0; + cly = 0; + if(t.clx)clx = new TRefArray(*(t.clx)); + if(t.cly)cly = new TRefArray(*(t.cly)); + +}; +//-------------------------------------- +// +// +//-------------------------------------- +void TrkTrack::Copy(TrkTrack& t){ + + t.seqno = seqno; + t.image = image; + t.chi2 = chi2; + t.nstep = nstep; + for(int it1=0;it1<5;it1++){ + t.al[it1] = al[it1]; + for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2]; + }; + for(int ip=0;ip<6;ip++){ + t.xgood[ip] = xgood[ip]; + t.ygood[ip] = ygood[ip]; + t.xm[ip] = xm[ip]; + t.ym[ip] = ym[ip]; + t.zm[ip] = zm[ip]; + t.resx[ip] = resx[ip]; + t.resy[ip] = resy[ip]; + t.xv[ip] = xv[ip]; + t.yv[ip] = yv[ip]; + t.zv[ip] = zv[ip]; + t.axv[ip] = axv[ip]; + t.ayv[ip] = ayv[ip]; + t.dedx_x[ip] = dedx_x[ip]; + t.dedx_y[ip] = dedx_y[ip]; + + }; + }; //-------------------------------------- // @@ -96,6 +145,11 @@ for (int i=0; i<5; i++) dal[i] = (double)al[i]; for (int i=0; inpoint; i++) dzin[i] = (double)t->z[i]; + TrkParams::Load(1); + if( !TrkParams::IsLoaded(1) ){ + cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<npoint),dzin,dxout,dyout,dal,&ifail); for (int i=0; inpoint; i++){ @@ -135,6 +189,11 @@ for (int i=0; i<5; i++) dal[i] = (double)al[i]; for (int i=0; inpoint; i++) dzin[i] = (double)t->z[i]; + TrkParams::Load(1); + if( !TrkParams::IsLoaded(1) ){ + cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); for (int i=0; inpoint; i++){ @@ -187,35 +246,312 @@ //-------------------------------------- void TrkTrack::Dump(){ cout << endl << "========== Track " ; + cout << endl << "seq. n. : "<< seqno; + cout << endl << "image n. : "<< image; cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " "; cout << endl << "chi^2 : "<< chi2; + cout << endl << "n.step : "<< nstep; cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << xgood[i] ; cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << ygood[i] ; cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " "; cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " "; cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " "; + cout << endl << "xv : "; for(int i=0; i<6; i++)cout << xv[i] << " "; + cout << endl << "yv : "; for(int i=0; i<6; i++)cout << yv[i] << " "; + cout << endl << "zv : "; for(int i=0; i<6; i++)cout << zv[i] << " "; + cout << endl << "resx : "; for(int i=0; i<6; i++)cout << resx[i] << " "; + cout << endl << "resy : "; for(int i=0; i<6; i++)cout << resy[i] << " "; + cout << endl << "coval : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" "; + cout << endl << " "; for(int i=0; i<5; i++)cout << coval[1][i]<<" "; + cout << endl << " "; for(int i=0; i<5; i++)cout << coval[2][i]<<" "; + cout << endl << " "; for(int i=0; i<5; i++)cout << coval[3][i]<<" "; + cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" "; cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " "; cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " "; + cout << endl; } +/** + * Set the TrkTrack position measurements + */ +void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){ + for(int i=0; i<6; i++) xm[i]=*xmeas++; + for(int i=0; i<6; i++) ym[i]=*ymeas++; + for(int i=0; i<6; i++) zm[i]=*zmeas++; +} +/** + * Set the TrkTrack position resolution + */ +void TrkTrack::SetResolution(double *rx, double *ry){ + for(int i=0; i<6; i++) resx[i]=*rx++; + for(int i=0; i<6; i++) resy[i]=*ry++; +} +/** + * Set the TrkTrack good measurement + */ +void TrkTrack::SetGood(int *xg, int *yg){ + for(int i=0; i<6; i++) xgood[i]=*xg++; + for(int i=0; i<6; i++) ygood[i]=*yg++; +} + +/** + * Load the magnetic field + */ +void TrkTrack::LoadField(TString path){ + +// strcpy(path_.path,path.Data()); +// path_.pathlen = path.Length(); +// path_.error = 0; +// readb_(); + + TrkParams::Set(path,1); + TrkParams::Load(1); + +}; + + +/** + * Method to fill minimization-routine common + */ +void TrkTrack::FillMiniStruct(cMini2track& track){ + + for(int i=0; i<6; i++){ + + track.xgood[i]=xgood[i]; + track.ygood[i]=ygood[i]; + + track.xm[i]=xm[i]; + track.ym[i]=ym[i]; + track.zm[i]=zm[i]; + +// --- temporaneo ---------------------------- +// andrebbe inserita la dimensione del sensore + float segment = 100.; + track.xm_a[i]=xm[i]; + track.xm_b[i]=xm[i]; + track.ym_a[i]=ym[i]; + track.ym_b[i]=ym[i]; + if( xgood[i] && !ygood[i] ){ + track.ym_a[i] = track.ym_a[i]+segment; + track.ym_b[i] = track.ym_b[i]-segment; + }else if( !xgood[i] && ygood[i]){ + track.xm_a[i] = track.xm_a[i]+segment; + track.xm_b[i] = track.xm_b[i]-segment; + } +// --- temporaneo ---------------------------- + + track.resx[i]=resx[i]; + track.resy[i]=resy[i]; + } + + for(int i=0; i<5; i++) track.al[i]=al[i]; + track.zini = 23.5; +// ZINI = 23.5 !!! it should be the same parameter in all codes + +} +/** + * Method to set values from minimization-routine common + */ +void TrkTrack::SetFromMiniStruct(cMini2track *track){ + + for(int i=0; i<5; i++) { + al[i]=track->al[i]; + for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j]; + } + chi2 = track->chi2; + nstep = track->nstep; + for(int i=0; i<6; i++){ + xv[i] = track->xv[i]; + yv[i] = track->yv[i]; + zv[i] = track->zv[i]; + xm[i] = track->xm[i]; + ym[i] = track->ym[i]; + zm[i] = track->zm[i]; + axv[i] = track->axv[i]; + ayv[i] = track->ayv[i]; + } + +} +/** + * Tracking method. It calls F77 mini routine. + */ +void TrkTrack::Fit(double pfixed, int& fail, int iprint){ + + float al_ini[] = {0.,0.,0.,0.,0.}; + + extern cMini2track track_; + fail = 0; + FillMiniStruct(track_); + + // if fit variables have been reset, evaluate the initial guess + if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); + + // --------------------- free momentum + if(pfixed==0.) { + track_.pfixed=0.; + } + // --------------------- fixed momentum + if(pfixed!=0.) { + al[4]=1./pfixed; + track_.pfixed=pfixed; + } + + // store temporarily the initial guess + for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; + + // ------------------------------------------ + // call mini routine + TrkParams::Load(1); + if( !TrkParams::IsLoaded(1) ){ + cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"< " << 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]; +// } + + if(fail){ + if(iprint)cout << " >>>> fit failed >>>> drawing initial par"<At(ip)); + return pt; +}; +/* + * Method to retrieve the Y-view clusters associated to the track. + * @param ip Tracker plane (0-5) + */ +TrkCluster *TrkTrack::GetClusterY(int ip){ + cout << " TrkCluster *TrkTrack::GetClusterY(int ip) -- momentaneamente fuori servizio --"<< endl; + if(!cly)return NULL; + TrkCluster *pt = (TrkCluster*)(cly->At(ip)); + return pt; +}; + + +//-------------------------------------- +// +// +//-------------------------------------- +void TrkTrack::Clear(){ +// cout << "TrkTrack::Clear()"<Clear(); + if(cly)cly->Clear(); +}; +//-------------------------------------- +// +// +//-------------------------------------- +void TrkTrack::Delete(){ +// cout << "TrkTrack::Delete()"<ntrk() ; cout << endl << "nclsx() : " << this->nclsx(); cout << endl << "nclsy() : " << this->nclsy(); - for(int i=0; intrk(); i++) ((TrkTrack *)t[i])->Dump(); - for(int i=0; inclsx(); i++) ((TrkSinglet *)sx[i])->Dump(); - for(int i=0; inclsy(); i++) ((TrkSinglet *)sy[i])->Dump(); +// TClonesArray &t = *Track; +// TClonesArray &sx = *SingletX; +// TClonesArray &sy = *SingletY; +// for(int i=0; iDump(); +// for(int i=0; iDump(); +// for(int i=0; iDump(); + if(Track){ + TClonesArray &t = *Track; + for(int i=0; iDump(); + } + if(SingletX){ + TClonesArray &sx = *SingletX; + for(int i=0; iDump(); + } + if(SingletY){ + TClonesArray &sy = *SingletY; + for(int i=0; iDump(); + } } //-------------------------------------- // @@ -270,34 +642,126 @@ /** * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). */ -void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){ - // -// Track = new TClonesArray("TrkTrack"); -// SingletX = new TClonesArray("TrkSinglet"); -// SingletY = new TClonesArray("TrkSinglet"); +// void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){ + +// // 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; +// for(int i=0; intrk; i++){ +// t_track->seqno = i;// NBNBNBNB deve sempre essere = i +// t_track->image = l2->image[i]-1; +// // cout << "track "<seqno << t_track->image<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]; +// // t_track->clx[ip] = 0; +// // t_track->cly[ip] = 0; +// }; +// new(t[i]) TrkTrack(*t_track); +// t_track->Clear(); +// }; +// // *** SINGLETS *** +// if(!SingletX)SingletX = new TClonesArray("TrkSinglet"); +// TClonesArray &sx = *SingletX; +// for(int i=0; inclsx; 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]; +// // t_singlet->cls = 0; +// new(sx[i]) TrkSinglet(*t_singlet); +// t_singlet->Clear(); +// } +// if(!SingletY)SingletY = new TClonesArray("TrkSinglet"); +// TClonesArray &sy = *SingletY; +// for(int i=0; inclsy; 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]; +// // t_singlet->cls = 0; +// new(sy[i]) TrkSinglet(*t_singlet); +// t_singlet->Clear(); +// }; + +// delete t_track; +// delete t_singlet; +// } +//-------------------------------------- +// +// +//-------------------------------------- +/** + * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). + * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set. + * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch) + */ +void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){ + +// cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<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( l1 && !t_track->clx )t_track->clx = new TRefArray(6,0); + if( l1 && !t_track->cly )t_track->cly = new TRefArray(6,0); + //----------------------------------------------------- for(int i=0; intrk; i++){ - t_track->seqno = i; +// cout <<" TRACK "<seqno = i;// NBNBNBNB deve sempre essere = i t_track->image = l2->image[i]-1; -// cout << "track "<seqno << t_track->image<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->xgood[ip] = l2->cltrx[i][ip];//l2->xgood_nt[i][ip]; + t_track->ygood[ip] = l2->cltry[i][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]; @@ -310,49 +774,162 @@ 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 << " ip "<cltrx[i][ip] "<< l2->cltrx[i][ip]<cltry[i][ip] "<< l2->cltry[i][ip]<xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip); +// if(l1 && t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip); + if(l2->xgood_nt[i][ip]){ +// cout << " ip "<cltrx[i][ip] "<< l2->cltrx[i][ip]<cltrx[i][ip] "<< l2->cltrx[i][ip]<<" "; +// if( l1->GetCluster(l2->cltrx[i][ip]-1)->TestBit(l1->GetCluster(l2->cltrx[i][ip]-1)->kIsReferenced) )cout << ">> is referenced "; + if(l1)t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip); +// cout << " --- "<GetCluster(l2->cltrx[i][ip]-1)->GetUniqueID()<xgood[ip] = l2->cltrx[i][ip]; // WORK-AROUND ***** + }else{ + if(l1)t_track->clx->RemoveAt(ip); + } + if(l2->ygood_nt[i][ip]){ +// cout << " ip "<cltry[i][ip] "<< l2->cltry[i][ip]<cltry[i][ip] "<< l2->cltry[i][ip]<<" "; +// if( l1->GetCluster(l2->cltry[i][ip]-1)->TestBit(l1->GetCluster(l2->cltry[i][ip]-1)->kIsReferenced) )cout << ">> is referenced "; + if(l1)t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip); +// cout << " --- "<GetCluster(l2->cltry[i][ip]-1)->GetUniqueID()<ygood[ip] = l2->cltry[i][ip]; // WORK-AROUND ***** + }else{ + if(l1)t_track->cly->RemoveAt(ip); + } + //----------------------------------------------------- + //----------------------------------------------------- }; new(t[i]) TrkTrack(*t_track); t_track->Clear(); }; +// ---------------- // *** SINGLETS *** +// ---------------- + if(!SingletX)SingletX = new TClonesArray("TrkSinglet"); TClonesArray &sx = *SingletX; for(int i=0; inclsx; 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]; + //----------------------------------------------------- + if(l1) t_singlet->cls = l1->GetCluster(l2->clsx[i]-1); + //----------------------------------------------------- new(sx[i]) TrkSinglet(*t_singlet); t_singlet->Clear(); } + if(!SingletY)SingletY = new TClonesArray("TrkSinglet"); TClonesArray &sy = *SingletY; for(int i=0; inclsy; 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]; + //----------------------------------------------------- + if(l1) t_singlet->cls = l1->GetCluster(l2->clsy[i]-1); + //----------------------------------------------------- new(sy[i]) TrkSinglet(*t_singlet); t_singlet->Clear(); - }; + }; - delete t_track; - delete t_singlet; + delete t_track; + delete t_singlet; +} +/** + * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common). + */ + +void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const { + +// general variables +// l2->good2 = good2 ; + for(Int_t i=0; i<12 ; i++){ +// l2->crc[i] = crc[i]; + l2->good[i] = good[i]; + }; +// *** TRACKS *** + + if(Track){ + l2->ntrk = Track->GetEntries(); + for(Int_t i=0;intrk;i++){ + l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image; + l2->chi2_nt[i] = ((TrkTrack *)Track->At(i))->chi2; + l2->nstep_nt[i] = ((TrkTrack *)Track->At(i))->nstep; + for(int it1=0;it1<5;it1++){ + l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1]; + for(int it2=0;it2<5;it2++) + l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2]; + }; + for(int ip=0;ip<6;ip++){ + l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip]; + l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip]; + l2->xm_nt[i][ip] = ((TrkTrack *)Track->At(i))->xm[ip]; + l2->ym_nt[i][ip] = ((TrkTrack *)Track->At(i))->ym[ip]; + l2->zm_nt[i][ip] = ((TrkTrack *)Track->At(i))->zm[ip]; + l2->resx_nt[i][ip] = ((TrkTrack *)Track->At(i))->resx[ip]; + l2->resy_nt[i][ip] = ((TrkTrack *)Track->At(i))->resy[ip]; + l2->xv_nt[i][ip] = ((TrkTrack *)Track->At(i))->xv[ip]; + l2->yv_nt[i][ip] = ((TrkTrack *)Track->At(i))->yv[ip]; + l2->zv_nt[i][ip] = ((TrkTrack *)Track->At(i))->zv[ip]; + l2->axv_nt[i][ip] = ((TrkTrack *)Track->At(i))->axv[ip]; + l2->ayv_nt[i][ip] = ((TrkTrack *)Track->At(i))->ayv[ip]; + l2->dedx_x[i][ip] = ((TrkTrack *)Track->At(i))->dedx_x[ip]; + l2->dedx_y[i][ip] = ((TrkTrack *)Track->At(i))->dedx_y[ip]; + }; + } + } +// *** SINGLETS *** + if(SingletX){ + l2->nclsx = SingletX->GetEntries(); + for(Int_t i=0;inclsx;i++){ + l2->planex[i] = ((TrkSinglet *)SingletX->At(i))->plane; + l2->xs[i][0] = ((TrkSinglet *)SingletX->At(i))->coord[0]; + l2->xs[i][1] = ((TrkSinglet *)SingletX->At(i))->coord[1]; + l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl; + } + } + + if(SingletY){ + l2->nclsy = SingletY->GetEntries(); + for(Int_t i=0;inclsy;i++){ + l2->planey[i] = ((TrkSinglet *)SingletY->At(i))->plane; + l2->ys[i][0] = ((TrkSinglet *)SingletY->At(i))->coord[0]; + l2->ys[i][1] = ((TrkSinglet *)SingletY->At(i))->coord[1]; + l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl; + } + } } //-------------------------------------- // // //-------------------------------------- void TrkLevel2::Clear(){ - good2 = -1; for(Int_t i=0; i<12 ; i++){ - crc[i] = -1; + good[i] = -1; }; -/* Track->RemoveAll(); - SingletX->RemoveAll(); - SingletY->RemoveAll();*/ - // modify to avoid memory leakage - Track->Clear(); - SingletX->Clear(); - SingletY->Clear(); +// if(Track)Track->Clear("C"); +// if(SingletX)SingletX->Clear("C"); +// if(SingletY)SingletY->Clear("C"); + if(Track)Track->Delete(); + if(SingletX)SingletX->Delete(); + if(SingletY)SingletY->Delete(); +} +// //-------------------------------------- +// // +// // +// //-------------------------------------- +void TrkLevel2::Delete(){ + +// cout << "void TrkLevel2::Delete()"<ntrk(); - vector m(N); for(int i=0; intrk(); i++){ - if(((TrkTrack *)t[i])->chi2 < chi2ref && m[i]==1){ - chi2ref = ((TrkTrack *)t[i])->chi2; - indi = i; - } - } - if( ((TrkTrack *)t[indi])->image != -1 ){ - m[((TrkTrack *)t[indi])->image] = 0; - N--; - } - new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]); - m[indi] = 0; - N--; - indo++; - } - return sorted; -} -TClonesArray *TrkLevel2::GetTracks_NFitSorted(){ - - TClonesArray *sorted = new TClonesArray("TrkTrack"); - TClonesArray &t = *Track; - TClonesArray &ts = *sorted; - int N=this->ntrk(); + TRefArray *sorted = new TRefArray(); + + TClonesArray &t = *Track; +// TClonesArray &ts = *PhysicalTrack; + int N = ntrk(); vector m(N); for(int i=0; i 0){ +// while(N != 0){ int nfit =0; - float chi2ref=1000000; + float chi2ref = numeric_limits::max(); + // first loop to search maximum num. of fit points - for(int i=0; intrk(); i++){ + for(int i=0; i < ntrk(); i++){ if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){ nfit = ((TrkTrack *)t[i])->GetNtot(); -// cout << "1** "<ntrk(); i++){ - if( ((TrkTrack *)t[i])->chi2 < chi2ref - && ((TrkTrack *)t[i])->GetNtot()== nfit - && m[i]==1){ + for(int i=0; ichi2; + if(chi2 < 0) chi2 = -chi2*1000; + if( chi2 < chi2ref + && ((TrkTrack *)t[i])->GetNtot() == nfit + && m[i]==1){ chi2ref = ((TrkTrack *)t[i])->chi2; indi = i; -// cout << "2** "<HasImage() ){ m[((TrkTrack *)t[indi])->image] = 0; N--; - -// Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image ])->GetNtot(); -// Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image ])->chi2; - + // cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<Add( (TrkTrack*)t[indi] ); + m[indi] = 0; +// cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<> (TClonesArray*) Track ==0 "<= this->nclsx()){ + cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; + cout << " Stored x-singlets nclsx() = "<< this->nclsx() << endl; + return 0; + } + if(!SingletX)return 0; + TClonesArray &t = *(SingletX); + TrkSinglet *singlet = (TrkSinglet*)t[is]; + return singlet; +} +//-------------------------------------- +// +// +//-------------------------------------- +/** + * Retrieves the is-th stored Y singlet. + * @param it Singlet number, ranging from 0 to nclsx(). + */ +TrkSinglet *TrkLevel2::GetSingletY(int is){ + + if(is >= this->nclsy()){ + cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; + cout << " Stored y-singlets nclsy() = "<< this->nclsx() << endl; + return 0; + } + if(!SingletY)return 0; + TClonesArray &t = *(SingletY); + TrkSinglet *singlet = (TrkSinglet*)t[is]; + return singlet; +} +//-------------------------------------- +// +// +//-------------------------------------- +/** * Retrieves the it-th "physical" track, sorted by the method GetNTracks(). * @param it Track number, ranging from 0 to GetNTracks(). */ + TrkTrack *TrkLevel2::GetTrack(int it){ - if(it >= this->GetNTracks()){ - cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; - cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; - return 0; - } - TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it]; - GetTracks()->Delete();////TEMPORANEO - return track; + if(it >= this->GetNTracks()){ + cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; + cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; + return 0; + } + + TRefArray *sorted = GetTracks(); //TEMPORANEO + if(!sorted)return 0; + TrkTrack *track = (TrkTrack*)sorted->At(it); + sorted->Clear(); + delete sorted; + return track; } +/** + * Give the number of "physical" tracks, sorted by the method GetTracks(). + */ Int_t TrkLevel2::GetNTracks(){ - Int_t ntot=0; - ntot = GetTracks()->GetEntries(); - GetTracks()->Delete();////TEMPORANEO - return ntot; + + Float_t ntot=0; + if(!Track)return 0; + TClonesArray &t = *Track; + for(int i=0; iGetImageSeqNo() == -1 ) ntot+=1.; + else ntot+=0.5; + } + return (Int_t)ntot; + }; //-------------------------------------- // @@ -502,12 +1111,21 @@ cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; return 0; } - TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it]; + + TRefArray* sorted = GetTracks(); //TEMPORANEO + if(!sorted)return 0; + TrkTrack *track = (TrkTrack*)sorted->At(it); + if(!track->HasImage()){ cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl; return 0; } + if(!Track)return 0; TrkTrack *image = (TrkTrack*)(*Track)[track->image]; + + sorted->Delete(); + delete sorted; + return image; } @@ -519,8 +1137,63 @@ * Loads the magnetic field. * @param s Path of the magnetic-field files. */ -void TrkLevel2::LoadField(TString s){ - readb_(s.Data()); +void TrkLevel2::LoadField(TString path){ +// +// strcpy(path_.path,path.Data()); +// path_.pathlen = path.Length(); +// path_.error = 0; +// readb_(); + + TrkParams::Set(path,1); + TrkParams::Load(1); + +// +}; +/** + * Get BY (kGauss) + * @param v (x,y,z) coordinates in cm + */ +float TrkLevel2::GetBX(float* v){ + float b[3]; + gufld_(v,b); + return b[0]/10.; +} +/** + * Get BY (kGauss) + * @param v (x,y,z) coordinates in cm + */ +float TrkLevel2::GetBY(float* v){ + float b[3]; + gufld_(v,b); + return b[1]/10.; +} +/** + * Get BY (kGauss) + * @param v (x,y,z) coordinates in cm + */ +float TrkLevel2::GetBZ(float* v){ + float b[3]; + gufld_(v,b); + return b[2]/10.; +} +//-------------------------------------- +// +// +//-------------------------------------- +/** + * Get tracker-plane (mechanical) z-coordinate + * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM) + */ +Float_t TrkLevel2::GetZTrk(Int_t plane_id){ + switch(plane_id){ + case 1: return ZTRK1; + case 2: return ZTRK2; + case 3: return ZTRK3; + case 4: return ZTRK4; + case 5: return ZTRK5; + case 6: return ZTRK6; + default: return 0.; + }; }; //-------------------------------------- // @@ -538,11 +1211,11 @@ thx = new float[npoint]; thy = new float[npoint]; tl = new float[npoint]; - float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1); + float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); for(int i=0; i