1 #include "art/Framework/Core/ModuleMacros.h"
2 #include "art/Framework/Core/EDProducer.h"
3 #include "art/Framework/Principal/Event.h"
5 #include "art/Persistency/Common/PtrMaker.h"
6 #include "canvas/Persistency/Common/Assns.h"
19 fhicl::Comment(
"Input tag for the raw::RawDigit collection.") };
22 fhicl::Comment(
"Input tag for the recob::Wire collection.") };
26 fhicl::Comment(
"Label the output raw::RawDigit collection."),
31 fhicl::Comment(
"Label the output recob::Wire collection."),
36 fhicl::Comment(
"Label the output associations."),
40 fhicl::Comment(
"Number of ticks from start of waveform to drop"),
43 fhicl::Comment(
"Number of remaining ticks to keep after initial drop"),
47 fhicl::Comment(
"A multiplicative scale factor applied to the output recob::Wires"),
54 using Parameters = art::EDProducer::Table<EventButcherConfig>;
79 , m_rawtag{m_cfg.inRawTag()}
80 , m_sigtag{m_cfg.inSigTag()}
85 produces< std::vector<raw::RawDigit> >(m_cfg.outRawTag());
86 produces< std::vector<recob::Wire> >(m_cfg.outSigTag());
87 produces< art::Assns<raw::RawDigit,recob::Wire> >(m_cfg.outAssnTag());
100 art::Handle< std::vector<raw::RawDigit> > raw;
102 event.getByLabel(m_rawtag, raw);
103 const size_t nraw = raw->size();
105 art::Handle< std::vector<recob::Wire> > sig;
107 event.getByLabel(m_sigtag, sig);
108 const size_t nsig = sig->size();
111 art::PtrMaker<raw::RawDigit> RawPtr(event, m_cfg.outRawTag());
112 art::PtrMaker<recob::Wire> SigPtr(event, m_cfg.outSigTag());
116 std::unordered_map<raw::ChannelID_t, art::Ptr<raw::RawDigit> > chid2rawptr;
119 auto outrsa = std::make_unique< art::Assns<raw::RawDigit,recob::Wire> >();
120 auto outraw = std::make_unique< std::vector<raw::RawDigit> >();
121 auto outsig = std::make_unique< std::vector<recob::Wire> >();
123 const int ndrop = m_cfg.ndrop();
124 const int nkeep = m_cfg.nkeep();
125 const double sigscale = m_cfg.sigscale();
128 for (
size_t iraw=0; iraw != nraw; ++iraw) {
129 const auto& inrd = raw->at(iraw);
130 const auto& inadcs = inrd.ADCs();
131 const size_t inlen = inadcs.size();
133 const int outlen = std::min(inlen-ndrop, nkeep < 0 ? inlen : nkeep);
139 size_t outind = outraw->size();
144 auto& outrd = outraw->back();
145 outrd.SetPedestal(inrd.GetPedestal(), inrd.GetSigma());
147 chid2rawptr[chid] = RawPtr(outind);
152 for (
size_t isig=0; isig != nsig; ++isig) {
153 const auto& inw = sig->at(isig);
154 std::vector<float> wave = inw.Signal();
155 const size_t inlen = wave.size();
157 const int outlen = std::min(inlen-ndrop, nkeep < 0 ? inlen : nkeep);
163 const auto chid = inw.Channel();
164 const auto view = inw.View();
168 auto first = wave.begin()+ndrop;
169 auto done = wave.begin()+ndrop+outlen;
172 beg = std::find_if(beg, done, [](
float v){
return v != 0.0;});
176 auto end = std::find_if(beg, done, [](
float v){
return v == 0.0;});
178 std::vector<float> scaled(beg,
end);
179 for (
int ind=0; ind<
end-beg; ++ind) {
180 scaled[ind] *= sigscale;
186 const size_t outind = outsig->size();
187 outsig->emplace_back(
recob::Wire(roi, chid, view));
190 auto rawit = chid2rawptr.find(chid);
191 if (rawit == chid2rawptr.end()) {
194 auto const& rawptr = rawit->second;
195 auto const sigptr = SigPtr(outind);
196 outrsa->addSingle(rawptr, sigptr);
199 event.put(std::move(outraw), m_cfg.outRawTag());
200 event.put(std::move(outsig), m_cfg.outSigTag());
201 event.put(std::move(outrsa), m_cfg.outAssnTag());
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Collection of charge vs time digitized from a single readout channel.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
Definition of basic raw digits.
fhicl::Atom< double > sigscale
fhicl::Atom< std::string > outRawTag
fhicl::Atom< std::string > outAssnTag
fhicl::Atom< std::string > inSigTag
auto end(FixedBins< T, C > const &) noexcept
BEGIN_PROLOG vertical distance to the surface Name
void produce(art::Event &evt)
fhicl::Atom< std::string > inRawTag
fhicl::Atom< std::string > outSigTag
EventButcher(Parameters const ¶ms)
Class holding the regions of interest of signal from a channel.
Declaration of basic channel signal object.
const EventButcherConfig m_cfg
unsigned int ChannelID_t
Type representing the ID of a readout channel.
art::EDProducer::Table< EventButcherConfig > Parameters