All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
icarus::calo::NormalizeYZ Class Reference
Inheritance diagram for icarus::calo::NormalizeYZ:
INormalizeCharge

Classes

class  ScaleInfo
 

Public Member Functions

 NormalizeYZ (fhicl::ParameterSet const &pset)
 
void configure (const fhicl::ParameterSet &pset) override
 
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
 
- Public Member Functions inherited from INormalizeCharge
virtual ~INormalizeCharge () noexcept=default
 Virtual Destructor. More...
 

Private Member Functions

const ScaleInfoGetScaleInfo (uint64_t timestamp)
 
std::string URL (uint64_t timestamp)
 

Private Attributes

int fTimeout
 
std::string fURL
 
bool fVerbose
 
std::map< uint64_t, ScaleInfofScaleInfos
 

Detailed Description

Definition at line 27 of file NormalizeYZ_tool.cc.

Constructor & Destructor Documentation

icarus::calo::NormalizeYZ::NormalizeYZ ( fhicl::ParameterSet const &  pset)

Definition at line 73 of file NormalizeYZ_tool.cc.

73  {
74  this->configure(pset);
75 }
void configure(const fhicl::ParameterSet &pset) override

Member Function Documentation

void icarus::calo::NormalizeYZ::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements INormalizeCharge.

Definition at line 77 of file NormalizeYZ_tool.cc.

77  {
78  fURL = pset.get<std::string>("URL");
79  fTimeout = pset.get<unsigned>("Timeout");
80  fVerbose = pset.get<bool>("Verbose", false);
81 }
const icarus::calo::NormalizeYZ::ScaleInfo & icarus::calo::NormalizeYZ::GetScaleInfo ( uint64_t  timestamp)
private

Definition at line 87 of file NormalizeYZ_tool.cc.

87  {
88  // check the cache
89  if (fScaleInfos.count(timestamp)) {
90  return fScaleInfos.at(timestamp);
91  }
92 
93  // Otherwise, look it up
94  int error = 0;
95  std::string url = URL(timestamp);
96 
97  if (fVerbose) std::cout << "NormalizeYZ Tool -- New Scale info, requesting data from url:\n" << url << std::endl;
98 
99  Dataset d = getDataWithTimeout(url.c_str(), "", fTimeout, &error);
100  if (error) {
101  throw cet::exception("NormalizeYZ") << "Calibration Database access failed. URL: (" << url << ") Error Code: " << error;
102  }
103 
104  if (fVerbose) std::cout << "NormalizeYZ Tool -- Received HTTP response:\n" << getHTTPmessage(d) << std::endl;
105 
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);
110  }
111 
112  // Collect the timestamp info
113  ScaleInfo thisscale;
114 
115  // Get the First row to get tzero
116  error = 0;
117  Tuple tup = getTuple(d, 0);
118  float tzero = getDoubleValue(tup, 0, &error);
119  if (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;
123  }
124 
125  if (fVerbose) std::cout << "NormalizeYZ Tool -- Obtained T0: " << tzero << std::endl;
126 
127  // Check if we've seen this t0 before
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) {
132  thisscale = scale;
133  found_scale_t0 = true;
134 
135  if (fVerbose) std::cout << "NormalizeYZ Tool -- Found prior matching T0 from timestamp: " << scale_pair.first << std::endl;
136 
137  break;
138  }
139  }
140 
141  if (found_scale_t0) {
142  fScaleInfos[timestamp] = thisscale;
143  return fScaleInfos.at(timestamp);
144  }
145 
146  // We haven't seen this timestamp before and we haven't seen the valid t0 before.
147  //
148  // Process the HTTP response
149  thisscale.tzero = tzero;
150 
151  // Number of rows
152  int n_tuple = getNtuples(d);
153  if (n_tuple < 0) {
154  throw cet::exception("NormalizeYZ") << "NormalizeYZ Tool -- Calibration Database access failed. URL: (" << url << ") Bad Tuple Number: " << n_tuple;
155  }
156 
157  // Iterate over the rows
158  // The first 4 are metadata
159  for (unsigned row = 4; row < (unsigned)n_tuple; row++) {
160  Tuple tup = getTuple(d, row);
161 
162  int err = 0;
163  // Get the TPC value
164  char tpcbuf[10];
165  int strl = getStringValue(tup, 1, tpcbuf, 10, &err);
166  (void) strl;
167  if (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;
169  }
170  int itpc = -1;
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;
176  else {
177  throw cet::exception("NormalizeYZ") << "NormalizeYZ Tool -- Bad TPC name (" << tpcname << ").";
178  }
179 
180  // Get the bin limits
181  double ylo = getDoubleValue(tup, 8, &err);
182  if (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;
184  }
185  double yhi = getDoubleValue(tup, 9, &err);
186  if (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;
188  }
189  double zlo = getDoubleValue(tup, 10, &err);
190  if (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;
192  }
193  double zhi = getDoubleValue(tup, 11, &err);
194  if (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;
196  }
197 
198  // Get the scale
199  double scale = getDoubleValue(tup, 4, &err);
200  if (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;
202  }
203 
204  ScaleInfo::ScaleBin bin;
205  bin.ylo = ylo;
206  bin.yhi = yhi;
207  bin.zlo = zlo;
208  bin.zhi = zhi;
209  bin.itpc = itpc;
210  bin.scale = scale;
211 
212  thisscale.bins.push_back(bin);
213  }
214 
215  // Set the cache
216  fScaleInfos[timestamp] = thisscale;
217  return fScaleInfos.at(timestamp);
218 }
EResult err(const char *call)
void * Tuple
Definition: DBFolder.h:13
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::map< uint64_t, ScaleInfo > fScaleInfos
j template void())
Definition: json.hpp:3108
void * Dataset
Definition: DBFolder.h:12
std::string URL(uint64_t timestamp)
BEGIN_PROLOG could also be cout
double icarus::calo::NormalizeYZ::Normalize ( double  dQdx,
const art::Event &  e,
const recob::Hit h,
const geo::Point_t location,
const geo::Vector_t direction,
double  t0 
)
overridevirtual

