30 a_scale = 2.4E4/1.3E5;
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);
57 timing_offsets.clear();
60 if(print_messages) jout <<
"In DFDCHit_factory, loading constants..." << endl;
63 map<string,double> scale_factors;
64 if(eventLoop->GetCalib(
"/FDC/digi_scales", scale_factors))
65 jout <<
"Error loading /FDC/digi_scales !" << endl;
66 if( scale_factors.find(
"FDC_ADC_ASCALE") != scale_factors.end() ) {
67 a_scale = scale_factors[
"FDC_ADC_ASCALE"];
69 jerr <<
"Unable to get FDC_ADC_ASCALE from /FDC/digi_scales !" << endl;
71 if( scale_factors.find(
"FDC_ADC_TSCALE") != scale_factors.end() ) {
72 t_scale = scale_factors[
"FDC_ADC_TSCALE"];
74 jerr <<
"Unable to get FDC_ADC_TSCALE from /FDC/digi_scales !" << endl;
78 map<string,double> base_time_offset;
79 if (eventLoop->GetCalib(
"/FDC/base_time_offset",base_time_offset))
80 jout <<
"Error loading /FDC/base_time_offset !" << endl;
81 if (base_time_offset.find(
"FDC_BASE_TIME_OFFSET") != base_time_offset.end())
82 fadc_t_base = base_time_offset[
"FDC_BASE_TIME_OFFSET"];
84 jerr <<
"Unable to get FDC_BASE_TIME_OFFSET from /FDC/base_time_offset !" << endl;
85 if (base_time_offset.find(
"FDC_TDC_BASE_TIME_OFFSET") != base_time_offset.end())
86 t_base = base_time_offset[
"FDC_TDC_BASE_TIME_OFFSET"];
88 jerr <<
"Unable to get FDC_TDC_BASE_TIME_OFFSET from /FDC/base_time_offset !" << endl;
92 LoadPackageCalibTables(eventLoop,
"/FDC/package1");
93 LoadPackageCalibTables(eventLoop,
"/FDC/package2");
94 LoadPackageCalibTables(eventLoop,
"/FDC/package3");
95 LoadPackageCalibTables(eventLoop,
"/FDC/package4");
100 sprintf(str,
"Bad # of planes for FDC gains from CCDB! CCDB=%zu , should be %d",
103 throw JException(str);
106 sprintf(str,
"Bad # of planes for FDC pedestals from CCDB! CCDB=%zu , should be %d",
109 throw JException(str);
112 sprintf(str,
"Bad # of planes for FDC timing offsets from CCDB! CCDB=%zu , should be %d",
115 throw JException(str);
138 loop->GetSingle(locTTabUtilities);
141 vector<const DFDCCathodeDigiHit*> cathodedigihits;
142 loop->Get(cathodedigihits);
143 for(
unsigned int i=0; i<cathodedigihits.size(); i++){
166 int gPlane=layer + 3*(gLayer - 1);
170 throw JException(str);
174 throw JException(str);
177 int plane_index=gPlane-1;
178 int strip_index=digihit->
strip-1;
202 digihit->GetSingle(FDCPulseObj);
203 if (FDCPulseObj != NULL){
205 vector<const Df125Config*> configs;
206 digihit->Get(configs);
210 if(!configs.empty()){
213 ABIT = config->
ABIT == 0xffff ? 3 : config->
ABIT;
214 PBIT = config->
PBIT == 0xffff ? 0 : config->
PBIT;
215 NW = config->
NW == 0xffff ? 80 : config->
NW;
216 IE = config->
IE == 0xffff ? 16 : config->
IE;
218 static int Nwarnings = 0;
220 _DBG_ <<
"NO Df125Config object associated with Df125FDCPulse object!" << endl;
222 if(Nwarnings==10)
_DBG_ <<
" --- LAST WARNING!! ---" << endl;
232 pulse_peak = FDCPulseObj->peak_amp << ABIT;
239 digihit->GetSingle(PPobj);
247 digihit->GetSingle(PIobj);
248 if ( PPobj == NULL || PIobj == NULL)
continue;
252 int scaled_ped = raw_ped << PBIT;
261 double t =
t_scale * T - timing_offsets[plane_index][strip_index]+fadc_t_base;
267 hit->
module = 1 + (gLayer-1)/3;
277 unsigned int stripOffset=0;
278 if (digihit->
strip_type == 3) stripOffset=9*12;
279 hit->
pulse_height=a_gains[plane_index][strip_index+stripOffset]
280 *double(pulse_peak - scaled_ped);
286 hit->AddAssociatedObject(digihit);
288 _data.push_back(hit);
292 vector<const DFDCWireDigiHit*> wiredigihits;
293 loop->Get(wiredigihits);
294 for(
unsigned int i=0; i<wiredigihits.size(); i++){
331 throw JException(str);
335 throw JException(str);
344 hit->AddAssociatedObject(digihit);
346 _data.push_back(hit);
374 vector< vector<double> > new_gains, new_pedestals, new_strip_t0s, new_wire_t0s;
377 if(eventLoop->GetCalib(ccdb_prefix+
"/strip_gains_v2", new_gains))
378 cout <<
"Error loading "+ccdb_prefix+
"/strip_gains_v2 !" << endl;
379 if(eventLoop->GetCalib(ccdb_prefix+
"/strip_pedestals", new_pedestals))
380 cout <<
"Error loading "+ccdb_prefix+
"/strip_pedestals !" << endl;
381 if(eventLoop->GetCalib(ccdb_prefix+
"/strip_timing_offsets", new_strip_t0s))
382 cout <<
"Error loading "+ccdb_prefix+
"/strip_timing_offsets!" << endl;
383 if(eventLoop->GetCalib(ccdb_prefix+
"/wire_timing_offsets", new_wire_t0s))
384 cout <<
"Error loading "+ccdb_prefix+
"/wire_timing_offsets!" << endl;
386 for(
int nchamber=0; nchamber<6; nchamber++) {
392 sprintf(str,
"Bad # of strips for FDC gain from CCDB! CCDB=%zu , should be %d", new_gains[2*nchamber].
size(),
STRIPS_PER_PLANE+24);
394 throw JException(str);
397 sprintf(str,
"Bad # of strips for FDC gain from CCDB! CCDB=%zu , should be %d", new_gains[2*nchamber+1].
size(),
STRIPS_PER_PLANE+24);
399 throw JException(str);
402 sprintf(str,
"Bad # of strips for FDC pedestals from CCDB! CCDB=%zu , should be %d", new_pedestals[2*nchamber].
size(),
STRIPS_PER_PLANE);
404 throw JException(str);
407 sprintf(str,
"Bad # of strips for FDC pedestals from CCDB! CCDB=%zu , should be %d", new_pedestals[2*nchamber+1].
size(),
STRIPS_PER_PLANE);
409 throw JException(str);
412 sprintf(str,
"Bad # of strips for FDC timing offsets from CCDB! CCDB=%zu , should be %d", new_strip_t0s[2*nchamber].
size(),
STRIPS_PER_PLANE);
414 throw JException(str);
417 sprintf(str,
"Bad # of strips for FDC timing offsets from CCDB! CCDB=%zu , should be %d", new_strip_t0s[2*nchamber+1].
size(),
STRIPS_PER_PLANE);
419 throw JException(str);
422 sprintf(str,
"Bad # of wires for FDC timing offsets from CCDB! CCDB=%zu , should be %d", new_wire_t0s[2*nchamber].
size(),
WIRES_PER_PLANE);
424 throw JException(str);
429 a_gains.push_back( new_gains[2*nchamber] );
430 a_gains.push_back( vector<double>() );
431 a_gains.push_back( new_gains[2*nchamber+1] );
434 a_pedestals.push_back( new_pedestals[2*nchamber] );
436 a_pedestals.push_back( new_pedestals[2*nchamber+1] );
439 timing_offsets.push_back( new_strip_t0s[2*nchamber] );
440 timing_offsets.push_back( new_wire_t0s[nchamber] );
441 timing_offsets.push_back( new_strip_t0s[2*nchamber+1] );
451 const int in_gPlane,
const int in_element)
const {
455 if( (in_gPlane <= 0) || (static_cast<unsigned int>(in_gPlane) >
FDC_NUM_PLANES)) {
456 sprintf(str,
"Bad gPlane # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %ud", in_gPlane,
FDC_NUM_PLANES);
458 throw JException(str);
461 if( (in_element <= 0) || (static_cast<unsigned int>(in_element) > the_table[in_gPlane].
size())) {
462 sprintf(str,
"Bad element # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %zu", in_element, the_table[in_gPlane].
size());
464 throw JException(str);
467 return the_table[in_gPlane-1][in_element-1];
476 int gPlane = in_digihit->
view + 3*(gLayer - 1);
478 if( (gPlane <= 0) || (
static_cast<unsigned int>(gPlane) >
FDC_NUM_PLANES)) {
479 sprintf(str,
"Bad gPlane # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %ud", gPlane,
FDC_NUM_PLANES);
481 throw JException(str);
485 sprintf(str,
"Bad strip # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %ud", in_digihit->
strip,
STRIPS_PER_PLANE);
487 throw JException(str);
490 return the_table[gPlane-1][in_digihit->
strip-1];
499 int gPlane = 2 + 3*(gLayer - 1);
501 if( (gPlane <= 0) || (
static_cast<unsigned int>(gPlane) >
FDC_NUM_PLANES)) {
502 sprintf(str,
"Bad gPlane # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %ud", gPlane,
FDC_NUM_PLANES);
504 throw JException(str);
508 sprintf(str,
"Bad wire # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %ud", in_digihit->
wire,
WIRES_PER_PLANE);
510 throw JException(str);
513 return the_table[gPlane-1][in_digihit->
wire-1];
522 sprintf(str,
"Bad gPlane # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %ud", in_hit->
gPlane,
FDC_NUM_PLANES);
524 throw JException(str);
527 if( (in_hit->
element <= 0) || (static_cast<unsigned int>(in_hit->
element) > the_table[in_hit->
gPlane].size())) {
528 sprintf(str,
"Bad element # requested in DFDCHit_factory::GetConstant()! requested=%d , should be %zu", in_hit->
element, the_table[in_hit->
gPlane].size());
530 throw JException(str);
double Convert_DigiTimeToNs_F1TDC(const JObject *locTDCDigiHit) const
jerror_t init(void)
Called once at program start.
uint32_t pulse_peak
from Pulse Pedestal Data word
sprintf(text,"Post KinFit Cut")
vector< vector< double > > fdc_digi_constants_t
const double GetConstant(const fdc_digi_constants_t &the_table, const int in_gPlane, const int in_element) const
uint32_t pedestal
pedestal info used by FPGA (if any)
uint32_t pulse_number
from Pulse Pedestal Data word
void LoadPackageCalibTables(jana::JEventLoop *eventLoop, string ccdb_prefix)
uint32_t pedestal
from Pulse Pedestal Data word
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
vector< double > a_pedestals
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static float getWireR(const DFDCHit *h)
DFDCGeometry::getWireR(): Return X coordinate of a wire.
class DFDCHit: definition for a basic FDC hit data type.