170 std::vector<art::Handle<artdaq::Fragments>> fragmentHandles =
e.getMany<std::vector<artdaq::Fragment>>();
173 for (
auto &handle : fragmentHandles) {
174 if (!handle.isValid() || handle->size() == 0)
continue;
175 if (handle->front().type()==sbndaq::detail::FragmentType::CAENV1730) {
176 if (
fVerbose)
std::cout <<
"Found " << handle->size() <<
" CAEN1730 fragments" << std::endl;
180 size_t beamFragmentIdx = 9999;
181 for (
size_t fragmentIdx = 0; fragmentIdx < handle->size(); fragmentIdx += 8) {
184 beamFragmentIdx = fragmentIdx;
185 if (
fVerbose)
std::cout <<
"Found fragment in time with beam at index: " << beamFragmentIdx << std::endl;
191 for (
size_t fragmentIdx = beamFragmentIdx; fragmentIdx < beamFragmentIdx+8; fragmentIdx++) {
200 std::unique_ptr<sbnd::trigger::pmtSoftwareTrigger> pmtSoftwareTriggerMetrics = std::make_unique<sbnd::trigger::pmtSoftwareTrigger>();
208 if (
fVerbose)
std::cout <<
"Saving trigger timestamp: " << triggerTimeStamp <<
" ns" << std::endl;
213 int nAboveThreshold = 0;
216 int beamStartBin = (triggerTimeStamp >= 1000)? 0 :
int(500 -
abs((triggerTimeStamp-1000)/2));
220 for (
int i_ch = 0; i_ch < 120; ++i_ch){
232 for (
int bin = beamStartBin;
bin < beamEndBin; ++
bin){
233 auto adc = wvfm[
bin];
239 auto prompt_window = std::vector<uint16_t>(wvfm.begin()+500, wvfm.begin()+1000);
240 auto prelim_window = std::vector<uint16_t>(wvfm.begin()+beamStartBin, wvfm.begin()+500);
242 double ch_promptPE = (baseline-(*std::min_element(prompt_window.begin(), prompt_window.end())))/8;
243 double ch_prelimPE = (baseline-(*std::min_element(prelim_window.begin(), prelim_window.end())))/8;
244 promptPE += ch_promptPE;
245 prelimPE += ch_prelimPE;
251 for (
auto pulse : pmtInfo.pulseVec){
252 if (pulse.t_start > 500 && pulse.t_end < 550) promptPE+=pulse.pe;
253 if ((triggerTimeStamp) >= 1000){
if (pulse.t_end < 500) prelimPE+=pulse.pe; }
254 else if (triggerTimeStamp < 1000){
255 if (pulse.t_start > (500 -
abs((triggerTimeStamp-1000)/2)) && pulse.t_end < 500) prelimPE+=pulse.pe;
262 pmtSoftwareTriggerMetrics->
promptPE = promptPE;
263 pmtSoftwareTriggerMetrics->
prelimPE = prelimPE;
264 if (
fVerbose)
std::cout <<
"nPMTs Above Threshold: " << nAboveThreshold << std::endl;
271 for (
size_t i_wvfm = 0; i_wvfm <
fWvfmsVec.size(); ++i_wvfm){
272 std::vector<uint16_t> wvfm =
fWvfmsVec[i_wvfm];
277 <<
"_channel_" << i_wvfm;
279 double EndTime = StartTime + (5210*2)*1
e-03;
280 TH1D *wvfmHist =
tfs->make< TH1D >(
histname.str().c_str(),
"Raw Waveform", wvfm.size(), StartTime, EndTime);
281 wvfmHist->GetXaxis()->SetTitle(
"t (#mus)");
282 for(
unsigned int i = 0; i < wvfm.size(); i++) {
283 wvfmHist->SetBinContent(i + 1, (
double)wvfm[i]);
294 pmtSoftwareTriggerMetrics->
promptPE = -9999;
295 pmtSoftwareTriggerMetrics->
prelimPE = -9999;
297 e.put(std::move(pmtSoftwareTriggerMetrics));
void estimateBaseline(int i_ch)
void analyzeCAEN1730Fragment(const artdaq::Fragment &frag)
double fInputBaselineSigma
std::vector< unsigned int > channelList
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::vector< sbnd::trigger::pmtInfo > fpmtInfoVec
void SimpleThreshAlgo(int i_ch)
std::vector< std::vector< uint16_t > > fWvfmsVec
std::stringstream histname
std::string fBaselineAlgo
art::EventNumber_t fEvent
BEGIN_PROLOG could also be cout
void checkCAEN1730FragmentTimeStamp(const artdaq::Fragment &frag)
art::ServiceHandle< art::TFileService > tfs