Have you tried carrying out the work for each case? We need to see what you've done and where you are stuck.
Take the first case, with [MATH]r_2\le a[/MATH]. Then throughout the interval [a,b], [MATH]r_2 - \theta \le 0[/MATH], so [MATH]|r_2 - \theta| = \theta - r_2[/MATH]. Put that into the integral and see what you get.
The second case will be a little more complicated (you'll need that piecewise function you expected).