% !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-001.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(-7,17)(-4,18){ % padding (L,T)(R,B)
  \begin{fmfgraph*}(150,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
    \fmfleft{i2,i1}
    \fmfright{o2,o1}
    % main
    \fmf{gluon}{v1,i1}
    \fmf{gluon,t=2}{v1,vr,i2}
    \fmf{fermion}{o2,v2,o1}
    \fmf{gluon,tension=0.8,label=$g$,label.side=left,label.dist=8}{v1,v2} % s-channel
    \fmfdot{v1,v2,vr,vcc}
    % initial-state radiation
    \fmffreeze
    \fmfforce{vloc(__vr)+(.2w,-.08h)}{vcc} % exact placement
    \fmfforce{vloc(__vcc)+(.28w,.03h)}{c1} % exact placement
    \fmfforce{vloc(__vcc)+(.26w,-.21h)}{c2} % exact placement
    \fmf{gluon}{vr,vcc} % gluon radiation
    \fmf{fermion,l.d=6.7,l.s=left,label=c}{vcc,c1} % charm 1
    \fmf{fermion,l.d=6,l.s=left,label=$\overline{\mathrm{c}}$}{c2,vcc} % charm 2
    %\fmfcmd{coljetline := red;} % override default color
    \fmfcone[a=10,e=0.12,s=0]{vcc}{c1} % jet cone
    \fmfcone[a=10,e=0.12,s=0]{vcc}{c2} % jet cone
    % labels
    \fmfv{l.a=155,l.d=6,l=$g$}{i1}
    \fmfv{l.a=-155,l.d=6,l=$g$}{i2}
    \fmfv{l.a=25,l.d=6,l=t}{o1}
    \fmfv{l.a=-25,l.d=6,l=$\overline{\mathrm{t}}$}{o2}
  \end{fmfgraph*}
  } % close \fmfframe
\end{fmffile}
\end{document}