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::Name("outRawTag"),
26  fhicl::Comment("Label the output raw::RawDigit collection."),
27  "truncraw"};
28 
30  fhicl::Name("outSigTag"),
31  fhicl::Comment("Label the output recob::Wire collection."),
32  "truncsig"};
33 
35  fhicl::Name("outAssnTag"),
36  fhicl::Comment("Label the output associations."),
37  "rawsigassns" };
38 
40  fhicl::Comment("Number of ticks from start of waveform to drop"),
41  0 };
43  fhicl::Comment("Number of remaining ticks to keep after initial drop"),
44  -1 };
45 
47  fhicl::Comment("A multiplicative scale factor applied to the output recob::Wires"),
48  1.0 };
49  };
50 
51  class EventButcher : public art::EDProducer {
52  public:
53 
55 
56  explicit EventButcher(Parameters const& params);
57  virtual ~EventButcher();
58 
59  void produce(art::Event & evt);
60 
61  private:
62 
64  // inputs
66  // this needs art 2.08
67  //art::ProductToken< std::vector<raw::RawDigit> > m_rawtok;
68  //art::ProductToken< std::vector<recob::Wire> > m_sigtok;
69  };
70 
71 
72 }
73 
74 using namespace std;
75 
77  : EDProducer{params}
78  , m_cfg(params())
81 // , m_rawtok{consumes< std::vector<raw::RawDigit> >(m_rawtag)}
82 // , m_sigtok{consumes< std::vector<recob::Wire> >(m_sigtag)}
83 {
84  //cerr << "Producing: outraw:"<<m_cfg.outRawTag()<<" outsig:"<<m_cfg.outSigTag()<<" outras:" << m_cfg.outAssnTag() << endl;
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());
88 }
89 
91 {
92 }
93 
94 
96 {
97 
98  //cerr <<"In raw=" << m_rawtag << " in sig=" << m_sigtag << "\n";
99 
101  //event.getByToken(m_rawtok, raw);
102  event.getByLabel(m_rawtag, raw);
103  const size_t nraw = raw->size();
104 
106  //event.getByToken(m_sigtok, sig);
107  event.getByLabel(m_sigtag, sig);
108  const size_t nsig = sig->size();
109 
110  // https://cdcvs.fnal.gov/redmine/projects/art/wiki/The_PtrMaker_utility
112  art::PtrMaker<recob::Wire> SigPtr(event, m_cfg.outSigTag());
113 
114  // keep track of raw digit Ptr by its channel id, for later look
115  // up in making associations.
116  std::unordered_map<raw::ChannelID_t, art::Ptr<raw::RawDigit> > chid2rawptr;
117 
118  // raw-signal association
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> >();
122 
123  const int ndrop = m_cfg.ndrop();
124  const int nkeep = m_cfg.nkeep();
125  const double sigscale = m_cfg.sigscale();
126 
127  // Truncate the raw digits
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();
132 
133  const int outlen = std::min(inlen-ndrop, nkeep < 0 ? inlen : nkeep);
134 
135  if (outlen <= 0) {
136  continue; // add a "keep_empty" option and save an empty place holder RawDigit here?
137  }
138 
139  size_t outind = outraw->size();
140  const raw::ChannelID_t chid = inrd.Channel();
141  raw::RawDigit::ADCvector_t outadc(inadcs.begin()+ndrop, inadcs.begin()+ndrop+outlen);
142  outraw->emplace_back(raw::RawDigit(chid, outlen, outadc, raw::kNone));
143  // given the truncationn, this is technically a BOGUS thing to do
144  auto& outrd = outraw->back();
145  outrd.SetPedestal(inrd.GetPedestal(), inrd.GetSigma());
146 
147  chid2rawptr[chid] = RawPtr(outind);
148  }
149 
150 
151  // Truncate the signal and make assns
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();
156 
157  const int outlen = std::min(inlen-ndrop, nkeep < 0 ? inlen : nkeep);
158 
159  if (outlen <= 0) {
160  continue;
161  }
162 
163  const auto chid = inw.Channel();
164  const auto view = inw.View();
165 
166  // resparsify
168  auto first = wave.begin()+ndrop;
169  auto done = wave.begin()+ndrop+outlen;
170  auto beg = first;
171  while (true) {
172  beg = std::find_if(beg, done, [](float v){return v != 0.0;});
173  if (beg == done) {
174  break;
175  }
176  auto end = std::find_if(beg, done, [](float v){return v == 0.0;});
177 
178  std::vector<float> scaled(beg, end);
179  for (int ind=0; ind<end-beg; ++ind) {
180  scaled[ind] *= sigscale;
181  }
182  roi.add_range(beg-first, scaled.begin(), scaled.end());
183  beg = end;
184  }
185 
186  const size_t outind = outsig->size();
187  outsig->emplace_back(recob::Wire(roi, chid, view));
188 
189  // associate
190  auto rawit = chid2rawptr.find(chid);
191  if (rawit == chid2rawptr.end()) {
192  continue; // emit warning about no accompaning raw digit?
193  }
194  auto const& rawptr = rawit->second;
195  auto const sigptr = SigPtr(outind);
196  outrsa->addSingle(rawptr, sigptr);
197  }
198 
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());
202 
203 }
204 
205 namespace butcher {
207 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
ChannelGroupService::Name Name
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
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.
Raw data description.
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:67
def move(depos, offset)
Definition: depos.py:107
fhicl::Atom< std::string > inSigTag
void produce(art::Event &evt)
fhicl::Atom< std::string > inRawTag
fhicl::Atom< std::string > outSigTag
#define Comment
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
EventButcher(Parameters const &params)
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:118
Declaration of basic channel signal object.
const EventButcherConfig m_cfg
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Event finding and building.