Computing for Science

The Computing for Science (CS) group supports ILL scientists, students and visitors in a number of activities including data analysis, instrument simulation and sample simulation.

Back to ILL Homepage

Virtual instruments and experiments

DEFINE INSTRUMENT ILL7CurvedGuide(MIn, m, 
InputWidth, ObtWidth, BallisticWidth, StraightWidth,
GuideHeight0, GuideHeight1, GuideHeight2,
SourceInputLength, ReactorStraightLength, BallisticLength1, BallisticLength2, FocLength,
CurvatureRadius1, CurvatureRadius2,
T1, I1, T2, I2, T3, I3,
GapSt, Gap,
Radius)
/* ILL simulation for McStas. E. Farhi <farhi@ill.fr> Feb 2002

setenv MCSTAS /usr/users/farhi/WORK/Sources/McStas/mcstas-1.6.3/lib
/usr/users/farhi/WORK/Sources/McStas/mcstas-1.6.3/mcstas -t ILLGuide.instr
cc -o ILLGuide.out ILLGuide.c -lm
source ILLGuide.csh
*/


DECLARE
%{

#define VERSION "ILL7CurvedGuide 0.8 Farhi 29/08/2002"
#define MON_OUT "x y hdiv vdiv lambda per cm2, auto"

/* all variables defined here can be used, and modified, in the whole instrument */
/* variables used in instrument definition and for user computations */

/* Source specifications */
double sLambda = 4;
double sDeltaLambdaPercent= 0.1; /* Lambda spread in % (half width) */
double sDeltaLambda;
double sT1, sI1, sT2, sI2, sT3, sI3;
double sH = 0.22;
double sW = 0.16;
double sRadius = 0;

/* Guide geometry specifications, default values */
double gSourceInputLength = 2.33; /* distance moderator-guide input */
double gInputWidth = 0.068; /* input of Pink carter */
double gInPileLength = 3.170;
double gObtWidth = 0.060; /* Lead shutter width */
double gReactorStraightLength = 0.02; /* Reactor C level straight guide length */
double gGuideHeight0 = 0.2; /* In Reactor C level straight guide height */
double gGuideHeight1 = 0.2; /* 1st ballistic section guide height */
double gGuideHeight2 = 0.125; /* 1st ballistic section guide height */

double gUnfocLength = 6.0; /* 5 pieces */
double gBallisticWidth = 0.09;
double gBallisticLength1 = 25.5; /* 19 pieces */
double gCurvatureRadius1 = 4000.0;
double gBallisticLength2 = 90.0; /* 18 pieces */
double gCurvatureRadius2 = 2000.0;
double gFocLength = 20; /* 5 pieces */

double gStraightInWidth = 0.06;
double gToInstrLength = 0.25;

double gElementGap = 0.003;

double gUnfocElementLength;
double gUnfocElementRotation;

double gUnfocElementLength;
double gUnfocElementRotation;
double gBallisticElmtLength1;
double gBallisticElmtRot1;

double gFocElementLength;
double gFocElementRotation;
double gBallisticElmtLength2;
double gBallisticElmtRot2;

/* Guide coatings specifications */
double mInPile = 2;
double mFoc = 2;
double mBallistic1 = 2;
double mBallistic2 = 2;
double mUnfoc = 2;
double mStraight = 2;

double mAlpha = 4.07;
double mQc = 0.021;
double mR0 = 1;
double mW = 1.0/300.0;

double gGapSt, gGapFoc, gGap1, gGap2;

/* working variables */

%}
/* end of DECLARE */

