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

#include <XYZCalibProtoDUNE.h>

Inheritance diagram for calib::XYZCalibProtoDUNE:
calib::XYZCalib

Public Member Functions

 XYZCalibProtoDUNE ()
 
 XYZCalibProtoDUNE (fhicl::ParameterSet const &pset)
 
 XYZCalibProtoDUNE (XYZCalibProtoDUNE const &)=delete
 
virtual ~XYZCalibProtoDUNE ()=default
 
bool Configure (fhicl::ParameterSet const &pset)
 
bool Update (uint64_t ts=0)
 
virtual double GetNormCorr (int plane) override
 
virtual double GetXCorr (int plane, double x) override
 
virtual double GetYZCorr (int plane, int side, double y, double z) override
 
void SetIsMC (bool v)
 
void SetNormCorr (int plane, double val)
 
void SetXCorr (int plane, double x, double dx, double val)
 
void SetYZCorr (int plane, int side, double y, double dx, double val)
 
void SetUseCondb (bool v)
 
void SetXCorrFileName (std::string f)
 
void SetYZCorrFileName (std::string f)
 
void SetNormCorrFileName (std::string f)
 
void SetInterpolate (bool v)
 
- Public Member Functions inherited from calib::XYZCalib
 XYZCalib (const XYZCalib &)=delete
 
 XYZCalib (XYZCalib &&)=delete
 
XYZCaliboperator= (const XYZCalib &)=delete
 
XYZCaliboperator= (XYZCalib &&)=delete
 
virtual ~XYZCalib ()=default
 

Protected Member Functions

bool LoadNormCorr ()
 
bool LoadXCorr ()
 
bool LoadYZCorr ()
 
- Protected Member Functions inherited from calib::XYZCalib
 XYZCalib ()=default
 

Protected Attributes

bool fUseCondbXYZCorr
 
bool fNormCorrLoaded
 
bool fXCorrLoaded
 
bool fYZCorrLoaded
 
bool fIsMC
 
bool fInterpolate
 
uint64_t fCurrentTS
 
std::string fXCorrFileName
 
std::string fYZCorrFileName
 
std::string fNormCorrFileName
 
std::string fXCorrDBTag
 
std::string fYZCorrDBTag
 
std::string fNormCorrDBTag
 
std::map< int, NormCorr_tfNormCorr
 
std::map< int, TH1F > fXCorrHist
 
std::map< int, TH2F > fYZCorrHist
 

Detailed Description

Definition at line 64 of file XYZCalibProtoDUNE.h.

Constructor & Destructor Documentation

calib::XYZCalibProtoDUNE::XYZCalibProtoDUNE ( )

Definition at line 29 of file XYZCalibProtoDUNE.cxx.

calib::XYZCalibProtoDUNE::XYZCalibProtoDUNE ( fhicl::ParameterSet const &  pset)

Definition at line 48 of file XYZCalibProtoDUNE.cxx.

51 {
52  fIsMC = true;
53  fYZCorrLoaded = false;
54  fXCorrLoaded = false;
55  fNormCorrLoaded = false;
56  fInterpolate = false;
57  fCurrentTS = 0;
58  fXCorrFileName="";
59  fYZCorrFileName="";
61  fXCorrDBTag="";
62  fYZCorrDBTag="";
63  fNormCorrDBTag="";
64  Configure(pset);
65 }
bool Configure(fhicl::ParameterSet const &pset)
calib::XYZCalibProtoDUNE::XYZCalibProtoDUNE ( XYZCalibProtoDUNE const &  )
delete
virtual calib::XYZCalibProtoDUNE::~XYZCalibProtoDUNE ( )
virtualdefault

Member Function Documentation

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

Definition at line 68 of file XYZCalibProtoDUNE.cxx.

69 {
70  fIsMC = pset.get<bool>("IsMC");
71  fUseCondbXYZCorr = pset.get<bool>("UseCondbXYZCorr");
72  fInterpolate = pset.get<bool>("Interpolate");
73  fXCorrFileName = pset.get<std::string>("XCorrFileName");
74  fYZCorrFileName = pset.get<std::string>("YZCorrFileName");
75  fNormCorrFileName= pset.get<std::string>("NormCorrFileName");
76  fXCorrDBTag = pset.get<std::string>("XCorrDBTag");
77  fYZCorrDBTag = pset.get<std::string>("YZCorrDBTag");
78  fNormCorrDBTag = pset.get<std::string>("NormCorrDBTag");
79  return true;
80 }
std::string string
Definition: nybbler.cc:12
double calib::XYZCalibProtoDUNE::GetNormCorr ( int  plane)
overridevirtual

Implements calib::XYZCalib.

Definition at line 108 of file XYZCalibProtoDUNE.cxx.

109 {
110  if (!fNormCorrLoaded) this->LoadNormCorr();
111 
112  if (fNormCorr.find(chanId) == fNormCorr.end()) {
113  mf::LogError("XYZCalibProtoDUNE") << "Plane not found!";
114  return 0.;
115  }
116 
117  return fNormCorr[chanId].corr;
118 }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::map< int, NormCorr_t > fNormCorr
double calib::XYZCalibProtoDUNE::GetXCorr ( int  plane,
double  x 
)
overridevirtual

Implements calib::XYZCalib.

Definition at line 121 of file XYZCalibProtoDUNE.cxx.

122 {
123  if (!fXCorrLoaded) this->LoadXCorr();
124 
125  if (fXCorrHist.find(plane) == fXCorrHist.end()) {
126  mf::LogError("XYZCalibProtoDUNE") << "Plane not found!";
127  return 0.;
128  }
129 
130  if (fInterpolate)
131  return fXCorrHist[plane].Interpolate(x);
132  else {
133  int ix = fXCorrHist[plane].FindBin(x);
134  return fXCorrHist[plane].GetBinContent(ix);
135  }
136 
137 }
std::map< int, TH1F > fXCorrHist
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
list x
Definition: train.py:276
double calib::XYZCalibProtoDUNE::GetYZCorr ( int  plane,
int  side,
double  y,
double  z 
)
overridevirtual

Implements calib::XYZCalib.

Definition at line 140 of file XYZCalibProtoDUNE.cxx.

142 {
143  if (!fYZCorrLoaded) this->LoadYZCorr();
144 
145  int chanId = plane*10+side;
146 
147  if (fYZCorrHist.find(chanId) == fYZCorrHist.end()) {
148  mf::LogError("XYZCalibProtoDUNE") << "Plane not found!";
149  return 0.;
150  }
151 
152  if (fInterpolate)
153  return fYZCorrHist[chanId].Interpolate(z,y);
154  else {
155  int iz = fYZCorrHist[chanId].GetXaxis()->FindBin(z);
156  int iy = fYZCorrHist[chanId].GetYaxis()->FindBin(y);
157  return fYZCorrHist[chanId].GetBinContent(iz,iy);
158  }
159 
160 }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::map< int, TH2F > fYZCorrHist
bool calib::XYZCalibProtoDUNE::LoadNormCorr ( )
protected

Definition at line 163 of file XYZCalibProtoDUNE.cxx.

