18 class DetectorProperties;
24 #include "CLHEP/Random/RandGauss.h" 44 mf::LogInfo(
"DataProviderAlg") <<
"Using calibration constants:";
56 mf::LogInfo(
"DataProviderAlg") <<
"No plane-to-plane calibration.";
67 mf::LogVerbatim(
"DataProviderAlg") <<
"Downscale mode is: " << mode_str;
68 if (mode_str ==
"maxpool") {
72 else if (mode_str ==
"maxmean") {
76 else if (mode_str ==
"mean") {
81 mf::LogError(
"DataProviderAlg") <<
"Downscale mode string not recognized, set to max pooling.";
126 for (
size_t t = 0;
t < drifts; ++
t) {
131 for (
size_t t = 0;
t < drifts; ++
t) {
142 size_t rw =
r, rd =
r;
147 if (d0 < 0) { d0 = 0; }
152 if (w0 < 0) { w0 = 0; }
156 float adc, max_adc = 0;
157 for (
int w = w0;
w <= w1; ++
w) {
159 for (
int d = d0;
d <= d1; ++
d) {
161 if (adc > max_adc) { max_adc =
adc; }
193 std::vector<float>
const&
adc,
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) {
203 for (
size_t k = k0 + 1;
k < k1; ++
k) {
205 if (ak > max_adc) max_adc = ak;
215 std::vector<float>
const&
adc,
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) {
225 for (
size_t k = k0 + 1;
k < k1; ++
k) {
238 if (max_idx + 1 < adc.size()) {
243 result[i] = max_adc /
n;
251 std::vector<float>
const&
adc,
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) {
261 for (
size_t k = k0;
k < k1; ++
k) {
271 std::optional<std::vector<float>>
278 if (!adc.empty()) {
return downscale(wData.size(),
adc, 0); }
284 if (adc.empty()) {
return std::nullopt; }
285 else if (adc.size() <= wData.size())
288 return std::vector<float>(adc.begin(), adc.begin() + wData.size());
291 return std::make_optional(wData);
298 const std::vector<recob::Wire>& wires,
303 mf::LogInfo(
"DataProviderAlg") <<
"Create image for cryo:" << cryo <<
" tpc:" << tpc
304 <<
" plane:" << plane;
318 auto const& channelStatus =
321 bool allWrong =
true;
322 for (
auto const& wire : wires) {
323 auto wireChannelNumber = wire.Channel();
324 if (!channelStatus.IsGood(wireChannelNumber)) {
continue; }
328 if ((
id.
Plane == plane) && (
id.TPC == tpc) && (
id.Cryostat == cryo)) {
331 auto adc = wire.Signal();
332 if (
adc.size() < ndrifts) {
333 mf::LogWarning(
"DataProviderAlg") <<
"Wire ADC vector size lower than NumberTimeSamples.";
356 <<
"Wires data not set in the cryo:" << cryo <<
" tpc:" << tpc <<
" plane:" << plane;
387 auto*
data = values.data();
389 size_t k = 0, size4 = values.size() >> 2,
size = values.size();
390 for (
size_t i = 0; i < size4; ++i)
393 data[k + 1] *= calib;
394 data[k + 2] *= calib;
395 data[k + 3] *= calib;
428 size_t margin_left = (
fBlurKernel.size() - 1) >> 1,
429 margin_right =
fBlurKernel.size() - margin_left - 1;
456 int halfSizeW = size_w / 2;
457 int halfSizeD = size_d / 2;
459 int w0 = wire - halfSizeW;
460 int w1 = wire + halfSizeW;
463 int d0 = sd - halfSizeD;
464 int d1 = sd + halfSizeD;
467 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch) {
468 auto& dst =
patch[wpatch];
469 if ((
w >= 0) && (
w < wsize)) {
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]; }
495 int halfSizeW = size_w / 2;
496 int halfSizeD = dsize / 2;
498 int w0 = wire - halfSizeW;
499 int w1 = wire + halfSizeW;
501 int d0 =
int(drift) - halfSizeD;
502 int d1 =
int(drift) + halfSizeD;
506 std::vector<float>
tmp(dsize);
508 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch) {
509 if ((
w >= 0) && (
w < wsize)) {
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]; }
541 for (
size_t d = 0;
d < wire.size(); ++
d) {
559 gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1);
560 gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1);
562 double group_amp = 1.0;
566 group_amp = amps2[
w >> 5];
571 for (
size_t d = 0;
d < wire.size(); ++
d) {
572 wire[
d] += group_amp * amps1[
w] * noise[
d];
geo::GeometryCore const * fGeometry
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fhicl::Atom< float > AdcMax
std::optional< std::vector< float > > setWireData(std::vector< float > const &adc, size_t wireIdx) const
unsigned int fNCachedDrifts
std::vector< std::vector< float > > fWireDriftData
fhicl::Atom< float > CoherentSigma
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
virtual ~DataProviderAlg()
virtual DataProviderAlgView resizeView(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, size_t wires, size_t drifts)
fhicl::Atom< unsigned int > DriftWindow
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
DataProviderAlg(const fhicl::ParameterSet &pset)
std::vector< float > downscaleMaxMean(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
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< float > fBlurKernel
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
double ElectronsFromADCPeak(double adc, unsigned short plane) const
fhicl::Sequence< float > BlurKernel
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
std::vector< float > downscaleMax(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
fhicl::Atom< bool > DownscaleFullView
std::vector< float > downscaleMean(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
unsigned int fNScaledDrifts
void scaleAdcSamples(std::vector< float > &values) const
std::vector< raw::ChannelID_t > fWireChannels
unsigned int NumberTimeSamples() const
General LArSoft Utilities.
float scaleAdcSample(float val) const
fhicl::Atom< float > AdcMin
DataProviderAlgView fAlgView
calo::CalorimetryAlg fCalorimetryAlg
bool patchFromOriginalView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
fhicl::Atom< bool > CalibrateLifetime
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)
Contains all timing reference information for the detector.
std::vector< float > fLifetimeCorrFactors
fhicl::Table< calo::CalorimetryAlg::Config > CalorimetryAlg
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< float > fAmplCalibConst
Interface for experiment-specific channel quality info provider.
fhicl::Atom< std::string > DownscaleFn
bool patchFromDownsampledView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
fhicl::Atom< bool > CalibrateAmpl
EDownscaleMode fDownscaleMode
fhicl::Atom< float > OutMin
fhicl::Atom< float > OutMax
CLHEP::HepJamesRandom fRndEngine
float poolMax(int wire, int drift, size_t r=0) const
Pool max value in a patch around the wire/drift pixel.
Interface for experiment-specific service for channel quality info.
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
LArSoft geometry interface.
size_t getDriftIndex(float drift) const
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
fhicl::Atom< float > NoiseSigma