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