Problem Filling a Histogram

Hi,

I am having trouble pushing back a leaf from my TChain into a histogram. The reason being, I have named my leaf with whitespace at the start of the name :frowning: . This causes the name of the leaf not to be recognized when I try to fill the histogram.

The example code is here:


TChain mychainJ0("jetVariables");

mychainJ0.Add(filename);
..
..
..
..

//I tried this but it didn't work
mychainJ0.GetLeaf(" nt_jet_pt").SetName("nt_jet_pt");                                                                        

myhist_MC10_Pythia_J0_pt = new TH1F("myhist_MC10_Pythia_J0_pt","", binnum, bins);


canvas1.cd(1);
mychainJ0->Draw(" nt_jet_pt>>myhist_MC10_Pythia_J0_pt");

The error message is as follows:

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

I have tried to change the name of the leaf using the SetName() member function, but it doesn’t work for me. Perhaps I am using it incorrectly.

Does anyone have any idea how to solve the whitespace problem I am having?

Cheers,

Mike

[quote]Does anyone have any idea how to solve the whitespace problem I am having?[/quote]The easiest is to regenerate the file without the white space in the name.

The exact set of things to change/update depends significantly on how you created the branch. If you add just a TTree, you might be able to pull it off (and get it to work with TTree::Draw).
However with a TChain is almost hopeless, as you would need to change the name every single time the TChain opens a new file.

If you are unable to re-write the files, you will need to fill the histogram by hand by using the result of TTree::MakeSelector or TTree::MakeProxy.

Cheers,
Philippe.