(* ::Package:: *)

\[Alpha][s_]:=deltaFinal[JJ][s]/\[Pi];


OmnesPrimeNInt[sig_][s_]:=Exp[s/Pi*NIntegrate[deltaFinal[1][sb]/(sb(sb-s-I sig \[Epsilon])),{sb,4mpi^2,4mK^2,4meta^2,Infinity},AccuracyGoal->ACURACY,MaxRecursion->MAXREC]];
OmnesPrime[sig_][s_]:=Which[s>4mpi^2,Exp[sig*I deltaFinal[JJ][s]+deltaFinal[JJ][s]/Pi*Log[-4mpi^2/(4mpi^2-s)]+s/Pi*NIntegrate[(deltaFinal[JJ][sb]-deltaFinal[JJ][s])/(sb(sb-s)),{sb,4mpi^2,4mK^2,4meta^2,Infinity},AccuracyGoal->ACURACY,MaxRecursion->MAXREC]],
s<=4mpi^2,Exp[s/Pi*NIntegrate[deltaFinal[JJ][sb]/(sb(sb-s)),{sb,4mpi^2,4mK^2,4meta^2,Infinity},AccuracyGoal->ACURACY,MaxRecursion->MAXREC]]
];


OmnesElNInt[sig_][s_]:=Which[sig==0,Exp[s/Pi*NIntegrate[deltaFinal[JJ][sb]/(sb(sb-s)),{sb,4mpi^2,4mK^2,4meta^2,LamOmnes^2},AccuracyGoal->ACURACY,MaxRecursion->MAXREC]],
sig==1||sig==-1,Which[s<=4mpi^2||s>=LamOmnes^2,Exp[s/Pi*NIntegrate[deltaFinal[JJ][sb]/(sb(sb-s)),{sb,4mpi^2,4mK^2,4meta^2,LamOmnes^2},AccuracyGoal->ACURACY,MaxRecursion->MAXREC]],
4mpi^2<s<LamOmnes^2,Exp[sig*I*deltaFinal[JJ][s]+deltaFinal[JJ][s]/Pi*Log[-(((-s+LamOmnes^2)*4mpi^2)/(LamOmnes^2*(-s+4mpi^2)))]
+s/Pi*NIntegrate[(deltaFinal[JJ][sb]-deltaFinal[JJ][s])/(sb(sb-s)),{sb,4mpi^2,4mK^2,4meta^2,LamOmnes^2},AccuracyGoal->ACURACY,MaxRecursion->MAXREC]]]
];

wgOmn=GaussianQuadratureWeights[nOmn,s0,LamOmnes^2];
snOmn=Table[wgOmn[[i,1]],{i,nOmn}];
wgnOmn=Table[wgOmn[[i,2]],{i,nOmn}];
Deltan=Table[deltaFinal[JJ][snOmn[[i]]],{i,nOmn}];

Clear[deltas];
OmnesTemp0[s_]=Exp[s/\[Pi]*Sum[Deltan[[i]]/(snOmn[[i]](snOmn[[i]]-s))*wgnOmn[[i]],{i,1,nOmn}]];
OmnesTemp[s_]=Exp[s/\[Pi]*Sum[(Deltan[[i]]-deltas)/(snOmn[[i]](snOmn[[i]]-s))*wgnOmn[[i]],{i,1,nOmn}]];

OmnesEl[sig_][s_]:=Which[sig==0, OmnesTemp0[s],
sig==1||sig==-1, deltas=deltaFinal[JJ][s]; Which[s<=4mpi^2||s>LamOmnes^2, OmnesTemp0[s], 
4mpi^2<s<=LamOmnes^2,Exp[I*sig*deltaFinal[JJ][s]]*Abs[s0(LamOmnes^2-s)]^\[Alpha][s]*Abs[LamOmnes^2(s-4mpi^2)]^(-\[Alpha][s])*OmnesTemp[s]]];


Omnes[sig_][s_]:=Which[sig==0, OmnesTemp0[s]/(LamOmnes^2-s-I sig 10^(-9))^\[Alpha][LamOmnes^2],
sig==1||sig==-1, deltas=deltaFinal[JJ][s]; Which[s<=4mpi^2||s>LamOmnes^2, OmnesTemp0[s]/(LamOmnes^2-s-I sig 10^(-9))^\[Alpha][LamOmnes^2], 
4mpi^2<s<=LamOmnes^2,Exp[I*sig*deltaFinal[JJ][s]]*Abs[s0]^\[Alpha][s]If[s==LamOmnes^2,1,Abs[LamOmnes^2-s]^(\[Alpha][s]-\[Alpha][LamOmnes^2])]*Abs[LamOmnes^2(s-4mpi^2)]^(-\[Alpha][s])*OmnesTemp[s]]];
