NotebookDirectory[]

opts={Frame->True, BaseStyle->{FontSize->15}};
SetOptions[ListPlot, opts];

mec2N = 0.511 (10^6);

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

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

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

pref = Table[adat[[i,2]][[1]], {i,1,Length[adat]}];
p[n_]:=Table[adat[[i,2]][[n]], {i,1,Length[adat]}];

Length[adat]

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, FrameLabel->{"Z (m)","X (m)", "Astra reference particle"}]

pdat={#[[3]],(1/(10^6))Sqrt[((#[[4]])^2)+ ((#[[6]])^2) +(mec2N^2)]}&/@Table[adat[[i,2]][[1]], {i,1,Length[adat]}];
ListPlot[{pdat, pdat}, Joined->{True, False},PlotStyle->{Black, Red}, Frame->True, FrameLabel->{"Z (m)","(Subscript[E, total]) (MeV)", "Max: "<>ToString[Max[pdat[[All,2]]]]},PlotRange->{{0,All},{0,All}}]

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]