LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
nnet::PointIdAlg Class Reference

#include "PointIdAlg.h"

Inheritance diagram for nnet::PointIdAlg:
img::DataProviderAlg

Classes

struct  Config
 

Public Types

enum  EDownscaleMode { kMax = 1, kMaxMean = 2, kMean = 3 }
 

Public Member Functions

 PointIdAlg (const fhicl::ParameterSet &pset)
 
 PointIdAlg (const Config &config)
 
 ~PointIdAlg () override
 
std::vector< std::string > const & outputLabels () const
 network output labels More...
 
float predictIdValue (unsigned int wire, float drift, size_t outIdx=0) const
 calculate single-value prediction (2-class probability) for [wire, drift] point More...
 
std::vector< float > predictIdVector (unsigned int wire, float drift) const
 calculate multi-class probabilities for [wire, drift] point More...
 
std::vector< std::vector< float > > predictIdVectors (std::vector< std::pair< unsigned int, float >> points) const
 
std::vector< std::vector< float > > const & patchData2D () const
 
std::vector< float > patchData1D () const
 
bool isInsideFiducialRegion (unsigned int wire, float drift) const
 
bool isCurrentPatch (unsigned int wire, float drift) const
 
bool isSamePatch (unsigned int wire1, float drift1, unsigned int wire2, float drift2) const
 test if two wire/drift coordinates point to the same patch More...
 
bool setWireDriftData (const detinfo::DetectorClocksData &clock_data, const detinfo::DetectorPropertiesData &det_prop, const std::vector< recob::Wire > &wires, unsigned int plane, unsigned int tpc, unsigned int cryo)
 
std::vector< float > const & wireData (size_t widx) const
 
std::vector< std::vector< float > > getPatch (size_t wire, float drift, size_t patchSizeW, size_t patchSizeD) const
 
float getPixelOrZero (int wire, int drift) const
 
double getAdcSum () const
 
size_t getAdcArea () const
 
float poolMax (int wire, int drift, size_t r=0) const
 Pool max value in a patch around the wire/drift pixel. More...
 
unsigned int Cryo () const
 Pool sum of pixels in a patch around the wire/drift pixel. More...
 
unsigned int TPC () const
 
unsigned int Plane () const
 
unsigned int NWires () const
 
unsigned int NScaledDrifts () const
 
unsigned int NCachedDrifts () const
 
unsigned int DriftWindow () const
 
float ZeroLevel () const
 Level of zero ADC after scaling. More...
 
double LifetimeCorrection (detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double tick) const
 

Static Public Member Functions

static std::vector< float > flattenData2D (std::vector< std::vector< float >> const &patch)
 

Protected Member Functions

