234 std::unique_ptr<std::vector<recob::Wire> > wirecol(
new std::vector<recob::Wire>);
236 std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn(
new art::Assns<raw::RawDigit,recob::Wire>);
239 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
243 if (!digitVecHandle->size())
252 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(
evt);
257 size_t transformSize = 0;
260 wirecol->reserve(digitVecHandle->size());
261 for(
size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter)
267 std::vector<std::pair<size_t, size_t>> rois;
270 art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
271 channel = digitVec->Channel();
277 if (digitVec->GetPedestal() < 0.)
continue;
282 size_t dataSize = digitVec->Samples();
286 std::cout <<
"***>> zero length data buffer, channel: " << channel << std::endl;
291 std::vector<short> rawadc(dataSize);
294 size_t thePlane = wids[0].Plane;
304 transformSize = dataSize;
309 rawAdcLessPedVec.resize(transformSize,0.);
317 float pdstl = pedestalRetrievalAlg.
PedMean(channel);
318 float rms_noise = digitVec->GetSigma();
322 else if (
fNoiseSource != 2) raw_noise = std::max(raw_noise,rms_noise);
326 if (transformSize > dataSize) binOffset = (transformSize - dataSize) / 2;
328 size_t startBin(binOffset);
329 size_t stopBin(binOffset+numBins);
332 float startThreshold = float(numBins) * (
fNumSigma[thePlane] * raw_noise +
fThreshold[thePlane]);
333 float stopThreshold = startThreshold;
336 std::transform(rawadc.begin(),rawadc.end(),rawAdcLessPedVec.begin()+startBin,[pdstl](
const short& adc){
return std::round(
float(adc) - pdstl);});
337 std::fill(rawAdcLessPedVec.begin(),rawAdcLessPedVec.begin()+startBin,0.);
338 std::fill(rawAdcLessPedVec.begin()+startBin+dataSize,rawAdcLessPedVec.end(),0.);
341 icarusutil::TimeVec::iterator overThreshItr = std::find_if(rawAdcLessPedVec.begin(),rawAdcLessPedVec.end(),[raw_noise](
const auto& val){
return val > 2.5 * raw_noise;});
343 if (overThreshItr == rawAdcLessPedVec.end())
continue;
345 float runningSum = std::accumulate(rawAdcLessPedVec.begin()+startBin,rawAdcLessPedVec.begin()+stopBin, 0.);
347 size_t roiStartBin(0);
348 bool roiCandStart(
false);
357 runningSum -= rawAdcLessPedVec[startBin++];
360 runningSum += rawAdcLessPedVec[stopBin++];
365 if (fabs(runningSum) < stopThreshold)
367 if (
bin - roiStartBin > 2) rois.push_back(std::make_pair(roiStartBin,
bin));
369 roiCandStart =
false;
375 if (fabs(runningSum) > startThreshold)
387 rois.push_back(std::make_pair(roiStartBin, dataSize-1));
391 if(rois.size() == 0)
continue;
394 for(
size_t ii = 0; ii < rois.size(); ++ii)
397 rois[ii].first = std::max(
int(rois[ii].
first -
fPreROIPad[thePlane]),0);
399 rois[ii].second = std::min(rois[ii].
second +
fPostROIPad[thePlane],dataSize - 1);
406 std::vector<std::pair<size_t,size_t>> trois;
409 size_t startRoi = rois.front().first;
410 size_t stopRoi = rois.front().second;
412 for(
size_t idx = 1; idx < rois.size(); idx++)
414 if (rois[idx].
first < stopRoi)
416 stopRoi = rois[idx].second;
420 trois.push_back(std::pair<size_t,size_t>(startRoi,stopRoi));
422 startRoi = rois[idx].first;
423 stopRoi = rois[idx].second;
428 trois.push_back(std::pair<size_t,size_t>(startRoi,stopRoi));
437 std::vector<float> holder;
439 for(
size_t roiIdx = 0; roiIdx < rois.size(); roiIdx++)
441 const auto roi = rois[roiIdx];
444 size_t roiLen = roi.second - roi.first;
446 holder.resize(roiLen);
448 std::copy(rawAdcLessPedVec.begin()+binOffset+roi.first, rawAdcLessPedVec.begin()+binOffset+roi.second, holder.begin());
449 float dnorm=samplingRate*deconNorm;
451 std::transform(holder.begin(),holder.end(),holder.begin(),[dnorm](
float& deconVal){
return deconVal/dnorm;});
461 size_t binsToAve(20);
462 float basePre = std::accumulate(holder.begin(),holder.begin()+binsToAve,0.) / float(binsToAve);
463 float basePost = std::accumulate(holder.end()-binsToAve,holder.end(),0.) / float(binsToAve);
470 if (!(fabs(basePre - basePost) < deconNoise))
475 icarusutil::TimeVec::iterator rawAdcRoiStartItr = rawAdcLessPedVec.begin() + binOffset + roi.first;
476 icarusutil::TimeVec::iterator rawAdcMaxItr = rawAdcLessPedVec.end() - binOffset;
479 if (roiIdx < rois.size() - 1)
480 rawAdcMaxItr = rawAdcLessPedVec.begin() + binOffset + rois[roiIdx+1].first;
483 while (!(fabs(basePre - basePost) < deconNoise) && nTries++ < 3)
485 size_t nBinsToAdd(100);
486 int nBinsLeft =
std::distance(rawAdcRoiStartItr+roiLen,rawAdcMaxItr) > 0
488 size_t roiLenAddition = std::min(nBinsToAdd,
size_t(nBinsLeft));
490 if (roiLenAddition > 0)
492 std::vector<float> additionVec(roiLenAddition);
494 std::copy(rawAdcRoiStartItr + roiLen, rawAdcRoiStartItr + roiLen + roiLenAddition, additionVec.begin());
496 holder.resize(holder.size() + roiLenAddition);
497 std::transform(additionVec.begin(),additionVec.end(),holder.begin() + roiLen,[deconNorm](
float& deconVal){
return deconVal/deconNorm;});
499 basePost = std::accumulate(holder.end()-binsToAve,holder.end(),0.) / float(binsToAve);
501 roiLen = holder.size();
508 base =
SubtractBaseline(holder, basePre,basePost,roi.first,roiLen,dataSize);
511 if (baseSet)
std::transform(holder.begin(),holder.end(),holder.begin(),[base](
float& adcVal){
return adcVal - base;});
520 for (
size_t iholder = 0; iholder < holder.size(); ++iholder) holder[iholder] *= constant;
525 float average_val = std::accumulate(holder.begin(),holder.end(),0.0) / holder.size();
526 float min = *std::min_element(holder.begin(),holder.end());
527 float max = *std::max_element(holder.begin(),holder.end());
530 ROIVec.
add_range(roi.first, std::move(holder));
542 throw art::Exception(art::errors::ProductRegistrationFailure)
543 <<
"Can't associate wire #" << (wirecol->size() - 1)
544 <<
" with raw digit #" << digitVec.key();
549 if(wirecol->size() == 0)
550 mf::LogWarning(
"RecoWireROI") <<
"No wires made for this event.";
556 art::ServiceHandle<art::TFileService>
tfs;
557 for (
size_t wireN = 0; wireN < wirecol->size(); wireN++)
559 std::vector<float> sigTMP = wirecol->at(wireN).Signal();
560 TH1D* fWire = tfs->make<TH1D>(Form(
"Noise_Evt%04zu_N%04zu",
fEventCount,wireN),
";Noise (ADC);", sigTMP.size(),-0.5,sigTMP.size()-0.5);
561 for (
size_t tick = 0;
tick < sigTMP.size();
tick++) fWire->SetBinContent(
tick+1, sigTMP.at(
tick) );
std::string fDigitModuleLabel
module that made digits
float SubtractBaseline(std::vector< float > &holder, float basePre, float basePost, size_t roiStart, size_t roiLen, size_t dataSize)
double GetRawNoise(unsigned int const channel) const
std::vector< unsigned short > fThreshold
abs(threshold) ADC counts for ROI
std::vector< int > fNumSigma
"# sigma" rms noise for ROI threshold
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
Class managing the creation of a new recob::Wire object.
bool fDodQdxCalib
Do we apply wire-by-wire calibration?
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
Object to handle thread safe FFT.
bool fDoBaselineSub
Do baseline subtraction after deconvolution?
virtual bool IsPresent(raw::ChannelID_t channel) const =0
Returns whether the specified channel is physical and connected to wire.
int fMinAllowedChanStatus
Don't consider channels with lower status.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
std::vector< unsigned short > fPostROIPad
ROI padding.
const lariov::ChannelStatusProvider & fChanFilt
std::vector< SigProcPrecision > TimeVec
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
virtual Status_t Status(raw::ChannelID_t channel) const
Returns a status integer with arbitrary meaning.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
std::map< unsigned int, float > fdQdxCalib
Map to do wire-by-wire calibration, key is channel number, content is correction factor.
size_t fEventCount
count of event processed
double GetDeconNoise(unsigned int const channel) const
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
unsigned short fNoiseSource
Used to determine ROI threshold.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
float fMinROIAverageTickThreshold
icarusutil::SignalShapingICARUSService & fSignalServices
const icarus_tool::IResponse & GetResponse(size_t channel) const
art::ServiceHandle< art::TFileService > tfs
unsigned int ChannelID_t
Type representing the ID of a readout channel.
std::vector< unsigned short > fPreROIPad
ROI padding.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
unsigned short fNumBinsHalf
Determines # bins in ROI running sum.
const geo::GeometryCore & fGeometry
int ResponseTOffset(unsigned int const channel) const
void SetDecon(double samplingRate, size_t fftsize, size_t channel)
BEGIN_PROLOG could also be cout
int fSaveWireWF
Save recob::wire object waveforms.