Entries in TNtuple are being overwritten when using TCuts

I am trying to analyze some data and am using a TNtuple to hold the data. I create cuts to examine subsets and the draw the ntuple in order to get the mean from it. The mean should always be greater than zero, since each instance of the variable I’m look at for the mean calculation (it is descriptively called “val”) is between ~150 and ~400. When running the code, it is outputting to screen the value of the mean of the histogram produced by draw. Zero is bad. It implies that the cut applied resulted in zero entries into the histogram. The “dcut” cut seems to be the only cut that is producing the empty set (but it shouldn’t, try n->Draw(“d:val”) in the .root file produced).The behavior I’m seeing I can’t explain, and I bet it is something simple.

Attached is some code to illustrate the problem. Some more odd behavior:

After running it and still in CINT, I can do n->Scan() and see that all of the entries are the same. If I do n->Scan() somewhere around line 200 (before the nested for loops) then I see that the entries are (nearly) all unique.

At the end of running, the ntuple is written to disk. If one opens this ntuple and does n->Scan() the entries are all (nearly) unique again.
chisquare2.C (2.51 KB)
feb16.txt (436 KB)


The issue is the retrieval of the created histogram (i.e. most time in the code you send, it turns out htemp is not pointing to the histogram you are looking for, see the result of htemp->GetTitle() for confirmation).

Use: n->Draw("val>>htemp",dcut); htemp = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp"); double mean = htemp->GetMean(); cout << htemp->GetTitle() << " : " << mean <<endl; delete htemp;