Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
calib::LifetimeCalibProtoDUNE Class Reference

#include <LifetimeCalibProtoDUNE.h>

Inheritance diagram for calib::LifetimeCalibProtoDUNE:
calib::LifetimeCalib

Public Member Functions

 LifetimeCalibProtoDUNE ()
 
 LifetimeCalibProtoDUNE (fhicl::ParameterSet const &pset)
 
 LifetimeCalibProtoDUNE (LifetimeCalibProtoDUNE const &)=delete
 
virtual ~LifetimeCalibProtoDUNE ()=default
 
bool Configure (fhicl::ParameterSet const &pset)
 
bool Update (uint64_t ts=0)
 
virtual double GetLifetime () override
 
virtual double GetLifetimeLow () override
 
virtual double GetLifetimeHigh () override
 
void SetIsMC (bool v)
 
void SetLifetime (double val)
 
void SetLifetimeLow (double val)
 
void SetLifetimeHigh (double val)
 
void SetUseCondb (bool v)
 
void SetLifetimeFileName (std::string f)
 
void SetInterpolate (bool v)
 
- Public Member Functions inherited from calib::LifetimeCalib
 LifetimeCalib (const LifetimeCalib &)=delete
 
 LifetimeCalib (LifetimeCalib &&)=delete
 
LifetimeCaliboperator= (const LifetimeCalib &)=delete
 
LifetimeCaliboperator= (LifetimeCalib &&)=delete
 
virtual ~LifetimeCalib ()=default
 

Protected Member Functions

bool LoadLifetime ()
 
- Protected Member Functions inherited from calib::LifetimeCalib
 LifetimeCalib ()=default
 

Protected Attributes

bool fUseCondbLifetime
 
bool fLifetimeLoaded
 
bool fIsMC
 
bool fInterpolate
 
uint64_t fCurrentTS
 
std::string fLifetimeFileName
 
std::string fLifetimeDBTag
 
std::map< int, LifetimePurMon_tfLifetimePurMon
 

Detailed Description

Definition at line 37 of file LifetimeCalibProtoDUNE.h.

Constructor & Destructor Documentation

calib::LifetimeCalibProtoDUNE::LifetimeCalibProtoDUNE ( )
calib::LifetimeCalibProtoDUNE::LifetimeCalibProtoDUNE ( fhicl::ParameterSet const &  pset)
calib::LifetimeCalibProtoDUNE::LifetimeCalibProtoDUNE ( LifetimeCalibProtoDUNE const &  )
delete
virtual calib::LifetimeCalibProtoDUNE::~LifetimeCalibProtoDUNE ( )
virtualdefault

Member Function Documentation

bool calib::LifetimeCalibProtoDUNE::Configure ( fhicl::ParameterSet const &  pset)

Definition at line 57 of file LifetimeCalibProtoDUNE.cxx.

58 {
59  fIsMC = pset.get<bool>("IsMC");
60  fUseCondbLifetime = pset.get<bool>("UseCondbLifetime");
61  fInterpolate = pset.get<bool>("Interpolate");
62  fLifetimeFileName = pset.get<std::string>("LifetimeFileName");
63  fLifetimeDBTag = pset.get<std::string>("LifetimeDBTag");
64  return true;
65 }
std::string string
Definition: nybbler.cc:12
double calib::LifetimeCalibProtoDUNE::GetLifetime ( )
overridevirtual

Implements calib::LifetimeCalib.

Definition at line 83 of file LifetimeCalibProtoDUNE.cxx.

84 {
85  if (!fLifetimeLoaded) this->LoadLifetime();
86 
87  if (fLifetimePurMon.find(1) == fLifetimePurMon.end()) {
88  mf::LogError("LifetimeCalibProtoDUNE") << "channel not found!";
89  return 0.;
90  }
91 
92  return fLifetimePurMon[1].center;
93 }
std::map< int, LifetimePurMon_t > fLifetimePurMon
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double calib::LifetimeCalibProtoDUNE::GetLifetimeHigh ( )
overridevirtual

Implements calib::LifetimeCalib.

Definition at line 96 of file LifetimeCalibProtoDUNE.cxx.

97 {
98  if (!fLifetimeLoaded) this->LoadLifetime();
99 
100  if (fLifetimePurMon.find(1) == fLifetimePurMon.end()) {
101  mf::LogError("LifetimeCalibProtoDUNE") << "channel not found!";
102  return 0.;
103  }
104 
105  return fLifetimePurMon[1].high;
106 }
std::map< int, LifetimePurMon_t > fLifetimePurMon
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double calib::LifetimeCalibProtoDUNE::GetLifetimeLow ( )
overridevirtual

Implements calib::LifetimeCalib.

Definition at line 109 of file LifetimeCalibProtoDUNE.cxx.

110 {
111  if (!fLifetimeLoaded) this->LoadLifetime();
112 
113  if (fLifetimePurMon.find(1) == fLifetimePurMon.end()) {
114  mf::LogError("LifetimeCalibProtoDUNE") << "channel not found!";
115  return 0.;
116  }
117 
118  return fLifetimePurMon[1].low;
119 }
std::map< int, LifetimePurMon_t > fLifetimePurMon
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool calib::LifetimeCalibProtoDUNE::LoadLifetime ( )
protected

