27 const TH2 *hist, std::vector<double> &integral_vec,
int &first,
int &last) {
29 Int_t nbinsx = hist->GetNbinsX();
30 Int_t nbinsy = hist->GetNbinsY();
31 Int_t nbins = nbinsx * nbinsy;
34 float hint = hist->Integral();
35 integral_vec.resize(nbins);
37 for (
int ix = 1; ix <= nbinsx; ix++) {
38 for (
int iy = 1; iy <= nbinsy; iy++) {
39 int globalbin = (ix - 1) * nbinsy + iy - 1;
40 float binval = hist->GetBinContent(ix, iy);
43 double fraction = binval / hint;
44 if (std::abs(fraction) > 1e-5) {
46 "Warning: bin content is negative in histogram "
47 << hist->GetName() <<
" : " << hist->GetTitle()
48 <<
" binval=" << binval <<
" " << fraction * 100
49 <<
"% of integral=" << hist->Integral()
50 <<
". Forcing bin to 0.");
59 for (first = 0; first < nbins; first++)
60 if (integral_vec[first] != 0)
62 for (last = nbins - 1; last > 0; last--)
69 << hist->GetName() <<
" : " << hist->GetTitle()
70 <<
" integral=" <<
integral <<
" is <=0");
77 TH2 *hist =
new TH2F(
"test2D",
"test2D", nbinsx, 0, 1, nbinsy, 0, 1);
79 for (
int ix = 1; ix <= nbinsx; ++ix) {
80 for (
int iy = 1; iy <= nbinsy; ++iy) {
81 hist->SetBinContent(ix, iy,
82 (0.5 + gRandom->Rndm()) * (nbinsx + ix) *
83 (nbinsy * nbinsy / 2 + iy * iy));
84 if (gRandom->Rndm() < 0.1)
85 hist->SetBinContent(ix, iy, 0);
86 hist->SetBinError(ix, iy, 0);
94 const char *outfilename,
98 hist = create_random_TH2();
102 int nbinsx = hist->GetNbinsX();
103 int nbinsy = hist->GetNbinsY();
108 for (
rnd[0] = 0;
rnd[0] < 0.9999;
rnd[0] += 0.25) {
109 for (
rnd[1] = 0;
rnd[1] < 0.9999;
rnd[1] += 0.25) {
112 <<
" -> x=" << value[0]
113 <<
" y=" << value[1]);
121 (TH2F *)hist->Clone(TString(hist->GetName()) +
"_" + rtof->ClassName());
124 float weight = hist->Integral() / nrnd;
126 for (
int i = 0; i < nrnd; ++i) {
127 rnd[0] = gRandom->Rndm();
128 rnd[1] = gRandom->Rndm();
130 hist_val->Fill(value[0], value[1], weight);
132 hist_val->Add(hist, -1);
135 new TH1F(TString(
"pull_") + rtof->ClassName(),
136 TString(
"pull for ") + rtof->ClassName(), 80, -4, 4);
137 for (
int ix = 1; ix <= nbinsx; ++ix) {
138 for (
int iy = 1; iy <= nbinsy; ++iy) {
139 float val = hist_val->GetBinContent(ix, iy);
140 float err = hist_val->GetBinError(ix, iy);
142 hist_pull->Fill(val / err);
147 std::unique_ptr<TFile>
outputfile(TFile::Open(outfilename,
"UPDATE"));
157#if defined(__FastCaloSimStandAlone__)
158 new TCanvas(hist->GetName(), hist->GetTitle());
161 new TCanvas(hist_val->GetName(), hist_val->GetTitle());
162 hist_val->Draw(
"colz");
164 new TCanvas(hist_pull->GetName(), hist_pull->GetTitle());