# Why is my integral zero?

**URL:** <https://root-forum.cern.ch/t/why-is-my-integral-zero/21999>\
**Category:** ROOT\
**Created:** [October 6, 2016, 1:05pm UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999 "2016-10-06T13:05:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![libalk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/7993a0/32.png) [@libalk](https://root-forum.cern.ch/u/libalk)\
**Post date:** [October 6, 2016, 1:05pm UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/1 "2016-10-06T13:05:32Z")

</div>

I am using root 5.34/36.  
I have defined a 2D function that I want to integrate, as in the attachment. This function is a sort of convolution, and I am using TF2. When I perform the integral with the given parameters it returns 0, but I can draw the function and see that it is zero or positive in the area of integration.  
I run the macro compiled in root with:  
root [0] .L fit.C+  
root [1] fit();

I want to use this function in a minimization (changing the parameters), with the integral in the denominator. I am open to suggestions about how to calculate this integral faster.

thanks!  
[fit.C](https://root-forum.cern.ch/uploads/default/original/2X/8/8d70e7b3c6f3a574195fc537b74d879a30d2491d.C) (3.08 KB)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [October 6, 2016, 1:19pm UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/2 "2016-10-06T13:19:25Z")

</div>

[EDIT] Sorry, I was mistaken, my comment only applied for a TH2, not for TF2. [How to integrate TH2 correctly?](https://root-forum.cern.ch/t/how-to-integrate-th2-correctly/9582/1)

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [October 6, 2016, 2:01pm UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/3 "2016-10-06T14:01:40Z")

</div>

I don’t think your calls to “Integral” are wrong.

I guess it’s a deficiency in ROOT.

It’s the “efficiency” / “efficiencyF” function which fools ROOT. It’s value “jumps” between 0 and 1 and the current “integrator” is known to misbehave in such cases.  
See also, for example: [Simple Integral - #2 by Pepe\_Le\_Pew](https://root-forum.cern.ch/t/simple-integral/21760/2)

Sometimes you can try to “hide” this problem if you increase the number of points … for each of your functions try to add:  
`SomeTF2->SetNpx(1000); SomeTF2->SetNpy(1000);`  
But I wouldn’t really trust the result.

---

<div class="post-metadata">

**Author:** ![libalk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/7993a0/32.png) [@libalk](https://root-forum.cern.ch/u/libalk)\
**Post date:** [October 6, 2016, 2:19pm UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/4 "2016-10-06T14:19:29Z")

</div>

> [@Pepe Le Pew](#):
>
> It’s the “efficiencyF” which fools ROOT. It’s value “jumps” between 0 and 1 and the current “integrator” is known to misbehave in such cases.

could it help to use another integrator?  
the “efficiencyF” is a try to implement limits for the integration which are not “square”, that is, the integral should not really by from -1 to 1 in both variables but inside the area returning 1 in “efficiencyF”. Is there a better way to implement integration limits which does not have this problem?

I will try the number of points suggestion as well!

---

<div class="post-metadata">

**Author:** ![libalk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/7993a0/32.png) [@libalk](https://root-forum.cern.ch/u/libalk)\
**Post date:** [October 10, 2016, 8:37am UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/5 "2016-10-10T08:37:03Z")

</div>

Using SomeTF2-\>SetNpx and SomeTF2-\>SetNpy solves the problem for these parameters, but the integral takes much longer. And I also find it hard to trust the result. So my other questions remain:

Is there another integrator which should work better? (or/and faster?)  
Is there a better way of implementing non-square integration limits?

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [October 10, 2016, 8:55am UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/6 "2016-10-10T08:55:12Z")

</div>

Maybe check:  
[root.cern.ch/function-integration](https://root.cern.ch/function-integration)  
[root.cern.ch/root/html/ROOT\_\_Ma … tiDim.html](https://root.cern.ch/root/html/ROOT __Math__ IntegratorMultiDim.html)

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [October 11, 2016, 6:55pm UTC](https://root-forum.cern.ch/t/why-is-my-integral-zero/21999/7 "2016-10-11T18:55:08Z")

</div>

If you play with the [ROOT::Math::IntegratorMultiDim](https://root.cern.ch/root/html/ROOT __Math__ IntegratorMultiDim.html), you should probably remember that the default “integrator” (which stumbles upon sharp edges / steps) is the “adaptive multi-dimensional integration method / algorithm” [ROOT::Math::AdaptiveIntegratorMultiDim](https://root.cern.ch/root/html534/ROOT __Math__ AdaptiveIntegratorMultiDim.html) (so, you’d better try something else).
