Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
img::DataProviderAlg Class Reference

#include <DataProviderAlg.h>

Inheritance diagram for img::DataProviderAlg:
nnet::PointIdAlg nnet::TrainingDataAlg PointIdAlgTools::IPointIdAlg PointIdAlgTools::PointIdAlgKeras PointIdAlgTools::PointIdAlgSonicTriton PointIdAlgTools::PointIdAlgTf PointIdAlgTools::PointIdAlgTriton

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

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

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
 
unsigned int fCryo = 9999
 
unsigned int fTPC = 9999
 
unsigned int fPlane = 9999
 
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 54 of file DataProviderAlg.h.

Member Enumeration Documentation

Enumerator
kMax 
kMaxMean 
kMean 

Definition at line 56 of file DataProviderAlg.h.

Constructor & Destructor Documentation

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

Definition at line 93 of file DataProviderAlg.h.

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

Definition at line 26 of file DataProviderAlg.cxx.

27  : fAlgView{}
29  , fDriftWindow(10)
32  , fAdcSumOverThr(0)
33  , fAdcSumThr(10)
34  , // set fixed threshold of 10 ADC counts for counting the sum
36  , fNoiseSigma(0)
37  , fCoherentSigma(0)
38 {
41 
43  if (fCalibrateAmpl) {
44  mf::LogInfo("DataProviderAlg") << "Using calibration constants:";
45  for (size_t p = 0; p < fAmplCalibConst.size(); ++p) {
46  try {
48  mf::LogInfo("DataProviderAlg") << " plane:" << p << " const:" << 1.0 / fAmplCalibConst[p];
49  }
50  catch (...) {
51  fAmplCalibConst[p] = 1.0;
52  }
53  }
54  }
55  else {
56  mf::LogInfo("DataProviderAlg") << "No plane-to-plane calibration.";
57  for (size_t p = 0; p < fAmplCalibConst.size(); ++p) {
58  fAmplCalibConst[p] = 1.0;
59  }
60  }
61 
65 
66  std::string mode_str = config.DownscaleFn();
67  mf::LogVerbatim("DataProviderAlg") << "Downscale mode is: " << mode_str;
68  if (mode_str == "maxpool") {
69  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMax(dst, adc, tick0); };
71  }
72  else if (mode_str == "maxmean") {
73  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMaxMean(dst, adc, tick0); };
75  }
76  else if (mode_str == "mean") {
77  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMean(dst, adc, tick0); };
79  }
80  else {
81  mf::LogError("DataProviderAlg") << "Downscale mode string not recognized, set to max pooling.";
82  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMax(dst, adc, tick0); };
84  }
85 
86  fAdcMax = config.AdcMax();
87  fAdcMin = config.AdcMin();
90  fAdcZero = fAdcOffset + fAdcScale * (0 - fAdcMin); // level of zero ADC after scaling
91 
92  if (fAdcMax <= fAdcMin) {
93  throw cet::exception("img::DataProviderAlg") << "Misconfigured: AdcMax <= AdcMin" << std::endl;
94  }
95  if (fAdcScale == 0) {
96  throw cet::exception("img::DataProviderAlg") << "Misconfigured: OutMax == OutMin" << std::endl;
97  }
98 
102 }
geo::GeometryCore const * fGeometry
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fhicl::Atom< float > AdcMax
fhicl::Atom< float > CoherentSigma
T * get() const
Definition: ServiceHandle.h:63
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
fhicl::Atom< unsigned int > DriftWindow
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< float > fBlurKernel
double ElectronsFromADCPeak(double adc, unsigned short plane) const
fhicl::Sequence< float > BlurKernel
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
fhicl::Atom< bool > DownscaleFullView
static Config * config
Definition: config.cpp:1054
p
Definition: test.py:223
fhicl::Atom< float > AdcMin
DataProviderAlgView fAlgView
calo::CalorimetryAlg fCalorimetryAlg
fhicl::Atom< bool > CalibrateLifetime
fhicl::Table< calo::CalorimetryAlg::Config > CalorimetryAlg
std::vector< float > fAmplCalibConst
fhicl::Atom< std::string > DownscaleFn
fhicl::Atom< bool > CalibrateAmpl
EDownscaleMode fDownscaleMode
fhicl::Atom< float > OutMin
fhicl::Atom< float > OutMax
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
fhicl::Atom< float > NoiseSigma
img::DataProviderAlg::~DataProviderAlg ( )
virtualdefault

