34 "Remove CDC Hits with peak amplitudes smaller than CDC_HIT_THRESHOLD");
46 a_scale = 4.0E3/1.0E2;
47 amp_a_scale = a_scale*28.8;
60 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
61 static set<int> runs_announced;
62 pthread_mutex_lock(&print_mutex);
63 bool print_messages =
false;
64 if(runs_announced.find(runnumber) == runs_announced.end()){
65 print_messages =
true;
66 runs_announced.insert(runnumber);
68 pthread_mutex_unlock(&print_mutex);
71 CalcNstraws(eventLoop, runnumber, Nstraws);
72 Nrings = Nstraws.size();
74 vector<double> raw_gains;
75 vector<double> raw_pedestals;
76 vector<double> raw_time_offsets;
78 if(print_messages) jout <<
"In DCDCHit_factory, loading constants..." << std::endl;
81 map<string,double> scale_factors;
82 if (eventLoop->GetCalib(
"/CDC/digi_scales", scale_factors))
83 jout <<
"Error loading /CDC/digi_scales !" << endl;
84 if (scale_factors.find(
"CDC_ADC_ASCALE") != scale_factors.end())
85 a_scale = scale_factors[
"CDC_ADC_ASCALE"];
87 jerr <<
"Unable to get CDC_ADC_ASCALE from /CDC/digi_scales !" << endl;
88 amp_a_scale=a_scale*28.8;
90 #ifdef ENABLE_UPSAMPLING
93 if (scale_factors.find(
"CDC_ADC_TSCALE") != scale_factors.end())
94 t_scale = scale_factors[
"CDC_ADC_TSCALE"];
96 jerr <<
"Unable to get CDC_ADC_TSCALE from /CDC/digi_scales !" << endl;
100 map<string,double> base_time_offset;
101 if (eventLoop->GetCalib(
"/CDC/base_time_offset",base_time_offset))
102 jout <<
"Error loading /CDC/base_time_offset !" << endl;
103 if (base_time_offset.find(
"CDC_BASE_TIME_OFFSET") != base_time_offset.end())
104 t_base = base_time_offset[
"CDC_BASE_TIME_OFFSET"];
106 jerr <<
"Unable to get CDC_BASE_TIME_OFFSET from /CDC/base_time_offset !" << endl;
109 if (eventLoop->GetCalib(
"/CDC/wire_gains", raw_gains))
110 jout <<
"Error loading /CDC/wire_gains !" << endl;
111 if (eventLoop->GetCalib(
"/CDC/pedestals", raw_pedestals))
112 jout <<
"Error loading /CDC/pedestals !" << endl;
113 if (eventLoop->GetCalib(
"/CDC/timing_offsets", raw_time_offsets))
114 jout <<
"Error loading /CDC/timing_offsets !" << endl;
117 FillCalibTable(gains, raw_gains, Nstraws);
118 FillCalibTable(pedestals, raw_pedestals, Nstraws);
119 FillCalibTable(time_offsets, raw_time_offsets, Nstraws);
123 if (gains.size() != Nrings) {
124 sprintf(str,
"Bad # of rings for CDC gain from CCDB! CCDB=%zu , should be %d", gains.size(), Nrings);
125 std::cerr << str << std::endl;
126 throw JException(str);
128 if (pedestals.size() != Nrings) {
129 sprintf(str,
"Bad # of rings for CDC pedestal from CCDB! CCDB=%zu , should be %d", pedestals.size(), Nrings);
130 std::cerr << str << std::endl;
131 throw JException(str);
133 if (time_offsets.size() != Nrings) {
134 sprintf(str,
"Bad # of rings for CDC time_offset from CCDB!"
135 " CCDB=%zu , should be %d", time_offsets.size(), Nrings);
136 std::cerr << str << std::endl;
137 throw JException(str);
141 for (
unsigned int i=0; i < Nrings; i++) {
142 if (gains[i].
size() != Nstraws[i]) {
143 sprintf(str,
"Bad # of straws for CDC gain from CCDB!"
144 " CCDB=%zu , should be %d for ring %d",
145 gains[i].
size(), Nstraws[i], i+1);
146 std::cerr << str << std::endl;
147 throw JException(str);
149 if (pedestals[i].
size() != Nstraws[i]) {
150 sprintf(str,
"Bad # of straws for CDC pedestal from CCDB!"
151 " CCDB=%zu , should be %d for ring %d",
152 pedestals[i].
size(), Nstraws[i], i+1);
153 std::cerr << str << std::endl;
154 throw JException(str);
156 if (time_offsets[i].
size() != Nstraws[i]) {
157 sprintf(str,
"Bad # of straws for CDC time_offset from CCDB!"
158 " CCDB=%zu , should be %d for ring %d",
159 time_offsets[i].
size(), Nstraws[i], i+1);
160 std::cerr << str << std::endl;
161 throw JException(str);
184 vector<const DCDCDigiHit*> digihits;
187 for (
unsigned int i=0; i < digihits.size(); i++) {
192 const int &ring = digihit->
ring;
193 const int &straw = digihit->
straw;
196 if ( (ring < 1) || (ring > (int)Nrings)) {
197 sprintf(str,
"DCDCDigiHit ring out of range!"
198 " ring=%d (should be 1-%d)", ring, Nrings);
199 throw JException(str);
201 if ( (straw < 1) || (straw > (
int)Nstraws[ring-1])) {
202 sprintf(str,
"DCDCDigiHit straw out of range!"
203 " straw=%d for ring=%d (should be 1-%d)",
204 straw, ring, Nstraws[ring-1]);
205 throw JException(str);
211 int nsamples_integral = 0;
221 digihit->GetSingle(PPobj);
222 if( PPobj != NULL ) {
241 digihit->GetSingle(PIobj);
242 if (PPobj == NULL || PIobj == NULL)
continue;
249 vector<const Df125Config*> configs;
250 digihit->Get(configs);
251 if( configs.empty() ){
252 static int Nwarnings = 0;
254 _DBG_ <<
"NO Df125Config object associated with Df125CDCPulse object!" << endl;
256 if(Nwarnings==10)
_DBG_ <<
" --- LAST WARNING!! ---" << endl;
261 IBIT = config->
IBIT == 0xffff ? 4 : config->
IBIT;
262 ABIT = config->
ABIT == 0xffff ? 3 : config->
ABIT;
263 PBIT = config->
PBIT == 0xffff ? 0 : config->
PBIT;
264 NW = config->
NW == 0xffff ? 180 : config->
NW;
272 nsamples_integral = (NW - (digihit->
pulse_time / 10));
276 int scaled_ped = raw_ped << PBIT;
278 if (maxamp > 0) maxamp = maxamp << ABIT;
281 maxamp = maxamp - scaled_ped;
291 double gain=gains[ring-1][straw-1];
295 - scaled_ped*nsamples_integral);
296 double amp = amp_a_scale*gain*double(maxamp);
298 double t =
t_scale * t_raw - time_offsets[ring-1][straw-1] +
t_base;
310 hit->
QF = digihit->
QF;
314 hit->AddAssociatedObject(digihit);
316 _data.push_back(hit);
345 vector<vector<DCDCWire *> >cdcwires;
358 for (
unsigned int i=0; i<cdcwires.size(); i++) {
359 Nstraws.push_back( cdcwires[i].
size() );
360 maxChannels += cdcwires[i].size();
364 for (
unsigned int i=0; i<cdcwires.size(); i++) {
365 for (
unsigned int j=0; j<cdcwires[i].size(); j++) {
366 delete cdcwires[i][j];
377 vector<unsigned int> &Nstraws)
384 table.resize( Nstraws.size() );
386 for (
unsigned int channel=0; channel<raw_table.size(); channel++,straw++) {
388 if (channel == maxChannels)
break;
391 if (straw == (
int)Nstraws[ring]) {
396 table[ring].push_back( raw_table[channel] );
407 const int in_ring,
const int in_straw)
const {
411 if ( (in_ring <= 0) || (static_cast<unsigned int>(in_ring) > Nrings)) {
412 sprintf(str,
"Bad ring # requested in DCDCHit_factory::GetConstant()!"
413 " requested=%d , should be %ud", in_ring, Nrings);
414 std::cerr << str << std::endl;
415 throw JException(str);
417 if ( (in_straw <= 0) ||
418 (static_cast<unsigned int>(in_straw) > Nstraws[in_ring]))
420 sprintf(str,
"Bad straw # requested in DCDCHit_factory::GetConstant()!"
421 " requested=%d , should be %ud", in_straw, Nstraws[in_ring]);
422 std::cerr << str << std::endl;
423 throw JException(str);
426 return the_table[in_ring-1][in_straw-1];
434 if ( (in_digihit->
ring <= 0) ||
435 (static_cast<unsigned int>(in_digihit->
ring) > Nrings))
437 sprintf(str,
"Bad ring # requested in DCDCHit_factory::GetConstant()!"
438 " requested=%d , should be %ud", in_digihit->
ring, Nrings);
439 std::cerr << str << std::endl;
440 throw JException(str);
442 if ( (in_digihit->
straw <= 0) ||
443 (static_cast<unsigned int>(in_digihit->
straw) > Nstraws[in_digihit->
ring]))
445 sprintf(str,
"Bad straw # requested in DCDCHit_factory::GetConstant()!"
446 " requested=%d , should be %ud",
447 in_digihit->
straw, Nstraws[in_digihit->
ring]);
448 std::cerr << str << std::endl;
449 throw JException(str);
452 return the_table[in_digihit->
ring-1][in_digihit->
straw-1];
460 if ( (in_hit->
ring <= 0) || (static_cast<unsigned int>(in_hit->
ring) > Nrings)) {
461 sprintf(str,
"Bad ring # requested in DCDCHit_factory::GetConstant()!"
462 " requested=%d , should be %ud", in_hit->
ring, Nrings);
463 std::cerr << str << std::endl;
464 throw JException(str);
466 if ( (in_hit->
straw <= 0) ||
467 (static_cast<unsigned int>(in_hit->
straw) > Nstraws[in_hit->
ring])) {
468 sprintf(str,
"Bad straw # requested in DCDCHit_factory::GetConstant()!"
469 " requested=%d , should be %ud",
471 std::cerr << str << std::endl;
472 throw JException(str);
475 return the_table[in_hit->
ring-1][in_hit->
straw-1];
jerror_t init(void)
Called once at program start.
uint32_t pulse_peak
from Pulse Pedestal Data word
sprintf(text,"Post KinFit Cut")
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
bool GetCDCWires(vector< vector< DCDCWire * > > &cdcwires) const
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
void FillCalibTable(vector< vector< double > > &table, vector< double > &raw_table, vector< unsigned int > &Nstraws)
vector< vector< double > > cdc_digi_constants_t
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
DGeometry * GetDGeometry(unsigned int run_number)
uint32_t pulse_number
from Pulse Pedestal Data word
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
const double GetConstant(const cdc_digi_constants_t &the_table, const int in_ring, const int in_straw) const
uint32_t pedestal
from Pulse Pedestal Data word
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
void CalcNstraws(jana::JEventLoop *eventLoop, int32_t runnumber, vector< unsigned int > &Nstraws)
uint32_t QF
Quality Factor from FPGA algorithms.
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t pedestal
pedestal info used by FPGA (if any)
uint32_t pulse_peak
identified pulse first peak as returned by FPGA algorithm (could be either Df125CDCPulse::first_max_a...