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

Classes

class  ScaleInfo
 

Public Member Functions

 NormalizeTPC (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 NormalizeTPC_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 61 of file NormalizeTPC_tool.cc.

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

Member Function Documentation

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

Implements INormalizeCharge.

Definition at line 65 of file NormalizeTPC_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::NormalizeTPC::ScaleInfo icarus::calo::NormalizeTPC::GetScaleInfo ( uint64_t  timestamp)
private

Definition at line 75 of file NormalizeTPC_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 << "NormalizeTPC 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("NormalizeTPC") << "Calibration Database access failed. URL: (" << url << ") Error Code: " << error;
90  }
91 
92  if (fVerbose) std::cout << "NormalizeTPC Tool -- Received HTTP response:\n" << getHTTPmessage(d) << std::endl;
93 
94  if (getHTTPstatus(d) != 200) {
95  throw cet::exception("NormalizeTPC")
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("NormalizeTPC") << "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 itpc number
116  int ch = getLongValue(tup, 0, &err);
117  if (error) {
118  throw cet::exception("NormalizeTPC") << "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, 2, &err);
123  if (error) {
124  throw cet::exception("NormalizeTPC") << "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
void * Dataset
Definition: DBFolder.h:12
std::string URL(uint64_t timestamp)
BEGIN_PROLOG could also be cout
double icarus::calo::NormalizeTPC::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 NormalizeTPC_tool.cc.

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

Definition at line 71 of file NormalizeTPC_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::NormalizeTPC::fScaleInfos
private

Definition at line 52 of file NormalizeTPC_tool.cc.

int icarus::calo::NormalizeTPC::fTimeout
private

Definition at line 37 of file NormalizeTPC_tool.cc.

std::string icarus::calo::NormalizeTPC::fURL
private

Definition at line 38 of file NormalizeTPC_tool.cc.

bool icarus::calo::NormalizeTPC::fVerbose
private

Definition at line 39 of file NormalizeTPC_tool.cc.


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