ROOTPWA
CalcAmpl2.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <stdio.h>
4 
5 #include "libconfig.h++"
6 
7 #include "libConfigUtils.hpp"
8 #include "particleDataTable.h"
9 #include "particle.h"
10 
11 #include "TFhh.h"
12 
13 using namespace std;
14 using namespace libconfig;
15 using namespace rpwa;
16 
17 // declaring functions:
18 int JansRelAmpl(int narg, char* carg[]);
19 bool ReadoutTestKeyfile(const char* filename);
20 bool buildDecayTopologyRelAmpl(const Setting* parent, int p_J, int p_P);
21 bool RelAmplDummy(int p_J, int p_P, int d1_J, int d1_P, int d2_J, int d2_P, int L, int S, const Setting* parent);
22 int lookupJ(const char* name);
23 int lookupP(const char* name);
24 
25 // main function:
26 int main(){
27  if (not ReadoutTestKeyfile("../relampl/test.key")) {
28  cout << "ReadoutTestKexfile failed" << endl;
29  }
30 
31  return 0;
32 }
33 
34 int JansRelAmpl(int narg, char* carg[]) {
35 
36  if (not ReadoutTestKeyfile("../relampl/test.key")) {
37  cout << "ReadoutTestKexfile failed" << endl;
38  }
39 
40 
41  if (narg < 4) {
42  cout << endl
43  << "This program requires 3 input strings for the mother and "<<endl
44  << "the 2 decay particles, each of the form Jp," << endl
45  << "where J is the spin of the particle and p = +/- its parity"
46  << endl
47  << endl
48  << "options that may follow the three Jp terms:" << endl
49  << "-H result output also in header file format" << endl
50  << endl;
51 
52  return 0;
53  }
54 
55  int opt=0;
56  for (int oi=4; oi<narg; oi++) {
57  int nchar = sizeof(carg[oi])/sizeof(char);
58  if (nchar>1 && carg[oi][1]=='H') {
59  cout << "H option length:" << nchar << endl;
60  opt=2;
61  }
62  }
63 
64  int jmother;
65  char pmother; int pm;
66  int jdecay1;
67  char pdecay1; int p1;
68  int jdecay2;
69  char pdecay2; int p2;
70 
71  sscanf(carg[1], "%d%c", &jmother, &pmother);
72  cout << "Mother particle: " << jmother << pmother << endl;
73  if (pmother=='+') pm= 1;
74  else pm=-1;
75 
76  sscanf(carg[2], "%1d%c", &jdecay1, &pdecay1);
77  cout << "1. decay particle: " << jdecay1 << pdecay1 << endl;
78  if (pdecay1=='+') p1= 1;
79  else p1=-1;
80 
81  sscanf(carg[3], "%1d%c", &jdecay2, &pdecay2);
82  cout << "2. decay particle: " << jdecay2 << pdecay2 << endl;
83  if (pdecay2=='+') p2= 1;
84  else p2=-1;
85 
86  cout << jmother << "," << pm << ","
87  << jdecay1 << "," << p1 << ","
88  << jdecay2 << "," << p2 << endl;
89 
90  TJSS jss(jmother, pm, jdecay1, p1, jdecay2, p2, opt);
91 
92  return 0;
93 }
94 
95 bool ReadoutTestKeyfile(const char* filename) {
96  const string KeyfileName = filename;
97  Config key;
98 
99  bool debug = false;
100 
101  if(not parseLibConfigFile(KeyfileName, key, debug)) {
102  printWarn << "problems reading keyfile" << endl;
103  return false;
104  }
105 
106  const Setting& rootKey = key.getRoot();
107  const Setting* decayVertKey = findLibConfigGroup(rootKey, "decayVertex");
108  const Setting* XWaveQn = findLibConfigGroup(*decayVertKey, "XQuantumNumbers");
109  const Setting* XDecay = findLibConfigGroup(*decayVertKey, "XDecay");
110 
111  int J_parent = (*XWaveQn)["J"];
112  int P_parent = (*XWaveQn)["P"];
113 
114  particleDataTable& pdt = particleDataTable::instance();
115  pdt.readFile("../amplitude/particleDataTable.txt");
116 
117 
118  if (not buildDecayTopologyRelAmpl(XDecay,J_parent/2,P_parent)) {
119  return false;
120  }
121 
122  return true;
123 }
124 
125 bool buildDecayTopologyRelAmpl(const Setting* parent, int p_J = 0, int p_P = 0) {
126 
127  int d1_J = 0, d1_P = 0, d2_J = 0, d2_P = 0, L = 0, S = 0;
128  // const char* name;
129  // const char* fsParticle1;
130  // const char* fsParticle2;
131  // const char* fsParticle3;
132  const Setting* isobar = findLibConfigList(*parent,"isobars",false);
133 
134  if (not not isobar) {
135  const Setting* isobar0 = findLibConfigGroup(*isobar,0,false);
136  if (not not isobar0) {
137  if (not buildDecayTopologyRelAmpl(isobar0)) return false;
138  }
139 
140  const Setting* isobar1 = findLibConfigGroup(*isobar,1,false);
141  if (not not isobar1){
142  if (not buildDecayTopologyRelAmpl(isobar1)) return false;
143  }
144  }
145 
146  try {
147  const char* name = (*parent)["name"];
148  // cout << "name: " << name << endl;
149  p_J = lookupJ(name);
150  p_P = lookupP(name);
151  } catch (SettingNotFoundException& NotFound) {
152 
153  }
154 
155  L = (*parent)["L"];
156  S = (*parent)["S"];
157  const Setting* fsParticles = findLibConfigList(*parent,"fsParticles",false);
158  if (not not fsParticles) {
159  const Setting* fsParticles0 = findLibConfigGroup(*fsParticles,0,false);
160  if (not not fsParticles0) {
161  const char* fsParticle1 = (*fsParticles0)["name"];
162  // cout << "fsParticle1: " << fsParticle1 << endl;
163  d1_J = lookupJ(fsParticle1);
164  d1_P = lookupP(fsParticle1);
165  }
166 
167  const Setting* fsParticles1 = findLibConfigGroup(*fsParticles,1,false);
168  if (not not fsParticles1) {
169  const char* fsParticle2 = (*fsParticles1)["name"];
170  // cout << "fsParticle2: " << fsParticle2 << endl;
171  d2_J = lookupJ(fsParticle2);
172  d2_P = lookupP(fsParticle2);
173  } else {
174  const char* Particle2 = (*parent)["isobars"][0]["name"];
175  d2_J = lookupJ(Particle2);
176  d2_P = lookupP(Particle2);
177  }
178 
179  // const Setting* fsParticles2 = findLibConfigGroup(*fsParticles,2);
180  // if (not not fsParticles2) {
181  // const char* fsParticle3 = (*fsParticles2)["name"];
182  // cout << "fsParticle3: " << fsParticle3 << endl;
183  // }
184  }
185 
186  // cout << "name: " << name << endl;
187  // cout << "L: " << L << endl;
188  // cout << "S: " << S << endl;
189 
190  if (not RelAmplDummy(p_J,p_P,d1_J,d1_P,d2_J,d2_P,L,S,parent)) return false;
191  return true;
192 }
193 
194 bool RelAmplDummy (int p_J, int p_P, int d1_J, int d1_P, int d2_J, int d2_P, int L, int S, const Setting* parent) {
195  // This dummy doesn't calculate the amplitudes, it just returns constants
196  // This function calcuates the relativistic amplitudes and writes them into the key file
197  // cout << "RelAmplDummy running" << endl;
198  cout << endl;
199  cout << "Parent J: "<< p_J << endl;
200  cout << "Parent P: "<< p_P << endl;
201  cout << "Daughter 1 J: "<< d1_J << endl;
202  cout << "Daughter 1 P: "<< d1_P << endl;
203  cout << "Daughter 2 J: "<< d2_J << endl;
204  cout << "Daughter 2 P: "<< d2_P << endl;
205  cout << "L: " << L << endl;
206  cout << "S: " << S << endl;
207 
208  // int opt = 0;
209  // TJSS jss(p_J, p_P, d1_J, d1_P, d2_J, d2_P, opt);
210 
211  const char* filename = "../relampl/test.key";
212  Config key;
213  parseLibConfigFile(filename, key, false);
214  const string path = (*parent).getPath();
215  // cout << "Path: " << path << endl;
216 
217  Setting& parent0 = key.lookup(path);
218 
219  if (parent0.exists("Relampl")) {
220  parent0.remove("Relampl");
221  }
222 
223  parent0.add("Relampl", Setting::TypeString) = path;
224 
225 
226  key.writeFile(filename);
227 
228  return true;
229 }
230 
231 int lookupJ(const char* name) {
232  // cout << "lookupJDummy running" << endl;
233  // particleDataTable& pdt = particleDataTable::instance();
234  // pdt.readFile("../amplitude/particleDataTable.txt");
235  particleProperties partProp;
236  if (not partProp.fillFromDataTable(name)) {
237  printErr << "canot find particle '" << name << "' in particle data table. aborting." << endl;
238  throw;
239  }
240  return (partProp.J()/2);
241 }
242 
243 int lookupP(const char* name) {
244  // cout << "lookupPDummy running" << endl;
245  // particleDataTable& pdt = particleDataTable::instance();
246  // pdt.readFile("../amplitude/particleDataTable.txt");
247  particleProperties partProp;
248  if (not partProp.fillFromDataTable(name)) {
249  printErr << "canot find particle '" << name << "' in particle data table. aborting." << endl;
250  throw;
251  }
252  return partProp.P();
253 }