#include #include #include #include #include #include #include #include "TCanvas.h" #include "TSystem.h" #include "TROOT.h" #include "TStyle.h" #include "TF1.h" #include "TAxis.h" #include "TGraph.h" TGraph *LumiGraphToFunction; double getLumiFunction(double *x, double *) { return LumiGraphToFunction->Eval(x[0]); } void savePlot(TCanvas*, TString); void TF1Rendering() { gROOT->SetStyle("Plain"); gStyle->SetPalette(1,0); gStyle->SetOptStat(000000); gStyle->SetOptFit(000000); gStyle->SetOptTitle(0); gStyle->SetGridStyle(3); gROOT->UseCurrentStyle(); // Fake Lumi data // const int nbx = 100; const int nbx = 450; std::vector bxvec; for(int i=0; i lumivec = {0,0,0,0,0,0,0,0,0,0,99,98,97,96,95,94,93,92,91,90,0,0,0,0,0,99,98,97,96,95,94,93,92,91,90,0,0,0,0,0, // 99,98,97,96,95,94,93,92,91,90,0,0,0,0,0,99,98,97,96,95,94,93,92,91,90,0,0,0,0,0, // 99,98,97,96,95,94,93,92,91,90,0,0,0,0,0,99,98,97,96,95,94,93,92,91,90,0,0,0,0,0}; std::vector lumivec = {0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0, 80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90, 0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0, 80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90, 0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0, 80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90, 0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0,80,90,100,110,100,90,100,90,100,90,0,0,0,0,0,0,0,0,0,0}; // Fake Lumi Graph LumiGraphToFunction = new TGraph(nbx, &bxvec[0], &lumivec[0]); LumiGraphToFunction->SetMarkerColor(kBlue); LumiGraphToFunction->SetLineColor(kBlue); LumiGraphToFunction->SetMarkerSize(0.5); LumiGraphToFunction->SetMarkerStyle(20); // Make TF1 TF1 *LumiFunction = new TF1("LumiFunction",getLumiFunction,0,nbx,0); // zero parameters LumiFunction->SetMarkerColor(kMagenta); LumiFunction->SetLineColor(kMagenta); LumiFunction->SetMarkerSize(0.5); LumiFunction->SetMarkerStyle(20); // Evaluate the TF1 in high density of points std::vector pointsfromtf1; for(int i=0; iEval(i)); } TGraph * FunctionToGraph = new TGraph(nbx, &bxvec[0], &pointsfromtf1[0]); FunctionToGraph->SetMarkerColor(kRed); FunctionToGraph->SetLineColor(kRed); FunctionToGraph->SetMarkerSize(0.5); FunctionToGraph->SetMarkerStyle(20); FunctionToGraph->SetLineStyle(2); TCanvas *c1 = new TCanvas("c1", "c1", 0,0,1000,600); c1->SetFillStyle(4000); c1->SetFillColor(4000); c1->SetFrameFillColor(4000); c1->SetFrameFillStyle(4000); c1->SetFrameBorderMode(0); c1->SetTicks(1,1); c1->SetGrid(1,1); // c1->SetLogy(1); // c1->SetLogx(1); c1->SetLeftMargin(0.025); c1->SetRightMargin(0.025); c1->SetTopMargin(0.05); c1->Divide(1,3); c1->cd(1); // Show the Original LumiGraphToFunction->Draw("APLE"); LumiGraphToFunction->GetXaxis()->SetRangeUser(0,nbx-1); c1->cd(2); // Show the TF1 LumiFunction->Draw("PC"); LumiFunction->GetXaxis()->SetRangeUser(0,nbx-1); c1->cd(3); // Show my sampled TF1 FunctionToGraph->Draw("APL"); FunctionToGraph->GetXaxis()->SetRangeUser(0,nbx-1); // Gsum->Print(); c1->Update(); c1->cd(1); savePlot(c1,"TF1Rendering"); } void savePlot(TCanvas * c, TString name) { c->SaveAs(name+".png"); c->SaveAs(name+".eps"); c->SaveAs(name+".pdf"); std::cout<<"Plot "<