I am developing a GEANT4 simulations that gives a ROOT tree as an output, with the data I need. Inside of this tree I am trying to fill a Branch with an array of strings, that should contain the name of the processes involved in each particle interaction. I saw in some previous topic of the ROOT forum that it is possible to fill the branch with std::vectorstd::string.
So I wrote, putting a maximum limit of 1000 elements on the array:
[quote] RProcess = NULL
So it seems that the filling procedure doesn’t work. [/quote]Nope . This actually only means that TTree::Show does not properly print vector (of string).
[quote]So I wrote, putting a maximum limit of 1000 elements on the array:
std::vectorstd::string RProcess(1000);
[/quote]Actually, you create exactly 1000 strings which will each be stored in the file (whether you set them or not).
[quote]I tried as well defining the variable as a pointer,
[/quote]Which version of ROOT are you using? The non-pointer interface works for ROOT v5.20 and newer.
thanks a lot for the reply. (I am using root v20.0.) You were right. The data was actually in my ROOT branch, but it is not printed when I put t1->Show() Only if I write as you said in your example:
then I get the information. So it was actually working all the time, what was wrong was the way to extract the information out of this branch.
I just have discovered a different problem related to it. Storing those arrays of strings not only produces larger output files, but also requires 25 times longer simulation time.
Therefore I have decided to change to a different approach: I give a different number to each possible physical process, and in this way I substitute the array of characters by a simple array of integers.
Knowing the conversion between my integer quantities to the GEANT4 physical process I can always identify which process has been involved in each step of my simulation.
It is maybe a not very elegant way to do it, but it saves a very large amount of time.
Just for curiosity, is it normal that writing an array of characters consumes so much time?