Home | News | Documentation | Download

Creating and filling root tree in separate functions

I am struggling with filling a TTree which I create with one function, then pass it back to another function which fills it. It seems as though the tree is being filled the correct number of times, but only with the initialised values (all zeroes).

I’m adding some code exceprts to illustrate my problem, hopefully they are clear.

This is the function that creates the tree with its branches

TTree* CreateTree(RAW raw_new, CUBENEW cube_new, MONITORNEW monitor_new){
TTree* CubeTree = new TTree("CubeTree","CubeTree");
return CubeTree;

Which is then called in a function ‘eventgen’, and filled with simulated data:

int eventgen(char* sortfile, int Nevents){

RAW raw_new = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
CUBENEW cube_new = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
MONITORNEW monitor_new = {0,0,0,0,0};
TTree* CubeTree = CreateTree(raw_new,cube_new,monitor_new);

//some calculations are done and variables populated
cube_new.XBack = x_ch;
cube_new.YBack = y_ch;
cube_new.EBack = 0.5*mwpcBin.mass[i]*pow(mwpcBin.Vlab[i],2);
t_ns -= (rxn.T0 + rxn.dT);
cube_new.TBack = quadCorr(t_ns,&mwpcCorr[mwpcBin.detID[i]],&mwpcBin,i);
cube_new.XBackSmall = -10000;
cube_new.YBackSmall = -10000;
cube_new.EBackSmall = -10000;
cube_new.TBackSmall = -10000;

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.10/08
Platform: Ubuntu 18.04
Compiler: gcc v4:7.4.0


(and/or passing by pointer), the original version is passing copies of the object to the function.

Thank you for the prompt reply and solution to my beginners problem!