All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
icarus::opdet::SampledWaveformFunctionTool Struct Reference

Creates a SampledWaveformFunction pulse shape. More...

Inheritance diagram for icarus::opdet::SampledWaveformFunctionTool:
icarus::opdet::SinglePhotonPulseFunctionTool

Classes

struct  Config
 Configuration parameters. More...
 

Public Types

using Parameters = art::ToolConfigTable< Config >
 Tool parameter configuration. More...
 
- Public Types inherited from icarus::opdet::SinglePhotonPulseFunctionTool
using nanoseconds = util::quantities::nanosecond
 Convenience definition for time stored in nanoseconds. More...
 
using PulseFunction_t = icarus::opdet::PhotoelectronPulseFunction< nanoseconds >
 Type of function returned. More...
 

Public Member Functions

 SampledWaveformFunctionTool (Parameters const &config)
 Constructor: sets the configuration. More...
 
- Public Member Functions inherited from icarus::opdet::SinglePhotonPulseFunctionTool
virtual ~SinglePhotonPulseFunctionTool ()=default
 
std::unique_ptr< PulseFunction_tgetPulseFunction ()
 Returns an instance of the pulse function. More...
 

Private Types

using MyFunction_t = icarus::opdet::SampledWaveformFunction< nanoseconds >
 The actual function type we offer. More...
 

Private Member Functions

virtual std::unique_ptr
< PulseFunction_t
doGetPulseFunction () override
 Returns the function that was created at construction time. More...
 

Static Private Member Functions

static std::unique_ptr
< PulseFunction_t
makePulseFunction (Config const &config)
 Creates and returns a pulse function with the specified configuration. More...
 
static
MyFunction_t::WaveformSpecs_t 
extractWaveformSpecification (std::string const &path)
 Parses the specified file and returns the information on the SPR waveform. More...
 

Private Attributes

std::unique_ptr< PulseFunction_tfPulseFunction
 Function stored while waiting to be delivered. More...
 

Detailed Description

Creates a SampledWaveformFunction pulse shape.

See Also
icarus::opdet::SinglePhotonPulseFunctionTool

This tool creates a icarus::opdet::SampledWaveformFunction<nanosecond> function to describe a R5912 PMT pulse attached to the ICARUS detector.

See icarus::opdet::SampledWaveformFunction for the details of the function.

Waveform specification file format

The response must be described in a plain text file following the syntax from icarus::details::KeyValueParser. The following fields are supported:

Configuration

Run lar --print-description SampledWaveformFunctionTool (or read Config data structure) for a short explanation of the meaning of the parameters.

Definition at line 97 of file SampledWaveformFunctionTool_tool.cc.

Member Typedef Documentation

The actual function type we offer.

Definition at line 136 of file SampledWaveformFunctionTool_tool.cc.

Tool parameter configuration.

Definition at line 126 of file SampledWaveformFunctionTool_tool.cc.

Constructor & Destructor Documentation

icarus::opdet::SampledWaveformFunctionTool::SampledWaveformFunctionTool ( Parameters const &  config)
inline

Constructor: sets the configuration.

Definition at line 129 of file SampledWaveformFunctionTool_tool.cc.

130  : fPulseFunction(makePulseFunction(config())) {}
std::unique_ptr< PulseFunction_t > fPulseFunction
Function stored while waiting to be delivered.
static std::unique_ptr< PulseFunction_t > makePulseFunction(Config const &config)
Creates and returns a pulse function with the specified configuration.

Member Function Documentation

virtual std::unique_ptr<PulseFunction_t> icarus::opdet::SampledWaveformFunctionTool::doGetPulseFunction ( )
inlineoverrideprivatevirtual

Returns the function that was created at construction time.

Implements icarus::opdet::SinglePhotonPulseFunctionTool.

Definition at line 142 of file SampledWaveformFunctionTool_tool.cc.

143  { return std::move(fPulseFunction); }
std::unique_ptr< PulseFunction_t > fPulseFunction
Function stored while waiting to be delivered.
auto icarus::opdet::SampledWaveformFunctionTool::extractWaveformSpecification ( std::string const &  path)
staticprivate

Parses the specified file and returns the information on the SPR waveform.

Definition at line 167 of file SampledWaveformFunctionTool_tool.cc.

