LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
img::DataProviderAlg Class Reference

#include "DataProviderAlg.h"

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

Classes

struct  Config
 

Public Types

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

Public Member Functions

 DataProviderAlg (const fhicl::ParameterSet &pset)
 
 DataProviderAlg (const Config &config)
 
virtual ~DataProviderAlg (void)
 
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
 

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

float scaleAdcSample (float val) const
 
void scaleAdcSamples (std::vector< float > &values) const
 
void applyBlur ()
 
void addWhiteNoise ()
 
void addCoherentNoise ()
 

Private Attributes

std::vector< float > fAmplCalibConst
 
bool fCalibrateAmpl
 
bool fCalibrateLifetime
 
float fAdcMax
 
float fAdcMin
 
float fAdcScale
 
float fAdcOffset
 
float fAdcZero
 
double fAdcSumOverThr
 
double fAdcSumThr
 
size_t fAdcAreaOverThr
 
CLHEP::HepJamesRandom fRndEngine
 
std::vector< float > fBlurKernel
 
float fNoiseSigma
 
float fCoherentSigma
 

Detailed Description

Base class providing data for training / running image based classifiers. It can be used also for any other algorithms where 2D projection image is useful. Currently the image is 32-bit fp / pixel, as sson as have time will template it so e.g. byte pixels would be possible.

Definition at line 46 of file DataProviderAlg.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

img::DataProviderAlg::DataProviderAlg ( const fhicl::ParameterSet pset)
inline

Definition at line 98 of file DataProviderAlg.h.

References setWireDriftData(), and ~DataProviderAlg().

98  :
100  {}
DataProviderAlg(const fhicl::ParameterSet &pset)
img::DataProviderAlg::DataProviderAlg ( const Config config)

Definition at line 20 of file DataProviderAlg.cxx.

References img::DataProviderAlg::Config::AdcMax, img::DataProviderAlg::Config::AdcMin, img::DataProviderAlg::Config::BlurKernel, img::DataProviderAlg::Config::CalibrateAmpl, img::DataProviderAlg::Config::CalibrateLifetime, img::DataProviderAlg::Config::CalorimetryAlg, img::DataProviderAlg::Config::CoherentSigma, img::DataProviderAlg::Config::DownscaleFn, img::DataProviderAlg::Config::DownscaleFullView, img::DataProviderAlg::Config::DriftWindow, calo::CalorimetryAlg::ElectronsFromADCPeak(), fAdcMax, fAdcMin, fAdcOffset, fAdcScale, fAdcZero, fAmplCalibConst, fBlurKernel, fCalibrateAmpl, fCalibrateLifetime, fCalorimetryAlg, fCoherentSigma, fDownscaleFullView, fDownscaleMode, fDriftWindow, fDriftWindowInv, fGeometry, fNoiseSigma, kMax, kMaxMean, kMean, geo::GeometryCore::MaxPlanes(), img::DataProviderAlg::Config::NoiseSigma, img::DataProviderAlg::Config::OutMax, img::DataProviderAlg::Config::OutMin, and calo::CalorimetryAlg::reconfigure().

