NotebookDirectory[]

file = "fieldgrid_1.astra";
dat = Import[NotebookDirectory[]<>file, "Table"];
ListPlot[dat]

dat[[1;;10]]//Grid

stepfiles = Flatten[ Import[NotebookDirectory[]<>"steps.txt", "Table"]];
adat = Table[{f, ImportAstraParticles[NotebookDirectory[]<>f]}, {f, stepfiles }];
atracks = Flatten[adat[[All, 2]], 1];

adat3D = adat;
atracks3D =atracks;

Length[adat]

pdat={#[[3]], #[[6]]}&/@Table[adat[[i,2]][[1]], {i,1,Length[adat]}];
ListPlot[{pdat, pdat}, Joined->{True, False},PlotStyle->{Black, Red}, PlotRange->All, Frame->True]

pdat={#[[3]], #[[1]]}&/@Table[adat[[i,2]][[1]], {i,1,Length[adat]}];
ListPlot[{pdat, pdat}, Joined->{True, False},PlotStyle->{Black, Red}, PlotRange->All, Frame->True]

adat0=ImportAstraParticles[NotebookDirectory[]<>"lat.astra_particles"];

Length[adat]

AstraPhaseSpace["z", "x", Flatten[Table[adat[[i,2]], {i,1,Length[adat], 1}], 1], PlotRange->All]

bdat = ImportBmadTimeParticles[NotebookDirectory[]<>"lat.out"];

atracks[[1;;10]]

g1=BmadPlot["z", "x",bdat, PlotStyle->Blue]

g2=AstraPhaseSpace["z", "x", atracks3D, PlotStyle->Red]

Show[g1,g2]

g1 = BmadPlot["z", "cp_z",bdat, PlotStyle->Blue];
g2 = AstraPhaseSpace["z", "pz", atracks1D, PlotStyle->{PointSize[Large], Green}];
g3 = AstraPhaseSpace["z", "pz", atracks3D, PlotStyle->Red];
Show[g1,g2,g3]

g1 = BmadPlot["z", "x",bdat, PlotStyle->Blue];
g2 = AstraPhaseSpace["z", "x", atracks1D, PlotStyle->{PointSize[Large], Green}];
g3 = AstraPhaseSpace["z", "x", atracks3D, PlotStyle->Red];
Show[g1,g2,g3]