22 #include "nuevdb/IFDatabase/Table.h" 25 #include "cetlib_except/exception.h" 113 mf::LogError(
"XYZCalibProtoDUNE") <<
"Plane not found!";
126 mf::LogError(
"XYZCalibProtoDUNE") <<
"Plane not found!";
145 int chanId = plane*10+side;
148 mf::LogError(
"XYZCalibProtoDUNE") <<
"Plane not found!";
155 int iz =
fYZCorrHist[chanId].GetXaxis()->FindBin(z);
156 int iy =
fYZCorrHist[chanId].GetYaxis()->FindBin(y);
169 nutools::dbi::Table NormCorrTable;
171 NormCorrTable.SetDetector(
"pdunesp");
172 NormCorrTable.SetTableName(
"distcorrnorm");
173 NormCorrTable.SetTableType(nutools::dbi::kConditionsTable);
174 NormCorrTable.SetDataTypeMask(nutools::dbi::kDataOnly);
176 NormCorrTable.SetDataTypeMask(nutools::dbi::kMCOnly);
178 int normIdx = NormCorrTable.AddCol(
"norm",
"double");
179 int normErrIdx = NormCorrTable.AddCol(
"norm_err",
"double");
185 NormCorrTable.SetVerbosity(100);
191 readOk = NormCorrTable.Load();
194 mf::LogError(
"XYZCalibProtoDUNE") <<
"Load from norm calib database table failed.";
200 if (NormCorrTable.NRow() == 0) {
201 mf::LogError(
"XYZCalibProtoDUNE") <<
"Number of rows in norm calib table is 0. This should never be the case!";
205 nutools::dbi::Row*
row;
207 for (
int i=0; i<NormCorrTable.NRow(); ++i) {
209 row = NormCorrTable.GetRow(i);
210 chan = row->Channel();
211 row->Col(normIdx).Get(norm.
corr);
212 row->Col(normErrIdx).Get(norm.
corr_err);
227 nutools::dbi::Table XCorrTable;
229 XCorrTable.SetDetector(
"pdunesp");
230 XCorrTable.SetTableName(
"distcorrx");
231 XCorrTable.SetTableType(nutools::dbi::kConditionsTable);
232 XCorrTable.SetDataTypeMask(nutools::dbi::kDataOnly);
234 XCorrTable.SetDataTypeMask(nutools::dbi::kMCOnly);
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");
245 XCorrTable.SetVerbosity(100);
251 readOk = XCorrTable.Load();
254 mf::LogError(
"XYZCalibProtoDUNE") <<
"Load from x calib database table failed.";
258 if (XCorrTable.NRow() == 0) {
259 mf::LogError(
"XYZCalibProtoDUNE") <<
"Number of rows in x calib table is 0. This should never be the case!";
263 nutools::dbi::Row*
row;
266 std::vector<int> planeVec;
268 std::map<int,std::vector<XCorr_t> > fXCorr;
270 for (
int i=0; i<XCorrTable.NRow(); ++i) {
271 row = XCorrTable.GetRow(i);
272 chan = row->Channel();
273 plane =
int(chan/10000);
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);
281 if (fXCorr.find(plane) == fXCorr.end()) {
282 planeVec.push_back(plane);
283 std::vector<XCorr_t> xcorrVec;
284 fXCorr[plane] = xcorrVec;
287 fXCorr[plane].push_back(xcorr);
292 for (
unsigned int i=0; i<planeVec.size(); ++i) {
293 int ip = planeVec[i];
294 std::sort(fXCorr[ip].
begin(),fXCorr[ip].
end());
296 sprintf(hname,
"xCorrHist_%d",ip);
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);
319 nutools::dbi::Table YZCorrTable;
321 YZCorrTable.SetDetector(
"pdunesp");
322 YZCorrTable.SetTableName(
"distcorryz");
323 YZCorrTable.SetTableType(nutools::dbi::kConditionsTable);
324 YZCorrTable.SetDataTypeMask(nutools::dbi::kDataOnly);
326 YZCorrTable.SetDataTypeMask(nutools::dbi::kMCOnly);
328 int corrIdx = YZCorrTable.AddCol(
"corr",
"double");
329 int corrErrIdx = YZCorrTable.AddCol(
"corr_err",
"double");
330 int yIdx = YZCorrTable.AddCol(
"y",
"double");
332 int zIdx = YZCorrTable.AddCol(
"z",
"double");
339 YZCorrTable.SetVerbosity(100);
345 readOk = YZCorrTable.Load();
348 mf::LogError(
"XYZCalibProtoDUNE") <<
"Load from yz calib database table failed.";
352 if (YZCorrTable.NRow() == 0) {
353 mf::LogError(
"XYZCalibProtoDUNE") <<
"Number of rows in yz calib table is 0. This should never be the case!";
357 nutools::dbi::Row*
row;
359 std::vector<int> planeVec;
361 std::map<int,std::vector<YZCorr_t> > fYZCorr;
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;
371 row->Col(yIdx).Get(yzcorr.
y);
373 row->Col(zIdx).Get(yzcorr.
z);
375 row->Col(corrIdx).Get(yzcorr.
corr);
376 row->Col(corrErrIdx).Get(yzcorr.
corr_err);
378 if (fYZCorr.find(chanId) == fYZCorr.end())
379 planeVec.push_back(chanId);
381 fYZCorr[chanId].push_back(yzcorr);
395 for (
unsigned int i=0; i<planeVec.size(); ++i) {
396 int ip = planeVec[i];
397 std::sort(fYZCorr[ip].
begin(),fYZCorr[ip].
end());
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;
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);
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);
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);
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::map< int, TH1F > fXCorrHist
bool Update(uint64_t ts=0)
virtual double GetNormCorr(int plane) override
std::string fNormCorrFileName
bool Configure(fhicl::ParameterSet const &pset)
std::string fYZCorrFileName
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
virtual double GetYZCorr(int plane, int side, double y, double z) override
std::map< int, TH2F > fYZCorrHist
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::map< int, NormCorr_t > fNormCorr
T get(std::string const &key) const
auto norm(Vector const &v)
Return norm of the specified vector.
std::string fNormCorrDBTag
std::string fXCorrFileName
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
virtual double GetXCorr(int plane, double x) override
QTextStream & endl(QTextStream &s)