ROOTPWA
generateWaveSet.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright 2010
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 // File and Version Information:
23 // $Rev:: $: revision of last commit
24 // $Author:: $: author of last commit
25 // $Date:: $: date of last commit
26 //
27 // Description:
28 // generates a set of all waves allowed by convervation laws and
29 // constrained by user specified parameters
30 //
31 //
32 // Author List:
33 // Boris Grube TUM (original author)
34 //
35 //
36 //-------------------------------------------------------------------------
37 
38 
39 #include <unistd.h>
40 #include <fstream>
41 
42 #include "particleDataTable.h"
43 #include "waveSetGenerator.h"
44 #include "waveDescription.h"
45 
46 
47 using namespace std;
48 using namespace rpwa;
49 
50 
51 void
52 usage(const string& progName,
53  const int errCode = 0)
54 {
55  cerr << "generates set of all allowed waves given by template .key file" << endl
56  << endl
57  << "usage:" << endl
58  << progName
59  << " -k template key file -o output directory [-p PDG file -n -v -h]" << endl
60  << " where:" << endl
61  << " -k file path to template key file" << endl
62  << " -p file path to particle data table file (default: ./particleDataTable.txt)" << endl
63  << " -d file path to decay config file (default: decay info will not be used)" << endl
64  << " isobars without defined decays will be allowed to decay to all possibilities" << endl
65  << " -f force decay check (only works with -d option); isobars without defined decay modes will be ignored" << endl
66  << " -o dir path to directory where key files will be written (default: '.')" << endl
67  << " -t file path to waveset LaTeX output file" << endl
68  << " -n use new key file name convention (default: false)" << endl
69  << " -v verbose; print debug output (default: false)" << endl
70  << " -h print help" << endl
71  << endl;
72  exit(errCode);
73 }
74 
75 
76 int
77 main(int argc,
78  char** argv)
79 {
80  printCompilerInfo();
81  printLibraryInfo ();
82  printSvnVersion ();
83  cout << endl;
84 
85  // parse command line options
86  const string progName = argv[0];
87  unsigned int entriesPerPage = 20;
88  string keyFileName = "";
89  string pdgFileName = "./particleDataTable.txt";
90  string decayFileName = "";
91  string texFileName = "waveset.tex";
92  string outDirName = ".";
93  bool newKeyFileNameConvention = false;
94  bool debug = false;
95  bool forceDecayCheck = false;
96  extern char* optarg;
97  int c;
98  while ((c = getopt(argc, argv, "k:p:d:o:t:fnvh")) != -1)
99  switch (c) {
100  case 'k':
101  keyFileName = optarg;
102  break;
103  case 'p':
104  pdgFileName = optarg;
105  break;
106  case 'd':
107  decayFileName = optarg;
108  break;
109  case 't':
110  texFileName = optarg;
111  break;
112  case 'o':
113  outDirName = optarg;
114  break;
115  case 'n':
116  newKeyFileNameConvention = true;
117  break;
118  case 'v':
119  debug = true;
120  break;
121  case 'f':
122  forceDecayCheck = true;
123  break;
124  case 'h':
125  default:
126  usage(progName);
127  }
128 
129  // initialize particle data table
130  particleDataTable::readFile(pdgFileName);
131  bool useDecays = false;
132  if (decayFileName != "") {
133  if (particleDataTable::readDecayModeFile(decayFileName))
134  useDecays = true;
135  else {
136  printErr << "could not read particle decay modes from file '" << decayFileName << "'. "
137  << "aborting." << endl;
138  exit(1);
139  }
140  }
141  if (debug)
142  printDebug << "particle data table:" << endl << particleDataTable::instance();
143  particleDataTable::setDebug(debug);
144 
145  // print latex header
146  ofstream wavelistTeX;
147  bool doTeX = false;
148  if (texFileName != "") {
149  doTeX = true;
150  wavelistTeX.open(texFileName.c_str());
151  wavelistTeX << "\\documentclass[10pt,a4paper]{article}" << endl
152  << "\\usepackage{amsmath,amsthm,amssymb}" << endl
153  << "\\def\\dst{\\displaystyle}" << endl
154  << "\\def\\vsp{\\hbox{\\vrule height12.5pt depth3.5pt width0pt}}" << endl
155  << "\\def\\ells#1#2{\\Big[\\hskip-5pt\\vsp\\begin{array}{c}\\dst#1\\\\[-4pt]\\dst#2\\end{array}\\vsp\\hskip-5pt\\Big]}" << endl
156  << "\\begin{document}" << endl
157  << "\\begin{align*} \n \\begin{aligned}" << endl;
158  }
159 
160 
161  printInfo << "generating wave set from template key file '" << keyFileName << "'" << endl;
162  waveSetGenerator waveSetGen;
163  waveSetGenerator::setDebug(debug);
164  if (not waveSetGen.setWaveSetParameters(keyFileName)) {
165  printErr << "could not initialize wave set generator. aborting." << endl;
166  exit(1);
167  }
168 
169  if (useDecays)
170  waveSetGen.setForceDecayCheck(forceDecayCheck);
171  printInfo << waveSetGen;
172  waveSetGen.generateWaveSet();
173 
174  printInfo << "checking generated waves..." << endl;
175  vector<isobarDecayTopology>& decayTopos = waveSetGen.waveSet();
176  unsigned int nmbInconsistentDecays = 0;
177  for (unsigned int i = 0; i < decayTopos.size(); ++i) {
178  bool isConsistent = decayTopos[i].checkTopology() and decayTopos[i].checkConsistency();
179  cout << " " << setw(4) << i << ": "
180  << waveDescription::waveNameFromTopology(decayTopos[i], newKeyFileNameConvention) << " ... ";
181  if (isConsistent) {
182  cout << "okay" << endl;
183  if (doTeX) {
184  wavelistTeX << waveDescription::waveLaTeXFromTopology(decayTopos[i]) << "\\\\" << endl;
185  if ((i + 1) % entriesPerPage ==0 ) {
186  wavelistTeX << "\\end{aligned} \n \\end{align*}"
187  << "\\pagebreak\n"
188  << "\\begin{align*} \n \\begin{aligned}" << endl;
189  }
190  }
191  } else {
192  cout << "problems!" << endl;
193  ++nmbInconsistentDecays;
194  }
195  }
196 
197  printInfo << "writing .key files for generated waves to directory '" << outDirName << "'" << endl;
198  waveSetGen.writeKeyFiles(outDirName, newKeyFileNameConvention);
199 
200  printInfo << ((nmbInconsistentDecays == 0) ? "successfully " : "")
201  << "generated " << decayTopos.size() << " waves";
202  if (nmbInconsistentDecays != 0)
203  cout << ". " << nmbInconsistentDecays << " waves have problems.";
204  cout<< endl;
205 
206  if (doTeX) {
207  wavelistTeX << "\\end{aligned} \n \\end{align*}" << endl;
208  wavelistTeX << "\\end{document}" << endl;
209  wavelistTeX.close();
210  }
211  return 0;
212 }