/[PAMELA software]/DarthVader/TrackerLevel2/src/TrkLevel2.cpp
ViewVC logotype

Contents of /DarthVader/TrackerLevel2/src/TrkLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.46 - (show annotations) (download)
Fri Apr 11 13:44:38 2008 UTC (16 years, 9 months ago) by pam-fi
Branch: MAIN
Changes since 1.45: +77 -27 lines
...

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 void gufld_(float*, float*);
18 float risxeta2_(float *);
19 float risxeta3_(float *);
20 float risxeta4_(float *);
21 float risyeta2_(float *);
22 }
23
24 //--------------------------------------
25 //
26 //
27 //--------------------------------------
28 TrkTrack::TrkTrack(){
29 // cout << "TrkTrack::TrkTrack()" << endl;
30 seqno = -1;
31 image = -1;
32 chi2 = 0;
33 nstep = 0;
34 for(int it1=0;it1<5;it1++){
35 al[it1] = 0;
36 for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
37 };
38 for(int ip=0;ip<6;ip++){
39 xgood[ip] = 0;
40 ygood[ip] = 0;
41 xm[ip] = 0;
42 ym[ip] = 0;
43 zm[ip] = 0;
44 resx[ip] = 0;
45 resy[ip] = 0;
46 tailx[ip] = 0;
47 taily[ip] = 0;
48 xv[ip] = 0;
49 yv[ip] = 0;
50 zv[ip] = 0;
51 axv[ip] = 0;
52 ayv[ip] = 0;
53 dedx_x[ip] = 0;
54 dedx_y[ip] = 0;
55 multmaxx[ip] = 0;
56 multmaxy[ip] = 0;
57 seedx[ip] = 0;
58 seedy[ip] = 0;
59 xpu[ip] = 0;
60 ypu[ip] = 0;
61
62 };
63
64 // TrkParams::SetTrackingMode();
65 // TrkParams::SetPrecisionFactor();
66 // TrkParams::SetStepMin();
67 TrkParams::SetMiniDefault();
68 TrkParams::SetPFA();
69
70 int ngf = TrkParams::nGF;
71 for(int i=0; i<ngf; i++){
72 xGF[i] = 0.;
73 yGF[i] = 0.;
74 }
75
76
77 };
78 //--------------------------------------
79 //
80 //
81 //--------------------------------------
82 TrkTrack::TrkTrack(const TrkTrack& t){
83 seqno = t.seqno;
84 image = t.image;
85 chi2 = t.chi2;
86 nstep = t.nstep;
87 for(int it1=0;it1<5;it1++){
88 al[it1] = t.al[it1];
89 for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
90 };
91 for(int ip=0;ip<6;ip++){
92 xgood[ip] = t.xgood[ip];
93 ygood[ip] = t.ygood[ip];
94 xm[ip] = t.xm[ip];
95 ym[ip] = t.ym[ip];
96 zm[ip] = t.zm[ip];
97 resx[ip] = t.resx[ip];
98 resy[ip] = t.resy[ip];
99 tailx[ip] = t.tailx[ip];
100 taily[ip] = t.taily[ip];
101 xv[ip] = t.xv[ip];
102 yv[ip] = t.yv[ip];
103 zv[ip] = t.zv[ip];
104 axv[ip] = t.axv[ip];
105 ayv[ip] = t.ayv[ip];
106 dedx_x[ip] = t.dedx_x[ip];
107 dedx_y[ip] = t.dedx_y[ip];
108 multmaxx[ip] = t.multmaxx[ip];
109 multmaxy[ip] = t.multmaxy[ip];
110 seedx[ip] = t.seedx[ip];
111 seedy[ip] = t.seedy[ip];
112 xpu[ip] = t.xpu[ip];
113 ypu[ip] = t.ypu[ip];
114 };
115
116 // TrkParams::SetTrackingMode();
117 // TrkParams::SetPrecisionFactor();
118 // TrkParams::SetStepMin();
119 TrkParams::SetMiniDefault();
120 TrkParams::SetPFA();
121
122 int ngf = TrkParams::nGF;
123 for(int i=0; i<ngf; i++){
124 xGF[i] = t.xGF[i];
125 yGF[i] = t.yGF[i];
126 }
127 };
128 //--------------------------------------
129 //
130 //
131 //--------------------------------------
132 void TrkTrack::Copy(TrkTrack& t){
133
134 t.seqno = seqno;
135 t.image = image;
136 t.chi2 = chi2;
137 t.nstep = nstep;
138 for(int it1=0;it1<5;it1++){
139 t.al[it1] = al[it1];
140 for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2];
141 };
142 for(int ip=0;ip<6;ip++){
143 t.xgood[ip] = xgood[ip];
144 t.ygood[ip] = ygood[ip];
145 t.xm[ip] = xm[ip];
146 t.ym[ip] = ym[ip];
147 t.zm[ip] = zm[ip];
148 t.resx[ip] = resx[ip];
149 t.resy[ip] = resy[ip];
150 t.tailx[ip] = tailx[ip];
151 t.taily[ip] = taily[ip];
152 t.xv[ip] = xv[ip];
153 t.yv[ip] = yv[ip];
154 t.zv[ip] = zv[ip];
155 t.axv[ip] = axv[ip];
156 t.ayv[ip] = ayv[ip];
157 t.dedx_x[ip] = dedx_x[ip];
158 t.dedx_y[ip] = dedx_y[ip];
159 t.multmaxx[ip] = multmaxx[ip];
160 t.multmaxy[ip] = multmaxy[ip];
161 t.seedx[ip] = seedx[ip];
162 t.seedy[ip] = seedy[ip];
163 t.xpu[ip] = xpu[ip];
164 t.ypu[ip] = ypu[ip];
165
166 };
167 int ngf = TrkParams::nGF;
168 for(int i=0; i<ngf; i++){
169 t.xGF[i] = xGF[i];
170 t.yGF[i] = yGF[i];
171 }
172
173
174 };
175 //--------------------------------------
176 //
177 //
178 //--------------------------------------
179 /**
180 * Evaluates the trajectory in the apparatus associated to the track.
181 * 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.
182 * @param t pointer to an object of the class Trajectory,
183 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
184 * @return error flag.
185 *
186 * >>> OBSOLETE !!! use TrkTrack::DoTrack2(Trajectory* t) instead
187 *
188 */
189 int TrkTrack::DoTrack(Trajectory* t){
190
191 cout << " int TrkTrack::DoTrack(Trajectory* t) --->> OBSOLETE !!! "<<endl;
192 cout << " use int TrkTrack::DoTrack2(Trajectory* t)"<<endl;
193
194 double *dxout = new double[t->npoint];
195 double *dyout = new double[t->npoint];
196 double *dzin = new double[t->npoint];
197 double dal[5];
198
199 int ifail = 0;
200
201 for (int i=0; i<5; i++) dal[i] = (double)al[i];
202 for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
203
204 TrkParams::Load(1);
205 if( !TrkParams::IsLoaded(1) ){
206 cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
207 return 0;
208 }
209 dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);
210
211 for (int i=0; i<t->npoint; i++){
212 t->x[i] = (float)*(dxout+i);
213 t->y[i] = (float)*(dyout+i);
214 }
215
216 delete [] dxout;
217 delete [] dyout;
218 delete [] dzin;
219
220 return ifail;
221 };
222 //--------------------------------------
223 //
224 //
225 //--------------------------------------
226 /**
227 * Evaluates the trajectory in the apparatus associated to the track.
228 * 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.
229 * @param t pointer to an object of the class Trajectory,
230 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
231 * @return error flag.
232 */
233 int TrkTrack::DoTrack2(Trajectory* t){
234
235 double *dxout = new double[t->npoint];
236 double *dyout = new double[t->npoint];
237 double *dthxout = new double[t->npoint];
238 double *dthyout = new double[t->npoint];
239 double *dtlout = new double[t->npoint];
240 double *dzin = new double[t->npoint];
241 double dal[5];
242
243 int ifail = 0;
244
245 for (int i=0; i<5; i++) dal[i] = (double)al[i];
246 for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
247
248 TrkParams::Load(1);
249 if( !TrkParams::IsLoaded(1) ){
250 cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
251 return 0;
252 }
253 dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
254
255 for (int i=0; i<t->npoint; i++){
256 t->x[i] = (float)*(dxout+i);
257 t->y[i] = (float)*(dyout+i);
258 t->thx[i] = (float)*(dthxout+i);
259 t->thy[i] = (float)*(dthyout+i);
260 t->tl[i] = (float)*(dtlout+i);
261 }
262
263 delete [] dxout;
264 delete [] dyout;
265 delete [] dzin;
266 delete [] dthxout;
267 delete [] dthyout;
268 delete [] dtlout;
269
270 return ifail;
271 };
272 //--------------------------------------
273 //
274 //
275 //--------------------------------------
276 //float TrkTrack::BdL(){
277 //};
278 //--------------------------------------
279 //
280 //
281 //--------------------------------------
282 Float_t TrkTrack::GetRigidity(){
283 Float_t rig=0;
284 if(chi2>0)rig=1./al[4];
285 if(rig<0) rig=-rig;
286 return rig;
287 };
288 //
289 Float_t TrkTrack::GetDeflection(){
290 Float_t def=0;
291 if(chi2>0)def=al[4];
292 return def;
293 };
294 //
295 /**
296 * Method to retrieve the dE/dx measured on a tracker view.
297 * @param ip plane (0-5)
298 * @param iv view (0=x 1=y)
299 */
300 Float_t TrkTrack::GetDEDX(int ip, int iv){
301 if(iv==0 && ip>=0 && ip<6)return fabs(dedx_x[ip]);
302 else if(iv==1 && ip>=0 && ip<6)return fabs(dedx_y[ip]);
303 else {
304 cout << "TrkTrack::GetDEDX(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
305 return 0.;
306 }
307 }
308 /**
309 * Method to evaluate the dE/dx measured on a tracker plane.
310 * The two measurements on x- and y-view are averaged.
311 * @param ip plane (0-5)
312 */
313 Float_t TrkTrack::GetDEDX(int ip){
314 if( (Int_t)XGood(ip)+(Int_t)YGood(ip) == 0 ) return 0;
315 return (GetDEDX(ip,0)+GetDEDX(ip,1))/((Int_t)XGood(ip)+(Int_t)YGood(ip));
316 };
317
318 /**
319 * Method to evaluate the dE/dx averaged over all planes.
320 */
321 Float_t TrkTrack::GetDEDX(){
322 Float_t dedx=0;
323 for(Int_t ip=0; ip<6; ip++)dedx+=GetDEDX(ip,0)*XGood(ip)+GetDEDX(ip,1)*YGood(ip);
324 dedx = dedx/(GetNX()+GetNY());
325 return dedx;
326 };
327 /**
328 * Returns 1 if the cluster on a tracker view includes bad strips
329 * (at least one bad strip among the four strip used by p.f.a.)
330 * @param ip plane (0-5)
331 * @param iv view (0=x 1=y)
332 */
333 Bool_t TrkTrack::IsBad(int ip,int iv){
334 if(iv==0 && ip>=0 && ip<6)return (xgood[ip]<0) ;
335 else if(iv==1 && ip>=0 && ip<6)return (ygood[ip]<0) ;
336 else {
337 cout << "TrkTrack::IsBad(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
338 return 0.;
339 }
340 };
341 /**
342 * Returns 1 if the signal on a tracker view is saturated.
343 * @param ip plane (0-5)
344 * @param iv view (0=x 1=y)
345 */
346 Bool_t TrkTrack::IsSaturated(int ip,int iv){
347 if(iv==0 && ip>=0 && ip<6)return (dedx_x[ip]<0) ;
348 else if(iv==1 && ip>=0 && ip<6)return (dedx_y[ip]<0) ;
349 else {
350 cout << "TrkTrack::IsSaturated(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
351 return 0.;
352 }
353 };
354 /**
355 * Returns 1 if either the x or the y signal on a tracker plane is saturated.
356 * @param ip plane (0-5)
357 */
358 Bool_t TrkTrack::IsSaturated(int ip){
359 return (IsSaturated(ip,0)||IsSaturated(ip,1));
360 };
361 /**
362 * Returns 1 if there is at least a saturated signal along the track.
363 */
364 Bool_t TrkTrack::IsSaturated(){
365 for(int ip=0; ip<6; ip++)for(int iv=0; iv<2; iv++)if(IsSaturated(ip,iv))return true;
366 return false;
367 }
368 /**
369 * Returns the track "lever-arm" on the x view, defined as the distance (in planes) between
370 * the upper and lower x measurements (the maximum value of lever-arm is 6).
371 */
372 Int_t TrkTrack::GetLeverArmX(){
373 int first_plane = -1;
374 int last_plane = -1;
375 for(Int_t ip=0; ip<6; ip++){
376 if( XGood(ip) && first_plane == -1 )first_plane = ip;
377 if( XGood(ip) && first_plane != -1 )last_plane = ip;
378 }
379 if( first_plane == -1 || last_plane == -1){
380 cout<< "Int_t TrkTrack::GetLeverArmX() -- XGood(ip) always false ??? "<<endl;
381 return 0;
382 }
383 return (last_plane-first_plane+1);
384 }
385 /**
386 * Returns the track "lever-arm" on the y view, defined as the distance (in planes) between
387 * the upper and lower y measurements (the maximum value of lever-arm is 6).
388 */
389 Int_t TrkTrack::GetLeverArmY(){
390 int first_plane = -1;
391 int last_plane = -1;
392 for(Int_t ip=0; ip<6; ip++){
393 if( YGood(ip) && first_plane == -1 )first_plane = ip;
394 if( YGood(ip) && first_plane != -1 )last_plane = ip;
395 }
396 if( first_plane == -1 || last_plane == -1){
397 cout<< "Int_t TrkTrack::GetLeverArmY() -- YGood(ip) always false ??? "<<endl;
398 return 0;
399 }
400 return (last_plane-first_plane+1);
401 }
402 /**
403 * Returns the reduced chi-square of track x-projection
404 */
405 Float_t TrkTrack::GetChi2X(){
406 float chiq=0;
407 for(int ip=0; ip<6; ip++)if(XGood(ip))chiq+= pow((xv[ip]-xm[ip])/resx[ip],2.);
408 if(GetNX()>3)chiq=chiq/(GetNX()-3);
409 else chiq=0;
410 if(chiq==0)cout << " Float_t TrkTrack::GetChi2X() -- WARNING -- value not defined "<<chiq<<endl;
411 return chiq;
412 }
413 /**
414 * Returns the reduced chi-square of track y-projection
415 */
416 Float_t TrkTrack::GetChi2Y(){
417 float chiq=0;
418 for(int ip=0; ip<6; ip++)if(YGood(ip))chiq+= pow((yv[ip]-ym[ip])/resy[ip],2.);
419 if(GetNY()>2)chiq=chiq/(GetNY()-2);
420 else chiq=0;
421 if(chiq==0)cout << " Float_t TrkTrack::GetChi2Y() -- WARNING -- value not defined "<<chiq<<endl;
422 return chiq;
423 }
424 /**
425 * Returns the logarythm of the likeliwood-function of track x-projection
426 */
427 Float_t TrkTrack::GetLnLX(){
428 float lnl=0;
429 for(int ip=0; ip<6; ip++)
430 if( XGood(ip) && tailx[ip]!=0 )
431 lnl += (tailx[ip]+1.) * log( (tailx[ip]*pow(resx[ip],2.) + pow(xv[ip]-xm[ip],2.)) / (tailx[ip]*pow(resx[ip],2)) );
432 if(GetNX()>3)lnl=lnl/(GetNX()-3);
433 else lnl=0;
434 if(lnl==0){
435 cout << " Float_t TrkTrack::GetLnLX() -- WARNING -- value not defined "<<lnl<<endl;
436 Dump();
437 }
438 return lnl;
439
440 }
441 /**
442 * Returns the logarythm of the likeliwood-function of track y-projection
443 */
444 Float_t TrkTrack::GetLnLY(){
445 float lnl=0;
446 for(int ip=0; ip<6; ip++)
447 if( YGood(ip) && taily[ip]!=0 )
448 lnl += (taily[ip]+1.) * log( (taily[ip]*pow(resy[ip],2.) + pow(yv[ip]-ym[ip],2.)) / (taily[ip]*pow(resy[ip],2)) );
449 if(GetNY()>2)lnl=lnl/(GetNY()-2);
450 else lnl=0;
451 if(lnl==0){
452 cout << " Float_t TrkTrack::GetLnLY() -- WARNING -- value not defined "<<lnl<<endl;
453 Dump();
454 }
455 return lnl;
456
457 }
458 /**
459 * Returns the effective angle, relative to the sensor, on each plane.
460 * @param ip plane (0-5)
461 * @param iv view (0=x 1=y)
462 */
463 Float_t TrkTrack::GetEffectiveAngle(int ip, int iv){
464
465 if(ip<0 || ip>5){
466 cout << "Float_t TrkTrack::GetEffectiveAngle(int "<<ip<<", int "<<iv<<") ==> wrong input"<<endl;
467 return 0.;
468 }
469
470 float v[3]={xv[ip],yv[ip],zv[ip]};
471 //-----------------------------------------
472 // effective angle (relative to the sensor)
473 //-----------------------------------------
474 float axv_geo = axv[ip];
475 float muhall_h = 297.61; //cm**2/Vs
476 float BY = TrkParams::GetBY(v);
477 float axv_eff = 0;
478 if(ip==5) axv_geo = -1*axv_geo;
479 if(ip==5) BY = -1*BY;
480 axv_eff = 180.*atan( tan(axv_geo*acos(-1.)/180.) + muhall_h * BY * 0.0001)/acos(-1.);
481 //-----------------------------------------
482 // effective angle (relative to the sensor)
483 //-----------------------------------------
484 float ayv_geo = ayv[ip];
485 float muhall_e = 1258.18; //cm**2/Vs
486 float BX = TrkParams::GetBX(v);
487 float ayv_eff = 0;
488 ayv_eff = 180.*atan( tan(ayv_geo*acos(-1.)/180.) + muhall_e * BX * 0.0001)/acos(-1.);
489
490 if (iv==0)return axv_eff;
491 else if(iv==1)return ayv_eff;
492 else{
493 cout << "Float_t TrkTrack::GetEffectiveAngle(int "<<ip<<", int "<<iv<<") ==> wrong input"<<endl;
494 return 0.;
495 }
496
497 };
498
499 //--------------------------------------
500 //
501 //
502 //--------------------------------------
503 void TrkTrack::Dump(){
504 cout << endl << "========== Track " ;
505 cout << endl << "seq. n. : "<< seqno;
506 cout << endl << "image n. : "<< image;
507 cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " ";
508 cout << endl << "chi^2 : "<< chi2;
509 cout << endl << "n.step : "<< nstep;
510 cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << XGood(i) ;
511 cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << YGood(i) ;
512 cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " ";
513 cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " ";
514 cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " ";
515 cout << endl << "xv : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
516 cout << endl << "yv : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
517 cout << endl << "zv : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
518 cout << endl << "resx : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
519 cout << endl << "resy : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
520 cout << endl << "tailx : "; for(int i=0; i<6; i++)cout << tailx[i] << " ";
521 cout << endl << "taily : "; for(int i=0; i<6; i++)cout << taily[i] << " ";
522 cout << endl << "coval : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
523 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
524 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
525 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
526 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
527 cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";
528 cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";
529 cout << endl << "maxs x : "; for(int i=0; i<6; i++)cout << GetClusterX_MaxStrip(i) << " ";
530 cout << endl << "maxs y : "; for(int i=0; i<6; i++)cout << GetClusterY_MaxStrip(i) << " ";
531 cout << endl << "mult x : "; for(int i=0; i<6; i++)cout << GetClusterX_Multiplicity(i) << " ";
532 cout << endl << "mult y : "; for(int i=0; i<6; i++)cout << GetClusterY_Multiplicity(i) << " ";
533 cout << endl << "seed x : "; for(int i=0; i<6; i++)cout << GetClusterX_Seed(i) << " ";
534 cout << endl << "seed y : "; for(int i=0; i<6; i++)cout << GetClusterY_Seed(i) << " ";
535 cout << endl << "xpu : "; for(int i=0; i<6; i++)cout << xpu[i] << " ";
536 cout << endl << "ypu : "; for(int i=0; i<6; i++)cout << ypu[i] << " ";
537
538 cout << endl;
539 }
540 /**
541 * Set the TrkTrack position measurements
542 */
543 void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
544 for(int i=0; i<6; i++) xm[i]=*xmeas++;
545 for(int i=0; i<6; i++) ym[i]=*ymeas++;
546 for(int i=0; i<6; i++) zm[i]=*zmeas++;
547 }
548 /**
549 * Set the TrkTrack position resolution
550 */
551 void TrkTrack::SetResolution(double *rx, double *ry){
552 for(int i=0; i<6; i++) resx[i]=*rx++;
553 for(int i=0; i<6; i++) resy[i]=*ry++;
554 }
555 /**
556 * Set the TrkTrack tails position resolution
557 */
558 void TrkTrack::SetTail(double *tx, double *ty, double factor){
559 for(int i=0; i<6; i++) tailx[i]=factor*(*tx++);
560 for(int i=0; i<6; i++) taily[i]=factor*(*ty++);
561 }
562 /**
563 * Set the TrkTrack Student parameter (resx,resy,tailx,taily)
564 * from previous gausian fit
565 *@param flag =0 standard, =1 with noise correction
566 */
567 void TrkTrack::SetStudentParam(int flag){
568 float sx[11]={0.000128242,
569 0.000136942,
570 0.000162718,
571 0.000202644,
572 0.00025597,
573 0.000317456,
574 0.000349048,
575 0.000384638,
576 0.000457295,
577 0.000512319,
578 0.000538573};
579 float tx[11]={1.79402,
580 2.04876,
581 2.88376,
582 3.3,
583 3.14084,
584 4.07686,
585 4.44736,
586 3.5179,
587 3.38697,
588 3.45739,
589 3.18627};
590 float sy[11]={0.000483075,
591 0.000466925,
592 0.000431658,
593 0.000428317,
594 0.000433854,
595 0.000444044,
596 0.000482098,
597 0.000537579,
598 0.000636279,
599 0.000741998,
600 0.000864261};
601 float ty[11]={0.997032,
602 1.11147,
603 1.18526,
604 1.61404,
605 2.21908,
606 3.08959,
607 4.48833,
608 4.42687,
609 4.65253,
610 4.52043,
611 4.29926};
612 int index;
613 float fact;
614 for(int i=0; i<6; i++) {
615 index = int((fabs(axv[i])+1.)/2.);
616 if(index>10) index=10;
617 tailx[i]=tx[index];
618 if(flag==1) {
619 if(fabs(axv[i])<=10.) fact = resx[i]/risxeta2_(&(axv[i]));
620 if(fabs(axv[i])>10.&&fabs(axv[i])<=15.) fact = resx[i]/risxeta3_(&(axv[i]));
621 if(fabs(axv[i])>15.) fact = resx[i]/risxeta4_(&(axv[i]));
622 } else fact = 1.;
623 resx[i] = sx[index]*fact;
624 }
625 for(int i=0; i<6; i++) {
626 index = int((fabs(ayv[i])+1.)/2.);
627 if(index>10) index=10;
628 taily[i]=ty[index];
629 if(flag==1) fact = resy[i]/risyeta2_(&(ayv[i]));
630 else fact = 1.;
631 resy[i] = sy[index]*fact;
632 }
633 }
634 /**
635 * Set the TrkTrack good measurement
636 */
637 void TrkTrack::SetGood(int *xg, int *yg){
638
639 for(int i=0; i<6; i++) xgood[i]=*xg++;
640 for(int i=0; i<6; i++) ygood[i]=*yg++;
641 }
642
643 /**
644 * Load the magnetic field
645 */
646 void TrkTrack::LoadField(TString path){
647
648 // strcpy(path_.path,path.Data());
649 // path_.pathlen = path.Length();
650 // path_.error = 0;
651 // readb_();
652
653 // TrkParams::SetTrackingMode();
654 // TrkParams::SetPrecisionFactor();
655 // TrkParams::SetStepMin();
656 TrkParams::SetMiniDefault();
657
658 TrkParams::Set(path,1);
659 TrkParams::Load(1);
660
661 };
662
663
664 /**
665 * Method to fill minimization-routine common
666 */
667 void TrkTrack::FillMiniStruct(cMini2track& track){
668
669 for(int i=0; i<6; i++){
670
671 // cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl;
672 // cout << i<<" - "<<ygood[i]<<" "<<YGood(i)<<endl;
673 track.xgood[i]=XGood(i);
674 track.ygood[i]=YGood(i);
675
676 track.xm[i]=xm[i];
677 track.ym[i]=ym[i];
678 track.zm[i]=zm[i];
679
680 // --- temporaneo ----------------------------
681 // float segment = 100.;
682 // track.xm_a[i]=xm[i];
683 // track.xm_b[i]=xm[i];
684 // track.ym_a[i]=ym[i];
685 // track.ym_b[i]=ym[i];
686 // if( XGood(i) && !YGood(i) ){
687 // track.ym_a[i] = track.ym_a[i]+segment;
688 // track.ym_b[i] = track.ym_b[i]-segment;
689 // }else if( !XGood(i) && YGood(i)){
690 // track.xm_a[i] = track.xm_a[i]+segment;
691 // track.xm_b[i] = track.xm_b[i]-segment;
692 // }
693 // --- temporaneo ----------------------------
694
695 if( XGood(i) || YGood(i) ){
696 double segment = 2.;//cm
697 // NB: i parametri di allineamento hanno una notazione particolare!!!
698 // sensor = 0 (hybrid side), 1
699 // ladder = 0-2 (increasing x)
700 // plane = 0-5 (from bottom to top!!!)
701 int is = (int)GetSensor(i); if(i==5)is=1-is;
702 int ip = 5-i;
703 int il = (int)GetLadder(i);
704
705 double omega = 0.;
706 double beta = 0.;
707 double gamma = 0.;
708 if(
709 (is < 0 || is > 1 || ip < 0 || ip > 5 || il < 0 || il > 2) &&
710 true){
711 // se il piano risulta colpito, ladder e sensore devono essere
712 // assegnati correttamente
713 cout << " void TrkTrack::FillMiniStruct(cMini2track&) --- WARNING --- sensor not defined, cannot read alignment parameters "<<endl;
714 cout << " is ip il = "<<is<<" "<<ip<<" "<<il<<endl;
715 }else{
716 omega = alignparameters_.omega[is][il][ip];
717 beta = alignparameters_.beta[is][il][ip];
718 gamma = alignparameters_.gamma[is][il][ip];
719 }
720
721 if( XGood(i) && !YGood(i) ){
722 track.xm_a[i] = xm[i] - omega * segment;
723 track.ym_a[i] = ym[i] + segment;
724 // track.zm_a[i] = zm[i] + beta * segment;//not used yet
725 track.xm_b[i] = xm[i] + omega * segment;
726 track.ym_b[i] = ym[i] - segment;
727 // track.zm_b[i] = zm[i] - beta * segment;//not used yet
728 }else if( !XGood(i) && YGood(i) ){
729 track.xm_a[i] = xm[i] + segment;
730 track.ym_a[i] = ym[i] + omega * segment;
731 // track.zm_a[i] = zm[i] - gamma * segment;//not used yet
732 track.xm_b[i] = xm[i] - segment;
733 track.ym_b[i] = ym[i] - omega * segment;
734 // track.zm_b[i] = zm[i] + gamma * segment;//not used yet
735 }
736 }
737
738 track.resx[i]=resx[i];
739 track.resy[i]=resy[i];
740 track.tailx[i]=tailx[i];
741 track.taily[i]=taily[i];
742 }
743
744 for(int i=0; i<5; i++) track.al[i]=al[i];
745 track.zini = 23.5;
746 // ZINI = 23.5 !!! it should be the same parameter in all codes
747
748 }
749 /**
750 * Method to set values from minimization-routine common
751 */
752 void TrkTrack::SetFromMiniStruct(cMini2track *track){
753
754 for(int i=0; i<5; i++) {
755 al[i]=track->al[i];
756 for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j];
757 }
758 chi2 = track->chi2;
759 nstep = track->nstep;
760 for(int i=0; i<6; i++){
761 xv[i] = track->xv[i];
762 yv[i] = track->yv[i];
763 zv[i] = track->zv[i];
764 xm[i] = track->xm[i];
765 ym[i] = track->ym[i];
766 zm[i] = track->zm[i];
767 axv[i] = track->axv[i];
768 ayv[i] = track->ayv[i];
769 }
770
771 }
772 /**
773 * \brief Method to re-evaluate coordinates of clusters associated with a track.
774 *
775 * The method can be applied only after recovering level1 information
776 * (either by reprocessing single events from level0 or from
777 * the TrkLevel1 branch, if present); it calls F77 subroutines that
778 * read the level1 common and fill the minimization-routine common.
779 * Some clusters can be excluded or added by means of the methods:
780 *
781 * TrkTrack::ResetXGood(int ip)
782 * TrkTrack::ResetYGood(int ip)
783 * TrkTrack::SetXGood(int ip, int cid, int is)
784 * TrkTrack::SetYGood(int ip, int cid, int is)
785 *
786 * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1)
787 * for the minimization-routine common. It deletes the cluster information
788 * (at least for the moment...) thus cannot be applied before
789 * TrkTrack::EvaluateClusterPositions().
790 *
791 * Different p.f.a. can be applied by calling (once) the method:
792 *
793 * TrkParams::SetPFA(0); //Set ETA p.f.a.
794 *
795 * @see TrkParams::SetPFA(int)
796 */
797 Bool_t TrkTrack::EvaluateClusterPositions(){
798
799 // cout << "void TrkTrack::GetClusterositions() "<<endl;
800
801 TrkParams::Load( );
802 if( !TrkParams::IsLoaded() )return false;
803
804 for(int ip=0; ip<6; ip++){
805 // cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;
806 int icx = GetClusterX_ID(ip)+1;
807 int icy = GetClusterY_ID(ip)+1;
808 int sensor = GetSensor(ip)+1;//<< convenzione "Paolo"
809 if(ip==5 && sensor!=0)sensor=3-sensor;//<< convenzione "Elena"
810 int ladder = GetLadder(ip)+1;
811 float ax = axv[ip];
812 float ay = ayv[ip];
813 float v[3];
814 v[0]=xv[ip];
815 v[1]=yv[ip];
816 v[2]=zv[ip];
817 float bfx = 10*TrkParams::GetBX(v);//Tesla
818 float bfy = 10*TrkParams::GetBY(v);//Tesla
819 int ipp=ip+1;
820 xyzpam_(&ipp,&icx,&icy,&ladder,&sensor,&ax,&ay,&bfx,&bfy);
821 if(icx<0 || icy<0)return false;
822 }
823 return true;
824 }
825 /**
826 * \brief Tracking method. It calls F77 mini routine.
827 *
828 * @param pfixed Particle momentum. If pfixed=0 the momentum
829 * is left as a free parameter, otherwise it is fixed to the input value.
830 * @param fail Output flag (!=0 if the fit failed).
831 * @param iprint Flag to set debug mode ( 0 = no output; 1 = verbose; 2 = debug).
832 * @param froml1 Flag to re-evaluate positions (see TrkTrack::GetClusterPositions()).
833 *
834 * The option to re-evaluate positions can be used only after recovering
835 * level1 information, eg. by reprocessing the single event.
836 *
837 * Example:
838 *
839 * if( !event->GetTrkLevel0() )return false;
840 * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1
841 * int fail=0;
842 * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1);
843 *
844 * @see EvaluateClusterPositions()
845 *
846 * The fitting procedure can be varied by changing the tracking mode,
847 * the fit-precision factor, the minimum number of step, etc.
848 * @see SetTrackingMode(int)
849 * @see SetPrecisionFactor(double)
850 * @see SetStepMin(int)
851 * @see SetDeltaB(int,double)
852 */
853 void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
854
855 float al_ini[] = {0.,0.,0.,0.,0.};
856
857 TrkParams::Load( );
858 if( !TrkParams::IsLoaded() )return;
859
860 extern cMini2track track_;
861 fail = 0;
862
863 FillMiniStruct(track_);
864
865 if(froml1!=0){
866 if( !EvaluateClusterPositions() ){
867 cout << "void TrkTrack::Fit("<<pfixed<<","<<fail<<","<<iprint<<","<<froml1<<") --- ERROR evaluating cluster positions "<<endl;
868 FillMiniStruct(track_) ;
869 fail = 1;
870 return;
871 }
872 }else{
873 FillMiniStruct(track_);
874 }
875
876 // if fit variables have been reset, evaluate the initial guess
877 if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
878
879 // --------------------- free momentum
880 if(pfixed==0.) {
881 track_.pfixed=0.;
882 }
883 // --------------------- fixed momentum
884 if(pfixed!=0.) {
885 al[4]=1./pfixed;
886 track_.pfixed=pfixed;
887 }
888
889 // store temporarily the initial guess
890 for(int i=0; i<5; i++) al_ini[i]=track_.al[i];
891
892 // ------------------------------------------
893 // call mini routine
894 // TrkParams::Load(1);
895 // if( !TrkParams::IsLoaded(1) ){
896 // cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl;
897 // return;
898 // }
899 int istep=0;
900 int ifail=0;
901 mini2_(&istep,&ifail, &iprint);
902 if(ifail!=0) {
903 if(iprint)cout << "ERROR: ifail= " << ifail << endl;
904 fail = 1;
905 }
906 // ------------------------------------------
907
908 SetFromMiniStruct(&track_);
909
910 if(fail){
911 if(iprint)cout << " >>>> fit failed "<<endl;
912 for(int i=0; i<5; i++) al[i]=al_ini[i];
913 }
914
915 };
916 /**
917 * Reset the fit parameters
918 */
919 void TrkTrack::FitReset(){
920 for(int i=0; i<5; i++) al[i]=-9999.;
921 chi2=0.;
922 nstep=0;
923 // for(int i=0; i<6; i++) xv[i]=0.;
924 // for(int i=0; i<6; i++) yv[i]=0.;
925 // for(int i=0; i<6; i++) zv[i]=0.;
926 // for(int i=0; i<6; i++) axv[i]=0.;
927 // for(int i=0; i<6; i++) ayv[i]=0.;
928 for(int i=0; i<5; i++) {
929 for(int j=0; j<5; j++) coval[i][j]=0.;
930 }
931 }
932 /**
933 * Set the tracking mode
934 */
935 void TrkTrack::SetTrackingMode(int trackmode){
936 extern cMini2track track_;
937 track_.trackmode = trackmode;
938 }
939 /**
940 * Set the factor scale for tracking precision
941 */
942 void TrkTrack::SetPrecisionFactor(double fact){
943 extern cMini2track track_;
944 track_.fact = fact;
945 }
946 /**
947 * Set the minimum number of steps for tracking precision
948 */
949 void TrkTrack::SetStepMin(int istepmin){
950 extern cMini2track track_;
951 track_.istepmin = istepmin;
952 }
953 /**
954 * Set deltaB parameters (id=0,1). By default they are set to zero.
955 */
956 void TrkTrack::SetDeltaB(int id, double db){
957 if(id!=0 && id!=1)cout << "void TrkTrack::SetDeltaB(int id,double db) -- wrong input parameters: "<<id<<" "<<db<<endl;
958 TrkParams::SetDeltaB(id,db);
959 }
960
961 /**
962 * Returns true if the track is inside the magnet cavity.
963 * @param toll Tolerance around the nominal volume (toll>0 define an inner fiducial volume)
964 */
965 Bool_t TrkTrack::IsInsideCavity(float toll){
966
967 // float xmagntop, ymagntop, xmagnbottom, ymagnbottom;
968 // xmagntop = xv[0] + (ZMAGNHIGH-zv[0])*tan(acos(-1.0)*axv[0]/180.);
969 // ymagntop = yv[0] + (ZMAGNHIGH-zv[0])*tan(acos(-1.0)*ayv[0]/180.);
970 // xmagnbottom = xv[5] + (ZMAGNLOW-zv[5])*tan(acos(-1.0)*axv[5]/180.);
971 // ymagnbottom = yv[5] + (ZMAGNLOW-zv[5])*tan(acos(-1.0)*ayv[5]/180.);
972 // if( xmagntop>XMAGNLOW && xmagntop<XMAGNHIGH &&
973 // ymagntop>YMAGNLOW && ymagntop<YMAGNHIGH &&
974 // xmagnbottom>XMAGNLOW && xmagnbottom<XMAGNHIGH &&
975 // ymagnbottom>YMAGNLOW && ymagnbottom<YMAGNHIGH ) return(true);
976 // else return(false);
977
978 int ngf = TrkParams::nGF;
979 for(int i=0; i<ngf; i++){
980 //
981 // cout << endl << TrkParams::GF_element[i];
982 if(
983 TrkParams::GF_element[i].CompareTo("CUF") &&
984 TrkParams::GF_element[i].CompareTo("T2") &&
985 TrkParams::GF_element[i].CompareTo("T3") &&
986 TrkParams::GF_element[i].CompareTo("T4") &&
987 TrkParams::GF_element[i].CompareTo("T5") &&
988 TrkParams::GF_element[i].CompareTo("CLF") &&
989 true)continue;
990 // apply condition only within the cavity
991 // cout << " -- "<<xGF[i]<<" "<<yGF[i];
992 if(
993 xGF[i] <= TrkParams::xGF_min[i] + toll ||
994 xGF[i] >= TrkParams::xGF_max[i] - toll ||
995 yGF[i] <= TrkParams::yGF_min[i] + toll ||
996 yGF[i] >= TrkParams::yGF_max[i] - toll ||
997 false){
998
999 return false;
1000 }
1001 }
1002 return true;
1003
1004
1005 }
1006 /**
1007 * Returns true if the track is inside the nominal acceptance, which is defined
1008 * by the intersection among magnet cavity, silicon-plane sensitive area and
1009 * ToF sensitive area (nominal values from the official document used to
1010 * calculate the geometrical factor)
1011 */
1012 Bool_t TrkTrack::IsInsideAcceptance(){
1013
1014 int ngf = TrkParams::nGF;
1015 for(int i=0; i<ngf; i++){
1016 if(
1017 xGF[i] <= TrkParams::xGF_min[i] ||
1018 xGF[i] >= TrkParams::xGF_max[i] ||
1019 yGF[i] <= TrkParams::yGF_min[i] ||
1020 yGF[i] >= TrkParams::yGF_max[i] ||
1021 false)return false;
1022 }
1023 return true;
1024
1025 }
1026 /**
1027 * Method to retrieve ID (0,1,...) of x-cluster (if any) associated to this track.
1028 * If no cluster is associated, ID=-1.
1029 * @param ip Tracker plane (0-5)
1030 */
1031 Int_t TrkTrack::GetClusterX_ID(int ip){
1032 return ((Int_t)fabs(xgood[ip]))%10000000-1;
1033 };
1034 /**
1035 * Method to retrieve ID (0-xxx) of y-cluster (if any) associated to this track.
1036 * If no cluster is associated, ID=-1.
1037 * @param ip Tracker plane (0-5)
1038 */
1039 Int_t TrkTrack::GetClusterY_ID(int ip){
1040 return ((Int_t)fabs(ygood[ip]))%10000000-1;
1041 };
1042
1043 /**
1044 * Method to retrieve the ladder (0-2, increasing x) traversed by the track on this plane.
1045 * If no ladder is traversed (dead area) the metod retuns -1.
1046 * @param ip Tracker plane (0-5)
1047 */
1048 Int_t TrkTrack::GetLadder(int ip){
1049 if(XGood(ip))return (Int_t)fabs(xgood[ip]/100000000)-1;
1050 if(YGood(ip))return (Int_t)fabs(ygood[ip]/100000000)-1;
1051 return -1;
1052 };
1053 /**
1054 * Method to retrieve the sensor (0-1, increasing y) traversed by the track on this plane.
1055 * If no sensor is traversed (dead area) the metod retuns -1.
1056 * @param ip Tracker plane (0-5)
1057 */
1058 Int_t TrkTrack::GetSensor(int ip){
1059 if(XGood(ip))return (Int_t)((Int_t)fabs(xgood[ip]/10000000)%10)-1;
1060 if(YGood(ip))return (Int_t)((Int_t)fabs(ygood[ip]/10000000)%10)-1;
1061 return -1;
1062 };
1063
1064 /**
1065 * \brief Method to include a x-cluster to the track.
1066 * @param ip Tracker plane (0-5)
1067 * @param clid Cluster ID (0 = no-cluster, 1,2,... otherwise )
1068 * @param il Ladder (0-2, increasing x, -1 if no sensitive area is hit)
1069 * @param is Sensor (0-1, increasing y, -1 if no sensitive area is hit)
1070 * @param bad True if the cluster contains bad strips
1071 * @see Fit(double pfixed, int& fail, int iprint, int froml1)
1072 */
1073 void TrkTrack::SetXGood(int ip, int clid, int il, int is, bool bad){
1074 // int il=0; //ladder (temporary)
1075 // bool bad=false; //ladder (temporary)
1076 if(ip<0||ip>5||clid<0||il<-1||il>2||is<-1||is>1)
1077 cout << " void TrkTrack::SetXGood(int,int,int,int,bool) --> MA SEI DI COCCIO?!?!"<<endl;
1078 xgood[ip]=(il+1)*100000000+(is+1)*10000000+clid;
1079 if(bad)xgood[ip]=-xgood[ip];
1080 };
1081 /**
1082 * \brief Method to include a y-cluster to the track.
1083 * @param ip Tracker plane (0-5)
1084 * @param clid Cluster ID (0 = no-cluster, 1,2,... otherwise )
1085 * @param il Ladder (0-2, increasing x, -1 if no sensitive area is hit)
1086 * @param is Sensor (0-1, increasing y, -1 if no sensitive area is hit)
1087 * @param bad True if the cluster contains bad strips
1088 * @see Fit(double pfixed, int& fail, int iprint, int froml1)
1089 */
1090 void TrkTrack::SetYGood(int ip, int clid, int il, int is, bool bad){
1091 // int il=0; //ladder (temporary)
1092 // bool bad=false; //ladder (temporary)
1093 if(ip<0||ip>5||clid<0||il<-1||il>2||is<-1||is>1)
1094 cout << " void TrkTrack::SetYGood(int,int,int,int,bool) --> MA SEI DI COCCIO?!?!"<<endl;
1095 ygood[ip]=(il+1)*100000000+(is+1)*10000000+clid;
1096 if(bad)ygood[ip]=-ygood[ip];
1097 };
1098
1099 /**
1100 * \brief Average X
1101 * Average value of <xv>, evaluated from the first to the last hit x view.
1102 */
1103 Float_t TrkTrack::GetXav(){
1104
1105 int first_plane = -1;
1106 int last_plane = -1;
1107 for(Int_t ip=0; ip<6; ip++){
1108 if( XGood(ip) && first_plane == -1 )first_plane = ip;
1109 if( XGood(ip) && first_plane != -1 )last_plane = ip;
1110 }
1111 if( first_plane == -1 || last_plane == -1){
1112 return -100;
1113 }
1114 if( last_plane-first_plane+1 ==0 )return -100;
1115
1116 Float_t av = 0;
1117 for(int ip=first_plane; ip<=last_plane; ip++)av+=xv[ip];
1118
1119 return (av/(last_plane-first_plane+1));
1120 }
1121 /**
1122 * \brief Average Y
1123 * Average value of <yv>, evaluated from the first to the last hit x view.
1124 */
1125 Float_t TrkTrack::GetYav(){
1126
1127 int first_plane = -1;
1128 int last_plane = -1;
1129 for(Int_t ip=0; ip<6; ip++){
1130 if( XGood(ip) && first_plane == -1 )first_plane = ip;
1131 if( XGood(ip) && first_plane != -1 )last_plane = ip;
1132 }
1133 if( first_plane == -1 || last_plane == -1){
1134 return -100;
1135 }
1136 if( last_plane-first_plane+1 ==0 )return -100;
1137
1138 Float_t av = 0;
1139 for(int ip=first_plane; ip<=last_plane; ip++)av+=yv[ip];
1140
1141 return (av/(last_plane-first_plane+1));
1142 }
1143 /**
1144 * \brief Average Z
1145 * Average value of <zv>, evaluated from the first to the last hit x view.
1146 */
1147 Float_t TrkTrack::GetZav(){
1148
1149 int first_plane = -1;
1150 int last_plane = -1;
1151 for(Int_t ip=0; ip<6; ip++){
1152 if( XGood(ip) && first_plane == -1 )first_plane = ip;
1153 if( XGood(ip) && first_plane != -1 )last_plane = ip;
1154 }
1155 if( first_plane == -1 || last_plane == -1){
1156 return -100;
1157 }
1158 if( last_plane-first_plane+1 ==0 )return -100;
1159
1160 Float_t av = 0;
1161 for(int ip=first_plane; ip<=last_plane; ip++)av+=zv[ip];
1162
1163 return (av/(last_plane-first_plane+1));
1164 }
1165
1166 /**
1167 * \brief Number of column traversed
1168 */
1169 Int_t TrkTrack::GetNColumns(){
1170 int sensors[] = {0,0,0,0,0,0};
1171 for(int ip=0; ip<6; ip++){
1172 int sensorid = GetLadder(ip)+3*GetSensor(ip);
1173 if(XGood(ip)||YGood(ip))
1174 if(sensorid>=0 && sensorid<6)sensors[sensorid]=1;
1175 }
1176 int nsensors=0;
1177 for(int is=0; is<6; is++)nsensors += sensors[is];
1178 return nsensors;
1179 };
1180 /**
1181 * \brief Give the maximum energy release
1182 */
1183 Float_t TrkTrack::GetDEDX_max(int ip, int iv){
1184 Float_t max=0;
1185 int pfrom = 0;
1186 int pto = 6;
1187 int vfrom = 0;
1188 int vto = 2;
1189 if(ip>=0&&ip<6){
1190 pfrom = ip;
1191 pto = ip+1;
1192 }
1193 if(iv>=0&&iv<2){
1194 vfrom = iv;
1195 vto = iv+1;
1196 }
1197 for(int i=pfrom; i<pto; i++)
1198 for(int j=0; j<vto; j++)
1199 if(GetDEDX(i,j)>max)max=GetDEDX(i,j);
1200
1201 return max;
1202
1203 };
1204
1205 /**
1206 * \brief Give the minimum energy release
1207 */
1208 Float_t TrkTrack::GetDEDX_min(int ip, int iv){
1209 Float_t min=100000000;
1210 int pfrom = 0;
1211 int pto = 6;
1212 int vfrom = 0;
1213 int vto = 2;
1214 if(ip>=0&&ip<6){
1215 pfrom = ip;
1216 pto = ip+1;
1217 }
1218 if(iv>=0&&iv<2){
1219 vfrom = iv;
1220 vto = iv+1;
1221 }
1222 for(int i=pfrom; i<pto; i++)
1223 for(int j=0; j<vto; j++)
1224 if(GetDEDX(i,j)<min)min=GetDEDX(i,j);
1225
1226 return min;
1227
1228 };
1229
1230 /**
1231 * \brief Give the maximum spatial residual release
1232 */
1233 Float_t TrkTrack::GetResidual_max(int ip, int iv){
1234 Float_t max=0;
1235 int pfrom = 0;
1236 int pto = 6;
1237 int vfrom = 0;
1238 int vto = 2;
1239 if(ip>=0&&ip<6){
1240 pfrom = ip;
1241 pto = ip+1;
1242 }
1243 if(iv>=0&&iv<2){
1244 vfrom = iv;
1245 vto = iv+1;
1246 }
1247 for(int i=pfrom; i<pto; i++){
1248 for(int j=0; j<vto; j++){
1249 if(j==0 && XGood(i) && fabs(xm[i]-xv[i])>fabs(max))max=xv[i]-xm[i];
1250 if(j==1 && YGood(i) && fabs(ym[i]-yv[i])>fabs(max))max=yv[i]-ym[i];
1251 }
1252 }
1253 return max;
1254
1255 };
1256
1257
1258 /**
1259 * \brief Give the maximum multiplicity on the x view
1260 */
1261 Int_t TrkTrack::GetClusterX_Multiplicity_max(){
1262 int max=0;
1263 for(int ip=0; ip<6; ip++)
1264 if(GetClusterX_Multiplicity(ip)>max)max=GetClusterX_Multiplicity(ip);
1265 return max;
1266 };
1267 /**
1268 * \brief Give the minimum multiplicity on the x view
1269 */
1270 Int_t TrkTrack::GetClusterX_Multiplicity_min(){
1271 int min=50;
1272 for(int ip=0; ip<6; ip++)
1273 if(GetClusterX_Multiplicity(ip)<min)min=GetClusterX_Multiplicity(ip);
1274 return min;
1275 };
1276 /**
1277 * \brief Give the maximum multiplicity on the x view
1278 */
1279 Int_t TrkTrack::GetClusterY_Multiplicity_max(){
1280 int max=0;
1281 for(int ip=0; ip<6; ip++)
1282 if(GetClusterY_Multiplicity(ip)>max)max=GetClusterY_Multiplicity(ip);
1283 return max;
1284 };
1285 /**
1286 * \brief Give the minimum multiplicity on the x view
1287 */
1288 Int_t TrkTrack::GetClusterY_Multiplicity_min(){
1289 int min=50;
1290 for(int ip=0; ip<6; ip++)
1291 if(GetClusterY_Multiplicity(ip)<min)min=GetClusterY_Multiplicity(ip);
1292 return min;
1293 };
1294
1295 /**
1296 * \brief Give the minimum seed on the x view
1297 */
1298 Float_t TrkTrack::GetClusterX_Seed_min(){
1299 Float_t min=100000;
1300 for(int ip=0; ip<6; ip++)
1301 if(XGood(ip) && GetClusterX_Seed(ip)<min)min=GetClusterX_Seed(ip);
1302 return min;
1303 };
1304 /**
1305 * \brief Give the minimum seed on the x view
1306 */
1307 Float_t TrkTrack::GetClusterY_Seed_min(){
1308 Float_t min=100000;
1309 for(int ip=0; ip<6; ip++)
1310 if(YGood(ip) && GetClusterY_Seed(ip)<min)min=GetClusterY_Seed(ip);
1311 return min;
1312 };
1313
1314
1315 //--------------------------------------
1316 //
1317 //
1318 //--------------------------------------
1319 void TrkTrack::Clear(){
1320 // cout << "TrkTrack::Clear()"<<endl;
1321 seqno = -1;
1322 image = -1;
1323 chi2 = 0;
1324 nstep = 0;
1325 for(int it1=0;it1<5;it1++){
1326 al[it1] = 0;
1327 for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
1328 };
1329 for(int ip=0;ip<6;ip++){
1330 xgood[ip] = 0;
1331 ygood[ip] = 0;
1332 xm[ip] = 0;
1333 ym[ip] = 0;
1334 zm[ip] = 0;
1335 resx[ip] = 0;
1336 resy[ip] = 0;
1337 tailx[ip] = 0;
1338 taily[ip] = 0;
1339 xv[ip] = 0;
1340 yv[ip] = 0;
1341 zv[ip] = 0;
1342 axv[ip] = 0;
1343 ayv[ip] = 0;
1344 dedx_x[ip] = 0;
1345 dedx_y[ip] = 0;
1346
1347 };
1348 int ngf = TrkParams::nGF;
1349 for(int i=0; i<ngf; i++){
1350 xGF[i] = 0.;
1351 yGF[i] = 0.;
1352 }
1353 // if(clx)clx->Clear();
1354 // if(cly)cly->Clear();
1355 // clx.Clear();
1356 // cly.Clear();
1357 };
1358 //--------------------------------------
1359 //
1360 //
1361 //--------------------------------------
1362 void TrkTrack::Delete(){
1363 // cout << "TrkTrack::Delete()"<<endl;
1364 Clear();
1365 // if(clx)delete clx;
1366 // if(cly)delete cly;
1367 };
1368 //--------------------------------------
1369 //
1370 //
1371 //--------------------------------------
1372
1373 //--------------------------------------
1374 //
1375 //
1376 //--------------------------------------
1377 TrkSinglet::TrkSinglet(){
1378 // cout << "TrkSinglet::TrkSinglet() " << GetUniqueID()<<endl;
1379 // plane = 0;
1380 // coord[0] = 0;
1381 // coord[1] = 0;
1382 // sgnl = 0;
1383 // multmax = 0;
1384 // cls = 0;
1385 Clear();
1386 };
1387 //--------------------------------------
1388 //
1389 //
1390 //--------------------------------------
1391 TrkSinglet::TrkSinglet(const TrkSinglet& s){
1392 // cout << "TrkSinglet::TrkSinglet(const TrkSinglet& s) " << GetUniqueID()<<endl;
1393 plane = s.plane;
1394 coord[0] = s.coord[0];
1395 coord[1] = s.coord[1];
1396 sgnl = s.sgnl;
1397 multmax = s.multmax;
1398 // cls = 0;//<<<<pointer
1399 // cls = TRef(s.cls);
1400 };
1401 //--------------------------------------
1402 //
1403 //
1404 //--------------------------------------
1405 void TrkSinglet::Dump(){
1406 int i=0;
1407 cout << endl << "========== Singlet " ;
1408 cout << endl << "plane : " << plane;
1409 cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++;
1410 cout << endl << "sgnl : " << sgnl;
1411 cout << endl << "max.strip : ";
1412 cout << endl << "multiplicity : ";
1413 }
1414 //--------------------------------------
1415 //
1416 //
1417 //--------------------------------------
1418 void TrkSinglet::Clear(){
1419 // cout << "TrkSinglet::Clear() " << GetUniqueID()<<endl;
1420 // cls=0;
1421 plane=-1;
1422 coord[0]=-999;
1423 coord[1]=-999;
1424 sgnl=0;
1425 multmax = 0;
1426
1427 }
1428 //--------------------------------------
1429 //
1430 //
1431 //--------------------------------------
1432 TrkLevel2::TrkLevel2(){
1433 // cout <<"TrkLevel2::TrkLevel2()"<<endl;
1434 for(Int_t i=0; i<12 ; i++){
1435 good[i] = -1;
1436 VKmask[i] = 0;
1437 VKflag[i] = 0;
1438 };
1439 Track = 0;
1440 SingletX = 0;
1441 SingletY = 0;
1442
1443 }
1444 //--------------------------------------
1445 //
1446 //
1447 //--------------------------------------
1448 void TrkLevel2::Set(){
1449 if(!Track)Track = new TClonesArray("TrkTrack");
1450 if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1451 if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1452 }
1453 //--------------------------------------
1454 //
1455 //
1456 //--------------------------------------
1457 void TrkLevel2::Dump(){
1458
1459 //
1460 cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
1461 cout << endl << "good : "; for(int i=0; i<12; i++) cout << hex <<" 0x"<< good[i]<<dec;
1462 cout << endl << "ntrk() : " << ntrk() ;
1463 cout << endl << "nclsx() : " << nclsx();
1464 cout << endl << "nclsy() : " << nclsy();
1465 if(Track){
1466 TClonesArray &t = *Track;
1467 for(int i=0; i<ntrk(); i++) ((TrkTrack *)t[i])->Dump();
1468 }
1469 // if(SingletX){
1470 // TClonesArray &sx = *SingletX;
1471 // for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
1472 // }
1473 // if(SingletY){
1474 // TClonesArray &sy = *SingletY;
1475 // for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
1476 // }
1477 cout << endl;
1478 }
1479 /**
1480 * \brief Dump processing status
1481 */
1482 void TrkLevel2::StatusDump(int view){
1483 cout << "DSP n. "<<view+1<<" status: "<<hex<<good[view]<<endl;
1484 };
1485 /**
1486 * \brief Check event status
1487 *
1488 * Check the event status, according to a flag-mask given as input.
1489 * Return true if the view passes the check.
1490 *
1491 * @param view View number (0-11)
1492 * @param flagmask Mask of flags to check (eg. flagmask=0x111 no missing packet,
1493 * no crc error, no software alarm)
1494 *
1495 * @see TrkLevel2 class definition to know how the status flag is defined
1496 *
1497 */
1498 Bool_t TrkLevel2::StatusCheck(int view, int flagmask){
1499
1500 if( view<0 || view >= 12)return false;
1501 return !(good[view]&flagmask);
1502
1503 };
1504
1505
1506 //--------------------------------------
1507 //
1508 //
1509 //--------------------------------------
1510 /**
1511 * The method returns false if the viking-chip was masked
1512 * either apriori ,on the basis of the mask read from the DB,
1513 * or run-by-run, on the basis of the calibration parameters)
1514 * @param iv Tracker view (0-11)
1515 * @param ivk Viking-chip number (0-23)
1516 */
1517 Bool_t TrkLevel2::GetVKMask(int iv, int ivk){
1518 Int_t whichbit = (Int_t)pow(2,ivk);
1519 return (whichbit&VKmask[iv])!=0;
1520 }
1521 /**
1522 * The method returns false if the viking-chip was masked
1523 * for this event due to common-noise computation failure.
1524 * @param iv Tracker view (0-11)
1525 * @param ivk Viking-chip number (0-23)
1526 */
1527 Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){
1528 Int_t whichbit = (Int_t)pow(2,ivk);
1529 return (whichbit&VKflag[iv])!=0;
1530 }
1531 /**
1532 * The method returns true if the viking-chip was masked, either
1533 * forced (see TrkLevel2::GetVKMask(int,int)) or
1534 * for this event only (TrkLevel2::GetVKFlag(int,int)).
1535 * @param iv Tracker view (0-11)
1536 * @param ivk Viking-chip number (0-23)
1537 */
1538 Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){
1539 return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) );
1540 };
1541
1542 //--------------------------------------
1543 //
1544 //
1545 //--------------------------------------
1546 /**
1547 * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
1548 * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set.
1549 * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch)
1550 */
1551 void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
1552
1553 // cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl;
1554 Clear();
1555
1556 // temporary objects:
1557 TrkSinglet* t_singlet = new TrkSinglet();
1558 TrkTrack* t_track = new TrkTrack();
1559
1560 // -----------------
1561 // general variables
1562 // -----------------
1563 for(Int_t i=0; i<12 ; i++){
1564 good[i] = l2->good[i];
1565 VKmask[i]=0;
1566 VKflag[i]=0;
1567 for(Int_t ii=0; ii<24 ; ii++){
1568 Int_t setbit = (Int_t)pow(2,ii);
1569 if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit;
1570 if( l2->vkflag[ii][i]!=0 )VKflag[i]=VKflag[i]|setbit;
1571 };
1572 };
1573 // --------------
1574 // *** TRACKS ***
1575 // --------------
1576 if(!Track) Track = new TClonesArray("TrkTrack");
1577 TClonesArray &t = *Track;
1578
1579 for(int i=0; i<l2->ntrk; i++){
1580 t_track->seqno = i;// NBNBNBNB deve sempre essere = i
1581 t_track->image = l2->image[i]-1;
1582 t_track->chi2 = l2->chi2_nt[i];
1583 t_track->nstep = l2->nstep_nt[i];
1584 for(int it1=0;it1<5;it1++){
1585 t_track->al[it1] = l2->al_nt[i][it1];
1586 for(int it2=0;it2<5;it2++)
1587 t_track->coval[it1][it2] = l2->coval[i][it2][it1];
1588 };
1589 for(int ip=0;ip<6;ip++){
1590 // ---------------------------------
1591 // new implementation of xgood/ygood
1592 // ---------------------------------
1593 t_track->xgood[ip] = l2->cltrx[i][ip]; //cluster ID
1594 t_track->ygood[ip] = l2->cltry[i][ip]; //cluster ID
1595 t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1596 t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1597 if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip];
1598 if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip];
1599 // if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){
1600 // if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){
1601 // cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl;
1602 // cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl;
1603 // cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl;
1604 // cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl;
1605 // cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl;
1606 // }
1607 t_track->xm[ip] = l2->xm_nt[i][ip];
1608 t_track->ym[ip] = l2->ym_nt[i][ip];
1609 t_track->zm[ip] = l2->zm_nt[i][ip];
1610 t_track->resx[ip] = l2->resx_nt[i][ip];
1611 t_track->resy[ip] = l2->resy_nt[i][ip];
1612 t_track->tailx[ip] = l2->tailx[i][ip];
1613 t_track->taily[ip] = l2->taily[i][ip];
1614 t_track->xv[ip] = l2->xv_nt[i][ip];
1615 t_track->yv[ip] = l2->yv_nt[i][ip];
1616 t_track->zv[ip] = l2->zv_nt[i][ip];
1617 t_track->axv[ip] = l2->axv_nt[i][ip];
1618 t_track->ayv[ip] = l2->ayv_nt[i][ip];
1619 t_track->dedx_x[ip] = l2->dedx_x[i][ip];
1620 t_track->dedx_y[ip] = l2->dedx_y[i][ip];
1621 t_track->multmaxx[ip] = l2->multmaxx[i][ip];
1622 t_track->multmaxy[ip] = l2->multmaxy[i][ip];
1623 t_track->seedx[ip] = l2->seedx[i][ip];
1624 t_track->seedy[ip] = l2->seedy[i][ip];
1625 t_track->xpu[ip] = l2->xpu[i][ip];
1626 t_track->ypu[ip] = l2->ypu[i][ip];
1627 //-----------------------------------------------------
1628 //-----------------------------------------------------
1629 //-----------------------------------------------------
1630 //-----------------------------------------------------
1631 };
1632 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1633 // evaluated coordinates (to define GF)
1634 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1635 int ngf = TrkParams::nGF;
1636 float *zgf = TrkParams::zGF;
1637 Trajectory tgf = Trajectory(ngf,zgf);
1638 tgf.DoTrack2(t_track->al);//<<<< integrate the trajectory
1639 for(int ip=0; ip<ngf; ip++){
1640 t_track->xGF[ip] = tgf.x[ip];
1641 t_track->yGF[ip] = tgf.y[ip];
1642 }
1643
1644 // if(t_track->IsSaturated())t_track->Dump();
1645 new(t[i]) TrkTrack(*t_track);
1646 t_track->Clear();
1647 };//end loop over track
1648
1649 // ----------------
1650 // *** SINGLETS ***
1651 // ----------------
1652 if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1653 TClonesArray &sx = *SingletX;
1654 for(int i=0; i<l2->nclsx; i++){
1655 t_singlet->plane = l2->planex[i];
1656 t_singlet->coord[0] = l2->xs[i][0];
1657 t_singlet->coord[1] = l2->xs[i][1];
1658 t_singlet->sgnl = l2->signlxs[i];
1659 t_singlet->multmax = l2->multmaxsx[i];
1660 if(l2->sxbad[i]>0) t_singlet->multmax = -1*t_singlet->multmax;
1661 //-----------------------------------------------------
1662 // if(l1) t_singlet->cls = l1->GetCluster(l2->clsx[i]-1);
1663 //-----------------------------------------------------
1664 new(sx[i]) TrkSinglet(*t_singlet);
1665 t_singlet->Clear();
1666 }
1667 if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1668 TClonesArray &sy = *SingletY;
1669 for(int i=0; i<l2->nclsy; i++){
1670 t_singlet->plane = l2->planey[i];
1671 t_singlet->coord[0] = l2->ys[i][0];
1672 t_singlet->coord[1] = l2->ys[i][1];
1673 t_singlet->sgnl = l2->signlys[i];
1674 t_singlet->multmax = l2->multmaxsy[i];
1675 if(l2->sybad[i]>0) t_singlet->multmax = -1*t_singlet->multmax;
1676 //-----------------------------------------------------
1677 // if(l1) t_singlet->cls = l1->GetCluster(l2->clsy[i]-1);
1678 //-----------------------------------------------------
1679 new(sy[i]) TrkSinglet(*t_singlet);
1680 t_singlet->Clear();
1681 };
1682
1683
1684
1685 delete t_track;
1686 delete t_singlet;
1687 }
1688 /**
1689 * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
1690 */
1691
1692 void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
1693
1694 // general variables
1695 // l2->good2 = good2 ;
1696 for(Int_t i=0; i<12 ; i++){
1697 // l2->crc[i] = crc[i];
1698 l2->good[i] = good[i];
1699 };
1700 // *** TRACKS ***
1701
1702 if(Track){
1703 l2->ntrk = Track->GetEntries();
1704 for(Int_t i=0;i<l2->ntrk;i++){
1705 l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
1706 l2->chi2_nt[i] = ((TrkTrack *)Track->At(i))->chi2;
1707 l2->nstep_nt[i] = ((TrkTrack *)Track->At(i))->nstep;
1708 for(int it1=0;it1<5;it1++){
1709 l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
1710 for(int it2=0;it2<5;it2++)
1711 l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
1712 };
1713 for(int ip=0;ip<6;ip++){
1714 l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip);
1715 l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip);
1716 l2->xm_nt[i][ip] = ((TrkTrack *)Track->At(i))->xm[ip];
1717 l2->ym_nt[i][ip] = ((TrkTrack *)Track->At(i))->ym[ip];
1718 l2->zm_nt[i][ip] = ((TrkTrack *)Track->At(i))->zm[ip];
1719 l2->resx_nt[i][ip] = ((TrkTrack *)Track->At(i))->resx[ip];
1720 l2->resy_nt[i][ip] = ((TrkTrack *)Track->At(i))->resy[ip];
1721 l2->tailx[i][ip] = ((TrkTrack *)Track->At(i))->tailx[ip];
1722 l2->taily[i][ip] = ((TrkTrack *)Track->At(i))->taily[ip];
1723 l2->xv_nt[i][ip] = ((TrkTrack *)Track->At(i))->xv[ip];
1724 l2->yv_nt[i][ip] = ((TrkTrack *)Track->At(i))->yv[ip];
1725 l2->zv_nt[i][ip] = ((TrkTrack *)Track->At(i))->zv[ip];
1726 l2->axv_nt[i][ip] = ((TrkTrack *)Track->At(i))->axv[ip];
1727 l2->ayv_nt[i][ip] = ((TrkTrack *)Track->At(i))->ayv[ip];
1728 l2->dedx_x[i][ip] = ((TrkTrack *)Track->At(i))->dedx_x[ip];
1729 l2->dedx_y[i][ip] = ((TrkTrack *)Track->At(i))->dedx_y[ip];
1730 };
1731 }
1732 }
1733 // *** SINGLETS ***
1734 if(SingletX){
1735 l2->nclsx = SingletX->GetEntries();
1736 for(Int_t i=0;i<l2->nclsx;i++){
1737 l2->planex[i] = ((TrkSinglet *)SingletX->At(i))->plane;
1738 l2->xs[i][0] = ((TrkSinglet *)SingletX->At(i))->coord[0];
1739 l2->xs[i][1] = ((TrkSinglet *)SingletX->At(i))->coord[1];
1740 l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
1741 }
1742 }
1743
1744 if(SingletY){
1745 l2->nclsy = SingletY->GetEntries();
1746 for(Int_t i=0;i<l2->nclsy;i++){
1747 l2->planey[i] = ((TrkSinglet *)SingletY->At(i))->plane;
1748 l2->ys[i][0] = ((TrkSinglet *)SingletY->At(i))->coord[0];
1749 l2->ys[i][1] = ((TrkSinglet *)SingletY->At(i))->coord[1];
1750 l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
1751 }
1752 }
1753 }
1754 //--------------------------------------
1755 //
1756 //
1757 //--------------------------------------
1758 void TrkLevel2::Clear(){
1759 for(Int_t i=0; i<12 ; i++){
1760 good[i] = -1;
1761 VKflag[i] = 0;
1762 VKmask[i] = 0;
1763 };
1764 // if(Track)Track->Clear("C");
1765 // if(SingletX)SingletX->Clear("C");
1766 // if(SingletY)SingletY->Clear("C");
1767 if(Track)Track->Delete();
1768 if(SingletX)SingletX->Delete();
1769 if(SingletY)SingletY->Delete();
1770 }
1771 // //--------------------------------------
1772 // //
1773 // //
1774 // //--------------------------------------
1775 void TrkLevel2::Delete(){
1776
1777 // cout << "void TrkLevel2::Delete()"<<endl;
1778 Clear();
1779 if(Track)delete Track;
1780 if(SingletX)delete SingletX;
1781 if(SingletY)delete SingletY;
1782
1783 }
1784 //--------------------------------------
1785 //
1786 //
1787 //--------------------------------------
1788 /**
1789 * 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).
1790 * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.
1791 */
1792 TRefArray *TrkLevel2::GetTracks_NFitSorted(){
1793
1794 if(!Track)return 0;
1795
1796 TRefArray *sorted = new TRefArray();
1797
1798 TClonesArray &t = *Track;
1799 // TClonesArray &ts = *PhysicalTrack;
1800 int N = ntrk();
1801 vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;
1802 // int m[50]; for(int i=0; i<N; i++)m[i]=1;
1803
1804 int indo=0;
1805 int indi=0;
1806 while(N > 0){
1807 // while(N != 0){
1808 int nfit =0;
1809 float chi2ref = numeric_limits<float>::max();
1810
1811 // first loop to search maximum num. of fit points
1812 for(int i=0; i < ntrk(); i++){
1813 if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
1814 nfit = ((TrkTrack *)t[i])->GetNtot();
1815 }
1816 }
1817 //second loop to search minimum chi2 among selected
1818 for(int i=0; i<ntrk(); i++){
1819 Float_t chi2 = ((TrkTrack *)t[i])->chi2;
1820 if(chi2 < 0) chi2 = -chi2*1000;
1821 if( chi2 < chi2ref
1822 && ((TrkTrack *)t[i])->GetNtot() == nfit
1823 && m[i]==1){
1824 chi2ref = ((TrkTrack *)t[i])->chi2;
1825 indi = i;
1826 };
1827 };
1828 if( ((TrkTrack *)t[indi])->HasImage() ){
1829 m[((TrkTrack *)t[indi])->image] = 0;
1830 N--;
1831
1832 // cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1833 };
1834 sorted->Add( (TrkTrack*)t[indi] );
1835
1836 m[indi] = 0;
1837 // cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl;
1838 N--;
1839 indo++;
1840 }
1841 m.clear();
1842 // cout << "GetTracks_NFitSorted(it): Done"<< endl;
1843
1844 return sorted;
1845 // return PhysicalTrack;
1846 }
1847 //--------------------------------------
1848 //
1849 //
1850 //--------------------------------------
1851 /**
1852 * Retrieves the is-th stored track.
1853 * @param it Track number, ranging from 0 to ntrk().
1854 * Fitted tracks ( images included ) are stored in a TObjectArray ( TrkLevel2::Track ) in the same order they are returned by the F77 fitting routine.
1855 */
1856 TrkTrack *TrkLevel2::GetStoredTrack(int is){
1857
1858 if(is >= this->ntrk()){
1859 cout << "TrkTrack *TrkLevel2::GetStoredTrack(int) >> Track "<< is << "doen not exits! " << endl;
1860 cout << "Stored tracks ntrk() = "<< this->ntrk() << endl;
1861 return 0;
1862 }
1863 if(!Track){
1864 cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (TClonesArray*) Track ==0 "<<endl;
1865 };
1866 TClonesArray &t = *(Track);
1867 TrkTrack *track = (TrkTrack*)t[is];
1868 return track;
1869 }
1870 //--------------------------------------
1871 //
1872 //
1873 //--------------------------------------
1874 /**
1875 * Retrieves the is-th stored X singlet.
1876 * @param it Singlet number, ranging from 0 to nclsx().
1877 */
1878 TrkSinglet *TrkLevel2::GetSingletX(int is){
1879
1880 if(is >= this->nclsx()){
1881 cout << "TrkSinglet *TrkLevel2::GetSingletX(int) >> Singlet "<< is << "doen not exits! " << endl;
1882 cout << "Stored x-singlets nclsx() = "<< this->nclsx() << endl;
1883 return 0;
1884 }
1885 if(!SingletX)return 0;
1886 TClonesArray &t = *(SingletX);
1887 TrkSinglet *singlet = (TrkSinglet*)t[is];
1888 return singlet;
1889 }
1890 //--------------------------------------
1891 //
1892 //
1893 //--------------------------------------
1894 /**
1895 * Retrieves the is-th stored Y singlet.
1896 * @param it Singlet number, ranging from 0 to nclsx().
1897 */
1898 TrkSinglet *TrkLevel2::GetSingletY(int is){
1899
1900 if(is >= this->nclsy()){
1901 cout << "TrkSinglet *TrkLevel2::GetSingletY(int) >> Singlet "<< is << "doen not exits! " << endl;
1902 cout << "Stored y-singlets nclsx() = "<< this->nclsx() << endl;
1903 return 0;
1904 }
1905 if(!SingletY)return 0;
1906 TClonesArray &t = *(SingletY);
1907 TrkSinglet *singlet = (TrkSinglet*)t[is];
1908 return singlet;
1909 }
1910 //--------------------------------------
1911 //
1912 //
1913 //--------------------------------------
1914 /**
1915 * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
1916 * @param it Track number, ranging from 0 to GetNTracks().
1917 */
1918
1919 TrkTrack *TrkLevel2::GetTrack(int it){
1920
1921 if(it >= this->GetNTracks()){
1922 cout << "TrkTrack *TrkLevel2::GetTrack(int) >> Track "<< it << "does not exits! " << endl;
1923 cout << "Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1924 return 0;
1925 }
1926
1927 TRefArray *sorted = GetTracks(); //TEMPORANEO
1928 if(!sorted)return 0;
1929 TrkTrack *track = (TrkTrack*)sorted->At(it);
1930 sorted->Clear();
1931 delete sorted;
1932 return track;
1933 }
1934 /**
1935 * Give the number of "physical" tracks, sorted by the method GetTracks().
1936 */
1937 Int_t TrkLevel2::GetNTracks(){
1938
1939 Float_t ntot=0;
1940 if(!Track)return 0;
1941 TClonesArray &t = *Track;
1942 for(int i=0; i<ntrk(); i++) {
1943 if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
1944 else ntot+=0.5;
1945 }
1946 return (Int_t)ntot;
1947
1948 };
1949 //--------------------------------------
1950 //
1951 //
1952 //--------------------------------------
1953 /**
1954 * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks().
1955 * @param it Track number, ranging from 0 to GetNTracks().
1956 */
1957 TrkTrack *TrkLevel2::GetTrackImage(int it){
1958
1959 if(it >= this->GetNTracks()){
1960 cout << "TrkTrack *TrkLevel2::GetTrackImage(int) >> Track "<< it << "does not exits! " << endl;
1961 cout << "Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1962 return 0;
1963 }
1964
1965 TRefArray* sorted = GetTracks(); //TEMPORANEO
1966 if(!sorted)return 0;
1967 TrkTrack *track = (TrkTrack*)sorted->At(it);
1968
1969 if(!track->HasImage()){
1970 cout << "TrkTrack *TrkLevel2::GetTrackImage(int) >> Track "<< it << "does not have image! " << endl;
1971 return 0;
1972 }
1973 if(!Track)return 0;
1974 TrkTrack *image = (TrkTrack*)(*Track)[track->image];
1975
1976 sorted->Delete();
1977 delete sorted;
1978
1979 return image;
1980
1981 }
1982 //--------------------------------------
1983 //
1984 //
1985 //--------------------------------------
1986 /**
1987 * Loads the magnetic field.
1988 * @param s Path of the magnetic-field files.
1989 */
1990 void TrkLevel2::LoadField(TString path){
1991 //
1992 // strcpy(path_.path,path.Data());
1993 // path_.pathlen = path.Length();
1994 // path_.error = 0;
1995 // readb_();
1996
1997 // TrkParams::SetTrackingMode();
1998 // TrkParams::SetPrecisionFactor();
1999 // TrkParams::SetStepMin();
2000 TrkParams::SetMiniDefault();
2001
2002 TrkParams::Set(path,1);
2003 TrkParams::Load(1);
2004
2005 //
2006 };
2007 // /**
2008 // * Get BY (kGauss)
2009 // * @param v (x,y,z) coordinates in cm
2010 // */
2011 // float TrkLevel2::GetBX(float* v){
2012 // float b[3];
2013 // gufld_(v,b);
2014 // return b[0]/10.;
2015 // }
2016 // /**
2017 // * Get BY (kGauss)
2018 // * @param v (x,y,z) coordinates in cm
2019 // */
2020 // float TrkLevel2::GetBY(float* v){
2021 // float b[3];
2022 // gufld_(v,b);
2023 // return b[1]/10.;
2024 // }
2025 // /**
2026 // * Get BY (kGauss)
2027 // * @param v (x,y,z) coordinates in cm
2028 // */
2029 // float TrkLevel2::GetBZ(float* v){
2030 // float b[3];
2031 // gufld_(v,b);
2032 // return b[2]/10.;
2033 // }
2034 //--------------------------------------
2035 //
2036 //
2037 //--------------------------------------
2038 /**
2039 * Get tracker-plane (mechanical) z-coordinate
2040 * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM)
2041 */
2042 Float_t TrkLevel2::GetZTrk(Int_t plane_id){
2043 switch(plane_id){
2044 case 1: return ZTRK1;
2045 case 2: return ZTRK2;
2046 case 3: return ZTRK3;
2047 case 4: return ZTRK4;
2048 case 5: return ZTRK5;
2049 case 6: return ZTRK6;
2050 default: return 0.;
2051 };
2052 };
2053 //--------------------------------------
2054 //
2055 //
2056 //--------------------------------------
2057 /**
2058 * Trajectory default constructor.
2059 * (By default is created with z-coordinates inside the tracking volume)
2060 */
2061 Trajectory::Trajectory(){
2062 npoint = 10;
2063 x = new float[npoint];
2064 y = new float[npoint];
2065 z = new float[npoint];
2066 thx = new float[npoint];
2067 thy = new float[npoint];
2068 tl = new float[npoint];
2069 float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
2070 for(int i=0; i<npoint; i++){
2071 x[i] = 0;
2072 y[i] = 0;
2073 z[i] = (ZTRK1) - i*dz;
2074 thx[i] = 0;
2075 thy[i] = 0;
2076 tl[i] = 0;
2077 }
2078 }
2079 //--------------------------------------
2080 //
2081 //
2082 //--------------------------------------
2083 /**
2084 * Trajectory constructor.
2085 * (By default is created with z-coordinates inside the tracking volume)
2086 * \param n Number of points
2087 */
2088 Trajectory::Trajectory(int n){
2089 if(n<=0){
2090 cout << "NB! Trajectory must have at least 1 point >>> created with 10 points" << endl;
2091 n=10;
2092 }
2093 npoint = n;
2094 x = new float[npoint];
2095 y = new float[npoint];
2096 z = new float[npoint];
2097 thx = new float[npoint];
2098 thy = new float[npoint];
2099 tl = new float[npoint];
2100 float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
2101 for(int i=0; i<npoint; i++){
2102 x[i] = 0;
2103 y[i] = 0;
2104 z[i] = (ZTRK1) - i*dz;
2105 thx[i] = 0;
2106 thy[i] = 0;
2107 tl[i] = 0;
2108 }
2109 }
2110 //--------------------------------------
2111 //
2112 //
2113 //--------------------------------------
2114 /**
2115 * Trajectory constructor.
2116 * \param n Number of points
2117 * \param pz Pointer to float array, defining z coordinates
2118 */
2119 Trajectory::Trajectory(int n, float* zin){
2120 npoint = 10;
2121 if(n>0)npoint = n;
2122 x = new float[npoint];
2123 y = new float[npoint];
2124 z = new float[npoint];
2125 thx = new float[npoint];
2126 thy = new float[npoint];
2127 tl = new float[npoint];
2128 int i=0;
2129 do{
2130 x[i] = 0;
2131 y[i] = 0;
2132 z[i] = zin[i];
2133 thx[i] = 0;
2134 thy[i] = 0;
2135 tl[i] = 0;
2136 i++;
2137 }while(zin[i-1] > zin[i] && i < npoint);
2138 npoint=i;
2139 if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
2140 }
2141 void Trajectory::Delete(){
2142
2143 if(x) delete [] x;
2144 if(y) delete [] y;
2145 if(z) delete [] z;
2146 if(thx) delete [] thx;
2147 if(thy) delete [] thy;
2148 if(tl) delete [] tl;
2149
2150 }
2151 //--------------------------------------
2152 //
2153 //
2154 //--------------------------------------
2155 /**
2156 * Dump the trajectory coordinates.
2157 */
2158 void Trajectory::Dump(){
2159 cout <<endl<< "Trajectory ========== "<<endl;
2160 for (int i=0; i<npoint; i++){
2161 cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] ;
2162 cout <<" -- " << thx[i] <<" "<< thy[i] ;
2163 cout <<" -- " << tl[i] << endl;
2164 };
2165 }
2166 //--------------------------------------
2167 //
2168 //
2169 //--------------------------------------
2170 /**
2171 * Get trajectory length between two points
2172 * @param ifirst first point (default 0)
2173 * @param ilast last point (default npoint)
2174 */
2175 float Trajectory::GetLength(int ifirst, int ilast){
2176 if( ifirst<0 ) ifirst = 0;
2177 if( ilast>=npoint) ilast = npoint-1;
2178 float l=0;
2179 for(int i=ifirst;i<=ilast;i++){
2180 l=l+tl[i];
2181 };
2182 if(z[ilast] > ZINI)l=l-tl[ilast];
2183 if(z[ifirst] < ZINI) l=l-tl[ifirst];
2184
2185 return l;
2186
2187 }
2188
2189 /**
2190 * Evaluates the trajectory in the apparatus associated to the track.
2191 * 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.
2192 * @param t pointer to an object of the class Trajectory,
2193 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
2194 * @return error flag.
2195 */
2196 int Trajectory::DoTrack2(float* al){
2197
2198 // double *dxout = new double[npoint];
2199 // double *dyout = new double[npoint];
2200 // double *dthxout = new double[npoint];
2201 // double *dthyout = new double[npoint];
2202 // double *dtlout = new double[npoint];
2203 // double *dzin = new double[npoint];
2204
2205 double *dxout;
2206 double *dyout;
2207 double *dthxout;
2208 double *dthyout;
2209 double *dtlout;
2210 double *dzin;
2211
2212 dxout = (double*) malloc(npoint*sizeof(double));
2213 dyout = (double*) malloc(npoint*sizeof(double));
2214 dthxout = (double*) malloc(npoint*sizeof(double));
2215 dthyout = (double*) malloc(npoint*sizeof(double));
2216 dtlout = (double*) malloc(npoint*sizeof(double));
2217 dzin = (double*) malloc(npoint*sizeof(double));
2218
2219 double dal[5];
2220
2221 int ifail = 0;
2222
2223 for (int i=0; i<5; i++) dal[i] = (double)al[i];
2224 for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
2225
2226 TrkParams::Load(1);
2227 if( !TrkParams::IsLoaded(1) ){
2228 cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;
2229 return 0;
2230 }
2231 dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
2232
2233 for (int i=0; i<npoint; i++){
2234 x[i] = (float)*(dxout+i);
2235 y[i] = (float)*(dyout+i);
2236 thx[i] = (float)*(dthxout+i);
2237 thy[i] = (float)*(dthyout+i);
2238 tl[i] = (float)*(dtlout+i);
2239 }
2240
2241 if(dxout) free( dxout );
2242 if(dyout) free( dyout );
2243 if(dthxout)free( dthxout );
2244 if(dthyout)free( dthyout );
2245 if(dtlout) free( dtlout );
2246 if(dzin) free( dzin );
2247
2248 // delete [] dxout;
2249 // delete [] dyout;
2250 // delete [] dthxout;
2251 // delete [] dthyout;
2252 // delete [] dtlout;
2253 // delete [] dzin;
2254
2255
2256 return ifail;
2257 };
2258
2259 ClassImp(TrkLevel2);
2260 ClassImp(TrkSinglet);
2261 ClassImp(TrkTrack);
2262 ClassImp(Trajectory);

  ViewVC Help
Powered by ViewVC 1.1.23