Error while reading branch through array

Hello all,

I made a function to read a branch from tree. It is working when I call branch like:

or

but as soon as I put () for some arithmetics like:

it is giving me following error:

Traceback (most recent call last):
File “main.py”, line 32, in
readTree.treeDraw(branch=[“Lep0_pt*(Lep1_pt)” ])

File “/home/ramkrishna/AdvancedPlotting/readTree.py”, line 168, in treeDraw
yMax = make_histo(z,y,x,cut_t,yMax) # returned yMax so that its value will be reset again and agin in loop
File “/home/ramkrishna/AdvancedPlotting/readTree.py”, line 112, in make_histo
h[x].Scale(1./h[x].Integral())
ZeroDivisionError: float division by zero

Please suggest what I am doing wrong.

with regards,
Ram

Hi,

well, you’re dividing by zero (i.e. “h[x].Integral()” is zero). Since all the code you show here is your own, I can’t help you further than that.

Cheers,
Wim

Thanks Wim for reply.

Actually I am trying to make a general tree reader in which I just need to give name of branch and it will save histogram corresponding to each variable.

So, for that I made a function part of that is :

h[x] = TH1F(branch[y]+`x`,"",Nbins[y],Min[y],Max[y]) t[z].Draw("%s>>%s" % (branch[y],branch[y]+`x`),cut[cut_t],"goff")

And if I call the function like:

then it was working but in above statement if I define branch like “branch=[”(Wqrk1_pt)"]" name of branch within () then it was not working.

Actually I need () for creating new variables from defined branch in tree.

You can find the full code at link: github.com/ram1123/AutoPlotterR … eadTree.py

Hi,

but you don’t only use ‘branch’ for drawing. You also use it as title (fine, I’m sure) and histo id (likely not), so the filling in Draw() fails, the histogram is empty, and it’s Integral() result zero.

Try using histo id’s that do not contain special characters such as ‘*’, ‘(’, ‘)’, etc.

Cheers,
Wim

Dear Wim,

Is there not a way to do this? Because I need to draw branch which is defined like cos(b1-b2). But it is not working. I think because of this only.

What if I define histo like this:

h[x] = TH1F("test"+`x`,"",Nbins[y],Min[y],Max[y]) t[z].Draw("%s>>%s" % (branch[y],"test"+`x`),cut[cut_t],"goff")

I tried but it is again giving me following error:

ERROR in TPDF::Open: Cannot open file:

Hi,

since you also use ‘branch’ as the file name, make sure that all characters used in the name are understood by the OS. Further, you don’t have a Open() call in the code you showed, so not sure what where that message is coming from. Anyway, just make sure that the file names match.

Cheers,
Wim