StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
eventTracker.cxx
1 #ifndef TRG_VERSION
2 #define TRG_VERSION 0x32
3 #endif
4 
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <string.h>
9 #include <daqFormats.h>
10 #include <rts.h>
11 #include "rtsLog.h"
12 #include <DAQ_READER/daqReader.h>
13 #include <DAQ_READER/daq_det.h>
14 #include <DAQ_READER/daq_dta.h>
15 #include <DAQ_L3/daq_l3.h>
16 #include <DAQ_TRG/daq_trg.h>
17 #include "eventTrackerLib.hh"
18 
19 
20 // control....
21 char g_fn[255]; // filename
22 uint g_seq = 0; // only write this event if != 0
23 float g_bfield = 1000;
24 uint g_ptracks = 0;
25 uint g_nftracks = 0;
26 uint g_nctracks = 0;
27 uint g_pause = 0;
28 uint g_vertex = 0;
29 
30 void printL3Info(l3_t& l3)
31 {
32  printf("%d tracks, %d clusters: Vertex = (%f, %f %f)\n",l3.tracks_num, l3.cluster_num, l3.xVertex,l3.yVertex,l3.zVertex);
33 
34  if(g_ptracks) {
35  for(u_int i=0;i<l3.tracks_num;i++) {
36  global_track *track = &l3.track[i];
37 
38  printf("%5d: pt=%5.3f z0=%7.2f q=%2d nHits=%2d ndedx=%2d ",
39  i, track->pt, track->z0, track->q,
40  track->nHits, track->ndedx);
41 
42  printf("flag=0x%04x iRow=%2d oRow=%2d\n",
43  track->flag, track->innerMostRow,
44  track->outerMostRow);
45  }
46  }
47 }
48 
49 
50 void parseArgs(int argc, char *argv[])
51 {
52  g_fn[0] = 0;
53 
54  for(int i=1;i<argc;i++) {
55  if(argv[i][0] != '-') { // should be filename...
56  if(g_fn[0] != 0) goto badargs;
57  strcpy(g_fn, argv[i]);
58  }
59  else if(strcmp(argv[i], "-event") == 0) {
60  i++;
61  g_seq = atoi(argv[i]);
62  //printf("g_seq = %d\n",g_seq);
63  }
64  else if(strcmp(argv[i], "-B") == 0) {
65  i++;
66  g_bfield = atof(argv[i]);
67  printf("g_bfield = %f\n",g_bfield);
68  }
69  else if (strcmp(argv[i], "-p") == 0) {
70  g_ptracks = 1;
71  }
72  else if (strcmp(argv[i], "-nft") == 0) {
73  g_nftracks = 1;
74  }
75  else if (strcmp(argv[i], "-nct") == 0) {
76  g_nctracks = 1;
77  }
78  else if (strcmp(argv[i], "-pause") == 0) {
79  g_pause = 1;
80  }
81  else if (strcmp(argv[i], "-vtx") == 0) {
82  rtsLogLevel(CRIT);
83  g_vertex = 1;
84  }
85  else {
86  goto badargs;
87  }
88  }
89 
90  if(g_fn[0] == 0) goto badargs;
91 
92  return;
93 
94  badargs:
95  printf("eventTracker <-event #> <-B> <-p> <-nft> <-nct> filename\n");
96  printf("\t-event -> event number\n");
97  printf("\t-B -> mag field\n");
98  printf("\t-p -> print track params\n");
99  printf("\t-nft -> don't read tracks from file\n");
100  printf("\t-nct -> don't calculate tracks\n");
101  printf("\t-pause -> pause before and after\n");
102  printf("\t-vtx -> produce output for vtx scan\n");
103 
104  exit(0);
105 }
106 
107 // Dumps tracks....
108 int main(int argc, char *argv[])
109 {
110 
111  daq_dta *dd;
112 
113  int ret = 0;
114 
115  l3_t l3_legacy;
116 
117  rtsLogOutput(RTS_LOG_STDERR);
118 
119  parseArgs(argc, argv);
120 
121  rtsLogLevel(WARN);
122 
123  // printf("sizeof tpc %d\n",sizeof(tpc));
124 
125  daqReader *rdr = new daqReader(g_fn);
126  if(!rdr) {
127  printf("Error getting daqReader\n");
128  return 0;
129  }
130 
131  // Buffer for event storage...
132  L3_P *l3p = (L3_P *)malloc(szL3_max);
133 
134  EventTracker *evtTracker;
135 
136  if(g_bfield == 1000)
137  evtTracker = new EventTracker();
138  else
139  evtTracker = new EventTracker(g_bfield);
140 
141  char tmp[200];
142 
143  if(g_pause) {
144  printf("Enter something: ");
145  scanf("%s", tmp);
146  }
147 
148  for(;;) {
149 
150 
151  char *mem = rdr->get(0,EVP_TYPE_PHYS);
152 
153 
154  if(!mem) {
155 
156  if(rdr->status == EVP_STAT_EOR) {
157  if(!g_vertex) {
158  printf("End of run...\n");
159  }
160  return 0;
161  }
162  else {
163  printf("Error reading an event\n");
164  return 0;
165  }
166  }
167 
168 
169  // We have an event of some kind...
170  //
171  // do filtering...
172  //
173  if(g_seq != 0) { // event number
174 
175  if(rdr->seq != g_seq) continue;
176 
177  }
178 
179 
180  if(rdr->token == 0) continue;
181 
182 
183  if(!g_vertex) {
184  printf("**** Event %d (seq = %d): %d bytes, token %d, triggers = 0x%x\n",
185 
186  rdr->event_number, rdr->seq, rdr->bytes, rdr->token, rdr->daqbits);
187  }
188 
189  DATAP *datap = (DATAP *)mem;
190  if(!datap) {
191  printf("Error reading datap:\n");
192  return 0;
193  }
194 
195  // First Use old L3 reader to read L3 from datafile if its there...
196 
197  if(!g_nftracks) {
198 
199  dd = rdr->det("l3")->get("legacy");
200  //LOG("JEFF", "blih");
201  if(!dd) {
202  //printf("No L3 banks in data file %d\n",ret);
203  }
204  else {
205 
206  dd->iterate();
207  l3_t *pL3 = (l3_t *)dd->Void;
208  printf("This comes from the datafile L3 banks...------ len=%d\n",ret);
209  printL3Info(*pL3);
210  printf("End Datafile L3 banks-------------------------\n");
211  }
212  }
213 
214 
215  //printf("*********** %s 0x%x **********\n",datap->bh.bank_type, (uint) datap);
216 
217  // Now, track the event into a new buffer l3p (this was allocated above)
218  //
219 
220  ret = evtTracker->trackEvent(rdr, mem, l3p, szL3_max);
221 
222  if(ret < 0) {
223 
224  printf("Error tracking event %d\n",rdr->seq);
225 
226  continue;
227  }
228 
229  // continue;
230 
231  if(l3p->tracks.off == 0) {
232  LOG(NOTE, "No tracks produced for event %d\n",rdr->seq);
233  continue;
234  }
235 
236  // And now that we have "retracked" events, get a l3Reader as before
237  //
238  // ***Note*** You must use "l3p" here which is of Type L3_P
239  // this is actually a different function than the one above!
240  // although it will write the data into the SAME global
241  // structure "l3"
242  //
243 
244  double zdc_vertex=0;
245  double bbc_vertex=0;
246  double zdc8=0;
247  double zdc9=0;
248  int zdc0 = 0;
249  int zdc4 = 0;
250  if(g_vertex) {
251  dd = rdr->det("trg")->get("legacy");
252  if(!dd) {
253  printf("Invalid trigger reader\n");
254  }
255  else {
256  dd->iterate();
257  trg_t *pTRG = (trg_t *)dd->Void;
258  zdc8 = (double)pTRG->ZDC[8];
259  zdc9 = (double)pTRG->ZDC[9];
260  zdc_vertex = (zdc9 - zdc8)*0.16*30.0/2.0;
261  zdc0 = pTRG->ZDC[0];
262  zdc4 = pTRG->ZDC[4];
263 
264  TrgSumData *sum =(TrgSumData *)pTRG->trg_sum;
265  bbc_vertex = sum->DSMdata.VTX[3]%512;
266  }
267  }
268 
269  if(!g_nctracks) {
270  ret = evtTracker->copyl3_t(l3_legacy, l3p);
271  if(ret <= 0) {
272  // printf("No retracked L3 banks valid %d\n",ret);
273  }
274  else {
275  if(g_vertex) {
276  printf("%d %d %lf %lf %lf %lf %lf %lf %lf %d %d\n", rdr->daqbits, l3_legacy.tracks_num, zdc8, zdc9, zdc_vertex, l3_legacy.xVertex, l3_legacy.yVertex,l3_legacy.zVertex, bbc_vertex, zdc0, zdc4);
277  }
278  else {
279  printf("This comes from retracking---------------- len=%d\n",ret);
280  printL3Info(l3_legacy);
281  printf("End of retracking-------------------------\n");
282  }
283  }
284  }
285 
286 
287 
288  // This is a dump of all the tracks... its probably better to use
289  // the standard l3Reader method however...
290  // L3_GTD *gtd = (L3_GTD *)((uint)l3p + l3p->tracks.off*4);
291  // LOG(DBG, "GTD size = %d\n",gtd->bh.length * 4);
292  // if(g_ptracks) evtTracker->dumpGTD(gtd);
293  }
294 
295  if(g_pause) {
296  printf("Enter something: ");
297  scanf("%s", tmp);
298  }
299 
300  free(l3p);
301 }
302 
303 
304 
Definition: daq_l3.h:10
Definition: daq_trg.h:9