void RootTutorial1_sol() { // Get the data file cout << "[root_tutorial_1] Getting data file!" << endl; TFile *f = new TFile("../zjet.root"); // Get the tree from the file cout << "[root_tutorial_1] Getting TTree from file" << endl; TTree *t = (TTree*)f->Get( "Tdata" ); // Create a 1D histogram cout << "[root_tutorial_1] Creating histogram object (TH1F)" << endl; //Change bin to 300 //TH1F *h_px = new TH1F("h_px","An Histogram",300,0,150); TH1F *h_px = new TH1F("h_px","An Histogram",300,89.5, 92.5); h_px->SetFillColor(4); h_px->SetLineColor(2); // Fill the histogram using information from the "px" branch from the tree cout << "[root_tutorial_1] Filling histogram and drawing it" << endl; t->Draw("m>>h_px", "id==0"); Double_t factor = 1.; h_px->Rebin(2); // Scale by factor equal to Area h_px->Scale(factor/h_px->Integral()); h_px->Sumw2(0); h_px->Fit("gaus"); h_px->SetTitle("Chaging title"); // You'll see some tails corresponding to a Lorentzian distributions... // The gaussian fit is not quite the best approach... // Adjust the boundaries of the fit TF1 *g = (TF1*)h_px->GetListOfFunctions()->FindObject("gaus"); //Extract the parameters double constant = g->GetParameter(0); double mean = g->GetParameter(1); double sigma = g->GetParameter(2); cout << "Results: "<< constant << " " << mean << " " << sigma << endl; }