BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesEvtGen-00-04-08/src/EvtGen/EvtGenBase/EvtMultiChannelParser.cc
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// File and Version Information:
3// $Id: EvtMultiChannelParser.cc,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
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
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());
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 int i = 2;
151 assert(isKeyword(v[2]));
152
153 while(i < v.size()) {
154
155 int 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;
162 assert(!isKeyword(v[++i]));
163 _dm = strtod(v[i].c_str(),tc);
164 i++;
165 }
166
167 std::vector<std::string> params;
168 EvtComplex c;
169 int format;
170
171 if(!conjugate && v[i] == std::string("AMPLITUDE")) {
172
173 while(!isKeyword(v[++i])) params.push_back(v[i]);
174 _amp.push_back(params);
175
176 parseComplexCoef(i,v,c,format);
177 _ampCoef.push_back(c);
178 _coefFormat.push_back(format);
179 continue;
180 }
181 else
182 if(conjugate && v[i] == std::string("AMPLITUDE")) {
183
184 while(!isKeyword(v[++i])) params.push_back(v[i]);
185 _ampConj.push_back(params);
186 parseComplexCoef(i,v,c,format);
187 _ampConjCoef.push_back(c);
188 _coefConjFormat.push_back(format);
189 continue;
190 }
191 else {
192
193 printf("Expect keyword, found parameter %s\n",v[i].c_str());
194 assert(0);
195 }
196
197
198 assert(i > i0);
199 }
200
201 printf("PARSING SUCCESSFUL\n");
202 printf("%d amplitude terms\n",_amp.size());
203 printf("%d conj amplitude terms\n",_ampConj.size());
204}
205
206
207
208void EvtMultiChannelParser::parseComplexCoef(int& i, const std::vector<std::string>& v,
209 EvtComplex& c, int& format)
210{
211 // place holder for strtod
212 char** tc = 0;
213
214 assert(v[i++] == std::string("COEFFICIENT"));
215
216 if(v[i] == std::string("POLAR_DEG")) {
217
218 double mag = strtod(v[i+1].c_str(),tc);
219 double phaseRad = strtod(v[i+2].c_str(),tc)*EvtConst::pi/180.0;
220 i += 3;
221 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
222 format = POLAR_DEG;
223 }
224 else if(v[i] == std::string("POLAR_RAD")) {
225
226 double mag = strtod(v[i+1].c_str(),tc);
227 double phaseRad = strtod(v[i+2].c_str(),tc);
228 i += 3;
229 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
230 format = POLAR_RAD;
231 }
232 else if(v[i] == std::string("CARTESIAN")) {
233
234 double re = strtod(v[i+1].c_str(),tc);
235 double im = strtod(v[i+2].c_str(),tc);
236 i += 3;
237 c = EvtComplex(re,im);
238 format = CARTESIAN;
239 }
240 else {
241
242 printf("Invalid format %s for complex coefficient\n",v[i].c_str());
243 exit(0);
244 }
245}
246
247
248double EvtMultiChannelParser::parseRealCoef(int& i, const std::vector<std::string>& v)
249{
250 // place holder for strtod
251 char** tc = 0;
252 double value = 0;
253
254 if(v[i] == std::string("COEFFICIENT")) {
255
256 value = strtod(v[i+1].c_str(),tc);
257 }
258 else assert(0);
259
260 i += 2;
261
262 assert(value > 0.);
263 return value;
264}
265
266
267bool EvtMultiChannelParser::isKeyword(const std::string& s)
268{
269 if(s == std::string("AMPLITUDE")) return true;
270 if(s == std::string("CONJUGATE")) return true;
271 if(s == std::string("COEFFICIENT")) return true;
272 return false;
273}
274
275
276
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
char * file
Definition: DQA_TO_DB.cxx:15
XmlRpcServer s
Definition: HelloServer.cpp:11
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
static void parseComplexCoef(int &i, const std::vector< std::string > &v, EvtComplex &c, int &format)
static double parseRealCoef(int &i, const std::vector< std::string > &v)
static EvtId getId(const std::string &name)