LArSoft  v10_04_05
Liquid Argon Software toolkit - https://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 ()
 
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::Geometry const * fGeometry
 
geo::WireReadoutGeom const * fWireReadoutGeom
 

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 60 of file DataProviderAlg.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 99 of file DataProviderAlg.h.

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

Definition at line 29 of file DataProviderAlg.cxx.

References calo::CalorimetryAlg::ElectronsFromADCPeak(), fAdcAreaOverThr, fAdcMax, fAdcMin, fAdcOffset, fAdcScale, fAdcSumOverThr, fAdcSumThr, fAdcZero, fAmplCalibConst, fBlurKernel, fCalibrateAmpl, fCalibrateLifetime, fCalorimetryAlg, fCoherentSigma, fDownscaleFullView, fDownscaleMode, fDriftWindow, fDriftWindowInv, fGeometry, fNoiseSigma, fWireReadoutGeom, Get, kMax, kMaxMean, kMean, geo::WireReadoutGeom::MaxPlanes(), and ~DataProviderAlg().

30  : fAlgView{}
32  , fDriftWindow(10)
33  , fCalorimetryAlg(config.CalorimetryAlg())
36  , fAdcSumOverThr(0)
37  , fAdcSumThr(10) // set fixed threshold of 10 ADC counts for counting the sum
38  , fAdcAreaOverThr(0)
39  , fNoiseSigma(0)
40  , fCoherentSigma(0)
41 {
42  fCalibrateLifetime = config.CalibrateLifetime();
43  fCalibrateAmpl = config.CalibrateAmpl();
44 
46  if (fCalibrateAmpl) {
47  mf::LogInfo("DataProviderAlg") << "Using calibration constants:";
48  for (size_t p = 0; p < fAmplCalibConst.size(); ++p) {
49  try {
51  mf::LogInfo("DataProviderAlg") << " plane:" << p << " const:" << 1.0 / fAmplCalibConst[p];
52  }
53  catch (...) {
54  fAmplCalibConst[p] = 1.0;
55  }
56  }
57  }
58  else {
59  mf::LogInfo("DataProviderAlg") << "No plane-to-plane calibration.";
60  for (size_t p = 0; p < fAmplCalibConst.size(); ++p) {
61  fAmplCalibConst[p] = 1.0;
62  }
63  }
64 
65  fDriftWindow = config.DriftWindow();
66  fDownscaleFullView = config.DownscaleFullView();
68 
69  std::string mode_str = config.DownscaleFn();
70  mf::LogVerbatim("DataProviderAlg") << "Downscale mode is: " << mode_str;
71  if (mode_str == "maxpool") {
72  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMax(dst, adc, tick0); };
74  }
75  else if (mode_str == "maxmean") {
76  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMaxMean(dst, adc, tick0); };
78  }
79  else if (mode_str == "mean") {
80  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMean(dst, adc, tick0); };
82  }
83  else {
84  mf::LogError("DataProviderAlg") << "Downscale mode string not recognized, set to max pooling.";
85  //fnDownscale = [this](std::vector<float> & dst, std::vector<float> const & adc, size_t tick0) { downscaleMax(dst, adc, tick0); };
87  }
88 
89  fAdcMax = config.AdcMax();
90  fAdcMin = config.AdcMin();
91  fAdcOffset = config.OutMin();
92  fAdcScale = (config.OutMax() - fAdcOffset) / (fAdcMax - fAdcMin);
93  fAdcZero = fAdcOffset + fAdcScale * (0 - fAdcMin); // level of zero ADC after scaling
94 
95  if (fAdcMax <= fAdcMin) {
96  throw cet::exception("img::DataProviderAlg") << "Misconfigured: AdcMax <= AdcMin" << std::endl;
97  }
98  if (fAdcScale == 0) {
99  throw cet::exception("img::DataProviderAlg") << "Misconfigured: OutMax == OutMin" << std::endl;
100  }
101 
102  fBlurKernel = config.BlurKernel();
103  fNoiseSigma = config.NoiseSigma();
104  fCoherentSigma = config.CoherentSigma();
105 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
geo::Geometry const * fGeometry
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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.
geo::WireReadoutGeom const * fWireReadoutGeom
DataProviderAlgView fAlgView
calo::CalorimetryAlg fCalorimetryAlg
std::vector< float > fAmplCalibConst
EDownscaleMode fDownscaleMode
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
img::DataProviderAlg::~DataProviderAlg ( )
virtualdefault

