void RotateHistogram() { auto h1 = new TH2D("h1","Original histogram",50,-5,5, 30, 0, 10); auto func = new TF2("func","xygaus"); func->SetParameters(1, 0, 2, 7, 1); h1->FillRandom("func",100000); auto ax = h1->GetXaxis(); auto ay = h1->GetYaxis(); auto h2 = new TH2D("h2","Rotate histogram", ay->GetNbins(), ay->GetXmin(), ay->GetXmax(), ax->GetNbins(), ax->GetXmin(), ax->GetXmax() ); for (int i = 0; i < ax->GetNbins() +2; ++i) { for (int j = 0; j < ay->GetNbins() +2; ++j) { h2->SetBinContent( j, i, h1->GetBinContent(i,j)); if (h1->GetSumw2N() > 0) h2->SetBinError( j, i, h1->GetBinError(i,j)); } } //h2->ResetStats(); auto c = new TCanvas(); c->Divide(1,2); c->cd(1); h1->Draw("COLZ"); c->cd(2); h2->Draw("COLZ"); }