See in attachement a script for a 1-D histogram
Rene Brun
Dongwook Jang wrote:
>
> Hi,
>
> Does anyone have a root macro that can variable rebin from a normal
> histogram?
>
> For example, h = new TH1F("h","h",100,0.0,100.0);
>
> I'd like to make this histogram as follows
>
> 2 bins together upto 50
> 5 bins together upto 80
> 10 bins together upto 100
>
> I have a macro to do this, but it's really stupid way.
> Also if we have this rebinning in 2-D, 3-D for a specific axis or both.
>
> --
>
> Best regards,
> Dongwook Jang.
> phone : 630-840-2118 (office B0 170-I) 630-840-6315 (FAX)
void rebins() {
// example of script to rebin a 1-d histogram grouping:
// 2 bins together upto 50
// 5 bins together upto 80
// 10 bins together upto 100
TF1 f1("f1","0.1/x",0,100);
TH1F *h1 = new TH1F("h1","original histo",100,0,100);
h1->FillRandom("f1",3000);
Int_t bin = 1;
Double_t bins[80];
Int_t nbins = 0;
TAxis *xaxis = h1->GetXaxis();
while (bin <100) {
bins[nbins] = xaxis->GetBinLowEdge(bin);
nbins++;
if (bin < 50) bin += 2;
else if (bin < 80) bin += 5;
else bin += 10;
}
bins[nbins] = xaxis->GetBinUpEdge(100);
TH1F *h2 = new TH1F("h2","rebinned histo",nbins,bins);
for (bin=1;bin<100;bin++) {
h2->Fill(xaxis->GetBinCenter(bin),h1->GetBinContent(bin));
}
TCanvas *c1 = new TCanvas("c1","c1",600,800);
c1->Divide(1,2);
c1->cd(1);
h1->Draw();
c1->cd(2);
h2->Draw();
}
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET