TLatex/TMathText not working in frames

Dear ROOT experts/users,

I’m doing a TGraph in a frame (as recommended in other posts) with DrawFrame command.
All works fine until I try to enter a TLatex or TMathText. The text is written down but not with Latex format. I’ve tried differents methods, but I have no idea what’s going on… Some idea?

My macro is as follows:

#include <iostream>
#include <fstream>
#include <string>

#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"

#include "TCanvas.h"
#include "TH1D.h"
#include "TGraph.h"
#include "TPad.h"
#include "TPaveText.h"

#include "TLatex.h"

// gStyle->SetOptStat(nemruoi)
//    n = 1;  name of histogram is printed
//    e = 1;  number of entries printed
//    m = 1;  mean value printed
//    r = 1;  rms printed
//    u = 1;  number of underflows printed
//    o = 1;  number of overflows printed
//    i = 1;  integral of bins printed
//
// gStyle->SetOptFit(pcev)
//    p = 1;  probability
//    c = 1;  Chi Square/Number of degree of freedom
//    e = 1;  errors
//    v = 1;  names/values of fitting parameters
 
void graph()
{
  gStyle->SetOptStat("nemruo");  
 // gStyle->SetOptStat(111100);
  gStyle->SetPalette(kCool);
  gStyle->SetStatY(0.9);
  gStyle->SetStatX(0.9);
  gStyle->SetStatW(0.2);
  gStyle->SetStatH(0.15); 
  gStyle->SetTextSize(1.5);
  gStyle->SetPaintTextFormat("5.2f");

  
  ifstream in;
  in.open("Quantum_Efficiency.txt);

  Double_t x,y,z,x2,y2,z2,t,t2;


  TGraph* graph1 = new TGraph();
 

  Int_t idx = 0;
  while (in.is_open() && !in.eof())
  {
    in >> x >> y;// >> z >> t;
    //ntuple1->Fill(x,y,z,t);
    graph1->SetPoint(idx,x,y);  // e-
    //graph2->SetPoint(idx,x,z);  // gammas
    //graph3->SetPoint(idx,x,t);  // muones
    idx++;
    cout << y << endl;
    
  }
 
  // Establecemos el "canvas"
  TCanvas* c1 = new TCanvas("c1", " ", 200, 10, 800, 600);
  
  aFrame = c1->DrawFrame(280,0,720,0.3);
  aFrame->GetXaxis()->SetTitle("#lambda [nm]");//"E [GeV]");
  aFrame->GetYaxis()->SetTitle("QE (%)");//"# #gamma-Bremsstrahlung");
  aFrame->GetXaxis()->SetTitleOffset(1.2);
  aFrame->GetYaxis()->SetTitleOffset(1.4); 
  
  // Ajuste
  
  TF1* fit1 = new TF1("fit1", "pol4");//"fit1", "[0]*x**4 + [1]*x**3 + [2]*x**2 + [3]*x + [4]", 300., 700.);
  fit1->SetParameters(-7.328, 0.057, -1.52e-4, 1.72e-7, -7.086e-11);
  
  Double_t param[5];
  
  graph1->Fit("fit1");
  param[0] = fit1->GetParameter(0);
  param[1] = fit1->GetParameter(1);
  param[2] = fit1->GetParameter(2);
  param[3] = fit1->GetParameter(3);
  param[4] = fit1->GetParameter(4);
  
  // Grafica  
  
  graph1->SetMarkerStyle(20);
  
  graph1->SetMarkerSize(0.8);
  graph1->SetMarkerColor(4);  
  graph1->Draw("P");  

  // Legend
  TLegend* legend1 = new TLegend(0.65, 0.8, 0.8999, 0.8999);
  legend1->AddEntry(graph1, "Experimental data", "p");
  legend1->AddEntry(fit1, "Fit function", "l");
  legend1->Draw();
  
// Here is what is not working
   
  TMathText* text0 = new TMathText();
  text0->SetTextFont(40);
  text0->SetTextColor(1);
  text0->SetTextSize(0.03);
  text0->SetTextAlign(22);
  text0->SetTextAngle(0);
  text0->DrawMathText(600,.2,"f(x)=a x^{4} +bx^{3}+cx^{2}+dx+e");
  
  c1->Update();
  
  in.close();

}

I’m using this ROOT and gcc compiler versions.


ROOT Version (6.08/04):
Platform, compiler (Ubuntu 16.04, gcc 5.4.0)


Quantum_Efficiency.txt (986 Bytes)

First includes are:

“iostream”, “fstream” and “string”

  text0->SetTextFont(42); // https://root.cern.ch/doc/master/classTAttText.html#T5

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

Sorry for that and thanks a lot… First time posting… I will get it in mind!

https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292/2

{
  // The TLatex class desctiption explicitly states:
  // "When the font precision (see TAttText) is low (0 or 1),
  // TLatex is painted as a normal TText, the control characters
  // are not interpreted."
  TLatex* l = new TLatex();
  l->SetTextFont(40);
  l->DrawLatex(0.1, 0.9, "a x^{4} + b x^{3} + c x^{2} + d x + e [L 40]");
  l->SetTextFont(41);
  l->DrawLatex(0.1, 0.8, "a x^{4} + b x^{3} + c x^{2} + d x + e [L 41]");
  l->SetTextFont(42); // drawn as (normal) ROMAN type
  l->DrawLatex(0.1, 0.7, "a x^{4} + b x^{3} + c x^{2} + d x + e [L 42]");
  l->SetTextFont(43); l->SetTextSize(34); // drawn as (normal) ROMAN type
  l->DrawLatex(0.1, 0.6, "a x^{4} + b x^{3} + c x^{2} + d x + e [L 43]");
  // The TMathText class description has no "font precision" warning.
  // Do all font precisions work o.k.? NO, THEY DO NOT!
  TMathText* t = new TMathText();
  t->SetTextFont(40);
  t->DrawMathText(0.1, 0.4, "a x^{4} + b x^{3} + c x^{2} + d x + e [M 40]");
  t->SetTextFont(41);
  t->DrawMathText(0.1, 0.3, "a x^{4} + b x^{3} + c x^{2} + d x + e [M 41]");
  t->SetTextFont(42); // drawn as OBLIQUE type
  t->DrawMathText(0.1, 0.2, "a x^{4} + b x^{3} + c x^{2} + d x + e [M 42]");
  t->SetTextFont(43); t->SetTextSize(34); // drawn as OBLIQUE type
  t->DrawMathText(0.1, 0.1, "a x^{4} + b x^{3} + c x^{2} + d x + e [M 43]");
}

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