# Weighted Monte Carlo Integration

I have a function $F(x)$ which drops exponentially (like differential QCD cross section vs. Invariant mass). I want to perform Monte-Carlo integration. The problem is that only small $x$'s which have large $F(x)$ are accounted. I mean if the range of $x$ is $[1, 8]$ TeV, the maximum value of $F$ is $F(1)$ and the minimum value of $F$ is $F(8)$ which differ by 8 orders of magnitude. Thus, only random generated $x$'s which are close to 1 are accepted. How can I generate large $x$? Thanks

• Why would you want to do that? The reason why large $x$ are not generated is because $F(x)$ does not contribute to the integral in a noticeable way for large $x$. Commented Apr 3, 2018 at 2:56
• Actually, the underlying problem is related to physics. At some large $x$ I have a bump in the curve which comes from the theory. That bump should be seen by the Monte Carlo Generator, although with a small probability. Commented Apr 3, 2018 at 3:10
• Is there a way to flatten the function? I saw this way of dealing with these kinds of curves (for example differential QCD cross-section ) in the ATLAS papers but don't know a starting point to learn it. Commented Apr 3, 2018 at 3:12
• Can you post a picture of $F(x)$? Commented Apr 3, 2018 at 12:27
• Do you want to integrate $F$ over the interval $[1,8]$? Commented Apr 4, 2018 at 9:55

What about dividing the interval $[0,0.6]$ in sub-intervals $[x_i,x_{i-1}]$ so that in each one the function value has the same order of magnitude? For example you could choose $x_0 =0$, $x_{m}=0.6$ $$x_i \;|\; 0<i<m \; \wedge \;F(x_i) = 10^i$$ Then you can integrate in each one and sum the partial results to get the total integral.

I have never done this, but it is what I would try first. The contributions at the extreme right of each interval will probably be underestimated, but at least this effect is reduced.

Be also sure to properly consider errors (they depend on your specific method): if the bump gives a contribution which is smaller than the uncertainty, either you have to reduce the error (which I suppose is your case, since you are interested in the bump) or you can ignore the bump.

If you try this, let me know if it works!

## Detailed implementation

(pseudo-code)

hit = 0
miss = 0
x = generate_random(x_interval)
y = generate_random([0,max_of_function])
if(F(x)>y) hit++
else if(F(x)<y) miss++
percentage_hits = hit/(hit+miss)
total_area = (x_interval*max_of_function)
function_area = percentage_hits * total_area


Now you have the area in the x_interval selected. Compute the same for each interval, then sum all the partial areas.

• Thanks for the answer. Actually, it works. Assume we take $x$ as a property of an event. So by Monte-Carlo we mean generating random events which have the property $x$, according to a distribution function $F(x)$. Let's say I have generated a million event out of the method you just mentioned. Assuming I have 20 intervals. In each interval I have around 50000 events. Then if I histogram the events, I can't see anything useful since there are equal number of events in each interval. Commented Apr 5, 2018 at 20:24
• Sorry, I think I don't understand your question: the basic idea with MC integration is to generate an uniform distribution of points, then see how much percentage of them is "under" the function and relate this to the fraction of the total area in which they are generated. I think you are using a more enveloped method, so if you will explain it or link some resource, then I hopefully can better understand. I'll try now to add some details to my answer. Commented Apr 5, 2018 at 21:01
• In fact, it is related to physics and how events are generated theoretically and compared to experimental results to evaluate the theory. The problem is that whatever I find on-line has complicated mathematics and there is nothing that clearly explains the procedure. Commented Apr 6, 2018 at 3:37
• But you are integrating the function, right? If this is your need, the pseudo-code I wrote should fit. Otherwise can you link some reference, even if it is compolicated, so that is clear what you need? Commented Apr 6, 2018 at 8:01
• At some point I have to integrate it which is simple. I just use the built-in functions of python to do it. Sure, I will send post some references as soon as possible. Thanks Commented Apr 6, 2018 at 18:04