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

Classes

class  RunInfo
 

Public Member Functions

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

RunInfo GetRunInfo (uint32_t run)
 
std::string URL (uint32_t run)
 

Private Attributes

int fTimeout
 
std::string fURL
 
bool fVerbose
 
std::map< uint32_t, RunInfofRunInfos
 

Detailed Description

Definition at line 27 of file NormalizeDrift_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 64 of file NormalizeDrift_tool.cc.

64  {
65  this->configure(pset);
66 }
void configure(const fhicl::ParameterSet &pset) override

Member Function Documentation

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

Implements INormalizeCharge.

Definition at line 68 of file NormalizeDrift_tool.cc.

68  {
69  fURL = pset.get<std::string>("URL");
70  fTimeout = pset.get<unsigned>("Timeout");
71  fVerbose = pset.get<bool>("Verbose", false);
72 }
icarus::calo::NormalizeDrift::RunInfo icarus::calo::NormalizeDrift::GetRunInfo ( uint32_t  run)
private

Definition at line 78 of file NormalizeDrift_tool.cc.

78  {
79  // check the cache
80  if (fRunInfos.count(run)) {
81  return fRunInfos.at(run);
82  }
83 
84  // Otherwise, look it up
85  int error = 0;
86  std::string url = URL(run);
87 
88  if (fVerbose) std::cout << "NormalizeDrift Tool -- New Run info, requesting data from url:\n" << url << std::endl;
89 
90  Dataset d = getDataWithTimeout(url.c_str(), "", fTimeout, &error);
91 
92  if (error) {
93  throw cet::exception("NormalizeDrift") << "Calibration Database access failed. URL: (" << url << ") Error Code: " << error;
94  }
95 
96  if (fVerbose) std::cout << "NormalizeDrift Tool -- Received HTTP response:\n" << getHTTPmessage(d) << std::endl;
97 
98  if (getHTTPstatus(d) != 200) {
99  throw cet::exception("NormalizeDrift")
100  << "Calibration Database access failed. URL: (" << url
101  << "). HTTP error status: " << getHTTPstatus(d) << ". HTTP error message: " << getHTTPmessage(d);
102  }
103 
104 
105  // Check all the TPC's are set
106  std::vector<bool> tpc_set(4, false);
107  RunInfo thisrun;
108 
109  // Iterate over the rows
110  // Should be 4: one for each TPC
111  // The first 4 rows are metadata
112  for (unsigned row = 4; row < 8; row++) {
113  Tuple tup = getTuple(d, row);
114 
115  int err = 0;
116  // Get the channel number
117  int ch = getLongValue(tup, 0, &err);
118  if (error) {
119  throw cet::exception("NormalizeDrift") << "Calibration Database access failed. URL: (" << url << ") Failed on tuple access, row: " << row << ", col 0. Error Code: " << error;
120  }
121 
122  // .. and the purity
123  double tau = getDoubleValue(tup, 1, &err);
124  if (error) {
125  throw cet::exception("NormalizeDrift") << "Calibration Database access failed. URL: (" << url << ") Failed on tuple access, row: " << row << ", col 1. Error Code: " << error;
126  }
127 
128  // Check the channel number
129  if (ch < 0 || ch > 3) {
130  throw cet::exception("NormalizeDrift") << "Calibration Database access failed. URL: (" << url << ") Bad channel number: " << ch;
131  }
132 
133  tpc_set.at(ch) = true;
134 
135  // Map channel to TPC
136  if (ch == 0) thisrun.tau_EE = tau;
137  if (ch == 1) thisrun.tau_EW = tau;
138  if (ch == 2) thisrun.tau_WE = tau;
139  if (ch == 3) thisrun.tau_WW = tau;
140  }
141 
142  if (fVerbose) std::cout << "NormalizeDrift Tool -- Lifetime Data:" << "\nTPC EE: " << thisrun.tau_EE << "\nTPC EW: " << thisrun.tau_EW << "\nTPC WE: " << thisrun.tau_WE << "\nTPC WW: " << thisrun.tau_WW << std::endl;
143 
144  // Make sure all the channels are set
145  for (unsigned tpc = 0; tpc < 4; tpc++) {
146  if (!tpc_set[tpc]) {
147  throw cet::exception("NormalizeDrift") << "Calibration Database access failed. URL: (" << url << ") TPC not set: " << tpc;
148  }
149  }
150 
151  // Set the cache
152  fRunInfos[run] = thisrun;
153 
154  return thisrun;
155 }
EResult err(const char *call)
void * Tuple
Definition: DBFolder.h:13
std::string URL(uint32_t run)
std::map< uint32_t, RunInfo > fRunInfos
void * Dataset
Definition: DBFolder.h:12
BEGIN_PROLOG could also be cout
double icarus::calo::NormalizeDrift::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 157 of file NormalizeDrift_tool.cc.

158  {
159  // Services
160  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
161 
162  // Get the info
163  RunInfo runelifetime = GetRunInfo(e.id().runID().run());
164 
165  // lookup the TPC
166  double thiselifetime = -1;
167  unsigned tpc = hit.WireID().TPC;
168  unsigned cryo = hit.WireID().Cryostat;
169 
170  // EE
171  if (cryo == 0 && (tpc == 0 || tpc == 1)) thiselifetime = runelifetime.tau_EE;
172  // EW
173  if (cryo == 0 && (tpc == 2 || tpc == 3)) thiselifetime = runelifetime.tau_EW;
174  // WE
175  if (cryo == 1 && (tpc == 0 || tpc == 1)) thiselifetime = runelifetime.tau_WE;
176  // WW
177  if (cryo == 1 && (tpc == 2 || tpc == 3)) thiselifetime = runelifetime.tau_WW;
178 
179  // Get the hit time
180  double thit = clock_data.TPCTick2TrigTime(hit.PeakTime()) - t0;
181 
182  if (fVerbose) std::cout << "NormalizeDrift Tool -- Norm factor: " << exp(thit / thiselifetime) << " at TPC: " << tpc << " Cryo: " << cryo << " Time: " << thit << " Track T0: " << t0 << std::endl;
183 
184  // Scale
185  if (thiselifetime > 0) {
186  dQdx = dQdx*exp(thit / thiselifetime);
187  }
188  // TODO: what to do if no lifetime is found? throw an exception??
189  else {}
190 
191  return dQdx;
192 }
RunInfo GetRunInfo(uint32_t run)
process_name hit
Definition: cheaterreco.fcl:51
do i e
BEGIN_PROLOG could also be cout
std::string icarus::calo::NormalizeDrift::URL ( uint32_t  run)
private

Definition at line 74 of file NormalizeDrift_tool.cc.

74  {
75  return fURL + std::to_string(run);
76 }
std::string to_string(WindowPattern const &pattern)

Member Data Documentation

std::map<uint32_t, RunInfo> icarus::calo::NormalizeDrift::fRunInfos
private

Definition at line 55 of file NormalizeDrift_tool.cc.

int icarus::calo::NormalizeDrift::fTimeout
private

Definition at line 37 of file NormalizeDrift_tool.cc.

std::string icarus::calo::NormalizeDrift::fURL
private

Definition at line 38 of file NormalizeDrift_tool.cc.

bool icarus::calo::NormalizeDrift::fVerbose
private

Definition at line 39 of file NormalizeDrift_tool.cc.


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