LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar::example::ShowerCalibrationGaloreFromPID Class Reference

Shower calibration service provider correcting according to PID. More...

#include "ShowerCalibrationGaloreFromPID.h"

Inheritance diagram for lar::example::ShowerCalibrationGaloreFromPID:
lar::example::ShowerCalibrationGalore lar::UncopiableAndUnmovableClass

Classes

struct  CalibrationInfo_t
 Internal structure containing the calibration information. More...
 
struct  Config
 Collection of configuration parameters for the service. More...
 

Public Types

using parameters_type = fhicl::Table< Config >
 Type describing all the parameters. More...
 
using PDGID_t = int
 A type representing a particle ID in Particle Data Group convention. More...
 

Public Member Functions

 ShowerCalibrationGaloreFromPID (Config const &config)
 Constructor from the complete configuration object. More...
 
 ShowerCalibrationGaloreFromPID (fhicl::ParameterSet const &pset)
 Constructor from a parameter set. More...
 
virtual std::string report () const override
 Returns a string with a short report of the current corrections. More...
 
void readCalibration (std::string path)
 Reads the calibration information from the specified file. More...
 
template<typename Stream >
void reportTo (Stream &&out) const
 Prints a short report of the current corrections. More...
 
Correction query
virtual float correctionFactor (recob::Shower const &, PDGID_t=unknownID) const override
 Returns a correction factor for a given reconstructed shower. More...
 
virtual Correction_t correction (recob::Shower const &, PDGID_t=unknownID) const override
 Returns the correction for a given reconstructed shower. More...
 

Static Public Member Functions

static void verifyOrder (TGraph const *graph)
 

Static Public Attributes

static constexpr PDGID_t unknownID = 0
 A mnemonic constant for unknown particle ID. More...
 

Private Member Functions

CalibrationInfo_t const & selectCorrection (PDGID_t id) const
 Returns the correct CalibrationInfo_t for specified id. More...
 
CalibrationInfo_t readParticleCalibration (TDirectory *SourceDir, std::string GraphName) const
 Reads and returns calibration information from the specified graph. More...
 
CalibrationInfo_t readParticleCalibration (TDirectory *SourceDir, std::string GraphName, PDGID_t id) const
 
CalibrationInfo_t readParticleCalibration (TDirectory *SourceDir, std::string GraphName, std::initializer_list< PDGID_t > ids) const
 

Static Private Member Functions

static TDirectory * OpenROOTdirectory (std::string path)
 Opens the specified ROOT directory, as in path/to/file.root:dir/dir. More...
 
static std::unique_ptr< ROOT::Math::Interpolator > createInterpolator (unsigned int N, double const *x, double const *y)
 Creates a ROOT interpolator from a set of N points. More...
 

Private Attributes

CalibrationInfo_t Calibration_pi0
 neutral pion calibration More...
 
CalibrationInfo_t Calibration_photon
 photon calibration More...
 
CalibrationInfo_t Calibration_electron
 electron/positron calibration More...
 
CalibrationInfo_t Calibration_muon
 muon/antimuon calibration More...
 
CalibrationInfo_t Calibration_other
 default calibration More...
 

Detailed Description

Shower calibration service provider correcting according to PID.

The service provider computes a calibration factor for a reconstructed shower. The calibration factor depends on an hypothesis on the type of particle. The calibration factors are extracted from the specified ROOT file.

Calibration file format

Calibration is represented by a list of objects with specific names:

  • "Pi0" (TGraphErrors): neutral pion calibration vs. reconstructed energy
  • "Photon" (TGraphErrors): photon calibration vs. reconstructed energy
  • "Electron" (TGraphErrors): electron/positron calibration vs. reconstructed energy
  • "Muon" (TGraphErrors): muon/antimuon calibration vs. reconstructed energy
  • "Default" (TGraphErrors): other particle calibration vs. reconstructed energy

Each graph is required to hold at least one point, and its points must be already sorted by energy. Energy is measured in GeV.