Member Function Documentation

void img::DataProviderAlg::addCoherentNoise ( )
private

Definition at line 549 of file DataProviderAlg.cxx.

550 {
551  if (fCoherentSigma == 0) return;
552 
553  double effectiveSigma = scaleAdcSample(fCoherentSigma);
554  if (fDownscaleFullView) effectiveSigma /= fDriftWindow;
555 
556  CLHEP::RandGauss gauss(fRndEngine);
557  std::vector<double> amps1(fAlgView.fWireDriftData.size());
558  std::vector<double> amps2(1 + (fAlgView.fWireDriftData.size() / 32));
559  gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1); // 10% wire-wire ampl. variation
560  gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1); // 10% group-group ampl. variation
561 
562  double group_amp = 1.0;
563  std::vector<double> noise(fAlgView.fNCachedDrifts);
564  for (size_t w = 0; w < fAlgView.fWireDriftData.size(); ++w) {
565  if ((w & 31) == 0) {
566  group_amp = amps2[w >> 5]; // div by 32
567  gauss.fireArray(fAlgView.fNCachedDrifts, noise.data(), 0., effectiveSigma);
568  } // every 32 wires
569 
570  auto& wire = fAlgView.fWireDriftData[w];
571  for (size_t d = 0; d < wire.size(); ++d) {
572  wire[d] += group_amp * amps1[w] * noise[d];
573  }
574  }
575 }
std::vector< std::vector< float > > fWireDriftData
float scaleAdcSample(float val) const
DataProviderAlgView fAlgView
CLHEP::HepJamesRandom fRndEngine
void img::DataProviderAlg::addWhiteNoise ( )
private

Definition at line 530 of file DataProviderAlg.cxx.

531 {
532  if (fNoiseSigma == 0) return;
533 
534  double effectiveSigma = scaleAdcSample(fNoiseSigma);
535  if (fDownscaleFullView) effectiveSigma /= fDriftWindow;
536 
537  CLHEP::RandGauss gauss(fRndEngine);
538  std::vector<double> noise(fAlgView.fNCachedDrifts);
539  for (auto& wire : fAlgView.fWireDriftData) {
540  gauss.fireArray(fAlgView.fNCachedDrifts, noise.data(), 0., effectiveSigma);
541  for (size_t d = 0; d < wire.size(); ++d) {
542  wire[d] += noise[d];
543  }
544  }
545 }
std::vector< std::vector< float > > fWireDriftData
float scaleAdcSample(float val) const
DataProviderAlgView fAlgView
CLHEP::HepJamesRandom fRndEngine
void img::DataProviderAlg::applyBlur ( )
private

Definition at line 424 of file DataProviderAlg.cxx.

