16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Core/EDProducer.h"
18 #include "art/Framework/Principal/Event.h"
19 #include "art/Framework/Principal/Handle.h"
20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "canvas/Persistency/Common/PtrVector.h"
22 #include "art/Framework/Services/Registry/ServiceHandle.h"
23 #include "art_root_io/TFileService.h"
24 #include "art_root_io/TFileDirectory.h"
25 #include "fhiclcpp/ParameterSet.h"
26 #include "messagefacility/MessageLogger/MessageLogger.h"
27 #include "cetlib_except/exception.h"
28 #include "cetlib/search_path.h"
29 #include "art/Utilities/make_tool.h"
60 explicit CalWireSBND(fhicl::ParameterSet
const& pset);
68 std::unique_ptr<sbnd_tool::IROIFinder>
fROITool;
107 fROITool = art::make_tool<sbnd_tool::IROIFinder>(pset.get<fhicl::ParameterSet>(
"ROITool"));
111 produces< std::vector<recob::Wire> >(fSpillName);
112 produces<art::Assns<raw::RawDigit, recob::Wire>>(fSpillName);
132 if( pos!=std::string::npos ) {
153 art::ServiceHandle<geo::Geometry> geom;
156 art::ServiceHandle<util::LArFFT> fFFT;
157 int transformSize = fFFT->FFTSize();
160 art::ServiceHandle<util::SignalShapingServiceSBND> sss;
161 double DeconNorm = sss->GetDeconNorm();
164 std::unique_ptr<std::vector<recob::Wire> > wirecol(
new std::vector<recob::Wire>);
167 std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire> > WireDigitAssn
168 (
new art::Assns<raw::RawDigit,recob::Wire>);
171 art::Handle< std::vector<raw::RawDigit> > digitVecHandle;
175 if (!digitVecHandle->size())
return;
176 mf::LogInfo(
"CalWireSBND") <<
"CalWireSBND:: digitVecHandle size is " << digitVecHandle->size();
179 art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
181 unsigned int dataSize = digitVec0->Samples();
184 if( (
unsigned int)transformSize < dataSize){
185 mf::LogWarning(
"CalWireSBND")<<
"FFT size (" << transformSize <<
") "
186 <<
"is smaller than the data size (" << dataSize <<
") "
187 <<
"\nResizing the FFT now...";
188 fFFT->ReinitializeFFT(dataSize,fFFT->FFTOptions(),fFFT->FFTFitBins());
189 transformSize = fFFT->FFTSize();
190 mf::LogWarning(
"CalWireSBND")<<
"FFT size is now (" << transformSize <<
") "
191 <<
"and should be larger than the data size (" << dataSize <<
")";
194 mf::LogInfo(
"CalWireSBND") <<
"Data size is " << dataSize <<
" and transform size is " << transformSize;
197 mf::LogError(
"CalWireSBND")<<
"Set BaseSampleBins modulo dataSize= "<<dataSize;
205 std::vector<float> holder;
206 std::vector<short> rawadc(transformSize);
207 std::vector<TComplex> freqHolder(transformSize+1);
209 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
212 wirecol->reserve(digitVecHandle->size());
213 for(
size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter){
217 art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
218 channel = digitVec->Channel();
225 holder.resize(transformSize, 0.);
231 float pdstl = digitVec->GetPedestal();
233 for(bin = 0; bin < dataSize; ++
bin)
234 holder[bin]=(rawadc[bin]-pdstl);
237 for(bin = dataSize; bin < holder.size(); bin++){
245 sss->Deconvolute(clockData, channel, holder);
246 for(bin = 0; bin < holder.size(); ++
bin) holder[bin]=holder[bin]/DeconNorm;
249 holder.resize(dataSize,1
e-5);
261 fROITool->FindROIs( holder, channel, candROIVec);
269 std::vector<float> roiHolder;
270 for(
size_t i_holder=roiStart; i_holder<=roiStop; i_holder++){
271 roiHolder.push_back(holder[i_holder]);
273 roiVec.
add_range(roiStart, std::move(roiHolder));
281 throw cet::exception(
"CalWireSBND")
282 <<
"Can't associate wire #" << (wirecol->size() - 1)
283 <<
" with raw digit #" << digitVec.key() <<
"\n";
288 if(wirecol->size() == 0)
289 mf::LogWarning(
"CalWireSBND") <<
"No wires made for this event.";
296 evt.put(std::move(WireDigitAssn),
fSpillName);
312 float min = 0, max = 0;
313 for(bin = 0; bin < holder.size(); bin++){
314 if (holder[bin] > max) max = holder[
bin];
315 if (holder[bin] < min) min = holder[
bin];
317 int nbin = max - min;
319 TH1F
h(
"h",
"h",nbin,min,max);
320 for(bin = 0; bin < holder.size(); bin++) h.Fill(holder[bin]);
321 float x_max = h.GetXaxis()->GetBinCenter(h.GetMaximumBin());
325 for(bin = 0; bin < holder.size(); bin++){
326 if( fabs(holder[bin]-x_max) < 2. ) {
331 if (ncount) ped = sum/ncount;
332 for(bin = 0; bin < holder.size(); bin++) holder[bin] -= ped;
345 std::vector<float> base;
346 for(
unsigned short ii = 0; ii < nBasePts; ++ii) base.push_back(0.);
350 unsigned short nfilld = 0;
351 for(
unsigned short ii = 0; ii < nBasePts; ++ii) {
356 for(
unsigned short bin = loBin;
bin < hiBin; ++
bin) {
358 sum += holder[
bin] * holder[
bin];
361 float var = (sum - fbins * ave * ave) / (fbins - 1.);
369 if(nfilld < nBasePts && nfilld > nBasePts / 2) {
373 unsigned short ii1 = 0;
374 for(
unsigned short ii = 1; ii < nBasePts; ++ii) {
380 unsigned short ii2 = 0;
381 for(
unsigned short ii = ii1 + 1; ii < nBasePts; ++ii) {
389 float slp = (base[ii2] - base[ii1]) / (
float)(ii2 - ii1);
390 base[0] = base[ii1] - slp * ii1;
396 if(baseOK && base[nBasePts] == 0) {
397 unsigned short ii2 = 0;
398 for(
unsigned short ii = nBasePts - 1; ii > 0; --ii) {
405 unsigned short ii1 = 0;
407 for(
unsigned short ii = ii2 - 1; ii > 0; --ii) {
416 float slp = (base[ii2] - base[ii1]) / (
float)(ii2 - ii1);
417 base[nBasePts] = base[ii2] + slp * (nBasePts - ii2);
421 for(
unsigned short ii = 1; ii < nBasePts - 1; ++ii) {
424 for(
unsigned short jj = ii + 1; jj < nBasePts; ++jj) {
426 float slp = (base[jj] - base[ii - 1]) / (jj - ii + 1);
427 base[ii] = base[ii - 1] + slp;
439 unsigned short lastRegion = 0;
440 for(
unsigned short bin = 0;
bin < holder.size(); ++
bin) {
443 if(region > lastRegion) {
449 holder[
bin] -= base[region] + (
bin - bof) * slp;
bool fDoAdvBaselineSub
use interpolation-based baseline subtraction
std::vector< float > Waveform
Helper functions to create a wire.
bool fDoBaselineSub
subtract baseline to restore DC component post-deconvolution
void produce(art::Event &evt)
std::unique_ptr< sbnd_tool::IROIFinder > fROITool
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
Definition of basic raw digits.
Class managing the creation of a new recob::Wire object.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
CalWireSBND(fhicl::ParameterSet const &pset)
void reconfigure(fhicl::ParameterSet const &p)
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
Collect all the RawData header files together.
void SubtractBaseline(std::vector< float > &holder)
float fBaseVarCut
baseline variance cut used in "interpolate" method
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.
int fBaseSampleBins
bin grouping size in "interpolate" method
std::string fDigitModuleLabel
module that made digits
std::pair< size_t, size_t > CandidateROI
Declaration of basic channel signal object.
Class defining a sparse vector (holes are zeroes)
void SubtractBaselineAdv(std::vector< float > &holder)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
process_name can override from command line with o or output caldata
art framework interface to geometry description
std::vector< CandidateROI > CandidateROIVec