How can I use ray collide with terrain?

I put the terrain collider on subscene, it has a built-in terrain collider, I think it will be transfered to unity psysics's terrain. How do I use ray to detect terrain height? It seems that this version of raycastinput can't specify layers.

Unfortunately, the built-in UnityEngine.TerrainCollider authoring component is not yet supported in Unity Physics baking when placed in a subscene.
If you want to use the Unity.Physics.TerrainCollider collider type in your scene, which is based on a height field representation, you need to create it manually at the moment.
Please refer to the Unity.Physics.TerrainCollider scripting API documentation, and specifically the Create function variants.

Once you have created a BlobAssetReference<Collider> using TerrainCollider.Create(), you can add it to a PhysicsCollider component that you add to an entity with the usual transformation components, e.g., LocalTransform. The latter will allow you to place the created terrain patch in your scene.

You can find example code for programmatic creation of rigid bodies here.
For a description of what distinguishes a dynamic rigid body from a static rigid body (which is likely what you would like to use to hold your terrain collider patch; or multiple patches via a compound collider), have a look at the section on data concepts in the Unity Physics package.