INITIALIZE
%{
double PhiC, GammaC, ThetaC, LambdaC, LStar, Zc;
int ORDER = 1;
double Ei, vi;
double Ef, vf, Kf;
int SM,SS,SA;

mInPile = MIn;
mFoc = m;
mBallistic1 = m;
mBallistic2 = m;
mUnfoc = m;
mStraight = m;

gBallisticWidth = BallisticWidth;

/* transfert input parameters */

if (BallisticLength1) gBallisticLength1 = BallisticLength1;
if (BallisticLength2) gBallisticLength2 = BallisticLength2;

if (CurvatureRadius1) gCurvatureRadius1 = CurvatureRadius1;
if (CurvatureRadius2) gCurvatureRadius2 = CurvatureRadius2;

if (StraightWidth) gStraightInWidth = StraightWidth;
if (InputWidth) gInputWidth = InputWidth;
if (GuideHeight0) gGuideHeight0 = GuideHeight0;
if (GuideHeight1) gGuideHeight1 = GuideHeight1;
if (GuideHeight2) gGuideHeight2 = GuideHeight2;
if (ObtWidth) gObtWidth = ObtWidth;
if (SourceInputLength) gSourceInputLength = SourceInputLength;
if (ReactorStraightLength) gReactorStraightLength = ReactorStraightLength;
if (FocLength) gFocLength = FocLength;

if (Radius != 0)
{ sH = 0; sW = 0; sRadius = Radius; }

if (Gap == 0) Gap = gElementGap;

if (GapSt) gGapSt = GapSt; else gGapSt=Gap;
gGap1 = Gap;
gGap2 = Gap;
gGapFoc = Gap;

sT1 = T1;
sI1 = I1;
sT2 = T2;
sI2 = I2;
sT3 = T3;
sI3 = I3;

if (gInputWidth < 0) { gInputWidth=gObtWidth; gSourceInputLength += gInPileLength; gInPileLength=0.01; }

/* total 25 m */
gUnfocElementLength = fabs(gUnfocLength)/5; /* 6 m */
gUnfocElementRotation = (gUnfocElementLength/gCurvatureRadius1*180/PI);
gBallisticElmtLength1 = fabs(gBallisticLength1- gUnfocLength)/19; /* 19.5 m = 25.5 - gUnfocLength */
gBallisticElmtRot1 = gBallisticElmtLength1/gCurvatureRadius1*180/PI;

/* total 90 m */
gFocElementLength = fabs(gFocLength)/5;
gFocElementRotation = (gFocElementLength/gCurvatureRadius2*180/PI);
gBallisticElmtLength2 = fabs(gBallisticLength2- gFocLength)/18; /* 90 m - gFocLength */
gBallisticElmtRot2 = gBallisticElmtLength2/gCurvatureRadius2*180/PI;

if (gGap1 >= gBallisticElmtLength1*0.95) gGap1 = gBallisticElmtLength1*0.8;
/* if (gGap2 >= gBallisticElmtLength2*0.95) gGap2 = gBallisticElmtLength2*0.8;
if (gGapFoc >= gFocElementLength*0.95) gGapFoc = gFocElementLength*0.8; */
if (gGapSt >= gReactorStraightLength) gGapSt = gElementGap;

/* INFO ******************************************************************* */
printf("Simulation : %s on %s\n",VERSION,getenv("HOSTNAME"));

/* Source and guide parameters */
/* Lambda = 2*PI/Ki;

sLambda = Lambda; */
/* sDeltaLambda = sDeltaLambdaPercent * sLambda / 2; */
/* sDeltaLambda = sLambda*0.95; 0.5 ; */

/* First guide Phase-Space parameters */
PhiC = sqrt(2*fabs(gBallisticWidth/gCurvatureRadius1));
GammaC = mBallistic1*mQc/4/PI;
ThetaC = sLambda*GammaC;
LambdaC = PhiC/GammaC;
LStar = sqrt(8*fabs(gBallisticWidth*gCurvatureRadius1));
Zc = gBallisticWidth*(0.5-ThetaC*ThetaC/PhiC/PhiC);

printf("INFO: 1: L =%.4f m, rho=%.4f m, m=%.2f\n", gBallisticLength1, gCurvatureRadius1, mBallistic1);
printf("INFO: 1: L*=%.2f m, Phi_c = %.2f deg, Gamma_c = %.2f deg/Angs\n", LStar, PhiC*RAD2DEG, GammaC*RAD2DEG);
printf("INFO: 1: Zc = %.4f m, Lambda_c = %.2f Angs\n", Zc, LambdaC);
if (sLambda < LambdaC)
printf("INFO: 1: Garland reflections only\n");
else
printf("INFO: 1: Garland and Zig-Zag reflections\n");
if (gBallisticLength1 < LStar)
printf("INFO: 1: Guide is too short\n");

/* Second guide Phase-Space parameters */
PhiC = sqrt(2*fabs(gBallisticWidth/gCurvatureRadius2));
GammaC = mBallistic2*mQc/4/PI;
ThetaC = sLambda*GammaC;
LambdaC = PhiC/GammaC;
LStar = sqrt(8*fabs(gBallisticWidth*gCurvatureRadius2));
Zc = gBallisticWidth*(0.5-ThetaC*ThetaC/PhiC/PhiC);

printf("INFO: 2: L =%.4f m, rho=%.4f m, m=%.2f\n", gBallisticLength2, gCurvatureRadius2, mBallistic2);
printf("INFO: 2: L*=%.2f m, Phi_c = %.2f deg, Gamma_c = %.2f deg/Angs\n", LStar, PhiC*RAD2DEG, GammaC*RAD2DEG);
printf("INFO: 2: Zc = %.4f m, Lambda_c = %.2f Angs\n", Zc, LambdaC);
if (sLambda < LambdaC)
printf("INFO: 2: Garland reflections only\n");
else
printf("INFO: 2: Garland and Zig-Zag reflections\n");
if (gBallisticLength2 < LStar)
printf("INFO: 2: Guide is too short\n");

printf("Lgth: %.4f %.4f %.4f %.4f\n", gReactorStraightLength, gBallisticLength1, gBallisticLength2, gFocLength);
printf("Elmts:%.4f %.4f %.4f %.4f\n", gReactorStraightLength, gBallisticElmtLength1, gBallisticElmtLength2, gFocElementLength);
printf("Gaps: %.4f %.4f %.4f %.4f\n", gGapSt, gGap1, gGap2, gGapFoc);

%}
/* end of INITIALIZE */

