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(),
"arithmetic average",
28 rebinnedHist2D_->GetNbinsX(),
29 rebinnedHist2D_->GetXaxis()->GetXmin(),
30 rebinnedHist2D_->GetXaxis()->GetXmax() );
32 const string rmsName = bname +
"_RMS";
33 RMS_ =
new TH1D( rmsName.c_str(),
"RMS",
34 rebinnedHist2D_->GetNbinsX(),
35 rebinnedHist2D_->GetXaxis()->GetXmin(),
36 rebinnedHist2D_->GetXaxis()->GetXmax() );
38 const string sigmaGaussName = bname +
"_sigmaGauss";
39 sigmaGauss_ =
new TH1D(sigmaGaussName.c_str(),
"sigmaGauss",
40 rebinnedHist2D_->GetNbinsX(),
41 rebinnedHist2D_->GetXaxis()->GetXmin(),
42 rebinnedHist2D_->GetXaxis()->GetXmax() );
44 const string meanXName = bname +
"_meanX";
45 meanXslice_ =
new TH1D(meanXName.c_str(),
"meanX",
46 rebinnedHist2D_->GetNbinsX(),
47 rebinnedHist2D_->GetXaxis()->GetXmin(),
48 rebinnedHist2D_->GetXaxis()->GetXmax() );
50 ProcessSlices( rebinnedHist2D_ );
54 if ( rebinnedHist2D_ )
delete rebinnedHist2D_;
55 if ( average_ )
delete average_;
56 if ( RMS_ )
delete RMS_;
57 if ( sigmaGauss_ )
delete sigmaGauss_;
58 if ( meanXslice_ )
delete meanXslice_;
68 const int binxmax,
const bool cst_binning)
71 const string bname = hist2D_->GetName();
72 const string rebinName = bname +
"_rebin";
74 if (binxmax>hist2D_->GetNbinsX())
76 std::cout <<
"Error: TH2Analyzer.cc: binxmax>hist2D_->GetNbinsX()" << std::endl;
87 rebinnedHist2D_ =
new TH2D(rebinName.c_str(),
"rebinned histo",
89 hist2D_->GetXaxis()->GetBinLowEdge(binxmin),
90 hist2D_->GetXaxis()->GetBinUpEdge(binxmax),
92 hist2D_->GetYaxis()->GetXmin(),
93 hist2D_->GetYaxis()->GetXmax() );
94 for (
int binyc=1;binyc<hist2D_->GetNbinsY()+1;++binyc)
96 for (
int binxc=binxmin;binxc<binxmax+1;++binxc)
101 rebinnedHist2D_->SetBinContent(binxc-binxmin+1,binyc,hist2D_->GetBinContent(binxc,binyc));
102 rebinnedHist2D_->SetBinError(binxc-binxmin+1,binyc,hist2D_->GetBinError(binxc,binyc));
105 rebinnedHist2D_->RebinX( rebinFactor );
107 const string averageName = bname +
"_average";
108 average_ =
new TH1D( averageName.c_str(),
"arithmetic average",
109 rebinnedHist2D_->GetNbinsX(),
110 rebinnedHist2D_->GetXaxis()->GetXmin(),
111 rebinnedHist2D_->GetXaxis()->GetXmax() );
113 const string rmsName = bname +
"_RMS";
114 RMS_ =
new TH1D( rmsName.c_str(),
"RMS",
115 rebinnedHist2D_->GetNbinsX(),
116 rebinnedHist2D_->GetXaxis()->GetXmin(),
117 rebinnedHist2D_->GetXaxis()->GetXmax() );
119 const string sigmaGaussName = bname +
"_sigmaGauss";
120 sigmaGauss_ =
new TH1D(sigmaGaussName.c_str(),
"sigmaGauss",
121 rebinnedHist2D_->GetNbinsX(),
122 rebinnedHist2D_->GetXaxis()->GetXmin(),
123 rebinnedHist2D_->GetXaxis()->GetXmax() );
125 const string meanXName = bname +
"_meanX";
126 meanXslice_ =
new TH1D(meanXName.c_str(),
"meanX",
127 rebinnedHist2D_->GetNbinsX(),
128 rebinnedHist2D_->GetXaxis()->GetXmin(),
129 rebinnedHist2D_->GetXaxis()->GetXmax() );
142 if (((binxmax-binxmin+1)%rebinFactor)!=0.0)
144 nbin=
std::abs((binxmax-binxmin+1)/rebinFactor)+1;
146 else nbin=(binxmax-binxmin+1)/rebinFactor;
148 double *xlow =
new double[nbin+1];
149 int *binlow =
new int[nbin+1];
151 TH1D* h0_slice1 = hist2D_->ProjectionY(
"h0_slice1", binxmin, binxmax,
"");
152 const unsigned int totalNumberOfEvents=
static_cast<unsigned int>(h0_slice1->GetEntries());
156 unsigned int neventsc=0;
157 unsigned int binXmaxc=binxmin+1;
158 xlow[0]=hist2D_->GetXaxis()->GetBinLowEdge(binxmin);
160 for (
unsigned int binc=1;binc<nbin;++binc)
162 while (neventsc<binc*totalNumberOfEvents/nbin)
164 TH1D* h0_slice1c = hist2D_->ProjectionY(
"h0_slice1",binxmin, binXmaxc,
"");
165 neventsc=
static_cast<unsigned int>(h0_slice1c->GetEntries());
172 binlow[binc]=binXmaxc-1;
173 xlow[binc]=hist2D_->GetXaxis()->GetBinLowEdge(binXmaxc-1);
175 xlow[nbin]=hist2D_->GetXaxis()->GetBinUpEdge(binxmax);
176 binlow[nbin]=binxmax;
183 rebinnedHist2D_ =
new TH2D(rebinName.c_str(),
"rebinned histo",
184 nbin, xlow, hist2D_->GetNbinsY(),
185 hist2D_->GetYaxis()->GetXmin(),
186 hist2D_->GetYaxis()->GetXmax() );
187 for (
int binyc=1;binyc<hist2D_->GetNbinsY()+1;++binyc)
189 for (
unsigned int binxc=1;binxc<nbin+1;++binxc)
192 for (
int binxh2c=binlow[binxc-1];binxh2c<binlow[binxc];++binxh2c)
194 sum+=hist2D_->GetBinContent(binxh2c,binyc);
196 rebinnedHist2D_->SetBinContent(binxc,binyc,sum);
200 const string averageName = bname +
"_average";
201 average_ =
new TH1D( averageName.c_str(),
"arithmetic average", nbin, xlow);
203 const string rmsName = bname +
"_RMS";
204 RMS_ =
new TH1D( rmsName.c_str(),
"RMS", nbin, xlow);
206 const string sigmaGaussName = bname +
"_sigmaGauss";
207 sigmaGauss_ =
new TH1D(sigmaGaussName.c_str(),
"sigmaGauss", nbin, xlow);
209 const string meanXName = bname +
"_meanX";
210 meanXslice_ =
new TH1D(meanXName.c_str(),
"meanX", nbin, xlow);
214 ProcessSlices( rebinnedHist2D_ );
221 TH1::AddDirectory(0);
223 for(
int i=1;
i<=histo->GetNbinsX(); ++
i) {
224 TH1D* proj = histo->ProjectionY(
"toto",
i,
i);
225 const double mean = proj->GetMean();
226 const double rms = proj->GetRMS();
229 average_->SetBinContent(
i, mean);
230 average_->SetBinError(
i, proj->GetMeanError());
231 RMS_->SetBinContent(
i, rms);
232 RMS_->SetBinError(
i, proj->GetRMSError());
234 const double error=(histo->GetXaxis()->GetBinUpEdge(
i)-histo->GetXaxis()->GetBinLowEdge(
i))/2.0;
236 meanXslice_->SetBinContent(
i, histo->GetXaxis()->GetBinLowEdge(
i)+
error);
237 meanXslice_->SetBinError(
i, error);
242 ProcessSlice(
i, proj );
246 TH1::AddDirectory(1);
253 const double rms = proj->GetRMS();
259 const double fitmin=proj->GetMean()-proj->GetRMS();
260 const double fitmax=proj->GetMean()+proj->GetRMS();
267 TF1*
f1=
new TF1(
"f1",
"gaus", fitmin, fitmax);
268 f1->SetParameters(proj->GetRMS(),proj->GetMean(),proj->GetBinContent(proj->GetMaximumBin()));
269 proj->Fit(
"f1",
"R",
"", proj->GetXaxis()->GetXmin(), proj->GetXaxis()->GetXmax());
279 sigmaGauss_->SetBinContent(i, f1->GetParameter(2));
280 sigmaGauss_->SetBinError(i, f1->GetParError(2));
285 sigmaGauss_->SetBinContent(i, 0.0);
286 sigmaGauss_->SetBinError(i, 0.0);
void Eval(const int rebinFactor)
void ProcessSlice(const int i, TH1D *histo) const
Abs< T >::type abs(const T &t)
void ProcessSlices(const TH2D *histo)
void Reset(std::vector< TH2F > &depth)