Referenced by DataProviderAlg().

Member Function Documentation

void img::DataProviderAlg::addCoherentNoise ( )
private

Definition at line 532 of file DataProviderAlg.cxx.

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

Referenced by setWireDriftData().

533 {
534  if (fCoherentSigma == 0) return;
535 
536  double effectiveSigma = scaleAdcSample(fCoherentSigma);
537  if (fDownscaleFullView) effectiveSigma /= fDriftWindow;
538 
539  CLHEP::RandGauss gauss(fRndEngine);
540  std::vector<double> amps1(fAlgView.fWireDriftData.size());
541  std::vector<double> amps2(1 + (fAlgView.fWireDriftData.size() / 32));
542  gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1); // 10% wire-wire ampl. variation
543  gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1); // 10% group-group ampl. variation
544 
545  double group_amp = 1.0;
546  std::vector<double> noise(fAlgView.fNCachedDrifts);
547  for (size_t w = 0; w < fAlgView.fWireDriftData.size(); ++w) {
548  if ((w & 31) == 0) {
549  group_amp = amps2[w >> 5]; // div by 32
550  gauss.fireArray(fAlgView.fNCachedDrifts, noise.data(), 0., effectiveSigma);
551  } // every 32 wires
552 
553  auto& wire = fAlgView.fWireDriftData[w];
554  for (size_t d = 0; d < wire.size(); ++d) {
555  wire[d] += group_amp * amps1[w] * noise[d];
556  }
557  }
558 }
std::vector< std::vector< float > > fWireDriftData
unsigned int noise()
Definition: chem4.cc:261
Float_t d
Definition: plot.C:235
float scaleAdcSample(float val) const
DataProviderAlgView fAlgView
CLHEP::HepJamesRandom fRndEngine
Float_t w
Definition: plot.C:20
void img::DataProviderAlg::addWhiteNoise ( )
private

Definition at line 514 of file DataProviderAlg.cxx.

References d, fAlgView, fDownscaleFullView, fDriftWindow, img::DataProviderAlgView::fNCachedDrifts, fNoiseSigma, fRndEngine, img::DataProviderAlgView::fWireDriftData, noise(), and scaleAdcSample().

Referenced by setWireDriftData().

515 {
516  if (fNoiseSigma == 0) return;
517 
518  double effectiveSigma = scaleAdcSample(fNoiseSigma);
519  if (fDownscaleFullView) effectiveSigma /= fDriftWindow;
520 
521  CLHEP::RandGauss gauss(fRndEngine);
522  std::vector<double> noise(fAlgView.fNCachedDrifts);
523  for (auto& wire : fAlgView.fWireDriftData) {
524  gauss.fireArray(fAlgView.fNCachedDrifts, noise.data(), 0., effectiveSigma);
525  for (size_t d = 0; d < wire.size(); ++d) {
526  wire[d] += noise[d];
527  }
528  }
529 }
std::vector< std::vector< float > > fWireDriftData
unsigned int noise()
Definition: chem4.cc:261
Float_t d
Definition: plot.C:235
float scaleAdcSample(float val) const
DataProviderAlgView fAlgView
CLHEP::HepJamesRandom fRndEngine
void img::DataProviderAlg::applyBlur ( )
private

Definition at line 411 of file DataProviderAlg.cxx.

References d, fAlgView, fBlurKernel, img::DataProviderAlgView::fWireDriftData, sum, and w.

Referenced by setWireDriftData().

