2 #include "art/Framework/Principal/Handle.h"
7 #include "art/Framework/Principal/Event.h"
8 #include "art/Framework/Principal/Run.h"
10 #include "TTimeStamp.h"
13 #include "WireCellAux/SimpleFrame.h"
14 #include "WireCellAux/SimpleTrace.h"
15 #include "WireCellUtil/NamedFactory.h"
22 using namespace WireCell;
23 using WireCell::Aux::SimpleTrace;
24 using WireCell::Aux::SimpleFrame;
31 RawFrameSource::~RawFrameSource()
36 WireCell::Configuration RawFrameSource::default_configuration()
const
40 cfg[
"tick"] = 0.5*WireCell::units::us;
41 cfg[
"frame_tags"][0] =
"orig";
42 cfg[
"nticks"] = m_nticks;
46 void RawFrameSource::configure(
const WireCell::Configuration& cfg)
48 const std::string art_tag = cfg[
"art_tag"].asString();
49 if (art_tag.empty()) {
50 THROW(ValueError() << errmsg{
"WireCell::RawFrameSource requires a source_label"});
52 m_inputTag = cfg[
"art_tag"].asString();
54 m_tick = cfg[
"tick"].asDouble();
55 for (
auto jtag : cfg[
"frame_tags"]) {
56 m_frame_tags.push_back(jtag.asString());
58 m_nticks =
get(cfg,
"nticks", m_nticks);
65 double tdiff(
const art::Timestamp& ts1,
const art::Timestamp& ts2)
67 TTimeStamp tts1(ts1.timeHigh(), ts1.timeLow());
68 TTimeStamp tts2(ts2.timeHigh(), ts2.timeLow());
69 return tts2.AsDouble() - tts1.AsDouble();
81 unsigned int nadcs = adcv.size();
82 if (nticks_want > 0) {
83 if (nticks_want > nadcs) {
84 baseline = Waveform::most_frequent(adcv);
86 nadcs = std::min(nadcs, nticks_want);
92 auto strace =
new SimpleTrace(chid, tbin, nticks_want);
93 for (
unsigned int itick=0; itick < nadcs; ++ itick) {
94 strace->charge()[itick] = adcv[itick];
96 for (
unsigned int itick = nadcs; itick < nticks_want; ++itick) {
102 void RawFrameSource::visit(art::Event & event)
105 const double tick = m_tick;
106 art::Handle< std::vector<raw::RawDigit> > rdvh;
107 bool okay =
event.getByLabel(m_inputTag, rdvh);
109 std::string
msg =
"WireCell::RawFrameSource failed to get vector<raw::RawDigit>: " + m_inputTag.encode();
111 THROW(RuntimeError() << errmsg{msg});
113 else if (rdvh->size() == 0)
return;
115 const std::vector<raw::RawDigit>& rdv(*rdvh);
116 const size_t nchannels = rdv.size();
117 std::cerr <<
"RawFrameSource: got " << nchannels <<
" raw::RawDigit objects\n";
120 for (
size_t ind=0; ind<nchannels; ++ind) {
121 auto const& rd = rdv.at(ind);
122 traces[ind] = ITrace::pointer(
make_trace(rd, m_nticks));
126 <<
"\tinput nticks=" << rd.ADCs().size() <<
" setting to " << m_nticks
131 <<
"\tinput nticks=" << rd.ADCs().size() <<
" keeping as is"
137 const double time =
tdiff(event.getRun().beginTime(),
event.time());
138 auto sframe =
new SimpleFrame(event.event(), time, traces,
tick);
139 for (
auto tag : m_frame_tags) {
141 sframe->tag_frame(tag);
143 m_frames.push_back(WireCell::IFrame::pointer(sframe));
144 m_frames.push_back(
nullptr);
147 bool RawFrameSource::operator()(WireCell::IFrame::pointer& frame)
150 if (m_frames.empty()) {
153 frame = m_frames.front();
154 m_frames.pop_front();
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
static SimpleTrace * make_trace(const raw::RawDigit &rd, unsigned int nticks_want)
Collection of charge vs time digitized from a single readout channel.
BEGIN_PROLOG could also be cerr
ChannelID_t Channel() const
DAQ channel this raw data was read from.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition of basic raw digits.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
WIRECELL_FACTORY(wclsChannelNoiseDB, wcls::ChannelNoiseDB, wcls::IArtEventVisitor, WireCell::IChannelNoiseDatabase) using namespace WireCell
static double tdiff(const art::Timestamp &ts1, const art::Timestamp &ts2)