00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef TRG_VERSION
00054 #define TRG_VERSION 0x32
00055 #endif
00056
00057 #include <stdlib.h>
00058 #include "FtfSl3.h"
00059 #include "rts.h"
00060 #include "l3Swap.h"
00061 #include "fcfClass.hh"
00062 #ifdef OLD_DAQ_READER
00063 #include <evpReader.hh>
00064 #else
00065 #include <DAQ_READER/daqReader.h>
00066 #endif
00067 #include <rtsSystems.h>
00068 #include <daqFormats.h>
00069 #ifndef OLD_DAQ_READER
00070 #include <DAQ_TPC/daq_tpc.h>
00071
00072 extern tpc_t *pTPC;
00073 #endif
00074
00075
00076
00077
00078 int FtfSl3::canItBeMerged ( FtfTrack* tTrack ) {
00079 double rTpcMin = 50. ;
00080 double rTpcMax = 210. ;
00081
00082 if ( nHits < 15 ) return 0 ;
00083
00084
00085
00086
00087
00088
00089 double x0 = tTrack->r0 * cos (tTrack->phi0);
00090 double y0 = tTrack->r0 * sin (tTrack->phi0);
00091 double rc = tTrack->pt / (bFactor * para.bField);
00092 double trackPhi0 = tTrack->psi + tTrack->q * 0.5 * M_PI / fabs ((double) tTrack->q);
00093 double xc = x0 - rc * cos (trackPhi0);
00094 double yc = y0 - rc * sin (trackPhi0);
00095
00096
00097
00098 double localPhi[2] ;
00099 localPhi[0] = para.phiMin ;
00100 localPhi[1] = para.phiMax ;
00101
00102
00103 double sinPhi, cosPhi, tanPhi ;
00104 double a, b, c, b2minus4ac ;
00105 double x1, y1, x2, y2, r1, r2 ;
00106 c = xc * xc + yc * yc - rc * rc ;
00107 for ( int i = 0 ; i < 2 ; i++ ) {
00108 sinPhi = sin(localPhi[i]);
00109 cosPhi = cos(localPhi[i]);
00110 tanPhi = tan(localPhi[i]);
00111 a = 1. + tanPhi * tanPhi ;
00112 b = -2. * xc - 2. * yc * tanPhi ;
00113
00114 b2minus4ac = b * b - 4. * a * c ;
00115 if ( b2minus4ac > 0 ) {
00116 double rootB2Minus4ac = sqrt(b2minus4ac);
00117
00118 x1 = 0.5 * (-b + rootB2Minus4ac) / a ;
00119 y1 = x1 * tanPhi ;
00120 r1 = sqrt(x1*x1+y1*y1);
00121
00122
00123 double ratiox = 0 ;
00124 if ( cosPhi != 0 ) ratiox = x1/cosPhi ;
00125 double ratioy = 0 ;
00126 if ( sinPhi != 0 ) ratiox = y1/sinPhi ;
00127
00128 if ( ratiox >= 0 && ratioy >= 0 &&
00129 r1 > rTpcMin && r1 < rTpcMax ) {
00130
00131 return 1 ;
00132 }
00133
00134 x2 = 0.5 * (-b - rootB2Minus4ac) / a ;
00135 y2 = x2 * tanPhi ;
00136 r2 = sqrt(x2*x2+y2*y2);
00137 ratiox = 0 ;
00138 if ( cosPhi != 0 ) ratiox = x2/cosPhi ;
00139 ratioy = 0 ;
00140 if ( sinPhi != 0 ) ratioy = y2/sinPhi ;
00141
00142
00143 if ( ratiox >= 0 && ratioy >= 0 &&
00144 r2 > rTpcMin && r2 < rTpcMax ) {
00145
00146 return 1 ;
00147 }
00148 }
00149
00150 }
00151
00152
00153
00154 double zMembrane = 0 ;
00155 double sToMembrane = (zMembrane - tTrack->z0 ) / tTrack->tanl ;
00156 double dangle = sToMembrane / rc ;
00157 double angle = dangle + trackPhi0 ;
00158 double xMembrane = xc + rc * cos(angle) ;
00159 double yMembrane = yc + rc * sin(angle) ;
00160 double rMembrane = sqrt(xMembrane*xMembrane+yMembrane*yMembrane);
00161 if ( rMembrane > rTpcMin && rMembrane < rTpcMax ) {
00162
00163 return 1 ;
00164 }
00165
00166 return 0 ;
00167 }
00168
00169
00170
00171 int FtfSl3::fillHits ( unsigned int maxBytes, char* buff, unsigned int token ) {
00172
00173
00174
00175 if ( (nHits-1) * sizeof(l3_cluster) + sizeof(L3_SECCD) > maxBytes ) {
00176 LOG (ERR, "FtfSl3::fillHits: buffer with %d bytes too small \n", maxBytes ) ;
00177 return 0 ;
00178 }
00179
00180
00181
00182 L3_SECCD* head = (L3_SECCD *)buff ;
00183
00184 head->nrClusters_in_sector = nHits ;
00185
00186 memcpy(head->bh.bank_type,CHAR_L3_SECCD,8);
00187 head->bh.bank_id = sectorNr;
00188 head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
00189 head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
00190 head->bh.format_number = 0;
00191 head->bh.token = token;
00192 head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
00193 head->bh.crc = 0;
00194
00195
00196 l3_cluster* hitP = (l3_cluster *)(head->cluster);
00197 FtfHit *nextHit ;
00198 int i ;
00199 int counter = 0 ;
00200
00201
00202 for ( i = 0 ; i < nTracks ; i++ ) {
00203 for ( nextHit = (FtfHit *)(track[i].firstHit) ;
00204 nextHit != 0 ;
00205 nextHit = (FtfHit *)nextHit->nextTrackHit) {
00206 hitP->padrow = nextHit->row ;
00207 hitP->pad = nextHit->buffer1 ;
00208 hitP->time = nextHit->buffer2 ;
00209 hitP->flags = nextHit->flags ;
00210 hitP->charge = (short)nextHit->q ;
00211 hitP->RB_MZ = (short)nextHit->hardwareId ;
00212 hitP->trackId = track[i].id ;
00213 if ( !(nextHit->track) ) {
00214 LOG (ERR, "FtfSl3:fillHits: we got a problem track %d row hit %d \n",
00215 track[i].id, hitP->padrow ) ;
00216 }
00217 hitP++ ;
00218 counter++ ;
00219 }
00220 }
00221
00222
00223
00224 for ( i = 0 ; i < nHits ; i++ ) {
00225 nextHit = &(hit[i]) ;
00226 if ( nextHit->track ) continue ;
00227 hitP->padrow = nextHit->row ;
00228 hitP->pad = nextHit->buffer1 ;
00229 hitP->time = nextHit->buffer2 ;
00230 hitP->flags = nextHit->flags ;
00231 hitP->charge = (short)nextHit->q ;
00232 hitP->RB_MZ = (short)nextHit->hardwareId ;
00233 hitP->trackId = 0 ;
00234 hitP++ ;
00235 counter++ ;
00236 }
00237
00238 if ( counter != nHits ) {
00239 LOG (ERR, "FtfSl3:fillHits: Warning! Actual number of hits written %d total nHits %d \n",
00240 counter, nHits );
00241 }
00242
00243 head->bh.length = ((char *)hitP-buff) / 4 ;
00244
00245 return ((char *)hitP-buff) ;
00246 }
00247
00248
00249
00250 int FtfSl3::fillTracks ( int maxBytes, char* buff, unsigned int token ) {
00251
00252
00253 if(buff == NULL) {
00254 LOG(ERR,"ERROR: trying to fill NULL buffer");
00255 return 0;
00256 }
00257
00258 int counter = nTracks ;
00259
00260 unsigned int headSize;
00261
00262 if(counter)
00263 headSize = sizeof(struct bankHeader);
00264 else
00265 headSize = 0;
00266
00267
00268 char *pointer = buff + sizeof(struct L3_SECTP) ;
00269
00270 char *endOfData = pointer + headSize
00271 + counter * sizeof(struct local_track) ;
00272
00273 int nBytes = (endOfData-buff) ;
00274 if ( nBytes > maxBytes ) {
00275 LOG(ERR, "FtfSl3::fillTracks: %d bytes needed, %d max, too short a buffer \n ",
00276 nBytes, maxBytes ) ;
00277 return -1 ;
00278 }
00279
00280
00281
00282
00283 struct L3_SECTP *head = (struct L3_SECTP *)buff ;
00284
00285
00286
00287 memcpy(head->bh.bank_type,CHAR_L3_SECTP,8);
00288 head->bh.length = sizeof(struct L3_SECTP) / 4 ;
00289 head->bh.bank_id = sectorNr;
00290 head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
00291 head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
00292 head->bh.format_number = 1;
00293 head->bh.token = token;
00294 head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
00295 head->bh.crc = 0;
00296
00297 head->nHits = (unsigned int)nHits ;
00298 head->nTracks = (unsigned int)nTracks ;
00299 head->cpuTime = (unsigned int)rint(cpuTime * 1000000);
00300 head->realTime = (unsigned int)rint(realTime * 1000000) ;
00301 head->xVert = (int)rint(para.xVertex * 1000000);
00302 head->yVert = (int)rint(para.yVertex * 1000000);
00303 head->zVert = (int)rint(para.zVertex * 1000000);
00304 head->para = 1 ;
00305 head->banks[0].off = (pointer-buff) / 4;
00306 head->banks[0].len = (endOfData-pointer)/ 4 ;
00307 head->banks[1].off = 0 ;
00308 head->banks[1].len = 0 ;
00309 head->banks[2].off = 0 ;
00310 head->banks[2].len = 0 ;
00311
00312
00313
00314
00315
00316
00317 struct L3_LTD* LTD = (struct L3_LTD*)pointer;
00318
00319 struct local_track* uSTrack =
00320 (struct local_track *)(pointer + headSize) ;
00321
00322
00323 if(headSize) {
00324 memcpy(LTD->bh.bank_type, CHAR_L3_LTD, 8);
00325 LTD->bh.length = (sizeof(struct bankHeader) +
00326 counter * sizeof(local_track))/4 ;
00327 LTD->bh.bank_id = sectorNr ;
00328 LTD->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
00329 LTD->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
00330 LTD->bh.format_number = 0 ;
00331 LTD->bh.token = token ;
00332 LTD->bh.w9 = DAQ_RAW_FORMAT_WORD9 ;
00333 LTD->bh.crc = 0;
00334 }
00335
00336 for ( int i = 0 ; i < nTracks ; i++ ) {
00337
00338 uSTrack->id = track[i].id ;
00339 if ( canItBeMerged ( &(track[i]) ) ) {
00340 uSTrack->id *= -1 ;
00341 }
00342 uSTrack->nHits = track[i].nHits ;
00343 uSTrack->ndedx = track[i].nDedx;
00344 uSTrack->innerMostRow = track[i].innerMostRow ;
00345 uSTrack->outerMostRow = track[i].outerMostRow ;
00346 uSTrack->xy_chisq = (unsigned short)rint(10 * track[i].chi2[0]
00347 /float(track[i].nHits));
00348 uSTrack->sz_chisq = (unsigned short)rint(10 * track[i].chi2[1]
00349 /float(track[i].nHits));
00350 uSTrack->dedx = track[i].dedx ;
00351 uSTrack->pt = track[i].pt * float(track[i].q) ;
00352 uSTrack->psi = track[i].psi ;
00353 uSTrack->tanl = track[i].tanl ;
00354 uSTrack->r0 = track[i].r0 ;
00355 uSTrack->phi0 = track[i].phi0 ;
00356 uSTrack->z0 = track[i].z0 ;
00357 uSTrack->trackLength = track[i].length ;
00358 uSTrack->dpt = (short)(32768. * track[i].dpt / track[i].pt ) ;
00359 uSTrack->dpsi = track[i].CompressOver1(track[i].dpsi,track[i].psi);
00360 uSTrack->dtanl = track[i].CompressOver1(64.*track[i].dtanl,track[i].tanl);
00361 uSTrack->dz0 = (short)(1024. * track[i].dz0 ) ;
00362
00363
00364
00365
00366
00367
00368 uSTrack++ ;
00369 }
00370
00371
00372
00373 return nBytes ;
00374
00375 }
00376
00377
00378
00379 int FtfSl3::getNrTracks (void) {
00380 return nTracks;
00381 }
00382
00383
00384
00385 int FtfSl3::setup ( int maxHitsIn, int maxTracksIn ) {
00386
00387
00388
00389
00390 para.setDefaults ( ) ;
00391
00392
00393
00394 setParameters ( ) ;
00395
00396
00397
00398 double toRad = acos(-1.)/180. ;
00399 sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
00400 sectorG[ 0].phiMin = 45. * toRad ;
00401 sectorG[ 1].phiMin = 15. * toRad ;
00402 sectorG[ 2].phiMin = 345. * toRad ;
00403 sectorG[ 3].phiMin = 315. * toRad ;
00404 sectorG[ 4].phiMin = 285. * toRad ;
00405 sectorG[ 5].phiMin = 255. * toRad ;
00406 sectorG[ 6].phiMin = 225. * toRad ;
00407 sectorG[ 7].phiMin = 195. * toRad ;
00408 sectorG[ 8].phiMin = 165. * toRad ;
00409 sectorG[ 9].phiMin = 135. * toRad ;
00410 sectorG[10].phiMin = 105. * toRad ;
00411 sectorG[11].phiMin = 75. * toRad ;
00412 sectorG[12].phiMin = 105. * toRad ;
00413 sectorG[13].phiMin = 135. * toRad ;
00414 sectorG[14].phiMin = 165. * toRad ;
00415 sectorG[15].phiMin = 195. * toRad ;
00416 sectorG[16].phiMin = 225. * toRad ;
00417 sectorG[17].phiMin = 255. * toRad ;
00418 sectorG[18].phiMin = 285. * toRad ;
00419 sectorG[19].phiMin = 315. * toRad ;
00420 sectorG[20].phiMin = 345. * toRad ;
00421 sectorG[21].phiMin = 15. * toRad ;
00422 sectorG[22].phiMin = 45. * toRad ;
00423 sectorG[23].phiMin = 75. * toRad ;
00424
00425 sectorG[ 0].phiMax = 75. * toRad ;
00426 sectorG[ 1].phiMax = 45. * toRad ;
00427 sectorG[ 2].phiMax = 15. * toRad ;
00428 sectorG[ 3].phiMax = 345. * toRad ;
00429 sectorG[ 4].phiMax = 315. * toRad ;
00430 sectorG[ 5].phiMax = 285. * toRad ;
00431 sectorG[ 6].phiMax = 255. * toRad ;
00432 sectorG[ 7].phiMax = 225. * toRad ;
00433 sectorG[ 8].phiMax = 195. * toRad ;
00434 sectorG[ 9].phiMax = 165. * toRad ;
00435 sectorG[10].phiMax = 135. * toRad ;
00436 sectorG[11].phiMax = 105. * toRad ;
00437 sectorG[12].phiMax = 135. * toRad ;
00438 sectorG[13].phiMax = 165. * toRad ;
00439 sectorG[14].phiMax = 195. * toRad ;
00440 sectorG[15].phiMax = 225. * toRad ;
00441 sectorG[16].phiMax = 255. * toRad ;
00442 sectorG[17].phiMax = 285. * toRad ;
00443 sectorG[18].phiMax = 315. * toRad ;
00444 sectorG[19].phiMax = 345. * toRad ;
00445 sectorG[20].phiMax = 15. * toRad ;
00446 sectorG[21].phiMax = 45. * toRad ;
00447 sectorG[22].phiMax = 75. * toRad ;
00448 sectorG[23].phiMax = 105. * toRad ;
00449
00450 double etaMin = 0.4 ;
00451 double etaMax = 2.3 ;
00452
00453 for ( int sector = 0 ; sector < 24 ; sector++ ) {
00454 sectorG[sector].phiShift = 0 ;
00455 if ( sector < 12 ) {
00456 sectorG[sector].etaMin = -1. * etaMin ;
00457 sectorG[sector].etaMax = etaMax ;
00458 }
00459 else {
00460 sectorG[sector].etaMin = -1. * etaMax ;
00461 sectorG[sector].etaMax = etaMin ;
00462 }
00463 }
00464 sectorG[ 2].phiShift = 16. * toRad ;
00465 sectorG[20].phiShift = 16. * toRad ;
00466
00467
00468
00469 reset ( ) ;
00470
00471
00472
00473 maxHits = maxHitsIn ;
00474 maxTracks = maxTracksIn ;
00475 hit = new FtfHit[maxHits] ;
00476 track = new FtfTrack[maxTracks] ;
00477
00478 para.phiMin = 0.F * pi / 180.F ;
00479 para.phiMax =360.F * pi / 180.F ;
00480 para.etaMin =-0.4F ;
00481 para.etaMax = 2.2F ;
00482 #ifdef TRDEBUG
00483 para.trackDebug = 24 ;
00484 para.debugLevel = 1 ;
00485 #endif
00486 return 0;
00487 }
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498 int FtfSl3::readMezzanine (int sector, int readOutBoard,
00499 int mezzanninneNr, struct TPCMZCLD_local *mzcld) {
00500
00501 unsigned int *tmp32;
00502 int row, rows;
00503 int len;
00504 int i, j;
00505 int counter;
00506
00507 if(mzcld->bh.length <= 10) {
00508 return 0;
00509 }
00510
00511
00512 FtfHit *hitP = &hit[nHits];
00513
00514
00515 l3xyzCoordinate XYZ(0,0,0) ;
00516 l3ptrsCoordinate PTRS(0,0,0,0) ;
00517
00518
00519 counter = 0;
00520 short swapByte = 0 ;
00521 if ( !checkByteOrder(mzcld->bh.byte_order) ) swapByte = 1 ;
00522
00523 tmp32 = mzcld->padrowFiller ;
00524
00525 rows = mzcld->rows;
00526 if ( swapByte ) rows = swap32(rows);
00527
00528
00529
00530 for (i=0; i<rows; i++) {
00531 row = *tmp32++ ;
00532 len = *tmp32++ ;
00533 if ( swapByte ) {
00534 row = swap32(row);
00535 len = swap32(len);
00536 }
00537
00538
00539 if (len == 0) {
00540
00541 continue;
00542 }
00543
00544
00545 if((row<0) || (row>45)){
00546 LOG(ERR, "ERROR: row (%i) is wrong in TPCMZCLD, len=%d\n",
00547 row,len);
00548 continue;
00549 }
00550
00551 for ( j=0; j<len; j++) {
00552 double fp, ft ;
00553 unsigned short pad ;
00554 unsigned short time ;
00555 unsigned short charge;
00556 unsigned short fla;
00557
00558 unsigned short flags = 0;
00559
00560
00561
00562 struct xt {
00563 unsigned short x ;
00564 unsigned short t ;
00565 } *xt ;
00566 struct c {
00567 unsigned short flags ;
00568 unsigned short charge ;
00569 } *c ;
00570
00571 xt = (struct xt *) tmp32++ ;
00572 c = (struct c *) tmp32++ ;
00573
00574
00575
00576
00577
00578
00579 if ( !swapByte ) {
00580 pad = xt->x ;
00581 time = xt->t ;
00582
00583 fla = c->flags ;
00584 charge = c->charge ;
00585 }
00586 else {
00587 pad = swap16(xt->x) ;
00588 time = swap16(xt->t) ;
00589
00590 fla = swap16(c->flags) ;
00591 charge = swap16(c->charge) ;
00592 }
00593
00594
00595
00596 if(pad & 0x8000) flags |= FCF_DOUBLE_PAD ;
00597 if(pad & 0x4000) flags |= FCF_DEAD_EDGE ;
00598 if(time & 0x8000) flags |= FCF_ONEPAD ;
00599 if(fla & 0x8000) flags |= FCF_ROW_EDGE ;
00600 if(fla & 0x4000) flags |= FCF_BROKEN_EDGE ;
00601
00602 pad &= 0x3FFF;
00603 time &= 0x7FFF;
00604
00605 fp = (double)pad / 64. ;
00606 ft = (double)time/ 64. ;
00607
00608
00609 if ( ft < minTimeBin ) continue ;
00610 if ( ft > maxTimeBin ) continue ;
00611 if ( c->charge < minClusterCharge ) continue ;
00612 if ( c->charge > maxClusterCharge ) continue ;
00613
00614 #ifdef MDEBUG
00615 LOG(ERR, "FtfSl3:readMezzaninne row %d \n", row ) ;
00616 LOG (ERR, "ft %f min max %d %d \n", ft, minTimeBin, maxTimeBin ) ;
00617 LOG (ERR "charge %d min max %d %d \n", c->charge, minClusterCharge, maxClusterCharge ) ;
00618 #endif
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 PTRS.Setptrs((double)fp, (double)ft,(double)row, (double)sector) ;
00629 getCoordinateTransformer()->raw_to_global(PTRS,XYZ) ;
00630
00631
00632
00633 hitP->id = nHits+counter ;
00634 hitP->row = row ;
00635 hitP->sector = sector ;
00636
00637 hitP->x = (float) XYZ.Getx();
00638 hitP->y = (float) XYZ.Gety();
00639 hitP->z = (float) XYZ.Getz();
00640
00641
00642 hitP->dx = xyError ;
00643 hitP->dy = xyError ;
00644 hitP->dz = zError ;
00645 hitP->buffer1 = pad ;
00646 hitP->buffer2 = time ;
00647 if(embedded)
00648 hitP->flags = (flags | (1<<7) );
00649 else
00650 hitP->flags = flags ;
00651 hitP->q = charge ;
00652 hitP->hardwareId = readOutBoard * 16 + mezzanninneNr ;
00653
00654
00655
00656
00657 hitP++;
00658
00659 counter++;
00660
00661
00662
00663
00664
00665 if ( (nHits+counter)>maxHits ) {
00666 LOG(ERR, "Error - FtfSl3:read: Hit array too small: %d + %d > %d \n",
00667 nHits, counter, maxHits ) ;
00668 return -1;
00669 }
00670 }
00671 }
00672 return counter;
00673 }
00674
00675
00676
00677
00678
00679
00680
00681
00682 int FtfSl3::readSector ( struct bankHeader *bank ) {
00683
00684 struct TPCSECLP *seclp;
00685 struct TPCRBCLP *rbclp ;
00686 struct TPCMZCLD_local *mzcld ;
00687 int iRb, kMz;
00688 int sector;
00689 int nHitsOfMz;
00690 embedded = 0;
00691
00692
00693
00694
00695
00696
00697
00698
00699 if ( 0 == strncmp(bank->bank_type, CHAR_TPCSECLP, 8 ) ){
00700
00701
00702
00703 seclp = (TPCSECLP *)bank;
00704
00705 } else if ( 0 == strncmp(bank->bank_type, CHAR_TPCSECP, 8 ) ){
00706
00707
00708
00709 if(bank->byte_order == DAQ_RAW_FORMAT_ORDER)
00710 seclp = (TPCSECLP *)((char*)bank + 4*bank->w9);
00711 else
00712 seclp = (TPCSECLP *)((char*)bank + 4*swap32(bank->w9));
00713
00714 } else {
00715
00716
00717 char type[9];
00718 strncpy(type, bank->bank_type, 8);
00719 type[8] = '\0';
00720 LOG(ERR,"readSector: Unknown bank type: '%s'\n", type);
00721
00722 return -1;
00723 }
00724
00725
00726
00727 nHits = 0;
00728
00729
00730
00731 short swapByte = 0 ;
00732 if ( !checkByteOrder(seclp->bh.byte_order) ) swapByte = 1 ;
00733
00734 nHitsOfMz = 0;
00735
00736 sector = (unsigned int)seclp->bh.bank_id ;
00737 if ( swapByte ) sector = swap32(sector) ;
00738
00739 sectorNr = sector;
00740 if ( sectorNr < 1 || sectorNr > 24 ) {
00741 LOG(ERR, "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
00742 return -1 ;
00743 }
00744
00745 sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
00746 para.phiMin = sectorG[sector-1].phiMin ;
00747 para.phiMax = sectorG[sector-1].phiMax ;
00748 para.etaMin = sectorG[sector-1].etaMin ;
00749 para.etaMax = sectorG[sector-1].etaMax ;
00750
00751
00752 for (iRb=0; iRb<SB_RB_NUM; iRb++) {
00753
00754 if (iRb==6) {
00755 sector++ ;
00756 if ( sector == 4 ) {
00757 para.phiMin = 0. ;
00758 para.phiMax = 1.1 ;
00759 para.phiShift = 0.8 ;
00760 }
00761 else if ( sector == 22 ) {
00762 para.phiMin = 0. ;
00763 para.phiMax = 1.1 ;
00764 para.phiShift = 0.27 ;
00765 }
00766 else {
00767 if ( sectorG[sector-1].phiMin < para.phiMin )
00768 para.phiMin = sectorG[sector-1].phiMin ;
00769 if ( sectorG[sector-1].phiMax > para.phiMax )
00770 para.phiMax = sectorG[sector-1].phiMax ;
00771 para.phiShift = 0 ;
00772 }
00773 if ( sectorG[sector-1].etaMin < para.etaMin )
00774 para.etaMin = sectorG[sector-1].etaMin ;
00775 if ( sectorG[sector-1].etaMax > para.etaMax )
00776 para.etaMax = sectorG[sector-1].etaMax ;
00777 }
00778
00779
00780
00781
00782 int off = (unsigned int)seclp->rb[iRb].off;
00783 if ( swapByte ) off = swap32(off);
00784 if ( !off ) continue ;
00785 rbclp = (struct TPCRBCLP *)((char *)seclp + off * 4) ;
00786
00787 int swapByteMezzaninne = 0 ;
00788 if ( !checkByteOrder(rbclp->bh.byte_order) ) swapByteMezzaninne = 1 ;
00789
00790
00791 for (kMz=0; kMz<RB_MZ_NUM; kMz++) {
00792
00793 if (!rbclp->mz[kMz].off) continue;
00794 off = rbclp->mz[kMz].off ;
00795 if ( swapByteMezzaninne ) off = swap32(off);
00796 mzcld = (struct TPCMZCLD_local *) ((char *)rbclp + off*4) ;
00797
00798 if(strncmp((char*)mzcld, "TPCMZCLD",8)!=0){
00799 if (swapByteMezzaninne) {
00800 LOG(ERR, "ERROR: TPCMZCLD header not found off=%d len=%d\n",
00801 swap32(rbclp->mz[kMz].off), swap32(rbclp->mz[kMz].len));
00802 } else {
00803 LOG(ERR, "ERROR: TPCMZCLD header not found off=%d len=%d\n",
00804 rbclp->mz[kMz].off, rbclp->mz[kMz].len);
00805 }
00806 continue;
00807 }
00808
00809 nHitsOfMz = readMezzanine (sector, iRb, kMz, mzcld);
00810 if (nHitsOfMz<0) {
00811 if (swapByteMezzaninne) {
00812 LOG(ERR, "ERROR: wrong reading mezzanine off=%d len=%d\n",
00813 swap32(rbclp->mz[kMz].off), swap32(rbclp->mz[kMz].len));
00814 } else {
00815 LOG(ERR,"ERROR: wrong reading mezzanine off=%d len=%d\n",
00816 rbclp->mz[kMz].off, rbclp->mz[kMz].len);
00817 }
00818 return -1;
00819 }
00820 nHits += nHitsOfMz;
00821
00822 }
00823 }
00824
00825
00826
00827 reset();
00828
00829 return 0;
00830 }
00831
00832
00833
00834
00835
00836
00837
00838 int FtfSl3::setTrackingAngles(int sector)
00839 {
00840 if(sector < 1 || sector > 24) {
00841 LOG(ERR, "Bad sector = %d",sector,0,0,0,0);
00842 return -1;
00843 }
00844
00845
00846 sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
00847 para.phiMin = sectorG[sector-1].phiMin ;
00848 para.phiMax = sectorG[sector-1].phiMax ;
00849 para.etaMin = sectorG[sector-1].etaMin ;
00850 para.etaMax = sectorG[sector-1].etaMax ;
00851
00852
00853 sector++ ;
00854 if ( sector == 4 ) {
00855 para.phiMin = 0.;
00856 para.phiMax = 1.1;
00857 para.phiShift = 0.8;
00858 }
00859 else if ( sector == 22 ) {
00860 para.phiMin = 0.;
00861 para.phiMax = 1.1;
00862 para.phiShift = 0.27;
00863 }
00864 else {
00865 if ( sectorG[sector-1].phiMin < para.phiMin )
00866 para.phiMin = sectorG[sector-1].phiMin ;
00867 if ( sectorG[sector-1].phiMax > para.phiMax )
00868 para.phiMax = sectorG[sector-1].phiMax ;
00869 para.phiShift = 0 ;
00870 }
00871
00872 if ( sectorG[sector-1].etaMin < para.etaMin )
00873 para.etaMin = sectorG[sector-1].etaMin ;
00874 if ( sectorG[sector-1].etaMax > para.etaMax )
00875 para.etaMax = sectorG[sector-1].etaMax ;
00876
00877 reset();
00878 return 0;
00879 }
00880
00882
00883
00884
00885
00886
00887 int FtfSl3::readSectorFromEvpReader(int sector) {
00888
00889
00890 embedded = 0;
00891
00892 l3xyzCoordinate XYZ(0,0,0);
00893 l3ptrsCoordinate PTRS(0,0,0,0);
00894
00895 sectorNr = sector;
00896 if ( sectorNr < 1 || sectorNr > 24 ) {
00897 LOG(ERR, "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
00898 return -1 ;
00899 }
00900
00901
00902 for(int r=0;r<45;r++) {
00903 #ifdef OLD_DAQ_READER
00904 for(int j=0;j<tpc.cl_counts[r];j++) {
00905 tpc_cl *c = &tpc.cl[r][j];
00906 #else
00907 for(int j=0;j<pTPC->cl_counts[r];j++) {
00908 tpc_cl *c = &pTPC->cl[r][j];
00909 #endif
00910
00911 FtfHit *hitP = &hit[nHits];
00912
00913
00914 if(c->t < minTimeBin) continue;
00915 if(c->t > maxTimeBin) continue;
00916 if(c->charge < minClusterCharge) continue;
00917 if(c->charge > maxClusterCharge) continue;
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930 PTRS.Setptrs(c->p - .5 , c->t - .5, r+1, sector);
00931 getCoordinateTransformer()->raw_to_global(PTRS, XYZ);
00932
00933 hitP->id = nHits;
00934 hitP->row = r+1;
00935 hitP->sector = sector;
00936 hitP->x = (float)XYZ.Getx();
00937 hitP->y = (float)XYZ.Gety();
00938 hitP->z = (float)XYZ.Getz();
00939 hitP->dx = xyError;
00940 hitP->dy = xyError;
00941 hitP->dz = zError;
00942 hitP->buffer1 = (int)((c->p - 0.5) * 64);
00943 hitP->buffer2 = (int)((c->t - 0.5) * 64);
00944
00945 if(embedded)
00946 hitP->flags = (c->flags | (1<<7));
00947 else
00948 hitP->flags = c->flags;
00949
00950 hitP->q = c->charge;
00951 hitP->hardwareId = 0;
00952
00953 nHits++;
00954 }
00955 }
00956
00957 return 0;
00958 }
00959
00960
00962
00963
00964
00965
00966
00967
00968 int FtfSl3::readSector (DATAP *datap, int sector) {
00969
00970 if ( sector < 1 && sector > 24 ) {
00971 LOG(ERR, "Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
00972 return -1 ;
00973 }
00974
00975 int off;
00976 int len;
00977
00978 int swapdatap=0;
00979 if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatap = 1;
00980 len = qswap32(swapdatap, datap->det[TPC_ID].len);
00981 off = qswap32(swapdatap, datap->det[TPC_ID].off);
00982 if(len == 0) return -1;
00983 if(off == 0) return -1;
00984
00985 TPCP *tpcp = (TPCP *)((u_int *)datap + off) ;
00986 int swaptpcp = 0;
00987 if(checkBank((char *)tpcp,"TPCP") < 0) return -1;
00988 if(tpcp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swaptpcp = 1;
00989 len = qswap32(swaptpcp, tpcp->sb[sector-1].len);
00990 off = qswap32(swaptpcp, tpcp->sb[sector-1].off);
00991 if(len == 0) return -1;
00992 if(off == 0) return -1;
00993
00994 TPCSECP *secp = (TPCSECP *)((u_int *)tpcp + off);
00995 int swapsecp = 0;
00996 if(checkBank((char *)secp,"TPCSECP") < 0) return -1;
00997 if(secp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapsecp = 1;
00998 off = qswap32(swapsecp, secp->bh.w9);
00999 if(off == 0) return -1;
01000
01001 TPCSECLP *seclp = (TPCSECLP *)((u_int *)secp + off);
01002 if(checkBank((char *)seclp,"TPCSECLP") < 0) return -1;
01003 readSector((bankHeader *)seclp);
01004
01005 return 0;
01006 }
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 int FtfSl3::readSector ( struct TPCSECLP *seclp1, struct TPCSECLP *seclp2 ) {
01017
01018 struct TPCRBCLP *rbclp ;
01019 struct TPCMZCLD_local *mzcld ;
01020 int iRb, kMz;
01021 int sector,tmpsector;
01022 int nHitsOfMz;
01023 struct TPCSECLP *seclp;
01024 short swapByte ;
01025
01026
01027 nHits = 0;
01028
01029
01030
01031 short swapByte1 = 0 ;
01032 short swapByte2 = 0;
01033 if ( !checkByteOrder(seclp1->bh.byte_order) ) swapByte1 = 1 ;
01034 if ( !checkByteOrder(seclp2->bh.byte_order) ) swapByte2 = 1 ;
01035
01036
01037
01038 sector = (unsigned int)seclp1->bh.bank_id ;
01039 if ( swapByte1 ) sector = swap32(sector) ;
01040 tmpsector = (unsigned int)seclp2->bh.bank_id ;
01041 if ( swapByte2 ) tmpsector = swap32(tmpsector) ;
01042
01043 if(tmpsector != sector){
01044 LOG(ERR,"Error in embedding got different sectors to read in\n");
01045 exit(1);
01046 }
01047 LOG(ERR,"sector: %i\n",sector);
01048
01049 sectorNr = sector;
01050 sectorGeometry* sectorG = (sectorGeometry *)sectorGeo ;
01051 para.phiMin = sectorG[sector-1].phiMin ;
01052 para.phiMax = sectorG[sector-1].phiMax ;
01053 para.etaMin = sectorG[sector-1].etaMin ;
01054 para.etaMax = sectorG[sector-1].etaMax ;
01055
01056
01057
01058 if ( sectorNr < 0 && sectorNr > 24 ) {
01059 LOG(ERR,"Error - FtfSl3::readSector: Wrong sector %d!\n",sectorNr);
01060 return -1 ;
01061 }
01062
01063 seclp = seclp1;
01064 swapByte = swapByte1;
01065 embedded = 0;
01066
01067 for(int embed=0;embed<2;embed++){
01068
01069
01070
01071
01072
01073 for (iRb=0; iRb<SB_RB_NUM; iRb++) {
01074
01075 if (iRb==6) {
01076 sector++ ;
01077 if ( sector == 4 ) {
01078 para.phiMin = 0. ;
01079 para.phiMax = 1.1 ;
01080 para.phiShift = 0.8 ;
01081 }
01082 else if ( sector == 22 ) {
01083 para.phiMin = 0. ;
01084 para.phiMax = 1.1 ;
01085 para.phiShift = 0.27 ;
01086 }
01087 else {
01088 if ( sectorG[sector-1].phiMin < para.phiMin ) para.phiMin = sectorG[sector-1].phiMin ;
01089 if ( sectorG[sector-1].phiMax > para.phiMax ) para.phiMax = sectorG[sector-1].phiMax ;
01090 para.phiShift = 0 ;
01091 }
01092 if ( sectorG[sector-1].etaMin < para.etaMin ) para.etaMin = sectorG[sector-1].etaMin ;
01093 if ( sectorG[sector-1].etaMax > para.etaMax ) para.etaMax = sectorG[sector-1].etaMax ;
01094 }
01095
01096
01097
01098 if ( !(unsigned int)seclp->rb[iRb].off) continue ;
01099
01100 int off = (unsigned int)seclp->rb[iRb].off;
01101 if ( swapByte ) off = swap32(off);
01102 rbclp = (struct TPCRBCLP *)((char *)seclp + off * 4) ;
01103 int swapByteMezzaninne = 0 ;
01104 if ( !checkByteOrder(rbclp->bh.byte_order) ) swapByteMezzaninne = 1 ;
01105
01106
01107 for (kMz=0; kMz<RB_MZ_NUM; kMz++) {
01108
01109 if( ! rbclp->mz[kMz].off) {
01110 continue;
01111 }
01112 #ifdef TRDEBUG
01113 else {
01114 if ( debugLevel > 1 ) {
01115 LOG(ERR, "FtfSl3::readSector: MZCLD %d exists!\n", kMz+1) ;
01116 }
01117 }
01118 #endif
01119
01120 off = rbclp->mz[kMz].off ;
01121 if ( swapByteMezzaninne ) off = swap32(off);
01122 if (off == 0) continue;
01123 mzcld = (struct TPCMZCLD_local *) ((char *)rbclp + off*4) ;
01124
01125 if (mzcld) {
01126 if(strncmp((char*)mzcld, "TPCMZCLD",8)!=0){
01127 LOG(ERR, "ERROR: TPCMZCLD header not found\n");
01128 continue;
01129 }
01130
01131 nHitsOfMz = readMezzanine (sector, iRb, kMz, mzcld);
01132 if (nHitsOfMz<0) {
01133 LOG(ERR, "FtfSl3:readSector: wrong reading mezzanine \n" ) ;
01134 return -1;
01135 }
01136 nHits += nHitsOfMz;
01137 }
01138
01139 }
01140 }
01141
01142 seclp = seclp2;
01143 swapByte = swapByte2;
01144 embedded = 1;
01145
01146 sector = sectorNr;
01147 }
01148
01149
01150
01151
01152 reset();
01153
01154 return 0;
01155 }
01156
01157
01158
01159
01160 int FtfSl3::processSector ( ){
01161
01162
01163
01164 for ( int h = 0 ; h < nHits ; h++ ) {
01165 hit[h].track = 0 ;
01166 }
01167 para.eventReset = 1 ;
01168 nTracks = 0 ;
01169 process ( ) ;
01170 if (para.dEdx) dEdx();
01171
01172 if ( debugLevel > 0 )
01173 LOG(ERR," FtfSl3::process: tracks %i Time: real %f cpu %f\n",
01174 nTracks, realTime, cpuTime ) ;
01175
01176
01177 return 0;
01178 }
01179
01180
01181
01182 #if 0
01183 int FtfSl3::processData(TPCSECLP* seclp, char* trackBuffer,
01184 int maxTrackBytes, int& nTrackBytes,
01185 char* hitBuffer, int maxHitBytes, int& nHitBytes)
01186 {
01187
01188 short swapByte = 0;
01189 if (!checkByteOrder(seclp->bh.byte_order)) swapByte = 1;
01190
01191 int token = (unsigned int)seclp->bh.token;
01192 if (swapByte) token = swap32(token);
01193
01194 readSector(seclp);
01195 processSector();
01196
01197
01198 if (trackBuffer) {
01199 int ret = fillTracks(maxTrackBytes, trackBuffer, token);
01200 if (ret>0) nTrackBytes = ret;
01201 else return 1;
01202 }
01203
01204 if (hitBuffer) {
01205 int ret = fillHits(maxHitBytes, hitBuffer, token);
01206 if (ret>0) nHitBytes = ret;
01207 else return 1;
01208 }
01209 return 0;
01210 }
01211 #endif
01212
01213
01214
01215
01216 int FtfSl3::dEdx ( ) {
01217
01218 for ( int i = 0 ; i<nTracks ; i++ ){
01219 if (track[i].nHits<para.minHitsForDedx) {
01220 track[i].nDedx = 0;
01221 track[i].dedx = 0;
01222 continue;
01223 }
01224 fDedx->TruncatedMean(&track[i]);
01225 }
01226 return 0;
01227 }
01228
01229
01230
01231 int FtfSl3::setParameters ( ) {
01232
01233
01234
01235 xyError = 0.12 ;
01236 zError = 0.24 ;
01237 para.hitChi2Cut = 50. ;
01238 para.goodHitChi2 = 20. ;
01239 para.trackChi2Cut = 10. ;
01240 para.maxChi2Primary = 50. ;
01241 para.segmentRowSearchRange = 2 ;
01242 para.trackRowSearchRange = 3 ;
01243 para.dphi = 0.08F ;
01244 para.deta = 0.08F ;
01245 para.dphiMerge = 0.01F ;
01246 para.detaMerge = 0.02F ;
01247 para.etaMinTrack = -2.2F ;
01248 para.etaMaxTrack = 2.2F ;
01249
01250 para.dEdx = 1 ;
01251
01252 para.getErrors = 0 ;
01253 para.goBackwards = 1 ;
01254 para.goodDistance = 5.F ;
01255 para.mergePrimaries = 0 ;
01256 para.maxDistanceSegment = 50.F ;
01257 para.minHitsPerTrack = 5 ;
01258 para.nHitsForSegment = 2 ;
01259 para.nEta = 40 ;
01260 para.nEtaTrack = 40 ;
01261 para.nPhi = 10 ;
01262 para.nPhiTrack = 40 ;
01263 para.nPrimaryPasses = 1 ;
01264 para.nSecondaryPasses = 0 ;
01265 para.xyErrorScale = 1.0F ;
01266 para.szErrorScale = 1.0F ;
01267 para.phiClosed = 0 ;
01268
01269
01270 para.ptMinHelixFit = 0.1 ;
01271 para.rVertex = 0.F ;
01272 para.xVertex = 0.F ;
01273 para.yVertex = 0.F ;
01274 para.zVertex = 0.F ;
01275 para.dxVertex = 0.05F ;
01276 para.dyVertex = 0.05F ;
01277 para.phiVertex = 0.F ;
01278
01279 para.zMax = 205. ;
01280 return 0;
01281 }
01282
01283
01284
01285
01286