<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:annotation>
		<xs:documentation> This schema regroups all the definitions pertaining to the beam
			definition at the start of the machine. Note that I defined the child elements such that
			they can occur in any order. In addition, I constrained the user to specify certain key
			parameters. It is safe to assume (I think) that most lattice codes will at least need to
			know what energy, charge and mass of particle to use. Tracking codes may need more but
			since this schema is supposed to cover all possible codes including pure matrix
			transport calculations, it is better not to force the user to specify these extra beam
			parameters. Should we also specify default values for these parameters that can be
			ommitted? </xs:documentation>
	</xs:annotation>
	<xs:include schemaLocation="expressions.xsd"/>
	<xs:include schemaLocation="positioning.xsd"/>
	<xs:element name="beam">
		<xs:complexType>
			<!-- following the comments by PT, I am forcing all the tags to appear in order -->
			<!-- I am still allowing some tags to be omitted. -->
			<!-- we will have to agree on which tags are mandatory, which are optional -->
			<xs:sequence>
				<xs:element ref="position" minOccurs="0"/>
				<xs:element ref="sigma_matrix" minOccurs="0"/>
				<xs:element ref="energy" minOccurs="1"/>
				<xs:element ref="mass" minOccurs="1"/>
				<xs:element ref="charge" minOccurs="1"/>
				<xs:element ref="particle" minOccurs="0"/>
				<xs:element ref="n_particles" minOccurs="0"/>
				<xs:element ref="pc" minOccurs="1"/>
				<xs:element ref="gamma" minOccurs="1"/>
				<xs:element ref="emittance_x" minOccurs="0"/>
				<xs:element ref="emittance_y" minOccurs="0"/>
				<xs:element ref="normalized_emittance_x" minOccurs="0"/>
				<xs:element ref="normalized_emittance_y" minOccurs="0"/>
				<xs:element ref="sig_z" minOccurs="0"/>
				<xs:element ref="sig_e" minOccurs="0"/>
				<xs:element ref="sig_t" minOccurs="0"/>
				<xs:element ref="num_bunches" minOccurs="0"/>
				<xs:element ref="beam_current" minOccurs="0"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="energy" type="valuearg"/>
	<xs:element name="mass" type="valuearg"/>
	<xs:element name="charge" type="valuearg"/>
	<xs:element name="particle" type="valuearg"/>
	<xs:element name="n_particles" type="valuearg"/>
	<xs:element name="pc" type="valuearg"/>
	<xs:element name="gamma" type="valuearg"/>
	<xs:element name="emittance_x" type="valuearg"/>
	<xs:element name="emittance_y" type="valuearg"/>
	<xs:element name="normalized_emittance_x" type="valuearg"/>
	<xs:element name="normalized_emittance_y" type="valuearg"/>
	<xs:element name="sig_z" type="valuearg"/>
	<xs:element name="sig_e" type="valuearg"/>
	<xs:element name="sig_t" type="valuearg"/>
	<xs:element name="num_bunches" type="valuearg"/>
	<xs:element name="beam_current" type="valuearg"/>
	<xs:complexType name="valuearg">
		<xs:attribute name="value" type="arglist"/>
	</xs:complexType>
	<xs:element name="sigma_matrix">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="sigma" minOccurs="1" maxOccurs="36"/>
				<xs:element ref="emittance" minOccurs="0" maxOccurs="3"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:string"/>
		</xs:complexType>
		<xs:unique name="sigmaName">
			<xs:selector xpath="./sigma_matrix"/>
			<xs:field xpath="@name"/>
		</xs:unique>
	</xs:element>
	<!-- sigma matrix element -->
	<xs:element name="sigma">
		<xs:complexType>
			<xs:attribute name="i" type="sigid" use="required"/>
			<xs:attribute name="j" type="sigid" use="required"/>
			<xs:attribute name="value" type="arglist" use="required"/>
		</xs:complexType>
	</xs:element>
	<!-- make sure user can only enter valid indices, its a 6x6 matrix. -->
	<xs:simpleType name="sigid">
		<xs:restriction base="xs:integer">
			<xs:maxInclusive value="6"/>
			<xs:minInclusive value="1"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="emittance">
		<xs:complexType>
			<xs:attribute name="i" type="emitid" use="required"/>
			<xs:attribute name="value" type="arglist" use="required"/>
		</xs:complexType>
	</xs:element>
	<!-- make sure user can only specify a valid emittance id -->
	<xs:simpleType name="emitid">
		<xs:restriction base="xs:integer">
			<xs:maxInclusive value="3"/>
			<xs:minInclusive value="1"/>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>
