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 **: l3CoordinateTransformer
47 **: jul 12, 2000 ppy get rid of mergeFlag in fillTracks (not used)
48 **: aug 21, 2000 ppy replace printf with l3Log
49 **: aug 10, 2001 ppy get rid of bFieldPolarity, this should be handle somewhere else
50 **:<------------------------------------------------------------------*/
51 
52 
53 #ifndef TRG_VERSION
54 #define TRG_VERSION 0x32
55 #endif
56 
57 #include <stdlib.h>
58 #include "FtfSl3.h"
59 #include "rts.h"
60 #include "l3Swap.h"
61 #include "fcfClass.hh"
62 #ifdef OLD_DAQ_READER
63 #include <evpReader.hh>
64 #else /* OLD_DAQ_READER */
65 #include <DAQ_READER/daqReader.h>
66 #include <DAQ_READER/daq_dta.h>
67 #endif /* OLD_DAQ_READER */
68 #include <rtsSystems.h>
69 #include <daqFormats.h>
70 #ifndef OLD_DAQ_READER
71 #include <DAQ_TPC/daq_tpc.h>
72 #include "gl3Event.h"
73 
74 extern tpc_t *pTPC;
75 #endif /* OLD_DAQ_READER */
76 
77 //******************************************************************
78 // Check whether tracs are mergable
79 //******************************************************************
80 int FtfSl3::canItBeMerged ( FtfTrack* tTrack ) {
81  double rTpcMin = 50. ;
82  double rTpcMax = 210. ;
83 
84  if ( nHits < 15 ) return 0 ;
85 //
86 // Get circle parameters
87 //
88 // double rc = tTrack->pt / ( 2.9979e-3 * para.bField );
89 // double xc = para.xVertex - tTrack->a2Xy / ( 2. * tTrack->a1Xy ) ;
90 // double yc = para.yVertex - 1. / ( 2. * tTrack->a1Xy ) ;
91  double x0 = tTrack->r0 * cos (tTrack->phi0);
92  double y0 = tTrack->r0 * sin (tTrack->phi0);
93  double rc = tTrack->pt / (bFactor * para.bField);
94  double trackPhi0 = tTrack->psi + tTrack->q * 0.5 * M_PI / fabs ((double) tTrack->q);
95  double xc = x0 - rc * cos (trackPhi0);
96  double yc = y0 - rc * sin (trackPhi0);
97 //
98 // Calculate intersection with tracking area (sector or supersector) boundaries
99 //
100  double localPhi[2] ;
101  localPhi[0] = para.phiMin ;
102  localPhi[1] = para.phiMax ;
103 
104 // l3Log ( " mergable track pt %f \n", tTrack->pt ) ;
105  double sinPhi, cosPhi, tanPhi ;
106  double a, b, c, b2minus4ac ;
107  double x1, y1, x2, y2, r1, r2 ;
108  c = xc * xc + yc * yc - rc * rc ;
109  for ( int i = 0 ; i < 2 ; i++ ) {
110  sinPhi = sin(localPhi[i]);
111  cosPhi = cos(localPhi[i]);
112  tanPhi = tan(localPhi[i]);
113  a = 1. + tanPhi * tanPhi ;
114  b = -2. * xc - 2. * yc * tanPhi ;
115 
116  b2minus4ac = b * b - 4. * a * c ;
117  if ( b2minus4ac > 0 ) {
118  double rootB2Minus4ac = sqrt(b2minus4ac);
119 
120  x1 = 0.5 * (-b + rootB2Minus4ac) / a ;
121  y1 = x1 * tanPhi ;
122  r1 = sqrt(x1*x1+y1*y1);
123 
124 // l3Log ( " x1 y1 %e %e cos sin %e %e\n", x1, y1, cosPhi, sinPhi ) ;
125  double ratiox = 0 ;
126  if ( cosPhi != 0 ) ratiox = x1/cosPhi ;
127  double ratioy = 0 ;
128  if ( sinPhi != 0 ) ratiox = y1/sinPhi ;
129 // l3Log ( " ratiox ratioy %e %e \n", ratiox, ratioy ) ;
130  if ( ratiox >= 0 && ratioy >= 0 &&
131  r1 > rTpcMin && r1 < rTpcMax ) {
132 // l3Log ( "phi %f boundary crossed !!!!\n", localPhi[i] ) ;
133  return 1 ;
134  }
135 
136  x2 = 0.5 * (-b - rootB2Minus4ac) / a ;
137  y2 = x2 * tanPhi ;
138  r2 = sqrt(x2*x2+y2*y2);
139  ratiox = 0 ;
140  if ( cosPhi != 0 ) ratiox = x2/cosPhi ;
141  ratioy = 0 ;
142  if ( sinPhi != 0 ) ratioy = y2/sinPhi ;
143 // l3Log ( " ratiox ratioy %e %e \n", ratiox, ratioy ) ;
144 // l3Log ( " x2 y2 %e %e cos sin %e %e\n", x2, y2, cosPhi, sinPhi ) ;
145  if ( ratiox >= 0 && ratioy >= 0 &&
146  r2 > rTpcMin && r2 < rTpcMax ) {
147 // l3Log ( "phi %f boundary crossed !!!!\n", localPhi[i] ) ;
148  return 1 ;
149  }
150  }
151 
152  }
153  //
154  // Check whether particle cross membrane
155  //
156  double zMembrane = 0 ;
157  double sToMembrane = (zMembrane - tTrack->z0 ) / tTrack->tanl ;
158  double dangle = sToMembrane / rc ;
159  double angle = dangle + trackPhi0 ;
160  double xMembrane = xc + rc * cos(angle) ;
161  double yMembrane = yc + rc * sin(angle) ;
162  double rMembrane = sqrt(xMembrane*xMembrane+yMembrane*yMembrane);
163  if ( rMembrane > rTpcMin && rMembrane < rTpcMax ) {
164 // l3Log ( "Membrane crossed at r %f !!!!\n", rMembrane ) ;
165  return 1 ;
166  }
167 //
168  return 0 ;
169 }
170 //******************************************************************
171 // fill Hits
172 //******************************************************************
173 int FtfSl3::fillHits ( unsigned int maxBytes, char* buff, unsigned int token ) {
174 //
175 // Check enough space
176 //
177  if ( (nHits-1) * sizeof(l3_cluster) + sizeof(L3_SECCD) > maxBytes ) {
178  LOG (ERR, "FtfSl3::fillHits: buffer with %d bytes too small \n", maxBytes ) ;
179  return 0 ;
180  }
181 //
182 // Loop over tracks
183 //
184  L3_SECCD* head = (L3_SECCD *)buff ;
185 
186  head->nrClusters_in_sector = nHits ;
187  // bankHeader
188  memcpy(head->bh.bank_type,CHAR_L3_SECCD,8);
189  head->bh.bank_id = sectorNr;
190  head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
191  head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
192  head->bh.format_number = 0;
193  head->bh.token = token;
194  head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
195  head->bh.crc = 0; //don't know yet....
196 
197 
198  l3_cluster* hitP = (l3_cluster *)(head->cluster);
199  FtfHit *nextHit ;
200  int i ;
201  int counter = 0 ;
202 
203 
204  for ( i = 0 ; i < nTracks ; i++ ) {
205  for ( nextHit = (FtfHit *)(track[i].firstHit) ;
206  nextHit != 0 ;
207  nextHit = (FtfHit *)nextHit->nextTrackHit) {
208  hitP->padrow = nextHit->row ;
209  hitP->pad = nextHit->buffer1 ;
210  hitP->time = nextHit->buffer2 ;
211  hitP->flags = nextHit->flags ;
212  hitP->charge = (short)nextHit->q ;
213  hitP->RB_MZ = (short)nextHit->hardwareId ;
214  hitP->trackId = track[i].id ;
215  if ( !(nextHit->track) ) {
216  LOG (ERR, "FtfSl3:fillHits: we got a problem track %d row hit %d \n",
217  track[i].id, hitP->padrow ) ;
218  }
219  hitP++ ;
220  counter++ ;
221  }
222  }
223 //
224 // Loop over hits
225 //
226  for ( i = 0 ; i < nHits ; i++ ) {
227  nextHit = &(hit[i]) ;
228  if ( nextHit->track ) continue ;
229  hitP->padrow = nextHit->row ;
230  hitP->pad = nextHit->buffer1 ;
231  hitP->time = nextHit->buffer2 ;
232  hitP->flags = nextHit->flags ;
233  hitP->charge = (short)nextHit->q ;
234  hitP->RB_MZ = (short)nextHit->hardwareId ;
235  hitP->trackId = 0 ;
236  hitP++ ;
237  counter++ ;
238  }
239 
240  if ( counter != nHits ) {
241  LOG (ERR, "FtfSl3:fillHits: Warning! Actual number of hits written %d total nHits %d \n",
242  counter, nHits );
243  }
244 
245  head->bh.length = ((char *)hitP-buff) / 4 ;
246 
247  return ((char *)hitP-buff) ;
248 }
249 //******************************************************************
250 // fill tracks
251 //******************************************************************
252 int FtfSl3::fillTracks ( int maxBytes, char* buff, unsigned int token ) {
253 
254 
255  if(buff == NULL) {
256  LOG(ERR,"ERROR: trying to fill NULL buffer");
257  return 0;
258  }
259 
260  LOG(DBG, "fill nTracks = %d", nTracks);
261  int counter = nTracks ;
262 
263  unsigned int headSize;
264 
265  if(counter)
266  headSize = sizeof(struct bankHeader);
267  else
268  headSize = 0;
269 
270 
271  char *pointer = buff + sizeof(struct L3_SECTP) ;
272 
273  char *endOfData = pointer + headSize
274  + counter * sizeof(struct local_track) ; // end
275 
276  int nBytes = (endOfData-buff) ;
277  if ( nBytes > maxBytes ) {
278  LOG(ERR, "FtfSl3::fillTracks: %d bytes needed, %d max, too short a buffer \n ",
279  nBytes, maxBytes ) ;
280  return -1 ;
281  }
282 //
283 // Fill header
284 //
285 
286  struct L3_SECTP *head = (struct L3_SECTP *)buff ;
287 
288  // bankHeader
289  // head->bh.bank_type = CHAR_L3_SECTP;
290  memcpy(head->bh.bank_type,CHAR_L3_SECTP,8);
291  head->bh.length = sizeof(struct L3_SECTP) / 4 ;
292  head->bh.bank_id = sectorNr;
293  LOG(DBG, "set bank_id to %d", sectorNr);
294  head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
295  head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
296  head->bh.format_number = 1; // 1 means only pointing to local_tracks
297  head->bh.token = token;
298  head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
299  head->bh.crc = 0; //don't know yet....
300 
301  head->nHits = (unsigned int)nHits ;
302  head->nTracks = (unsigned int)nTracks ;
303  head->cpuTime = (unsigned int)rint(cpuTime * 1000000); // to get microsec
304  head->realTime = (unsigned int)rint(realTime * 1000000) ; // same here
305  head->xVert = (int)rint(para.xVertex * 1000000); // to get cm*10**-6
306  head->yVert = (int)rint(para.yVertex * 1000000);
307  head->zVert = (int)rint(para.zVertex * 1000000);
308  head->para = 1 ;
309  head->banks[0].off = (pointer-buff) / 4;
310  head->banks[0].len = (endOfData-pointer)/ 4 ;
311  head->banks[1].off = 0 ;
312  head->banks[1].len = 0 ;
313  head->banks[2].off = 0 ;
314  head->banks[2].len = 0 ;
315 
316 // done with L3_SECTP
317 
318 
319 // L3_STKXD banks:
320 
321  struct L3_LTD* LTD = (struct L3_LTD*)pointer;
322 
323  struct local_track* uSTrack =
324  (struct local_track *)(pointer + headSize) ;
325 
326 
327  if(headSize) {
328  memcpy(LTD->bh.bank_type, CHAR_L3_LTD, 8);
329  LTD->bh.length = (sizeof(struct bankHeader) +
330  counter * sizeof(local_track))/4 ;
331  LTD->bh.bank_id = sectorNr ;
332  LTD->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
333  LTD->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
334  LTD->bh.format_number = 0 ;
335  LTD->bh.token = token ;
336  LTD->bh.w9 = DAQ_RAW_FORMAT_WORD9 ;
337  LTD->bh.crc = 0; // for now!!!
338  }
339 //
340  for ( int i = 0 ; i < nTracks ; i++ ) {
341  //
342  uSTrack->id = track[i].id ;
343  if ( canItBeMerged ( &(track[i]) ) ) {
344  uSTrack->id *= -1 ;
345  }
346  uSTrack->nHits = track[i].nHits ;
347  uSTrack->ndedx = track[i].nDedx;
348  uSTrack->innerMostRow = track[i].innerMostRow ;
349  uSTrack->outerMostRow = track[i].outerMostRow ;
350  uSTrack->xy_chisq = (unsigned short)rint(10 * track[i].chi2[0]
351  /float(track[i].nHits));
352  uSTrack->sz_chisq = (unsigned short)rint(10 * track[i].chi2[1]
353  /float(track[i].nHits));
354  uSTrack->dedx = track[i].dedx ;
355  uSTrack->pt = track[i].pt * float(track[i].q) ;
356  uSTrack->psi = track[i].psi ;
357  uSTrack->tanl = track[i].tanl ;
358  uSTrack->r0 = track[i].r0 ;
359  uSTrack->phi0 = track[i].phi0 ;
360  uSTrack->z0 = track[i].z0 ;
361  uSTrack->trackLength = track[i].length ;
362  uSTrack->dpt = (short)(32768. * track[i].dpt / track[i].pt ) ;
363  uSTrack->dpsi = track[i].CompressOver1(track[i].dpsi,track[i].psi);
364  uSTrack->dtanl = track[i].CompressOver1(64.*track[i].dtanl,track[i].tanl);
365  uSTrack->dz0 = (short)(1024. * track[i].dz0 ) ;
366 
367 // if (uSTrack->trackLength < 0) {
368 // printf("ERROR: writing tracks(sl3): length = %f < 0\n",
369 // uSTrack->trackLength);
370 // }
371 
372  uSTrack++ ;
373  }
374 // delete array
375 
376 //
377  return nBytes ;
378 //
379 }
380 //******************************************************************
381 // get nr of tracks
382 //******************************************************************
383 int FtfSl3::getNrTracks (void) {
384  return nTracks;
385 }
386 //******************************************************************
387 // Initialize sl3 tracker
388 //******************************************************************
389 int FtfSl3::setup ( int maxHitsIn, int maxTracksIn ) {
390 //
391 // Set parameters
392 //
393  // l3Log("setting up tracker\n");
394  para.setDefaults ( ) ;
395 //
396 // Set Parameters
397 //
398  setParameters ( ) ;
399 //
400 // Set sector geometry parameters
401 //
402  double toRad = acos(-1.)/180. ;
403  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
404  sectorG[ 0].phiMin = 45. * toRad ;
405  sectorG[ 1].phiMin = 15. * toRad ;
406  sectorG[ 2].phiMin = 345. * toRad ;
407  sectorG[ 3].phiMin = 315. * toRad ;
408  sectorG[ 4].phiMin = 285. * toRad ;
409  sectorG[ 5].phiMin = 255. * toRad ;
410  sectorG[ 6].phiMin = 225. * toRad ;
411  sectorG[ 7].phiMin = 195. * toRad ;
412  sectorG[ 8].phiMin = 165. * toRad ;
413  sectorG[ 9].phiMin = 135. * toRad ;
414  sectorG[10].phiMin = 105. * toRad ;
415  sectorG[11].phiMin = 75. * toRad ;
416  sectorG[12].phiMin = 105. * toRad ;
417  sectorG[13].phiMin = 135. * toRad ;
418  sectorG[14].phiMin = 165. * toRad ;
419  sectorG[15].phiMin = 195. * toRad ;
420  sectorG[16].phiMin = 225. * toRad ;
421  sectorG[17].phiMin = 255. * toRad ;
422  sectorG[18].phiMin = 285. * toRad ;
423  sectorG[19].phiMin = 315. * toRad ;
424  sectorG[20].phiMin = 345. * toRad ;
425  sectorG[21].phiMin = 15. * toRad ;
426  sectorG[22].phiMin = 45. * toRad ;
427  sectorG[23].phiMin = 75. * toRad ;
428 //
429  sectorG[ 0].phiMax = 75. * toRad ;
430  sectorG[ 1].phiMax = 45. * toRad ;
431  sectorG[ 2].phiMax = 15. * toRad ;
432  sectorG[ 3].phiMax = 345. * toRad ;
433  sectorG[ 4].phiMax = 315. * toRad ;
434  sectorG[ 5].phiMax = 285. * toRad ;
435  sectorG[ 6].phiMax = 255. * toRad ;
436  sectorG[ 7].phiMax = 225. * toRad ;
437  sectorG[ 8].phiMax = 195. * toRad ;
438  sectorG[ 9].phiMax = 165. * toRad ;
439  sectorG[10].phiMax = 135. * toRad ;
440  sectorG[11].phiMax = 105. * toRad ;
441  sectorG[12].phiMax = 135. * toRad ;
442  sectorG[13].phiMax = 165. * toRad ;
443  sectorG[14].phiMax = 195. * toRad ;
444  sectorG[15].phiMax = 225. * toRad ;
445  sectorG[16].phiMax = 255. * toRad ;
446  sectorG[17].phiMax = 285. * toRad ;
447  sectorG[18].phiMax = 315. * toRad ;
448  sectorG[19].phiMax = 345. * toRad ;
449  sectorG[20].phiMax = 15. * toRad ;
450  sectorG[21].phiMax = 45. * toRad ;
451  sectorG[22].phiMax = 75. * toRad ;
452  sectorG[23].phiMax = 105. * toRad ;
453 //
454  double etaMin = 0.4 ;
455  double etaMax = 2.3 ;
456 //
457  for ( int sector = 0 ; sector < 24 ; sector++ ) {
458  sectorG[sector].phiShift = 0 ;
459  if ( sector < 12 ) {
460  sectorG[sector].etaMin = -1. * etaMin ;
461  sectorG[sector].etaMax = etaMax ;
462  }
463  else {
464  sectorG[sector].etaMin = -1. * etaMax ;
465  sectorG[sector].etaMax = etaMin ;
466  }
467  }
468  sectorG[ 2].phiShift = 16. * toRad ;
469  sectorG[20].phiShift = 16. * toRad ;
470 //
471 // Reset tracker
472 //
473  reset ( ) ;
474 //
475 // Allocate memory
476 //
477  maxHits = maxHitsIn ;
478  maxTracks = maxTracksIn ;
479  hit = new FtfHit[maxHits] ;
480  track = new FtfTrack[maxTracks] ;
481 //
482  para.phiMin = 0.F * pi / 180.F ;
483  para.phiMax =360.F * pi / 180.F ;
484  para.etaMin =-0.4F ;
485  para.etaMax = 2.2F ;
486 #ifdef TRDEBUG
487  para.trackDebug = 24 ;
488  para.debugLevel = 1 ;
489 #endif
490  return 0;
491 }
492 //******************************************************************
493 // Read cluster data from TPCMZCLD bank (using daqFormats.h)
494 //
495 // returns number of hits from this mezzanine
496 //
497 //
498 // author: christof, derived from tonko's 'sl3'
499 // ppy: modified to look at byte order
500 //******************************************************************
501 //#define TRDEBUG
502 int FtfSl3::readMezzanine (int sector, int readOutBoard,
503  int mezzanninneNr, struct TPCMZCLD_local *mzcld) {
504 
505  unsigned int *tmp32;
506  int row, rows;
507  int len;
508  int i, j;
509  int counter;
510 
511  if(mzcld->bh.length <= 10) {
512  return 0;
513  }
514 
515 
516  FtfHit *hitP = &hit[nHits];
517 
518  // Prepare transformation
519  l3xyzCoordinate XYZ(0,0,0) ;
520  l3ptrsCoordinate PTRS(0,0,0,0) ;
521 
522 
523  counter = 0;
524  short swapByte = 0 ;
525  if ( !checkByteOrder(mzcld->bh.byte_order) ) swapByte = 1 ;
526 
527  tmp32 = mzcld->padrowFiller ;
528 
529  rows = mzcld->rows;
530  if ( swapByte ) rows = swap32(rows);
531 
532  // LOG(ERR, "FtfSl3::readMezzaninne: Found %d rows.\n",rows) ;
533 
534  for (i=0; i<rows; i++) {
535  row = *tmp32++ ;
536  len = *tmp32++ ;
537  if ( swapByte ) {
538  row = swap32(row);
539  len = swap32(len);
540  }
541  //l3Log(" Row# %d: clusters %d\n",row,len) ;
542 
543  if (len == 0) {
544  // No data in this row, go to next row
545  continue;
546  }
547 
548 
549  if((row<0) || (row>45)){
550  LOG(ERR, "ERROR: row (%i) is wrong in TPCMZCLD, len=%d\n",
551  row,len);
552  continue;
553  }
554 
555  for ( j=0; j<len; j++) {
556  double fp, ft ;
557  unsigned short pad ;
558  unsigned short time ;
559  unsigned short charge;
560  unsigned short fla;
561 
562  unsigned short flags = 0;
563 
564  //l3Log("FtfSl3: Read cluster %i\n", j);
565 
566  struct xt {
567  unsigned short x ;
568  unsigned short t ;
569  } *xt ;
570  struct c {
571  unsigned short flags ;
572  unsigned short charge ;
573  } *c ;
574 
575  xt = (struct xt *) tmp32++ ;
576  c = (struct c *) tmp32++ ;
577  //
578  // Discard 1 pad clusters
579  // cs: discard one-pad cluster marked by the cluster finder as such (set first bit)
580  //l3Log ( "flags %d \n", c->flags ) ;
581  //if ( (c->flags & 1) == 1) continue;
582 
583  if ( !swapByte ) {
584  pad = xt->x ;
585  time = xt->t ;
586 
587  fla = c->flags ;
588  charge = c->charge ;
589  }
590  else {
591  pad = swap16(xt->x) ;
592  time = swap16(xt->t) ;
593 
594  fla = swap16(c->flags) ;
595  charge = swap16(c->charge) ;
596  }
597 
598 
599  // TODO: extract some flags from pad and time
600  if(pad & 0x8000) flags |= FCF_DOUBLE_PAD ;
601  if(pad & 0x4000) flags |= FCF_DEAD_EDGE ;
602  if(time & 0x8000) flags |= FCF_ONEPAD ;
603  if(fla & 0x8000) flags |= FCF_ROW_EDGE ;
604  if(fla & 0x4000) flags |= FCF_BROKEN_EDGE ;
605 
606  pad &= 0x3FFF;
607  time &= 0x7FFF;
608 
609  fp = (double)pad / 64. ;
610  ft = (double)time/ 64. ;
611 
612 
613  LOG(DBG, "**************************************MZ*********************************");
614  // Cut on timebins and clustercharge added by cle 02/21/00
615  if ( ft < minTimeBin ) continue ;
616  if ( ft > maxTimeBin ) continue ;
617  if ( c->charge < minClusterCharge ) continue ;
618  if ( c->charge > maxClusterCharge ) continue ;
619  //#define MDEBUG
620 #ifdef MDEBUG
621  LOG(ERR, "FtfSl3:readMezzaninne row %d \n", row ) ;
622  LOG (ERR, "ft %f min max %d %d \n", ft, minTimeBin, maxTimeBin ) ;
623  LOG (ERR "charge %d min max %d %d \n", c->charge, minClusterCharge, maxClusterCharge ) ;
624 #endif
625  //
626  //l3Log("sector:%i RB:%i pad: %f time: %f row: %i\n",
627  //sector, readOutBoard,fp,ft,row);
628  //if((sector == 1)) {
629  // printf("cl old: %4.2f %4.2f %f %f\n",fp, ft, (float)row, (float)sector);
630  //}
631 
632 
633 
634  PTRS.Setptrs((double)fp, (double)ft,(double)row, (double)sector) ;
635  getCoordinateTransformer()->raw_to_global(PTRS,XYZ) ;
636 
637  //printf("hitP = 0x%x\n",hitP);
638 
639  hitP->id = nHits+counter ;
640  hitP->row = row ;
641  hitP->sector = sector ;
642 
643  hitP->x = (float) XYZ.Getx();
644  hitP->y = (float) XYZ.Gety();
645  hitP->z = (float) XYZ.Getz();
646  // l3Log ( "x %f y %f z %f \n", hitP->x, hitP->y, hitP->z ) ;
647 
648  hitP->dx = xyError ;
649  hitP->dy = xyError ;
650  hitP->dz = zError ;
651  hitP->buffer1 = pad ;
652  hitP->buffer2 = time ;
653  if(embedded)
654  hitP->flags = (flags | (1<<7) );
655  else
656  hitP->flags = flags ;
657  hitP->q = charge ;
658  hitP->hardwareId = readOutBoard * 16 + mezzanninneNr ;
659 
660  //l3Log("x: %f y: %f z: %f", hitP->x, hitP->y, hitP->z);
661 
662 
663  hitP++;
664 
665  counter++;
666 
667  // DEBUGGING: log cluster info
668  //l3Log("pad: %f time: %f charge: %i flags: %x aaa\n",
669  // fp, ft, charge, flags);
670 
671  if ( (nHits+counter)>maxHits ) {
672  LOG(ERR, "Error - FtfSl3:read: Hit array too small: %d + %d > %d \n",
673  nHits, counter, maxHits ) ;
674  return -1;
675  }
676  }
677  }
678  return counter;
679 }
680 
681 //******************************************************************
682 // Read Sector from buffer (using daqFormats.h)
683 //
684 //
685 // author: christof, derived from tonko's 'sl3'
686 // ppy: modified to look at byte order
687 //******************************************************************
688 int FtfSl3::readSector ( struct bankHeader *bank ) {
689 
690  struct TPCSECLP *seclp;
691  struct TPCRBCLP *rbclp ;
692  struct TPCMZCLD_local *mzcld ;
693  int iRb, kMz;
694  int sector;
695  int nHitsOfMz;
696  embedded = 0;
697 
698  // until 2002, the DETs sent us TPCSECLPs, but from 2003, we
699  // get a TPCSECP bank header that has the offset to the TPCSECLP
700  // in w9
701  // So, we have to check, if the bank header is a SECP or a SECLP,
702  // and extract the SECLP that we need for further processing
703  //l3Log("readSector: start %x\n", bank);
704 
705  if ( 0 == strncmp(bank->bank_type, CHAR_TPCSECLP, 8 ) ){
706  // Old case, we get only the TPCSECLP
707  //l3Log("readSector: old\n");
708 
709  seclp = (TPCSECLP *)bank;
710 
711  } else if ( 0 == strncmp(bank->bank_type, CHAR_TPCSECP, 8 ) ){
712  // New case: we have to look into w9 to get the TPCSECLP
713  //l3Log("readSector: new, w9=0x%x\n", bank->w9);
714 
715  if(bank->byte_order == DAQ_RAW_FORMAT_ORDER)
716  seclp = (TPCSECLP *)((char*)bank + 4*bank->w9);
717  else
718  seclp = (TPCSECLP *)((char*)bank + 4*swap32(bank->w9));
719 
720  } else {
721  // We don't know that type
722 
723  char type[9];
724  strncpy(type, bank->bank_type, 8);
725  type[8] = '\0';
726  LOG(ERR,"readSector: Unknown bank type: '%s'\n", type);
727 
728  return -1;
729  }
730 
731 
732  // reset sector-hit counter
733  nHits = 0;
734  //
735  // check byte order of SECLP bank
736  // byte swapping is needed
737  short swapByte = 0 ;
738  if ( !checkByteOrder(seclp->bh.byte_order) ) swapByte = 1 ;
739 
740  nHitsOfMz = 0;
741 
742  sector = (unsigned int)seclp->bh.bank_id ;
743  if ( swapByte ) sector = swap32(sector) ;
744 
745  sectorNr = sector;
746  LOG(DBG, "Set sectorNr to %d", sectorNr);
747  if ( sectorNr < 1 || sectorNr > 24 ) {
748  LOG(ERR, "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
749  return -1 ;
750  }
751 
752  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
753  para.phiMin = sectorG[sector-1].phiMin ;
754  para.phiMax = sectorG[sector-1].phiMax ;
755  para.etaMin = sectorG[sector-1].etaMin ;
756  para.etaMax = sectorG[sector-1].etaMax ;
757 
758  // run over receiver boards
759  for (iRb=0; iRb<SB_RB_NUM; iRb++) {
760 
761  if (iRb==6) {
762  sector++ ; // the other Sector
763  if ( sector == 4 ) {
764  para.phiMin = 0. ;
765  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
766  para.phiShift = 0.8 ; // ~45 degrees
767  }
768  else if ( sector == 22 ) {
769  para.phiMin = 0. ;
770  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
771  para.phiShift = 0.27 ; // ~15 degrees
772  }
773  else {
774  if ( sectorG[sector-1].phiMin < para.phiMin )
775  para.phiMin = sectorG[sector-1].phiMin ;
776  if ( sectorG[sector-1].phiMax > para.phiMax )
777  para.phiMax = sectorG[sector-1].phiMax ;
778  para.phiShift = 0 ;
779  }
780  if ( sectorG[sector-1].etaMin < para.etaMin )
781  para.etaMin = sectorG[sector-1].etaMin ;
782  if ( sectorG[sector-1].etaMax > para.etaMax )
783  para.etaMax = sectorG[sector-1].etaMax ;
784  }
785  //l3Log ( "sector %d rb %d phi min/max %f %f \n",
786  // sector, iRb, para.phiMin, para.phiMax ) ;
787 
788  // Get pointer to RPCLP
789  int off = (unsigned int)seclp->rb[iRb].off;
790  if ( swapByte ) off = swap32(off);
791  if ( !off ) continue ;
792  rbclp = (struct TPCRBCLP *)((char *)seclp + off * 4) ;
793 
794  int swapByteMezzaninne = 0 ;
795  if ( !checkByteOrder(rbclp->bh.byte_order) ) swapByteMezzaninne = 1 ;
796 
797  // run over the 3 mezzanines
798  for (kMz=0; kMz<RB_MZ_NUM; kMz++) {
799 
800  if (!rbclp->mz[kMz].off) continue;
801  off = rbclp->mz[kMz].off ;
802  if ( swapByteMezzaninne ) off = swap32(off);
803  mzcld = (struct TPCMZCLD_local *) ((char *)rbclp + off*4) ;
804 
805  if(strncmp((char*)mzcld, "TPCMZCLD",8)!=0){
806  if (swapByteMezzaninne) {
807  LOG(ERR, "ERROR: TPCMZCLD header not found off=%d len=%d\n",
808  swap32(rbclp->mz[kMz].off), swap32(rbclp->mz[kMz].len));
809  } else {
810  LOG(ERR, "ERROR: TPCMZCLD header not found off=%d len=%d\n",
811  rbclp->mz[kMz].off, rbclp->mz[kMz].len);
812  }
813  continue;
814  }
815  // printf("sector=%d %d %d 0x%x\n",sector,iRb,kMz,mzcld);
816  nHitsOfMz = readMezzanine (sector, iRb, kMz, mzcld);
817  if (nHitsOfMz<0) {
818  if (swapByteMezzaninne) {
819  LOG(ERR, "ERROR: wrong reading mezzanine off=%d len=%d\n",
820  swap32(rbclp->mz[kMz].off), swap32(rbclp->mz[kMz].len));
821  } else {
822  LOG(ERR,"ERROR: wrong reading mezzanine off=%d len=%d\n",
823  rbclp->mz[kMz].off, rbclp->mz[kMz].len);
824  }
825  return -1;
826  }
827  nHits += nHitsOfMz;
828 
829  }
830  }
831  //
832  // Since phiMin/Max etaMin/etaMax may have changed reset tracker
833  //
834  reset();
835  //
836  return 0;
837 }
838 
839 
840 // Need to set the angles by sector... lost of special cases. Don't know why!
841 // perhaps its because have a region -x to +x, move to 0 ... 2x with "shift" of x
842 //
843 // sector is the hypersector, counting from 1
844 //
845 int FtfSl3::setTrackingAngles(int sector)
846 {
847  if(sector < 1 || sector > 24) {
848  LOG(ERR, "Bad sector = %d",sector,0,0,0,0);
849  return -1;
850  }
851 
852  // This is basically it....
853  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
854  para.phiMin = sectorG[sector-1].phiMin ;
855  para.phiMax = sectorG[sector-1].phiMax ;
856  para.etaMin = sectorG[sector-1].etaMin ;
857  para.etaMax = sectorG[sector-1].etaMax ;
858 
859  // Now do the next sector...
860  sector++ ;
861  if ( sector == 4 ) { // What's different?
862  para.phiMin = 0.;
863  para.phiMax = 1.1;
864  para.phiShift = 0.8;
865  }
866  else if ( sector == 22 ) { // What's different?
867  para.phiMin = 0.;
868  para.phiMax = 1.1;
869  para.phiShift = 0.27;
870  }
871  else {
872  if ( sectorG[sector-1].phiMin < para.phiMin )
873  para.phiMin = sectorG[sector-1].phiMin ;
874  if ( sectorG[sector-1].phiMax > para.phiMax )
875  para.phiMax = sectorG[sector-1].phiMax ;
876  para.phiShift = 0 ;
877  }
878 
879  if ( sectorG[sector-1].etaMin < para.etaMin )
880  para.etaMin = sectorG[sector-1].etaMin ;
881  if ( sectorG[sector-1].etaMax > para.etaMax )
882  para.etaMax = sectorG[sector-1].etaMax ;
883 
884  reset(); // this is needed I think!
885  return 0;
886 }
887 
889 // Read sector from evpReader
890 //
891 // Assumes that tpcReader(mem,sector) has already been called
892 // so that tpc structure contains data for sector already
893 //
894 
895 
896 void FtfSl3::setClustersFromGl3Event(gl3Event *event, int sector) {
897  int filtered_out = 0;
898 
899  sectorNr = sector;
900  LOG(DBG, "set sectorNr to %d maxHits=%d nhits=%d", sector, maxHits, event->nHits);
901 
902  for(int i=event->sectorFirstHit[sector]; i < event->nHits; i++) {
903  if(i >= maxHits) {
904  LOG(ERR, "Too many hits for sector %d, (%d/%d) truncating", sector, i, maxHits);
905  break;
906  }
907 
908  gl3Hit *gl3 = &event->hit[i];
909  if((gl3->rowSector / 100) != sector) return;
910 
911  FtfHit *hitP = &hit[nHits];
912 
913  hitP->id = nHits;
914  hitP->row = gl3->rowSector % 100;
915  hitP->sector = sector;
916  hitP->x = gl3->getX();
917  hitP->y = gl3->getY();
918  hitP->z = gl3->getZ();
919  hitP->dx = xyError;
920  hitP->dy = xyError;
921  hitP->dz = zError;
922  hitP->buffer1 = 0; //(int)(pad * 64);
923  hitP->buffer2 = 0; //(int)(tb * 64);
924 
925  hitP->flags = gl3->flags;
926 
927  hitP->q = gl3->charge;
928  hitP->hardwareId = 0;
929 
930 
931  //if(c->t < minTimeBin) continue;
932  //if(c->t > maxTimeBin) continue;
933  if(hitP->q < minClusterCharge) { filtered_out++; continue; }
934  if(hitP->q > maxClusterCharge) { filtered_out++; continue; }
935 
936  nHits++;
937 
938  //printf("z: %f\n", hitP->z);
939  }
940 
941  LOG(DBG, "sect = %d (%d) nhits = %d (%d)", sector, event->sectorFirstHit[sector], nHits, filtered_out);
942 }
943 
944 /*
945 int FtfSl3::readSectorFromEvpReader(int sector) {
946 
947  embedded = 0;
948 
949  l3xyzCoordinate XYZ(0,0,0);
950  l3ptrsCoordinate PTRS(0,0,0,0);
951 
952  sectorNr = sector;
953  LOG("JEFF", "set sectorNr to %d", sector);
954  if ( sectorNr < 1 || sectorNr > 24 ) {
955  LOG(ERR, "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
956  return -1 ;
957  }
958 
959  // read data...
960 
961  FtfHit *hitP;
962 
963  // Read TPC clusters in (doesn't use gl3 event, reads it again!
964  // First do iTPC
965 
966  if(rdr != NULL) {
967  daq_dta *dd;
968  dd = rdr->det("itpc")->get("cld", sector);
969  if(dd) {
970  while(dd->iterate()) {
971  int padrow = dd->row;
972  int sec = dd->sec;
973 
974  for(u_int i=0;i<dd->ncontent;i++) {
975  float pad = dd->cld[i].pad;
976  float tb = dd->cld[i].tb;
977  int charge = dd->cld[i].charge;
978  int flags = dd->cld[i].flags;
979  int padrow = dd->row;
980 
981 
982  //printf("nHits = %d\n", nHits);
983  hitP = &hit[nHits];
984 
985  l3ptrsCoordinate raw;
986  l3xyzCoordinate local;
987  l3xyzCoordinate global;
988 
989  int pads = 2 * (padrow + 25 - (int)((double)padrow/7.0));
990  int padpos = pad - pads/2;
991 
992  raw.Sets(sector);
993  local.Setx(padpos * .5);
994  local.Sety(55.80 + 1.6 * (padrow - 1));
995  local.Setz(getCoordinateTransformer()->drift_length_inner - tb * getCoordinateTransformer()->lengthPerTb);
996  getCoordinateTransformer()->local_to_global(raw, local, global);
997 
998  hitP->id = nHits;
999  hitP->row = padrow;
1000  hitP->sector = sector;
1001  hitP->x = (float)global.Getx();
1002  hitP->y = (float)global.Gety();
1003  hitP->z = (float)global.Getz();
1004  hitP->dx = xyError;
1005  hitP->dy = xyError;
1006  hitP->dz = zError;
1007  hitP->buffer1 = (int)(pad * 64);
1008  hitP->buffer2 = (int)(tb * 64);
1009 
1010  if(embedded)
1011  hitP->flags = (flags | (1<<7));
1012  else
1013  hitP->flags = flags;
1014 
1015  hitP->q = charge;
1016  hitP->hardwareId = 0;
1017 
1018  nHits++;
1019  }
1020  }
1021 
1022 
1023 
1024 
1025  //gl3c->setITPCHit(coordinateTransformer, sec, padrow, pad, tb, charge, flags);
1026  }
1027  }
1028 
1029  //LOG("JEFF","itpc nHits=%d", nHits);
1030  int filtered_out = 0;
1031 
1032  // Now do TPC!
1033  if(pTPC) {
1034  for(int r=0;r<45;r++) {
1035 
1036  for(int j=0;j<pTPC->cl_counts[r];j++) {
1037  tpc_cl *c = &pTPC->cl[r][j];
1038 
1039 
1040  hitP = &hit[nHits];
1041 
1042 
1043  // Some cuts...
1044  if(c->t < minTimeBin) { filtered_out++; continue; }
1045  if(c->t > maxTimeBin) { filtered_out++; continue; }
1046  if(c->charge < minClusterCharge) { filtered_out++; continue; }
1047  if(c->charge > maxClusterCharge) { filtered_out++; continue; }
1048 
1049  //if((sector == 1)) {
1050  //printf("cl new: %4.2f %4.2f %f %f\n",c->p - .5, c->t - .5, (float)r+1, (float)sector);
1051  //}
1052 
1053  // The subtractions are to handle the pad offsets
1054  // My choice at the momement is to make L3 tracking identical to
1055  // old versions. The difference is because Tonko includes the pad centroid
1056  // shifts in the calculation of c->t & c->p. It may be that in the old
1057  // L3 code this shift was included, but in the transform code instead.
1058  // Untill I know, I leave it as it was before...
1059  //
1060  PTRS.Setptrs(c->p - .5 , c->t - .5, r+1, sector);
1061  getCoordinateTransformer()->raw_to_global(PTRS, XYZ);
1062 
1063  hitP->id = nHits;
1064  hitP->row = r+1;
1065  hitP->sector = sector;
1066  hitP->x = (float)XYZ.Getx();
1067  hitP->y = (float)XYZ.Gety();
1068  hitP->z = (float)XYZ.Getz();
1069  hitP->dx = xyError;
1070  hitP->dy = xyError;
1071  hitP->dz = zError;
1072  hitP->buffer1 = (int)((c->p - 0.5) * 64);
1073  hitP->buffer2 = (int)((c->t - 0.5) * 64);
1074 
1075  if(embedded)
1076  hitP->flags = (c->flags | (1<<7));
1077  else
1078  hitP->flags = c->flags;
1079 
1080  hitP->q = c->charge;
1081  hitP->hardwareId = 0;
1082 
1083  nHits++;
1084  }
1085  }
1086  }
1087 
1088  LOG(DBG, "sector = %d nHits = %d (%d)", sector, nHits, filtered_out);
1089 
1090  return 0;
1091 }
1092 */
1093 
1094 
1095 
1096 // Done with read sector from evpReader
1098 
1099 
1100 
1101 // Read 1 sector, starting from DATAP.
1102 // sector is hypersector, numbered 1..23
1103 //
1104 int FtfSl3::readSector (DATAP *datap, int sector) {
1105 
1106  if ( sector < 1 && sector > 24 ) {
1107  LOG(ERR, "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
1108  return -1 ;
1109  }
1110 
1111  int off;
1112  int len;
1113 
1114  int swapdatap=0;
1115  if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatap = 1;
1116  len = qswap32(swapdatap, datap->det[TPC_ID].len);
1117  off = qswap32(swapdatap, datap->det[TPC_ID].off);
1118  if(len == 0) return -1;
1119  if(off == 0) return -1;
1120 
1121  TPCP *tpcp = (TPCP *)((u_int *)datap + off) ;
1122  int swaptpcp = 0;
1123  if(checkBank((char *)tpcp,"TPCP") < 0) return -1;
1124  if(tpcp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swaptpcp = 1;
1125  len = qswap32(swaptpcp, tpcp->sb[sector-1].len);
1126  off = qswap32(swaptpcp, tpcp->sb[sector-1].off);
1127  if(len == 0) return -1;
1128  if(off == 0) return -1;
1129 
1130  TPCSECP *secp = (TPCSECP *)((u_int *)tpcp + off);
1131  int swapsecp = 0;
1132  if(checkBank((char *)secp,"TPCSECP") < 0) return -1;
1133  if(secp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapsecp = 1;
1134  off = qswap32(swapsecp, secp->bh.w9);
1135  if(off == 0) return -1;
1136 
1137  TPCSECLP *seclp = (TPCSECLP *)((u_int *)secp + off);
1138  if(checkBank((char *)seclp,"TPCSECLP") < 0) return -1;
1139  readSector((bankHeader *)seclp);
1140 
1141  return 0;
1142 }
1143 
1144 //******************************************************************
1145 // Read Sector from buffer (using daqFormats.h)
1146 //
1147 // function to read in 2 sectors from different event and merge them
1148 // to be able to embed one event into another one
1149 //
1150 //
1151 //******************************************************************
1152 int FtfSl3::readSector ( struct TPCSECLP *seclp1, struct TPCSECLP *seclp2 ) {
1153 
1154  struct TPCRBCLP *rbclp ;
1155  struct TPCMZCLD_local *mzcld ;
1156  int iRb, kMz;
1157  int sector,tmpsector;
1158  int nHitsOfMz;
1159  struct TPCSECLP *seclp; // 'generic' sector pointer
1160  short swapByte ;
1161 
1162  // reset sector-hit counter
1163  nHits = 0;
1164  //
1165  // check byte order of SECLP bank
1166  // byte swapping is needed
1167  short swapByte1 = 0 ;
1168  short swapByte2 = 0;
1169  if ( !checkByteOrder(seclp1->bh.byte_order) ) swapByte1 = 1 ;
1170  if ( !checkByteOrder(seclp2->bh.byte_order) ) swapByte2 = 1 ;
1171 
1172  // nHitsOfMz = 0;
1173 
1174  sector = (unsigned int)seclp1->bh.bank_id ;
1175  if ( swapByte1 ) sector = swap32(sector) ;
1176  tmpsector = (unsigned int)seclp2->bh.bank_id ;
1177  if ( swapByte2 ) tmpsector = swap32(tmpsector) ;
1178  // check that both sectors are consistent
1179  if(tmpsector != sector){
1180  LOG(ERR,"Error in embedding got different sectors to read in\n");
1181  exit(1);
1182  }
1183  LOG(ERR,"sector: %i\n",sector);
1184 
1185  sectorNr = sector;
1186  sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
1187  para.phiMin = sectorG[sector-1].phiMin ;
1188  para.phiMax = sectorG[sector-1].phiMax ;
1189  para.etaMin = sectorG[sector-1].etaMin ;
1190  para.etaMax = sectorG[sector-1].etaMax ;
1191  //
1192  // Check Sector
1193  //
1194  if ( sectorNr < 0 && sectorNr > 24 ) {
1195  LOG(ERR,"Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
1196  return -1 ;
1197  }
1198 
1199  seclp = seclp1;
1200  swapByte = swapByte1;
1201  embedded = 0;
1202 
1203  for(int embed=0;embed<2;embed++){
1204  // two loops first set the pointers to event one then after that is
1205  // done to event 2, at end of for loop
1206 
1207 
1208  // run over receiver boards
1209  for (iRb=0; iRb<SB_RB_NUM; iRb++) {
1210 
1211  if (iRb==6) {
1212  sector++ ; // the other Sector
1213  if ( sector == 4 ) {
1214  para.phiMin = 0. ;
1215  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
1216  para.phiShift = 0.8 ; // ~45 degrees
1217  }
1218  else if ( sector == 22 ) {
1219  para.phiMin = 0. ;
1220  para.phiMax = 1.1 ; // 60 degress a bit more than a rad
1221  para.phiShift = 0.27 ; // ~15 degrees
1222  }
1223  else {
1224  if ( sectorG[sector-1].phiMin < para.phiMin ) para.phiMin = sectorG[sector-1].phiMin ;
1225  if ( sectorG[sector-1].phiMax > para.phiMax ) para.phiMax = sectorG[sector-1].phiMax ;
1226  para.phiShift = 0 ;
1227  }
1228  if ( sectorG[sector-1].etaMin < para.etaMin ) para.etaMin = sectorG[sector-1].etaMin ;
1229  if ( sectorG[sector-1].etaMax > para.etaMax ) para.etaMax = sectorG[sector-1].etaMax ;
1230  }
1231  //l3Log ( "sector %d rb %d phi min/max %f %f \n", sector, iRb, para.phiMin, para.phiMax ) ;
1232 
1233 
1234  if ( !(unsigned int)seclp->rb[iRb].off) continue ;
1235 
1236  int off = (unsigned int)seclp->rb[iRb].off;
1237  if ( swapByte ) off = swap32(off);
1238  rbclp = (struct TPCRBCLP *)((char *)seclp + off * 4) ;
1239  int swapByteMezzaninne = 0 ;
1240  if ( !checkByteOrder(rbclp->bh.byte_order) ) swapByteMezzaninne = 1 ;
1241 
1242  // run over the 3 mezzanines
1243  for (kMz=0; kMz<RB_MZ_NUM; kMz++) {
1244 
1245  if( ! rbclp->mz[kMz].off) {
1246  continue;
1247  }
1248 #ifdef TRDEBUG
1249  else {
1250  if ( debugLevel > 1 ) {
1251  LOG(ERR, "FtfSl3::readSector: MZCLD %d exists!\n", kMz+1) ;
1252  }
1253  }
1254 #endif
1255 
1256  off = rbclp->mz[kMz].off ;
1257  if ( swapByteMezzaninne ) off = swap32(off);
1258  if (off == 0) continue;
1259  mzcld = (struct TPCMZCLD_local *) ((char *)rbclp + off*4) ;
1260 
1261  if (mzcld) {
1262  if(strncmp((char*)mzcld, "TPCMZCLD",8)!=0){
1263  LOG(ERR, "ERROR: TPCMZCLD header not found\n");
1264  continue;
1265  }
1266 
1267  nHitsOfMz = readMezzanine (sector, iRb, kMz, mzcld);
1268  if (nHitsOfMz<0) {
1269  LOG(ERR, "FtfSl3:readSector: wrong reading mezzanine \n" ) ;
1270  return -1;
1271  }
1272  nHits += nHitsOfMz;
1273  }
1274 
1275  }
1276  }
1277 
1278  seclp = seclp2;
1279  swapByte = swapByte2;
1280  embedded = 1;
1281  // reset sector
1282  sector = sectorNr;
1283  }
1284 
1285  //
1286  // Since phiMin/Max etaMin/etaMax may have changed reset tracker
1287  //
1288  reset();
1289  //
1290  return 0;
1291 }
1292 
1293 //*******************************************************************
1294 // Process
1295 //*******************************************************************
1296 int FtfSl3::processSector ( ){
1297  //
1298  // Reset hit track assignment
1299  //
1300  for ( int h = 0 ; h < nHits ; h++ ) {
1301  hit[h].track = 0 ;
1302  }
1303  para.eventReset = 1 ;
1304  nTracks = 0 ;
1305  if(process()==1) return 1 ; // error!
1306  if (para.dEdx) dEdx();
1307  //
1308  if ( debugLevel > 0 )
1309  LOG(ERR," FtfSl3::process: tracks %i Time: real %f cpu %f\n",
1310  nTracks, realTime, cpuTime ) ;
1311  //
1312  //
1313  return 0;
1314 }
1315 //********************************************************************
1316 // Prcess, encapsulates readSector(); processSector(); fillTracks/Hits()
1317 //********************************************************************
1318 #if 0
1319 int FtfSl3::processData(TPCSECLP* seclp, char* trackBuffer,
1320  int maxTrackBytes, int& nTrackBytes,
1321  char* hitBuffer, int maxHitBytes, int& nHitBytes)
1322 {
1323  // first: get token number
1324  short swapByte = 0;
1325  if (!checkByteOrder(seclp->bh.byte_order)) swapByte = 1;
1326 
1327  int token = (unsigned int)seclp->bh.token;
1328  if (swapByte) token = swap32(token);
1329 
1330  readSector(seclp);
1331  processSector();
1332 
1333  // write out tracks only if trackBuffer != 0
1334  if (trackBuffer) {
1335  int ret = fillTracks(maxTrackBytes, trackBuffer, token);
1336  if (ret>0) nTrackBytes = ret;
1337  else return 1;
1338  }
1339  // write out hits only if hitBuffer != 0
1340  if (hitBuffer) {
1341  int ret = fillHits(maxHitBytes, hitBuffer, token);
1342  if (ret>0) nHitBytes = ret;
1343  else return 1;
1344  }
1345  return 0;
1346 }
1347 #endif
1348 
1349 //********************************************************************
1350 // Calculates deposited Energy
1351 //********************************************************************
1352 int FtfSl3::dEdx ( ) {
1353 
1354  for ( int i = 0 ; i<nTracks ; i++ ){
1355  if (track[i].nHits<para.minHitsForDedx) {
1356  track[i].nDedx = 0;
1357  track[i].dedx = 0;
1358  continue;
1359  }
1360  fDedx->TruncatedMean(&track[i]);
1361  }
1362  return 0;
1363 }
1364 //***************************************************************
1365 // Set Default parameters
1366 //***************************************************************
1367 int FtfSl3::setParameters ( ) {
1368 
1369  // FtfPara* para = &(para) ;
1370 
1371  xyError = 0.12 ;
1372  zError = 0.24 ;
1373  para.hitChi2Cut = 50. ;
1374  para.goodHitChi2 = 20. ;
1375  para.trackChi2Cut = 10. ;
1376  para.maxChi2Primary = 50. ; // track with vertex if refit and minPtHelix is reasonable.
1377  para.segmentRowSearchRange = 2 ;
1378  para.trackRowSearchRange = 3 ;
1379  para.dphi = 0.08F ;
1380  para.deta = 0.08F ;
1381  para.dphiMerge = 0.01F ;
1382  para.detaMerge = 0.02F ;
1383  para.etaMinTrack = -2.2F ;
1384  para.etaMaxTrack = 2.2F ;
1385 
1386  para.dEdx = 1 ;
1387  // get Errors = 1 makes FPE's
1388  para.getErrors = 0 ;
1389  para.goBackwards = 1 ;
1390  para.goodDistance = 5.F ;
1391  para.mergePrimaries = 0 ;
1392  para.maxDistanceSegment = 50.F ;
1393  para.minHitsPerTrack = 5 ;
1394  para.nHitsForSegment = 2 ;
1395  para.nEta = 40 ;
1396  para.nEtaTrack = 40 ;
1397  para.nPhi = 10 ;
1398  para.nPhiTrack = 40 ;
1399  para.nPrimaryPasses = 1 ;
1400  para.nSecondaryPasses = 0 ;
1401  para.xyErrorScale = 1.0F ;
1402  para.szErrorScale = 1.0F ;
1403  para.phiClosed = 0 ;
1404 
1405 // para.ptMinHelixFit = 100.F ;
1406  para.ptMinHelixFit = 0.1 ; // enables refit
1407  para.rVertex = 0.F ;
1408  para.xVertex = 0.F ;
1409  para.yVertex = 0.F ;
1410  para.zVertex = 0.F ;
1411  para.dxVertex = 0.05F ;
1412  para.dyVertex = 0.05F ;
1413  para.phiVertex = 0.F ;
1414 
1415  para.zMax = 205. ;
1416  return 0;
1417 }
1418 
1419 
1420 
1421 
1422 
Definition: FtfHit.h:16
Definition: gl3Hit.h:24
Definition: daq_tpc.h:22