StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FtfSl3.cxx
1 /*:>-------------------------------------------------------------------
2 **: FILE: FtfSl3.cxx
3 **: HISTORY:
4 **: aug 23, 1999 add setup with number of hits and tracks
5 **: oct 6, 1999 ppy new version from Christof
6 **: oct 11, 1999 ppy call rawToLocal with variables instead of pointers
7 **: oct 11, 1999 ppy phiMin, phiMax changed to 0 and 2 pi
8 **: oct 21, 1999 ppy call to rawToGlobal with variables rather than pointers
9 **: oct 22, 1999 ppy back to pointers to make Christof happy
10 **:
11 **: nov 24, 1999 cle extra method for filling US tracks deleted
12 **: (FtfSl3::fillUSTracks)
13 **: added 'token' as argument for fill method
14 **: changed formats to official L3 formats
15 **: dec 2, 1999 ppy setup and readSector modified
16 **: sectorGeo class added to keep sector phase space
17 **: readSector uses it to define tracker phase space
18 **: dec 6, 1999 ppy add xLastHit and yLastHit to type1_track
19 **: dec 6, 1999 ppy provisional patch to avoid generaring type1 tracks
20 **: dec 6, 1999 ppy pt in type 1 & 2 tracks is pt * charge
21 **: dec 6, 1999 ppy method CanItBeMerged added
22 **: dec 16, 1999 ppy readSector and readMezzaninne look at
23 **: byte order now
24 **: dec 20, 1999 ppy sectorGeo[23].phiMax set to correct value in setup
25 **: dec 21, 1999 ppy fillTracks=0 deleted, leave default value (1)
26 **: dec 21, 1999 ppy bug corrected phiShift = 0 zero for non-border sectors
27 **: dec 21, 1999 ppy ptHelixFit set to zero in setParameters
28 **: dec 21, 1999 ppy maxChi2Primary =10 in setParameters
29 **: jan 27, 2000 ppy canItMerged beefed up
30 **: feb 10, 2000 ppy add xyError and zError
31 **: feb 10, 2000 ppy add xyError and zError
32 **: feb 14, 2000 ppy track length filled for tracks type 2 and 3
33 **: feb 17, 2000 ppy check ratiox and ratioy are no division by zero
34 **: feb 24, 2000 ppy hit id in readMezzaninne should be nHits+counter
35 **: mar 09, 2000 ppy trackLength changed to length
36 **: mar 09, 2000 ppy some changes to accomodate void pointers
37 **: mar 11, 2000 ppy fill hits
38 **: mar 29, 2000 ppy add errors to tracks in daq format
39 **: apr 06, 2000 cle change L3_CLUSTER to l3_cluster
40 **: apr 08, 2000 ppy add variables to cut cluster for high/low charge/time bin
41 **: apr 18, 2000 ppy include readout board and mezzannine in readMezzanine
42 **: arguments
43 **: apr 19, 2000 cs add dEdx from Christof
44 **: apr 19, 2000 cs discard one-apd cluster (flag == 1) in readMezzanine(...)
45 **: jun 28, 2000 ppy replace sl3CoordinateTransform with class
46 **: St_l3_Coordinate_Transformer
47 **: jul 12, 2000 ppy get rid of mergeFlag in fillTracks (not used)
48 **: aug 21, 2000 ppy replace printf with ftfLog
49 **:<------------------------------------------------------------------*/
50 #include "Stl3Util/ftf/FtfSl3.h"
51 
52 #include "Stl3Util/base/L3swap.h"
53 
54 //******************************************************************
55 // Check whether tracs are mergable
56 //******************************************************************
57 int FtfSl3::canItBeMerged ( FtfTrack* tTrack ) {
58  double rTpcMin = 50. ;
59  double rTpcMax = 210. ;
60 
61  if ( nHits < 15 ) return 0 ;
62 //
63 // Get circle parameters
64 //
65 // double rc = tTrack->pt / ( 2.9979e-3 * para.bField );
66 // double xc = para.xVertex - tTrack->a2Xy / ( 2. * tTrack->a1Xy ) ;
67 // double yc = para.yVertex - 1. / ( 2. * tTrack->a1Xy ) ;
68  double x0 = tTrack->r0 * cos (tTrack->phi0);
69  double y0 = tTrack->r0 * sin (tTrack->phi0);
70  double rc = tTrack->pt / (bFactor * para.bField);
71  double trackPhi0 = tTrack->psi + tTrack->q * 0.5 * M_PI / fabs ((double) tTrack->q);
72  double xc = x0 - rc * cos (trackPhi0);
73  double yc = y0 - rc * sin (trackPhi0);
74 //
75 // Calculate intersection with tracking area (sector or supersector) boundaries
76 //
77  double localPhi[2] ;
78  localPhi[0] = para.phiMin ;
79  localPhi[1] = para.phiMax ;
80 
81 // ftfLog ( " mergable track pt %f \n", tTrack->pt ) ;
82  double sinPhi, cosPhi, tanPhi ;
83  double a, b, c, b2minus4ac ;
84  double x1, y1, x2, y2, r1, r2 ;
85  c = xc * xc + yc * yc - rc * rc ;
86  for ( int i = 0 ; i < 2 ; i++ ) {
87  sinPhi = sin(localPhi[i]);
88  cosPhi = cos(localPhi[i]);
89  tanPhi = tan(localPhi[i]);
90  a = 1. + tanPhi * tanPhi ;
91  b = -2. * xc - 2. * yc * tanPhi ;
92 
93  b2minus4ac = b * b - 4. * a * c ;
94  if ( b2minus4ac > 0 ) {
95  double rootB2Minus4ac = ::sqrt(b2minus4ac);
96 
97  x1 = 0.5 * (-b + rootB2Minus4ac) / a ;
98  y1 = x1 * tanPhi ;
99  r1 = ::sqrt(x1*x1+y1*y1);
100 
101 // ftfLog ( " x1 y1 %e %e cos sin %e %e\n", x1, y1, cosPhi, sinPhi ) ;
102  double ratiox = 0 ;
103  if ( cosPhi != 0 ) ratiox = x1/cosPhi ;
104  double ratioy = 0 ;
105  if ( sinPhi != 0 ) ratiox = y1/sinPhi ;
106 // ftfLog ( " ratiox ratioy %e %e \n", ratiox, ratioy ) ;
107  if ( ratiox >= 0 && ratioy >= 0 &&
108  r1 > rTpcMin && r1 < rTpcMax ) {
109 // ftfLog ( "phi %f boundary crossed !!!!\n", localPhi[i] ) ;
110  return 1 ;
111  }
112 
113  x2 = 0.5 * (-b - rootB2Minus4ac) / a ;
114  y2 = x2 * tanPhi ;
115  r2 = ::sqrt(x2*x2+y2*y2);
116  ratiox = 0 ;
117  if ( cosPhi != 0 ) ratiox = x2/cosPhi ;
118  ratioy = 0 ;
119  if ( sinPhi != 0 ) ratioy = y2/sinPhi ;
120 // ftfLog ( " ratiox ratioy %e %e \n", ratiox, ratioy ) ;
121 // ftfLog ( " x2 y2 %e %e cos sin %e %e\n", x2, y2, cosPhi, sinPhi ) ;
122  if ( ratiox >= 0 && ratioy >= 0 &&
123  r2 > rTpcMin && r2 < rTpcMax ) {
124 // ftfLog ( "phi %f boundary crossed !!!!\n", localPhi[i] ) ;
125  return 1 ;
126  }
127  }
128 
129  }
130  //
131  // Check whether particle cross membrane
132  //
133  double zMembrane = 0 ;
134  double sToMembrane = (zMembrane - tTrack->z0 ) / tTrack->tanl ;
135  double dangle = sToMembrane / rc ;
136  double angle = dangle + trackPhi0 ;
137  double xMembrane = xc + rc * cos(angle) ;
138  double yMembrane = yc + rc * sin(angle) ;
139  double rMembrane = ::sqrt(xMembrane*xMembrane+yMembrane*yMembrane);
140  if ( rMembrane > rTpcMin && rMembrane < rTpcMax ) {
141 // ftfLog ( "Membrane crossed at r %f !!!!\n", rMembrane ) ;
142  return 1 ;
143  }
144 //
145  return 0 ;
146 }
147 //******************************************************************
148 // fill Hits
149 //******************************************************************
150 int FtfSl3::fillHits ( unsigned int maxBytes, char* buff, unsigned int token ) {
151 //
152 // Check enough space
153 //
154  if ( (nHits-1) * sizeof(l3_cluster) + sizeof(L3_SECCD) > maxBytes ) {
155  ftfLog ( "FtfSl3::fillHits: buffer with %d bytes too small \n", maxBytes ) ;
156  return 0 ;
157  }
158 //
159 // Loop over tracks
160 //
161  L3_SECCD* head = (L3_SECCD *)buff ;
162 
163  head->nrClusters_in_sector = nHits ;
164  // bankHeader
165  memcpy(head->bh.bank_type,CHAR_L3_SECCD,8);
166  head->bh.bank_id = sectorNr;
167  head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
168  head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
169  head->bh.format_number = 0;
170  head->bh.token = token;
171  head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
172  head->bh.crc = 0; //don't know yet....
173 
174 
175  l3_cluster* hitP = (l3_cluster *)(head->cluster);
176  FtfHit *nextHit ;
177  int i ;
178  int counter = 0 ;
179 
180 
181  for ( i = 0 ; i < nTracks ; i++ ) {
182  for ( nextHit = (FtfHit *)(track[i].firstHit) ;
183  nextHit != 0 ;
184  nextHit = (FtfHit *)nextHit->nextTrackHit) {
185  hitP->padrow = nextHit->row ;
186  hitP->pad = nextHit->buffer1 ;
187  hitP->time = nextHit->buffer2 ;
188  hitP->flags = nextHit->flags ;
189  hitP->charge = (short)nextHit->q ;
190  hitP->RB_MZ = (short)nextHit->hardwareId ;
191  hitP->trackId = track[i].id ;
192  if ( !(nextHit->track) ) {
193  ftfLog ( "FtfSl3:fillHits: we got a problem track %d row hit %d \n",
194  track[i].id, hitP->padrow ) ;
195  }
196  hitP++ ;
197  counter++ ;
198  }
199  }
200 //
201 // Loop over hits
202 //
203  for ( i = 0 ; i < nHits ; i++ ) {
204  nextHit = &(hit[i]) ;
205  if ( nextHit->track ) continue ;
206  hitP->padrow = nextHit->row ;
207  hitP->pad = nextHit->buffer1 ;
208  hitP->time = nextHit->buffer2 ;
209  hitP->flags = nextHit->flags ;
210  hitP->charge = (short)nextHit->q ;
211  hitP->RB_MZ = (short)nextHit->hardwareId ;
212  hitP->trackId = 0 ;
213  hitP++ ;
214  counter++ ;
215  }
216 
217  if ( counter != nHits ) {
218  ftfLog ( "FtfSl3:fillHits: Warning! Actual number of hits written %d total nHits %d \n",
219  counter, nHits );
220  }
221 
222  head->bh.length = ((char *)hitP-buff) / 4 ;
223 
224  return ((char *)hitP-buff) ;
225 }
226 //******************************************************************
227 // fill tracks
228 //******************************************************************
229 int FtfSl3::fillTracks ( int maxBytes, char* buff, unsigned int token ) {
230 //
231 // Loop over tracks
232 //
233  int counter = 0 ;
234 
235  counter = nTracks ;
236 //
237  // this is done to ease calcultion of offsets further down.
238  unsigned int headSize;
239 
240  if(counter)
241  headSize = sizeof(struct bankHeader);
242  else
243  headSize = 0;
244 
245 
246  char *pointer = buff + sizeof(struct L3_SECTP) ;
247 
248  char *endOfData = pointer + headSize
249  + counter * sizeof(struct local_track) ; // end
250 
251  int nBytes = (endOfData-buff) ;
252  if ( nBytes > maxBytes ) {
253  ftfLog ( "FtfSl3::fillTracks: %d bytes needed, %d max, too short a buffer \n ", nBytes, maxBytes ) ;
254  return -1 ;
255  }
256 //
257 // Fill header
258 //
259 
260  struct L3_SECTP *head = (struct L3_SECTP *)buff ;
261 
262  // bankHeader
263  // head->bh.bank_type = CHAR_L3_SECTP;
264  memcpy(head->bh.bank_type,CHAR_L3_SECTP,8);
265  head->bh.length = sizeof(struct L3_SECTP) / 4 ;
266  head->bh.bank_id = sectorNr;
267  head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
268  head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
269  head->bh.format_number = 1; // 1 means only pointing to local_tracks
270  head->bh.token = token;
271  head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
272  head->bh.crc = 0; //don't know yet....
273 
274  head->nHits = (unsigned int)nHits ;
275  head->nTracks = (unsigned int)nTracks ;
276  head->cpuTime = (unsigned int)rint(cpuTime * 1000000); // to get microsec
277  head->realTime = (unsigned int)rint(realTime * 1000000) ; // same here
278  head->xVert = (int)rint(para.xVertex * 1000000); // to get cm*10**-6
279  head->yVert = (int)rint(para.yVertex * 1000000);
280  head->zVert = (int)rint(para.zVertex * 1000000);
281  head->para = 1 ;
282  head->banks[0].off = (pointer-buff) / 4;
283  head->banks[0].len = (endOfData-pointer)/ 4 ;
284  head->banks[1].off = 0 ;
285  head->banks[1].len = 0 ;
286  head->banks[2].off = 0 ;
287  head->banks[2].len = 0 ;
288 
289 // done with L3_SECTP
290 
291 
292 // L3_STKXD banks:
293 
294  struct L3_LTD* LTD = (struct L3_LTD*)pointer;
295 
296  struct local_track* uSTrack =
297  (struct local_track *)(pointer + headSize) ;
298 
299 
300  if(headSize) {
301  memcpy(LTD->bh.bank_type, CHAR_L3_LTD, 8);
302  LTD->bh.length = (sizeof(struct bankHeader) +
303  counter * sizeof(local_track))/4 ;
304  LTD->bh.bank_id = sectorNr ;
305  LTD->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
306  LTD->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
307  LTD->bh.format_number = 0 ;
308  LTD->bh.token = token ;
309  LTD->bh.w9 = DAQ_RAW_FORMAT_WORD9 ;
310  LTD->bh.crc = 0; // for now!!!
311  }
312 //
313  for ( int i = 0 ; i < nTracks ; i++ ) {
314  //
315  uSTrack->id = track[i].id ;
316  if ( canItBeMerged ( &(track[i]) ) ) {
317  uSTrack->id *= -1 ;
318  }
319  uSTrack->nHits = track[i].nHits ;
320  uSTrack->ndedx = track[i].nDedx;
321  uSTrack->innerMostRow = track[i].innerMostRow ;
322  uSTrack->outerMostRow = track[i].outerMostRow ;
323  uSTrack->xy_chisq = (unsigned short)rint(10 * track[i].chi2[0]
324  /float(track[i].nHits));
325  uSTrack->sz_chisq = (unsigned short)rint(10 * track[i].chi2[1]
326  /float(track[i].nHits));
327  uSTrack->dedx = track[i].dedx ;
328  uSTrack->pt = track[i].pt * float(track[i].q * para.bFieldPolarity) ;
329  uSTrack->psi = track[i].psi ;
330  uSTrack->tanl = track[i].tanl ;
331  uSTrack->r0 = track[i].r0 ;
332  uSTrack->phi0 = track[i].phi0 ;
333  uSTrack->z0 = track[i].z0 ;
334  uSTrack->trackLength = track[i].length ;
335  uSTrack->dpt = (short)(32768. * track[i].dpt / track[i].pt ) ;
336  uSTrack->dpsi = track[i].CompressOver1(track[i].dpsi,track[i].psi);
337  uSTrack->dtanl = track[i].CompressOver1(64.*track[i].dtanl,track[i].tanl);
338  uSTrack->dz0 = (short)(1024. * track[i].dz0 ) ;
339  uSTrack++ ;
340  }
341 // delete array
342 
343 //
344  return nBytes ;
345 //
346 }
347 //******************************************************************
348 // get nr of tracks
349 //******************************************************************
350 int FtfSl3::getNrTracks (void) {
351  return nTracks;
352 }
353 //******************************************************************
354 // Initialize sl3 tracker
355 //******************************************************************
356 int FtfSl3::setup ( int maxHitsIn, int maxTracksIn ) {
357 //
358 // Set parameters
359 //
360  // ftfLog("setting up tracker\n");
361  para.setDefaults ( ) ;
362 //
363 // Set Parameters
364 //
365  setParameters ( ) ;
366 //
367 // Set sector geometry parameters
368 //
369  double toRad = acos(-1.)/180. ;
370  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
371  sectorG[ 0].phiMin = 45. * toRad ;
372  sectorG[ 1].phiMin = 15. * toRad ;
373  sectorG[ 2].phiMin = 345. * toRad ;
374  sectorG[ 3].phiMin = 315. * toRad ;
375  sectorG[ 4].phiMin = 285. * toRad ;
376  sectorG[ 5].phiMin = 255. * toRad ;
377  sectorG[ 6].phiMin = 225. * toRad ;
378  sectorG[ 7].phiMin = 195. * toRad ;
379  sectorG[ 8].phiMin = 165. * toRad ;
380  sectorG[ 9].phiMin = 135. * toRad ;
381  sectorG[10].phiMin = 105. * toRad ;
382  sectorG[11].phiMin = 75. * toRad ;
383  sectorG[12].phiMin = 105. * toRad ;
384  sectorG[13].phiMin = 135. * toRad ;
385  sectorG[14].phiMin = 165. * toRad ;
386  sectorG[15].phiMin = 195. * toRad ;
387  sectorG[16].phiMin = 225. * toRad ;
388  sectorG[17].phiMin = 255. * toRad ;
389  sectorG[18].phiMin = 285. * toRad ;
390  sectorG[19].phiMin = 315. * toRad ;
391  sectorG[20].phiMin = 345. * toRad ;
392  sectorG[21].phiMin = 15. * toRad ;
393  sectorG[22].phiMin = 45. * toRad ;
394  sectorG[23].phiMin = 75. * toRad ;
395 //
396  sectorG[ 0].phiMax = 75. * toRad ;
397  sectorG[ 1].phiMax = 45. * toRad ;
398  sectorG[ 2].phiMax = 15. * toRad ;
399  sectorG[ 3].phiMax = 345. * toRad ;
400  sectorG[ 4].phiMax = 315. * toRad ;
401  sectorG[ 5].phiMax = 285. * toRad ;
402  sectorG[ 6].phiMax = 255. * toRad ;
403  sectorG[ 7].phiMax = 225. * toRad ;
404  sectorG[ 8].phiMax = 195. * toRad ;
405  sectorG[ 9].phiMax = 165. * toRad ;
406  sectorG[10].phiMax = 135. * toRad ;
407  sectorG[11].phiMax = 105. * toRad ;
408  sectorG[12].phiMax = 135. * toRad ;
409  sectorG[13].phiMax = 165. * toRad ;
410  sectorG[14].phiMax = 195. * toRad ;
411  sectorG[15].phiMax = 225. * toRad ;
412  sectorG[16].phiMax = 255. * toRad ;
413  sectorG[17].phiMax = 285. * toRad ;
414  sectorG[18].phiMax = 315. * toRad ;
415  sectorG[19].phiMax = 345. * toRad ;
416  sectorG[20].phiMax = 15. * toRad ;
417  sectorG[21].phiMax = 45. * toRad ;
418  sectorG[22].phiMax = 75. * toRad ;
419  sectorG[23].phiMax = 105. * toRad ;
420 
421  double etaMin = 0.4 ;
422  double etaMax = 2.3 ;
423 
424  for ( int sector = 0 ; sector < NSECTORS ; sector++ ) {
425  sectorG[sector].phiShift = 0 ;
426  if ( sector < 12 ) {
427  sectorG[sector].etaMin = -1. * etaMin ;
428  sectorG[sector].etaMax = etaMax ;
429  }
430  else {
431  sectorG[sector].etaMin = -1. * etaMax ;
432  sectorG[sector].etaMax = etaMin ;
433  }
434  }
435  sectorG[ 2].phiShift = 16. * toRad ;
436  sectorG[20].phiShift = 16. * toRad ;
437 
438  // Reset tracker
439  reset ( ) ;
440 
441  // Allocate memory
442  maxHits = maxHitsIn ;
443  maxTracks = maxTracksIn ;
444  hit = new FtfHit[maxHits] ;
445  track = new FtfTrack[maxTracks] ;
446 
447  para.phiMin = 0.F * pi / 180.F ;
448  para.phiMax =360.F * pi / 180.F ;
449  para.etaMin =-0.4F ;
450  para.etaMax = 2.2F ;
451 #ifdef TRDEBUG
452  para.trackDebug = 24 ;
453  para.debugLevel = 1 ;
454 #endif
455  return 0;
456 }
457 
458 
459 //******************************************************************
460 // Read cluster data from TPCMZCLD bank (using daqFormats.h)
461 //
462 // returns number of hits from this mezzanine
463 //
464 //
465 // author: christof, derived from tonko's 'sl3'
466 // ppy: modified to look at byte order
467 //******************************************************************
468 //#define TRDEBUG
469 int FtfSl3::readMezzanine (int sector, int readOutBoard,
470  int mezzanninneNr, struct TPCMZCLD_local *mzcld) {
471 
472  unsigned int *tmp32;
473  int row, rows;
474  int len;
475  int i, j;
476  int counter;
477 
478  FtfHit *hitP = &hit[nHits];
479 
480  // Prepare transformation
481  St_l3_xyz_Coordinate XYZ(0,0,0) ;
482  St_l3_ptrs_Coordinate PTRS(0,0,0,0) ;
483 
484 
485  counter = 0;
486  short swapByte = 0 ;
487  if ( !checkByteOrder(mzcld->bh.byte_order) ) swapByte = 1 ;
488 
489  tmp32 = mzcld->padrowFiller ;
490 
491  rows = mzcld->rows;
492  if ( swapByte ) rows = swap32(rows);
493 
494  // ftfLog("FtfSl3::readMezzaninne: Found %d rows.\n",rows) ;
495 
496  for (i=0; i<rows; i++) {
497  row = *tmp32++ ;
498  len = *tmp32++ ;
499  if ( swapByte ) {
500  row = swap32(row);
501  len = swap32(len);
502  }
503  //ftfLog(" Row# %d: clusters %d\n",row,len) ;
504 
505  for ( j=0; j<len; j++) {
506  double fp, ft ;
507  unsigned short pad ;
508  unsigned short time ;
509 
510  struct xt {
511  unsigned short x ;
512  unsigned short t ;
513  } *xt ;
514  struct c {
515  unsigned short flags ;
516  unsigned short charge ;
517  } *c ;
518 
519  xt = (struct xt *) tmp32++ ;
520  c = (struct c *) tmp32++ ;
521 //
522 // Discard 1 pad clusters
523 // cs: discard one-pad cluster marked by the cluster finder as such (set first bit)
524  //ftfLog ( "flags %d \n", c->flags ) ;
525  if ( (c->flags & 1) == 1) continue;
526 
527 
528 
529  if ( !swapByte ) {
530  pad = xt->x ;
531  time = xt->t ;
532  }
533  else {
534  pad = swap16(xt->x) ;
535  time = swap16(xt->t) ;
536  }
537  fp = (double)pad / 64. ;
538  ft = (double)time/ 64. ;
539 
540 // Cut on timebins and clustercharge added by cle 02/21/00
541  if ( ft < minTimeBin ) continue ;
542  if ( ft > maxTimeBin ) continue ;
543  if ( c->charge < minClusterCharge ) continue ;
544  if ( c->charge > maxClusterCharge ) continue ;
545 #ifdef MDEBUG
546  ftfLog ( "FtfSl3:readMezzaninne row %d \n", row ) ;
547  ftfLog ( "ft %f min max %d %d \n", ft, minTimeBin, maxTimeBin ) ;
548  ftfLog ( "charge %d min max %d %d \n", c->charge, minClusterCharge, maxClusterCharge ) ;
549 #endif
550 //
551  // printf("sector:%i RB:%i pad: %f time: %f row: %i\n",sector, readOutBoard,fp,ft,row);
552  PTRS.Setptrs((double)fp, (double)ft,(double)row, (double)sector) ;
553 
554 // St_l3_xyz_Coordinate local;
555 // ((St_l3_Coordinate_Transformer *)coordinateTransformer)->raw_to_local(PTRS,local) ;
556 // ((St_l3_Coordinate_Transformer *)coordinateTransformer)->local_to_global(PTRS,local,XYZ) ;
557  ((St_l3_Coordinate_Transformer *)coordinateTransformer)->raw_to_global(PTRS,XYZ) ;
558 
559  hitP->id = nHits+counter ;
560  hitP->row = row ;
561  hitP->sector = sector ;
562 
563  hitP->x = (float) XYZ.Getx();
564  hitP->y = (float) XYZ.Gety();
565  hitP->z = (float) XYZ.Getz();
566 // ftfLog ( "x %f y %f z %f \n", hitP->x, hitP->y, hitP->z ) ;
567 
568  hitP->dx = xyError ;
569  hitP->dy = xyError ;
570  hitP->dz = zError ;
571  hitP->buffer1 = pad ;
572  hitP->buffer2 = time ;
573  if(embedded)
574  hitP->flags = (c->flags | (1<<7) );
575  else
576  hitP->flags = c->flags ;
577  hitP->q = c->charge ;
578  hitP->hardwareId = readOutBoard * 16 + mezzanninneNr ;
579 
580  hitP++;
581 
582  counter++;
583 
584  if ( (nHits+counter)>maxHits ) {
585  ftfLog ( "Error - FtfSl3:read: Hit array too small: counter %d maxHits %d \n",
586  counter, maxHits ) ;
587  return -1;
588  }
589  }
590  }
591  return counter;
592 }
593 
594 //******************************************************************
595 // Read Sector from buffer (using daqFormats.h)
596 //
597 //
598 // author: christof, derived from tonko's 'sl3'
599 // ppy: modified to look at byte order
600 //******************************************************************
601 int FtfSl3::readSector ( struct TPCSECLP *seclp ) {
602 
603  struct TPCRBCLP *rbclp ;
604  struct TPCMZCLD_local *mzcld ;
605  int iRb, kMz;
606  int sector;
607  int nHitsOfMz;
608  embedded = 0;
609 
610  // reset sector-hit counter
611  nHits = 0;
612  //
613  // check byte order of SECLP bank
614  // byte swapping is needed
615  short swapByte = 0 ;
616  if ( !checkByteOrder(seclp->bh.byte_order) ) swapByte = 1 ;
617 
618  nHitsOfMz = 0;
619 
620  sector = (unsigned int)seclp->bh.bank_id ;
621  if ( swapByte ) sector = swap32(sector) ;
622 
623  sectorNr = sector;
624  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
625  para.phiMin = sectorG[sector-1].phiMin ;
626  para.phiMax = sectorG[sector-1].phiMax ;
627  para.etaMin = sectorG[sector-1].etaMin ;
628  para.etaMax = sectorG[sector-1].etaMax ;
629 
630  // Check Sector
631  if ( sectorNr < 1 && sectorNr > 24 ) {
632  ftfLog ( "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
633  return -1 ;
634  }
635 
636  // run over receiver boards
637  for (iRb=0; iRb<SB_RB_NUM; iRb++) {
638 
639  if (iRb==6) {
640  sector++ ; // the other Sector
641  if ( sector == 4 ) {
642  para.phiMin = 0. ;
643  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
644  para.phiShift = 0.8 ; // ~45 degrees
645  }
646  else if ( sector == 22 ) {
647  para.phiMin = 0. ;
648  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
649  para.phiShift = 0.27 ; // ~15 degrees
650  }
651  else {
652  if ( sectorG[sector-1].phiMin < para.phiMin )
653  para.phiMin = sectorG[sector-1].phiMin ;
654  if ( sectorG[sector-1].phiMax > para.phiMax )
655  para.phiMax = sectorG[sector-1].phiMax ;
656  para.phiShift = 0 ;
657  }
658  if ( sectorG[sector-1].etaMin < para.etaMin )
659  para.etaMin = sectorG[sector-1].etaMin ;
660  if ( sectorG[sector-1].etaMax > para.etaMax )
661  para.etaMax = sectorG[sector-1].etaMax ;
662  }
663 
664  if ( !(unsigned int)seclp->rb[iRb].off) continue ;
665 
666  int off = (unsigned int)seclp->rb[iRb].off;
667  if ( swapByte ) off = swap32(off);
668  rbclp = (struct TPCRBCLP *)((char *)seclp + off * 4) ;
669  int swapByteMezzaninne = 0 ;
670  if ( !checkByteOrder(rbclp->bh.byte_order) ) swapByteMezzaninne = 1;
671 
672  // run over the 3 mezzanines
673  for (kMz=0; kMz<RB_MZ_NUM; kMz++) {
674 
675  if(rbclp->mz[kMz].off) {
676 #ifdef TRDEBUG
677  if ( debugLevel > 1 ) {
678  ftfLog ( "FtfSl3::readSector: MZCLD %d exists!\n",
679  kMz+1) ;
680  }
681 #endif
682  }
683  else continue ;
684 
685  off = rbclp->mz[kMz].off ;
686  if ( swapByteMezzaninne ) off = swap32(off);
687  // ftfLog ( "mezz %d off len %d %d \n",
688  // kMz, rbclp->mz[kMz].off, rbclp->mz[kMz].len ) ;
689  mzcld = (struct TPCMZCLD_local *) ((char *)rbclp + off*4) ;
690 
691  if (mzcld) {
692  nHitsOfMz = readMezzanine (sector, iRb, kMz, mzcld);
693  if (nHitsOfMz<0) {
694  ftfLog ( "FtfSl3:readSector: wrong reading mezzanine \n" ) ;
695  return -1;
696  }
697  nHits += nHitsOfMz;
698  }
699 
700  }
701  }
702  //
703  // Since phiMin/Max etaMin/etaMax may have changed reset tracker
704  //
705  reset();
706  //
707  return 0;
708 }
709 
710 
711 
712 
713 
714 
715 
716 
717 
718 
719 //******************************************************************
720 // Read Sector from buffer (using daqFormats.h)
721 //
722 // function to read in 2 sectors from different event and merge them
723 // to be able to embed one event into another one
724 //
725 //
726 //******************************************************************
727 int FtfSl3::readSector ( struct TPCSECLP *seclp1, struct TPCSECLP *seclp2 ) {
728 
729  struct TPCRBCLP *rbclp ;
730  struct TPCMZCLD_local *mzcld ;
731  int iRb, kMz;
732  int sector,tmpsector;
733  int nHitsOfMz;
734  struct TPCSECLP *seclp; // 'generic' sector pointer
735  short swapByte ;
736 
737  // reset sector-hit counter
738  nHits = 0;
739  //
740  // check byte order of SECLP bank
741  // byte swapping is needed
742  short swapByte1 = 0 ;
743  short swapByte2 = 0;
744  if ( !checkByteOrder(seclp1->bh.byte_order) ) swapByte1 = 1 ;
745  if ( !checkByteOrder(seclp2->bh.byte_order) ) swapByte2 = 1 ;
746 
747  // nHitsOfMz = 0;
748 
749  sector = (unsigned int)seclp1->bh.bank_id ;
750  if ( swapByte1 ) sector = swap32(sector) ;
751  tmpsector = (unsigned int)seclp2->bh.bank_id ;
752  if ( swapByte2 ) tmpsector = swap32(tmpsector) ;
753  // check that both sectors are consistent
754  if(tmpsector != sector){
755  ftfLog("Error in embedding got different sectors to read in\n");
756  exit(1);
757  }
758  //ftfLog("sector: %i\n",sector);
759 
760  sectorNr = sector;
761  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
762  para.phiMin = sectorG[sector-1].phiMin ;
763  para.phiMax = sectorG[sector-1].phiMax ;
764  para.etaMin = sectorG[sector-1].etaMin ;
765  para.etaMax = sectorG[sector-1].etaMax ;
766  //
767  // Check Sector
768  //
769  if ( sectorNr < 0 && sectorNr > 24 ) {
770  ftfLog ( "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
771  return -1 ;
772  }
773 
774  seclp = seclp1;
775  swapByte = swapByte1;
776  embedded = 0;
777 
778  for(int embed=0;embed<2;embed++){
779  // two loops first set the pointers to event one then after that is
780  // done to event 2, at end of for loop
781 
782 
783  // run over receiver boards
784  for (iRb=0; iRb<SB_RB_NUM; iRb++) {
785 
786  if (iRb==6) {
787  sector++ ; // the other Sector
788  if ( sector == 4 ) {
789  para.phiMin = 0. ;
790  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
791  para.phiShift = 0.8 ; // ~45 degrees
792  }
793  else if ( sector == 22 ) {
794  para.phiMin = 0. ;
795  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
796  para.phiShift = 0.27 ; // ~15 degrees
797  }
798  else {
799  if ( sectorG[sector-1].phiMin < para.phiMin ) para.phiMin = sectorG[sector-1].phiMin ;
800  if ( sectorG[sector-1].phiMax > para.phiMax ) para.phiMax = sectorG[sector-1].phiMax ;
801  para.phiShift = 0 ;
802  }
803  if ( sectorG[sector-1].etaMin < para.etaMin ) para.etaMin = sectorG[sector-1].etaMin ;
804  if ( sectorG[sector-1].etaMax > para.etaMax ) para.etaMax = sectorG[sector-1].etaMax ;
805  }
806  //ftfLog ( "sector %d rb %d phi min/max %f %f \n", sector, iRb, para.phiMin, para.phiMax ) ;
807 
808 
809  if ( !(unsigned int)seclp->rb[iRb].off) continue ;
810 
811  int off = (unsigned int)seclp->rb[iRb].off;
812  if ( swapByte ) off = swap32(off);
813  rbclp = (struct TPCRBCLP *)((char *)seclp + off * 4) ;
814  int swapByteMezzaninne = 0 ;
815  if ( !checkByteOrder(rbclp->bh.byte_order) ) swapByteMezzaninne = 1 ;
816 
817  // run over the 3 mezzanines
818  for (kMz=0; kMz<RB_MZ_NUM; kMz++) {
819 
820  if(rbclp->mz[kMz].off) {
821 #ifdef TRDEBUG
822  if ( debugLevel > 1 ) {
823  ftfLog ( "FtfSl3::readSector: MZCLD %d exists!\n", kMz+1) ;
824  }
825 #endif
826  }
827  else continue ;
828 
829  off = rbclp->mz[kMz].off ;
830  if ( swapByteMezzaninne ) off = swap32(off);
831  // ftfLog ( "mezz %d off len %d %d \n",
832  // kMz, rbclp->mz[kMz].off, rbclp->mz[kMz].len ) ;
833  mzcld = (struct TPCMZCLD_local *) ((char *)rbclp + off*4) ;
834 
835  if (mzcld) {
836  nHitsOfMz = readMezzanine (sector, iRb, kMz, mzcld);
837  if (nHitsOfMz<0) {
838  ftfLog ( "FtfSl3:readSector: wrong reading mezzanine \n" ) ;
839  return -1;
840  }
841  nHits += nHitsOfMz;
842  }
843 
844  }
845  }
846 
847  seclp = seclp2;
848  swapByte = swapByte2;
849  embedded = 1;
850  // reset sector
851  sector = sectorNr;
852  }
853 
854  //
855  // Since phiMin/Max etaMin/etaMax may have changed reset tracker
856  //
857  reset();
858  //
859  return 0;
860 }
861 
862 
863 
864 
865 
866 
867 
868 //*******************************************************************
869 // Process
870 //*******************************************************************
871 int FtfSl3::processSector ( ){
872  //
873  // Reset hit track assignment
874  //
875  for ( int h = 0 ; h < nHits ; h++ ) {
876  hit[h].track = 0 ;
877  }
878  para.eventReset = 1 ;
879  nTracks = 0 ;
880  process ( ) ;
881  if (para.dEdx) dEdx();
882  //
883  if ( debugLevel > 0 )
884  ftfLog ( " FtfSl3::process: tracks %i Time: real %f cpu %f\n",
885  nTracks, realTime, cpuTime ) ;
886  //
887  //
888  return 1;
889 }
890 
891 //********************************************************************
892 // Calculates deposited Energy
893 //********************************************************************
894 int FtfSl3::dEdx ( ) {
895 
896  for ( int i = 0 ; i<nTracks ; i++ ){
897  if (track[i].nHits<para.minHitsForDedx) {
898  track[i].nDedx = 0;
899  track[i].dedx = 0;
900  continue;
901  }
902  fDedx->TruncatedMean(&track[i]);
903  }
904  return 0;
905 }
906 //***************************************************************
907 // Set Default parameters
908 //***************************************************************
909 int FtfSl3::setParameters ( ) {
910 
911  // FtfPara* para = &(para) ;
912 
913  xyError = 0.3 ;
914  zError = 1.0 ;
915  para.hitChi2Cut = 50.F ;
916  para.goodHitChi2 = 10.F ;
917  para.trackChi2Cut = 30.F ;
918  para.maxChi2Primary = 0. ;
919  para.segmentRowSearchRange = 2 ;
920  para.trackRowSearchRange = 3 ;
921  para.dphi = 0.08F ;
922  para.deta = 0.08F ;
923  para.dphiMerge = 0.01F ;
924  para.detaMerge = 0.02F ;
925  para.etaMinTrack = -2.2F ;
926  para.etaMaxTrack = 2.2F ;
927 
928  para.dEdx = 1 ;
929  // get Errors = 1 makes FPE's
930  para.getErrors = 0 ;
931  para.goBackwards = 1 ;
932  para.goodDistance = 5.F ;
933  para.mergePrimaries = 0 ;
934  para.maxDistanceSegment = 50.F ;
935  para.minHitsPerTrack = 5 ;
936  para.nHitsForSegment = 2 ;
937  para.nEta = 40 ;
938  para.nEtaTrack = 40 ;
939  para.nPhi = 10 ;
940  para.nPhiTrack = 40 ;
941  para.nPrimaryPasses = 1 ;
942  para.nSecondaryPasses = 0 ;
943  para.xyErrorScale = 1.0F ;
944  para.szErrorScale = 1.0F ;
945  para.phiClosed = 0 ;
946 
947 // para.ptMinHelixFit = 100.F ;
948  para.ptMinHelixFit = 0. ;
949  para.rVertex = 0.F ;
950  para.xVertex = 0.F ;
951  para.yVertex = 0.F ;
952  para.zVertex = 0.F ;
953  para.dxVertex = 0.005F ;
954  para.dyVertex = 0.005F ;
955  para.phiVertex = 0.F ;
956 
957  para.zMax = 205. ;
958  return 0;
959 }
960 
961 
962 
963 
964 
Definition: FtfHit.h:16