24 _mbdgeom = std::make_unique<MbdGeomV1>();
38 std::cout <<
PHWHERE << std::endl;
53 std::cout <<
"sampmax_url " << sampmax_url << std::endl;
60 std::cout <<
"qfit_url " << qfit_url << std::endl;
73 std::cout <<
"tq_t0_url " << tq_t0_url << std::endl;
88 std::cout <<
"shape_url " << shape_url << std::endl;
97 std::cout <<
"Reading MBD Calibrations from " << bbc_caldir << std::endl;
99 std::string sampmax_file = bbc_caldir +
"/bbc_sampmax.calib";
102 std::string qfit_file = bbc_caldir +
"/bbc_qfit.calib";
108 std::string tq_t0_file = bbc_caldir +
"/bbc_tq_t0.calib";
116 std::string shape_file = bbc_caldir +
"/bbc_shape.calib";
127 _qfit_integ.fill(std::numeric_limits<float>::quiet_NaN());
128 _qfit_mpv.fill(std::numeric_limits<float>::quiet_NaN());
129 _qfit_sigma.fill(std::numeric_limits<float>::quiet_NaN());
131 _qfit_mpverr.fill(std::numeric_limits<float>::quiet_NaN());
137 std::cout <<
"Opening " << dbase_location << std::endl;
140 if (dbase_file.extension() ==
".root")
158 std::cout << ipmt <<
"\t" <<
_qfit_mpv[ipmt] << std::endl;
164 else if (dbase_file.extension() ==
".calib")
166 std::ifstream
infile(dbase_location);
167 if (!infile.is_open())
169 std::cout <<
PHWHERE <<
"unable to open " << dbase_location << std::endl;
175 while (infile >> pmt)
184 <<
"\t" << _qfit_chi2ndf[pmt] << std::endl;
191 std::cout <<
PHWHERE <<
", ERROR, unknown file type, " << dbase_location << std::endl;
209 std::cout <<
"Opening " << dbase_location << std::endl;
212 if (dbase_file.extension() ==
".root")
225 if (ipmt < 5 || ipmt >= MbdDefs::MBD_N_PMT - 5)
227 std::cout << ipmt <<
"\t" <<
_tqfit_t0mean[ipmt] << std::endl;
233 else if (dbase_file.extension() ==
".calib")
235 std::ifstream
infile(dbase_location);
236 if (!infile.is_open())
238 std::cout <<
PHWHERE <<
"unable to open " << dbase_location << std::endl;
244 while (infile >> pmt)
253 <<
"\t" <<
_tqfit_t0sigma[pmt] <<
"\t" << _tqfit_t0sigmaerr[pmt] << std::endl;
261 std::cout <<
PHWHERE <<
", ERROR, unknown file type, " << dbase_location << std::endl;
279 std::cout <<
"Opening " << dbase_location << std::endl;
282 if (dbase_file.extension() ==
".root")
295 if (ipmt < 5 || ipmt >= MbdDefs::MBD_N_PMT - 5)
297 std::cout << ipmt <<
"\t" <<
_ttfit_t0mean[ipmt] << std::endl;
303 else if (dbase_file.extension() ==
".calib")
305 std::ifstream
infile(dbase_location);
306 if (!infile.is_open())
308 std::cout <<
PHWHERE <<
"unable to open " << dbase_location << std::endl;
314 while (infile >> pmt)
323 <<
"\t" <<
_ttfit_t0sigma[pmt] <<
"\t" << _ttfit_t0sigmaerr[pmt] << std::endl;
331 std::cout <<
PHWHERE <<
", ERROR, unknown file type, " << dbase_location << std::endl;
345 if (dbase_file.extension() ==
".root")
355 if (ifeech < 5 || ifeech >= MbdDefs::MBD_N_FEECH - 5)
357 std::cout << ifeech <<
"\t" <<
_sampmax[ifeech] << std::endl;
363 else if (dbase_file.extension() ==
".calib")
365 std::ifstream
infile(dbase_location);
366 if (!infile.is_open())
368 std::cout <<
PHWHERE <<
"unable to open " << dbase_location << std::endl;
374 while (infile >> feech)
381 std::cout << feech <<
"\t" << _sampmax[
feech] << std::endl;
389 std::cout <<
PHWHERE <<
", ERROR, unknown file type, " << dbase_location << std::endl;
402 std::cout <<
"In MbdCalib::Download_Slew" << std::endl;
411 if (dbase_file.extension() ==
".root")
415 std::cout <<
"Reading from CDB " << dbase_location << std::endl;
422 if (
_mbdgeom->get_type(ifeech) == 0)
435 for (
int ipt = 0; ipt <
_slew_npts[ifeech]; ipt++)
437 int chtemp = 1000 * ipt + ifeech;
440 _slew_y[ifeech].push_back(val);
448 if (ifeech < 5 || ifeech >= MbdDefs::MBD_N_FEECH - 5)
450 std::cout << ifeech <<
"\t" << _slew_y[ifeech][0] << std::endl;
456 else if (dbase_file.extension() ==
".calib")
460 std::cout <<
"Reading from " << dbase_location << std::endl;
462 std::ifstream
infile(dbase_location);
463 if (!infile.is_open())
465 std::cout <<
PHWHERE <<
"unable to open " << dbase_location << std::endl;
471 int temp_npoints = -1;
472 float temp_begintime = -1;
473 float temp_endtime = -1;
474 while (infile >> temp_feech >> temp_npoints >> temp_begintime >> temp_endtime)
478 std::cout <<
"slew " << temp_feech <<
"\t" << temp_npoints <<
"\t" << temp_begintime <<
"\t" << temp_endtime << std::endl;
480 if (temp_feech < 0 || temp_feech > 255)
482 std::cout <<
"ERROR, invalid FEECH " << temp_feech <<
" in MBD waveforms calibration" << std::endl;
492 for (
int isamp = 0; isamp < temp_npoints; isamp++)
495 _slew_y[temp_feech].push_back(temp_val);
496 if (
Verbosity() && (temp_feech == 8 || temp_feech == 255))
498 std::cout << _slew_y[temp_feech][isamp] <<
" ";
501 std::cout << std::endl;
507 std::cout << std::endl;
515 std::cout <<
PHWHERE <<
", ERROR, unknown file type, " << dbase_location << std::endl;
529 std::cout <<
"In MbdCalib::Download_Shapes" << std::endl;
542 if (dbase_file.extension() ==
".root")
546 std::cout <<
"Reading from CDB " << dbase_location << std::endl;
553 if (
_mbdgeom->get_type(ifeech) == 0)
566 for (
int ipt = 0; ipt <
_shape_npts[ifeech]; ipt++)
568 int chtemp = 1000 * ipt + ifeech;
571 _shape_y[ifeech].push_back(val);
574 _sherr_yerr[ifeech].push_back(val);
579 if (ifeech < 5 || ifeech >= MbdDefs::MBD_N_FEECH - 5)
581 std::cout << ifeech <<
"\t" << _shape_y[ifeech][0] << std::endl;
587 else if (dbase_file.extension() ==
".calib")
591 std::cout <<
"Reading from " << dbase_location << std::endl;
593 std::ifstream
infile(dbase_location);
594 if (!infile.is_open())
596 std::cout <<
PHWHERE <<
"unable to open " << dbase_location << std::endl;
602 int temp_npoints = -1;
603 float temp_begintime = -1;
604 float temp_endtime = -1;
605 while (infile >> temp_feech >> temp_npoints >> temp_begintime >> temp_endtime)
609 std::cout <<
"shape " << temp_feech <<
"\t" << temp_npoints <<
"\t" << temp_begintime <<
"\t" << temp_endtime << std::endl;
611 if (temp_feech < 0 || temp_feech > 255)
613 std::cout <<
"ERROR, invalid FEECH " << temp_feech <<
" in MBD waveforms calibration" << std::endl;
623 for (
int isamp = 0; isamp < temp_npoints; isamp++)
626 _shape_y[temp_feech].push_back(temp_val);
627 if (
Verbosity() && (temp_feech == 8 || temp_feech == 255))
629 std::cout << _shape_y[temp_feech][isamp] <<
" ";
632 std::cout << std::endl;
638 std::cout << std::endl;
645 std::string sherr_dbase_location = std::regex_replace(dbase_location, std::regex(
"bbc_shape.calib"),
"bbc_sherr.calib");
648 std::cout <<
"Reading from " << sherr_dbase_location << std::endl;
650 infile.open(sherr_dbase_location);
651 if (!infile.is_open())
653 std::cout <<
PHWHERE <<
"unable to open " << sherr_dbase_location << std::endl;
662 while (infile >> temp_feech >> temp_npoints >> temp_begintime >> temp_endtime)
666 std::cout <<
"sheer " << temp_feech <<
"\t" << temp_npoints <<
"\t" << temp_begintime <<
"\t" << temp_endtime << std::endl;
668 if (temp_feech < 0 || temp_feech > 255)
670 std::cout <<
"ERROR, invalid FEECH " << temp_feech <<
" in MBD waveforms calibration" << std::endl;
680 for (
int isamp = 0; isamp < temp_npoints; isamp++)
683 _sherr_yerr[temp_feech].push_back(temp_val);
684 if (
Verbosity() && (temp_feech == 8 || temp_feech == 255))
686 std::cout << _sherr_yerr[temp_feech][isamp] <<
" ";
689 std::cout << std::endl;
695 std::cout << std::endl;
703 std::cout <<
PHWHERE <<
", ERROR, unknown file type, " << dbase_location << std::endl;
716 std::cout <<
"Creating " << dbfile << std::endl;
718 cdbttree->SetSingleIntValue(
"version", 1);
719 cdbttree->CommitSingle();
721 std::cout <<
"SAMPMAX" << std::endl;
722 for (
size_t ifeech = 0; ifeech <
_sampmax.size(); ifeech++)
725 cdbttree->SetIntValue(ifeech,
"sampmax",
_sampmax[ifeech]);
729 std::cout << ifeech <<
"\t" << cdbttree->GetIntValue(ifeech,
"sampmax") << std::endl;
737 cdbttree->WriteCDBTTree();
745 std::ofstream cal_file;
746 cal_file.open(dbfile);
749 cal_file << ipmt <<
"\t" <<
_sampmax[ipmt] << std::endl;
758 std::ofstream cal_t0_file;
759 cal_t0_file.open(dbfile);
775 std::cout <<
"Creating " << dbfile << std::endl;
777 cdbttree->SetSingleIntValue(
"version", 1);
778 cdbttree->CommitSingle();
780 std::cout <<
"SHAPES" << std::endl;
781 for (
unsigned int ifeech = 0; ifeech <
_sampmax.size(); ifeech++)
783 if (
_mbdgeom->get_type(ifeech) == 0)
788 cdbttree->SetIntValue(ifeech,
"shape_npts",
_shape_npts[ifeech]);
792 for (
int ipt = 0; ipt <
_shape_npts[ifeech]; ipt++)
794 int temp_ch = ipt * 1000 + ifeech;
795 cdbttree->SetFloatValue(temp_ch,
"shape_val",
_shape_y[ifeech][ipt]);
798 cdbttree->SetIntValue(ifeech,
"sherr_npts",
_sherr_npts[ifeech]);
802 for (
int ipt = 0; ipt < _shape_npts[ifeech]; ipt++)
804 int temp_ch = ipt * 1000 + ifeech;
805 cdbttree->SetFloatValue(temp_ch,
"sherr_val",
_sherr_yerr[ifeech][ipt]);
812 for (
unsigned int ifeech = 0; ifeech <
_sampmax.size(); ifeech++)
814 if (
_mbdgeom->get_type(ifeech) == 0)
821 std::cout << ifeech <<
"\t" << cdbttree->GetIntValue(ifeech,
"shape_npts") << std::endl;
822 for (
int ipt = 0; ipt < 10; ipt++)
824 int temp_ch = ipt * 1000 + ifeech;
825 std::cout << cdbttree->GetFloatValue(temp_ch,
"shape_val") <<
" ";
827 std::cout << std::endl;
832 cdbttree->WriteCDBTTree();
846 _qfit_integ.fill(std::numeric_limits<float>::quiet_NaN());
847 _qfit_mpv.fill(std::numeric_limits<float>::quiet_NaN());
848 _qfit_sigma.fill(std::numeric_limits<float>::quiet_NaN());
850 _qfit_mpverr.fill(std::numeric_limits<float>::quiet_NaN());