Histogram macro isn't drawing branch data

I’m trying to create a histogram using data in a given tree, but the baseline code doesn’t seem to create a histogram.

#include "TCanvas.h"
#include "TROOT.h"
#include "TH1.h"
#include "TLegend.h" //used for adding a legend in the histogram at the end
#include "TFile.h"
#include "TTree.h"

void Hist_Drawer() {
      auto RCanv = new TCanvas;
      TFile f("file name");
      f.cd("internal directory");

     TTree *treename = (TTree*)gDirectory->Get("Tree");
     TH1F *hist1 = new TH1F("hist1","Histogram",100,0,70);
int main() {

It opens the new canvas, but the branch isn’t drawn in the histogram. I’m using this method because I need to draw other histograms and plot them on the same axis while scaling all of the data evenly. Am I doing something wrong with the code?

Try to add:

hist1->SetDirectory(gROOT); // (gROOT) ... or ... (0)

Yep, that seemed to work. Thank you!

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