accumulableManager->Merge() and rms calculation in exampleB1

Does ‘accumulableManager->Merge()’ merge the data from different events as well?

I thought the function merged the data returned by multiple threads so it wouldn’t do anything in a non-multithread mode. However, if this is true, the rms calculation in B1RunAction.cc of exampleB1 cannot be explained.

Currently,
G4double rms = edep2 - edep*edep/nofEvents;
if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;

I believe it should be like this:
G4double rms = (edep2 - edep*edep/nofEvents)/nofEvents;
if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;

, unless the Merge() function returns the ‘average’ of the data (deposited energy) from different ‘events’…

1 Like

We do not print the average value of edepPerEvent, but the sum of edepPerEvent over the run, eg. the total energy deposited in the run.
I believe that the rms formula of this sum is correct in exampleB1

Hi maire,

Thank you for the reply. I believe my question was a bit confusing. Let me split it into two.

  1. Am I understanding correctly that ‘accumulableManager->Merge()’ wouldn’t do anything in a non-multithread mode, as it merges the data returned by multiple threads?

  2. With regard to the quantity calculated for ‘rms’ in exampleB1,

G4double edep=fEdep.GetValue() calculates the sum of Ei, where Ei is the edepPerEvent, while G4double edep2=fEdep2.GetValue() calculates the sum of Ei^2.

The rms calculation is done in the following:
G4double rms = edep2 - edep*edep/nofEvents;
if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;

These two lines calculate rms = sqrt (sum of Ei^2 - (sum of Ei)^2 / nofEvents), which is ‘the sum of the squares of the deviations from the mean’ (https://people.richland.edu/james/lecture/m113/variation.html).

The ‘root mean square’ would be sqrt (sum of Ei^2 / nofEvents). The ‘root mean square of the deviations from the mean’, which I believe the code was trying to calculate, would be sqrt (sum of Ei^2 / nofEvents - (sum of Ei / nofEvents)^2), or sqrt (sum of Ei^2 - (sum of Ei)^2 / nofEvents) / nofEvents.

1- yes of course : in sequential mode, Merge( ) is nothing.
2- let me repeat what I said. Given a random variable X,
S = X1+X2+…+Xn is a random variable.
M = S/n is another random variable.
The formula in exampleB1 is for S, not for M.

1- Thank you for the clarification.
2- I understand edep is the sum of energy deposits. My question was about rms calculation.

I am speaking of the rms too ! The formula is what the mathematics give for the variance of the variable S. I encourage you to redo the calculation yourself.
But I am not a super expert in statistic, and I am not sure of how to interpret the formula.

This has become a statistics discussion, which I understand is not your expertise. Thanks for your time.