Home | News | Documentation | Download

Confidence Levels in Root


#1

Hello Everyone!
I am trying to plot 2-D histogram for contour making at 1,2 and 3 sigma confidence level.
I am reading data from a .dat file with three columns and i want plot it as a contour at above mentioned confidence levels . Please suggest me how to set 1,2 and 3 sigma confidence levels in my code…
‘’’
#include
#include<math.h>
#include <TVirtualFitter.h>
#include <TF2.h>

void rootContourPlot()

{

ifstream f1;
TCanvas *c1 = new TCanvas(“c1”,“c1”,600,400);
TH2F *hcont2 = new TH2F(“hcont2”," ",40,-4,-2,40,0,200);

Double_t x[10001]={0.}, y[10001]={0.},z[10001]={0.}, i,j,k;
int ss=0;

f1.open(“test1.dat”);
while(!f1.eof())
{
f1>>i>>j>>k;

   hcont2->Fill(i,j,k);
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(hcont2, 0.95);

 }

hcont2->Draw("CONT2 ");
c1->Update();
f1.close();

}
‘’’


#2

Hi,

The method TVirtualFitter::GetFitter())->GetConfidenceIntervals(hcont2, 0.95) computes the confidence level of your model (fitting) function after having it fitted to an histogram.
I don’t see in your code where you have performed the fit.
If you have an histogram and you want to plot the contour lines, you just need to do hcont2->Draw(“CONT2”)

Lorenzo


#3

Hello Thank you for your reply… I have a file with three columns and want to see how z varies with x and y at 1, 2 and 3 sigma levels, i am not getting what function should i use to plot this… A 3D graph or 2DProfile histogram, I want to see only x and y axes… I have made it using Gnuplot but not able to make it from ROOT
.example1.pdf (9.3 KB)


#4

${ROOTSYS}/tutorials/hist/ContourList.C


#5

Hi,

Then what you need to use is hcont2->Draw(“CONT1”). You can set the contour and their level with hcont2->SetContours(n, levels), where n is the number of contours you want and levels are the z values for which you want to draw the contour.

Lorenzo


#6

I understood the meaning of your first two lines now… yes I havnt implemented any fitting function…
I performed simply - hcont2->Draw(“CONT2”) but this is not my desired result… i have attached :
rootcontour.pdf (36.1 KB)


#7

As I said you need to set the number of contours if you don’t like the default.
You should look at the documentation of the Contour option of TH2
https://root.cern/doc/v610/classTHistPainter.html#HP16

Lorenzo


#8

Thanks a lot… it worked with a little a more help from another example :slight_smile:


#9

I was using help from this very link only since 2 days but i wasnt able to set the contour levels…that I wanted


#10

How can I make my best fit point in this ? I am attaching the plot example1root.pdf (15.1 KB)


#11

I am not sure I have understood exactly what you want. Add a point in the plot ?
Maybe @couet can help you with this

Lorenzo


#12

(new TMarker(-3., 90., 30))->Draw();


#13

Hii… Thanks a lot , it made the best fit point but please tell me how did you write the entries in your statement given above…


#14

Hi,

Do you know how to make best fit point in gnuplot ??


#15

What do you mean by “write the entry” ? the code Wile proposed will draw a marker at the position (-3, 90)


#16

yes I realized it later… Thank you


#17

Hi,

I want to know how does root calculates confidence levels at 1,2 and 3 sigma values…
For one data file I am getting a plot using the code below but for another data file I am not getting a proper contour plot while both these files are giving contour plots with gnuplot… I am not able to get this…
I am using the code below…

Also I have one more doubt about contour plots… What i know is- If we have three columns x,y,z then we fix a particular value of z=confidence level and plot corresponding x and y… am I correct ?
Please help me out
Thank you…

#include<iostream>
#include<math.h>
#include <TVirtualFitter.h>
#include <TF2.h>

void rootContourPlot()

  {

   ifstream f1;
   TCanvas *c1 = new TCanvas("c1","c1",600,400);
   TH2F *hcont2 = new TH2F("hcont2"," ",40,0,360,40,0,0.9);

   Double_t x[10001]={0.}, y[10001]={0.},z[10001]={0.},i,j,k;
   int ss=0;

   double contours[3];
   contours[0] = 2.3;
   contours[1] = 6.2;
   contours[2] = 11.8;
  
   f1.open("test12.dat");
   while(!f1.eof())
      {
      f1>>i>>j>>k;

      hcont2->Fill(i,j,k);
     

       }
   hcont2->SetContour(3,contours);
   hcont2->Draw("CONT1");
//   (new TMarker(-3., 90., 30))->Draw();    // Makes the best fit point
   c1->Update();
   f1.close();

   }

#18

Can you provide the data files ?


#19

datafiles.tar.gz (23.1 KB)

Hi,
Please find the tar file which contains the datafiles.
Thank you.


#20

In case of test1.dat you are filling the histogram outside its limits. SO all the Fill() you do generate underflow or overflow and the histogram is empty.