21 smart_rebin_loop(
hist, cut_maxdev);
24 std::unique_ptr<double[]>
27 TH1D *h_clone = (TH1D *)
hist->Clone(
"h_clone");
28 h_clone->Scale(1.0 / h_clone->Integral());
30 auto histoVals = std::make_unique<double[]>(h_clone->GetNbinsX());
31 histoVals[0] = h_clone->GetBinContent(1);
32 for (
int i = 1;
i < h_clone->GetNbinsX();
i++) {
33 histoVals[
i] = histoVals[
i - 1] + h_clone->GetBinContent(
i + 1);
41 auto histoVals = histo_to_array(
hist);
44 (
int)TMath::BinarySearch(
hist->GetNbinsX(), histoVals.get(), random);
45 value =
hist->GetBinCenter(chosenBin + 2);
55 TH1 *
hist = vector_to_histo();
56 hist->SetName(
"hist");
57 auto histoVals = histo_to_array(
hist);
59 (
int)TMath::BinarySearch(
hist->GetNbinsX(), histoVals.get(), random);
60 value =
hist->GetBinCenter(chosenBin + 2);
67 double *
bins =
new double[m_HistoBorders.size()];
68 for (
unsigned int i = 0;
i < m_HistoBorders.size();
i++)
69 bins[
i] = m_HistoBorders[
i];
71 TH1 *h_out =
new TH1D(
"h_out",
"h_out", m_HistoBorders.size() - 1,
bins);
72 for (
int b = 1;
b <= h_out->GetNbinsX();
b++)
73 h_out->SetBinContent(
b, m_HistoContents[
b - 1]);
82 m_HistoContents.clear();
83 m_HistoBorders.clear();
86 get_change(
hist) * 1.000001;
90 TH1D *h_input = (TH1D *)
hist->Clone(
"h_input");
91 TH1D *h_output =
nullptr;
98 h_out = (TH1D *)h_input->Clone(
"h_out");
100 h_out = smart_rebin(h_input);
101 h_out->SetName(
"h_out");
104 maxdev = get_maxdev(
hist, h_out);
108 ATH_MSG_INFO(
"Iteration nr. " <<
i <<
" -----> change " << change
109 <<
" bins " << h_out->GetNbinsX()
110 <<
" -> maxdev=" << maxdev);
112 if (maxdev < cut_maxdev && h_out->GetNbinsX() > 5 &&
i < 1000) {
114 h_input = (TH1D *)h_out->Clone(
"h_input");
115 change = get_change(h_input) * 1.000001;
119 h_output = (TH1D *)h_input->Clone(
"h_output");
125 ATH_MSG_INFO(
"Info: Rebinned histogram has " << h_output->GetNbinsX()
130 for (
int b = 1;
b <= h_output->GetNbinsX();
b++)
131 m_HistoBorders.push_back((
float)h_output->GetBinLowEdge(
b));
132 m_HistoBorders.push_back((
float)h_output->GetXaxis()->GetXmax());
134 for (
int b = 1;
b < h_output->GetNbinsX();
b++)
135 m_HistoContents.push_back(h_output->GetBinContent(
b));
136 m_HistoContents.push_back(1);
142 for (
int i = 1;
i <= h_in->GetNbinsX();
i++) {
143 int bin = h_out->FindBin(h_in->GetBinCenter(
i));
144 double val = fabs(h_out->GetBinContent(
bin) - h_in->GetBinContent(
i));
154 double minchange = 100.0;
155 for (
int b = 2;
b <
histo->GetNbinsX();
b++) {
157 if (diff < minchange && diff > 0)
166 TH1D *h_out1 = (TH1D *)h_input->Clone(
"h_out1");
169 double change = get_change(h_out1) * 1.00001;
172 vector<double> binborder;
174 binborder.push_back(h_out1->GetXaxis()->GetXmin());
178 int secondlastbin_merge = 0;
179 for (
int b = 1;
b < h_out1->GetNbinsX() - 1;
b++)
181 double thisBin = h_out1->GetBinContent(
b);
182 double nextBin = h_out1->GetBinContent(
b + 1);
183 double width = h_out1->GetBinWidth(
b);
184 double nextwidth = h_out1->GetBinWidth(
b + 1);
185 double diff = fabs(nextBin - thisBin);
186 if (!
skip && (
diff > change || merged)) {
187 binborder.push_back(h_out1->GetBinLowEdge(
b + 1));
191 if (
diff <= change && !merged) {
192 double sum = thisBin *
width + nextBin * nextwidth;
193 double sumwidth =
width + nextwidth;
194 binborder.push_back(h_out1->GetBinLowEdge(
b + 2));
198 if (
b == (h_out1->GetNbinsX() - 2))
199 secondlastbin_merge = 1;
202 if (!secondlastbin_merge) {
203 binborder.push_back(h_out1->GetBinLowEdge(h_out1->GetNbinsX()));
204 content.push_back(h_out1->GetBinContent(h_out1->GetNbinsX() - 1));
206 binborder.push_back(h_out1->GetXaxis()->GetXmax());
207 content.push_back(h_out1->GetBinContent(h_out1->GetNbinsX()));
210 for (
unsigned int i = 0;
i < binborder.size();
i++)
213 TH1D *h_out2 =
new TH1D(
"h_out2",
"h_out2",
content.size(),
bins);
214 for (
unsigned int b = 1;
b <=
content.size();
b++)
215 h_out2->SetBinContent(
b,
content[
b - 1]);
225 double value2 = get_inverse(rnd);
231 double x2,
double y) {
234 double eps = 0.0000000001;
247 double x2,
double y) {
249 double eps = 0.0000000001;
253 double b = (
x1 -
x2) / (sqrt(
y1) - sqrt(
y2));
254 double a =
x1 -
b * sqrt(
y1);
264 if (rnd < m_HistoContents[0]) {
265 double x1 = m_HistoBorders[0];
266 double x2 = m_HistoBorders[1];
268 double y2 = m_HistoContents[0];
269 double x = non_linear(
y1,
y2,
x1,
x2, rnd);
273 vector<float>::const_iterator larger_element =
274 std::upper_bound(m_HistoContents.begin(), m_HistoContents.end(), rnd);
275 size_t index = larger_element - m_HistoContents.begin();
276 if (
index >= m_HistoContents.size()) {
279 double y = m_HistoContents[
index];
280 double x1 = m_HistoBorders[
index];
281 double x2 = m_HistoBorders[
index + 1];
282 double y1 = m_HistoContents[
index - 1];
284 if ((
index + 1) == (m_HistoContents.size() - 1)) {
285 x2 = m_HistoBorders[m_HistoBorders.size() - 1];
286 y2 = m_HistoContents[m_HistoContents.size() - 1];
288 double x = non_linear(
y1,
y2,
x1,
x2, rnd);