TEfficiency, x-axis text labels and scales not persistent

Hi
I want to use text labels on a TEfficiency plot. I got this halfway working (on screen), but the labels are gone when I try to save and restore the canvas. containing the plot.

It shows correct on screen. It shows correct if printed to pdf.
But if I write the TCanvas to a file and reopen it, the labels will be gone, the axis (x and y) range reset etc.

tefftest.C (1.6 KB)


ROOT Version: 6.14/06
Platform: Linux 64bit, Ubuntu 18.10
Compiler: gcc 8.2.0


It seems TEfficiency saving in ROOT file et .C file does not implement this.
Anyway I would simplify your macro as follow:

{
   TCanvas* c1 = new TCanvas("example","",600,400);
   c1->SetFillStyle(1001);
   c1->SetFillColor(kWhite);

   //create one-dimensional TEfficiency object with fixed bin size
   TEfficiency* pEff = new TEfficiency("eff","my efficiency;x;#epsilon",20,0,10);
   TRandom3 rand3;
   bool bPassed;
   double x;
   for (int i=0; i<10000; ++i) {
      //simulate events with variable under investigation
      x = rand3.Uniform(10);
      //check selection: bPassed = DoesEventPassSelection(x)
      bPassed = rand3.Rndm() < TMath::Gaus(x,5,4);
      pEff->Fill(bPassed,x);
   }

   pEff->Draw("AP");
   c1->Update();

   TGraphAsymmErrors *gg = pEff->GetPaintedGraph();

   if (gg) {
       TAxis *ax = gg->GetXaxis();
       Double_t x1 = ax->GetBinLowEdge(1);
       Double_t x2 = ax->GetBinUpEdge(ax->GetNbins());

       ax->Set(20,0,10);
       TAxis *ay = gg->GetYaxis();
       ay->SetRangeUser(0,1.0); // overwrite auto

       vector <string > names={
           "aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","iii","jjj",
           "aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","iii","jjj"
      };
      for (Int_t k=0;k<20;k++) ax->SetBinLabel(k+1,names[k].c_str());
   }
   c1->Modified();
   c1->Update();
}

“my code”. well. I just modified the example macro to have some “minimal” kind of macro which show my problem. Actually I want to ship the Canvas over network to a httpserver with jsroot to display the canvas. Which works nicely for normal Histograms, but not TEfficiency.

Ah ok . I understand the context now… Let me see why TEfficiency behaves that way. May be @moneta have an idea also.

In fact TEfficiency does not paint itself. It paints a TGraphAsymmErrors. Then you can act on the TGraphAsymmErrors to change its graphical attributes (that’s what you are doing). But in the list of primitives TEfficiency appears as such. So when you access it form saved canvas in a ROOT file it will be repainted and a new TGraphAsymmErrors will be created, which will not have the changed attributes. I would suggest to not save the TEfficiency but instead the modified TGraphAsymmErrors.

1 Like

Sounds reasonable. I will try this. Thanks you very much.

I modded the script such that it works. If someone needs a reference how to do it.

tefftest.C (1.4 KB)

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