# Can't get histogram to draw after reading from .root file

**URL:** <https://root-forum.cern.ch/t/cant-get-histogram-to-draw-after-reading-from-root-file/44937>\
**Category:** Newbie\
**Created:** [May 17, 2021, 10:15pm UTC](https://root-forum.cern.ch/t/cant-get-histogram-to-draw-after-reading-from-root-file/44937 "2021-05-17T22:15:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacob\_Repucci](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jacob_repucci/32/24488_2.png) [@Jacob\_Repucci](https://root-forum.cern.ch/u/Jacob_Repucci)\
**Post date:** [May 17, 2021, 10:15pm UTC](https://root-forum.cern.ch/t/cant-get-histogram-to-draw-after-reading-from-root-file/44937/1 "2021-05-17T22:15:17Z")

</div>

I’m trying to write some code that reads in a histogram from a .root file and then graphs it. However, for whatever reason, when I run the code, it reads in the histogram fine (according to a cout statement which says I have ~100 entries in it, which is what I expected) but it refuses to draw it. I tried messing around with using .Paint() for the histogram instead of .Draw() and using .Modified() and .Update() for the canvas, but when I do that the histogram flashes briefly on the canvas before disappearing. Does anyone know how to resolve this?

Here’s my code for reference:

```auto
#include "TPythia8.h"
#include "TClonesArray.h"
#include "TParticle.h"
#include "TCanvas.h"
#include "TH2F.h"
#include "TMath.h"
#include "TLorentzVector.h"
#include "TVector3.h"

#include <cmath>
#include <vector>
#include <math.h>

using namespace Pythia8;
using namespace std;
using namespace RooFit;

void drellyan_read(Double_t dilution_factor=0.250) {
	cout << "Starting code\n";
	gSystem->Load("libEG");
	gSystem->Load("libEGPythia8");

	//print graphing results
	gStyle->SetOptFit(1111);

	cout << "Reading data \n";

	TFile allbinsfile("allbinsfile.root");
	TH2F * eq_9_hist = (TH2F *) allbinsfile.Get("equation_9_fit");

	cout << "Eq 9 N: " << eq_9_hist->GetEntries() << "\n";

	cout << "Data read!\n";

	// ******************
	// ***GRAPH DATA***
	// ******************

	//drawing the fit of eq 9
	cout << "Making the canvas\n";
	TCanvas * ca = new TCanvas("Eq 9 Fit", "Eq 9 Fit", 1200, 600);
	cout << "Canvas made!\n";

	eq_9_hist->Paint("Colz");
	ca->Modified();
	ca->Update();
	cout << "Drawing complete\n";
} //macro function

```

* * *

_ROOT Version:_ 6.22  
_Platform:_ Ubuntu 18.04.5  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 17, 2021, 10:20pm UTC](https://root-forum.cern.ch/t/cant-get-histogram-to-draw-after-reading-from-root-file/44937/2 "2021-05-17T22:20:22Z")

</div>

```cpp
#include "TROOT.h"
// ...
	eq_9_hist->SetDirectory(gROOT);
	eq_9_hist->Draw("COLZ");

```
