<?xml version="1.0" encoding="UTF-8"?>
<laboratory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="aml.xsd" name="JEFFERSON LAB">
	<!-- the following constants should probably be included from a separate file. I am putting them here for test -->
	<constant name="pi">3.14159255369 </constant>
	<constant name="twopi"> 6.2831851138</constant>
	<constant name="fourpi">12.5663702276</constant>
	<constant name="sqrt_2"> 1.4142135623731</constant>
	<constant name="degrees">57.295781336859913613136404378359</constant>
	<constant name="Hz"> 0.15915494309189533576888376337251</constant>
	<constant name="m_electron">0.51099906E+06</constant>
	<constant name="m_proton"> 0.938271998E+09</constant>
	<constant name="c_light"> 2.99792458E+08</constant>
	<constant name="r_e"> 2.8179380E-15</constant>
	<constant name="r_p"> 1.5346980E-18</constant>
	<constant name="$e_charge"> 1.6021892E-19</constant>
	<constant name="h_planck"> 6.626196E-34</constant>
	<constant name="h_bar_planck">1.054591E-34</constant>
	<constant name="e_mass"> 0.51099906E-03</constant>
	<constant name="p_mass"> 0.938271998</constant>
	<!-- here we start defining mathematical expressions -->
	<!-- the Schema will validate these expressions if they follow the rules given in the AML specs -->
	<!-- A benefit of doing that in the Schema is that we dont have to worry about checking the syntax -->
	<!--  in the C++ parsers where it is usually harder   -->
	<constant name="e"> 0.445 - $e_mass</constant>
	<constant name="gamma"> sqrt( 1.0 - ( $ / $e_mass ) * ( $e / $e_mass ) ) </constant>
	<constant name="pc"> $gamma * $e_mass</constant>
	<constant name="halfgap"> = 1.27 </constant>
	<constant name="fi"> $pi / 16.0 </constant>
	<constant name="gap"> 2.54 </constant>
	<doc author="Yves Roblin" date="2005-02-05" href="http://www.jlab.org/"> this deck is for
		testing the AML parsers. It properly validates under the AML Schema. </doc>
	<parameter>
		<ran_seed value="2421424"/>
		<taylor_order value="4"/>
	</parameter>
	<machine>
		<lattice_name> CEBAF lattice</lattice_name>
		<layout_name> DESIGN setup</layout_name>
		<initial>
			<!-- note that it is probably good practice to compute the redundant values -->
			<!-- such as momentum, energy, gamma in order to be sure they are not -->
			<!-- uncompatible -->
			<twiss name="myfavoriteset">
				<beta_a value="1.0"/>
				<!-- all the parameters below will also accept expressions -->
				<beta_b value="1.0"/>
				<alpha_a value="0.0"/>
				<alpha_b value="0.0"/>
				<phase_a value="0.0"/>
				<phase_b value="0.0"/>
				<eta_x value="0.0"/>
				<eta_y value="0.0"/>
				<etap_x value="0.0"/>
				<etap_y value="0.0"/>
				<C11 value="1.0"/>
				<C12 value="0.0"/>
				<C21 value="0.0"/>
				<C22 value="1.0"/>
			</twiss>
			<global_position name="beamspot" at="CENTER">
				<x value="2.0"/>
				<y value="5.0"/>
				<z value="0.0"/>
				<phi value="0.0"/>
				<psi value="0.1"/>
				<theta value="0.0"/>
			</global_position>
		</initial>
		<beam>
			<sigma_matrix name="stdbeam">
				<sigma i="1" j="2" value="3.7E-6"/>
				<emittance i="1" value="3.2E-7"/>
			</sigma_matrix>
			<energy value="$e"/>
			<mass value="$e_mass"/>
			<charge value="1.0"/>
			<pc value="$pc "/>
			<gamma value="$gamma"/>
		</beam>
		<sector name="fodo1"/>
		<sector name="fodo2"/>
		<sector name="arc1" arg1="A1" arg2="A2">
			<element name="quad01">
				<quadrupole name="quad01design">
					<description>
						<type>standard 30cm quad</type>
						<alias>MQB1A01</alias>
					</description>
					<state>ON</state>
					<!-- this is one way to specify multipole components. -->
					<!-- see the solquad below for the alternative formulation -->
					<multipole>
						<a value="0.0 0.0"/>
						<b value="0.0 1.0"/>
						<radius value="1.0"/>
					</multipole>
					<aperture name="ap01" shape="ELLIPTICAL">
						<x_limit side="+" value="1.5 * $gap"/>
						<!-- can use expressions here.. -->
						<y_limit side="+" value="2.0"/>
						<!-- of course numbers also work -->
					</aperture>
				</quadrupole>
				<!-- the orientation tag inside the element is used for misalignments -->
				<orientation name="quad01misaligments">
					<x_offset value="0.001"/>
					<y_offset value="-0.002"/>
					<roll value="0.01"/>
				</orientation>
			</element>
			<element name="solquad01">
				<Sol_Quad name="solquad01design">
					<!-- this composite element also has design offsets -->
					<orientation name="designorientation" who="QUADRUPOLE">
						<x_offset value="0.01"/>
						<roll value="45.0"/>
					</orientation>
					<ks/>
					<!-- and here we added multipole components using the alternate syntax -->
					<multipole>
						<KL value="0.0 0.001 0.00"/>
						<T value="0.0 -0.2 0.0"/>
					</multipole>
				</Sol_Quad>
				<orientation name="solquad01misalignments">
					<s_offset value="0.01"/>
					<roll value="0.01"/>
				</orientation>
			</element>
			<!-- define a girder to use in sector definitions -->
			<!-- it is useful since it allows us to offset or rotate -->
			<!-- groups of elements together. -->
			<element name="girder">
				<i_beam name="ib1">
					<orientation>
						<x_pitch value="0.1"/>
						<y_pitch value="0.3"/>
					</orientation>
				</i_beam>
			</element>
			<!-- define a few elements-->
			<element name="bpm1can">
				<monitor name="bpm1"/>
			</element>
			<!-- use a drift with apertures to represents  a 3/4 inches beampipe -->
			<element name="driftspace">
				<drift name="drift12" >
					<length value="10.0"/>
					<aperture at="BOTH ENDS" shape="ELLIPTICAL">
						<x_limit side="BOTH" value="0.75"/>
						<y_limit side="BOTH" value="0.75"/>
					</aperture>
				</drift>
			</element>
			<element name="bpm2can">
				<monitor name="bpm2"/>
			</element>		
			<!-- elements will sit on top of the girder -->
			<sector name="girder01sector" i_beam="girder">
				<element ref="bpm1can"/>
				<element ref="driftspace"/>
				<element ref="bpm2can"/>	
			</sector>
			<!-- the schema will enforce that we type the coefficients properly (6  0/1 integer in exp attribute) -->
			<!-- it will also enforce having 6 taylor series (one per out coef) -->
			<element name="taylor01">
				<Taylor name="taylor01design">
					<taylor_map>
						<taylor_series out="1">
							<term coef="2.53" exp="1 0 0 0 0 0"/>
						</taylor_series>
						<taylor_series out="2">
							<term coef="1.53" exp="0 1 0 0 0 0"/>
						</taylor_series>
						<taylor_series out="3">
							<term coef="-0.5" exp="0 0 1 0 0 0 "/>
						</taylor_series>
						<taylor_series out="4">
							<term coef="0.01" exp="0 0 0 1 0 0"/>
						</taylor_series>
						<taylor_series out="5">
							<term coef="-1.0" exp="0 0 0 0 1 0"/>
						</taylor_series>
						<taylor_series out="6">
							<term coef="0.02" exp="0 0 0 0 0 1"/>
						</taylor_series>
					</taylor_map>
				</Taylor>
			</element>
		</sector>
	</machine>
</laboratory>