Definition at line 122 of file LifetimeCalibProtoDUNE.cxx.

123 {
124  if (!fUseCondbLifetime) return true;
125 
126  if (fLifetimeLoaded) return true;
127 
128  nutools::dbi::Table LifetimePurMonTable;
129  LifetimePurMonTable.SetDetector("pdunesp");
130  LifetimePurMonTable.SetTableName("lifetime_purmon");
131  LifetimePurMonTable.SetTableType(nutools::dbi::kConditionsTable);
132  LifetimePurMonTable.SetDataTypeMask(nutools::dbi::kDataOnly);
133  if (fIsMC) LifetimePurMonTable.SetDataTypeMask(nutools::dbi::kMCOnly);
134 
135  int centerIdx = LifetimePurMonTable.AddCol("center", "double");
136  int lowIdx = LifetimePurMonTable.AddCol("low", "double");
137  int highIdx = LifetimePurMonTable.AddCol("high", "double");
138 
139  if (!fInterpolate) {
140  LifetimePurMonTable.SetMinTSVld(fCurrentTS); // only load one previous lifetime
141  LifetimePurMonTable.SetMaxTSVld(fCurrentTS);
142  }
143  else {
144  // load lifetime IOV: runtime +- 1 days for interpolation
145  LifetimePurMonTable.SetMinTSVld(fCurrentTS-1*86400.);
146  LifetimePurMonTable.SetMaxTSVld(fCurrentTS+1*86400.);
147  }
148  LifetimePurMonTable.SetTag(fLifetimeDBTag);
149 
150  LifetimePurMonTable.SetVerbosity(100);
151 
152  bool readOk = false;
153  if (!fLifetimeFileName.empty())
154  readOk = LifetimePurMonTable.LoadFromCSV(fLifetimeFileName);
155  else
156  readOk = LifetimePurMonTable.Load();
157 
158  if (! readOk) {
159  mf::LogError("LifetimeCalibProtoDUNE") << "Load from lifetime calib database table failed.";
160  throw cet::exception("LifetimeCalibProtoDUNE") << "Failed to query lifetime database. Please check URL: https://dbdata0vm.fnal.gov:9443/dune_con_prod/app" << "\n";
161 
162  return false; //std::abort();
163  }
164 
165  if (LifetimePurMonTable.NRow() == 0) {
166  mf::LogError("LifetimeCalibProtoDUNE") << "Number of rows in lifetime calib table is 0. This should never be the case!";
167  return false;
168  }
169 
170  std::vector<double> loaded_tv;
171  std::vector<double> loaded_center;
172  std::vector<double> loaded_low;
173  std::vector<double> loaded_high;
174  loaded_tv.clear();
175  loaded_center.clear();
176  loaded_low.clear();
177  loaded_high.clear();
178 
179  if (LifetimePurMonTable.NRow() == 1) fInterpolate = false;
180 
181  nutools::dbi::Row* row;
182  uint64_t chan;
183 
184  for (int i=0; i<LifetimePurMonTable.NRow(); ++i) {
185 
186  LifetimePurMon_t lifetime;
187  row = LifetimePurMonTable.GetRow(i);
188  chan = row->Channel(); // One channel only, start with 1
189 
190  if (chan != 1) {
191  mf::LogError("LifetimeCalibProtoDUNE") << "Channel numuber in lifetime calib table is not 1. This should never be the case!";
192  return false;
193  }
194 
195  row->Col(centerIdx).Get(lifetime.center);
196  row->Col(lowIdx).Get(lifetime.low);
197  row->Col(highIdx).Get(lifetime.high);
198 
199  loaded_tv.push_back(row->VldTime());
200  loaded_center.push_back(lifetime.center);
201  loaded_low.push_back(lifetime.low);
202  loaded_high.push_back(lifetime.high);
203 
204  if (!fInterpolate) fLifetimePurMon[chan] = lifetime;
205  }
206 
207  if (fInterpolate && loaded_tv.size()>1) {
208 
209  LifetimePurMon_t interpolate_lifetime;
210 
211  // find the previous and following lifetime for fCurrentTS
212  int t0_idx = -1;
213  int t1_idx = -1;
214  double temp_0 = 1e10;
215  double temp_1 = 1e10;
216  for (size_t j=0; j<loaded_tv.size(); j++) {
217  if ( fCurrentTS - loaded_tv[j] >= 0 && fCurrentTS - loaded_tv[j] < temp_0 ) {
218  temp_0 = fCurrentTS- loaded_tv[j];
219  t0_idx = j;
220  }
221 
222  if ( loaded_tv[j]-fCurrentTS >= 0 && loaded_tv[j]-fCurrentTS < temp_1 ) {
223  temp_1 = loaded_tv[j]-fCurrentTS;
224  t1_idx = j;
225  }
226  }
227 
228  if (t0_idx == -1) { // only lifetime measurement after fCurrentTS during selected IOV
229  // use the following one only
230  interpolate_lifetime.center = loaded_center[t1_idx];
231  interpolate_lifetime.low = loaded_low[t1_idx];
232  interpolate_lifetime.high = loaded_high[t1_idx];
233  }
234  if (t1_idx == -1) { // only lifetime measurement before fCurrentTS during selected IOV
235  // use the previous one only
236  interpolate_lifetime.center = loaded_center[t0_idx];
237  interpolate_lifetime.low = loaded_low[t0_idx];
238  interpolate_lifetime.high = loaded_high[t0_idx];
239  }
240  if (t0_idx != -1 && t1_idx != -1) {
241  if (t0_idx == t1_idx) { // ideally, this is not possible
242  interpolate_lifetime.center = loaded_center[t0_idx];
243  interpolate_lifetime.low = loaded_low[t0_idx];
244  interpolate_lifetime.high = loaded_high[t0_idx];
245  }
246  else {
247  // do linear interpolation using previous one and following one
248  // refer: https://en.wikipedia.org/wiki/Linear_interpolation
249  interpolate_lifetime.center = ( loaded_center[t0_idx]*(loaded_tv[t1_idx]-fCurrentTS) + loaded_center[t1_idx]*(fCurrentTS-loaded_tv[t0_idx]) ) / (loaded_tv[t1_idx]-loaded_tv[t0_idx]);
250  interpolate_lifetime.low = ( loaded_low[t0_idx]*(loaded_tv[t1_idx]-fCurrentTS) + loaded_low[t1_idx]*(fCurrentTS-loaded_tv[t0_idx]) ) / (loaded_tv[t1_idx]-loaded_tv[t0_idx]);
251  interpolate_lifetime.high = ( loaded_high[t0_idx]*(loaded_tv[t1_idx]-fCurrentTS) + loaded_high[t1_idx]*(fCurrentTS-loaded_tv[t0_idx]) ) / (loaded_tv[t1_idx]-loaded_tv[t0_idx]);
252  }
253  }
254 
255  fLifetimePurMon[chan] = interpolate_lifetime;
256  } // end if fInterpolate
257 
258  fLifetimeLoaded = true;
259  return true;
260 }
std::map< int, LifetimePurMon_t > fLifetimePurMon
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void calib::LifetimeCalibProtoDUNE::SetInterpolate ( bool  v)
inline

