All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
icarus_tool::FullWireDeconvolution Class Reference
Inheritance diagram for icarus_tool::FullWireDeconvolution:
icarus_tool::IDeconvolution

Public Member Functions

 FullWireDeconvolution (const fhicl::ParameterSet &pset)
 
 ~FullWireDeconvolution ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void initializeHistograms (art::TFileDirectory &) const override
 
void Deconvolve (IROIFinder::Waveform const &, double samplingRate, raw::ChannelID_t, IROIFinder::CandidateROIVec const &, recob::Wire::RegionsOfInterest_t &) const override
 
- Public Member Functions inherited from icarus_tool::IDeconvolution
virtual ~IDeconvolution () noexcept=default
 

Private Attributes

bool fDodQdxCalib
 Do we apply wire-by-wire calibration? More...
 
std::string fdQdxCalibFileName
 Text file for constants to do wire-by-wire calibration. More...
 
std::map< unsigned int, float > fdQdxCalib
 Map to do wire-by-wire calibration, key is channel. More...
 
icarus_signal_processing::WaveformTools
< float > 
fWaveformTool
 
std::unique_ptr
< icarus_signal_processing::ICARUSFFT
< double > > 
fFFT
 Object to handle thread safe FFT. More...
 
const geo::GeometryCorefGeometry = lar::providerFrom<geo::Geometry>()
 
art::ServiceHandle
< icarusutil::SignalShapingICARUSService
fSignalShaping
 

Detailed Description

Definition at line 29 of file FullWireDeconvolution_tool.cc.

Constructor & Destructor Documentation

icarus_tool::FullWireDeconvolution::FullWireDeconvolution ( const fhicl::ParameterSet &  pset)
explicit

Definition at line 62 of file FullWireDeconvolution_tool.cc.

63 {
64  configure(pset);
65 }
void configure(const fhicl::ParameterSet &pset) override
icarus_tool::FullWireDeconvolution::~FullWireDeconvolution ( )

Definition at line 67 of file FullWireDeconvolution_tool.cc.

68 {
69 }

Member Function Documentation

void icarus_tool::FullWireDeconvolution::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements icarus_tool::IDeconvolution.

Definition at line 71 of file FullWireDeconvolution_tool.cc.

72 {
73  // Start by recovering the parameters
74  //wire-by-wire calibration
75  fDodQdxCalib = pset.get< bool >("DodQdxCalib", false);
76 
77  if (fDodQdxCalib)
78  {
79  fdQdxCalibFileName = pset.get< std::string >("dQdxCalibFileName");
80  std::string fullname;
81  cet::search_path sp("FW_SEARCH_PATH");
82  sp.find_file(fdQdxCalibFileName, fullname);
83 
84  if (fullname.empty())
85  {
86  std::cout << "Input file " << fdQdxCalibFileName << " not found" << std::endl;
87  throw cet::exception("File not found");
88  }
89  else
90  std::cout << "Applying wire-by-wire calibration using file " << fdQdxCalibFileName << std::endl;
91 
92  std::ifstream inFile(fullname, std::ios::in);
93  std::string line;
94 
95  while (std::getline(inFile,line))
96  {
97  unsigned int channel;
98  float constant;
99  std::stringstream linestream(line);
100  linestream >> channel >> constant;
101  fdQdxCalib[channel] = constant;
102  if (channel%1000==0) std::cout<<"Channel "<<channel<<" correction factor "<<fdQdxCalib[channel]<<std::endl;
103  }
104  }
105 
106  // Get signal shaping service.
107  fSignalShaping = art::ServiceHandle<icarusutil::SignalShapingICARUSService>();
108 
109  // Now set up our plans for doing the convolution
110  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
111  fFFT = std::make_unique<icarus_signal_processing::ICARUSFFT<double>>(detProp.NumberTimeSamples());
112 
113  return;
114 }
std::map< unsigned int, float > fdQdxCalib
Map to do wire-by-wire calibration, key is channel.
TString inFile
std::string fdQdxCalibFileName
Text file for constants to do wire-by-wire calibration.
bool fDodQdxCalib
Do we apply wire-by-wire calibration?
art::ServiceHandle< icarusutil::SignalShapingICARUSService > fSignalShaping
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
Object to handle thread safe FFT.
BEGIN_PROLOG could also be cout
auto const detProp
void icarus_tool::FullWireDeconvolution::Deconvolve ( IROIFinder::Waveform const &  waveform,
double  samplingRate,
raw::ChannelID_t  channel,
IROIFinder::CandidateROIVec const &  roiVec,
recob::Wire::RegionsOfInterest_t ROIVec 
) const
overridevirtual

Implements icarus_tool::IDeconvolution.

Definition at line 116 of file FullWireDeconvolution_tool.cc.

