Law of unconsious statistician: application in characteristic function Let $g(x)=(x-a)\mathbf 1_{x\ge a}$ for some $a>0$ and let $X$ be a non-negative random variable with cdf $F$ and $E[X]<+\infty$. I want to calculate $$\frac{d}{da}E[g(X)]$$ To do that I thought as a first step to use this formula here:

...Using representations as Riemann–Stieltjes integral and integration by parts the formula can be restated as
  $$\operatorname {E}[g(X)]=\int _{-\infty }^{\infty }g(x)\,\mathrm{d}P(X\le x)=g(a)+\int _{a}^{\infty }g'(x)P(X>x)\,\mathrm {d} x$$
  if $P\left(g(X)\geq g(a)\right)=1$.

So I calculated $$g'(x)=\begin{cases}0, & 0\le x< a \\ \text{undefined}, & x=a \\ 1, & a<x \end{cases}$$ and since $P(g(X)>g(a))=P(g(X)>0)=1$, I wrote: $$E[g(X)]=g(a)+\int_{a}^{+\infty}(1-F(x))\,\mathrm{d}x=\int_{a}^{+\infty}(1-F(x))\,\mathrm{d}x \tag{1}$$
My first question: Is this correct, or is $g'(x)|_{x=a}$ undefined a problem?
So, taking the derivative of $(1)$ gives me that $$\frac{d}{da}\int_{a}^{+\infty}1-F(x)\, \mathrm dx=F(a)-1 \tag{2}$$
My second question: Is this derivative correct? 
Thanks in advance!
 A: Formula (1) is correct for any random variable (r.v.) $X$ and any real $a$, even without assuming that $X$ is nonnegative and/or continuous. Indeed, by the Fubini--Tonelli theorem, 
$$\int_a^\infty (1-F(x))\,dx 
=\int_a^\infty P(X>x)\,dx =\int_a^\infty dx \int_{(x,\infty)}P(X\in du)
$$ 
$$=\int_{\mathbb R}dx\,I\{x\ge a\}\int_{\mathbb R}I\{u>x\} P(X\in du) $$ 
$$=\int_{\mathbb R}P(X\in du)\int_{\mathbb R}dx\,I\{u>x\ge a\} $$
$$=\int_{\mathbb R}P(X\in du)(u-a)_+ = E(X-a)_+; 
$$
here $I\{\cdot\}$ denotes the indicator function.  
Assume now that $E X_+<\infty$ (your conditions $X\ge0$ and $EX<\infty$ are more than enough for that). Then $E(X-a)_+<\infty$ for all real $a$. Moreover, by (1), the right and left derivatives of $E(X-t)_+$ in $t$ at $t=a$ equal $-\lim_{x\downarrow a}P(X>x)=-P(X>a)=F(a)-1$ and $-\lim_{x\uparrow a}P(X>x)=-P(X\ge a)=F(a-)-1$, respectively. If $P(X=a)=0$ then the derivative of $E(X-t)_+$ in $t$ at $t=a$ exists and equals $-P(X>a)=F(a)-1$. 
Addendum: A more direct way to compute these one-sided derivatives (again for any r.v. $X$ with $E X_+<\infty$) is as follows. 
Let  $f_{a,h}(x):=\frac1h\,[(x-a)_+-(x-a-h)_+]$. Then $0\le f_{a,h}(x)\le1$ for real $x$ and real $h>0$, and $\lim_{h\downarrow0}f_{a,h}(x)=I\{x>a\}$. 
So, the right derivative of $E(X-t)_+$ in $t$ at $t=a$ equals 
$$-\lim_{h\downarrow0}\frac{E(X-a)_+-E(X-a-h)_+}h
=-\lim_{h\downarrow0}Ef_{a,h}(X)=-EI\{X>a\}=-P(X>a),$$ 
by the dominated convergence theorem. 
Quite similarly, for the left derivative.