425 {
426  if (fBlurKernel.size() < 2) return;
427 
428  size_t margin_left = (fBlurKernel.size() - 1) >> 1,
429  margin_right = fBlurKernel.size() - margin_left - 1;
430 
431  std::vector<std::vector<float>> src(fAlgView.fWireDriftData.size());
432  for (size_t w = 0; w < fAlgView.fWireDriftData.size(); ++w) {
433  src[w] = fAlgView.fWireDriftData[w];
434  }
435 
436  for (size_t w = margin_left; w < fAlgView.fWireDriftData.size() - margin_right; ++w) {
437  for (size_t d = 0; d < fAlgView.fWireDriftData[w].size(); ++d) {
438  float sum = 0;
439  for (size_t i = 0; i < fBlurKernel.size(); ++i) {
440  sum += fBlurKernel[i] * src[w + i - margin_left][d];
441  }
442  fAlgView.fWireDriftData[w][d] = sum;
443  }
444  }
445 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > fBlurKernel
DataProviderAlgView fAlgView
unsigned int img::DataProviderAlg::Cryo ( ) const
inline

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

Definition at line 167 of file DataProviderAlg.h.

168  {
169  return fCryo;
170  }
std::vector<float> img::DataProviderAlg::downscale ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
inlineprotected

Definition at line 237 of file DataProviderAlg.h.

238  {
239  switch (fDownscaleMode) {
240  case img::DataProviderAlg::kMean: return downscaleMean(dst_size, adc, tick0);
241  case img::DataProviderAlg::kMaxMean: return downscaleMaxMean(dst_size, adc, tick0);
242  case img::DataProviderAlg::kMax: return downscaleMax(dst_size, adc, tick0);
243  }
244  throw cet::exception("img::DataProviderAlg") << "Downscale mode not supported." << std::endl;
245  }
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
QTextStream & endl(QTextStream &s)
std::vector< float > img::DataProviderAlg::downscaleMax ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
protected

Definition at line 192 of file DataProviderAlg.cxx.

195 {
196  size_t kStop = dst_size;
197  std::vector<float> result(dst_size);
198  if (adc.size() < kStop) { kStop = adc.size(); }
199  for (size_t i = 0, k0 = 0; i < kStop; ++i, k0 += fDriftWindow) {
200  size_t k1 = k0 + fDriftWindow;
201 
202  float max_adc = adc[k0] * fAlgView.fLifetimeCorrFactors[k0 + tick0];
203  for (size_t k = k0 + 1; k < k1; ++k) {
204  float ak = adc[k] * fAlgView.fLifetimeCorrFactors[k + tick0];
205  if (ak > max_adc) max_adc = ak;
206  }
207  result[i] = max_adc;
208  }
210  return result;
211 }
static QCString result
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
protected

Definition at line 214 of file DataProviderAlg.cxx.

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

Definition at line 250 of file DataProviderAlg.cxx.

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

Definition at line 198 of file DataProviderAlg.h.

199  {
200  return fDriftWindow;
201  }
size_t img::DataProviderAlg::getAdcArea ( ) const
inline

Definition at line 155 of file DataProviderAlg.h.

156  {
157  return fAdcAreaOverThr;
158  }
double img::DataProviderAlg::getAdcSum ( ) const
inline

Definition at line 150 of file DataProviderAlg.h.

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

Definition at line 248 of file DataProviderAlg.h.

249  {
250  if (fDownscaleFullView)
251  return (size_t)(drift * fDriftWindowInv);
252  else
253  return (size_t)drift;
254  }
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 120 of file DataProviderAlg.h.

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

140  {
141  size_t didx = getDriftIndex(drift), widx = (size_t)wire;
142 
143  if ((widx < fAlgView.fWireDriftData.size()) && (didx < fAlgView.fNCachedDrifts)) {
144  return fAlgView.fWireDriftData[widx][didx];
145  }
146  return 0;
147  }
std::vector< std::vector< float > > fWireDriftData
DataProviderAlgView fAlgView
size_t getDriftIndex(float drift) const
double img::DataProviderAlg::LifetimeCorrection ( detinfo::DetectorClocksData const &  clock_data,
detinfo::DetectorPropertiesData const &  det_prop,
double  tick 
) const
inline

Definition at line 211 of file DataProviderAlg.h.

214  {
215  return fCalorimetryAlg.LifetimeCorrection(clock_data, det_prop, tick);
216  }
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
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
inline

Definition at line 193 of file DataProviderAlg.h.

194  {
195  return fAlgView.fNCachedDrifts;
196  }
DataProviderAlgView fAlgView
unsigned int img::DataProviderAlg::NScaledDrifts ( ) const
inline

Definition at line 188 of file DataProviderAlg.h.

189  {
190  return fAlgView.fNScaledDrifts;
191  }
DataProviderAlgView fAlgView
unsigned int img::DataProviderAlg::NWires ( ) const
inline

Definition at line 183 of file DataProviderAlg.h.

184  {
185  return fAlgView.fNWires;
186  }
DataProviderAlgView fAlgView
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 450 of file DataProviderAlg.cxx.

455 {
456  int halfSizeW = size_w / 2;
457  int halfSizeD = size_d / 2;
458 
459  int w0 = wire - halfSizeW;
460  int w1 = wire + halfSizeW;
461 
462  size_t sd = (size_t)(drift / fDriftWindow);
463  int d0 = sd - halfSizeD;
464  int d1 = sd + halfSizeD;
465 
466  int wsize = fAlgView.fWireDriftData.size();
467  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch) {
468  auto& dst = patch[wpatch];
469  if ((w >= 0) && (w < wsize)) {
470  auto& src = fAlgView.fWireDriftData[w];
471  int dsize = src.size();
472  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch) {
473  if ((d >= 0) && (d < dsize)) { dst[dpatch] = src[d]; }
474  else {
475  dst[dpatch] = fAdcZero;
476  }
477  }
478  }
479  else {
480  std::fill(dst.begin(), dst.end(), fAdcZero);
481  }
482  }
483 
484  return true;
485 }
std::vector< std::vector< float > > fWireDriftData
DataProviderAlgView fAlgView
def fill(s)
Definition: translator.py:93
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 488 of file DataProviderAlg.cxx.

