{ gROOT->Reset(); gStyle->SetOptFit(1); gStyle->SetPadGridY(1); TCanvas c1 ("c1", "2D hist", 0, 0, 400, 400); TH2F h3 ("h3", "histogram title", 10, -5.0 , 5.0, 10, 0.0, 1.0); // Create a 1D histogram object of floats TF2 func ("gaus2","xgaus(0)*ygaus(3)"); // Create a 2-param gaussian distribution function // Set the parameters of the function we created: func.SetParameters(1. , 0., 1., // Set the parameters of the first gaussian to N=1, mean=0, sigma=1 1. , 0.5, 0.1); // Set the parameters of the second gaussian to N=1, mean=0.5, sigma=0.1 h3.FillRandom("gaus2",10000); // Calls the FillRandom function of the TH1F class which fills the histogram with 10000 gaus-distributed events gStyle->SetPalette(1); // Sets a better-looking color-palette than the default ROOT one h3.Draw("COLZTEXT"); // Draw the histogram TCanvas c2("c2", "ProjectionX", 0, 400, 400, 400); double x[2] = {-5.,5.}; double y[2] = {0.1, 0.3}; TCutG cut("cut", 2, x, y); TH1D* h3_proj = (TH1D*) h3.ProjectionX("_px", 1, h3.GetNbinsY(), "[cut]"); h3_proj->Draw(); h3_proj->Fit("gaus"); TCanvas c3("c3", "FitSlicesY", 400, 0, 400, 400); h3.FitSlicesY(); TH1D* h3_slices = (TH1D*) gDirectory->Get("h3_2"); h3_slices->Draw(); }