4 #define TRG_VERSION 0x32
10 #include <daqFormats.h>
11 #include "l3CoordinateTransformer.h"
16 #include <evpReader.hh>
18 #include <DAQ_READER/daqReader.h>
21 #include "eventTrackerLib.hh"
22 #include <DAQ_L3/daq_l3.h>
26 int EventTracker::trackEvent(
evpReader *evp,
char *mem,
L3_P *l3p,
int max_size)
28 int EventTracker::trackEvent(
daqReader *rdr,
char *mem,
L3_P *l3p,
int max_size)
34 char *buff = (
char *)l3p;
39 ret = trackTPC(evp, mem, gtd, max_size -
sizeof(
L3_P));
41 ret = trackTPC(rdr, mem, gtd, max_size -
sizeof(
L3_P));
44 LOG(DBG,
"gtd: nHits=%d", gtd->nHits);
47 memset(l3p, 0,
sizeof(
L3_P));
49 memcpy(l3p->bh.bank_type, CHAR_L3_P, 8);
50 l3p->bh.length =
sizeof(
L3_P) / 4;
52 l3p->bh.format_ver = DAQ_RAW_FORMAT_VERSION;
53 l3p->bh.byte_order = DAQ_RAW_FORMAT_ORDER;
54 l3p->bh.format_number = 0;
56 l3p->bh.w9 = DAQ_RAW_FORMAT_WORD9;
60 l3p->len = (
sizeof(
L3_P) + gtd->bh.length * 4) / 4;
63 int sdatap = (datap->bh.byte_order == DAQ_RAW_FORMAT_ORDER) ? 0 : 1;
66 l3p->time = qswap32(sdatap, datap->time);
68 l3p->trg_word = qswap32(sdatap, datap->trg_word);
69 l3p->trg_in_word = qswap32(sdatap, datap->trg_in_word);
72 l3p->tracks.off =
sizeof(
L3_P) / 4;
73 l3p->tracks.len = gtd->bh.length;
79 int EventTracker::trackTPC(
evpReader *rdr,
char *mem,
L3_GTD *gtd,
int max_size)
81 int EventTracker::trackTPC(
daqReader *rdr,
char *mem,
L3_GTD *gtd,
int max_size)
85 int ret = gl3->readFromEvpReader(rdr, 1000);
87 return gl3Event_to_GTD(gtd, max_size);
91 int EventTracker::gl3Event_to_GTD(
L3_GTD *gtd, u_int max_size)
94 memcpy(gtd->bh.bank_type, CHAR_L3_GTD, 8);
96 gtd->bh.format_ver = DAQ_RAW_FORMAT_VERSION;
97 gtd->bh.byte_order = DAQ_RAW_FORMAT_ORDER;
98 gtd->bh.format_number = 0;
100 gtd->bh.w9 = DAQ_RAW_FORMAT_WORD9;
106 if(gtd->bh.length * 4 > max_size) {
107 LOG(ERR,
"GDT length needs to be %d bytes, but max buffers size only %d bytes",
108 gtd->bh.length * 4, max_size,0,0,0);
116 gtd->xVert = gl3->getVertex().Getx();
117 gtd->yVert = gl3->getVertex().Gety();
118 gtd->zVert = gl3->getVertex().Getz();
119 gtd->nTracks = gl3->getNTracks();
121 for(uint i=0;i<gtd->nTracks;i++) {
124 gl3Track *gl3track = gl3->getTrack(i);
126 gtrack.id = gl3track->id;
127 gtrack.flag = gl3track->flag;
128 gtrack.innerMostRow = gl3track->innerMostRow;
129 gtrack.outerMostRow = gl3track->outerMostRow;
131 gtrack.nHits = gl3track->nHits;
132 gtd->nHits += gtrack.nHits;
135 gtrack.ndedx = gl3track->nDedx;
136 gtrack.q = gl3track->q;
137 gtrack.chi2[0] = gl3track->chi2[0];
138 gtrack.chi2[1] = gl3track->chi2[1];
139 gtrack.dedx = gl3track->dedx;
140 gtrack.pt = gl3track->pt;
141 gtrack.phi0 = gl3track->phi0;
142 gtrack.psi = gl3track->psi;
143 gtrack.r0 = gl3track->r0;
144 gtrack.tanl = gl3track->tanl;
145 gtrack.z0 = gl3track->z0;
146 gtrack.length = gl3track->length;
147 gtrack.dpt = gl3track->dpt;
148 gtrack.dpsi = gl3track->dpsi;
149 gtrack.dz0 = gl3track->dz0;
150 gtrack.dtanl = gl3track->dtanl;
159 void EventTracker::dumpGTD(
L3_GTD *gtd)
161 if(memcmp(gtd->bh.bank_type,
"L3_GTD", 5) != 0) {
162 printf(
"Not a L3_GTD Bank: %s\n",gtd->bh.bank_type);
166 printf(
"Computed: Tracks: %5d: Vertex: (%6.2f/%6.2f/%6.2f)\n",
167 gtd->nTracks,gtd->xVert, gtd->yVert, gtd->zVert);
169 for(u_int i=0;i<gtd->nTracks;i++) {
173 printf(
"%5d: pt=%5.3f z0=%7.2f q=%2d nHits=%2d ndedx=%2d ",
174 i, track->pt, track->z0, track->q,
175 track->nHits, track->ndedx);
177 printf(
"flag=0x%04x iRow=%2d oRow=%2d\n",
178 track->flag, track->innerMostRow,
179 track->outerMostRow);
184 int EventTracker::copyl3_t(
l3_t &l3,
L3_P *l3p)
186 int len = l3p->bh.length;
188 l3.max_channels = 1280000 ;
196 l3.xVertex = -1000.0 ;
197 l3.yVertex = -1000.0 ;
198 l3.zVertex = -1000.0 ;
200 LOG(DBG,
"L3_P bytes %d",len,0,0,0) ;
202 if(checkBank(l3p->bh.bank_type,
"L3_P") != 0) {
207 if(l3p->tracks.len && l3p->tracks.off){
209 (
struct L3_GTD*)((
char*)l3p + l2h32(l3p->tracks.off)*4) ;
212 if(checkBank(l3gtd->bh.bank_type,
"L3_GTD") < 0) {
216 LOG(NOTE,
"l3gtd->nTracks=%d nHits=%d", l2h32(l3gtd->nTracks), l2h32(l3gtd->nHits));
217 l3.tracks_num = l2h32(l3gtd->nTracks);
218 l3.cluster_num = l2h32(l3gtd->nHits);
219 l3.xVertex = l2hfloat(l3gtd->xVert);
220 l3.yVertex = l2hfloat(l3gtd->yVert);
221 l3.zVertex = l2hfloat(l3gtd->zVert);
224 if(l3.tracks_num >= L3_MAX_NR_TRACKS) {
225 LOG(ERR,
"L3 track number %d > %d!",l3.tracks_num,L3_MAX_NR_TRACKS ,0,0,0) ;
230 for (
unsigned int i=0; i<l3.tracks_num; i++) {
233 l3.track[i].id = l2h32(tr->id);
235 #ifndef UNIX_LITTLE_ENIDAN
236 l3.track[i].flag = tr->flag;
237 l3.track[i].innerMostRow = tr->innerMostRow;
238 l3.track[i].outerMostRow = tr->outerMostRow;
240 l3.track[i].nHits = tr->nHits;
241 l3.track[i].ndedx = tr->ndedx;
242 l3.track[i].q = tr->q;
244 l3.track[i].flag = ( ((
unsigned short)tr->innerMostRow) |
245 ((
unsigned short)tr->outerMostRow)<<8);
246 l3.track[i].innerMostRow = (char)( tr->flag & 0x00ff );
247 l3.track[i].outerMostRow = (char)((tr->flag & 0xff00)>>8);
249 l3.track[i].nHits = (
unsigned char)tr->q;
250 l3.track[i].reserved = (
char)tr->ndedx;
251 l3.track[i].ndedx = (
unsigned char)tr->reserved;
252 l3.track[i].q = (
char)tr->nHits;
254 l3.track[i].chi2[0] = l2hfloat(tr->chi2[0]);
255 l3.track[i].chi2[1] = l2hfloat(tr->chi2[1]);
256 l3.track[i].dedx = l2hfloat(tr->dedx);
257 l3.track[i].pt = l2hfloat(tr->pt);
258 l3.track[i].phi0 = l2hfloat(tr->phi0);
259 l3.track[i].psi = l2hfloat(tr->psi);
260 l3.track[i].r0 = l2hfloat(tr->r0);
261 l3.track[i].tanl = l2hfloat(tr->tanl);
262 l3.track[i].z0 = l2hfloat(tr->z0);
263 l3.track[i].length = l2hfloat(tr->length);
264 l3.track[i].dpt = l2hfloat(tr->dpt);
265 l3.track[i].dpsi = l2hfloat(tr->dpsi);
266 l3.track[i].dz0 = l2hfloat(tr->dz0);
267 l3.track[i].dtanl = l2hfloat(tr->dtanl);
275 #ifdef SHOW_DEBUG_INFO
277 #ifdef UNIX_LITTLE_ENDIAN
278 printf(
"Running on LITTLE endian machine\n");
280 printf(
"Running on BIG endian machine\n");
283 printf(
"\nVertex: (%6.2f/%6.2f/%6.2f)\n",
284 l3.xVertex, l3.yVertex, l3.zVertex);
286 printf(
"Tracks: %5d Clusters %7d\n",
287 l3.tracks_num, l3.cluster_num);
289 for (
unsigned int i=0; i<l3.tracks_num; i++) {
290 printf(
"%5d: pt=%5.3f z0=%7.2f q=%2d nHits=%2d ndedx=%2d ",
291 i, l3.track[i].pt, l3.track[i].z0, l3.track[i].q,
292 l3.track[i].nHits, l3.track[i].ndedx);
294 printf(
"flag=0x%04x iRow=%2d oRow=%2d\n",
295 l3.track[i].flag, l3.track[i].innerMostRow,
296 l3.track[i].outerMostRow);