Stat box is not showing up for TF1 plot

Hello experts,

I’m trying to display a stat box for a TF1 plot where I edit the box with the parameters and the values I’m using for plot. However, the stat box is not displaying on the canvas. I’m not sure what could be the problem unless I’m missing a part that is important for displaying it. Hope to hear a response soon. Thanks in advance.

-Charlie Clark

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

#include "TFile.h"
#include "TMath.h"
#include "TH1.h"
#include "TF1.h"
#include "TPDF.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TLatex.h"
#include "TString.h"
#include "TLine.h"
#include "TPaveStats.h"
void CustomizeStatBox(TF1 *GausLandau){
  TCanvas *canvas = new TCanvas("c","c",1000,1000);

  GausLandau->Draw();

  canvas->Update();

  // Get the stats box


  TPaveStats *stats = new TPaveStats(0.7, 0.7, 0.9, 0.9, "stats");
  stats->SetFillColor(0); // Set background color to transparent
  stats->SetTextAlign(12); // Align text left



  // Customize content of the stats box for different parameters
  stats->AddText(Form("#alpha: %.2f", GausLandau->GetParameter(0))); // Add amplitude
  stats->AddText(Form("#mu_g: %.2f", GausLandau->GetParameter(1))); // Add gaussian mean
  stats->AddText(Form("#sigma_g: %.2f", GausLandau->GetParameter(2))); // Add gaussian sigma
  stats->AddText(Form("#mu_l: %.2f", GausLandau->GetParameter(3))); // Add landau mean
  stats->AddText(Form("#sigma_l: %.2f", GausLandau->GetParameter(4))); // Add landau sigma

  canvas->cd();
  stats->Draw();

  // Update the canvas
  canvas->Modified();
  canvas->Update();


}
void landau (){

  //Float_t pi = TMath::Pi();

  Double_t low = 0;

  Double_t high = 70;
  /*
  //Parameters changed for fit.
  TF1 *Landau1 = new TF1("Landau1","[0]*TMath::Landau(x,[1],[2])",low,high);
  //[1] = location parameter, [2] = scaling parameter
  Landau1->SetParameters(649.5,22.95,7.534);
  Landau1->SetTitle("Landau vs. Gaus*Landau Comparison");
*/
  TF1 *GausLandau = new TF1("GausLandau","[0]*TMath::Gaus(x,[1],[2])*TMath::Landau(x,[3],[4])",low,high);
  GausLandau->SetParameters(649.5,11.29,7.856,22.95,7.534);
  GausLandau->SetLineColor(kBlue);

  CustomizeStatBox(GausLandau);
/*
  TF1 *Gaus = new TF1("Gaus","[0]*TMath::Gaus(x,[1],[2])",low,high);
  Gaus->SetParameters(649.5,11.29,7.856);
  Gaus->SetLineColor(kGreen);

  TF1 *Landau2 = new TF1("Landau2","TMath::Landau(x,[0],[1])",low,high);
  Landau2->SetParameters(0,pi/2);
*/
}

Give the coordinates as per your plot axes, not NDC (0 to 1); e.g.

  TPaveStats *stats = new TPaveStats(50, 50, 70, 70, "stats");

GausLandau_Statbox.pdf (14.2 KB)

Hi,

The stat box has appeared, but it doesn’t look like the conventional stat box I’m use to seeing from the picture I just uploaded. Is it because of the way I’m initializing it?

Add

  stats->SetBorderSize(1);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.