void GetRandomTest(){ double k0=1.39; double k1 = 0.425; double theta0 = 3.41; double theta1 = 1.30; int iNpart=2; double k_=k0+k1*(iNpart-2); double theta_=theta0+theta1*TMath::Log(iNpart-1); TF1 *f = new TF1("f","TMath::GammaDist(x,[0],0,[1])",0,200); f->SetParameters(k1,theta_); cout<<"Value at 0 = "<<f->Eval(0)<<endl; cout<<"Value at 1e-11 = "<<f->Eval(1e-11)<<endl; cout<<"Integral 1= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl; f->SetRange(1e-12,200); cout<<"Integral 2= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl; cout<<"fXmin = "<<f->GetXmin()<<"\tfXmax = "<<f->GetXmax()<<"\tfNpx = "<<f->GetNpx()<<endl; f->SetNpx(1e5); TCanvas *c1 = new TCanvas(); c1->SetLogy(); cout<<"f mean = "<<f->Mean(0,200)<<endl; cout<<"math mean = "<<f->GetParameter(0)*f->GetParameter(1)<<endl; TH1D* h = new TH1D("h","h",1000,0,200); for(int i=0;i<1e6;i++){ double para = f->GetRandom(); h->Fill(para); } h->Scale(1.0/h->Integral()*1000/200); h->GetYaxis()->SetRangeUser(1e-10,1); h->SetMarkerStyle(24); h->SetMarkerColor(4); h->SetMarkerSize(1.1); TLegend *leg = new TLegend(0.6,0.7,0.8,0.9); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.03); leg->AddEntry(f,"function","lp"); leg->AddEntry(h,"filled histogram","lp"); h->Draw("P"); f->Draw("same"); leg->Draw("same"); cout<<"h mean = "<<h->GetMean(1)<<endl; c1->Print("TestGetRandom.png"); }
void DrawL2(int etabin) { gROOT->SetStyle("Plain"); gStyle->SetOptStat(0000); gStyle->SetOptFit(000); gStyle->SetPalette(1); if (etabin<0 || etabin>=NETA) { cout<<"Eta bin must be >=0 and <"<<NETA<<endl; break; } TPaveText *pave = new TPaveText(0.3,0.7,0.5,0.85,"NDC"); pave->AddText(Version); pave->AddText(Algorithm); pave->SetLineColor(0); pave->SetBorderSize(0); pave->SetFillColor(0); pave->SetBorderSize(0); TGraphErrors *g_EtaCorrection; TGraph *g_L2Correction; TCanvas *c_Resp; TCanvas *c_L2Cor; TF1 *L2Fit; TF1 *CorFit; TFile *rel_f; char filename[100],name[100]; rel_f = new TFile(L2OutputROOTFilename,"r"); if (!rel_f->IsOpen()) break; /////////////////////////////// Correction ///////////////////////// sprintf(name,"EtaCorrection"); c_Cor = new TCanvas(name,name,900,700); sprintf(name,"Correction_EtaBin%d",etabin); g_EtaCorrection = (TGraphErrors*)rel_f->Get(name); sprintf(name,"Correction%d",etabin); CorFit = (TF1*)g_EtaCorrection->GetFunction(name); if (CorFit->GetXmax()>200) gPad->SetLogx(); CorFit->SetLineColor(2); g_EtaCorrection->GetXaxis()->SetTitle("Uncorrected jet p_{T} (GeV)"); g_EtaCorrection->GetYaxis()->SetTitle("Absolute Correction"); sprintf(name,"%1.3f<#eta<%1.3f",eta_boundaries[etabin],eta_boundaries[etabin+1]); g_EtaCorrection->SetTitle(name); g_EtaCorrection->SetMarkerStyle(20); g_EtaCorrection->Draw("AP"); pave->Draw(); /////////////////////////////// L2 correction ///////////////////////// sprintf(name,"L2Correction"); c_L2Cor = new TCanvas(name,name,900,700); sprintf(name,"L2Correction_EtaBin%d",etabin); g_L2Correction = (TGraph*)rel_f->Get(name); sprintf(name,"L2Correction%d",etabin); L2Fit = (TF1*)g_L2Correction->GetFunction(name); if (L2Fit->GetXmax()>200) gPad->SetLogx(); g_L2Correction->SetMinimum(0.3); g_L2Correction->SetMaximum(1.4); g_L2Correction->GetXaxis()->SetTitle("Uncorrected jet p_{T} (GeV)"); g_L2Correction->GetYaxis()->SetTitle("Relative Correction"); sprintf(name,"%1.3f<#eta<%1.3f",eta_boundaries[etabin],eta_boundaries[etabin+1]); g_L2Correction->SetTitle(name); g_L2Correction->Draw("AP"); g_L2Correction->SetMarkerStyle(20); L2Fit->SetLineColor(2); pave->Draw(); }
void showFunctions1d(std::vector<TF1*>& functions, const std::vector<std::string>& legendEntries, const TString& xAxisTitle, double yMin, double yMax, const TString& yAxisTitle, const std::string& outputFileName) { assert(functions.size() == legendEntries.size()); TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.12); canvas->SetBottomMargin(0.12); assert(functions.size() > 0); TF1* refFunction = functions[0]; TH1* dummyHistogram = new TH1F("dummyHistogram", "dummyHistogram", 10, refFunction->GetXmin(), refFunction->GetXmax()); dummyHistogram->SetStats(false); dummyHistogram->SetTitle(""); dummyHistogram->SetMinimum(-TMath::Log(yMax)); dummyHistogram->SetMaximum(-TMath::Log(yMax) + 5.); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.Data()); xAxis->SetTitleOffset(1.15); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(Form("-log(%s)", yAxisTitle.Data())); yAxis->SetTitleOffset(1.30); dummyHistogram->Draw("axis"); int colors[] = { 1, 2, 3, 4, 5, 6, 7, 15 }; int numFunctions = functions.size(); if ( numFunctions > 8 ) { std::cerr << "<showFunctions1d>:" << std::endl; std::cerr << "Number of functions must not exceed 8 !!" << std::endl; assert(0); } for ( int iFunction = 0; iFunction < numFunctions; ++iFunction ) { TF1* function = functions[iFunction]; function->SetLineColor(colors[iFunction]); function->SetLineWidth(2); function->Draw("same"); } TLegend* legend = new TLegend(0.68, 0.89 - (0.03 + 0.040*numFunctions), 0.89, 0.89, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextSize(0.035); for ( int iFunction = 0; iFunction < numFunctions; ++iFunction ) { TF1* function = functions[iFunction]; const std::string& legendEntry = legendEntries[iFunction]; legend->AddEntry(function, legendEntry.data(), "l"); } legend->Draw(); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete dummyHistogram; delete legend; delete canvas; }