Raycast and alighning to the terrain

I’m trying to align Node objects to the terrain (I’m using them in a hex grid). currently they adjust height with a raycast, but because I did not write this code myself I’m having trouble understanding and adding orientation to the nodes.

public void SetupNodeHeights(LayerMask checkAgainstLayer, bool unlinkIsActive)
	{
		if (nodesCache == null) return;
		if (nodesCache.Length == 0) return;

		foreach (GameObject go in nodesCache)
		{
			if (go == null) continue;
			Transform tr = go.transform;
			LayerMask rayMask = (1 << checkAgainstLayer);
			Vector3 pos = tr.position; pos.y = 100f;
			RaycastHit hit;
			if (Physics.Raycast(pos, -Vector3.up, out hit, 200f, rayMask))
			{
				pos.y = hit.point.y;
				tr.position = pos;
			}
			else if (unlinkIsActive)
			{
				// node is not over something usefull (like terrain), delete it
				TileNode node = go.GetComponent<TileNode>();
				node.Unlink();
#if UNITY_EDITOR
				DestroyImmediate(go);
#else
				Destroy(go);
#endif
			}
		}
	}

Depends on what u mean by aligining…
Heres how you can set each node to have the same rotation as the underlying normal

if (Physics.Raycast(pos, -Vector3.up, out hit, 200f, rayMask))
{
pos.y = hit.point.y;
tr.position = pos;
//i dont know how well this works, but the idea is to make use of the normal.
tr.up = hit.normal;
}