32 gPARMS->SetDefaultParameter(
"CCAL:HIT_DEBUG", HIT_DEBUG);
33 gPARMS->SetDefaultParameter(
"CCAL:DB_PEDESTAL", DB_PEDESTAL);
55 pedestals = pedestals_tmp;
56 time_offsets = time_offsets_tmp;
57 adc_offsets = adc_offsets_tmp;
76 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
77 static set<int> runs_announced;
78 pthread_mutex_lock(&print_mutex);
80 if(runs_announced.find(runnumber) == runs_announced.end()){
82 runs_announced.insert(runnumber);
84 pthread_mutex_unlock(&print_mutex);
87 vector<const DCCALGeometry*> ccalGeomVect;
88 eventLoop->Get( ccalGeomVect );
89 if (ccalGeomVect.size() < 1)
90 return OBJECT_NOT_AVAILABLE;
94 vector< double > ccal_gains_ch;
95 vector< double > ccal_pedestals_ch;
96 vector< double > time_offsets_ch;
97 vector< double > adc_offsets_ch;
100 map<string,double> scale_factors;
102 if (eventLoop->GetCalib(
"/CCAL/digi_scales", scale_factors))
103 jout <<
"Error loading /CCAL/digi_scales !" << endl;
104 if (scale_factors.find(
"ADC_EN_SCALE") != scale_factors.end())
105 adc_en_scale = scale_factors[
"ADC_EN_SCALE"];
107 jerr <<
"Unable to get ADC_EN_SCALE from /CCAL/digi_scales !" << endl;
108 if (scale_factors.find(
"ADC_TIME_SCALE") != scale_factors.end())
109 adc_time_scale = scale_factors[
"ADC_TIME_SCALE"];
111 jerr <<
"Unable to get ADC_TIME_SCALE from /CCAL/digi_scales !" << endl;
113 map<string,double> base_time_offset;
114 if (eventLoop->GetCalib(
"/CCAL/base_time_offset",base_time_offset))
115 jout <<
"Error loading /CCAL/base_time_offset !" << endl;
116 if (base_time_offset.find(
"BASE_TIME") != base_time_offset.end())
117 base_time = base_time_offset[
"BASE_TIME"];
119 jerr <<
"Unable to get BASE_TIME from /CCAL/base_time_offset !" << endl;
122 if (eventLoop->GetCalib(
"/CCAL/gains", ccal_gains_ch))
123 jout <<
"DCCALHit_factory: Error loading /CCAL/gains !" << endl;
124 if (eventLoop->GetCalib(
"/CCAL/pedestals", ccal_pedestals_ch))
125 jout <<
"DCCALHit_factory: Error loading /CCAL/pedestals !" << endl;
127 if (eventLoop->GetCalib(
"/CCAL/timing_offsets", time_offsets_ch))
128 jout <<
"Error loading /CCAL/timing_offsets !" << endl;
129 if (eventLoop->GetCalib(
"/CCAL/adc_offsets", adc_offsets_ch))
130 jout <<
"Error loading /CCAL/adc_offsets !" << endl;
133 LoadCCALConst(gains, ccal_gains_ch, ccalGeom);
134 LoadCCALConst(pedestals, ccal_pedestals_ch, ccalGeom);
135 LoadCCALConst(time_offsets, time_offsets_ch, ccalGeom);
136 LoadCCALConst(adc_offsets, adc_offsets_ch, ccalGeom);
143 cout <<
" ------- Gains -----------" << endl;
145 for(
int ii = 0; ii < 12; ii++){
146 for(
int jj = 0; jj < 12; jj++){
147 cout <<
" " << gains[ii][jj];
153 cout <<
" ------- Pedestals -----------" << endl;
155 for(
int ii = 0; ii < 12; ii++){
156 for(
int jj = 0; jj < 12; jj++){
157 cout <<
" " << pedestals[ii][jj];
163 cout <<
" ------- Timing offsets -----------" << endl;
165 for(
int ii = 0; ii < 12; ii++){
166 for(
int jj = 0; jj < 12; jj++){
167 cout <<
" " << time_offsets[ii][jj];
173 cout <<
" ------- ADC offsets -----------" << endl;
175 for(
int ii = 0; ii < 12; ii++){
176 for(
int jj = 0; jj < 12; jj++){
177 cout <<
" " << adc_offsets[ii][jj];
183 cout <<
"ADC_EN_SCALE = " << adc_en_scale << endl;
184 cout <<
"ADC_TIME_SCALE = " << adc_time_scale << endl;
188 cout <<
"BASE_TIME_OFFSET = " << base_time << endl;
213 vector<const DCCALGeometry*> ccalGeomVect;
214 eventLoop->Get( ccalGeomVect );
215 if (ccalGeomVect.size() < 1)
216 return OBJECT_NOT_AVAILABLE;
220 vector<const DCCALDigiHit*> digihits;
224 for (
unsigned int i = 0; i < digihits.size(); i++) {
238 pedestal = pedestals[digihit->
row][digihit->
column];
240 pedestal = (double)digihit->
pedestal/nsamples_pedestal;
244 double integratedPedestal = pedestal * nsamples_integral;
248 double pulse_time = (
double)digihit->
pulse_time;
252 cout <<
"Row = " << digihit->
row <<
"Column = " << digihit->
column <<
253 " pulse_int = " << pulse_int <<
" integratedPedestal = " << integratedPedestal <<
254 " Pedestal = " << pedestal << endl;
256 double pulse_int_ped_subt = adc_en_scale * gains[digihit->
row][digihit->
column] * (pulse_int - integratedPedestal);
257 double pulse_time_correct = adc_time_scale * pulse_time + base_time - time_offsets[digihit->
row][digihit->
column] +
258 adc_offsets[digihit->
row][digihit->
column];
261 if(pulse_int_ped_subt > 0 && pulse_time > 0){
269 hit->
E = pulse_int_ped_subt;
270 hit->
t = pulse_time_correct;
278 if(pulse_amplitude > 0){
279 hit->
intOverPeak = (pulse_int - integratedPedestal)/pulse_amplitude;
283 hit->AddAssociatedObject(digihit);
284 _data.push_back(hit);
322 for (
int ch = 0; ch < static_cast<int>(ccal_const_ch.size()); ch++) {
328 int row = ccalGeom.
row(ch);
329 int col = ccalGeom.
column(ch);
335 sprintf(str,
"DCCALHit: Loading CCAL constant for inactive channel! "
336 "row=%d, col=%d", row, col);
337 throw JException(str);
340 table[row][col] = ccal_const_ch[ch];
DVector2 positionOnFace(int row, int column) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
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
sprintf(text,"Post KinFit Cut")
void LoadCCALConst(ccal_constants_t &table, const vector< double > &ccal_const_ch, const DCCALGeometry &ccalGeom)
static const int kCCALBlocksWide
uint32_t pedestal
pedestal info used by FPGA (if any)
int column(int channel) const
jerror_t init(void)
Called once at program start.2.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
vector< vector< double > > ccal_constants_t
static const int kCCALBlocksTall
uint32_t nsamples_integral
number of samples used in integral
uint32_t nsamples_pedestal
number of samples used in pedestal
static TH1I * pedestal[nChan]
uint32_t pulse_peak
maximum sample in pulse
int row(int channel) const
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
bool isBlockActive(int row, int column) const
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
int numActiveBlocks() const