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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download)
Thu Oct 26 16:22:37 2006 UTC (18 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.12: +135 -5 lines
fitting methods

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

  ViewVC Help
Powered by ViewVC 1.1.23