28 #include "larrecodnn/ImagePatternAlgs/ToolInterfaces/IWaveformDenoise.h" 29 #include "larrecodnn/ImagePatternAlgs/ToolInterfaces/IWaveformRecog.h" 44 class WaveformDenoiseTest;
64 void endJob()
override;
101 p.get<std::string>(
"CleanSignalDigitModuleLabel",
"simWire:signal"))
108 <<
"Both DigitModuleLabel and CleanSignalModuleLabel are empty";
115 auto const tool_psets1 = p.get<std::vector<fhicl::ParameterSet>>(
"WaveformRecogs");
116 for (
auto const& pset : tool_psets1) {
122 auto const tool_psets2 = p.get<std::vector<fhicl::ParameterSet>>(
"WaveformDenoisers");
123 for (
auto const& pset : tool_psets2) {
138 std::ostringstream name;
147 std::ostringstream name;
156 std::ostringstream name;
180 auto digitVecHandle2 =
183 if (!digitVecHandle->size() || !digitVecHandle2->size()) {
185 <<
"At least one of the raw digits lists is empty.";
193 std::vector<raw::RawDigit>
const& rawDigits = *digitVecHandle;
195 unsigned int dataSize = digitVec0.
Samples();
196 if (dataSize != detProp.ReadOutWindowSize()) {
197 throw cet::exception(
"NoiseWaveformRoiAnalyzer") <<
"Bad dataSize: " << dataSize;
199 std::vector<raw::RawDigit>
const& rawDigits2 = *digitVecHandle2;
201 unsigned int dataSize2 = digitVec20.
Samples();
202 if (dataSize != dataSize2) {
204 <<
"RawDigits from the 2 data products have different dataSizes: " << dataSize <<
"not eq to" 209 std::map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> rawdigitMap;
211 for (
size_t rdIter = 0; rdIter < rawDigits.size(); ++rdIter) {
216 rawdigitMap[chnum] = digitVec;
218 std::map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> rawdigitMap2;
220 for (
size_t rdIter = 0; rdIter < rawDigits2.size(); ++rdIter) {
225 rawdigitMap2[chnum2] = digitVec2;
233 std::vector<raw::ChannelID_t> signalchannels;
236 iter != rawdigitMap2.end();
238 std::vector<short> rawadc(dataSize);
239 std::vector<short> adcvec2(dataSize);
241 auto rawdig2 = iter->second;
242 raw::Uncompress(rawdig2->ADCs(), rawadc, rawdig2->GetPedestal(), rawdig2->Compression());
243 for (
size_t j = 0; j < rawadc.size(); ++j) {
244 adcvec2[j] = rawadc[j] - rawdig2->GetPedestal();
247 auto itnz = find_if(adcvec2.begin(), adcvec2.end(), [](
auto x) {
return x != 0; });
248 if (itnz != adcvec2.end()) signalchannels.push_back(iter->first);
251 for (
size_t ich = 0; ich < signalchannels.size(); ++ich) {
254 auto ch1 = signalchannels[ich];
258 std::vector<short> rawadc(dataSize);
259 std::vector<short> adcvec(dataSize);
260 std::vector<short> adcvec2(dataSize);
261 std::vector<float> inputsignal(dataSize);
263 auto search = rawdigitMap.find(ch1);
264 if (search == rawdigitMap.end())
continue;
265 auto rawdig = (*search).second;
266 raw::Uncompress(rawdig->ADCs(), rawadc, rawdig->GetPedestal(), rawdig->Compression());
267 for (
size_t j = 0; j < rawadc.size(); ++j) {
268 adcvec[j] = rawadc[j] - rawdig->GetPedestal();
269 inputsignal[j] = adcvec[j];
272 auto search2 = rawdigitMap2.find(ch1);
273 if (search2 == rawdigitMap2.end())
continue;
274 auto rawdig2 = (*search2).second;
275 raw::Uncompress(rawdig2->ADCs(), rawadc, rawdig2->GetPedestal(), rawdig2->Compression());
276 for (
size_t i = 0; i < rawadc.size(); ++i) {
277 adcvec2[i] = rawadc[i] - rawdig2->GetPedestal();
281 std::vector<bool> inroi(dataSize,
false);
284 auto itnf = find_if(inroi.begin(), inroi.end(), [](
auto x) {
return x; });
285 if (itnf == inroi.end())
continue;
288 std::vector<CnnROI> cnn_rois;
291 bool was_roi =
false;
293 for (
size_t itck = 0; itck < inroi.size() - 1; ++itck) {
294 is_roi = inroi[itck];
295 if (is_roi && !was_roi) { roi.
start = itck; }
296 else if (!is_roi && was_roi) {
298 cnn_rois.push_back(roi);
303 for (
size_t i = 0; i < cnn_rois.size(); ++i) {
308 unsigned int tcka = cnn_rois[i].start;
309 unsigned int tckb = cnn_rois[i].end;
310 unsigned int ntcks_roi = tckb - tcka + 1;
311 unsigned int ntcks_dis = ntcks_roi;
314 ntcks_dis = tckb - tcka + 1;
318 for (
unsigned int itck = tcka; itck < tckb; ++itck) {
319 wavraw[jtck] = adcvec[itck];
320 wavcln[jtck] = adcvec2[itck];
324 std::vector<float> wavinp(ntcks_roi, 0);
325 std::vector<float> wavout(ntcks_roi, 0);
328 for (
unsigned int itck = tcka; itck < tcka + ntcks_roi; ++itck) {
329 wavinp[jtck] = float(adcvec[itck]);
334 for (
unsigned int itck = 0; itck < ntcks_dis; ++itck) {
335 wavdns[itck] = wavout[itck];
int c2numpy_init(c2numpy_writer *writer, const std::string outputFilePrefix, int32_t numRowsPerFile)
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Collection of charge vs time digitized from a single readout channel.
Declaration of signal hit object.
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition of basic raw digits.
int c2numpy_close(c2numpy_writer *writer)
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
int c2numpy_addcolumn(c2numpy_writer *writer, const std::string name, c2numpy_type type)
#define DEFINE_ART_MODULE(klass)
Collect all the RawData header files together.
int c2numpy_uint32(c2numpy_writer *writer, uint32_t data)
int c2numpy_float32(c2numpy_writer *writer, float data)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Encapsulate the construction of a single detector plane.
View_t View(PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
int c2numpy_uint16(c2numpy_writer *writer, uint16_t data)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
int c2numpy_int16(c2numpy_writer *writer, int16_t data)
EventNumber_t event() const
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
SubRunNumber_t subRun() const
int c2numpy_string(c2numpy_writer *writer, const char *data)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception