LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EventButcher_module.cc
Go to the documentation of this file.
4 
7 
10 
11 namespace butcher {
12 
14 
15  // fixme: provide reasonable defaults
16 
18  fhicl::Name("inRawTag"),
19  fhicl::Comment("Input tag for the raw::RawDigit collection.")};
20 
22  fhicl::Comment("Input tag for the recob::Wire collection.")};
23 
25  fhicl::Comment("Label the output raw::RawDigit collection."),
26  "truncraw"};
27 
29  fhicl::Comment("Label the output recob::Wire collection."),
30  "truncsig"};
31 
33  fhicl::Comment("Label the output associations."),
34  "rawsigassns"};
35 
37  fhicl::Comment("Number of ticks from start of waveform to drop"),
38  0};
40  fhicl::Comment("Number of remaining ticks to keep after initial drop"),
41  -1};
42 
44  fhicl::Name("sigscale"),
45  fhicl::Comment("A multiplicative scale factor applied to the output recob::Wires"),
46  1.0};
47  };
48 
49  class EventButcher : public art::EDProducer {
50  public:
52 
53  explicit EventButcher(Parameters const& params);
54  virtual ~EventButcher();
55 
56  void produce(art::Event& evt);
57 
58  private:
60  // inputs
62  // this needs art 2.08
63  //art::ProductToken< std::vector<raw::RawDigit> > m_rawtok;
64  //art::ProductToken< std::vector<recob::Wire> > m_sigtok;
65  };
66 
67 }
68 
69 using namespace std;
70 
72  : EDProducer{params}, m_cfg(params()), m_rawtag{m_cfg.inRawTag()}, m_sigtag{m_cfg.inSigTag()}
73 // , m_rawtok{consumes< std::vector<raw::RawDigit> >(m_rawtag)}
74 // , m_sigtok{consumes< std::vector<recob::Wire> >(m_sigtag)}
75 {
76  //cerr << "Producing: outraw:"<<m_cfg.outRawTag()<<" outsig:"<<m_cfg.outSigTag()<<" outras:" << m_cfg.outAssnTag() << endl;
77  produces<std::vector<raw::RawDigit>>(m_cfg.outRawTag());
78  produces<std::vector<recob::Wire>>(m_cfg.outSigTag());
79  produces<art::Assns<raw::RawDigit, recob::Wire>>(m_cfg.outAssnTag());
80 }
81 
83 
85 {
86 
87  //cerr <<"In raw=" << m_rawtag << " in sig=" << m_sigtag << "\n";
88 
90  //event.getByToken(m_rawtok, raw);
91  event.getByLabel(m_rawtag, raw);
92  const size_t nraw = raw->size();
93 
95  //event.getByToken(m_sigtok, sig);
96  event.getByLabel(m_sigtag, sig);
97  const size_t nsig = sig->size();
98 
99  // https://cdcvs.fnal.gov/redmine/projects/art/wiki/The_PtrMaker_utility
101  art::PtrMaker<recob::Wire> SigPtr(event, m_cfg.outSigTag());
102 
103  // keep track of raw digit Ptr by its channel id, for later look
104  // up in making associations.
105  std::unordered_map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> chid2rawptr;
106 
107  // raw-signal association
108  auto outrsa = std::make_unique<art::Assns<raw::RawDigit, recob::Wire>>();
109  auto outraw = std::make_unique<std::vector<raw::RawDigit>>();
110  auto outsig = std::make_unique<std::vector<recob::Wire>>();
111 
112  const int ndrop = m_cfg.ndrop();
113  const int nkeep = m_cfg.nkeep();
114  const double sigscale = m_cfg.sigscale();
115 
116  // Truncate the raw digits
117  for (size_t iraw = 0; iraw != nraw; ++iraw) {
118  const auto& inrd = raw->at(iraw);
119  const auto& inadcs = inrd.ADCs();
120  const size_t inlen = inadcs.size();
121 
122  const int outlen = std::min(inlen - ndrop, nkeep < 0 ? inlen : nkeep);
123 
124  if (outlen <= 0) {
125  continue; // add a "keep_empty" option and save an empty place holder RawDigit here?
126  }
127 
128  size_t outind = outraw->size();
129  const raw::ChannelID_t chid = inrd.Channel();
130  raw::RawDigit::ADCvector_t outadc(inadcs.begin() + ndrop, inadcs.begin() + ndrop + outlen);
131  outraw->emplace_back(raw::RawDigit(chid, outlen, outadc, raw::kNone));
132  // given the truncationn, this is technically a BOGUS thing to do
133  auto& outrd = outraw->back();
134  outrd.SetPedestal(inrd.GetPedestal(), inrd.GetSigma());
135 
136  chid2rawptr[chid] = RawPtr(outind);
137  }
138 
139  // Truncate the signal and make assns
140  for (size_t isig = 0; isig != nsig; ++isig) {
141  const auto& inw = sig->at(isig);
142  std::vector<float> wave = inw.Signal();
143  const size_t inlen = wave.size();
144 
145  const int outlen = std::min(inlen - ndrop, nkeep < 0 ? inlen : nkeep);
146 
147  if (outlen <= 0) { continue; }
148 
149  const auto chid = inw.Channel();
150  const auto view = inw.View();
151 
152  // resparsify
154  auto first = wave.begin() + ndrop;
155  auto done = wave.begin() + ndrop + outlen;
156  auto beg = first;
157  while (true) {
158  beg = std::find_if(beg, done, [](float v) { return v != 0.0; });
159  if (beg == done) { break; }
160  auto end = std::find_if(beg, done, [](float v) { return v == 0.0; });
161 
162  std::vector<float> scaled(beg, end);
163  for (int ind = 0; ind < end - beg; ++ind) {
164  scaled[ind] *= sigscale;
165  }
166  roi.add_range(beg - first, scaled.begin(), scaled.end());
167  beg = end;
168  }
169 
170  const size_t outind = outsig->size();
171  outsig->emplace_back(recob::Wire(roi, chid, view));
172 
173  // associate
174  auto rawit = chid2rawptr.find(chid);
175  if (rawit == chid2rawptr.end()) {
176  continue; // emit warning about no accompaning raw digit?
177  }
178  auto const& rawptr = rawit->second;
179  auto const sigptr = SigPtr(outind);
180  outrsa->addSingle(rawptr, sigptr);
181  }
182 
183  event.put(std::move(outraw), m_cfg.outRawTag());
184  event.put(std::move(outsig), m_cfg.outSigTag());
185  event.put(std::move(outrsa), m_cfg.outAssnTag());
186 }
187 
188 namespace butcher {
190 }
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:68
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:72
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
STL namespace.
Definition of basic raw digits.
Raw data description.
Definition: RawTypes.h:6
fhicl::Atom< double > sigscale
no compression
Definition: RawTypes.h:9
fhicl::Atom< std::string > outRawTag
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
fhicl::Atom< std::string > outAssnTag
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
fhicl::Atom< std::string > inSigTag
void produce(art::Event &evt)
fhicl::Atom< std::string > inRawTag
fhicl::Atom< std::string > outSigTag
EventButcher(Parameters const &params)
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:116
Declaration of basic channel signal object.
const EventButcherConfig m_cfg
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Event finding and building.