13 #include "Stl3Util/gl3/gl3Event.h"
15 #include "Stl3Util/base/realcc.h"
16 #include "Stl3Util/base/FtfLog.h"
22 gl3Event::gl3Event(
int mxHits,
int mxTracks,
32 maxSectorNForTrackMerging = 1000000;
33 coordinateTransformer = inTrans;
34 setup( mxHits, mxTracks );
39 gl3Event::~gl3Event( )
41 if (
hit != 0 )
delete[]
hit ;
43 if ( trackContainer != 0 )
delete[] trackContainer;
44 if ( trackIndex != 0 )
delete[] trackIndex ;
53 gl3Track* gl3Event::getTrack (
int n ) {
54 if ( n < 0 || n > nTracks ) {
55 fprintf ( stderr,
" %d track index out of range \n", n );
62 gl3Hit* gl3Event::getHit (
int n ) {
63 if ( n < 0 || n > nHits ) {
64 fprintf ( stderr,
" %d hit index out of range \n", n );
70 gl3Sector* gl3Event::getSector (
int n ) {
71 if ( n < 0 || n > NSECTORS ) {
72 fprintf ( stderr,
" %d sector index out of range \n", n );
75 return &(sectorInfo[n]);
79 int gl3Event::getTrgCmd()
81 return trgData.trgCmd;
84 int gl3Event::getTrgWord()
86 return trgData.trgWord;
89 int gl3Event::getZDC(
int n)
91 return trgData.ZDC[n];
94 int gl3Event::getCTB(
int n)
96 return trgData.CTB[n];
108 int indexStore = -1 ;
111 for (
int i = 0 ; i < nTrk ; i++ ) {
112 lTrack->
set ( sector, trk ) ;
113 lTrack->id = sector * 1000 + abs(trk->id) ;
114 lTrack->para = ¶ ;
115 lTrack->sector = sector ;
121 if ( hitProcessing ) {
123 if ( abs(idTrack) < maxTracksSector )
124 indexStore = (sector-1)*maxTracksSector + abs(idTrack) ;
126 ftfLog (
" gl3Event::addTracks: max number of tracks per Sector reached %d reached\n",
134 if ( maxSectorNForTrackMerging > nTrk && idTrack < 0 ) {
136 fatterTrack = lTrack->merge ( trackContainer ) ;
139 if ( hitProcessing && indexStore > 0 ) {
140 trackIndex[indexStore] =
151 if ( hitProcessing && indexStore > 0 )
152 trackIndex[indexStore] = nTracks + 1;
158 if ( nTracks+1 >= maxTracks ) {
159 ftfLog (
" gl3Event::addTracks: max number of tracks %d reached, sector: %i nrSectorTracks: %i\n", maxTracks, sector, nTrk ) ;
172 int gl3Event::fillTracks (
int maxBytes,
char* buffer,
unsigned int token ){
177 if ( nBytesNeeded > maxBytes ) {
178 ftfLog (
" gl3Event::writeTracks: %d bytes needed less than max = %d \n",
179 nBytesNeeded, maxBytes ) ;
185 head->nHits = nHits ;
191 memcpy(head->bh.bank_type,CHAR_L3_GTD,8);
192 head->bh.bank_id = 1;
193 head->bh.format_ver = DAQ_RAW_FORMAT_VERSION ;
194 head->bh.byte_order = DAQ_RAW_FORMAT_ORDER ;
195 head->bh.format_number = 0;
196 head->bh.token = token;
197 head->bh.w9 = DAQ_RAW_FORMAT_WORD9;
199 head->bh.length = (
sizeof(
struct L3_GTD)
208 for (
int i = 0 ; i < nTracks ; i++ ) {
209 if ( fabs(
track[i].z0) > 205 ) {
215 oTrack->id =
track[i].id ;
216 oTrack->flag =
track[i].flag ;
217 oTrack->innerMostRow =
track[i].innerMostRow ;
218 oTrack->outerMostRow =
track[i].outerMostRow ;
219 oTrack->nHits =
track[i].nHits ;
220 oTrack->ndedx =
track[i].nDedx ;
221 oTrack->q =
track[i].q ;
222 oTrack->chi2[0] =
track[i].chi2[0] ;
223 oTrack->chi2[1] =
track[i].chi2[1] ;
224 oTrack->dedx =
track[i].dedx ;
225 oTrack->pt =
track[i].pt ;
226 oTrack->phi0 =
track[i].phi0 ;
227 oTrack->r0 =
track[i].r0 ;
228 oTrack->z0 =
track[i].z0 ;
229 oTrack->psi =
track[i].psi ;
230 oTrack->tanl =
track[i].tanl ;
231 oTrack->length =
track[i].length ;
232 oTrack->dpt =
track[i].dpt ;
233 oTrack->dpsi =
track[i].dpsi ;
234 oTrack->dz0 =
track[i].dz0 ;
235 oTrack->dtanl =
track[i].dtanl ;
239 head->nTracks = counter ;
243 return ((
char *)oTrack-buffer) ;
255 ftfLog(
"gl3Event::readEventDescriptor: got NULL pointer");
259 trgData.trgCmd = ((descr->TRG_DAQ_cmds) & 0xf0) >> 4;
260 trgData.trgWord = descr->TRG_word;
272 int gl3Event::readL3Data(
L3_P* header )
275 char* buffer = (
char *)header;
285 for ( i = 0 ; i < NSECTORS ; i++ ) {
286 length = header->sector[i].len ;
288 if ( length==0 ) continue ;
290 offset = 4 * header->sector[i].off ;
291 sectorP = (
L3_SECP *)&(buffer[offset]);
292 trackPointer = (
char *)sectorP + sectorP->trackp.off * 4 ;
293 int nSectorTracks = readSectorTracks ( trackPointer ) ;
295 if ( nSectorTracks < 0 ) {
296 ftfLog(
"gl3Event:readEvent: error reading tracks, sector %d \n",
301 if ( hitProcessing && sectorP->sl3clusterp.off ) {
302 hitPointer = (
char *)sectorP + sectorP->sl3clusterp.off * 4 ;
303 readSectorHits ( hitPointer, nSectorTracks ) ;
321 for (
int i = 0 ; i < nTracks ; i++ ) {
323 radius = coordinateTransformer->
324 GetRadialDistanceAtRow(
track[i].innerMostRow-1) ;
326 track[i].updateToRadius ( radius ) ;
330 if ( fabs(
track[i].z0) > 205 )
track[i].updateToRadius ( radius+5. ) ;
331 if ( fabs(
track[i].z0) > 205 ) {
332 ftfLog (
"gl3Event:: problem after extrapolation id %d z0 %f\n",
352 if (trgSum != NULL) {
354 for (
int i=0; i<16; i++) {
355 trgData.ZDC[i] = trgSum->DSM.ZDC[i];
359 if (rawTrg != NULL) {
366 for (
int chunk=0; chunk<16; chunk++) {
367 for (
int slat=0; slat<15; slat++) {
368 trgData.CTB[15*chunk + slat] =
369 rawTrg->CTB[16*chunk + slat];
381 int gl3Event::readSectorHits (
char* buffer,
int nSectorTracks ){
386 if ( !coordinateTransformer ) {
387 ftfLog(
"gl3Event::readSectorHits: there is not Coordinate Transformer \n");
395 if ( strncmp(head->bh.bank_type,CHAR_L3_SECCD,8) ) {
396 ftfLog (
"gl3Event::readSectorHits: wrong bank type %s\n",
397 head->bh.bank_type ) ;
398 ftfLog (
" right bank type %s \n", CHAR_L3_SECCD ) ;
401 int sector = head->bh.bank_id;
402 int nSectorHits = head->nrClusters_in_sector ;
407 if ( nHits + nSectorHits > maxHits ) {
408 ftfLog(
"gl3Event:readSectorHits: not enough space for hits in sector %d\n",
410 ftfLog (
" maxHits %d nSectorHits %d nHits %d \n", maxHits,
411 nSectorHits, nHits ) ;
419 for (
int i = 0 ; i < nSectorHits ; i++ ) {
420 hitP = &(cluster[i]) ;
424 if ( hitProcessing > 1 ) {
425 gHitP = &(
hit[nHits+i]);
426 gHitP->set (coordinateTransformer, sector, hitP);
432 int trkId = hitP->trackId ;
433 if ( trkId < 0 || trkId > nSectorTracks ) {
434 ftfLog (
"gl3Event:readSectorHits: %d wrong track id in hit of sector %d \n",
438 int indexStore = (sector-1)*maxTracksSector+trkId ;
439 if ( indexStore < 0 || indexStore > NSECTORS*maxTracksSector ) {
440 ftfLog (
"gl3Event:readSectorHits: %d wrong indexStore\n",
444 int index = trackIndex[indexStore] - 1 ;
445 if ( index < 0 || index > nTracks ) continue ;
450 if ( hitProcessing > 1 ) {
451 if (
track[index].firstHit == 0 )
452 track[index].firstHit = (
void *)gHitP ;
454 ((
gl3Hit *)(
track[index].lastHit))->nextHit = (
void *)gHitP ;
455 track[index].lastHit = (
void *)gHitP ;
456 gHitP->trackId =
track[index].id ;
461 hitP->trackId =
track[index].id ;
465 nHits += nSectorHits ;
475 int gl3Event::readSectorTracks (
char* buffer ){
479 if ( strncmp(head->bh.bank_type,CHAR_L3_SECTP,8) ) {
480 ftfLog (
"gl3Event::readSectorTracks, wrong bank type %s\n",
481 head->bh.bank_type ) ;
485 int sector = head->bh.bank_id ;
486 if ( sector < 0 || sector > NSECTORS ) {
487 ftfLog (
" gl3Event::readSector: %d wrong sector \n", sector ) ;
491 gl3Sector* sectorP = &(sectorInfo[sector-1]) ;
492 sectorP->filled = 1 ;
493 sectorP->nHits = head->nHits ;
494 sectorP->nTracks = head->nTracks ;
495 sectorP->cpuTime = head->cpuTime ;
496 sectorP->realTime = head->realTime ;
497 sectorP->xVert = float(head->xVert)/1000000 ;
498 sectorP->yVert = float(head->yVert)/1000000 ;
499 sectorP->zVert = float(head->zVert)/1000000 ;
500 sectorP->rVert = ::sqrt((
double)( sectorP->xVert*sectorP->xVert +
501 sectorP->yVert*sectorP->yVert)) ;
502 sectorP->phiVert = atan2((
double)sectorP->yVert,(
double)sectorP->xVert) ;
503 if ( sectorP->phiVert < 0 ) sectorP->phiVert += 2. * M_PI ;
509 para.xVertex = sectorP->xVert ;
510 para.yVertex = sectorP->yVert ;
511 para.zVertex = sectorP->zVert ;
512 para.rVertex = sectorP->rVert ;
513 para.phiVertex = sectorP->phiVert ;
515 char* pointer = head->banks[0].off * 4 + buffer ;
518 if ( (head->banks[0].len > 0) && (head->bh.format_number > 0) ) {
520 nSectorTracks = (4 * head->banks[0].len -
sizeof(
struct bankHeader))
523 else nSectorTracks = 0 ;
527 if ( nSectorTracks > 0 ) {
530 addTracks ( sector, nSectorTracks, localTrack ) ;
534 return sectorP->nTracks ;
541 void gl3Event::makeVertex (){
554 vertex.Setxyz(0.0,0.0,0.0);
557 for(
int iter = 0 ; iter<1; iter++ ) {
559 for(
int trkcnt = 0 ; trkcnt<getNTracks(); trkcnt++ ) {
560 gTrack = getTrack(trkcnt);
563 if ( gTrack->nHits > minNoOfHitsOnTrackUsedForVertexCalc &&
564 gTrack->pt > minMomUsedForVertexCalc) {
566 closestHit = gTrack->closestApproach(getVertex().Getx(),
569 hVz->
Fill(closestHit.z,1.0);
570 hVx->
Fill(closestHit.x,1.0);
571 hVy->
Fill(closestHit.y,1.0);
576 vertex.Setxyz(hVx->getWeightedMean(6.0),
577 hVy->getWeightedMean(6.0),
578 hVz->getWeightedMean(4.0));
587 int gl3Event::resetEvent ( ){
591 nMergableTracks = 0 ;
596 memset(trackContainer, 0,
597 para.nPhiTrackPlusOne*para.nEtaTrackPlusOne*
sizeof(
FtfContainer));
601 memset ( trackIndex, 0, maxTracksSector*NSECTORS*
sizeof(
int) ) ;
604 for (
int i=0; i<16; i++)
607 for (
int i=0; i<240; i++)
624 int gl3Event::setup (
int mxHits,
int mxTracks )
627 if ( mxHits < 0 || mxHits > 1000000 ) {
628 ftfLog(
" gl3Event::setup: maxHits %d out of range \n", maxHits ) ;
632 if ( mxTracks < 0 || mxTracks > 1000000 ) {
633 ftfLog(
" gl3Event::setup: maxTracks %d out of range \n", maxTracks );
639 maxTracks = mxTracks ;
640 maxTracksSector = maxTracks*2/ NSECTORS ;
643 trackIndex =
new int[maxTracksSector*NSECTORS];
649 para.nPhiTrackPlusOne = para.nPhiTrack + 1 ;
650 para.nEtaTrackPlusOne = para.nEtaTrack + 1 ;
654 para.phiSliceTrack = (para.phiMaxTrack - para.phiMinTrack)/para.nPhiTrack;
655 para.etaSliceTrack = (para.etaMaxTrack - para.etaMinTrack)/para.nEtaTrack;
657 int nTrackVolumes = para.nPhiTrackPlusOne* para.nEtaTrackPlusOne ;
659 if(trackContainer == NULL) {
660 ftfLog (
"Problem with memory allocation... exiting\n") ;
664 para.ptMinHelixFit = 1.e60 ;
671 minNoOfHitsOnTrackUsedForVertexCalc=14;
672 minMomUsedForVertexCalc=0.25;
679 hVz =
new gl3Histo (
"Vertex_Vz",
"Vertex_Vz", 400, -200., 200. ) ;
683 hVx =
new gl3Histo (
"Vertex_Vx",
"Vertex_Vx", 100,-10,10);
688 hVy =
new gl3Histo (
"Vertex_Vy",
"Vertex_Vy", 100,-10,10);
void set(short sectorIn, local_track *trk)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
int Reset()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void addTracks(bool cuts=false)
Add tracks to the list of the rendered objects from current MuDst event.
int Fill(double x, double weight=1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...