10 |
//...................................... |
//...................................... |
11 |
extern "C" { |
extern "C" { |
12 |
void dotrack_(int*, double*, double*, double*, double*, int*); |
void dotrack_(int*, double*, double*, double*, double*, int*); |
13 |
|
void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*); |
14 |
int readb_(const char*); |
int readb_(const char*); |
15 |
} |
} |
16 |
//-------------------------------------- |
//-------------------------------------- |
18 |
// |
// |
19 |
//-------------------------------------- |
//-------------------------------------- |
20 |
TrkTrack::TrkTrack(){ |
TrkTrack::TrkTrack(){ |
21 |
image = 0; |
seqno = -1; |
22 |
|
image = -1; |
23 |
chi2 = 0; |
chi2 = 0; |
24 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
25 |
al[it1] = 0; |
al[it1] = 0; |
48 |
// |
// |
49 |
//-------------------------------------- |
//-------------------------------------- |
50 |
TrkTrack::TrkTrack(const TrkTrack& t){ |
TrkTrack::TrkTrack(const TrkTrack& t){ |
51 |
|
seqno = t.seqno; |
52 |
image = t.image; |
image = t.image; |
53 |
chi2 = t.chi2; |
chi2 = t.chi2; |
54 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
113 |
// |
// |
114 |
// |
// |
115 |
//-------------------------------------- |
//-------------------------------------- |
116 |
|
/** |
117 |
|
* Evaluates the trajectory in the apparatus associated to the track. |
118 |
|
* 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. |
119 |
|
* @param t pointer to an object of the class Trajectory, |
120 |
|
* which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). |
121 |
|
* @return error flag. |
122 |
|
*/ |
123 |
|
int TrkTrack::DoTrack2(Trajectory* t){ |
124 |
|
|
125 |
|
double *dxout = new double[t->npoint]; |
126 |
|
double *dyout = new double[t->npoint]; |
127 |
|
double *dthxout = new double[t->npoint]; |
128 |
|
double *dthyout = new double[t->npoint]; |
129 |
|
double *dtlout = new double[t->npoint]; |
130 |
|
double *dzin = new double[t->npoint]; |
131 |
|
double dal[5]; |
132 |
|
|
133 |
|
int ifail = 0; |
134 |
|
|
135 |
|
for (int i=0; i<5; i++) dal[i] = (double)al[i]; |
136 |
|
for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i]; |
137 |
|
|
138 |
|
dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); |
139 |
|
|
140 |
|
for (int i=0; i<t->npoint; i++){ |
141 |
|
t->x[i] = (float)*dxout++; |
142 |
|
t->y[i] = (float)*dyout++; |
143 |
|
t->thx[i] = (float)*dthxout++; |
144 |
|
t->thy[i] = (float)*dthyout++; |
145 |
|
t->tl[i] = (float)*dtlout++; |
146 |
|
} |
147 |
|
|
148 |
|
// delete [] dxout; |
149 |
|
// delete [] dyout; |
150 |
|
// delete [] dzin; |
151 |
|
|
152 |
|
return ifail; |
153 |
|
}; |
154 |
|
//-------------------------------------- |
155 |
|
// |
156 |
|
// |
157 |
|
//-------------------------------------- |
158 |
//float TrkTrack::BdL(){ |
//float TrkTrack::BdL(){ |
159 |
//}; |
//}; |
160 |
//-------------------------------------- |
//-------------------------------------- |
240 |
Track = new TClonesArray("TrkTrack"); |
Track = new TClonesArray("TrkTrack"); |
241 |
SingletX = new TClonesArray("TrkSinglet"); |
SingletX = new TClonesArray("TrkSinglet"); |
242 |
SingletY = new TClonesArray("TrkSinglet"); |
SingletY = new TClonesArray("TrkSinglet"); |
243 |
|
|
244 |
|
// PhysicalTrack = new TClonesArray("TrkTrack"); |
245 |
|
//sostituire con TRefArray... appena ho capito come si usa |
246 |
} |
} |
247 |
//-------------------------------------- |
//-------------------------------------- |
248 |
// |
// |
271 |
* Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). |
* Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common). |
272 |
*/ |
*/ |
273 |
void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){ |
void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){ |
274 |
|
// |
275 |
|
// Track = new TClonesArray("TrkTrack"); |
276 |
|
// SingletX = new TClonesArray("TrkSinglet"); |
277 |
|
// SingletY = new TClonesArray("TrkSinglet"); |
278 |
// temporary objects: |
// temporary objects: |
279 |
TrkSinglet* t_singlet = new TrkSinglet(); |
TrkSinglet* t_singlet = new TrkSinglet(); |
280 |
TrkTrack* t_track = new TrkTrack(); |
TrkTrack* t_track = new TrkTrack(); |
286 |
// *** TRACKS *** |
// *** TRACKS *** |
287 |
TClonesArray &t = *Track; |
TClonesArray &t = *Track; |
288 |
for(int i=0; i<l2->ntrk; i++){ |
for(int i=0; i<l2->ntrk; i++){ |
289 |
|
t_track->seqno = i; |
290 |
t_track->image = l2->image[i]-1; |
t_track->image = l2->image[i]-1; |
291 |
|
// cout << "track "<<i<<t_track->seqno << t_track->image<<endl; |
292 |
t_track->chi2 = l2->chi2_nt[i]; |
t_track->chi2 = l2->chi2_nt[i]; |
293 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
294 |
t_track->al[it1] = l2->al_nt[i][it1]; |
t_track->al[it1] = l2->al_nt[i][it1]; |
333 |
new(sy[i]) TrkSinglet(*t_singlet); |
new(sy[i]) TrkSinglet(*t_singlet); |
334 |
t_singlet->Clear(); |
t_singlet->Clear(); |
335 |
}; |
}; |
336 |
|
|
337 |
|
delete t_track; |
338 |
|
delete t_singlet; |
339 |
} |
} |
340 |
//-------------------------------------- |
//-------------------------------------- |
341 |
// |
// |
346 |
for(Int_t i=0; i<12 ; i++){ |
for(Int_t i=0; i<12 ; i++){ |
347 |
crc[i] = -1; |
crc[i] = -1; |
348 |
}; |
}; |
349 |
Track->RemoveAll(); |
/* Track->RemoveAll(); |
350 |
SingletX->RemoveAll(); |
SingletX->RemoveAll(); |
351 |
SingletY->RemoveAll(); |
SingletY->RemoveAll();*/ |
352 |
|
// modify to avoid memory leakage |
353 |
|
Track->Clear(); |
354 |
|
SingletX->Clear(); |
355 |
|
SingletY->Clear(); |
356 |
} |
} |
357 |
//-------------------------------------- |
//-------------------------------------- |
358 |
// |
// |
363 |
* This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. |
* This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. |
364 |
*/ |
*/ |
365 |
TClonesArray *TrkLevel2::GetTracks(){ |
TClonesArray *TrkLevel2::GetTracks(){ |
366 |
|
TClonesArray *sorted = GetTracks_NFitSorted(); |
367 |
|
return sorted; |
368 |
|
|
369 |
|
// fare di meglio... |
370 |
|
/* PhysicalTrack->Clear(); |
371 |
|
if(ntrk() > 0) GetTracks_NFitSorted(); |
372 |
|
return PhysicalTrack;*/ |
373 |
|
}; |
374 |
|
|
375 |
|
/*TClonesArray *TrkLevel2::GetTracks_Chi2Sorted(){ |
376 |
|
|
377 |
TClonesArray *sorted = new TClonesArray("TrkTrack"); |
TClonesArray *sorted = new TClonesArray("TrkTrack"); |
378 |
TClonesArray &t = *Track; |
TClonesArray &t = *Track; |
400 |
indo++; |
indo++; |
401 |
} |
} |
402 |
return sorted; |
return sorted; |
403 |
|
}*/ |
404 |
|
TClonesArray *TrkLevel2::GetTracks_NFitSorted(){ |
405 |
|
|
406 |
|
TClonesArray *sorted = new TClonesArray("TrkTrack"); |
407 |
|
TClonesArray &t = *Track; |
408 |
|
TClonesArray &ts = *sorted; |
409 |
|
// TClonesArray &ts = *PhysicalTrack; |
410 |
|
int N=this->ntrk(); |
411 |
|
vector<int> m(N); for(int i=0; i<N; i++)m[i]=1; |
412 |
|
|
413 |
|
int indo=0; |
414 |
|
int indi=0; |
415 |
|
while(N != 0){ |
416 |
|
int nfit =0; |
417 |
|
float chi2ref=1000000; |
418 |
|
// first loop to search maximum num. of fit points |
419 |
|
for(int i=0; i<this->ntrk(); i++){ |
420 |
|
if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){ |
421 |
|
nfit = ((TrkTrack *)t[i])->GetNtot(); |
422 |
|
// cout << "1** "<<i<< " " << nfit<<endl; |
423 |
|
} |
424 |
|
} |
425 |
|
//second loop to search minimum chi2 among selected |
426 |
|
for(int i=0; i<this->ntrk(); i++){ |
427 |
|
if( ((TrkTrack *)t[i])->chi2 < chi2ref |
428 |
|
&& ((TrkTrack *)t[i])->GetNtot()== nfit |
429 |
|
&& m[i]==1){ |
430 |
|
chi2ref = ((TrkTrack *)t[i])->chi2; |
431 |
|
indi = i; |
432 |
|
// cout << "2** "<<i<< " " << nfit <<" "<<chi2ref<<endl; |
433 |
|
} |
434 |
|
} |
435 |
|
if( ((TrkTrack *)t[indi])->HasImage() ){ |
436 |
|
m[((TrkTrack *)t[indi])->image] = 0; |
437 |
|
N--; |
438 |
|
|
439 |
|
// Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image ])->GetNtot(); |
440 |
|
// Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image ])->chi2; |
441 |
|
|
442 |
|
// cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl; |
443 |
|
} |
444 |
|
new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]); |
445 |
|
m[indi] = 0; |
446 |
|
N--; |
447 |
|
indo++; |
448 |
|
} |
449 |
|
return sorted; |
450 |
|
// return PhysicalTrack; |
451 |
} |
} |
452 |
//-------------------------------------- |
//-------------------------------------- |
453 |
// |
// |
474 |
// |
// |
475 |
//-------------------------------------- |
//-------------------------------------- |
476 |
/** |
/** |
477 |
|
* Retrieves the is-th stored X singlet. |
478 |
|
* @param it Singlet number, ranging from 0 to nclsx(). |
479 |
|
*/ |
480 |
|
TrkSinglet *TrkLevel2::GetSingletX(int is){ |
481 |
|
|
482 |
|
if(is >= this->nclsx()){ |
483 |
|
cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; |
484 |
|
cout << " Stored x-singlets nclsx() = "<< this->nclsx() << endl; |
485 |
|
return 0; |
486 |
|
} |
487 |
|
TClonesArray &t = *(SingletX); |
488 |
|
TrkSinglet *singlet = (TrkSinglet*)t[is]; |
489 |
|
return singlet; |
490 |
|
} |
491 |
|
//-------------------------------------- |
492 |
|
// |
493 |
|
// |
494 |
|
//-------------------------------------- |
495 |
|
/** |
496 |
|
* Retrieves the is-th stored Y singlet. |
497 |
|
* @param it Singlet number, ranging from 0 to nclsx(). |
498 |
|
*/ |
499 |
|
TrkSinglet *TrkLevel2::GetSingletY(int is){ |
500 |
|
|
501 |
|
if(is >= this->nclsy()){ |
502 |
|
cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl; |
503 |
|
cout << " Stored y-singlets nclsy() = "<< this->nclsx() << endl; |
504 |
|
return 0; |
505 |
|
} |
506 |
|
TClonesArray &t = *(SingletY); |
507 |
|
TrkSinglet *singlet = (TrkSinglet*)t[is]; |
508 |
|
return singlet; |
509 |
|
} |
510 |
|
//-------------------------------------- |
511 |
|
// |
512 |
|
// |
513 |
|
//-------------------------------------- |
514 |
|
/** |
515 |
* Retrieves the it-th "physical" track, sorted by the method GetNTracks(). |
* Retrieves the it-th "physical" track, sorted by the method GetNTracks(). |
516 |
* @param it Track number, ranging from 0 to GetNTracks(). |
* @param it Track number, ranging from 0 to GetNTracks(). |
517 |
*/ |
*/ |
523 |
return 0; |
return 0; |
524 |
} |
} |
525 |
TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it]; |
TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it]; |
526 |
|
GetTracks()->Delete();////TEMPORANEO |
527 |
return track; |
return track; |
528 |
} |
} |
529 |
|
/** |
530 |
|
* Give the number of "physical" tracks, sorted by the method GetTracks(). |
531 |
|
*/ |
532 |
|
Int_t TrkLevel2::GetNTracks(){ |
533 |
|
Int_t ntot=0; |
534 |
|
ntot = GetTracks()->GetEntries(); |
535 |
|
GetTracks()->Delete();////TEMPORANEO |
536 |
|
return ntot; |
537 |
|
}; |
538 |
//-------------------------------------- |
//-------------------------------------- |
539 |
// |
// |
540 |
// |
// |
556 |
return 0; |
return 0; |
557 |
} |
} |
558 |
TrkTrack *image = (TrkTrack*)(*Track)[track->image]; |
TrkTrack *image = (TrkTrack*)(*Track)[track->image]; |
559 |
|
GetTracks()->Delete(); ////TEMPORANEO |
560 |
return image; |
return image; |
561 |
|
|
562 |
} |
} |
576 |
// |
// |
577 |
//-------------------------------------- |
//-------------------------------------- |
578 |
/** |
/** |
579 |
|
* Get tracker-plane (mechanical) z-coordinate |
580 |
|
* @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM) |
581 |
|
*/ |
582 |
|
Float_t TrkLevel2::GetZTrk(Int_t plane_id){ |
583 |
|
switch(plane_id){ |
584 |
|
case 1: return ZTRK1; |
585 |
|
case 2: return ZTRK2; |
586 |
|
case 3: return ZTRK3; |
587 |
|
case 4: return ZTRK4; |
588 |
|
case 5: return ZTRK5; |
589 |
|
case 6: return ZTRK6; |
590 |
|
default: return 0.; |
591 |
|
}; |
592 |
|
}; |
593 |
|
//-------------------------------------- |
594 |
|
// |
595 |
|
// |
596 |
|
//-------------------------------------- |
597 |
|
/** |
598 |
|
* Trajectory default constructor. |
599 |
|
* (By default is created with z-coordinates inside the tracking volume) |
600 |
|
*/ |
601 |
|
Trajectory::Trajectory(){ |
602 |
|
npoint = 10; |
603 |
|
x = new float[npoint]; |
604 |
|
y = new float[npoint]; |
605 |
|
z = new float[npoint]; |
606 |
|
thx = new float[npoint]; |
607 |
|
thy = new float[npoint]; |
608 |
|
tl = new float[npoint]; |
609 |
|
float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); |
610 |
|
for(int i=0; i<npoint; i++){ |
611 |
|
x[i] = 0; |
612 |
|
y[i] = 0; |
613 |
|
z[i] = (ZTRK1) - i*dz; |
614 |
|
thx[i] = 0; |
615 |
|
thy[i] = 0; |
616 |
|
tl[i] = 0; |
617 |
|
} |
618 |
|
} |
619 |
|
//-------------------------------------- |
620 |
|
// |
621 |
|
// |
622 |
|
//-------------------------------------- |
623 |
|
/** |
624 |
* Trajectory constructor. |
* Trajectory constructor. |
625 |
|
* (By default is created with z-coordinates inside the tracking volume) |
626 |
* \param n Number of points |
* \param n Number of points |
627 |
*/ |
*/ |
628 |
Trajectory::Trajectory(int n){ |
Trajectory::Trajectory(int n){ |
629 |
|
if(n<=0){ |
630 |
|
cout << "NB! Trajectory must have at least 1 point >>> created with 10 points" << endl; |
631 |
|
n=10; |
632 |
|
} |
633 |
npoint = n; |
npoint = n; |
634 |
x = new float[npoint]; |
x = new float[npoint]; |
635 |
y = new float[npoint]; |
y = new float[npoint]; |
636 |
z = new float[npoint]; |
z = new float[npoint]; |
637 |
|
thx = new float[npoint]; |
638 |
|
thy = new float[npoint]; |
639 |
|
tl = new float[npoint]; |
640 |
|
float dz = ((ZTRK1)-(ZTRK6))/(npoint-1); |
641 |
for(int i=0; i<npoint; i++){ |
for(int i=0; i<npoint; i++){ |
642 |
x[i] = 0; |
x[i] = 0; |
643 |
y[i] = 0; |
y[i] = 0; |
644 |
z[i] = 0; |
z[i] = (ZTRK1) - i*dz; |
645 |
|
thx[i] = 0; |
646 |
|
thy[i] = 0; |
647 |
|
tl[i] = 0; |
648 |
} |
} |
649 |
} |
} |
650 |
//-------------------------------------- |
//-------------------------------------- |
657 |
* \param pz Pointer to float array, defining z coordinates |
* \param pz Pointer to float array, defining z coordinates |
658 |
*/ |
*/ |
659 |
Trajectory::Trajectory(int n, float* zin){ |
Trajectory::Trajectory(int n, float* zin){ |
660 |
npoint = n; |
npoint = 10; |
661 |
|
if(n>0)npoint = n; |
662 |
x = new float[npoint]; |
x = new float[npoint]; |
663 |
y = new float[npoint]; |
y = new float[npoint]; |
664 |
z = new float[npoint]; |
z = new float[npoint]; |
665 |
for(int i=0; i<npoint; i++){ |
thx = new float[npoint]; |
666 |
|
thy = new float[npoint]; |
667 |
|
tl = new float[npoint]; |
668 |
|
int i=0; |
669 |
|
do{ |
670 |
x[i] = 0; |
x[i] = 0; |
671 |
y[i] = 0; |
y[i] = 0; |
672 |
z[i] = zin[i]; |
z[i] = zin[i]; |
673 |
} |
thx[i] = 0; |
674 |
|
thy[i] = 0; |
675 |
|
tl[i] = 0; |
676 |
|
i++; |
677 |
|
}while(zin[i-1] > zin[i] && i < npoint); |
678 |
|
npoint=i; |
679 |
|
if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl; |
680 |
} |
} |
681 |
//-------------------------------------- |
//-------------------------------------- |
682 |
// |
// |
688 |
void Trajectory::Dump(){ |
void Trajectory::Dump(){ |
689 |
cout <<endl<< "Trajectory ========== "<<endl; |
cout <<endl<< "Trajectory ========== "<<endl; |
690 |
for (int i=0; i<npoint; i++){ |
for (int i=0; i<npoint; i++){ |
691 |
cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] << endl;; |
cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] ; |
692 |
|
cout <<" -- " << thx[i] <<" "<< thy[i] ; |
693 |
|
cout <<" -- " << tl[i] << endl; |
694 |
|
}; |
695 |
|
} |
696 |
|
//-------------------------------------- |
697 |
|
// |
698 |
|
// |
699 |
|
//-------------------------------------- |
700 |
|
/** |
701 |
|
* Get trajectory length between two points |
702 |
|
* @param ifirst first point (default 0) |
703 |
|
* @param ilast last point (default npoint) |
704 |
|
*/ |
705 |
|
float Trajectory::GetLength(int ifirst, int ilast){ |
706 |
|
if( ifirst<0 ) ifirst = 0; |
707 |
|
if( ilast>=npoint) ilast = npoint-1; |
708 |
|
float l=0; |
709 |
|
for(int i=ifirst;i<=ilast;i++){ |
710 |
|
l=l+tl[i]; |
711 |
}; |
}; |
712 |
|
if(z[ilast] > ZINI)l=l-tl[ilast]; |
713 |
|
if(z[ifirst] < ZINI) l=l-tl[ifirst]; |
714 |
|
|
715 |
|
return l; |
716 |
|
|
717 |
} |
} |
718 |
|
|
719 |
ClassImp(TrkLevel2); |
ClassImp(TrkLevel2); |