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(); }