Do ray sensors detect collision bounds? in my game I have a painting behind glass and the glass is in the front side of the "painting case". Like this: 


All 3 objects (Mona Lisa, painting case and the glass) have the block property.

I am trying to detect only the painting case with a ray sensor without the x-ray mode. As I was testing it, I activated all the collision bounds of the objects as a box and the result is that the painting case's box covers the painting(Mona Lisa)'s and the glass's surfaces so I always got the painting case with my ray. 

My question is : Does the ray detect surfaces or the collision bounds of the objects or an area near the surfaces, or what if none of the above? And if the correct answer is the collision bounds, should I have them "ticked" for this to work? If they are not ticked what does the ray detect(cause it returns the object, but the paint itselft )?
And as a side-question : How does the margin attribute affect the collision bounds exactly? Is it visible somehow in the viewport?
Background

"Rays" are a method to detect if an imaginary line crosses one or more faces. That leads to the question: What faces?

In the BGE there are two kinds of faces:


visible faces (display mesh) and 
collision faces (physics mesh). 


These face types can but do not need to match. (Often it is better when there are less collision meshes than display meshes for faster processing).

Rays are part of the physics aspect. Therefore faces the physics would collide with are considered for hit detection.

Conclusion

I guess after this (hopefully understandable) explanation, you come to the conclusion that the ray will hit the shape defined by the objects Physics/Collision Bounds/Bounds


If it is set to Box, the physics mesh is a box where the display mesh fits in. 
If it is set to convex hull, the physics mesh will span a convex triangle mesh around the display mesh (faster than triangle mesh processing)
if it is set to triangle mesh, the physics mesh will match the display mesh (creates the most processing overhead)


Be aware: quads are broken into two triangles. The triangles might not match the triangles of the display mesh as there are two ways to break a quad.

You can see the current physics mesh by enabling Main menu/Game/Show Physics Visualization (the green mesh when resting otherwise white lines). 
Attention: The visualization on a convex hull is not necessarily correct. I guess it is simpler to detect collisions than drawing a convex hull.

Answer

The ray detects the collision bounds your explicitly set up.