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