Home | News | Documentation | Download

Filling a histogram with ntuple entries with cuts

I have basic problems with operating on ntuple. All I can do is to read ntuple from loop made by MakeClass function. Now I’m suppposed to draw a histogram with bins whrere in the first one I have number of all events before preselction cuts, and next ones show number of events after each cut.
I wrote definotions for all of my cuts and then I have the part in my code form MakeClass:

   if (fChain == 0) { cout << "fChain is null" << endl; 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;
      // if (Cut(ientry) < 0) continue;

And then I have the part that draw me a histogram for the leaf with all events:

   int Events = h->GetEntries();
   cout << Events << endl;

However, I want to put all these entres to just one bin of histogram and then add bins with preselected events. I tried to use something like this:

if( !m_SR_passTrigger ) return false;
h->Fill(number of bin i guess, weight);

But all I get is empty histogram and the Events gives 0. And I have no more ideas on how aproach this problem. Thanks in andvace for any help!

if( m_SR_passTrigger ) h->Fill(number of bin i guess, weight);

Hi Ada,
note that there are simpler ways to read ROOT datasets than MakeClass.
With RDataFrame this is all the code you need:

#include <ROOT/RDataFrame.hxx>

void macro() {
  ROOT::RDataFrame df("treename", "filename.root");
  auto histo1 = df.Histo1D("NOMINAL_pileup_random_run_number");
  auto histo2 = df.Filter("m_SR_passTrigger").Histo1D("valuecolumn", "weightcolumn");
  /* do what you want with the histograms */

Hope this helps!