9 #include "cetlib_except/exception.h" 14 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h" 15 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h" 17 class DetectorClocksData;
25 #include "CLHEP/Random/RandGauss.h" 50 mf::LogInfo(
"DataProviderAlg") <<
"Using calibration constants:";
62 mf::LogInfo(
"DataProviderAlg") <<
"No plane-to-plane calibration.";
72 std::string mode_str = config.DownscaleFn();
73 mf::LogVerbatim(
"DataProviderAlg") <<
"Downscale mode is: " << mode_str;
74 if (mode_str ==
"maxpool") {
78 else if (mode_str ==
"maxmean") {
82 else if (mode_str ==
"mean") {
87 mf::LogError(
"DataProviderAlg") <<
"Downscale mode string not recognized, set to max pooling.";
99 throw cet::exception(
"img::DataProviderAlg") <<
"Misconfigured: AdcMax <= AdcMin" << std::endl;
102 throw cet::exception(
"img::DataProviderAlg") <<
"Misconfigured: OutMax == OutMin" << std::endl;
132 for (
size_t t = 0; t < drifts; ++t) {
137 for (
size_t t = 0; t < drifts; ++t) {
147 size_t rw =
r, rd =
r;
152 if (d0 < 0) { d0 = 0; }
157 if (w0 < 0) { w0 = 0; }
161 float adc, max_adc = 0;
162 for (
int w = w0;
w <= w1; ++
w) {
164 for (
int d = d0;
d <= d1; ++
d) {
166 if (adc > max_adc) { max_adc = adc; }
197 std::vector<float>
const& adc,
200 size_t kStop = dst_size;
201 std::vector<float> result(dst_size);
202 if (adc.size() < kStop) { kStop = adc.size(); }
203 for (
size_t i = 0, k0 = 0; i < kStop; ++i, k0 +=
fDriftWindow) {
207 for (
size_t k = k0 + 1; k < k1; ++k) {
209 if (ak > max_adc) max_adc = ak;
218 std::vector<float>
const& adc,
221 size_t kStop = dst_size;
222 std::vector<float> result(dst_size);
223 if (adc.size() < kStop) { kStop = adc.size(); }
224 for (
size_t i = 0, k0 = 0; i < kStop; ++i, k0 +=
fDriftWindow) {
228 for (
size_t k = k0 + 1; k < k1; ++k) {
241 if (max_idx + 1 < adc.size()) {
246 result[i] = max_adc /
n;
253 std::vector<float>
const& adc,
256 size_t kStop = dst_size;
257 std::vector<float> result(dst_size);
258 if (adc.size() < kStop) { kStop = adc.size(); }
259 for (
size_t i = 0, k0 = 0; i < kStop; ++i, k0 +=
fDriftWindow) {
263 for (
size_t k = k0; k < k1; ++k) {
274 size_t wireIdx)
const 280 if (!adc.empty()) {
return downscale(wData.size(), adc, 0); }
283 if (adc.empty()) {
return std::nullopt; }
284 if (adc.size() <= wData.size()) {
return adc; }
285 return std::vector<float>(adc.begin(), adc.begin() + wData.size());
291 const std::vector<recob::Wire>& wires,
296 mf::LogInfo(
"DataProviderAlg") <<
"Create image for cryo:" << cryo <<
" tpc:" << tpc
297 <<
" plane:" << plane;
311 auto const& channelStatus =
314 bool allWrong =
true;
315 for (
auto const& wire : wires) {
316 auto wireChannelNumber = wire.Channel();
317 if (!channelStatus.IsGood(wireChannelNumber)) {
continue; }
321 if ((
id.
Plane == plane) && (
id.TPC == tpc) && (
id.Cryostat == cryo)) {
324 auto adc = wire.Signal();
325 if (adc.size() < ndrifts) {
326 mf::LogWarning(
"DataProviderAlg") <<
"Wire ADC vector size lower than NumberTimeSamples.";
349 <<
"Wires data not set in the cryo:" << cryo <<
" tpc:" << tpc <<
" plane:" << plane;
378 auto* data = values.data();
380 size_t k = 0, size4 = values.size() >> 2,
size = values.size();
381 for (
size_t i = 0; i < size4; ++i)
384 data[k + 1] *= calib;
385 data[k + 2] *= calib;
386 data[k + 3] *= calib;
418 size_t margin_left = (
fBlurKernel.size() - 1) >> 1,
419 margin_right =
fBlurKernel.size() - margin_left - 1;
445 int halfSizeW = size_w / 2;
446 int halfSizeD = size_d / 2;
448 int w0 = wire - halfSizeW;
449 int w1 = wire + halfSizeW;
452 int d0 = sd - halfSizeD;
453 int d1 = sd + halfSizeD;
456 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch) {
457 auto& dst = patch[wpatch];
458 if ((
w >= 0) && (
w < wsize)) {
460 int dsize = src.size();
461 for (
int d = d0, dpatch = 0;
d < d1; ++
d, ++dpatch) {
462 if ((
d >= 0) && (
d < dsize)) { dst[dpatch] = src[
d]; }
483 int halfSizeW = size_w / 2;
484 int halfSizeD = dsize / 2;
486 int w0 = wire - halfSizeW;
487 int w1 = wire + halfSizeW;
489 int d0 = int(drift) - halfSizeD;
490 int d1 = int(drift) + halfSizeD;
494 std::vector<float>
tmp(dsize);
496 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch) {
497 if ((
w >= 0) && (
w < wsize)) {
499 int src_size = src.size();
500 for (
int d = d0, dpatch = 0;
d < d1; ++
d, ++dpatch) {
501 if ((
d >= 0) && (
d < src_size)) { tmp[dpatch] = src[
d]; }
528 for (
size_t d = 0;
d < wire.size(); ++
d) {
545 gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1);
546 gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1);
548 double group_amp = 1.0;
552 group_amp = amps2[
w >> 5];
557 for (
size_t d = 0;
d < wire.size(); ++
d) {
558 wire[
d] += group_amp * amps1[
w] * noise[
d];
geo::GeometryCore const * fGeometry
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::optional< std::vector< float > > setWireData(std::vector< float > const &adc, size_t wireIdx) const
unsigned int fNCachedDrifts
std::vector< std::vector< float > > fWireDriftData
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
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)
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
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
std::vector< float > fBlurKernel
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double ElectronsFromADCPeak(double adc, unsigned short plane) const
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.
std::vector< float > downscaleMean(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
unsigned int fNScaledDrifts
void scaleAdcSamples(std::vector< float > &values) const
std::vector< raw::ChannelID_t > fWireChannels
unsigned int NumberTimeSamples() const
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
General LArSoft Utilities.
float scaleAdcSample(float val) const
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
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
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< float > fAmplCalibConst
unsigned int Nwires(PlaneID const &planeid) const
Returns the total number of wires in the specified plane.
Declaration of basic channel signal object.
bool patchFromDownsampledView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float >> &patch) const
EDownscaleMode fDownscaleMode
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.
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
Namespace collecting geometry-related classes utilities.
size_t getDriftIndex(float drift) const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception