What if in the time between initialization of cosmic_ray to False, and the time this if statement executes, a legitimate cosmic ray flips the bool bit representing cosmic_ray?
This is a really good point and a common error in bit flip detection code. To avoid this kind of look-before-you-leap hazard the following is recommended: