User Tools

Site Tools


latex:tikz

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
latex:tikz [2021/05/20 12:25] – [Jets vectors] iwnlatex:tikz [2022/12/02 15:42] (current) – [For-loops: Pseudorapidity 𝜂 and polar angle 𝜃] iwn
Line 4: Line 4:
  
 ''TikZ'' should work out-of-the-box with ''\usepackage{tikz}'', but the syntax is not so straightforward at first. To get started, take a look at these materials: ''TikZ'' should work out-of-the-box with ''\usepackage{tikz}'', but the syntax is not so straightforward at first. To get started, take a look at these materials:
-  * [[https://www.sharelatex.com/blog/2013/08/27/tikz-series-pt1.html|some basic shapes]] +  * [[https://www.sharelatex.com/blog/2013/08/27/tikz-series-pt1.html|Some basic shapes]]. 
-  * [[https://www.tug.org/TUGboat/tb29-1/tb91walczak.pdf|some more basic shapes]] +  * [[https://www.tug.org/TUGboat/tb29-1/tb91walczak.pdf|Some more basic shapes]]. 
-  * [[http://www.texample.net/tikz/examples/|large database of simple and advanced examples]] with a [[http://www.texample.net/tikz/examples/area/physics/|physics section]], including a Feynman diagram and a Standard Model diagram. +  * [[http://www.texample.net/tikz/examples/|TeXample]]: A large database of simple and advanced examples with a [[http://www.texample.net/tikz/examples/area/physics/|physics section]], including a Feynman diagram and a Standard Model diagram. This website will be superseded by [[https://tikz.net|TikZ.net]]. 
-  * [[http://pgf.sourceforge.net/pgf_CVS.pdf|official TikZ & PGF manual]] +  * The examples below and many more are also available on [[https://github.com/IzaakWN/CodeSnippets/tree/master/LaTeX/TikZ|GitHub]] and [[https://ineuteli.web.cern.ch/ineuteli/diagrams/|this gallery page]]
- +  * [[http://pgf.sourceforge.net/pgf_CVS.pdf|Official TikZ & PGF manual]]. 
 +  * [[http://tug.ctan.org/info/visualtikz/VisualTikZ.pdf|Visual Tikz]]: an extensive cheat sheet with TikZ's many features and commands.  
 +  * For Feynman diagrams, please see [[latex:feynman|this page]].
  
  ===== Control regions =====  ===== Control regions =====
Line 388: Line 389:
 </WRAP></WRAP> </WRAP></WRAP>
  
 +Using a for-loop over two variables:
 +<WRAP group><WRAP half column lo 65%>
 +<code latex>
 +\begin{tikzpicture}[scale=3]
 +  
 +  % limits
 +  \def\R{1.2} % radius/length of lines
 +  
 +  % axis labels
 +  \node[scale=1,below left=1] at (0,\R) {$y$}; % y axis
 +  \node[scale=1,below left=1] at (\R,0) {$z$}; % z axis
 +  
 +  % lines
 +  \foreach \t/\e in {90/0,60/0.55,45/0.88,30/1.32,10/2.43,0/+\infty}{ % loop over theta/eta
 +    \pgfkeys{/pgf/number format/precision=2}
 +    \draw[->,black!60!red,thick,line cap=round] % eta lines
 +      (0,0) -- (\t:\R) node[anchor=180+\t,black] {$\eta=\e$}
 +      node[black,pos=0.7,fill=white,scale=0.8,inner sep=1.5pt] {$\theta=\t^\circ$};
 +  }
 +  
 +\end{tikzpicture}
 +</code>
 +</WRAP><WRAP half column 30%>
 +\\
 +{{ latex:tikz:axis2d_pseudorapidity.png ? 2000 }}
 +\\
 +</WRAP></WRAP>
  
 +Using for-loop and calculation + rounding:
 <WRAP group><WRAP half column lo 65%> <WRAP group><WRAP half column lo 65%>
 <code latex> <code latex>
Line 394: Line 423:
      
   % limits   % limits
-  \def\R{1.2}+  \def\R{1.2} % radius/length of lines
      
   % axis labels   % axis labels
-  \node[scale=0.9,below=5pt,left=2pt] at (0,\R) {$y$}; +  \node[scale=1,below left=1] at (0,\R) {$y$}; % y axis 
-  \node[scale=0.9,left=5pt,below=2pt] at (\R,0) {$z$};+  \node[scale=1,below left=1] at (\R,0) {$z$}; % z axis
      
   % lines   % lines
-  \foreach \t/\e in {90/0,60/0.55,45/0.88,30/1.32,10/2.44,0/\infty}{ +  \pgfkeys{/pgf/number format/precision=2} % two decimals 
-    \draw[->,black!60!red,thick] +  \foreach \t in {90,60,45,30,10,0}{ % loop over theta 
-      (0,0) -- ({\R*cos(\t)},{\R*sin(\t)}) +    \ifnum \t = 0 
-      node[anchor=180+\t,black] {$\eta=\e$}; +      \def\e{+\infty} % infinity symbol 
-    \node[fill=white,scale=0.8] at ({0.8*cos(\t)},{0.8*sin(\t)}) {$\theta=\t^\circ$};+    \else 
 +      \pgfmathparse{-ln(tan(\t/2))} % pseudorapidity 
 +      %\pgfmathroundto{\pgfmathresult} % round without traling zeroes 
 +      \pgfmathroundtozerofill{\pgfmathresult} % round with trailing zeroes 
 +      \pgfmathsetmacro\e{\t==90?0:\pgfmathresult} % no trailing zeroes for theta = 0 
 +    \fi 
 +    \draw[->,black!60!red,thick,line cap=round% eta lines 
 +      (0,0) -- (\t:\R) node[anchor=180+\t,black] {$\eta=\e$} 
 +      node[black,pos=0.7,fill=white,scale=0.8,inner sep=1.5pt] {$\theta=\t^\circ$};
   }   }
-    +  
 \end{tikzpicture} \end{tikzpicture}
 </code> </code>
 </WRAP><WRAP half column 30%> </WRAP><WRAP half column 30%>
 \\ \\
-{{ latex:theta-eta.png ? 2000 }}+{{ latex:tikz:axis2d_pseudorapidity.png ? 2000 }}
 \\ \\
 </WRAP></WRAP> </WRAP></WRAP>
Line 799: Line 836:
  ===== 3D axis with spherical coordinates & CMS coordinate system =====  ===== 3D axis with spherical coordinates & CMS coordinate system =====
  
-This piece of code is based on [[https://tex.stackexchange.com/questions/116206/how-to-draw-and-annotate-a-spherical-coordinate-system|this StackExchange thread]]. It is a simple exercise in making axes and labeling angles in 3D. ''\usepackage{tikz-3dplot}'' needs to be included. The full code can be found [[latex:example_spherical_coordinates|here]].+This piece of code is based on [[https://tex.stackexchange.com/questions/116206/how-to-draw-and-annotate-a-spherical-coordinate-system|this StackExchange thread]]. It is a simple exercise in making axes and labeling angles in 3D. ''\usepackage{tikz-3dplot}'' needs to be included. The full code can be found [[https://tikz.net/axis3d/|here]].
  
 <WRAP group><WRAP half column lo 65%> <WRAP group><WRAP half column lo 65%>
Line 837: Line 874:
  
  
-An example of rotating the 3D axes with the CMS conventional coordinate system by using the option ''rotate around x=<//angle//>'' and more ([[latex:example_spherical_coordinates|full code]]):+An example of rotating the 3D axes with the CMS conventional coordinate system by using the option ''rotate around x=<//angle//>'' and more ([[https://tikz.net/axis3d_cms|full code]]):
  
 <WRAP group><WRAP third column 20%> <WRAP group><WRAP third column 20%>
Line 907: Line 944:
 \end{tikzpicture} \end{tikzpicture}
 </code></WRAP> </code></WRAP>
- 
- 
- 
- 
  
  
Line 918: Line 951:
  ===== Tau lepton decay signatures =====  ===== Tau lepton decay signatures =====
  
-Inspiration from [[http://cds.cern.ch/record/1514540|Takahashi & Tomoto (2012) [Fig. 3.14, p. 37]]]. [[latex:tikz:tau_decay_signatures|Full code]].+Inspiration from [[http://cds.cern.ch/record/1514540|Takahashi & Tomoto (2012) [Fig. 3.14, p. 37]]]. [[https://tikz.net/tau_decay/|Full code]].
  
 \\ \\
Line 974: Line 1007:
 \\ \\
 </WRAP></WRAP> </WRAP></WRAP>
 +
 +
 +
  ===== Higgs decay planes =====  ===== Higgs decay planes =====
  
-Decay planes of Higgs decay to measure the Higgs boson's parity. The full code can be found [[latex:tikz:decay_planes|here]]. Adaptation of [[https://arxiv.org/abs/hep-ph/0503172|Djouadi (2008) [Fig. 2.6, 2.11]]].+Decay planes of Higgs decay to measure the Higgs boson's parity. The full code can be found [[https://tikz.net/decay_planes/|here]]. Adaptation of [[https://arxiv.org/abs/hep-ph/0503172|Djouadi (2008) [Fig. 2.6, 2.11]]].
  
 <WRAP group><WRAP third column 20%> <WRAP group><WRAP third column 20%>
Line 991: Line 1027:
  
  
 +
 + ===== Impact parameters =====
 +
 +Examples of defining impact parameters in proton collisions ([[https://tikz.net/impact_parameters/|full code]]).
 +
 +<WRAP group><WRAP column 28%>
 +{{latex:tikz:impact_parameters1.png ? 0x1000 }}
 +</WRAP><WRAP column 26%>
 +{{latex:tikz:impact_parameters2.png ? 0x1000 }}
 +</WRAP><WRAP column 38%>
 +{{latex:tikz:impact_parameters3.png ? 0x1000 }}
 +</WRAP></WRAP>
  
  ===== Timelines and scales =====  ===== Timelines and scales =====
  
-Examples of a simple time or energy scale with labels and arrows ([[latex:tikz:timescales|full code]]).+Examples of a simple time or energy scale with labels and arrows ([[https://tikz.net/timeline/|full code]]).
  
 <WRAP group><WRAP third column 15%> <WRAP group><WRAP third column 15%>
Line 1011: Line 1059:
 \\ \\
 </WRAP></WRAP> </WRAP></WRAP>
- 
  
  
Line 1017: Line 1064:
  ===== Jets cones =====  ===== Jets cones =====
  
-Two examples of cones. Full code can be found [[latex:tikz:jet_cones|here]].+Two examples of cones. Full code can be found [[https://tikz.net/jet_cone/|here]].
  
  
Line 1124: Line 1171:
  
  
- ===== Jets vectors ===== 
  
-One can do some projections of jet and MET vectors to construct variables like MT2 in SUSY searches. The full code can be found [[latex:tikz:jet_vectors|here]].. 
  
-<WRAP group><WRAP half column 50%>+ ===== Top jets === 
 + 
 +The full code can be found [[https://tikz.net/jet_top/|here]]. 
 + 
 +<WRAP group><WRAP column 30%> 
 +{{ latex:tikz:jet_top_resolved.png ? 0x1000 }} 
 +</WRAP><WRAP column 30%> 
 +{{latex:tikz:jet_top_merged_partial.png ? 0x1000 }} 
 +</WRAP><WRAP column 30%> 
 +\\ \\ \\ \\ \\ 
 +{{latex:tikz:jet_top_merged_full.png ? 0x1000 }} 
 +</WRAP></WRAP> 
 + 
 +<code latex> 
 +\newcommand\jetcone[5][blue]{{ 
 +  \pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}{\pgfpointanchor{#3}{center}} 
 +  \edef\ang{#4/2} 
 +  \edef\e{#5} 
 +  \edef\vang{\pgfmathresult} % angle of vector OV 
 +  \tikzmath{ 
 +    coordinate \C; 
 +    \C = (#2)-(#3); 
 +    \x = veclen(\Cx,\Cy)*\e*sin(\ang)^2; % x coordinate P 
 +    \y = tan(\ang)*(veclen(\Cx,\Cy)-\x); % y coordinate P 
 +    \a = veclen(\Cx,\Cy)*sqrt(\e)*sin(\ang); % vertical radius 
 +    \b = veclen(\Cx,\Cy)*tan(\ang)*sqrt(1-\e*sin(\ang)^2); % horizontal radius 
 +    \angb = acos(sqrt(\e)*sin(\ang)); % angle of P in ellipse 
 +  } 
 +  \coordinate (tmpL) at ($(#3)-(\vang:\x pt)+(\vang+90:\y pt)$); % tangency 
 +  \draw[thin,#1!40!black,fill=#1!50!black!80,rotate=\vang] 
 +    (#3) ellipse({\a pt} and {\b pt}); 
 +  \draw[thin,#1!40!black,fill=#1!80!black!40,rotate=\vang] 
 +    (tmpL) arc(180-\angb:180+\angb:{\a pt} and {\b pt}) 
 +    -- ($(#2)+(\vang:0.018)$) -- cycle; 
 +}} 
 + 
 +\begin{tikzpicture} 
 +  \def\R{2.5} 
 +  \coordinate (O) at (0,0); 
 +  \coordinate (BJ) at ( 65:1.1*\R); % b jet 1 
 +  \coordinate (J1) at ( 15:1.0*\R); % q jet 1 
 +  \coordinate (J2) at (-20:1.0*\R); % q jet 2 
 +  \jetcone[green!80!black]{O}{BJ}{14}{0.10} 
 +  \jetcone{O}{J1}{16}{0.08} 
 +  \jetcone{O}{J2}{16}{0.10} 
 +  \node[green!50!black] at (65:1.24*\R) {b}; 
 +  \node[blue!80!black,right] at (-5:1.00*\R) {$\mathrm{W} \to qq$}; 
 +\end{tikzpicture} 
 +</code> 
 + 
 + 
 + ===== Jet vectors ===== 
 + 
 +One can do some projections of jet and MET vectors to construct variables like MT2 in SUSY searches. The full code can be found [[https://tikz.net/jet_vectors/|here]]. 
 + 
 +<WRAP group><WRAP half column 54%>
 {{ latex:tikz:jet_vectors.png ? 0x1000 }} {{ latex:tikz:jet_vectors.png ? 0x1000 }}
-</WRAP><WRAP half column 45%> +</WRAP><WRAP half column 42%> 
-{{latex:tikz:jet_vectors_3D.png ? 0x250 }}+{{latex:tikz:jet_vectors_3D.png ? 0x1000 }}
 </WRAP></WRAP> </WRAP></WRAP>
  
Line 1184: Line 1284:
      
 \end{tikzpicture} \end{tikzpicture}
 +</code>
 +
 +
 + ===== Tangent to a circle or ellipse =====
 +
 +Some different methods of finding the tangent to a circle or ellipse in TikZ.
 +Using these methods a nice cone can be made.
 +The full code can be found [[https://tikz.net/circle_tangent/|here]].
 +
 +
 +<WRAP group><WRAP half column 45%>
 +{{ latex:tikz:circle_tangent.png ? 0x250 }}
 +</WRAP><WRAP half column 45%>
 +{{latex:tikz:circle_tangent_ellipse.png ? 0x200 }}
 +</WRAP></WRAP>
 +
 +<WRAP group><WRAP half column 45%> \\ \\
 +{{ latex:tikz:circle_tangent_cone1.png ? 0x200 }}
 +</WRAP><WRAP half column 45%>
 +{{latex:tikz:circle_tangent_cone2.png ? 0x250 }}
 +</WRAP></WRAP> \\
 +
 +<code latex>
 +% TANGENT to CIRCLE - known: r, q
 +\begin{tikzpicture}
 +  \def\r{1.5} % radius
 +  \def\q{4} % distance center-external point q = |OQ|
 +  \def\x{{\r^2/\q}} % Q x coordinate
 +  \def\y{{\r*sqrt(1-(\r/\q)^2}} % Q y coordinate
 +  \coordinate (O) at (0,0); % circle center O
 +  \coordinate (Q) at (\q,0); % external point Q
 +  \coordinate (P) at (\x,\y); % point of tangency, P
 +  \draw[->] (0,-1.3*\r) -- (0,1.5*\r);
 +  \draw[->] (-1.3*\r,0) -- (\q+0.4*\r,0);
 +  \draw[dashed] (\x,0) |- (0,\y);
 +  \draw[myblue,thick] (O) circle(\r);
 +  \draw[mygreen,thick] ($(Q)!-0.2!(P)$) -- ($(Q)!1.3!(P)$);
 +  \draw[mygreen,thick] ($(O)!-0.3!(P)$) -- ($(O)!1.4!(P)$);
 +  \rightAngle{Q}{P}{O}{0.40}
 +  \fill[myred] (O) circle(0.05) node[below right] {O};
 +  \fill[myred] (Q) circle(0.05) node[below left] {Q};
 +  \fill[myred] (P) circle(0.05) node[above=3,right=4] {P};
 +\end{tikzpicture}
 +
 +% TANGENT to ELLIPSE - known: a, b, q
 +\begin{tikzpicture}
 +  \def\a{1.5} % horizontal radius
 +  \def\b{1.0} % vertical radius
 +  \def\q{4} % distance center-external point q = |OQ|
 +  \def\x{{\a^2/\q}} % x coordinate P
 +  \def\y{{\b*sqrt(1-(\a/\q)^2}} % y coordinate P
 +  \coordinate (O) at (0,0); % circle center O
 +  \coordinate (Q) at (\q,0); % external point Q
 +  \coordinate (P) at (\x,\y); % point of tangency, P
 +  \draw[->] (0,-\b-0.3*\a) -- (0,\b+0.4*\a);
 +  \draw[->] (-1.3*\a,0) -- (\q+0.4*\a,0);
 +  \draw[dashed] (\x,0) |- (0,\y);
 +  \draw[myblue,thick] (O) ellipse({\a} and {\b});
 +  \draw[mygreen,thick] ($(Q)!-0.2!(P)$) -- ($(Q)!1.3!(P)$);
 +  \draw[mygreen,thick] ($(O)!-0.3!(P)$) -- ($(O)!1.4!(P)$);
 +  \fill[myred] (O) circle(0.05) node[below right] {O};
 +  \fill[myred] (Q) circle(0.05) node[below left] {Q};
 +  \fill[myred] (P) circle(0.05) node[above=3,right=4] {P};
 +\end{tikzpicture}
 +
 +</code>
latex/tikz.1621506308.txt.gz · Last modified: 2021/05/20 12:25 by iwn