TRACE
/* Source description ******************************************************* */

/* a flat rectangular source with Maxwellian distribution */
/* Reactor source 22x16 cm */

COMPONENT Source = Source_gen(
h = sH,
w = sW,
radius = sRadius,
length = 0.1,
dist = gSourceInputLength,
xw = gInputWidth,
yh = gGuideHeight0,
Lmin = 0.5,
Lmax = 15,
T1 = sT1,
I1 = sI1,
T2 = sT2,
I2 = sI2,
T3 = sT3,
I3 = sI3,
verbose = 1)
AT (0,0,0) ABSOLUTE

COMPONENT AlWindow1 = Al_window(win_thick=0.002)
AT (0,0,gSourceInputLength-0.01) RELATIVE Source

COMPONENT Input_1D = Monitor_nD(
xwidth=gInputWidth, yheight=gGuideHeight0,
options=MON_OUT)
AT (0,0,gSourceInputLength-0.005) RELATIVE Source

COMPONENT InPileGuide = Guide_gravity(
w1=gInputWidth, h1=gGuideHeight0, w2=gObtWidth, h2=gGuideHeight0, l=gInPileLength,
R0=mR0, Qc=mQc, alpha=mAlpha, m=mInPile, W=mW)
AT (0,0,gSourceInputLength) RELATIVE Source /* 2.33 from Source */

COMPONENT AlWindow2 = Al_window(win_thick=0.002)
AT (0,0,5.517) RELATIVE Source

/* Followed by a standart 228 mm guide (for H1) in Obturator, after at 20 mm gap, ends at 5.795 m from source */

COMPONENT FirstObturator = Guide_gravity(
w1=gObtWidth, h1=gGuideHeight0, w2=gObtWidth, h2=gGuideHeight0, l=0.228,
R0=mR0, Qc=mQc, alpha=mAlpha, m=mInPile, W=mW)
AT (0,0,5.520) RELATIVE Source /* 5.520 = 2.33+3.170+0.02 */

COMPONENT Obt_1D = Monitor_nD(
xwidth=gObtWidth, yheight=gGuideHeight0,
options=MON_OUT)
AT (0,0,.32) RELATIVE FirstObturator

COMPONENT AlWindow3 = Al_window(win_thick=0.002)
AT (0,0,.321) RELATIVE FirstObturator

/* gap 0.17 V.P. to start of Curved Guide (exit of In Pile part, Lead Shutter) */
/* now in Reactor C level, then in Guide hall */

/*-------------------------*/
/* Curved Guide ("MAN") */
/*-------------------------*/

/* curvature radius is 2700 m , start at XR=5.913 m from source, includes gap 17 cm after obturator*/
/* 5.918 = 2.33+3.170+0.02+0.228+0.17 */

