LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 (void) override
 
std::vector< std::string > const & outputLabels (void) 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 (void) const
 
std::vector< float > patchData1D (void) 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 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 (void) const
 
size_t getAdcArea (void) const
 
float poolMax (int wire, int drift, size_t r=0) const
 Pool max value in a patch around the wire/drift pixel. More...
 
float poolSum (int wire, int drift, size_t r=0) const
 Pool sum of pixels in a patch around the wire/drift pixel. More...
 
unsigned int Cryo (void) const
 
unsigned int TPC (void) const
 
unsigned int Plane (void) const
 
unsigned int NWires (void) const
 
unsigned int NScaledDrifts (void) const
 
unsigned int NCachedDrifts (void) const
 
unsigned int DriftWindow (void) const
 
float ZeroLevel (void) const
 Level of zero ADC after scaling. More...
 
double LifetimeCorrection (double tick) const
 

Static Public Member Functions

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

Protected Member Functions

void downscaleMax (std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
 
void downscaleMaxMean (std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
 
void downscaleMean (std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
 
void downscale (std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
 
size_t getDriftIndex (float drift) const
 
bool setWireData (std::vector< float > const &adc, size_t wireIdx)
 
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 void resizeView (size_t wires, size_t drifts)
 

Protected Attributes

unsigned int fCryo
 
unsigned int fTPC
 
unsigned int fPlane
 
unsigned int fNWires
 
unsigned int fNDrifts
 
unsigned int fNScaledDrifts
 
unsigned int fNCachedDrifts
 
std::vector< raw::ChannelID_tfWireChannels
 
std::vector< std::vector< float > > fWireDriftData
 
std::vector< float > fLifetimeCorrFactors
 
EDownscaleMode fDownscaleMode
 
size_t fDriftWindow
 
bool fDownscaleFullView
 
float fDriftWindowInv
 
calo::CalorimetryAlg fCalorimetryAlg
 
geo::GeometryCore const * fGeometry
 
detinfo::DetectorProperties const * fDetProp
 

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)
 
void deleteNNet (void)
 

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 89 of file PointIdAlg.h.

Member Enumeration Documentation

Enumerator
kMax 
kMaxMean 
kMean 

Definition at line 49 of file DataProviderAlg.h.

Constructor & Destructor Documentation

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

Definition at line 114 of file PointIdAlg.h.

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

Definition at line 154 of file PointIdAlg.cxx.

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

154  : img::DataProviderAlg(config),
155  fNNet(0),
156  fPatchSizeW(config.PatchSizeW()), fPatchSizeD(config.PatchSizeD()),
157  fCurrentWireIdx(99999), fCurrentScaledDrift(99999)
158 {
159  fNNetModelFilePath = config.NNetModelFile();
160  fNNetOutputs = config.NNetOutputs();
161 
162  deleteNNet();
163 
164  if ((fNNetModelFilePath.length() > 5) &&
165  (fNNetModelFilePath.compare(fNNetModelFilePath.length() - 5, 5, ".nnet") == 0))
166  {
168  }
169  else if ((fNNetModelFilePath.length() > 3) &&
170  (fNNetModelFilePath.compare(fNNetModelFilePath.length() - 3, 3, ".pb") == 0))
171  {
173  }
174  else
175  {
176  mf::LogError("PointIdAlg") << "File name extension not supported.";
177  }
178 
179  if (!fNNet) { throw cet::exception("nnet::PointIdAlg") << "Loading model from file failed."; }
180 
181  resizePatch();
182 }
void resizePatch(void)
Definition: PointIdAlg.cxx:191
void deleteNNet(void)
Definition: PointIdAlg.h:181
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< std::string > fNNetOutputs
Definition: PointIdAlg.h:149
size_t fPatchSizeD
Definition: PointIdAlg.h:153
size_t fCurrentScaledDrift
Definition: PointIdAlg.h:155
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:150
size_t fPatchSizeW
Definition: PointIdAlg.h:153
std::string fNNetModelFilePath
Definition: PointIdAlg.h:148
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
size_t fCurrentWireIdx
Definition: PointIdAlg.h:155
nnet::PointIdAlg::~PointIdAlg ( void  )
override

Definition at line 185 of file PointIdAlg.cxx.

References deleteNNet().

186 {
187  deleteNNet();
188 }
void deleteNNet(void)
Definition: PointIdAlg.h:181

Member Function Documentation

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

Definition at line 156 of file PointIdAlg.h.

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

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

Definition at line 178 of file PointIdAlg.h.

References bufferPatch().

Referenced by bufferPatch().

178 { return bufferPatch(wire, drift, fWireDriftPatch); }
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float > > &patch) const
Definition: PointIdAlg.h:156
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:152
unsigned int img::DataProviderAlg::Cryo ( void  ) const
inlineinherited

Definition at line 157 of file DataProviderAlg.h.

References img::DataProviderAlg::fCryo.

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

Definition at line 181 of file PointIdAlg.h.

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

181 { if (fNNet) delete fNNet; fNNet = 0; }
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:150
void img::DataProviderAlg::downscale ( std::vector< float > &  dst,
std::vector< float > const &  adc,
size_t  tick0 
) const
inlineprotectedinherited

Definition at line 189 of file DataProviderAlg.h.

References img::DataProviderAlg::downscaleMax(), img::DataProviderAlg::downscaleMaxMean(), img::DataProviderAlg::downscaleMean(), img::DataProviderAlg::kMax, img::DataProviderAlg::kMaxMean, and img::DataProviderAlg::kMean.

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

190  {
191  switch (fDownscaleMode)
192  {
193  case img::DataProviderAlg::kMean: downscaleMean(dst, adc, tick0); break;
194  case img::DataProviderAlg::kMaxMean: downscaleMaxMean(dst, adc, tick0); break;
195  case img::DataProviderAlg::kMax: downscaleMax(dst, adc, tick0); break;
196  default:throw cet::exception("img::DataProviderAlg") << "Downscale mode not supported." << std::endl; break;
197  }
198  }
void downscaleMaxMean(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
void downscaleMax(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
EDownscaleMode fDownscaleMode
void downscaleMean(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void img::DataProviderAlg::downscaleMax ( std::vector< float > &  dst,
std::vector< float > const &  adc,
size_t  tick0 
) const
protectedinherited

Definition at line 182 of file DataProviderAlg.cxx.

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

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

183 {
184  size_t kStop = dst.size();
185  if (adc.size() < kStop) { kStop = adc.size(); }
186  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow)
187  {
188  size_t k1 = k0 + fDriftWindow;
189 
190  float max_adc = adc[k0] * fLifetimeCorrFactors[k0 + tick0];
191  for (size_t k = k0 + 1; k < k1; ++k)
192  {
193  float ak = adc[k] * fLifetimeCorrFactors[k + tick0];
194  if (ak > max_adc) max_adc = ak;
195  }
196 
197  dst[i] = max_adc;
198  }
199  scaleAdcSamples(dst);
200 }
std::vector< float > fLifetimeCorrFactors
void scaleAdcSamples(std::vector< float > &values) const
void img::DataProviderAlg::downscaleMaxMean ( std::vector< float > &  dst,
std::vector< float > const &  adc,
size_t  tick0 
) const
protectedinherited

Definition at line 202 of file DataProviderAlg.cxx.

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

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

203 {
204  size_t kStop = dst.size();
205  if (adc.size() < kStop) { kStop = adc.size(); }
206  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow)
207  {
208  size_t k1 = k0 + fDriftWindow;
209 
210  size_t max_idx = k0;
211  float max_adc = adc[k0] * fLifetimeCorrFactors[k0 + tick0];
212  for (size_t k = k0 + 1; k < k1; ++k)
213  {
214  float ak = adc[k] * fLifetimeCorrFactors[k + tick0];
215  if (ak > max_adc) { max_adc = ak; max_idx = k; }
216  }
217 
218  size_t n = 1;
219  if (max_idx > 0) { max_adc += adc[max_idx - 1] * fLifetimeCorrFactors[max_idx - 1 + tick0]; n++; }
220  if (max_idx + 1 < adc.size()) { max_adc += adc[max_idx + 1] * fLifetimeCorrFactors[max_idx + 1 + tick0]; n++; }
221 
222  dst[i] = max_adc / n;
223  }
224  scaleAdcSamples(dst);
225 }
std::vector< float > fLifetimeCorrFactors
void scaleAdcSamples(std::vector< float > &values) const
Char_t n[5]
void img::DataProviderAlg::downscaleMean ( std::vector< float > &  dst,
std::vector< float > const &  adc,
size_t  tick0 
) const
protectedinherited

Definition at line 227 of file DataProviderAlg.cxx.

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

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

228 {
229  size_t kStop = dst.size();
230  if (adc.size() < kStop) { kStop = adc.size(); }
231  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow)
232  {
233  size_t k1 = k0 + fDriftWindow;
234 
235  float sum_adc = 0;
236  for (size_t k = k0; k < k1; ++k)
237  {
238  sum_adc += adc[k] * fLifetimeCorrFactors[k + tick0];
239  }
240  dst[i] = sum_adc * fDriftWindowInv;
241  }
242  scaleAdcSamples(dst);
243 }
std::vector< float > fLifetimeCorrFactors
void scaleAdcSamples(std::vector< float > &values) const
unsigned int img::DataProviderAlg::DriftWindow ( void  ) const
inlineinherited

Definition at line 164 of file DataProviderAlg.h.

References img::DataProviderAlg::fDriftWindow.

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

Definition at line 303 of file PointIdAlg.cxx.

References d, and w.

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

Definition at line 148 of file DataProviderAlg.h.

References img::DataProviderAlg::fAdcSumOverThr.

148 { return fAdcSumOverThr; }
size_t img::DataProviderAlg::getDriftIndex ( float  drift) const
inlineprotectedinherited
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 114 of file DataProviderAlg.h.

References img::DataProviderAlg::fDownscaleFullView, img::DataProviderAlg::patchFromDownsampledView(), and img::DataProviderAlg::patchFromOriginalView().

115  {
116  bool ok = false;
117  std::vector< std::vector<float> > patch;
118  if (fDownscaleFullView)
119  {
120  ok = patchFromDownsampledView(wire, drift, patchSizeW, patchSizeD, patch);
121  }
122  else
123  {
124  ok = patchFromOriginalView(wire, drift, patchSizeW, patchSizeD, patch);
125  }
126 
127  if (ok) return patch;
128  else
129  {
130  throw cet::exception("img::DataProviderAlg") << "Patch filling failed." << std::endl;
131  }
132  }
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
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 136 of file DataProviderAlg.h.

References img::DataProviderAlg::fNCachedDrifts, img::DataProviderAlg::fWireDriftData, and img::DataProviderAlg::getDriftIndex().

137  {
138  size_t didx = getDriftIndex(drift), widx = (size_t)wire;
139 
140  if ((widx < fWireDriftData.size()) &&
141  (didx < fNCachedDrifts))
142  {
143  return fWireDriftData[widx][didx];
144  }
145  else { return 0; }
146  }
std::vector< std::vector< float > > fWireDriftData
unsigned int fNCachedDrifts
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 285 of file PointIdAlg.cxx.

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

286 {
287  if (fDownscaleFullView)
288  {
289  size_t sd = (size_t)(drift / fDriftWindow);
290  if ((fCurrentWireIdx == wire) && (fCurrentScaledDrift == sd))
291  return true; // still within the current position
292  }
293  else
294  {
295  if ((fCurrentWireIdx == wire) && (fCurrentScaledDrift == drift))
296  return true; // still within the current position
297  }
298 
299  return false; // not a current position
300 }
size_t fCurrentScaledDrift
Definition: PointIdAlg.h:155
size_t fCurrentWireIdx
Definition: PointIdAlg.h:155
bool nnet::PointIdAlg::isInsideFiducialRegion ( unsigned int  wire,
float  drift 
) const

Definition at line 327 of file PointIdAlg.cxx.

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

328 {
329  size_t marginW = fPatchSizeW / 8; // fPatchSizeX/2 will make patch always completely filled
330  size_t marginD = fPatchSizeD / 8;
331 
332  size_t scaledDrift = (size_t)(drift / fDriftWindow);
333  if ((wire >= marginW) && (wire < fNWires - marginW) &&
334  (scaledDrift >= marginD) && (scaledDrift < fNScaledDrifts - marginD)) return true;
335  else return false;
336 }
size_t fPatchSizeD
Definition: PointIdAlg.h:153
unsigned int fNScaledDrifts
size_t fPatchSizeW
Definition: PointIdAlg.h:153
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 267 of file PointIdAlg.cxx.

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

268 {
269  if (fDownscaleFullView)
270  {
271  size_t sd1 = (size_t)(drift1 / fDriftWindow);
272  size_t sd2 = (size_t)(drift2 / fDriftWindow);
273  if ((wire1 == wire2) && (sd1 == sd2))
274  return true; // the same position
275  }
276  else
277  {
278  if ((wire1 == wire2) && ((size_t)drift1 == (size_t)drift2))
279  return true; // the same position
280  }
281 
282  return false; // not the same position
283 }
double img::DataProviderAlg::LifetimeCorrection ( double  tick) const
inlineinherited

Definition at line 169 of file DataProviderAlg.h.

References img::DataProviderAlg::fCalorimetryAlg, and calo::CalorimetryAlg::LifetimeCorrection().

169 { return fCalorimetryAlg.LifetimeCorrection(tick); }
calo::CalorimetryAlg fCalorimetryAlg
double LifetimeCorrection(double time, double T0=0) const
unsigned int img::DataProviderAlg::NCachedDrifts ( void  ) const
inlineinherited

Definition at line 163 of file DataProviderAlg.h.

References img::DataProviderAlg::fNCachedDrifts.

163 { return fNCachedDrifts; }
unsigned int fNCachedDrifts
unsigned int img::DataProviderAlg::NScaledDrifts ( void  ) const
inlineinherited

Definition at line 162 of file DataProviderAlg.h.

References img::DataProviderAlg::fNScaledDrifts.

162 { return fNScaledDrifts; }
unsigned int fNScaledDrifts
unsigned int img::DataProviderAlg::NWires ( void  ) const
inlineinherited

Definition at line 161 of file DataProviderAlg.h.

References img::DataProviderAlg::fNWires.

161 { return fNWires; }
std::vector< std::string > const& nnet::PointIdAlg::outputLabels ( void  ) const
inline

network output labels

Definition at line 123 of file PointIdAlg.h.

References lar::dump::vector().

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

Definition at line 136 of file PointIdAlg.h.

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

Definition at line 135 of file PointIdAlg.h.

135 { return fWireDriftPatch; }
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:152
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 400 of file DataProviderAlg.cxx.

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

Referenced by img::DataProviderAlg::getDriftIndex(), and img::DataProviderAlg::getPatch().

402 {
403  int halfSizeW = size_w / 2;
404  int halfSizeD = size_d / 2;
405 
406  int w0 = wire - halfSizeW;
407  int w1 = wire + halfSizeW;
408 
409  size_t sd = (size_t)(drift / fDriftWindow);
410  int d0 = sd - halfSizeD;
411  int d1 = sd + halfSizeD;
412 
413  int wsize = fWireDriftData.size();
414  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch)
415  {
416  auto & dst = patch[wpatch];
417  if ((w >= 0) && (w < wsize))
418  {
419  auto & src = fWireDriftData[w];
420  int dsize = src.size();
421  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch)
422  {
423  if ((d >= 0) && (d < dsize))
424  {
425  dst[dpatch] = src[d];
426  }
427  else
428  {
429  dst[dpatch] = fAdcZero;
430  }
431  }
432  }
433  else
434  {
435  std::fill(dst.begin(), dst.end(), fAdcZero);
436  }
437  }
438 
439  return true;
440 }
std::vector< std::vector< float > > fWireDriftData
Float_t d
Definition: plot.C:237
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
Float_t w
Definition: plot.C:23
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 442 of file DataProviderAlg.cxx.

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

