Histogram not being filled

Hello,

I have a loop in my program which is outputting the variables that pass an if statement but is then not filling my histogram. The problem lines of code are:

  for ( int i=0 ; i<nvars ; i++){
    cout << endl << endl << "Starting " << varsName[i] << endl;

    c[i] = new TCanvas("c" + varsName[i], varsName[i]);
    hs[i] = new THStack("hs" + varsName[i], varsName[i] + ";" + varsLabel[i] + " " + units[i] + ";Events");
    varHist[i][0] = new TH1F("hSig" + varsName[i], varsName[i] + " , signal", 100, XlimitsLower[i], XlimitsUpper[i]);
    varHist[i][1] = new TH1F("hBck" + varsName[i], varsName[i] + " , background", 100, XlimitsLower[i], XlimitsUpper[i]);
    cutHist[i][0] = new TH1F("hSig" + varsName[i] + "_afterCuts", varsName[i] + " , signal after cuts", 100, XlimitsLower[i], XlimitsUpper[i]);
    cutHist[i][1] = new TH1F("hBck" + varsName[i] + "_afterCuts", varsName[i] + " , background after cuts", 100, XlimitsLower[i], XlimitsUpper[i]);

    for ( int k=0 ; k<2 ; k++){
      for ( int j=0 ; j<nEntries[k] ; j++){
        if ( k==0 ) {sigTree->GetEntry(j);}
        if ( k==1 ) {bckTree->GetEntry(j);}
        varHist[i][k]->Fill(vars[i][k]*sf[i]);

        if ( vars[0][k]*sf[0] > cutVals[0][0] && vars[0][k]*sf[0] < cutVals[0][1] && vars[1][k]*sf[1] > cutVals[1][0] && vars[1][k]*sf[1] < cutVals[1][1] && vars[2][k]*sf[2] > cutVals[2][0] && vars[2][k]*sf[2] < cutVals[2][1] && vars[3][k]*sf[3] > cutVals[3][0] && vars[3][k]*sf[3] < cutVals[3][1] && vars[4][k]*sf[4] > cutVals[4][0] && vars[4][k]*sf[4] < cutVals[4][1] && vars[5][k]*sf[5] > cutVals[5][0] && vars[5][k]*sf[5] < cutVals[5][1] ) { 

          cout << vars[i][k]*sf[i] << endl;
          cutHist[i][k]->Fill(vars[i][k]*sf[i]);

        }
      }
    }
}

Thanks in advanced for your help!


_ROOT Version: ROOT 6.14/06 Built for linuxx8664gcc


SLT_NR_VariablePlots_PostCuts.C (8.5 KB)
SLT_NonResonantPlots_AfterCuts.root (46.3 KB)

If you see the output from the “cout” in the loop on your screen then I assume the x-range of your histograms is not correct. Try to create them with “automatic binning”: new TH1F("...", "...", 100, 0., 0.)

Hi,

I know the bins are correct as they are filling for the varsHist but not the cutHist. I have attached the full C file and the root output file to the original message so you can see in more detail what I have done and the outputs I am getting.

Maybe you want

        if ( k==0 ) {sigTree->GetEvent(j);}
        if ( k==1 ) {bckTree->GetEvent(j);}

instead of GetEntry?

Try with:

if ( vars[i][k]*sf[i] > cutVals[i][0] && vars[i][k]*sf[i] < cutVals[i][1] ) { /* fill cutHist[i][k] here */ }

With

Maybe you want

        if ( k==0 ) {sigTree->GetEvent(j);}
        if ( k==1 ) {bckTree->GetEvent(j);}

instead of GetEntry?

It now fills the histograms and shows up on the canvas but then is not printing as a png.

SLT_NR_VariablePlots_PostCuts.C (8.5 KB)
SLT_NonResonantPlots_AfterCuts.root (46.3 KB)

1. mBB (Events after Cuts)
2. mMMC (Events after Cuts)
3. mHH (Events after Cuts)
4. drBB (Events after Cuts)
5. drLepTau (Events after Cuts)
6. mtLepMet (Events after Cuts)

Try moving these lines:

  // save and close the outputfile
  outputFile->Write();
  outputFile->Close();

to the end of the PlotData function, i.e. after this

  for ( int i=0 ; i<nvars ; i++){
    delete img[i];
    delete c[i];
  }

Hi,

It didn’t like being after the delete section but I moved those two line to after the png’s were created and it works just fine now. Thank you for your help!

Well, TTree::GetEvent does exactly the same as TTree::GetEntry and that means that, if replacing one call with the other one changes something in the behaviour of your source code then there is something really really wrong in your source code.

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