Calibration factors from the input

The input calibration objects are graphs with symmetric errors. The independent variable is the best estimation of the reconstructed energy of the shower. The correction factor is interpolated (by a cubic spline) between the points in the graph; errors are likewise interpolated. If the requested energy is outside the range of the graph the correction is the same as the closest available energy point, with its uncertainty doubled every half full range of the graph. As a special case, if the graph has only one point, the correction is uniform in the full energy spectrum (including its uncertainty).

Configuration parameters

  • CalibrationFile (string, mandatory): path to the file containing the full shower calibration information; it is made of a file system path to the ROOT file, and an optional ROOT directory path; for example: path/to/file.root:Calibrations/Shower expects a nested ROOT directory structure Calibrations/Shower in the ROOT file path/to/file.root, where path is accessible from the usual search path in FW_SEARCH_PATH

Definition at line 121 of file ShowerCalibrationGaloreFromPID.h.

Member Typedef Documentation

Type describing all the parameters.

Definition at line 141 of file ShowerCalibrationGaloreFromPID.h.

A type representing a particle ID in Particle Data Group convention.

Definition at line 66 of file ShowerCalibrationGalore.h.

Constructor & Destructor Documentation

lar::example::ShowerCalibrationGaloreFromPID::ShowerCalibrationGaloreFromPID ( Config const &  config)
inline

Constructor from the complete configuration object.

Definition at line 146 of file ShowerCalibrationGaloreFromPID.h.

References lar::example::ShowerCalibrationGaloreFromPID::Config::CalibrationFile.

147  { readCalibration(config.CalibrationFile()); }
void readCalibration(std::string path)
Reads the calibration information from the specified file.
lar::example::ShowerCalibrationGaloreFromPID::ShowerCalibrationGaloreFromPID ( fhicl::ParameterSet const &  pset)
inline

Constructor from a parameter set.

Definition at line 151 of file ShowerCalibrationGaloreFromPID.h.

153  (parameters_type(pset, { "service_type", "service_provider" })())
154  {}
ShowerCalibrationGaloreFromPID(Config const &config)
Constructor from the complete configuration object.
fhicl::Table< Config > parameters_type
Type describing all the parameters.

Member Function Documentation

lar::example::ShowerCalibrationGalore::Correction_t lar::example::ShowerCalibrationGaloreFromPID::correction ( recob::Shower const &  shower,
PDGID_t  id = unknownID 
) const
overridevirtual

Returns the correction for a given reconstructed shower.

Returns
the correction with its uncertainty
See also
correctionFactor()

The returned value includes a correction factor to be applied to any shower energy to calibrate it, with its global uncertainty.

Implements lar::example::ShowerCalibrationGalore.

Definition at line 50 of file ShowerCalibrationGaloreFromPID.cxx.

References recob::Shower::best_plane(), E, recob::Shower::Energy(), lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::evalError(), lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::evalFactor(), and readCalibration().

Referenced by correctionFactor().

51 {
52  CalibrationInfo_t const& corr = selectCorrection(id);
53 
54  double const E = shower.Energy().at(shower.best_plane());
55 
56  return { (float) corr.evalFactor(E), (float) corr.evalError(E) };
57 } // lar::example::ShowerCalibrationGaloreFromPID::correction()
Float_t E
Definition: plot.C:23
CalibrationInfo_t const & selectCorrection(PDGID_t id) const
Returns the correct CalibrationInfo_t for specified id.
float lar::example::ShowerCalibrationGaloreFromPID::correctionFactor ( recob::Shower const &  shower,
PDGID_t  id = unknownID 
) const
overridevirtual

Returns a correction factor for a given reconstructed shower.

LArSoft libraries.

Returns
the uniform energy correction factor
See also
correction()

The returned value includes a correction factor to be applied to the shower energy to calibrate it, but no uncertainty.

framework and utility libraries