Referenced by img::DataProviderAlg::getDriftIndex(), and img::DataProviderAlg::getPatch().

444 {
445  int dsize = fDriftWindow * size_d;
446  int halfSizeW = size_w / 2;
447  int halfSizeD = dsize / 2;
448 
449  int w0 = wire - halfSizeW;
450  int w1 = wire + halfSizeW;
451 
452  int d0 = drift - halfSizeD;
453  int d1 = drift + halfSizeD;
454 
455  std::vector<float> tmp(dsize);
456  int wsize = fWireDriftData.size();
457  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch)
458  {
459  if ((w >= 0) && (w < wsize))
460  {
461  auto & src = fWireDriftData[w];
462  int src_size = src.size();
463  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch)
464  {
465  if ((d >= 0) && (d < src_size))
466  {
467  tmp[dpatch] = src[d];
468  }
469  else
470  {
471  tmp[dpatch] = fAdcZero;
472  }
473  }
474  }
475  else
476  {
477  std::fill(tmp.begin(), tmp.end(), fAdcZero);
478  }
479 
480  downscale(patch[wpatch], tmp, d0);
481  }
482 
483  return true;
484 }
std::vector< std::vector< float > > fWireDriftData
Float_t tmp
Definition: plot.C:37
Float_t d
Definition: plot.C:237
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
void downscale(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
Float_t w
Definition: plot.C:23
unsigned int img::DataProviderAlg::Plane ( void  ) 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 133 of file DataProviderAlg.cxx.

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

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

134 {
135  size_t rw = r, rd = r;
136  if (!fDownscaleFullView) { rd *= fDriftWindow; }
137 
138  size_t didx = getDriftIndex(drift);
139  int d0 = didx - rd; if (d0 < 0) { d0 = 0; }
140  int d1 = didx + rd; if (d1 >= (int)fNCachedDrifts) { d1 = fNCachedDrifts - 1; }
141 
142  int w0 = wire - rw; if (w0 < 0) { w0 = 0; }
143  int w1 = wire + rw; if (w1 >= (int)fNWires) { w1 = fNWires - 1; }
144 
145  float adc, max_adc = 0;
146  for (int w = w0; w <= w1; ++w)
147  {
148  auto const * col = fWireDriftData[w].data();
149  for (int d = d0; d <= d1; ++d)
150  {
151  adc = col[d]; if (adc > max_adc) { max_adc = adc; }
152  }
153  }
154 
155  return max_adc;
156 }
std::vector< std::vector< float > > fWireDriftData
unsigned int fNCachedDrifts
Int_t col[ntarg]
Definition: Style.C:29
Float_t d
Definition: plot.C:237
Float_t w
Definition: plot.C:23
size_t getDriftIndex(float drift) const
float img::DataProviderAlg::poolSum ( int  wire,
int  drift,
size_t  r = 0 
) const
inherited

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

Definition at line 159 of file DataProviderAlg.cxx.

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

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

160 {
161  size_t rw = r, rd = r;
162  if (!fDownscaleFullView) { rd *= fDriftWindow; }
163 
164  size_t didx = getDriftIndex(drift);
165  int d0 = didx - rd; if (d0 < 0) { d0 = 0; }
166  int d1 = didx + rd; if (d1 >= (int)fNCachedDrifts) { d1 = fNCachedDrifts - 1; }
167 
168  int w0 = wire - rw; if (w0 < 0) { w0 = 0; }
169  int w1 = wire + rw; if (w1 >= (int)fNWires) { w1 = fNWires - 1; }
170 
171  float sum = 0;
172  for (int w = w0; w <= w1; ++w)
173  {
174  auto const * col = fWireDriftData[w].data();
175  for (int d = d0; d <= d1; ++d) { sum += col[d]; }
176  }
177 
178  return sum;
179 }
std::vector< std::vector< float > > fWireDriftData
unsigned int fNCachedDrifts
Int_t col[ntarg]
Definition: Style.C:29
Float_t d
Definition: plot.C:237
Float_t w
Definition: plot.C:23
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 198 of file PointIdAlg.cxx.

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

199 {
200  float result = 0.;
201 
202  if (!bufferPatch(wire, drift))
203  {
204  mf::LogError("PointIdAlg") << "Patch buffering failed.";
205  return result;
206  }
207 
208  if (fNNet)
209  {
210  auto out = fNNet->Run(fWireDriftPatch);
211  if (!out.empty()) { result = out[outIdx]; }
212  else
213  {
214  mf::LogError("PointIdAlg") << "Problem with applying model to input.";
215  }
216  }
217 
218  return result;
219 }
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float > > &patch) const
Definition: PointIdAlg.h:156
virtual std::vector< float > Run(std::vector< std::vector< float > > const &inp2d)=0
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:152
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:150
std::vector< float > nnet::PointIdAlg::predictIdVector ( unsigned int  wire,
float  drift 
) const

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

