diff --git a/LArSoftWiki/using_raw_waveform.md b/LArSoftWiki/using_raw_waveform.md index 0e1d0e1..57af6fc 100644 --- a/LArSoftWiki/using_raw_waveform.md +++ b/LArSoftWiki/using_raw_waveform.md @@ -1,58 +1,58 @@ Using the 1DCNN raw waveform algorithm -For general information, see [Waveform region-of-interest finding for supernova event triggering]{https://larsoft.org/waveform-region/) on larsoft.org. +For general information, see [Waveform region-of-interest finding for supernova event triggering](https://larsoft.org/waveform-region/) on larsoft.org. To see how you can use the 1DCNN ROI finder in your LarSoft module, let us start by looking at what needs to be in the fhicl configuration file. First of all, you will need a section specifying parameters related to the model. In the example below, we have three sections, one for each view – U, V, & Z, since there are separate models for each view: ``` tool_WaveformRecogU: { -NNetModelFile: "models/ROI_finder/saved_model_60kU_ROI" -NNetOutputPattern: [ -"cnn_output", -"dense_3", -"wavrec_out" -] -UseSavedModelBundle: true -WaveformSize: 6000 -ScanWindowSize: 200 -StrideLength: 150 -CnnMean: 0.003920474537037037417 -CnnScale: 4.839853236628326449 -CnnPredCut: 0.999 -tool_type: "WaveformRecogTf" + NNetModelFile: "models/ROI_finder/saved_model_60kU_ROI" + NNetOutputPattern: [ + "cnn_output", + "dense_3", + "wavrec_out" + ] + UseSavedModelBundle: true + WaveformSize: 6000 + ScanWindowSize: 200 + StrideLength: 150 + CnnMean: 0.003920474537037037417 + CnnScale: 4.839853236628326449 + CnnPredCut: 0.999 + tool_type: "WaveformRecogTf" } tool_WaveformRecogV: { -NNetModelFile: "models/ROI_finder/saved_model_60kV_ROI" -NNetOutputPattern: [ -"cnn_output", -"dense_3", -"wavrec_out" -] -UseSavedModelBundle: true -WaveformSize: 6000 -ScanWindowSize: 200 -StrideLength: 150 -CnnMean: 0.008304051471056719466 -CnnScale: 4.831063572580124976 -CnnPredCut: 0.999 -tool_type: "WaveformRecogTf" + NNetModelFile: "models/ROI_finder/saved_model_60kV_ROI" + NNetOutputPattern: [ + "cnn_output", + "dense_3", + "wavrec_out" + ] + UseSavedModelBundle: true + WaveformSize: 6000 + ScanWindowSize: 200 + StrideLength: 150 + CnnMean: 0.008304051471056719466 + CnnScale: 4.831063572580124976 + CnnPredCut: 0.999 + tool_type: "WaveformRecogTf" } tool_WaveformRecogZ: { -NNetModelFile: "models/ROI_finder/saved_model_60kZ_ROI" -NNetOutputPattern: [ -"cnn_output", -"dense_3", -"wavrec_out" -] -UseSavedModelBundle: true -WaveformSize: 6000 -ScanWindowSize: 200 -StrideLength: 150 -CnnMean: 0.3008088657407407274 -CnnScale: 4.201201416668982169 -CnnPredCut: 0.999 -tool_type: "WaveformRecogTf" + NNetModelFile: "models/ROI_finder/saved_model_60kZ_ROI" + NNetOutputPattern: [ + "cnn_output", + "dense_3", + "wavrec_out" + ] + UseSavedModelBundle: true + WaveformSize: 6000 + ScanWindowSize: 200 + StrideLength: 150 + CnnMean: 0.3008088657407407274 + CnnScale: 4.201201416668982169 + CnnPredCut: 0.999 + tool_type: "WaveformRecogTf" } ``` Here is a brief description of each parameter above: @@ -72,73 +72,82 @@ This next section shows you how to pass the model specific parameters above to y ``` standard_roifinder: { -module_type: "NameOfYourROIFinderModule" -DigitModuleLabel: "tpcrawdecoder:daq" -WaveformRecogs: [ -@local::tool_WaveformRecogU, -@local::tool_WaveformRecogV, -@local::tool_WaveformRecogZ -] -. -. -. + module_type: "NameOfYourROIFinderModule" + DigitModuleLabel: "tpcrawdecoder:daq" + WaveformRecogs: [ + @local::tool_WaveformRecogU, + @local::tool_WaveformRecogV, + @local::tool_WaveformRecogZ + ] + . + . + . } physics: { -analyzers: -{ -roifinder: @local::standard_roifinder -} -ana: [ roifinder ] -end_paths: [ ana ] + analyzers: + { + roifinder: @local::standard_roifinder + } + ana: [ roifinder ] + end_paths: [ ana ] } ``` In this example, the RawDigits are taken from the LArSoft product labeled “tpcrawdecoder:daq”. + In your LArSoft ROI finder module, you will need the following include: + `#include "larrecodnn/ImagePatternAlgs/ToolInterfaces/IwaveformRecog.h"` + and a declaration like: + `std::vector> fWaveformRecogToolVec;` + then in your constructor, you can do: ``` fDigitModuleLabel = p.get("DigitModuleLabel", ""); -. -. -. + . + . + . // ... load fcl params for Signal/Noise waveform recognition tool auto const tool_psets = p.get>("WaveformRecogs"); if(tool_psets.size()!=geom->Nviews())throw cet::exception("NameOfYourROIFinderModule") -<< "Number of WaveformRecog tool fcl configs not equal to Nviews: " << tool_psets.size(); + << "Number of WaveformRecog tool fcl configs not equal to Nviews: " << tool_psets.size(); fWaveformSize = tool_psets[0].get("WaveformSize"); + fWaveformRecogToolVec.reserve(geom->Nviews()); for (auto const& pset : tool_psets) { -fWaveformRecogToolVec.push_back(art::make_tool(pset)); + fWaveformRecogToolVec.push_back(art::make_tool(pset)); } ``` + In the analysis section of your module, you can then do: ``` // ... Get the raw digits. art::Handle> rawListHandle; std::vector> rawlist; if (e.getByLabel(fDigitModuleLabel, rawListHandle)) art::fill_ptr_vector(rawlist, rawListHandle); -. -. -. + . + . + . for (unsigned int iraw = 0; iraw < rawlist.size()); ++iraw) { -const auto& digitVec = rawlist[iraw]; -unsigned int view = geo->View(rawlist[iraw]->Channel()); -std::vector rawadc(fWaveformSize); -std::vector inputsignal(fWaveformSize); -raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression()); -for (size_t itck = 0; itck < rawadc.size(); ++itck) { -inputsignal[itck] = rawadc[itck] - digitVec->GetPedestal(); -} -// ... use waveform recognition CNN to perform inference on each window -std::vector inroi(fWaveformSize, false); -inroi = fWaveformRecogToolVec[view]→findROI(inputsignal); -. -. -. + const auto& digitVec = rawlist[iraw]; + unsigned int view = geo->View(rawlist[iraw]->Channel()); + + std::vector rawadc(fWaveformSize); + std::vector inputsignal(fWaveformSize); + + raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression()); + for (size_t itck = 0; itck < rawadc.size(); ++itck) { + inputsignal[itck] = rawadc[itck] - digitVec->GetPedestal(); + } + // ... use waveform recognition CNN to perform inference on each window + std::vector inroi(fWaveformSize, false); + inroi = fWaveformRecogToolVec[view]→findROI(inputsignal); + . + . + . } ``` In the example above, we loop over all the raw digits in rawlist and feed each vector, after converting it to float, into the ROI finder using the findROI method. This method returns a boolean vector with the same size as the input vector where the ROIs are identified by the elements that are set to true.