Implements lar::example::ShowerCalibrationGalore.

Definition at line 37 of file ShowerCalibrationGaloreFromPID.cxx.

References recob::Shower::best_plane(), correction(), E, recob::Shower::Energy(), and lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::evalFactor().

38 {
39  CalibrationInfo_t const& corr = selectCorrection(id);
40 
41  double const E = shower.Energy().at(shower.best_plane());
42 
43  return (float) corr.evalFactor(E);
44 } // lar::example::ShowerCalibrationGaloreFromPID::correctionFactor()
Float_t E
Definition: plot.C:23
CalibrationInfo_t const & selectCorrection(PDGID_t id) const
Returns the correct CalibrationInfo_t for specified id.
std::unique_ptr< ROOT::Math::Interpolator > lar::example::ShowerCalibrationGaloreFromPID::createInterpolator ( unsigned int  N,
double const *  x,
double const *  y 
)
staticprivate

Creates a ROOT interpolator from a set of N points.

Definition at line 311 of file ShowerCalibrationGaloreFromPID.cxx.

References max, x, and y.

Referenced by lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::evalError(), and readParticleCalibration().

312 {
313 
314  // decide the type of interpolation based on the available number of points
315  ROOT::Math::Interpolation::Type type;
316  if (N >= 5) type = ROOT::Math::Interpolation::kAKIMA;
317  else if (N >= 3) type = ROOT::Math::Interpolation::kCSPLINE;
318  else type = ROOT::Math::Interpolation::kLINEAR;
319 
320  auto interp
321  = std::make_unique<ROOT::Math::Interpolator>(std::max(N, 2U), type);
322  if (N > 1) interp->SetData(N, x, y);
323  else { // we need to make up the second point
324  double const x_p[2] = { *x, *x + 1. };
325  double const y_p[2] = { *y, *y };
326  interp->SetData(2, x_p, y_p);
327  }
328  return interp;
329 } // lar::example::ShowerCalibrationGaloreFromPID::createInterpolator()
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Int_t max
Definition: plot.C:27
TDirectory * lar::example::ShowerCalibrationGaloreFromPID::OpenROOTdirectory ( std::string  path)
staticprivate

Opens the specified ROOT directory, as in path/to/file.root:dir/dir.

Definition at line 221 of file ShowerCalibrationGaloreFromPID.cxx.

References lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::applyTo(), dir, and lar::example::splitROOTpath().

Referenced by readParticleCalibration().

222 {
223  //
224  // split the data file path
225  //
226  std::string filePath, ROOTdirPath;
227  std::tie(filePath, ROOTdirPath) = splitROOTpath(path);
228 
229  //
230  // find the ROOT file in the search path
231  //
232  std::string fullFilePath;
233  cet::search_path sp("FW_SEARCH_PATH");
234  // if we can't find the file in FW_SEARCH_PATH, we try in current directory
235  if (!sp.find_file(filePath, fullFilePath)) fullFilePath = filePath;
236 
237  //
238  // open the ROOT file (created new)
239  //
240  auto inputFile = std::make_unique<TFile>(fullFilePath.c_str(), "READ");
241  if (!(inputFile->IsOpen())) {
242  throw cet::exception("ShowerCalibrationGaloreFromPID")
243  << "ShowerCalibrationGaloreFromPID::OpenROOTdirectory() can't read '"
244  << fullFilePath << "' (from '" << filePath << "' specification)\n";
245  }
246 
247  //
248  // get the ROOT directory
249  //
250  TDirectory* dir = ROOTdirPath.empty()?
251  inputFile.get(): inputFile->GetDirectory(ROOTdirPath.c_str());
252  if (!dir) {
253  throw cet::exception("ShowerCalibrationGaloreFromPID")
254  << "ShowerCalibrationGaloreFromPID::OpenROOTdirectory() can't find '"
255  << ROOTdirPath << "' in ROOT file '" << inputFile->GetPath() << "'\n";
256  }
257 
258  //
259  // return the directory
260  //
261  inputFile.release(); // do not delete the file any more
262  return dir;
263 } // lar::example::ShowerCalibrationGaloreFromPID::OpenROOTdirectory()
TDirectory * dir
Definition: macro.C:5
std::pair< std::string, std::string > splitROOTpath(std::string path)
Splits path into ROOT file name and directory path.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void lar::example::ShowerCalibrationGaloreFromPID::readCalibration ( std::string  path)

