All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>

Classes

struct  Config
 

Public Types

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

Public Member Functions

 DataProviderAlg (const fhicl::ParameterSet &pset)
 
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 60 of file DataProviderAlg.h.

Member Enumeration Documentation

Enumerator
kMax 
kMaxMean 
kMean 

Definition at line 62 of file DataProviderAlg.h.

Constructor & Destructor Documentation

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

Definition at line 99 of file DataProviderAlg.h.

100  : DataProviderAlg(fhicl::Table<Config>(pset, {})())
DataProviderAlg(const fhicl::ParameterSet &pset)
img::DataProviderAlg::~DataProviderAlg ( )
virtualdefault

Member Function Documentation

void img::DataProviderAlg::addCoherentNoise ( )
private

Definition at line 555 of file DataProviderAlg.cxx.

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

Definition at line 536 of file DataProviderAlg.cxx.

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

Definition at line 430 of file DataProviderAlg.cxx.

431 {
432  if (fBlurKernel.size() < 2) return;
433 
434  size_t margin_left = (fBlurKernel.size() - 1) >> 1,
435  margin_right = fBlurKernel.size() - margin_left - 1;
436 
437  std::vector<std::vector<float>> src(fAlgView.fWireDriftData.size());
438  for (size_t w = 0; w < fAlgView.fWireDriftData.size(); ++w) {
439  src[w] = fAlgView.fWireDriftData[w];
440  }
441 
442  for (size_t w = margin_left; w < fAlgView.fWireDriftData.size() - margin_right; ++w) {
443  for (size_t d = 0; d < fAlgView.fWireDriftData[w].size(); ++d) {
444  float sum = 0;
445  for (size_t i = 0; i < fBlurKernel.size(); ++i) {
446  sum += fBlurKernel[i] * src[w + i - margin_left][d];
447  }
448  fAlgView.fWireDriftData[w][d] = sum;
449  }
450  }
451 }
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 173 of file DataProviderAlg.h.

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

Definition at line 243 of file DataProviderAlg.h.

244  {
245  switch (fDownscaleMode) {
246  case img::DataProviderAlg::kMean: return downscaleMean(dst_size, adc, tick0);
247  case img::DataProviderAlg::kMaxMean: return downscaleMaxMean(dst_size, adc, tick0);
248  case img::DataProviderAlg::kMax: return downscaleMax(dst_size, adc, tick0);
249  }
250  throw cet::exception("img::DataProviderAlg") << "Downscale mode not supported." << std::endl;
251  }
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
std::vector< float > img::DataProviderAlg::downscaleMax ( std::size_t  dst_size,
std::vector< float > const &  adc,
size_t  tick0 
) const
protected

Definition at line 198 of file DataProviderAlg.cxx.

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

Definition at line 220 of file DataProviderAlg.cxx.

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

Definition at line 256 of file DataProviderAlg.cxx.

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

Definition at line 204 of file DataProviderAlg.h.

205  {
206  return fDriftWindow;
207  }
size_t img::DataProviderAlg::getAdcArea ( ) const
inline

Definition at line 161 of file DataProviderAlg.h.

162  {
163  return fAdcAreaOverThr;
164  }
double img::DataProviderAlg::getAdcSum ( ) const
inline

Definition at line 156 of file DataProviderAlg.h.

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

Definition at line 254 of file DataProviderAlg.h.

255  {
256  if (fDownscaleFullView)
257  return (size_t)(drift * fDriftWindowInv);
258  else
259  return (size_t)drift;
260  }
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 126 of file DataProviderAlg.h.

127  {
128  bool ok = false;
129  std::vector<std::vector<float>> patch;
130  if (fDownscaleFullView) {
131  ok = patchFromDownsampledView(wire, drift, patchSizeW, patchSizeD, patch);
132  }
133  else {
134  ok = patchFromOriginalView(wire, drift, patchSizeW, patchSizeD, patch);
135  }
136 
137  if (ok)
138  return patch;
139  throw cet::exception("img::DataProviderAlg") << "Patch filling failed." << std::endl;
140  }
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
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 145 of file DataProviderAlg.h.

146  {
147  size_t didx = getDriftIndex(drift), widx = (size_t)wire;
148 
149  if ((widx < fAlgView.fWireDriftData.size()) && (didx < fAlgView.fNCachedDrifts)) {
150  return fAlgView.fWireDriftData[widx][didx];
151  }
152  return 0;
153  }
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 217 of file DataProviderAlg.h.

220  {
221  return fCalorimetryAlg.LifetimeCorrection(clock_data, det_prop, tick);
222  }
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 199 of file DataProviderAlg.h.

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

Definition at line 194 of file DataProviderAlg.h.

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

Definition at line 189 of file DataProviderAlg.h.

190  {
191  return fAlgView.fNWires;
192  }
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 456 of file DataProviderAlg.cxx.

