This is just cherry picking @rjoshi's MR that cleaned up the b-tagging code a bit.
Unfortunately OldFlags2NewFlags has already diverged quite a lot between the releases so this created a conflict.
OldFlags2NewFlags