Definition at line 59 of file LifetimeCalibProtoDUNE.h.

void calib::LifetimeCalibProtoDUNE::SetIsMC ( bool  v)
inline

Definition at line 53 of file LifetimeCalibProtoDUNE.h.

void calib::LifetimeCalibProtoDUNE::SetLifetime ( double  val)
void calib::LifetimeCalibProtoDUNE::SetLifetimeFileName ( std::string  f)
inline
void calib::LifetimeCalibProtoDUNE::SetLifetimeHigh ( double  val)
void calib::LifetimeCalibProtoDUNE::SetLifetimeLow ( double  val)
void calib::LifetimeCalibProtoDUNE::SetUseCondb ( bool  v)
inline

Definition at line 57 of file LifetimeCalibProtoDUNE.h.

bool calib::LifetimeCalibProtoDUNE::Update ( uint64_t  ts = 0)

Definition at line 68 of file LifetimeCalibProtoDUNE.cxx.

69 {
70 
71  if (fLifetimeLoaded && ts != fCurrentTS) {
72  fLifetimePurMon.clear();
73  fLifetimeLoaded = false;
74  }
75 
76  fCurrentTS = ts;
77  // all done!
78 
79  return true;
80 }
std::map< int, LifetimePurMon_t > fLifetimePurMon

Member Data Documentation

uint64_t calib::LifetimeCalibProtoDUNE::fCurrentTS
protected

Definition at line 68 of file LifetimeCalibProtoDUNE.h.

bool calib::LifetimeCalibProtoDUNE::fInterpolate
protected

Definition at line 67 of file LifetimeCalibProtoDUNE.h.

bool calib::LifetimeCalibProtoDUNE::fIsMC
protected

Definition at line 66 of file LifetimeCalibProtoDUNE.h.

std::string calib::LifetimeCalibProtoDUNE::fLifetimeDBTag
protected

Definition at line 71 of file LifetimeCalibProtoDUNE.h.

std::string calib::LifetimeCalibProtoDUNE::fLifetimeFileName
protected

Definition at line 70 of file LifetimeCalibProtoDUNE.h.

bool calib::LifetimeCalibProtoDUNE::fLifetimeLoaded
protected

Definition at line 65 of file LifetimeCalibProtoDUNE.h.

std::map<int,LifetimePurMon_t> calib::LifetimeCalibProtoDUNE::fLifetimePurMon
protected

Definition at line 73 of file LifetimeCalibProtoDUNE.h.

bool calib::LifetimeCalibProtoDUNE::fUseCondbLifetime
protected

Definition at line 64 of file LifetimeCalibProtoDUNE.h.


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