I have two codes indeed. One is with arrays and another one is with vectors. I simply try to see how to fill a Tree Branch with a vector. For some reason, macro doesn’t work with array-branch combination.
I attach the macro again. Probably, something went wrong when posting. I noticed that Xcode didn’t save the document when I was working on it as well. That’s why I had funny error at that time. Now, it’s worked. Anyways, I post it here.
By the way, macros are designed to create random numbers, but I will read data from a file and do calculation. Then, I will fill the vectors for my work.
Can you give me a website link I can refer to learn TTree examples with vectors?
I also want to know the difference between Branch() and SetBranchAddress() member functions? Both can have the syntax like below:
However, I guess the parameters of px values, for instance, should be different. For Branch(), it is a value, but it’s a pointer for SetBranchAddress(). Is that the case?
Just search this Forum (search icon on the top right side), there are many similar questions and replies.
For the Branch, etc. question, again search the Forum, or go to the TTree documentation: https://root.cern/doc/master/classTTree.html
and read and scroll down to the Public functions to read about Branch, SetBranchAddress and all other TTree functions. In general, to search for documentation, click on the Documentation link at the top of this (Forum) page, then click on the Search icon (top right) of the Doc page and search for any object (TTree, TGraph,…) or function (Branch, SetBranchAddress,…) you want to see the reference page and source code for (look for the results saying “Class Reference”).
For some reason, when we call this member function, we don’t use all the arguments (for instance T*tree) as far as I noticed. I type a part of the code to give an example.
What rule am I missing in c++ or ROOT when I try to understand the usage of member functions while calling them in my code?
TFile *f = TFile::Open(“myfile.root”, “RECREATE”);
if (!f) { return; }
TTree *T = new TTree(“T”, “Tree with vector”);
std::vector px;
std::vector py;
std::vector pz;
Not really a ROOT question. Anyway, to understand that, read about c++ function overloading and function arguments; then go back to the documentation pages.
Is that the specific concept and example I should know? For instance, to put only three out of 6 arguments (probably the other three were known and given previously, or set to some fixed value) were enough. I mean somebody probably set some of these arguments to some values in the function definition. That’s why it enables us top work with 3 parameters as well even though it seems it needs 6 arguments for function call.