]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TEvtGen/EvtGenBase/EvtMultiChannelParser.cpp
Fix for definitions for CINT
[u/mrichter/AliRoot.git] / TEvtGen / EvtGenBase / EvtMultiChannelParser.cpp
CommitLineData
da0e9ce3 1//-----------------------------------------------------------------------
2// File and Version Information:
0ca57c2f 3// $Id: EvtMultiChannelParser.cpp,v 1.4 2009-03-16 15:46:01 robbep Exp $
da0e9ce3 4//
5// Environment:
6// This software is part of the EvtGen package developed jointly
7// for the BaBar and CLEO collaborations. If you use all or part
8// of it, please give an appropriate acknowledgement.
9//
10// Copyright Information:
11// Copyright (C) 1998 Caltech, UCSB
12//
13// Module creator:
14// Alexei Dvoretskii, Caltech, 2001-2002.
15//-----------------------------------------------------------------------
16#include "EvtGenBase/EvtPatches.hh"
17
18#include <assert.h>
19#include <stdlib.h>
20#include <stdio.h>
21#include <math.h>
22#include <string>
23#include <vector>
24#include "EvtGenBase/EvtParser.hh"
25#include "EvtGenBase/EvtMultiChannelParser.hh"
26#include "EvtGenBase/EvtDecayMode.hh"
27#include "EvtGenBase/EvtPDL.hh"
28
29using std::string;
30using std::vector;
31
32EvtDecayMode EvtMultiChannelParser::getDecayMode(const char* file)
33{
34 // Open file, read tokens
35
36 EvtParser parser;
37 parser.read(file);
38
39 // Seek Decay
40
41 int i = 0;
42 int N = parser.getNToken();
43 while(i<N) {
44
45 std::string tok = parser.getToken(i++);
46 if(tok == std::string("Decay")) break;
47 }
48
49 // Get mother
50
51 string mother = string(parser.getToken(i++).c_str());
52 std::string bf = parser.getToken(i++);
53
54 vector<string> dauV;
55 // Get daughters
56
57 while(1) {
58
59 std::string d = parser.getToken(i++);
60
61 if(EvtPDL::getStdHep(EvtPDL::getId(d.c_str())) == 0) break;
62
63 dauV.push_back(string(d.c_str()));
64 }
65
66 EvtDecayMode mode(mother,dauV);
67 printf("Decay File defines mode %s\n",mode.mode().c_str());
68
69 return mode;
70}
71
72
73
74void EvtMultiChannelParser::parse(const char* file, const char* model)
75{
76 // Open file, read tokens
77
78 EvtParser parser;
79 parser.read(file);
80
81
82 // Get parameters (tokens between the model name and ;)
83
84 int i = 0;
85 int N = parser.getNToken();
86
87 // Seek the model name
88
89 while(i<N) {
90
91 std::string tok = parser.getToken(i++);
92 if(tok == std::string(model)) break;
93 }
94 if(i == N) {
95
96 printf("No model %s found in decay file %s",model,file);
97 exit(0);
98 }
99
100
101 // Add all tokens up to a semicolon to vector
102
103 std::vector<std::string> v;
104 while(i<N) {
105
106 std::string tok = parser.getToken(i++);
107 if(tok == std::string(";")) break;
108 else v.push_back(tok);
109 }
110
111 if(i == N) {
112
113 printf("No terminating ; found in decay file %s",file);
114 assert(0);
115 }
116
117 parse(v);
118}
119
120
121void EvtMultiChannelParser::parse(const std::vector<std::string>& v)
122{
123 // place holder for strtod
124 char** tc = 0;
125
126
127 // Get PDF maximum or number of points to
128 // use in the scan.
129
130 if(v[0] == std::string("MAXPDF")) {
131
132 _pdfMax = strtod(v[1].c_str(),tc);
133 if(_pdfMax <= 0) { printf("Bad pdfMax=%f\n",_pdfMax); assert(0); }
134 }
135 else
136 if(v[0] == std::string("SCANPDF")) {
137
138 _nScan = atoi(v[1].c_str());
139 }
140 else {
141
142 printf("Error parsing decay file\n");
143 assert(0);
144 }
145
146
147 // Now parse the rest of file for amplitude specifications.
148
149 bool conjugate = false;
150 size_t i = 2;
151 assert(isKeyword(v[2]));
152
153 while(i < v.size()) {
154
155 size_t i0 = i;
156
157 // Switch to conjugate amplitudes after keyword
158 if(v[i] == std::string("CONJUGATE")) {
159
160 assert(conjugate == false);
161 conjugate = true;
0ca57c2f 162 i++;
da0e9ce3 163 _dm = strtod(v[i++].c_str(),tc);
164 _mixAmpli = strtod(v[i++].c_str(),tc);
165 _mixPhase = strtod(v[i++].c_str(),tc);
166 }
167
168 if (i >= v.size()) break;
169 std::vector<std::string> params;
170 EvtComplex c;
171 int format;
172
173 if(!conjugate && v[i] == std::string("AMPLITUDE")) {
174
175 while(!isKeyword(v[++i])) params.push_back(v[i]);
176 _amp.push_back(params);
177
178 parseComplexCoef(i,v,c,format);
179 _ampCoef.push_back(c);
180 _coefFormat.push_back(format);
181 continue;
182 }
183 else
184 if(conjugate && v[i] == std::string("AMPLITUDE")) {
185
186 while(!isKeyword(v[++i])) params.push_back(v[i]);
187 _ampConj.push_back(params);
188 parseComplexCoef(i,v,c,format);
189 _ampConjCoef.push_back(c);
190 _coefConjFormat.push_back(format);
191 continue;
192 }
193 else {
194
195 printf("Expect keyword, found parameter %s\n",v[i].c_str());
196 assert(0);
197 }
198
199
0ca57c2f 200 assert(i > i0); _unused( i0 );
da0e9ce3 201 }
202
203 printf("PARSING SUCCESSFUL\n");
204 printf("%d amplitude terms\n",(int)_amp.size());
205 printf("%d conj amplitude terms\n",(int)_ampConj.size());
206}
207
208
209
210void EvtMultiChannelParser::parseComplexCoef(size_t& i, const std::vector<std::string>& v,
211 EvtComplex& c, int& format)
212{
213 // place holder for strtod
214 char** tc = 0;
215
0ca57c2f 216 std::string coefString = v[i++];
217 assert(coefString == std::string("COEFFICIENT"));
da0e9ce3 218
219 if(v[i] == std::string("POLAR_DEG")) {
220
221 double mag = strtod(v[i+1].c_str(),tc);
222 double phaseRad = strtod(v[i+2].c_str(),tc)*EvtConst::pi/180.0;
223 i += 3;
224 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
225 format = POLAR_DEG;
226 }
227 else if(v[i] == std::string("POLAR_RAD")) {
228
229 double mag = strtod(v[i+1].c_str(),tc);
230 double phaseRad = strtod(v[i+2].c_str(),tc);
231 i += 3;
232 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
233 format = POLAR_RAD;
234 }
235 else if(v[i] == std::string("CARTESIAN")) {
236
237 double re = strtod(v[i+1].c_str(),tc);
238 double im = strtod(v[i+2].c_str(),tc);
239 i += 3;
240 c = EvtComplex(re,im);
241 format = CARTESIAN;
242 }
243 else {
244
245 printf("Invalid format %s for complex coefficient\n",v[i].c_str());
246 exit(0);
247 }
248}
249
250
251double EvtMultiChannelParser::parseRealCoef(int& i, const std::vector<std::string>& v)
252{
253 // place holder for strtod
254 char** tc = 0;
255 double value = 0;
256
257 if(v[i] == std::string("COEFFICIENT")) {
258
259 value = strtod(v[i+1].c_str(),tc);
260 }
261 else assert(0);
262
263 i += 2;
264
265 assert(value > 0.);
266 return value;
267}
268
269
270bool EvtMultiChannelParser::isKeyword(const std::string& s)
271{
272 if(s == std::string("AMPLITUDE")) return true;
273 if(s == std::string("CONJUGATE")) return true;
274 if(s == std::string("COEFFICIENT")) return true;
275 return false;
276}
277
278
279