I have solved the problem. The source of the problem lies not in c++ but in the ROOT file. Root file has its tree, branch structure and leafs inside each branches. In the above example, I have a root file named
filen1, which has one
tree and it has 2
branches:
Particle1 and
Particle2, but it has 4
leafs in each
branches namely
spin,
charge ,
mass and
energy. So in the step where I am assigning the addresses to these variables, I have to maintain there order perfectly, while using an array,
spin should be the 0th element then
charge and so on. If I mess up the order, the conditions will be wrong and hence the code will return bogus results. So the correct code will be:
1 2 3 4
|
particle_spin[0] = &arr[0][0], particle_spin[1] = &arr[1][0];
particle_mass[0] = &arr[0][1], particle_mass[1] = &arr[1][1];
particle_energy[0] = &arr[0][2], particle_energy[1] = &arr[1][2];
particle_charge[0] = &arr[0][3], particle_charge[1] = &arr[1][3];
|
And in fact I can use two dimensional array for the other parameters too, by identifying their order. So the above assignments will now look like:
1 2 3 4 5 6 7
|
for(i = 0; i < 2; ++i)
{
for(j = 0; j < 5; ++j)
{
param[i][j] = &arr[i][j];
}
}
|
I have to keep in mind that, in
param[i][j],
i = 0, 1 would be
particle 1, 2 respectively and
j = 0, 1, 2, 3, 4 would mean
spin, mass, energy, charge respectively.
Of course an order like that is expected but as I am almost an absolute newbie in C++ and ROOT, it took time to understand this.
Anyways.. thanks everyone.