9#include <framework/logging/Logger.h>
10#include <pxd/calibration/PXDCalibrationUtilities.h>
11#include <vxd/dataobjects/VxdID.h>
20#include <boost/format.hpp>
35 void getNumberOfBins(
const std::shared_ptr<TH1I>& histo_ptr,
unsigned short& nBinsU,
unsigned short& nBinsV)
37 set<unsigned short> uBinSet;
38 set<unsigned short> vBinSet;
41 for (
auto histoBin = 1; histoBin <= histo_ptr->GetXaxis()->GetNbins(); histoBin++) {
43 string label = histo_ptr->GetXaxis()->GetBinLabel(histoBin);
46 istringstream stream(label);
48 getline(stream, token,
'_');
49 getline(stream, token,
'_');
50 unsigned short uBin = std::stoi(token);
52 getline(stream, token,
'_');
53 unsigned short vBin = std::stoi(token);
59 if (uBinSet.empty() || vBinSet.empty()) {
60 B2FATAL(
"Not able to determine the grid size. Something is wrong with collected data.");
62 nBinsU = *uBinSet.rbegin() + 1;
63 nBinsV = *vBinSet.rbegin() + 1;
70 set<unsigned short> sensorSet;
73 for (
auto histoBin = 1; histoBin <= histo_ptr->GetXaxis()->GetNbins(); histoBin++) {
75 string label = histo_ptr->GetXaxis()->GetBinLabel(histoBin);
78 istringstream stream(label);
80 getline(stream, token,
'_');
81 VxdID sensorID(token);
82 sensorSet.insert(sensorID.
getID());
84 return sensorSet.size();
90 auto size = signals.size();
94 }
else if (size <= 100) {
96 sort(signals.begin(), signals.end());
98 return (signals[size / 2 - 1] + signals[size / 2]) / 2;
100 return signals[size / 2];
106 nth_element(signals.begin(), signals.begin() + n, signals.end());
107 auto med = signals[n];
109 auto max_it = max_element(signals.begin(), signals.begin() + n);
110 med = (*max_it + med) / 2.0;
119 double probSums[1] = {0.5};
120 hist->GetQuantiles(1, quantiles, probSums);
127 auto size = hist->GetEntries();
128 if (size == 0)
return 0.0;
130 int max = hist->GetBinLowEdge(hist->GetNbinsX() + 1);
131 int min = hist->GetBinLowEdge(1);
134 TF1* landau =
new TF1(
"landau",
"TMath::Landau(x,[0],[1])*[2]", min, max);
135 landau->SetParNames(
"MPV",
"sigma",
"scale");
136 landau->SetParameters(1., 0.1, 1000);
137 landau->SetParLimits(0, 0., 3.);
139 Int_t status = hist->Fit(
"landau",
"Lq",
"", min, max);
140 double MPV = landau->GetParameter(
"MPV");
142 B2INFO(
"Fit result: " << status <<
" MPV " << MPV <<
" sigma " << landau->GetParameter(
"sigma")
143 <<
" scale " << landau->GetParameter(
"scale") <<
" chi2 " << landau->GetChisquare());
149 if (status == 0)
return MPV;
151 B2WARNING(
"Fit failed!. using default value.");
159 auto size = signals.size();
160 if (size == 0)
return 0.0;
163 double max = *max_element(signals.begin(), signals.end());
164 double min = *min_element(signals.begin(), signals.end());
167 TH1D* hist_signals =
new TH1D(
"",
"", max - min, min, max);
168 for (
auto it = signals.begin(); it != signals.end(); ++it) {
169 hist_signals->Fill(*it);
Class to uniquely identify a any structure of the PXD and SVD.
baseType getID() const
Get the unique id.
unsigned short getNumberOfSensors(const std::shared_ptr< TH1I > &histo_ptr)
Helper function to extract number of sensors from counter histogram labels.
void getNumberOfBins(const std::shared_ptr< TH1I > &histo_ptr, unsigned short &nBinsU, unsigned short &nBinsV)
Helper function to extract number of bins along u side and v side from counter histogram labels.
double CalculateMedian(std::vector< double > &signals)
Helper function to calculate a median from unsorted signal vector.
double FitLandau(TH1 *hist)
Helper function to estimate MPV from 1D histogram.
Abstract base class for different kinds of events.