20  :
21  fCryo(9999), fTPC(9999), fPlane(9999),
24  fCalorimetryAlg(config.CalorimetryAlg()),
26  fDetProp(lar::providerFrom<detinfo::DetectorPropertiesService>()),
27  fAdcSumOverThr(0), fAdcSumThr(10), // set fixed threshold of 10 ADC counts for counting the sum
28  fAdcAreaOverThr(0),
30 {
31  fCalorimetryAlg.reconfigure(config.CalorimetryAlg());
32  fCalibrateLifetime = config.CalibrateLifetime();
33  fCalibrateAmpl = config.CalibrateAmpl();
34 
36  if (fCalibrateAmpl)
37  {
38  mf::LogInfo("DataProviderAlg") << "Using calibration constants:";
39  for (size_t p = 0; p < fAmplCalibConst.size(); ++p)
40  {
41  try
42  {
44  mf::LogInfo("DataProviderAlg") << " plane:" << p << " const:" << 1.0 / fAmplCalibConst[p];
45  }
46  catch (...) { fAmplCalibConst[p] = 1.0; }
47  }
48  }
49  else
50  {
51  mf::LogInfo("DataProviderAlg") << "No plane-to-plane calibration.";
52  for (size_t p = 0; p < fAmplCalibConst.size(); ++p) { fAmplCalibConst[p] = 1.0; }
53  }
54 
55  fDriftWindow = config.DriftWindow();
56  fDownscaleFullView = config.DownscaleFullView();
58 
59  std::string mode_str = config.DownscaleFn();
60  mf::LogVerbatim("DataProviderAlg") << "Downscale mode is: " << mode_str;
61  if (mode_str == "maxpool")
62  {
63  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMax(dst, adc, tick0); };
65  }
66  else if (mode_str == "maxmean")
67  {
68  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMaxMean(dst, adc, tick0); };
70  }
71  else if (mode_str == "mean")
72  {
73  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMean(dst, adc, tick0); };
75  }
76  else
77  {
78  mf::LogError("DataProviderAlg") << "Downscale mode string not recognized, set to max pooling.";
79  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMax(dst, adc, tick0); };
81  }
82 
83  fAdcMax = config.AdcMax();
84  fAdcMin = config.AdcMin();
85  fAdcOffset = config.OutMin();
86  fAdcScale = (config.OutMax() - fAdcOffset) / (fAdcMax - fAdcMin);
87  fAdcZero = fAdcOffset + fAdcScale * (0 - fAdcMin); // level of zero ADC after scaling
88 
89  if (fAdcMax <= fAdcMin) { throw cet::exception("img::DataProviderAlg") << "Misconfigured: AdcMax <= AdcMin" << std::endl; }
90  if (fAdcScale == 0) { throw cet::exception("img::DataProviderAlg") << "Misconfigured: OutMax == OutMin" << std::endl; }
91 
92  fBlurKernel = config.BlurKernel();
93  fNoiseSigma = config.NoiseSigma();
94  fCoherentSigma = config.CoherentSigma();
95 }
geo::GeometryCore const * fGeometry
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void reconfigure(const Config &config)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< float > fBlurKernel
double ElectronsFromADCPeak(double adc, unsigned short plane) const
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
detinfo::DetectorProperties const * fDetProp
unsigned int fNCachedDrifts
calo::CalorimetryAlg fCalorimetryAlg
unsigned int fNScaledDrifts
std::vector< float > fAmplCalibConst
EDownscaleMode fDownscaleMode
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
img::DataProviderAlg::~DataProviderAlg ( void  )
virtual

Definition at line 98 of file DataProviderAlg.cxx.

Referenced by DataProviderAlg().

99 {
100 }

Member Function Documentation

void img::DataProviderAlg::addCoherentNoise ( )
private

Definition at line 507 of file DataProviderAlg.cxx.

References d, fCoherentSigma, fDownscaleFullView, fDriftWindow, fNCachedDrifts, fRndEngine, fWireDriftData, noise(), scaleAdcSample(), and w.

Referenced by setWireDriftData().

508 {
509  if (fCoherentSigma == 0) return;
510 
511  double effectiveSigma = scaleAdcSample(fCoherentSigma);
512  if (fDownscaleFullView) effectiveSigma /= fDriftWindow;
513 
514  CLHEP::RandGauss gauss(fRndEngine);
515  std::vector<double> amps1(fWireDriftData.size());
516  std::vector<double> amps2(1 + (fWireDriftData.size() / 32));
517  gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1); // 10% wire-wire ampl. variation
518  gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1); // 10% group-group ampl. variation
519 
520  double group_amp = 1.0;
521  std::vector<double> noise(fNCachedDrifts);
522  for (size_t w = 0; w < fWireDriftData.size(); ++w)
523  {
524  if ((w & 31) == 0)
525  {
526  group_amp = amps2[w >> 5]; // div by 32
527  gauss.fireArray(fNCachedDrifts, noise.data(), 0., effectiveSigma);
528  } // every 32 wires
529 
530  auto & wire = fWireDriftData[w];
531  for (size_t d = 0; d < wire.size(); ++d)
532  {
533  wire[d] += group_amp * amps1[w] * noise[d];
534  }
535  }
536 }
std::vector< std::vector< float > > fWireDriftData
unsigned int noise()
Definition: chem4.cc:265
unsigned int fNCachedDrifts
Float_t d
Definition: plot.C:237
float scaleAdcSample(float val) const
CLHEP::HepJamesRandom fRndEngine
Float_t w
Definition: plot.C:23
void img::DataProviderAlg::addWhiteNoise ( )
private

Definition at line 487 of file DataProviderAlg.cxx.

References d, fDownscaleFullView, fDriftWindow, fNCachedDrifts, fNoiseSigma, fRndEngine, fWireDriftData, noise(), and scaleAdcSample().

Referenced by setWireDriftData().