121 {
122  // The goal of this function is to reproduce "exactly" the operation of the deconvolution process in MCC7
123  // hence the copying over of some of the code that has been pushed into external tools.
124 
125  // The size of the input waveform **should** be the raw buffer size
126  size_t dataSize = waveform.size();
127 
128  // Make sure the deconvolution size is set correctly (this will probably be a noop after first call)
129  fSignalShaping->SetDecon(samplingRate, dataSize, channel);
130 
131  // now make a buffer to contain the waveform which will be of the right size
132  icarusutil::TimeVec rawAdcLessPedVec(dataSize,0.);
133 
134  size_t binOffset = 0; //transformSize > dataSize ? (transformSize - dataSize) / 2 : 0;
135  float deconNorm = fSignalShaping->GetDeconNorm();
136  float normFactor = 1. / deconNorm; // This is what we had previously: (samplingRate * deconNorm);
137  bool applyNormFactor = std::abs(normFactor - 1.) > std::numeric_limits<float>::epsilon() ? true : false;
138 
139  // Copy the input (assumed pedestal subtracted) waveforms into our zero padded deconvolution buffer
140  std::copy(waveform.begin(),waveform.end(),rawAdcLessPedVec.begin()+binOffset);
141 
142  // Strategy is to run deconvolution on the entire channel and then pick out the ROI's we found above
143  fFFT->deconvolute(rawAdcLessPedVec, fSignalShaping->GetResponse(channel).getDeconvKernel(), fSignalShaping->ResponseTOffset(channel));
144 
145  std::vector<float> holder;
146 
147  for(size_t roiIdx = 0; roiIdx < roiVec.size(); roiIdx++)
148  {
149  const auto& roi = roiVec[roiIdx];
150 
151  // First up: copy out the relevent ADC bins into the ROI holder
152  size_t roiLen = roi.second - roi.first + 1;
153 
154  holder.resize(roiLen);
155 
156  std::copy(rawAdcLessPedVec.begin()+binOffset+roi.first, rawAdcLessPedVec.begin()+binOffset+roiLen, holder.begin());
157  if (applyNormFactor) std::transform(holder.begin(),holder.end(),holder.begin(), std::bind(std::multiplies<float>(),std::placeholders::_1,normFactor));
158 
159  // Get the truncated mean and rms
160  float truncMean;
161  int nTrunc;
162  int range;
163 
164  fWaveformTool.getTruncatedMean(holder, truncMean, nTrunc, range);
165 
166  std::transform(holder.begin(),holder.end(),holder.begin(), std::bind(std::minus<float>(),std::placeholders::_1,truncMean));
167 
168  // apply wire-by-wire calibration
169  if (fDodQdxCalib){
170  if(fdQdxCalib.find(channel) != fdQdxCalib.end()){
171  float constant = fdQdxCalib.at(channel);
172  //std::cout<<channel<<" "<<constant<<std::endl;
173  for (size_t iholder = 0; iholder < holder.size(); ++iholder){
174  holder[iholder] *= constant;
175  }
176  }
177  }
178 
179  // add the range into ROIVec
180  ROIVec.add_range(roi.first, std::move(holder));
181  }
182 
183  return;
184 }
static constexpr Sample_t transform(Sample_t sample)
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
std::map< unsigned int, float > fdQdxCalib
Map to do wire-by-wire calibration, key is channel.
T abs(T value)
std::vector< SigProcPrecision > TimeVec
bool fDodQdxCalib
Do we apply wire-by-wire calibration?
art::ServiceHandle< icarusutil::SignalShapingICARUSService > fSignalShaping
icarus_signal_processing::WaveformTools< float > fWaveformTool
T copy(T const &v)
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
Object to handle thread safe FFT.
void icarus_tool::FullWireDeconvolution::initializeHistograms ( art::TFileDirectory &  histDir) const
overridevirtual

Implements icarus_tool::IDeconvolution.

Definition at line 186 of file FullWireDeconvolution_tool.cc.

187 {
188  // It is assumed that the input TFileDirectory has been set up to group histograms into a common
189  // folder at the calling routine's level. Here we create one more level of indirection to keep
190  // histograms made by this tool separate.
191 /*
192  std::string dirName = "FullWireDeconvolutionPlane_" + std::to_string(fPlane);
193 
194  art::TFileDirectory dir = histDir.mkdir(dirName.c_str());
195 
196  auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
197  double samplingRate = detprop->SamplingRate();
198  double numBins = fFullWireDeconvolutionVec.size();
199  double maxFreq = 500. / samplingRate;
200  std::string histName = "FullWireDeconvolutionPlane_" + std::to_string(fPlane);
201 
202  TH1D* hist = dir.make<TH1D>(histName.c_str(), "FullWireDeconvolution;Frequency(MHz)", numBins, 0., maxFreq);
203 
204  for(int bin = 0; bin < numBins; bin++)
205  {
206  double freq = maxFreq * double(bin + 0.5) / double(numBins);
207 
208  hist->Fill(freq, fFullWireDeconvolutionVec.at(bin).Re());
209  }
210 */
211 
212  return;
213 }

Member Data Documentation

bool icarus_tool::FullWireDeconvolution::fDodQdxCalib
private

Do we apply wire-by-wire calibration?

Definition at line 48 of file FullWireDeconvolution_tool.cc.

std::map<unsigned int, float> icarus_tool::FullWireDeconvolution::fdQdxCalib
private

Map to do wire-by-wire calibration, key is channel.

Definition at line 50 of file FullWireDeconvolution_tool.cc.

std::string icarus_tool::FullWireDeconvolution::fdQdxCalibFileName
private

Text file for constants to do wire-by-wire calibration.

Definition at line 49 of file FullWireDeconvolution_tool.cc.

std::unique_ptr<icarus_signal_processing::ICARUSFFT<double> > icarus_tool::FullWireDeconvolution::fFFT
private

Object to handle thread safe FFT.

Definition at line 54 of file FullWireDeconvolution_tool.cc.

const geo::GeometryCore* icarus_tool::FullWireDeconvolution::fGeometry = lar::providerFrom<geo::Geometry>()
private

Definition at line 56 of file FullWireDeconvolution_tool.cc.

art::ServiceHandle<icarusutil::SignalShapingICARUSService> icarus_tool::FullWireDeconvolution::fSignalShaping
private

Definition at line 57 of file FullWireDeconvolution_tool.cc.

icarus_signal_processing::WaveformTools<float> icarus_tool::FullWireDeconvolution::fWaveformTool
private

Definition at line 52 of file FullWireDeconvolution_tool.cc.


The documentation for this class was generated from the following file: