10#include <top/calibration/TOPDatabaseImporter.h>
13#include <top/geometry/TOPGeometryPar.h>
16#include <framework/database/IntervalOfValidity.h>
17#include <framework/database/DBImportArray.h>
18#include <framework/database/DBImportObjPtr.h>
19#include <framework/database/DBArray.h>
20#include <framework/database/DBObjPtr.h>
23#include <framework/logging/Logger.h>
26#include <top/dbobjects/TOPCalTimebase.h>
27#include <top/dbobjects/TOPCalChannelT0.h>
28#include <top/dbobjects/TOPCalModuleT0.h>
29#include <top/dbobjects/TOPCalChannelMask.h>
30#include <top/dbobjects/TOPCalChannelPulseHeight.h>
31#include <top/dbobjects/TOPCalChannelThresholdEff.h>
32#include <top/dbobjects/TOPCalChannelNoise.h>
33#include <top/dbobjects/TOPCalChannelRQE.h>
34#include <top/dbobjects/TOPCalChannelThreshold.h>
35#include <top/dbobjects/TOPCalCommonT0.h>
36#include <top/dbobjects/TOPCalIntegratedCharge.h>
37#include <top/dbobjects/TOPCalModuleAlignment.h>
38#include <top/dbobjects/TOPCalAsicShift.h>
39#include <top/dbobjects/TOPCalTimeWalk.h>
41#include <top/dbobjects/TOPPmtGainPar.h>
42#include <top/dbobjects/TOPPmtQE.h>
43#include <top/dbobjects/TOPPmtInstallation.h>
44#include <top/dbobjects/TOPPmtObsoleteData.h>
45#include <top/dbobjects/TOPPmtTTSPar.h>
46#include <top/dbobjects/TOPPmtTTSHisto.h>
48#include <top/dbobjects/TOPFrontEndSetting.h>
70 int firstExp,
int firstRun,
71 int lastExp,
int lastRun)
76 vector<string> fileNames;
77 stringstream ss(fNames);
80 fileNames.push_back(fName);
95 for (
const auto& fileName : fileNames) {
96 TFile* file = TFile::Open(fileName.c_str(),
"r");
98 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
101 B2INFO(fileName <<
": open for reading");
103 TH1F* hsuccess =
static_cast<TH1F*
>(file->Get(
"success"));
105 B2ERROR(
"Fit status histogram '" << hsuccess <<
"' not found");
110 int goodChannels = 0;
111 int numChannels = hsuccess->GetNbinsX();
112 for (
int channel = 0; channel < numChannels; channel++) {
113 if (hsuccess->GetBinContent(channel + 1) == 0)
continue;
115 string hname =
"sampleTimes_ch" + to_string(channel);
117 TH1F* hsampleTimes =
static_cast<TH1F*
>(file->Get(hname.c_str()));
119 B2ERROR(
"Histogram '" << hname <<
"' with calibration constants not found");
123 string title = hsampleTimes->GetTitle();
124 auto iscrod = title.find(
"scrod");
125 auto ichannel = title.find(
"channel");
126 if (iscrod == string::npos or ichannel == string::npos) {
127 B2ERROR(
"Unsuccessful parsing of scrodID from '" << title <<
"'");
131 int len = ichannel - iscrod;
133 B2ERROR(
"Unsuccessful parsing of scrodID from '" << title <<
"'");
136 int scrodID = stoi(title.substr(iscrod, len));
137 scrodIDs.insert(scrodID);
140 if (hsampleTimes->GetBinContent(257) > 0)
141 rescale = 2 * syncTimeBase / hsampleTimes->GetBinContent(257);
143 vector<double> sampleTimes;
144 for (
int isamp = 0; isamp < 256; isamp++) {
145 sampleTimes.push_back(hsampleTimes->GetBinContent(isamp + 1) * rescale);
149 timeBase->append(scrodID, channel, sampleTimes);
153 B2INFO(
"--> number of calibrated channels: " << goodChannels);
154 B2INFO(
"file closed");
159 B2INFO(
"set constants for uncalibrated channels using nearest calibrated channel within an ASIC");
160 for (
auto scrodID : scrodIDs) {
162 for (
int as = 0; as < nasic; as++) {
164 for (
int ch = 0; ch < 15; ch++) {
165 int channel = as * 8 + (ch % 8);
166 if (timeBase->isAvailable(scrodID, channel)) {
167 sampleTimes = timeBase->getSampleTimes(scrodID, channel);
168 }
else if (sampleTimes) {
169 timeBase->append(scrodID, channel, sampleTimes->
getTimeAxis());
173 B2INFO(
"No calibration available for ASIC " << as <<
" of scrodID " << scrodID);
184 int nall = timeBase->getSampleTimes().size();
186 for (
const auto& sampleTimes : timeBase->getSampleTimes()) {
187 if (sampleTimes.isCalibrated()) ncal++;
190 B2RESULT(
"Sample time calibration constants imported to database, calibrated channels: "
191 << ncal <<
"/" << nall);
196 int firstExp,
int firstRun,
197 int lastExp,
int lastRun)
199 vector<string> fileNames;
200 stringstream ss(fNames);
202 while (ss >> fName) {
203 fileNames.push_back(fName);
213 for (
const auto& fileName : fileNames) {
214 TFile* file = TFile::Open(fileName.c_str(),
"r");
215 B2INFO(
"--> Opening constants file " << fileName);
218 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
221 B2INFO(
"--> " << fileName <<
": open for reading");
223 TTree* treeCal =
static_cast<TTree*
>(file->Get(
"chT0"));
226 B2ERROR(
"openFile: no tree named chT0 found in " << fileName);
232 double t0CalErr = 0.;
237 treeCal->SetBranchAddress(
"channel", &channelID);
238 treeCal->SetBranchAddress(
"slot", &slotID);
239 treeCal->SetBranchAddress(
"channelT0", &t0Cal);
240 treeCal->SetBranchAddress(
"channelT0Err", &t0CalErr);
241 treeCal->SetBranchAddress(
"fitStatus", &fitStatus);
243 B2INFO(
"--> importing constats");
245 for (
int iCal = 0; iCal < treeCal->GetEntries(); iCal++) {
246 treeCal->GetEntry(iCal);
247 if (!geo->isModuleIDValid(slotID)) {
248 B2ERROR(
"Slot ID is not valid (fileName = " << fileName
249 <<
", SlotID = " << slotID <<
", ChannelID = " << channelID <<
250 "). Skipping the entry.");
253 if (channelID < 0 or channelID > 511) {
254 B2ERROR(
"Channel ID is not valid (fileName = " << fileName
255 <<
", SlotID = " << slotID <<
", ChannelID = " << channelID <<
256 "). Skipping the entry.");
259 channelT0->setT0(slotID, channelID, t0Cal, t0CalErr);
260 if (fitStatus == 0) {
263 channelT0->setUnusable(slotID, channelID);
268 B2INFO(
"--> Input file closed");
270 channelT0->suppressAverage();
277 for (
int iSlot = 1; iSlot < 17; iSlot++) {
278 B2INFO(
"--> Number of calibrated channels on Slot " << iSlot <<
" : " << nCal[iSlot - 1] <<
"/512");
279 B2INFO(
"--> Cal on ch 1, 256 and 511: " << channelT0->getT0(iSlot, 0) <<
", " << channelT0->getT0(iSlot,
280 257) <<
", " << channelT0->getT0(iSlot, 511));
281 nCalTot += nCal[iSlot - 1];
285 B2RESULT(
"Channel T0 calibration constants imported to database, calibrated channels: "
286 << nCalTot <<
"/ 8192");
291 int expNo,
int firstRun,
int lastRun)
298 TFile* file = TFile::Open(fileName.c_str(),
"r");
300 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
303 B2INFO(fileName <<
": open for reading");
308 for (
int moduleID = 1; moduleID <= nModules; moduleID++) {
309 std::string name =
"channelT0_slot";
310 if (moduleID < 10) name +=
"0";
311 name += std::to_string(moduleID);
312 auto* h =
static_cast<TH1F*
>(file->Get(name.c_str()));
314 B2ERROR(
"Histogram with name '" + name +
"' not found");
317 for (
int channel = 0; channel < h->GetNbinsX(); channel++) {
318 double value = h->GetBinContent(channel + 1);
319 double error = h->GetBinError(channel + 1);
320 channelT0->setT0(moduleID, channel, value, error);
324 channelT0->setUnusable(moduleID, channel);
330 channelT0->suppressAverage();
336 B2INFO(
"Channel T0 for exp " << expNo <<
" run " << firstRun <<
" to " << lastRun
337 <<
" imported. Calibrated channels: " << count <<
"/" << nModules * 512);
343 int expNo,
int firstRun,
int lastRun)
346 std::vector<double> shifts;
347 shifts.push_back(s0);
348 shifts.push_back(s1);
349 shifts.push_back(s2);
350 shifts.push_back(s3);
357 for (
unsigned carrier = 0; carrier < 4; carrier++) {
358 for (
unsigned a = 0; a < 4; a++) {
359 unsigned asic = a + carrier * 4 + bs * 16;
360 asicShift->setT0(moduleID, asic, shifts[carrier]);
367 B2INFO(
"ASIC shifts of BS13d imported for exp " << expNo <<
" run " << firstRun <<
373 int firstExp,
int firstRun,
374 int lastExp,
int lastRun)
376 TFile* file = TFile::Open(fileName.c_str(),
"r");
377 B2INFO(
"--> Opening constants file " << fileName);
380 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
383 B2INFO(
"--> " << fileName <<
": open for reading");
385 TTree* treeCal =
static_cast<TTree*
>(file->Get(
"tree"));
388 B2ERROR(
"openFile: no tree named tree found in " << fileName);
401 treeCal->SetBranchAddress(
"offset", &t0);
402 treeCal->SetBranchAddress(
"runNum", &runNum);
403 treeCal->SetBranchAddress(
"sigma", &sigma);
404 treeCal->SetBranchAddress(
"offsetErr", &t0Err);
405 treeCal->SetBranchAddress(
"chi2", &chi2);
406 treeCal->SetBranchAddress(
"integral", &integral);
407 treeCal->SetBranchAddress(
"fitStatus", &fitStatus);
409 treeCal->GetEntry(0);
411 if (lastRun == -1 and firstRun == -1) {
414 B2INFO(
"Using the run number from the tree ");
416 B2INFO(
"Using the run numbers passed to the importer");
418 B2INFO(
"IOV = (" << firstExp <<
", " << firstRun <<
", "
419 << lastExp <<
", " << lastRun <<
")");
424 if (fitStatus == 0 and integral > 10 and sigma > 0.05 and sigma < 0.33) {
425 B2INFO(
"Good calibration found ");
426 B2INFO(
"t0 = " << t0 <<
" +- " << t0Err);
427 B2INFO(
"sigma = " << sigma);
428 B2INFO(
"chi2 = " << chi2);
430 B2INFO(
"BAD calibration found - set calibration to 'unusable'");
431 B2INFO(
"t0 = " << t0 <<
" +- " << t0Err);
432 B2INFO(
"sigma = " << sigma);
433 B2INFO(
"chi2 = " << chi2);
434 B2INFO(
"fit status = " << fitStatus);
435 commonT0->setUnusable();
442 B2INFO(
"--> constants imported");
447 int expNo,
int firstRun,
int lastRun,
448 bool roughlyCalibrated)
452 if (roughlyCalibrated) commonT0->setRoughlyCalibrated();
457 B2INFO(
"--> constants for exp = " << expNo
458 <<
" run = " << firstRun <<
" to " << lastRun <<
" imported");
462 int firstExp,
int firstRun,
463 int lastExp,
int lastRun)
471 ifstream inFile(fileName);
472 B2INFO(
"--> Opening constants file " << fileName);
475 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
478 B2INFO(
"--> " << fileName <<
": open for reading");
481 B2INFO(
"--> importing constants");
483 while (!inFile.eof()) {
489 inFile >> slot >> dummy >> T0 >> T0_err;
490 if (slot < 1 or slot > 16) {
491 B2ERROR(
"Module ID is not valid. Skipping the entry.");
494 moduleT0->setT0(slot, T0, T0_err);
498 B2INFO(
"--> Input file closed");
500 moduleT0->suppressAverage();
506 for (
int iSlot = 1; iSlot < 17; iSlot++) {
507 B2INFO(
"--> Time offset of Slot " << iSlot <<
" = " << moduleT0->getT0(iSlot));
515 int expNo,
int firstRun,
int lastRun)
523 TFile* file = TFile::Open(fileName.c_str(),
"r");
525 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
528 B2INFO(fileName <<
": open for reading");
531 auto* h =
static_cast<TH1F*
>(file->Get(
"moduleT0"));
533 B2ERROR(
"no histogram 'moduleT0' found in the file, nothing imported");
537 for (
int slot = 1; slot <= h->GetNbinsX(); slot++) {
538 double value = h->GetBinContent(slot);
539 double error = h->GetBinError(slot);
540 moduleT0->setT0(slot, value, error);
544 moduleT0->setUnusable(slot);
549 moduleT0->suppressAverage();
555 B2INFO(
"Module T0 for exp " << expNo <<
" run " << firstRun <<
" to " << lastRun
556 <<
" imported. Calibrated modules: " << count <<
"/" << 16);
565 B2ERROR(
"No time base calibration available");
573 cout <<
"Time base calibration: number of calibrated channels in database" << endl << endl;
574 for (
int moduleID = 1; moduleID <= numModules; moduleID++) {
575 int ncal[4] = {0, 0, 0, 0};
576 int scrodID[4] = {0, 0, 0, 0};
577 for (
int bs = 0; bs < 4; bs++) {
578 auto* femap = feMapper.getMap(moduleID, bs);
580 B2ERROR(
"No FrontEnd map available for boardstack " << bs <<
" of module " << moduleID);
583 scrodID[bs] = femap->getScrodID();
584 for (
int channel = 0; channel < 128; channel++) {
585 if (timeBase->isAvailable(scrodID[bs], channel)) ncal[bs]++;
589 cout <<
"Slot " << moduleID << endl;
590 for (
int bs = 0; bs < 4; bs++) {
591 cout <<
" scrodID " << scrodID[bs] <<
": " << ncal[bs] <<
"/128";
592 if (ncal[bs] < 128) cout <<
" (" << 128 - ncal[bs] <<
" missing)";
606 B2ERROR(
"No time base calibration available");
610 for (
const auto& sampleTimes : timeBase->getSampleTimes()) {
611 cout << sampleTimes.getScrodID() <<
" " << sampleTimes.getChannel() << endl;
612 for (
const auto& time : sampleTimes.getTimeAxis()) {
622 int expNo,
int firstRun,
int lastRun)
629 TFile* file = TFile::Open(fileName.c_str(),
"r");
631 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
634 B2INFO(fileName <<
": open for reading");
638 int active = 0, dead = 0, noisy = 0;
639 for (
int moduleID = 1; moduleID <= nModules; moduleID++) {
640 std::string name =
"slot_" + std::to_string(moduleID);
641 auto* h =
static_cast<TH1F*
>(file->Get(name.c_str()));
643 B2ERROR(
"Histogram with name '" + name +
"' not found");
646 for (
int channel = 0; channel < h->GetNbinsX(); channel++) {
647 int value = h->GetBinContent(channel + 1);
649 channelMask->setActive(moduleID, channel);
651 }
else if (value == 1) {
652 channelMask->setDead(moduleID, channel);
655 channelMask->setNoisy(moduleID, channel);
666 B2INFO(
"Channel mask for exp " << expNo <<
" run " << firstRun <<
" to " << lastRun
667 <<
" imported. Active channels: " << active <<
", dead: " << dead
668 <<
", noisy: " << noisy);
675 int firstExp,
int firstRun,
676 int lastExp,
int lastRun)
689 for (
size_t moduleID = 1; moduleID <= nModules; moduleID++) {
693 for (
int boardStack = 0; boardStack < 4; boardStack++) {
694 for (
int carrierBoard = 0; carrierBoard < 4; carrierBoard++) {
695 for (
int asic = 0; asic < 4; asic++) {
696 for (
int chan = 0; chan < 8; chan++) {
697 auto channel = chMapper.getChannel(boardStack, carrierBoard, asic, chan);
699 if (gRandom->Rndm() < fractionDead) {
700 channelMask->setDead(moduleID, channel);
703 if (gRandom->Rndm() < fractionHot) {
704 channelMask->setNoisy(moduleID, channel);
717 B2RESULT(
"Generated and imported a fake channel mask to database for testing: "
718 << ncall <<
"/" << nall);
724 int firstExp,
int firstRun,
725 int lastExp,
int lastRun)
731 static const int nChann = 16;
732 std::string* serialNum = 0;
733 std::vector<float>* QE_data[nChann];
734 float lambdaFirst, lambdaStep, collEff0, collEff;
736 TBranch* bQE_data[nChann];
739 TFile* file = TFile::Open(fileName.c_str(),
"r");
741 B2ERROR(
"Cannot open the file " << fileName);
744 TTree* tQeData =
static_cast<TTree*
>(file->Get(treeName.c_str()));
746 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
751 tQeData->SetBranchAddress(
"serialNum", &serialNum);
752 tQeData->SetBranchAddress(
"lambdaFirst", &lambdaFirst);
753 tQeData->SetBranchAddress(
"lambdaStep", &lambdaStep);
754 tQeData->SetBranchAddress(
"collEff0", &collEff0);
755 tQeData->SetBranchAddress(
"collEff", &collEff);
757 for (
int ic = 0; ic < nChann; ic++) {
759 QE_data[ic] =
new std::vector<float>;
760 bQE_data[ic] =
new TBranch();
762 TString cString =
"QE_ch";
764 tQeData->SetBranchAddress(cString, &QE_data[ic], &bQE_data[ic]);
770 for (
int ient = 0; ient < tQeData->GetEntries(); ient++) {
772 tQeData->GetEntry(ient);
774 auto* pmtQE = pmtQEs.
appendNew(*serialNum, lambdaFirst, lambdaStep, collEff0, collEff);
776 for (
int ic = 0; ic < nChann; ic++) {
777 int tEntry = tQeData->LoadTree(ient);
778 bQE_data[ic]->GetEntry(tEntry);
780 pmtQE->setQE(ic + 1, *QE_data[ic]);
790 B2RESULT(
"PMT QE data imported to database for " << countPMTs <<
" PMT's.");
797 int firstExp,
int firstRun,
798 int lastExp,
int lastRun)
804 static const int nChann = 16;
805 std::string* serialNum = 0;
806 float gain_const[nChann], gain_slope[nChann], gain_ratio[nChann];
810 TFile* file = TFile::Open(fileName.c_str(),
"r");
812 B2ERROR(
"Cannot open the file " << fileName);
815 TTree* tGainData =
static_cast<TTree*
>(file->Get(treeName.c_str()));
817 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
822 tGainData->SetBranchAddress(
"serialNum", &serialNum);
823 tGainData->SetBranchAddress(
"gain_const", &gain_const);
824 tGainData->SetBranchAddress(
"gain_slope", &gain_slope);
825 tGainData->SetBranchAddress(
"gain_ratio", &gain_ratio);
826 tGainData->SetBranchAddress(
"hv_op0", &hv_op0);
827 tGainData->SetBranchAddress(
"hv_op", &hv_op);
833 for (
int ient = 0; ient < tGainData->GetEntries(); ient++) {
834 tGainData->GetEntry(ient);
835 auto* pmtGain = pmtGains.
appendNew(*serialNum);
837 for (
int ic = 0; ic < nChann; ic++) {
838 pmtGain->setPmtPixelData(ic + 1, gain_const[ic], gain_slope[ic], gain_ratio[ic]);
839 pmtGain->setNominalHV0(-fabs(hv_op0));
840 pmtGain->setNominalHV(-fabs(hv_op));
849 B2RESULT(
"PMT gain data imported to database for " << countPMTs <<
" PMT's.");
856 int firstExp,
int firstRun,
857 int lastExp,
int lastRun)
863 std::string* serialNum = 0;
864 int moduleCNum, slotNum, arrayNum, PMTposition;
868 TFile* file = TFile::Open(fileName.c_str(),
"r");
870 B2ERROR(
"Cannot open the file " << fileName);
873 TTree* tInstData =
static_cast<TTree*
>(file->Get(treeName.c_str()));
875 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
880 tInstData->SetBranchAddress(
"serialNum", &serialNum);
881 tInstData->SetBranchAddress(
"moduleCNum", &moduleCNum);
882 tInstData->SetBranchAddress(
"slotNum", &slotNum);
883 tInstData->SetBranchAddress(
"arrayNum", &arrayNum);
884 tInstData->SetBranchAddress(
"PMTposition", &PMTposition);
885 tInstData->SetBranchAddress(
"type", &type);
890 for (
int ient = 0; ient < tInstData->GetEntries(); ient++) {
891 tInstData->GetEntry(ient);
892 pmtInst.
appendNew(*serialNum, moduleCNum, slotNum, arrayNum, PMTposition, type);
900 B2RESULT(
"PMT installation data imported to database for " << countPMTs <<
" PMT's.");
906 int firstExp,
int firstRun,
907 int lastExp,
int lastRun)
913 std::string* serialNum = 0;
914 std::string* cathode = 0;
915 float hv_spec, dark_spec, qe380_spec;
919 TFile* file = TFile::Open(fileName.c_str(),
"r");
921 B2ERROR(
"Cannot open the file " << fileName);
924 TTree* tObsData =
static_cast<TTree*
>(file->Get(treeName.c_str()));
926 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
931 tObsData->SetBranchAddress(
"serialNum", &serialNum);
932 tObsData->SetBranchAddress(
"cathode", &cathode);
933 tObsData->SetBranchAddress(
"hv_spec", &hv_spec);
934 tObsData->SetBranchAddress(
"dark_spec", &dark_spec);
935 tObsData->SetBranchAddress(
"qe380_spec", &qe380_spec);
936 tObsData->SetBranchAddress(
"type", &type);
941 for (
int ient = 0; ient < tObsData->GetEntries(); ient++) {
942 tObsData->GetEntry(ient);
945 hv_spec = -fabs(hv_spec);
947 pmtObsData.
appendNew(*serialNum, type, *cathode, hv_spec, dark_spec, qe380_spec);
954 B2RESULT(
"PMT obsolete data imported to database for " << countPMTs <<
" PMT's.");
966 int firstExp,
int firstRun,
967 int lastExp,
int lastRun)
973 static const int nChann = 16;
974 std::string* serialNum = 0;
975 std::vector<float>* gausFrac[nChann];
976 std::vector<float>* gausMean[nChann];
977 std::vector<float>* gausSigma[nChann];
979 TBranch* bGFrac[nChann];
980 TBranch* bGMean[nChann];
981 TBranch* bGSigma[nChann];
985 TFile* file = TFile::Open(fileName.c_str(),
"r");
987 B2ERROR(
"Cannot open the file " << fileName);
990 TTree* tTtsPar =
static_cast<TTree*
>(file->Get(treeName.c_str()));
992 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
997 tTtsPar->SetBranchAddress(
"serialNum", &serialNum);
998 for (
int ic = 0; ic < nChann; ic++) {
1000 gausFrac[ic] =
new std::vector<float>;
1001 gausMean[ic] =
new std::vector<float>;
1002 gausSigma[ic] =
new std::vector<float>;
1004 bGFrac[ic] =
new TBranch();
1005 bGMean[ic] =
new TBranch();
1006 bGSigma[ic] =
new TBranch();
1009 TString cStringF =
"gausFrac_ch";
1010 TString cStringM =
"gausMean_ch";
1011 TString cStringS =
"gausSigma_ch";
1017 tTtsPar->SetBranchAddress(cStringF, &gausFrac[ic], &bGFrac[ic]);
1018 tTtsPar->SetBranchAddress(cStringM, &gausMean[ic], &bGMean[ic]);
1019 tTtsPar->SetBranchAddress(cStringS, &gausSigma[ic], &bGSigma[ic]);
1025 for (
int ient = 0; ient < tTtsPar->GetEntries(); ient++) {
1027 tTtsPar->GetEntry(ient);
1029 auto* pmtTtsPar = pmtTtsPars.
appendNew(*serialNum);
1031 for (
int ic = 0; ic < nChann; ic++) {
1033 int tEntry = tTtsPar->LoadTree(ient);
1034 bGFrac[ic]->GetEntry(tEntry);
1035 bGMean[ic]->GetEntry(tEntry);
1036 bGSigma[ic]->GetEntry(tEntry);
1039 if ((gausFrac[ic]->size() != gausMean[ic]->size()) ||
1040 (gausFrac[ic]->size() != gausSigma[ic]->size())) {
1042 B2ERROR(
"The TTSPar vectors for PMT " << serialNum <<
", channel " << ic + 1 <<
" have different sizes! Skipping channel...");
1046 for (uint iv = 0; iv < gausFrac[ic]->size(); iv++) {
1047 pmtTtsPar->appendGaussian(ic + 1,
1048 gausFrac[ic]->at(iv),
1049 gausMean[ic]->at(iv),
1050 gausSigma[ic]->at(iv));
1060 B2RESULT(
"PMT TTS parameters imported to database for " << countPMTs <<
" PMT's.");
1067 int firstExp,
int firstRun,
1068 int lastExp,
int lastRun)
1074 static const int nChann = 16;
1075 std::string* serialNum = 0;
1077 TH1F* histo[nChann] = {0};
1080 TFile* file = TFile::Open(fileName.c_str(),
"r");
1082 B2ERROR(
"Cannot open the file " << fileName);
1085 TTree* tTtsHisto =
static_cast<TTree*
>(file->Get(treeName.c_str()));
1087 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
1092 tTtsHisto->SetBranchAddress(
"serialNum", &serialNum);
1093 tTtsHisto->SetBranchAddress(
"hv", &hv);
1094 for (
int ic = 0; ic < nChann; ic++) {
1095 TString hString =
"hist_ch";
1097 tTtsHisto->SetBranchAddress(hString, &histo[ic]);
1103 for (
int ient = 0; ient < tTtsHisto->GetEntries(); ient++) {
1105 tTtsHisto->GetEntry(ient);
1110 B2INFO(
"Saving TTS histograms for PMT " << *serialNum <<
", HV = " << hv);
1112 auto* pmtTtsHisto = pmtTtsHistos.
appendNew(*serialNum, hv);
1113 for (
int ic = 0; ic < nChann; ic++) {
1114 pmtTtsHisto->setHistogram(ic + 1, histo[ic]);
1121 pmtTtsHistos.
import(iov);
1123 B2RESULT(
"Imported " << countHists <<
" sets of TTS histograms from " << fileName <<
" file.");
1129 int firstExp,
int firstRun,
1130 int lastExp,
int lastRun)
1138 TFile* file = TFile::Open(fileName.c_str());
1140 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
1143 TTree* tr =
static_cast<TTree*
>(file->Get(
"tree"));
1145 B2ERROR(
"No TTree with name tree found in " << fileName);
1155 float threshold = -1;
1156 float efficiency = -1;
1157 float chisquare = -1;
1159 tr->SetBranchAddress(
"slotId", &slotId);
1160 tr->SetBranchAddress(
"pixelId", &pixelId);
1161 tr->SetBranchAddress(
"p1UseIntegral", &p1);
1162 tr->SetBranchAddress(
"p2UseIntegral", &p2);
1163 tr->SetBranchAddress(
"x0UseIntegral", &x0);
1164 tr->SetBranchAddress(
"thresholdForIntegral", &threshold);
1165 tr->SetBranchAddress(
"efficiencyUseIntegral", &efficiency);
1166 tr->SetBranchAddress(
"chisquareUseIntegral", &chisquare);
1167 tr->SetBranchAddress(
"ndfUseIntegral", &ndf);
1170 if (!channelMapper.isValid()) {
1171 B2ERROR(
"No valid channel mapper found");
1176 long nEntries = tr->GetEntries();
1177 std::map<short, float> reducedChisqMap;
1178 for (
long iEntry = 0 ; iEntry < nEntries ; iEntry++) {
1179 tr->GetEntry(iEntry);
1181 if (efficiency < 0)
continue;
1183 if (!channelMapper.isPixelIDValid(pixelId)) {
1184 B2ERROR(
"invalid pixelID" << pixelId);
1187 auto channel = channelMapper.getChannel(pixelId);
1188 short globalChannelNumber = slotId * 1000 + channel;
1189 float redChisq = chisquare / ndf;
1193 if (reducedChisqMap.count(globalChannelNumber) == 0
1194 or reducedChisqMap[globalChannelNumber] > redChisq) {
1195 reducedChisqMap[globalChannelNumber] = redChisq;
1196 calChannelPulseHeight->setParameters(slotId, channel, x0, p1, p2);
1197 calChannelThresholdEff->setThrEff(slotId, channel, efficiency, (
short)threshold);
1199 if (redChisq > 10.) {
1200 calChannelPulseHeight->setUnusable(slotId, channel);
1201 calChannelThresholdEff->setUnusable(slotId, channel);
1208 calChannelPulseHeight.
import(iov);
1209 calChannelThresholdEff.
import(iov);
1211 B2RESULT(
"Imported channel-by-channel gain and efficiency data from fitting of pulse height distribution for "
1212 << reducedChisqMap.size() <<
" channels from " << fileName <<
" file.");
1224 TFile file(outFileName.c_str(),
"recreate");
1227 for (
const auto& element : elements) {
1229 B2INFO(
"serialNum = " << element.getSerialNumber() <<
", HV = " << element.getHV());
1230 for (
int ic = 0; ic < element.getNumOfPixels(); ic++) {
1231 const auto* ttsHisto = element.getHistogram(ic + 1);
1232 if (ttsHisto) ttsHisto->Write();
1242 int extraWin,
int offset,
1243 int expNo,
int firstRun,
int lastRun)
1249 std::vector<int> writeDepths;
1250 for (
int i = 0; i < 3; i++) {
1251 writeDepths.push_back(214);
1252 writeDepths.push_back(212);
1253 writeDepths.push_back(214);
1255 feSetting->setWriteDepths(writeDepths);
1256 feSetting->setLookbackWindows(lookback);
1257 feSetting->setReadoutWindows(readoutWin);
1258 feSetting->setExtraWindows(extraWin);
1259 feSetting->setOffset(offset);
1262 std::vector<int> shifts = {0, 0, 1, 1, 1, 2};
1263 feSetting->setWindowShifts(shifts);
1268 B2INFO(
"Front-end settings imported for exp " << expNo <<
" run " << firstRun <<
1274 int lastExp,
int lastRun)
1279 moduleAlignment.
import(iov);
1280 B2INFO(
"Dummy TOPCalModuleAlignment imported");
1285 int lastExp,
int lastRun)
1291 B2INFO(
"Dummy TOPCalModuleT0 imported");
1296 int lastExp,
int lastRun)
1302 B2INFO(
"Dummy TOPCalChannelT0 imported");
1307 int lastExp,
int lastRun)
1313 B2INFO(
"Dummy TOPCalTimebase imported");
1318 int lastExp,
int lastRun)
1323 channelNoise.
import(iov);
1324 B2INFO(
"Dummy TOPCalChannelNoise imported");
1329 int lastExp,
int lastRun)
1335 B2INFO(
"Dummy TOPCalChannelPulseHeight imported");
1340 int lastExp,
int lastRun)
1346 B2INFO(
"Dummy TOPCalChannelRQE imported");
1351 int lastExp,
int lastRun)
1356 channelThresholdEff.
import(iov);
1357 B2INFO(
"Dummy TOPCalChannelThresholdEff imported");
1362 int lastExp,
int lastRun)
1367 channelThreshold.
import(iov);
1368 B2INFO(
"Dummy TOPCalChannelThreshold imported");
1373 int lastExp,
int lastRun)
1379 B2INFO(
"Dummy TOPCalCommonT0 imported");
1384 int lastExp,
int lastRun)
1389 integratedCharge.
import(iov);
1390 B2INFO(
"Dummy TOPCalIntegratedCharge imported");
1395 int lastExp,
int lastRun)
1401 B2INFO(
"Dummy TOPCalAsicShift imported");
1406 B2ERROR(
"Function disabled since the corrected payload TOPPmtQEs already imported");
1412 for (
const auto& pmt : pmtQEData) {
1413 auto* pmtCorr = pmtQECorrected.
appendNew(pmt.getSerialNumber(),
1414 pmt.getLambdaFirst(),
1415 pmt.getLambdaStep(),
1418 for (
unsigned pmtPixel = 1; pmtPixel <= TOPPmtQE::c_NumPmtPixels; pmtPixel++) {
1419 auto qeData = pmt.getQE(pmtPixel);
1420 float lambda = pmt.getLambdaFirst();
1421 float step = pmt.getLambdaStep();
1422 for (
auto& qe : qeData) {
1424 double reflectance = pow((n - 1) / (n + 1), 2);
1425 qe /= (1 - reflectance);
1428 pmtCorr->setQE(pmtPixel, qeData);
1433 pmtQECorrected.
import(iov);
1435 B2RESULT(
"Corrected PMT QE data imported to database for "
1436 << pmtQECorrected.
getEntries() <<
" PMT's.");
1442 int firstExp,
int firstRun,
1443 int lastExp,
int lastRun)
1446 std::vector<double> params;
1447 if (PyList_Check(list)) {
1448 for (Py_ssize_t i = 0; i < PyList_Size(list); i++) {
1449 PyObject* value = PyList_GetItem(list, i);
1450 params.push_back(PyFloat_AsDouble(value));
1451 B2INFO(i <<
" " << params.back());
1454 B2ERROR(
"Input Python object is not a list");
1460 timeWalk->set(params, a, b);
1465 B2RESULT(
"Time-walk constants imported");
1476 vector<double> timeAxis;
1477 for (
int i = 0; i < 256; i++) {
1478 timeAxis.push_back(syncTimeBase / 128.0 * i);
1483 for (
unsigned scrodID = 0; scrodID < 64; scrodID++) {
1484 for (
unsigned channel = 0; channel < 128; channel++) {
1485 timeBase->append(scrodID, channel, timeAxis);
1489 if (runNumber == 3) {
1492 for (
unsigned scrodID = 0; scrodID < 64; scrodID++) {
1493 for (
unsigned channel = 0; channel < 128; channel++) {
1494 timeBase->append(scrodID, channel, timeAxis);
1510 auto* pmtGain = pmtGains.
appendNew(
"JT00123");
1511 pmtGain->setNominalHV(3520);
1512 for (
unsigned channel = 1; channel <= 16; channel++) {
1513 pmtGain->setPmtPixelData(channel, -13.77, 0.0042, 0.4);
1516 pmtGain = pmtGains.
appendNew(
"JT02135");
1517 pmtGain->setNominalHV(3450);
1518 for (
unsigned channel = 1; channel <= 16; channel++) {
1519 pmtGain->setPmtPixelData(channel, -12.77, 0.0045, 0.4);
1522 for (
const auto& gain : pmtGains) gain.print();
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing arrays of objects in the database.
Class for importing array of objects to the database.
T * appendNew()
Construct a new T object at the end of the array.
int getEntries() const
Returns number of objects in the array.
bool import(const IntervalOfValidity &iov)
Import the object to database.
virtual void addEventDependency(unsigned int eventNumber)
add event dependency
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class for accessing objects in the database.
A class that describes the interval of experiments/runs for which an object in the database is valid.
const TOPNominalTDC & getNominalTDC() const
Returns nominal time-to-digit conversion parameters.
unsigned getNumModules() const
Returns number of modules.
double getSyncTimeBase() const
Returns synchronization time base (time width of c_syncWindows)
Calibration constants of a single ASIC channel: time axis (sample times)
static double getPhaseIndex(double energy)
Returns phase refractive index of quartz at given photon energy.
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
const ChannelMapper & getChannelMapper() const
Returns default channel mapper (mapping of channels to pixels)
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
const FrontEndMapper & getFrontEndMapper() const
Returns front-end mapper (mapping of SCROD's to positions within TOP modules)
static const double c_hc
Planck constant times speed of light in [eV*nm].
static void importDummyCalChannelNoise(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelNoise DB objects
static void importPmtTTSHisto(const std::string &fileName, const std::string &treeName="ttsPmtHisto", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import histograms used for PMT TTS determination.
static void importDummyCalTimebase(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalTimebase DB objects
static void importDummyCalChannelRQE(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelRQE DB objects
static void printSampleTimeCalibrationInfo()
Prints sample time calibration info about constants stored in database.
static void importModuleT0Calibration(const std::string &fileName, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import module T0 calibration constants to database The input is the text file.
static void importAsicShifts_BS13d(double s0, double s1, double s2, double s3, int expNo, int firstRun, int lastRun)
Import ASIC shifts of BS13d.
static void importDummyCalChannelT0(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelT0 DB objects
static void importDummyCalChannelThreshold(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelThreshold DB objects
static void importPmtQEData(const std::string &fileName, const std::string &treeName="qePmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT Quantum Efficiency data to database.
static void importDummyCalModuleT0(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalCalModuleT0 DB objects
static void importDummyCalCommonT0(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalCommonT0 DB objects
static void importDummyCalAsicShift(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalAsicShift DB objects
static void importChannelMask(const std::string &fileName, int expNo, int firstRun, int lastRun)
Import channel mask from a root file (given as 1D histograms, one per slot).
static void importPmtGainData(const std::string &fileName, const std::string &treeName="gainPmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT gain parameters data to database.
static void importDummyCalIntegratedCharge(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalIntegratedCharge DB objects
static void importTimeWalk(PyObject *list, double a, double b, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
payload TOPCalTimeWalk import parameters for time-walk correction and electronic time resolution tuni...
static void importFrontEndSettings(int lookback, int readoutWin, int extraWin, int offset, int expNo, int firstRun, int lastRun)
Import front-end settings.
static void importDummyCalChannelThresholdEff(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelThresholdEff DB objects
static void correctTOPPmtQE()
correct QE values in database for the reflection on window surface be sure that you run the function ...
static void printSampleTimeCalibration()
Print sample time calibration constants stored in database.
static void importTest()
for testing purposes only!
static void importPmtTTSPar(const std::string &fileName, const std::string &treeName="ttsPmtPar", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import gaussians fitting the TTS distributions.
static void importDummyCalModuleAlignment(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalModuleAlignment DB objects
static void importPmtInstallationData(const std::string &fileName, const std::string &treeName="installationPmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT installation data to database.
static void importDummyCalChannelPulseHeight(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelPulseHeight DB objects
static void importLocalT0Calibration(const std::string &fileNames, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import channel-by-channel T0 calibration constants to database The input is the root file with ntuple...
static void importCommonT0(double value, double error, int expNo, int firstRun, int lastRun, bool roughlyCalibrated=false)
Import common T0 calibration constants.
static void importOfflineCommonT0Calibration(const std::string &fileName, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import common T0 calibration constants derived form the offline data reprocessing to database The inp...
static void importModuleT0(const std::string &fileName, int expNo, int firstRun, int lastRun)
Import module T0 calibration constants The input is a root file with 1D histogram (name is "moduleT0"...
static void importPmtObsoleteData(const std::string &fileName, const std::string &treeName="obsPmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT specifications from Hamamatsu (not to be used!)
static void generateFakeChannelMask(double fractionDead, double fractionHot, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Generate and import a (random, fake) channel mask for testing.
std::vector< double > getTimeAxis() const
Returns time axis (sample times)
static void exportPmtTTSHisto(const std::string &outFileName="RetrievedHistos.root")
Example of exporting TTS histograms.
static void importPmtPulseHeightFitResult(const std::string &fileName, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import fit results of pulse height distribution for channel gain and threshold efficiency.
static void importSampleTimeCalibration(const std::string &fileNames, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import sample time calibration constants to database Output of TOPTimeBaseCalibrator (root files with...
static void importChannelT0(const std::string &fileName, int expNo, int firstRun, int lastRun)
Import channel T0 calibration constants The input is a root file with 1D histograms (one per slot,...
Abstract base class for different kinds of events.