13 #ifndef LAREXAMPLES_SERVICES_SHOWERCALIBRATIONGALORE_PROVIDERS_SHOWERCALIBRATIONGALOREFROMPID_H
14 #define LAREXAMPLES_SERVICES_SHOWERCALIBRATIONGALORE_PROVIDERS_SHOWERCALIBRATIONGALOREFROMPID_H
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/types/Comment.h"
23 #include "fhiclcpp/types/Name.h"
24 #include "fhiclcpp/types/Table.h"
27 #include "Math/Interpolator.h"
28 #include "TDirectory.h"
36 #include <type_traits>
37 #include <initializer_list>
55 template <
typename ROOTobj>
57 (TDirectory* sourceDir, std::string
name);
131 Name(
"CalibrationFile"),
133 "path to calibration file and ROOT directory"
134 " (e.g. path/to/file.root:Dir/Dir)"
188 virtual std::string
report()
const override
189 { std::ostringstream sstr;
reportTo(sstr);
return sstr.str(); }
197 template <
typename Stream>
215 std::unique_ptr<ROOT::Math::Interpolator>
factor;
218 std::unique_ptr<ROOT::Math::Interpolator>
error;
230 template <
typename Stream>
247 (TDirectory* SourceDir, std::string GraphName)
const;
252 (TDirectory* SourceDir, std::string GraphName,
PDGID_t id)
const;
257 TDirectory* SourceDir, std::string GraphName,
258 std::initializer_list<PDGID_t> ids
265 static std::unique_ptr<ROOT::Math::Interpolator>
282 template <
typename ROOTobj>
284 (TDirectory* sourceDir, std::string
name)
287 throw cet::exception(
"readROOTobject")
288 <<
"Invalid source ROOT directory\n";
292 TObject* pObj = sourceDir->Get(name.c_str());
294 throw cet::exception(
"readROOTobject")
295 <<
"No object '" << name <<
"' in ROOT directory '"
296 << sourceDir->GetPath() <<
"'\n";
299 if (std::is_base_of<TH1, std::decay_t<ROOTobj>>::
value)
300 static_cast<TH1*
>(pObj)->SetDirectory(
nullptr);
303 std::unique_ptr<TObject> obj(pObj);
306 if (!obj->InheritsFrom(ROOTobj::Class())) {
307 throw cet::exception(
"readROOTobject")
308 <<
"Object '" << name <<
"' in ROOT directory '"
309 << sourceDir->GetPath() <<
"' is a " << obj->IsA()->GetName()
310 <<
", not derived from " << ROOTobj::Class()->GetName() <<
"\n";
315 return std::unique_ptr<ROOTobj>(
static_cast<ROOTobj*
>(obj.release()));
321 template <
typename Stream>
324 out <<
"Corrections for:";
325 out <<
"\n - neutral pion: ";
327 out <<
"\n - photon: ";
329 out <<
"\n - electron/positron: ";
331 out <<
"\n - muon/antimuon: ";
333 out <<
"\n - other (default): ";
340 template <
typename Stream>
345 out <<
"not present";
349 out <<
"uniform correction " << factor->Eval(minE) <<
" +/- "
350 <<
error->Eval(minE) <<
" for all energies";
353 out <<
"correction valid from E=" << minE
354 <<
" GeV (" << factor->Eval(minE) <<
" +/- " <<
error->Eval(minE)
356 <<
" GeV (" << factor->Eval(maxE) <<
" +/- " <<
error->Eval(maxE)
359 if (!appliesTo.empty()) {
360 out <<
"; covers particles ID={";
361 for (
auto id: appliesTo) out <<
" " << id;
371 #endif // LAREXAMPLES_SERVICES_SHOWERCALIBRATIONGALORE_PROVIDERS_SHOWERCALIBRATIONGALOREFROMPID_H
CalibrationInfo_t Calibration_pi0
neutral pion calibration
double minE
lower end of the energy range covered [GeV]
CalibrationInfo_t Calibration_electron
electron/positron calibration
Internal structure containing the calibration information.
process_name opflash particleana ie x
double evalError(double E) const
std::unique_ptr< ROOT::Math::Interpolator > error
parametrisation of the correction uncertainty
fhicl::Atom< std::string > CalibrationFile
CalibrationInfo_t const & selectCorrection(PDGID_t id) const
Returns the correct CalibrationInfo_t for specified id.
Collection of configuration parameters for the service.
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.
std::vector< PDGID_t > appliesTo
PID it applies to; unused.
virtual Correction_t correction(recob::Shower const &, PDGID_t=unknownID) const override
Returns the correction for a given reconstructed shower.
Shower calibration service provider correcting according to PID.
virtual std::string report() const override
Returns a string with a short report of the current corrections.
CalibrationInfo_t Calibration_photon
photon calibration
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
ShowerCalibrationGaloreFromPID(fhicl::ParameterSet const &pset)
Constructor from a parameter set.
CalibrationInfo_t Calibration_other
default calibration
process_name opflash particleana ie ie y
virtual float correctionFactor(recob::Shower const &shower, PDGID_t PDGID=unknownID) const =0
Returns a correction factor for a given reconstructed shower.
CalibrationInfo_t readParticleCalibration(TDirectory *SourceDir, std::string GraphName) const
Reads and returns calibration information from the specified graph.
static void verifyOrder(TGraph const *graph)
CalibrationInfo_t & applyTo(PDGID_t id)
BEGIN_PROLOG vertical distance to the surface Name
CalibrationInfo_t Calibration_muon
muon/antimuon calibration
std::unique_ptr< ROOT::Math::Interpolator > factor
parametrisation of the correction factor
static constexpr PDGID_t unknownID
A mnemonic constant for unknown particle ID.
int PDGID_t
A type representing a particle ID in Particle Data Group convention.
Interface for a shower calibration service provider.
process_name largeant stream1 can override from command line with o or output physics producers generator N
std::unique_ptr< ROOTobj > readROOTobject(TDirectory *sourceDir, std::string name)
double maxE
upper end of the energy range covered [GeV]
std::pair< std::string, std::string > splitROOTpath(std::string path)
Splits path into ROOT file name and directory path.
void reportTo(Stream &&out) const
Prints a short report of this correction.
double evalFactor(double E) const
ShowerCalibrationGaloreFromPID(Config const &config)
Constructor from the complete configuration object.
void readCalibration(std::string path)
Reads the calibration information from the specified file.
static TDirectory * OpenROOTdirectory(std::string path)
Opens the specified ROOT directory, as in path/to/file.root:dir/dir.
void reportTo(Stream &&out) const
Prints a short report of the current corrections.
Interface for a shower calibration service provider.
fhicl::Table< Config > parameters_type
Type describing all the parameters.