2 #include "art/Framework/Core/EDProducer.h"
3 #include "art/Framework/Principal/Event.h"
4 #include "art/Framework/Principal/Handle.h"
5 #include "art/Framework/Services/Registry/ServiceHandle.h"
6 #include "art/Persistency/Common/PtrMaker.h"
7 #include "art/Utilities/ToolMacros.h"
8 #include "cetlib/cpu_timer.h"
9 #include "fhiclcpp/ParameterSet.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
32 void configure(
const fhicl::ParameterSet& pset)
override;
56 std::vector<ScaleBin>
bins;
61 std::string
URL(uint64_t timestamp);
78 fURL = pset.get<std::string>(
"URL");
79 fTimeout = pset.get<
unsigned>(
"Timeout");
80 fVerbose = pset.get<
bool>(
"Verbose",
false);
89 if (fScaleInfos.count(timestamp)) {
90 return fScaleInfos.at(timestamp);
95 std::string url = URL(timestamp);
97 if (fVerbose)
std::cout <<
"NormalizeYZ Tool -- New Scale info, requesting data from url:\n" << url << std::endl;
99 Dataset d = getDataWithTimeout(url.c_str(),
"", fTimeout, &
error);
101 throw cet::exception(
"NormalizeYZ") <<
"Calibration Database access failed. URL: (" << url <<
") Error Code: " <<
error;
104 if (fVerbose)
std::cout <<
"NormalizeYZ Tool -- Received HTTP response:\n" << getHTTPmessage(d) << std::endl;
106 if (getHTTPstatus(d) != 200) {
107 throw cet::exception(
"NormalizeYZ")
108 <<
"Calibration Database access failed. URL: (" << url
109 <<
"). HTTP error status: " << getHTTPstatus(d) <<
". HTTP error message: " << getHTTPmessage(d);
117 Tuple tup = getTuple(d, 0);
118 float tzero = getDoubleValue(tup, 0, &error);
120 throw cet::exception(
"NormalizeYZ")
121 <<
"Calibration Database access failed. URL: (" << url
122 <<
"). Failed on tuple access, row 0, col 0. Error Code: " <<
error;
125 if (fVerbose)
std::cout <<
"NormalizeYZ Tool -- Obtained T0: " << tzero << std::endl;
128 bool found_scale_t0 =
false;
129 for (
auto const &scale_pair: fScaleInfos) {
130 const ScaleInfo &scale = scale_pair.second;
131 if (scale.
tzero == tzero) {
133 found_scale_t0 =
true;
135 if (fVerbose)
std::cout <<
"NormalizeYZ Tool -- Found prior matching T0 from timestamp: " << scale_pair.first << std::endl;
141 if (found_scale_t0) {
142 fScaleInfos[timestamp] = thisscale;
143 return fScaleInfos.at(timestamp);
149 thisscale.
tzero = tzero;
152 int n_tuple = getNtuples(d);
154 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Bad Tuple Number: " << n_tuple;
159 for (
unsigned row = 4;
row < (unsigned)n_tuple;
row++) {
165 int strl = getStringValue(tup, 1, tpcbuf, 10, &err);
168 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Failed on tuple access, row: " <<
row <<
", col 1. Error Code: " <<
err;
171 std::string tpcname(tpcbuf);
172 if (tpcname ==
"EE") itpc = 0;
173 else if (tpcname ==
"EW") itpc = 1;
174 else if (tpcname ==
"WE") itpc = 2;
175 else if (tpcname ==
"WW") itpc = 3;
177 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Bad TPC name (" << tpcname <<
").";
181 double ylo = getDoubleValue(tup, 8, &err);
183 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Failed on tuple access, row: " <<
row <<
", col 8. Error Code: " <<
err;
185 double yhi = getDoubleValue(tup, 9, &err);
187 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Failed on tuple access, row: " <<
row <<
", col 9. Error Code: " <<
err;
189 double zlo = getDoubleValue(tup, 10, &err);
191 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Failed on tuple access, row: " <<
row <<
", col 10. Error Code: " <<
err;
193 double zhi = getDoubleValue(tup, 11, &err);
195 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Failed on tuple access, row: " <<
row <<
", col 11. Error Code: " <<
err;
199 double scale = getDoubleValue(tup, 4, &err);
201 throw cet::exception(
"NormalizeYZ") <<
"NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url <<
") Failed on tuple access, row: " <<
row <<
", col 4. Error Code: " <<
err;
212 thisscale.
bins.push_back(bin);
216 fScaleInfos[timestamp] = thisscale;
217 return fScaleInfos.at(timestamp);
223 ScaleInfo i = GetScaleInfo(e.time().timeHigh());
226 bool found_bin =
false;;
231 int itpc = cryo*2 + tpc/2;
233 double y = location.y();
234 double z = location.z();
237 if (itpc == b.
itpc &&
238 (y >= b.
ylo) && (y < b.
yhi) &&
239 (z >= b.
zlo) && (z < b.
zhi)) {
248 if (fVerbose)
std::cout <<
"NormalizeYZ Tool -- Data Cryo: " << cryo <<
" TPC: " << tpc <<
" iTPC: " << itpc <<
" Y: " << y <<
" Z: " << z <<
" scale: " << scale << std::endl;
double Normalize(double dQdx, const art::Event &e, const recob::Hit &h, const geo::Point_t &location, const geo::Vector_t &direction, double t0) override
process_name opflash particleana ie ie ie z
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
geo::WireID WireID() const
EResult err(const char *call)
CryostatID_t Cryostat
Index of cryostat.
INormalizeCharge interface class definiton.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
process_name can override from command line with o or output calo
std::map< uint64_t, ScaleInfo > fScaleInfos
process_name opflash particleana ie ie y
NormalizeYZ(fhicl::ParameterSet const &pset)
const ScaleInfo & GetScaleInfo(uint64_t timestamp)
std::vector< ScaleBin > bins
std::string to_string(WindowPattern const &pattern)
std::string URL(uint64_t timestamp)
2D representation of charge deposited in the TDC/wire plane
void configure(const fhicl::ParameterSet &pset) override
TPCID_t TPC
Index of the TPC within its cryostat.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
BEGIN_PROLOG could also be cout
This is an interface for an art Tool which scales charge by some factor given information about its a...