std::vector< float > downscaleMax (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
std::vector< float > downscaleMaxMean (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
std::vector< float > downscaleMean (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
std::vector< float > downscale (std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
 
size_t getDriftIndex (float drift) const
 
std::optional< std::vector< float > > setWireData (std::vector< float > const &adc, size_t wireIdx) const
 
bool patchFromDownsampledView (size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
 
bool patchFromOriginalView (size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
 
virtual DataProviderAlgView resizeView (detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, size_t wires, size_t drifts)
 

Protected Attributes

DataProviderAlgView fAlgView
 
EDownscaleMode fDownscaleMode
 
size_t fDriftWindow
 
bool fDownscaleFullView
 
float fDriftWindowInv
 
calo::CalorimetryAlg fCalorimetryAlg
 
geo::GeometryCore const * fGeometry
 

Private Member Functions

bool bufferPatch (size_t wire, float drift, std::vector< std::vector< float >> &patch) const
 
bool bufferPatch (size_t wire, float drift) const
 
void resizePatch ()
 
void deleteNNet ()
 

Private Attributes

std::string fNNetModelFilePath
 
std::vector< std::string > fNNetOutputs
 
nnet::ModelInterfacefNNet
 
std::vector< std::vector< float > > fWireDriftPatch
 
size_t fPatchSizeW
 
size_t fPatchSizeD
 
size_t fCurrentWireIdx
 
size_t fCurrentScaledDrift
 

Detailed Description

Definition at line 98 of file PointIdAlg.h.

Member Enumeration Documentation

Enumerator
kMax 
kMaxMean 
kMean 

Definition at line 64 of file DataProviderAlg.h.

Constructor & Destructor Documentation

nnet::PointIdAlg::PointIdAlg ( const fhicl::ParameterSet pset)
inline

Definition at line 114 of file PointIdAlg.h.

114 : PointIdAlg(fhicl::Table<Config>(pset, {})()) {}
PointIdAlg(const fhicl::ParameterSet &pset)
Definition: PointIdAlg.h:114
nnet::PointIdAlg::PointIdAlg ( const Config config)

Definition at line 173 of file PointIdAlg.cxx.

References deleteNNet(), fNNet, fNNetModelFilePath, fNNetOutputs, nnet::PointIdAlg::Config::NNetModelFile, nnet::PointIdAlg::Config::NNetOutputs, and resizePatch().

174  : img::DataProviderAlg(config)
175  , fNNet(0)
176  , fPatchSizeW(config.PatchSizeW())
177  , fPatchSizeD(config.PatchSizeD())
178  , fCurrentWireIdx(99999)
179  , fCurrentScaledDrift(99999)
180 {
181  fNNetModelFilePath = config.NNetModelFile();
182  fNNetOutputs = config.NNetOutputs();
183 
184  deleteNNet();
185 
186  if ((fNNetModelFilePath.length() > 5) &&
187  (fNNetModelFilePath.compare(fNNetModelFilePath.length() - 5, 5, ".nnet") == 0)) {
189  }
190  else if ((fNNetModelFilePath.length() > 3) &&
191  (fNNetModelFilePath.compare(fNNetModelFilePath.length() - 3, 3, ".pb") == 0)) {
193  }
194  else {
195  mf::LogError("PointIdAlg") << "File name extension not supported.";
196  }
197 
198  if (!fNNet) { throw cet::exception("nnet::PointIdAlg") << "Loading model from file failed."; }
199 
200  resizePatch();
201 }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< std::string > fNNetOutputs
Definition: PointIdAlg.h:151
size_t fPatchSizeD
Definition: PointIdAlg.h:155
size_t fCurrentScaledDrift
Definition: PointIdAlg.h:157
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:152
size_t fPatchSizeW
Definition: PointIdAlg.h:155
std::string fNNetModelFilePath
Definition: PointIdAlg.h:150
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
size_t fCurrentWireIdx
Definition: PointIdAlg.h:157
nnet::PointIdAlg::~PointIdAlg ( )
override

Definition at line 204 of file PointIdAlg.cxx.

References deleteNNet().

205 {
206  deleteNNet();
207 }

Member Function Documentation

bool nnet::PointIdAlg::bufferPatch ( size_t  wire,
float  drift,
std::vector< std::vector< float >> &  patch 
) const
inlineprivate

Definition at line 158 of file PointIdAlg.h.

Referenced by predictIdValue(), predictIdVector(), and predictIdVectors().

159  {
160  if (fDownscaleFullView) {
161  size_t sd = (size_t)(drift / fDriftWindow);
162  if ((fCurrentWireIdx == wire) && (fCurrentScaledDrift == sd))
163  return true; // still within the current position
164 
165  fCurrentWireIdx = wire;
166  fCurrentScaledDrift = sd;
167 
168  return patchFromDownsampledView(wire, drift, fPatchSizeW, fPatchSizeD, patch);
169  }
170  else {
171  if ((fCurrentWireIdx == wire) && (fCurrentScaledDrift == drift))
172  return true; // still within the current position
173 
174  fCurrentWireIdx = wire;
175  fCurrentScaledDrift = drift;
176 
177  return patchFromOriginalView(wire, drift, fPatchSizeW, fPatchSizeD, patch);
178  }
179  }
size_t fPatchSizeD
Definition: PointIdAlg.h:155
bool patchFromOriginalView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
size_t fCurrentScaledDrift
Definition: PointIdAlg.h:157
bool patchFromDownsampledView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
size_t fPatchSizeW
Definition: PointIdAlg.h:155
size_t fCurrentWireIdx
Definition: PointIdAlg.h:157
bool nnet::PointIdAlg::bufferPatch ( size_t  wire,
float  drift 
) const
inlineprivate

Definition at line 180 of file PointIdAlg.h.

181  {
182  return bufferPatch(wire, drift, fWireDriftPatch);
183  }
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:154
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float >> &patch) const
Definition: PointIdAlg.h:158
unsigned int img::DataProviderAlg::Cryo ( ) const
inlineinherited

Pool sum of pixels in a patch around the wire/drift pixel.

Definition at line 161 of file DataProviderAlg.h.

Referenced by nnet::TrainingDataAlg::collectVtxFlags().

161 { return fCryo; }
void nnet::PointIdAlg::deleteNNet ( )
inlineprivate

Definition at line 186 of file PointIdAlg.h.

Referenced by PointIdAlg(), and ~PointIdAlg().

187  {
188  if (fNNet) delete fNNet;
189  fNNet = 0;
190  }
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:152
std::vector<float> img::DataProviderAlg::downscale ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
inlineprotectedinherited

Definition at line 198 of file DataProviderAlg.h.

References img::DataProviderAlg::kMax, img::DataProviderAlg::kMaxMean, and img::DataProviderAlg::kMean.

Referenced by img::DataProviderAlg::patchFromOriginalView(), and img::DataProviderAlg::setWireData().

201  {
202  switch (fDownscaleMode) {
203  case img::DataProviderAlg::kMean: return downscaleMean(dst_size, adc, tick0);
204  case img::DataProviderAlg::kMaxMean: return downscaleMaxMean(dst_size, adc, tick0);
205  case img::DataProviderAlg::kMax: return downscaleMax(dst_size, adc, tick0);
206  }
207  throw cet::exception("img::DataProviderAlg") << "Downscale mode not supported." << std::endl;
208  }
std::vector< float > downscaleMaxMean(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
std::vector< float > downscaleMax(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
std::vector< float > downscaleMean(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
EDownscaleMode fDownscaleMode
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< float > img::DataProviderAlg::downscaleMax ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
protectedinherited

Definition at line 196 of file DataProviderAlg.cxx.

References img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDriftWindow, img::DataProviderAlgView::fLifetimeCorrFactors, and img::DataProviderAlg::scaleAdcSamples().

199 {
200  size_t kStop = dst_size;
201  std::vector<float> result(dst_size);
202  if (adc.size() < kStop) { kStop = adc.size(); }
203  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow) {
204  size_t k1 = k0 + fDriftWindow;
205 
206  float max_adc = adc[k0] * fAlgView.fLifetimeCorrFactors[k0 + tick0];
207  for (size_t k = k0 + 1; k < k1; ++k) {
208  float ak = adc[k] * fAlgView.fLifetimeCorrFactors[k + tick0];
209  if (ak > max_adc) max_adc = ak;
210  }
211  result[i] = max_adc;
212  }
213  scaleAdcSamples(result);
214  return result;
215 }
void scaleAdcSamples(std::vector< float > &values) const
DataProviderAlgView fAlgView
std::vector< float > fLifetimeCorrFactors
std::vector< float > img::DataProviderAlg::downscaleMaxMean ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
protectedinherited

Definition at line 217 of file DataProviderAlg.cxx.

References img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDriftWindow, img::DataProviderAlgView::fLifetimeCorrFactors, n, and img::DataProviderAlg::scaleAdcSamples().

220 {
221  size_t kStop = dst_size;
222  std::vector<float> result(dst_size);
223  if (adc.size() < kStop) { kStop = adc.size(); }
224  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow) {
225  size_t k1 = k0 + fDriftWindow;
226  size_t max_idx = k0;
227  float max_adc = adc[k0] * fAlgView.fLifetimeCorrFactors[k0 + tick0];
228  for (size_t k = k0 + 1; k < k1; ++k) {
229  float ak = adc[k] * fAlgView.fLifetimeCorrFactors[k + tick0];
230  if (ak > max_adc) {
231  max_adc = ak;
232  max_idx = k;
233  }
234  }
235 
236  size_t n = 1;
237  if (max_idx > 0) {
238  max_adc += adc[max_idx - 1] * fAlgView.fLifetimeCorrFactors[max_idx - 1 + tick0];
239  n++;
240  }
241  if (max_idx + 1 < adc.size()) {
242  max_adc += adc[max_idx + 1] * fAlgView.fLifetimeCorrFactors[max_idx + 1 + tick0];
243  n++;
244  }
245 
246  result[i] = max_adc / n;
247  }
248  scaleAdcSamples(result);
249  return result;
250 }
void scaleAdcSamples(std::vector< float > &values) const
DataProviderAlgView fAlgView
std::vector< float > fLifetimeCorrFactors
Char_t n[5]
std::vector< float > img::DataProviderAlg::downscaleMean ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
protectedinherited

Definition at line 252 of file DataProviderAlg.cxx.

References img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDriftWindow, img::DataProviderAlg::fDriftWindowInv, img::DataProviderAlgView::fLifetimeCorrFactors, and img::DataProviderAlg::scaleAdcSamples().

255 {
256  size_t kStop = dst_size;
257  std::vector<float> result(dst_size);
258  if (adc.size() < kStop) { kStop = adc.size(); }
259  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow) {
260  size_t k1 = k0 + fDriftWindow;
261 
262  float sum_adc = 0;
263  for (size_t k = k0; k < k1; ++k) {
264  if (k + tick0 < fAlgView.fLifetimeCorrFactors.size())
265  sum_adc += adc[k] * fAlgView.fLifetimeCorrFactors[k + tick0];
266  }
267  result[i] = sum_adc * fDriftWindowInv;
268  }
269  scaleAdcSamples(result);
270  return result;
271 }
void scaleAdcSamples(std::vector< float > &values) const
DataProviderAlgView fAlgView
std::vector< float > fLifetimeCorrFactors
unsigned int img::DataProviderAlg::DriftWindow ( ) const
inlineinherited

Definition at line 168 of file DataProviderAlg.h.

168 { return fDriftWindow; }
std::vector< float > nnet::PointIdAlg::flattenData2D ( std::vector< std::vector< float >> const &  patch)
static

Definition at line 309 of file PointIdAlg.cxx.

References d, and w.

310 {
311  std::vector<float> flat;
312  if (patch.empty() || patch.front().empty()) {
313  mf::LogError("DataProviderAlg") << "Patch is empty.";
314  return flat;
315  }
316 
317  flat.resize(patch.size() * patch.front().size());
318 
319  for (size_t w = 0, i = 0; w < patch.size(); ++w) {
320  auto const& wire = patch[w];
321  for (size_t d = 0; d < wire.size(); ++d, ++i) {
322  flat[i] = wire[d];
323  }
324  }
325 
326  return flat;
327 }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Float_t d
Definition: plot.C:235
Float_t w
Definition: plot.C:20
size_t img::DataProviderAlg::getAdcArea ( ) const
inlineinherited

Definition at line 153 of file DataProviderAlg.h.

References r.

153 { return fAdcAreaOverThr; }
double img::DataProviderAlg::getAdcSum ( ) const
inlineinherited

Definition at line 152 of file DataProviderAlg.h.

152 { return fAdcSumOverThr; }
size_t img::DataProviderAlg::getDriftIndex ( float  drift) const
inlineprotectedinherited

Definition at line 210 of file DataProviderAlg.h.

References lar::dump::vector().

Referenced by img::DataProviderAlg::poolMax().

211  {
212  if (fDownscaleFullView)
213  return (size_t)(drift * fDriftWindowInv);
214  else
215  return (size_t)drift;
216  }
std::vector<std::vector<float> > img::DataProviderAlg::getPatch ( size_t  wire,
float  drift,
size_t  patchSizeW,
size_t  patchSizeD 
) const
inlineinherited

Return patch of data centered on the wire and drift, witht the size in (downscaled) pixels givent with patchSizeW and patchSizeD. Pad with the zero-level calue if patch extends beyond the event projection.

Definition at line 122 of file DataProviderAlg.h.

126  {
127  bool ok = false;
128  std::vector<std::vector<float>> patch;
129  if (fDownscaleFullView) {
130  ok = patchFromDownsampledView(wire, drift, patchSizeW, patchSizeD, patch);
131  }
132  else {
133  ok = patchFromOriginalView(wire, drift, patchSizeW, patchSizeD, patch);
134  }
135 
136  if (ok) return patch;
137  throw cet::exception("img::DataProviderAlg") << "Patch filling failed." << std::endl;
138  }
bool patchFromOriginalView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
bool patchFromDownsampledView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
float img::DataProviderAlg::getPixelOrZero ( int  wire,
int  drift 
) const
inlineinherited

Return value from the ADC buffer, or zero if coordinates are out of the view; will scale the drift according to the downscale settings.

Definition at line 142 of file DataProviderAlg.h.

143  {
144  size_t didx = getDriftIndex(drift), widx = (size_t)wire;
145 
146  if ((widx < fAlgView.fWireDriftData.size()) && (didx < fAlgView.fNCachedDrifts)) {
147  return fAlgView.fWireDriftData[widx][didx];
148  }
149  return 0;
150  }
std::vector< std::vector< float > > fWireDriftData
DataProviderAlgView fAlgView
size_t getDriftIndex(float drift) const
bool nnet::PointIdAlg::isCurrentPatch ( unsigned int  wire,
float  drift 
) const

test if wire/drift coordinates point to the current patch (so maybe the cnn output does not need to be recalculated)

Definition at line 293 of file PointIdAlg.cxx.

References fCurrentScaledDrift, fCurrentWireIdx, img::DataProviderAlg::fDownscaleFullView, and img::DataProviderAlg::fDriftWindow.

294 {
295  if (fDownscaleFullView) {
296  size_t sd = (size_t)(drift / fDriftWindow);
297  if ((fCurrentWireIdx == wire) && (fCurrentScaledDrift == sd))
298  return true; // still within the current position
299  }
300  else {
301  if ((fCurrentWireIdx == wire) && (fCurrentScaledDrift == drift))
302  return true; // still within the current position
303  }
304 
305  return false; // not a current position
306 }
size_t fCurrentScaledDrift
Definition: PointIdAlg.h:157
size_t fCurrentWireIdx
Definition: PointIdAlg.h:157
bool nnet::PointIdAlg::isInsideFiducialRegion ( unsigned int  wire,
float  drift 
) const

Definition at line 330 of file PointIdAlg.cxx.

References img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDriftWindow, img::DataProviderAlgView::fNScaledDrifts, img::DataProviderAlgView::fNWires, fPatchSizeD, and fPatchSizeW.

Referenced by nnet::EmTrackClusterId2out::produce(), nnet::EmTrackClusterId::produce(), and nnet::EmTrackMichelId::produce().

331 {
332  size_t marginW = fPatchSizeW / 8; // fPatchSizeX/2 will make patch always completely filled
333  size_t marginD = fPatchSizeD / 8;
334 
335  size_t scaledDrift = (size_t)(drift / fDriftWindow);
336  if ((wire >= marginW) && (wire < fAlgView.fNWires - marginW) && (scaledDrift >= marginD) &&
337  (scaledDrift < fAlgView.fNScaledDrifts - marginD))
338  return true;
339  else
340  return false;
341 }
size_t fPatchSizeD
Definition: PointIdAlg.h:155
DataProviderAlgView fAlgView
size_t fPatchSizeW
Definition: PointIdAlg.h:155
bool nnet::PointIdAlg::isSamePatch ( unsigned int  wire1,
float  drift1,
unsigned int  wire2,
float  drift2 
) const

test if two wire/drift coordinates point to the same patch

Definition at line 276 of file PointIdAlg.cxx.

References img::DataProviderAlg::fDownscaleFullView, and img::DataProviderAlg::fDriftWindow.

280 {
281  if (fDownscaleFullView) {
282  size_t sd1 = (size_t)(drift1 / fDriftWindow);
283  size_t sd2 = (size_t)(drift2 / fDriftWindow);
284  if ((wire1 == wire2) && (sd1 == sd2)) return true; // the same position
285  }
286  else {
287  if ((wire1 == wire2) && ((size_t)drift1 == (size_t)drift2)) return true; // the same position
288  }
289 
290  return false; // not the same position
291 }
double img::DataProviderAlg::LifetimeCorrection ( detinfo::DetectorClocksData const &  clock_data,
detinfo::DetectorPropertiesData const &  det_prop,
double  tick 
) const
inlineinherited

Definition at line 173 of file DataProviderAlg.h.

176  {
177  return fCalorimetryAlg.LifetimeCorrection(clock_data, det_prop, tick);
178  }
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
calo::CalorimetryAlg fCalorimetryAlg
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
unsigned int img::DataProviderAlg::NCachedDrifts ( ) const
inlineinherited

Definition at line 167 of file DataProviderAlg.h.

167 { return fAlgView.fNCachedDrifts; }
DataProviderAlgView fAlgView
unsigned int img::DataProviderAlg::NScaledDrifts ( ) const
inlineinherited

Definition at line 166 of file DataProviderAlg.h.

Referenced by nnet::PointIdTrainingData::analyze().

166 { return fAlgView.fNScaledDrifts; }
DataProviderAlgView fAlgView
unsigned int img::DataProviderAlg::NWires ( ) const
inlineinherited

Definition at line 165 of file DataProviderAlg.h.

Referenced by nnet::PointIdTrainingData::analyze().

165 { return fAlgView.fNWires; }
DataProviderAlgView fAlgView
std::vector<std::string> const& nnet::PointIdAlg::outputLabels ( ) const
inline

network output labels

Definition at line 121 of file PointIdAlg.h.

References lar::dump::vector().

Referenced by nnet::EmTrackClusterId2out::produce(), nnet::EmTrackClusterId::produce(), and nnet::EmTrackMichelId::produce().

121 { return fNNetOutputs; }
std::vector< std::string > fNNetOutputs
Definition: PointIdAlg.h:151
std::vector<float> nnet::PointIdAlg::patchData1D ( ) const
inline

Definition at line 135 of file PointIdAlg.h.

136  {
138  } // flat vector made of the patch data, wire after wire
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:154
static std::vector< float > flattenData2D(std::vector< std::vector< float >> const &patch)
Definition: PointIdAlg.cxx:309
std::vector<std::vector<float> > const& nnet::PointIdAlg::patchData2D ( ) const
inline

Definition at line 134 of file PointIdAlg.h.

134 { return fWireDriftPatch; }
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:154
bool img::DataProviderAlg::patchFromDownsampledView ( size_t  wire,
float  drift,
size_t  size_w,
size_t  size_d,
std::vector< std::vector< float >> &  patch 
) const
protectedinherited

Definition at line 439 of file DataProviderAlg.cxx.

References d, img::DataProviderAlg::fAdcZero, img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDriftWindow, trkf::fill(), img::DataProviderAlgView::fWireDriftData, and w.

444 {
445  int halfSizeW = size_w / 2;
446  int halfSizeD = size_d / 2;
447 
448  int w0 = wire - halfSizeW;
449  int w1 = wire + halfSizeW;
450 
451  size_t sd = (size_t)(drift / fDriftWindow);
452  int d0 = sd - halfSizeD;
453  int d1 = sd + halfSizeD;
454 
455  int wsize = fAlgView.fWireDriftData.size();
456  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch) {
457  auto& dst = patch[wpatch];
458  if ((w >= 0) && (w < wsize)) {
459  auto& src = fAlgView.fWireDriftData[w];
460  int dsize = src.size();
461  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch) {
462  if ((d >= 0) && (d < dsize)) { dst[dpatch] = src[d]; }
463  else {
464  dst[dpatch] = fAdcZero;
465  }
466  }
467  }
468  else {
469  std::fill(dst.begin(), dst.end(), fAdcZero);
470  }
471  }
472 
473  return true;
474 }
std::vector< std::vector< float > > fWireDriftData
Float_t d
Definition: plot.C:235
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
DataProviderAlgView fAlgView
Float_t w
Definition: plot.C:20
bool img::DataProviderAlg::patchFromOriginalView ( size_t  wire,
float  drift,
size_t  size_w,
size_t  size_d,
std::vector< std::vector< float >> &  patch 
) const
protectedinherited

Definition at line 476 of file DataProviderAlg.cxx.

References d, img::DataProviderAlg::downscale(), img::DataProviderAlg::fAdcZero, img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDriftWindow, trkf::fill(), img::DataProviderAlgView::fWireDriftData, util::size(), tmp, and w.

481 {
482  int dsize = fDriftWindow * size_d;
483  int halfSizeW = size_w / 2;
484  int halfSizeD = dsize / 2;
485 
486  int w0 = wire - halfSizeW;
487  int w1 = wire + halfSizeW;
488 
489  int d0 = int(drift) - halfSizeD;
490  int d1 = int(drift) + halfSizeD;
491 
492  if (d0 < 0) d0 = 0;
493 
494  std::vector<float> tmp(dsize);
495  int wsize = fAlgView.fWireDriftData.size();
496  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch) {
497  if ((w >= 0) && (w < wsize)) {
498  auto& src = fAlgView.fWireDriftData[w];
499  int src_size = src.size();
500  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch) {
501  if ((d >= 0) && (d < src_size)) { tmp[dpatch] = src[d]; }
502  else {
503  tmp[dpatch] = fAdcZero;
504  }
505  }
506  }
507  else {
508  std::fill(tmp.begin(), tmp.end(), fAdcZero);
509  }
510  patch[wpatch] = downscale(patch[wpatch].size(), tmp, d0);
511  }
512 
513  return true;
514 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
Float_t tmp
Definition: plot.C:35
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Float_t d
Definition: plot.C:235
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
DataProviderAlgView fAlgView
Float_t w
Definition: plot.C:20
unsigned int img::DataProviderAlg::Plane ( ) const
inlineinherited
float img::DataProviderAlg::poolMax ( int  wire,
int  drift,
size_t  r = 0 
) const
inherited

Pool max value in a patch around the wire/drift pixel.

Definition at line 145 of file DataProviderAlg.cxx.

References col, d, img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDownscaleFullView, img::DataProviderAlg::fDriftWindow, img::DataProviderAlgView::fNCachedDrifts, img::DataProviderAlgView::fNWires, img::DataProviderAlgView::fWireDriftData, img::DataProviderAlg::getDriftIndex(), r, and w.

Referenced by pma::ProjectionMatchingAlg::validate_on_adc(), and pma::ProjectionMatchingAlg::validate_on_adc_test().

146 {
147  size_t rw = r, rd = r;
148  if (!fDownscaleFullView) { rd *= fDriftWindow; }
149 
150  size_t didx = getDriftIndex(drift);
151  int d0 = didx - rd;
152  if (d0 < 0) { d0 = 0; }
153  int d1 = didx + rd;
154  if (d1 >= (int)fAlgView.fNCachedDrifts) { d1 = fAlgView.fNCachedDrifts - 1; }
155 
156  int w0 = wire - rw;
157  if (w0 < 0) { w0 = 0; }
158  int w1 = wire + rw;
159  if (w1 >= (int)fAlgView.fNWires) { w1 = fAlgView.fNWires - 1; }
160 
161  float adc, max_adc = 0;
162  for (int w = w0; w <= w1; ++w) {
163  auto const* col = fAlgView.fWireDriftData[w].data();
164  for (int d = d0; d <= d1; ++d) {
165  adc = col[d];
166  if (adc > max_adc) { max_adc = adc; }
167  }
168  }
169 
170  return max_adc;
171 }
TRandom r
Definition: spectrum.C:23
std::vector< std::vector< float > > fWireDriftData
Int_t col[ntarg]
Definition: Style.C:29
Float_t d
Definition: plot.C:235
DataProviderAlgView fAlgView
Float_t w
Definition: plot.C:20
size_t getDriftIndex(float drift) const
float nnet::PointIdAlg::predictIdValue ( unsigned int  wire,
float  drift,
size_t  outIdx = 0 
) const

calculate single-value prediction (2-class probability) for [wire, drift] point

Definition at line 218 of file PointIdAlg.cxx.

References bufferPatch(), fNNet, fWireDriftPatch, and nnet::ModelInterface::Run().

219 {
220  float result = 0.;
221 
222  if (!bufferPatch(wire, drift)) {
223  mf::LogError("PointIdAlg") << "Patch buffering failed.";
224  return result;
225  }
226 
227  if (fNNet) {
228  auto out = fNNet->Run(fWireDriftPatch);
229  if (!out.empty()) { result = out[outIdx]; }
230  else {
231  mf::LogError("PointIdAlg") << "Problem with applying model to input.";
232  }
233  }
234 
235  return result;
236 }
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:154
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float >> &patch) const
Definition: PointIdAlg.h:158
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
virtual std::vector< float > Run(std::vector< std::vector< float >> const &inp2d)=0
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:152
std::vector< float > nnet::PointIdAlg::predictIdVector ( unsigned int  wire,
float  drift 
) const

calculate multi-class probabilities for [wire, drift] point

Definition at line 239 of file PointIdAlg.cxx.

References bufferPatch(), fNNet, fWireDriftPatch, and nnet::ModelInterface::Run().

Referenced by nnet::ParticleDecayId::DetectDecay().

240 {
241  std::vector<float> result;
242 
243  if (!bufferPatch(wire, drift)) {
244  mf::LogError("PointIdAlg") << "Patch buffering failed.";
245  return result;
246  }
247 
248  if (fNNet) {
249  result = fNNet->Run(fWireDriftPatch);
250  if (result.empty()) { mf::LogError("PointIdAlg") << "Problem with applying model to input."; }
251  }
252 
253  return result;
254 }
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:154
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float >> &patch) const
Definition: PointIdAlg.h:158
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
virtual std::vector< float > Run(std::vector< std::vector< float >> const &inp2d)=0
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:152
std::vector< std::vector< float > > nnet::PointIdAlg::predictIdVectors ( std::vector< std::pair< unsigned int, float >>  points) const