488 {
489  if (fNoiseSigma == 0) return;
490 
491  double effectiveSigma = scaleAdcSample(fNoiseSigma);
492  if (fDownscaleFullView) effectiveSigma /= fDriftWindow;
493 
494  CLHEP::RandGauss gauss(fRndEngine);
495  std::vector<double> noise(fNCachedDrifts);
496  for (auto & wire : fWireDriftData)
497  {
498  gauss.fireArray(fNCachedDrifts, noise.data(), 0., effectiveSigma);
499  for (size_t d = 0; d < wire.size(); ++d)
500  {
501  wire[d] += noise[d];
502  }
503  }
504 }
std::vector< std::vector< float > > fWireDriftData
unsigned int noise()
Definition: chem4.cc:265
unsigned int fNCachedDrifts
Float_t d
Definition: plot.C:237
float scaleAdcSample(float val) const
CLHEP::HepJamesRandom fRndEngine
void img::DataProviderAlg::applyBlur ( )
private

Definition at line 375 of file DataProviderAlg.cxx.

References d, fBlurKernel, fWireDriftData, and w.

Referenced by setWireDriftData().

376 {
377  if (fBlurKernel.size() < 2) return;
378 
379  size_t margin_left = (fBlurKernel.size()-1) >> 1, margin_right = fBlurKernel.size() - margin_left - 1;
380 
381  std::vector< std::vector<float> > src(fWireDriftData.size());
382  for (size_t w = 0; w < fWireDriftData.size(); ++w) { src[w] = fWireDriftData[w]; }
383 
384  for (size_t w = margin_left; w < fWireDriftData.size() - margin_right; ++w)
385  {
386  for (size_t d = 0; d < fWireDriftData[w].size(); ++d)
387  {
388  float sum = 0;
389  for (size_t i = 0; i < fBlurKernel.size(); ++i)
390  {
391  sum += fBlurKernel[i] * src[w + i - margin_left][d];
392  }
393  fWireDriftData[w][d] = sum;
394  }
395  }
396 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > fBlurKernel
Float_t d
Definition: plot.C:237
Float_t w
Definition: plot.C:23
unsigned int img::DataProviderAlg::Cryo ( void  ) const
inline

Definition at line 157 of file DataProviderAlg.h.

References fCryo.

157 { return fCryo; }
void img::DataProviderAlg::downscale ( std::vector< float > &  dst,
std::vector< float > const &  adc,
size_t  tick0 
) const
inlineprotected

Definition at line 189 of file DataProviderAlg.h.

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

Referenced by patchFromOriginalView(), and 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
protected

Definition at line 182 of file DataProviderAlg.cxx.

References fDriftWindow, fLifetimeCorrFactors, and scaleAdcSamples().

Referenced by 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
protected

Definition at line 202 of file DataProviderAlg.cxx.

References fDriftWindow, fLifetimeCorrFactors, n, and scaleAdcSamples().

Referenced by 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
protected

Definition at line 227 of file DataProviderAlg.cxx.

References fDriftWindow, fDriftWindowInv, fLifetimeCorrFactors, and scaleAdcSamples().

Referenced by 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
inline

Definition at line 164 of file DataProviderAlg.h.

References fDriftWindow.

164 { return fDriftWindow; }
size_t img::DataProviderAlg::getAdcArea ( void  ) const
inline

Definition at line 149 of file DataProviderAlg.h.

References fAdcAreaOverThr, poolMax(), and poolSum().

149 { return fAdcAreaOverThr; }
double img::DataProviderAlg::getAdcSum ( void  ) const
inline

Definition at line 148 of file DataProviderAlg.h.

References fAdcSumOverThr.

148 { return fAdcSumOverThr; }
size_t img::DataProviderAlg::getDriftIndex ( float  drift) const
inlineprotected

Definition at line 200 of file DataProviderAlg.h.

References fDriftWindowInv, patchFromDownsampledView(), patchFromOriginalView(), resizeView(), setWireData(), and lar::dump::vector().

Referenced by getPixelOrZero(), poolMax(), and poolSum().

201  {
202  if (fDownscaleFullView) return (size_t)(drift * fDriftWindowInv);
203  else return (size_t)drift;
204  }
std::vector< std::vector<float> > img::DataProviderAlg::getPatch ( size_t  wire,
float  drift,
size_t  patchSizeW,
size_t  patchSizeD 
) const
inline

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 fDownscaleFullView, patchFromDownsampledView(), and 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
inline

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 fNCachedDrifts, fWireDriftData, and 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
double img::DataProviderAlg::LifetimeCorrection ( double  tick) const
inline

Definition at line 169 of file DataProviderAlg.h.

References 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
inline

Definition at line 163 of file DataProviderAlg.h.

References fNCachedDrifts.

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

Definition at line 162 of file DataProviderAlg.h.

References fNScaledDrifts.

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

Definition at line 161 of file DataProviderAlg.h.

References fNWires.

161 { return fNWires; }
bool img::DataProviderAlg::patchFromDownsampledView ( size_t  wire,
float  drift,
size_t  size_w,
size_t  size_d,
std::vector< std::vector< float > > &  patch 
) const
protected

Definition at line 400 of file DataProviderAlg.cxx.

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

Referenced by getDriftIndex(), and 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
protected

Definition at line 442 of file DataProviderAlg.cxx.

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

Referenced by getDriftIndex(), and 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
inline
float img::DataProviderAlg::poolMax ( int  wire,
int  drift,
size_t  r = 0 
) const

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

Definition at line 133 of file DataProviderAlg.cxx.

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

Referenced by 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

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

Definition at line 159 of file DataProviderAlg.cxx.

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

Referenced by 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
void img::DataProviderAlg::resizeView ( size_t  wires,
size_t  drifts 
)
protectedvirtual

Reimplemented in nnet::TrainingDataAlg.

Definition at line 103 of file DataProviderAlg.cxx.

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

Referenced by getDriftIndex(), nnet::TrainingDataAlg::resizeView(), and 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
float img::DataProviderAlg::scaleAdcSample ( float  val) const
private

Definition at line 331 of file DataProviderAlg.cxx.

References fAdcMax, fAdcMin, fAdcOffset, fAdcScale, fAmplCalibConst, and fPlane.

Referenced by addCoherentNoise(), addWhiteNoise(), and scaleAdcSamples().

332 {
333  val *= fAmplCalibConst[fPlane]; // prescale by plane-to-plane calibration factors
334 
335  if (val < fAdcMin) { val = fAdcMin; } // saturate
336  else if (val > fAdcMax) { val = fAdcMax; }
337 
338  return fAdcOffset + fAdcScale * (val - fAdcMin); // shift and scale to the output range, shift to the output min
339 }
std::vector< float > fAmplCalibConst
void img::DataProviderAlg::scaleAdcSamples ( std::vector< float > &  values) const
private

Definition at line 341 of file DataProviderAlg.cxx.

References fAdcMax, fAdcMin, fAdcOffset, fAdcScale, fAmplCalibConst, fPlane, and scaleAdcSample().

Referenced by downscaleMax(), downscaleMaxMean(), and downscaleMean().

342 {
343  float calib = fAmplCalibConst[fPlane];
344  auto * data = values.data();
345 
346  size_t k = 0, size4 = values.size() >> 2, size = values.size();
347  for (size_t i = 0; i < size4; ++i) // vectorize if you can
348  {
349  data[k] *= calib; // prescale by plane-to-plane calibration factors
350  data[k+1] *= calib;
351  data[k+2] *= calib;
352  data[k+3] *= calib;
353 
354  if (data[k] < fAdcMin) { data[k] = fAdcMin; } // saturate min
355  if (data[k+1] < fAdcMin) { data[k+1] = fAdcMin; }
356  if (data[k+2] < fAdcMin) { data[k+2] = fAdcMin; }
357  if (data[k+3] < fAdcMin) { data[k+3] = fAdcMin; }
358 
359  if (data[k] > fAdcMax) { data[k] = fAdcMax; } // saturate max
360  if (data[k+1] > fAdcMax) { data[k+1] = fAdcMax; }
361  if (data[k+2] > fAdcMax) { data[k+2] = fAdcMax; }
362  if (data[k+3] > fAdcMax) { data[k+3] = fAdcMax; }
363 
364  data[k] = fAdcOffset + fAdcScale * (data[k] - fAdcMin); // shift and scale to the output range, shift to the output min
365  data[k+1] = fAdcOffset + fAdcScale * (data[k+1] - fAdcMin);
366  data[k+2] = fAdcOffset + fAdcScale * (data[k+2] - fAdcMin);
367  data[k+3] = fAdcOffset + fAdcScale * (data[k+3] - fAdcMin);
368 
369  k += 4;
370  }
371  while (k < size) { data[k] = scaleAdcSample(data[k]); ++k; } // do the tail
372 }
float scaleAdcSample(float val) const
std::vector< float > fAmplCalibConst
bool img::DataProviderAlg::setWireData ( std::vector< float > const &  adc,
size_t  wireIdx 
)
protected

Definition at line 245 of file DataProviderAlg.cxx.

References downscale(), fDownscaleFullView, and fWireDriftData.

Referenced by getDriftIndex(), and 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 
)