Reads the calibration information from the specified file.

Definition at line 62 of file ShowerCalibrationGaloreFromPID.cxx.

References e.

Referenced by correction().

63 {
64 
65  //
66  // open the input file
67  //
68  TDirectory* CalibDir = nullptr;
69  try {
70  CalibDir = OpenROOTdirectory(path);
71  }
72  catch (cet::exception const& e) {
73  // wrap the exception with context information
74  throw cet::exception
75  ("ShowerCalibrationGaloreFromPID", "readCalibration()", e)
76  << "Reading calibration from: '" << path << "'";
77  }
78  if (!CalibDir) { // this would be actually a bug
79  throw cet::exception
80  ("ShowerCalibrationGaloreFromPID", "readCalibration()")
81  << "Null directory reading calibration from: '" << path << "'";
82  }
83 
84  // make sure that when this is over we are done with the ROOT file
85  std::unique_ptr<TFile> InputFile(CalibDir->GetFile());
86 
87  //
88  // read each calibration object and associate it with its particle category
89  //
90 
91  Calibration_pi0 = readParticleCalibration(CalibDir, "Pi0", 111);
92 
93  Calibration_photon = readParticleCalibration(CalibDir, "Photon", 22);
94 
96  = readParticleCalibration(CalibDir, "Electron", { -11, 11 });
97 
98  Calibration_muon = readParticleCalibration(CalibDir, "Muon", { -13, 13 });
99 
100  Calibration_other = readParticleCalibration(CalibDir, "Default", unknownID);
101 
102  //
103  // release resources
104  //
105 
106  // TFile freed by its unique pointer
107 
108 } // lar::example::ShowerCalibrationGaloreFromPID::readCalibration()
CalibrationInfo_t Calibration_pi0
neutral pion calibration
CalibrationInfo_t Calibration_electron
electron/positron calibration
CalibrationInfo_t Calibration_photon
photon calibration
CalibrationInfo_t Calibration_other
default calibration
CalibrationInfo_t readParticleCalibration(TDirectory *SourceDir, std::string GraphName) const
Reads and returns calibration information from the specified graph.
CalibrationInfo_t Calibration_muon
muon/antimuon calibration
static constexpr PDGID_t unknownID
A mnemonic constant for unknown particle ID.
Float_t e
Definition: plot.C:34
static TDirectory * OpenROOTdirectory(std::string path)
Opens the specified ROOT directory, as in path/to/file.root:dir/dir.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::readParticleCalibration ( TDirectory *  SourceDir,
std::string  GraphName 
) const
private

Reads and returns calibration information from the specified graph.

Definition at line 136 of file ShowerCalibrationGaloreFromPID.cxx.

References createInterpolator(), lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::error, lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::factor, lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::maxE, lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::minE, and verifyOrder().

Referenced by readParticleCalibration(), selectCorrection(), and verifyOrder().

