def get_simulation( self, bpms, magnets, fields ):
		self.use_field_setpoint( magnets )
		self.apply_magnet_fields( magnets, fields )
		if self.has_synched:
			self.scenario.resyncFromCache()
		else:
			self.scenario.resync()
			self.has_synched = true
		self.probe.reset()
		self.scenario.run()
		for magnet in magnets:  self.remove_magnet_override( magnet )
		trajectory = self.probe.getTrajectory()
		resultsAdaptor = SimpleSimResultsAdaptor( trajectory )

		foil_state = trajectory.statesForElement( "Ring_Inj:Foil" )[0]
		fixed_orbit_at_foil = resultsAdaptor.computeFixedOrbit( foil_state )
		foil_displacement = 1000 * fixed_orbit_at_foil.getx()
		foil_angle = 1000 * fixed_orbit_at_foil.getxp()
		
		orbit = []
		for bpm in bpms:
			state = trajectory.statesForElement( bpm.getId() )[0]
			fixed_orbit = resultsAdaptor.computeFixedOrbit( state )
			displacement = 1000 * fixed_orbit.getx()
			orbit.append( displacement )
			
		simulation = Simulation( orbit, foil_displacement, foil_angle )
			
		return simulation
def get_orbit( bpms, trajectory, plane_adaptor ):
	resultsAdaptor = SimpleSimResultsAdaptor( trajectory )
	orbit = []
	for bpm in bpms:
		state = trajectory.statesForElement( bpm.getId() )[0]
		displacement = plane_adaptor.getOffset( resultsAdaptor.computeFixedOrbit( state ) )
		orbit.append( displacement )
		
	return orbit
	def get_orbit( self, bpms, kickers, plane_adaptor, fields ):
		self.apply_kicker_fields( kickers, fields )
		if self.has_synched:
			self.scenario.resyncFromCache()
		else:
			self.scenario.resync()
			self.has_synched = true
		self.probe.reset()
		self.scenario.run()
		for kicker in kickers:  self.apply_kicker_field( kicker, 0.0 )
		trajectory = self.probe.getTrajectory()
		resultsAdaptor = SimpleSimResultsAdaptor( trajectory )

		orbit = []
		for bpm in bpms:
			state = trajectory.statesForElement( bpm.getId() )[0]
			displacement = plane_adaptor.getOffset( resultsAdaptor.computeFixedOrbit( state ) )
			orbit.append( displacement )
			
		return orbit
	def get_zero_field_orbit( self, bpms, plane_adaptor ):
		if self.zero_field_orbit_plane == plane_adaptor:		# need to recalculate only if the plane has changed since last calculation
			return self.zero_field_orbit
		if self.has_synched:
			self.scenario.resyncFromCache()
		else:
			self.scenario.resync()
			self.has_synched = true
		self.probe.reset()
		self.scenario.run()
		trajectory = self.probe.getTrajectory()
		resultsAdaptor = SimpleSimResultsAdaptor( trajectory )
		
		orbit = []
		for bpm in bpms:
			state = trajectory.statesForElement( bpm.getId() )[0]
			displacement = plane_adaptor.getOffset( resultsAdaptor.computeFixedOrbit( state ) )
			orbit.append( displacement )
			
		self.zero_field_orbit = orbit
		self.zero_field_orbit_plane =  plane_adaptor
		return orbit