4949#include < bitset>
5050#include < memory>
5151
52+ #include " sbndcode/OpDetSim/TriggerEmulationService.h"
53+
5254namespace sbndaq {
5355 class SBNDPMTDecoder ;
5456}
@@ -123,6 +125,8 @@ class sbndaq::SBNDPMTDecoder : public art::EDProducer {
123125
124126 std::vector<uint> fch_map;
125127
128+ int fmon_threshold;
129+
126130 // histogram info
127131 std::stringstream histname; // raw waveform hist name
128132 art::ServiceHandle<art::TFileService> tfs;
@@ -177,6 +181,8 @@ sbndaq::SBNDPMTDecoder::SBNDPMTDecoder(fhicl::ParameterSet const& p)
177181
178182 fch_map = p.get <std::vector<uint>>(" ch_map" ,{});
179183
184+ fmon_threshold = p.get <int >(" mon_threshold" , 15 );
185+
180186 produces< std::vector< raw::OpDetWaveform > >(fpmt_instance_name);
181187 produces< std::vector< raw::OpDetWaveform > >(fflt_instance_name);
182188 produces< std::vector< raw::OpDetWaveform > >(ftim_instance_name);
@@ -186,6 +192,9 @@ sbndaq::SBNDPMTDecoder::SBNDPMTDecoder(fhicl::ParameterSet const& p)
186192 produces< art::Assns< raw::pmt::BoardTimingInfo, raw::OpDetWaveform > >(fpmt_timing_instance_name);
187193 produces< art::Assns< raw::pmt::BoardTimingInfo, raw::OpDetWaveform > >(fflt_timing_instance_name);
188194 produces< art::Assns< raw::pmt::BoardTimingInfo, raw::OpDetWaveform > >(ftim_timing_instance_name);
195+
196+ produces< std::vector<int > >(" MonPulses" );
197+ produces< std::vector<int > >(" MonPulseSizes" );
189198}
190199
191200void sbndaq::SBNDPMTDecoder::produce (art::Event& evt)
@@ -264,6 +273,11 @@ void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
264273 evt.put (std::move (pmtTimingAssns),fpmt_timing_instance_name);
265274 evt.put (std::move (fltTimingAssns),fflt_timing_instance_name);
266275 evt.put (std::move (timTimingAssns),ftim_timing_instance_name);
276+
277+ auto flatPtr = std::make_unique<std::vector<int >>();
278+ auto sizesPtr = std::make_unique<std::vector<int >>();
279+ evt.put (std::move (flatPtr), " MonPulses" );
280+ evt.put (std::move (sizesPtr), " MonPulseSizes" );
267281 return ;
268282 }
269283
@@ -597,6 +611,43 @@ void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
597611 }
598612 }
599613 } // end board loop
614+
615+ // loop through flashes
616+ art::ServiceHandle<art::TFileService> tfs;
617+ art::ServiceHandle<calib::TriggerEmulationService> fTriggerService ;
618+ int PMTPerBoard = fTriggerService ->getPMTPerBoard ();
619+ // int fTotalCAENBoards = fTriggerService->getTotalCAENBoards();
620+ // std::vector< std::vector<int> > MonPulsesAll;
621+ // MonPulseAll.clear();
622+ std::vector<int > MonPulsesFlat;
623+ std::vector<int > pulseSizes;
624+ MonPulsesFlat.clear ();
625+ pulseSizes.clear ();
626+ int TotalFlash = pmtwvfmVec->size ()/((int )fn_caenboards*PMTPerBoard); // pmtwvfmVec = waveHandle ???
627+ for (int FlashCounter=0 ; FlashCounter<TotalFlash; FlashCounter++)
628+ {
629+ int WaveIndex = FlashCounter*PMTPerBoard;
630+ int WaveformSize = (*pmtwvfmVec)[WaveIndex].size ();
631+ std::vector<int > *MonPulse = new std::vector<int >(WaveformSize);
632+ fTriggerService ->ConstructMonPulse (*pmtwvfmVec, fmon_threshold, MonPulse, FlashCounter);
633+ // MonPulsesAll.push_back(std::move(MonPulse));
634+ MonPulsesFlat.insert (MonPulsesFlat.end (), (*MonPulse).begin (), (*MonPulse).end ());
635+ pulseSizes.push_back (MonPulse->size ());
636+ delete MonPulse;
637+ }
638+ // make ptrs
639+ auto flatPtr = std::make_unique<std::vector<int >>(std::move (MonPulsesFlat));
640+ auto sizesPtr = std::make_unique<std::vector<int >>(std::move (pulseSizes));
641+
642+ /* std::unique_ptr< std::vector< std::vector<int> > > MonPulsesPtr(std::make_unique< std::vector< std::vector<int> > > ());
643+ for (auto &pulse : MonPulsesAll) {
644+ MonPulsesPtr->reserve(MonPulsesPtr->size() + pulse.size());
645+ std::move(pulse.begin(), pulse.end(), std::back_inserter(*MonPulsesPtr));
646+ }
647+ // clean up the vector
648+ for (unsigned i = 0; i < MonPulsesAll.size(); i++) MonPulsesAll[i] = std::vector<int>();
649+ */
650+
600651 board_frag_v.clear ();
601652
602653 evt.put (std::move (pmtwvfmVec),fpmt_instance_name);
@@ -609,6 +660,9 @@ void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
609660 evt.put (std::move (pmtTimingAssns),fpmt_timing_instance_name);
610661 evt.put (std::move (fltTimingAssns),fflt_timing_instance_name);
611662 evt.put (std::move (timTimingAssns),ftim_timing_instance_name);
663+
664+ evt.put (std::move (flatPtr), " MonPulses" );
665+ evt.put (std::move (sizesPtr), " MonPulseSizes" );
612666}
613667
614668void sbndaq::SBNDPMTDecoder::get_fragments (artdaq::Fragment & frag, std::vector<std::vector<artdaq::Fragment>> & board_frag_v){
0 commit comments