Set axis title in TEfficiency class

Hi,

I am using the TEfficiency(const TH1& passed, const TH1& total) constructor but there is no option to set the axis title in the TEfficiency object with this specific constructor.

Is there a way to do it?

pantso

1 Like

What about doing SetTitle like for graphs ?

Hi,

I cannot get the pointer to the axis of my TEfficiency object.
Thus:

  TEfficiency *effiEWX = new TEfficiency(*protofound, *protointer);
  effiEWX->GetXaxis()->SetTitle("whatever");

returns
Error: Can’t call TEfficiency::GetXaxis() in current scope

Is this what you suggested?

pantso

Hi,

What you can do in two ways:

  1. using SetTitle:
effiEWX->SetTitle("myTitle; whatever-x ; what0ever-y"); 
  1. Using TEfficiency::GetPaintedGraph(), which works only after having painted the graph
effiEWX->Draw(); 
gPad->Update();
effiEWX->GetPaintedGraph()->GetXaxis()->SetTitle("whatever-x");

Best Regards

Lorenzo

1 Like

Hi Lorenzo,

both worked fine!
Thank you very much for your help.

pantso

Dear all,

I am using ROOT 5.34/09, and the only successful way I have to set the axis titles is doing:

  pEff->Draw("AP");
  gPad->Update();
  pEff->GetPaintedGraph()->GetXaxis()->SetTitle("x3");
  pEff->GetPaintedGraph()->GetYaxis()->SetTitle("#epsilon3");

Setting axis titles in the constructor:

or using

does not work for me. Can you reproduce this problem?

I attach the code I am using to test this.

{
  TEfficiency* pEff = new TEfficiency("eff","my efficiency1;x1;#epsilon1",20,0,10);
  TRandom3 rand;

  bool bPassed;
  double x;
  for(int i=0; i<10000; ++i)
    {
      x = rand.Uniform(10);
      bPassed = rand.Rndm() < TMath::Gaus(x,5,4);
      pEff->Fill(bPassed,x);
    }

  TCanvas* c1 = new TCanvas("example1","example1",600,400);
  /*                                                                                                                                                         
  // Axis titles are NOT drawn                                                                                                                               
  pEff->Draw("AP");                                                                                                                                          
  */
  /*                                                                                                                                                         
  // Axis titles are NOT drawn                                                                                                                               
  pEff->Draw("AP");                                                                                                                                          
  pEff->SetTitle("my efficiency2;x2;#epsilon2");                                                                                                             
  */

  // Axis titles are drawn                                                                                                                                   
  pEff->Draw("AP");
  gPad->Update();
  pEff->GetPaintedGraph()->GetXaxis()->SetTitle("x3");
  pEff->GetPaintedGraph()->GetYaxis()->SetTitle("#epsilon3");
}

Hi,

This should be fixed now in the HEAD of 5.34 patches.
Thank you for reporting this problem

Best Regards

Lorenzo

Dear all,

I am using ROOT 6.08/00
and in the above example from jcrespo:

axis are drawn but titles are not updated: in the plot I see β€œx1” and β€œ#epsilon1” instead of β€œx3” and β€œ#epsilon3”.

Interestingly,

pEff->GetPaintedGraph()->GetXaxis()->GetTitle()

returns the correct value.

How do I update the title of an already drawn axis?
I want to update only the title of the Y axis leaving the X axis unchanged.

Thank you for your help,
Estel