Definition at line 222 of file PointIdAlg.cxx.

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

223 {
224  std::vector<float> result;
225 
226  if (!bufferPatch(wire, drift))
227  {
228  mf::LogError("PointIdAlg") << "Patch buffering failed.";
229  return result;
230  }
231 
232  if (fNNet)
233  {
234  result = fNNet->Run(fWireDriftPatch);
235  if (result.empty())
236  {
237  mf::LogError("PointIdAlg") << "Problem with applying model to input.";
238  }
239  }
240 
241  return result;
242 }
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float > > &patch) const
Definition: PointIdAlg.h:156
virtual std::vector< float > Run(std::vector< std::vector< float > > const &inp2d)=0
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:152
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:150
std::vector< std::vector< float > > nnet::PointIdAlg::predictIdVectors ( std::vector< std::pair< unsigned int, float > >  points) const

Definition at line 245 of file PointIdAlg.cxx.

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

246 {
247  if (points.empty() || !fNNet) { return std::vector< std::vector<float> >(); }
248 
249  std::vector< std::vector< std::vector<float> > > inps(
250  points.size(), std::vector< std::vector<float> >(
251  fPatchSizeW, std::vector<float>(fPatchSizeD)));
252  for (size_t i = 0; i < points.size(); ++i)
253  {
254  unsigned int wire = points[i].first;
255  float drift = points[i].second;
256  if (!bufferPatch(wire, drift, inps[i]))
257  {
258  throw cet::exception("PointIdAlg") << "Patch buffering failed" << std::endl;
259  }
260 
261  }
262 
263  return fNNet->Run(inps);
264 }
bool bufferPatch(size_t wire, float drift, std::vector< std::vector< float > > &patch) const
Definition: PointIdAlg.h:156
virtual std::vector< float > Run(std::vector< std::vector< float > > const &inp2d)=0
size_t fPatchSizeD
Definition: PointIdAlg.h:153
nnet::ModelInterface * fNNet
Definition: PointIdAlg.h:150
size_t fPatchSizeW
Definition: PointIdAlg.h:153
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void nnet::PointIdAlg::resizePatch ( void  )
private

