| 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 | void mini2_(int*,int*,int*); | 
| 16 | void guess_(); | 
| 17 | } | 
| 18 |  | 
| 19 | //-------------------------------------- | 
| 20 | // | 
| 21 | // | 
| 22 | //-------------------------------------- | 
| 23 | TrkTrack::TrkTrack(){ | 
| 24 | //    cout << "TrkTrack::TrkTrack()" << endl; | 
| 25 | seqno = -1; | 
| 26 | image = -1; | 
| 27 | chi2  = 0; | 
| 28 | nstep = 0; | 
| 29 | for(int it1=0;it1<5;it1++){ | 
| 30 | al[it1] = 0; | 
| 31 | for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; | 
| 32 | }; | 
| 33 | for(int ip=0;ip<6;ip++){ | 
| 34 | xgood[ip]  = 0; | 
| 35 | ygood[ip]  = 0; | 
| 36 | xm[ip]     = 0; | 
| 37 | ym[ip]     = 0; | 
| 38 | zm[ip]     = 0; | 
| 39 | resx[ip]   = 0; | 
| 40 | resy[ip]   = 0; | 
| 41 | tailx[ip]   = 0; | 
| 42 | taily[ip]   = 0; | 
| 43 | xv[ip]     = 0; | 
| 44 | yv[ip]     = 0; | 
| 45 | zv[ip]     = 0; | 
| 46 | axv[ip]    = 0; | 
| 47 | ayv[ip]    = 0; | 
| 48 | dedx_x[ip] = 0; | 
| 49 | dedx_y[ip] = 0; | 
| 50 | }; | 
| 51 | //    clx = 0; | 
| 52 | //    cly = 0; | 
| 53 | //    clx = new TRefArray(6,0); //forse causa memory leak??? | 
| 54 | //    cly = new TRefArray(6,0); //forse causa memory leak??? | 
| 55 | //    clx = TRefArray(6,0); | 
| 56 | //    cly = TRefArray(6,0); | 
| 57 |  | 
| 58 | TrkParams::SetTrackingMode(); | 
| 59 | TrkParams::SetPrecisionFactor(); | 
| 60 | TrkParams::SetStepMin(); | 
| 61 | TrkParams::SetPFA(); | 
| 62 |  | 
| 63 | }; | 
| 64 | //-------------------------------------- | 
| 65 | // | 
| 66 | // | 
| 67 | //-------------------------------------- | 
| 68 | TrkTrack::TrkTrack(const TrkTrack& t){ | 
| 69 | seqno = t.seqno; | 
| 70 | image = t.image; | 
| 71 | chi2  = t.chi2; | 
| 72 | nstep = t.nstep; | 
| 73 | for(int it1=0;it1<5;it1++){ | 
| 74 | al[it1] = t.al[it1]; | 
| 75 | for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2]; | 
| 76 | }; | 
| 77 | for(int ip=0;ip<6;ip++){ | 
| 78 | xgood[ip]  = t.xgood[ip]; | 
| 79 | ygood[ip]  = t.ygood[ip]; | 
| 80 | xm[ip]     = t.xm[ip]; | 
| 81 | ym[ip]     = t.ym[ip]; | 
| 82 | zm[ip]     = t.zm[ip]; | 
| 83 | resx[ip]   = t.resx[ip]; | 
| 84 | resy[ip]   = t.resy[ip]; | 
| 85 | tailx[ip]  = t.tailx[ip]; | 
| 86 | taily[ip]  = t.taily[ip]; | 
| 87 | xv[ip]     = t.xv[ip]; | 
| 88 | yv[ip]     = t.yv[ip]; | 
| 89 | zv[ip]     = t.zv[ip]; | 
| 90 | axv[ip]    = t.axv[ip]; | 
| 91 | ayv[ip]    = t.ayv[ip]; | 
| 92 | dedx_x[ip] = t.dedx_x[ip]; | 
| 93 | dedx_y[ip] = t.dedx_y[ip]; | 
| 94 | }; | 
| 95 | //    clx = 0; | 
| 96 | //    cly = 0; | 
| 97 | //    if(t.clx)clx = new TRefArray(*(t.clx)); | 
| 98 | //    if(t.cly)cly = new TRefArray(*(t.cly)); | 
| 99 | //    clx = TRefArray(t.clx); | 
| 100 | //    cly = TRefArray(t.cly); | 
| 101 |  | 
| 102 | TrkParams::SetTrackingMode(); | 
| 103 | TrkParams::SetPrecisionFactor(); | 
| 104 | TrkParams::SetStepMin(); | 
| 105 | TrkParams::SetPFA(); | 
| 106 |  | 
| 107 | }; | 
| 108 | //-------------------------------------- | 
| 109 | // | 
| 110 | // | 
| 111 | //-------------------------------------- | 
| 112 | void TrkTrack::Copy(TrkTrack& t){ | 
| 113 |  | 
| 114 | t.seqno = seqno; | 
| 115 | t.image = image; | 
| 116 | t.chi2  = chi2; | 
| 117 | t.nstep = nstep; | 
| 118 | for(int it1=0;it1<5;it1++){ | 
| 119 | t.al[it1] = al[it1]; | 
| 120 | for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2]; | 
| 121 | }; | 
| 122 | for(int ip=0;ip<6;ip++){ | 
| 123 | t.xgood[ip]  = xgood[ip]; | 
| 124 | t.ygood[ip]  = ygood[ip]; | 
| 125 | t.xm[ip]     = xm[ip]; | 
| 126 | t.ym[ip]     = ym[ip]; | 
| 127 | t.zm[ip]     = zm[ip]; | 
| 128 | t.resx[ip]   = resx[ip]; | 
| 129 | t.resy[ip]   = resy[ip]; | 
| 130 | t.tailx[ip]  = tailx[ip]; | 
| 131 | t.taily[ip]  = taily[ip]; | 
| 132 | t.xv[ip]     = xv[ip]; | 
| 133 | t.yv[ip]     = yv[ip]; | 
| 134 | t.zv[ip]     = zv[ip]; | 
| 135 | t.axv[ip]    = axv[ip]; | 
| 136 | t.ayv[ip]    = ayv[ip]; | 
| 137 | t.dedx_x[ip] = dedx_x[ip]; | 
| 138 | t.dedx_y[ip] = dedx_y[ip]; | 
| 139 |  | 
| 140 | }; | 
| 141 |  | 
| 142 | //    t.clx = TRefArray(clx); | 
| 143 | //    t.cly = TRefArray(cly); | 
| 144 |  | 
| 145 | }; | 
| 146 | //-------------------------------------- | 
| 147 | // | 
| 148 | // | 
| 149 | //-------------------------------------- | 
| 150 | /** | 
| 151 | * Evaluates the trajectory in the apparatus associated to the track. | 
| 152 | * 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. | 
| 153 | * @param t pointer to an object of the class Trajectory, | 
| 154 | * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). | 
| 155 | * @return error flag. | 
| 156 | */ | 
| 157 | int TrkTrack::DoTrack(Trajectory* t){ | 
| 158 |  | 
| 159 | double *dxout = new double[t->npoint]; | 
| 160 | double *dyout = new double[t->npoint]; | 
| 161 | double *dzin = new double[t->npoint]; | 
| 162 | double dal[5]; | 
| 163 |  | 
| 164 | int ifail = 0; | 
| 165 |  | 
| 166 | for (int i=0; i<5; i++)         dal[i]  = (double)al[i]; | 
| 167 | for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i]; | 
| 168 |  | 
| 169 | TrkParams::Load(1); | 
| 170 | if( !TrkParams::IsLoaded(1) ){ | 
| 171 | cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl; | 
| 172 | return 0; | 
| 173 | } | 
| 174 | dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail); | 
| 175 |  | 
| 176 | for (int i=0; i<t->npoint; i++){ | 
| 177 | t->x[i] = (float)*dxout++; | 
| 178 | t->y[i] = (float)*dyout++; | 
| 179 | } | 
| 180 |  | 
| 181 | //    delete [] dxout; | 
| 182 | //    delete [] dyout; | 
| 183 | //    delete [] dzin; | 
| 184 |  | 
| 185 | return ifail; | 
| 186 | }; | 
| 187 | //-------------------------------------- | 
| 188 | // | 
| 189 | // | 
| 190 | //-------------------------------------- | 
| 191 | /** | 
| 192 | * Evaluates the trajectory in the apparatus associated to the track. | 
| 193 | * 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. | 
| 194 | * @param t pointer to an object of the class Trajectory, | 
| 195 | * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). | 
| 196 | * @return error flag. | 
| 197 | */ | 
| 198 | int TrkTrack::DoTrack2(Trajectory* t){ | 
| 199 |  | 
| 200 | double *dxout   = new double[t->npoint]; | 
| 201 | double *dyout   = new double[t->npoint]; | 
| 202 | double *dthxout = new double[t->npoint]; | 
| 203 | double *dthyout = new double[t->npoint]; | 
| 204 | double *dtlout  = new double[t->npoint]; | 
| 205 | double *dzin    = new double[t->npoint]; | 
| 206 | double dal[5]; | 
| 207 |  | 
| 208 | int ifail = 0; | 
| 209 |  | 
| 210 | for (int i=0; i<5; i++)         dal[i]  = (double)al[i]; | 
| 211 | for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i]; | 
| 212 |  | 
| 213 | TrkParams::Load(1); | 
| 214 | if( !TrkParams::IsLoaded(1) ){ | 
| 215 | cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<<endl; | 
| 216 | return 0; | 
| 217 | } | 
| 218 | dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); | 
| 219 |  | 
| 220 | for (int i=0; i<t->npoint; i++){ | 
| 221 | t->x[i]   = (float)*dxout++; | 
| 222 | t->y[i]   = (float)*dyout++; | 
| 223 | t->thx[i] = (float)*dthxout++; | 
| 224 | t->thy[i] = (float)*dthyout++; | 
| 225 | t->tl[i]  = (float)*dtlout++; | 
| 226 | } | 
| 227 |  | 
| 228 | //    delete [] dxout; | 
| 229 | //    delete [] dyout; | 
| 230 | //    delete [] dzin; | 
| 231 |  | 
| 232 | return ifail; | 
| 233 | }; | 
| 234 | //-------------------------------------- | 
| 235 | // | 
| 236 | // | 
| 237 | //-------------------------------------- | 
| 238 | //float TrkTrack::BdL(){ | 
| 239 | //}; | 
| 240 | //-------------------------------------- | 
| 241 | // | 
| 242 | // | 
| 243 | //-------------------------------------- | 
| 244 | Float_t TrkTrack::GetRigidity(){ | 
| 245 | Float_t rig=0; | 
| 246 | if(chi2>0)rig=1./al[4]; | 
| 247 | if(rig<0) rig=-rig; | 
| 248 | return rig; | 
| 249 | }; | 
| 250 | // | 
| 251 | Float_t TrkTrack::GetDeflection(){ | 
| 252 | Float_t def=0; | 
| 253 | if(chi2>0)def=al[4]; | 
| 254 | return def; | 
| 255 | }; | 
| 256 | // | 
| 257 | /** | 
| 258 | * Method to retrieve the dE/dx measured on a tracker view. | 
| 259 | * @param ip plane (0-5) | 
| 260 | * @param iv view (0=x 1=y) | 
| 261 | */ | 
| 262 | Float_t TrkTrack::GetDEDX(int ip, int iv){ | 
| 263 | if(iv==0 && ip>=0 && ip<6)return fabs(dedx_x[ip]); | 
| 264 | else if(iv==1 && ip>=0 && ip<6)return fabs(dedx_y[ip]); | 
| 265 | else { | 
| 266 | cout << "TrkTrack::GetDEDX(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl; | 
| 267 | return 0.; | 
| 268 | } | 
| 269 | } | 
| 270 | /** | 
| 271 | * Method to evaluate the dE/dx measured on a tracker plane. | 
| 272 | * The two measurements on x- and y-view are averaged. | 
| 273 | * @param ip plane (0-5) | 
| 274 | */ | 
| 275 | Float_t TrkTrack::GetDEDX(int ip){ | 
| 276 | if( (Int_t)XGood(ip)+(Int_t)YGood(ip) == 0 ) return 0; | 
| 277 | return (GetDEDX(ip,0)+GetDEDX(ip,1))/((Int_t)XGood(ip)+(Int_t)YGood(ip)); | 
| 278 | }; | 
| 279 |  | 
| 280 | /** | 
| 281 | * Method to evaluate the dE/dx averaged over all planes. | 
| 282 | */ | 
| 283 | Float_t TrkTrack::GetDEDX(){ | 
| 284 | Float_t dedx=0; | 
| 285 | for(Int_t ip=0; ip<6; ip++)dedx+=GetDEDX(ip,0)*XGood(ip)+GetDEDX(ip,1)*YGood(ip); | 
| 286 | dedx = dedx/(GetNX()+GetNY()); | 
| 287 | return dedx; | 
| 288 | }; | 
| 289 | /** | 
| 290 | * Returns 1 if the cluster on a tracker view includes bad strips. | 
| 291 | * @param ip plane (0-5) | 
| 292 | * @param iv view (0=x 1=y) | 
| 293 | */ | 
| 294 | Bool_t TrkTrack::IsBad(int ip,int iv){ | 
| 295 | if(iv==0 && ip>=0 && ip<6)return (xgood[ip]<0) ; | 
| 296 | else if(iv==1 && ip>=0 && ip<6)return (ygood[ip]<0) ; | 
| 297 | else { | 
| 298 | cout << "TrkTrack::IsBad(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl; | 
| 299 | return 0.; | 
| 300 | } | 
| 301 | }; | 
| 302 | /** | 
| 303 | * Returns 1 if the signal on a tracker view is saturated. | 
| 304 | * @param ip plane (0-5) | 
| 305 | * @param iv view (0=x 1=y) | 
| 306 | */ | 
| 307 | Bool_t TrkTrack::IsSaturated(int ip,int iv){ | 
| 308 | if(iv==0 && ip>=0 && ip<6)return (dedx_x[ip]<0) ; | 
| 309 | else if(iv==1 && ip>=0 && ip<6)return (dedx_y[ip]<0) ; | 
| 310 | else { | 
| 311 | cout << "TrkTrack::IsSaturated(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl; | 
| 312 | return 0.; | 
| 313 | } | 
| 314 | }; | 
| 315 | /** | 
| 316 | * Returns 1 if either the x or the y signal on a tracker plane is saturated. | 
| 317 | * @param ip plane (0-5) | 
| 318 | */ | 
| 319 | Bool_t TrkTrack::IsSaturated(int ip){ | 
| 320 | return (IsSaturated(ip,0)||IsSaturated(ip,1)); | 
| 321 | }; | 
| 322 | /** | 
| 323 | * Returns 1 if there is at least a saturated signal along the track. | 
| 324 | */ | 
| 325 | Bool_t TrkTrack::IsSaturated(){ | 
| 326 | for(int ip=0; ip<6; ip++)for(int iv=0; iv<2; iv++)if(IsSaturated(ip,iv))return true; | 
| 327 | return false; | 
| 328 | } | 
| 329 | /** | 
| 330 | * Returns the track "lever-arm" on the x view, defined as the distance (in planes) between | 
| 331 | * the upper and lower x measurements (the maximum value of lever-arm is 6). | 
| 332 | */ | 
| 333 | Int_t TrkTrack::GetLeverArmX(){ | 
| 334 | int first_plane = -1; | 
| 335 | int last_plane  = -1; | 
| 336 | for(Int_t ip=0; ip<6; ip++){ | 
| 337 | if( XGood(ip) && first_plane == -1 )first_plane = ip; | 
| 338 | if( XGood(ip) && first_plane != -1 )last_plane = ip; | 
| 339 | } | 
| 340 | if( first_plane == -1 || last_plane == -1){ | 
| 341 | cout<< "Int_t TrkTrack::GetLeverArmX() -- XGood(ip) always false ??? "<<endl; | 
| 342 | return 0; | 
| 343 | } | 
| 344 | return (last_plane-first_plane+1); | 
| 345 | } | 
| 346 | /** | 
| 347 | * Returns the track "lever-arm" on the y view, defined as the distance (in planes) between | 
| 348 | * the upper and lower y measurements (the maximum value of lever-arm is 6). | 
| 349 | */ | 
| 350 | Int_t TrkTrack::GetLeverArmY(){ | 
| 351 | int first_plane = -1; | 
| 352 | int last_plane  = -1; | 
| 353 | for(Int_t ip=0; ip<6; ip++){ | 
| 354 | if( YGood(ip) && first_plane == -1 )first_plane = ip; | 
| 355 | if( YGood(ip) && first_plane != -1 )last_plane = ip; | 
| 356 | } | 
| 357 | if( first_plane == -1 || last_plane == -1){ | 
| 358 | cout<< "Int_t TrkTrack::GetLeverArmY() -- YGood(ip) always false ??? "<<endl; | 
| 359 | return 0; | 
| 360 | } | 
| 361 | return (last_plane-first_plane+1); | 
| 362 | } | 
| 363 | //-------------------------------------- | 
| 364 | // | 
| 365 | // | 
| 366 | //-------------------------------------- | 
| 367 | void TrkTrack::Dump(){ | 
| 368 | cout << endl << "========== Track " ; | 
| 369 | cout << endl << "seq.  n. : "<< seqno; | 
| 370 | cout << endl << "image n. : "<< image; | 
| 371 | cout << endl << "al       : "; for(int i=0; i<5; i++)cout << al[i] << " "; | 
| 372 | cout << endl << "chi^2    : "<< chi2; | 
| 373 | cout << endl << "n.step   : "<< nstep; | 
| 374 | cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << XGood(i) ; | 
| 375 | cout << endl << "ygood    : "; for(int i=0; i<6; i++)cout << YGood(i) ; | 
| 376 | cout << endl << "xm       : "; for(int i=0; i<6; i++)cout << xm[i] << " "; | 
| 377 | cout << endl << "ym       : "; for(int i=0; i<6; i++)cout << ym[i] << " "; | 
| 378 | cout << endl << "zm       : "; for(int i=0; i<6; i++)cout << zm[i] << " "; | 
| 379 | cout << endl << "xv       : "; for(int i=0; i<6; i++)cout << xv[i] << " "; | 
| 380 | cout << endl << "yv       : "; for(int i=0; i<6; i++)cout << yv[i] << " "; | 
| 381 | cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " "; | 
| 382 | cout << endl << "resx     : "; for(int i=0; i<6; i++)cout << resx[i] << " "; | 
| 383 | cout << endl << "resy     : "; for(int i=0; i<6; i++)cout << resy[i] << " "; | 
| 384 | cout << endl << "coval    : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" "; | 
| 385 | cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[1][i]<<" "; | 
| 386 | cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" "; | 
| 387 | cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[3][i]<<" "; | 
| 388 | cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" "; | 
| 389 | cout << endl << "dedx_x   : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " "; | 
| 390 | cout << endl << "dedx_y   : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " "; | 
| 391 | cout << endl; | 
| 392 | } | 
| 393 | /** | 
| 394 | * Set the TrkTrack position measurements | 
| 395 | */ | 
| 396 | void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){ | 
| 397 | for(int i=0; i<6; i++) xm[i]=*xmeas++; | 
| 398 | for(int i=0; i<6; i++) ym[i]=*ymeas++; | 
| 399 | for(int i=0; i<6; i++) zm[i]=*zmeas++; | 
| 400 | } | 
| 401 | /** | 
| 402 | * Set the TrkTrack position resolution | 
| 403 | */ | 
| 404 | void TrkTrack::SetResolution(double *rx, double *ry){ | 
| 405 | for(int i=0; i<6; i++) resx[i]=*rx++; | 
| 406 | for(int i=0; i<6; i++) resy[i]=*ry++; | 
| 407 | } | 
| 408 | /** | 
| 409 | * Set the TrkTrack good measurement. | 
| 410 | */ | 
| 411 | void TrkTrack::SetGood(int *xg, int *yg){ | 
| 412 |  | 
| 413 | for(int i=0; i<6; i++) xgood[i]=*xg++; | 
| 414 | for(int i=0; i<6; i++) ygood[i]=*yg++; | 
| 415 | } | 
| 416 |  | 
| 417 | /** | 
| 418 | * Load the magnetic field | 
| 419 | */ | 
| 420 | void TrkTrack::LoadField(TString path){ | 
| 421 |  | 
| 422 | //     strcpy(path_.path,path.Data()); | 
| 423 | //     path_.pathlen = path.Length(); | 
| 424 | //     path_.error   = 0; | 
| 425 | //     readb_(); | 
| 426 |  | 
| 427 | TrkParams::SetTrackingMode(); | 
| 428 | TrkParams::SetPrecisionFactor(); | 
| 429 | TrkParams::SetStepMin(); | 
| 430 |  | 
| 431 | TrkParams::Set(path,1); | 
| 432 | TrkParams::Load(1); | 
| 433 |  | 
| 434 | }; | 
| 435 |  | 
| 436 |  | 
| 437 | /** | 
| 438 | * Method to fill minimization-routine common | 
| 439 | */ | 
| 440 | void TrkTrack::FillMiniStruct(cMini2track& track){ | 
| 441 |  | 
| 442 | for(int i=0; i<6; i++){ | 
| 443 |  | 
| 444 | //      cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl; | 
| 445 | //      cout << i<<" - "<<ygood[i]<<" "<<YGood(i)<<endl; | 
| 446 | track.xgood[i]=XGood(i); | 
| 447 | track.ygood[i]=YGood(i); | 
| 448 |  | 
| 449 | track.xm[i]=xm[i]; | 
| 450 | track.ym[i]=ym[i]; | 
| 451 | track.zm[i]=zm[i]; | 
| 452 |  | 
| 453 | //      --- temporaneo ---------------------------- | 
| 454 | //      andrebbe inserita la dimensione del sensore | 
| 455 | float segment = 100.; | 
| 456 | track.xm_a[i]=xm[i]; | 
| 457 | track.xm_b[i]=xm[i]; | 
| 458 | track.ym_a[i]=ym[i]; | 
| 459 | track.ym_b[i]=ym[i]; | 
| 460 | if(       XGood(i) && !YGood(i) ){ | 
| 461 | track.ym_a[i] = track.ym_a[i]+segment; | 
| 462 | track.ym_b[i] = track.ym_b[i]-segment; | 
| 463 | }else if( !XGood(i) && YGood(i)){ | 
| 464 | track.xm_a[i] = track.xm_a[i]+segment; | 
| 465 | track.xm_b[i] = track.xm_b[i]-segment; | 
| 466 | } | 
| 467 | //      --- temporaneo ---------------------------- | 
| 468 |  | 
| 469 | track.resx[i]=resx[i]; | 
| 470 | track.resy[i]=resy[i]; | 
| 471 | } | 
| 472 |  | 
| 473 | for(int i=0; i<5; i++) track.al[i]=al[i]; | 
| 474 | track.zini = 23.5; | 
| 475 | // ZINI = 23.5 !!! it should be the same parameter in all codes | 
| 476 |  | 
| 477 | } | 
| 478 | /** | 
| 479 | * Method to set values from  minimization-routine common | 
| 480 | */ | 
| 481 | void TrkTrack::SetFromMiniStruct(cMini2track *track){ | 
| 482 |  | 
| 483 | for(int i=0; i<5; i++) { | 
| 484 | al[i]=track->al[i]; | 
| 485 | for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j]; | 
| 486 | } | 
| 487 | chi2  = track->chi2; | 
| 488 | nstep = track->nstep; | 
| 489 | for(int i=0; i<6; i++){ | 
| 490 | xv[i]  = track->xv[i]; | 
| 491 | yv[i]  = track->yv[i]; | 
| 492 | zv[i]  = track->zv[i]; | 
| 493 | xm[i]  = track->xm[i]; | 
| 494 | ym[i]  = track->ym[i]; | 
| 495 | zm[i]  = track->zm[i]; | 
| 496 | axv[i] = track->axv[i]; | 
| 497 | ayv[i] = track->ayv[i]; | 
| 498 | } | 
| 499 |  | 
| 500 | } | 
| 501 | /** | 
| 502 | * \brief Method to re-evaluate coordinates of clusters associated with a track. | 
| 503 | * | 
| 504 | * The method can be applied only after recovering level1 information | 
| 505 | * (either by reprocessing single events from level0 or from | 
| 506 | * the TrkLevel1 branch, if present); it calls F77 subroutines that | 
| 507 | * read the level1 common and fill the minimization-routine common. | 
| 508 | * Some clusters can be excluded or added by means of the methods: | 
| 509 | * | 
| 510 | * TrkTrack::ResetXGood(int ip) | 
| 511 | * TrkTrack::ResetYGood(int ip) | 
| 512 | * TrkTrack::SetXGood(int ip, int cid, int is) | 
| 513 | * TrkTrack::SetYGood(int ip, int cid, int is) | 
| 514 | * | 
| 515 | * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1) | 
| 516 | * for the minimization-routine common. It deletes the cluster information | 
| 517 | * (at least for the moment...) thus cannot be applied before | 
| 518 | * TrkTrack::EvaluateClusterPositions(). | 
| 519 | * | 
| 520 | * Different p.f.a. can be applied by calling (once) the method: | 
| 521 | * | 
| 522 | * TrkParams::SetPFA(0); //Set ETA p.f.a. | 
| 523 | * | 
| 524 | * @see TrkParams::SetPFA(int) | 
| 525 | */ | 
| 526 | void TrkTrack::EvaluateClusterPositions(){ | 
| 527 |  | 
| 528 | //     cout << "void TrkTrack::GetClusterPositions() "<<endl; | 
| 529 |  | 
| 530 | TrkParams::Load( ); | 
| 531 | if( !TrkParams::IsLoaded() )return; | 
| 532 |  | 
| 533 | for(int ip=0; ip<6; ip++){ | 
| 534 | //      cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;; | 
| 535 | int icx = GetClusterX_ID(ip)+1; | 
| 536 | int icy = GetClusterY_ID(ip)+1; | 
| 537 | int sensor = GetSensor(ip)+1;//<< convenzione "Paolo" | 
| 538 | if(ip==5 && sensor!=0)sensor=3-sensor;//<< convenzione "Elena" | 
| 539 | int ladder = GetLadder(ip)+1; | 
| 540 | float ax = axv[ip]; | 
| 541 | float ay = ayv[ip]; | 
| 542 | float v[3]; | 
| 543 | v[0]=xv[ip]; | 
| 544 | v[1]=yv[ip]; | 
| 545 | v[2]=zv[ip]; | 
| 546 | float bfx = 10*TrkParams::GetBX(v);//Tesla | 
| 547 | float bfy = 10*TrkParams::GetBY(v);//Tesla | 
| 548 | int ipp=ip+1; | 
| 549 | xyzpam_(&ipp,&icx,&icy,&ladder,&sensor,&ax,&ay,&bfx,&bfy); | 
| 550 | } | 
| 551 | } | 
| 552 | /** | 
| 553 | * \brief Tracking method. It calls F77 mini routine. | 
| 554 | * | 
| 555 | * @param pfixed Particle momentum. If pfixed=0 the momentum | 
| 556 | * is left as a free parameter, otherwise it is fixed to the input value. | 
| 557 | * @param fail Output flag (!=0 if the fit failed). | 
| 558 | * @param iprint Flag to set debug mode ( 0 = no output; 1 = verbose; 2 = debug). | 
| 559 | * @param froml1 Flag to re-evaluate positions (see TrkTrack::GetClusterPositions()). | 
| 560 | * | 
| 561 | * The option to re-evaluate positions can be used only after recovering | 
| 562 | * level1 information, eg. by reprocessing the single event. | 
| 563 | * | 
| 564 | * Example: | 
| 565 | * | 
| 566 | * if( !event->GetTrkLevel0() )return false; | 
| 567 | * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1 | 
| 568 | * int fail=0; | 
| 569 | * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1); | 
| 570 | * | 
| 571 | * @see EvaluateClusterPositions() | 
| 572 | * | 
| 573 | * The fitting procedure can be varied by changing the tracking mode, | 
| 574 | * the fit-precision factor and the minimum number of step. | 
| 575 | * @see SetTrackingMode(int) | 
| 576 | * @see SetPrecisionFactor(double) | 
| 577 | * @see SetStepMin(int) | 
| 578 | */ | 
| 579 | void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){ | 
| 580 |  | 
| 581 | float al_ini[] = {0.,0.,0.,0.,0.}; | 
| 582 |  | 
| 583 | TrkParams::Load( ); | 
| 584 | if( !TrkParams::IsLoaded() )return; | 
| 585 |  | 
| 586 | extern cMini2track track_; | 
| 587 | fail = 0; | 
| 588 | FillMiniStruct(track_); | 
| 589 |  | 
| 590 | if(froml1!=0)EvaluateClusterPositions(); | 
| 591 |  | 
| 592 | // if fit variables have been reset, evaluate the initial guess | 
| 593 | if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); | 
| 594 |  | 
| 595 | // --------------------- free momentum | 
| 596 | if(pfixed==0.) { | 
| 597 | track_.pfixed=0.; | 
| 598 | } | 
| 599 | // --------------------- fixed momentum | 
| 600 | if(pfixed!=0.) { | 
| 601 | al[4]=1./pfixed; | 
| 602 | track_.pfixed=pfixed; | 
| 603 | } | 
| 604 |  | 
| 605 | //  store temporarily the initial guess | 
| 606 | for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; | 
| 607 |  | 
| 608 | //  ------------------------------------------ | 
| 609 | //  call mini routine | 
| 610 | //     TrkParams::Load(1); | 
| 611 | //     if( !TrkParams::IsLoaded(1) ){ | 
| 612 | //      cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl; | 
| 613 | //      return; | 
| 614 | //     } | 
| 615 | int istep=0; | 
| 616 | int ifail=0; | 
| 617 | mini2_(&istep,&ifail, &iprint); | 
| 618 | if(ifail!=0) { | 
| 619 | if(iprint)cout << "ERROR: ifail= " << ifail << endl; | 
| 620 | fail = 1; | 
| 621 | } | 
| 622 | //  ------------------------------------------ | 
| 623 |  | 
| 624 | SetFromMiniStruct(&track_); | 
| 625 |  | 
| 626 | if(fail){ | 
| 627 | if(iprint)cout << " >>>> fit failed "<<endl; | 
| 628 | for(int i=0; i<5; i++) al[i]=al_ini[i]; | 
| 629 | } | 
| 630 |  | 
| 631 | }; | 
| 632 | /** | 
| 633 | * Reset the fit parameters | 
| 634 | */ | 
| 635 | void TrkTrack::FitReset(){ | 
| 636 | for(int i=0; i<5; i++) al[i]=-9999.; | 
| 637 | chi2=0.; | 
| 638 | nstep=0; | 
| 639 | //     for(int i=0; i<6; i++) xv[i]=0.; | 
| 640 | //     for(int i=0; i<6; i++) yv[i]=0.; | 
| 641 | //     for(int i=0; i<6; i++) zv[i]=0.; | 
| 642 | //     for(int i=0; i<6; i++) axv[i]=0.; | 
| 643 | //     for(int i=0; i<6; i++) ayv[i]=0.; | 
| 644 | for(int i=0; i<5; i++) { | 
| 645 | for(int j=0; j<5; j++) coval[i][j]=0.; | 
| 646 | } | 
| 647 | } | 
| 648 | /** | 
| 649 | * Set the tracking mode | 
| 650 | */ | 
| 651 | void TrkTrack::SetTrackingMode(int trackmode){ | 
| 652 | extern cMini2track track_; | 
| 653 | track_.trackmode = trackmode; | 
| 654 | } | 
| 655 | /** | 
| 656 | * Set the factor scale for tracking precision | 
| 657 | */ | 
| 658 | void TrkTrack::SetPrecisionFactor(double fact){ | 
| 659 | extern cMini2track track_; | 
| 660 | track_.fact = fact; | 
| 661 | } | 
| 662 | /** | 
| 663 | * Set the factor scale for tracking precision | 
| 664 | */ | 
| 665 | void TrkTrack::SetStepMin(int istepmin){ | 
| 666 | extern cMini2track track_; | 
| 667 | track_.istepmin = istepmin; | 
| 668 | } | 
| 669 |  | 
| 670 |  | 
| 671 | /** | 
| 672 | * Method to retrieve ID (0,1,...) of x-cluster (if any) associated to this track. | 
| 673 | * If no cluster is associated, ID=-1. | 
| 674 | * @param ip Tracker plane (0-5) | 
| 675 | */ | 
| 676 | Int_t TrkTrack::GetClusterX_ID(int ip){ | 
| 677 | return ((Int_t)fabs(xgood[ip]))%10000000-1; | 
| 678 | }; | 
| 679 | /** | 
| 680 | * Method to retrieve ID (0-xxx) of y-cluster (if any) associated to this track. | 
| 681 | * If no cluster is associated, ID=-1. | 
| 682 | * @param ip Tracker plane (0-5) | 
| 683 | */ | 
| 684 | Int_t TrkTrack::GetClusterY_ID(int ip){ | 
| 685 | return ((Int_t)fabs(ygood[ip]))%10000000-1; | 
| 686 | }; | 
| 687 | /** | 
| 688 | * Method to retrieve the ladder (0-4, increasing x) traversed by the track on this plane. | 
| 689 | * If no ladder is traversed (dead area) the metod retuns -1. | 
| 690 | * @param ip Tracker plane (0-5) | 
| 691 | */ | 
| 692 | Int_t TrkTrack::GetLadder(int ip){ | 
| 693 | if(XGood(ip))return (Int_t)fabs(xgood[ip]/100000000)-1; | 
| 694 | if(YGood(ip))return (Int_t)fabs(ygood[ip]/100000000)-1; | 
| 695 | return -1; | 
| 696 | }; | 
| 697 | /** | 
| 698 | * Method to retrieve the sensor (0-1, increasing y) traversed by the track on this plane. | 
| 699 | * If no sensor is traversed (dead area) the metod retuns -1. | 
| 700 | * @param ip Tracker plane (0-5) | 
| 701 | */ | 
| 702 | Int_t TrkTrack::GetSensor(int ip){ | 
| 703 | if(XGood(ip))return (Int_t)((Int_t)fabs(xgood[ip]/10000000)%10)-1; | 
| 704 | if(YGood(ip))return (Int_t)((Int_t)fabs(ygood[ip]/10000000)%10)-1; | 
| 705 | return -1; | 
| 706 | }; | 
| 707 |  | 
| 708 | /** | 
| 709 | * \brief Method to include a x-cluster to the track. | 
| 710 | * @param ip Tracker plane (0-5) | 
| 711 | * @param clid Cluster ID (0,1,...) | 
| 712 | * @param is Sensor (0-1, increasing y) | 
| 713 | * @see Fit(double pfixed, int& fail, int iprint, int froml1) | 
| 714 | */ | 
| 715 | void TrkTrack::SetXGood(int ip, int clid, int is){ | 
| 716 | int il=0;       //ladder (temporary) | 
| 717 | bool bad=false; //ladder (temporary) | 
| 718 | xgood[ip]=il*100000000+is*10000000+clid; | 
| 719 | if(bad)xgood[ip]=-xgood[ip]; | 
| 720 | }; | 
| 721 | /** | 
| 722 | * \brief Method to include a y-cluster to the track. | 
| 723 | * @param ip Tracker plane (0-5) | 
| 724 | * @param clid Cluster ID (0,1,...) | 
| 725 | * @param is Sensor (0-1) | 
| 726 | * @see Fit(double pfixed, int& fail, int iprint, int froml1) | 
| 727 | */ | 
| 728 | void TrkTrack::SetYGood(int ip, int clid, int is){ | 
| 729 | int il=0;       //ladder (temporary) | 
| 730 | bool bad=false; //ladder (temporary) | 
| 731 | ygood[ip]=il*100000000+is*10000000+clid; | 
| 732 | if(bad)ygood[ip]=-ygood[ip]; | 
| 733 | }; | 
| 734 |  | 
| 735 | //-------------------------------------- | 
| 736 | // | 
| 737 | // | 
| 738 | //-------------------------------------- | 
| 739 | void TrkTrack::Clear(){ | 
| 740 | //    cout << "TrkTrack::Clear()"<<endl; | 
| 741 | seqno = -1; | 
| 742 | image = -1; | 
| 743 | chi2  = 0; | 
| 744 | nstep = 0; | 
| 745 | for(int it1=0;it1<5;it1++){ | 
| 746 | al[it1] = 0; | 
| 747 | for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; | 
| 748 | }; | 
| 749 | for(int ip=0;ip<6;ip++){ | 
| 750 | xgood[ip]  = 0; | 
| 751 | ygood[ip]  = 0; | 
| 752 | xm[ip]     = 0; | 
| 753 | ym[ip]     = 0; | 
| 754 | zm[ip]     = 0; | 
| 755 | resx[ip]   = 0; | 
| 756 | resy[ip]   = 0; | 
| 757 | tailx[ip]  = 0; | 
| 758 | taily[ip]  = 0; | 
| 759 | xv[ip]     = 0; | 
| 760 | yv[ip]     = 0; | 
| 761 | zv[ip]     = 0; | 
| 762 | axv[ip]    = 0; | 
| 763 | ayv[ip]    = 0; | 
| 764 | dedx_x[ip] = 0; | 
| 765 | dedx_y[ip] = 0; | 
| 766 |  | 
| 767 | }; | 
| 768 | //     if(clx)clx->Clear(); | 
| 769 | //     if(cly)cly->Clear(); | 
| 770 | //    clx.Clear(); | 
| 771 | //    cly.Clear(); | 
| 772 | }; | 
| 773 | //-------------------------------------- | 
| 774 | // | 
| 775 | // | 
| 776 | //-------------------------------------- | 
| 777 | void TrkTrack::Delete(){ | 
| 778 | //    cout << "TrkTrack::Delete()"<<endl; | 
| 779 | Clear(); | 
| 780 | //    if(clx)delete clx; | 
| 781 | //    if(cly)delete cly; | 
| 782 | }; | 
| 783 | //-------------------------------------- | 
| 784 | // | 
| 785 | // | 
| 786 | //-------------------------------------- | 
| 787 |  | 
| 788 | //-------------------------------------- | 
| 789 | // | 
| 790 | // | 
| 791 | //-------------------------------------- | 
| 792 | TrkSinglet::TrkSinglet(){ | 
| 793 | //    cout << "TrkSinglet::TrkSinglet() " << GetUniqueID()<<endl; | 
| 794 | plane    = 0; | 
| 795 | coord[0] = 0; | 
| 796 | coord[1] = 0; | 
| 797 | sgnl     = 0; | 
| 798 | //    cls      = 0; | 
| 799 | }; | 
| 800 | //-------------------------------------- | 
| 801 | // | 
| 802 | // | 
| 803 | //-------------------------------------- | 
| 804 | TrkSinglet::TrkSinglet(const TrkSinglet& s){ | 
| 805 | //    cout << "TrkSinglet::TrkSinglet(const TrkSinglet& s) " << GetUniqueID()<<endl; | 
| 806 | plane    = s.plane; | 
| 807 | coord[0] = s.coord[0]; | 
| 808 | coord[1] = s.coord[1]; | 
| 809 | sgnl     = s.sgnl; | 
| 810 | //      cls      = 0;//<<<<pointer | 
| 811 | //    cls      = TRef(s.cls); | 
| 812 | }; | 
| 813 | //-------------------------------------- | 
| 814 | // | 
| 815 | // | 
| 816 | //-------------------------------------- | 
| 817 | void TrkSinglet::Dump(){ | 
| 818 | int i=0; | 
| 819 | cout << endl << "========== Singlet " ; | 
| 820 | cout << endl << "plane    : " << plane; | 
| 821 | cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++; | 
| 822 | cout << endl << "sgnl     : " << sgnl; | 
| 823 | } | 
| 824 | //-------------------------------------- | 
| 825 | // | 
| 826 | // | 
| 827 | //-------------------------------------- | 
| 828 | void TrkSinglet::Clear(){ | 
| 829 | //    cout << "TrkSinglet::Clear() " << GetUniqueID()<<endl; | 
| 830 | //    cls=0; | 
| 831 | plane=-1; | 
| 832 | coord[0]=-999; | 
| 833 | coord[1]=-999; | 
| 834 | sgnl=0; | 
| 835 |  | 
| 836 | } | 
| 837 | //-------------------------------------- | 
| 838 | // | 
| 839 | // | 
| 840 | //-------------------------------------- | 
| 841 | TrkLevel2::TrkLevel2(){ | 
| 842 | //    cout <<"TrkLevel2::TrkLevel2()"<<endl; | 
| 843 | for(Int_t i=0; i<12 ; i++){ | 
| 844 | good[i] = -1; | 
| 845 | VKmask[i] = 0; | 
| 846 | VKflag[i] = 0; | 
| 847 | }; | 
| 848 | Track    = 0; | 
| 849 | SingletX = 0; | 
| 850 | SingletY = 0; | 
| 851 |  | 
| 852 | } | 
| 853 | //-------------------------------------- | 
| 854 | // | 
| 855 | // | 
| 856 | //-------------------------------------- | 
| 857 | void TrkLevel2::Set(){ | 
| 858 | if(!Track)Track    = new TClonesArray("TrkTrack"); | 
| 859 | if(!SingletX)SingletX = new TClonesArray("TrkSinglet"); | 
| 860 | if(!SingletY)SingletY = new TClonesArray("TrkSinglet"); | 
| 861 | } | 
| 862 | //-------------------------------------- | 
| 863 | // | 
| 864 | // | 
| 865 | //-------------------------------------- | 
| 866 | void TrkLevel2::Dump(){ | 
| 867 |  | 
| 868 | // | 
| 869 | cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"; | 
| 870 | cout << endl << "good     : "; for(int i=0; i<12; i++) cout << good[i]<<" "; | 
| 871 | cout << endl << "ntrk()   : " << this->ntrk() ; | 
| 872 | cout << endl << "nclsx()  : " << this->nclsx(); | 
| 873 | cout << endl << "nclsy()  : " << this->nclsy(); | 
| 874 | if(Track){ | 
| 875 | TClonesArray &t  = *Track; | 
| 876 | for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump(); | 
| 877 | } | 
| 878 | if(SingletX){ | 
| 879 | TClonesArray &sx = *SingletX; | 
| 880 | for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump(); | 
| 881 | } | 
| 882 | if(SingletY){ | 
| 883 | TClonesArray &sy = *SingletY; | 
| 884 | for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump(); | 
| 885 | } | 
| 886 | } | 
| 887 | //-------------------------------------- | 
| 888 | // | 
| 889 | // | 
| 890 | //-------------------------------------- | 
| 891 | /** | 
| 892 | * The method returns false if the viking-chip was masked | 
| 893 | * either apriori ,on the basis of the mask read from the DB, | 
| 894 | * or run-by-run, on the basis of the calibration parameters) | 
| 895 | * @param iv Tracker view (0-11) | 
| 896 | * @param ivk Viking-chip number (0-23) | 
| 897 | */ | 
| 898 | Bool_t TrkLevel2::GetVKMask(int iv, int ivk){ | 
| 899 | Int_t whichbit = (Int_t)pow(2,ivk); | 
| 900 | return (whichbit&VKmask[iv])!=0; | 
| 901 | } | 
| 902 | /** | 
| 903 | * The method returns false if the viking-chip was masked | 
| 904 | * for this event due to common-noise computation failure. | 
| 905 | * @param iv Tracker view (0-11) | 
| 906 | * @param ivk Viking-chip number (0-23) | 
| 907 | */ | 
| 908 | Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){ | 
| 909 | Int_t whichbit = (Int_t)pow(2,ivk); | 
| 910 | return (whichbit&VKflag[iv])!=0; | 
| 911 | } | 
| 912 | /** | 
| 913 | * The method returns true if the viking-chip was masked, either | 
| 914 | * forced (see TrkLevel2::GetVKMask(int,int)) or | 
| 915 | * for this event only (TrkLevel2::GetVKFlag(int,int)). | 
| 916 | * @param iv Tracker view (0-11) | 
| 917 | * @param ivk Viking-chip number (0-23) | 
| 918 | */ | 
| 919 | Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){ | 
| 920 | return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) ); | 
| 921 | }; | 
| 922 |  | 
| 923 | //-------------------------------------- | 
| 924 | // | 
| 925 | // | 
| 926 | //-------------------------------------- | 
| 927 | /** | 
| 928 | * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). | 
| 929 | * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set. | 
| 930 | * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch) | 
| 931 | */ | 
| 932 | void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){ | 
| 933 |  | 
| 934 | //    cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl; | 
| 935 | Clear(); | 
| 936 |  | 
| 937 | //  temporary objects: | 
| 938 | TrkSinglet* t_singlet = new TrkSinglet(); | 
| 939 | TrkTrack*   t_track   = new TrkTrack(); | 
| 940 |  | 
| 941 | //  ----------------- | 
| 942 | //  general variables | 
| 943 | //  ----------------- | 
| 944 | for(Int_t i=0; i<12 ; i++){ | 
| 945 | good[i] = l2->good[i]; | 
| 946 | VKmask[i]=0; | 
| 947 | VKflag[i]=0; | 
| 948 | for(Int_t ii=0; ii<24 ; ii++){ | 
| 949 | Int_t setbit = (Int_t)pow(2,ii); | 
| 950 | if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit; | 
| 951 | if( l2->vkflag[ii][i]!=0  )VKflag[i]=VKflag[i]|setbit; | 
| 952 | }; | 
| 953 | }; | 
| 954 | //  -------------- | 
| 955 | //  *** TRACKS *** | 
| 956 | //  -------------- | 
| 957 | if(!Track) Track = new TClonesArray("TrkTrack"); | 
| 958 | TClonesArray &t = *Track; | 
| 959 |  | 
| 960 | for(int i=0; i<l2->ntrk; i++){ | 
| 961 | t_track->seqno = i;// NBNBNBNB deve sempre essere = i | 
| 962 | t_track->image = l2->image[i]-1; | 
| 963 | t_track->chi2  = l2->chi2_nt[i]; | 
| 964 | t_track->nstep = l2->nstep_nt[i]; | 
| 965 | for(int it1=0;it1<5;it1++){ | 
| 966 | t_track->al[it1] = l2->al_nt[i][it1]; | 
| 967 | for(int it2=0;it2<5;it2++) | 
| 968 | t_track->coval[it1][it2] = l2->coval[i][it2][it1]; | 
| 969 | }; | 
| 970 | for(int ip=0;ip<6;ip++){ | 
| 971 | // --------------------------------- | 
| 972 | // new implementation of xgood/ygood | 
| 973 | // --------------------------------- | 
| 974 | t_track->xgood[ip]  = l2->cltrx[i][ip]; //cluster ID | 
| 975 | t_track->ygood[ip]  = l2->cltry[i][ip]; //cluster ID | 
| 976 | t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor | 
| 977 | t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor | 
| 978 | if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip]; | 
| 979 | if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip]; | 
| 980 | //          if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){ | 
| 981 | //          if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){ | 
| 982 | //              cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl; | 
| 983 | //              cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl; | 
| 984 | //              cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl; | 
| 985 | //              cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl; | 
| 986 | //              cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl; | 
| 987 | //          } | 
| 988 | t_track->xm[ip]     = l2->xm_nt[i][ip]; | 
| 989 | t_track->ym[ip]     = l2->ym_nt[i][ip]; | 
| 990 | t_track->zm[ip]     = l2->zm_nt[i][ip]; | 
| 991 | t_track->resx[ip]   = l2->resx_nt[i][ip]; | 
| 992 | t_track->resy[ip]   = l2->resy_nt[i][ip]; | 
| 993 | t_track->tailx[ip]  = l2->tailx[i][ip]; | 
| 994 | t_track->taily[ip]  = l2->taily[i][ip]; | 
| 995 | t_track->xv[ip]     = l2->xv_nt[i][ip]; | 
| 996 | t_track->yv[ip]     = l2->yv_nt[i][ip]; | 
| 997 | t_track->zv[ip]     = l2->zv_nt[i][ip]; | 
| 998 | t_track->axv[ip]    = l2->axv_nt[i][ip]; | 
| 999 | t_track->ayv[ip]    = l2->ayv_nt[i][ip]; | 
| 1000 | t_track->dedx_x[ip] = l2->dedx_x[i][ip]; | 
| 1001 | t_track->dedx_y[ip] = l2->dedx_y[i][ip]; | 
| 1002 | //----------------------------------------------------- | 
| 1003 | //----------------------------------------------------- | 
| 1004 | //----------------------------------------------------- | 
| 1005 | //----------------------------------------------------- | 
| 1006 | }; | 
| 1007 | //      if(t_track->IsSaturated())t_track->Dump(); | 
| 1008 | new(t[i]) TrkTrack(*t_track); | 
| 1009 | t_track->Clear(); | 
| 1010 | }; | 
| 1011 |  | 
| 1012 | //  ---------------- | 
| 1013 | //  *** SINGLETS *** | 
| 1014 | //  ---------------- | 
| 1015 | if(!SingletX)SingletX = new TClonesArray("TrkSinglet"); | 
| 1016 | TClonesArray &sx = *SingletX; | 
| 1017 | for(int i=0; i<l2->nclsx; i++){ | 
| 1018 | t_singlet->plane    = l2->planex[i]; | 
| 1019 | t_singlet->coord[0] = l2->xs[i][0]; | 
| 1020 | t_singlet->coord[1] = l2->xs[i][1]; | 
| 1021 | t_singlet->sgnl     = l2->signlxs[i]; | 
| 1022 | //----------------------------------------------------- | 
| 1023 | //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1); | 
| 1024 | //----------------------------------------------------- | 
| 1025 | new(sx[i]) TrkSinglet(*t_singlet); | 
| 1026 | t_singlet->Clear(); | 
| 1027 | } | 
| 1028 | if(!SingletY)SingletY = new TClonesArray("TrkSinglet"); | 
| 1029 | TClonesArray &sy = *SingletY; | 
| 1030 | for(int i=0; i<l2->nclsy; i++){ | 
| 1031 | t_singlet->plane    = l2->planey[i]; | 
| 1032 | t_singlet->coord[0] = l2->ys[i][0]; | 
| 1033 | t_singlet->coord[1] = l2->ys[i][1]; | 
| 1034 | t_singlet->sgnl     = l2->signlys[i]; | 
| 1035 | //----------------------------------------------------- | 
| 1036 | //      if(l1) t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1); | 
| 1037 | //----------------------------------------------------- | 
| 1038 | new(sy[i]) TrkSinglet(*t_singlet); | 
| 1039 | t_singlet->Clear(); | 
| 1040 | }; | 
| 1041 |  | 
| 1042 | delete t_track; | 
| 1043 | delete t_singlet; | 
| 1044 | } | 
| 1045 | /** | 
| 1046 | * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common). | 
| 1047 | */ | 
| 1048 |  | 
| 1049 | void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const { | 
| 1050 |  | 
| 1051 | //  general variables | 
| 1052 | //    l2->good2 = good2 ; | 
| 1053 | for(Int_t i=0; i<12 ; i++){ | 
| 1054 | //      l2->crc[i] = crc[i]; | 
| 1055 | l2->good[i] = good[i]; | 
| 1056 | }; | 
| 1057 | //  *** TRACKS *** | 
| 1058 |  | 
| 1059 | if(Track){ | 
| 1060 | l2->ntrk              =  Track->GetEntries(); | 
| 1061 | for(Int_t i=0;i<l2->ntrk;i++){ | 
| 1062 | l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image; | 
| 1063 | l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2; | 
| 1064 | l2->nstep_nt[i] =  ((TrkTrack *)Track->At(i))->nstep; | 
| 1065 | for(int it1=0;it1<5;it1++){ | 
| 1066 | l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1]; | 
| 1067 | for(int it2=0;it2<5;it2++) | 
| 1068 | l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2]; | 
| 1069 | }; | 
| 1070 | for(int ip=0;ip<6;ip++){ | 
| 1071 | l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip); | 
| 1072 | l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip); | 
| 1073 | l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip]; | 
| 1074 | l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip]; | 
| 1075 | l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip]; | 
| 1076 | l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip]; | 
| 1077 | l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip]; | 
| 1078 | l2->tailx[i][ip]  = ((TrkTrack *)Track->At(i))->tailx[ip]; | 
| 1079 | l2->taily[i][ip]  = ((TrkTrack *)Track->At(i))->taily[ip]; | 
| 1080 | l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip]; | 
| 1081 | l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip]; | 
| 1082 | l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip]; | 
| 1083 | l2->axv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->axv[ip]; | 
| 1084 | l2->ayv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->ayv[ip]; | 
| 1085 | l2->dedx_x[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_x[ip]; | 
| 1086 | l2->dedx_y[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_y[ip]; | 
| 1087 | }; | 
| 1088 | } | 
| 1089 | } | 
| 1090 | //  *** SINGLETS *** | 
| 1091 | if(SingletX){ | 
| 1092 | l2->nclsx              = SingletX->GetEntries(); | 
| 1093 | for(Int_t i=0;i<l2->nclsx;i++){ | 
| 1094 | l2->planex[i]  = ((TrkSinglet *)SingletX->At(i))->plane; | 
| 1095 | l2->xs[i][0]   = ((TrkSinglet *)SingletX->At(i))->coord[0]; | 
| 1096 | l2->xs[i][1]   = ((TrkSinglet *)SingletX->At(i))->coord[1]; | 
| 1097 | l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl; | 
| 1098 | } | 
| 1099 | } | 
| 1100 |  | 
| 1101 | if(SingletY){ | 
| 1102 | l2->nclsy              = SingletY->GetEntries(); | 
| 1103 | for(Int_t i=0;i<l2->nclsy;i++){ | 
| 1104 | l2->planey[i]  = ((TrkSinglet *)SingletY->At(i))->plane; | 
| 1105 | l2->ys[i][0]   = ((TrkSinglet *)SingletY->At(i))->coord[0]; | 
| 1106 | l2->ys[i][1]   = ((TrkSinglet *)SingletY->At(i))->coord[1]; | 
| 1107 | l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl; | 
| 1108 | } | 
| 1109 | } | 
| 1110 | } | 
| 1111 | //-------------------------------------- | 
| 1112 | // | 
| 1113 | // | 
| 1114 | //-------------------------------------- | 
| 1115 | void TrkLevel2::Clear(){ | 
| 1116 | for(Int_t i=0; i<12 ; i++){ | 
| 1117 | good[i] = -1; | 
| 1118 | VKflag[i] = 0; | 
| 1119 | VKmask[i] = 0; | 
| 1120 | }; | 
| 1121 | //    if(Track)Track->Clear("C"); | 
| 1122 | //    if(SingletX)SingletX->Clear("C"); | 
| 1123 | //    if(SingletY)SingletY->Clear("C"); | 
| 1124 | if(Track)Track->Delete(); | 
| 1125 | if(SingletX)SingletX->Delete(); | 
| 1126 | if(SingletY)SingletY->Delete(); | 
| 1127 | } | 
| 1128 | // //-------------------------------------- | 
| 1129 | // // | 
| 1130 | // // | 
| 1131 | // //-------------------------------------- | 
| 1132 | void TrkLevel2::Delete(){ | 
| 1133 |  | 
| 1134 | //    cout << "void TrkLevel2::Delete()"<<endl; | 
| 1135 | Clear(); | 
| 1136 | if(Track)delete Track; | 
| 1137 | if(SingletX)delete SingletX; | 
| 1138 | if(SingletY)delete SingletY; | 
| 1139 |  | 
| 1140 | } | 
| 1141 | //-------------------------------------- | 
| 1142 | // | 
| 1143 | // | 
| 1144 | //-------------------------------------- | 
| 1145 | /** | 
| 1146 | * 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). | 
| 1147 | * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. | 
| 1148 | */ | 
| 1149 | TRefArray *TrkLevel2::GetTracks_NFitSorted(){ | 
| 1150 |  | 
| 1151 | if(!Track)return 0; | 
| 1152 |  | 
| 1153 | TRefArray *sorted = new TRefArray(); | 
| 1154 |  | 
| 1155 | TClonesArray &t  = *Track; | 
| 1156 | //    TClonesArray &ts = *PhysicalTrack; | 
| 1157 | int N = ntrk(); | 
| 1158 | vector<int> m(N); for(int i=0; i<N; i++)m[i]=1; | 
| 1159 | //      int m[50]; for(int i=0; i<N; i++)m[i]=1; | 
| 1160 |  | 
| 1161 | int indo=0; | 
| 1162 | int indi=0; | 
| 1163 | while(N > 0){ | 
| 1164 | //    while(N != 0){ | 
| 1165 | int nfit =0; | 
| 1166 | float chi2ref = numeric_limits<float>::max(); | 
| 1167 |  | 
| 1168 | // first loop to search maximum num. of fit points | 
| 1169 | for(int i=0; i < ntrk(); i++){ | 
| 1170 | if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){ | 
| 1171 | nfit =    ((TrkTrack *)t[i])->GetNtot(); | 
| 1172 | } | 
| 1173 | } | 
| 1174 | //second loop to search minimum chi2 among selected | 
| 1175 | for(int i=0; i<ntrk(); i++){ | 
| 1176 | Float_t chi2 = ((TrkTrack *)t[i])->chi2; | 
| 1177 | if(chi2 < 0) chi2 = -chi2*1000; | 
| 1178 | if(    chi2 < chi2ref | 
| 1179 | && ((TrkTrack *)t[i])->GetNtot() == nfit | 
| 1180 | && m[i]==1){ | 
| 1181 | chi2ref = ((TrkTrack *)t[i])->chi2; | 
| 1182 | indi = i; | 
| 1183 | }; | 
| 1184 | }; | 
| 1185 | if( ((TrkTrack *)t[indi])->HasImage() ){ | 
| 1186 | m[((TrkTrack *)t[indi])->image] = 0; | 
| 1187 | N--; | 
| 1188 |  | 
| 1189 | //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl; | 
| 1190 | }; | 
| 1191 | sorted->Add( (TrkTrack*)t[indi] ); | 
| 1192 |  | 
| 1193 | m[indi] = 0; | 
| 1194 | //      cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl; | 
| 1195 | N--; | 
| 1196 | indo++; | 
| 1197 | } | 
| 1198 | m.clear(); | 
| 1199 | //    cout << "GetTracks_NFitSorted(it): Done"<< endl; | 
| 1200 |  | 
| 1201 | return sorted; | 
| 1202 | //    return PhysicalTrack; | 
| 1203 | } | 
| 1204 | //-------------------------------------- | 
| 1205 | // | 
| 1206 | // | 
| 1207 | //-------------------------------------- | 
| 1208 | /** | 
| 1209 | * Retrieves the is-th stored track. | 
| 1210 | * @param it Track number, ranging from 0 to ntrk(). | 
| 1211 | * Fitted tracks ( images included ) are stored in a TObjectArray ( TrkLevel2::Track ) in the same order they are returned by the F77 fitting routine. | 
| 1212 | */ | 
| 1213 | TrkTrack *TrkLevel2::GetStoredTrack(int is){ | 
| 1214 |  | 
| 1215 | if(is >= this->ntrk()){ | 
| 1216 | cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl; | 
| 1217 | cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl; | 
| 1218 | return 0; | 
| 1219 | } | 
| 1220 | if(!Track){ | 
| 1221 | cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (TClonesArray*) Track ==0 "<<endl; | 
| 1222 | }; | 
| 1223 | TClonesArray &t = *(Track); | 
| 1224 | TrkTrack *track = (TrkTrack*)t[is]; | 
| 1225 | return track; | 
| 1226 | } | 
| 1227 | //-------------------------------------- | 
| 1228 | // | 
| 1229 | // | 
| 1230 | //-------------------------------------- | 
| 1231 | /** | 
| 1232 | * Retrieves the is-th stored X singlet. | 
| 1233 | * @param it Singlet number, ranging from 0 to nclsx(). | 
| 1234 | */ | 
| 1235 | TrkSinglet *TrkLevel2::GetSingletX(int is){ | 
| 1236 |  | 
| 1237 | if(is >= this->nclsx()){ | 
| 1238 | cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; | 
| 1239 | cout << "                Stored x-singlets nclsx() = "<< this->nclsx() << endl; | 
| 1240 | return 0; | 
| 1241 | } | 
| 1242 | if(!SingletX)return 0; | 
| 1243 | TClonesArray &t = *(SingletX); | 
| 1244 | TrkSinglet *singlet = (TrkSinglet*)t[is]; | 
| 1245 | return singlet; | 
| 1246 | } | 
| 1247 | //-------------------------------------- | 
| 1248 | // | 
| 1249 | // | 
| 1250 | //-------------------------------------- | 
| 1251 | /** | 
| 1252 | * Retrieves the is-th stored Y singlet. | 
| 1253 | * @param it Singlet number, ranging from 0 to nclsx(). | 
| 1254 | */ | 
| 1255 | TrkSinglet *TrkLevel2::GetSingletY(int is){ | 
| 1256 |  | 
| 1257 | if(is >= this->nclsy()){ | 
| 1258 | cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; | 
| 1259 | cout << "                Stored y-singlets nclsy() = "<< this->nclsx() << endl; | 
| 1260 | return 0; | 
| 1261 | } | 
| 1262 | if(!SingletY)return 0; | 
| 1263 | TClonesArray &t = *(SingletY); | 
| 1264 | TrkSinglet *singlet = (TrkSinglet*)t[is]; | 
| 1265 | return singlet; | 
| 1266 | } | 
| 1267 | //-------------------------------------- | 
| 1268 | // | 
| 1269 | // | 
| 1270 | //-------------------------------------- | 
| 1271 | /** | 
| 1272 | * Retrieves the it-th "physical" track, sorted by the method GetNTracks(). | 
| 1273 | * @param it Track number, ranging from 0 to GetNTracks(). | 
| 1274 | */ | 
| 1275 |  | 
| 1276 | TrkTrack *TrkLevel2::GetTrack(int it){ | 
| 1277 |  | 
| 1278 | if(it >= this->GetNTracks()){ | 
| 1279 | cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; | 
| 1280 | cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl; | 
| 1281 | return 0; | 
| 1282 | } | 
| 1283 |  | 
| 1284 | TRefArray *sorted = GetTracks();  //TEMPORANEO | 
| 1285 | if(!sorted)return 0; | 
| 1286 | TrkTrack *track = (TrkTrack*)sorted->At(it); | 
| 1287 | sorted->Clear(); | 
| 1288 | delete sorted; | 
| 1289 | return track; | 
| 1290 | } | 
| 1291 | /** | 
| 1292 | * Give the number of "physical" tracks, sorted by the method GetTracks(). | 
| 1293 | */ | 
| 1294 | Int_t TrkLevel2::GetNTracks(){ | 
| 1295 |  | 
| 1296 | Float_t ntot=0; | 
| 1297 | if(!Track)return 0; | 
| 1298 | TClonesArray &t = *Track; | 
| 1299 | for(int i=0; i<ntrk(); i++) { | 
| 1300 | if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.; | 
| 1301 | else ntot+=0.5; | 
| 1302 | } | 
| 1303 | return (Int_t)ntot; | 
| 1304 |  | 
| 1305 | }; | 
| 1306 | //-------------------------------------- | 
| 1307 | // | 
| 1308 | // | 
| 1309 | //-------------------------------------- | 
| 1310 | /** | 
| 1311 | * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks(). | 
| 1312 | * @param it Track number, ranging from 0 to GetNTracks(). | 
| 1313 | */ | 
| 1314 | TrkTrack *TrkLevel2::GetTrackImage(int it){ | 
| 1315 |  | 
| 1316 | if(it >= this->GetNTracks()){ | 
| 1317 | cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl; | 
| 1318 | cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl; | 
| 1319 | return 0; | 
| 1320 | } | 
| 1321 |  | 
| 1322 | TRefArray* sorted = GetTracks(); //TEMPORANEO | 
| 1323 | if(!sorted)return 0; | 
| 1324 | TrkTrack *track = (TrkTrack*)sorted->At(it); | 
| 1325 |  | 
| 1326 | if(!track->HasImage()){ | 
| 1327 | cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl; | 
| 1328 | return 0; | 
| 1329 | } | 
| 1330 | if(!Track)return 0; | 
| 1331 | TrkTrack *image = (TrkTrack*)(*Track)[track->image]; | 
| 1332 |  | 
| 1333 | sorted->Delete(); | 
| 1334 | delete sorted; | 
| 1335 |  | 
| 1336 | return image; | 
| 1337 |  | 
| 1338 | } | 
| 1339 | //-------------------------------------- | 
| 1340 | // | 
| 1341 | // | 
| 1342 | //-------------------------------------- | 
| 1343 | /** | 
| 1344 | * Loads the magnetic field. | 
| 1345 | * @param s Path of the magnetic-field files. | 
| 1346 | */ | 
| 1347 | void TrkLevel2::LoadField(TString path){ | 
| 1348 | // | 
| 1349 | //     strcpy(path_.path,path.Data()); | 
| 1350 | //     path_.pathlen = path.Length(); | 
| 1351 | //     path_.error   = 0; | 
| 1352 | //     readb_(); | 
| 1353 |  | 
| 1354 | TrkParams::SetTrackingMode(); | 
| 1355 | TrkParams::SetPrecisionFactor(); | 
| 1356 | TrkParams::SetStepMin(); | 
| 1357 |  | 
| 1358 | TrkParams::Set(path,1); | 
| 1359 | TrkParams::Load(1); | 
| 1360 |  | 
| 1361 | // | 
| 1362 | }; | 
| 1363 | // /** | 
| 1364 | //  * Get BY (kGauss) | 
| 1365 | //  * @param v (x,y,z) coordinates in cm | 
| 1366 | //  */ | 
| 1367 | // float TrkLevel2::GetBX(float* v){ | 
| 1368 | //     float b[3]; | 
| 1369 | //     gufld_(v,b); | 
| 1370 | //     return b[0]/10.; | 
| 1371 | // } | 
| 1372 | // /** | 
| 1373 | //  * Get BY (kGauss) | 
| 1374 | //  * @param v (x,y,z) coordinates in cm | 
| 1375 | //  */ | 
| 1376 | // float TrkLevel2::GetBY(float* v){ | 
| 1377 | //     float b[3]; | 
| 1378 | //     gufld_(v,b); | 
| 1379 | //     return b[1]/10.; | 
| 1380 | // } | 
| 1381 | // /** | 
| 1382 | //  * Get BY (kGauss) | 
| 1383 | //  * @param v (x,y,z) coordinates in cm | 
| 1384 | //  */ | 
| 1385 | // float TrkLevel2::GetBZ(float* v){ | 
| 1386 | //     float b[3]; | 
| 1387 | //     gufld_(v,b); | 
| 1388 | //     return b[2]/10.; | 
| 1389 | // } | 
| 1390 | //-------------------------------------- | 
| 1391 | // | 
| 1392 | // | 
| 1393 | //-------------------------------------- | 
| 1394 | /** | 
| 1395 | * Get tracker-plane (mechanical) z-coordinate | 
| 1396 | * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM) | 
| 1397 | */ | 
| 1398 | Float_t TrkLevel2::GetZTrk(Int_t plane_id){ | 
| 1399 | switch(plane_id){ | 
| 1400 | case 1: return ZTRK1; | 
| 1401 | case 2: return ZTRK2; | 
| 1402 | case 3: return ZTRK3; | 
| 1403 | case 4: return ZTRK4; | 
| 1404 | case 5: return ZTRK5; | 
| 1405 | case 6: return ZTRK6; | 
| 1406 | default: return 0.; | 
| 1407 | }; | 
| 1408 | }; | 
| 1409 | //-------------------------------------- | 
| 1410 | // | 
| 1411 | // | 
| 1412 | //-------------------------------------- | 
| 1413 | /** | 
| 1414 | * Trajectory default constructor. | 
| 1415 | * (By default is created with z-coordinates inside the tracking volume) | 
| 1416 | */ | 
| 1417 | Trajectory::Trajectory(){ | 
| 1418 | npoint = 10; | 
| 1419 | x = new float[npoint]; | 
| 1420 | y = new float[npoint]; | 
| 1421 | z = new float[npoint]; | 
| 1422 | thx = new float[npoint]; | 
| 1423 | thy = new float[npoint]; | 
| 1424 | tl = new float[npoint]; | 
| 1425 | float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); | 
| 1426 | for(int i=0; i<npoint; i++){ | 
| 1427 | x[i] = 0; | 
| 1428 | y[i] = 0; | 
| 1429 | z[i] = (ZTRK1) - i*dz; | 
| 1430 | thx[i] = 0; | 
| 1431 | thy[i] = 0; | 
| 1432 | tl[i] = 0; | 
| 1433 | } | 
| 1434 | } | 
| 1435 | //-------------------------------------- | 
| 1436 | // | 
| 1437 | // | 
| 1438 | //-------------------------------------- | 
| 1439 | /** | 
| 1440 | * Trajectory constructor. | 
| 1441 | * (By default is created with z-coordinates inside the tracking volume) | 
| 1442 | * \param n Number of points | 
| 1443 | */ | 
| 1444 | Trajectory::Trajectory(int n){ | 
| 1445 | if(n<=0){ | 
| 1446 | cout << "NB! Trajectory must have at least 1 point >>> created with 10 points" << endl; | 
| 1447 | n=10; | 
| 1448 | } | 
| 1449 | npoint = n; | 
| 1450 | x = new float[npoint]; | 
| 1451 | y = new float[npoint]; | 
| 1452 | z = new float[npoint]; | 
| 1453 | thx = new float[npoint]; | 
| 1454 | thy = new float[npoint]; | 
| 1455 | tl = new float[npoint]; | 
| 1456 | float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); | 
| 1457 | for(int i=0; i<npoint; i++){ | 
| 1458 | x[i] = 0; | 
| 1459 | y[i] = 0; | 
| 1460 | z[i] = (ZTRK1) - i*dz; | 
| 1461 | thx[i] = 0; | 
| 1462 | thy[i] = 0; | 
| 1463 | tl[i] = 0; | 
| 1464 | } | 
| 1465 | } | 
| 1466 | //-------------------------------------- | 
| 1467 | // | 
| 1468 | // | 
| 1469 | //-------------------------------------- | 
| 1470 | /** | 
| 1471 | * Trajectory constructor. | 
| 1472 | * \param n Number of points | 
| 1473 | * \param pz Pointer to float array, defining z coordinates | 
| 1474 | */ | 
| 1475 | Trajectory::Trajectory(int n, float* zin){ | 
| 1476 | npoint = 10; | 
| 1477 | if(n>0)npoint = n; | 
| 1478 | x = new float[npoint]; | 
| 1479 | y = new float[npoint]; | 
| 1480 | z = new float[npoint]; | 
| 1481 | thx = new float[npoint]; | 
| 1482 | thy = new float[npoint]; | 
| 1483 | tl = new float[npoint]; | 
| 1484 | int i=0; | 
| 1485 | do{ | 
| 1486 | x[i] = 0; | 
| 1487 | y[i] = 0; | 
| 1488 | z[i] = zin[i]; | 
| 1489 | thx[i] = 0; | 
| 1490 | thy[i] = 0; | 
| 1491 | tl[i] = 0; | 
| 1492 | i++; | 
| 1493 | }while(zin[i-1] > zin[i] && i < npoint); | 
| 1494 | npoint=i; | 
| 1495 | if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl; | 
| 1496 | } | 
| 1497 | void Trajectory::Delete(){ | 
| 1498 |  | 
| 1499 | if(x) delete [] x; | 
| 1500 | if(y) delete [] y; | 
| 1501 | if(z) delete [] z; | 
| 1502 | if(thx) delete [] thx; | 
| 1503 | if(thy) delete [] thy; | 
| 1504 | if(tl) delete [] tl; | 
| 1505 |  | 
| 1506 | } | 
| 1507 | //-------------------------------------- | 
| 1508 | // | 
| 1509 | // | 
| 1510 | //-------------------------------------- | 
| 1511 | /** | 
| 1512 | * Dump the trajectory coordinates. | 
| 1513 | */ | 
| 1514 | void Trajectory::Dump(){ | 
| 1515 | cout <<endl<< "Trajectory ========== "<<endl; | 
| 1516 | for (int i=0; i<npoint; i++){ | 
| 1517 | cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] ; | 
| 1518 | cout <<" -- " << thx[i] <<" "<< thy[i] ; | 
| 1519 | cout <<" -- " << tl[i] << endl; | 
| 1520 | }; | 
| 1521 | } | 
| 1522 | //-------------------------------------- | 
| 1523 | // | 
| 1524 | // | 
| 1525 | //-------------------------------------- | 
| 1526 | /** | 
| 1527 | * Get trajectory length between two points | 
| 1528 | * @param ifirst first point (default 0) | 
| 1529 | * @param ilast last point (default npoint) | 
| 1530 | */ | 
| 1531 | float Trajectory::GetLength(int ifirst, int ilast){ | 
| 1532 | if( ifirst<0    ) ifirst = 0; | 
| 1533 | if( ilast>=npoint) ilast  = npoint-1; | 
| 1534 | float l=0; | 
| 1535 | for(int i=ifirst;i<=ilast;i++){ | 
| 1536 | l=l+tl[i]; | 
| 1537 | }; | 
| 1538 | if(z[ilast] > ZINI)l=l-tl[ilast]; | 
| 1539 | if(z[ifirst] < ZINI)   l=l-tl[ifirst]; | 
| 1540 |  | 
| 1541 | return l; | 
| 1542 |  | 
| 1543 | } | 
| 1544 |  | 
| 1545 | /** | 
| 1546 | * Evaluates the trajectory in the apparatus associated to the track. | 
| 1547 | * 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. | 
| 1548 | * @param t pointer to an object of the class Trajectory, | 
| 1549 | * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). | 
| 1550 | * @return error flag. | 
| 1551 | */ | 
| 1552 | int Trajectory::DoTrack2(float* al){ | 
| 1553 |  | 
| 1554 | double *dxout   = new double[npoint]; | 
| 1555 | double *dyout   = new double[npoint]; | 
| 1556 | double *dthxout = new double[npoint]; | 
| 1557 | double *dthyout = new double[npoint]; | 
| 1558 | double *dtlout  = new double[npoint]; | 
| 1559 | double *dzin    = new double[npoint]; | 
| 1560 | double dal[5]; | 
| 1561 |  | 
| 1562 | int ifail = 0; | 
| 1563 |  | 
| 1564 | for (int i=0; i<5; i++)      dal[i]  = (double)al[i]; | 
| 1565 | for (int i=0; i<npoint; i++) dzin[i] = (double)z[i]; | 
| 1566 |  | 
| 1567 | TrkParams::Load(1); | 
| 1568 | if( !TrkParams::IsLoaded(1) ){ | 
| 1569 | cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl; | 
| 1570 | return 0; | 
| 1571 | } | 
| 1572 | dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); | 
| 1573 |  | 
| 1574 | for (int i=0; i<npoint; i++){ | 
| 1575 | x[i]   = (float)*dxout++; | 
| 1576 | y[i]   = (float)*dyout++; | 
| 1577 | thx[i] = (float)*dthxout++; | 
| 1578 | thy[i] = (float)*dthyout++; | 
| 1579 | tl[i]  = (float)*dtlout++; | 
| 1580 | } | 
| 1581 |  | 
| 1582 | return ifail; | 
| 1583 | }; | 
| 1584 |  | 
| 1585 | ClassImp(TrkLevel2); | 
| 1586 | ClassImp(TrkSinglet); | 
| 1587 | ClassImp(TrkTrack); | 
| 1588 | ClassImp(Trajectory); |