#include #include //=============================== // * EGamma crystal ball function //=============================== double Func_EGMCrystalBall (double *x, double *par) { double funcVal=0; // + List of parameters //--------------------- double sigmaLeft = 2.776; double sigmaRight = 2.0; double mean = 90.0-2.178; double alpha = 1.791; double tailLeft = 1.0; double slope = -0.303; // + List of variables //-------------------- double zLeft = (x[0] - mean) / sigmaLeft; double zRight = (x[0] - mean) / sigmaRight; if (tailLeft >= 0 ) { if (zLeft > 0) { funcVal = exp (-0.5*zRight*zRight); } else { if (zLeft > -alpha) { funcVal = exp(-0.5*zLeft*zLeft); } else { double a = exp (-0.5*alpha*alpha); double b = exp (slope * (zLeft+alpha)); funcVal = a * b; } } } else { //// rather fit high tail for n < 0 if (zRight < 0) { funcVal= exp (-0.5*zLeft*zLeft); } else if (zRight < alpha) { funcVal= exp(-0.5*zRight*zRight); } else { double a = pow(slope/alpha, slope) * exp(-0.5*alpha*alpha); double b = slope/alpha - alpha; funcVal= a/pow(b+zRight, slope); } } return 100*funcVal; } // + Charaterize function //======================= // * Style functions void Characterize_Function (TF1 *func, int colour_func) { func -> SetTitle (""); func -> GetXaxis() -> SetTitle ("M(ee) [GeV]"); func -> GetXaxis() -> SetTitleSize (0.035); func -> GetXaxis() -> SetTitleOffset (1.6); func -> GetXaxis() -> SetLabelSize (0.025); func -> GetXaxis() -> SetLabelOffset (0.03); func -> GetXaxis() -> SetNdivisions (10, 0); func -> GetYaxis() -> SetTitle ("Number of events"); func -> GetYaxis() -> SetTitleSize (0.035); func -> GetYaxis() -> SetLabelSize (0.025); func -> GetYaxis() -> SetTitleOffset (1.2); func -> SetLineWidth (2); func -> SetLineColor (colour_func); func -> SetMarkerColor (colour_func); func -> SetMarkerStyle (20); func -> SetMarkerSize (1); } //================ // * Main function //================ void CodeTest_EGMCrystalBall () { system ("mkdir -p /home/longhoa/ROOT_Work/Task_Test/Output/Plot_TestFunction/"); gStyle -> SetOptStat (0); gStyle -> SetOptFit (0); // + Define the function to be drawn //---------------------------------- // * Draw function TF1 *func_draw = new TF1("func_draw", Func_EGMCrystalBall, 60, 120, 0); // + Charaterize the objects //-------------------------- // * Function //func_draw -> SetLineWidth (2); //func_draw -> SetLineColor (kAzure); Characterize_Function (func_draw, (int)kAzure); // + Draw everything onto a canvas //-------------------------------- // * Canvas TCanvas *canvas = new TCanvas (Form("canvas1"), "", 600, 600); canvas -> cd (); // * Pad TPad *pad = new TPad (Form("pad1"), "", 0.0, 0.0, 1.0, 1.0); pad -> SetTopMargin (0.050); pad -> SetBottomMargin (0.120); pad -> SetLeftMargin (0.120); pad -> SetRightMargin (0.050); pad -> SetGrid (1, 1); pad -> Draw (); pad -> cd(); // * Draw main stuff func_draw -> Draw (); // * Draw legend TLegend *legend = new TLegend (0.320, 0.870, 0.750, 0.920); legend -> SetTextSize (0.030); //legend -> SetNColumns (3); //legend -> AddEntry (func, "Data", "ep"); //legend -> AddEntry (func_fit, "Fit", "l"); legend -> AddEntry (func_draw, "Egamma Crystal Ball", "l"); legend -> Draw ("same"); // * Draw title //TLatex *tex1 = new TLatex(); //tex1 -> SetNDC (); //tex1 -> SetTextFont (42); //tex1 -> SetTextSize (0.032); //tex1 -> DrawLatex (0.075, 0.940, Form("Signal: Landau x Gaussian (#bf{%ld})", nSignal)); // * Print information TLatex *tex11 = new TLatex(); tex11 -> SetNDC (); tex11 -> SetTextFont (42); tex11 -> SetTextSize (0.028); tex11 -> SetTextAlign (13); //tex11 -> DrawLatex (0.770, 0.800, Form("#bf{Fit parameters - Signal}")); //tex11 -> DrawLatex (0.770, 0.750, Form("#bullet Width = %.2f (#color[%d]{5} ) #pm %.2f", width_v, kAzure, width_e)); //tex11 -> DrawLatex (0.770, 0.700, Form("#bullet MIP = %.2f (#color[%d]{40} ) #pm %.2f", mip_v, kAzure, mip_e)); //tex11 -> DrawLatex (0.770, 0.650, Form("#bullet Area = %.0f (#color[%d]{%ld} ) #pm %.0f", area1_v, kAzure, nSignal, area1_e)); //tex11 -> DrawLatex (0.770, 0.600, Form("#bullet sigma = %.2f (#color[%d]{4} ) #pm %.2f", gsig1_v, kAzure, gsig1_e)); //tex11 -> DrawLatex (0.770, 0.500, Form("#bf{Fit quality}")); //tex11 -> DrawLatex (0.770, 0.450, Form("#bullet #chi^{2}/ndf = %.1f/%d = %.2f", chi1, ndf1, con1)); // + Save to file //--------------- canvas -> SaveAs (Form("/home/longhoa/ROOT_Work/Task_Test/Output/Plot_TestFunction/function_EGammaCrystalBall.png")); }