493 {
494  int dsize = fDriftWindow * size_d;
495  int halfSizeW = size_w / 2;
496  int halfSizeD = dsize / 2;
497 
498  int w0 = wire - halfSizeW;
499  int w1 = wire + halfSizeW;
500 
501  int d0 = int(drift) - halfSizeD;
502  int d1 = int(drift) + halfSizeD;
503 
504  if (d0 < 0) d0 = 0;
505 
506  std::vector<float> tmp(dsize);
507  int wsize = fAlgView.fWireDriftData.size();
508  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch) {
509  if ((w >= 0) && (w < wsize)) {
510  auto& src = fAlgView.fWireDriftData[w];
511  int src_size = src.size();
512  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch) {
513  if ((d >= 0) && (d < src_size)) { tmp[dpatch] = src[d]; }
514  else {
515  tmp[dpatch] = fAdcZero;
516  }
517  }
518  }
519  else {
520  std::fill(tmp.begin(), tmp.end(), fAdcZero);
521  }
522  patch[wpatch] = downscale(patch[wpatch].size(), tmp, d0);
523  }
524 
525  return true;
526 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
string tmp
Definition: languages.py:63
DataProviderAlgView fAlgView
def fill(s)
Definition: translator.py:93
unsigned int img::DataProviderAlg::Plane ( ) const
inline

Definition at line 177 of file DataProviderAlg.h.

178  {
179  return fPlane;
180  }
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 140 of file DataProviderAlg.cxx.

141 {
142  size_t rw = r, rd = r;
143  if (!fDownscaleFullView) { rd *= fDriftWindow; }
144 
145  size_t didx = getDriftIndex(drift);
146  int d0 = didx - rd;
147  if (d0 < 0) { d0 = 0; }
148  int d1 = didx + rd;
149  if (d1 >= (int)fAlgView.fNCachedDrifts) { d1 = fAlgView.fNCachedDrifts - 1; }
150 
151  int w0 = wire - rw;
152  if (w0 < 0) { w0 = 0; }
153  int w1 = wire + rw;
154  if (w1 >= (int)fAlgView.fNWires) { w1 = fAlgView.fNWires - 1; }
155 
156  float adc, max_adc = 0;
157  for (int w = w0; w <= w1; ++w) {
158  auto const* col = fAlgView.fWireDriftData[w].data();
159  for (int d = d0; d <= d1; ++d) {
160  adc = col[d];
161  if (adc > max_adc) { max_adc = adc; }
162  }
163  }
164 
165  return max_adc;
166 }
std::vector< std::vector< float > > fWireDriftData
int16_t adc
Definition: CRTFragment.hh:202
DataProviderAlgView fAlgView
size_t getDriftIndex(float drift) const
img::DataProviderAlgView img::DataProviderAlg::resizeView ( detinfo::DetectorClocksData const &  clock_data,
detinfo::DetectorPropertiesData const &  det_prop,
size_t  wires,
size_t  drifts 
)
protectedvirtual