164 {
165  if (!fUseCondbXYZCorr) return true;
166 
167  if (fNormCorrLoaded) return true;
168 
169  nutools::dbi::Table NormCorrTable;
170 
171  NormCorrTable.SetDetector("pdunesp");
172  NormCorrTable.SetTableName("distcorrnorm");
173  NormCorrTable.SetTableType(nutools::dbi::kConditionsTable);
174  NormCorrTable.SetDataTypeMask(nutools::dbi::kDataOnly);
175  if (fIsMC)
176  NormCorrTable.SetDataTypeMask(nutools::dbi::kMCOnly);
177 
178  int normIdx = NormCorrTable.AddCol("norm","double");
179  int normErrIdx = NormCorrTable.AddCol("norm_err","double");
180 
181  NormCorrTable.SetMinTSVld(fCurrentTS);
182  NormCorrTable.SetMaxTSVld(fCurrentTS);
183  NormCorrTable.SetTag(fNormCorrDBTag);
184 
185  NormCorrTable.SetVerbosity(100);
186 
187  bool readOk = false;
188  if (!fNormCorrFileName.empty())
189  readOk = NormCorrTable.LoadFromCSV(fNormCorrFileName);
190  else
191  readOk = NormCorrTable.Load();
192 
193  if (! readOk) {
194  mf::LogError("XYZCalibProtoDUNE") << "Load from norm calib database table failed.";
195 
196  return false; //std::abort();
197 
198  }
199 
200  if (NormCorrTable.NRow() == 0) {
201  mf::LogError("XYZCalibProtoDUNE") << "Number of rows in norm calib table is 0. This should never be the case!";
202  return false;
203  }
204 
205  nutools::dbi::Row* row;
206  uint64_t chan;
207  for (int i=0; i<NormCorrTable.NRow(); ++i) {
208  NormCorr_t norm;
209  row = NormCorrTable.GetRow(i);
210  chan = row->Channel();
211  row->Col(normIdx).Get(norm.corr);
212  row->Col(normErrIdx).Get(norm.corr_err);
213  fNormCorr[chan] = norm;
214  }
215 
216  fNormCorrLoaded = true;
217  return true;
218 }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::map< int, NormCorr_t > fNormCorr
auto norm(Vector const &v)
Return norm of the specified vector.
bool calib::XYZCalibProtoDUNE::LoadXCorr ( )
protected

Definition at line 221 of file XYZCalibProtoDUNE.cxx.

