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)