Consider the following example (I had a lot of trouble to find a minimal working example, I think it is compactified enough now).
Omega0 = 1.
t=2
nAvg = 10.
Omegan[n_] := Omega0*Sqrt[n + 1]
f[n_] := Piecewise[{{Cos[Omegan[n]*t/2]^2*
Abs[Exp[-nAvg/2]*Sqrt[nAvg]^n/Sqrt[Factorial[n]]],
0 <= n <= 20}}, 0]
NSum[f[n], {n, 1, 100}]
If you run this short script, it should return you :
NSum::nsnum: Summand (or its derivative) [...] big message [...] is not numerical at point n = 16
This problem I am facing occurs only with some specific function. It occurs with this complicated looking function I gave you but if you try simpler one the script may just work correctly.
My questions :
First: I would like to understand why I have this error.
Second: How to solve it ?
Extra question
Is it really more efficient to use NSum[] than N[Sum[]]. Because I have read (I don't remember where) that when Mathematica sees N[Sum[]] he understands that the sum has to be done numerically (instead of trying symbolic method THEN approximating numerically).
Extra infos :
I have already seen Is this a bug of NSum?
With some functions it solves the problem to add NSumTerms->number, with some other it doesn't. The thing is I would like to be able to face this problem "in general" so for this I need to understand what is happening (I read the documentation and I don't).
In short : how to do numeric summation in general with mathematica ? In my specific case I have functions that may be piecewise defined. In all generality my function can be a product/sum of piecewise functions so it is not obvious at first view to know the boundary of the sum without looking more carefully, which I would like to avoid.