Problem in filling a tree branches

Try to run it through ACLiC (and fix reported errors):
root [0] .x twodim_new.cc++

For example, I can see that you need to move some definitions to outside of “if statements”:
double z1_mass, z2_mass, z3_mass;

BTW. You should really start with a ROOT generated “analysis skeleton”. The simplest thing to try could be (and then see how your tree branches should be defined):
AnaTree->MakeClass();