Definition at line 257 of file PointIdAlg.cxx.

References bufferPatch(), fNNet, fPatchSizeD, fPatchSizeW, and nnet::ModelInterface::Run().

Referenced by nnet::EmTrackClusterId2out::produce(), nnet::EmTrackClusterId::produce(), and nnet::EmTrackMichelId::produce().

259 {
260  if (points.empty() || !fNNet) { return std::vector<std::vector<float>>(); }
261 
262  std::vector<std::vector<std::vector<float>>> inps(
263  points.size(), std::vector<std::vector<float>>(fPatchSizeW, std::vector<float>(fPatchSizeD)));
264  for (size_t i = 0; i < points.size(); ++i) {
265  unsigned int wire = points[i].first;
266  float drift = points[i].second;
267  if (!bufferPatch(wire, drift, inps[i])) {
268  throw cet::exception("PointIdAlg") << "Patch buffering failed" << std::endl;
269  }
270  }
271 
272  return fNNet->Run(inps);
273 }
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float >> &patch) const
Definition: PointIdAlg.h:158
virtual std::vector< float > Run(std::vector< std::vector< float >> const &inp2d)=0
size_t fPatchSizeD
Definition: PointIdAlg.h:155
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:152
size_t fPatchSizeW
Definition: PointIdAlg.h:155
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void nnet::PointIdAlg::resizePatch ( )
private

