how to take derivative of an integral of a piece-wise function????
You cannot - unless you restrict the domain.