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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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.");
1068 int firstExp,
int firstRun,
1069 int lastExp,
int lastRun)
1075 static const int nChann = 16;
1076 std::string* serialNum = 0;
1078 TH1F* histo[nChann] = {0};
1081 TFile* file = TFile::Open(fileName.c_str(),
"r");
1083 B2ERROR(
"Cannot open the file " << fileName);
1086 TTree* tTtsHisto = (TTree*)file->Get(treeName.c_str());
1088 B2ERROR(
"No TTree with name " << treeName <<
" in file " << fileName);
1093 tTtsHisto->SetBranchAddress(
"serialNum", &serialNum);
1094 tTtsHisto->SetBranchAddress(
"hv", &hv);
1095 for (
int ic = 0; ic < nChann; ic++) {
1096 TString hString =
"hist_ch";
1098 tTtsHisto->SetBranchAddress(hString, &histo[ic]);
1104 for (
int ient = 0; ient < tTtsHisto->GetEntries(); ient++) {
1106 tTtsHisto->GetEntry(ient);
1111 B2INFO(
"Saving TTS histograms for PMT " << *serialNum <<
", HV = " << hv);
1113 auto* pmtTtsHisto = pmtTtsHistos.
appendNew(*serialNum, hv);
1114 for (
int ic = 0; ic < nChann; ic++) {
1115 pmtTtsHisto->setHistogram(ic + 1, histo[ic]);
1122 pmtTtsHistos.
import(iov);
1124 B2RESULT(
"Imported " << countHists <<
" sets of TTS histograms from " << fileName <<
" file.");
1130 int firstExp,
int firstRun,
1131 int lastExp,
int lastRun)
1139 TFile* file = TFile::Open(fileName.c_str());
1141 B2ERROR(
"openFile: " << fileName <<
" *** failed to open");
1144 TTree* tr = (TTree*)file->Get(
"tree");
1146 B2ERROR(
"No TTree with name tree found in " << fileName);
1156 float threshold = -1;
1157 float efficiency = -1;
1158 float chisquare = -1;
1160 tr->SetBranchAddress(
"slotId", &slotId);
1161 tr->SetBranchAddress(
"pixelId", &pixelId);
1162 tr->SetBranchAddress(
"p1UseIntegral", &p1);
1163 tr->SetBranchAddress(
"p2UseIntegral", &p2);
1164 tr->SetBranchAddress(
"x0UseIntegral", &x0);
1165 tr->SetBranchAddress(
"thresholdForIntegral", &threshold);
1166 tr->SetBranchAddress(
"efficiencyUseIntegral", &efficiency);
1167 tr->SetBranchAddress(
"chisquareUseIntegral", &chisquare);
1168 tr->SetBranchAddress(
"ndfUseIntegral", &ndf);
1171 if (!channelMapper.isValid()) {
1172 B2ERROR(
"No valid channel mapper found");
1177 long nEntries = tr->GetEntries();
1178 std::map<short, float> reducedChisqMap;
1179 for (
long iEntry = 0 ; iEntry < nEntries ; iEntry++) {
1180 tr->GetEntry(iEntry);
1182 if (efficiency < 0)
continue;
1184 if (!channelMapper.isPixelIDValid(pixelId)) {
1185 B2ERROR(
"invalid pixelID" << pixelId);
1188 auto channel = channelMapper.getChannel(pixelId);
1189 short globalChannelNumber = slotId * 1000 + channel;
1190 float redChisq = chisquare / ndf;
1194 if (reducedChisqMap.count(globalChannelNumber) == 0
1195 or reducedChisqMap[globalChannelNumber] > redChisq) {
1196 reducedChisqMap[globalChannelNumber] = redChisq;
1197 calChannelPulseHeight->setParameters(slotId, channel, x0, p1, p2);
1198 calChannelThresholdEff->setThrEff(slotId, channel, efficiency, (
short)threshold);
1200 if (redChisq > 10.) {
1201 calChannelPulseHeight->setUnusable(slotId, channel);
1202 calChannelThresholdEff->setUnusable(slotId, channel);
1209 calChannelPulseHeight.
import(iov);
1210 calChannelThresholdEff.
import(iov);
1212 B2RESULT(
"Imported channel-by-channel gain and efficiency data from fitting of pulse height distribution for "
1213 << reducedChisqMap.size() <<
" channels from " << fileName <<
" file.");
1225 TFile file(outFileName.c_str(),
"recreate");
1228 for (
const auto& element : elements) {
1230 B2INFO(
"serialNum = " << element.getSerialNumber() <<
", HV = " << element.getHV());
1231 for (
int ic = 0; ic < element.getNumOfPixels(); ic++) {
1232 const auto* ttsHisto = element.getHistogram(ic + 1);
1233 if (ttsHisto) ttsHisto->Write();
1243 int extraWin,
int offset,
1244 int expNo,
int firstRun,
int lastRun)
1250 std::vector<int> writeDepths;
1251 for (
int i = 0; i < 3; i++) {
1252 writeDepths.push_back(214);
1253 writeDepths.push_back(212);
1254 writeDepths.push_back(214);
1256 feSetting->setWriteDepths(writeDepths);
1257 feSetting->setLookbackWindows(lookback);
1258 feSetting->setReadoutWindows(readoutWin);
1259 feSetting->setExtraWindows(extraWin);
1260 feSetting->setOffset(offset);
1263 std::vector<int> shifts = {0, 0, 1, 1, 1, 2};
1264 feSetting->setWindowShifts(shifts);
1269 B2INFO(
"Front-end settings imported for exp " << expNo <<
" run " << firstRun <<
1275 int lastExp,
int lastRun)
1280 moduleAlignment.
import(iov);
1281 B2INFO(
"Dummy TOPCalModuleAlignment imported");
1286 int lastExp,
int lastRun)
1292 B2INFO(
"Dummy TOPCalModuleT0 imported");
1297 int lastExp,
int lastRun)
1303 B2INFO(
"Dummy TOPCalChannelT0 imported");
1308 int lastExp,
int lastRun)
1314 B2INFO(
"Dummy TOPCalTimebase imported");
1319 int lastExp,
int lastRun)
1324 channelNoise.
import(iov);
1325 B2INFO(
"Dummy TOPCalChannelNoise imported");
1330 int lastExp,
int lastRun)
1336 B2INFO(
"Dummy TOPCalChannelPulseHeight imported");
1341 int lastExp,
int lastRun)
1347 B2INFO(
"Dummy TOPCalChannelRQE imported");
1352 int lastExp,
int lastRun)
1357 channelThresholdEff.
import(iov);
1358 B2INFO(
"Dummy TOPCalChannelThresholdEff imported");
1363 int lastExp,
int lastRun)
1368 channelThreshold.
import(iov);
1369 B2INFO(
"Dummy TOPCalChannelThreshold imported");
1374 int lastExp,
int lastRun)
1380 B2INFO(
"Dummy TOPCalCommonT0 imported");
1385 int lastExp,
int lastRun)
1390 integratedCharge.
import(iov);
1391 B2INFO(
"Dummy TOPCalIntegratedCharge imported");
1396 int lastExp,
int lastRun)
1402 B2INFO(
"Dummy TOPCalAsicShift imported");
1407 B2ERROR(
"Function disabled since the corrected payload TOPPmtQEs already imported");
1413 for (
const auto& pmt : pmtQEData) {
1414 auto* pmtCorr = pmtQECorrected.
appendNew(pmt.getSerialNumber(),
1415 pmt.getLambdaFirst(),
1416 pmt.getLambdaStep(),
1419 for (
unsigned pmtPixel = 1; pmtPixel <= TOPPmtQE::c_NumPmtPixels; pmtPixel++) {
1420 auto qeData = pmt.getQE(pmtPixel);
1421 float lambda = pmt.getLambdaFirst();
1422 float step = pmt.getLambdaStep();
1423 for (
auto& qe : qeData) {
1425 double reflectance = pow((n - 1) / (n + 1), 2);
1426 qe /= (1 - reflectance);
1429 pmtCorr->setQE(pmtPixel, qeData);
1434 pmtQECorrected.
import(iov);
1436 B2RESULT(
"Corrected PMT QE data imported to database for "
1437 << pmtQECorrected.
getEntries() <<
" PMT's.");
1443 int firstExp,
int firstRun,
1444 int lastExp,
int lastRun)
1447 std::vector<double> params;
1448 if (PyList_Check(list)) {
1449 for (Py_ssize_t i = 0; i < PyList_Size(list); i++) {
1450 PyObject* value = PyList_GetItem(list, i);
1451 params.push_back(PyFloat_AsDouble(value));
1452 B2INFO(i <<
" " << params.back());
1455 B2ERROR(
"Input Python object is not a list");
1461 timeWalk->set(params, a, b);
1466 B2RESULT(
"Time-walk constants imported");
1477 vector<double> timeAxis;
1478 for (
int i = 0; i < 256; i++) {
1479 timeAxis.push_back(syncTimeBase / 128.0 * i);
1484 for (
unsigned scrodID = 0; scrodID < 64; scrodID++) {
1485 for (
unsigned channel = 0; channel < 128; channel++) {
1486 timeBase->append(scrodID, channel, timeAxis);
1490 if (runNumber == 3) {
1493 for (
unsigned scrodID = 0; scrodID < 64; scrodID++) {
1494 for (
unsigned channel = 0; channel < 128; channel++) {
1495 timeBase->append(scrodID, channel, timeAxis);
1511 auto* pmtGain = pmtGains.
appendNew(
"JT00123");
1512 pmtGain->setNominalHV(3520);
1513 for (
unsigned channel = 1; channel <= 16; channel++) {
1514 pmtGain->setPmtPixelData(channel, -13.77, 0.0042, 0.4);
1517 pmtGain = pmtGains.
appendNew(
"JT02135");
1518 pmtGain->setNominalHV(3450);
1519 for (
unsigned channel = 1; channel <= 16; channel++) {
1520 pmtGain->setPmtPixelData(channel, -12.77, 0.0045, 0.4);
1523 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 synchonization time base (time width of c_syncWindows)
Calibration constants of a singe ASIC channel: time axis (sample times)
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].
double getPhaseIndex(double energy) const
Returns phase refractive index of quartz at given photon energy.
void importDummyCalChannelNoise(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelNoise DB objects
void importModuleT0(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"...
void importDummyCalTimebase(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalTimebase DB objects
void importDummyCalChannelRQE(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelRQE DB objects
void printSampleTimeCalibrationInfo()
Prints sample time calibration info about constants stored in database.
void importPmtQEData(std::string fileName, std::string treeName="qePmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT Quantum Efficiency data to database.
void importModuleT0Calibration(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.
void importAsicShifts_BS13d(double s0, double s1, double s2, double s3, int expNo, int firstRun, int lastRun)
Import ASIC shifts of BS13d.
void importDummyCalChannelT0(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelT0 DB objects
void importDummyCalChannelThreshold(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelThreshold DB objects
void exportPmtTTSHisto(std::string outFileName="RetrievedHistos.root")
Example of exporting TTS histograms.
void importPmtTTSHisto(std::string fileName, std::string treeName="ttsPmtHisto", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import histograms used for PMT TTS determination.
void importDummyCalModuleT0(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalCalModuleT0 DB objects
void importPmtPulseHeightFitResult(std::string fileName, int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import fit results of pulse height disribution for channel gain and threshold efficiency.
void importDummyCalCommonT0(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalCommonT0 DB objects
void importChannelT0(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,...
void importDummyCalAsicShift(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalAsicShift DB objects
void importDummyCalIntegratedCharge(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalIntegratedCharge DB objects
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...
void importFrontEndSettings(int lookback, int readoutWin, int extraWin, int offset, int expNo, int firstRun, int lastRun)
Import front-end settings.
void importPmtObsoleteData(std::string fileName, 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!)
void importChannelMask(std::string fileName, int expNo, int firstRun, int lastRun)
Import channel mask from a root file (given as 1D histograms, one per slot).
void importSampleTimeCalibration(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...
void importDummyCalChannelThresholdEff(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelThresholdEff DB objects
void correctTOPPmtQE()
correct QE values in database for the reflection on window surface be sure that you run the function ...
void printSampleTimeCalibration()
Print sample time calibration constants stored in database.
void importTest()
for testing purposes only! - will be removed ...
void importDummyCalModuleAlignment(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalModuleAlignment DB objects
void importPmtTTSPar(std::string fileName, std::string treeName="ttsPmtPar", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import gaussians fitting the TTS distributions.
void importDummyCalChannelPulseHeight(int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
import a dummy payload of TOPCalChannelPulseHeight DB objects
void importCommonT0(double value, double error, int expNo, int firstRun, int lastRun, bool roughlyCalibrated=false)
Import common T0 calibration constants.
void importLocalT0Calibration(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...
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)
void importPmtInstallationData(std::string fileName, std::string treeName="installationPmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT installation data to database.
void importPmtGainData(std::string fileName, std::string treeName="gainPmtData", int firstExp=0, int firstRun=0, int lastExp=-1, int lastRun=-1)
Import PMT gain parameters data to database.
void importOfflineCommonT0Calibration(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...
Abstract base class for different kinds of events.