""" \namespace xboa::examples::Example_2 Example code to read a file and make some plots \include xboa/examples/Example_2.py """ ############# # EXAMPLE 2 # # PLOTTING # ############# # # Load a data file; make some plots # #try to import the XBOA library - if this fails, review the installation procedure from xboa import * from xboa.Hit import Hit from xboa.Bunch import Bunch import sys #some input data if (len(sys.argv) < 2): print "No input data supplied. Fail. " raise SystemExit #do nothing filename = sys.argv[1] filetype = "maus_root_virtual_hit" print '========= XBOA example 2 =========' #try to load an input file #this will load the for009 file, and make a list of "bunches", one for each region #a list is a python version of an array print "This example shows how to make plots\nYou will need to have access to either ROOT library or the matplotlib library to make plots" print "First loading the data... " bunch_list = Bunch.new_list_from_read_builtin(filetype, filename) print "Loaded" #make some plots #first try to make plots with ROOT if PyROOT exists try: print 'Trying to make some plots using PyROOT plotting package' Common.has_root() #check for PyRoot library #momentum distribution at start and end bunch_list[0] .root_histogram('px', 'MeV/c') bunch_list[-1].root_histogram('px', 'MeV/c') #energy-time scatter plot at start bunch_list[0].root_scatter_graph('t', 'energy', 'ns', 'MeV/c') #histogram at start; note that in the first instance it *looks* like a scatter plot #but it is not; hence I draw the same histogram twice, once as a pseudo-scatter #and once as a contour plot bunch_list[0].root_histogram('t', 'ns', 'energy', 'MeV/c') (canvas, hist) = bunch_list[0] .root_histogram('t', 'ns', 'energy', 'MeV/c') hist.Draw('CONT') canvas.Update() #evolution of RMS emittance in x along the beamline Bunch.root_graph(bunch_list, 'mean', ['z'], 'mean', ['x'], 'm', 'mm') Bunch.root_graph(bunch_list, 'mean', ['z'], 'mean', ['pz'], 'm', 'mm') ********************* ## added by Tim ************** ************************* Bunch.root_graph(bunch_list, 'mean', ['z'], 'beta', ['x','y'], 'm', 'mm') Bunch.root_graph(bunch_list, 'mean', ['z'], 'emittance', ['x','y'], 'm', 'mm') *********************************** except ImportError: print "PyROOT not detected - skipping PyROOT graphics" #now wait for user to review plots before ending print 'Press key to finish' raw_input()