COMPONENT CurvedGuideStart = Arm()
AT (0,0,5.9228) RELATIVE Source

COMPONENT ReactorGuide1 = Guide_gravity(
w1=gObtWidth, h1=gGuideHeight0,
w2=gObtWidth, h2=gGuideHeight0,
l=gReactorStraightLength/2-gElementGap-gGapSt/2,
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,0.0002) RELATIVE CurvedGuideStart

COMPONENT AlWindow04 = Al_window(win_thick=0.002)
AT (0,0,gReactorStraightLength/2-gGapSt/2) RELATIVE ReactorGuide1

/* first gap gGapSt */
/* height: gGuideHeight0 -> gGuideHeight1 */

COMPONENT Straight_1D = Monitor_nD(
xwidth=gObtWidth, yheight=gGuideHeight0,
options=MON_OUT)
AT (0,0,gGapSt/4+0.002) RELATIVE AlWindow04

COMPONENT AlWindow05 = Al_window(win_thick=0.002)
AT (0,0,gGapSt/4) RELATIVE Straight_1D

COMPONENT ReactorGuide2 = Guide_gravity(
w1=gObtWidth, h1=gGuideHeight1,
w2=gObtWidth, h2=gGuideHeight1,
l=gReactorStraightLength/2-gElementGap,
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gGapSt/2+0.002) RELATIVE AlWindow05

/* START of the Curved Guide at 5.8628 m from source ************************ */
/* 5 elements for unfocussing part */

COMPONENT ufcg1 = Guide_gravity(
w1=gObtWidth, h1=gGuideHeight1,
w2=((8*gObtWidth+2*gBallisticWidth)/10), h2=gGuideHeight1,
l=(gUnfocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gReactorStraightLength/2) RELATIVE ReactorGuide2 ROTATED (0,gUnfocElementRotation,0) RELATIVE ReactorGuide2

COMPONENT ufcg2 = Guide_gravity(
w1=((8*gObtWidth+2*gBallisticWidth)/10), h1=gGuideHeight1,
w2=((6*gObtWidth+4*gBallisticWidth)/10), h2=gGuideHeight1,
l=(gUnfocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gUnfocElementLength) RELATIVE ufcg1 ROTATED (0,gUnfocElementRotation,0) RELATIVE ufcg1

COMPONENT ufcg3 = Guide_gravity(
w1=((6*gObtWidth+4*gBallisticWidth)/10), h1=gGuideHeight1,
w2=((4*gObtWidth+6*gBallisticWidth)/10), h2=gGuideHeight1,
l=(gUnfocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gUnfocElementLength) RELATIVE ufcg2 ROTATED (0,gUnfocElementRotation,0) RELATIVE ufcg2

COMPONENT ufcg4 = Guide_gravity(
w1=((4*gObtWidth+6*gBallisticWidth)/10), h1=gGuideHeight1,
w2=((2*gObtWidth+8*gBallisticWidth)/10), h2=gGuideHeight1,
l=(gUnfocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gUnfocElementLength) RELATIVE ufcg3 ROTATED (0,gUnfocElementRotation,0) RELATIVE ufcg3

COMPONENT ufcg5 = Guide_gravity(
w1=((2*gObtWidth+8*gBallisticWidth)/10), h1=gGuideHeight1,
w2=gBallisticWidth, h2=gGuideHeight1,
l=(gUnfocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gUnfocElementLength) RELATIVE ufcg4 ROTATED (0,gUnfocElementRotation,0) RELATIVE ufcg4

COMPONENT AlWindow4 = Al_window(win_thick=0.002)
AT (0,0,gUnfocElementLength+0.001) RELATIVE ufcg5

/* gap V.S. 0.148, normally at 6 m from CurvedGuideStart ******************** */

COMPONENT VS_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight1,
options=MON_OUT)
AT (0,0,gUnfocElementLength+0.03+0.002) RELATIVE ufcg5

COMPONENT AlWindow5 = Al_window(win_thick=0.002)
AT (0,0,gUnfocElementLength+0.05) RELATIVE ufcg5

/* curved/ballistic part 1, 19 elements : should be about 19 m long, rho=2700 */
COMPONENT BallisticSectionStart = Arm()
AT (0,0, (gUnfocElementLength + 0.148+0.002)) RELATIVE ufcg5 ROTATED (0, 0 ,0) RELATIVE ufcg5

COMPONENT cg1 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0,0) RELATIVE BallisticSectionStart ROTATED (0, gBallisticElmtRot1,0) RELATIVE BallisticSectionStart

COMPONENT cg2 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg1 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg1

COMPONENT cg3 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg2 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg2

COMPONENT cg4 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg3 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg3
COMPONENT cg5 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg4 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg4

COMPONENT BalMon1_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight1,
options=MON_OUT)
AT (0,0,gBallisticElmtLength1-gElementGap/2) RELATIVE cg5

COMPONENT cg6 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg5 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg5

COMPONENT cg7 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg6 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg6

COMPONENT cg8 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap-0.002-gGap1),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg7 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg7

/* gap gGap1 */

COMPONENT BalMon2_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight1,
options=MON_OUT)
AT (0,0,gBallisticElmtLength1-gElementGap/2) RELATIVE cg8

