/** * \file TrkLevel2.cpp * \author Elena Vannuccini */ #include #include #include using namespace std; //...................................... // F77 routines //...................................... extern "C" { void dotrack_(int*, double*, double*, double*, double*, int*); void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*); void mini2_(int*,int*,int*); void guess_(); void gufld_(float*, float*); float risxeta2_(float *); float risxeta3_(float *); float risxeta4_(float *); float risyeta2_(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 ip=0;ip<6;ip++){ xgood[ip] = 0; ygood[ip] = 0; xm[ip] = 0; ym[ip] = 0; zm[ip] = 0; resx[ip] = 0; resy[ip] = 0; tailx[ip] = 0; taily[ip] = 0; xv[ip] = 0; yv[ip] = 0; zv[ip] = 0; axv[ip] = 0; 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??? // clx = TRefArray(6,0); // cly = TRefArray(6,0); TrkParams::SetTrackingMode(); TrkParams::SetPrecisionFactor(); TrkParams::SetStepMin(); TrkParams::SetPFA(); }; //-------------------------------------- // // //-------------------------------------- TrkTrack::TrkTrack(const TrkTrack& t){ 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 ip=0;ip<6;ip++){ xgood[ip] = t.xgood[ip]; ygood[ip] = t.ygood[ip]; xm[ip] = t.xm[ip]; ym[ip] = t.ym[ip]; zm[ip] = t.zm[ip]; resx[ip] = t.resx[ip]; resy[ip] = t.resy[ip]; tailx[ip] = t.tailx[ip]; taily[ip] = t.taily[ip]; xv[ip] = t.xv[ip]; yv[ip] = t.yv[ip]; zv[ip] = t.zv[ip]; axv[ip] = t.axv[ip]; 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)); // clx = TRefArray(t.clx); // cly = TRefArray(t.cly); TrkParams::SetTrackingMode(); TrkParams::SetPrecisionFactor(); TrkParams::SetStepMin(); TrkParams::SetPFA(); }; //-------------------------------------- // // //-------------------------------------- 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.tailx[ip] = tailx[ip]; t.taily[ip] = taily[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]; }; // t.clx = TRefArray(clx); // t.cly = TRefArray(cly); }; //-------------------------------------- // // //-------------------------------------- /** * 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. */ int TrkTrack::DoTrack(Trajectory* t){ 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; 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++){ t->x[i] = (float)*dxout++; t->y[i] = (float)*dyout++; } // delete [] dxout; // delete [] dyout; // delete [] dzin; return ifail; }; //-------------------------------------- // // //-------------------------------------- /** * 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. */ int TrkTrack::DoTrack2(Trajectory* t){ double *dxout = new double[t->npoint]; double *dyout = new double[t->npoint]; double *dthxout = new double[t->npoint]; double *dthyout = new double[t->npoint]; double *dtlout = 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; 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++){ t->x[i] = (float)*dxout++; t->y[i] = (float)*dyout++; t->thx[i] = (float)*dthxout++; t->thy[i] = (float)*dthyout++; t->tl[i] = (float)*dtlout++; } // delete [] dxout; // delete [] dyout; // delete [] dzin; return ifail; }; //-------------------------------------- // // //-------------------------------------- //float TrkTrack::BdL(){ //}; //-------------------------------------- // // //-------------------------------------- Float_t TrkTrack::GetRigidity(){ Float_t rig=0; if(chi2>0)rig=1./al[4]; if(rig<0) rig=-rig; return rig; }; // Float_t TrkTrack::GetDeflection(){ Float_t def=0; if(chi2>0)def=al[4]; return def; }; // /** * Method to retrieve the dE/dx measured on a tracker view. * @param ip plane (0-5) * @param iv view (0=x 1=y) */ Float_t TrkTrack::GetDEDX(int ip, int iv){ if(iv==0 && ip>=0 && ip<6)return fabs(dedx_x[ip]); else if(iv==1 && ip>=0 && ip<6)return fabs(dedx_y[ip]); else { cout << "TrkTrack::GetDEDX(int ip, int iv) -- wrong input parameters "<=0 && ip<6)return (xgood[ip]<0) ; else if(iv==1 && ip>=0 && ip<6)return (ygood[ip]<0) ; else { cout << "TrkTrack::IsBad(int ip, int iv) -- wrong input parameters "<=0 && ip<6)return (dedx_x[ip]<0) ; else if(iv==1 && ip>=0 && ip<6)return (dedx_y[ip]<0) ; else { cout << "TrkTrack::IsSaturated(int ip, int iv) -- wrong input parameters "<10) index=10; tailx[i]=tx[index]; if(flag==1) { if(fabs(axv[i])<=10.) fact = resx[i]/risxeta2_(&(axv[i])); if(fabs(axv[i])>10.&&fabs(axv[i])<=15.) fact = resx[i]/risxeta3_(&(axv[i])); if(fabs(axv[i])>15.) fact = resx[i]/risxeta4_(&(axv[i])); } else fact = 1.; resx[i] = sx[index]*fact; } for(int i=0; i<6; i++) { index = int((fabs(ayv[i])+1.)/2.); if(index>10) index=10; taily[i]=ty[index]; if(flag==1) fact = resy[i]/risyeta2_(&(ayv[i])); else fact = 1.; resy[i] = sy[index]*fact; } } /** * 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::SetTrackingMode(); TrkParams::SetPrecisionFactor(); TrkParams::SetStepMin(); 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++){ // cout << i<<" - "<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]; } } /** * \brief Method to re-evaluate coordinates of clusters associated with a track. * * The method can be applied only after recovering level1 information * (either by reprocessing single events from level0 or from * the TrkLevel1 branch, if present); it calls F77 subroutines that * read the level1 common and fill the minimization-routine common. * Some clusters can be excluded or added by means of the methods: * * TrkTrack::ResetXGood(int ip) * TrkTrack::ResetYGood(int ip) * TrkTrack::SetXGood(int ip, int cid, int is) * TrkTrack::SetYGood(int ip, int cid, int is) * * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1) * for the minimization-routine common. It deletes the cluster information * (at least for the moment...) thus cannot be applied before * TrkTrack::EvaluateClusterPositions(). * * Different p.f.a. can be applied by calling (once) the method: * * TrkParams::SetPFA(0); //Set ETA p.f.a. * * @see TrkParams::SetPFA(int) */ void TrkTrack::EvaluateClusterPositions(){ // cout << "void TrkTrack::GetClusterPositions() "<GetTrkLevel0() )return false; * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1 * int fail=0; * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1); * * @see EvaluateClusterPositions() * * The fitting procedure can be varied by changing the tracking mode, * the fit-precision factor and the minimum number of step. * @see SetTrackingMode(int) * @see SetPrecisionFactor(double) * @see SetStepMin(int) */ void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){ float al_ini[] = {0.,0.,0.,0.,0.}; TrkParams::Load( ); if( !TrkParams::IsLoaded() )return; extern cMini2track track_; fail = 0; FillMiniStruct(track_); if(froml1!=0)EvaluateClusterPositions(); // 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"<>>> fit failed "<XMAGNLOW && xmagntopYMAGNLOW && ymagntopXMAGNLOW && xmagnbottomYMAGNLOW && ymagnbottomClear(); // if(cly)cly->Clear(); // clx.Clear(); // cly.Clear(); }; //-------------------------------------- // // //-------------------------------------- void TrkTrack::Delete(){ // cout << "TrkTrack::Delete()"<ntrk() ; cout << endl << "nclsx() : " << this->nclsx(); cout << endl << "nclsy() : " << this->nclsy(); 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(); } } //-------------------------------------- // // //-------------------------------------- /** * The method returns false if the viking-chip was masked * either apriori ,on the basis of the mask read from the DB, * or run-by-run, on the basis of the calibration parameters) * @param iv Tracker view (0-11) * @param ivk Viking-chip number (0-23) */ Bool_t TrkLevel2::GetVKMask(int iv, int ivk){ Int_t whichbit = (Int_t)pow(2,ivk); return (whichbit&VKmask[iv])!=0; } /** * The method returns false if the viking-chip was masked * for this event due to common-noise computation failure. * @param iv Tracker view (0-11) * @param ivk Viking-chip number (0-23) */ Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){ Int_t whichbit = (Int_t)pow(2,ivk); return (whichbit&VKflag[iv])!=0; } /** * The method returns true if the viking-chip was masked, either * forced (see TrkLevel2::GetVKMask(int,int)) or * for this event only (TrkLevel2::GetVKFlag(int,int)). * @param iv Tracker view (0-11) * @param ivk Viking-chip number (0-23) */ Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){ return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) ); }; //-------------------------------------- // // //-------------------------------------- /** * 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)"<good[i]; VKmask[i]=0; VKflag[i]=0; for(Int_t ii=0; ii<24 ; ii++){ Int_t setbit = (Int_t)pow(2,ii); if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit; if( l2->vkflag[ii][i]!=0 )VKflag[i]=VKflag[i]|setbit; }; }; // -------------- // *** 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; 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++){ // --------------------------------- // new implementation of xgood/ygood // --------------------------------- t_track->xgood[ip] = l2->cltrx[i][ip]; //cluster ID t_track->ygood[ip] = l2->cltry[i][ip]; //cluster ID t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip]; if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip]; // if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){ // if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){ // cout << ip << " - "<< l2->cltrx[i][ip] << " "<cltry[i][ip]<<" "<ls[i][ip]<xgood[ip]<<" "<ygood[ip]<GetClusterX_ID(ip)<<" "<GetClusterY_ID(ip)<<" "<GetLadder(ip)<<" "<GetSensor(ip)<BadClusterX(ip)<<" "<BadClusterY(ip)<SaturatedClusterX(ip)<<" "<SaturatedClusterY(ip)<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->tailx[ip] = l2->tailx[i][ip]; t_track->taily[ip] = l2->taily[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]; //----------------------------------------------------- //----------------------------------------------------- //----------------------------------------------------- //----------------------------------------------------- }; // if(t_track->IsSaturated())t_track->Dump(); 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; } /** * 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->tailx[i][ip] = ((TrkTrack *)Track->At(i))->tailx[ip]; l2->taily[i][ip] = ((TrkTrack *)Track->At(i))->taily[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(){ for(Int_t i=0; i<12 ; i++){ good[i] = -1; VKflag[i] = 0; VKmask[i] = 0; }; // 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()"< m(N); for(int i=0; i 0){ // while(N != 0){ int nfit =0; float chi2ref = numeric_limits::max(); // first loop to search maximum num. of fit points for(int i=0; i < ntrk(); i++){ if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){ nfit = ((TrkTrack *)t[i])->GetNtot(); } } //second loop to search minimum chi2 among selected 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; }; }; if( ((TrkTrack *)t[indi])->HasImage() ){ m[((TrkTrack *)t[indi])->image] = 0; N--; // cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<Add( (TrkTrack*)t[indi] ); m[indi] = 0; // cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<= this->ntrk()){ cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl; cout << " Stored tracks ntrk() = "<< this->ntrk() << endl; return 0; } if(!Track){ cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (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; } 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(){ 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; }; //-------------------------------------- // // //-------------------------------------- /** * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks(). * @param it Track number, ranging from 0 to GetNTracks(). */ TrkTrack *TrkLevel2::GetTrackImage(int it){ 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); 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; } //-------------------------------------- // // //-------------------------------------- /** * Loads the magnetic field. * @param s Path of the magnetic-field files. */ void TrkLevel2::LoadField(TString path){ // // strcpy(path_.path,path.Data()); // path_.pathlen = path.Length(); // path_.error = 0; // readb_(); TrkParams::SetTrackingMode(); TrkParams::SetPrecisionFactor(); TrkParams::SetStepMin(); 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.; }; }; //-------------------------------------- // // //-------------------------------------- /** * Trajectory default constructor. * (By default is created with z-coordinates inside the tracking volume) */ Trajectory::Trajectory(){ npoint = 10; x = new float[npoint]; y = new float[npoint]; z = new float[npoint]; thx = new float[npoint]; thy = new float[npoint]; tl = new float[npoint]; float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); for(int i=0; i>> created with 10 points" << endl; n=10; } npoint = n; x = new float[npoint]; y = new float[npoint]; z = new float[npoint]; thx = new float[npoint]; thy = new float[npoint]; tl = new float[npoint]; float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); for(int i=0; i0)npoint = n; x = new float[npoint]; y = new float[npoint]; z = new float[npoint]; thx = new float[npoint]; thy = new float[npoint]; tl = new float[npoint]; int i=0; do{ x[i] = 0; y[i] = 0; z[i] = zin[i]; thx[i] = 0; thy[i] = 0; tl[i] = 0; i++; }while(zin[i-1] > zin[i] && i < npoint); npoint=i; if(npoint != n)cout << "NB! Trajectory created with "<> " << x[i] <<" "<< y[i] <<" "<< z[i] ; cout <<" -- " << thx[i] <<" "<< thy[i] ; cout <<" -- " << tl[i] << endl; }; } //-------------------------------------- // // //-------------------------------------- /** * Get trajectory length between two points * @param ifirst first point (default 0) * @param ilast last point (default npoint) */ float Trajectory::GetLength(int ifirst, int ilast){ if( ifirst<0 ) ifirst = 0; if( ilast>=npoint) ilast = npoint-1; float l=0; for(int i=ifirst;i<=ilast;i++){ l=l+tl[i]; }; if(z[ilast] > ZINI)l=l-tl[ilast]; if(z[ifirst] < ZINI) l=l-tl[ifirst]; return l; } /** * 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. */ int Trajectory::DoTrack2(float* al){ double *dxout = new double[npoint]; double *dyout = new double[npoint]; double *dthxout = new double[npoint]; double *dthyout = new double[npoint]; double *dtlout = new double[npoint]; double *dzin = new double[npoint]; double dal[5]; int ifail = 0; for (int i=0; i<5; i++) dal[i] = (double)al[i]; for (int i=0; i