461 {
462  int halfSizeW = size_w / 2;
463  int halfSizeD = size_d / 2;
464 
465  int w0 = wire - halfSizeW;
466  int w1 = wire + halfSizeW;
467 
468  size_t sd = (size_t)(drift / fDriftWindow);
469  int d0 = sd - halfSizeD;
470  int d1 = sd + halfSizeD;
471 
472  int wsize = fAlgView.fWireDriftData.size();
473  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch) {
474  auto& dst = patch[wpatch];
475  if ((w >= 0) && (w < wsize)) {
476  auto& src = fAlgView.fWireDriftData[w];
477  int dsize = src.size();
478  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch) {
479  if ((d >= 0) && (d < dsize)) { dst[dpatch] = src[d]; }
480  else {
481  dst[dpatch] = fAdcZero;
482  }
483  }
484  }
485  else {
486  std::fill(dst.begin(), dst.end(), fAdcZero);
487  }
488  }
489 
490  return true;
491 }
std::vector< std::vector< float > > fWireDriftData
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
DataProviderAlgView fAlgView
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 494 of file DataProviderAlg.cxx.

499 {
500  int dsize = fDriftWindow * size_d;
501  int halfSizeW = size_w / 2;
502  int halfSizeD = dsize / 2;
503 
504  int w0 = wire - halfSizeW;
505  int w1 = wire + halfSizeW;
506 
507  int d0 = int(drift) - halfSizeD;
508  int d1 = int(drift) + halfSizeD;
509 
510  if (d0 < 0) d0 = 0;
511 
512  std::vector<float> tmp(dsize);
513  int wsize = fAlgView.fWireDriftData.size();
514  for (int w = w0, wpatch = 0; w < w1; ++w, ++wpatch) {
515  if ((w >= 0) && (w < wsize)) {
516  auto& src = fAlgView.fWireDriftData[w];
517  int src_size = src.size();
518  for (int d = d0, dpatch = 0; d < d1; ++d, ++dpatch) {
519  if ((d >= 0) && (d < src_size)) { tmp[dpatch] = src[d]; }
520  else {
521  tmp[dpatch] = fAdcZero;
522  }
523  }
524  }
525  else {
526  std::fill(tmp.begin(), tmp.end(), fAdcZero);
527  }
528  patch[wpatch] = downscale(patch[wpatch].size(), tmp, d0);
529  }
530 
531  return true;
532 }
std::vector< std::vector< float > > fWireDriftData
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
DataProviderAlgView fAlgView
unsigned int img::DataProviderAlg::Plane ( ) const
inline

Definition at line 183 of file DataProviderAlg.h.

184  {
185  return fPlane;
186  }
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 146 of file DataProviderAlg.cxx.

147 {
148  size_t rw = r, rd = r;
149  if (!fDownscaleFullView) { rd *= fDriftWindow; }
150 
151  size_t didx = getDriftIndex(drift);
152  int d0 = didx - rd;
153  if (d0 < 0) { d0 = 0; }
154  int d1 = didx + rd;
155  if (d1 >= (int)fAlgView.fNCachedDrifts) { d1 = fAlgView.fNCachedDrifts - 1; }
156 
157  int w0 = wire - rw;
158  if (w0 < 0) { w0 = 0; }
159  int w1 = wire + rw;
160  if (w1 >= (int)fAlgView.fNWires) { w1 = fAlgView.fNWires - 1; }
161 
162  float adc, max_adc = 0;
163  for (int w = w0; w <= w1; ++w) {
164  auto const* col = fAlgView.fWireDriftData[w].data();
165  for (int d = d0; d <= d1; ++d) {
166  adc = col[d];
167  if (adc > max_adc) { max_adc = adc; }
168  }
169  }
170 
171  return max_adc;
172 }
std::vector< std::vector< float > > fWireDriftData
DataProviderAlgView fAlgView
esac echo uname r
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

Definition at line 115 of file DataProviderAlg.cxx.

119 {
121  result.fNWires = wires;
122  result.fNDrifts = drifts;
123  result.fNScaledDrifts = drifts / fDriftWindow;
124  result.fNCachedDrifts = fDownscaleFullView ? result.fNScaledDrifts : drifts;
125 
126  result.fWireChannels.resize(wires, raw::InvalidChannelID);
127 
128  result.fWireDriftData.resize(wires, std::vector<float>(result.fNCachedDrifts, fAdcZero));
129 
130  result.fLifetimeCorrFactors.resize(drifts);
131  if (fCalibrateLifetime) {
132  for (size_t t = 0; t < drifts; ++t) {
133  result.fLifetimeCorrFactors[t] = fCalorimetryAlg.LifetimeCorrection(clock_data, det_prop, t);
134  }
135  }
136  else {
137  for (size_t t = 0; t < drifts; ++t) {
138  result.fLifetimeCorrFactors[t] = 1.0;
139  }
140  }
141  return result;
142 }
std::vector< std::vector< float > > fWireDriftData
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h: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 375 of file DataProviderAlg.cxx.

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

Definition at line 390 of file DataProviderAlg.cxx.

