13 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h" 14 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h" 18 #include "CLHEP/Random/RandGauss.h" 21 fCryo(9999), fTPC(9999), fPlane(9999),
22 fNWires(0), fNDrifts(0), fNScaledDrifts(0), fNCachedDrifts(0),
24 fCalorimetryAlg(config.CalorimetryAlg()),
25 fGeometry( &*(
art::ServiceHandle<
geo::Geometry>()) ),
27 fAdcSumOverThr(0), fAdcSumThr(10),
29 fNoiseSigma(0), fCoherentSigma(0)
38 mf::LogInfo(
"DataProviderAlg") <<
"Using calibration constants:";
51 mf::LogInfo(
"DataProviderAlg") <<
"No plane-to-plane calibration.";
60 mf::LogVerbatim(
"DataProviderAlg") <<
"Downscale mode is: " << mode_str;
61 if (mode_str ==
"maxpool")
66 else if (mode_str ==
"maxmean")
71 else if (mode_str ==
"mean")
78 mf::LogError(
"DataProviderAlg") <<
"Downscale mode string not recognized, set to max pooling.";
90 if (
fAdcScale == 0) {
throw cet::exception(
"img::DataProviderAlg") <<
"Misconfigured: OutMax == OutMin" << std::endl; }
135 size_t rw = r, rd = r;
139 int d0 = didx - rd;
if (d0 < 0) { d0 = 0; }
140 int d1 = didx + rd;
if (d1 >= (
int)
fNCachedDrifts) { d1 = fNCachedDrifts - 1; }
142 int w0 = wire - rw;
if (w0 < 0) { w0 = 0; }
143 int w1 = wire + rw;
if (w1 >= (
int)
fNWires) { w1 = fNWires - 1; }
145 float adc, max_adc = 0;
146 for (
int w = w0;
w <= w1; ++
w)
149 for (
int d = d0;
d <= d1; ++
d)
151 adc =
col[
d];
if (adc > max_adc) { max_adc = adc; }
161 size_t rw = r, rd = r;
165 int d0 = didx - rd;
if (d0 < 0) { d0 = 0; }
166 int d1 = didx + rd;
if (d1 >= (
int)
fNCachedDrifts) { d1 = fNCachedDrifts - 1; }
168 int w0 = wire - rw;
if (w0 < 0) { w0 = 0; }
169 int w1 = wire + rw;
if (w1 >= (
int)
fNWires) { w1 = fNWires - 1; }
172 for (
int w = w0;
w <= w1; ++
w)
175 for (
int d = d0;
d <= d1; ++
d) { sum +=
col[
d]; }
184 size_t kStop = dst.size();
185 if (adc.size() < kStop) { kStop = adc.size(); }
186 for (
size_t i = 0, k0 = 0; i < kStop; ++i, k0 +=
fDriftWindow)
191 for (
size_t k = k0 + 1; k < k1; ++k)
193 float ak = adc[k] * fLifetimeCorrFactors[k + tick0];
194 if (ak > max_adc) max_adc = ak;
204 size_t kStop = dst.size();
205 if (adc.size() < kStop) { kStop = adc.size(); }
206 for (
size_t i = 0, k0 = 0; i < kStop; ++i, k0 +=
fDriftWindow)
212 for (
size_t k = k0 + 1; k < k1; ++k)
214 float ak = adc[k] * fLifetimeCorrFactors[k + tick0];
215 if (ak > max_adc) { max_adc = ak; max_idx = k; }
219 if (max_idx > 0) { max_adc += adc[max_idx - 1] * fLifetimeCorrFactors[max_idx - 1 + tick0]; n++; }
220 if (max_idx + 1 < adc.size()) { max_adc += adc[max_idx + 1] * fLifetimeCorrFactors[max_idx + 1 + tick0]; n++; }
222 dst[i] = max_adc /
n;
229 size_t kStop = dst.size();
230 if (adc.size() < kStop) { kStop = adc.size(); }
231 for (
size_t i = 0, k0 = 0; i < kStop; ++i, k0 +=
fDriftWindow)
236 for (
size_t k = k0; k < k1; ++k)
252 if (!adc.empty()) {
downscale(wData, adc, 0); }
253 else {
return false; }
257 if (adc.empty()) {
return false; }
258 else if (adc.size() <= wData.size()) { std::copy(adc.begin(), adc.end(), wData.begin()); }
259 else { std::copy(adc.begin(), adc.begin()+wData.size(), wData.begin()); }
266 unsigned int plane,
unsigned int tpc,
unsigned int cryo)
268 mf::LogInfo(
"DataProviderAlg") <<
"Create image for cryo:" 269 << cryo <<
" tpc:" << tpc <<
" plane:" << plane;
283 bool allWrong =
true;
284 for (
auto const & wire : wires)
286 auto wireChannelNumber = wire.Channel();
287 if (!channelStatus.IsGood(wireChannelNumber)) {
continue; }
292 if ((
id.
Plane == plane) && (
id.TPC == tpc) && (
id.Cryostat == cryo))
296 auto adc = wire.Signal();
297 if (adc.size() < ndrifts)
299 mf::LogWarning(
"DataProviderAlg") <<
"Wire ADC vector size lower than NumberTimeSamples.";
318 mf::LogError(
"DataProviderAlg") <<
"Wires data not set in the cryo:" 319 << cryo <<
" tpc:" << tpc <<
" plane:" << plane;
344 auto * data = values.data();
346 size_t k = 0, size4 = values.size() >> 2, size = values.size();
347 for (
size_t i = 0; i < size4; ++i)
403 int halfSizeW = size_w / 2;
404 int halfSizeD = size_d / 2;
406 int w0 = wire - halfSizeW;
407 int w1 = wire + halfSizeW;
410 int d0 = sd - halfSizeD;
411 int d1 = sd + halfSizeD;
414 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch)
416 auto & dst = patch[wpatch];
417 if ((
w >= 0) && (
w < wsize))
420 int dsize = src.size();
421 for (
int d = d0, dpatch = 0;
d < d1; ++
d, ++dpatch)
423 if ((
d >= 0) && (
d < dsize))
425 dst[dpatch] = src[
d];
446 int halfSizeW = size_w / 2;
447 int halfSizeD = dsize / 2;
449 int w0 = wire - halfSizeW;
450 int w1 = wire + halfSizeW;
452 int d0 = drift - halfSizeD;
453 int d1 = drift + halfSizeD;
455 std::vector<float>
tmp(dsize);
457 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch)
459 if ((
w >= 0) && (
w < wsize))
462 int src_size = src.size();
463 for (
int d = d0, dpatch = 0;
d < d1; ++
d, ++dpatch)
465 if ((
d >= 0) && (
d < src_size))
467 tmp[dpatch] = src[
d];
498 gauss.fireArray(
fNCachedDrifts, noise.data(), 0., effectiveSigma);
499 for (
size_t d = 0;
d < wire.size(); ++
d)
517 gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1);
518 gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1);
520 double group_amp = 1.0;
526 group_amp = amps2[
w >> 5];
527 gauss.fireArray(
fNCachedDrifts, noise.data(), 0., effectiveSigma);
531 for (
size_t d = 0;
d < wire.size(); ++
d)
533 wire[
d] += group_amp * amps1[
w] * noise[
d];
virtual void resizeView(size_t wires, size_t drifts)
std::vector< float > fLifetimeCorrFactors
geo::GeometryCore const * fGeometry
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fhicl::Atom< float > AdcMax
std::vector< raw::ChannelID_t > fWireChannels
Utilities related to art service access.
fhicl::Atom< float > CoherentSigma
float poolSum(int wire, int drift, size_t r=0) const
Pool sum of pixels in a patch around the wire/drift pixel.
void downscaleMaxMean(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
std::vector< std::vector< float > > fWireDriftData
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool patchFromDownsampledView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float > > &patch) const
fhicl::Atom< unsigned int > DriftWindow
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
void reconfigure(const Config &config)
DataProviderAlg(const fhicl::ParameterSet &pset)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
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.
bool setWireDriftData(const std::vector< recob::Wire > &wires, unsigned int plane, unsigned int tpc, unsigned int cryo)
bool setWireData(std::vector< float > const &adc, size_t wireIdx)
std::vector< float > fBlurKernel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double ElectronsFromADCPeak(double adc, unsigned short plane) const
fhicl::Sequence< float > BlurKernel
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
detinfo::DetectorProperties const * fDetProp
fhicl::Atom< bool > DownscaleFullView
void downscaleMax(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
unsigned int fNCachedDrifts
void scaleAdcSamples(std::vector< float > &values) const
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
General LArSoft Utilities.
virtual unsigned int NumberTimeSamples() const =0
unsigned int Plane(void) const
float scaleAdcSample(float val) const
fhicl::Atom< float > AdcMin
calo::CalorimetryAlg fCalorimetryAlg
fhicl::Atom< bool > CalibrateLifetime
LArSoft-specific namespace.
unsigned int fNScaledDrifts
fhicl::Table< calo::CalorimetryAlg::Config > CalorimetryAlg
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< float > fAmplCalibConst
fhicl::Atom< std::string > DownscaleFn
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.
bool patchFromOriginalView(size_t wire, float drift, size_t size_w, size_t size_d, std::vector< std::vector< float > > &patch) const
void downscale(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
Namespace collecting geometry-related classes utilities.
double LifetimeCorrection(double time, double T0=0) const
size_t getDriftIndex(float drift) const
void downscaleMean(std::vector< float > &dst, std::vector< float > const &adc, size_t tick0) const
cet::coded_exception< error, detail::translate > exception
virtual ~DataProviderAlg(void)
fhicl::Atom< float > NoiseSigma