DuneDPhaseDeconvolutionService_service.cc
Go to the documentation of this file.
1 // DuneDPhaseDeconvolutionService_service.cc
2 
4 #include <iostream>
9 
10 using std::string;
11 using std::cout;
12 using std::endl;
13 
14 //**********************************************************************
15 
18 : m_LogLevel(1) {
19  const string myname = "DuneDPhaseDeconvolutionService::ctor: ";
20  pset.get_if_present<int>("LogLevel", m_LogLevel);
21  print(cout, myname);
22 }
23 
24 //**********************************************************************
25 
28  AdcChannelData& data) const {
29  const string myname = "DuneDPhaseDeconvolutionService::update: ";
30  AdcChannel chan = data.channel();
31  AdcSignalVector& samples = data.samples;
32  unsigned int nsam = samples.size();
33  if ( m_LogLevel >= 2 ) cout << myname << "Deconvoluting channel " << chan
34  << " with " << nsam << " samples." << endl;
35  // Fetch the FFT size.
37  unsigned int fftsize = hFFT->FFTSize();
38  if ( nsam > fftsize ) {
39  cout << myname << "ERROR: Data has too many ticks for FFT: "
40  << nsam << " > " << fftsize << "." << endl;
41  return 1;
42  }
43  // Pad the data to the FFT size.
44  bool pad = fftsize > nsam;
45  if ( pad ) {
46  if ( m_LogLevel >= 3 ) cout << myname << " Padding sample vector to " << fftsize << endl;
47  samples.resize(fftsize);
48  for ( unsigned int isam=nsam; isam<fftsize; ++isam ) {
49  samples[isam] = samples[isam-nsam];
50  }
51  }
52  // Deconvolute.
54  if ( m_LogLevel >= 3 ) cout << myname << " Deconvoluting." << endl;
55  hsss->Deconvolute(chan, samples);
56  if ( pad ) samples.resize(nsam);
57  if ( m_LogLevel >= 3 ) cout << myname << " Normalizing." << endl;
58  float norm = 1.0/hsss->GetDeconNorm();
59  if ( m_LogLevel >= 3 ) cout << myname << " Scale factor: " << norm << endl;
60  for ( float& sam : samples ) sam *= norm;
61  // Done.
62  return 0;
63 }
64 
65 //**********************************************************************
66 
68 print(std::ostream& out, std::string prefix) const {
69  out << prefix << "DuneDPhaseDeconvolutionService:" << endl;
70  out << prefix << " LogLevel: " << m_LogLevel << endl;
71  return out;
72 }
73 
74 //**********************************************************************
75 
77 
78 //**********************************************************************
std::string string
Definition: nybbler.cc:12
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
int FFTSize() const
Definition: LArFFT.h:69
int update(detinfo::DetectorClocksData const &clockData, AdcChannelData &data) const
Service to provide DUNE dual-phase signal shaping for simulation (convolution) and reconstruction (de...
auto norm(Vector const &v)
Return norm of the specified vector.
DuneDPhaseDeconvolutionService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
Channel channel() const
Contains all timing reference information for the detector.
unsigned int AdcChannel
Definition: AdcTypes.h:50
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
void Deconvolute(unsigned int channel, std::vector< T > &func) const
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)