9#include <top/calibration/TOPPulseHeightAlgorithm.h>
11#include <TDirectory.h>
29 setDescription(
"Calibration algorithm for pulse-height and threshold efficiency calibration");
39 string expNo = to_string(expRun[0].first);
40 while (expNo.length() < 4) expNo.insert(0,
"0");
41 string runNo = to_string(expRun[0].second);
42 while (runNo.length() < 5) runNo.insert(0,
"0");
43 string outputFileName =
"pulseHeight-e" + expNo +
"-r" + runNo +
".root";
44 m_file = TFile::Open(outputFileName.c_str(),
"recreate");
46 m_tree =
new TTree(
"tree",
"pulse-height calibration results");
66 auto h1a = getObjectPtr<TH1F>(
"time");
67 if (h1a) h1a->Write();
68 auto h1b = getObjectPtr<TH1F>(
"time_sel");
69 if (h1b) h1b->Write();
70 auto h2a = getObjectPtr<TH2F>(
"ph_vs_width");
71 if (h2a) h2a->Write();
72 auto h2b = getObjectPtr<TH2F>(
"ph_vs_width_sel");
73 if (h2b) h2b->Write();
82 TDirectory* oldDir = gDirectory;
84 for (
int slot = 1; slot <= 16; slot++) {
86 string name =
"ph_slot_" + to_string(slot);
87 auto h = getObjectPtr<TH2F>(name);
90 name =
"slot_" + to_string(slot);
91 oldDir->mkdir(name.c_str())->cd();
95 B2INFO(
"slot " << slot <<
": " << n <<
"/512 channels successfully fitted");
125 for (
int ch = 0; ch < h2d->GetNbinsX(); ch++) {
127 string chan = to_string(ch);
128 while (chan.length() < 3) chan.insert(0,
"0");
129 string name =
"chan_" + chan;
130 auto* h = h2d->ProjectionY(name.c_str(), ch + 1, ch + 1);
131 string title =
"slot " + to_string(
m_slot) +
" channel " + to_string(ch);
132 h->SetTitle(title.c_str());
136 if (status == 0 and
m_good) {
152 double xmin = h->GetXaxis()->GetXmin();
153 double xmax = h->GetXaxis()->GetXmax();
155 auto* func =
new TF1(
"func",
"[0]*x/[1]*exp(-pow(x/[1],[2]))", xmin, xmax);
161 func->SetParameter(1, x0);
162 func->SetParameter(2, p2);
164 int status = h->Fit(func,
"LRSQ",
"",
m_xmin, xmax);
166 m_x0 = func->GetParameter(1);
168 m_p2 = func->GetParameter(2);
169 m_x0err = func->GetParError(1);
171 m_p2err = func->GetParError(2);
172 m_chi2 = func->GetChisquare();
188 m_ndf = -func->GetNumberFreeParameters();
189 for (
int i = 0; i < h->GetNbinsX(); i++) {
190 double x = h->GetBinCenter(i + 1);
192 fabove += func->Eval(x);
193 count += h->GetBinContent(i);
194 if (h->GetBinContent(i) > 0)
m_ndf++;
196 fbelow += func->Eval(x);
199 double integral = (fbelow + fabove) * count / fabove;
200 return h->GetSumOfWeights() / integral;
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_NotEnoughData
Needs more data =2 in Python.
Pulse height parameterizations for all 512 channels of 16 modules.
void setParameters(int moduleID, unsigned channel, double x0, double p1, double p2)
Sets calibration for a single channel and switches status to calibrated.
Class to store the threshold efficiency (i.e.
void setThrEff(int moduleID, unsigned channel, float ThrEff, short offlineThreshold)
Sets the threshold efficiency and correspolding threshold for a single channel and switches status to...
int fitChannels(std::shared_ptr< TH2F > h)
Fit pulse-height distributions of a single module.
int m_minEntries
minimal number of histogram entries to perform fit
double m_xmin
fit range lower limit [ADC counts]
TTree * m_tree
output ntuple
double getEfficiency(TH1D *h, TF1 *func)
Calculate and return threshold efficiency.
int fitPulseHeight(TH1D *h)
Fit pulse-height distribution of a single channel with P(x) = (x/x0)^p1 * exp(-(x/x0)^p2) and p1 = 1.
unsigned m_channel
channel ID
float m_effi
threshold efficiency
virtual EResult calibrate() final
algorithm implementation
TOPCalChannelThresholdEff * m_thresholdEffi
threshold efficiencies
TOPPulseHeightAlgorithm()
Constructor.
float m_p1
fitted distribution parameter p1
float m_meanFunc
fitted distribution mean value
float m_p2
fitted distribution parameter p2
int m_fitStatus
fit status
float m_x0err
error on x0 [ADC counts]
float m_x0
fitted distribution parameter x0 [ADC counts]
bool m_good
on true fit is good
double m_minCalibrated
min.
int m_numPhot
number of photons (histogram entries)
float m_meanHist
histogram mean value
TOPCalChannelPulseHeight * m_pulseHeight
parametrized PH distributions
Abstract base class for different kinds of events.