Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_rawevent.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_rawevent.cc
4 // Created: Fri Jun 24 12:05:19 EDT 2011
5 // Creator: wolin (on Linux stan.jlab.org 2.6.18-194.11.1.el5 x86_64)
6 //
7 //
8 //
9 // JANA event processor plugin "rawevent"
10 //
11 // Gets raw hit data from hddm file, converts to (crate,slot,channel), then creates
12 // simulated raw output evio event and writes to file.
13 //
14 // Opens new file for every run.
15 // Default output file name is rawevent_xxxxxx.evio where xxxxxx is the run number.
16 // Can change via -PRAWEVENT:FILEBASE=newBaseName
17 //
18 // Reads translation table in via -PRAWEVENT:TRANSLATION=fileName.xml
19 // default is fakeTranslationTable.xml
20 //
21 // mc2coda expects time in natural units of the readout module:
22 // 25 ps/count for CAENTDC
23 // 60 ps/count for F1TDC32
24 // 115 ps/count for F1TDC48
25 // 4 ns/count for FADC250
26 // 8 ns/count for FADC125
27 //
28 // trig time minimum is 8 us or 2000 counts using 4 ns/count
29 //
30 //
31 //
32 // to compile/link:
33 // source some-halld-build
34 // setenv EVIOROOT /group/da/ejw/coda/Linux-xxx
35 // setenv HALLD_MY /home/wolin/halld_my
36 //
37 //
38 // To run:
39 //
40 // $ hd_ana -PPLUGINS=rawevent -PEVENTS_TO_KEEP=1 -EVENTS_TO_SKIP=0 /local/scratch/filtered.hddm
41 //
42 //
43 // still to do:
44 // remove ROOT
45 // negative times ok
46 // energy, charge units? bombproof values for mc2coda
47 // bombproofing should be done in mcsmear
48 // too many hits in one channel? hit merging?
49 // pair spectrometer, others
50 //
51 //
52 // ejw, 5-Nov-2012
53 
54 
55 
57 
58 #include<cmath>
59 #include<sstream>
60 #include<iomanip>
61 #include<limits>
62 #include<algorithm>
63 #include<fstream>
64 #include <expat.h>
65 
66 #ifdef HAVE_EVIO
67 
68 // root histograms...probably not thread-safe
69 static TH1F *tofEnergies;
70 static TH1F *fcalEnergies;
71 static TH1F *bcalEnergies;
72 static TH1F *stEnergies;
73 static TH1F *tagmEnergies;
74 static TH1F *taghEnergies;
75 
76 static TH1F *fdcCharges;
77 static TH1F *cdcCharges;
78 
79 static TH1F *tofTimes;
80 static TH1F *fdcTimes;
81 static TH1F *cdcTimes;
82 static TH1F *fcalTimes;
83 static TH1F *bcalTimes;
84 static TH1F *stTimes;
85 static TH1F *tagmTimes;
86 static TH1F *taghTimes;
87 
88 
89 // is this thread-safe?
90 extern "C" {
91 #include "mc2coda.h"
92 }
93 
94 
95 
96 // Replace use of BOOST lexical_cast with a simple templated function
97 // so that BOOST is no longer required. 1/24/2014 DL
98 //#include <boost/lexical_cast.hpp>
99 //using namespace boost;
100 template<typename T>
101 string lexical_cast(T t)
102 {
103  stringstream ss;
104  ss << t;
105  return ss.str();
106 }
107 
108 
109 // to protect writing to output file
110 static pthread_mutex_t rawMutex = PTHREAD_MUTEX_INITIALIZER;
111 
112 
113 // for evio output and translation table
114 static evioFileChannel *chan = NULL;
115 static string fileBase = "rawevent";
116 static string outputFileName;
117 static string translationTableName = "tt.xml";
118 
119 
120 // current run number
121 static int runNumber;
122 static unsigned int user_runNumber=0xdeadbeef; // specified via configuration parameter
123 
124 
125 // csc map converts from detector spec to (crate,slot,channel)
126 // key is detector-dependent encoded string (e.g. "cdcadc::2:25" for CDC ring 2 straw 25)
127 // value is struct containing (crate,slot,channel)
128 static map<string,cscVal> cscMap;
129 
130 // Useful "non-value" for a cscRef
131 static cscVal CDCBAL_NULL = {-1, -1, -1};
132 static cscRef CSCREF_NULL = CDCBAL_NULL;
133 
134 // detector map (inverse of csc map) is 3-dimensional array of strings with indices (crate,slot,channel)
135 // content is detector-dependent encoded string
136 #define MAXDCRATE 99+1
137 #define MAXDSLOT 21+1
138 #define MAXDCHANNEL 72+1
139 static string detectorMap[MAXDCRATE][MAXDSLOT][MAXDCHANNEL];
140 
141 
142 // for Dave's mc2coda package
143 #define MAXCRATE 128
144 #define MAXSLOT 21
145 #define MAXEVENTSIZE 30000*4 // in bytes
146 
147 
148 static string expName = "HallD";
149 static CODA_EXP_INFO *expID = NULL;
150 static CODA_EVENT_INFO *eventID = NULL;
151 
152 static int nCrate = 0;
153 static int maxCrateNum = 0;
154 static int crateID[MAXCRATE];
155 static int nModules[MAXCRATE];
156 static int modules[MAXCRATE][MAXSLOT];
157 static int detID[MAXCRATE][MAXSLOT];
158 
159 
160 // misc
161 static uint64_t trigTime = 32000000; // in picoseconds
162 static float tMin = -100000.; // minimum hit time in picoseconds
163 
164 // default time steps
165 static double trigtick = 4000; // in picoseconds
166 static double CAENTDCtick = 25.; // in picoseconds
167 static double F1TDC32tick = 60.; // in picoseconds
168 static double F1TDC48tick = 115.; // in picoseconds
169 static double FADC250tick = 62.5; // in picoseconds
170 static double FADC125tick = 800.; // in picoseconds
171 
172 static double CDC_ADCscale = 0.25E5/1.0E6;
173 static double FDC_ADCscale = 1.3E5/2.4E4;
174 static double FCAL_ADCscale = 2.5E5/4.0E1;
175 static double BCAL_ADCscale = 10000.;
176 static double TOF_ADCscale = 5.2E5/0.2;
177 static double SC_ADCscale = 10000.;
178 //static double TAGH_ADCscale = 10000.;
179 //static double TAGM_ADCscale = 10000.;
180 static double PSC_ADCscale = 10000.;
181 static double PS_ADCscale = 10000.;
182 
183 //static double CDC_ADCtick = FADC125tick;
184 static float CDC_ADCtick = FADC125tick;
185 static double FDC_ADCtick = FADC125tick;
186 static double FCAL_ADCtick = FADC250tick;
187 static double BCAL_ADCtick = FADC250tick;
188 static double TOF_ADCtick = FADC250tick;
189 static double SC_ADCtick = FADC250tick;
190 //static double TAGH_ADCtick = FADC250tick;
191 //static double TAGM_ADCtick = FADC250tick;
192 static double PSC_ADCtick = FADC250tick;
193 static double PS_ADCtick = FADC250tick;
194 
195 static double FDC_TDCtick = F1TDC48tick;
196 static double BCAL_TDCtick = F1TDC32tick;
197 static double TOF_TDCtick = CAENTDCtick;
198 static double SC_TDCtick = F1TDC32tick;
199 //static double TAGH_TDCtick = F1TDC32tick;
200 //static double TAGM_TDCtick = F1TDC32tick;
201 static double PSC_TDCtick = F1TDC32tick;
202 
203 // optional parameters for specifying windows (in ns) in which to keep hits
204 // these are useful in cases when one is generating events overlaid
205 // with EM background, and the EM background window is large,
206 // causing an unrealistic number of events to register in the
207 // channels of certain detectors
208 static double CDC_time_window = -1.;
209 static double FDC_time_window = -1.;
210 static double FCAL_time_window = -1.;
211 static double BCAL_time_window = -1.;
212 static double TOF_time_window = 100.;
213 static double SC_time_window = -1.;
214 static double TAGH_time_window = -1.;
215 static double TAGM_time_window = -1.;
216 static double PSC_time_window = 200.;
217 static double PS_time_window = 200.;
218 
219 // debug
220 static int dumphits = 0;
221 static int nomc2coda = 0;
222 static int noroot = 0;
223 static int dumpmap = 0;
224 
225 // Translation table
226 bool NO_CCDB = false; // try and read from CCDB by default
227 string XML_FILENAME = "tt.xml"; // default filename for XML file if CCDB fails or is not used
228 
229 // Pedestals (defined in mc2coda_random.cc)
230 extern bool NO_PEDESTAL;
231 extern bool NO_RANDOM_PEDESTAL;
232 extern float MEAN_PEDESTAL;
233 extern float SIGMA_COMMON_PEDESTAL;
234 extern float SIGMA_INDIVIDUAL_PEDESTAL;
235 
236 #endif //HAVE_EVIO
237 
238 //----------------------------------------------------------------------------
239 
240 
241 // required for JANA framework to find and identify this plugin
242 extern "C"{
243 void InitPlugin(JApplication *app) {
244  InitJANAPlugin(app);
245  app->AddProcessor(new JEventProcessor_rawevent());
246 }
247 } // "C"
248 
249 
250 //----------------------------------------------------------------------------
251 #ifdef HAVE_EVIO
252 
253 // Comparison operator for testing if two cscRefs are equal
254 bool operator == (cscRef a, cscRef b) {
255  if (a.channel != b.channel)
256  return false;
257  if (a.slot != b.slot)
258  return false;
259  return a.crate == b.crate;
260 }
261 
262 #endif //HAVE_EVIO
263 
264 // JEventProcessor_rawevent (Constructor) invoked once only
266 #ifdef HAVE_EVIO
267 
268  // Default is to just read translation table from CCDB. If this fails,
269  // then an attempt will be made to read from a file on the local disk.
270  // The filename can be specified to be anything, but if the user specifies
271  // this, then we assume that they want to use it and skip using the CCDB.
272  // They may also specify that they want to skip checking the CCDB via
273  // the "TT:NO_CCDB" parameter. This would only be useful if they want to
274  // force the use of a local file named "tt.xml".
275  gPARMS->SetDefaultParameter("TT:NO_CCDB", NO_CCDB, "Don't try getting"
276  " translation table from CCDB and just look for file. Only useful"
277  " if you want to force reading tt.xml. This is automatically set"
278  " if you specify a different filename via the "
279  "TT:XML_FILENAME parameter.");
280  JParameter *p = gPARMS->SetDefaultParameter("TT:XML_FILENAME", XML_FILENAME,
281  "Fallback filename of translation table XML file."
282  " If set to non-default, CCDB will not be checked.");
283  if (p->GetDefault() != p->GetValue())
284  NO_CCDB = true;
285 
286 
287  // get fileBase from command line params
288  gPARMS->SetDefaultParameter("RAWEVENT:FILEBASE",fileBase);
289 
290  // get translation table file name from command line
291  gPARMS->SetDefaultParameter("RAWEVENT:TRANSLATION",translationTableName);
292 
293  // trigger time picoseconds
294  gPARMS->SetDefaultParameter("RAWEVENT:TRIGTIME",trigTime);
295 
296  // minimum time in picoseconds
297  gPARMS->SetDefaultParameter("RAWEVENT:TMIN",tMin);
298 
299  // option to turn off mc2coda output
300  gPARMS->SetDefaultParameter("RAWEVENT:NOMC2CODA",nomc2coda);
301 
302  // option to turn off root
303  gPARMS->SetDefaultParameter("RAWEVENT:NOROOT",noroot);
304 
305  // option to dump hits
306  gPARMS->SetDefaultParameter("RAWEVENT:DUMPHITS",dumphits);
307 
308  // option to dump map to file
309  gPARMS->SetDefaultParameter("RAWEVENT:DUMPMAP",dumpmap,
310  "Dump map of translation table map to file (for debugging)");
311 
312  // option to set run number
313  gPARMS->SetDefaultParameter("RAWEVENT:RUNNUMBER",user_runNumber,
314  "Override run number from input file with this one"
315  " which will be written to every event in output file");
316 
317  // options for pedestals
318  gPARMS->SetDefaultParameter("RAWEVENT:NO_PEDESTAL",NO_PEDESTAL, "Set to non-zero value to enable pedestals (default is to always use \"0\" for all pedestals)");
319  gPARMS->SetDefaultParameter("RAWEVENT:NO_RANDOM_PEDESTAL",NO_RANDOM_PEDESTAL, "Set this to zero to disable any randomness in pedestals (def. is to randomize)");
320  gPARMS->SetDefaultParameter("RAWEVENT:MEAN_PEDESTAL",MEAN_PEDESTAL, "Mean value of single sample pedestal.");
321  gPARMS->SetDefaultParameter("RAWEVENT:SIGMA_COMMON_PEDESTAL",SIGMA_COMMON_PEDESTAL, "Stochastic width of common pedestal distribution. Common pedestal is used for all channels in a module but will be different module to module.");
322  gPARMS->SetDefaultParameter("RAWEVENT:SIGMA_INDIVIDUAL_PEDESTAL",SIGMA_INDIVIDUAL_PEDESTAL, "Stochastic width of MEASURED pedestal");
323 
324  // options for time windows
325  gPARMS->SetDefaultParameter("RAWEVENT:CDC_TIME_WINDOW",CDC_time_window, "Optional window size in which to save CDC hits (in ns)");
326  gPARMS->SetDefaultParameter("RAWEVENT:FDC_TIME_WINDOW",FDC_time_window, "Optional window size in which to save FDC hits (in ns)");
327  gPARMS->SetDefaultParameter("RAWEVENT:FCAL_TIME_WINDOW",FCAL_time_window, "Optional window size in which to save FCAL hits (in ns)");
328  gPARMS->SetDefaultParameter("RAWEVENT:BCAL_TIME_WINDOW",BCAL_time_window, "Optional window size in which to save BCAL hits (in ns)");
329  gPARMS->SetDefaultParameter("RAWEVENT:TOF_TIME_WINDOW",TOF_time_window, "Optional window size in which to save TOF hits (in ns)");
330  gPARMS->SetDefaultParameter("RAWEVENT:SC_TIME_WINDOW",SC_time_window, "Optional window size in which to save Start Counter hits (in ns)");
331  gPARMS->SetDefaultParameter("RAWEVENT:TAGH_TIME_WINDOW",TAGH_time_window, "Optional window size in which to save Tagger Hodoscope hits (in ns)");
332  gPARMS->SetDefaultParameter("RAWEVENT:TAGM_TIME_WINDOW",TAGM_time_window, "Optional window size in which to save Tagger Microscope hits (in ns)");
333  gPARMS->SetDefaultParameter("RAWEVENT:PSC_TIME_WINDOW",PSC_time_window, "Optional window size in which to save Coarse Pair Spectrometer hits (in ns)");
334  gPARMS->SetDefaultParameter("RAWEVENT:PS_TIME_WINDOW",PS_time_window, "Optional window size in which to save Fine Pair Spectrometer hits (in ns)");
335 
336 #endif //HAVE_EVIO
337 
338 
339 }
340 
341 
342 //----------------------------------------------------------------------------
343 
344 
345 // ~JEventProcessor_rawevent (Destructor) once only
347 #ifdef HAVE_EVIO
348  if (nomc2coda == 0) {
349  mc2codaFree(expID);
350  }
351 #endif //HAVE_EVIO
352 }
353 
354 
355 //----------------------------------------------------------------------------
356 
357 
358 // init called once-only at beginning, independent of the number of processing threads
360 #ifdef HAVE_EVIO
361 
362  // read translation table, fill crate id arrays
363  readTranslationTable();
364 
365  // initialize mc2coda package
366  if (nomc2coda == 0) {
367  expID=mc2codaInitExp(maxCrateNum+1,expName.c_str());
368  if (expID == NULL) {
369  jerr << "?NULL return from mc2codaInitExp()" << std::endl;
370  exit(EXIT_FAILURE);
371  }
372  }
373 
374 
375  // feed crate-specific info to mc2coda package,
376  // note that VMECPU and TID not included in module count
377  int stat;
378  if (nomc2coda == 0) {
379  for (int i=0; i<nCrate; i++) {
380  int nMod = nModules[i]-2;
381  if (nMod < 1)
382  continue; // ignore crates with no digitization modules
383 
384  // hack to configure slot for F1TDC reference signal
385  // crate = 51, slot = 17, channel = 8
386  if(crateID[i] == 51) {
387  modules[i][16] = F1TDC32;
388  detID[i][16] = 1;
389  nModules[i]++;
390  }
391 
392  stat = mc2codaSetCrate(expID,crateID[i],nModules[i]-2,modules[i],detID[i]);
393  if (stat == -1) {
394  jerr << "?JEventProcessor_rawevent...error return from mc2codaSetCrate()"
395  << std::endl << std::endl;
396  exit(EXIT_FAILURE);
397  }
398  }
399  }
400 
401  // Optionally dump translation table map into file for debugging
402  if (dumpmap) {
403  ofstream *ofs = new ofstream("cscMap.out");
404  if (ofs) {
405  jout << "Dumping translation table map to cscMap.out ..." << std::endl;
406  map<string,cscVal>::iterator iter = cscMap.begin();
407  for (; iter != cscMap.end(); iter++) {
408  cscVal &csc = iter->second;
409  *ofs << iter->first << " " << csc.crate << " " << csc.slot
410  << " " << csc.channel << std::endl;
411  }
412  ofs->close();
413  delete ofs;
414  }
415  }
416 
417  // root histograms
418  if (noroot == 0) {
419  tofEnergies = new TH1F("tofe", "TOF energies in keV",1000,0.,5000.);
420  stEnergies = new TH1F("ste", "ST energies in keV",1000,0.,5000.);
421  fcalEnergies = new TH1F("fcale", "FCAL energies in keV",1000,0.,500000.);
422  bcalEnergies = new TH1F("bcale", "BCAL energies in keV",1000,0.,1000000.);
423  tagmEnergies = new TH1F("tagme", "Tagger microscope energies in keV",1000,0.,40000.);
424  taghEnergies = new TH1F("taghe", "Tagger hodoscope array energies in keV",1000,0.,40000.);
425 
426  fdcCharges = new TH1F("fdcq", "FDC charges in fC",1000,0.,1500.);
427  cdcCharges = new TH1F("cdcq", "CDC charges in fC",1000,0.,25000.);
428 
429  tofTimes = new TH1F("toft"," TOF times in nsec",1000,0.,500.-tMin/1000);
430  stTimes = new TH1F("stt", "ST times in nsec",1000,0.,250.-tMin/1000);
431  fdcTimes = new TH1F("fdct", "FDC times in nsec",1000,0.,2000.-tMin/1000);
432  cdcTimes = new TH1F("cdct", "CDC times in nsec",1000,0.,1000.-tMin/1000);
433  bcalTimes = new TH1F("bcalt", "BCAL times in nsec",1000,0.,200.-tMin/1000);
434  fcalTimes = new TH1F("fcalt", "FCAL times in nsec",1000,0.,200.-tMin/1000);
435  tagmTimes = new TH1F("tagmt", "Tagger microscope times in nsec",1000,0.,250.-tMin/1000);
436  taghTimes = new TH1F("tahft", "Tagger hodoscope times in nsec",1000,0.,250.-tMin/1000);
437  }
438 
439 #endif //HAVE_EVIO
440 
441  return NOERROR;
442 }
443 
444 //----------------------------------------------------------------------------
445 
446 
447 // brun called once-only at beginning of run, independent of the number of processing threads
448 jerror_t JEventProcessor_rawevent::brun(JEventLoop *eventLoop, int32_t runnumber) {
449 #ifdef HAVE_EVIO
450 
451  runNumber=runnumber;
452  jout << std::endl << " brun called for run " << runNumber << std::endl;
453  if (user_runNumber != 0xdeadbeef) {
454  jout << " *** overriding with user-supplied run number: "
455  << user_runNumber << " ***" << std::endl;
456  runNumber = runnumber = user_runNumber;
457  }
458  mc2codaSetRunNumber(runNumber);
459 
460  // close old output file
461  if (chan != NULL) {
462  chan->close();
463  delete(chan);
464  chan=NULL;
465  }
466 
467 
468  // get new file name
469  stringstream ss;
470  ss << fileBase << "_" << setw(6) << setfill('0') << runNumber << ".evio" << ends;
471  outputFileName=ss.str();
472 
473 
474  // open new output file
475  chan = new evioFileChannel(outputFileName,"w");
476  chan->open();
477  jout << std::endl << " opening output file: " << outputFileName << std::endl << std::endl << std::endl;
478 
479 
480  // load scale factors for converting from physical units into detector hit units
481  // the converstion factors are set to reasonable default values when they are defined
482  // but try to load them from the CCDB so that we are using the same factors to create
483  // the EVIO files as are used to read them in
484  jout << "Loading ADC/TDC scale factors..." << endl;
485 
486  //F1TDCs
487  map<string, int> tdc_parms;
488  if(eventLoop->GetCalib("/F1TDC/rollover", tdc_parms))
489  jout << "Error loading /F1TDC/rollover !" << endl;
490  map<string, int>::const_iterator locMapIterator = tdc_parms.find("tframe");
491  double dRolloverTimeWindowLength = (locMapIterator != tdc_parms.end()) ? double(tdc_parms["tframe"]) : std::numeric_limits<double>::quiet_NaN();
492 
493  locMapIterator = tdc_parms.find("count");
494  uint64_t dNumTDCTicksInRolloverTimeWindow = (locMapIterator != tdc_parms.end()) ? double(tdc_parms["count"]) : std::numeric_limits<double>::quiet_NaN();
495  double locTDCToNsScaleFactor = dRolloverTimeWindowLength/double(dNumTDCTicksInRolloverTimeWindow);
496 
497  FDC_TDCtick = 1000.0*locTDCToNsScaleFactor*2.0; //FDC has fewer TDC-ticks per ns
498  BCAL_TDCtick = 1000.0*locTDCToNsScaleFactor;
499  SC_TDCtick = 1000.0*locTDCToNsScaleFactor;
500  PSC_TDCtick = 1000.0*locTDCToNsScaleFactor;
501 
502  map<string,double> scale_factors;
503  if (eventLoop->GetCalib("/CDC/digi_scales", scale_factors))
504  jout << "Error loading /CDC/digi_scales !" << endl;
505  if ( scale_factors.find("CDC_ADC_ASCALE") != scale_factors.end() ) {
506  CDC_ADCscale = 1. / scale_factors["CDC_ADC_ASCALE"];
507  } else {
508  jerr << "Unable to get CDC_ADC_ASCALE from /CDC/digi_scales !" << endl;
509  }
510  if ( scale_factors.find("CDC_ADC_TSCALE") != scale_factors.end() ) {
511  CDC_ADCtick = 1000. * scale_factors["CDC_ADC_TSCALE"];
512  } else {
513  jerr << "Unable to get CDC_ADC_TSCALE from /CDC/digi_scales !" << endl;
514  }
515 
516  if (eventLoop->GetCalib("/FDC/digi_scales", scale_factors))
517  jout << "Error loading /FDC/digi_scales !" << endl;
518  if ( scale_factors.find("FDC_ADC_ASCALE") != scale_factors.end() ) {
519  FDC_ADCscale = 1. / scale_factors["FDC_ADC_ASCALE"];
520  } else {
521  jerr << "Unable to get FDC_ADC_ASCALE from /FDC/digi_scales !" << endl;
522  }
523  if ( scale_factors.find("FDC_ADC_TSCALE") != scale_factors.end() ) {
524  FDC_ADCtick = 1000. * scale_factors["FDC_ADC_TSCALE"];
525  } else {
526  jerr << "Unable to get FDC_ADC_TSCALE from /FDC/digi_scales !" << endl;
527  }
528 
529  if (eventLoop->GetCalib("/FCAL/digi_scales", scale_factors))
530  jout << "Error loading /FCAL/digi_scales !" << endl;
531  if ( scale_factors.find("FCAL_ADC_ASCALE") != scale_factors.end() ) {
532  FCAL_ADCscale = 1. / scale_factors["FCAL_ADC_ASCALE"];
533  } else {
534  jerr << "Unable to get FCAL_ADC_ASCALE from /FCAL/digi_scales !" << endl;
535  }
536  if ( scale_factors.find("FCAL_ADC_TSCALE") != scale_factors.end() ) {
537  FCAL_ADCtick = 1000. * scale_factors["FCAL_ADC_TSCALE"];
538  } else {
539  jerr << "Unable to get FCAL_ADC_TSCALE from /FCAL/digi_scales !" << endl;
540  }
541 
542  if (eventLoop->GetCalib("/BCAL/digi_scales", scale_factors))
543  jout << "Error loading /BCAL/digi_scales !" << endl;
544  if ( scale_factors.find("BCAL_ADC_ASCALE") != scale_factors.end() ) {
545  BCAL_ADCscale = 1. / scale_factors["BCAL_ADC_ASCALE"];
546  } else {
547  jerr << "Unable to get BCAL_ADC_ASCALE from /BCAL/digi_scales !" << endl;
548  }
549  if ( scale_factors.find("BCAL_ADC_TSCALE") != scale_factors.end() ) {
550  BCAL_ADCtick = 1000. * scale_factors["BCAL_ADC_TSCALE"];
551  } else {
552  jerr << "Unable to get BCAL_ADC_TSCALE from /BCAL/digi_scales !" << endl;
553  }
554 
555  if (eventLoop->GetCalib("/TOF/digi_scales", scale_factors))
556  jout << "Error loading /TOF/digi_scales !" << endl;
557  if ( scale_factors.find("TOF_ADC_ASCALE") != scale_factors.end() ) {
558  TOF_ADCscale = 1. / scale_factors["TOF_ADC_ASCALE"];
559  } else {
560  jerr << "Unable to get TOF_ADC_ASCALE from /TOF/digi_scales !" << endl;
561  }
562  if ( scale_factors.find("TOF_ADC_TSCALE") != scale_factors.end() ) {
563  TOF_ADCtick = 1000. * scale_factors["TOF_ADC_TSCALE"];
564  } else {
565  jerr << "Unable to get TOF_ADC_TSCALE from /TOF/digi_scales !" << endl;
566  }
567  if ( scale_factors.find("TOF_TDC_SCALE") != scale_factors.end() ) {
568  TOF_TDCtick = 1000. * scale_factors["TOF_TDC_SCALE"];
569  } else {
570  jerr << "Unable to get TOF_TDC_SCALE from /TOF/digi_scales !" << endl;
571  }
572 
573  if (eventLoop->GetCalib("/START_COUNTER/digi_scales", scale_factors))
574  jout << "Error loading /START_COUNTER/digi_scales !" << endl;
575  if ( scale_factors.find("SC_ADC_ASCALE") != scale_factors.end() ) {
576  SC_ADCscale = 1. / scale_factors["SC_ADC_ASCALE"];
577  } else {
578  jerr << "Unable to get SC_ADC_ASCALE from /START_COUNTER/digi_scales !" << endl;
579  }
580  if ( scale_factors.find("SC_ADC_TSCALE") != scale_factors.end() ) {
581  SC_ADCtick = 1000. * scale_factors["SC_ADC_TSCALE"];
582  } else {
583  jerr << "Unable to get SC_ADC_TSCALE from /START_COUNTER/digi_scales !" << endl;
584  }
585 
586  // PS and PSC scales are stored in the same table
587  if (eventLoop->GetCalib("/PHOTON_BEAM/pair_spectrometer/digi_scales", scale_factors))
588  jout << "Error loading /PHOTON_BEAM/pair_spectrometer/digi_scales !" << endl;
589  if ( scale_factors.find("PSC_ADC_ASCALE") != scale_factors.end() ) {
590  PSC_ADCscale = 1. / scale_factors["PSC_ADC_ASCALE"];
591  } else {
592  jerr << "Unable to get PSC_ADC_ASCALE from /PHOTON_BEAM/pair_spectrometer/digi_scales !" << endl;
593  }
594  if ( scale_factors.find("PSC_ADC_TSCALE") != scale_factors.end() ) {
595  PSC_ADCtick = 1000. * scale_factors["PSC_ADC_TSCALE"];
596  } else {
597  jerr << "Unable to get PSC_ADC_TSCALE from /PHOTON_BEAM/pair_spectrometer/digi_scales !" << endl;
598  }
599 
600  if ( scale_factors.find("PS_ADC_ASCALE") != scale_factors.end() ) {
601  PS_ADCscale = 1. / scale_factors["PS_ADC_ASCALE"];
602  } else {
603  jerr << "Unable to get PS_ADC_ASCALE from /PHOTON_BEAM/pair_spectrometer/digi_scales !" << endl;
604  }
605  if ( scale_factors.find("PS_ADC_TSCALE") != scale_factors.end() ) {
606  PS_ADCtick = 1000. * scale_factors["PS_ADC_TSCALE"];
607  } else {
608  jerr << "Unable to get PS_ADC_TSCALE from /PHOTON_BEAM/pair_spectrometer/digi_scales !" << endl;
609  }
610 
611 
612  // add header event if required
613  // ...
614 // map<string,cscVal>::iterator iter = cscMap.begin();
615 // for (; iter != cscMap.end(); iter++) {
616 // string key = iter->first;
617 // if (key.find("toftdc") == 0) _DBG_ << key << std::endl;
618 // }
619 
620 #endif //HAVE_EVIO
621 
622  return NOERROR;
623 }
624 
625 
626 //----------------------------------------------------------------------------
627 
628 #ifdef HAVE_EVIO
629 
630  static bool compareDTOFHits(const DTOFHit* h1, const DTOFHit* h2) {
631  if (h1->plane != h2->plane) {
632  return(h1->plane<h2->plane);
633  } else if (h1->bar != h2->bar) {
634  return(h1->bar<h2->bar);
635  } else if (h1->end != h2->end) {
636  return(h1->end<h2->end);
637  } else {
638  return(h1->t<h2->t);
639  }
640  }
641 
642  static bool compareDFCALHits(const DFCALHit* h1, const DFCALHit* h2) {
643  if (h1->row != h2->row) {
644  return(h1->row<h2->row);
645  } else if (h1->column != h2->column) {
646  return(h1->column<h2->column);
647  } else {
648  return(h1->t<h2->t);
649  }
650  }
651 
652  static bool compareDBCALHits(const DBCALHit* h1, const DBCALHit* h2) {
653  if (h1->module != h2->module) {
654  return(h1->module<h2->module);
655  } else if (h1->sector != h2->sector) {
656  return(h1->sector<h2->sector);
657  } else if (h1->layer != h2->layer) {
658  return(h1->layer<h2->layer);
659  } else if (h1->end != h2->end) {
660  return(h1->end<h2->end);
661  } else {
662  return(h1->t<h2->t);
663  }
664  }
665 
666  static bool compareDBCALTDCHits(const DBCALTDCHit* h1, const DBCALTDCHit* h2) {
667  if (h1->module != h2->module) {
668  return(h1->module<h2->module);
669  } else if (h1->sector != h2->sector) {
670  return(h1->sector<h2->sector);
671  } else if (h1->layer != h2->layer) {
672  return(h1->layer<h2->layer);
673  } else if (h1->end != h2->end) {
674  return(h1->end<h2->end);
675  } else {
676  return(h1->t<h2->t);
677  }
678  }
679 
680  static bool compareDFDCHits(const DFDCHit* h1, const DFDCHit* h2) {
681  if (h1->gPlane != h2->gPlane) {
682  return(h1->gPlane<h2->gPlane);
683  } else if (h1->element != h2->element) {
684  return(h1->element<h2->element);
685  } else {
686  return(h1->t<h2->t);
687  }
688  }
689 
690  static bool compareDCDCHits(const DCDCHit* h1, const DCDCHit* h2) {
691  if (h1->ring != h2->ring) {
692  return(h1->ring<h2->ring);
693  } else if (h1->straw != h2->straw) {
694  return(h1->straw<h2->straw);
695  } else {
696  return(h1->t<h2->t);
697  }
698  }
699 
700  static bool compareDSTHits(const DSCHit* h1, const DSCHit* h2) {
701  if (h1->sector != h2->sector) {
702  return(h1->sector<h2->sector);
703  } else {
704  return(h1->t<h2->t);
705  }
706  }
707 
708  static bool compareDTAGMHits(const DTAGMHit* h1, const DTAGMHit* h2) {
709  if (h1->column != h2->column) {
710  return (h1->column < h2->column);
711  }
712  else if (h1->row != h2->row) {
713  return (h1->row < h2->row);
714  }
715  else if (h1->t != h2->t) {
716  return (h1->t <h2->t);
717  }
718  else {
719  return (h1->time_fadc < h2->time_fadc);
720  }
721  }
722 
723  static bool compareDTAGHHits(const DTAGHHit* h1, const DTAGHHit* h2) {
724  if (h1->counter_id != h2->counter_id) {
725  return (h1->counter_id < h2->counter_id);
726  }
727  else if (h1->t != h2->t) {
728  return (h1->t < h2->t);
729  }
730  else {
731  return (h1->time_fadc < h2->time_fadc);
732  }
733  }
734 
735  static bool compareDPSCHits(const DPSCHit* h1, const DPSCHit* h2) {
736  if (h1->arm != h2->arm) {
737  return(h1->arm<h2->arm);
738  } else if (h1->module != h2->module) {
739  return(h1->module<h2->module);
740  } else {
741  return(h1->t<h2->t);
742  }
743  }
744 
745 
746  static bool compareDPSHits(const DPSHit* h1, const DPSHit* h2) {
747  if (h1->arm != h2->arm) {
748  return(h1->arm<h2->arm);
749  } else if (h1->column != h2->column) {
750  return(h1->column<h2->column);
751  } else {
752  return(h1->t<h2->t);
753  }
754  }
755 
756 
757 #endif //HAVE_EVIO
758 
759 //----------------------------------------------------------------------------
760 
761 
762 // Called once per event in many different processing threads, so:
763 //
764 //
765 // *** MUST be thread-safe ***
766 //
767 //
768 // Note: Accesses MC hit data in DANA objects and converts to crate/slot/channel/energy/time.
769 // DAQ group task is to take this data, sort and combine the hits, then create an EVIO
770 // buffer in the format planned for disentangled events.
771 // The buffer is written to disk using a mutex-locked EVIO write.
772 
773 jerror_t JEventProcessor_rawevent::evnt(JEventLoop *eventLoop, uint64_t eventnumber) {
774 #ifdef HAVE_EVIO
775 
776  unsigned int i;
777  CODA_HIT_INFO hit[10];
778  uint32_t mcData[10];
779  int stat,nhits,hc;
780  static bool first_time = true;
781 
782 
783  // initialize event buffer info
784  int hitCount = 0;
785  int detID = 1;
786  unsigned short eventType = 0;
787 
788 
789  // open event, default max event size is 1 MB
790  if (nomc2coda == 0) {
791  if (first_time) {
792  first_time=false;
793  eventID = mc2codaOpenEvent(expID, (uint64_t)eventnumber, trigTime/trigtick, eventType, MAXEVENTSIZE);
794  if (eventID == NULL) {
795  jerr << "?NULL return from mc2codaOpenEvent()" << std::endl << std::endl;
796  exit(EXIT_FAILURE);
797  }
798  } else {
799  int stat = mc2codaResetEvent(eventID, (uint64_t)eventnumber, trigTime/trigtick, eventType);
800  if (stat != 0) {
801  jerr << "?error return from mc2codaResetEvent()" << std::endl << std::endl;
802  exit(EXIT_FAILURE);
803  }
804  }
805  }
806 
807 
808  // get all raw hit data, sort according to id and time order before feeding to mc2coda package
809  // scale data appropriately to minimize loss of precision by using full available bit range
810 
811  // FADC125 pulse integral = 17 bits or about 1.3E5
812  // pulse_time = 14 bits or about 1.6E4
813  //
814  // FADC250 pulse_integral = 19 bits or about 5.2E5
815  // pulse_time = 16 bits or about 6.5E4
816  //
817  // F21TDC time = 7.8 us for 115ps resolution
818  // = 3.9 us for 60ps resolution
819 
820 
821  // DCDCHit - FADC125
822  vector<const DCDCHit*> dcdchits;
823  eventLoop->Get(dcdchits);
824  sort(dcdchits.begin(),dcdchits.end(),compareDCDCHits);
825 
826  hc=0;
827  for (i=0; i<dcdchits.size(); i++) {
828  if ((dcdchits[i]->q > 0) && ((dcdchits[i]->t*1000.) > tMin) &&
829  (dcdchits[i]->t*1000. < trigTime))
830  {
831  if(CDC_time_window > 0.)
832  if(fabs(dcdchits[i]->t) > CDC_time_window)
833  continue;
834 
835  //uint32_t q = dcdchits[i]->q * (1./5.18) * (1.3E5/1.0E6); // q is in femtoCoulombs (max is ~1E6)
836  uint32_t q = dcdchits[i]->q * CDC_ADCscale; // q is in femtoCoulombs (max is ~1E6)
837  //uint32_t t = dcdchits[i]->t*1000.0 -tMin; // t is in nanoseconds (max is ~900ns)
838  //uint32_t t = static_cast<double>(dcdchits[i]->t)*1000.0 - static_cast<double>(tMin); // t is in nanoseconds (max is ~900ns)
839  //double t = static_cast<double>(dcdchits[i]->t)*1000.0 - static_cast<double>(tMin); // t is in nanoseconds (max is ~900ns)
840  //float t = dcdchits[i]->t*1000.0 - tMin; // t is in nanoseconds (max is ~900ns)
841  float t = dcdchits[i]->t - (tMin/1000.); // t is in nanoseconds (max is ~900ns)
842 
843  //jout << " q = " << dcdchits[i]->q << ", digitized = " << q << endl;
844  //jout << " t = " << dcdchits[i]->t << ", shifted = " << t << endl;
845 
846  if (noroot == 0)
847  cdcCharges->Fill(dcdchits[i]->q);
848  if (noroot == 0)
849  cdcTimes->Fill(dcdchits[i]->t-tMin/1000);
850 
851  cscRef cscADC = DCDCHitTranslationADC(dcdchits[i]);
852  if (cscADC == CSCREF_NULL)
853  continue;
854  hc++;
855  hitCount++;
856  nhits=1;
857  hit[0].hit_id = hitCount;
858  hit[0].det_id = detID;
859  hit[0].crate_id = cscADC.crate;
860  hit[0].slot_id = cscADC.slot;
861  hit[0].chan_id = cscADC.channel;
862  hit[0].module_id = FADC125;
863  hit[0].module_mode = FADC125_MODE_IP;
864  hit[0].nwords = 2;
865  hit[0].hdata = mcData;
866  hit[0].hdata[0] = q; // in fADC counts
867  //hit[0].hdata[1] = static_cast<double>(t)/CDC_ADCtick;
868  hit[0].hdata[1] = t/(CDC_ADCtick/1000.);
869  //if (q > 0x7ffff) std::cerr << "q too large for CDC: " << q << std::endl;
870 
871  if (dumphits > 1) {
872  jout << std::endl;
873  jout << " CDC ADC ring,straw are " << dcdchits[i]->ring
874  << ", " << dcdchits[i]->straw << std::endl;
875  jout << " c,s,c are " << cscADC.crate << ", "
876  << cscADC.slot << ", " << cscADC.channel << std::endl;
877  jout << " hdata is: " << hit[0].hdata[0] << ", "
878  << hit[0].hdata[1] << std::endl;
879  jout << " q,t are " << q << ", " << t << std::endl;
880  jout << std::endl;
881  }
882 
883  if (nomc2coda == 0) {
884  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
885  if (stat != nhits) {
886  jerr << "?error return from mc2codaWrite() for CDC ADC: "
887  << stat << std::endl << std::endl;
888  exit(EXIT_FAILURE);
889  }
890  }
891  }
892  }
893  if ((dumphits >= 1) && (hc > 0)) {
894  jout << std::endl << "CDC hits: " << hc << std::endl << std::endl;
895  }
896 
897 
898  // DTOFHit - FADC250 and CAEN TDC (25 ps)
899  vector<const DTOFHit*> dtofrawhits;
900  eventLoop->Get(dtofrawhits);
901  sort(dtofrawhits.begin(),dtofrawhits.end(),compareDTOFHits);
902 
903  hc=0;
904  for (i=0; i < dtofrawhits.size(); i++) {
905  if ((dtofrawhits[i]->dE > 0) && ((dtofrawhits[i]->t*1000.) > tMin) &&
906  (dtofrawhits[i]->t*1000. < trigTime))
907  {
908  if(TOF_time_window > 0.)
909  if(fabs(dtofrawhits[i]->t) > TOF_time_window)
910  continue;
911 
912  //uint32_t E = dtofrawhits[i]->dE*(5.2E5/0.2); // E is GeV (max ~0.1)
913  uint32_t E = dtofrawhits[i]->dE*TOF_ADCscale; // E is GeV (max ~0.1)
914  uint32_t t = dtofrawhits[i]->t*1000.-tMin; // in picoseconds
915 
916  if (noroot == 0)
917  tofEnergies->Fill(dtofrawhits[i]->dE*1000000.);
918  if (noroot == 0)
919  tofTimes->Fill(dtofrawhits[i]->t-tMin/1000);
920 
921  hc++;
922  hitCount++;
923  nhits=1;
924  cscRef cscADC = DTOFHitTranslationADC(dtofrawhits[i]);
925  hit[0].hit_id = hitCount;
926  hit[0].det_id = detID;
927  hit[0].crate_id = cscADC.crate;
928  hit[0].slot_id = cscADC.slot;
929  hit[0].chan_id = cscADC.channel;
930  hit[0].module_id = FADC250;
931  hit[0].module_mode = FADC250_MODE_IP;
932  hit[0].nwords = 2;
933  hit[0].hdata = mcData;
934  hit[0].hdata[0] = E; // in fADC counts
935  hit[0].hdata[1] = static_cast<double>(t)/TOF_ADCtick;
936  if (E > 0x7ffff)
937  std::cerr << "E too large for TOF: " << E << std::endl;
938 
939  if (dumphits > 1) {
940  jout << std::endl;
941  jout << " TOF ADC plane,bar,lr are " << dtofrawhits[i]->plane << ", " << dtofrawhits[i]->bar
942  << ", " << dtofrawhits[i]->end << std::endl;
943  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot << ", " << cscADC.channel << std::endl;
944  jout << " hdata is: " << hit[0].hdata[0] << ", " << hit[0].hdata[1] << std::endl;
945  jout << " E,t are " << E << ", " << t << std::endl;
946  jout << std::endl;
947  }
948 
949  if (nomc2coda == 0) {
950  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
951  if (stat != nhits) {
952  jerr << "?error return from mc2codaWrite() for TOF ADC: " << stat << std::endl << std::endl;
953  exit(EXIT_FAILURE);
954  }
955  }
956 
957  hitCount++;
958  nhits=1;
959  cscRef cscTDC = DTOFHitTranslationTDC(dtofrawhits[i]);
960  hit[0].hit_id = hitCount;
961  hit[0].det_id = detID;
962  hit[0].crate_id = cscTDC.crate;
963  hit[0].slot_id = cscTDC.slot;
964  hit[0].chan_id = cscTDC.channel;
965  hit[0].module_id = CAEN1290;
966  hit[0].module_mode = 0;
967  hit[0].nwords = 1;
968  hit[0].hdata = mcData;
969  hit[0].hdata[0] = static_cast<double>(t)/TOF_TDCtick;
970 
971  if (dumphits > 1) {
972  jout << std::endl;
973  jout << " TOF TDC plane,bar,lr are " << dtofrawhits[i]->plane << ", " << dtofrawhits[i]->bar
974  << ", " << dtofrawhits[i]->end << std::endl;
975  jout << " c,s,c are " << cscTDC.crate << ", " << cscTDC.slot << ", " << cscTDC.channel << std::endl;
976  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
977  jout << " E,t are " << E << ", " << t << std::endl;
978  jout << std::endl;
979  }
980 
981  if (nomc2coda == 0) {
982  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
983  if (stat != nhits) {
984  jerr << "?error return from mc2codaWrite() for TOF TDC: " << stat << std::endl << std::endl;
985  exit(EXIT_FAILURE);
986  }
987  }
988  }
989  }
990  if ((dumphits >= 1) && (hc > 0)) {
991  jout << std::endl << "TOF hits: " << hc << std::endl << std::endl;
992  }
993 
994 
995  // DBCALHit - FADC250 and F1TDC32 (60 ps)
996  vector<const DBCALHit*> dbcalhits;
997  eventLoop->Get(dbcalhits);
998  sort(dbcalhits.begin(),dbcalhits.end(),compareDBCALHits);
999 
1000  hc=0;
1001  for (i=0; i < dbcalhits.size(); i++) {
1002  if ((dbcalhits[i]->E > 0) && ((dbcalhits[i]->t*1000.) > tMin) &&
1003  (dbcalhits[i]->t*1000. < trigTime))
1004  {
1005  if(BCAL_time_window > 0.)
1006  if(fabs(dbcalhits[i]->t) > BCAL_time_window)
1007  continue;
1008 
1009  uint32_t E = dbcalhits[i]->E*BCAL_ADCscale; // (each fADC count ~ 100keV) (max ~2.5E4)
1010  uint32_t t = dbcalhits[i]->t*1000.-tMin; // in picoseconds
1011 
1012  if (noroot == 0)
1013  bcalEnergies->Fill(dbcalhits[i]->E*1000.);
1014  if (noroot == 0)
1015  bcalTimes->Fill(dbcalhits[i]->t-tMin/1000);
1016 
1017  cscRef cscADC = DBCALHitTranslationADC(dbcalhits[i]);
1018  if (cscADC == CSCREF_NULL)
1019  continue;
1020  hc++;
1021  hitCount++;
1022  nhits=1;
1023  hit[0].hit_id = hitCount;
1024  hit[0].det_id = detID;
1025  hit[0].crate_id = cscADC.crate;
1026  hit[0].slot_id = cscADC.slot;
1027  hit[0].chan_id = cscADC.channel;
1028  hit[0].module_id = FADC250;
1029  hit[0].module_mode = FADC250_MODE_IP;
1030  hit[0].nwords = 2;
1031  hit[0].hdata = mcData;
1032  hit[0].hdata[0] = E;
1033  hit[0].hdata[1] = static_cast<double>(t)/BCAL_ADCtick;
1034  if (E/10 > 0x7ffff)
1035  std::cerr << "E too large for BCAL: " << E << std::endl;
1036 
1037  if (dumphits > 1) {
1038  jout << std::endl;
1039  jout << " BCAL ADC module,sector,layer,end are "
1040  << dbcalhits[i]->module << ", " << dbcalhits[i]->sector
1041  << ", " << dbcalhits[i]->layer << ", "
1042  << dbcalhits[i]->end << std::endl;
1043  jout << " c,s,c are " << cscADC.crate << ", "
1044  << cscADC.slot << ", " << cscADC.channel << std::endl;
1045  jout << " hdata is: " << hit[0].hdata[0] << ", "
1046  << hit[0].hdata[1] << std::endl;
1047  jout << " E,t are " << E << ", " << t << std::endl;
1048  jout << std::endl;
1049  }
1050 
1051 
1052  if (nomc2coda == 0) {
1053  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1054  if (stat != nhits) {
1055  jerr << "?error return from mc2codaWrite() for BCAL ADC: "
1056  << stat << std::endl << std::endl;
1057  exit(EXIT_FAILURE);
1058  }
1059  }
1060  /**
1061  hitCount++;
1062  nhits=1;
1063  cscRef cscTDC = DBCALHitTranslationTDC(dbcalhits[i]);
1064  hit[0].hit_id = hitCount;
1065  hit[0].det_id = detID;
1066  hit[0].crate_id = cscTDC.crate;
1067  hit[0].slot_id = cscTDC.slot;
1068  hit[0].chan_id = cscTDC.channel;
1069  hit[0].module_id = F1TDC32;
1070  hit[0].module_mode = 0;
1071  hit[0].nwords = 1;
1072  hit[0].hdata = mcData;
1073  hit[0].hdata[0] = static_cast<double>(t)/F1TDC32tick;
1074 
1075  if (dumphits > 1) {
1076  jout << std::endl;
1077  jout << " BCAL TDC module,sector,layer,end are " << dbcalhits[i]->module << ", " << dbcalhits[i]->sector
1078  << ", " << dbcalhits[i]->layer << ", " << dbcalhits[i]->end << std::endl;
1079  jout << " c,s,c are " << cscTDC.crate << ", " << cscTDC.slot << ", " << cscTDC.channel << std::endl;
1080  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1081  jout << " E,t are " << E << ", " << t << std::endl;
1082  jout << std::endl;
1083  }
1084 
1085  if (nomc2coda == 0) {
1086  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1087  if (stat != nhits) {
1088  jerr << "?error return from mc2codaWrite() for BCAL TDC: " << stat << std::endl << std::endl;
1089  exit(EXIT_FAILURE);
1090  }
1091  }
1092  **/
1093  }
1094  }
1095  if ((dumphits >= 1) && (hc > 0)) {
1096  jout << std::endl << "BCAL hits: " << hc << std::endl << std::endl;
1097  }
1098 
1099 
1100  // BCAL TDC hits are handled in separate objects
1101  vector<const DBCALTDCHit*> dbcaltdchits;
1102  eventLoop->Get(dbcaltdchits);
1103  sort(dbcaltdchits.begin(),dbcaltdchits.end(),compareDBCALTDCHits);
1104 
1105  hc=0;
1106  for (i=0; i<dbcaltdchits.size(); i++) {
1107  if (((dbcaltdchits[i]->t*1000.) > tMin) &&
1108  (dbcaltdchits[i]->t*1000. < trigTime))
1109  {
1110  if(BCAL_time_window > 0.)
1111  if(fabs(dbcaltdchits[i]->t) > BCAL_time_window)
1112  continue;
1113 
1114  int32_t E = 0;
1115  int32_t t = dbcaltdchits[i]->t*1000.-tMin; // in picoseconds
1116 
1117  if (noroot == 0)
1118  bcalTimes->Fill(dbcaltdchits[i]->t-tMin/1000);
1119 
1120  cscRef cscTDC = DBCALHitTranslationTDC(dbcaltdchits[i]);
1121  if (cscTDC == CSCREF_NULL)
1122  continue;
1123 
1124  hc++;
1125  hitCount++;
1126  nhits=1;
1127  hit[0].hit_id = hitCount;
1128  hit[0].det_id = detID;
1129  hit[0].crate_id = cscTDC.crate;
1130  hit[0].slot_id = cscTDC.slot;
1131  hit[0].chan_id = cscTDC.channel;
1132  hit[0].module_id = F1TDC32;
1133  hit[0].module_mode = 0;
1134  hit[0].nwords = 1;
1135  hit[0].hdata = mcData;
1136  hit[0].hdata[0] = static_cast<double>(t)/BCAL_TDCtick;
1137 
1138  if (dumphits > 1) {
1139  jout << std::endl;
1140  jout << " BCAL TDC module,sector,layer,end are "
1141  << dbcaltdchits[i]->module << ", " << dbcaltdchits[i]->sector
1142  << ", " << dbcaltdchits[i]->layer << ", "
1143  << dbcaltdchits[i]->end << std::endl;
1144  jout << " c,s,c are " << cscTDC.crate << ", "
1145  << cscTDC.slot << ", " << cscTDC.channel << std::endl;
1146  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1147  jout << " E,t are " << E << ", " << t << std::endl;
1148  jout << std::endl;
1149  }
1150 
1151  if (nomc2coda == 0) {
1152  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1153  if (stat != nhits) {
1154  jerr << "?error return from mc2codaWrite() for BCAL TDC: "
1155  << stat << std::endl << std::endl;
1156  exit(EXIT_FAILURE);
1157  }
1158  }
1159  }
1160  }
1161  if ((dumphits >= 1) && (hc > 0)) {
1162  jout << std::endl << "BCAL TDC hits: " << hc << std::endl << std::endl;
1163  }
1164 
1165 
1166  // DFCALHit - FADC250
1167  vector<const DFCALHit*> dfcalhits;
1168  eventLoop->Get(dfcalhits);
1169  sort(dfcalhits.begin(),dfcalhits.end(),compareDFCALHits);
1170 
1171  hc=0;
1172  for (i=0; i<dfcalhits.size(); i++) {
1173  if ((dfcalhits[i]->E > 0) && ((dfcalhits[i]->t*1000.) > tMin) &&
1174  (dfcalhits[i]->t*1000. < trigTime))
1175  {
1176  if(FCAL_time_window > 0.)
1177  if(fabs(dfcalhits[i]->t) > FCAL_time_window)
1178  continue;
1179 
1180  uint32_t E = dfcalhits[i]->E*FCAL_ADCscale; // E in GeV (max ~4)
1181  uint32_t t = dfcalhits[i]->t*1000.-tMin; // in picoseconds
1182 
1183  if (noroot == 0)
1184  fcalEnergies->Fill(dfcalhits[i]->E*1000000.);
1185  if (noroot == 0)
1186  fcalTimes->Fill(dfcalhits[i]->t-tMin/1000);
1187 
1188  hc++;
1189  hitCount++;
1190  nhits=1;
1191  cscRef cscADC = DFCALHitTranslationADC(dfcalhits[i]);
1192  hit[0].hit_id = hitCount;
1193  hit[0].det_id = detID;
1194  hit[0].crate_id = cscADC.crate;
1195  hit[0].slot_id = cscADC.slot;
1196  hit[0].chan_id = cscADC.channel;
1197  hit[0].module_id = FADC250;
1198  hit[0].module_mode = FADC250_MODE_IP;
1199  hit[0].nwords = 2;
1200  hit[0].hdata = mcData;
1201  hit[0].hdata[0] = E;
1202  hit[0].hdata[1] = static_cast<double>(t)/FCAL_ADCtick;
1203  if (E/10 > 0x7ffff)
1204  std::cerr << "E too large for FCAL: " << E << std::endl;
1205 
1206  if (dumphits > 1) {
1207  jout << std::endl;
1208  jout << " FCAL ADC row,column are " << dfcalhits[i]->row
1209  << ", " << dfcalhits[i]->column << std::endl;
1210  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot
1211  << ", " << cscADC.channel << std::endl;
1212  jout << " hdata is: " << hit[0].hdata[0] << ", "
1213  << hit[0].hdata[1] << std::endl;
1214  jout << " E,t are " << E << ", " << t << std::endl;
1215  jout << std::endl;
1216  }
1217 
1218  if (nomc2coda == 0) {
1219  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1220  if (stat != nhits) {
1221  jerr << "?error return from mc2codaWrite() for FCAL ADC: "
1222  << stat << std::endl << std::endl;
1223  exit(EXIT_FAILURE);
1224  }
1225  }
1226  }
1227  }
1228  if ((dumphits >= 1) && (hc > 0)) {
1229  jout << std::endl << "FCAL hits: " << hc << std::endl << std::endl;
1230  }
1231 
1232 
1233  // DFDCHit - cathode strips FADC125 or anode wires F1TDC48 (115 ps)
1234  vector<const DFDCHit*> dfdchits;
1235  eventLoop->Get(dfdchits);
1236  sort(dfdchits.begin(),dfdchits.end(),compareDFDCHits);
1237 
1238  hc=0;
1239  for (i=0; i < dfdchits.size(); i++) {
1240  if ((dfdchits[i]->q > 0) && ((dfdchits[i]->t*1000.) > tMin) &&
1241  (dfdchits[i]->t*1000. < trigTime))
1242  {
1243  if(FDC_time_window > 0.)
1244  if(fabs(dfdchits[i]->t) > FDC_time_window)
1245  continue;
1246 
1247  uint32_t q = dfdchits[i]->q*FDC_ADCscale; // for cathodes
1248  if (dfdchits[i]->type == 0)
1249  q = 0.0; // No amplitude read for wires
1250  uint32_t t = dfdchits[i]->t*1000.-tMin; // in picoseconds
1251 
1252  if (noroot == 0)
1253  fdcCharges->Fill(dfdchits[i]->q);
1254  if (noroot == 0)fdcTimes->Fill(dfdchits[i]->t-tMin/1000);
1255 
1256  int type = dfdchits[i]->type;
1257  // FADC125
1258  if (type == 1) {
1259  hc++;
1260  hitCount++;
1261  nhits=1;
1262  cscRef cscADC = DFDCCathodeHitTranslation(dfdchits[i]);
1263  hit[0].hit_id = hitCount;
1264  hit[0].det_id = detID;
1265  hit[0].crate_id = cscADC.crate;
1266  hit[0].slot_id = cscADC.slot;
1267  hit[0].chan_id = cscADC.channel;
1268  hit[0].module_id = FADC125;
1269  hit[0].module_mode = FADC125_MODE_IP;
1270  hit[0].nwords = 2;
1271  hit[0].hdata = mcData;
1272  hit[0].hdata[0] = q;
1273  hit[0].hdata[1] = static_cast<double>(t)/FDC_ADCtick;
1274  //if (q > 0x7ffff)
1275  // std::cerr << "q too large for FDC: " << q << std::endl;
1276 
1277  if (dumphits > 2) {
1278  jout << std::endl;
1279  jout << " FDC ADC gPlane,element are " << dfdchits[i]->gPlane
1280  << ", " << dfdchits[i]->element << std::endl;
1281  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot
1282  << ", " << cscADC.channel << std::endl;
1283  jout << " hdata is: " << hit[0].hdata[0] << ", "
1284  << hit[0].hdata[1] << std::endl;
1285  jout << " q,t are " << q << ", " << t << std::endl;
1286  jout << std::endl;
1287  }
1288 
1289  if (nomc2coda == 0) {
1290  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1291  if (stat != nhits) {
1292  jerr << "?error return from mc2codaWrite() for FDC ADC: "
1293  << stat << std::endl << std::endl;
1294  exit(EXIT_FAILURE);
1295  }
1296  }
1297 
1298  // F1TDC48
1299  }
1300  else if (type == 0) {
1301  hc++;
1302  hitCount++;
1303  nhits=1;
1304  cscRef cscTDC = DFDCAnodeHitTranslation(dfdchits[i]);
1305  hit[0].hit_id = hitCount;
1306  hit[0].det_id = detID;
1307  hit[0].crate_id = cscTDC.crate;
1308  hit[0].slot_id = cscTDC.slot;
1309  hit[0].chan_id = cscTDC.channel;
1310  hit[0].module_id = F1TDC48;
1311  hit[0].module_mode = 0;
1312  hit[0].nwords = 1;
1313  hit[0].hdata = mcData;
1314  hit[0].hdata[0] = static_cast<double>(t)/FDC_TDCtick;
1315 
1316  if (dumphits > 2) {
1317  jout << std::endl;
1318  jout << " FDC TDC gPlane,element are " << dfdchits[i]->gPlane
1319  << ", " << dfdchits[i]->element << std::endl;
1320  jout << " c,s,c are " << cscTDC.crate << ", "
1321  << cscTDC.slot << ", " << cscTDC.channel << std::endl;
1322  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1323  jout << " q,t are " << q << ", " << t << std::endl;
1324  jout << std::endl;
1325  }
1326 
1327  if (nomc2coda == 0) {
1328  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1329  if (stat != nhits) {
1330  jerr << "?error return from mc2codaWrite() for Fdc TDC: "
1331  << stat << std::endl << std::endl;
1332  exit(EXIT_FAILURE);
1333  }
1334  }
1335  }
1336  }
1337  }
1338 
1339  if ((dumphits >= 1) && (hc > 0)) {
1340  jout << std::endl << "FDC hits: " << hc << std::endl << std::endl;
1341  }
1342 
1343 
1344  // DSCHit - FADC250 and F1TDC32 (60 ps)
1345  vector<const DSCHit*> dsthits;
1346  eventLoop->Get(dsthits);
1347  sort(dsthits.begin(),dsthits.end(),compareDSTHits);
1348 
1349  hc=0;
1350  for (i=0; i < dsthits.size(); i++) {
1351  if ((dsthits[i]->dE > 0) && ((dsthits[i]->t*1000.) > tMin) &&
1352  (dsthits[i]->t*1000. < trigTime))
1353  {
1354  if(SC_time_window > 0.)
1355  if(fabs(dsthits[i]->t) > SC_time_window)
1356  continue;
1357 
1358  uint32_t E = dsthits[i]->dE*SC_ADCscale; // dE in GeV (max ~2E-2)
1359  uint32_t t = dsthits[i]->t*1000.-tMin; // in picoseconds
1360 
1361  if (noroot == 0)
1362  stEnergies->Fill(dsthits[i]->dE*1000000.);
1363  if (noroot == 0)
1364  stTimes->Fill(dsthits[i]->t-tMin/1000);
1365 
1366  hc++;
1367  hitCount++;
1368  nhits=1;
1369  cscRef cscADC = DSTHitTranslationADC(dsthits[i]);
1370  hit[0].hit_id = hitCount;
1371  hit[0].det_id = detID;
1372  hit[0].crate_id = cscADC.crate;
1373  hit[0].slot_id = cscADC.slot;
1374  hit[0].chan_id = cscADC.channel;
1375  hit[0].module_id = FADC250;
1376  hit[0].module_mode = FADC250_MODE_IP;
1377  hit[0].nwords = 2;
1378  hit[0].hdata = mcData;
1379  hit[0].hdata[0] = E;
1380  hit[0].hdata[1] = static_cast<double>(t)/SC_ADCtick;
1381  if (E > 0x7ffff)
1382  std::cerr << "E too large for ST: " << E << std::endl;
1383 
1384  if (dumphits > 1) {
1385  jout << std::endl;
1386  jout << " ST ADC sector is " << dsthits[i]->sector << std::endl;
1387  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot
1388  << ", " << cscADC.channel << std::endl;
1389  jout << " hdata is: " << hit[0].hdata[0] << ", "
1390  << hit[0].hdata[1] << std::endl;
1391  jout << " E,t are " << E << ", " << t << std::endl;
1392  jout << std::endl;
1393  }
1394 
1395  if (nomc2coda == 0) {
1396  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1397  if (stat != nhits) {
1398  jerr << "?error return from mc2codaWrite() for ST ADC: "
1399  << stat << std::endl << std::endl;
1400  exit(EXIT_FAILURE);
1401  }
1402  }
1403 
1404  hitCount++;
1405  nhits=1;
1406  cscRef cscTDC = DSTHitTranslationTDC(dsthits[i]);
1407  hit[0].hit_id = hitCount;
1408  hit[0].det_id = detID;
1409  hit[0].crate_id = cscTDC.crate;
1410  hit[0].slot_id = cscTDC.slot;
1411  hit[0].chan_id = cscTDC.channel;
1412  hit[0].module_id = F1TDC32;
1413  hit[0].module_mode = 0;
1414  hit[0].nwords = 1;
1415  hit[0].hdata = mcData;
1416  hit[0].hdata[0] = static_cast<double>(t)/SC_TDCtick;
1417 
1418  if (dumphits > 1) {
1419  jout << std::endl;
1420  jout << " ST TDC sector is " << dsthits[i]->sector << std::endl;
1421  jout << " c,s,c are " << cscTDC.crate << ", " << cscTDC.slot
1422  << ", " << cscTDC.channel << std::endl;
1423  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1424  jout << " E,t are " << E << ", " << t << std::endl;
1425  jout << std::endl;
1426  }
1427 
1428  if (nomc2coda == 0) {
1429  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1430  if (stat != nhits) {
1431  jerr << "?error return from mc2codaWrite() for ST TDC: "
1432  << stat << std::endl << std::endl;
1433  exit(EXIT_FAILURE);
1434  }
1435  }
1436  }
1437  }
1438  if ((dumphits >= 1) && (hc > 0)) {
1439  jout << std::endl << "ST hits: " << hc << std::endl << std::endl;
1440  }
1441 
1442 
1443  // DTAGM - FADC250 and F1TDC32 (60 ps)
1444  vector<const DTAGMHit*> dtagmhits;
1445  eventLoop->Get(dtagmhits);
1446  sort(dtagmhits.begin(),dtagmhits.end(),compareDTAGMHits);
1447 
1448  hc=0;
1449  for (i=0; i < dtagmhits.size(); i++) {
1450  if (dtagmhits[i]->npix_fadc > 0 &&
1451  ((dtagmhits[i]->t*1000 > tMin && dtagmhits[i]->t*1000 < trigTime) ||
1452  (dtagmhits[i]->time_fadc*1000 > tMin &&
1453  dtagmhits[i]->time_fadc*1000 < trigTime)) )
1454  {
1455  uint32_t pA = dtagmhits[i]->npix_fadc + 2500; // in SiPM pixels
1456  uint32_t t = dtagmhits[i]->t*1000 - tMin; // in ps
1457  uint32_t tA = dtagmhits[i]->time_fadc*1000 - tMin; // in ps
1458 
1459  if(TAGM_time_window > 0.)
1460  if(fabs(dtagmhits[i]->t) > TAGM_time_window)
1461  continue;
1462 
1463  if (noroot == 0)
1464  tagmEnergies->Fill(dtagmhits[i]->npix_fadc);
1465  if (noroot == 0)
1466  tagmTimes->Fill(dtagmhits[i]->time_fadc-tMin/1000);
1467 
1468  cscRef cscADC = DTAGMHitTranslationADC(dtagmhits[i]);
1469  if (! (cscADC == CSCREF_NULL)) {
1470  hc++;
1471  hitCount++;
1472  nhits=1;
1473  hit[0].hit_id = hitCount;
1474  hit[0].det_id = detID;
1475  hit[0].crate_id = cscADC.crate;
1476  hit[0].slot_id = cscADC.slot;
1477  hit[0].chan_id = cscADC.channel;
1478  hit[0].module_id = FADC250;
1479  hit[0].module_mode = FADC250_MODE_IP;
1480  hit[0].nwords = 2;
1481  hit[0].hdata = mcData;
1482  hit[0].hdata[0] = pA; // in SiPM pixels
1483  hit[0].hdata[1] = static_cast<double>(tA)/FADC250tick;
1484  if (pA > 0x7ffff)
1485  std::cerr << "pA too large for tagger microscope: "
1486  << pA << std::endl;
1487 
1488  if (dumphits > 1) {
1489  jout << std::endl;
1490  jout << " Tagger microscope ADC row,column are "
1491  << dtagmhits[i]->row << ", " << dtagmhits[i]->column << std::endl;
1492  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot << ", "
1493  << cscADC.channel << std::endl;
1494  jout << " hdata is: " << hit[0].hdata[0] << ", " << hit[0].hdata[1]
1495  << std::endl;
1496  jout << " pA,tA are " << pA << ", " << tA << std::endl;
1497  jout << std::endl;
1498  }
1499 
1500  if (nomc2coda == 0) {
1501  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1502  if (stat != nhits) {
1503  jerr << "?error return from mc2codaWrite() for TAGGER ADC: "
1504  << stat << std::endl << std::endl;
1505  exit(EXIT_FAILURE);
1506  }
1507  }
1508  }
1509 
1510  cscRef cscTDC = DTAGMHitTranslationTDC(dtagmhits[i]);
1511  if (! (cscADC == CSCREF_NULL)) {
1512  hitCount++;
1513  nhits=1;
1514  hit[0].hit_id = hitCount;
1515  hit[0].det_id = detID;
1516  hit[0].crate_id = cscTDC.crate;
1517  hit[0].slot_id = cscTDC.slot;
1518  hit[0].chan_id = cscTDC.channel;
1519  hit[0].module_id = F1TDC32;
1520  hit[0].module_mode = 0;
1521  hit[0].nwords = 1;
1522  hit[0].hdata = mcData;
1523  hit[0].hdata[0] = static_cast<double>(t)/F1TDC32tick;
1524 
1525  if (dumphits > 1) {
1526  jout << std::endl;
1527  jout << " Tagger microscope TDC row,column are "
1528  << dtagmhits[i]->row << ", " << dtagmhits[i]->column << std::endl;
1529  jout << " c,s,c are " << cscTDC.crate << ", " << cscTDC.slot
1530  << ", " << cscTDC.channel << std::endl;
1531  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1532  jout << " t is " << t << std::endl;
1533  jout << std::endl;
1534  }
1535 
1536  if (nomc2coda == 0) {
1537  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1538  if (stat != nhits) {
1539  jerr << "?error return from mc2codaWrite() for Tagger TDC: "
1540  << stat << std::endl << std::endl;
1541  exit(EXIT_FAILURE);
1542  }
1543  }
1544  }
1545  }
1546  }
1547  if ((dumphits >= 1) && (hc > 0)) {
1548  jout << std::endl << "Tagger microscope hits: " << hc << std::endl << std::endl;
1549  }
1550 
1551  // DTAGH - FADC250 and F1TDC32 (60 ps)
1552  vector<const DTAGHHit*> dtaghhits;
1553  eventLoop->Get(dtaghhits);
1554  sort(dtaghhits.begin(),dtaghhits.end(),compareDTAGHHits);
1555 
1556  hc=0;
1557  for (i=0; i < dtaghhits.size(); i++) {
1558  if (dtaghhits[i]->npe_fadc > 0 &&
1559  ((dtaghhits[i]->t*1000 > tMin && dtaghhits[i]->t*1000 < trigTime) ||
1560  (dtaghhits[i]->time_fadc*1000 > tMin &&
1561  dtaghhits[i]->time_fadc*1000 < trigTime)) )
1562  {
1563  uint32_t pA = dtaghhits[i]->npe_fadc + 2500; // in SiPM pixels
1564  uint32_t t = dtaghhits[i]->t*1000 - tMin; // in ps
1565  uint32_t tA = dtaghhits[i]->time_fadc*1000 - tMin; // in ps
1566 
1567  if(TAGH_time_window > 0.)
1568  if(fabs(dtaghhits[i]->t) > TAGH_time_window)
1569  continue;
1570 
1571  if (noroot == 0)
1572  taghEnergies->Fill(dtaghhits[i]->npe_fadc);
1573  if (noroot == 0)
1574  taghTimes->Fill(dtaghhits[i]->time_fadc-tMin/1000);
1575 
1576  cscRef cscADC = DTAGHHitTranslationADC(dtaghhits[i]);
1577  if (! (cscADC == CSCREF_NULL)) {
1578  hc++;
1579  hitCount++;
1580  nhits=1;
1581  hit[0].hit_id = hitCount;
1582  hit[0].det_id = detID;
1583  hit[0].crate_id = cscADC.crate;
1584  hit[0].slot_id = cscADC.slot;
1585  hit[0].chan_id = cscADC.channel;
1586  hit[0].module_id = FADC250;
1587  hit[0].module_mode = FADC250_MODE_IP;
1588  hit[0].nwords = 2;
1589  hit[0].hdata = mcData;
1590  hit[0].hdata[0] = pA; // in SiPM pixels
1591  hit[0].hdata[1] = static_cast<double>(tA)/FADC250tick;
1592  if (pA > 0x7ffff)
1593  std::cerr << "pA too large for tagger hodoscope: " << pA << std::endl;
1594 
1595  if (dumphits > 1) {
1596  jout << std::endl;
1597  jout << " Tagger hodoscope ADC counter_id is "
1598  << dtaghhits[i]->counter_id << std::endl;
1599  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot << ", "
1600  << cscADC.channel << std::endl;
1601  jout << " hdata is: " << hit[0].hdata[0] << ", " << hit[0].hdata[1]
1602  << std::endl;
1603  jout << " pA,tA are " << pA << ", " << tA << std::endl;
1604  jout << std::endl;
1605  }
1606 
1607  if (nomc2coda == 0) {
1608  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1609  if (stat != nhits) {
1610  jerr << "?error return from mc2codaWrite() for TAGGER ADC: "
1611  << stat << std::endl << std::endl;
1612  exit(EXIT_FAILURE);
1613  }
1614  }
1615  }
1616 
1617  cscRef cscTDC = DTAGHHitTranslationTDC(dtaghhits[i]);
1618  if (! (cscADC == CSCREF_NULL)) {
1619  hitCount++;
1620  nhits=1;
1621  hit[0].hit_id = hitCount;
1622  hit[0].det_id = detID;
1623  hit[0].crate_id = cscTDC.crate;
1624  hit[0].slot_id = cscTDC.slot;
1625  hit[0].chan_id = cscTDC.channel;
1626  hit[0].module_id = F1TDC32;
1627  hit[0].module_mode = 0;
1628  hit[0].nwords = 1;
1629  hit[0].hdata = mcData;
1630  hit[0].hdata[0] = static_cast<double>(t)/F1TDC32tick;
1631 
1632  if (dumphits > 1) {
1633  jout << std::endl;
1634  jout << " Tagger hodoscope TDC counter_id is "
1635  << dtaghhits[i]->counter_id << std::endl;
1636  jout << " c,s,c are " << cscTDC.crate << ", " << cscTDC.slot
1637  << ", " << cscTDC.channel << std::endl;
1638  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1639  jout << " t is " << t << std::endl;
1640  jout << std::endl;
1641  }
1642 
1643  if (nomc2coda == 0) {
1644  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1645  if (stat != nhits) {
1646  jerr << "?error return from mc2codaWrite() for Tagger TDC: "
1647  << stat << std::endl << std::endl;
1648  exit(EXIT_FAILURE);
1649  }
1650  }
1651  }
1652  }
1653  }
1654  if ((dumphits >= 1) && (hc > 0)) {
1655  jout << std::endl << "Tagger hodoscope hits: " << hc << std::endl << std::endl;
1656  }
1657 
1658  // DPSCHit - FADC250 and F1TDC32 (60 ps)
1659  vector<const DPSCHit*> dpschits;
1660  eventLoop->Get(dpschits);
1661  sort(dpschits.begin(),dpschits.end(),compareDPSCHits);
1662 
1663  hc=0;
1664  for (i=0; i < dpschits.size(); i++) {
1665  if ((dpschits[i]->npe_fadc > 0) && ((dpschits[i]->t*1000.) > tMin) &&
1666  (dpschits[i]->t*1000. < trigTime))
1667  {
1668  if(PSC_time_window > 0.)
1669  if(fabs(dpschits[i]->t) > PSC_time_window)
1670  continue;
1671 
1672  uint32_t E = dpschits[i]->npe_fadc*PSC_ADCscale; // dE in GeV
1673  uint32_t t = dpschits[i]->t*1000.-tMin; // in picoseconds
1674 
1675  hc++;
1676  hitCount++;
1677  nhits=1;
1678  cscRef cscADC = DPSCHitTranslationADC(dpschits[i]);
1679  hit[0].hit_id = hitCount;
1680  hit[0].det_id = detID;
1681  hit[0].crate_id = cscADC.crate;
1682  hit[0].slot_id = cscADC.slot;
1683  hit[0].chan_id = cscADC.channel;
1684  hit[0].module_id = FADC250;
1685  hit[0].module_mode = FADC250_MODE_IP;
1686  hit[0].nwords = 2;
1687  hit[0].hdata = mcData;
1688  hit[0].hdata[0] = E;
1689  hit[0].hdata[1] = static_cast<double>(t)/PSC_ADCtick;
1690  if (E > 0x7ffff)
1691  std::cerr << "E too large for PSC: " << E << std::endl;
1692 
1693  if (dumphits > 1) {
1694  jout << std::endl;
1695  jout << " PSC ADC arm,module is "
1696  << dpschits[i]->arm << "," << dpschits[i]->module << std::endl;
1697  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot
1698  << ", " << cscADC.channel << std::endl;
1699  jout << " hdata is: " << hit[0].hdata[0] << ", "
1700  << hit[0].hdata[1] << std::endl;
1701  jout << " E,t are " << E << ", " << t << std::endl;
1702  jout << std::endl;
1703  }
1704 
1705  if (nomc2coda == 0) {
1706  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1707  if (stat != nhits) {
1708  jerr << "?error return from mc2codaWrite() for PSC ADC: "
1709  << stat << std::endl << std::endl;
1710  exit(EXIT_FAILURE);
1711  }
1712  }
1713 
1714  hitCount++;
1715  nhits=1;
1716  cscRef cscTDC = DPSCHitTranslationTDC(dpschits[i]);
1717  hit[0].hit_id = hitCount;
1718  hit[0].det_id = detID;
1719  hit[0].crate_id = cscTDC.crate;
1720  hit[0].slot_id = cscTDC.slot;
1721  hit[0].chan_id = cscTDC.channel;
1722  hit[0].module_id = F1TDC32;
1723  hit[0].module_mode = 0;
1724  hit[0].nwords = 1;
1725  hit[0].hdata = mcData;
1726  hit[0].hdata[0] = static_cast<double>(t)/PSC_TDCtick;
1727 
1728  if (dumphits > 1) {
1729  jout << std::endl;
1730  jout << " PSC TDC arm,module is "
1731  << dpschits[i]->arm << "," << dpschits[i]->module << std::endl;
1732  jout << " c,s,c are " << cscTDC.crate << ", " << cscTDC.slot
1733  << ", " << cscTDC.channel << std::endl;
1734  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1735  jout << " E,t are " << E << ", " << t << std::endl;
1736  jout << std::endl;
1737  }
1738 
1739  if (nomc2coda == 0) {
1740  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1741  if (stat != nhits) {
1742  jerr << "?error return from mc2codaWrite() for PSC TDC: "
1743  << stat << std::endl << std::endl;
1744  exit(EXIT_FAILURE);
1745  }
1746  }
1747  }
1748  }
1749  if ((dumphits >= 1) && (hc > 0)) {
1750  jout << std::endl << "PSC hits: " << hc << std::endl << std::endl;
1751  }
1752 
1753 
1754  // DPSHit - FADC250
1755  vector<const DPSHit*> dpshits;
1756  eventLoop->Get(dpshits);
1757  sort(dpshits.begin(),dpshits.end(),compareDPSHits);
1758 
1759  hc=0;
1760  for (i=0; i < dpshits.size(); i++) {
1761  if ((dpshits[i]->npix_fadc > 0) && ((dpshits[i]->t*1000.) > tMin) &&
1762  (dpshits[i]->t*1000. < trigTime))
1763  {
1764  if(PS_time_window > 0.)
1765  if(fabs(dpshits[i]->t) > PS_time_window)
1766  continue;
1767 
1768  uint32_t E = dpshits[i]->npix_fadc*PS_ADCscale; // dE in GeV
1769  uint32_t t = dpshits[i]->t*1000.-tMin; // in picoseconds
1770 
1771  hc++;
1772  hitCount++;
1773  nhits=1;
1774  cscRef cscADC = DPSHitTranslationADC(dpshits[i]);
1775  hit[0].hit_id = hitCount;
1776  hit[0].det_id = detID;
1777  hit[0].crate_id = cscADC.crate;
1778  hit[0].slot_id = cscADC.slot;
1779  hit[0].chan_id = cscADC.channel;
1780  hit[0].module_id = FADC250;
1781  hit[0].module_mode = FADC250_MODE_IP;
1782  hit[0].nwords = 2;
1783  hit[0].hdata = mcData;
1784  hit[0].hdata[0] = E;
1785  hit[0].hdata[1] = static_cast<double>(t)/PS_ADCtick;
1786  if (E > 0x7ffff)
1787  std::cerr << "E too large for PS: " << E << std::endl;
1788 
1789  if (dumphits > 1) {
1790  jout << std::endl;
1791  jout << " PS ADC arm,column is "
1792  << dpshits[i]->arm << "," << dpshits[i]->column << std::endl;
1793  jout << " c,s,c are " << cscADC.crate << ", " << cscADC.slot
1794  << ", " << cscADC.channel << std::endl;
1795  jout << " hdata is: " << hit[0].hdata[0] << ", "
1796  << hit[0].hdata[1] << std::endl;
1797  jout << " E,t are " << E << ", " << t << std::endl;
1798  jout << std::endl;
1799  }
1800 
1801  if (nomc2coda == 0) {
1802  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1803  if (stat != nhits) {
1804  jerr << "?error return from mc2codaWrite() for PS ADC: "
1805  << stat << std::endl << std::endl;
1806  exit(EXIT_FAILURE);
1807  }
1808  }
1809  }
1810  }
1811  if ((dumphits >= 1) && (hc > 0)) {
1812  jout << std::endl << "PS hits: " << hc << std::endl << std::endl;
1813  }
1814 
1815 
1816  // Write out F1TDC reference time information
1817  // Set it to zero for MC
1818  hitCount++;
1819  nhits=1;
1820  double E=0;
1821  double t=0;
1822  hit[0].hit_id = hitCount;
1823  hit[0].det_id = detID;
1824  // this corresponds to a particular channel set up by Beni
1825  hit[0].crate_id = 51;
1826  hit[0].slot_id = 17;
1827  hit[0].chan_id = 8;
1828  hit[0].module_id = F1TDC32;
1829  hit[0].module_mode = 0;
1830  hit[0].nwords = 1;
1831  hit[0].hdata = mcData;
1832  hit[0].hdata[0] = t;
1833 
1834  if (dumphits > 1) {
1835  jout << std::endl;
1836  jout << " F1TDC reference signal" << std::endl;
1837  jout << " c,s,c are " << hit[0].crate_id << ", " << hit[0].slot_id
1838  << ", " << hit[0].chan_id << std::endl;
1839  jout << " hdata is: " << hit[0].hdata[0] << std::endl;
1840  jout << " E,t are " << E << ", " << t << std::endl;
1841  jout << std::endl;
1842  }
1843 
1844  if (nomc2coda == 0) {
1845  stat = mc2codaWrite(eventID,nhits,(struct coda_hit_info *)&hit[0]);
1846  if (stat != nhits) {
1847  jerr << "?error return from mc2codaWrite() for F1TDC reference time: "
1848  << stat << std::endl << std::endl;
1849  exit(EXIT_FAILURE);
1850  }
1851  }
1852 
1853  // close event
1854  if (nomc2coda == 0) {
1855  int nwords = mc2codaCloseEvent(eventID);
1856  if (nwords < 0) {
1857  jerr << "?error return from mc2codaCloseEVent(): " << nwords
1858  << std::endl << std::endl;
1859  exit(EXIT_FAILURE);
1860  }
1861  }
1862 
1863  // write event
1864  pthread_mutex_lock(&rawMutex);
1865  chan->write(eventID->evbuf);
1866  pthread_mutex_unlock(&rawMutex);
1867 
1868 #else
1869 cout << "Built without EVIO" << endl;
1870 #endif
1871  return NOERROR;
1872 }
1873 
1874 
1875 //----------------------------------------------------------------------------
1876 
1877 
1878 // erun called once-only at end of run, independent of the number of processing threads
1880 #ifdef HAVE_EVIO
1881 
1882  jout << std::endl << " erun called for run " << runNumber << std::endl << std::endl;
1883 
1884 
1885  // add end event if required
1886  // ...
1887 
1888 
1889  // close evio output file and delete channel
1890  if (chan != NULL) {
1891  chan->close();
1892  delete(chan);
1893  chan=NULL;
1894  jout << std::endl << " output file " << outputFileName << " closed" << std::endl << std::endl;
1895  }
1896 #endif
1897 
1898  return NOERROR;
1899 }
1900 
1901 
1902 //----------------------------------------------------------------------------
1903 
1904 
1905 // fini called once-only when done, independent of the number of processing threads
1907  return NOERROR;
1908 }
1909 
1910 
1911 //----------------------------------------------------------------------------
1912 
1913 
1914 
1915 
1916 
1917 
1918 //----------------------------------------------------------------------------
1919 //----------------------------------------------------------------------------
1920 // The following routines access the translation table
1921 //----------------------------------------------------------------------------
1922 //----------------------------------------------------------------------------
1923 
1924 #ifdef HAVE_EVIO
1925 
1926 void JEventProcessor_rawevent::readTranslationTable(void) {
1927 
1928  jout << "Reading translation table " << translationTableName << std::endl;
1929 
1930 
1931  // Get the calibration object
1932  JCalibration *jcalib = japp->GetJCalibration(1);
1933 
1934  //--------------------------------------------------------------
1935  // (this block cut and pasted from TTab/DTranslationTable.cc)
1936 
1937  // String to hold entire XML translation table
1938  string tt_xml;
1939 
1940  // Try getting it from CCDB first
1941  if (jcalib && !NO_CCDB) {
1942  map<string,string> tt;
1943  string namepath = "Translation/DAQ2detector";
1944  jout << "Reading translation table from calib DB: " << namepath << " ..." << std::endl;
1945  jcalib->GetCalib(namepath, tt);
1946  if (tt.size() != 1) {
1947  jerr << " Error: Unexpected translation table format!" << std::endl;
1948  jerr << " tt.size()=" << tt.size() << " (expected 1)" << std::endl;
1949  }else{
1950  // Copy table into tt string
1951  map<string,string>::iterator iter = tt.begin();
1952  tt_xml = iter->second;
1953  }
1954  }
1955 
1956  // If getting from CCDB fails, try just reading in local file
1957  if (tt_xml.size() == 0) {
1958  if (!NO_CCDB) jout << "Unable to get translation table from CCDB." << std::endl;
1959  jout << "Will try reading TT from local file: " << XML_FILENAME << std::endl;
1960 
1961  // Open file
1962  ifstream ifs(XML_FILENAME.c_str());
1963  if (! ifs.is_open()) {
1964  jerr << " Error: Cannot open file! Translation table unavailable." << std::endl;
1965  exit(-1);
1966  }
1967 
1968  // read lines into stringstream object
1969  stringstream ss;
1970  while (ifs.good()) {
1971  char line[4096];
1972  ifs.getline(line, 4096);
1973  ss << line;
1974  }
1975 
1976  // Close file
1977  ifs.close();
1978 
1979  // Copy from stringstream to tt
1980  tt_xml = ss.str();
1981  }
1982 
1983  // create parser and specify element handlers
1984  XML_Parser xmlParser = XML_ParserCreate(NULL);
1985  if (xmlParser == NULL) {
1986  jerr << "readTranslationTable...unable to create parser" << std::endl;
1987  exit(EXIT_FAILURE);
1988  }
1989  XML_SetElementHandler(xmlParser,StartElement,EndElement);
1990 
1991  // Parse XML string
1992  int status=XML_Parse(xmlParser, tt_xml.c_str(), tt_xml.size(), 1); // "1" indicates this is the final piece of XML
1993  if (status == 0) {
1994  jerr << " ?readTranslationTable...parseXMLFile parse error for " << XML_FILENAME << std::endl;
1995  jerr << XML_ErrorString(XML_GetErrorCode(xmlParser)) << std::endl;
1996  }
1997 
1998  //--------------------------------------------------------------
1999 
2000 
2001  XML_ParserFree(xmlParser);
2002 }
2003 
2004 
2005 //----------------------------------------------------------------------------
2006 
2007 
2008 int type2detID(string &type) {
2009  if (type == "vmecpu" || type == "cpu") {
2010  return(VMECPU);
2011  } else if (type == "tid" || type == "ti") {
2012  return(TID);
2013  } else if (type == "fadc250") {
2014  return(FADC250);
2015  } else if (type == "fadc125") {
2016  return(FADC125);
2017  } else if (type == "f1tdcv2") {
2018  return(F1TDC32);
2019  } else if (type == "f1tdcv3") {
2020  return(F1TDC48);
2021  } else if (type == "jldisc" || type == "disc") {
2022  return(JLAB_DISC);
2023  } else if (type == "vx1290a") {
2024  return(CAEN1290);
2025  } else {
2026  return(UNKNOWN);
2027  }
2028 }
2029 
2030 
2031 
2032 void JEventProcessor_rawevent::StartElement(void *userData, const char *xmlname, const char **atts) {
2033 
2034  static int crate=0, slot=0;
2035 
2036  static string type,Type, locSystem;
2037  int mc2codaType;
2038  int channel = 0;
2039  string Detector;
2040  string end;
2041  string id,row,column,module,sector,layer,chan;
2042  string ring,straw,plane,bar,gPlane,element;
2043  string package,chamber,view,strip,wire;
2044  string side;
2045 
2046  // store crate summary info, fill both maps
2047  if (strcasecmp(xmlname,"halld_online_translation_table") == 0) {
2048  // do nothing
2049 
2050 
2051  } else if (strcasecmp(xmlname,"crate") == 0) {
2052  for (int i=0; atts[i]; i+=2) {
2053  if (strcasecmp(atts[i],"number") == 0) {
2054  crate = atoi(atts[i+1]);
2055  break;
2056  }
2057  }
2058  nCrate++;
2059  crateID[nCrate-1]=crate;
2060  nModules[nCrate-1]=0;
2061  if (crate > maxCrateNum) maxCrateNum = crate;
2062 
2063  } else if (strcasecmp(xmlname,"slot") == 0) {
2064  for (int i=0; atts[i]; i+=2) {
2065  if (strcasecmp(atts[i],"number") == 0) {
2066  slot = atoi(atts[i+1]);
2067  } else if (strcasecmp(atts[i],"type") == 0) {
2068  Type = string(atts[i+1]);
2069  type = string(atts[i+1]);
2070  std::transform(type.begin(), type.end(), type.begin(), (int(*)(int)) tolower);
2071  }
2072  }
2073 
2074  // The detID value set here shows up in the header of the Data Block Bank
2075  // of the output file. It should be set to one if this crate has JLab
2076  // made modules that output in the standard format (see document:
2077  // "VME Data Format Standards for JLAB Modules"). These would include
2078  // f250ADC, f125ADC, F1TDC, .... Slots containing other types of modules
2079  // (e.g. CAEN1290) should have their own unique detID. We use detID of
2080  // zero for non-digitizing modules like CPUs nd TIDs even though potentially,
2081  // one could read data from these.
2082  mc2codaType = type2detID(type);
2083  if (mc2codaType != UNKNOWN) {
2084  nModules[nCrate-1]++;
2085  modules[nCrate-1][slot-1] = mc2codaType;
2086  switch(mc2codaType) {
2087  case FADC250:
2088  case FADC125:
2089  case F1TDC32:
2090  case F1TDC48:
2091  detID[nCrate-1][slot-1] = 1;
2092  break;
2093  case CAEN1190:
2094  case CAEN1290:
2095  detID[nCrate-1][slot-1] = 20;
2096  break;
2097  default:
2098  detID[nCrate-1][slot-1] = 0;
2099  }
2100  }
2101 
2102 
2103  } else if (strcasecmp(xmlname,"channel") == 0) {
2104 
2105  for (int i=0; atts[i]; i+=2) {
2106  if (strcasecmp(atts[i],"number") == 0) {
2107  channel = atoi(atts[i+1]);
2108  } else if (strcasecmp(atts[i],"detector") == 0) {
2109  Detector = string(atts[i+1]);
2110  } else if (strcasecmp(atts[i],"id") == 0) {
2111  id = string(atts[i+1]);
2112  } else if (strcasecmp(atts[i],"row") == 0) {
2113  row = string(atts[i+1]);
2114  } else if (strcasecmp(atts[i],"column") == 0) {
2115  column = string(atts[i+1]);
2116  } else if (strcasecmp(atts[i],"col") == 0) {
2117  column = string(atts[i+1]);
2118  } else if (strcasecmp(atts[i],"module") == 0) {
2119  module = string(atts[i+1]);
2120  } else if (strcasecmp(atts[i],"sector") == 0) {
2121  sector = string(atts[i+1]);
2122  } else if (strcasecmp(atts[i],"layer") == 0) {
2123  layer = string(atts[i+1]);
2124  } else if (strcasecmp(atts[i],"end") == 0) {
2125  end = string(atts[i+1]);
2126  } else if (strcasecmp(atts[i],"chan") == 0) {
2127  chan = string(atts[i+1]);
2128  } else if (strcasecmp(atts[i],"ring") == 0) {
2129  ring = string(atts[i+1]);
2130  } else if (strcasecmp(atts[i],"straw") == 0) {
2131  straw = string(atts[i+1]);
2132  } else if (strcasecmp(atts[i],"gPlane") == 0) {
2133  gPlane = string(atts[i+1]);
2134  } else if (strcasecmp(atts[i],"element") == 0) {
2135  element = string(atts[i+1]);
2136  } else if (strcasecmp(atts[i],"plane") == 0) {
2137  plane = string(atts[i+1]);
2138  } else if (strcasecmp(atts[i],"bar") == 0) {
2139  bar = string(atts[i+1]);
2140  } else if (strcasecmp(atts[i],"package") == 0) {
2141  package = string(atts[i+1]);
2142  } else if (strcasecmp(atts[i],"chamber") == 0) {
2143  chamber = string(atts[i+1]);
2144  } else if (strcasecmp(atts[i],"view") == 0) {
2145  view = string(atts[i+1]);
2146  } else if (strcasecmp(atts[i],"strip") == 0) {
2147  strip = string(atts[i+1]);
2148  } else if (strcasecmp(atts[i],"wire") == 0) {
2149  wire = string(atts[i+1]);
2150  } else if (strcasecmp(atts[i],"side") == 0) {
2151  side = string(atts[i+1]);
2152  } else if (strcasecmp(atts[i],"system") == 0) {
2153  locSystem = string(atts[i+1]);
2154  }
2155  }
2156 
2157  // ignore certain module types
2158  if (type == "disc")
2159  return;
2160  if (type == "ctp")
2161  return;
2162  if (type == "sd")
2163  return;
2164  if (type == "a1535sn")
2165  return;
2166 
2167  // fill maps
2168 
2169  cscVal csc = {crate,slot,channel};
2170  string detector = Detector;
2171  std::transform(detector.begin(), detector.end(), detector.begin(),
2172  (int(*)(int)) tolower);
2173 
2174  string s="unknown::";
2175 
2176  if (detector == "fcal") {
2177  if (type == "fadc250") {
2178  s = "fcaladc::";
2179  } else {
2180  s = "unknownFCAL::";
2181  jerr << std::endl << std::endl
2182  << "?startElement...illegal type for FCAL: "
2183  << Type << std::endl << std::endl;
2184  }
2185  s += row + ":" + column;
2186  cscMap[s] = csc;
2187 
2188 
2189  } else if (detector == "bcal") {
2190  if (type == "f1tdcv2") {
2191  s = "bcaltdc::";
2192  } else if (type == "fadc250") {
2193  s = "bcaladc::";
2194  } else {
2195  s = "unknownBCAL::";
2196  jerr << std::endl << std::endl
2197  << "?startElement...illegal type for BCAL: "
2198  << Type << " (" << type << ")" << std::endl << std::endl;
2199  }
2200  s += module + ":" + sector + ":" + layer + ":" + end;
2201  cscMap[s] = csc;
2202 
2203  } else if (detector == "cdc") {
2204  if (type == "fadc125") {
2205  s = "cdcadc::";
2206  } else {
2207  s = "unknownCDC::";
2208  jerr << std::endl << std::endl
2209  << "?startElement...illegal type for CDC: "
2210  << Type << std::endl << std::endl;
2211  }
2212  s += ring + ":" + straw;
2213  cscMap[s] = csc;
2214 
2215 
2216  } else if (detector == "st") {
2217  if (type == "f1tdcv2") {
2218  s = "sttdc::";
2219  } else if (type == "fadc250") {
2220  s = "stadc::";
2221  } else if (type == "iseg") {
2222  s = "stiseg::"; // this just here to prevent warning message below
2223  } else {
2224  s = "unknownST::";
2225  jerr << std::endl << std::endl
2226  << "?startElement...illegal type for ST: "
2227  << Type << std::endl << std::endl;
2228  }
2229  s += sector;
2230  cscMap[s] = csc;
2231 
2232  } else if (detector == "fdc_cathodes") {
2233  int ipackage = atoi(package.c_str());
2234  int ichamber = atoi(chamber.c_str());
2235  int igPlane = 1 + (ipackage-1)*6*3 + (ichamber-1)*3 + (view == "U" ? 0:2);
2236  stringstream ss;
2237  ss << igPlane;
2238  gPlane = ss.str();
2239  if (type == "fadc125") {
2240  s = "fdccathode::";
2241  } else {
2242  s = "unknownFDCCathode::";
2243  jerr << std::endl << std::endl
2244  << "?startElement...illegal type for FDC Cathode: "
2245  << Type << std::endl << std::endl;
2246  }
2247  s += gPlane + ":" + strip;
2248  cscMap[s] = csc;
2249 
2250 
2251  } else if (detector == "fdc_wires") {
2252  int ipackage = atoi(package.c_str());
2253  int ichamber = atoi(chamber.c_str());
2254  int igPlane = 2 + (ipackage-1)*6*3 + (ichamber-1)*3;
2255  stringstream ss;
2256  ss << igPlane;
2257  gPlane = ss.str();
2258  if (type == "f1tdcv3") {
2259  s = "fdcanode::";
2260  } else {
2261  s = "unknownFDCAnode::";
2262  jerr << std::endl << std::endl
2263  << "?startElement...illegal type for FDC Anode: "
2264  << Type << std::endl << std::endl;
2265  }
2266  s += gPlane + ":" + wire;
2267  cscMap[s] = csc;
2268 
2269  } else if (detector == "tof") {
2270  if (type == "vx1290a") {
2271  s = "toftdc::";
2272  } else if (type == "fadc250") {
2273  s = "tofadc::";
2274  } else {
2275  s = "unknownTOF::";
2276  jerr << std::endl << std::endl
2277  << "?startElement...illegal type for TOF: "
2278  << Type << std::endl << std::endl;
2279  }
2280  s += plane + ":" + bar + ":" + end;
2281  cscMap[s] = csc;
2282 
2283  } else if (detector == "tagh") {
2284  if (type == "f1tdcv2") {
2285  s = "taghtdc::";
2286  } else if (type == "fadc250") {
2287  s = "taghadc::";
2288  } else {
2289  s = "unknownTagger::";
2290  jerr << std::endl << std::endl
2291  << "?startElement...illegal type for TAGH: "
2292  << Type << std::endl << std::endl;
2293  }
2294  s += id;
2295  cscMap[s] = csc;
2296 
2297  } else if (detector == "tagm") {
2298  if (type == "f1tdcv2") {
2299  s = "tagmtdc::";
2300  } else if (type == "fadc250") {
2301  s = "tagmadc::";
2302  } else {
2303  s = "unknownTagger::";
2304  jerr << std::endl << std::endl
2305  << "?startElement...illegal type for TAGM: "
2306  << Type << std::endl << std::endl;
2307  }
2308  s += row + ":" + column;
2309  cscMap[s] = csc;
2310 
2311  } else if (detector == "psc") {
2312  if (type == "f1tdcv2") {
2313  s = "psctdc::" + id;
2314  } else if (type == "fadc250") {
2315  s = "pscadc::" + id;
2316  } else {
2317  s = "unknownPSC::";
2318  jerr << std::endl << std::endl
2319  << "?startElement...illegal type for PSC: "
2320  << Type << std::endl << std::endl;
2321  }
2322  //s += row + ":" + column;
2323  cscMap[s] = csc;
2324 
2325  } else if (detector == "ps") {
2326  if (type == "fadc250") {
2327  //s = "psadc::" + id;
2328  s = "psadc::";
2329  } else {
2330  s = "unknownPS::";
2331  jerr << std::endl << std::endl
2332  << "?startElement...illegal type for PS: "
2333  << Type << std::endl << std::endl;
2334  }
2335  //s += row + ":" + column;
2336  s += side + ":" + id;
2337  cscMap[s] = csc;
2338 
2339  } else {
2340  jerr << std::endl << std::endl
2341  << "?startElement...unknown detector "
2342  << Detector << std::endl << std::endl;
2343  }
2344 
2345  if (crate < 0 || crate >= MAXDCRATE) {
2346  jerr << " Crate value of " << crate
2347  << " is not in range 0 <= crate < " << MAXDCRATE << std::endl;
2348  exit(-1);
2349  }
2350 
2351  if (slot < 0 || slot >= MAXDSLOT) {
2352  jerr << " Slot value of " << slot
2353  << " is not in range 0 <= slot < " << MAXDSLOT << std::endl;
2354  exit(-1);
2355  }
2356 
2357  if (channel < 0 || channel >= MAXDCHANNEL) {
2358  jerr << " Crate value of " << channel
2359  << " is not in range 0 <= channel < " << MAXDCHANNEL << std::endl;
2360  exit(-1);
2361  }
2362 
2363 
2364  // fill detector map, index is crate,slot,channel
2365  detectorMap[crate][slot][channel] = s;
2366 
2367  } else {
2368  jerr << std::endl << std::endl
2369  << "?startElement...unknown xml tag "
2370  << xmlname << std::endl << std::endl;
2371  }
2372 
2373 }
2374 
2375 
2376 //--------------------------------------------------------------------------
2377 
2378 
2379 void JEventProcessor_rawevent::EndElement(void *userData, const char *xmlname) {
2380  // nothing to do yet...
2381 }
2382 
2383 
2384 //--------------------------------------------------------------------------
2385 
2386 
2387 
2388 //--------------------------------------------------------------------------
2389 //--------------------------------------------------------------------------
2390 // aux routines encode hit info into string for inverse lookup table
2391 //--------------------------------------------------------------------------
2392 //--------------------------------------------------------------------------
2393 
2394 
2395 cscRef JEventProcessor_rawevent::DTOFHitTranslationADC(const DTOFHit* hit) const {
2396  string end;
2397  if (hit->plane == 0) {
2398  end = (hit->end == 0 ? "UP":"DW");
2399  }else{
2400  end = (hit->end == 0 ? "N":"S");
2401  }
2402  string s = "tofadc::" + lexical_cast(hit->plane) + ":"
2403  + lexical_cast(hit->bar) + ":" + end;
2404  if (cscMap.count(s) <= 0)
2405  jerr << "?unknown map entry " << s << std::endl;
2406  return(cscMap[s]);
2407 }
2408 
2409 
2410 //----------------------------------------------------------------------------
2411 
2412 
2413 cscRef JEventProcessor_rawevent::DTOFHitTranslationTDC(const DTOFHit* hit) const {
2414  string end;
2415  if (hit->plane == 0) {
2416  end = (hit->end == 0 ? "UP":"DW");
2417  }else{
2418  end = (hit->end == 0 ? "N":"S");
2419  }
2420  string s = "toftdc::" + lexical_cast(hit->plane) + ":"
2421  + lexical_cast(hit->bar) + ":" + end;
2422  if (cscMap.count(s) <= 0)
2423  jerr << "?unknown map entry " << s << std::endl;
2424  return(cscMap[s]);
2425 }
2426 
2427 
2428 //----------------------------------------------------------------------------
2429 
2430 
2431 cscRef JEventProcessor_rawevent::DBCALHitTranslationADC(const DBCALHit *hit) const {
2432  string end = hit->end == 0 ? "U":"D";
2433  string s = "bcaladc::" + lexical_cast(hit->module) + ":"
2434  + lexical_cast(hit->sector) + ":"
2435  + lexical_cast(hit->layer) + ":" + end;
2436  if (cscMap.count(s) <= 0)
2437  jerr << "?unknown map entry " << s << std::endl;
2438  return(cscMap[s]);
2439 }
2440 
2441 
2442 //----------------------------------------------------------------------------
2443 
2444 
2445 //cscRef JEventProcessor_rawevent::DBCALHitTranslationTDC(const DBCALHit *hit) const {
2446 cscRef JEventProcessor_rawevent::DBCALHitTranslationTDC(const DBCALTDCHit *hit) const {
2447  // BCAL does not have TDC channels for layer 4, but some older simulation files
2448  // have this. Ignore those hits here.
2449  if (hit->layer > 3)
2450  return CSCREF_NULL;
2451  string end = hit->end == 0 ? "U":"D";
2452  string s = "bcaltdc::" + lexical_cast(hit->module) + ":"
2453  + lexical_cast(hit->sector) + ":"
2454  + lexical_cast(hit->layer) + ":" + end;
2455  if (cscMap.count(s) <= 0)
2456  jerr << "?unknown map entry " << s << std::endl;
2457  return(cscMap[s]);
2458 }
2459 
2460 
2461 //----------------------------------------------------------------------------
2462 
2463 
2464 cscRef JEventProcessor_rawevent::DFCALHitTranslationADC(const DFCALHit* hit) const {
2465  string s = "fcaladc::" + lexical_cast(hit->row) + ":"
2466  + lexical_cast(hit->column);
2467  if (cscMap.count(s) <= 0)
2468  jerr << "?unknown map entry " << s << std::endl;
2469  return(cscMap[s]);
2470 }
2471 
2472 
2473 //----------------------------------------------------------------------------
2474 
2475 
2476 cscRef JEventProcessor_rawevent::DFDCAnodeHitTranslation(const DFDCHit* hit) const {
2477  string s = "fdcanode::" + lexical_cast(hit->gPlane) + ":"
2478  + lexical_cast(hit->element);
2479  if (cscMap.count(s) <= 0)
2480  jerr << "?unknown map entry " << s << std::endl;
2481  return(cscMap[s]);
2482 }
2483 
2484 
2485 //----------------------------------------------------------------------------
2486 
2487 
2488 cscRef JEventProcessor_rawevent::DFDCCathodeHitTranslation(const DFDCHit* hit) const {
2489  string s = "fdccathode::" + lexical_cast(hit->gPlane) + ":"
2490  + lexical_cast(hit->element);
2491  if (cscMap.count(s) <= 0)
2492  jerr << "?unknown map entry " << s << std::endl;
2493  return(cscMap[s]);
2494 }
2495 
2496 
2497 //----------------------------------------------------------------------------
2498 
2499 
2500 cscRef JEventProcessor_rawevent::DCDCHitTranslationADC(const DCDCHit* hit) const {
2501  string s = "cdcadc::" + lexical_cast(hit->ring) + ":"
2502  + lexical_cast(hit->straw);
2503  if (cscMap.count(s) <= 0)
2504  jerr << "?unknown map entry " << s << std::endl;
2505  return(cscMap[s]);
2506 }
2507 
2508 
2509 //----------------------------------------------------------------------------
2510 
2511 
2512 cscRef JEventProcessor_rawevent::DSTHitTranslationADC(const DSCHit* hit) const {
2513  string s = "stadc::" + lexical_cast(hit->sector);
2514  if (cscMap.count(s) <= 0)
2515  jerr << "?unknown map entry " << s << std::endl;
2516  return(cscMap[s]);
2517 }
2518 
2519 
2520 //----------------------------------------------------------------------------
2521 
2522 
2523 cscRef JEventProcessor_rawevent::DSTHitTranslationTDC(const DSCHit* hit) const {
2524  string s = "sttdc::" + lexical_cast(hit->sector);
2525  if (cscMap.count(s) <= 0)
2526  jerr << "?unknown map entry " << s << std::endl;
2527  return(cscMap[s]);
2528 }
2529 
2530 
2531 //----------------------------------------------------------------------------
2532 
2533 
2534 cscRef JEventProcessor_rawevent::DTAGMHitTranslationTDC(const DTAGMHit* hit) const {
2535  if ( hit->column > 100)
2536  return CSCREF_NULL;
2537  string s = "tagmtdc::" + lexical_cast(hit->row) + ":"
2538  + lexical_cast(hit->column);
2539  if (cscMap.count(s) <= 0)
2540  jerr << "?unknown map entry " << s << std::endl;
2541  return cscMap[s];
2542 }
2543 
2544 
2545 //----------------------------------------------------------------------------
2546 
2547 
2548 cscRef JEventProcessor_rawevent::DTAGMHitTranslationADC(const DTAGMHit* hit) const {
2549  if ( hit->column > 100)
2550  return CSCREF_NULL;
2551  string s = "tagmadc::" + lexical_cast(hit->row) + ":"
2552  + lexical_cast(hit->column);
2553  if (cscMap.count(s) <= 0)
2554  jerr << "?unknown map entry " << s << std::endl;
2555  return cscMap[s];
2556 }
2557 
2558 
2559 //----------------------------------------------------------------------------
2560 
2561 
2562 cscRef JEventProcessor_rawevent::DTAGHHitTranslationTDC(const DTAGHHit* hit) const {
2563  if ( hit->counter_id > 274)
2564  return CSCREF_NULL;
2565  string s = "taghtdc::" + lexical_cast(hit->counter_id);
2566  if (cscMap.count(s) <= 0)
2567  jerr << "?unknown map entry " << s << std::endl;
2568  return cscMap[s];
2569 }
2570 
2571 
2572 //----------------------------------------------------------------------------
2573 
2574 
2575 cscRef JEventProcessor_rawevent::DTAGHHitTranslationADC(const DTAGHHit* hit) const {
2576  if ( hit->counter_id > 274)
2577  return CSCREF_NULL;
2578  string s = "taghadc::" + lexical_cast(hit->counter_id);
2579  if (cscMap.count(s) <= 0)
2580  jerr << "?unknown map entry " << s << std::endl;
2581  return cscMap[s];
2582 }
2583 
2584 //----------------------------------------------------------------------------
2585 
2586 
2587 cscRef JEventProcessor_rawevent::DPSCHitTranslationTDC(const DPSCHit* hit) const {
2588  int module_id = 8*hit->arm + hit->module;
2589  string s = "pscadc::" + lexical_cast(module_id);
2590  cerr << "checking = " << s << endl;
2591  if (cscMap.count(s) <= 0)
2592  jerr << "?unknown map entry " << s << std::endl;
2593  return cscMap[s];
2594 }
2595 
2596 
2597 //----------------------------------------------------------------------------
2598 
2599 
2600 cscRef JEventProcessor_rawevent::DPSCHitTranslationADC(const DPSCHit* hit) const {
2601  int module_id = 8*hit->arm + hit->module;
2602  string s = "pscadc::" + lexical_cast(module_id);
2603  cerr << "checking = " << s << endl;
2604  if (cscMap.count(s) <= 0)
2605  jerr << "?unknown map entry " << s << std::endl;
2606  return cscMap[s];
2607 }
2608 
2609 //----------------------------------------------------------------------------
2610 
2611 
2612 cscRef JEventProcessor_rawevent::DPSHitTranslationADC(const DPSHit* hit) const {
2613  string arm = hit->arm==0 ? "A" : "B";
2614  string s = "psadc::" + arm + ":" + lexical_cast(hit->column);
2615  cerr << "checking = " << s << endl;
2616  if (cscMap.count(s) <= 0)
2617  jerr << "?unknown map entry " << s << std::endl;
2618  return cscMap[s];
2619 }
2620 
2621 #endif
2622 
2623 //----------------------------------------------------------------------------
2624 //----------------------------------------------------------------------------
2625 
2626 //--------------------------------------------------------------------------
double t
Definition: DTAGHHit.h:19
int module
Definition: DPSCHit.h:20
Definition: DPSHit.h:15
int end
Definition: DTOFHit.h:23
CODA_EXP_INFO * mc2codaInitExp(int nCrates, const char *name)
Definition: mc2coda.c:45
void mc2codaSetRunNumber(unsigned int run_number)
Definition: mc2coda.c:34
Int_t layer
int plane
Definition: DTOFHit.h:21
int module
Definition: DBCALHit.h:25
char string[256]
unsigned int mc2codaCloseEvent(CODA_EVENT_INFO *event)
Definition: mc2coda.c:347
int row
Definition: DTAGMHit.h:20
int crate_id
Definition: mc2coda.h:120
DPSGeometry::Arm arm
Definition: DPSCHit.h:19
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
float SIGMA_COMMON_PEDESTAL
double time_fadc
Definition: DTAGMHit.h:25
float t
Definition: DTOFHit.h:28
float tMin
int layer
Definition: DBCALHit.h:26
double t
Definition: DTAGMHit.h:19
double t
Definition: DPSCHit.h:21
JApplication * japp
int sector
Definition: DSCHit.h:18
bool NO_RANDOM_PEDESTAL
DBCALGeometry::End end
Definition: DBCALHit.h:28
unsigned int * evbuf
Definition: mc2coda.h:113
int counter_id
Definition: DTAGHHit.h:20
Definition: DSCHit.h:14
float t
Definition: DCDCHit.h:22
static void EndElement(void *userData, const char *xmlname)
float MEAN_PEDESTAL
Definition: mc2coda.h:36
InitPlugin_t InitPlugin
int row
Definition: DFCALHit.h:23
static evioFileChannel * chan
float SIGMA_INDIVIDUAL_PEDESTAL
string XML_FILENAME
Definition: hddm2root.cc:17
int mc2codaSetCrate(CODA_EXP_INFO *expID, int crateid, int nmod, int *modules, int *detid)
Definition: mc2coda.c:102
int ring
Definition: DCDCHit.h:18
bool NO_PEDESTAL
#define FADC125_MODE_IP
Definition: mc2coda.h:54
int module_id
Definition: mc2coda.h:123
int element
Definition: DFDCHit.h:25
int module_mode
Definition: mc2coda.h:124
#define FADC250_MODE_IP
Definition: mc2coda.h:49
float t
Definition: DBCALHit.h:31
int sector
Definition: DBCALHit.h:27
Definition: mc2coda.h:15
float t
Definition: DFDCHit.h:32
int bar
Definition: DTOFHit.h:22
double time_fadc
Definition: DTAGHHit.h:24
float t
Definition: DSCHit.h:20
double t
Definition: DPSHit.h:22
File: DTOFHit.h Created: Tue Jan 18 16:15:26 EST 2011 Creator: B. Zihlmann Purpose: Container class t...
Definition: DTOFHit.h:16
int column
Definition: DTAGMHit.h:21
DPSGeometry::Arm arm
Definition: DPSHit.h:19
DBCALGeometry::End end
Definition: DBCALTDCHit.h:25
static void StartElement(void *userData, const char *xmlname, const char **atts)
int column
Definition: DPSHit.h:20
float t
Definition: DFCALHit.h:28
int column
Definition: DFCALHit.h:24
uint32_t nwords
Definition: mc2coda.h:126
int straw
Definition: DCDCHit.h:19
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
int gPlane
Definition: DFDCHit.h:27
int mc2codaWrite(CODA_EVENT_INFO *event, int nHits, struct coda_hit_info *codaHits)
Definition: mc2coda.c:273
void mc2codaFree(CODA_EXP_INFO *expID)
Definition: mc2coda.c:639
int mc2codaResetEvent(CODA_EVENT_INFO *eventID, uint64_t eventNum, uint64_t trigTime, unsigned short eventType)
Definition: mc2coda.c:483
uint32_t * hdata
Definition: mc2coda.h:127
class DFDCHit: definition for a basic FDC hit data type.
Definition: DFDCHit.h:20
CODA_EVENT_INFO * mc2codaOpenEvent(CODA_EXP_INFO *expID, uint64_t eventNum, uint64_t trigTime, unsigned short eventType, int maxSize)
Definition: mc2coda.c:155