Wordpress pre_get_posts

Sorry for the off topic question, but I'm having real trouble understanding pre_get_posts().
I have a page that I'm creating a custom loop for a custom post type. And I want to modify the main query to change the ordering.
So I add the function I want:

function order_by_menu_order($query){

if ( !is_admin() && $query->is_main_query() ) {
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'DESC' );

This is at the top of the page, before the:
if ( have_posts() ) :

I've created a custom archive page that is being called for my post type. And I'm putting the code in there.

The file is called archive-department.php because I'm creating departments.