391 {
392  float calib = fAmplCalibConst[fPlane];
393  auto* data = values.data();
394 
395  size_t k = 0, size4 = values.size() >> 2, size = values.size();
396  for (size_t i = 0; i < size4; ++i) // vectorize if you can
397  {
398  data[k] *= calib; // prescale by plane-to-plane calibration factors
399  data[k + 1] *= calib;
400  data[k + 2] *= calib;
401  data[k + 3] *= calib;
402 
403  if (data[k] < fAdcMin) { data[k] = fAdcMin; } // saturate min
404  if (data[k + 1] < fAdcMin) { data[k + 1] = fAdcMin; }
405  if (data[k + 2] < fAdcMin) { data[k + 2] = fAdcMin; }
406  if (data[k + 3] < fAdcMin) { data[k + 3] = fAdcMin; }
407 
408  if (data[k] > fAdcMax) { data[k] = fAdcMax; } // saturate max
409  if (data[k + 1] > fAdcMax) { data[k + 1] = fAdcMax; }
410  if (data[k + 2] > fAdcMax) { data[k + 2] = fAdcMax; }
411  if (data[k + 3] > fAdcMax) { data[k + 3] = fAdcMax; }
412 
413  data[k] = fAdcOffset +
414  fAdcScale *
415  (data[k] - fAdcMin); // shift and scale to the output range, shift to the output min
416  data[k + 1] = fAdcOffset + fAdcScale * (data[k + 1] - fAdcMin);
417  data[k + 2] = fAdcOffset + fAdcScale * (data[k + 2] - fAdcMin);
418  data[k + 3] = fAdcOffset + fAdcScale * (data[k + 3] - fAdcMin);
419 
420  k += 4;
421  }
422  while (k < size) {
423  data[k] = scaleAdcSample(data[k]);
424  ++k;
425  } // do the tail
426 }
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
float scaleAdcSample(float val) const
std::vector< float > fAmplCalibConst
pdgs k
Definition: selectors.fcl:22
std::optional< std::vector< float > > img::DataProviderAlg::setWireData ( std::vector< float > const &  adc,
size_t  wireIdx 
) const
protected

Definition at line 278 of file DataProviderAlg.cxx.

279 {
280  if (wireIdx >= fAlgView.fWireDriftData.size()) return std::nullopt;
281  auto& wData = fAlgView.fWireDriftData[wireIdx];
282 
283  if (fDownscaleFullView) {
284  if (!adc.empty()) { return downscale(wData.size(), adc, 0); }
285  else {
286  return std::nullopt;
287  }
288  }
289  else {
290  if (adc.empty()) { return std::nullopt; }
291  else if (adc.size() <= wData.size())
292  return adc;
293  else {
294  return std::vector<float>(adc.begin(), adc.begin() + wData.size());
295  }
296  }
297  return std::make_optional(wData);
298 }
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 302 of file DataProviderAlg.cxx.

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

Definition at line 178 of file DataProviderAlg.h.

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

Definition at line 117 of file DataProviderAlg.h.

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

Level of zero ADC after scaling.

Definition at line 211 of file DataProviderAlg.h.

212  {
213  return fAdcZero;
214  }

Member Data Documentation

size_t img::DataProviderAlg::fAdcAreaOverThr
private

Definition at line 295 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcMax
private

Definition at line 293 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcMin
private

Definition at line 293 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcOffset
private

Definition at line 293 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcScale
private

Definition at line 293 of file DataProviderAlg.h.

double img::DataProviderAlg::fAdcSumOverThr
private

Definition at line 294 of file DataProviderAlg.h.

double img::DataProviderAlg::fAdcSumThr
private

Definition at line 294 of file DataProviderAlg.h.

float img::DataProviderAlg::fAdcZero
private

Definition at line 293 of file DataProviderAlg.h.

DataProviderAlgView img::DataProviderAlg::fAlgView
protected

Definition at line 225 of file DataProviderAlg.h.

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

Definition at line 290 of file DataProviderAlg.h.

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

Definition at line 300 of file DataProviderAlg.h.

bool img::DataProviderAlg::fCalibrateAmpl
private

Definition at line 291 of file DataProviderAlg.h.

bool img::DataProviderAlg::fCalibrateLifetime
private

Definition at line 291 of file DataProviderAlg.h.

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

Definition at line 282 of file DataProviderAlg.h.

float img::DataProviderAlg::fCoherentSigma
private

Definition at line 306 of file DataProviderAlg.h.

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

Definition at line 292 of file DataProviderAlg.h.

bool img::DataProviderAlg::fDownscaleFullView
protected

Definition at line 230 of file DataProviderAlg.h.

EDownscaleMode img::DataProviderAlg::fDownscaleMode
protected

Definition at line 226 of file DataProviderAlg.h.

size_t img::DataProviderAlg::fDriftWindow
protected

Definition at line 229 of file DataProviderAlg.h.

float img::DataProviderAlg::fDriftWindowInv
protected

Definition at line 231 of file DataProviderAlg.h.

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

Definition at line 285 of file DataProviderAlg.h.

float img::DataProviderAlg::fNoiseSigma
private

Definition at line 303 of file DataProviderAlg.h.

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

Definition at line 292 of file DataProviderAlg.h.

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

Definition at line 297 of file DataProviderAlg.h.

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

Definition at line 292 of file DataProviderAlg.h.


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