In a loop of events, I want to calculate a Gaussian for each event, using the corresponding mean and width of the event, but also summing all the gaussians after each event. This is what I tried (naively), which doesn’t work:
It is not clear to me exactly what you wnat to do it. It looks like you want to build a parametrize function as sum of many gaussian, each one for each single event. Is this really what you need ?
If you just want just to evaluate a Gaussian function on one event using a TF1 is not the optimal way to do it. You should use for example the TMath::Gaus function and do something like
gaus_tot = 0.
for iev in chain:
gaus_tot += ROOT.TMath.Gaus(x, iev.mean, iev.width, true) ## use true if you want a normalized gaussian
but it is not clear to me on what you are evaluating on, what is x ?
My apologies for the vague description, but I want to construct a PDF that is the sum of gaussians with as mean the value of the parameter I’m considering and the resolution as the standard deviation. Then I want to compare this resulting distribution to a certain histogram.
is the x here the amplitude of the Gaussian? Would it make sense if I equate it to the weight of the event?
The piece of code you wrote is exactly what I want to calculate, I want to know that specifi distribution which is the sum of the gaussians, however I don’t know how to plot the resulting distribution, TMath returns just a number right? Because I want to compare it to a histogram