9 #include "cetlib_except/exception.h" 15 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h" 16 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h" 18 class DetectorClocksData;
22 #include "CLHEP/Random/RandGauss.h" 47 mf::LogInfo(
"DataProviderAlg") <<
"Using calibration constants:";
59 mf::LogInfo(
"DataProviderAlg") <<
"No plane-to-plane calibration.";
69 std::string mode_str = config.DownscaleFn();
70 mf::LogVerbatim(
"DataProviderAlg") <<
"Downscale mode is: " << mode_str;
71 if (mode_str ==
"maxpool") {
75 else if (mode_str ==
"maxmean") {
79 else if (mode_str ==
"mean") {
84 mf::LogError(
"DataProviderAlg") <<
"Downscale mode string not recognized, set to max pooling.";
96 throw cet::exception(
"img::DataProviderAlg") <<
"Misconfigured: AdcMax <= AdcMin" << std::endl;
99 throw cet::exception(
"img::DataProviderAlg") <<
"Misconfigured: OutMax == OutMin" << std::endl;
129 for (
size_t t = 0; t < drifts; ++t) {
134 for (
size_t t = 0; t < drifts; ++t) {
144 size_t rw =
r, rd =
r;
149 if (d0 < 0) { d0 = 0; }
154 if (w0 < 0) { w0 = 0; }
158 float adc, max_adc = 0;
159 for (
int w = w0;
w <= w1; ++
w) {
161 for (
int d = d0;
d <= d1; ++
d) {
163 if (adc > max_adc) { max_adc = adc; }
194 std::vector<float>
const& adc,
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) {
204 for (
size_t k = k0 + 1; k < k1; ++k) {
206 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;
250 std::vector<float>
const& adc,
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) {
260 for (
size_t k = k0; k < k1; ++k) {
271 size_t wireIdx)
const 277 if (!adc.empty()) {
return downscale(wData.size(), adc, 0); }
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());
288 const std::vector<recob::Wire>& wires,
293 mf::LogInfo(
"DataProviderAlg") <<
"Create image for cryo:" << cryo <<
" tpc:" << tpc
294 <<
" plane:" << plane;
308 auto const& channelStatus =
311 bool allWrong =
true;
312 for (
auto const& wire : wires) {
313 auto wireChannelNumber = wire.Channel();
314 if (!channelStatus.IsGood(wireChannelNumber)) {
continue; }
318 if ((
id.
Plane == plane) && (
id.TPC == tpc) && (
id.Cryostat == cryo)) {
321 auto adc = wire.Signal();
322 if (adc.size() < ndrifts) {
323 mf::LogWarning(
"DataProviderAlg") <<
"Wire ADC vector size lower than NumberTimeSamples.";
346 <<
"Wires data not set in the cryo:" << cryo <<
" tpc:" << tpc <<
" plane:" << plane;
375 auto* data = values.data();
377 size_t k = 0, size4 = values.size() >> 2,
size = values.size();
378 for (
size_t i = 0; i < size4; ++i)
381 data[k + 1] *= calib;
382 data[k + 2] *= calib;
383 data[k + 3] *= calib;
415 size_t margin_left = (
fBlurKernel.size() - 1) >> 1,
416 margin_right =
fBlurKernel.size() - margin_left - 1;
442 int halfSizeW = size_w / 2;
443 int halfSizeD = size_d / 2;
445 int w0 = wire - halfSizeW;
446 int w1 = wire + halfSizeW;
449 int d0 = sd - halfSizeD;
450 int d1 = sd + halfSizeD;
453 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch) {
454 auto& dst = patch[wpatch];
455 if ((
w >= 0) && (
w < wsize)) {
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]; }
480 int halfSizeW = size_w / 2;
481 int halfSizeD = dsize / 2;
483 int w0 = wire - halfSizeW;
484 int w1 = wire + halfSizeW;
486 int d0 = int(drift) - halfSizeD;
487 int d1 = int(drift) + halfSizeD;
491 std::vector<float>
tmp(dsize);
493 for (
int w = w0, wpatch = 0;
w < w1; ++
w, ++wpatch) {
494 if ((
w >= 0) && (
w < wsize)) {
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]; }
525 for (
size_t d = 0;
d < wire.size(); ++
d) {
542 gauss.fireArray(amps1.size(), amps1.data(), 1., 0.1);
543 gauss.fireArray(amps2.size(), amps2.data(), 1., 0.1);
545 double group_amp = 1.0;
549 group_amp = amps2[
w >> 5];
554 for (
size_t d = 0;
d < wire.size(); ++
d) {
555 wire[
d] += group_amp * amps1[
w] * noise[
d];
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::optional< std::vector< float > > setWireData(std::vector< float > const &adc, size_t wireIdx) const
unsigned int fNCachedDrifts
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 ~DataProviderAlg()
virtual DataProviderAlgView resizeView(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, size_t wires, size_t drifts)
geo::Geometry const * fGeometry
std::vector< float > downscale(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
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
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
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
std::vector< float > downscaleMean(std::size_t dst_size, std::vector< float > const &adc, size_t tick0) const
geo::WireReadoutGeom const * fWireReadoutGeom
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)
virtual std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const =0
Contains all timing reference information for the detector.
std::vector< float > fLifetimeCorrFactors
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< float > fAmplCalibConst
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
size_t getDriftIndex(float drift) const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception