| 1 |
/** |
| 2 |
* \file TrkLevel2.cpp |
| 3 |
* \author Elena Vannuccini |
| 4 |
*/ |
| 5 |
#include <TrkLevel2.h> |
| 6 |
#include <iostream> |
| 7 |
#include <math.h> |
| 8 |
using namespace std; |
| 9 |
//...................................... |
| 10 |
// F77 routines |
| 11 |
//...................................... |
| 12 |
extern "C" { |
| 13 |
void dotrack_(int*, double*, double*, double*, double*, int*); |
| 14 |
void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*); |
| 15 |
int readb_(const char*); |
| 16 |
void mini2_(int*,int*,int*); |
| 17 |
void guess_(); |
| 18 |
} |
| 19 |
//-------------------------------------- |
| 20 |
// |
| 21 |
// |
| 22 |
//-------------------------------------- |
| 23 |
TrkTrack::TrkTrack(){ |
| 24 |
seqno = -1; |
| 25 |
image = -1; |
| 26 |
chi2 = 0; |
| 27 |
nstep = 0; |
| 28 |
for(int it1=0;it1<5;it1++){ |
| 29 |
al[it1] = 0; |
| 30 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
| 31 |
}; |
| 32 |
for(int ip=0;ip<6;ip++){ |
| 33 |
xgood[ip] = 0; |
| 34 |
ygood[ip] = 0; |
| 35 |
xm[ip] = 0; |
| 36 |
ym[ip] = 0; |
| 37 |
zm[ip] = 0; |
| 38 |
resx[ip] = 0; |
| 39 |
resy[ip] = 0; |
| 40 |
xv[ip] = 0; |
| 41 |
yv[ip] = 0; |
| 42 |
zv[ip] = 0; |
| 43 |
axv[ip] = 0; |
| 44 |
ayv[ip] = 0; |
| 45 |
dedx_x[ip] = 0; |
| 46 |
dedx_y[ip] = 0; |
| 47 |
// clx[ip] = 0; |
| 48 |
// cly[ip] = 0; |
| 49 |
}; |
| 50 |
clx = new TRefArray(6,0); |
| 51 |
cly = new TRefArray(6,0); |
| 52 |
}; |
| 53 |
//-------------------------------------- |
| 54 |
// |
| 55 |
// |
| 56 |
//-------------------------------------- |
| 57 |
TrkTrack::TrkTrack(const TrkTrack& t){ |
| 58 |
seqno = t.seqno; |
| 59 |
image = t.image; |
| 60 |
chi2 = t.chi2; |
| 61 |
nstep = t.nstep; |
| 62 |
for(int it1=0;it1<5;it1++){ |
| 63 |
al[it1] = t.al[it1]; |
| 64 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2]; |
| 65 |
}; |
| 66 |
for(int ip=0;ip<6;ip++){ |
| 67 |
xgood[ip] = t.xgood[ip]; |
| 68 |
ygood[ip] = t.ygood[ip]; |
| 69 |
xm[ip] = t.xm[ip]; |
| 70 |
ym[ip] = t.ym[ip]; |
| 71 |
zm[ip] = t.zm[ip]; |
| 72 |
resx[ip] = t.resx[ip]; |
| 73 |
resy[ip] = t.resy[ip]; |
| 74 |
xv[ip] = t.xv[ip]; |
| 75 |
yv[ip] = t.yv[ip]; |
| 76 |
zv[ip] = t.zv[ip]; |
| 77 |
axv[ip] = t.axv[ip]; |
| 78 |
ayv[ip] = t.ayv[ip]; |
| 79 |
dedx_x[ip] = t.dedx_x[ip]; |
| 80 |
dedx_y[ip] = t.dedx_y[ip]; |
| 81 |
// clx[ip] = 0;//<<<<pointer |
| 82 |
// cly[ip] = 0;//<<<<pointer |
| 83 |
}; |
| 84 |
clx = new TRefArray(*(t.clx)); |
| 85 |
cly = new TRefArray(*(t.cly)); |
| 86 |
|
| 87 |
}; |
| 88 |
//-------------------------------------- |
| 89 |
// |
| 90 |
// |
| 91 |
//-------------------------------------- |
| 92 |
/** |
| 93 |
* Evaluates the trajectory in the apparatus associated to the track. |
| 94 |
* 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. |
| 95 |
* @param t pointer to an object of the class Trajectory, |
| 96 |
* which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). |
| 97 |
* @return error flag. |
| 98 |
*/ |
| 99 |
int TrkTrack::DoTrack(Trajectory* t){ |
| 100 |
|
| 101 |
double *dxout = new double[t->npoint]; |
| 102 |
double *dyout = new double[t->npoint]; |
| 103 |
double *dzin = new double[t->npoint]; |
| 104 |
double dal[5]; |
| 105 |
|
| 106 |
int ifail = 0; |
| 107 |
|
| 108 |
for (int i=0; i<5; i++) dal[i] = (double)al[i]; |
| 109 |
for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i]; |
| 110 |
|
| 111 |
dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail); |
| 112 |
|
| 113 |
for (int i=0; i<t->npoint; i++){ |
| 114 |
t->x[i] = (float)*dxout++; |
| 115 |
t->y[i] = (float)*dyout++; |
| 116 |
} |
| 117 |
|
| 118 |
// delete [] dxout; |
| 119 |
// delete [] dyout; |
| 120 |
// delete [] dzin; |
| 121 |
|
| 122 |
return ifail; |
| 123 |
}; |
| 124 |
//-------------------------------------- |
| 125 |
// |
| 126 |
// |
| 127 |
//-------------------------------------- |
| 128 |
/** |
| 129 |
* Evaluates the trajectory in the apparatus associated to the track. |
| 130 |
* 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. |
| 131 |
* @param t pointer to an object of the class Trajectory, |
| 132 |
* which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). |
| 133 |
* @return error flag. |
| 134 |
*/ |
| 135 |
int TrkTrack::DoTrack2(Trajectory* t){ |
| 136 |
|
| 137 |
double *dxout = new double[t->npoint]; |
| 138 |
double *dyout = new double[t->npoint]; |
| 139 |
double *dthxout = new double[t->npoint]; |
| 140 |
double *dthyout = new double[t->npoint]; |
| 141 |
double *dtlout = new double[t->npoint]; |
| 142 |
double *dzin = new double[t->npoint]; |
| 143 |
double dal[5]; |
| 144 |
|
| 145 |
int ifail = 0; |
| 146 |
|
| 147 |
for (int i=0; i<5; i++) dal[i] = (double)al[i]; |
| 148 |
for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i]; |
| 149 |
|
| 150 |
dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); |
| 151 |
|
| 152 |
for (int i=0; i<t->npoint; i++){ |
| 153 |
t->x[i] = (float)*dxout++; |
| 154 |
t->y[i] = (float)*dyout++; |
| 155 |
t->thx[i] = (float)*dthxout++; |
| 156 |
t->thy[i] = (float)*dthyout++; |
| 157 |
t->tl[i] = (float)*dtlout++; |
| 158 |
} |
| 159 |
|
| 160 |
// delete [] dxout; |
| 161 |
// delete [] dyout; |
| 162 |
// delete [] dzin; |
| 163 |
|
| 164 |
return ifail; |
| 165 |
}; |
| 166 |
//-------------------------------------- |
| 167 |
// |
| 168 |
// |
| 169 |
//-------------------------------------- |
| 170 |
//float TrkTrack::BdL(){ |
| 171 |
//}; |
| 172 |
//-------------------------------------- |
| 173 |
// |
| 174 |
// |
| 175 |
//-------------------------------------- |
| 176 |
Float_t TrkTrack::GetRigidity(){ |
| 177 |
Float_t rig=0; |
| 178 |
if(chi2>0)rig=1./al[4]; |
| 179 |
if(rig<0) rig=-rig; |
| 180 |
return rig; |
| 181 |
}; |
| 182 |
// |
| 183 |
Float_t TrkTrack::GetDeflection(){ |
| 184 |
Float_t def=0; |
| 185 |
if(chi2>0)def=al[4]; |
| 186 |
return def; |
| 187 |
}; |
| 188 |
// |
| 189 |
Float_t TrkTrack::GetDEDX(){ |
| 190 |
Float_t dedx=0; |
| 191 |
for(Int_t i=0; i<6; i++)dedx+=dedx_x[i]*xgood[i]+dedx_y[i]*ygood[i]; |
| 192 |
dedx = dedx/(this->GetNX()+this->GetNY()); |
| 193 |
return dedx; |
| 194 |
}; |
| 195 |
|
| 196 |
//-------------------------------------- |
| 197 |
// |
| 198 |
// |
| 199 |
//-------------------------------------- |
| 200 |
void TrkTrack::Dump(){ |
| 201 |
cout << endl << "========== Track " ; |
| 202 |
cout << endl << "seq. n. : "<< seqno; |
| 203 |
cout << endl << "image n. : "<< image; |
| 204 |
cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " "; |
| 205 |
cout << endl << "chi^2 : "<< chi2; |
| 206 |
cout << endl << "n.step : "<< nstep; |
| 207 |
cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << xgood[i] ; |
| 208 |
cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << ygood[i] ; |
| 209 |
cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " "; |
| 210 |
cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " "; |
| 211 |
cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " "; |
| 212 |
cout << endl << "xv : "; for(int i=0; i<6; i++)cout << xv[i] << " "; |
| 213 |
cout << endl << "yv : "; for(int i=0; i<6; i++)cout << yv[i] << " "; |
| 214 |
cout << endl << "zv : "; for(int i=0; i<6; i++)cout << zv[i] << " "; |
| 215 |
cout << endl << "resx : "; for(int i=0; i<6; i++)cout << resx[i] << " "; |
| 216 |
cout << endl << "resy : "; for(int i=0; i<6; i++)cout << resy[i] << " "; |
| 217 |
cout << endl << "coval : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" "; |
| 218 |
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[1][i]<<" "; |
| 219 |
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[2][i]<<" "; |
| 220 |
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[3][i]<<" "; |
| 221 |
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" "; |
| 222 |
cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " "; |
| 223 |
cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " "; |
| 224 |
cout << endl; |
| 225 |
} |
| 226 |
/** |
| 227 |
* Set the TrkTrack position measurements |
| 228 |
*/ |
| 229 |
void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){ |
| 230 |
for(int i=0; i<6; i++) xm[i]=*xmeas++; |
| 231 |
for(int i=0; i<6; i++) ym[i]=*ymeas++; |
| 232 |
for(int i=0; i<6; i++) zm[i]=*zmeas++; |
| 233 |
} |
| 234 |
/** |
| 235 |
* Set the TrkTrack position resolution |
| 236 |
*/ |
| 237 |
void TrkTrack::SetResolution(double *rx, double *ry){ |
| 238 |
for(int i=0; i<6; i++) resx[i]=*rx++; |
| 239 |
for(int i=0; i<6; i++) resy[i]=*ry++; |
| 240 |
} |
| 241 |
/** |
| 242 |
* Set the TrkTrack good measurement |
| 243 |
*/ |
| 244 |
void TrkTrack::SetGood(int *xg, int *yg){ |
| 245 |
for(int i=0; i<6; i++) xgood[i]=*xg++; |
| 246 |
for(int i=0; i<6; i++) ygood[i]=*yg++; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Load the magnetic field |
| 251 |
*/ |
| 252 |
void TrkTrack::LoadField(TString s){ |
| 253 |
readb_(s.Data()); |
| 254 |
}; |
| 255 |
/** |
| 256 |
* Tracking method. It calls F77 mini routine. |
| 257 |
*/ |
| 258 |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
| 259 |
|
| 260 |
float al_ini[] = {0.,0.,0.,0.,0.}; |
| 261 |
|
| 262 |
extern cMini2track track_; |
| 263 |
fail = 0; |
| 264 |
// extern cMini2fitinfo fit_info_; |
| 265 |
// extern void mini_2_(int*,int*); |
| 266 |
// track_.xm[0]=1.0; |
| 267 |
|
| 268 |
cout << "fitting routine "<<endl; |
| 269 |
|
| 270 |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
| 271 |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
| 272 |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
| 273 |
for(int i=0; i<6; i++) track_.resx[i]=resx[i]; |
| 274 |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
| 275 |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
| 276 |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
| 277 |
|
| 278 |
// initial guess of "al" with linear fit |
| 279 |
// if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){ |
| 280 |
|
| 281 |
// cout << "initial guess "<<endl; |
| 282 |
|
| 283 |
// double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
| 284 |
// double det, ax, ay, bx, by; |
| 285 |
// for(int i=0; i<NPLANE; i++) { |
| 286 |
// szz=szz+zm[i]*zm[i]; |
| 287 |
// szx=szx+zm[i]*xm[i]; |
| 288 |
// szy=szy+zm[i]*ym[i]; |
| 289 |
// ssx=ssx+xm[i]; |
| 290 |
// ssy=ssy+ym[i]; |
| 291 |
// sz=sz+zm[i]; |
| 292 |
// s1=s1+1.; |
| 293 |
// } |
| 294 |
// det=szz*s1-sz*sz; |
| 295 |
// ax=(szx*s1-sz*ssx)/det; |
| 296 |
// bx=(szz*ssx-szx*sz)/det; |
| 297 |
// ay=(szy*s1-sz*ssy)/det; |
| 298 |
// by=(szz*ssy-szy*sz)/det; |
| 299 |
// al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
| 300 |
// al[1]=ay*23.5+by; // " |
| 301 |
// al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
| 302 |
// al[3]=0.; |
| 303 |
// if( (ax!=0.)||(ay!=0.) ) { |
| 304 |
// al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
| 305 |
// if(ax<0.) al[3]=acos(-1.)-al[3]; |
| 306 |
// } |
| 307 |
// al[4]=0.; |
| 308 |
|
| 309 |
// } |
| 310 |
// end guess |
| 311 |
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
| 312 |
track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes |
| 313 |
|
| 314 |
// elena ----- |
| 315 |
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
| 316 |
// elena ----- |
| 317 |
|
| 318 |
if(pfixed==0.) { |
| 319 |
// al[4]=0.; // free momentum |
| 320 |
track_.pfixed=0.; // " |
| 321 |
} |
| 322 |
if(pfixed!=0.) { |
| 323 |
al[4]=1./pfixed; // to fix the momentum |
| 324 |
track_.pfixed=pfixed; // " |
| 325 |
} |
| 326 |
|
| 327 |
// 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; |
| 332 |
int ifail=0; |
| 333 |
mini2_(&istep,&ifail, &iprint); |
| 334 |
if(ifail!=0) { |
| 335 |
if(iprint==1)cout << "ERROR: ifail= " << ifail << endl; |
| 336 |
fail = 1; |
| 337 |
// return; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
| 342 |
|
| 343 |
for(int i=0; i<5; i++) al[i]=track_.al[i]; |
| 344 |
chi2=track_.chi2; |
| 345 |
nstep=track_.nstep; |
| 346 |
for(int i=0; i<6; i++) xv[i]=track_.xv[i]; |
| 347 |
for(int i=0; i<6; i++) yv[i]=track_.yv[i]; |
| 348 |
for(int i=0; i<6; i++) zv[i]=track_.zv[i]; |
| 349 |
for(int i=0; i<6; i++) axv[i]=track_.axv[i]; |
| 350 |
for(int i=0; i<6; i++) ayv[i]=track_.ayv[i]; |
| 351 |
for(int i=0; i<5; i++) { |
| 352 |
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 fit parameters |
| 363 |
*/ |
| 364 |
void TrkTrack::FitReset(){ |
| 365 |
for(int i=0; i<5; i++) al[i]=-9999.; |
| 366 |
chi2=0.; |
| 367 |
nstep=0; |
| 368 |
for(int i=0; i<6; i++) xv[i]=0.; |
| 369 |
for(int i=0; i<6; i++) yv[i]=0.; |
| 370 |
for(int i=0; i<6; i++) zv[i]=0.; |
| 371 |
for(int i=0; i<6; i++) axv[i]=0.; |
| 372 |
for(int i=0; i<6; i++) ayv[i]=0.; |
| 373 |
for(int i=0; i<5; i++) { |
| 374 |
for(int j=0; j<5; j++) coval[i][j]=0.; |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
//-------------------------------------- |
| 379 |
// |
| 380 |
// |
| 381 |
//-------------------------------------- |
| 382 |
void TrkTrack::Clear(){ |
| 383 |
seqno = -1; |
| 384 |
image = -1; |
| 385 |
chi2 = 0; |
| 386 |
nstep = 0; |
| 387 |
for(int it1=0;it1<5;it1++){ |
| 388 |
al[it1] = 0; |
| 389 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
| 390 |
}; |
| 391 |
for(int ip=0;ip<6;ip++){ |
| 392 |
xgood[ip] = 0; |
| 393 |
ygood[ip] = 0; |
| 394 |
xm[ip] = 0; |
| 395 |
ym[ip] = 0; |
| 396 |
zm[ip] = 0; |
| 397 |
resx[ip] = 0; |
| 398 |
resy[ip] = 0; |
| 399 |
xv[ip] = 0; |
| 400 |
yv[ip] = 0; |
| 401 |
zv[ip] = 0; |
| 402 |
axv[ip] = 0; |
| 403 |
ayv[ip] = 0; |
| 404 |
dedx_x[ip] = 0; |
| 405 |
dedx_y[ip] = 0; |
| 406 |
// clx[ip] = 0; |
| 407 |
// cly[ip] = 0; |
| 408 |
}; |
| 409 |
clx->Clear(); |
| 410 |
cly->Clear(); |
| 411 |
}; |
| 412 |
//-------------------------------------- |
| 413 |
// |
| 414 |
// |
| 415 |
//-------------------------------------- |
| 416 |
void TrkTrack::Delete(){ |
| 417 |
Clear(); |
| 418 |
clx->Delete(); |
| 419 |
cly->Delete(); |
| 420 |
}; |
| 421 |
//-------------------------------------- |
| 422 |
// |
| 423 |
// |
| 424 |
//-------------------------------------- |
| 425 |
|
| 426 |
//-------------------------------------- |
| 427 |
// |
| 428 |
// |
| 429 |
//-------------------------------------- |
| 430 |
TrkSinglet::TrkSinglet(){ |
| 431 |
plane = 0; |
| 432 |
coord[0] = 0; |
| 433 |
coord[1] = 0; |
| 434 |
sgnl = 0; |
| 435 |
cls = 0; |
| 436 |
}; |
| 437 |
//-------------------------------------- |
| 438 |
// |
| 439 |
// |
| 440 |
//-------------------------------------- |
| 441 |
TrkSinglet::TrkSinglet(const TrkSinglet& s){ |
| 442 |
plane = s.plane; |
| 443 |
coord[0] = s.coord[0]; |
| 444 |
coord[1] = s.coord[1]; |
| 445 |
sgnl = s.sgnl; |
| 446 |
// cls = 0;//<<<<pointer |
| 447 |
cls = TRef(s.cls); |
| 448 |
}; |
| 449 |
//-------------------------------------- |
| 450 |
// |
| 451 |
// |
| 452 |
//-------------------------------------- |
| 453 |
void TrkSinglet::Dump(){ |
| 454 |
int i=0; |
| 455 |
cout << endl << "========== Singlet " ; |
| 456 |
cout << endl << "plane : " << plane; |
| 457 |
cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++; |
| 458 |
cout << endl << "sgnl : " << sgnl; |
| 459 |
} |
| 460 |
//-------------------------------------- |
| 461 |
// |
| 462 |
// |
| 463 |
//-------------------------------------- |
| 464 |
TrkLevel2::TrkLevel2(){ |
| 465 |
// good2 = -1; |
| 466 |
for(Int_t i=0; i<12 ; i++){ |
| 467 |
// crc[i] = -1; |
| 468 |
good[i] = -1; |
| 469 |
}; |
| 470 |
Track = new TClonesArray("TrkTrack"); |
| 471 |
SingletX = new TClonesArray("TrkSinglet"); |
| 472 |
SingletY = new TClonesArray("TrkSinglet"); |
| 473 |
|
| 474 |
// PhysicalTrack = new TClonesArray("TrkTrack"); |
| 475 |
//sostituire con TRefArray... appena ho capito come si usa |
| 476 |
} |
| 477 |
//-------------------------------------- |
| 478 |
// |
| 479 |
// |
| 480 |
//-------------------------------------- |
| 481 |
void TrkLevel2::Dump(){ |
| 482 |
|
| 483 |
TClonesArray &t = *Track; |
| 484 |
TClonesArray &sx = *SingletX; |
| 485 |
TClonesArray &sy = *SingletY; |
| 486 |
// |
| 487 |
cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"; |
| 488 |
cout << endl << "good : "; for(int i=0; i<12; i++) cout << good[i]<<" "; |
| 489 |
cout << endl << "ntrk() : " << this->ntrk() ; |
| 490 |
cout << endl << "nclsx() : " << this->nclsx(); |
| 491 |
cout << endl << "nclsy() : " << this->nclsy(); |
| 492 |
for(int i=0; i<this->ntrk(); i++) ((TrkTrack *)t[i])->Dump(); |
| 493 |
for(int i=0; i<this->nclsx(); i++) ((TrkSinglet *)sx[i])->Dump(); |
| 494 |
for(int i=0; i<this->nclsy(); i++) ((TrkSinglet *)sy[i])->Dump(); |
| 495 |
} |
| 496 |
//-------------------------------------- |
| 497 |
// |
| 498 |
// |
| 499 |
//-------------------------------------- |
| 500 |
/** |
| 501 |
* Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). |
| 502 |
*/ |
| 503 |
void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){ |
| 504 |
|
| 505 |
// temporary objects: |
| 506 |
TrkSinglet* t_singlet = new TrkSinglet(); |
| 507 |
TrkTrack* t_track = new TrkTrack(); |
| 508 |
|
| 509 |
// **** general variables **** |
| 510 |
// good2 = l2->good2; |
| 511 |
for(Int_t i=0; i<12 ; i++){ |
| 512 |
// crc[i] = l2->crc[i]; |
| 513 |
good[i] = l2->good[i]; |
| 514 |
}; |
| 515 |
// *** TRACKS *** |
| 516 |
TClonesArray &t = *Track; |
| 517 |
for(int i=0; i<l2->ntrk; i++){ |
| 518 |
t_track->seqno = i;// NBNBNBNB deve sempre essere = i |
| 519 |
t_track->image = l2->image[i]-1; |
| 520 |
// cout << "track "<<i<<t_track->seqno << t_track->image<<endl; |
| 521 |
t_track->chi2 = l2->chi2_nt[i]; |
| 522 |
t_track->nstep = l2->nstep_nt[i]; |
| 523 |
for(int it1=0;it1<5;it1++){ |
| 524 |
t_track->al[it1] = l2->al_nt[i][it1]; |
| 525 |
for(int it2=0;it2<5;it2++) |
| 526 |
t_track->coval[it1][it2] = l2->coval[i][it2][it1]; |
| 527 |
}; |
| 528 |
for(int ip=0;ip<6;ip++){ |
| 529 |
t_track->xgood[ip] = l2->xgood_nt[i][ip]; |
| 530 |
t_track->ygood[ip] = l2->ygood_nt[i][ip]; |
| 531 |
t_track->xm[ip] = l2->xm_nt[i][ip]; |
| 532 |
t_track->ym[ip] = l2->ym_nt[i][ip]; |
| 533 |
t_track->zm[ip] = l2->zm_nt[i][ip]; |
| 534 |
t_track->resx[ip] = l2->resx_nt[i][ip]; |
| 535 |
t_track->resy[ip] = l2->resy_nt[i][ip]; |
| 536 |
t_track->xv[ip] = l2->xv_nt[i][ip]; |
| 537 |
t_track->yv[ip] = l2->yv_nt[i][ip]; |
| 538 |
t_track->zv[ip] = l2->zv_nt[i][ip]; |
| 539 |
t_track->axv[ip] = l2->axv_nt[i][ip]; |
| 540 |
t_track->ayv[ip] = l2->ayv_nt[i][ip]; |
| 541 |
t_track->dedx_x[ip] = l2->dedx_x[i][ip]; |
| 542 |
t_track->dedx_y[ip] = l2->dedx_y[i][ip]; |
| 543 |
// t_track->clx[ip] = 0; |
| 544 |
// t_track->cly[ip] = 0; |
| 545 |
}; |
| 546 |
new(t[i]) TrkTrack(*t_track); |
| 547 |
t_track->Clear(); |
| 548 |
}; |
| 549 |
// *** SINGLETS *** |
| 550 |
TClonesArray &sx = *SingletX; |
| 551 |
for(int i=0; i<l2->nclsx; i++){ |
| 552 |
t_singlet->plane = l2->planex[i]; |
| 553 |
t_singlet->coord[0] = l2->xs[i][0]; |
| 554 |
t_singlet->coord[1] = l2->xs[i][1]; |
| 555 |
t_singlet->sgnl = l2->signlxs[i]; |
| 556 |
// t_singlet->cls = 0; |
| 557 |
new(sx[i]) TrkSinglet(*t_singlet); |
| 558 |
t_singlet->Clear(); |
| 559 |
} |
| 560 |
TClonesArray &sy = *SingletY; |
| 561 |
for(int i=0; i<l2->nclsy; i++){ |
| 562 |
t_singlet->plane = l2->planey[i]; |
| 563 |
t_singlet->coord[0] = l2->ys[i][0]; |
| 564 |
t_singlet->coord[1] = l2->ys[i][1]; |
| 565 |
t_singlet->sgnl = l2->signlys[i]; |
| 566 |
// t_singlet->cls = 0; |
| 567 |
new(sy[i]) TrkSinglet(*t_singlet); |
| 568 |
t_singlet->Clear(); |
| 569 |
}; |
| 570 |
|
| 571 |
delete t_track; |
| 572 |
delete t_singlet; |
| 573 |
} |
| 574 |
//-------------------------------------- |
| 575 |
// |
| 576 |
// |
| 577 |
//-------------------------------------- |
| 578 |
/** |
| 579 |
* Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). |
| 580 |
* Ref to Level1 data (clusters) is also set. |
| 581 |
*/ |
| 582 |
void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){ |
| 583 |
|
| 584 |
// temporary objects: |
| 585 |
TrkSinglet* t_singlet = new TrkSinglet(); |
| 586 |
TrkTrack* t_track = new TrkTrack(); |
| 587 |
// general variables |
| 588 |
// good2 = l2->good2; |
| 589 |
for(Int_t i=0; i<12 ; i++){ |
| 590 |
// crc[i] = l2->crc[i]; |
| 591 |
good[i] = l2->good[i]; |
| 592 |
}; |
| 593 |
// *** TRACKS *** |
| 594 |
TClonesArray &t = *Track; |
| 595 |
for(int i=0; i<l2->ntrk; i++){ |
| 596 |
t_track->seqno = i;// NBNBNBNB deve sempre essere = i |
| 597 |
t_track->image = l2->image[i]-1; |
| 598 |
// cout << "track "<<i<<t_track->seqno << t_track->image<<endl; |
| 599 |
t_track->chi2 = l2->chi2_nt[i]; |
| 600 |
t_track->nstep = l2->nstep_nt[i]; |
| 601 |
for(int it1=0;it1<5;it1++){ |
| 602 |
t_track->al[it1] = l2->al_nt[i][it1]; |
| 603 |
for(int it2=0;it2<5;it2++) |
| 604 |
t_track->coval[it1][it2] = l2->coval[i][it2][it1]; |
| 605 |
}; |
| 606 |
for(int ip=0;ip<6;ip++){ |
| 607 |
t_track->xgood[ip] = l2->xgood_nt[i][ip]; |
| 608 |
t_track->ygood[ip] = l2->ygood_nt[i][ip]; |
| 609 |
t_track->xm[ip] = l2->xm_nt[i][ip]; |
| 610 |
t_track->ym[ip] = l2->ym_nt[i][ip]; |
| 611 |
t_track->zm[ip] = l2->zm_nt[i][ip]; |
| 612 |
t_track->resx[ip] = l2->resx_nt[i][ip]; |
| 613 |
t_track->resy[ip] = l2->resy_nt[i][ip]; |
| 614 |
t_track->xv[ip] = l2->xv_nt[i][ip]; |
| 615 |
t_track->yv[ip] = l2->yv_nt[i][ip]; |
| 616 |
t_track->zv[ip] = l2->zv_nt[i][ip]; |
| 617 |
t_track->axv[ip] = l2->axv_nt[i][ip]; |
| 618 |
t_track->ayv[ip] = l2->ayv_nt[i][ip]; |
| 619 |
t_track->dedx_x[ip] = l2->dedx_x[i][ip]; |
| 620 |
t_track->dedx_y[ip] = l2->dedx_y[i][ip]; |
| 621 |
// cout << "traccia "<<i<<" -- "<< ip << " "<< l2->cltrx[i][ip] <<" "<< l2->cltry[i][ip] <<" "<< t_track->xgood[ip] << t_track->ygood[ip]<<endl; |
| 622 |
//----------------------------------------------------- |
| 623 |
// t_track->clx[ip] = l1->GetCluster(l2->cltrx[i][ip]-1); |
| 624 |
// t_track->cly[ip] = l1->GetCluster(l2->cltry[i][ip]-1); |
| 625 |
if(t_track->xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip); |
| 626 |
if(t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip); |
| 627 |
// if(t_track->ygood[ip])cout<<" i "<<i<<" ip "<<ip<<" l2->cltry[i][ip] "<<l2->cltry[i][ip]<< " l1->GetCluster(l2->cltry[i][ip]-1) "<<l1->GetCluster(l2->cltry[i][ip]-1)<<endl; |
| 628 |
// if(t_track->xgood[ip])cout<<" i "<<i<<" ip "<<ip<<" l2->cltrx[i][ip] "<<l2->cltrx[i][ip]<< " l1->GetCluster(l2->cltrx[i][ip]-1) "<<l1->GetCluster(l2->cltrx[i][ip]-1)<<endl; |
| 629 |
//----------------------------------------------------- |
| 630 |
}; |
| 631 |
new(t[i]) TrkTrack(*t_track); |
| 632 |
t_track->Clear(); |
| 633 |
}; |
| 634 |
// *** SINGLETS *** |
| 635 |
TClonesArray &sx = *SingletX; |
| 636 |
for(int i=0; i<l2->nclsx; i++){ |
| 637 |
t_singlet->plane = l2->planex[i]; |
| 638 |
t_singlet->coord[0] = l2->xs[i][0]; |
| 639 |
t_singlet->coord[1] = l2->xs[i][1]; |
| 640 |
t_singlet->sgnl = l2->signlxs[i]; |
| 641 |
//----------------------------------------------------- |
| 642 |
// cout << "singolo x "<<i<<" -- "<< l2->clsx[i] <<endl; |
| 643 |
t_singlet->cls = l1->GetCluster(l2->clsx[i]-1); |
| 644 |
// cout<<" i "<<i<<" l2->clsx[i] "<<l2->clsx[i]<< " l1->GetCluster(l2->clsx[i]-1) "<<l1->GetCluster(l2->clsx[i]-1)<<endl; |
| 645 |
//----------------------------------------------------- |
| 646 |
new(sx[i]) TrkSinglet(*t_singlet); |
| 647 |
t_singlet->Clear(); |
| 648 |
} |
| 649 |
TClonesArray &sy = *SingletY; |
| 650 |
for(int i=0; i<l2->nclsy; i++){ |
| 651 |
t_singlet->plane = l2->planey[i]; |
| 652 |
t_singlet->coord[0] = l2->ys[i][0]; |
| 653 |
t_singlet->coord[1] = l2->ys[i][1]; |
| 654 |
t_singlet->sgnl = l2->signlys[i]; |
| 655 |
//----------------------------------------------------- |
| 656 |
// cout << "singolo y "<<i<<" -- "<< l2->clsy[i] <<endl; |
| 657 |
t_singlet->cls = l1->GetCluster(l2->clsy[i]-1); |
| 658 |
// cout<<" i "<<i<<" l2->clsy[i] "<<l2->clsy[i]<< " l1->GetCluster(l2->clsy[i]-1) "<<l1->GetCluster(l2->clsy[i]-1)<<endl; |
| 659 |
//----------------------------------------------------- |
| 660 |
new(sy[i]) TrkSinglet(*t_singlet); |
| 661 |
t_singlet->Clear(); |
| 662 |
}; |
| 663 |
|
| 664 |
delete t_track; |
| 665 |
delete t_singlet; |
| 666 |
} |
| 667 |
/** |
| 668 |
* Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common). |
| 669 |
*/ |
| 670 |
|
| 671 |
void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const { |
| 672 |
|
| 673 |
// general variables |
| 674 |
// l2->good2 = good2 ; |
| 675 |
for(Int_t i=0; i<12 ; i++){ |
| 676 |
// l2->crc[i] = crc[i]; |
| 677 |
l2->good[i] = good[i]; |
| 678 |
}; |
| 679 |
// *** TRACKS *** |
| 680 |
|
| 681 |
l2->ntrk = Track->GetEntries(); |
| 682 |
for(Int_t i=0;i<l2->ntrk;i++){ |
| 683 |
l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image; |
| 684 |
l2->chi2_nt[i] = ((TrkTrack *)Track->At(i))->chi2; |
| 685 |
l2->nstep_nt[i] = ((TrkTrack *)Track->At(i))->nstep; |
| 686 |
for(int it1=0;it1<5;it1++){ |
| 687 |
l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1]; |
| 688 |
for(int it2=0;it2<5;it2++) |
| 689 |
l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2]; |
| 690 |
}; |
| 691 |
for(int ip=0;ip<6;ip++){ |
| 692 |
l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip]; |
| 693 |
l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip]; |
| 694 |
l2->xm_nt[i][ip] = ((TrkTrack *)Track->At(i))->xm[ip]; |
| 695 |
l2->ym_nt[i][ip] = ((TrkTrack *)Track->At(i))->ym[ip]; |
| 696 |
l2->zm_nt[i][ip] = ((TrkTrack *)Track->At(i))->zm[ip]; |
| 697 |
l2->resx_nt[i][ip] = ((TrkTrack *)Track->At(i))->resx[ip]; |
| 698 |
l2->resy_nt[i][ip] = ((TrkTrack *)Track->At(i))->resy[ip]; |
| 699 |
l2->xv_nt[i][ip] = ((TrkTrack *)Track->At(i))->xv[ip]; |
| 700 |
l2->yv_nt[i][ip] = ((TrkTrack *)Track->At(i))->yv[ip]; |
| 701 |
l2->zv_nt[i][ip] = ((TrkTrack *)Track->At(i))->zv[ip]; |
| 702 |
l2->axv_nt[i][ip] = ((TrkTrack *)Track->At(i))->axv[ip]; |
| 703 |
l2->ayv_nt[i][ip] = ((TrkTrack *)Track->At(i))->ayv[ip]; |
| 704 |
l2->dedx_x[i][ip] = ((TrkTrack *)Track->At(i))->dedx_x[ip]; |
| 705 |
l2->dedx_y[i][ip] = ((TrkTrack *)Track->At(i))->dedx_y[ip]; |
| 706 |
}; |
| 707 |
} |
| 708 |
|
| 709 |
// *** SINGLETS *** |
| 710 |
l2->nclsx = SingletX->GetEntries(); |
| 711 |
for(Int_t i=0;i<l2->nclsx;i++){ |
| 712 |
l2->planex[i] = ((TrkSinglet *)SingletX->At(i))->plane; |
| 713 |
l2->xs[i][0] = ((TrkSinglet *)SingletX->At(i))->coord[0]; |
| 714 |
l2->xs[i][1] = ((TrkSinglet *)SingletX->At(i))->coord[1]; |
| 715 |
l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl; |
| 716 |
} |
| 717 |
l2->nclsy = SingletY->GetEntries(); |
| 718 |
for(Int_t i=0;i<l2->nclsy;i++){ |
| 719 |
l2->planey[i] = ((TrkSinglet *)SingletY->At(i))->plane; |
| 720 |
l2->ys[i][0] = ((TrkSinglet *)SingletY->At(i))->coord[0]; |
| 721 |
l2->ys[i][1] = ((TrkSinglet *)SingletY->At(i))->coord[1]; |
| 722 |
l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl; |
| 723 |
} |
| 724 |
} |
| 725 |
//-------------------------------------- |
| 726 |
// |
| 727 |
// |
| 728 |
//-------------------------------------- |
| 729 |
void TrkLevel2::Clear(){ |
| 730 |
// good2 = -1; |
| 731 |
for(Int_t i=0; i<12 ; i++){ |
| 732 |
// crc[i] = -1; |
| 733 |
good[i] = -1; |
| 734 |
}; |
| 735 |
/* Track->RemoveAll(); |
| 736 |
SingletX->RemoveAll(); |
| 737 |
SingletY->RemoveAll();*/ |
| 738 |
// modify to avoid memory leakage |
| 739 |
Track->Clear(); |
| 740 |
SingletX->Clear(); |
| 741 |
SingletY->Clear(); |
| 742 |
} |
| 743 |
//-------------------------------------- |
| 744 |
// |
| 745 |
// |
| 746 |
//-------------------------------------- |
| 747 |
void TrkLevel2::Delete(){ |
| 748 |
|
| 749 |
Clear(); |
| 750 |
Track->Delete(); |
| 751 |
SingletX->Delete(); |
| 752 |
SingletY->Delete(); |
| 753 |
} |
| 754 |
//-------------------------------------- |
| 755 |
// |
| 756 |
// |
| 757 |
//-------------------------------------- |
| 758 |
/** |
| 759 |
* 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). |
| 760 |
* This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. |
| 761 |
*/ |
| 762 |
TRefArray *TrkLevel2::GetTracks_NFitSorted(){ |
| 763 |
|
| 764 |
TRefArray *sorted = new TRefArray(); |
| 765 |
|
| 766 |
TClonesArray &t = *Track; |
| 767 |
// TClonesArray &ts = *PhysicalTrack; |
| 768 |
int N = ntrk(); |
| 769 |
vector<int> m(N); for(int i=0; i<N; i++)m[i]=1; |
| 770 |
// int m[50]; for(int i=0; i<N; i++)m[i]=1; |
| 771 |
|
| 772 |
int indo=0; |
| 773 |
int indi=0; |
| 774 |
while(N != 0){ |
| 775 |
int nfit =0; |
| 776 |
float chi2ref = numeric_limits<float>::max(); |
| 777 |
|
| 778 |
// first loop to search maximum num. of fit points |
| 779 |
for(int i=0; i < ntrk(); i++){ |
| 780 |
if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){ |
| 781 |
nfit = ((TrkTrack *)t[i])->GetNtot(); |
| 782 |
} |
| 783 |
} |
| 784 |
//second loop to search minimum chi2 among selected |
| 785 |
for(int i=0; i<this->ntrk(); i++){ |
| 786 |
Float_t chi2 = ((TrkTrack *)t[i])->chi2; |
| 787 |
if(chi2 < 0) chi2 = chi2*1000; |
| 788 |
if( chi2 < chi2ref |
| 789 |
&& ((TrkTrack *)t[i])->GetNtot() == nfit |
| 790 |
&& m[i]==1){ |
| 791 |
chi2ref = ((TrkTrack *)t[i])->chi2; |
| 792 |
indi = i; |
| 793 |
}; |
| 794 |
}; |
| 795 |
if( ((TrkTrack *)t[indi])->HasImage() ){ |
| 796 |
m[((TrkTrack *)t[indi])->image] = 0; |
| 797 |
N--; |
| 798 |
|
| 799 |
// cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl; |
| 800 |
}; |
| 801 |
sorted->Add( (TrkTrack*)t[indi] ); |
| 802 |
|
| 803 |
m[indi] = 0; |
| 804 |
// cout << "SORTED "<< indo << " "<< indi << " "<< N << endl; |
| 805 |
N--; |
| 806 |
indo++; |
| 807 |
} |
| 808 |
m.clear(); |
| 809 |
// cout << "GetTracks_NFitSorted(it): Done"<< endl; |
| 810 |
|
| 811 |
return sorted; |
| 812 |
// return PhysicalTrack; |
| 813 |
} |
| 814 |
//-------------------------------------- |
| 815 |
// |
| 816 |
// |
| 817 |
//-------------------------------------- |
| 818 |
/** |
| 819 |
* Retrieves the is-th stored track. |
| 820 |
* @param it Track number, ranging from 0 to ntrk(). |
| 821 |
* Fitted tracks ( images included ) are stored in a TObjectArray ( TrkLevel2::Track ) in the same order they are returned by the F77 fitting routine. |
| 822 |
*/ |
| 823 |
TrkTrack *TrkLevel2::GetStoredTrack(int is){ |
| 824 |
|
| 825 |
if(is >= this->ntrk()){ |
| 826 |
cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl; |
| 827 |
cout << " Stored tracks ntrk() = "<< this->ntrk() << endl; |
| 828 |
return 0; |
| 829 |
} |
| 830 |
TClonesArray &t = *(Track); |
| 831 |
TrkTrack *track = (TrkTrack*)t[is]; |
| 832 |
return track; |
| 833 |
} |
| 834 |
//-------------------------------------- |
| 835 |
// |
| 836 |
// |
| 837 |
//-------------------------------------- |
| 838 |
/** |
| 839 |
* Retrieves the is-th stored X singlet. |
| 840 |
* @param it Singlet number, ranging from 0 to nclsx(). |
| 841 |
*/ |
| 842 |
TrkSinglet *TrkLevel2::GetSingletX(int is){ |
| 843 |
|
| 844 |
if(is >= this->nclsx()){ |
| 845 |
cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; |
| 846 |
cout << " Stored x-singlets nclsx() = "<< this->nclsx() << endl; |
| 847 |
return 0; |
| 848 |
} |
| 849 |
TClonesArray &t = *(SingletX); |
| 850 |
TrkSinglet *singlet = (TrkSinglet*)t[is]; |
| 851 |
return singlet; |
| 852 |
} |
| 853 |
//-------------------------------------- |
| 854 |
// |
| 855 |
// |
| 856 |
//-------------------------------------- |
| 857 |
/** |
| 858 |
* Retrieves the is-th stored Y singlet. |
| 859 |
* @param it Singlet number, ranging from 0 to nclsx(). |
| 860 |
*/ |
| 861 |
TrkSinglet *TrkLevel2::GetSingletY(int is){ |
| 862 |
|
| 863 |
if(is >= this->nclsy()){ |
| 864 |
cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; |
| 865 |
cout << " Stored y-singlets nclsy() = "<< this->nclsx() << endl; |
| 866 |
return 0; |
| 867 |
} |
| 868 |
TClonesArray &t = *(SingletY); |
| 869 |
TrkSinglet *singlet = (TrkSinglet*)t[is]; |
| 870 |
return singlet; |
| 871 |
} |
| 872 |
//-------------------------------------- |
| 873 |
// |
| 874 |
// |
| 875 |
//-------------------------------------- |
| 876 |
/** |
| 877 |
* Retrieves the it-th "physical" track, sorted by the method GetNTracks(). |
| 878 |
* @param it Track number, ranging from 0 to GetNTracks(). |
| 879 |
*/ |
| 880 |
|
| 881 |
TrkTrack *TrkLevel2::GetTrack(int it){ |
| 882 |
|
| 883 |
if(it >= this->GetNTracks()){ |
| 884 |
cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; |
| 885 |
cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; |
| 886 |
return 0; |
| 887 |
} |
| 888 |
|
| 889 |
TRefArray *sorted = GetTracks(); //TEMPORANEO |
| 890 |
TrkTrack *track = (TrkTrack*)sorted->At(it); |
| 891 |
sorted->Delete(); |
| 892 |
return track; |
| 893 |
} |
| 894 |
/** |
| 895 |
* Give the number of "physical" tracks, sorted by the method GetTracks(). |
| 896 |
*/ |
| 897 |
Int_t TrkLevel2::GetNTracks(){ |
| 898 |
|
| 899 |
Float_t ntot=0; |
| 900 |
TClonesArray &t = *Track; |
| 901 |
for(int i=0; i<ntrk(); i++) { |
| 902 |
if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.; |
| 903 |
else ntot+=0.5; |
| 904 |
} |
| 905 |
return (Int_t)ntot; |
| 906 |
|
| 907 |
}; |
| 908 |
//-------------------------------------- |
| 909 |
// |
| 910 |
// |
| 911 |
//-------------------------------------- |
| 912 |
/** |
| 913 |
* Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks(). |
| 914 |
* @param it Track number, ranging from 0 to GetNTracks(). |
| 915 |
*/ |
| 916 |
TrkTrack *TrkLevel2::GetTrackImage(int it){ |
| 917 |
|
| 918 |
if(it >= this->GetNTracks()){ |
| 919 |
cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; |
| 920 |
cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl; |
| 921 |
return 0; |
| 922 |
} |
| 923 |
|
| 924 |
TRefArray* sorted = GetTracks(); //TEMPORANEO |
| 925 |
TrkTrack *track = (TrkTrack*)sorted->At(it); |
| 926 |
|
| 927 |
if(!track->HasImage()){ |
| 928 |
cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl; |
| 929 |
return 0; |
| 930 |
} |
| 931 |
TrkTrack *image = (TrkTrack*)(*Track)[track->image]; |
| 932 |
|
| 933 |
sorted->Delete(); |
| 934 |
|
| 935 |
return image; |
| 936 |
|
| 937 |
} |
| 938 |
//-------------------------------------- |
| 939 |
// |
| 940 |
// |
| 941 |
//-------------------------------------- |
| 942 |
/** |
| 943 |
* Loads the magnetic field. |
| 944 |
* @param s Path of the magnetic-field files. |
| 945 |
*/ |
| 946 |
void TrkLevel2::LoadField(TString s){ |
| 947 |
readb_(s.Data()); |
| 948 |
}; |
| 949 |
//-------------------------------------- |
| 950 |
// |
| 951 |
// |
| 952 |
//-------------------------------------- |
| 953 |
/** |
| 954 |
* Get tracker-plane (mechanical) z-coordinate |
| 955 |
* @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM) |
| 956 |
*/ |
| 957 |
Float_t TrkLevel2::GetZTrk(Int_t plane_id){ |
| 958 |
switch(plane_id){ |
| 959 |
case 1: return ZTRK1; |
| 960 |
case 2: return ZTRK2; |
| 961 |
case 3: return ZTRK3; |
| 962 |
case 4: return ZTRK4; |
| 963 |
case 5: return ZTRK5; |
| 964 |
case 6: return ZTRK6; |
| 965 |
default: return 0.; |
| 966 |
}; |
| 967 |
}; |
| 968 |
//-------------------------------------- |
| 969 |
// |
| 970 |
// |
| 971 |
//-------------------------------------- |
| 972 |
/** |
| 973 |
* Trajectory default constructor. |
| 974 |
* (By default is created with z-coordinates inside the tracking volume) |
| 975 |
*/ |
| 976 |
Trajectory::Trajectory(){ |
| 977 |
npoint = 10; |
| 978 |
x = new float[npoint]; |
| 979 |
y = new float[npoint]; |
| 980 |
z = new float[npoint]; |
| 981 |
thx = new float[npoint]; |
| 982 |
thy = new float[npoint]; |
| 983 |
tl = new float[npoint]; |
| 984 |
float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); |
| 985 |
for(int i=0; i<npoint; i++){ |
| 986 |
x[i] = 0; |
| 987 |
y[i] = 0; |
| 988 |
z[i] = (ZTRK1) - i*dz; |
| 989 |
thx[i] = 0; |
| 990 |
thy[i] = 0; |
| 991 |
tl[i] = 0; |
| 992 |
} |
| 993 |
} |
| 994 |
//-------------------------------------- |
| 995 |
// |
| 996 |
// |
| 997 |
//-------------------------------------- |
| 998 |
/** |
| 999 |
* Trajectory constructor. |
| 1000 |
* (By default is created with z-coordinates inside the tracking volume) |
| 1001 |
* \param n Number of points |
| 1002 |
*/ |
| 1003 |
Trajectory::Trajectory(int n){ |
| 1004 |
if(n<=0){ |
| 1005 |
cout << "NB! Trajectory must have at least 1 point >>> created with 10 points" << endl; |
| 1006 |
n=10; |
| 1007 |
} |
| 1008 |
npoint = n; |
| 1009 |
x = new float[npoint]; |
| 1010 |
y = new float[npoint]; |
| 1011 |
z = new float[npoint]; |
| 1012 |
thx = new float[npoint]; |
| 1013 |
thy = new float[npoint]; |
| 1014 |
tl = new float[npoint]; |
| 1015 |
float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); |
| 1016 |
for(int i=0; i<npoint; i++){ |
| 1017 |
x[i] = 0; |
| 1018 |
y[i] = 0; |
| 1019 |
z[i] = (ZTRK1) - i*dz; |
| 1020 |
thx[i] = 0; |
| 1021 |
thy[i] = 0; |
| 1022 |
tl[i] = 0; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
//-------------------------------------- |
| 1026 |
// |
| 1027 |
// |
| 1028 |
//-------------------------------------- |
| 1029 |
/** |
| 1030 |
* Trajectory constructor. |
| 1031 |
* \param n Number of points |
| 1032 |
* \param pz Pointer to float array, defining z coordinates |
| 1033 |
*/ |
| 1034 |
Trajectory::Trajectory(int n, float* zin){ |
| 1035 |
npoint = 10; |
| 1036 |
if(n>0)npoint = n; |
| 1037 |
x = new float[npoint]; |
| 1038 |
y = new float[npoint]; |
| 1039 |
z = new float[npoint]; |
| 1040 |
thx = new float[npoint]; |
| 1041 |
thy = new float[npoint]; |
| 1042 |
tl = new float[npoint]; |
| 1043 |
int i=0; |
| 1044 |
do{ |
| 1045 |
x[i] = 0; |
| 1046 |
y[i] = 0; |
| 1047 |
z[i] = zin[i]; |
| 1048 |
thx[i] = 0; |
| 1049 |
thy[i] = 0; |
| 1050 |
tl[i] = 0; |
| 1051 |
i++; |
| 1052 |
}while(zin[i-1] > zin[i] && i < npoint); |
| 1053 |
npoint=i; |
| 1054 |
if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl; |
| 1055 |
} |
| 1056 |
//-------------------------------------- |
| 1057 |
// |
| 1058 |
// |
| 1059 |
//-------------------------------------- |
| 1060 |
/** |
| 1061 |
* Dump the trajectory coordinates. |
| 1062 |
*/ |
| 1063 |
void Trajectory::Dump(){ |
| 1064 |
cout <<endl<< "Trajectory ========== "<<endl; |
| 1065 |
for (int i=0; i<npoint; i++){ |
| 1066 |
cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] ; |
| 1067 |
cout <<" -- " << thx[i] <<" "<< thy[i] ; |
| 1068 |
cout <<" -- " << tl[i] << endl; |
| 1069 |
}; |
| 1070 |
} |
| 1071 |
//-------------------------------------- |
| 1072 |
// |
| 1073 |
// |
| 1074 |
//-------------------------------------- |
| 1075 |
/** |
| 1076 |
* Get trajectory length between two points |
| 1077 |
* @param ifirst first point (default 0) |
| 1078 |
* @param ilast last point (default npoint) |
| 1079 |
*/ |
| 1080 |
float Trajectory::GetLength(int ifirst, int ilast){ |
| 1081 |
if( ifirst<0 ) ifirst = 0; |
| 1082 |
if( ilast>=npoint) ilast = npoint-1; |
| 1083 |
float l=0; |
| 1084 |
for(int i=ifirst;i<=ilast;i++){ |
| 1085 |
l=l+tl[i]; |
| 1086 |
}; |
| 1087 |
if(z[ilast] > ZINI)l=l-tl[ilast]; |
| 1088 |
if(z[ifirst] < ZINI) l=l-tl[ifirst]; |
| 1089 |
|
| 1090 |
return l; |
| 1091 |
|
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
ClassImp(TrkLevel2); |
| 1096 |
ClassImp(TrkSinglet); |
| 1097 |
ClassImp(TrkTrack); |
| 1098 |
ClassImp(Trajectory); |