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;
centBins.push_back(0.0);
centBins.push_back(0.1);
centBins.push_back(0.4);
centBins.push_back(0.8);

float binLo = centBins.at(icent);
float binUp = centBins.at(icent+1);

for(int icent=0; icent<centralityBins; icent++){
treeTru->Draw("pt>>hPtPlusGenCutCent[icent]","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&&charge==1&&centrality>=binLo&&centrality<binUp");
}

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 = centBins.at(icent);
        float binUp = centBins.at(icent+1);
        std::cout << binUp << std::endl;

        TString binCut = "centrality>=";
        binCut+=binLo;
        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&&";
        cuts+=binCut;
        TString cutsPlus = cuts + "&&charge==1";
        TString cutsMinus = cuts + "charge==-1";
        treeTru->Draw("pt>>hPtPlusGenCutCent[icent]",cutsPlus);

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.


treeTru->Draw(TString::Format("pt>>hPtPlusGenCutCent[%i]",icent).Data(),cutsPlus);
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

sprintf(hPlusGenCut,"hPtPlusGenCutCent%i",icent);

so this works.

treeTru->Draw((TString("pt>>")+hPlusGenCut).Data(),cutsPlus);

Thanks again for all your help!