% !TEX program = pdflatexmk
% !TEX parameter = -shell-escape
% Author: Izaak Neutelings (May 25)
% Instructions: To compile via command line, run the following twice
%   pdflatex -shell-escape extract/ttcc_jet-003.tex
\documentclass[11pt,border=4pt]{standalone}
\usepackage{feynmp-auto}

% HELP MACRO to create convert numbers to letters
% This is needed because MetaPost cannot handle variable names with numbers
\makeatletter
  \newcommand{\numberToRoman}[1]{\@Roman{#1}}
\makeatother

% JET CONE MACRO
\def\ijc{0} % start \ijc counter from 0
\def\fmfcone[a=#1,e=#2,s=#3]#4#5{
  % Create a 3D-like jet cone between two given vertices
  % The computations for tangents to an ellipse are based on
  %   https://tikz.net/circle_tangent/
  % Arguments:
  %   a = half of cone's opening angle (degrees), e.g. 20
  %   e = excentricity as ratio rx/ry, e.g. 0.15
  %   s = length to shorten or elongate cone
  %   #4, #5 = vertices defining the direction
  \fmffreeze % needed to access vertices in MetaPost
  \edef\ijc{\number\numexpr\ijc + 1\relax} % increment \ijc counter
  \edef\jcpath{conebase_\numberToRoman{\ijc}} % add space
  \message{^^J^^J  path name=\jcpath\ for \ijc=\ijc}
  \edef\tmpcmd{% expand macros inside \fmfcmd before executing it
    \noexpand\fmfcmd{ % draw behind Feynman diagram
      % settings
      pair A, B, C, O;
      numeric ang; ang := #1; % half of cone's opening angle
      numeric e; e := #2; % excentricity as ratio rx/ry
      message "  fmfcone \jcpath: e=" & decimal(e) & ", ang=" & decimal(ang);
      % vector
      A := vloc(__#4); % vertex origin
      O := vloc(__#5); % center of ellipse
      numeric len_jc; len_jc := length(O-A); % distance between A and B
      numeric ang_jc; ang_jc := angle(O-A);
      O := O + (#3,0) rotated ang_jc; % add shift
      message "  fmfcone \jcpath: len_jc=" & decimal(len_jc) & ", ang_jc=" & decimal(ang_jc);
      % tangents to ellipse
      x := len_jc*e*sind(ang)*sind(ang); % x coordinate P
      y := (len_jc-x)*sind(ang)/cosd(ang); % y coordinate P
      B := O + (-x, y) rotated ang_jc; % tangent point 1
      C := O + (-x,-y) rotated ang_jc; % tangent point 2
      message "  fmfcone \jcpath: x=" & decimal(x) & ", y=" & decimal(y);
      % triangle
      path cone; cone := A -- B -- C -- cycle; 
      fill cone withcolor coljetfill;
      draw cone withcolor coljetline;
      % ellipse base
      numeric rx, ry;
      rx := len_jc*sqrt(e)*sind(ang); % horizontal radius
      ry := len_jc*sind(ang)/cosd(ang)*sqrt(1-e*sind(ang)*sind(ang)); % vertical radius
      message "  fmfcone \jcpath: rx=" & decimal(rx) & ", ry=" & decimal(ry);
      path \jcpath;
      \jcpath := fullcircle xscaled (2*rx) yscaled (2*ry) rotated ang_jc shifted O;
      fill \jcpath\ withcolor coljetbase;
      draw \jcpath\ withcolor coljetline;
      % custom line style to draw on top
      style_def jet\jcpath\ expr p =
        draw subpath (2,6) of \jcpath\ withcolor coljetline;
      enddef;
    } % end \fmfcmd
    \noexpand\fmf{jet\jcpath}{#4,#4_#5_help_,#5} % draw are in front of Feynman diagram
  }\tmpcmd % execute above lines now that all macros are expanded
}

\begin{document}
\begin{fmffile}{feyngraph}
  \fmfframe(5,22)(8,26){ % padding (L,T)(R,B)
  \begin{fmfgraph*}(120,80) % dimensions (WH)
    % line style
    \fmfset{dash_len}{10} % dashes length
    \fmfset{wiggly_len}{12} % boson wavelength
    \fmfset{wiggly_slope}{65} % boson slope of waves
    % line colors
    \fmfcmd{
      color coljetline; coljetline := (.91,.54,.22); % jet line color
      color coljetfill; coljetfill := (1.0,.85,.75); % jet fill color
      color coljetbase; coljetbase := (1.0,.70,.50); % jet base fill color
    }
    % external vertices
    \fmfstraight
    \fmfleft{i2,i1}
    \fmfright{o3,o2,o1}
    \fmfshift{6 left}{o1}
    \fmfshift{9 down}{o2,o3}
    \fmfforce{(.38w,.8h)}{v1} % exact placement
    \fmfforce{(.38w,.2h)}{v2} % exact placement
    % main
    \fmf{quark}{i1,v1}
    \fmf{gluon}{i2,v2}
    \fmf{fermion}{v1,o1}
    \fmf{gluon,tension=0.8,label=$g$,label.side=left,label.dist=8}{v1,v2} % t-channel
    \fmfdot{v1,v2,vtt}
    % ttbar
    \fmf{gluon,t=1.4}{v2,vtt}
    \fmf{fermion}{o3,vtt,o2}
    % initial-state radiation
    %\fmfcmd{coljetline := red;} % override default color
    \fmfcone[a=14,e=0.12,s=-2]{v1}{o1} % jet cone
    % labels
    \fmfv{l.a=155,l.d=6,l=c}{i1}
    \fmfv{l.a=-155,l.d=6,l=$g$}{i2}
    \fmfv{l.a=12,l.d=8,l=c}{o1}
    \fmfv{l.a=25,l.d=6,l=t}{o2}
    \fmfv{l.a=-25,l.d=6,l=$\overline{\mathrm{t}}$}{o3}
  \end{fmfgraph*}
  } % close \fmfframe
\end{fmffile}
\end{document}