bpmorbit/generate_bpm_orbit.c

Go to the documentation of this file.
00001 
00005 #include <bpm/bpm_messages.h>
00006 #include <bpm/bpm_orbit.h>
00007 
00008 int generate_bpm_orbit( beamconf_t *beam, bpmconf_t *bpm ) {
00009 
00010   if ( ! beam ) {
00011     bpm_error( "Invalid pointer arguments in generate_bpm_orbit(...)",
00012                __FILE__, __LINE__ ); 
00013     return BPM_FAILURE;
00014   }
00015 
00016   if ( ! bpm ) {
00017     bpm_error( "Invalid pointer arguments in generate_bpm_orbit(...)",
00018                __FILE__, __LINE__ ); 
00019     return BPM_FAILURE;
00020   }
00021 
00022   // PLEASE NOTE: THIS IS A STUB OF FUNCTION TO ALLOW TESTING
00023   // STEWART IS GOING TO ADD THE PROPER VERSION SOON
00024 
00025   int i = 0;
00026   
00027   struct v3 nl;     /* direction of the line */
00028   struct v3 pl;     /* point on the line */
00029   struct v3 np;     /* normal of the plane */
00030   struct v3 pp;     /* point in the plane */
00031   struct v3 xp;     /* coordinate system x unit vector */
00032   struct v3 yp;     /* coordinate system y unit vector */
00033   struct v3 zp;     /* coordinate system z unit vector */
00034   struct m33 rotp;  /* rotation matrix in yaw,roll,pitch of BPM */
00035   double lambda;    /* parametric line / plane intersection solution */
00036   struct v3 vtemp;  /* temporary vector */
00037   struct v3 v;      /* solution */
00038   struct v3 lv;     /* local BPM coordinates solution */
00039 
00040 
00041     /* form BPM detector plane */
00042     pp.x = bpm->geom_pos[0]; 
00043     pp.y = bpm->geom_pos[1]; 
00044     pp.z = bpm->geom_pos[2]; 
00045     xp.x = 1.0; xp.y = 0;   xp.z = 0;
00046     yp.x = 0;   yp.y = 1.0; yp.z = 0;
00047     zp.x = 0;   zp.y = 0;   zp.z = 1.0;
00048 
00049     m_rotmat(&rotp, bpm->geom_tilt[0], bpm->geom_tilt[1], bpm->geom_tilt[2]);
00050     v_matmult(&rotp,&xp);
00051     v_matmult(&rotp,&yp);
00052     v_matmult(&rotp,&zp);
00053     
00054     /* m_print(&rotp); */
00055     
00056     v_copy(&np,&xp);
00057     v_cross(&np,&yp);
00058     
00059     /*    v_print(&np);
00060           v_print(&zp); */
00061            
00062     /* find intersection of beam with BPM */
00063     pl.x = beam->beampos[0];
00064     pl.y = beam->beampos[1];
00065     pl.z = bpm->geom_pos[2];
00066 
00067     beam->beamslope[0] = 3.1415926/4;
00068     beam->beamslope[1] = 3.1415926/2;
00069 
00070     nl.x = sin(beam->beamslope[0]) * cos(beam->beamslope[1]);
00071     nl.y = sin(beam->beamslope[0]) * sin(beam->beamslope[1]);
00072     nl.z = cos(beam->beamslope[0]);
00073     
00074     /* intersection solution */    
00075     v_copy(&vtemp,&pp);
00076     v_sub(&vtemp,&pl);
00077     lambda = v_dot(&vtemp,&np)/v_dot(&np,&nl);
00078     /*    printf("generate_beam_orbit> lambda : %f \n",lambda); */
00079     v_copy(&v,&nl);
00080     v_scale(&v,lambda);
00081     v_add(&v,&pl);
00082     
00083     /*v_print(&v);*/
00084 
00085     /* beam position in coordinate system of bpm */
00086     v_copy(&lv,&v);
00087     v_sub(&lv,&pp);
00088     
00089     beam->bpmhit[0] = v_dot(&lv,&xp);
00090     beam->bpmhit[1] = v_dot(&lv,&yp);
00091     beam->bpmhit[2] = v.z;
00092     
00093     lv.x = beam->bpmhit[0];
00094     lv.y = beam->bpmhit[1];
00095     lv.z = beam->bpmhit[2];
00096         
00097     /*v_print(&lv);    */
00098     
00099     /*
00100     // Old and crude version - uncomment for checking 
00101     beam->bpmhit[0] = beam->beampos[0] - bpm->geom_pos[0];
00102     beam->bpmhit[1] = beam->beampos[1] - bpm->geom_pos[1];
00103     beam->bpmhit[2] = 0;
00104     */
00105     
00106     
00107     beam->bpmslope[0] = beam->beamslope[0] - bpm->geom_tilt[0];
00108     beam->bpmslope[1] = beam->beamslope[1] - bpm->geom_tilt[1];
00109     
00110     return BPM_SUCCESS;
00111 }

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1