15 #include <Event/Event.h>
16 #include <Event/EventTypes.h>
46 _mbdsig.emplace_back(ifeech, nsamples);
50 _mbdsig[ifeech].SetEventPed0PreSamp(6, 2);
55 for (
int iarm = 0; iarm < 2; iarm++)
60 title =
"bbc times, arm ";
62 hevt_bbct[iarm] =
new TH1F(name.c_str(), title.c_str(), 2000, -50., 50.);
66 h2_tmax[0]->SetXTitle(
"sample");
69 h2_tmax[1]->SetXTitle(
"sample");
78 const char *bbccaldir = getenv(
"BBCCALIB");
157 std::cout <<
"SIMFLAG IS " <<
_simflag << std::endl;
188 std::fill_n(
m_pmttt, 128, 1e12);
189 std::fill_n(
m_pmttq, 128, 1e12);
190 std::fill_n(
m_pmtq, 128, 0.);
193 for (
int iarm = 0; iarm < 2; iarm++)
201 hevt_bbct[iarm]->GetXaxis()->SetRangeUser(-50, 50);
205 m_bbcz = std::numeric_limits<Float_t>::quiet_NaN();
206 m_bbczerr = std::numeric_limits<Float_t>::quiet_NaN();
207 m_bbct0 = std::numeric_limits<Float_t>::quiet_NaN();
208 m_bbct0err = std::numeric_limits<Float_t>::quiet_NaN();
214 if (event ==
nullptr || bbcpmts ==
nullptr)
219 int evt_type =
event->getEvtType();
222 std::cout <<
PHWHERE <<
"MbdEvent: Event type is not DATAEVENT, skipping" << std::endl;
226 m_evt =
event->getEvtSequence();
227 UShort_t xmitclocks[2];
228 UShort_t femclocks[2][2];
234 for (
int ipkt = 0; ipkt < 2; ipkt++)
236 int pktid = 1001 + ipkt;
237 p[ipkt] =
event->getPacket(pktid);
241 static int counter = 0;
244 std::cout <<
"Found packet " << pktid <<
"\t" <<
p[ipkt] << std::endl;
250 xmitclocks[ipkt] =
static_cast<UShort_t
>(
p[ipkt]->
iValue(0,
"CLOCK"));
252 femclocks[ipkt][0] =
static_cast<UShort_t
>(
p[ipkt]->
iValue(0,
"FEMCLOCK"));
253 femclocks[ipkt][1] =
static_cast<UShort_t
>(
p[ipkt]->
iValue(1,
"FEMCLOCK"));
255 for (
int ich = 0; ich <
NCHPERPKT; ich++)
257 int feech = ipkt * NCHPERPKT + ich;
283 std::cout <<
PHWHERE <<
" ERROR, evt " <<
m_evt <<
" Missing Packet " << pktid << std::endl;
289 if (xmitclocks[0] != xmitclocks[1])
291 std::cout << __FILE__ <<
":" << __LINE__ <<
" ERROR, xmitclocks don't agree" << std::endl;
293 for (
auto &femclock : femclocks)
295 for (
unsigned short iadc : femclock)
297 if (iadc != femclocks[0][0])
299 std::cout << __FILE__ <<
":" << __LINE__ <<
" ERROR, femclocks don't agree" << std::endl;
305 m_clk = xmitclocks[0];
323 m_pmttt[pmtch] = 26.5 - tdc * 0.00189;
331 _mbdsig[ifeech].GetSplineAmpl();
332 Double_t threshold = 0.5;
346 m_pmttq[pmtch] = std::numeric_limits<Float_t>::quiet_NaN();
362 m_pmttq[pmtch] = std::numeric_limits<Float_t>::quiet_NaN();
382 bbcpmts->
set_npmt(MbdDefs::BBC_N_PMT);
398 std::cout <<
"In MbdEvent::Calculate() " <<
m_evt << std::endl;
401 if (bbcout !=
nullptr)
416 for (
int iarm = 0; iarm < 2; iarm++)
420 gausfit[iarm] =
new TF1(name,
"gaus", 0, 20);
422 gausfit[iarm]->SetLineColor(2);
426 std::vector<float> hit_times[2];
431 std::cout <<
"Hit PMT info " << std::endl;
436 double tepmt[2]{1e9, 1e9};
437 double tlpmt[2]{-1e9, -1e9};
445 float q_pmt = bbcpmt->
get_q();
449 std::cout << ipmt <<
"\t" << t_pmt << std::endl;
452 if (fabs(t_pmt) < 25. && q_pmt > 0.)
454 hit_times[arm].push_back(t_pmt);
462 std::cout << ipmt <<
"\t" << t_pmt <<
"\t" << q_pmt << std::endl;
464 if (t_pmt < tepmt[arm])
469 if (t_pmt > tlpmt[arm])
480 std::cout <<
"nhits " <<
m_bbcn[0] <<
"\t" <<
m_bbcn[1] << std::endl;
484 for (
int iarm = 0; iarm < 2; iarm++)
486 if (hit_times[iarm].empty())
496 float earliest = hit_times[iarm].at(0);
497 float latest = hit_times[iarm].back();
500 gausfit[iarm]->SetParameter(0, 5);
511 ac =
new TCanvas(
"ac",
"ac", 550 * 1.5, 425 * 1.5);
529 hevt_bbct[iarm]->GetXaxis()->SetRangeUser(tepmt[iarm] - 3., tlpmt[iarm] + 3.);
537 double zearly = (tepmt[0] - tepmt[1]) *
MbdDefs::C / 2.0;
546 std::cout <<
"**ERR** " << znew <<
"\t" <<
mybbz[
_syncevt] << std::endl;
550 std::cout <<
m_evt <<
" gmean " <<
gausfit[0]->GetParameter(1) <<
"\t" <<
gausfit[1]->GetParameter(1) << std::endl;
552 std::cout <<
m_evt <<
" gsigma " <<
gausfit[0]->GetParameter(2) <<
"\t" <<
gausfit[1]->GetParameter(2) << std::endl;
554 std::cout <<
m_evt <<
" te ch " << epmt[0] <<
"\t" << epmt[1] <<
"\t" << tepmt[0] <<
"\t" << tepmt[1] << std::endl;
557 std::cout <<
m_evt <<
" bze " << zearly <<
"\t" << intzediff << std::endl;
571 std::cout <<
"Evt " <<
m_evt <<
"\tt0\t" <<
m_bbct[0] <<
"\t" <<
m_bbct[1] << std::endl;
572 std::cout <<
"bbcn " <<
m_bbcn[0] <<
"\t" <<
m_bbcn[1] << std::endl;
573 std::cout <<
"bbcq " <<
m_bbcq[0] <<
"\t" <<
m_bbcq[1] << std::endl;
598 std::cout <<
"bbcz " <<
m_bbcz << std::endl;
606 if (bbcout !=
nullptr)
608 for (
int iarm = 0; iarm < 2; iarm++)
638 for (
int ifeech = 0; ifeech < 256; ifeech++)
643 int tq = (ifeech / 8) % 2;
644 int pmtch = (ifeech / 16) * 8 + ifeech % 8;
651 if (
h2_tmax[1]->GetEntries() == 128 * 100)
654 TH1 *h_trigsamp[16]{};
655 for (
int iboard = 0; iboard < 16; iboard++)
659 h_trigsamp[iboard] =
h2_tmax[1]->ProjectionX(name, iboard * 8 + 1, (iboard + 1) * 8);
660 int maxbin = h_trigsamp[iboard]->GetMaximumBin();
661 TRIG_SAMP[iboard] = h_trigsamp[iboard]->GetBinCenter(maxbin);
663 std::cout <<
"TRIG_SAMP" << iboard <<
"\t" <<
TRIG_SAMP[iboard] << std::endl;
672 std::ifstream gainfile(gainfname);
674 std::cout <<
"Reading gains from " << gainfname << std::endl;
676 float integ, integerr;
678 float width, widtherr;
680 while (gainfile >> ch >> integ >> peak >> width >> integerr >> peakerr >> widtherr >> chi2ndf)
695 std::ifstream tcalibfile(t0cal_fname);
697 std::cout <<
"Reading tq_t0 offset calibrations from " << t0cal_fname << std::endl;
705 tcalibfile >> pmtnum >>
tq_t0_offsets[ipmt] >> meanerr >> sigma >> sigmaerr;
708 std::cout <<
"ERROR, pmtnum != ipmt, " << pmtnum <<
"\t" << ipmt << std::endl;
720 std::ifstream tcalibfile(t0cal_fname);
722 std::cout <<
"Reading tq_clk offset calibrations from " << t0cal_fname << std::endl;
730 std::cout <<
"ERROR, pmtnum != ipmt, " << pmtnum <<
"\t" << ipmt << std::endl;
742 std::ifstream tcalibfile(t0cal_fname);
744 std::cout <<
"Reading tq_clk offset calibrations from " << t0cal_fname << std::endl;
752 std::cout <<
"ERROR, pmtnum != ipmt, " << pmtnum <<
"\t" << ipmt << std::endl;
764 UShort_t f_femclk{0};
766 Long64_t bco_full{0};
767 Double_t ES_zvtx{0.};
772 _syncttree->SetBranchAddress(
"evt", &f_evt);
773 _syncttree->SetBranchAddress(
"femclk", &f_femclk);
774 _syncttree->SetBranchAddress(
"bz", &f_bz);
775 _syncttree->SetBranchAddress(
"bco_full", &bco_full);
776 _syncttree->SetBranchAddress(
"ES_zvtx", &ES_zvtx);
777 _syncttree->SetBranchAddress(
"mbd_bz", &mbd_bz);
779 Stat_t nentries = _syncttree->GetEntries();
780 for (
int ientry = 0; ientry < nentries; ientry++)
782 _syncttree->GetEntry(ientry);
784 bbevt.push_back(f_evt);
785 bbclk.push_back(f_femclk);
786 mybbz.push_back(f_bz);
787 bco.push_back(bco_full);
788 intz.push_back(ES_zvtx);
789 bbz.push_back(mbd_bz);
792 std::cout <<
"Read in " <<
bbevt.size() <<
" INTT sync events" << std::endl;