168 {
169  //
170  // text file parsing
171  //
172  std::ifstream srcFile { path };
173  if (!srcFile.is_open()) {
174  // quite strange, actually, since the file was found by `cet::search_path`
175  throw art::Exception{ art::errors::FileReadError }
176  << "Can't open single photoelectron response file '" << path << "'\n";
177  }
178 
180  icarus::KeyValuesData const data { parser(srcFile) };
181  srcFile.close();
182 
183  //
184  // interpretation
185  //
186 
187  auto makeException = [path]()
188  {
189  return cet::exception{ "SampledWaveformFunctionTool" }
190  << "in '" << path << "': ";
191  };
192 
193  MyFunction_t::WaveformSpecs_t specs;
194 
195  if (auto const* item = data.findItem("Name")) {
196  if (item->nValues() != 1) {
197  throw makeException() << "'Name' must have exactly 1 entry, not "
198  << item->nValues() << "!\n";
199  }
200  specs.name = item->value();
201  }
202 
203  if (auto const* item = data.findItem("Description")) {
204  if (item->nValues() != 1) {
205  throw makeException()
206  << "'Description' must have exactly 1 entry (possibly quoted), not "
207  << item->nValues() << "!\n";
208  }
209  specs.description = item->value();
210  }
211 
212  if (auto const* item = data.findItem("Date")) {
213  if (item->nValues() != 1) {
214  throw makeException()
215  << "'Date' must have exactly 1 entry (possibly quoted), not "
216  << item->nValues() << "!\n";
217  }
218  specs.date = item->value();
219  }
220 
221  if (auto const* item = data.findItem("Version")) {
222  if (item->nValues() != 1) {
223  throw makeException()
224  << "'Version' must have exactly 1 entry, not " << item->nValues()
225  << "!\n";
226  }
227  try {
228  specs.version = item->getNumber<unsigned int>(0);
229  }
230  catch (icarus::KeyValuesData::Error const& e) {
231  throw makeException() << "value in 'Version' ('" << item->value()
232  << "') can't be interpreted as version number (unsigned int):\n"
233  << e.what() << "\n";
234  }
235  }
236 
237  if (auto const* item = data.findItem("Tick")) {
238  if (item->nValues() != 1) {
239  throw makeException()
240  << "'Date' must have exactly 1 entry (possibly quoted), not "
241  << item->nValues() << "!\n";
242  }
243  try {
244  specs.sampleDuration
245  = util::quantities::makeQuantity<nanoseconds>(item->value());
246  }
247  catch(std::runtime_error const& e) {
248  throw makeException()
249  << "Failed to parse 'Tick' ('" << item->value() << "') as a time:\n"
250  << e.what() << "\n";
251  }
252  }
253  else throw makeException() << "'Tick' entry is mandatory.\n";
254 
255  if (auto const* item = data.findItem("Gain")) {
256  if (item->nValues() != 1) {
257  throw makeException()
258  << "'Gain' must have exactly 1 entry, not " << item->nValues() << "!\n";
259  }
260  try {
261  specs.gain = item->getNumber<float>(0);
262  }
263  catch (icarus::KeyValuesData::Error const& e) {
264  throw makeException() << "value in 'Gain' ('" << item->value()
265  << "') can't be interpreted as a gain factor:\n"
266  << e.what() << "\n";
267  }
268  }
269 
270 
271  if (auto const* item = data.findItem("Samples")) {
272  if (item->nValues() < 2) {
273  throw makeException()
274  << "'Samples' has only " << item->nValues() << " values!!\n";
275  }
276  try {
277  specs.samples = item->getVector<float>();
278  }
279  catch(icarus::KeyValuesData::Error const& e) {
280  throw makeException()
281  << "Error converting values in 'Samples' into voltage:\n"
282  << e.what() << "\n";
283  }
284  }
285  else throw makeException() << "'Samples' entry is mandatory.\n";
286 
287 
288  if (auto const* item = data.findItem("NSamples")) {
289  if (item->nValues() != 1) {
290  throw makeException()
291  << "'NSamples' must have exactly 1 entry, not " << item->nValues()
292  << "!\n";
293  }
294  unsigned int nSamples;
295  try {
296  nSamples = item->getNumber<unsigned int>(0);
297  }
298  catch (icarus::KeyValuesData::Error const& e) {
299  throw makeException() << "value in 'NSamples' ('" << item->value()
300  << "') can't be interpreted as a sample number (unsigned int):\n"
301  << e.what() << "\n";
302  }
303  if (specs.samples.size() != nSamples) {
304  throw makeException() << "'Samples' has " << specs.samples.size()
305  << " values, but according to 'NSamples' there should be " << nSamples
306  << "!\n";
307  }
308  }
309 
310 
311  return specs;
312 } // icarus::opdet::SampledWaveformFunctionTool::extractWaveformSpecification()
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
Collection of items with key/values structure.
Parser to fill a KeyValuesData structure out of a character buffer.
do i e
auto icarus::opdet::SampledWaveformFunctionTool::makePulseFunction ( Config const &  config)
staticprivate

Creates and returns a pulse function with the specified configuration.

Definition at line 316 of file SampledWaveformFunctionTool_tool.cc.

317 {
318 
319  //
320  // find and process the waveform information file
321  //
322  cet::search_path searchPath{ "FW_SEARCH_PATH" };
323  std::string waveformSpecsPath;
324  try {
325  waveformSpecsPath = searchPath.find_file(config.WaveformData());
326  }
327  catch (cet::exception& e) {
328  throw art::Exception{ art::errors::Configuration, "", e }
329  << "Error looking for the waveform data file '" << config.WaveformData()
330  << "' (configured via: '" << config.WaveformData.name() << "')\n";
331  }
332 
333  MyFunction_t::WaveformSpecs_t waveformSpecs
334  = extractWaveformSpecification(waveformSpecsPath);
335 
336  //
337  // fix the gain request
338  //
339  if ((config.Gain().value_or(0.0) != 0.0) && (waveformSpecs.gain == 0.0)) {
340  throw art::Exception(art::errors::Configuration)
341  << "The single photoelectron response '" << waveformSpecs.name
342  << "' at '" << waveformSpecsPath
343  << "' does not specify a base gain, so it can't be rescaled to "
344  << config.Gain().value()
345  << " ('" << config.Gain.name() << "' parameter)\n";
346  }
347  float const reqGain = (config.Gain().value_or(0.0) != 0.0)
348  ? config.Gain().value(): waveformSpecs.gain;
349 
350  //
351  // create the algorithm
352  //
353  return std::make_unique<MyFunction_t>(
354  std::move(waveformSpecs) // waveformSpecs
355  , config.TransitTime() // peakTime
356  , reqGain // gain
357  );
358 
359 } // icarus::opdet::SampledWaveformFunctionTool::makePulseFunction()
static MyFunction_t::WaveformSpecs_t extractWaveformSpecification(std::string const &path)
Parses the specified file and returns the information on the SPR waveform.
do i e

Member Data Documentation

std::unique_ptr<PulseFunction_t> icarus::opdet::SampledWaveformFunctionTool::fPulseFunction
private

Function stored while waiting to be delivered.

Definition at line 148 of file SampledWaveformFunctionTool_tool.cc.


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