Reimplemented in nnet::TrainingDataAlg.

Definition at line 109 of file DataProviderAlg.cxx.

113 {
115  result.fNWires = wires;
116  result.fNDrifts = drifts;
117  result.fNScaledDrifts = drifts / fDriftWindow;
118  result.fNCachedDrifts = fDownscaleFullView ? result.fNScaledDrifts : drifts;
119 
120  result.fWireChannels.resize(wires, raw::InvalidChannelID);
121 
122  result.fWireDriftData.resize(wires, std::vector<float>(result.fNCachedDrifts, fAdcZero));
123 
124  result.fLifetimeCorrFactors.resize(drifts);
125  if (fCalibrateLifetime) {
126  for (size_t t = 0; t < drifts; ++t) {
127  result.fLifetimeCorrFactors[t] = fCalorimetryAlg.LifetimeCorrection(clock_data, det_prop, t);
128  }
129  }
130  else {
131  for (size_t t = 0; t < drifts; ++t) {
132  result.fLifetimeCorrFactors[t] = 1.0;
133  }
134  }
135  return result;
136 }
std::vector< std::vector< float > > fWireDriftData
static QCString result
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
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
float img::DataProviderAlg::scaleAdcSample ( float  val) const
private

Definition at line 369 of file DataProviderAlg.cxx.

370 {
371  val *= fAmplCalibConst[fPlane]; // prescale by plane-to-plane calibration factors
372 
373  if (val < fAdcMin) { val = fAdcMin; } // saturate
374  else if (val > fAdcMax) {
375  val = fAdcMax;
376  }
377 
378  return fAdcOffset +
379  fAdcScale *
380  (val - fAdcMin); // shift and scale to the output range, shift to the output min
381 }
std::vector< float > fAmplCalibConst
void img::DataProviderAlg::scaleAdcSamples ( std::vector< float > &  values) const
private

Definition at line 384 of file DataProviderAlg.cxx.

