"At the end of your game, you can hover over your Champion Mastery points bar to see the grade our new system gives you. These grades are awarded based on your overall performance in the role, the champion you're playing and, crucially, where you're playing them. For example, we look at an Annie going mid differently from an Annie going support. We take a series of performance metrics and compare how you did to all other players in your region in that specific champion/position combination.
This is percentile-driven; earning a high score means you performed in the top x% of players in that champion/position combination."
Quote taken from:
https://support.riotgames.com/hc/en-us/articles/204211284-Champion-Mastery-Guide
Looks like it depends on your performance with a champion depending on what role you take as compared to other players playing that champion and role in your region. The actual calculation and metrics used are of course a secret so nobody can tell you what it is exactly you can do to get a high rank. But considering that they have to use different metrics to deal with the different roles (at least thats my guess*) it can't just be as simple as getting a good KDA or high CS, and because your performance is compared to other people in your region only the very top % of performances will get a S+ ranking.
*It is possible that the same metric is used to determine the performance of all champions and all roles, but I still doubt it would include things like KDA and CS.