ROOTPWA
key2tex.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 
23 // creates latex output from wavefile name
24 // reades from stdin
25 
26 
27 #include <iostream>
28 #include <map>
29 
30 #include "TString.h"
31 #include "TObjString.h"
32 #include "TObjArray.h"
33 
34 
35 using namespace std;
36 
37 
38 int main(int argc, char** argv)
39 {
40  const unsigned int maxNmbWavesPerPage = 1;
41 
42  // setup isobar dictionary key->tex
43  map<TString, TString> isobars;
44  isobars["pi+" ] = "\\pi^+";
45  isobars["pi-" ] = "\\pi^-";
46  isobars["pi+-" ] = "\\pi^\\pm";
47  isobars["pi-+" ] = "\\pi^\\mp";
48  isobars["sigma" ] = "\\sigma";
49  isobars["rho770" ] = "\\rho(770)";
50  isobars["a11269" ] = "a_1(1269)";
51  isobars["a21320" ] = "a_2(1320)";
52  isobars["rho1450" ] = "\\rho(1450)";
53  isobars["rho1700" ] = "\\rho(1700)";
54  isobars["pi1300" ] = "\\pi(1300)";
55  isobars["pi1800" ] = "\\pi(1800)";
56  isobars["pi21670" ] = "\\pi_2(1670)";
57  isobars["f01370" ] = "f_0(1370)";
58  isobars["f01500" ] = "f_0(1500)";
59  isobars["f01700" ] = "f_0(1700)";
60  isobars["f11285" ] = "f_1(1285)";
61  isobars["f11420" ] = "f_1(1420)";
62  isobars["b11235" ] = "b_1(1235)";
63  isobars["b11800" ] = "b_1(1800)";
64  isobars["b11500" ] = "b_1(1500)";
65  isobars["f21270" ] = "f_2(1270)";
66  isobars["f21950" ] = "f_2(1950)";
67  isobars["f21565" ] = "f_2(1565)";
68  isobars["f21270" ] = "f_2(1270)";
69  isobars["f22010" ] = "f_2(2010)";
70  isobars["f11420" ] = "f_1(1420)";
71  isobars["eta1440" ] = "\\eta(1420)";
72  isobars["eta21645"] = "\\eta_2(1645)";
73  isobars["eta11600"] = "\\eta_1(1600)";
74  isobars["rho31690"] = "\\rho_3(1690)";
75  isobars["rho1600"] = "\\rho(1600)";
76  isobars["a21320" ] = "a_2(1320)";
77 
78  // print latex header
79  cout << "\\documentclass[10pt,a4paper]{article}" << endl
80  << "\\usepackage{amsmath,amsthm,amssymb}" << endl
81  << "\\begin{document}" << endl
82  << "\\(";
83  // "\\begin{aligned}" << endl;
84  string line;
85  int countWave = 0;
86  while (!(cin >> line).eof()) { // begin event loop
87 
88  TString l(line);
89  if (l.IsAlnum()) {
90  cout << l;
91  continue;
92  }
93 
94  if (countWave > 0) {
95  //cout << " \\\\" << endl;
96  // pagebreak
97  if (countWave % maxNmbWavesPerPage == 0)
98  cout << "\\) \\\\" << endl
99  //<< "\\end{align*}" << endl
100  << "\\pagebreak" << endl
101  << "\\(";
102  //<< "\\begin{aligned}" << endl;
103  }
104  ++countWave;
105 
106  cerr << countWave << ": " << line << endl;
107  // remove file extension
108  l.Remove(l.Length() - 4);
109  // extract X quantum numbers
110  const TString head = l(0, 7);
111  const TString I = head(0, 1);
112  const TString G = head(1, 1);
113  const TString J = head(2, 1);
114  const TString P = head(3, 1);
115  const TString C = head(4, 1);
116  const TString M = head(5, 1);
117  const TString refl = head(6, 1);
118  l.Remove(0, 7);
119  // print X quantum numbers
120  cout << I << "^" << G << "("<< J << "^{" << P << C << "}" << M << "^" << refl << ")\\, ";
121 
122  // tokenize input
123  TObjArray* tokens = l.Tokenize("_=");
124  int mode = 0;
125  for (int i = 0; i < tokens->GetEntries(); ++i) {
126  const TString token = ((TObjString*)tokens->At(i))->GetString();
127  cerr << " " << mode << ": '" << token << "'" << endl;
128  if (mode == 0) { // isobar mode
129  if (isobars.find(token) != isobars.end())
130  cout << isobars[token];
131  else
132  cout << token;
133  cout << " ";
134  // check which mode to switch to depending whether we get _ or =
135  l.Remove(0, token.Length());
136  if (l(0, 1) == "_")
137  mode = 1;
138  else
139  mode = 2;
140  } else if (mode == 1) { // ls mode
141  if (token.Length() == 1) // only l
142  cout << "(" << token << ") ";
143  else
144  cout << "{" << token(0, 1) << " \\choose "
145  << token(1, 1) << "}";
146  l.Remove(0, token.Length());
147  mode = 0;
148  } else if (mode == 2) {
149  cout << "~\\rightarrow~";
150  if (isobars.find(token) != isobars.end())
151  cout << isobars[token];
152  else
153  cout << token;
154  cout << " ";
155  l.Remove(0, token.Length());
156  if (l(0, 1) == "_" )
157  mode = 1;
158  else
159  mode = 2;
160  }
161  l.Remove(0, 1); // remove delimiter
162  }
163  //cout << "\\,";
164  }
165  cout << "\\)" << endl
166  //<< "\\end{align*}" << endl
167  << "\\end{document}" << endl;
168 };