137 {
138  CalibrationInfo_t info;
139 
140  // apply list is left empty
141 
142  //
143  // retrieve the object
144  //
145  auto graph = details::readROOTobject<TGraphErrors>(SourceDir, GraphName);
146 
147  verifyOrder(graph.get());
148 
149  size_t const N = (size_t) graph->GetN();
150  if (N == 0) {
151  throw cet::exception("ShowerCalibrationGaloreFromPID")
152  << "No point in graph " << SourceDir->GetPath() << "/" << GraphName
153  << "\n";
154  }
155 
156  // include the "error" on x in the full range
157  info.minE = graph->GetX()[0];
158  info.maxE = graph->GetX()[N - 1];
159 
160  // a spline; if there are at least 5 points, use AKIMA spline, that is
161  // "stable" for outliers (reducing over/undershoot)
162  // set to zero
163  info.factor = createInterpolator(N, graph->GetX(), graph->GetY());
164 
165  // compute the error in the same way; kind of an approximation here
166  info.error = createInterpolator(N, graph->GetX(), graph->GetEY());
167 
168  return info;
169 } // lar::example::ShowerCalibrationGaloreFromPID::readParticleCalibration()
static std::unique_ptr< ROOT::Math::Interpolator > createInterpolator(unsigned int N, double const *x, double const *y)
Creates a ROOT interpolator from a set of N points.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::readParticleCalibration ( TDirectory *  SourceDir,
std::string  GraphName,
PDGID_t  id 
) const
private

Reads and returns calibration information from the specified graph and register a particle ID in it

Definition at line 200 of file ShowerCalibrationGaloreFromPID.cxx.

References lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::applyTo(), and readParticleCalibration().

201 {
202  CalibrationInfo_t info = readParticleCalibration(SourceDir, GraphName);
203  info.applyTo(id);
204  return info;
205 } // lar::example::ShowerCalibrationGaloreFromPID::readParticleCalibration(ID)
CalibrationInfo_t readParticleCalibration(TDirectory *SourceDir, std::string GraphName) const
Reads and returns calibration information from the specified graph.
lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::readParticleCalibration ( TDirectory *  SourceDir,
std::string  GraphName,
std::initializer_list< PDGID_t ids 
) const
private

Reads and returns calibration information from the specified graph and register a list of particle IDs to it

Definition at line 209 of file ShowerCalibrationGaloreFromPID.cxx.

References lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::applyTo(), OpenROOTdirectory(), and readParticleCalibration().

212  {
213  CalibrationInfo_t info = readParticleCalibration(SourceDir, GraphName);
214  info.applyTo(ids);
215  return info;
216 } // lar::example::ShowerCalibrationGaloreFromPID::readParticleCalibration(IDs)
CalibrationInfo_t readParticleCalibration(TDirectory *SourceDir, std::string GraphName) const
Reads and returns calibration information from the specified graph.
virtual std::string lar::example::ShowerCalibrationGaloreFromPID::report ( ) const
inlineoverridevirtual

Returns a string with a short report of the current corrections.

Implements lar::example::ShowerCalibrationGalore.

Definition at line 188 of file ShowerCalibrationGaloreFromPID.h.

189  { std::ostringstream sstr; reportTo(sstr); return sstr.str(); }
void reportTo(Stream &&out) const
Prints a short report of the current corrections.
template<typename Stream >
void lar::example::ShowerCalibrationGaloreFromPID::reportTo ( Stream &&  out) const

Prints a short report of the current corrections.

Definition at line 322 of file ShowerCalibrationGaloreFromPID.h.

References lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t::reportTo().

323 {
324  out << "Corrections for:";
325  out << "\n - neutral pion: ";
326  Calibration_pi0.reportTo(std::forward<Stream>(out));
327  out << "\n - photon: ";
328  Calibration_photon.reportTo(std::forward<Stream>(out));
329  out << "\n - electron/positron: ";
330  Calibration_electron.reportTo(std::forward<Stream>(out));
331  out << "\n - muon/antimuon: ";
332  Calibration_muon.reportTo(std::forward<Stream>(out));
333  out << "\n - other (default): ";
334  Calibration_other.reportTo(std::forward<Stream>(out));
335  out << "\n";
336 } // lar::example::ShowerCalibrationGaloreFromPID::report()
CalibrationInfo_t Calibration_pi0
neutral pion calibration
CalibrationInfo_t Calibration_electron
electron/positron calibration
CalibrationInfo_t Calibration_photon
photon calibration
CalibrationInfo_t Calibration_other
default calibration
CalibrationInfo_t Calibration_muon
muon/antimuon calibration
void reportTo(Stream &&out) const
Prints a short report of this correction.
lar::example::ShowerCalibrationGaloreFromPID::CalibrationInfo_t const & lar::example::ShowerCalibrationGaloreFromPID::selectCorrection ( PDGID_t  id) const
private

