00001
00005 #include <bpm/bpm_messages.h>
00006 #include <bpm/bpm_orbit.h>
00007 #include <bpm/bpm_interface.h>
00008
00009 int get_bpmhits( beamconf_t *beam, bpmconf_t *bpm ) {
00010
00011 int i = 0;
00012
00013 if ( ! beam ) {
00014 bpm_error( "Invalid pointer arguments in get_bpmhits(...)",
00015 __FILE__, __LINE__ );
00016 return BPM_FAILURE;
00017 }
00018
00019 if ( ! bpm ) {
00020 bpm_error( "Invalid pointer arguments in get_bpmhits(...)",
00021 __FILE__, __LINE__ );
00022 return BPM_FAILURE;
00023 }
00024
00025 for ( i = 0; i < beam->nbunches; i++ ) {
00026 if ( get_bpmhit( &(beam->bunch[i]), bpm ) == BPM_FAILURE ) return BPM_FAILURE;
00027 }
00028
00029 return BPM_SUCCESS;
00030 }
00031
00032
00033
00034 int get_bpmhit( bunchconf_t *bunch, bpmconf_t *bpm ) {
00035
00036 int i = 0;
00037
00038 struct v3 nl;
00039 struct v3 pl;
00040 struct v3 np;
00041 struct v3 pp;
00042 struct v3 xp;
00043 struct v3 yp;
00044 struct v3 zp;
00045 struct m33 rotp;
00046 double lambda;
00047 struct v3 vtemp;
00048 struct v3 v;
00049 struct v3 lv;
00050
00051 if ( ! bunch ) {
00052 bpm_error( "Invalid pointer arguments in get_bpmhit(...)",
00053 __FILE__, __LINE__ );
00054 return BPM_FAILURE;
00055 }
00056
00057 if ( ! bpm ) {
00058 bpm_error( "Invalid pointer arguments in get_bpmhit(...)",
00059 __FILE__, __LINE__ );
00060 return BPM_FAILURE;
00061 }
00062
00063
00064 pp.x = bpm->geom_pos[0];
00065 pp.y = bpm->geom_pos[1];
00066 pp.z = bpm->geom_pos[2];
00067 xp.x = 1.0; xp.y = 0; xp.z = 0;
00068 yp.x = 0; yp.y = 1.0; yp.z = 0;
00069 zp.x = 0; zp.y = 0; zp.z = 1.0;
00070
00071 m_rotmat(&rotp, bpm->geom_tilt[0], bpm->geom_tilt[1], bpm->geom_tilt[2]);
00072 v_matmult(&rotp,&xp);
00073 v_matmult(&rotp,&yp);
00074 v_matmult(&rotp,&zp);
00075
00076 v_copy(&np,&xp);
00077 v_cross(&np,&yp);
00078
00079
00080 pl.x = bunch->position[0];
00081 pl.y = bunch->position[1];
00082 pl.z = bpm->geom_pos[2];
00083
00084 nl.x = sin(bunch->slope[0]) * cos(bunch->slope[1]);
00085 nl.y = sin(bunch->slope[0]) * sin(bunch->slope[1]);
00086 nl.z = cos(bunch->slope[0]);
00087
00088
00089 v_copy(&vtemp,&pp);
00090 v_sub(&vtemp,&pl);
00091 lambda = v_dot(&vtemp,&np)/v_dot(&np,&nl);
00092
00093 v_copy(&v,&nl);
00094 v_scale(&v,lambda);
00095 v_add(&v,&pl);
00096
00097
00098 v_copy(&lv,&v);
00099 v_sub(&lv,&pp);
00100
00101 bunch->bpmposition[0] = v_dot(&lv,&xp);
00102 bunch->bpmposition[1] = v_dot(&lv,&yp);
00103 bunch->bpmposition[2] = v.z;
00104
00105 bunch->bpmslope[0] = bunch->slope[0] - bpm->geom_tilt[0];
00106 bunch->bpmslope[1] = bunch->slope[1] - bpm->geom_tilt[1];
00107
00108 bunch->bpmtilt[0] = 0.;
00109 bunch->bpmtilt[1] = 0.;
00110
00111
00112 return BPM_SUCCESS;
00113 }