StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
eventTrackerLib.cxx
1 // Switch between l3t and ftf in sl3.h!!!
2 
3 #ifndef TRG_VERSION
4 #define TRG_VERSION 0x32
5 #endif
6 
7 #include <unistd.h>
8 #include <string.h>
9 #include <setjmp.h>
10 #include <daqFormats.h>
11 #include "l3CoordinateTransformer.h"
12 #include <rts.h>
13 #include "rtsLog.h"
14 #include "FtfSl3.h"
15 #ifdef OLD_DAQ_READER
16 #include <evpReader.hh>
17 #else /* OLD_DAQ_READER */
18 #include <DAQ_READER/daqReader.h>
19 #endif /* OLD_DAQ_READER */
20 #include "gl3Event.h"
21 #include "eventTrackerLib.hh"
22 #include <DAQ_L3/daq_l3.h>
23 
24 
25 #ifdef OLD_DAQ_READER
26 int EventTracker::trackEvent(evpReader *evp, char *mem, L3_P *l3p, int max_size)
27 #else /* OLD_DAQ_READER */
28 int EventTracker::trackEvent(daqReader *rdr, char *mem, L3_P *l3p, int max_size)
29 #endif /* OLD_DAQ_READER */
30 {
31  DATAP *datap = (DATAP *)mem;
32  // Build L3_p
33  int ret=0;
34  char *buff = (char *)l3p;
35 
36  // First do tracking...
37  L3_GTD *gtd = (L3_GTD *)(buff + sizeof(L3_P));
38 #ifdef OLD_DAQ_READER
39  ret = trackTPC(evp, mem, gtd, max_size - sizeof(L3_P));
40 #else /* OLD_DAQ_READER */
41  ret = trackTPC(rdr, mem, gtd, max_size - sizeof(L3_P));
42 #endif /* OLD_DAQ_READER */
43 
44  LOG(DBG, "gtd: nHits=%d", gtd->nHits);
45 
46  // Now build the L3_P bank...
47  memset(l3p, 0, sizeof(L3_P));
48 
49  memcpy(l3p->bh.bank_type, CHAR_L3_P, 8);
50  l3p->bh.length = sizeof(L3_P) / 4;
51  l3p->bh.bank_id = 0;
52  l3p->bh.format_ver = DAQ_RAW_FORMAT_VERSION;
53  l3p->bh.byte_order = DAQ_RAW_FORMAT_ORDER;
54  l3p->bh.format_number = 0;
55  l3p->bh.token = 0;
56  l3p->bh.w9 = DAQ_RAW_FORMAT_WORD9;
57  l3p->bh.crc = 0;
58 
59  // Pick up trigger info from datap if possible...
60  l3p->len = (sizeof(L3_P) + gtd->bh.length * 4) / 4;
61 
62  // do we need to swap datap?
63  int sdatap = (datap->bh.byte_order == DAQ_RAW_FORMAT_ORDER) ? 0 : 1;
64 
65 
66  l3p->time = qswap32(sdatap, datap->time);
67  l3p->gl3Id = 0;
68  l3p->trg_word = qswap32(sdatap, datap->trg_word);
69  l3p->trg_in_word = qswap32(sdatap, datap->trg_in_word);
70 
71  // Currently only fill tracks...
72  l3p->tracks.off = sizeof(L3_P) / 4;
73  l3p->tracks.len = gtd->bh.length;
74 
75  return ret;
76 }
77 
78 #ifdef OLD_DAQ_READER
79 int EventTracker::trackTPC(evpReader *rdr, char *mem, L3_GTD *gtd, int max_size)
80 #else /* OLD_DAQ_READER */
81 int EventTracker::trackTPC(daqReader *rdr, char *mem, L3_GTD *gtd, int max_size)
82 #endif /* OLD_DAQ_READER */
83 {
84  // bField != 1000 means use it, 1000 means take from file...
85  int ret = gl3->readFromEvpReader(rdr, 1000);
86  //LOG("JEFF", "readFromEvpReader: %d\n", ret);
87  return gl3Event_to_GTD(gtd, max_size);
88 }
89 
90 
91 int EventTracker::gl3Event_to_GTD(L3_GTD *gtd, u_int max_size)
92 {
93  // Build GTD...
94  memcpy(gtd->bh.bank_type, CHAR_L3_GTD, 8);
95  gtd->bh.bank_id = 1;
96  gtd->bh.format_ver = DAQ_RAW_FORMAT_VERSION;
97  gtd->bh.byte_order = DAQ_RAW_FORMAT_ORDER;
98  gtd->bh.format_number = 0;
99  gtd->bh.token = 0;
100  gtd->bh.w9 = DAQ_RAW_FORMAT_WORD9;
101  gtd->bh.crc = 0;
102 
103  // GTD structure already includes one track
104  gtd->bh.length = (sizeof(L3_GTD) + (gl3->getNTracks() - 1) * sizeof(global_track))/4;
105 
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);
109 
110  return -1;
111  }
112 
113  // This stuff need to figure out later.
114  gtd->nHits = 0;
115 
116  gtd->xVert = gl3->getVertex().Getx();
117  gtd->yVert = gl3->getVertex().Gety();
118  gtd->zVert = gl3->getVertex().Getz();
119  gtd->nTracks = gl3->getNTracks();
120 
121  for(uint i=0;i<gtd->nTracks;i++) {
122 
123  global_track gtrack;
124  gl3Track *gl3track = gl3->getTrack(i);
125 
126  gtrack.id = gl3track->id;
127  gtrack.flag = gl3track->flag; // Primaries flag=1, Secondaries flag=0
128  gtrack.innerMostRow = gl3track->innerMostRow;
129  gtrack.outerMostRow = gl3track->outerMostRow;
130 
131  gtrack.nHits = gl3track->nHits; // Number of points assigned to that track
132  gtd->nHits += gtrack.nHits;
133 
134  //gtrack->reserved ;
135  gtrack.ndedx = gl3track->nDedx; // nr of clusters contributing to the dedx value
136  gtrack.q = gl3track->q; // charge
137  gtrack.chi2[0] = gl3track->chi2[0]; // chi squared of the momentum fit
138  gtrack.chi2[1] = gl3track->chi2[1];
139  gtrack.dedx = gl3track->dedx; // dE/dx information
140  gtrack.pt = gl3track->pt; // pt (transverse momentum) at (r,phi,z)
141  gtrack.phi0 = gl3track->phi0; // azimuthal angle of the first point
142  gtrack.psi = gl3track->psi; // azimuthal angle of the momentum at (r,..
143  gtrack.r0 = gl3track->r0; // r (in cyl. coord.) for the first point
144  gtrack.tanl = gl3track->tanl; // tg of the dip angle at (r,phi,z)
145  gtrack.z0 = gl3track->z0; // z coordinate of the first point
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;
151 
152 
153  memcpy(&gtd->track[i], &gtrack, sizeof(global_track));
154  }
155 
156  return 0;
157 }
158 
159 void EventTracker::dumpGTD(L3_GTD *gtd)
160 {
161  if(memcmp(gtd->bh.bank_type, "L3_GTD", 5) != 0) {
162  printf("Not a L3_GTD Bank: %s\n",gtd->bh.bank_type);
163  return;
164  }
165 
166  printf("Computed: Tracks: %5d: Vertex: (%6.2f/%6.2f/%6.2f)\n",
167  gtd->nTracks,gtd->xVert, gtd->yVert, gtd->zVert);
168 
169  for(u_int i=0;i<gtd->nTracks;i++) {
170  global_track *track = &(gtd->track[i]);
171 
172 
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);
176 
177  printf("flag=0x%04x iRow=%2d oRow=%2d\n",
178  track->flag, track->innerMostRow,
179  track->outerMostRow);
180  }
181 }
182 
183 
184 int EventTracker::copyl3_t(l3_t &l3, L3_P *l3p)
185 {
186  int len = l3p->bh.length;
187 
188  l3.max_channels = 1280000 ;
189  l3.channels = 0 ;
190  l3.mode = 1 ;
191 
192  // Tonko, zero this out and make non-sensical in case of further
193  // problems down the road
194  l3.tracks_num = 0 ;
195  l3.cluster_num = 0 ;
196  l3.xVertex = -1000.0 ;
197  l3.yVertex = -1000.0 ;
198  l3.zVertex = -1000.0 ;
199 
200  LOG(DBG,"L3_P bytes %d",len,0,0,0) ;
201 
202  if(checkBank(l3p->bh.bank_type,"L3_P") != 0) {
203  return -1 ;
204  }
205 
206 
207  if(l3p->tracks.len && l3p->tracks.off){
208  struct L3_GTD* l3gtd =
209  (struct L3_GTD*)((char*)l3p + l2h32(l3p->tracks.off)*4) ;
210 
211  // Tonko, sanity check
212  if(checkBank(l3gtd->bh.bank_type,"L3_GTD") < 0) {
213  return -1 ;
214  }
215 
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);
222 
223  // Tonko, sanity check
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) ;
226  return -1 ;
227  }
228 
229 
230  for (unsigned int i=0; i<l3.tracks_num; i++) {
231  global_track *tr = &(l3gtd->track[i]);
232 
233  l3.track[i].id = l2h32(tr->id);
234 
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;
239 
240  l3.track[i].nHits = tr->nHits;
241  l3.track[i].ndedx = tr->ndedx;
242  l3.track[i].q = tr->q;
243 #else
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);
248 
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;
253 #endif
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);
268 
269  }
270 
271 
272  }
273 
274 
275 #ifdef SHOW_DEBUG_INFO
276 
277 #ifdef UNIX_LITTLE_ENDIAN
278  printf("Running on LITTLE endian machine\n");
279 #else
280  printf("Running on BIG endian machine\n");
281 #endif
282 
283  printf("\nVertex: (%6.2f/%6.2f/%6.2f)\n",
284  l3.xVertex, l3.yVertex, l3.zVertex);
285 
286  printf("Tracks: %5d Clusters %7d\n",
287  l3.tracks_num, l3.cluster_num);
288 
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);
293 
294  printf("flag=0x%04x iRow=%2d oRow=%2d\n",
295  l3.track[i].flag, l3.track[i].innerMostRow,
296  l3.track[i].outerMostRow);
297  }
298 
299 #endif
300 
301  return len ;
302 
303 }
Definition: daq_l3.h:10