385 {
386  float calib = fAmplCalibConst[fPlane];
387  auto* data = values.data();
388 
389  size_t k = 0, size4 = values.size() >> 2, size = values.size();
390  for (size_t i = 0; i < size4; ++i) // vectorize if you can
391  {
392  data[k] *= calib; // prescale by plane-to-plane calibration factors
393  data[k + 1] *= calib;
394  data[k + 2] *= calib;
395  data[k + 3] *= calib;
396 
397  if (data[k] < fAdcMin) { data[k] = fAdcMin; } // saturate min
398  if (data[k + 1] < fAdcMin) { data[k + 1] = fAdcMin; }
399  if (data[k + 2] < fAdcMin) { data[k + 2] = fAdcMin; }
400  if (data[k + 3] < fAdcMin) { data[k + 3] = fAdcMin; }
401 
402  if (data[k] > fAdcMax) { data[k] = fAdcMax; } // saturate max
403  if (data[k + 1] > fAdcMax) { data[k + 1] = fAdcMax; }
404  if (data[k + 2] > fAdcMax) { data[k + 2] = fAdcMax; }
405  if (data[k + 3] > fAdcMax) { data[k + 3] = fAdcMax; }
406 
407  data[k] = fAdcOffset +
408  fAdcScale *
409  (data[k] - fAdcMin); // shift and scale to the output range, shift to the output min
410  data[k + 1] = fAdcOffset + fAdcScale * (data[k + 1] - fAdcMin);
411  data[k + 2] = fAdcOffset + fAdcScale * (data[k + 2] - fAdcMin);
412  data[k + 3] = fAdcOffset + fAdcScale * (data[k + 3] - fAdcMin);
413 
414  k += 4;
415  }
416  while (k < size) {
417  data[k] = scaleAdcSample(data[k]);
418  ++k;
419  } // do the tail
420 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
float scaleAdcSample(float val) const
std::vector< float > fAmplCalibConst
std::optional< std::vector< float > > img::DataProviderAlg::setWireData ( std::vector< float > const &  adc,
size_t  wireIdx 
) const
protected

Definition at line 272 of file DataProviderAlg.cxx.

273 {
274  if (wireIdx >= fAlgView.fWireDriftData.size()) return std::nullopt;
275  auto& wData = fAlgView.fWireDriftData[wireIdx];
276 
277  if (fDownscaleFullView) {
278  if (!adc.empty()) { return downscale(wData.size(), adc, 0); }
279  else {
280  return std::nullopt;
281  }
282  }
283  else {
284  if (adc.empty()) { return std::nullopt; }
285  else if (adc.size() <= wData.size())
286  return adc;
287  else {
288  return std::vector<float>(adc.begin(), adc.begin() + wData.size());
289  }
290  }
291  return std::make_optional(wData);
292 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
int16_t adc
Definition: CRTFragment.hh:202
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 
)

Definition at line 296 of file DataProviderAlg.cxx.

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

Definition at line 172 of file DataProviderAlg.h.

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

Definition at line 111 of file DataProviderAlg.h.

112  {
113  return fAlgView.fWireDriftData[widx];
114  }
std::vector< std::vector< float > > fWireDriftData
DataProviderAlgView fAlgView
float img::DataProviderAlg::ZeroLevel ( ) const
inline

Level of zero ADC after scaling.

Definition at line 205 of file DataProviderAlg.h.

206  {
207  return fAdcZero;
208  }

Member Data Documentation

size_t img::DataProviderAlg::fAdcAreaOverThr
private

Definition at line 289 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcMax
private

Definition at line 287 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcMin
private

Definition at line 287 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcOffset
private

Definition at line 287 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcScale
private

Definition at line 287 of file DataProviderAlg.h.

double img::DataProviderAlg::fAdcSumOverThr
private

Definition at line 288 of file DataProviderAlg.h.

double img::DataProviderAlg::fAdcSumThr
private

Definition at line 288 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcZero
private

Definition at line 287 of file DataProviderAlg.h.

DataProviderAlgView img::DataProviderAlg::fAlgView
protected

Definition at line 219 of file DataProviderAlg.h.

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

Definition at line 284 of file DataProviderAlg.h.

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

Definition at line 294 of file DataProviderAlg.h.

bool img::DataProviderAlg::fCalibrateAmpl
private

Definition at line 285 of file DataProviderAlg.h.

bool img::DataProviderAlg::fCalibrateLifetime
private

Definition at line 285 of file DataProviderAlg.h.

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

Definition at line 276 of file DataProviderAlg.h.

float img::DataProviderAlg::fCoherentSigma
private

Definition at line 300 of file DataProviderAlg.h.

unsigned int img::DataProviderAlg::fCryo = 9999
private

Definition at line 286 of file DataProviderAlg.h.

bool img::DataProviderAlg::fDownscaleFullView
protected

Definition at line 224 of file DataProviderAlg.h.

EDownscaleMode img::DataProviderAlg::fDownscaleMode
protected

Definition at line 220 of file DataProviderAlg.h.

size_t img::DataProviderAlg::fDriftWindow
protected

Definition at line 223 of file DataProviderAlg.h.

float img::DataProviderAlg::fDriftWindowInv
protected

Definition at line 225 of file DataProviderAlg.h.

geo::GeometryCore const* img::DataProviderAlg::fGeometry
protected

Definition at line 279 of file DataProviderAlg.h.

float img::DataProviderAlg::fNoiseSigma
private

Definition at line 297 of file DataProviderAlg.h.

unsigned int img::DataProviderAlg::fPlane = 9999
private

Definition at line 286 of file DataProviderAlg.h.

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

Definition at line 291 of file DataProviderAlg.h.

unsigned int img::DataProviderAlg::fTPC = 9999
private

Definition at line 286 of file DataProviderAlg.h.


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