412 {
413  if (fBlurKernel.size() < 2) return;
414 
415  size_t margin_left = (fBlurKernel.size() - 1) >> 1,
416  margin_right = fBlurKernel.size() - margin_left - 1;
417 
418  std::vector<std::vector<float>> src(fAlgView.fWireDriftData.size());
419  for (size_t w = 0; w < fAlgView.fWireDriftData.size(); ++w) {
420  src[w] = fAlgView.fWireDriftData[w];
421  }
422 
423  for (size_t w = margin_left; w < fAlgView.fWireDriftData.size() - margin_right; ++w) {
424  for (size_t d = 0; d < fAlgView.fWireDriftData[w].size(); ++d) {
425  float sum = 0;
426  for (size_t i = 0; i < fBlurKernel.size(); ++i) {
427  sum += fBlurKernel[i] * src[w + i - margin_left][d];
428  }
430  }
431  }
432 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > fBlurKernel
Float_t d
Definition: plot.C:235
DataProviderAlgView fAlgView
Double_t sum
Definition: plot.C:31
Float_t w
Definition: plot.C:20
unsigned int img::DataProviderAlg::Cryo ( ) const
inline

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

Definition at line 159 of file DataProviderAlg.h.

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

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

Definition at line 196 of file DataProviderAlg.h.

References kMax, kMaxMean, and kMean.

Referenced by patchFromOriginalView(), and setWireData().

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

Definition at line 193 of file DataProviderAlg.cxx.

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

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

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

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  }
245  scaleAdcSamples(result);
246  return result;
247 }
void scaleAdcSamples(std::vector< float > &values) const
DataProviderAlgView fAlgView
std::vector< float > fLifetimeCorrFactors
Char_t n[5]
std::vector< float > img::DataProviderAlg::downscaleMean ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
protected

Definition at line 249 of file DataProviderAlg.cxx.

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

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

Definition at line 166 of file DataProviderAlg.h.

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

Definition at line 151 of file DataProviderAlg.h.

References r.

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

Definition at line 150 of file DataProviderAlg.h.

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

Definition at line 208 of file DataProviderAlg.h.

References lar::dump::vector().

Referenced by poolMax().

209  {
210  if (fDownscaleFullView)
211  return (size_t)(drift * fDriftWindowInv);
212  else
213  return (size_t)drift;
214  }
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.

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

141  {
142  size_t didx = getDriftIndex(drift), widx = (size_t)wire;
143 
144  if ((widx < fAlgView.fWireDriftData.size()) && (didx < fAlgView.fNCachedDrifts)) {
145  return fAlgView.fWireDriftData[widx][didx];
146  }
147  return 0;
148  }
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 171 of file DataProviderAlg.h.

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

Definition at line 165 of file DataProviderAlg.h.

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

Definition at line 164 of file DataProviderAlg.h.

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

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

Definition at line 163 of file DataProviderAlg.h.

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

163 { return fAlgView.fNWires; }
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 436 of file DataProviderAlg.cxx.

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

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

Definition at line 473 of file DataProviderAlg.cxx.

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

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

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

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

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

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

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

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

Definition at line 358 of file DataProviderAlg.cxx.

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

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

359 {
360  val *= fAmplCalibConst[fPlane]; // prescale by plane-to-plane calibration factors
361 
362  if (val < fAdcMin) { val = fAdcMin; } // saturate
363  else if (val > fAdcMax) {
364  val = fAdcMax;
365  }
366 
367  return fAdcOffset +
368  fAdcScale *
369  (val - fAdcMin); // shift and scale to the output range, shift to the output min
370 }
std::vector< float > fAmplCalibConst
void img::DataProviderAlg::scaleAdcSamples ( std::vector< float > &  values) const
private

Definition at line 372 of file DataProviderAlg.cxx.

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

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