Returns the correct CalibrationInfo_t for specified id.

Definition at line 113 of file ShowerCalibrationGaloreFromPID.cxx.

References Calibration_electron, Calibration_muon, Calibration_other, Calibration_photon, Calibration_pi0, readParticleCalibration(), and lar::example::ShowerCalibrationGalore::unknownID.

114 {
115  switch (id) {
116  case 111: // pi0
117  return Calibration_pi0;
118  case 22: // photon
119  return Calibration_photon;
120  case -11: // electron
121  case +11: // positron
122  return Calibration_electron;
123  case -13: // muon
124  case +13: // antimuon
125  return Calibration_muon;
126  case unknownID:
127  default:
128  return Calibration_other;
129  } // switch
130 } // lar::example::ShowerCalibrationGaloreFromPID::selectCorrection()
CalibrationInfo_t Calibration_pi0
neutral pion calibration
CalibrationInfo_t Calibration_electron
electron/positron calibration
CalibrationInfo_t Calibration_photon
photon calibration
CalibrationInfo_t Calibration_other
default calibration
CalibrationInfo_t Calibration_muon
muon/antimuon calibration
static constexpr PDGID_t unknownID
A mnemonic constant for unknown particle ID.
void lar::example::ShowerCalibrationGaloreFromPID::verifyOrder ( TGraph const *  graph)
static

Verifies that points in specified graph have increasing abscissa

Exceptions
cet::exceptionif points are not sorted by growing x

Definition at line 174 of file ShowerCalibrationGaloreFromPID.cxx.

References readParticleCalibration(), and x.

Referenced by readParticleCalibration().

175 {
176 
177  if (!graph) {
178  throw cet::exception("ShowerCalibrationGaloreFromPID")
179  << "VerifyOrder(): invalid graph specified\n";
180  }
181 
182  size_t const N = graph->GetN();
183  if (N < 2) return;
184 
185  Double_t const* x = graph->GetX();
186 
187  for (size_t i = 1; i < N; ++i) {
188  if (x[i-1] > x[i]) {
189  throw cet::exception("ShowerCalibrationGaloreFromPID")
190  << "VerifyOrder(): points in graph '" << graph->GetName()
191  << "' are not sorted in abscissa\n";
192  }
193  } // while
194 } // lar::example::ShowerCalibrationGaloreFromPID::verifyOrder()
Float_t x
Definition: compare.C:6
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::Calibration_electron
private

electron/positron calibration

Definition at line 237 of file ShowerCalibrationGaloreFromPID.h.

Referenced by selectCorrection().

CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::Calibration_muon
private

muon/antimuon calibration

Definition at line 238 of file ShowerCalibrationGaloreFromPID.h.

Referenced by selectCorrection().

CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::Calibration_other
private

default calibration

Definition at line 239 of file ShowerCalibrationGaloreFromPID.h.

Referenced by selectCorrection().

CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::Calibration_photon
private

photon calibration

Definition at line 236 of file ShowerCalibrationGaloreFromPID.h.

Referenced by selectCorrection().

CalibrationInfo_t lar::example::ShowerCalibrationGaloreFromPID::Calibration_pi0
private

neutral pion calibration

Definition at line 235 of file ShowerCalibrationGaloreFromPID.h.

Referenced by selectCorrection().

constexpr PDGID_t lar::example::ShowerCalibrationGalore::unknownID = 0
staticinherited

A mnemonic constant for unknown particle ID.

Definition at line 69 of file ShowerCalibrationGalore.h.

Referenced by selectCorrection().


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