Selective filling of a histogram

From: Roger Mason <rmason_at_esd.mun.ca>
Date: Fri, 31 Oct 2008 06:06:19 -0230


Hello,

I'm trying to fill a histogram selectively using the following code (generated using TTree::MakeClass the modified):

#define MyClass_cxx
#include "MyClass.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void MyClass::Loop()
{
  if (fChain == 0) return;

  Long64_t nentries = fChain->GetEntriesFast();  

  Double_t min = 0;
  Double_t max = 0;

  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;
    if ( ientry == 0)
      max = min = energy;
    if ( energy < min )
      min = energy;
    if ( energy > max )
      max = energy;
  }
  cout << " Min = " << min << " max = " << max << endl;

  TH1D *henergy = new TH1D("energy","energy(eV)",100,min-max/10,   max+max/10);
  TH1D *h = new TH1D("selected","energy(eV)",100,min-max/10,   max+max/10);
  TCanvas *canv = new TCanvas("canv","Canvas");

  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;
    henergy->Fill(energy);

    if ( energy > -2143.58 ) {

      //      cout << "Energy = " << energy << endl;
      h->Fill(energy);

    }
  }

  h->SetFillColor(2);

  henergy->Draw();
  h->Draw("same");
  canv->Modified();
  canv->Update();
}

I run the code:

root [0] .L MyClass.C
root [1] MyClass m
root [2] m.Loop()

 Min = -2143.61 max = -2143.55

but histogram h is alway empty.

Can someone point out what is wrong?

Thanks,
Roger

ROOT 5.20/00 (trunk_at_24524, Sep 30 2008, 15:32:00 on linux) Received on Fri Oct 31 2008 - 09:38:09 CET

This archive was generated by hypermail 2.2.0 : Fri Oct 31 2008 - 11:50:02 CET