Reading file form NTuple and drawing histogram

Hi!
Recently I’ve started learning Root. Now I’m supposed to draw histograms form NTuple file. Well, maybe it sounds trivial, but I’ve got some problems. My program doesn’t show any erros but also any histograms…

I’ve done:

root group.phys-higgs.10878592._000001.hist-output.root 
root [1] .ls
root [2] NOMINAL->MakeClass("MyAnalysis")

(NOMINAL is a name of branch in which is leaf I wanted to draw.)
Which gave me MyAnalysis.h and MyAnalysis.C files. I tried to write my code for histogram for one leaf of my NTuple in MyAnalysis.C and it looks like this:

#define MyAnalysis_cxx
#include "MyAnalysis.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void MyAnalysis::Loop()
{
   TH1F *h0  = new TH1F("h0" ,"tau 0 transverse momentum",100,0,485);
  //that part was automaticly made in MyAnalysi.C
     if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();

   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
   
   //And this is my try
    h0->Fill(ditau_tau0_pt);
    TCanvas *can = new TCanvas("can","can",600,600);
   can->cd();
   h0->Draw();

   TFile  outputFile("histoanal.root","RECREATE");

   outputFile.cd();
   h0->Write();
   outputFile.Close();

}

I will apreciate any help. Thank you in advace!

Hve you checked that fChain exists? Modify this line and see if you get the message:

    if (fChain == 0) { cout << "fChain is null" << endl; return; }
    // ...
    h0->Fill(ditau_tau0_pt);
   } // end of the "for" loop
    TCanvas *can = new TCanvas("can","can",600,600);
    // ...

BTW. You need to call MakeClass for the whole TTree, not for a single TBranch.

I did that and nothing happend - when I run the code I see only:

root [0]
Processing MyAnalysis.C...
(MyAnalysis) @0x7fffcc0a3630
'''

You need to follow “usage instructions” shown in the generated “MyAnalysis.C” file. Something like:

root [0] .L MyAnalysis.C
root [0] MyAnalysis t;
root [0] t.Loop();

It works! I didn’t know that I have to follow this usage instuctions, I thought of it as a kind of example.
Thanks a lot!