Definition at line 265 of file DataProviderAlg.cxx.

References addCoherentNoise(), addWhiteNoise(), applyBlur(), geo::GeometryCore::ChannelToWire(), fAdcAreaOverThr, fAdcSumOverThr, fAdcSumThr, fCryo, fDetProp, fGeometry, fPlane, fTPC, fWireChannels, detinfo::DetectorProperties::NumberTimeSamples(), geo::GeometryCore::Nwires(), Plane(), resizeView(), and setWireData().

Referenced by 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
inline

Definition at line 158 of file DataProviderAlg.h.

References fTPC.

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

Definition at line 109 of file DataProviderAlg.h.

References fWireDriftData.

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

Level of zero ADC after scaling.

Definition at line 167 of file DataProviderAlg.h.

References fAdcZero.

167 { return fAdcZero; }

Member Data Documentation

size_t img::DataProviderAlg::fAdcAreaOverThr
private

Definition at line 228 of file DataProviderAlg.h.

Referenced by getAdcArea(), and setWireDriftData().

float img::DataProviderAlg::fAdcMax
private

Definition at line 226 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), scaleAdcSample(), and scaleAdcSamples().

float img::DataProviderAlg::fAdcMin
private

Definition at line 226 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), scaleAdcSample(), and scaleAdcSamples().

