The investigation of a problem connected to probabilistic risk assessments for industrial plants led us to the need to optimize integrals calculated over sets that depend upon parameters. The problem was developed for two applications of tested and inspected components as an optimal control problem involving nonsmooth state transitions. In solving the optimization problem it is necessary to calculate the derivatives of an integral over a domain depending upon the parameters to be optimized. Up to date the theory of the differentiation these integrals is not fully developed. In the working paper a new general formula for differentiation of such integrals is proposed. These results were used for calculation of sensitivities for risk functions. This approach can have a wide application for the stochastic programming problems.