A more microscopic view of the cross section is

\displaystyle  \frac{dN}{dS} \sigma \rho dt dA= dn,

where N is the number of incident particle, S is the area of the beam, \sigma is the total cross section, \rho is the particle density in the target, A is the area of the target, t is the thickness of the target, and n is the particle detected.

The cross section is a constant, so, after integration on the target area and thickness,

\displaystyle \sigma = \frac{n}{N \rho t} .

If the beam is not uniform, dN/dS = f(S) is a function of S. The integration has to be careful.