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];

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", "y",bdat, PlotStyle->Blue]

g2=AstraPhaseSpace["z", "y", atracks, PlotStyle->Red]

Show[g1,g2]