How to determine if the current file is loaded in a plugin or in a theme?

EDIT

Talking to @s_ha_dum, there are issues between operating system with the paths, Windows uses backslashes, so we need to compensate for them

Because OP needs a boolean returned, we need a function to return either true or false, so we can either write two separate functions to cover both bases or just choose one and go with it. This method has its drawbacks though as it does not cover for files loaded outside the plugins and theme folders

Lets look at a conditional that would return true if a file is loaded from a theme

function is_file_in_theme( $file_path = __FILE__ )
{
    // Get the them root folder
    $root = get_theme_root();   
    // Change all '\' to "https://wordpress.stackexchange.com/" to compensate for localhosts
    $root = str_replace( '\\', "https://wordpress.stackexchange.com/", $root ); // This will output E:\xampp\htdocs\wordpress\wp-content\themes

    // Make sure we do that to $file_path as well
    $file_path = str_replace( '\\', "https://wordpress.stackexchange.com/", $file_path ); 

    // We can now look for $root in $file_path and either return true or false
    $bool = stripos( $file_path, $root );
    if ( false === $bool )
        return false;

    return true;
}

We can alternatively do the same for plugins

function is_file_in_plugin( $file_path = __FILE__ )
{
    // Get the plugin root folder
    $root = WP_PLUGIN_DIR; 
    // Change all '\' to "https://wordpress.stackexchange.com/" to compensate for localhosts
    $root = str_replace( '\\', "https://wordpress.stackexchange.com/", $root ); 

    // Make sure we do that to $file_path as well
    $file_path = str_replace( '\\', "https://wordpress.stackexchange.com/", $file_path ); 

    // We can now look for $root in $file_path and either return true or false
    $bool = stripos( $file_path, $root );
    if ( false === $bool )
        return false;

    return true;
}