COMPONENT cg9 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg8 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg8

COMPONENT cg10 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg9 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg9

COMPONENT cg11 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg10 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg10

COMPONENT cg12 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg11 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg11

COMPONENT cg13 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg12 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg12

COMPONENT cg14 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg13 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg13

COMPONENT cg15 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg14 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg14

COMPONENT cg16 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap-0.002-gGap1),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg15 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg15

/* gap gGap1 */

COMPONENT BalMon3_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight1,
options=MON_OUT)
AT (0,0,gBallisticElmtLength1-gElementGap/2) RELATIVE cg16

COMPONENT cg17 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg16 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg16

COMPONENT cg18 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg17 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg17

COMPONENT cg19 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight1,w2=gBallisticWidth,h2=gGuideHeight1,
l=(gBallisticElmtLength1-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic1,W=mW)
AT (0,0, gBallisticElmtLength1) RELATIVE cg18 ROTATED (0, gBallisticElmtRot1,0) RELATIVE cg18

COMPONENT AlWindow6 = Al_window(win_thick=0.002)
AT (0,0,gBallisticElmtLength1+0.001) RELATIVE cg19

/* gap V.T.E. 0.260, normally at 25.5 + 0.148 m from CurvedGuideStart ******* */

COMPONENT BalMon4_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight1,
options=MON_OUT)
AT (0,0,gBallisticElmtLength1+0.003+0.002) RELATIVE cg19

COMPONENT AlWindow7 = Al_window(win_thick=0.002)
AT (0,0,gBallisticElmtLength1+0.05) RELATIVE cg19

/* curved/ballistic part 2, 18 elements : should be 75 m - gFocLength long, rho=2700 */
/* small gaps 0.003 every two sections ~ 10 m */
COMPONENT BallisticSectionStart2 = Arm()
AT (0,(gGuideHeight2 - gGuideHeight1)/2, (gBallisticElmtLength1 + 0.260)) RELATIVE cg19 ROTATED (0, 0 ,0) RELATIVE cg19

COMPONENT scg1 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0,0) RELATIVE BallisticSectionStart2 ROTATED (0, gBallisticElmtRot2,0) RELATIVE BallisticSectionStart2

COMPONENT scg2 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg1 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg1

COMPONENT scg3 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg2 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg2

COMPONENT scg4 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg3 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg3

COMPONENT scg5 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg4 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg4

COMPONENT scg6 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg5 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg5

/* gap gGap2 */

COMPONENT BalMon5_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight2,
options=MON_OUT)
AT (0,0,gBallisticElmtLength2+gGap2-gElementGap/2) RELATIVE scg6

COMPONENT scg7 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2+gGap2) RELATIVE scg6 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg6

COMPONENT scg8 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg7 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg7

COMPONENT scg9 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg8 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg8

COMPONENT scg10 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg9 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg9

COMPONENT scg11 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg10 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg10

COMPONENT scg12 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg11 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg11

COMPONENT scg13 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg12 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg12

COMPONENT scg14 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg13 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg13

/* gap gGap2 */

COMPONENT BalMon7_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight2,
options=MON_OUT)
AT (0,0,gBallisticElmtLength2+gGap2-gElementGap/2) RELATIVE scg14

