34 DELTA_T_ADC_TDC_MAX = 10.0;
35 gPARMS->SetDefaultParameter(
"TAGHHit:DELTA_T_ADC_TDC_MAX", DELTA_T_ADC_TDC_MAX,
36 "Maximum difference in ns between a (calibrated) fADC time and"
37 " F1TDC time for them to be matched in a single hit");
38 ADC_THRESHOLD = 200.0;
39 gPARMS->SetDefaultParameter(
"TAGHHit:ADC_THRESHOLD",ADC_THRESHOLD,
40 "pulse height threshold");
42 CHECK_FADC_ERRORS =
true;
43 gPARMS->SetDefaultParameter(
"TAGHHit:CHECK_FADC_ERRORS", CHECK_FADC_ERRORS,
"Set to 1 to reject hits with fADC250 errors, ser to 0 to keep these hits");
69 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
70 static set<int> runs_announced;
71 pthread_mutex_lock(&print_mutex);
72 bool print_messages =
false;
73 if(runs_announced.find(runnumber) == runs_announced.end()){
74 print_messages =
true;
75 runs_announced.insert(runnumber);
77 pthread_mutex_unlock(&print_mutex);
81 fadc_t_scale = 0.0625;
84 if(print_messages) jout <<
"In DTAGHHit_factory, loading constants..." << std::endl;
87 map<string,double> base_time_offset;
88 if (eventLoop->GetCalib(
"/PHOTON_BEAM/hodoscope/base_time_offset",base_time_offset))
89 jout <<
"Error loading /PHOTON_BEAM/hodoscope/base_time_offset !" << endl;
90 if (base_time_offset.find(
"TAGH_BASE_TIME_OFFSET") != base_time_offset.end())
91 t_base = base_time_offset[
"TAGH_BASE_TIME_OFFSET"];
93 jerr <<
"Unable to get TAGH_BASE_TIME_OFFSET from /PHOTON_BEAM/hodoscope/base_time_offset !" << endl;
95 if (base_time_offset.find(
"TAGH_TDC_BASE_TIME_OFFSET") != base_time_offset.end())
96 t_tdc_base = base_time_offset[
"TAGH_TDC_BASE_TIME_OFFSET"];
98 jerr <<
"Unable to get TAGH_TDC_BASE_TIME_OFFSET from /PHOTON_BEAM/hodoscope/base_time_offset !" << endl;
100 if (load_ccdb_constants(
"fadc_gains",
"gain", fadc_gains) &&
101 load_ccdb_constants(
"fadc_pedestals",
"pedestal", fadc_pedestals) &&
102 load_ccdb_constants(
"fadc_time_offsets",
"offset", fadc_time_offsets) &&
104 load_ccdb_constants(
"counter_quality",
"code", counter_quality) &&
105 load_ccdb_constants(
"tdc_timewalk",
"c0", tdc_twalk_c0) &&
106 load_ccdb_constants(
"tdc_timewalk",
"c1", tdc_twalk_c1) &&
107 load_ccdb_constants(
"tdc_timewalk",
"c2", tdc_twalk_c2) &&
108 load_ccdb_constants(
"tdc_timewalk",
"c3", tdc_twalk_c3))
112 return UNRECOVERABLE_ERROR;
130 vector<const DTAGHGeometry*> taghGeomVect;
131 eventLoop->Get( taghGeomVect );
132 if (taghGeomVect.size() < 1)
133 return OBJECT_NOT_AVAILABLE;
137 loop->GetSingle(locTTabUtilities);
140 vector<const DTAGHDigiHit*> digihits;
142 for (
unsigned int i=0; i < digihits.size(); i++) {
147 int quality = counter_quality[
counter];
148 if (quality == k_counter_bad || quality == k_counter_noisy)
162 if(nsamples_pedestal == 0) {
163 jerr <<
"DTAGHDigiHit with nsamples_pedestal == 0 ! Event = " << eventnumber << endl;
170 pedestal = (double)digihit->
pedestal/nsamples_pedestal;
179 A -= pedestal*nsamples_integral;
182 if (pulse_peak < ADC_THRESHOLD)
continue;
186 double Elow = taghGeom.
getElow(counter);
187 double Ehigh = taghGeom.
getEhigh(counter);
188 hit->
E = (Elow + Ehigh)/2;
196 hit->
time_tdc = numeric_limits<double>::quiet_NaN();
202 hit->AddAssociatedObject(digihit);
203 _data.push_back(hit);
209 vector<const DTAGHTDCDigiHit*> tdcdigihits;
210 loop->Get(tdcdigihits);
211 for (
unsigned int i=0; i < tdcdigihits.size(); i++) {
221 for (
unsigned int j=0; j < _data.size(); ++j) {
222 if (_data[j]->counter_id == counter &&
223 fabs(T - _data[j]->time_fadc) < DELTA_T_ADC_TDC_MAX)
228 if (hit ==
nullptr) {
231 double Elow = taghGeom.
getElow(counter);
232 double Ehigh = taghGeom.
getEhigh(counter);
233 hit->
E = (Elow + Ehigh)/2;
234 hit->
time_fadc = numeric_limits<double>::quiet_NaN();
235 hit->
integral = numeric_limits<double>::quiet_NaN();
236 hit->
pulse_peak = numeric_limits<double>::quiet_NaN();
237 hit->
npe_fadc = numeric_limits<double>::quiet_NaN();
240 _data.push_back(hit);
249 T -= (P <= c3 || c3 <= 0.0) ? c0 + c1/pow(P,c2) : c0 + c1*(1.0+
c2)/pow(c3,c2) - c1*c2*P/pow(c3,1.0+c2);
252 hit->AddAssociatedObject(digihit);
281 std::vector< std::map<std::string, double> > table;
282 std::string ccdb_key =
"/PHOTON_BEAM/hodoscope/" + table_name;
283 if (eventLoop->GetCalib(ccdb_key, table))
285 jout <<
"Error loading " << ccdb_key <<
" from ccdb!" << std::endl;
288 for (
unsigned int i=0; i < table.size(); ++i) {
289 int counter = (table[i])[
"id"];
290 result[
counter] = (table[i])[column_name];
static const int k_counter_good
int counter_id
counter id 1-274
double Convert_DigiTimeToNs_F1TDC(const JObject *locTDCDigiHit) const
double getElow(unsigned int counter) const
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
bool CheckFADC250_NoErrors(uint32_t QF) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
uint32_t QF
Quality Factor from FPGA algorithms.
int counter_id
counter id 1-274
static const int k_counter_bad
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
bool load_ccdb_constants(std::string table_name, std::string column_name, double table[TAGH_MAX_COUNTER+1])
double getEhigh(unsigned int counter) const
bool CheckFADC250_PedestalOK(uint32_t QF) const
static const int k_counter_dead
vector< double > tdc_time_offsets
static TH1I * pedestal[nChan]
uint32_t pedestal
pedestal info used by FPGA (if any)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static const int k_counter_noisy
uint32_t nsamples_pedestal
number of samples used in pedestal
jerror_t init(void)
Called once at program start.
uint32_t pulse_peak
maximum sample in pulse
uint32_t nsamples_integral
number of samples used in integral