closest hit program, any hit program and ray type

Often, when we use Optix to conduct raytracing program, we will do as follow.
1.

context->setRayTypeCount( 2 );
material->setClosestHitProgram(0,closet_hit);
material->setAnyHitProgram(1,any_hit);
ray = make_Ray(origin,dir,ray_type,1.e-4f,RT_DEFAULT_MAX);
rtTrace(top_object,ray,ray_load);

Usually, we need 2 types of ray, the radiance ray and shadow ray, so the RayTypeCount is 2. And then, the closest hit program relates to radiance ray, while the any hit program relates to shadow ray, must we observe the regulation? if so, why should we specify ray type when setting ClosestHitProgram and AnyHitProgram? If not, which means, we can do like that:

material->setClosestHitProgram(1,closet_hit);
material->setAnyHitProgram(0,any_hit);

In this case, what does it mean? does it mean that 0 represents shadow ray and 1 represents radiance ray? I am a little confused about the design.
Moreover, if I just want use one type of ray, for example, the shadow ray, then the ray type count should be 1.

context->setRayTypeCount( 1 );
material->setAnyHitProgram(0,any_hit);

3.[code]
ray = make_Ray(origin,dir,0,1.e-4f,RT_DEFAULT_MAX);
rtTrace(top_object,ray,ray_load);
Is it right to do like this?

No, you can have any number of ray types and any number of closest hit and any hit programs. For instance you can do this:

material->setClosestHitProgram(0,closet_hit_number_0);
material->setAnyHitProgram(0,any_hit_number_0);
material->setClosestHitProgram(1,closet_hit_number_1);
material->setAnyHitProgram(1,any_hit_number_1);
material->setClosestHitProgram(2,closet_hit_number_2);
material->setAnyHitProgram(2,any_hit_number_2);
//...
material->setClosestHitProgram(100,closet_hit_number_100);
material->setAnyHitProgram(100,any_hit_number_100);

It depends on what ray 0 and ray 1 are. There is no rule that says that 0 must be a radiance ray or that 1 must be a shadow ray. What your code says is that you have assigned a closest hit program to the ray that you have called type 1, and you have assigned an any hit program to the ray that you have called type 0.

Yes, that will work.

@nljones, Thank you very much.
You are right, it is really helpful.