Smearing of a variable inside a Tree

Hi,

I am using a root file which contains information about position and direction of the particles ( e.g. px, py, pz, x, y, z etc…) .

I need to to make a smearing to the variable pz according to a gaussian, centered to zero. I do not need to draw this variable, but when I call it, I require to get the new pz with the applied smearing on it. I found an example below but I don’t really understand how to do the variable correction, and also why the event number of the file is used as a seed? Any help would be appreciated.

for (int i = 0; i < Tree->GetEntries(); i++) {

myrandom3->SetSeed(TheEventNumberOfFile);
myrandom3->Gaus(0,a given value);
//make the correction to the variable

}

Thanks a lot,
Steve

Hi Steve,

indeed the setting of the seed can be put outside of the loop. The sequence of numbers will be reproducible by definition.
The code could look like:

...
myrandom3->SetSeed(MySeed);
const double the_pz_sigma = ...; 
...
for (int i = 0; i < Tree->GetEntries(); i++) {
   ...
   double smeared_pz_value = myrandom3->Gaus(the_pz_value, the_pz_sigma); // See https://root.cern.ch/doc/master/classTRandom.html#a0e445e213eae1343b3d22086ecb87314
   //make the correction to the variable
   ...
} 

Cheers,
D