Problems using Form when drawing a TTree branch

Hi,

I want to loop over a load of branches of a TTree and draw each branch as a histogram. I’ve been trying to do this as follows:

TObjArray *branches = MyTree->GetListOfBranches();
int nbranches = branches->GetEntries();

for (int i = 0; i < nbranches; ++i) {
string branchname = ((TBranch*)(*branches)[i])->GetName();
MyTree->Draw(Form("%s>>hist", branchname),“m_PassCuts == 1”);

}

The problem I’ve been getting is errors like:

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

I’m using ROOT 5.29.02 using SL5. I used to use the same code in an older version of ROOT (v5.24.00) & in SL4 and it used to work fine so I’m not sure why it doesn’t work now.

Any ideas about how to solve this would be much appreciated!

Thanks,
Gemma

Hi,

You meantMyTree->Draw(Form("%s>>hist", branchname.c_str()),"m_PassCuts == 1");and I recommend to use MyTree->Draw(TString::Format("%s>>hist", branchname.c_str()),"m_PassCuts == 1");

Cheers,
Philippe.

Hi Philippe,

Thanks, that worked perfectly!

Cheers,
Gemma