LDMX Software
HcalReconConditions.cxx
1#include "Hcal/HcalReconConditions.h"
2
5
6namespace hcal {
7
8const std::string HcalReconConditions::CONDITIONS_NAME = "HcalReconConditions";
9
13 const conditions::DoubleTableCondition& tot_calib,
14 const conditions::DoubleTableCondition& toa_calib)
15 : framework::ConditionsObject(HcalReconConditions::CONDITIONS_NAME),
16 adc_pedestals_{adc_ped},
17 adc_gains_{adc_gain},
18 tot_calibs_{tot_calib},
19 toa_calibs_{toa_calib} {}
20
22 double sum_tot) const {
23 // check if the linearization has been done correctly
24 // a non-zero flag value is implicitly converted to true
25 if (totCalib(id, i_flagged) == 1) {
26 return true;
27 }
28
29 // if we are in ADC range (which was used as a reference in linearization),
30 // we use ADC
31 if (sum_tot < totCalib(id, i_lower_offset)) {
32 return true;
33 }
34
35 return false;
36}
37
39 double sum_tot) const {
40 // we know we have a linearization fit and are in TOT range,
41 // the lower side of TOT needs to be linearized with a specialized power law
42 if (sum_tot < totCalib(id, i_cut_point_tot)) {
43 return pow((sum_tot - totCalib(id, i_lower_offset)) /
45 1 / totCalib(id, i_low_power)) +
47 }
48
49 // we know sum_tot is >= lower offset and >= tot cut
50 // higher tot, linearized with adc using a simple linear mapping
51 return (sum_tot - totCalib(id, i_high_offset)) * totCalib(id, i_high_slope);
52}
53
66 std::string adc_gain_;
68 std::string adc_ped_;
70 std::string tot_calib_;
72 std::string toa_calib_;
73
74 public:
85 HcalReconConditionsProvider(const std::string& name,
86 const std::string& tagname,
87 const framework::config::Parameters& parameters,
89 : ConditionsObjectProvider(hcal::HcalReconConditions::CONDITIONS_NAME,
90 tagname, parameters, proc) {
92 EXCEPTION_RAISE("BadConfig",
93 "The name provided to HcalReconConditionsProvider " +
94 name + " is not equal to the expected name " +
96 }
97 adc_gain_ = parameters.getParameter<std::string>("adc_gain");
98 adc_ped_ = parameters.getParameter<std::string>("adc_ped");
99 tot_calib_ = parameters.getParameter<std::string>("tot_calib");
100 toa_calib_ = parameters.getParameter<std::string>("toa_calib");
101 }
102
114 virtual std::pair<const framework::ConditionsObject*,
116 getCondition(const ldmx::EventHeader& context) final override {
117 // requestParentCondition does check current context for validity
118 // to avoid extra constructions
119 auto [adc_gain_co, adc_gain_iov] =
121 auto [adc_ped_co, adc_ped_iov] = requestParentCondition(adc_ped_, context);
122 auto [tot_calib_co, tot_calib_iov] =
124 auto [toa_calib_co, toa_calib_iov] =
126
127 // deduce "minimum" IOV
128 // TODO: Framework #56 :
129 // https://github.com/LDMX-Software/Framework/issues/56
130 [[maybe_unused]] auto min_iov = adc_ped_iov;
131 // use std::move(min_iov) in return statement below
132
133 // wrap
135 dynamic_cast<const conditions::DoubleTableCondition&>(*adc_ped_co),
136 dynamic_cast<const conditions::DoubleTableCondition&>(*adc_gain_co),
137 dynamic_cast<const conditions::DoubleTableCondition&>(*tot_calib_co),
138 dynamic_cast<const conditions::DoubleTableCondition&>(*toa_calib_co));
139
140 return {co, framework::ConditionsIOV(context.getRun(), context.getRun())};
141 }
142};
143
144} // namespace hcal
145
146DECLARE_CONDITIONS_PROVIDER_NS(hcal, HcalReconConditionsProvider);
Base class for provider of conditions information like pedestals, gains, electronics maps,...
#define DECLARE_CONDITIONS_PROVIDER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that provides header information about an event such as event number and timestamp.
be configured to load conditions objects from CSV files.
Class which defines the run/event/type range for which a given condition is valid,...
Base class for all providers of conditions objects.
std::pair< const ConditionsObject *, ConditionsIOV > requestParentCondition(const std::string &name, const ldmx::EventHeader &context)
Request another condition needed to construct this condition.
Base class for all conditions objects, very simple.
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
a helpful interface for grabbing the parent conditions at once
virtual std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > getCondition(const ldmx::EventHeader &context) final override
Get the wrapped condition.
std::string adc_gain_
name of condition object for hcal adc gains
std::string adc_ped_
name of condition object for hcal adc pedestals
std::string tot_calib_
name of condition object for hcal tot calibrations
HcalReconConditionsProvider(const std::string &name, const std::string &tagname, const framework::config::Parameters &parameters, framework::Process &proc)
Retrieve the name of the parent conditions from the configuration.
std::string toa_calib_
name of condition object for hcal toa calibrations
Class to wrap around the various recon condition tables.
static const unsigned int i_lower_offset
index of lower_offset in tot_calib table
static const unsigned int i_high_offset
index of high_offset in tot_calib table
static const unsigned int i_flagged
index of flagged in tot_calib table
bool is_adc(const ldmx::HcalDigiID &id, double sum_tot) const
check if the input digi is in ADC mode (or not) using the digi id and its evaluated sum tot
double linearize(const ldmx::HcalDigiID &id, double sum_tot) const
linearize the input sum_tot for the input channel into unified amplitude units
static const std::string CONDITIONS_NAME
the name of the HcalReconConditions table (must match python registration name)
double totCalib(const ldmx::HcalDigiID &id, int idx=0) const
get a TOT calibration value
HcalReconConditions(const conditions::DoubleTableCondition &adc_ped, const conditions::DoubleTableCondition &adc_gain, const conditions::DoubleTableCondition &tot_calib, const conditions::DoubleTableCondition &toa_calib)
Provide the necessary tables to hold in one conditions object.
static const unsigned int i_high_slope
index of high_slope in tot_calib table
static const unsigned int i_cut_point_tot
index of cut_point_tot in tot_calib table
static const unsigned int i_tot_not
index of tot_not in tot_calib table
static const unsigned int i_low_slope
index of low_slope in tot_calib table
static const unsigned int i_low_power
index of low_power in tot_calib table
Provides header information an event such as event number and timestamp.
Definition EventHeader.h:44
Extension of HcalAbstractID providing access to HCal digi information.
Definition HcalDigiID.h:13
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45