Wrong filling of THnSparse object

Hello
I am filling 7 axis THnSparse object with MakeClass before that
And for 6 and 7-th of them I have overflows and underflows
I do not see what is wrong with it :frowning:

[code]#include <THnSparse.h>
void HI_JPsi_MinBias_el::Loop()
{
if (fChain == 0) return;
int dims = 7;
int nbins[7] = {11 ,20 ,20 ,100 ,125 ,125 ,82 };
float mins[7] = {-0.5,-0.5 ,-0.5,-5 ,-25 ,-25 ,-0.05 };
float maxs[7] = {10.5,19.5 ,19.5,5 ,100 ,100 ,0.2 };

Int_t* bins = new Int_t[dims];
Double_t *xmin = new Double_t[dims];
Double_t *xmax = new Double_t[dims];
for(int i =0;i<dims;i++)
{
bins[i]=nbins[i];
xmin[i]=mins[i];
xmax[i]=maxs[i];
}

THnSparseF *hist_R30 = new THnSparseF(“hist_R30”,“hist_R30”,dims,bins,xmin,xmax);

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;

Double_t *vals = new Double_t[24];
vals[0]=5.0;
vals[1]=11.0;
vals[2]=12.3;
vals[3]=3.4;
vals[4]=56;
vals[5]=54;
vals[6]=0.1;
hist_R30->Fill(vals);

}//End of HI_JPsi_MinBias_el::Loop

TFile* f=new TFile(“Data_electrons.root”,“recreate”);

hist_R30->Write();

f -> Close();
f -> Write();
}[/code]

Hi,

Yikes - really, you will benefit from reading an intro to C++. You create several memory leaks. Use the following code instead:

#include "THnSparse.h"
void HI_JPsi_MinBias_el::Loop()
{
  if (fChain == 0) return;
   const int dims = 7;  
   static const int nbins[7]  = {11  ,20   ,20  ,100  ,125   ,125  ,82    };
   static const double mins[7] = {-0.5,-0.5 ,-0.5,-5   ,-25   ,-25  ,-0.05 };
   static const double maxs[7] = {10.5,19.5 ,19.5,5    ,100   ,100  ,0.2   };

   THnSparseF *hist_R30 = new THnSparseF("hist_R30","hist_R30",dims,nbins,mins,maxs);

  Long64_t nentries = fChain->GetEntriesFast();
  Double_t vals[7] = {0};

  for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      fChain->GetEntry(jentry);

   vals[0]=5.0;
   vals[1]=11.0;
   vals[2]=12.3;
   vals[3]=3.4;
   vals[4]=56;
   vals[5]=54;
   vals[6]=0.1;
   hist_R30->Fill(vals);
  }//End of HI_JPsi_MinBias_el::Loop

  TFile* f=new TFile("Data_electrons.root","recreate");

  hist_R30->Write();
  delete f;
  delete hist_R30;
}

If that doesn’t work I will need much, much more info:

  • ROOT version?
  • operating system?
  • complete code?
  • which input files?
  • what’s the error message?

Cheers, Axel.