32 DELTA_T_ADC_TDC_MAX = 10.0;
35 gPARMS->SetDefaultParameter(
"TAGMHit: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 gPARMS->SetDefaultParameter(
"TAGMHit:CUT_FACTOR", CUT_FACTOR,
"TAGM pulse integral cut factor, 0 = no cut");
39 gPARMS->SetDefaultParameter(
"TAGMHit:USE_ADC", USE_ADC,
"Use ADC times in TAGM");
41 CHECK_FADC_ERRORS =
true;
42 gPARMS->SetDefaultParameter(
"TAGMHit:CHECK_FADC_ERRORS", CHECK_FADC_ERRORS,
"Set to 1 to reject hits with fADC250 errors, ser to 0 to keep these hits");
53 fadc_gains[row][col] = 0;
54 fadc_pedestals[row][col] = 0;
55 fadc_time_offsets[row][col] = 0;
57 fiber_quality[row][col] = 0;
70 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
71 static set<int> runs_announced;
72 pthread_mutex_lock(&print_mutex);
73 bool print_messages =
false;
74 if(runs_announced.find(runnumber) == runs_announced.end()){
75 print_messages =
true;
76 runs_announced.insert(runnumber);
78 pthread_mutex_unlock(&print_mutex);
82 fadc_t_scale = 0.0625;
85 pthread_mutex_unlock(&print_mutex);
86 if(print_messages) jout <<
"In DTAGMHit_factory_Calib, loading constants..." << std::endl;
89 map<string,double> base_time_offset;
90 if (eventLoop->GetCalib(
"/PHOTON_BEAM/microscope/base_time_offset",base_time_offset))
91 jout <<
"Error loading /PHOTON_BEAM/microscope/base_time_offset !" << endl;
92 if (base_time_offset.find(
"TAGM_BASE_TIME_OFFSET") != base_time_offset.end())
93 t_base = base_time_offset[
"TAGM_BASE_TIME_OFFSET"];
95 jerr <<
"Unable to get TAGM_BASE_TIME_OFFSET from /PHOTON_BEAM/microscope/base_time_offset !" << endl;
96 if (base_time_offset.find(
"TAGM_TDC_BASE_TIME_OFFSET") != base_time_offset.end())
97 t_tdc_base = base_time_offset[
"TAGM_TDC_BASE_TIME_OFFSET"];
99 jerr <<
"Unable to get TAGM_TDC_BASE_TIME_OFFSET from /PHOTON_BEAM/microscope/base_time_offset !" << endl;
101 if (load_ccdb_constants(
"fadc_gains",
"gain", fadc_gains) &&
102 load_ccdb_constants(
"fadc_pedestals",
"pedestal", fadc_pedestals) &&
103 load_ccdb_constants(
"fadc_time_offsets",
"offset", fadc_time_offsets) &&
105 load_ccdb_constants(
"fiber_quality",
"code", fiber_quality) &&
106 load_ccdb_constants(
"tdc_timewalk_corrections",
"c0", tw_c0) &&
107 load_ccdb_constants(
"tdc_timewalk_corrections",
"c1", tw_c1) &&
108 load_ccdb_constants(
"tdc_timewalk_corrections",
"c2", tw_c2) &&
109 load_ccdb_constants(
"tdc_timewalk_corrections",
"threshold", tw_c3) &&
110 load_ccdb_constants(
"tdc_timewalk_corrections",
"reference", ref) &&
111 load_ccdb_constants(
"integral_cuts",
"integral", int_cuts))
115 return UNRECOVERABLE_ERROR;
133 vector<const DTAGMGeometry*> tagmGeomVect;
134 eventLoop->Get( tagmGeomVect );
135 if (tagmGeomVect.size() < 1)
136 return OBJECT_NOT_AVAILABLE;
140 loop->GetSingle(locTTabUtilities);
143 vector<const DTAGMDigiHit*> digihits;
145 for (
unsigned int i=0; i < digihits.size(); i++) {
159 if(nsamples_pedestal == 0) {
160 jerr <<
"DTAGMDigiHit with nsamples_pedestal == 0 ! Event = " << eventnumber << endl;
167 pedestal = (double)digihit->
pedestal/nsamples_pedestal;
175 int quality = fiber_quality[digihit->
row][digihit->
column];
176 if (quality == k_fiber_bad || quality == k_fiber_noisy)
182 A -= pedestal*nsamples_integral;
183 int row = digihit->
row;
185 if (A < CUT_FACTOR*int_cuts[row][column])
continue;
190 double Elow = tagmGeom.
getElow(column);
191 double Ehigh = tagmGeom.
getEhigh(column);
192 hit->
E = (Elow + Ehigh)/2;
202 hit->AddAssociatedObject(digihit);
203 _data.push_back(hit);
209 vector<const DTAGMTDCDigiHit*> tdcdigihits;
210 loop->Get(tdcdigihits);
211 for (
unsigned int i=0; i < tdcdigihits.size(); i++) {
215 int row = digihit->
row;
222 for (
unsigned int j=0; j < _data.size(); ++j) {
223 if (_data[j]->row == row && _data[j]->column == column &&
224 fabs(T - _data[j]->time_fadc) < DELTA_T_ADC_TDC_MAX)
229 if (hit ==
nullptr) {
233 double Elow = tagmGeom.
getElow(column);
234 double Ehigh = tagmGeom.
getEhigh(column);
235 hit->
E = (Elow + Ehigh)/2;
241 _data.push_back(hit);
253 double t0 = ref[row][
column];
257 T -= c1*pow(1/(P+c3),c2) - (t0 -
c0);
264 hit->AddAssociatedObject(digihit);
294 std::vector< std::map<std::string, double> > table;
295 std::string ccdb_key =
"/PHOTON_BEAM/microscope/" + table_name;
296 if (eventLoop->GetCalib(ccdb_key, table))
298 jout <<
"Error loading " << ccdb_key <<
" from ccdb!" << std::endl;
301 for (
unsigned int i=0; i < table.size(); ++i) {
302 int row = (table[i])[
"row"];
303 int col = (table[i])[
"column"];
304 result[row][col] = (table[i])[column_name];
double Convert_DigiTimeToNs_F1TDC(const JObject *locTDCDigiHit) const
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
bool CheckFADC250_NoErrors(uint32_t QF) const
int column
column number 1-102
jerror_t fini(void)
Called after last event of last event source has been processed.
double getEhigh(unsigned int column) const
uint32_t pulse_peak
maximum sample in pulse
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
uint32_t pedestal
pedestal info used by FPGA (if any)
uint32_t QF
Quality Factor from FPGA algorithms.
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
double getElow(unsigned int column) const
static const int k_fiber_bad
bool CheckFADC250_PedestalOK(uint32_t QF) const
bool load_ccdb_constants(std::string table_name, std::string column_name, double table[TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1])
vector< double > tdc_time_offsets
static const int k_fiber_noisy
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static TH1I * pedestal[nChan]
uint32_t nsamples_integral
number of samples used in integral
jerror_t erun(void)
Called everytime run number changes, if brun has been called.
static const int k_fiber_good
uint32_t nsamples_pedestal
number of samples used in pedestal
jerror_t init(void)
Called once at program start.