21 const string bname = hist2D_->GetName();
22 const string rebinName = bname +
"_rebin";
23 rebinnedHist2D_ = (TH2D *)hist2D_->Clone(rebinName.c_str());
24 rebinnedHist2D_->RebinX(rebinFactor);
26 const string averageName = bname +
"_average";
27 average_ =
new TH1D(averageName.c_str(),
29 rebinnedHist2D_->GetNbinsX(),
30 rebinnedHist2D_->GetXaxis()->GetXmin(),
31 rebinnedHist2D_->GetXaxis()->GetXmax());
33 const string rmsName = bname +
"_RMS";
34 RMS_ =
new TH1D(rmsName.c_str(),
36 rebinnedHist2D_->GetNbinsX(),
37 rebinnedHist2D_->GetXaxis()->GetXmin(),
38 rebinnedHist2D_->GetXaxis()->GetXmax());
40 const string sigmaGaussName = bname +
"_sigmaGauss";
41 sigmaGauss_ =
new TH1D(sigmaGaussName.c_str(),
43 rebinnedHist2D_->GetNbinsX(),
44 rebinnedHist2D_->GetXaxis()->GetXmin(),
45 rebinnedHist2D_->GetXaxis()->GetXmax());
47 const string meanXName = bname +
"_meanX";
48 meanXslice_ =
new TH1D(meanXName.c_str(),
50 rebinnedHist2D_->GetNbinsX(),
51 rebinnedHist2D_->GetXaxis()->GetXmin(),
52 rebinnedHist2D_->GetXaxis()->GetXmax());
54 ProcessSlices(rebinnedHist2D_);
59 delete rebinnedHist2D_;
76 void TH2Analyzer::Eval(
const int rebinFactor,
const int binxmin,
const int binxmax,
const bool cst_binning) {
78 const string bname = hist2D_->GetName();
79 const string rebinName = bname +
"_rebin";
81 if (binxmax > hist2D_->GetNbinsX()) {
82 std::cout <<
"Error: TH2Analyzer.cc: binxmax>hist2D_->GetNbinsX()" << std::endl;
95 rebinnedHist2D_ =
new TH2D(rebinName.c_str(),
97 binxmax - binxmin + 1,
98 hist2D_->GetXaxis()->GetBinLowEdge(binxmin),
99 hist2D_->GetXaxis()->GetBinUpEdge(binxmax),
100 hist2D_->GetNbinsY(),
101 hist2D_->GetYaxis()->GetXmin(),
102 hist2D_->GetYaxis()->GetXmax());
103 for (
int binyc = 1; binyc < hist2D_->GetNbinsY() + 1; ++binyc) {
104 for (
int binxc = binxmin; binxc < binxmax + 1; ++binxc) {
110 rebinnedHist2D_->SetBinContent(binxc - binxmin + 1, binyc, hist2D_->GetBinContent(binxc, binyc));
111 rebinnedHist2D_->SetBinError(binxc - binxmin + 1, binyc, hist2D_->GetBinError(binxc, binyc));
114 rebinnedHist2D_->RebinX(rebinFactor);
116 const string averageName = bname +
"_average";
117 average_ =
new TH1D(averageName.c_str(),
118 "arithmetic average",
119 rebinnedHist2D_->GetNbinsX(),
120 rebinnedHist2D_->GetXaxis()->GetXmin(),
121 rebinnedHist2D_->GetXaxis()->GetXmax());
123 const string rmsName = bname +
"_RMS";
124 RMS_ =
new TH1D(rmsName.c_str(),
126 rebinnedHist2D_->GetNbinsX(),
127 rebinnedHist2D_->GetXaxis()->GetXmin(),
128 rebinnedHist2D_->GetXaxis()->GetXmax());
130 const string sigmaGaussName = bname +
"_sigmaGauss";
131 sigmaGauss_ =
new TH1D(sigmaGaussName.c_str(),
133 rebinnedHist2D_->GetNbinsX(),
134 rebinnedHist2D_->GetXaxis()->GetXmin(),
135 rebinnedHist2D_->GetXaxis()->GetXmax());
137 const string meanXName = bname +
"_meanX";
138 meanXslice_ =
new TH1D(meanXName.c_str(),
140 rebinnedHist2D_->GetNbinsX(),
141 rebinnedHist2D_->GetXaxis()->GetXmin(),
142 rebinnedHist2D_->GetXaxis()->GetXmax());
156 unsigned int nbin = 0;
157 if (((binxmax - binxmin + 1) % rebinFactor) != 0.0) {
158 nbin =
std::abs((binxmax - binxmin + 1) / rebinFactor) + 1;
160 nbin = (binxmax - binxmin + 1) / rebinFactor;
162 double *xlow =
new double[
nbin + 1];
163 int *binlow =
new int[
nbin + 1];
165 TH1D *h0_slice1 = hist2D_->ProjectionY(
"h0_slice1", binxmin, binxmax,
"");
166 const unsigned int totalNumberOfEvents = static_cast<unsigned int>(h0_slice1->GetEntries());
171 unsigned int neventsc = 0;
172 unsigned int binXmaxc = binxmin + 1;
173 xlow[0] = hist2D_->GetXaxis()->GetBinLowEdge(binxmin);
175 for (
unsigned int binc = 1; binc <
nbin; ++binc) {
176 while (neventsc < binc * totalNumberOfEvents /
nbin) {
177 TH1D *h0_slice1c = hist2D_->ProjectionY(
"h0_slice1", binxmin, binXmaxc,
"");
178 neventsc = static_cast<unsigned int>(h0_slice1c->GetEntries());
185 binlow[binc] = binXmaxc - 1;
186 xlow[binc] = hist2D_->GetXaxis()->GetBinLowEdge(binXmaxc - 1);
188 xlow[
nbin] = hist2D_->GetXaxis()->GetBinUpEdge(binxmax);
189 binlow[
nbin] = binxmax;
196 rebinnedHist2D_ =
new TH2D(rebinName.c_str(),
200 hist2D_->GetNbinsY(),
201 hist2D_->GetYaxis()->GetXmin(),
202 hist2D_->GetYaxis()->GetXmax());
203 for (
int binyc = 1; binyc < hist2D_->GetNbinsY() + 1; ++binyc) {
204 for (
unsigned int binxc = 1; binxc <
nbin + 1; ++binxc) {
206 for (
int binxh2c = binlow[binxc - 1]; binxh2c < binlow[binxc]; ++binxh2c) {
207 sum += hist2D_->GetBinContent(binxh2c, binyc);
209 rebinnedHist2D_->SetBinContent(binxc, binyc, sum);
213 const string averageName = bname +
"_average";
214 average_ =
new TH1D(averageName.c_str(),
"arithmetic average",
nbin, xlow);
216 const string rmsName = bname +
"_RMS";
217 RMS_ =
new TH1D(rmsName.c_str(),
"RMS",
nbin, xlow);
219 const string sigmaGaussName = bname +
"_sigmaGauss";
220 sigmaGauss_ =
new TH1D(sigmaGaussName.c_str(),
"sigmaGauss",
nbin, xlow);
222 const string meanXName = bname +
"_meanX";
223 meanXslice_ =
new TH1D(meanXName.c_str(),
"meanX",
nbin, xlow);
227 ProcessSlices(rebinnedHist2D_);
233 TH1::AddDirectory(
false);
235 for (
int i = 1;
i <=
histo->GetNbinsX(); ++
i) {
237 const double mean =
proj->GetMean();
238 const double rms =
proj->GetRMS();
241 average_->SetBinContent(
i,
mean);
242 average_->SetBinError(
i,
proj->GetMeanError());
243 RMS_->SetBinContent(
i,
rms);
244 RMS_->SetBinError(
i,
proj->GetRMSError());
246 const double error = (
histo->GetXaxis()->GetBinUpEdge(
i) -
histo->GetXaxis()->GetBinLowEdge(
i)) / 2.0;
248 meanXslice_->SetBinContent(
i,
histo->GetXaxis()->GetBinLowEdge(
i) +
error);
249 meanXslice_->SetBinError(
i,
error);
254 ProcessSlice(
i,
proj);
258 TH1::AddDirectory(
true);
263 const double rms =
proj->GetRMS();
268 const double fitmin =
proj->GetMean() -
proj->GetRMS();
269 const double fitmax =
proj->GetMean() +
proj->GetRMS();
276 TF1 *
f1 =
new TF1(
"f1",
"gaus", fitmin, fitmax);
277 f1->SetParameters(
proj->GetRMS(),
proj->GetMean(),
proj->GetBinContent(
proj->GetMaximumBin()));
278 proj->Fit(
f1,
"R",
"",
proj->GetXaxis()->GetXmin(),
proj->GetXaxis()->GetXmax());
288 sigmaGauss_->SetBinContent(
i,
f1->GetParameter(2));
289 sigmaGauss_->SetBinError(
i,
f1->GetParError(2));
292 sigmaGauss_->SetBinContent(
i, 0.0);
293 sigmaGauss_->SetBinError(
i, 0.0);