GetConfidenceIntervals() returns nothing

Hi,

I am trying to duplicate the results of the tutorial here: root.cern.ch/root/html/tutorials … als.C.html.

The tutorial runs fine, however I cannot seem to duplicate the results for my custom function fit. My code looks like:

TFile * n0 = new TFile("/home/euix/Desktop/clumeq_backup/backup_oct30/prunstuff/pythia_v95_combined_ht_TeV_exclusive_projection.root");
TH2D * jetpt_N = (TH2D*)gDirectory->Get("jetpt_N");
jetpt_N->ProjectionX("jet",4,4);
   TCanvas *myc = new TCanvas("myc","Confidence intervals on the fitted function",1200, 500);
myc->SetLogy();
TF1 * dijet_fit=new TF1("dijet_fit"," ([0]*(1-x/8)^[1] )/(x/8)^([2])",1.6,3.0);
dijet_fit->SetParameters(100,12,3);
jet->Draw();
TFitResultPtr fit_results;
fit_results=jet->Fit("dijet_fit","VSR0");
double * points[100];
double * results[100];

TH1D * hint  = new TH1D("hint","hint",100,0,10);
(TVirtualFitter::GetFitter())->GetConfidenceIntervals(hint)
   hint->SetStats(kFALSE);
   hint->SetFillColor(2);
   hint->Draw("e3 same");

When I plot “hint” I see there is nothing in the histogram. I don’t understand what is going on, the fit seems to return good parameters:

 MIGRAD MINIMIZATION HAS CONVERGED.
 MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
   START COVARIANCE MATRIX CALCULATION.
 EIGENVALUES OF SECOND-DERIVATIVE MATRIX:
         5.2906e-05  6.0746e-02  2.9392e+00
 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
 FCN=19.6143 FROM MIGRAD    STATUS=CONVERGED     581 CALLS         582 TOTAL
                     EDM=4.07242e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           1.59604e+02   1.86704e+01   3.73231e-04  -5.07177e-04
   2  p1           1.01555e+01   1.40804e-01   6.99342e-06   4.11422e-02
   3  p2           5.39169e+00   5.47148e-02   2.57096e-06  -6.47370e-02
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=1
  3.486e+02  2.623e+00 -1.021e+00 
  2.623e+00  1.983e-02 -7.660e-03 
 -1.021e+00 -7.660e-03  2.994e-03 
 PARAMETER  CORRELATION COEFFICIENTS  
       NO.  GLOBAL      1      2      3
        1  0.99996   1.000  0.998 -0.999
        2  0.99975   0.998  1.000 -0.994
        3  0.99989  -0.999 -0.994  1.000
Info in <Minimize>: Finished to run MIGRAD - status 0
 EXTERNAL ERROR MATRIX.    NDIM=   3    NPAR=  3    ERR DEF=1
  3.486e+02  2.623e+00 -1.021e+00 
  2.623e+00  1.983e-02 -7.660e-03 
 -1.021e+00 -7.660e-03  2.994e-03 
 FCN=19.6143 FROM MIGRAD    STATUS=CONVERGED     581 CALLS         582 TOTAL
                     EDM=4.07242e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                  PARABOLIC         MINOS ERRORS        
  NO.   NAME      VALUE            ERROR      NEGATIVE      POSITIVE   
   1  p0           1.59604e+02   1.86704e+01                            
   2  p1           1.01555e+01   1.40804e-01                            
   3  p2           5.39169e+00   5.47148e-02 

Can anyone advise?

Thank You,

Kuhan

Ah nevermind. That was silly. The method works fine.

It turns out if the histogram with the confidence interval is not the first histogram to be drawn on the canvas it looks invisible. If you then proceed to resize the canvas it becomes visible.

Hi, I encounter the same problem that confidence interval does not appear on canvas. The difference is I use TGraphError to store it. Is it the same problem as canvas size? How can I set the size to make confidence interval visible?

Hi,
It is probably also a drawing order issue. Can you maybe share your code ?

Lorenzo

Thank you for your reply! The output image contains scatter plot and fitting line. I am confused about why confidence interval is not visible.

