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::NormalizeWire Class Reference
Inheritance diagram for icarus::calo::NormalizeWire:
INormalizeCharge

Classes

class  ScaleInfo
 

Public Member Functions

 NormalizeWire (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

ScaleInfo GetScaleInfo (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 NormalizeWire_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 61 of file NormalizeWire_tool.cc.

61  {
62  this->configure(pset);
63 }
void configure(const fhicl::ParameterSet &pset) override

Member Function Documentation

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

Implements INormalizeCharge.

Definition at line 65 of file NormalizeWire_tool.cc.

65  {
66  fURL = pset.get<std::string>("URL");
67  fTimeout = pset.get<unsigned>("Timeout");
68  fVerbose = pset.get<bool>("Verbose", false);
69 }
icarus::calo::NormalizeWire::ScaleInfo icarus::calo::NormalizeWire::GetScaleInfo ( uint64_t  timestamp)
private

Definition at line 75 of file NormalizeWire_tool.cc.

75  {
76  // check the cache
77  if (fScaleInfos.count(timestamp)) {
78  return fScaleInfos.at(timestamp);
79  }
80 
81  // Otherwise, look it up
82  int error = 0;
83  std::string url = URL(timestamp);
84 
85  if (fVerbose) std::cout << "NormalizeWire Tool -- New Scale info, requesting data from url:\n" << url << std::endl;
86 
87  Dataset d = getDataWithTimeout(url.c_str(), "", fTimeout, &error);
88  if (error) {
89  throw cet::exception("NormalizeWire") << "Calibration Database access failed. URL: (" << url << ") Error Code: " << error;
90  }
91 
92  if (fVerbose) std::cout << "NormalizeWire Tool -- Received HTTP response:\n" << getHTTPmessage(d) << std::endl;
93 
94  if (getHTTPstatus(d) != 200) {
95  throw cet::exception("NormalizeWire")
96  << "Calibration Database access failed. URL: (" << url
97  << "). HTTP error status: " << getHTTPstatus(d) << ". HTTP error message: " << getHTTPmessage(d);
98  }
99 
100  // Collect the timestamp info
101  ScaleInfo thisscale;
102 
103  // Number of rows
104  int n_tuple = getNtuples(d);
105  if (n_tuple < 0) {
106  throw cet::exception("NormalizeWire") << "Calibration Database access failed. URL: (" << url << ") Bad Tuple Number: " << n_tuple;
107  }
108 
109  // Iterate over the rows
110  // The first 4 are metadata
111  for (unsigned row = 4; row < (unsigned)n_tuple; row++) {
112  Tuple tup = getTuple(d, row);
113 
114  int err = 0;
115  // Get the channel number
116  int ch = getLongValue(tup, 0, &err);
117  if (error) {
118  throw cet::exception("NormalizeWire") << "Calibration Database access failed. URL: (" << url << ") Failed on tuple access, row: " << row << ", col 0. Error Code: " << error;
119  }
120 
121  // and the scale
122  double scale = getDoubleValue(tup, 1, &err);
123  if (error) {
124  throw cet::exception("NormalizeWire") << "Calibration Database access failed. URL: (" << url << ") Failed on tuple access, row: " << row << ", col 1. Error Code: " << error;
125  }
126 
127  thisscale.scale[ch] = scale;
128  }
129 
130  // Set the cache
131  fScaleInfos[timestamp] = thisscale;
132 
133  return thisscale;
134 }
std::map< uint64_t, ScaleInfo > fScaleInfos
EResult err(const char *call)
void * Tuple
Definition: DBFolder.h:13
std::string URL(uint64_t timestamp)
void * Dataset
Definition: DBFolder.h:12
BEGIN_PROLOG could also be cout
double icarus::calo::NormalizeWire::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 136 of file NormalizeWire_tool.cc.

137  {
138  // Get the info
139  ScaleInfo i = GetScaleInfo(e.time().timeHigh());
140 
141  // Lookup the channel
142  unsigned channel = hit.Channel();
143 
144  double scale = 1;
145 
146  // TODO: what to do if no lifetime is found? throw an exception??
147  if (i.scale.count(channel)) scale = i.scale.at(channel);
148 
149  if (fVerbose) std::cout << "NormalizeWire Tool -- Data at channel: " << channel << " scale: " << scale << std::endl;
150 
151  return dQdx / scale;
152 }
ScaleInfo GetScaleInfo(uint64_t timestamp)
process_name hit
Definition: cheaterreco.fcl:51
do i e
BEGIN_PROLOG could also be cout
std::string icarus::calo::NormalizeWire::URL ( uint64_t  timestamp)
private

Definition at line 71 of file NormalizeWire_tool.cc.

71  {
72  return fURL + std::to_string(timestamp);
73 }
std::string to_string(WindowPattern const &pattern)

Member Data Documentation

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

Definition at line 52 of file NormalizeWire_tool.cc.

int icarus::calo::NormalizeWire::fTimeout
private

Definition at line 37 of file NormalizeWire_tool.cc.

std::string icarus::calo::NormalizeWire::fURL
private

Definition at line 38 of file NormalizeWire_tool.cc.

bool icarus::calo::NormalizeWire::fVerbose
private

Definition at line 39 of file NormalizeWire_tool.cc.


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