25 #include "fhiclcpp/ParameterSet.h"
26 #include "messagefacility/MessageLogger/MessageLogger.h"
27 #include "art/Framework/Core/ModuleMacros.h"
28 #include "art/Framework/Core/EDProducer.h"
29 #include "art/Framework/Principal/Event.h"
30 #include "art/Framework/Principal/Handle.h"
31 #include "art/Utilities/make_tool.h"
32 #include "canvas/Persistency/Common/Ptr.h"
33 #include "canvas/Persistency/Common/PtrVector.h"
34 #include "art/Framework/Services/Registry/ServiceHandle.h"
35 #include "art_root_io/TFileService.h"
36 #include "canvas/Utilities/Exception.h"
56 #include "icarus_signal_processing/WaveformTools.h"
119 produces< std::vector<recob::Wire> >(fSpillName);
120 produces<art::Assns<raw::RawDigit, recob::Wire>>(fSpillName);
132 const fhicl::ParameterSet& roiFinderTools = pset.get<fhicl::ParameterSet>(
"ROIFinderToolVec");
134 fROIFinderVec.resize(roiFinderTools.get_pset_names().size());
136 for(
const std::string& roiFinderTool : roiFinderTools.get_pset_names())
138 const fhicl::ParameterSet& roiFinderToolParamSet = roiFinderTools.get<fhicl::ParameterSet>(roiFinderTool);
139 size_t planeIdx = roiFinderToolParamSet.get<
size_t>(
"Plane");
141 fROIFinderVec.at(planeIdx) = art::make_tool<icarus_tool::IROIFinder>(roiFinderToolParamSet);
146 fDeconvolution = art::make_tool<icarus_tool::IDeconvolution>(pset.get<fhicl::ParameterSet>(
"Deconvolution"));
149 fNoiseSource = pset.get<
unsigned short >(
"NoiseSource", 3);
159 if( pos!=std::string::npos )
169 art::ServiceHandle<art::TFileService>
tfs;
180 for(
size_t planeIdx = 0; planeIdx < 3; planeIdx++)
182 fPedestalOffsetVec[planeIdx] = tfs->make<TH1F>( Form(
"PedPlane_%02zu",planeIdx),
";Pedestal Offset (ADC);", 100, -5., 5.);
183 fFullRMSVec[planeIdx] = tfs->make<TH1F>( Form(
"RMSFPlane_%02zu",planeIdx),
"Full RMS;RMS (ADC);", 100, 0., 10.);
184 fTruncRMSVec[planeIdx] = tfs->make<TH1F>( Form(
"RMSTPlane_%02zu",planeIdx),
"Truncated RMS;RMS (ADC);", 100, 0., 10.);
185 fNumTruncBinsVec[planeIdx] = tfs->make<TH1F>( Form(
"NTruncBins_%02zu",planeIdx),
";# bins", 640, 0., 6400.);
188 fNumROIsHistVec[planeIdx] = tfs->make<TH1F>( Form(
"NROISplane_%02zu",planeIdx),
";# ROIs;", 100, 0, 100);
189 fROILenHistVec[planeIdx] = tfs->make<TH1F>( Form(
"ROISIZEplane_%02zu",planeIdx),
";ROI size;", 500, 0, 500);
214 std::unique_ptr<std::vector<recob::Wire> > wirecol(
new std::vector<recob::Wire>);
216 std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn(
new art::Assns<raw::RawDigit,recob::Wire>);
219 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
224 if (!digitVecHandle->size())
227 evt.put(std::move(WireDigitAssn),
fSpillName);
235 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
238 wirecol->reserve(digitVecHandle->size());
239 for(
size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter)
245 art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
246 channel = digitVec->Channel();
249 if (!chanFilt.
IsPresent(channel))
continue;
252 if (digitVec->GetPedestal() < 0.)
continue;
259 size_t dataSize = digitVec->Samples();
266 std::vector<short> rawadc(dataSize);
273 pedestal = pedestalRetrievalAlg.
PedMean(channel);
276 std::vector<float> rawAdcLessPedVec(dataSize);
278 std::transform(rawadc.begin(),rawadc.end(),rawAdcLessPedVec.begin(),std::bind(std::minus<short>(),std::placeholders::_1,pedestal));
297 fDeconvolution->Deconvolve(rawAdcLessPedVec, samplingRate, channel, candRoiVec, ROIVec);
308 for(
const auto& pair : candRoiVec)
320 throw art::Exception(art::errors::ProductRegistrationFailure)
321 <<
"Can't associate wire #" << (wirecol->size() - 1)
322 <<
" with raw digit #" << digitVec.key();
327 if(wirecol->size() == 0)
328 mf::LogWarning(
"RecoWireROIICARUS") <<
"No wires made for this event.";
333 art::ServiceHandle<art::TFileService>
tfs;
334 for (
size_t wireN = 0; wireN < wirecol->size(); wireN++){
335 std::vector<float> sigTMP = wirecol->at(wireN).Signal();
336 TH1D* fWire = tfs->make<TH1D>(Form(
"Noise_Evt%04zu_N%04zu",
fEventCount,wireN),
";Noise (ADC);",
337 sigTMP.size(),-0.5,sigTMP.size()-0.5);
339 fWire->SetBinContent(
tick+1, sigTMP.at(
tick) );
345 evt.put(std::move(WireDigitAssn),
fSpillName);
355 std::vector<float> locWaveform = waveform;
358 std::sort(locWaveform.begin(), locWaveform.end(),[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
362 std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](
const auto& val){
return std::fabs(val) > threshold;});
367 float truncRms = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
369 truncRms = std::sqrt(std::max(0.,truncRms /
double(minNumBins)));
384 fixedWaveform.resize(waveform.size());
386 fWaveformTool.getPedestalCorrectedWaveform(waveform, fixedWaveform, nSig, truncMean, fullRMS, truncRMS, nTrunc, range);
394 size_t plane = wids[0].Plane;
395 size_t wire = wids[0].Wire;
std::vector< TH1F * > fPedestalOffsetVec
std::vector< TH1F * > fFullRMSVec
Utilities related to art service access.
bool fOutputHistograms
Output histograms?
This provides an interface for tools which are tasked with running the deconvolution algorithm...
icarus_signal_processing::WaveformTools< float > fWaveformTool
const geo::GeometryCore * fGeometry
Helper functions to create a wire.
std::vector< std::unique_ptr< icarus_tool::IROIFinder > > fROIFinderVec
ROI finders per plane.
The data type to uniquely identify a Plane.
std::vector< TProfile * > fPedByChanVec
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
Definition of basic raw digits.
float fixTheFreakingWaveform(const std::vector< float > &, raw::ChannelID_t, std::vector< float > &)
Class managing the creation of a new recob::Wire object.
This provides an interface for tools which are tasked with finding the baselines in input waveforms...
std::vector< TH1F * > fNumTruncBinsVec
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.
size_t fEventCount
count of event processed
unsigned short fNoiseSource
Used to determine ROI threshold.
void reconfigure(fhicl::ParameterSet const &p)
virtual bool IsPresent(raw::ChannelID_t channel) const =0
Returns whether the specified channel is physical and connected to wire.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
float getTruncatedRMS(const std::vector< float > &) const
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
Collect all the RawData header files together.
float fTruncRMSMinFraction
or at least this fraction of time bins
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.
float fTruncRMSThreshold
Calculate RMS up to this threshold...
Class providing information about the quality of channels.
int fSaveWireWF
Save recob::wire object waveforms.
PlaneID_t Plane
Index of the plane within its TPC.
Description of geometry of one entire detector.
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
virtual ~RecoWireROIICARUS()
std::unique_ptr< icarus_tool::IDeconvolution > fDeconvolution
void produce(art::Event &evt)
std::vector< TH1F * > fTruncRMSVec
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.
std::vector< TH1F * > fROILenHistVec
Interface for experiment-specific channel quality info provider.
RecoWireROIICARUS(fhicl::ParameterSet const &pset)
std::string fDigitModuleLabel
module that made digits
Declaration of basic channel signal object.
std::vector< TProfile * > fTruncRMSByChanVec
art::ServiceHandle< art::TFileService > tfs
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Interface for experiment-specific service for channel quality info.
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.
std::vector< TH1F * > fNumROIsHistVec
process_name can override from command line with o or output caldata
art framework interface to geometry description
int fMinAllowedChanStatus
Don't consider channels with lower status.