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

Public Member Functions

 Filter (const fhicl::ParameterSet &pset)
 
 ~Filter ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void setResponse (size_t numBins, double correct3D, double timeScaleFctr) override
 
void outputHistograms (art::TFileDirectory &) const override
 
size_t getPlane () const override
 
const icarusutil::FrequencyVecgetResponseVec () const override
 

Private Attributes

size_t fPlane
 
std::vector< double > fParameters
 
std::string fFunctionString
 
double fFilterWidthCorrectionFactor
 
icarusutil::FrequencyVec fFilterVec
 

Additional Inherited Members

- Private Member Functions inherited from icarus_tool::IFilter
virtual ~IFilter () noexcept=default
 

Detailed Description

Definition at line 23 of file Filter_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 50 of file Filter_tool.cc.

51 {
52  configure(pset);
53 }
void configure(const fhicl::ParameterSet &pset) override
Definition: Filter_tool.cc:60
icarus_tool::Filter::~Filter ( )

Definition at line 55 of file Filter_tool.cc.

56 {
57  return;
58 }

Member Function Documentation

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

Implements icarus_tool::IFilter.

Definition at line 60 of file Filter_tool.cc.

61 {
62  // Start by recovering the parameters
63  fPlane = pset.get<size_t>("Plane");
64  fParameters = pset.get<std::vector<double>>("FilterParametersVec");
65  fFunctionString = pset.get<std::string>("FilterFunction");
66  fFilterWidthCorrectionFactor = pset.get<double>("FilterWidthCorrectionFactor");
67 
68  return;
69 }
std::string fFunctionString
Definition: Filter_tool.cc:41
std::vector< double > fParameters
Definition: Filter_tool.cc:40
double fFilterWidthCorrectionFactor
Definition: Filter_tool.cc:42
size_t icarus_tool::Filter::getPlane ( ) const
inlineoverridevirtual

Implements icarus_tool::IFilter.

Definition at line 34 of file Filter_tool.cc.

34 {return fPlane;}
const icarusutil::FrequencyVec& icarus_tool::Filter::getResponseVec ( ) const
inlineoverridevirtual

Implements icarus_tool::IFilter.

Definition at line 35 of file Filter_tool.cc.

35 {return fFilterVec;}
icarusutil::FrequencyVec fFilterVec
Definition: Filter_tool.cc:45
void icarus_tool::Filter::outputHistograms ( art::TFileDirectory &  histDir) const
overridevirtual

Implements icarus_tool::IFilter.

Definition at line 124 of file Filter_tool.cc.

125 {
126  // It is assumed that the input TFileDirectory has been set up to group histograms into a common
127  // folder at the calling routine's level. Here we create one more level of indirection to keep
128  // histograms made by this tool separate.
129  std::string dirName = "FilterPlane_" + std::to_string(fPlane);
130 
131  art::TFileDirectory dir = histDir.mkdir(dirName.c_str());
132 
133  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
134  double samplingRate = 1.e-3 * sampling_rate(clockData); // Note sampling rate is in ns, convert to us
135  double numBins = fFilterVec.size();
136  double maxFreq = 1.e3 / samplingRate; // Max frequency in MHz
137  double minFreq = maxFreq / numBins;
138  std::string histName = "FilterPlane_" + std::to_string(fPlane);
139  TProfile* hist = dir.make<TProfile>(histName.c_str(), "Filter;Frequency(kHz)", numBins/2, minFreq, 0.5*maxFreq);
140 
141  for(int bin = 0; bin < numBins/2; bin++)
142  {
143  double freq = bin * minFreq;
144 
145  hist->Fill(freq, std::abs(fFilterVec.at(bin)), 1.);
146  }
147 
148 
149  return;
150 }
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
T abs(T value)
tuple dir
Definition: dropbox.py:28
std::string to_string(WindowPattern const &pattern)
icarusutil::FrequencyVec fFilterVec
Definition: Filter_tool.cc:45
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
void icarus_tool::Filter::setResponse ( size_t  numBins,
double  correct3D,
double  timeScaleFctr 
)
overridevirtual

Implements icarus_tool::IFilter.

Definition at line 71 of file Filter_tool.cc.

72 {
73  // Note that here we are working in frequency space, not in the time domain...
74  // FIXME: Assumes that the job-level clock data is sufficient.
75  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
76  double samplingRate = 1.e-3 * sampling_rate(clockData); // Note sampling rate is in ns, convert to us
77  double maxFreq = 1.e3 / (2. * samplingRate); // highest frequency in cycles/us (MHz)
78  double freqRes = maxFreq / double(numBins/2); // frequency resolution in cycles/us
79 
80  std::string funcName = "tempFilter";
81  TF1 function(funcName.c_str(),fFunctionString.c_str());
82 
83  // Set the range on the function, probably not really necessary
84  function.SetRange(0, maxFreq);
85 
86  // now to scale the filter function!
87  // only scale params 1,2 &3
88  double timeFactor = 1. / (timeScaleFctr * correct3D * fFilterWidthCorrectionFactor);
89  size_t paramIdx(0);
90 
91  for(const auto& parameter : fParameters) function.SetParameter(paramIdx++, timeFactor * parameter);
92 
93  // Don't assume that the filter vec has not already been initialized...
94  // Note we are setting up the FFT to be the "full" so add a bin for folding over
95  fFilterVec.resize(numBins,icarusutil::ComplexVal(0.,0.));
96 
97  // Keep track of the peak value
98  double peakVal(std::numeric_limits<double>::min());
99 
100  size_t nyquistBin = numBins/2 + 1;
101 
102  // Now ready to set the response vector
103  for(size_t bin = 0; bin < nyquistBin; bin++)
104  {
105  // This takes a sampling rate in ns -> gives a frequency in cycles/us
106  double freq = bin * freqRes;
107  double f = function.Eval(freq);
108 
109  peakVal = std::max(peakVal, f);
110 
112  }
113 
114  // Since we are returning the "full" FFT... folder over the first half
115  for(size_t bin = nyquistBin; bin < numBins; bin++)
116  fFilterVec[bin] = std::conj(fFilterVec[numBins - bin]);
117 
118  // "Normalize" to peak value
119  for(auto& filterValue : fFilterVec) filterValue = filterValue / peakVal;
120 
121  return;
122 }
std::complex< SigProcPrecision > ComplexVal
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::string fFunctionString
Definition: Filter_tool.cc:41
std::vector< double > fParameters
Definition: Filter_tool.cc:40
double fFilterWidthCorrectionFactor
Definition: Filter_tool.cc:42
icarusutil::FrequencyVec fFilterVec
Definition: Filter_tool.cc:45
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.

Member Data Documentation

icarusutil::FrequencyVec icarus_tool::Filter::fFilterVec
private

Definition at line 45 of file Filter_tool.cc.

double icarus_tool::Filter::fFilterWidthCorrectionFactor
private

Definition at line 42 of file Filter_tool.cc.

std::string icarus_tool::Filter::fFunctionString
private

Definition at line 41 of file Filter_tool.cc.

std::vector<double> icarus_tool::Filter::fParameters
private

Definition at line 40 of file Filter_tool.cc.

size_t icarus_tool::Filter::fPlane
private

Definition at line 39 of file Filter_tool.cc.


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