Definition at line 210 of file PointIdAlg.cxx.

References fPatchSizeD, fPatchSizeW, fWireDriftPatch, and r.

Referenced by PointIdAlg().

211 {
213  for (auto& r : fWireDriftPatch)
214  r.resize(fPatchSizeD);
215 }
TRandom r
Definition: spectrum.C:23
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:154
size_t fPatchSizeD
Definition: PointIdAlg.h:155
size_t fPatchSizeW
Definition: PointIdAlg.h:155
img::DataProviderAlgView img::DataProviderAlg::resizeView ( detinfo::DetectorClocksData const &  clock_data,
detinfo::DetectorPropertiesData const &  det_prop,
size_t  wires,
size_t  drifts 
)
protectedvirtualinherited

Reimplemented in nnet::TrainingDataAlg.

Definition at line 114 of file DataProviderAlg.cxx.

References img::DataProviderAlg::fAdcZero, img::DataProviderAlg::fCalibrateLifetime, img::DataProviderAlg::fCalorimetryAlg, img::DataProviderAlg::fDownscaleFullView, img::DataProviderAlg::fDriftWindow, img::DataProviderAlgView::fLifetimeCorrFactors, img::DataProviderAlgView::fNCachedDrifts, img::DataProviderAlgView::fNDrifts, img::DataProviderAlgView::fNScaledDrifts, img::DataProviderAlgView::fNWires, img::DataProviderAlgView::fWireChannels, img::DataProviderAlgView::fWireDriftData, raw::InvalidChannelID, and calo::CalorimetryAlg::LifetimeCorrection().

