Personally, I don't like any of the methods discussed in the links provided. I find that the quickest, most controllable, and most straightforward way to generate luminosity masks is by using a curves adjustment layer on a B&W version of the image to select a particular tonal range (and turn it white, leaving all other parts of the image very dark, if not black).
To illustrate how well one can pick out various tonal ranges, as my test image, I used a simple, linear gradient that goes smoothly all the way from (0,0,0) to (255,255,255).
00
For example, if you use this curve:
01
You can generate a mask which selects a narrow range of shadow tones (as shown immediately below)
01
If you use this curve:
02
You can generate a mask which selects a narrow range of mid tones (as shown immediately below)
02
If you use this curve:
03
You can generate a mask which selects a slightly brighter, equally narrow range of mid tones (as shown immediately below)
03
And as a final example, if you use this curve:
04
You can generate a mask which selects light and dark tones but no mid-tones (as shown immediately below)
04
I have been using this method since the 1990's.
HTH,
Tom M