Hi,
there are several ways, in ROOT, to access the content of a TTree and fill an histogram.
This answer goes over the most common ways to do it and shows some example code. TTree::SetBranchAddress
, that you are using in your snippet, is the lower-level, hands-on-the-internals way, mostly meant for expert users nowadays.
If you have access to ROOT v6.14, I agree with @Danilo that RDataFrame is the simplest way to produce a histogram from a TTree (at the time of the answer I linked, it was still called TDataFrame
). Here’s an example snippet:
// rdf.C
void rdf()
{
ROOT::RDataFrame df("Analysed_Data", "run07*.root"); // build the dataframe
ROOT::RDF::TH1DModel hm("h1", "h1", 180, 0 180); // build a histogram model
auto h1 = df.Histo1D(hm, "Theta_p"); // ask the dataframe for a histogram of Theta_p with binning like the model's
h1->Draw("colz") // draw the histogram
}
Hope this clarifies things.
If you have more specific questions feel free to post them here or in a new thread.
As far as how I fell, I HAVE TO create something which is, for instance, a histogram to store the content of, for example, a branch from a TREE of CHAIN. Can anyone approve this theory of mine?
No, that’s not correct. You can do whatever you want with the values you read from a TTree, you can sum them together, forget about them, use them to fill a histogram…your choice.
One thing I notice, you should define the branch type correctly, otherwise it doesn’t work
Of course
TTree::Draw
and, for most common operations, RDataFrame
offer interfaces that do not require that you specify the type of a branch to do things with it, but in the general case you will have to put the branch value in a variable (e.g. when using TTree::SetBranchAddress
and that variable must be of the correct type). Higher-level interfaces (e.g. RDataFrame
and TTreeReader
will complain if there is a type mismatch).
Cheers,
Enrico