Referenced by nnet::TrainingDataAlg::resizeView(), and img::DataProviderAlg::setWireDriftData().

119 {
121  result.fNWires = wires;
122  result.fNDrifts = drifts;
123  result.fNScaledDrifts = drifts / fDriftWindow;
124  result.fNCachedDrifts = fDownscaleFullView ? result.fNScaledDrifts : drifts;
125 
126  result.fWireChannels.resize(wires, raw::InvalidChannelID);
127 
128  result.fWireDriftData.resize(wires, std::vector<float>(result.fNCachedDrifts, fAdcZero));
129 
130  result.fLifetimeCorrFactors.resize(drifts);
131  if (fCalibrateLifetime) {
132  for (size_t t = 0; t < drifts; ++t) {
133  result.fLifetimeCorrFactors[t] = fCalorimetryAlg.LifetimeCorrection(clock_data, det_prop, t);
134  }
135  }
136  else {
137  for (size_t t = 0; t < drifts; ++t) {
138  result.fLifetimeCorrFactors[t] = 1.0;
139  }
140  }
141  return result;
142 }
std::vector< std::vector< float > > fWireDriftData
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:31
std::vector< raw::ChannelID_t > fWireChannels
calo::CalorimetryAlg fCalorimetryAlg
std::vector< float > fLifetimeCorrFactors
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
std::optional< std::vector< float > > img::DataProviderAlg::setWireData ( std::vector< float > const &  adc,
size_t  wireIdx 
) const
protectedinherited

