23 TH1D *h_input = (TH1D *)h_input1->Clone(
"h_input");
24 TH1D *h_approx = (TH1D *)h_approx1->Clone(
"h_approx");
29 double integral_input = h_input->Integral();
30 double integral_approx = 0.0;
31 for (
int b = 1;
b <= h_input->GetNbinsX();
b++)
33 h_approx->GetBinContent(h_approx->FindBin(h_input->GetBinCenter(
b)));
34 h_approx->Scale(integral_input / integral_approx);
36 double ymax = h_approx->GetBinContent(h_approx->GetNbinsX()) -
37 h_approx->GetBinContent(h_approx->GetMinimumBin());
38 for (
int i = 1;
i <= h_input->GetNbinsX();
i++) {
39 double val = std::abs(h_approx->GetBinContent(
40 h_approx->FindBin(h_input->GetBinCenter(
i))) -
41 h_input->GetBinContent(
i)) /
50 return maxdev * 100.0;
54 const TH1 *
hist, std::vector<double> &integral_vec,
int &
first,
int &last) {
59 integral_vec.resize(
nbins);
60 for (
int ix = 1; ix <=
nbins; ix++) {
61 float binval =
hist->GetBinContent(ix);
64 double fraction = binval /
hist->Integral();
65 if (std::abs(fraction) > 1
e-5) {
67 <<
hist->GetName() <<
" : "
68 <<
hist->GetTitle() <<
" binval=" << binval
69 <<
" " << fraction * 100
70 <<
"% of integral=" <<
hist->Integral()
71 <<
". Forcing bin to 0.");
80 if (integral_vec[
first] != 0)
82 for (last =
nbins - 1; last > 0; last--)
89 <<
hist->GetName() <<
" : " <<
hist->GetTitle()
90 <<
" integral=" <<
integral <<
" is <=0");
95 TH1 *TFCS1DFunction::generate_histogram_random_slope
97 double zerothreshold) {
98 TH1 *
hist =
new TH1D(
"test_slope1D",
"test_slope1D", nbinsx,
xmin,
xmax);
100 for (
int ix = 1; ix <= nbinsx; ++ix) {
101 double val = (0.5 + gRandom->Rndm()) * (nbinsx + ix);
102 if (gRandom->Rndm() < zerothreshold)
105 hist->SetBinError(ix, 0);
110 TH1 *TFCS1DFunction::generate_histogram_random_gauss
112 double xpeak,
double sigma) {
113 TH1 *
hist =
new TH1D(
"test_gauss1D",
"test_gauss1D", nbinsx,
xmin,
xmax);
115 for (
int i = 1;
i <= ntoy; ++
i) {
116 double x = gRandom->Gaus(xpeak,
sigma);
125 int nrnd, TH1 *histfine) {
129 int nbinsx =
hist->GetNbinsX();
135 for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
140 TH1 *hist_val =
nullptr;
142 hist_val = (TH1 *)histfine->Clone(TString(
hist->GetName()) +
"hist_val");
144 hist_val = (TH1 *)
hist->Clone(TString(
hist->GetName()) +
"hist_val");
145 double weightfine = hist_val->Integral() / nrnd;
146 hist_val->SetTitle(
"toy simulation");
148 hist_val->SetLineColor(2);
151 TH1 *hist_diff = (TH1 *)
hist->Clone(TString(
hist->GetName()) +
"_difference");
152 hist_diff->SetTitle(
"cut efficiency difference");
157 for (
int i = 0;
i < nrnd; ++
i) {
158 rnd[0] = gRandom->Rndm();
160 hist_val->Fill(
value[0], weightfine);
163 hist_diff->Add(
hist, -1);
167 new TH1F(TString(
hist->GetName()) +
"_pull",
"pull", 200, -10, 10);
168 for (
int ix = 1; ix <= nbinsx; ++ix) {
169 float val = hist_diff->GetBinContent(ix);
170 float err = hist_diff->GetBinError(ix);
172 hist_pull->Fill(
val /
err);
177 #if defined(__FastCaloSimStandAlone__)
178 TCanvas *
c =
new TCanvas(
hist->GetName(),
hist->GetName());
183 histfine->SetLineColor(kGray);
184 histfine->DrawClone(
"hist");
185 hist->DrawClone(
"same");
189 hist_val->DrawClone(
"sameshist");
193 histfine->SetLineColor(kGray);
194 histfine->DrawClone(
"hist");
195 hist->DrawClone(
"same");
199 hist_val->DrawClone(
"sameshist");