EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
EvtMultiChannelParser.cpp
Go to the documentation of this file.
1
2/***********************************************************************
3* Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4* *
5* This file is part of EvtGen. *
6* *
7* EvtGen 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* EvtGen 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 EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19***********************************************************************/
20
22
24#include "EvtGenBase/EvtPDL.hh"
26
27#include <assert.h>
28#include <math.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string>
32#include <vector>
33
34using std::string;
35using std::vector;
36
38{
39 // Open file, read tokens
40
41 EvtParser parser;
42 parser.read( file );
43
44 // Seek Decay
45
46 int i = 0;
47 int N = parser.getNToken();
48 while ( i < N ) {
49 std::string tok = parser.getToken( i++ );
50 if ( tok == std::string( "Decay" ) )
51 break;
52 }
53
54 // Get mother
55
56 string mother = string( parser.getToken( i++ ).c_str() );
57 std::string bf = parser.getToken( i++ );
58
59 vector<string> dauV;
60 // Get daughters
61
62 while ( 1 ) {
63 std::string d = parser.getToken( i++ );
64
65 if ( EvtPDL::getStdHep( EvtPDL::getId( d.c_str() ) ) == 0 )
66 break;
67
68 dauV.push_back( string( d.c_str() ) );
69 }
70
71 EvtDecayMode mode( mother, dauV );
72 printf( "Decay File defines mode %s\n", mode.mode().c_str() );
73
74 return mode;
75}
76
77void EvtMultiChannelParser::parse( const char* file, const char* model )
78{
79 // Open file, read tokens
80
81 EvtParser parser;
82 parser.read( file );
83
84 // Get parameters (tokens between the model name and ;)
85
86 int i = 0;
87 int N = parser.getNToken();
88
89 // Seek the model name
90
91 while ( i < N ) {
92 std::string tok = parser.getToken( i++ );
93 if ( tok == std::string( model ) )
94 break;
95 }
96 if ( i == N ) {
97 printf( "No model %s found in decay file %s", model, file );
98 exit( 0 );
99 }
100
101 // Add all tokens up to a semicolon to vector
102
103 std::vector<std::string> v;
104 while ( i < N ) {
105 std::string tok = parser.getToken( i++ );
106 if ( tok == std::string( ";" ) )
107 break;
108 else
109 v.push_back( tok );
110 }
111
112 if ( i == N ) {
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{
122 // place holder for strtod
123 char** tc = nullptr;
124
125 // Get PDF maximum or number of points to
126 // use in the scan.
127
128 if ( v[0] == std::string( "MAXPDF" ) ) {
129 m_pdfMax = strtod( v[1].c_str(), tc );
130 if ( m_pdfMax <= 0 ) {
131 printf( "Bad pdfMax=%f\n", m_pdfMax );
132 assert( 0 );
133 }
134 } else if ( v[0] == std::string( "SCANPDF" ) ) {
135 m_nScan = atoi( v[1].c_str() );
136 } else {
137 printf( "Error parsing decay file\n" );
138 assert( 0 );
139 }
140
141 // Now parse the rest of file for amplitude specifications.
142
143 bool conjugate = false;
144 size_t i = 2;
145 assert( isKeyword( v[2] ) );
146
147 while ( i < v.size() ) {
148 [[maybe_unused]] size_t i0 = i;
149
150 // Switch to conjugate amplitudes after keyword
151 if ( v[i] == std::string( "CONJUGATE" ) ) {
152 assert( conjugate == false );
153 conjugate = true;
154 i++;
155 m_dm = strtod( v[i++].c_str(), tc );
156 m_mixAmpli = strtod( v[i++].c_str(), tc );
157 m_mixPhase = strtod( v[i++].c_str(), tc );
158 }
159
160 if ( i >= v.size() )
161 break;
162 std::vector<std::string> params;
163 EvtComplex c;
164 int format;
165
166 if ( !conjugate && v[i] == std::string( "AMPLITUDE" ) ) {
167 while ( !isKeyword( v[++i] ) )
168 params.push_back( v[i] );
169 m_amp.push_back( params );
170
171 parseComplexCoef( i, v, c, format );
172 m_ampCoef.push_back( c );
173 m_coefFormat.push_back( format );
174 continue;
175 } else if ( conjugate && v[i] == std::string( "AMPLITUDE" ) ) {
176 while ( !isKeyword( v[++i] ) )
177 params.push_back( v[i] );
178 m_ampConj.push_back( params );
179 parseComplexCoef( i, v, c, format );
180 m_ampConjCoef.push_back( c );
181 m_coefConjFormat.push_back( format );
182 continue;
183 } else {
184 printf( "Expect keyword, found parameter %s\n", v[i].c_str() );
185 assert( 0 );
186 }
187
188 assert( i > i0 );
189 }
190
191 printf( "PARSING SUCCESSFUL\n" );
192 printf( "%d amplitude terms\n", (int)m_amp.size() );
193 printf( "%d conj amplitude terms\n", (int)m_ampConj.size() );
194}
195
197 const std::vector<std::string>& v,
198 EvtComplex& c, int& format )
199{
200 // place holder for strtod
201 char** tc = nullptr;
202
203 std::string coefString = v[i++];
204 assert( coefString == std::string( "COEFFICIENT" ) );
205
206 if ( v[i] == std::string( "POLAR_DEG" ) ) {
207 double mag = strtod( v[i + 1].c_str(), tc );
208 double phaseRad = strtod( v[i + 2].c_str(), tc ) * EvtConst::pi / 180.0;
209 i += 3;
210 c = EvtComplex( mag * cos( phaseRad ), mag * sin( phaseRad ) );
211 format = POLAR_DEG;
212 } else if ( v[i] == std::string( "POLAR_RAD" ) ) {
213 double mag = strtod( v[i + 1].c_str(), tc );
214 double phaseRad = strtod( v[i + 2].c_str(), tc );
215 i += 3;
216 c = EvtComplex( mag * cos( phaseRad ), mag * sin( phaseRad ) );
217 format = POLAR_RAD;
218 } else if ( v[i] == std::string( "CARTESIAN" ) ) {
219 double re = strtod( v[i + 1].c_str(), tc );
220 double im = strtod( v[i + 2].c_str(), tc );
221 i += 3;
222 c = EvtComplex( re, im );
223 format = CARTESIAN;
224 } else {
225 printf( "Invalid format %s for complex coefficient\n", v[i].c_str() );
226 exit( 0 );
227 }
228}
229
231 const std::vector<std::string>& v )
232{
233 // place holder for strtod
234 char** tc = nullptr;
235 double value = 0;
236
237 if ( v[i] == std::string( "COEFFICIENT" ) ) {
238 value = strtod( v[i + 1].c_str(), tc );
239 } else
240 assert( 0 );
241
242 i += 2;
243
244 assert( value > 0. );
245 return value;
246}
247
248bool EvtMultiChannelParser::isKeyword( const std::string& s )
249{
250 if ( s == std::string( "AMPLITUDE" ) )
251 return true;
252 if ( s == std::string( "CONJUGATE" ) )
253 return true;
254 if ( s == std::string( "COEFFICIENT" ) )
255 return true;
256 return false;
257}
static const double pi
Definition EvtConst.hh:26
std::string mode() const
std::vector< std::vector< std::string > > m_amp
static EvtDecayMode getDecayMode(const char *file)
std::vector< EvtComplex > m_ampConjCoef
std::vector< std::vector< std::string > > m_ampConj
std::vector< int > m_coefFormat
std::vector< EvtComplex > m_ampCoef
void parse(const char *file, const char *model)
std::vector< int > m_coefConjFormat
static bool isKeyword(const std::string &s)
static void parseComplexCoef(size_t &i, const std::vector< std::string > &v, EvtComplex &c, int &format)
static double parseRealCoef(int &i, const std::vector< std::string > &v)
static int getStdHep(EvtId id)
Definition EvtPDL.cpp:356
static EvtId getId(const std::string &name)
Definition EvtPDL.cpp:283
int read(const std::string filename)
Definition EvtParser.cpp:61
int getNToken()
Definition EvtParser.cpp:46
const std::string & getToken(int i)
Definition EvtParser.cpp:51