Histograms coming out blank when filling from TTree

Hi,

I am having a problem filling a particular histogram. I have a root file which contains numerous variables saved in a tree. I am able to open the root file, get the tree (which is saved in a directory) and then SetBranchAddress for each of the variables. I then loop through the entries in the tree and try to fill many histograms. Each are filling apart from one histogram. It is a histogram that labels whether an event is signal or background (hence the variable only contains the values of 1==background or 0==signal). Note that the root file that the variable comes from is saved in a histogram declared as a TH1F. The histogram I am trying to draw (classID) has the number of correct entries, but they are all going into the overflow, when they need to be between 0 and 2. classID

     TFile *file =  new TFile("MVA_fold1.root", "READ");

     TTree *tree = (TTree*)file->Get("dataset_1o2/TestTree");

     Int_t  classID;

     tree->SetBranchAddress("classID", &classID);

     TH1F *h1 = new TH1F ("classID", "classID", 2, 0.0, 2.0);

     Long64_t n_entries = (Long64_t)tree->GetEntries();

     for (Long64_t entry = 0; entry < n_entries; entry++){
       tree->GetEntry(entry);
      h1->Fill(classID);
     }

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi,

what do you see if you print the values of classID?

Cheers,
D

Hi,

I figured out what was wrong. Thank you for taking the time though.

Hi,

for our user community: what was exactly the issue?

Cheers,
D

Hi,

I had this line wrong:

    tree->GetEntry(entry);

I amended the code above.

1 Like

What did you have before?

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