<< NumericalMath`ListIntegrate`
<< Statistics`DataSmoothing`
<< NumericalMath`PolynomialFit`
hide = DisplayFunction -> Identity
SetDirectory["/afs/cern.ch/user/a/afabich/public/MERIT"]
<< "prolog.m"

    
SetDirectory["/nfs/cs-ccr-nfs4/data/slopsdata/2007/MD_DATA/CPS_MERIT/\
MERIT_libera"]
Files = FileNames["2007*result.txt"];

SetDirectory["/nfs/cs-ccr-nfs4/data/slopsdata/2007/MD_DATA/CPS_\
MERIT/MERIT_libera"]

      
AllSingles = {};
AllSingInt = {};
AllSingIntMax = {};
\(Do[
If[
        And[k ≠ 170, 
          k ≠ 171], {
data162 = 
            Take[ReadList[Files[\([k]\)], Number], {870, 
                1050}], 
Do[
            If[data162[\([m]\)] < 0, {Cut = m, Break[]}], {m, 15, 
              65}], 
data162 = 
            Join[Table[0, {30 - Cut}], data162], 
data162 = 
            N[data162/Max[data162]], 
data162 = 
            Drop[data162, \(Position[
                    data162, _?\((# ≥ 0.6 &)\)]\)[\([1, 1]\)] - 
                10], 
AppendTo[AllSingles, 
            data162], 
SingInt = {data162[\([1]\)]}, 
Do[
            AppendTo[SingInt, SingInt[\([\(-1\)]\)] + data162[\([m]\)]], {m, 
              2, Length[data162]}], 
SingInt /= 
            Max[SingInt], 
AppendTo[AllSingInt, 
            SingInt], 
AppendTo[
            AllSingIntMax, {k, Files[\([k]\)], 
              Max[Take[SingInt, {1, 33}]]}]
}]
, {k, 162, 
        179}]\)

\(Export["/afs/cern.ch/user/a/afabich/public/MERIT/AllSingIntMax.gif", 
Show[
        GraphicsArray[{
MultipleListPlot[AllSingles, hide, 
              PlotRange -> {{1, 40}, {\(-0.2\), 
                    1.2}}], 
MultipleListPlot[AllSingles, 
              hide, PlotRange -> {{40, 80}, {\(-0.2\), 
                    1.2}}], 
MultipleListPlot[AllSingInt, 
              hide]
}], 
        ImageSize -> 900]
]\)

Show[
      GraphicsArray[{
MultipleListPlot[AllSingles, hide, 
            PlotRange -> {{1, 40}, {-0.2, 
                  1.2}}], 
MultipleListPlot[AllSingles, 
            hide, PlotRange -> {{40, 80}, {-0.2, 
                  1.2}}], 
MultipleListPlot[AllSingInt, 
            hide]
}], 
      ImageSize -> 1200]

    
ListPlot[Transpose[
          AllSingIntMax][[3]]]

    
Export["/afs/cern.ch/user/a/afabich/public/MERIT/temp.dat", 
      AllSingIntMax]

ListPlot[
Take[
Abs[
          Fourier[Take[data162, {40, 185}]]]
, 
        35]
]

peaks = {};
Do[
If[
        data[[m - 1]] < data162[[m]] < data162[[m + 1]], 
        AppendTo[peaks, m]]
, {m, 2, 
        Length[data162] - 1}]

peaksP = {};
peaksT = {peaks[[1]]};
Do[
If[
        peaksT[[-1]] == peaks[[m]] - 1, 
        AppendTo[peaksT, peaks[[m]]], {AppendTo[peaksP, Mean[peaksT]], 
          peaksT = {peaks[[m]]}}]
, {m, 2, 
        Length[peaks] - 1}]

funcInt = 
      Interpolation[AllSingInt[[1]]]
mid = 
      First[First[
Select[
Table[{k, 
                funcInt[k]}, {k, 10, 30, 
                0.01}]
, #[[2]] > 
                Max[AllSingInt[[1]]]/
                  2 &]
]]

DisplayTogether[
ListPlot[
        AllSingInt[[1]]], 
Plot[
        funcInt[x], {x, 1, 
          Length[AllSingInt[[1]]]}], 
Graphics[
        Line[{{mid + 5, 0}, {mid + 5, 
              10000}}]]
]