373 {
374  float calib = fAmplCalibConst[fPlane];
375  auto* data = values.data();
376 
377  size_t k = 0, size4 = values.size() >> 2, size = values.size();
378  for (size_t i = 0; i < size4; ++i) // vectorize if you can
379  {
380  data[k] *= calib; // prescale by plane-to-plane calibration factors
381  data[k + 1] *= calib;
382  data[k + 2] *= calib;
383  data[k + 3] *= calib;
384 
385  if (data[k] < fAdcMin) { data[k] = fAdcMin; } // saturate min
386  if (data[k + 1] < fAdcMin) { data[k + 1] = fAdcMin; }
387  if (data[k + 2] < fAdcMin) { data[k + 2] = fAdcMin; }
388  if (data[k + 3] < fAdcMin) { data[k + 3] = fAdcMin; }
389 
390  if (data[k] > fAdcMax) { data[k] = fAdcMax; } // saturate max
391  if (data[k + 1] > fAdcMax) { data[k + 1] = fAdcMax; }
392  if (data[k + 2] > fAdcMax) { data[k + 2] = fAdcMax; }
393  if (data[k + 3] > fAdcMax) { data[k + 3] = fAdcMax; }
394 
395  data[k] = fAdcOffset +
396  fAdcScale *
397  (data[k] - fAdcMin); // shift and scale to the output range, shift to the output min
398  data[k + 1] = fAdcOffset + fAdcScale * (data[k + 1] - fAdcMin);
399  data[k + 2] = fAdcOffset + fAdcScale * (data[k + 2] - fAdcMin);
400  data[k + 3] = fAdcOffset + fAdcScale * (data[k + 3] - fAdcMin);
401 
402  k += 4;
403  }
404  while (k < size) {
405  data[k] = scaleAdcSample(data[k]);
406  ++k;
407  } // do the tail
408 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Definition: OpHitAlg.h:20
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 270 of file DataProviderAlg.cxx.

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

Referenced by setWireDriftData().

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

Definition at line 286 of file DataProviderAlg.cxx.

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

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

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

Definition at line 160 of file DataProviderAlg.h.

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

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

Definition at line 115 of file DataProviderAlg.h.

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

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

Level of zero ADC after scaling.

Definition at line 169 of file DataProviderAlg.h.

169 { return fAdcZero; }

Member Data Documentation

size_t img::DataProviderAlg::fAdcAreaOverThr
private

Definition at line 250 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and setWireDriftData().

float img::DataProviderAlg::fAdcMax
private

Definition at line 248 of file DataProviderAlg.h.

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

float img::DataProviderAlg::fAdcMin
private

Definition at line 248 of file DataProviderAlg.h.

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

float img::DataProviderAlg::fAdcOffset
private

Definition at line 248 of file DataProviderAlg.h.

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

float img::DataProviderAlg::fAdcScale
private

Definition at line 248 of file DataProviderAlg.h.

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

double img::DataProviderAlg::fAdcSumOverThr
private

Definition at line 249 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and setWireDriftData().

double img::DataProviderAlg::fAdcSumThr
private

Definition at line 249 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and setWireDriftData().

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

Definition at line 245 of file DataProviderAlg.h.

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

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

Definition at line 255 of file DataProviderAlg.h.

Referenced by applyBlur(), and DataProviderAlg().

bool img::DataProviderAlg::fCalibrateAmpl
private

Definition at line 246 of file DataProviderAlg.h.

Referenced by DataProviderAlg().

bool img::DataProviderAlg::fCalibrateLifetime
private

Definition at line 246 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and resizeView().

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

Definition at line 236 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and resizeView().

float img::DataProviderAlg::fCoherentSigma
private

Definition at line 261 of file DataProviderAlg.h.

Referenced by addCoherentNoise(), and DataProviderAlg().

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

Definition at line 247 of file DataProviderAlg.h.

Referenced by setWireDriftData().

EDownscaleMode img::DataProviderAlg::fDownscaleMode
protected

Definition at line 180 of file DataProviderAlg.h.

Referenced by DataProviderAlg().

float img::DataProviderAlg::fDriftWindowInv
protected

Definition at line 185 of file DataProviderAlg.h.

Referenced by DataProviderAlg(), and downscaleMean().

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

Definition at line 239 of file DataProviderAlg.h.

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

float img::DataProviderAlg::fNoiseSigma
private

Definition at line 258 of file DataProviderAlg.h.

Referenced by addWhiteNoise(), and DataProviderAlg().

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

Definition at line 247 of file DataProviderAlg.h.

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

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

Definition at line 252 of file DataProviderAlg.h.

Referenced by addCoherentNoise(), and addWhiteNoise().

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

Definition at line 247 of file DataProviderAlg.h.

Referenced by setWireDriftData().

geo::WireReadoutGeom const* img::DataProviderAlg::fWireReadoutGeom
protected

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