Chains and plot histogram

Hi all
I have two root files file1.root , file2.root “they are in attachment” and each file contains one ntuple “data”
and I create a chain with the with the following statement

[code]TChain chain("data"); chain .Add("file1.root"); chain.Add("file2.root"); chain.Draw("Ei") Error in <TTreeFormula::Compile>: Bad numerical expression : "Ei"[/code]
what is the problem ?
and the second thing How can I plot many histogram in one macrofile and read file1.root ,file2.root together like that

data.Draw("N","Decay==1") data.Draw("Ep","Decay==1")
ascii2root2.C (827 Bytes)
ascii2root.C (981 Bytes)
file2.root (216 Bytes)
file1.root (25.4 KB)

Hi, the simplest way to do that is to use the “hadd” binary
In a terminal, you can do

At the end, you will have a out.root file which contains the data from file1.root merged with file2.root ones.

So, you just have to open out.root file as file1.root and do the command that you want.
E.g.

data.Draw("N","Decay==1") data.Draw("Ep","Decay==1")
should work

Thank you

Hi ,
It is not work
root [12] hadd -h out.root file1.root file2.root Error: Symbol hadd is not defined in current scope (tmpfile):1: Error: Invalid type 'h' in declaration of 'out' (tmpfile):1: Error: Invalid type 'h' in declaration of 'out' (tmpfile):1: Error: Invalid type 'h' in declaration of 'out' (tmpfile):1: Error: Invalid type 'h' in declaration of 'out' (tmpfile):1: Error: Symbol h out is not defined in current scope (tmpfile):1: Error: Failed to evaluate h out.root file1 Error: Failed to evaluate h out.root file1.root file2 Error: Failed to evaluate h out.root file1.root file2.root (const int)0
what is the problem?

You need to distinguish the command prompt (e.g. bash) from the ROOT prompt. “hadd” is a binary program that comes bundled with ROOT, but it’s not a command inside ROOT itself. The binary should live at $ROOTSYS/bin/hadd.

As to your original post, the “Bad numerical expression: Ei” is probably because there is no such branch in your TTrees. Try looking at your TChain using a TBrowser, or do TChain.Print() to see the list of branches. I’m betting there isn’t one called “Ei”. The name needs to match exactly for TChain::Draw to work.

Jean-François

Hi all,
I try another branch and I still have the same problem

TChain chain("data") root [3] chain.Add("file1.root") (Int_t)1 root [4] chain.Add("file2.root") (Int_t)1 root [5] chain.Draw("Ap") Error in <TTreeFormula::Compile>: Bad numerical expression : "Ap" root [6] TChain.Print() Error: Symbol TChain is not defined in current scope (tmpfile):1: Error: Failed to evaluate TChain.Print()
:frowning: :frowning: :frowning: :frowning: :frowning:

If you choose to use hadd, you have to do it in your bash terminal (or other), not in the ROOT prompt
Note I wrote a mistake previously, the “-h” option does not exist
You should type (in a “classic” terminal)

Concerning your last post, you have to type

not “TChain.Print()”