23 ADC_THRESHOLD = 500.0;
24 gPARMS->SetDefaultParameter(
"PSHit:ADC_THRESHOLD",ADC_THRESHOLD,
25 "pedestal-subtracted pulse integral threshold");
32 CHECK_FADC_ERRORS =
true;
33 gPARMS->SetDefaultParameter(
"PSHit:CHECK_FADC_ERRORS", CHECK_FADC_ERRORS,
"Set to 1 to reject hits with fADC250 errors, ser to 0 to keep these hits");
44 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
45 static set<int> runs_announced;
46 pthread_mutex_lock(&print_mutex);
47 bool print_messages =
false;
48 if(runs_announced.find(runnumber) == runs_announced.end()){
49 print_messages =
true;
50 runs_announced.insert(runnumber);
52 pthread_mutex_unlock(&print_mutex);
55 if(print_messages) jout <<
"In DPSHit_factory, loading constants..." << endl;
58 vector<const DPSGeometry*> psGeomVect;
59 eventLoop->Get(psGeomVect);
60 if (psGeomVect.size() < 1)
61 return OBJECT_NOT_AVAILABLE;
65 map<string,double> scale_factors;
66 if (eventLoop->GetCalib(
"/PHOTON_BEAM/pair_spectrometer/digi_scales", scale_factors))
67 jout <<
"Error loading /PHOTON_BEAM/pair_spectrometer/digi_scales !" << endl;
68 if (scale_factors.find(
"PS_ADC_ASCALE") != scale_factors.end())
69 a_scale = scale_factors[
"PS_ADC_ASCALE"];
71 jerr <<
"Unable to get PS_ADC_ASCALE from /PHOTON_BEAM/pair_spectrometer/digi_scales !"
73 if (scale_factors.find(
"PS_ADC_TSCALE") != scale_factors.end())
74 t_scale = scale_factors[
"PS_ADC_TSCALE"];
76 jerr <<
"Unable to get PS_ADC_TSCALE from /PHOTON_BEAM/pair_spectrometer/digi_scales !"
80 map<string,double> base_time_offset;
81 if (eventLoop->GetCalib(
"/PHOTON_BEAM/pair_spectrometer/base_time_offset",base_time_offset))
82 jout <<
"Error loading /PHOTON_BEAM/pair_spectrometer/base_time_offset !" << endl;
83 if (base_time_offset.find(
"PS_FINE_BASE_TIME_OFFSET") != base_time_offset.end())
84 t_base = base_time_offset[
"PS_FINE_BASE_TIME_OFFSET"];
86 jerr <<
"Unable to get PS_FINE_BASE_TIME_OFFSET from /PHOTON_BEAM/pair_spectrometer/base_time_offset !" << endl;
88 FillCalibTable(adc_pedestals,
"/PHOTON_BEAM/pair_spectrometer/fine/adc_pedestals", psGeom);
89 FillCalibTable(adc_gains,
"/PHOTON_BEAM/pair_spectrometer/fine/adc_gain_factors", psGeom);
90 FillCalibTable(
adc_time_offsets,
"/PHOTON_BEAM/pair_spectrometer/fine/adc_timing_offsets", psGeom);
110 vector<const DPSGeometry*> psGeomVect;
111 eventLoop->Get(psGeomVect);
112 if (psGeomVect.size() < 1)
113 return OBJECT_NOT_AVAILABLE;
117 loop->GetSingle(locTTabUtilities);
120 vector<const DPSDigiHit*> digihits;
124 for (
unsigned int i=0; i < digihits.size(); i++) {
129 sprintf(str,
"DPSDigiHit arm out of range! arm=%d (should be 0-%d)",
131 throw JException(str);
134 sprintf(str,
"DPSDigiHit column out of range! column=%d (should be 0-%d)",
136 throw JException(str);
145 double pedestal = GetConstant(adc_pedestals,digihit,psGeom);
150 if(nsamples_pedestal == 0) {
151 jerr <<
"DPSDigiHit with nsamples_pedestal == 0 ! Event = " << eventnumber << endl;
158 pedestal = (double)digihit->
pedestal/nsamples_pedestal;
167 A -= pedestal*nsamples_integral;
170 if (A < ADC_THRESHOLD)
continue;
180 hit->column = digihit->
column;
182 hit->pulse_peak = pulse_peak;
183 hit->npix_fadc = A * a_scale * GetConstant(adc_gains, digihit, psGeom);
187 hit->AddAssociatedObject(digihit);
189 _data.push_back(hit);
221 if(eventLoop->GetCalib(table_name, table))
222 jout <<
"Error loading " + table_name +
" !" << endl;
227 sprintf(str,
"PS table loaded with wrong size! number of columns=%d (should be %d)",
230 throw JException(str);
235 sprintf(str,
"PS table loaded with wrong size! column=%d number of arms=%d (should be %d)",
238 throw JException(str);
259 sprintf(str,
"Bad arm requested in DPSHit_factory::GetConstant()! requested=%d , should be 0-%d",
262 throw JException(str);
265 sprintf(str,
"Bad column # requested in DPSHit_factory::GetConstant()! requested=%d , should be 1-%d", in_column, psGeom.
NUM_FINE_COLUMNS);
267 throw JException(str);
273 return the_table[in_column-1][in_arm];
275 return the_table[in_column-1][in_arm];
285 sprintf(str,
"Bad arm requested in DPSHit_factory::GetConstant()! requested=%d , should be 0-%d",
288 throw JException(str);
291 sprintf(str,
"Bad column # requested in DPSHit_factory::GetConstant()! requested=%d , should be 1-%d", in_hit->
column, psGeom.
NUM_FINE_COLUMNS);
293 throw JException(str);
299 return the_table[in_hit->
column-1][in_hit->
arm];
301 return the_table[in_hit->
column-1][in_hit->
arm];
311 sprintf(str,
"Bad arm requested in DPSHit_factory::GetConstant()! requested=%d , should be 0-%d",
314 throw JException(str);
317 sprintf(str,
"Bad column # requested in DPSHit_factory::GetConstant()! requested=%d , should be 1-%d", in_digihit->
column, psGeom.
NUM_FINE_COLUMNS);
319 throw JException(str);
325 return the_table[in_digihit->
column-1][in_digihit->
arm];
327 return the_table[in_digihit->
column-1][in_digihit->
arm];
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
bool CheckFADC250_NoErrors(uint32_t QF) const
if(locHist_BCALShowerPhiVsZ!=NULL)
static const int NUM_ARMS
uint32_t pedestal
pedestal info used by FPGA (if any)
sprintf(text,"Post KinFit Cut")
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t init(void)
Called once at program start.
double getEhigh(int arm, int column) const
uint32_t pulse_peak
maximum sample in pulse
vector< vector< double > > ps_digi_constants_t
void FillCalibTable(ps_digi_constants_t &table, string table_name, const DPSGeometry &psGeom)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
const double GetConstant(const ps_digi_constants_t &the_table, const DPSGeometry::Arm in_arm, const int in_column, const DPSGeometry &psGeom) const
bool CheckFADC250_PedestalOK(uint32_t QF) const
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t QF
Quality Factor from FPGA algorithms.
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
static TH1I * pedestal[nChan]
uint32_t nsamples_pedestal
number of samples used in pedestal
static const int NUM_FINE_COLUMNS
vector< double > adc_time_offsets
uint32_t nsamples_integral
number of samples used in integral
double getElow(int arm, int column) const