Implements INormalizeCharge.

Definition at line 220 of file NormalizeYZ_tool.cc.

221  {
222  // Get the info
223  ScaleInfo i = GetScaleInfo(e.time().timeHigh());
224 
225  double scale = 1;
226  bool found_bin = false;;
227 
228  // compute itpc
229  int cryo = hit.WireID().Cryostat;
230  int tpc = hit.WireID().TPC;
231  int itpc = cryo*2 + tpc/2;
232  // position
233  double y = location.y();
234  double z = location.z();
235 
236  for (const ScaleInfo::ScaleBin &b: i.bins) {
237  if (itpc == b.itpc &&
238  (y >= b.ylo) && (y < b.yhi) &&
239  (z >= b.zlo) && (z < b.zhi)) {
240  found_bin = true;
241  scale = b.scale;
242  break;
243  }
244  }
245  // TODO: what to do if no lifetime is found? throw an exception??
246  (void) found_bin;
247 
248  if (fVerbose) std::cout << "NormalizeYZ Tool -- Data Cryo: " << cryo << " TPC: " << tpc << " iTPC: " << itpc << " Y: " << y << " Z: " << z << " scale: " << scale << std::endl;
249 
250  return dQdx / scale;
251 }
process_name opflash particleana ie ie ie z
process_name hit
Definition: cheaterreco.fcl:51
process_name opflash particleana ie ie y
const ScaleInfo & GetScaleInfo(uint64_t timestamp)
j template void())
Definition: json.hpp:3108
do i e
BEGIN_PROLOG could also be cout
std::string icarus::calo::NormalizeYZ::URL ( uint64_t  timestamp)
private

Definition at line 83 of file NormalizeYZ_tool.cc.

83  {
84  return fURL + std::to_string(timestamp);
85 }
std::string to_string(WindowPattern const &pattern)

Member Data Documentation

std::map<uint64_t, ScaleInfo> icarus::calo::NormalizeYZ::fScaleInfos
private

Definition at line 64 of file NormalizeYZ_tool.cc.

int icarus::calo::NormalizeYZ::fTimeout
private

Definition at line 37 of file NormalizeYZ_tool.cc.

std::string icarus::calo::NormalizeYZ::fURL
private

Definition at line 38 of file NormalizeYZ_tool.cc.

bool icarus::calo::NormalizeYZ::fVerbose
private

Definition at line 39 of file NormalizeYZ_tool.cc.


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