Definition at line 273 of file DataProviderAlg.cxx.

References img::DataProviderAlg::downscale(), img::DataProviderAlg::fAlgView, img::DataProviderAlg::fDownscaleFullView, and img::DataProviderAlgView::fWireDriftData.

Referenced by img::DataProviderAlg::setWireDriftData().

275 {
276  if (wireIdx >= fAlgView.fWireDriftData.size()) { return std::nullopt; }
277  auto& wData = fAlgView.fWireDriftData[wireIdx];
278 
279  if (fDownscaleFullView) {
280  if (!adc.empty()) { return downscale(wData.size(), adc, 0); }
281  return std::nullopt;
282  }
283  if (adc.empty()) { return std::nullopt; }
284  if (adc.size() <= wData.size()) { return adc; }
285  return std::vector<float>(adc.begin(), adc.begin() + wData.size());
286 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
DataProviderAlgView fAlgView
bool img::DataProviderAlg::setWireDriftData ( const detinfo::DetectorClocksData clock_data,
const detinfo::DetectorPropertiesData det_prop,
const std::vector< recob::Wire > &  wires,
unsigned int  plane,
unsigned int  tpc,
unsigned int  cryo 
)
inherited

Definition at line 289 of file DataProviderAlg.cxx.

References img::DataProviderAlg::addCoherentNoise(), img::DataProviderAlg::addWhiteNoise(), img::DataProviderAlg::applyBlur(), geo::GeometryCore::ChannelToWire(), img::DataProviderAlg::fAdcAreaOverThr, img::DataProviderAlg::fAdcSumOverThr, img::DataProviderAlg::fAdcSumThr, img::DataProviderAlg::fAlgView, img::DataProviderAlg::fCryo, img::DataProviderAlg::fGeometry, img::DataProviderAlg::fPlane, img::DataProviderAlg::fTPC, img::DataProviderAlgView::fWireChannels, img::DataProviderAlgView::fWireDriftData, detinfo::DetectorPropertiesData::NumberTimeSamples(), geo::GeometryCore::Nwires(), img::DataProviderAlg::Plane(), img::DataProviderAlg::resizeView(), and img::DataProviderAlg::setWireData().

Referenced by nnet::ParticleDecayId::DetectDecay(), nnet::EmTrackClusterId2out::produce(), nnet::EmTrackClusterId::produce(), nnet::EmTrackMichelId::produce(), nnet::TrainingDataAlg::setDataEventData(), and nnet::TrainingDataAlg::setEventData().

295 {
296  mf::LogInfo("DataProviderAlg") << "Create image for cryo:" << cryo << " tpc:" << tpc
297  << " plane:" << plane;
298 
299  fCryo = cryo;
300  fTPC = tpc;
301  fPlane = plane;
302 
303  fAdcSumOverThr = 0;
304  fAdcAreaOverThr = 0;
305 
306  size_t nwires = fGeometry->Nwires({cryo, tpc, plane});
307  size_t ndrifts = det_prop.NumberTimeSamples();
308 
309  fAlgView = resizeView(clock_data, det_prop, nwires, ndrifts);
310 
311  auto const& channelStatus =
313 
314  bool allWrong = true;
315  for (auto const& wire : wires) {
316  auto wireChannelNumber = wire.Channel();
317  if (!channelStatus.IsGood(wireChannelNumber)) { continue; }
318 
319  size_t w_idx = 0;
320  for (auto const& id : fGeometry->ChannelToWire(wireChannelNumber)) {
321  if ((id.Plane == plane) && (id.TPC == tpc) && (id.Cryostat == cryo)) {
322  w_idx = id.Wire;
323 
324  auto adc = wire.Signal();
325  if (adc.size() < ndrifts) {
326  mf::LogWarning("DataProviderAlg") << "Wire ADC vector size lower than NumberTimeSamples.";
327  continue; // not critical, maybe other wires are OK, so continue
328  }
329  auto wire_data = setWireData(adc, w_idx);
330  if (!wire_data) {
331  mf::LogWarning("DataProviderAlg") << "Wire data not set.";
332  continue; // also not critical, try to set other wires
333  }
334  fAlgView.fWireDriftData[w_idx] = *wire_data;
335  for (auto v : adc) {
336  if (v >= fAdcSumThr) {
337  fAdcSumOverThr += v;
338  fAdcAreaOverThr++;
339  }
340  }
341 
342  fAlgView.fWireChannels[w_idx] = wireChannelNumber;
343  allWrong = false;
344  }
345  }
346  }
347  if (allWrong) {
348  mf::LogError("DataProviderAlg")
349  << "Wires data not set in the cryo:" << cryo << " tpc:" << tpc << " plane:" << plane;
350  return false;
351  }
352 
353  applyBlur();
354  addWhiteNoise();
356 
357  return true;
358 }
geo::GeometryCore const * fGeometry
std::optional< std::vector< float > > setWireData(std::vector< float > const &adc, size_t wireIdx) const
std::vector< std::vector< float > > fWireDriftData
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
virtual DataProviderAlgView resizeView(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, size_t wires, size_t drifts)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
unsigned int Plane() const
std::vector< raw::ChannelID_t > fWireChannels
DataProviderAlgView fAlgView
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
unsigned int Nwires(PlaneID const &planeid) const
Returns the total number of wires in the specified plane.
unsigned int img::DataProviderAlg::TPC ( ) const
inlineinherited

Definition at line 162 of file DataProviderAlg.h.

Referenced by nnet::TrainingDataAlg::collectVtxFlags().

162 { return fTPC; }
std::vector<float> const& img::DataProviderAlg::wireData ( size_t  widx) const
inlineinherited

Definition at line 117 of file DataProviderAlg.h.

Referenced by nnet::PointIdTrainingData::analyze().

117 { return fAlgView.fWireDriftData[widx]; }
std::vector< std::vector< float > > fWireDriftData
DataProviderAlgView fAlgView
float img::DataProviderAlg::ZeroLevel ( ) const
inlineinherited

Level of zero ADC after scaling.

Definition at line 171 of file DataProviderAlg.h.

171 { return fAdcZero; }

Member Data Documentation

calo::CalorimetryAlg img::DataProviderAlg::fCalorimetryAlg
protectedinherited
size_t nnet::PointIdAlg::fCurrentScaledDrift
mutableprivate

Definition at line 157 of file PointIdAlg.h.

Referenced by isCurrentPatch().

size_t nnet::PointIdAlg::fCurrentWireIdx
mutableprivate

Definition at line 157 of file PointIdAlg.h.

Referenced by isCurrentPatch().

EDownscaleMode img::DataProviderAlg::fDownscaleMode
protectedinherited

Definition at line 182 of file DataProviderAlg.h.

Referenced by img::DataProviderAlg::DataProviderAlg().

float img::DataProviderAlg::fDriftWindowInv
protectedinherited
geo::GeometryCore const* img::DataProviderAlg::fGeometry
protectedinherited
nnet::ModelInterface* nnet::PointIdAlg::fNNet
private

Definition at line 152 of file PointIdAlg.h.

Referenced by PointIdAlg(), predictIdValue(), predictIdVector(), and predictIdVectors().

std::string nnet::PointIdAlg::fNNetModelFilePath
private

Definition at line 150 of file PointIdAlg.h.

Referenced by PointIdAlg().

std::vector<std::string> nnet::PointIdAlg::fNNetOutputs
private

Definition at line 151 of file PointIdAlg.h.

Referenced by PointIdAlg().

size_t nnet::PointIdAlg::fPatchSizeD
private

Definition at line 155 of file PointIdAlg.h.

Referenced by isInsideFiducialRegion(), predictIdVectors(), and resizePatch().

size_t nnet::PointIdAlg::fPatchSizeW
private

Definition at line 155 of file PointIdAlg.h.

Referenced by isInsideFiducialRegion(), predictIdVectors(), and resizePatch().

std::vector<std::vector<float> > nnet::PointIdAlg::fWireDriftPatch
mutableprivate

Definition at line 154 of file PointIdAlg.h.

Referenced by predictIdValue(), predictIdVector(), and resizePatch().


The documentation for this class was generated from the following files: