11 #ifndef ICARUSCODE_PMT_ALGORITHMS_CUSTOMPULSEFUNCTION_H
12 #define ICARUSCODE_PMT_ALGORITHMS_CUSTOMPULSEFUNCTION_H
37 namespace icarus::opdet {
99 std::string
const& expression,
104 std::string
const& expression,
136 std::string
const& expression,
150 {
return ADCcount::castFrom(
fFormula.Eval(static_cast<double>(time))); }
167 std::string
const& indent, std::string
const& firstIndent
196 template <
typename T>
198 std::string
const& expression,
209 template <
typename T>
211 std::string
const& expression,
213 std::string
const& peakTime
217 TFormula peakExpr(
"CustomPulseFunctionPeak", peakTime.c_str(),
false);
221 if (!msg.empty())
throw std::runtime_error(
"CustomPulseFunction:" + msg);
230 template <
typename T>
232 std::string
const& expression,
236 "CustomPulseFunction",
241 std::string
const msg = checkMissingParameters(fFormula, parameters)
242 + checkExcessParameters(fFormula, parameters);
243 if (!msg.empty())
throw std::runtime_error(
"CustomPulseFunction:" + msg);
245 setParameters(fFormula, parameters);
250 template <
typename T>
265 template <
typename T>
268 std::string
const& indent, std::string
const& firstIndent
272 << firstIndent <<
"Custom pulse shape: " << fFormula.GetTitle()
273 <<
"\n" << indent <<
" peak " << fStats.peakAmplitude
274 <<
" at " << fStats.peakTime
276 if (fFormula.GetNpar() > 0) {
277 out <<
"\n" << indent <<
"Parameters (" << fFormula.GetNpar() <<
"):";
279 out <<
"\n" << indent <<
" [" << fFormula.GetParName(iPar) <<
"] = "
280 << fFormula.GetParameter(iPar);
288 template <
typename T>
292 std::set<std::string> required;
294 required.insert(formula.GetParName(iPar));
295 std::set<std::string> offered;
296 for (
auto const& nameAndValue: parameters)
297 offered.insert(nameAndValue.first);
299 std::set<std::string> missing;
301 required.cbegin(), required.cend(), offered.cbegin(), offered.cend(),
302 std::inserter(missing, missing.begin())
304 if (missing.empty())
return {};
307 {
"\n * " +
std::to_string(missing.size()) +
" parameters missing:" };
308 for (
auto const&
name: missing) msg +=
"\n - '" +
name +
"'";
316 template <
typename T>
320 std::set<std::string> offered;
321 for (
auto const& nameAndValue: parameters)
322 offered.insert(nameAndValue.first);
323 std::set<std::string> required;
325 required.insert(formula.GetParName(iPar));
327 std::set<std::string> excess;
329 offered.cbegin(), offered.cend(), required.cbegin(), required.cend(),
330 std::inserter(excess, excess.begin())
332 if (excess.empty())
return {};
335 {
"\n * " +
std::to_string(excess.size()) +
" unused parameters:" };
336 for (
auto const&
name: excess) msg +=
"\n - '" +
name +
"'";
344 template <
typename T>
348 for (
auto const& [
name,
value ]: parameters) {
349 auto const iPar = formula.GetParNumber(
name.c_str());
350 if (iPar < 0)
continue;
351 formula.SetParameter(iPar,
value);
358 #endif // ICARUSCODE_PMT_ALGORITHMS_CUSTOMPULSEFUNCTION_H
static std::string checkMissingParameters(TFormula const &formula, PulseParameters_t const ¶meters)
static std::string checkExcessParameters(TFormula const &formula, PulseParameters_t const ¶meters)
Record of collected information on the pulse shape.
virtual ADCcount doEvaluateAt(Time time) const override
Evaluates the pulse at the given time.
virtual ADCcount doPeakAmplitude() const override
Returns the amplitude of the first peak in ADC counts.
TFormula fFormula
Formula of the shape.
T Time
Type of time being used.
static void setParameters(TFormula &formula, PulseParameters_t const ¶meters)
Sets the value of the parameters of formula.
CustomPulseFunction(std::string const &expression, PulseParameters_t const ¶meters, Time peakTime)
Constructor: chooses shape and the values of its parameters.
std::pair< std::string, ParameterValue_t > NameAndValue_t
Type of parameter name/value definition.
Abstract interface of shape of a pulse from one photoelectron.
bool negativePulse
Whether the pulse is considered negative.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
std::vector< NameAndValue_t > PulseParameters_t
Type of list of all function parameters.
ParameterValue_t parameter(std::string const &name) const
Returns the value of the parameter specified by name.
Time peakTime() const
Returns the time at which the first peak is found.
Interface for a function describing a pulse from a photoelectron.
ADCcount peakAmplitude
Pulse amplitude at peak time.
Test of util::counter and support utilities.
typename Base_t::ADCcount ADCcount
Type for ADC counts (floating point).
PulseStats_t fStats
Collected information about the pulse.
virtual Time doPeakTime() const override
Returns the time at which the first peak is found.
Dimensioned variables related to electronics.
Describes the waveform from a single photoelectron.
std::string to_string(WindowPattern const &pattern)
Time peakTime
Time of the pulse peak.
double ParameterValue_t
Type of value for parameters (TFormula).
typename Base_t::Time Time
Type of time being used.
PulseStats_t extractStats(Time peakTime) const
Extracts statistics from pulse shape.
util::quantities::counts_f ADCcount
Type for ADC counts (floating point).
virtual void doDump(std::ostream &out, std::string const &indent, std::string const &firstIndent) const override
Prints on stream the parameters of this shape.