#include "THStack.h" #include "TLegend.h" #include "TFile.h" #include "TCanvas.h" { char title1[255],title2[255],line[255]; int i,j; char title[255],rootname[255]; TCanvas *c1 = new TCanvas(); /* c1->SetGrid(); c1->SetTickx(); c1->SetTicky();*/ c1->SetLogx(); c1->SetFillColor(33); c1->SetFrameFillColor(41); c1->SetGrid(); // gStyle->SetOptFit(1101); gStyle->SetOptFit(0); gStyle->SetOptStat(0); TFile *rootfile = new TFile("Counting.root"); rootfile->ls(); // list everything gStyle->SetOptStat(0); gStyle->SetTitleY(1.0); //title Y location gStyle->SetTitleH(0.1); //title height int ih; float myhmax; TH1F *counth = (TH1F *) rootfile->Get("Countingw"); counth->SetLineStyle(20); counth->SetLineWidth(2); counth->SetLineColor(1); Float_t *bins = counth->GetArray(); // printf("Hist %d bins[0] %g bins[%d] = %f \n",i,bins[0],counth->GetNbinsX()),bins[counth->GetNbinsX()-1]; // counth->SetMaximum(myhmax); // float minf=0,maxf=bins[counth->GetNbinsX()-1]; // maxf = 100; float minf=0,maxf=1.0e6; printf("minf %f maxf %f \n",minf,maxf); TF1 *fitfunc = new TF1("polf6","pol7",minf,maxf); // Create the fit function // gfit->SetParameters(bins[binmax],pedesthist[i*4+j]->GetMean(1), // pedesthist[i*4+j]->GetRMS(1)); counth->SetXTitle("Incident Neutron Energy(MeV)"); counth->SetYTitle("Counts/cm^2"); counth->SetMarkerColor(1); counth->SetMarkerStyle(20); counth->SetMarkerSize(0.7); counth->SetOption("P"); counth->SetLineColor(1); counth->Fit("polf6","RQ"); // Fit histogram counth->Draw("hist FUNC"); counth->Draw(); c1->Update(); c1->SaveAs("Couning.pdf"); }