- First working version of the triple axis UB matrix code

This commit is contained in:
koennecke
2005-05-13 07:40:57 +00:00
parent d0a535faa3
commit 6145b513f8
16 changed files with 1681 additions and 527 deletions

View File

@ -17,6 +17,64 @@
#define UBNOMEMORY -702
#define TRIANGLENOTCLOSED -703
#define BADRMATRIX -704
/*========================== defines for tasMode ====================*/
#define KICONST 1
#define KFCONST 2
/*=========================== TAS Variables =========================*/
#define EI 1
#define KI 2
#define QH 3
#define QK 4
#define QL 5
#define EF 6
#define KF 7
#define EN 8
#define QM 9
/*=========================== data structures =======================*/
/**
* data structure describing a monochromator or analyzer crystal
*/
typedef struct {
double dd; /* lattice spacing */
int ss; /* scattering sense */
double HB1, HB2; /* horizontal curvature parameters */
double VB1, VB2; /* vertical curvature parameters */
} maCrystal, *pmaCrystal;
/**
* the machine parameters of a triple axis spectrometer
*/
typedef struct {
maCrystal monochromator, analyzer;
MATRIX UB;
MATRIX planeNormal;
int ss_sample; /* scattering sense sample */
}tasMachine, *ptasMachine;
/**
* a position in Q - Energy space
*/
typedef struct {
double ki, kf;
double qh,qk,ql;
double qm;
}tasQEPosition, *ptasQEPosition;
/**
* A triple axis angle position
*/
typedef struct {
double monochromator_two_theta;
double a3;
double sample_two_theta;
double sgl;
double sgu;
double analyzer_two_theta;
}tasAngles, *ptasAngles;
/**
* a full triple axis reflection
*/
typedef struct {
tasQEPosition qe;
tasAngles angles;
}tasReflection, *ptasReflection;
/*================= Monochromator/Analyzer stuff =====================*/
/**
* convert an energy in meV to Ki, Kf type values
@ -32,46 +90,35 @@ double energyToK(double energy);
double KtoEnergy(double k);
/*----------------------------------------------------------------------*/
/**
* data structure describing a monochromator or analyzer crystal
* calculate two_theta for k
* @param data The crystals parameter
* @param k The input K value to calculate
* @param two_theta The resulting two_theta
* @return 1 on success, a negative error code on failure
*/
typedef struct {
double dd; /* lattice spacing */
int ss; /* scattering sense */
double HB1, HB2; /* horizontal curvature parameters */
double VB1, VB2; /* vertical curvature parameters */
} maCrystal, *pmaCrystal;
int maCalcTwoTheta(maCrystal data, double k, double *two_theta);
/**
* data structure for the angles of a mono/ana calculation
* calculate the value for the vertical curvature
* @param data The input crystal parameters
* @param two_theta The tow theta value for which to calculate the curvature.
* @return A new value for the curvature.
*/
typedef struct{
double theta;
double two_theta;
double horizontal_curvature;
double vertical_curvature;
}maAngles, *pmaAngles;
/*-----------------------------------------------------------------------*/
double maCalcVerticalCurvature(maCrystal data, double two_theta);
/**
* calculate the angles for the wavelength or K value k
* calculate the value for the horizontal curvature
* @param data The input crystal parameters
* @param two_theta The tow theta value for which to calculate the curvature.
* @return A new value for the curvature.
*/
double maCalcHorizontalCurvature(maCrystal data, double two_theta);
/**
* calculate the value of the K vector from the angle
* @param data The crystals constants
* @param angles output angles
* @param k The wavelength or k value to calculate
* @return 1 on success, a negative error code on failure.
* @param two_theta The two theta read from the motor
* @return The k value calculated from two_theta and the parameters.
*/
int maCalcAngles(maCrystal data, pmaAngles angles, double k);
/**
* calculate the value of the K vector from angles
* @param data The crystals constants
* @param angles The current angles
* @param k The output K vector
* @return 1 on success, a negative error code on failure.
*/
int maCalcK(maCrystal data, maAngles angles, double *k);
double maCalcK(maCrystal data, double two_theta);
/*======================= reciprocal space =============================*/
typedef struct {
double h,k,l;
double a3, two_theta, sgu, sgl;
double ki, kf;
}tasReflection, *ptasReflection;
/**
* calculate a UB from two reflections and the cell.
* @param cell The lattice constant of the crystal
@ -97,41 +144,22 @@ MATRIX calcPlaneNormal(tasReflection r1, tasReflection r2);
* @param UB The UB matrix to use
* @param planeNormal The normal to the scattering plane to use
* @param ss The scattering sense at the sample
* @param r The input/output reflection
* @param qe The desired Q Energy position
* @param angles The resulting angles.
* @return 1 on success, a negative error code when errors are encountered
*/
int calcTasQAngles(MATRIX UB, MATRIX planeNormal,
int ss, ptasReflection r);
int ss, tasQEPosition qe,
ptasAngles angles);
/**
* calculate QH, QK, QL from the angles given
* @param UB The UB matrix to use
* @param r The reflection to proecess. The angles and ki, kf have to be set
* to appropriate values before this can work properly.
* @param angles The angles as read from the motors
* @param qe The resulting Q Energy positions
* @return 1 on success, a negative error code on failures.
*/
int calcTasQH(MATRIX UB, ptasReflection r);
int calcTasQH(MATRIX UB, tasAngles angles, ptasQEPosition qe);
/*======================== pulling it together.. =======================*/
typedef struct {
maCrystal monochromator, analyzer;
MATRIX UB;
MATRIX planeNormal;
int ss_sample; /* scattering sense sample */
tasReflection r;
}tasMachine, *ptasMachine;
/*---------------------------------------------------------------------*/
typedef struct {
maAngles monochromator;
double a3;
double sample_two_theta;
double sgl;
double sgu;
maAngles analyzer;
}tasAngles, *ptasAngles;
/*-------------------------------------------------------------------*/
typedef struct {
double ki, kf;
double qh,qk,ql;
}tasQEPosition, *ptasQEPosition;
/**
* calculate all the tas target angles for a position in Q-Energy space.
* @param machine The machine description
@ -151,4 +179,45 @@ int calcAllTasAngles(ptasMachine machine, tasQEPosition qe,
*/
int calcTasQEPosition(ptasMachine machine, tasAngles angles,
ptasQEPosition qe);
/*======================== POWDER MODE =================================
Powder mode is driving only QM, A3, SGGU, SGL will not be touched,
only energy and sample two theta will be driven.
========================================================================*/
/**
* calculate the angles for a specified energy and qm position (in qe).
* @param machine The machine constants of the spectrometer
* @param qe The energy, qm position desired.
* @param angles The angles for this qe position. Please ignore a3, sgu, sgl
* @return 1 on success, a negative error code else
*/
int calcTasPowderAngles(ptasMachine machine, tasQEPosition qe,
ptasAngles angles);
/**
* calculate the current energy qm position from angles.
* @param machine The spectrometer parameters.
* @param angles The angles as read from the motors
* @param qe The resulting qe position
* @return 1 on success, a negative error code on errors
*/
int calcTasPowderPosition(ptasMachine machine, tasAngles angles,
ptasQEPosition qe);
/*======================= TAS Logic =====================================*/
/**
* set triple axis parameters, thereby taking the tasMode into account
* @param qe The Q Energy variable set to update
* @param tasMode The triple axis mode to apply
* @param tasVar The TAS variable to handle. This MUST be one of the
* defines at the top of this file.
* @param value The value to set for tasPar
*/
void setTasPar(ptasQEPosition qe, int tasMode, int tasVar, double value);
/**
* calculates the value of a TAS parameter from qe.
* @param qe The Q Energy psoition to extract data from
* @parm tasVar The TAS variable to extract. This MUST be one of the
* defines given at the top of this file.
* @return The value of the TAS variable.
*/
double getTasPar(tasQEPosition qe, int tasVar);
#endif