Different results using TGraph2D with ROOT 6.30/04 vs 6.32/06

Hi all,

I am not sure if this is already known or expected behaviour but I decided to report it here anyway.

I am working with the results of a 2D likelihood scan stored in a ROOT file. The idea is simple, for each value of r_{1} (our first variable, x-axis) and r_{2} (the second variable, y-axis) we have the -2\Delta log L value. We want to plot the likelihood values as a function of x and y. To do so, we read the values from a ROOT file and create a TGraph2D using the commands:

import ROOT
ff = ROOT.TFile.Open("test.root")  # same ROOT file for the two cases
limit = ff.Get("limit")

r_1 = "r_1"
r_2 = "r_2"
whatToDraw = ROOT.Form(f"{r_1}:{r_2}:2*deltaNLL")

n = limit.Draw(whatToDraw,"1", "colz")
graphScan = ROOT.TGraph2D(n,limit.GetV1(),limit.GetV2(),limit.GetV3())

The code is simple. However, we obtain completely different results when we run it using ROOT 6.30/04 and 6.32/06. The expected (and correct) result is the one from the ROOT 6.30/04 version. I show the results below.

I hope this is helpful for anyone since I spent sometime trying to understand what was going on there.
Bests,
Sergio.

ROOT 6.30/04

ROOT 6.32/06

Ah yes, really different !! can you provide a running example ? (test.root is missing)

Hi Sergio,

Thanks for the report: it’s useful for us.
Can you confirm that the data read out from the file is the same?
Can you share the input file with us so that we can reproduce?

@couet

Best,
D

Sure, I am uploading here the input file. I confirm that the same file was used for the two versions.

higgsCombine_limits_2D_25_2D.root (1.1 MB)

The exact piece of code that I used is this one (I modified the name of the variables for simplicity):

import ROOT
ff = ROOT.TFile.Open("higgsCombine_limits_2D_25_2D.root")
limit = ff.Get("limit")

r_1 = "r_LL"
r_2 = "r_TT"
whatToDraw = ROOT.Form(f"{r_1}:{r_2}:2*deltaNLL")

n = limit.Draw(whatToDraw,"1", "colz")
graphScan = ROOT.TGraph2D(n,limit.GetV1(),limit.GetV2(),limit.GetV3())

# To plot the results
tc = ROOT.TCanvas("test", "test", 900, 800)
graphScan.Draw("colz")
tc.Draw()

Bests,
Sergio

I see the same with master. I will install 6.30 to see what I get

I see the difference between master and 6.30 it seems the TTree::Draw command gives the same output on both versions. I am investigating further why the TGraph2D one is different.

In November 2023 we changed the triangulation package. We now use CDT. It looks like in your particular case the result it gives is different from the previous one (triangles.c, we can not use it anymore because of license issues). Until now we didn’t have problems (all the tests are fine). I need to investigate why it gives you a such different result. The very old package (before triangles.c) is still available under the option OLD.

graphScan.Draw("old colz")

It gives the same result with both root versions. I am investigating CDT now.

Also note that graphScan.Draw("P0") is correct.

I have identified the problem. The triangulation algorithm can sometimes encounter issues when the dataset contains multiple instances of the same point. In your case, the dataset has a total of 1997 points, of which 1000 are identical to (1,1,0).

The following version of your code ensures that only one instance of (1,1,0) is included. With this modification, it works as expected:

{
   auto ff = new TFile("higgsCombine_limits_2D_25_2D.root");
   int n = limit->Draw("r_LL:r_TT:2*deltaNLL","1", "COL");
   double *x = limit->GetV1();
   double *y = limit->GetV2();
   double *z = limit->GetV3();
   auto graphScan = new TGraph2D();
   graphScan->AddPoint(1.,1.,0.);
   for (int i=0; i<n; i++) {
      if (x[i]==1. && y[i]==1. && z[i]==0.) continue;
      graphScan->AddPoint(x[i], y[i], z[i]);
   }
   graphScan->Draw("COLZ");
}

It’s great to see that you have identified the issue and there is a quick solution for it. Thank you very much!
Sergio

1 Like

I am now implementing a utility to remove the duplicated vertices.

This PR implements TGraph2D::RemoveDuplicates. Once merged your code could be:

{
   auto ff = new TFile("higgsCombine_limits_2D_25_2D.root");
   int n = limit->Draw("r_LL:r_TT:2*deltaNLL","1", "COL");
   auto graphScan = new TGraph2D(n,limit->GetV1(),limit->GetV2(),limit->GetV3());
   graphScan->RemoveDuplicates();
   graphScan->Draw("COLZ");
}

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