Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBCALHit_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DBCALHit_factory.cc
4 // Created: Tue Aug 6 09:26:13 EDT 2013
5 // Creator: davidl (on Darwin harriet.jlab.org 11.4.2 i386)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <cmath>
12 using namespace std;
13 
14 #include <BCAL/DBCALDigiHit.h>
15 #include "DBCALGeometry.h"
16 #include "DBCALHit_factory.h"
17 #include <DAQ/Df250PulseIntegral.h>
18 #include <DAQ/Df250Config.h>
19 #include <TTAB/DTTabUtilities.h>
20 using namespace jana;
21 
22 //------------------
23 // init
24 //------------------
25 jerror_t DBCALHit_factory::init(void)
26 {
27  t_scale = 0.0625; // There are 62.5 ps/count from the fADC
28  t_base = 0.;
29 
30  CHECK_FADC_ERRORS = true;
31  gPARMS->SetDefaultParameter("BCAL:CHECK_FADC_ERRORS", CHECK_FADC_ERRORS, "Set to 1 to reject hits with fADC250 errors, ser to 0 to keep these hits");
32  CORRECT_FADC_SATURATION = true;
33  gPARMS->SetDefaultParameter("BCAL:CORRECT_FADC_SATURATION", CORRECT_FADC_SATURATION, "Set to 1 to correct pulse integral for fADC saturation, set to 0 to not correct pulse integral. (default = 1)");
34  CORRECT_SIPM_SATURATION = true;
35  gPARMS->SetDefaultParameter("BCAL:CORRECT_SIPM_SATURATION", CORRECT_SIPM_SATURATION, "Set to 1 to correct for SiPM saturation, set to 0 to not correct pulse integral or peak. (default = 1)");
36 
37  // cout << " CORRECT_SIPM_SATURATION=" << CORRECT_SIPM_SATURATION << endl;
38 
39  return NOERROR;
40 }
41 
42 //------------------
43 // brun
44 //------------------
45 jerror_t DBCALHit_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
46 {
47  // Only print messages for one thread whenever run number changes
48  static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
49  static set<int> runs_announced;
50  pthread_mutex_lock(&print_mutex);
51  bool print_messages = false;
52  if(runs_announced.find(runnumber) == runs_announced.end()){
53  print_messages = true;
54  runs_announced.insert(runnumber);
55  }
56  pthread_mutex_unlock(&print_mutex);
57 
58  /// Read in calibration constants
59  vector<double> raw_gains;
60  vector<double> raw_pedestals;
61  vector<double> raw_ADC_timing_offsets;
62  vector<double> raw_channel_global_offset;
63  vector<double> raw_tdiff_u_d;
64 
65  if(print_messages) jout << "In DBCALHit_factory, loading constants..." << endl;
66 
67  // load scale factors
68  map<string,double> scale_factors;
69  if (eventLoop->GetCalib("/BCAL/digi_scales", scale_factors))
70  jout << "Error loading /BCAL/digi_scales !" << endl;
71  if (scale_factors.find("BCAL_ADC_ASCALE") != scale_factors.end())
72  a_scale = scale_factors["BCAL_ADC_ASCALE"];
73  else
74  jerr << "Unable to get BCAL_ADC_ASCALE from /BCAL/digi_scales !" << endl;
75  if (scale_factors.find("BCAL_ADC_TSCALE") != scale_factors.end()) {
76  t_scale = scale_factors["BCAL_ADC_TSCALE"];
77  if (PRINTCALIBRATION) {
78  jout << "DBCALHit_factory >>BCAL_ADC_TSCALE = " << t_scale << endl;
79  }
80  }
81  else
82  jerr << "Unable to get BCAL_ADC_TSCALE from /BCAL/digi_scales !" << endl;
83 
84  // load base time offset
85  map<string,double> base_time_offset;
86  if (eventLoop->GetCalib("/BCAL/base_time_offset",base_time_offset))
87  jout << "Error loading /BCAL/base_time_offset !" << endl;
88  if (base_time_offset.find("BCAL_BASE_TIME_OFFSET") != base_time_offset.end()) {
89  t_base = base_time_offset["BCAL_BASE_TIME_OFFSET"];
90  if (PRINTCALIBRATION) {
91  jout << "DBCALHit_factory >>BCAL_BASE_TIME_OFFSET = " << t_base << endl;
92  }
93  }
94  else
95  jerr << "Unable to get BCAL_BASE_TIME_OFFSET from /BCAL/base_time_offset !" << endl;
96 
97  // load constant tables
98  if (eventLoop->GetCalib("/BCAL/ADC_gains", raw_gains))
99  jout << "Error loading /BCAL/ADC_gains !" << endl;
100  if (eventLoop->GetCalib("/BCAL/ADC_pedestals", raw_pedestals))
101  jout << "Error loading /BCAL/ADC_pedestals !" << endl;
102  if (eventLoop->GetCalib("/BCAL/ADC_timing_offsets", raw_ADC_timing_offsets))
103  jout << "Error loading /BCAL/ADC_timing_offsets !" << endl;
104  if(eventLoop->GetCalib("/BCAL/channel_global_offset", raw_channel_global_offset))
105  jout << "Error loading /BCAL/channel_global_offset !" << endl;
106  if(eventLoop->GetCalib("/BCAL/tdiff_u_d", raw_tdiff_u_d))
107  jout << "Error loading /BCAL/tdiff_u_d !" << endl;
108 
109  if (PRINTCALIBRATION) jout << "DBCALHit_factory >> raw_gains" << endl;
110  FillCalibTable(gains, raw_gains);
111  if (PRINTCALIBRATION) jout << "DBCALHit_factory >> raw_pedestals" << endl;
112  FillCalibTable(pedestals, raw_pedestals);
113  if (PRINTCALIBRATION) jout << "DBCALHit_factory >> raw_ADC_timing_offsets" << endl;
114  FillCalibTable(ADC_timing_offsets, raw_ADC_timing_offsets);
115  if (PRINTCALIBRATION) jout << "DBCALHit_factory >> raw_channel_global_offset" << endl;
116  FillCalibTableShort(channel_global_offset, raw_channel_global_offset);
117  if (PRINTCALIBRATION) jout << "DBCALHit_factory >> raw_tdiff_u_d" << endl;
118  FillCalibTableShort(tdiff_u_d, raw_tdiff_u_d);
119 
120  std::vector<std::map<string,double> > saturation_ADC_pars;
121  if(eventLoop->GetCalib("/BCAL/ADC_saturation", saturation_ADC_pars))
122  jout << "Error loading /BCAL/ADC_saturation !" << endl;
123  for (unsigned int i=0; i < saturation_ADC_pars.size(); i++) {
124  int end = (saturation_ADC_pars[i])["end"];
125  int layer = (saturation_ADC_pars[i])["layer"] - 1;
126  fADC_MinIntegral_Saturation[end][layer] = (saturation_ADC_pars[i])["par0"];
127  fADC_Saturation_Linear[end][layer] = (saturation_ADC_pars[i])["par1"];
128  fADC_Saturation_Quadratic[end][layer] = (saturation_ADC_pars[i])["par2"];
129  }
130 
131  // load parameters for SiPM saturation
132  std::vector<std::map<string,double> > saturation_SiPM_pars;
133  if(eventLoop->GetCalib("/BCAL/SiPM_saturation", saturation_SiPM_pars))
134  jout << "Error loading /SiPM/SiPM_saturation !" << endl;
135  for (unsigned int i=0; i < saturation_SiPM_pars.size(); i++) {
136  int end = (saturation_SiPM_pars[i])["END"];
137  int layer = (saturation_SiPM_pars[i])["LAYER"] - 1;
138  integral_to_peak[end][layer] = (saturation_SiPM_pars[i])["INTEGRAL_TO_PEAK"];
139  sipm_npixels[end][layer] = (saturation_SiPM_pars[i])["SIPM_NPIXELS"];
140  pixel_per_count[end][layer] = (saturation_SiPM_pars[i])["PIXEL_PER_COUNT"];
141  }
142 
143 
144 
145  return NOERROR;
146 }
147 
148 //------------------
149 // evnt
150 //------------------
151 jerror_t DBCALHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
152 {
153  /// Generate DBCALHit object for each DBCALDigiHit object.
154  /// This is where the first set of calibration constants
155  /// is applied to convert from digitzed units into natural
156  /// units.
157  ///
158  /// Note that this code does NOT get called for simulated
159  /// data in HDDM format. The HDDM event source will copy
160  /// the precalibrated values directly into the _data vector.
161 
162  const DTTabUtilities* locTTabUtilities = NULL;
163  loop->GetSingle(locTTabUtilities);
164 
165  vector<const DBCALDigiHit*> digihits;
166  loop->Get(digihits);
167  for(unsigned int i=0; i<digihits.size(); i++){
168  const DBCALDigiHit *digihit = digihits[i];
169 
170  // Error checking for pre-Fall 2016 firmware
171  if(digihit->datasource == 1) {
172  // There is a slight difference between Mode 7 and 8 data
173  // The following condition signals an error state in the flash algorithm
174  // Do not make hits out of these
175  const Df250PulsePedestal* PPobj = NULL;
176  digihit->GetSingle(PPobj);
177  if (PPobj != NULL){
178  if (PPobj->pedestal == 0 || PPobj->pulse_peak == 0) continue;
179  }
180  }
181 
182  if(CHECK_FADC_ERRORS && !locTTabUtilities->CheckFADC250_NoErrors(digihit->QF))
183  continue;
184 
185  // parse digi-hit data
186  double integral, pedestal, nsamples_integral, nsamples_pedestal;
187  if(digihit->datasource == 1) { // pre-fall 2016 firmware
188  // Get Df250PulseIntegral object from DBCALDigiHit object
189  const Df250PulseIntegral* PIobj = NULL;
190  digihit->GetSingle(PIobj);
191 
192  if (PIobj == NULL && digihit->pedestal == 1 && digihit->QF == 1){ // This is a simulated event. Set the pedestal to zero.
193  integral = (double)digihit->pulse_integral;
194  pedestal = 0.;
195  nsamples_integral = 0.;
196  nsamples_pedestal = 1.;
197  } else {
198  // Calculate attenuated energy for channel
199  integral = (double)PIobj->integral;
200  pedestal = (double)PIobj->pedestal;
201  nsamples_integral = (double)PIobj->nsamples_integral;
202  nsamples_pedestal = (double)PIobj->nsamples_pedestal;
203  }
204  } else { // post-fall 2016 firmware (& emulated hits)
205  // Calculate attenuated energy for channel
206  integral = (double)digihit->pulse_integral;
207  // require an accurate pedestal
208  if(locTTabUtilities->CheckFADC250_PedestalOK(digihit->QF)) {
209  pedestal = (double)digihit->pedestal;
210  } else {
211  //pedestal = 0.; // need to set to some reasonable default value?
212  continue;
213  }
214  nsamples_integral = (double)digihit->nsamples_integral;
215  nsamples_pedestal = (double)digihit->nsamples_pedestal;
216  }
217 
218  // nsamples_pedestal should always be positive for valid data - err on the side of caution for now
219  if(nsamples_pedestal == 0) {
220  //throw JException("DBCALDigiHit with nsamples_pedestal == 0 !");
221  if(VERBOSE>0)jerr << "DBCALDigiHit with nsamples_pedestal == 0 ! Event = " << eventnumber << endl;
222  continue;
223  }
224 
225  //double totalpedestal = pedestal * nsamples_integral/nsamples_pedestal;
226  double single_sample_ped = pedestal/nsamples_pedestal;
227  double totalpedestal = nsamples_integral * single_sample_ped;
228 
229  double gain = GetConstant(gains,digihit);
230  double hit_E = 0;
231 
232 
233  // make corrections for SiPM saturation
234 
235  double integral_pedsub =0;
236  if ( integral > 0 ) {
237  // compute in double precision to prevent round off errors
238  integral_pedsub = integral - totalpedestal;
239  if(CORRECT_FADC_SATURATION && integral_pedsub > fADC_MinIntegral_Saturation[digihit->end][digihit->layer-1]) {
240  if(digihit->pulse_peak > 4094 || (digihit->pedestal == 1 && digihit->QF == 1)) { // check if fADC is saturated or is MC event
241  double locSaturatedIntegral = integral_pedsub - fADC_MinIntegral_Saturation[digihit->end][digihit->layer-1];
242  double locScaleFactor = 1. + fADC_Saturation_Linear[digihit->end][digihit->layer-1]*locSaturatedIntegral + fADC_Saturation_Quadratic[digihit->end][digihit->layer-1]*locSaturatedIntegral*locSaturatedIntegral;
243  integral_pedsub *= 1./locScaleFactor;
244  }
245  }
246  // make corrections for SiPM saturation (after correcting for fADC saturation)
247  // compute in double precision to prevent round off errors
248  if (CORRECT_SIPM_SATURATION) {
249  double integral_pedsub_measured = integral_pedsub;
250  double Npixels_measured = pixel_per_count[digihit->end][digihit->layer-1]*integral_pedsub_measured;
251  double Mpixels = sipm_npixels[digihit->end][digihit->layer-1];
252  double Npixels_true = Npixels_measured < Mpixels? -Mpixels*log(1 - Npixels_measured/Mpixels) : Mpixels;
253  integral_pedsub = Npixels_true/pixel_per_count[digihit->end][digihit->layer-1];
254  // cout << " event=" << eventnumber << " Layer=" << digihit->layer << " integral_pedsub_measured=" << integral_pedsub_measured
255  // << " Npixels_measured=" << Npixels_measured << " Mpixels=" << Mpixels << " integral_pedsub=" << integral_pedsub << endl;
256  }
257  hit_E = gain * integral_pedsub;
258 
259  }
260  if (VERBOSE>2) printf("%5lu digihit %2i of %2lu, type %i time %4u, peak %3u, int %4.0f %.0f, ped %3.0f %.0f %5.1f %6.1f, gain %.1e, E=%5.0f MeV\n",
261  eventnumber,i,digihits.size(),digihit->datasource,
262  digihit->pulse_time,digihit->pulse_peak,integral,nsamples_integral,
263  pedestal,nsamples_pedestal,single_sample_ped,totalpedestal,gain,hit_E*1000);
264  if ( hit_E <= 0 ) continue; // Throw away negative energy hits
265 
266  // integral and peak should be corrected separately because the ratio is not necessarily a constant.
267  //
268  int pulse_peak_pedsub=0;
269  if (CORRECT_SIPM_SATURATION) {
270  double pulse_peak_pedsub_measured = (int)digihit->pulse_peak - (int)single_sample_ped;
271  double Npixels_measured = pixel_per_count[digihit->end][digihit->layer-1]*pulse_peak_pedsub_measured*integral_to_peak[digihit->end][digihit->layer-1];
272  double Mpixels = sipm_npixels[digihit->end][digihit->layer-1];
273  double Npixels_true = Npixels_measured < Mpixels? -Mpixels*log(1 - Npixels_measured/Mpixels) : Mpixels;
274  pulse_peak_pedsub = round(Npixels_true/pixel_per_count[digihit->end][digihit->layer-1]/integral_to_peak[digihit->end][digihit->layer-1]);
275  // cout << " event=" << eventnumber << " Layer=" << digihit->layer << " pulse_peak_pedsub_measured=" << pulse_peak_pedsub_measured
276  // << " Npixels_measured=" << Npixels_measured << " Mpixels=" << Mpixels << " pulse_peak_pedsub=" << pulse_peak_pedsub
277  // << " Int/Peak Ratio=" << integral_pedsub/pulse_peak_pedsub << endl << endl;
278  }
279  else {
280  pulse_peak_pedsub = (int)digihit->pulse_peak - (int)single_sample_ped;
281  }
282 
283  // Calculate time for channel
284  double pulse_time = (double)digihit->pulse_time;
285  double end_sign = digihit->end ? -1.0 : 1.0; // Upstream = 0 -> Positive (then subtracted)
286  double hit_t_raw = t_scale * pulse_time + t_base;
287  double hit_t = t_scale * pulse_time + t_base
288  + GetConstant(ADC_timing_offsets,digihit) // low level indiviual corrections (eg 4 ns offset)
289  - GetConstant(channel_global_offset,digihit)
290  - (0.5 * end_sign) * GetConstant(tdiff_u_d,digihit);
291  if (VERBOSE>2) printf(" %2i %i %i %i , t: %4.0f %.4f %7.3f traw=%7.3f %7.3f %7.3f %7.3f t=%7.3f\n",
292  digihit->module, digihit->layer, digihit->sector, digihit->end,
293  pulse_time,t_scale,t_base,hit_t_raw,
294  GetConstant(ADC_timing_offsets,digihit),
295  GetConstant(channel_global_offset,digihit),
296  (0.5 * end_sign * GetConstant(tdiff_u_d,digihit)),hit_t);
297  DBCALHit *hit = new DBCALHit;
298  hit->module = digihit->module;
299  hit->layer = digihit->layer;
300  hit->sector = digihit->sector;
301  hit->end = digihit->end;
302 
303  hit->E = hit_E;
304  hit->pulse_peak = pulse_peak_pedsub;
305  hit->t = hit_t;
306  hit->t_raw = hit_t_raw;
307 
308  hit->AddAssociatedObject(digihit);
309 
310  _data.push_back(hit);
311  }
312 
313  return NOERROR;
314 }
315 
316 //------------------
317 // erun
318 //------------------
320 {
321  return NOERROR;
322 }
323 
324 //------------------
325 // fini
326 //------------------
328 {
329  return NOERROR;
330 }
331 
332 
333 //------------------
334 // FillCalibTable
335 //------------------
337  const vector<double> &raw_table)
338 {
339  char str[256];
340  int channel = 0;
341 
342  // reset the table before filling it
343  table.clear();
344 
345  for (int module=1; module<=BCAL_NUM_MODULES; module++) {
346  for (int layer=1; layer<=BCAL_NUM_LAYERS; layer++) {
347  for (int sector=1; sector<=BCAL_NUM_SECTORS; sector++) {
348  if ((channel > BCAL_MAX_CHANNELS) || (channel+1 > BCAL_MAX_CHANNELS)) { // sanity check
349  sprintf(str, "Too many channels for BCAL table!"
350  " channel=%d (should be %d)",
351  channel, BCAL_MAX_CHANNELS);
352  cerr << str << endl;
353  throw JException(str);
354  }
355 
356  table.push_back( cell_calib_t(raw_table[channel],raw_table[channel+1]) );
357 
358  if (PRINTCALIBRATION) {
359  printf("%2i %2i %2i %.10f %.10f\n",module,layer,sector,raw_table[channel],raw_table[channel+1]);
360  }
361 
362  channel += 2;
363  }
364  }
365  }
366 
367  // check to make sure that we loaded enough channels
368  if (channel != BCAL_MAX_CHANNELS) {
369  sprintf(str, "Not enough channels for BCAL table!"
370  " channel=%d (should be %d)",
371  channel, BCAL_MAX_CHANNELS);
372  cerr << str << endl;
373  throw JException(str);
374  }
375 }
376 
377 //------------------
378 // FillCalibTableShort
379 //------------------
381  const vector<double> &raw_table)
382 {
383  char str[256];
384  int channel = 0;
385 
386  // reset the table before filling it
387  table.clear();
388 
389  for (int module=1; module<=BCAL_NUM_MODULES; module++) {
390  for (int layer=1; layer<=BCAL_NUM_LAYERS; layer++) {
391  for (int sector=1; sector<=BCAL_NUM_SECTORS; sector++) {
392  if (channel > BCAL_MAX_CHANNELS/2) { // sanity check
393  sprintf(str, "Too many channels for BCAL table!"
394  " channel=%d (should be %d)",
395  channel, BCAL_MAX_CHANNELS/2);
396  cerr << str << endl;
397  throw JException(str);
398  }
399 
400  table.push_back( cell_calib_t(raw_table[channel],raw_table[channel]) );
401 
402  if (PRINTCALIBRATION) {
403  printf("%2i %2i %2i %.10f\n",module,layer,sector,raw_table[channel]);
404  }
405 
406  channel += 1;
407  }
408  }
409  }
410 
411  // check to make sure that we loaded enough channels
412  if (channel != BCAL_MAX_CHANNELS/2) {
413  sprintf(str, "Not enough channels for BCAL table!"
414  " channel=%d (should be %d)",
415  channel, BCAL_MAX_CHANNELS/2);
416  cerr << str << endl;
417  throw JException(str);
418  }
419 }
420 
421 //------------------------------------
422 // GetConstant
423 // Allow a few different interfaces
424 //------------------------------------
426  const int in_module,
427  const int in_layer,
428  const int in_sector,
429  const int in_end) const
430 {
431  char str[256];
432 
433  if ( (in_module <= 0) || (in_module > BCAL_NUM_MODULES)) {
434  sprintf(str, "Bad module # requested in DBCALHit_factory::GetConstant()!"
435  " requested=%d , should be 1-%d", in_module, BCAL_NUM_MODULES);
436  cerr << str << endl;
437  throw JException(str);
438  }
439  if ( (in_layer <= 0) || (in_layer > BCAL_NUM_LAYERS)) {
440  sprintf(str, "Bad layer # requested in DBCALHit_factory::GetConstant()!"
441  " requested=%d , should be 1-%d", in_layer, BCAL_NUM_LAYERS);
442  cerr << str << endl;
443  throw JException(str);
444  }
445  if ( (in_sector <= 0) || (in_sector > BCAL_NUM_SECTORS)) {
446  sprintf(str, "Bad sector # requested in DBCALHit_factory::GetConstant()!"
447  " requested=%d , should be 1-%d", in_sector, BCAL_NUM_SECTORS);
448  cerr << str << endl;
449  throw JException(str);
450  }
451  if ( (in_end != DBCALGeometry::kUpstream) && (in_end != DBCALGeometry::kDownstream) ) {
452  sprintf(str, "Bad end # requested in DBCALHit_factory::GetConstant()!"
453  " requested=%d , should be 0-1", in_end);
454  cerr << str << endl;
455  throw JException(str);
456  }
457 
458  const int the_cell = GetCalibIndex( in_module, in_layer, in_sector);
459 
460  if (in_end == DBCALGeometry::kUpstream) {
461  // handle the upstream end
462  return the_table.at(the_cell).first;
463  } else {
464  // handle the downstream end
465  return the_table.at(the_cell).second;
466  }
467 
468 }
469 
470 const double DBCALHit_factory::GetConstant( const bcal_digi_constants_t &the_table,
471  const DBCALHit *in_hit) const
472 {
473  char str[256];
474 
475  if ( (in_hit->module <= 0) || (in_hit->module > BCAL_NUM_MODULES)) {
476  sprintf(str, "Bad module # requested in DBCALHit_factory::GetConstant()!"
477  " requested=%d , should be 1-%d", in_hit->module, BCAL_NUM_MODULES);
478  cerr << str << endl;
479  throw JException(str);
480  }
481  if ( (in_hit->layer <= 0) || (in_hit->layer > BCAL_NUM_LAYERS)) {
482  sprintf(str, "Bad layer # requested in DBCALHit_factory::GetConstant()!"
483  " requested=%d , should be 1-%d", in_hit->layer, BCAL_NUM_LAYERS);
484  cerr << str << endl;
485  throw JException(str);
486  }
487  if ( (in_hit->sector <= 0) || (in_hit->sector > BCAL_NUM_SECTORS)) {
488  sprintf(str, "Bad sector # requested in DBCALHit_factory::GetConstant()!"
489  " requested=%d , should be 1-%d", in_hit->sector, BCAL_NUM_SECTORS);
490  cerr << str << endl;
491  throw JException(str);
492  }
493  if ( (in_hit->end != DBCALGeometry::kUpstream) &&
494  (in_hit->end != DBCALGeometry::kDownstream) )
495  {
496  sprintf(str, "Bad end # requested in DBCALHit_factory::GetConstant()!"
497  " requested=%d , should be 0-1", in_hit->end);
498  cerr << str << endl;
499  throw JException(str);
500  }
501 
502  const int the_cell = GetCalibIndex( in_hit->module, in_hit->layer, in_hit->sector );
503 
504  if (in_hit->end == DBCALGeometry::kUpstream) {
505  // handle the upstream end
506  return the_table.at(the_cell).first;
507  //return the_table[the_cell].first;
508  } else {
509  // handle the downstream end
510  return the_table.at(the_cell).second;
511  //return the_table[the_cell].second;
512  }
513 
514 }
515 
517  const DBCALDigiHit *in_digihit) const
518 {
519  char str[256];
520 
521  if ( (in_digihit->module <= 0) || (in_digihit->module > BCAL_NUM_MODULES)) {
522  sprintf(str, "Bad module # requested in DBCALHit_factory::GetConstant()!"
523  " requested=%d , should be 1-%d",
524  in_digihit->module, BCAL_NUM_MODULES);
525  cerr << str << endl;
526  throw JException(str);
527  }
528  if ( (in_digihit->layer <= 0) || (in_digihit->layer > BCAL_NUM_LAYERS)) {
529  sprintf(str, "Bad layer # requested in DBCALHit_factory::GetConstant()!"
530  " requested=%d , should be 1-%d",
531  in_digihit->layer, BCAL_NUM_LAYERS);
532  cerr << str << endl;
533  throw JException(str);
534  }
535  if ( (in_digihit->sector <= 0) || (in_digihit->sector > BCAL_NUM_SECTORS)) {
536  sprintf(str, "Bad sector # requested in DBCALHit_factory::GetConstant()!"
537  " requested=%d , should be 1-%d",
538  in_digihit->sector, BCAL_NUM_SECTORS);
539  cerr << str << endl;
540  throw JException(str);
541  }
542  if ( (in_digihit->end != DBCALGeometry::kUpstream) &&
543  (in_digihit->end != DBCALGeometry::kDownstream) )
544  {
545  sprintf(str, "Bad end # requested in DBCALHit_factory::GetConstant()!"
546  " requested=%d , should be 0-1", in_digihit->end);
547  cerr << str << endl;
548  throw JException(str);
549  }
550 
551  const int the_cell = GetCalibIndex( in_digihit->module, in_digihit->layer, in_digihit->sector );
552 
553  if (in_digihit->end == DBCALGeometry::kUpstream) {
554  // handle the upstream end
555  return the_table.at(the_cell).first;
556  } else {
557  // handle the downstream end
558  return the_table.at(the_cell).second;
559  }
560 
561 }
562 /*
563  const double DBCALHit_factory::GetConstant(const bcal_digi_constants_t &the_table,
564  const DTranslationTable *ttab,
565  const int in_rocid,
566  const int in_slot,
567  const int in_channel) const
568  {
569  char str[256];
570 
571  DTranslationTable::csc_t daq_index = { in_rocid, in_slot, in_channel };
572  DTranslationTable::DChannelInfo channel_info = ttab->GetDetectorIndex(daq_index);
573 
574  if ( (channel_info.bcal.module <= 0)
575  || (channel_info.bcal.module > static_cast<unsigned int>(BCAL_NUM_MODULES)))
576  {
577  sprintf(str, "Bad module # requested in DBCALHit_factory::GetConstant()!"
578  " requested=%d , should be 1-%d", channel_info.bcal.module, BCAL_NUM_MODULES);
579  cerr << str << endl;
580  throw JException(str);
581  }
582  if ( (channel_info.bcal.layer <= 0)
583  || (channel_info.bcal.layer > static_cast<unsigned int>(BCAL_NUM_LAYERS)))
584  {
585  sprintf(str, "Bad layer # requested in DBCALHit_factory::GetConstant()!"
586  " requested=%d , should be 1-%d", channel_info.bcal.layer, BCAL_NUM_LAYERS);
587  cerr << str << endl;
588  throw JException(str);
589  }
590  if ( (channel_info.bcal.sector <= 0)
591  || (channel_info.bcal.sector > static_cast<unsigned int>(BCAL_NUM_SECTORS)))
592  {
593  sprintf(str, "Bad sector # requested in DBCALHit_factory::GetConstant()!"
594  " requested=%d , should be 1-%d", channel_info.bcal.sector, BCAL_NUM_SECTORS);
595  cerr << str << endl;
596  throw JException(str);
597  }
598  if ( (channel_info.bcal.end != DBCALGeometry::kUpstream)
599  && (channel_info.bcal.end != DBCALGeometry::kDownstream) )
600  {
601  sprintf(str, "Bad end # requested in DBCALHit_factory::GetConstant()!"
602  " requested=%d , should be 0-1", channel_info.bcal.end);
603  cerr << str << endl;
604  throw JException(str);
605  }
606 
607  int the_cell = DBCALGeometry::cellId(channel_info.bcal.module,
608  channel_info.bcal.layer,
609  channel_info.bcal.sector);
610 
611  if (channel_info.bcal.end == DBCALGeometry::kUpstream) {
612 // handle the upstream end
613 return the_table.at(the_cell).first;
614 } else {
615 // handle the downstream end
616 return the_table.at(the_cell).second;
617 }
618 }
619 */
float E
Definition: DBCALHit.h:30
bool CheckFADC250_NoErrors(uint32_t QF) const
void FillCalibTable(bcal_digi_constants_t &table, const vector< double > &raw_table)
char str[256]
Int_t layer
int module
Definition: DBCALHit.h:25
sprintf(text,"Post KinFit Cut")
jerror_t init(void)
Called once at program start.
void FillCalibTableShort(bcal_digi_constants_t &table, const vector< double > &raw_table)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
uint32_t nsamples_integral
number of samples used in integral
Definition: DBCALDigiHit.h:34
uint32_t nsamples_integral
number of samples used in integral
int layer
Definition: DBCALHit.h:26
uint32_t pulse_peak
from Pulse Pedestal Data word
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t fini(void)
Called after last event of last event source has been processed.
DBCALGeometry::End end
Definition: DBCALDigiHit.h:28
uint32_t datasource
0=window raw data, 1=old(pre-Fall16) firmware, 2=Df250PulseData, 3=MC
Definition: DBCALDigiHit.h:37
uint32_t pulse_peak
identified pulse height as returned by FPGA algorithm
Definition: DBCALDigiHit.h:30
DBCALGeometry::End end
Definition: DBCALHit.h:28
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DBCALDigiHit.h:29
const bool VERBOSE
uint32_t nsamples_pedestal
number of samples used in pedestal
Definition: DBCALDigiHit.h:35
pair< double, double > cell_calib_t
const double GetConstant(const bcal_digi_constants_t &the_table, const int in_module, const int in_layer, const int in_sector, const int in_end) const
uint32_t QF
Quality Factor from FPGA algorithms.
Definition: DBCALDigiHit.h:33
float t
Definition: DBCALHit.h:31
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
int sector
Definition: DBCALHit.h:27
bool CheckFADC250_PedestalOK(uint32_t QF) const
uint32_t pedestal
pedestal info used by FPGA (if any)
Definition: DBCALDigiHit.h:32
uint32_t integral
from Pulse Integral Data word
uint32_t pedestal
from Pulse Integral Data word (future)
int pulse_peak
Definition: DBCALHit.h:29
static TH1I * pedestal[nChan]
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DBCALDigiHit.h:31
uint32_t pedestal
from Pulse Pedestal Data word
vector< cell_calib_t > bcal_digi_constants_t
uint32_t nsamples_pedestal
number of samples used in pedestal
printf("string=%s", string)
float t_raw
Uncalibrated time in ns.
Definition: DBCALHit.h:32