# Contour Plot with bin error

**URL:** <https://root-forum.cern.ch/t/contour-plot-with-bin-error/43646>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [February 21, 2021, 5:08pm UTC](https://root-forum.cern.ch/t/contour-plot-with-bin-error/43646 "2021-02-21T17:08:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matt/32/30804_2.png) [@matt](https://root-forum.cern.ch/u/matt)\
**Post date:** [February 21, 2021, 5:08pm UTC](https://root-forum.cern.ch/t/contour-plot-with-bin-error/43646/1 "2021-02-21T17:08:47Z")

</div>

ROOT Version:\_ 6.18/00  
Platform:\_ Ubuntu 20.04

I wanted to plot this figure

 ![pic](https://root-forum.cern.ch/uploads/default/original/3X/6/3/63cc245210407d1b59fae9544fa540a7ac9fe51b.png) . Which is from this paper [https://arxiv.org/pdf/hep-ex/0606028.pdf](https://arxiv.org/pdf/hep-ex/0606028.pdf). Here is the root file.[data.root](https://root-forum.cern.ch/uploads/short-url/3VgY8Y53AWLSD7LkfdOLIO1RzPu.root) (8.1 KB) .

Here is my code. [dat\_root.C](https://root-forum.cern.ch/uploads/short-url/oeE2dlrrbJu7OcHvTxRzp8mzmo9.C) (1.7 KB) and the text file [data.txt](https://root-forum.cern.ch/uploads/short-url/hwhaHiDS81epEbPPlvp25KSfxON.txt) (7.7 KB) . Can anyone please help me? I wanted to add the error (I hope the data is sufficient to for the error ).

```auto
#include<iostream>
#include<fstream>
#include<TFile.h>
#include<TNtuple.h>
#include<TCanvas.h>
#include<TH2F.h>

void dat_root()
  { 
   ifstream data;
   Float_t xF, pT, xsect, error;
   
   data.open("data.txt");
   TFile* file = new TFile("data.root","RECREATE");
   
  // TTree* tree = 0;
   
   TNtuple* ntup = new TNtuple("ntup","import data file","xF:pT:xsect:error");
   
   while(1){ 
   data>>xF>>pT>>xsect>>error;
   if(!data.good()) break;
   
   ntup->Fill(xF,pT,xsect,error);
  // cout<<xF<<pT<<xsect<<error<<endl;
   }
   
   data.close();
   file->Write();
    
   file->Get("ntup");
   
   //access branch 
   
   ntup->SetBranchAddress("xF",&xF);
   ntup->SetBranchAddress("pT",&pT);
   ntup->SetBranchAddress("xsect",&xsect);
   ntup->SetBranchAddress("error",&error);
   
    Int_t nEntries = 271;
    Int_t nbins = 270;   
   
   TH2F* hist = new TH2F(""," ",nbins,0,0.5,nbins,0,1);
   TH1F* hist_c = new TH1F(""," ",nbins,0,700);//,nbins,0,1);
   TCanvas* c = new TCanvas("c","",800,600); 
    
    
   for (Int_t i = 0; i<nEntries; i++)
     { 
       ntup->GetEntry(i);
       hist->Fill(xF,pT);
      // hist_c->Fill(xsect,error); 
       //hist_c->Fill(xsect,error);    
     }
     
   hist->SetMarkerStyle(kFullDotMedium);
   hist->SetMarkerColor(1);
  
   hist->GetXaxis()->SetRangeUser(0,0.5);
   hist->GetYaxis()->SetRangeUser(0,1); 
   //ntup->Draw("xF:pT","xsect","COLZ");
  // hist->SetCellError(xF,pT,error);
   hist->Draw("COLZ");  
   hist->SetLineColor(kBlack);
   //ntup->Draw("pT:xF","error","colz"); // for weighting with error
 // hist_c->Draw("COLZ SAME");   
   hist->GetXaxis()->SetTitle("Feynman Variable xF");
   hist->GetYaxis()->SetTitle("Momentum Transverse pT");
   c->Update();
}

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 22, 2021, 7:59am UTC](https://root-forum.cern.ch/t/contour-plot-with-bin-error/43646/2 "2021-02-22T07:59:03Z")

</div>

1. this is not a COL plot but it is a BOX plot
2. the number of bins (270) for your histogram is much larger than the number of bin of this plot. Also the binning of the plot seems to be not regular. So a regular binning as you do is not right very likely.

May be you should try ask for the orignal macro which produces this plot.

---

<div class="post-metadata">

**Author:** ![matt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matt/32/30804_2.png) [@matt](https://root-forum.cern.ch/u/matt)\
**Post date:** [February 22, 2021, 9:25am UTC](https://root-forum.cern.ch/t/contour-plot-with-bin-error/43646/3 "2021-02-22T09:25:53Z")

</div>

Okay. Thanks a lot for the reply.