222 {
223  if (!fUseCondbXYZCorr) return true;
224 
225  if (fXCorrLoaded) return true;
226 
227  nutools::dbi::Table XCorrTable;
228 
229  XCorrTable.SetDetector("pdunesp");
230  XCorrTable.SetTableName("distcorrx");
231  XCorrTable.SetTableType(nutools::dbi::kConditionsTable);
232  XCorrTable.SetDataTypeMask(nutools::dbi::kDataOnly);
233  if (fIsMC)
234  XCorrTable.SetDataTypeMask(nutools::dbi::kMCOnly);
235 
236  int shapeIdx = XCorrTable.AddCol("shape","double");
237  int shapeErrIdx = XCorrTable.AddCol("shape_err","double");
238  int xIdx = XCorrTable.AddCol("x","double");
239  int dxIdx = XCorrTable.AddCol("dx","double");
240 
241  XCorrTable.SetMinTSVld(fCurrentTS);
242  XCorrTable.SetMaxTSVld(fCurrentTS);
243  XCorrTable.SetTag(fXCorrDBTag);
244 
245  XCorrTable.SetVerbosity(100);
246 
247  bool readOk = false;
248  if (!fXCorrFileName.empty())
249  readOk = XCorrTable.LoadFromCSV(fXCorrFileName);
250  else
251  readOk = XCorrTable.Load();
252 
253  if (! readOk) {
254  mf::LogError("XYZCalibProtoDUNE") << "Load from x calib database table failed.";
255  return false; //std::abort();
256  }
257 
258  if (XCorrTable.NRow() == 0) {
259  mf::LogError("XYZCalibProtoDUNE") << "Number of rows in x calib table is 0. This should never be the case!";
260  return false;
261  }
262 
263  nutools::dbi::Row* row;
264  uint64_t chan;
265  int plane;
266  std::vector<int> planeVec;
267 
268  std::map<int,std::vector<XCorr_t> > fXCorr;
269 
270  for (int i=0; i<XCorrTable.NRow(); ++i) {
271  row = XCorrTable.GetRow(i);
272  chan = row->Channel();
273  plane = int(chan/10000);
274 
275  XCorr_t xcorr;
276  row->Col(xIdx).Get(xcorr.x);
277  row->Col(dxIdx).Get(xcorr.dx);
278  row->Col(shapeIdx).Get(xcorr.corr);
279  row->Col(shapeErrIdx).Get(xcorr.corr_err);
280 
281  if (fXCorr.find(plane) == fXCorr.end()) {
282  planeVec.push_back(plane);
283  std::vector<XCorr_t> xcorrVec;
284  fXCorr[plane] = xcorrVec;
285  }
286 
287  fXCorr[plane].push_back(xcorr);
288 
289  }
290 
291  // sort the x-corrections by x for easy look-up
292  for (unsigned int i=0; i<planeVec.size(); ++i) {
293  int ip = planeVec[i];
294  std::sort(fXCorr[ip].begin(),fXCorr[ip].end());
295  char hname[256];
296  sprintf(hname,"xCorrHist_%d",ip);
297  int nbins = int(fXCorr[ip].size());
298  double xmin = fXCorr[ip][0].x;
299  double xmax = fXCorr[ip][nbins-1].x;
300  double bw = (xmax-xmin)/(nbins-1);
301  fXCorrHist[ip] = TH1F(hname,"",nbins,xmin-bw/2,xmax+bw/2);
302  std::cout<<"fXcorrHist["<<ip<<"] binning: Nbins = "<<fXCorrHist[ip].GetNbinsX()<<" Xmin = "<<fXCorrHist[ip].GetXaxis()->GetXmin()<<" Xmax = "<<fXCorrHist[ip].GetXaxis()->GetXmax()<<std::endl;
303  for (unsigned int j=0; j<fXCorr[ip].size(); ++j)
304  fXCorrHist[ip].SetBinContent(j+1,fXCorr[ip][j].corr);
305  }
306 
307  fXCorrLoaded = true;
308  return true;
309 
310 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::map< int, TH1F > fXCorrHist
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
QTextStream & endl(QTextStream &s)
bool calib::XYZCalibProtoDUNE::LoadYZCorr ( )
protected

Definition at line 313 of file XYZCalibProtoDUNE.cxx.

314 {
315  if (!fUseCondbXYZCorr) return true;
316 
317  if (fYZCorrLoaded) return true;
318 
319  nutools::dbi::Table YZCorrTable;
320 
321  YZCorrTable.SetDetector("pdunesp");
322  YZCorrTable.SetTableName("distcorryz");
323  YZCorrTable.SetTableType(nutools::dbi::kConditionsTable);
324  YZCorrTable.SetDataTypeMask(nutools::dbi::kDataOnly);
325  if (fIsMC)
326  YZCorrTable.SetDataTypeMask(nutools::dbi::kMCOnly);
327 
328  int corrIdx = YZCorrTable.AddCol("corr","double");
329  int corrErrIdx = YZCorrTable.AddCol("corr_err","double");
330  int yIdx = YZCorrTable.AddCol("y","double");
331  // int dyIdx = YZCorrTable.AddCol("dy","double");
332  int zIdx = YZCorrTable.AddCol("z","double");
333  // int dzIdx = YZCorrTable.AddCol("dz","double");
334 
335  YZCorrTable.SetMinTSVld(fCurrentTS);
336  YZCorrTable.SetMaxTSVld(fCurrentTS);
337  YZCorrTable.SetTag(fYZCorrDBTag);
338 
339  YZCorrTable.SetVerbosity(100);
340 
341  bool readOk = false;
342  if (!fYZCorrFileName.empty())
343  readOk = YZCorrTable.LoadFromCSV(fYZCorrFileName);
344  else
345  readOk = YZCorrTable.Load();
346 
347  if (! readOk) {
348  mf::LogError("XYZCalibProtoDUNE") << "Load from yz calib database table failed.";
349  return false; //std::abort();
350  }
351 
352  if (YZCorrTable.NRow() == 0) {
353  mf::LogError("XYZCalibProtoDUNE") << "Number of rows in yz calib table is 0. This should never be the case!";
354  return false;
355  }
356 
357  nutools::dbi::Row* row;
358  uint64_t chan;
359  std::vector<int> planeVec;
360 
361  std::map<int,std::vector<YZCorr_t> > fYZCorr;
362 
363  for (int i=0; i<YZCorrTable.NRow(); ++i) {
364  row = YZCorrTable.GetRow(i);
365  chan = row->Channel();
366  int plane = chan/10000000;
367  int side = (chan-plane*10000000)/1000000;
368  int chanId = plane*10+side;
369 
370  YZCorr_t yzcorr;
371  row->Col(yIdx).Get(yzcorr.y);
372  // row->Col(dyIdx).Get(yzcorr.dy);
373  row->Col(zIdx).Get(yzcorr.z);
374  // row->Col(dzIdx).Get(yzcorr.dz);
375  row->Col(corrIdx).Get(yzcorr.corr);
376  row->Col(corrErrIdx).Get(yzcorr.corr_err);
377 
378  if (fYZCorr.find(chanId) == fYZCorr.end())
379  planeVec.push_back(chanId);
380 
381  fYZCorr[chanId].push_back(yzcorr);
382 
383  }
384 
385  // sort the (y,z)-corrections by y and then by z for easy look-up
386  int nbinsy=0;
387  int nbinsz=0;
388  double ymin=0.;
389  double ymax=0.;
390  double zmin=0;
391  double zmax=0.;
392  double bwy=0.;
393  double bwz=0.;
394 
395  for (unsigned int i=0; i<planeVec.size(); ++i) {
396  int ip = planeVec[i];
397  std::sort(fYZCorr[ip].begin(),fYZCorr[ip].end());
398  if (i==0) {
399  ymin = fYZCorr[ip][0].y;
400  zmin = fYZCorr[ip][0].z;
401  ymax = fYZCorr[ip][fYZCorr[ip].size()-1].y;
402  zmax = fYZCorr[ip][fYZCorr[ip].size()-1].z;
403  // now figure out how many z bins there are
404  for (unsigned j=1; j<fYZCorr[ip].size(); ++j, ++nbinsz)
405  if (fYZCorr[ip][j].z < fYZCorr[ip][j-1].z) break;
406  nbinsy = int(fYZCorr[ip].size())/++nbinsz;
407  bwz = (zmax-zmin)/(nbinsz-1);
408  bwy = (ymax-ymin)/(nbinsy-1);
409  }
410  char hname[256];
411  sprintf(hname,"yzCorrHist_%d",i);
412  fYZCorrHist[ip] = TH2F(hname,"",nbinsz,zmin-bwz/2,zmax+bwz/2,
413  nbinsy,ymin-bwy/2,ymax+bwy/2);
414  std::cout<<"fYZcorrHist["<<ip<<"] binning: Nbins = "<<fYZCorrHist[ip].GetNbinsX()<<" Xmin = "<<fYZCorrHist[ip].GetXaxis()->GetXmin()<<" Xmax = "<<fYZCorrHist[ip].GetXaxis()->GetXmax()<<" Ymin = "<<fYZCorrHist[ip].GetYaxis()->GetXmin()<<" Ymax = "<<fYZCorrHist[ip].GetYaxis()->GetXmax()<<std::endl;
415 
416  for (unsigned int j=0; j<fYZCorr[ip].size(); ++j)
417  fYZCorrHist[ip].Fill(fYZCorr[ip][j].z,fYZCorr[ip][j].y,fYZCorr[ip][j].corr);
418  }
419 
420  fYZCorrLoaded = true;
421  return true;
422 
423 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::map< int, TH2F > fYZCorrHist
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
QTextStream & endl(QTextStream &s)
void calib::XYZCalibProtoDUNE::SetInterpolate ( bool  v)
inline

Definition at line 89 of file XYZCalibProtoDUNE.h.

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

Definition at line 80 of file XYZCalibProtoDUNE.h.

void calib::XYZCalibProtoDUNE::SetNormCorr ( int  plane,
double  val 
)
void calib::XYZCalibProtoDUNE::SetNormCorrFileName ( std::string  f)
inline
void calib::XYZCalibProtoDUNE::SetUseCondb ( bool  v)
inline

Definition at line 84 of file XYZCalibProtoDUNE.h.

void calib::XYZCalibProtoDUNE::SetXCorr ( int  plane,
double  x,
double  dx,
double  val 
)
void calib::XYZCalibProtoDUNE::SetXCorrFileName ( std::string  f)
inline
void calib::XYZCalibProtoDUNE::SetYZCorr ( int  plane,
int  side,
double  y,
double  dx,
double  val 
)
void calib::XYZCalibProtoDUNE::SetYZCorrFileName ( std::string  f)
inline
bool calib::XYZCalibProtoDUNE::Update ( uint64_t  ts = 0)

Definition at line 83 of file XYZCalibProtoDUNE.cxx.

84 {
85 
86  if (fYZCorrLoaded && ts != fCurrentTS) {
87  fYZCorrHist.clear();
88  fYZCorrLoaded = false;
89  }
90 
91  if (fXCorrLoaded && ts != fCurrentTS) {
92  fXCorrHist.clear();
93  fXCorrLoaded = false;
94  }
95 
96  if (fNormCorrLoaded && ts != fCurrentTS) {
97  fNormCorr.clear();
98  fNormCorrLoaded = false;
99  }
100 
101  fCurrentTS = ts;
102  // all done!
103 
104  return true;
105 }
std::map< int, TH1F > fXCorrHist
std::map< int, TH2F > fYZCorrHist
std::map< int, NormCorr_t > fNormCorr

Member Data Documentation

uint64_t calib::XYZCalibProtoDUNE::fCurrentTS
protected

Definition at line 103 of file XYZCalibProtoDUNE.h.

bool calib::XYZCalibProtoDUNE::fInterpolate
protected

Definition at line 102 of file XYZCalibProtoDUNE.h.

bool calib::XYZCalibProtoDUNE::fIsMC
protected

Definition at line 101 of file XYZCalibProtoDUNE.h.

std::map<int,NormCorr_t> calib::XYZCalibProtoDUNE::fNormCorr
protected

Definition at line 112 of file XYZCalibProtoDUNE.h.

std::string calib::XYZCalibProtoDUNE::fNormCorrDBTag
protected

Definition at line 110 of file XYZCalibProtoDUNE.h.

std::string calib::XYZCalibProtoDUNE::fNormCorrFileName
protected

Definition at line 107 of file XYZCalibProtoDUNE.h.

bool calib::XYZCalibProtoDUNE::fNormCorrLoaded
protected

Definition at line 98 of file XYZCalibProtoDUNE.h.

bool calib::XYZCalibProtoDUNE::fUseCondbXYZCorr
protected

Definition at line 97 of file XYZCalibProtoDUNE.h.

std::string calib::XYZCalibProtoDUNE::fXCorrDBTag
protected

Definition at line 108 of file XYZCalibProtoDUNE.h.

std::string calib::XYZCalibProtoDUNE::fXCorrFileName
protected

Definition at line 105 of file XYZCalibProtoDUNE.h.

std::map<int,TH1F> calib::XYZCalibProtoDUNE::fXCorrHist
protected

Definition at line 113 of file XYZCalibProtoDUNE.h.

bool calib::XYZCalibProtoDUNE::fXCorrLoaded
protected

Definition at line 99 of file XYZCalibProtoDUNE.h.

std::string calib::XYZCalibProtoDUNE::fYZCorrDBTag
protected

Definition at line 109 of file XYZCalibProtoDUNE.h.

std::string calib::XYZCalibProtoDUNE::fYZCorrFileName
protected

Definition at line 106 of file XYZCalibProtoDUNE.h.

std::map<int,TH2F> calib::XYZCalibProtoDUNE::fYZCorrHist
protected

Definition at line 114 of file XYZCalibProtoDUNE.h.

bool calib::XYZCalibProtoDUNE::fYZCorrLoaded
protected

Definition at line 100 of file XYZCalibProtoDUNE.h.


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