bpmorbit/get_bpmhit.c

Go to the documentation of this file.
00001 
00005 #include <bpm/bpm_messages.h>
00006 #include <bpm/bpm_orbit.h>
00007 
00008 int get_bpmhit( beamconf_t *beam, bpmconf_t *bpm ) {
00009 
00010   if ( ! beam ) {
00011     bpm_error( "Invalid pointer arguments in get_bpmhit(...)",
00012                __FILE__, __LINE__ ); 
00013     return BPM_FAILURE;
00014   }
00015 
00016   if ( ! bpm ) {
00017     bpm_error( "Invalid pointer arguments in get_bpmhit(...)",
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   v_copy(&np,&xp);
00055   v_cross(&np,&yp);
00056   
00057   /* find intersection of beam with BPM */
00058   pl.x = beam->beampos[0];
00059   pl.y = beam->beampos[1];
00060   pl.z = bpm->geom_pos[2];
00061   
00062   nl.x = sin(beam->beamslope[0]) * cos(beam->beamslope[1]);
00063   nl.y = sin(beam->beamslope[0]) * sin(beam->beamslope[1]);
00064   nl.z = cos(beam->beamslope[0]);
00065   
00066   /* intersection solution */    
00067   v_copy(&vtemp,&pp);
00068   v_sub(&vtemp,&pl);
00069   lambda = v_dot(&vtemp,&np)/v_dot(&np,&nl);
00070   
00071   v_copy(&v,&nl);
00072   v_scale(&v,lambda);
00073   v_add(&v,&pl);
00074   
00075   /* beam position in coordinate system of bpm */
00076   v_copy(&lv,&v);
00077   v_sub(&lv,&pp);
00078   
00079 
00080   
00081   beam->bpmhit[0]   = v_dot(&lv,&xp);
00082   beam->bpmhit[1]   = v_dot(&lv,&yp);
00083   beam->bpmhit[2]   = v.z; // in global coo !!!!
00084   
00085   beam->bpmslope[0] = beam->beamslope[0] - bpm->geom_tilt[0];
00086   beam->bpmslope[1] = beam->beamslope[1] - bpm->geom_tilt[1];
00087   
00088   beam->bpmtilt[0]  = 0.; // bunch tilt beam->bunchtilt[0], beam->bunchtilt[1]...
00089   beam->bpmtilt[1]  = 0.; // bunch tilt...
00090 
00091 
00092   return BPM_SUCCESS;
00093 }

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