Error in <TTreeFormula::Compile>: Bad numerical expression

Dear Rooters,

I am trying to simply fill a histogram with the tree->Draw(“var>>histo”) method. I do this by

std::vector <float> centBins;

float binLo =;
float binUp =;

for(int icent=0; icent<centralityBins; icent++){

However, I get the error when running myScript.C++

Error in TTreeFormula::Compile: Bad numerical expression : “binLo”

Past threads I’ve looked at mention generating a dictionary, but I’m unsure if that’s the problem in this case.

[url]Bad numerical expression?
[url]Problem in applying cuts
[url]T(Tree)Formula and variables
[url]Error in TTreeFormula::Compile
(BTW. You can “Search…” the forum for “Bad numerical expression” and see what you get -> that’s how I got these above links for you.)

Thanks Pepe. (For those interested, the following method also works

        float binLo =;
        float binUp =;
        std::cout << binUp << std::endl;

        TString binCut = "centrality>=";
        binCut+= "&&centrality<";
        binCut+= binUp;

        //generator level muon tracks in fiducial region
        TString cuts = "prompt==24&&val>10&&abs(eta)<2.5&&abs(eLoss)<0.5&&abs(scat)<4.0&&pt>25&&  pt<100&&nu_pt>20&&ptcone20/pt<0.5&&mt>40.0&&mt<120&&";
        TString cutsPlus = cuts + "&&charge==1";
        TString cutsMinus = cuts + "charge==-1";

There still seems to be a problem (and the answer is probably simple), but when I execute the code below, the histogram hPtPlusGenCutCent[%i] fills correctly, but the call to Integral() returns a value of 0.

float ptPlusGenCutTemp = hPtPlusGenCutCent[icent]->Integral();
std::cout << "Integral\t" << ptPlusGenCutTemp <<std::endl;

To be clear, the entries in the histo are not empty (I checked this), so the problem is with how I’m calling the method.

Are you trying to say that the NAMES of your histograms are “hPtPlusGenCutCent[0]”, “hPtPlusGenCutCent[1]”, “hPtPlusGenCutCent[2]”, …
ROOT will, of course, happily create histograms with such crazy names when you use “>>” in the Draw call.

In contrary, the call “hPtPlusGenCutCent[icent]->Integral();” seems to suggest that the “hPtPlusGenCutCent” is a table of histogram pointers.

The name is


so this works.


Thanks again for all your help!