// // Root macro to linearly transform the y axis of a 1D histogram // such that the minimum and maximum contents are the requested values. // TH1D *rescale(const TH1D *hist, Double_t newmin=0, Double_t newmax=1) { TString hname = hist->GetName(); TH1D *hres = hist->Clone(hname + "_rescaled"); Double_t oldmin = hres->GetBinContent(hres->GetMinimumBin()); Double_t oldmax = hres->GetBinContent(hres->GetMaximumBin()); Int_t nbins = hres->GetXaxis()->GetNbins(); for (Int_t bin=1; bin <= nbins; ++bin) { Double_t y = hres->GetBinContent(bin); y = (y-oldmin)*(newmax-newmin)/(oldmax-oldmin)+newmin; hres->SetBinContent(bin,y); } return hres; }