Definition at line 191 of file PointIdAlg.cxx.

References fPatchSizeD, fPatchSizeW, and fWireDriftPatch.

Referenced by PointIdAlg().

192 {
194  for (auto & r : fWireDriftPatch) r.resize(fPatchSizeD);
195 }
std::vector< std::vector< float > > fWireDriftPatch
Definition: PointIdAlg.h:152
size_t fPatchSizeD
Definition: PointIdAlg.h:153
size_t fPatchSizeW
Definition: PointIdAlg.h:153
void img::DataProviderAlg::resizeView ( size_t  wires,
size_t  drifts 
)
protectedvirtualinherited

Reimplemented in nnet::TrainingDataAlg.

Definition at line 103 of file DataProviderAlg.cxx.

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

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

104 {
105  fNWires = wires; fNDrifts = drifts;
106  fNScaledDrifts = drifts / fDriftWindow;
107 
109  else { fNCachedDrifts = fNDrifts; }
110 
111  fWireChannels.resize(wires);
113 
114  fWireDriftData.resize(wires);
115  for (auto & w : fWireDriftData)
116  {
117  w.resize(fNCachedDrifts);
118  std::fill(w.begin(), w.end(), fAdcZero);
119  }
120 
122  if (fCalibrateLifetime)
123  {
124  for (size_t t = 0; t < fNDrifts; ++t) { fLifetimeCorrFactors[t] = fCalorimetryAlg.LifetimeCorrection(t); }
125  }
126  else
127  {
128  for (size_t t = 0; t < fNDrifts; ++t) { fLifetimeCorrFactors[t] = 1.0; }
129  }
130 }
std::vector< float > fLifetimeCorrFactors
std::vector< raw::ChannelID_t > fWireChannels
std::vector< std::vector< float > > fWireDriftData
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:31
unsigned int fNCachedDrifts
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
calo::CalorimetryAlg fCalorimetryAlg
unsigned int fNScaledDrifts
double LifetimeCorrection(double time, double T0=0) const
Float_t w
Definition: plot.C:23
bool img::DataProviderAlg::setWireData ( std::vector< float > const &  adc,
size_t  wireIdx 
)
protectedinherited

Definition at line 245 of file DataProviderAlg.cxx.

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

Referenced by img::DataProviderAlg::getDriftIndex(), and img::DataProviderAlg::setWireDriftData().

246 {
247  if (wireIdx >= fWireDriftData.size()) return false;
248  auto & wData = fWireDriftData[wireIdx];
249 
250  if (fDownscaleFullView)
251  {
252  if (!adc.empty()) { downscale(wData, adc, 0); }
253  else { return false; }
254  }
255  else
256  {
257  if (adc.empty()) { return false; }
258  else if (adc.size() <= wData.size()) { std::copy(adc.begin(), adc.end(), wData.begin()); }
259  else { std::copy(adc.begin(), adc.begin()+wData.size(), wData.begin()); }
260  }
261  return true;
262 }
std::vector< std::vector< float > > fWireDriftData
void downscale(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
bool img::DataProviderAlg::setWireDriftData ( const std::vector< recob::Wire > &  wires,
unsigned int  plane,
unsigned int  tpc,
unsigned int  cryo 
)
inherited

Definition at line 265 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::fCryo, img::DataProviderAlg::fDetProp, img::DataProviderAlg::fGeometry, img::DataProviderAlg::fPlane, img::DataProviderAlg::fTPC, img::DataProviderAlg::fWireChannels, detinfo::DetectorProperties::NumberTimeSamples(), geo::GeometryCore::Nwires(), img::DataProviderAlg::Plane(), img::DataProviderAlg::resizeView(), and img::DataProviderAlg::setWireData().

Referenced by img::DataProviderAlg::DataProviderAlg(), nnet::TrainingDataAlg::setDataEventData(), and nnet::TrainingDataAlg::setEventData().

267 {
268  mf::LogInfo("DataProviderAlg") << "Create image for cryo:"
269  << cryo << " tpc:" << tpc << " plane:" << plane;
270 
271  fCryo = cryo; fTPC = tpc; fPlane = plane;
272 
273  fAdcSumOverThr = 0;
274  fAdcAreaOverThr = 0;
275 
276  size_t nwires = fGeometry->Nwires(plane, tpc, cryo);
277  size_t ndrifts = fDetProp->NumberTimeSamples();
278 
279  resizeView(nwires, ndrifts);
280 
281  auto const & channelStatus = art::ServiceHandle< lariov::ChannelStatusService >()->GetProvider();
282 
283  bool allWrong = true;
284  for (auto const & wire : wires)
285  {
286  auto wireChannelNumber = wire.Channel();
287  if (!channelStatus.IsGood(wireChannelNumber)) { continue; }
288 
289  size_t w_idx = 0;
290  for (auto const& id : fGeometry->ChannelToWire(wireChannelNumber))
291  {
292  if ((id.Plane == plane) && (id.TPC == tpc) && (id.Cryostat == cryo))
293  {
294  w_idx = id.Wire;
295 
296  auto adc = wire.Signal();
297  if (adc.size() < ndrifts)
298  {
299  mf::LogWarning("DataProviderAlg") << "Wire ADC vector size lower than NumberTimeSamples.";
300  continue; // not critical, maybe other wires are OK, so continue
301  }
302 
303  if (!setWireData(adc, w_idx))
304  {
305  mf::LogWarning("DataProviderAlg") << "Wire data not set.";
306  continue; // also not critical, try to set other wires
307  }
308 
309  for (auto v : adc) { if (v >= fAdcSumThr) { fAdcSumOverThr += v; fAdcAreaOverThr++; } }
310 
311  fWireChannels[w_idx] = wireChannelNumber;
312  allWrong = false;
313  }
314  }
315  }
316  if (allWrong)
317  {
318  mf::LogError("DataProviderAlg") << "Wires data not set in the cryo:"
319  << cryo << " tpc:" << tpc << " plane:" << plane;
320  return false;
321  }
322 
323  applyBlur();
324  addWhiteNoise();
326 
327  return true;
328 }
virtual void resizeView(size_t wires, size_t drifts)
geo::GeometryCore const * fGeometry
std::vector< raw::ChannelID_t > fWireChannels
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
bool setWireData(std::vector< float > const &adc, size_t wireIdx)
detinfo::DetectorProperties const * fDetProp
virtual unsigned int NumberTimeSamples() const =0
unsigned int Plane(void) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
unsigned int img::DataProviderAlg::TPC ( void  ) const
inlineinherited

Definition at line 158 of file DataProviderAlg.h.

References img::DataProviderAlg::fTPC.

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

Definition at line 109 of file DataProviderAlg.h.

References img::DataProviderAlg::fWireDriftData.

109 { return fWireDriftData[widx]; }
std::vector< std::vector< float > > fWireDriftData
float img::DataProviderAlg::ZeroLevel ( void  ) const
inlineinherited

Level of zero ADC after scaling.

Definition at line 167 of file DataProviderAlg.h.

References img::DataProviderAlg::fAdcZero.

167 { return fAdcZero; }

Member Data Documentation

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

Definition at line 155 of file PointIdAlg.h.

Referenced by isCurrentPatch().

size_t nnet::PointIdAlg::fCurrentWireIdx
mutableprivate

Definition at line 155 of file PointIdAlg.h.

Referenced by isCurrentPatch().

detinfo::DetectorProperties const* img::DataProviderAlg::fDetProp
protectedinherited
EDownscaleMode img::DataProviderAlg::fDownscaleMode
protectedinherited

Definition at line 179 of file DataProviderAlg.h.

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

float img::DataProviderAlg::fDriftWindowInv
protectedinherited
geo::GeometryCore const* img::DataProviderAlg::fGeometry
protectedinherited
std::vector<float> img::DataProviderAlg::fLifetimeCorrFactors
protectedinherited
unsigned int img::DataProviderAlg::fNDrifts
protectedinherited
nnet::ModelInterface* nnet::PointIdAlg::fNNet
private

Definition at line 150 of file PointIdAlg.h.

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

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

Definition at line 148 of file PointIdAlg.h.

Referenced by PointIdAlg().

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

Definition at line 149 of file PointIdAlg.h.

Referenced by PointIdAlg().

unsigned int img::DataProviderAlg::fNScaledDrifts
protectedinherited
size_t nnet::PointIdAlg::fPatchSizeD
private

Definition at line 153 of file PointIdAlg.h.

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

size_t nnet::PointIdAlg::fPatchSizeW
private

Definition at line 153 of file PointIdAlg.h.

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

unsigned int img::DataProviderAlg::fPlane
protectedinherited
unsigned int img::DataProviderAlg::fTPC
protectedinherited
std::vector< raw::ChannelID_t > img::DataProviderAlg::fWireChannels
protectedinherited
std::vector< std::vector<float> > nnet::PointIdAlg::fWireDriftPatch
mutableprivate

Definition at line 152 of file PointIdAlg.h.

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


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