void test() {

   // Simplified version of cernbuild.C.

   // This macro to read data from an ascii file and

   // create a root file with a TTree

   Int_t           A;
   Int_t           Step;
   Int_t           N;

   Double_t        Susceptible;
   Double_t        Exposed;
   Double_t        Asymptomatic;
   Double_t        SymptQuarantined;
   Double_t        AsymptQuarantined;
   Double_t        Severe;
   Double_t        Recovered;
   Double_t        Deceased;
   Double_t        Isolated;
   Double_t        CumulPrivValue;
   Double_t        CumulPublValue;
   Double_t        CumulTestCost;
   Double_t        Rt;
   Double_t        Employed;
   Double_t        Unemployed;

   Int_t           Tested;
   Int_t           Traced;
   Int_t           Iteration;

   cout << "file opened" << endl;

   gSystem->ChangeDirectory("C:\\Users\\14037\\COVID19-mesa\\outcomes");

   // open File with raw Data

   FILE *fp = fopen("cu-current-R0-callibration.csv","r");

   

   // create File

   TFile *hfile = hfile = TFile::Open("cu-current-R0-callibration.root","RECREATE");

   // create Tree

   TTree *tree = new TTree("T","R0-callibration Tree");

   // create Branches

   tree->Branch("A",&A,"A/I");
   tree->Branch("Step",&Step,"Step/I");
   tree->Branch("N",&N,"N/I");
   tree->Branch("Susceptible",&Susceptible,"Susceptible/D");
   tree->Branch("Exposed",&Exposed,"Exposed/D");
   tree->Branch("Asymptomatic",&Asymptomatic,"Asymptomatic/D");
   tree->Branch("SymptQuarantined",&SymptQuarantined,"SymptQuarantined/D");
   tree->Branch("AsymptQuarantined",&AsymptQuarantined,"AsymptQuarantined/D");
   tree->Branch("Severe",&Severe,"Severe/D");
   tree->Branch("Recovered",&Recovered,"Recovered/D");
   tree->Branch("Deceased",&Deceased,"Deceased/D");
   tree->Branch("Isolated",&Isolated,"Isolated/D");
   tree->Branch("CumulPrivValue",&CumulPrivValue,"CumulPrivValue/D");
   tree->Branch("CumulPublValue",&CumulPublValue,"CumulPublValue/D");
   tree->Branch("CumulTestCost",&CumulTestCost,"CumulTestCost/D");
   tree->Branch("Rt",&Rt,"Rt/D");
   tree->Branch("Employed",&Employed,"Employed/D");
   tree->Branch("Unemployed",&Unemployed,"Unemployed/D");
   tree->Branch("Tested",&Tested,"Tested/I");
   tree->Branch("Traced",&Traced,"Traced/I");
   tree->Branch("Iteration",&Iteration,"Iteration/I");

   //fill the tree

   tree->ReadFile("cu-current-R0-callibration.csv");

   //cout << tree->GetSelectedRows() << endl;

   TCanvas *c1 = new TCanvas("c1","graph",700,500);

   //create graph

   tree->Draw("Step:Susceptible>>graph");

   graph->GetXaxis()->SetTitle("Susceptible");

   graph->GetYaxis()->SetTitle("Step");

   //Create the fitting function

   TF1 *fpol = new TF1("fpol", "pol1", -1, 1);

   fpol->SetLineWidth(2);

   graph->Fit(fpol, "Q");

 

   /*Create a TGraphErrors to hold the confidence intervals*/

   ngr = tree->GetEntries();

   TGraphErrors *grint = new TGraphErrors(ngr);

   grint->SetTitle("Fitted line with .95 conf. band");

   for (i=0; i<ngr; i++)

      grint->SetPoint(i, gr->GetX()[i], 0);

   

   /*Compute the confidence intervals at the x points of the created graph*/

   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint);

   //Draw the graph, the function and the confidence intervals

   grint->SetLineColor(kRed);

   grint->Draw("ap");

   graph->SetMarkerStyle(5);

   graph->SetMarkerSize(0.7);

   graph->Draw("psame");

   tree->Print();

   tree->Write();

   fclose(fp);

   delete hfile;

}

Hi,

It is difficult to read code pasted like this in text. You should following the guideline to past code in the forum.
However I don’t see where you create the graph in the text, when you call tree->Draw(“Step:Susceptible>>graph”); you make a 2D histogram.
Otherwise the code later for the confidence interval seems correct.
You should also check that the confidence interval values are not too small, otherwise will not be visible in the plot

Lorenzo