LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
EventButcher_module.cc
Go to the documentation of this file.
3 
5 
8 
9 namespace butcher {
10 
12 
13  // fixme: provide reasonable defaults
14 
16  fhicl::Name("inRawTag"),
17  fhicl::Comment("Input tag for the raw::RawDigit collection.") };
18 
20  fhicl::Comment("Input tag for the recob::Wire collection.") };
21 
23  fhicl::Name("outRawTag"),
24  fhicl::Comment("Label the output raw::RawDigit collection."),
25  "truncraw"};
26 
28  fhicl::Name("outSigTag"),
29  fhicl::Comment("Label the output recob::Wire collection."),
30  "truncsig"};
31 
33  fhicl::Name("outAssnTag"),
34  fhicl::Comment("Label the output associations."),
35  "rawsigassns" };
36 
38  fhicl::Comment("Number of ticks from start of waveform to drop"),
39  0 };
41  fhicl::Comment("Number of remaining ticks to keep after initial drop"),
42  -1 };
43 
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:
51 
53 
54  explicit EventButcher(Parameters const& params);
55  virtual ~EventButcher();
56 
57  void produce(art::Event & evt);
58 
59  private:
60 
62  // inputs
64  // this needs art 2.08
65  //art::ProductToken< std::vector<raw::RawDigit> > m_rawtok;
66  //art::ProductToken< std::vector<recob::Wire> > m_sigtok;
67  };
68 
69 
70 }
71 
72 #include <iostream>
73 using namespace std;
74 
76  : m_cfg(params())
77  , m_rawtag{m_cfg.inRawTag()}
79 // , m_rawtok{consumes< std::vector<raw::RawDigit> >(m_rawtag)}
80 // , m_sigtok{consumes< std::vector<recob::Wire> >(m_sigtag)}
81 {
82  //cerr << "Producing: outraw:"<<m_cfg.outRawTag()<<" outsig:"<<m_cfg.outSigTag()<<" outras:" << m_cfg.outAssnTag() << endl;
83  produces< std::vector<raw::RawDigit> >(m_cfg.outRawTag());
84  produces< std::vector<recob::Wire> >(m_cfg.outSigTag());
85  produces< art::Assns<raw::RawDigit,recob::Wire> >(m_cfg.outAssnTag());
86 }
87 
89 {
90 }
91 
92 
94 {
95 
96  //cerr <<"In raw=" << m_rawtag << " in sig=" << m_sigtag << "\n";
97 
99  //event.getByToken(m_rawtok, raw);
100  event.getByLabel(m_rawtag, raw);
101  const size_t nraw = raw->size();
102 
104  //event.getByToken(m_sigtok, sig);
105  event.getByLabel(m_sigtag, sig);
106  const size_t nsig = sig->size();
107 
108  // https://cdcvs.fnal.gov/redmine/projects/art/wiki/The_PtrMaker_utility
109  art::PtrMaker<raw::RawDigit> RawPtr(event, *this, m_cfg.outRawTag());
110  art::PtrMaker<recob::Wire> SigPtr(event, *this, m_cfg.outSigTag());
111 
112  // keep track of raw digit Ptr by its channel id, for later look
113  // up in making associations.
114  std::unordered_map<raw::ChannelID_t, art::Ptr<raw::RawDigit> > chid2rawptr;
115 
116  // raw-signal association
117  auto outrsa = std::make_unique< art::Assns<raw::RawDigit,recob::Wire> >();
118  auto outraw = std::make_unique< std::vector<raw::RawDigit> >();
119  auto outsig = std::make_unique< std::vector<recob::Wire> >();
120 
121  const int ndrop = m_cfg.ndrop();
122  const int nkeep = m_cfg.nkeep();
123  const double sigscale = m_cfg.sigscale();
124 
125  // Truncate the raw digits
126  for (size_t iraw=0; iraw != nraw; ++iraw) {
127  const auto& inrd = raw->at(iraw);
128  const auto& inadcs = inrd.ADCs();
129  const size_t inlen = inadcs.size();
130 
131  const int outlen = std::min(inlen-ndrop, nkeep < 0 ? inlen : nkeep);
132 
133  if (outlen <= 0) {
134  continue; // add a "keep_empty" option and save an empty place holder RawDigit here?
135  }
136 
137  size_t outind = outraw->size();
138  const raw::ChannelID_t chid = inrd.Channel();
139  raw::RawDigit::ADCvector_t outadc(inadcs.begin()+ndrop, inadcs.begin()+ndrop+outlen);
140  outraw->emplace_back(raw::RawDigit(chid, outlen, outadc, raw::kNone));
141  // given the truncationn, this is technically a BOGUS thing to do
142  auto& outrd = outraw->back();
143  outrd.SetPedestal(inrd.GetPedestal(), inrd.GetSigma());
144 
145  chid2rawptr[chid] = RawPtr(outind);
146  }
147 
148 
149  // Truncate the signal and make assns
150  for (size_t isig=0; isig != nsig; ++isig) {
151  const auto& inw = sig->at(isig);
152  std::vector<float> wave = inw.Signal();
153  const size_t inlen = wave.size();
154 
155  const int outlen = std::min(inlen-ndrop, nkeep < 0 ? inlen : nkeep);
156 
157  if (outlen <= 0) {
158  continue;
159  }
160 
161  const auto chid = inw.Channel();
162  const auto view = inw.View();
163 
164  // resparsify
166  auto first = wave.begin()+ndrop;
167  auto done = wave.begin()+ndrop+outlen;
168  auto beg = first;
169  while (true) {
170  beg = std::find_if(beg, done, [](float v){return v != 0.0;});
171  if (beg == done) {
172  break;
173  }
174  auto end = std::find_if(beg, done, [](float v){return v == 0.0;});
175 
176  std::vector<float> scaled(beg, end);
177  for (int ind=0; ind<end-beg; ++ind) {
178  scaled[ind] *= sigscale;
179  }
180  roi.add_range(beg-first, scaled.begin(), scaled.end());
181  beg = end;
182  }
183 
184  const size_t outind = outsig->size();
185  outsig->emplace_back(recob::Wire(roi, chid, view));
186 
187  // associate
188  auto rawit = chid2rawptr.find(chid);
189  if (rawit == chid2rawptr.end()) {
190  continue; // emit warning about no accompaning raw digit?
191  }
192  auto const& rawptr = rawit->second;
193  auto const sigptr = SigPtr(outind);
194  outrsa->addSingle(rawptr, sigptr);
195  }
196 
197  event.put(std::move(outraw), m_cfg.outRawTag());
198  event.put(std::move(outsig), m_cfg.outSigTag());
199  event.put(std::move(outrsa), m_cfg.outAssnTag());
200 
201 }
202 
203 namespace butcher {
205 }
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
fhicl::Atom< std::string > outAssnTag
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
fhicl::Atom< std::string > inSigTag
void produce(art::Event &evt)
fhicl::Atom< std::string > inRawTag
fhicl::Atom< std::string > outSigTag
Int_t min
Definition: plot.C:26
EventButcher(Parameters const &params)
Class holding the deconvoluted signals from a channel.
Definition: Wire.h:80
Declaration of basic channel signal object.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
const EventButcherConfig m_cfg
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
Event finding and building.