BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
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 "EvtPatches.hh"
17
18#include "EvtDecayMode.hh"
20#include "EvtPDL.hh"
21#include "EvtParser.hh"
22#include <assert.h>
23#include <math.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string>
27#include <vector>
28
29using std::string;
30using std::vector;
31
33 // Open file, read tokens
34
35 EvtParser parser;
36 parser.Read( file );
37
38 // Seek Decay
39
40 int i = 0;
41 int N = parser.getNToken();
42 while ( i < N )
43 {
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
60 std::string d = parser.getToken( i++ );
61
62 if ( EvtPDL::getStdHep( EvtPDL::getId( d.c_str() ) ) == 0 ) break;
63
64 dauV.push_back( string( d.c_str() ) );
65 }
66
67 EvtDecayMode mode( mother, dauV );
68 printf( "Decay File defines mode %s\n", mode.mode() );
69
70 return mode;
71}
72
73void EvtMultiChannelParser::parse( const char* file, const char* model ) {
74 // Open file, read tokens
75
76 EvtParser parser;
77 parser.Read( file );
78
79 // Get parameters (tokens between the model name and ;)
80
81 int i = 0;
82 int N = parser.getNToken();
83
84 // Seek the model name
85
86 while ( i < N )
87 {
88
89 std::string tok = parser.getToken( i++ );
90 if ( tok == std::string( model ) ) break;
91 }
92 if ( i == N )
93 {
94
95 printf( "No model %s found in decay file %s", model, file );
96 exit( 0 );
97 }
98
99 // Add all tokens up to a semicolon to vector
100
101 std::vector<std::string> v;
102 while ( i < N )
103 {
104
105 std::string tok = parser.getToken( i++ );
106 if ( tok == std::string( ";" ) ) break;
107 else v.push_back( tok );
108 }
109
110 if ( i == N )
111 {
112
113 printf( "No terminating ; found in decay file %s", file );
114 assert( 0 );
115 }
116
117 parse( v );
118}
119
120void EvtMultiChannelParser::parse( const std::vector<std::string>& v ) {
121 // place holder for strtod
122 char** tc = 0;
123
124 // Get PDF maximum or number of points to
125 // use in the scan.
126
127 if ( v[0] == std::string( "MAXPDF" ) )
128 {
129
130 _pdfMax = strtod( v[1].c_str(), tc );
131 if ( _pdfMax <= 0 )
132 {
133 printf( "Bad pdfMax=%f\n", _pdfMax );
134 assert( 0 );
135 }
136 }
137 else if ( v[0] == std::string( "SCANPDF" ) ) { _nScan = atoi( v[1].c_str() ); }
138 else
139 {
140
141 printf( "Error parsing decay file\n" );
142 assert( 0 );
143 }
144
145 // Now parse the rest of file for amplitude specifications.
146
147 bool conjugate = false;
148 int i = 2;
149 assert( isKeyword( v[2] ) );
150
151 while ( i < v.size() )
152 {
153
154 int i0 = i;
155
156 // Switch to conjugate amplitudes after keyword
157 if ( v[i] == std::string( "CONJUGATE" ) )
158 {
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
174 while ( !isKeyword( v[++i] ) ) params.push_back( v[i] );
175 _amp.push_back( params );
176
177 parseComplexCoef( i, v, c, format );
178 _ampCoef.push_back( c );
179 _coefFormat.push_back( format );
180 continue;
181 }
182 else if ( conjugate && v[i] == std::string( "AMPLITUDE" ) )
183 {
184
185 while ( !isKeyword( v[++i] ) ) params.push_back( v[i] );
186 _ampConj.push_back( params );
187 parseComplexCoef( i, v, c, format );
188 _ampConjCoef.push_back( c );
189 _coefConjFormat.push_back( format );
190 continue;
191 }
192 else
193 {
194
195 printf( "Expect keyword, found parameter %s\n", v[i].c_str() );
196 assert( 0 );
197 }
198
199 assert( i > i0 );
200 }
201
202 printf( "PARSING SUCCESSFUL\n" );
203 printf( "%d amplitude terms\n", _amp.size() );
204 printf( "%d conj amplitude terms\n", _ampConj.size() );
205}
206
207void EvtMultiChannelParser::parseComplexCoef( int& i, const std::vector<std::string>& v,
208 EvtComplex& c, int& format ) {
209 // place holder for strtod
210 char** tc = 0;
211
212 assert( v[i++] == std::string( "COEFFICIENT" ) );
213
214 if ( v[i] == std::string( "POLAR_DEG" ) )
215 {
216
217 double mag = strtod( v[i + 1].c_str(), tc );
218 double phaseRad = strtod( v[i + 2].c_str(), tc ) * EvtConst::pi / 180.0;
219 i += 3;
220 c = EvtComplex( mag * cos( phaseRad ), mag * sin( phaseRad ) );
221 format = POLAR_DEG;
222 }
223 else if ( v[i] == std::string( "POLAR_RAD" ) )
224 {
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
235 double re = strtod( v[i + 1].c_str(), tc );
236 double im = strtod( v[i + 2].c_str(), tc );
237 i += 3;
238 c = EvtComplex( re, im );
239 format = CARTESIAN;
240 }
241 else
242 {
243
244 printf( "Invalid format %s for complex coefficient\n", v[i].c_str() );
245 exit( 0 );
246 }
247}
248
249double EvtMultiChannelParser::parseRealCoef( int& i, const std::vector<std::string>& v ) {
250 // place holder for strtod
251 char** tc = 0;
252 double value = 0;
253
254 if ( v[i] == std::string( "COEFFICIENT" ) ) { value = strtod( v[i + 1].c_str(), tc ); }
255 else assert( 0 );
256
257 i += 2;
258
259 assert( value > 0. );
260 return value;
261}
262
263bool EvtMultiChannelParser::isKeyword( const std::string& s ) {
264 if ( s == std::string( "AMPLITUDE" ) ) return true;
265 if ( s == std::string( "CONJUGATE" ) ) return true;
266 if ( s == std::string( "COEFFICIENT" ) ) return true;
267 return false;
268}
char * file
Definition DQA_TO_DB.cxx:16
XmlRpcServer s
**********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 const double pi
Definition EvtConst.hh:27
const char * mode() const
static EvtDecayMode getDecayMode(const char *file)
void parse(const char *file, const char *model)
static void parseComplexCoef(int &i, const std::vector< std::string > &v, EvtComplex &c, int &format)
static bool isKeyword(const std::string &s)
static double parseRealCoef(int &i, const std::vector< std::string > &v)
static int getStdHep(EvtId id)
Definition EvtPDL.hh:61
static EvtId getId(const std::string &name)
Definition EvtPDL.cc:272
int getNToken()
Definition EvtParser.cc:48
const std::string & getToken(int i)
Definition EvtParser.cc:50
int Read(const std::string filename)
Definition EvtParser.cc:54