float img::DataProviderAlg::fAdcOffset
private

Definition at line 226 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), scaleAdcSample(), and scaleAdcSamples().

float img::DataProviderAlg::fAdcScale
private

Definition at line 226 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), scaleAdcSample(), and scaleAdcSamples().

double img::DataProviderAlg::fAdcSumOverThr
private

Definition at line 227 of file DataProviderAlg.h.

Referenced by getAdcSum(), and setWireDriftData().

double img::DataProviderAlg::fAdcSumThr
private

Definition at line 227 of file DataProviderAlg.h.

Referenced by setWireDriftData().

float img::DataProviderAlg::fAdcZero
private
std::vector<float> img::DataProviderAlg::fAmplCalibConst
private

Definition at line 223 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), scaleAdcSample(), and scaleAdcSamples().

std::vector<float> img::DataProviderAlg::fBlurKernel
private

Definition at line 233 of file DataProviderAlg.h.

Referenced by applyBlur(), and DataProviderAlg().

bool img::DataProviderAlg::fCalibrateAmpl
private

Definition at line 224 of file DataProviderAlg.h.

Referenced by DataProviderAlg().

bool img::DataProviderAlg::fCalibrateLifetime
private

Definition at line 224 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and resizeView().

calo::CalorimetryAlg img::DataProviderAlg::fCalorimetryAlg
protected

Definition at line 214 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), LifetimeCorrection(), and resizeView().

float img::DataProviderAlg::fCoherentSigma
private

Definition at line 239 of file DataProviderAlg.h.

Referenced by addCoherentNoise(), and DataProviderAlg().

unsigned int img::DataProviderAlg::fCryo
protected
detinfo::DetectorProperties const* img::DataProviderAlg::fDetProp
protected

Definition at line 218 of file DataProviderAlg.h.

Referenced by nnet::TrainingDataAlg::getProjection(), and setWireDriftData().

EDownscaleMode img::DataProviderAlg::fDownscaleMode
protected

Definition at line 179 of file DataProviderAlg.h.

Referenced by DataProviderAlg().

float img::DataProviderAlg::fDriftWindowInv
protected

Definition at line 184 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), downscaleMean(), and getDriftIndex().

geo::GeometryCore const* img::DataProviderAlg::fGeometry
protected
std::vector<float> img::DataProviderAlg::fLifetimeCorrFactors
protected

Definition at line 177 of file DataProviderAlg.h.

Referenced by downscaleMax(), downscaleMaxMean(), downscaleMean(), and resizeView().

unsigned int img::DataProviderAlg::fNDrifts
protected
float img::DataProviderAlg::fNoiseSigma
private

Definition at line 236 of file DataProviderAlg.h.

Referenced by addWhiteNoise(), and DataProviderAlg().

unsigned int img::DataProviderAlg::fNScaledDrifts
protected
unsigned int img::DataProviderAlg::fNWires
protected
unsigned int img::DataProviderAlg::fPlane
protected

Definition at line 172 of file DataProviderAlg.h.

Referenced by Plane(), scaleAdcSample(), scaleAdcSamples(), and setWireDriftData().

CLHEP::HepJamesRandom img::DataProviderAlg::fRndEngine
private

Definition at line 230 of file DataProviderAlg.h.

Referenced by addCoherentNoise(), and addWhiteNoise().

unsigned int img::DataProviderAlg::fTPC
protected
std::vector< raw::ChannelID_t > img::DataProviderAlg::fWireChannels
protected
std::vector< std::vector<float> > img::DataProviderAlg::fWireDriftData
protected

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