COMPONENT scg15 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2+gGap2) RELATIVE scg14 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg14

COMPONENT scg16 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg15 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg15

COMPONENT scg17 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg16 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg16

COMPONENT scg18 = Guide_gravity(w1=gBallisticWidth,h1=gGuideHeight2,w2=gBallisticWidth,h2=gGuideHeight2,
l=(gBallisticElmtLength2-gElementGap-0.002),
R0=mR0,Qc=mQc,alpha=mAlpha,m=mBallistic2,W=mW)
AT (0,0, gBallisticElmtLength2) RELATIVE scg17 ROTATED (0, gBallisticElmtRot2,0) RELATIVE scg17

/* 5 elements for focussing part ******************************************** */

COMPONENT fcg1 = Guide_gravity(
w1=gBallisticWidth, h1=gGuideHeight2,
w2=((8*gBallisticWidth+2*gStraightInWidth)/10), h2=gGuideHeight2,
l=(gFocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gBallisticElmtLength2) RELATIVE scg18 ROTATED (0,gFocElementRotation,0) RELATIVE scg18

COMPONENT fcg2 = Guide_gravity(
w1=((8*gBallisticWidth+2*gStraightInWidth)/10), h1=gGuideHeight2,
w2=((6*gBallisticWidth+4*gStraightInWidth)/10), h2=gGuideHeight2,
l=(gFocElementLength-gElementGap-0.002),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gFocElementLength) RELATIVE fcg1 ROTATED (0,gFocElementRotation,0) RELATIVE fcg1

COMPONENT fcg3 = Guide_gravity(
w1=((6*gBallisticWidth+4*gStraightInWidth)/10), h1=gGuideHeight2,
w2=((4*gBallisticWidth+6*gStraightInWidth)/10), h2=gGuideHeight2,
l=(gFocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gFocElementLength) RELATIVE fcg2 ROTATED (0,gFocElementRotation,0) RELATIVE fcg2

COMPONENT fcg4 = Guide_gravity(
w1=((4*gBallisticWidth+6*gStraightInWidth)/10), h1=gGuideHeight2,
w2=((2*gBallisticWidth+8*gStraightInWidth)/10), h2=gGuideHeight2,
l=(gFocElementLength-gElementGap-0.002),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gFocElementLength) RELATIVE fcg3 ROTATED (0,gFocElementRotation,0) RELATIVE fcg3

/* gap gGapFoc */

COMPONENT BalMon8_1D = Monitor_nD(
xwidth=gBallisticWidth, yheight=gGuideHeight2,
options=MON_OUT)
AT (0,0,gFocElementLength+gGapFoc-gElementGap/2) RELATIVE fcg4

COMPONENT fcg5 = Guide_gravity(
w1=((2*gBallisticWidth+8*gStraightInWidth)/10), h1=gGuideHeight2,
w2=gStraightInWidth, h2=gGuideHeight2,
l=(gFocElementLength-gElementGap),
R0=mR0, Qc=mQc, alpha=mAlpha, m=mBallistic1, W=mW)
AT (0,0,gFocElementLength+gGapFoc) RELATIVE fcg4 ROTATED (0,gFocElementRotation,0) RELATIVE fcg4

/* End of ballistic guide. exp ****************************************** */

COMPONENT CurvedGuideEnd = Arm()
AT (0,0,gFocElementLength) RELATIVE fcg5

COMPONENT AlWindow8 = Al_window(win_thick=0.002)
AT (0,0,gFocElementLength+0.001) RELATIVE fcg5

/*-------------------------*/
/* End of Curved Guide */
/*-------------------------*/

COMPONENT END_In_XY = Monitor_nD(
xwidth=gStraightInWidth, yheight=gGuideHeight2,
options="x y, per cm2, all bins=40 capture")
AT (0,0,gToInstrLength/2+0.01) RELATIVE CurvedGuideEnd

COMPONENT END_In_1D = Monitor_nD(
xwidth=gStraightInWidth, yheight=gGuideHeight2,
options="x y hdiv vdiv lambda k, all bins=50, per cm2, auto")
AT (0,0,gToInstrLength/2+0.02) RELATIVE CurvedGuideEnd

END