9#include <top/calibration/TOPPhotonYieldsAlgorithm.h>
10#include <top/dbobjects/TOPCalPhotonYields.h>
28 setDescription(
"Calibration algorithm for photon pixel yields aimed for PMT ageing studies and for finding optically decoupled PMT's");
38 string expNo = to_string(expRun[0].first);
39 while (expNo.length() < 4) expNo.insert(0,
"0");
40 string runNo = to_string(expRun[0].second);
41 while (runNo.length() < 5) runNo.insert(0,
"0");
42 string outputFileName =
"photonYields-e" + expNo +
"-r" + runNo +
".root";
43 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
47 auto numTracks = getObjectPtr<TH1F>(
"numTracks");
49 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'numTracks' not found");
55 auto timeStamp = getObjectPtr<TProfile>(
"timeStamp");
57 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'timeStamp' not found");
66 dbobject->setTimeStamp(timeStamp->GetBinContent(1), timeStamp->GetBinError(1));
70 int numModules = numTracks->GetNbinsX();
71 for (
int slot = 1; slot <= numModules; slot++) {
72 string slotName = (slot < 10) ?
"_0" + to_string(slot) :
"_" + to_string(slot);
74 auto signalHits = getObjectPtr<TH1F>(
"signalHits" + slotName);
76 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'signalHits' for slot " << slot <<
" not found");
83 auto bkgHits = getObjectPtr<TH1F>(
"bkgHits" + slotName);
85 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'bkgHits' for slot " << slot <<
" not found");
92 auto activePixels = getObjectPtr<TH1F>(
"activePixels" + slotName);
93 if (not activePixels) {
94 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'activePixels' for slot " << slot <<
" not found");
99 activePixels->Write();
101 auto alphaLow = getObjectPtr<TH1F>(
"alphaLow" + slotName);
103 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'alphaLow' for slot " << slot <<
" not found");
111 auto alphaHigh = getObjectPtr<TH1F>(
"alphaHigh" + slotName);
113 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'alphaHigh' for slot " << slot <<
" not found");
121 auto pulseHeights = getObjectPtr<TH2F>(
"pulseHeights" + slotName);
122 if (not pulseHeights) {
123 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'pulseHeights' for slot " << slot <<
" not found");
128 pulseHeights->Write();
130 auto muonZ = getObjectPtr<TH1F>(
"muonZ" + slotName);
132 B2ERROR(
"TOPPhotonYieldsAlgorithm: histogram 'muonZ' for slot " << slot <<
" not found");
139 auto* photonYields = (TH1F*) signalHits->Clone(
"tmp1");
140 photonYields->Add(signalHits.get(), bkgHits.get(), 1, -1);
141 for (
int bin = 1; bin <= activePixels->GetNbinsX(); bin++) activePixels->SetBinError(bin, 0);
142 photonYields->Divide(activePixels.get());
144 auto* bkgYields = (TH1F*) bkgHits->Clone(
"tmp2");
145 bkgYields->Divide(activePixels.get());
147 auto* alphaRatio = (TH1F*) alphaHigh->Clone(
"tmp2");
148 alphaRatio->Divide(alphaHigh.get(), alphaLow.get());
151 dbobject->set(slot, photonYields, bkgYields, alphaRatio, activePixels.get(), pulseHeights.get(), muonZ.get());
169 const double a[] = {1.50301, 1.16907, 1.00912, 0.943571, 0.889658, 0.93418, 1.01846, 0.953715};
170 const double b[] = {-1.02531, -0.111269, 0.0731595, -0.121119, -0.79083, -1.00261, -1.41012, -1.23368};
171 const double c[] = {8.47995, 3.18639, 1.9513, 2.58279, 4.79672, 5.5659, 7.558, 6.71336};
172 const double d[] = {1.49743, 1.17224, 1.02211, 0.928502, 0.829334, 0.849355, 0.921871, 0.850427};
174 int row = (bin - 1) / 64;
175 if (row < 0 or row > 7)
return 1;
177 int col = (bin - 1) % 64 + 1;
178 if (col == 1 or col == 64)
return d[row];
180 double x = (col - 32.5) / 64.;
181 return a[row] + b[row] * pow(x, 2) + c[row] * pow(x, 4);
187 for (
int bin = 1; bin <= h->GetNbinsX(); bin++) {
189 h->SetBinContent(bin, h->GetBinContent(bin) / s);
190 h->SetBinError(bin, h->GetBinError(bin) / s);
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_Failure
Failed =3 in Python.
Class to store photon pixel yields for PMT ageing studies, and equalized alpha ratios for finding opt...
void equalize(TH1F *h)
Equalize alpha ratio histogram.
virtual EResult calibrate() final
algorithm implementation
TOPPhotonYieldsAlgorithm()
Constructor.
double getEqualizingValue(int bin)
Returns equalizing value for alpha ratio.
Abstract base class for different kinds of events.