StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gl3Track.cxx
1 #include "Stl3Util/gl3/gl3Track.h"
2 
3 #include "Stl3Util/base/FtfLog.h"
4 
5 #include <stdlib.h>
6 //:>------------------------------------------------------------------
7 //: FILE: gl3Track.cc
8 //: HISTORY:
9 //: 14 jul 2000 changing no overlaping tracks code in merging method
10 //: 27 jul 2000 add methods to drop hits
11 //:<------------------------------------------------------------------
12 
13 
14 
15 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16 // Merges tracks
17 //
18 // values are combined using recipe form particle data booklet
19 // Phys. Rev. D. 50(1994) 1180
20 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 int gl3Track::addTrack ( gl3Track* piece ){
22 
23  double w1 = 1./ ( dpt * dpt ) ;
24  double w2 = 1./ ( piece->dpt * piece->dpt ) ;
25  double wsum = w1 + w2 ;
26  pt = ( w1 * pt + w2 * piece->pt ) / wsum ;
27  dpt = 1./::sqrt(wsum);
28 
29  w1 = 1./ ( dpsi * dpsi ) ;
30  w2 = 1./ ( piece->dpsi * piece->dpsi ) ;
31  wsum = w1 + w2 ;
32  psi = ( w1 * psi + w2 * piece->psi ) / wsum ;
33  dpsi = 1./::sqrt(wsum) ;
34 
35  w1 = 1./ ( dtanl * dtanl ) ;
36  w2 = 1./ ( piece->dtanl * piece->dtanl ) ;
37  wsum = w1 + w2 ;
38  tanl = ( w1 * tanl + w2 * piece->tanl ) / wsum ;
39  dtanl = 1./::sqrt(wsum);
40 
41  w1 = 1./ ( dz0 * dz0 ) ;
42  w2 = 1./ ( piece->dz0 * piece->dz0 ) ;
43  wsum = w1 + w2 ;
44  z0 = ( w1 * z0 + w2 * piece->z0 ) / wsum ;
45  dz0 = 1./::sqrt(wsum);
46 
47  if ( piece->innerMostRow < innerMostRow ) innerMostRow = piece->innerMostRow ;
48  if ( piece->outerMostRow > outerMostRow ) outerMostRow = piece->outerMostRow ;
49 
50  nHits += piece->nHits ;
51 //
52 // Add chi2's
53 //
54  chi2[0] += piece->chi2[0] ;
55  chi2[1] += piece->chi2[1] ;
56 //
57  return 0 ;
58 }
59 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
60 //
61 // input:
62 // rest: 0= drops even rows, 1=drops odd rows, negative=no effect
63 // rowMin: drops rows < rowMin
64 // rowMax: drops rows > rowMin
65 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 void gl3Track::dropHits ( int rest, int rowMin, int rowMax ) {
67 
68  gl3Hit* previousHit = 0 ;
69  gl3Hit* cHit = (gl3Hit *)firstHit ;
70  gl3Hit* deleteHit ;
71 
72 // ftfLog ( "Start dropping routine \n" ) ;
73 // Print(31);
74  int counter = 0 ;
75  int newCounter = 0 ;
76  while ( counter < nHits && cHit ) {
77  if ( ( rest > 0 && cHit->getRowSector()%2 == rest ) ||
78  cHit->getRowSector()%100 < rowMin ||
79  cHit->getRowSector()%100 > rowMax ) {
80 
81  deleteHit = cHit ;
82  cHit = (gl3Hit *)(cHit->nextHit) ;
83  if ( previousHit ) previousHit->nextHit = cHit ;
84 //
85  deleteHit->trackId = 0 ;
86  deleteHit->nextHit = 0 ;
87  }
88  else {
89  if ( newCounter == 0 ) firstHit = cHit ;
90  previousHit = cHit ;
91  cHit = (gl3Hit *)(cHit->nextHit) ;
92  newCounter++ ;
93  }
94  counter++ ;
95  lastHit = cHit ;
96  }
97 
98  nHits = newCounter ;
99  if ( nHits == 0 ) {
100  firstHit = 0 ;
101  }
102 // ftfLog ( "End dropping routine \n" ) ;
103 // Print(31);
104 }
105 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 // Merges tracks
107 // returns track to which this tracks was added
108 //
109 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110 gl3Track* gl3Track::merge ( FtfContainer *trackArea ){
111  gl3Track* track_merged ;
112  register int areaIndex ;
113  int i_phi, i_eta ;
114  gl3Track *i_track ;
115  int ip, ie ;
116  double delta_psi ;
117  //
118  // Get track area
119  //
120  i_phi = (int)(( psi - getPara()->phiMinTrack ) / getPara()->phiSliceTrack + 1 );
121  if ( i_phi < 0 ) {
122 // ftfLog ( " Track phi index too low %d \n", i_phi ) ;
123  i_phi = 1 ;
124  }
125  if ( i_phi >= getPara()->nPhiTrackPlusOne ) {
126 // ftfLog ( " Track phi index too high %d \n", i_phi ) ;
127  i_phi = getPara()->nPhiTrack ;
128  }
129  //
130  // Now eta
131  //
132  i_eta = (int)(( eta - getPara()->etaMinTrack ) / getPara()->etaSliceTrack + 1 );
133  if ( i_eta <= 0 ) {
134 // ftfLog ( " Track eta index too low %d \n", i_eta ) ;
135  i_eta = 1 ;
136  }
137  if ( i_eta >= getPara()->nEtaTrackPlusOne ) {
138 // ftfLog ( " Track eta index too high %d \n", i_eta ) ;
139  i_eta = getPara()->nEtaTrack ;
140  }
141  //
142  // Loop around selected area
143  //
144  track_merged = 0 ;
145 
146  for ( ip = max(i_phi-1,1) ; ip < min(i_phi+2,getPara()->nPhiTrackPlusOne) ; ip++ ) {
147  for ( ie = max(i_eta-1,1) ; ie < min(i_eta+2,getPara()->nEtaTrackPlusOne) ; ie++ ) {
148  areaIndex = ip * getPara()->nEtaTrackPlusOne + ie ;
149  //
150  // Loop over tracks
151  //
152  for ( i_track = (gl3Track *)trackArea[areaIndex].first ;
153  i_track != 0 && !track_merged ;
154  i_track = i_track->getNextTrack() ) {
155  //
156  // Reject track if it is not good
157  //
158  if ( i_track->flag < 0 ) continue ;
159 
160  //
161  // Compare both tracks
162  //
163  // No overlapping tracks
164  //
165  short p1 = i_track->innerMostRow ;
166  short p2 = i_track->outerMostRow ;
167  short t1 = innerMostRow ;
168  short t2 = outerMostRow ;
169  if ( p1 < t1 && p2 > t1 ) continue ;
170  if ( p1 < t2 && p2 > t2 ) continue ;
171  if ( p1 > t1 && p2 < t2 ) continue ;
172  if ( t1 < p1 && t2 > p1 ) continue ;
173  if ( t1 < p2 && t2 > p2 ) continue ;
174  if ( t1 > p1 && t2 < p2 ) continue ;
175  //
176  // Tracks close enough
177  //
178  double dr0 = fabs(r0-i_track->r0) ;
179 //
180 // If tracks close extrapolation is not needed
181 //
182  if ( dr0 < getPara()->distanceMerge ) {
183  if ( fabs(eta-i_track->eta) > getPara()->detaMerge ) continue ;
184 
185  delta_psi = fabs(psi - i_track->psi) ;
186  if ( delta_psi > getPara()->dphiMerge && delta_psi < twoPi - getPara()->dphiMerge ) continue ;
187  //
188  // Check radious difference
189  //
190  double dx0 = fabs(r0*cos(phi0)-i_track->r0*cos(i_track->phi0));
191  if ( dx0 > getPara()->distanceMerge ) continue ;
192  double dy0 = fabs(r0*sin(phi0)-i_track->r0*sin(i_track->phi0));
193  if ( dy0 > getPara()->distanceMerge ) continue ;
194  double dz0 = fabs(z0-i_track->z0);
195  if ( dz0 > getPara()->distanceMerge ) continue ;
196  //
197 // ftfLog ( "gl3Track: close tracks merged !!! \n " ) ;
198 // i_track->Print(30);
199 // Print(30);
200 
201  i_track->addTrack ( this ) ;
202  track_merged = i_track ;
203  break ;
204  }
205  else {
206  //
207  // if tracks too far away in r0 extrapolate the one with smallest r0
208  //
209  gl3Track originalTrack ;
210  short whichTrack = 0 ;
211  if ( r0 > i_track->r0 ) {
212  originalTrack = *this ;
213  whichTrack = 1 ;
214  q *= -1 ;// charge needs to be changed to extrapolate backwards
215  updateToRadius ( i_track->r0 ) ;
216  q *= -1 ;
217  }
218  else {
219  originalTrack = *i_track ;
220  i_track->q *= -1 ;// charge needs to be changed to extrapolate backwards
221  i_track->updateToRadius ( r0 ) ;
222  i_track->q *= -1 ;
223  }
224  // double dx0 = fabs(r0*cos(phi0)-i_track->r0*cos(i_track->phi0)) ;
225  // double dy0 = fabs(r0*sin(phi0)-i_track->r0*sin(i_track->phi0));
226  // double dz0 = fabs(z0-i_track->z0);
227  if ( fabs(r0*cos(phi0)-i_track->r0*cos(i_track->phi0)) < getPara()->distanceMerge
228  && fabs(r0*sin(phi0)-i_track->r0*sin(i_track->phi0)) < getPara()->distanceMerge
229  && fabs(z0-i_track->z0) < getPara()->distanceMerge ) {
230  //
231  // Coarse eta/phi cuts
232  //
233  if ( fabs(eta-i_track->eta) < 0.9 && fabs(psi - i_track->psi) < 0.9
234  && fabs(psi - i_track->psi) < 5.9 ) {
235  //
236 // ftfLog ( "gl3Track: far apart tracks merged !!! \n " ) ;
237 // i_track->Print(30);
238 // Print(30);
239 
240  i_track->addTrack ( this ) ;
241  track_merged = i_track ;
242  break ;
243  }
244  } // end checking merging conditions
245  //
246  // if no merging put original track parameters
247  //
248  if ( whichTrack )
249  *this = originalTrack ;
250  else
251  *i_track = originalTrack ;
252  }
253  }
254 #ifdef TRDEBUG
255  if ( getPara()->debugLevel > 1 )
256  ftfLog ( " \n Track %d merge into %d ", this->id, i_track->id ) ;
257 #endif
258  }
259  }
260 //
261 //-> If track not matched add it
262 //
263  if ( !track_merged ) {
264  areaIndex = i_phi * getPara()->nEtaTrackPlusOne + i_eta ;
265  if ( trackArea[areaIndex].first == 0 )
266  trackArea[areaIndex].first =
267  trackArea[areaIndex].last = (void *)this ;
268  else {
269  ((gl3Track *)trackArea[areaIndex].last)->nextTrack = this ;
270  trackArea[areaIndex].last = (void *)this ;
271  }
272  }
273  return track_merged ;
274 }
275 //*************************************************************************
276 // Prints one track information
277 //*************************************************************************
278 void gl3Track::Print ( int level )
279 {
280  double pmom, pz;
281 /*
282 -----> Print info
283 */
284  if ( level > 9 ) {
285  pz = pt * tanl ;
286  pmom = (double)sqrt ( pz * pz + pt * pt ) ;
287  ftfLog ( " =======> Track %d <======== \n", id ) ;
288  ftfLog ( " p, pt, q %7.2f %7.2f %2d \n", pmom, pt, q ) ;
289  }
290  if ( level > 19 ) {
291  ftfLog ( " r0, z0, nHits %7.2f %7.2f %d \n ", r0, z0, nHits ) ;
292  ftfLog ( " phi0, psi, tanl %7.2f %7.2f %7.2f \n", phi0, psi, tanl ) ;
293  }
294  else ftfLog ( "\n " ) ;
295 
296  if ( level > 29 ) {
297  ftfLog ( " chi2 (s,z) %6.2e %6.2e \n", chi2[0], chi2[1] ) ;
298  }
299  else ftfLog ( "\n " ) ;
300 
301 
302  if ( fmod((double)level,10.) > 0 ) {
303  ftfLog ( " *** Clusters in this track *** \n" ) ;
304  for ( startLoop() ; done() ; nextHit() ) {
305  ((gl3Hit *)currentHit)->print ( ) ;
306  }
307  }
308  ftfLog ( "\n " ) ;
309 }
Definition: gl3Hit.h:24