00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "EvtGenBase/EvtPatches.hh"
00017
00018 #include <assert.h>
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <math.h>
00022 #include <string>
00023 #include <vector>
00024 #include "EvtGenBase/EvtParser.hh"
00025 #include "EvtGenBase/EvtMultiChannelParser.hh"
00026 #include "EvtGenBase/EvtDecayMode.hh"
00027 #include "EvtGenBase/EvtPDL.hh"
00028
00029 using std::string;
00030 using std::vector;
00031
00032 EvtDecayMode EvtMultiChannelParser::getDecayMode(const char* file)
00033 {
00034
00035
00036 EvtParser parser;
00037 parser.Read(file);
00038
00039
00040
00041 int i = 0;
00042 int N = parser.getNToken();
00043 while(i<N) {
00044
00045 std::string tok = parser.getToken(i++);
00046 if(tok == std::string("Decay")) break;
00047 }
00048
00049
00050
00051 string mother = string(parser.getToken(i++).c_str());
00052 std::string bf = parser.getToken(i++);
00053
00054 vector<string> dauV;
00055
00056
00057 while(1) {
00058
00059 std::string d = parser.getToken(i++);
00060
00061 if(EvtPDL::getStdHep(EvtPDL::getId(d.c_str())) == 0) break;
00062
00063 dauV.push_back(string(d.c_str()));
00064 }
00065
00066 EvtDecayMode mode(mother,dauV);
00067 printf("Decay File defines mode %s\n",mode.mode());
00068
00069 return mode;
00070 }
00071
00072
00073
00074 void EvtMultiChannelParser::parse(const char* file, const char* model)
00075 {
00076
00077
00078 EvtParser parser;
00079 parser.Read(file);
00080
00081
00082
00083
00084 int i = 0;
00085 int N = parser.getNToken();
00086
00087
00088
00089 while(i<N) {
00090
00091 std::string tok = parser.getToken(i++);
00092 if(tok == std::string(model)) break;
00093 }
00094 if(i == N) {
00095
00096 printf("No model %s found in decay file %s",model,file);
00097 exit(0);
00098 }
00099
00100
00101
00102
00103 std::vector<std::string> v;
00104 while(i<N) {
00105
00106 std::string tok = parser.getToken(i++);
00107 if(tok == std::string(";")) break;
00108 else v.push_back(tok);
00109 }
00110
00111 if(i == N) {
00112
00113 printf("No terminating ; found in decay file %s",file);
00114 assert(0);
00115 }
00116
00117 parse(v);
00118 }
00119
00120
00121 void EvtMultiChannelParser::parse(const std::vector<std::string>& v)
00122 {
00123
00124 char** tc = 0;
00125
00126
00127
00128
00129
00130 if(v[0] == std::string("MAXPDF")) {
00131
00132 _pdfMax = strtod(v[1].c_str(),tc);
00133 if(_pdfMax <= 0) { printf("Bad pdfMax=%f\n",_pdfMax); assert(0); }
00134 }
00135 else
00136 if(v[0] == std::string("SCANPDF")) {
00137
00138 _nScan = atoi(v[1].c_str());
00139 }
00140 else {
00141
00142 printf("Error parsing decay file\n");
00143 assert(0);
00144 }
00145
00146
00147
00148
00149 bool conjugate = false;
00150 int i = 2;
00151 assert(isKeyword(v[2]));
00152
00153 while(i < v.size()) {
00154
00155 int i0 = i;
00156
00157
00158 if(v[i] == std::string("CONJUGATE")) {
00159
00160 assert(conjugate == false);
00161 conjugate = true;
00162 assert(!isKeyword(v[++i]));
00163 _dm = strtod(v[i].c_str(),tc);
00164 i++;
00165 }
00166
00167 std::vector<std::string> params;
00168 EvtComplex c;
00169 int format;
00170
00171 if(!conjugate && v[i] == std::string("AMPLITUDE")) {
00172
00173 while(!isKeyword(v[++i])) params.push_back(v[i]);
00174 _amp.push_back(params);
00175
00176 parseComplexCoef(i,v,c,format);
00177 _ampCoef.push_back(c);
00178 _coefFormat.push_back(format);
00179 continue;
00180 }
00181 else
00182 if(conjugate && v[i] == std::string("AMPLITUDE")) {
00183
00184 while(!isKeyword(v[++i])) params.push_back(v[i]);
00185 _ampConj.push_back(params);
00186 parseComplexCoef(i,v,c,format);
00187 _ampConjCoef.push_back(c);
00188 _coefConjFormat.push_back(format);
00189 continue;
00190 }
00191 else {
00192
00193 printf("Expect keyword, found parameter %s\n",v[i].c_str());
00194 assert(0);
00195 }
00196
00197
00198 assert(i > i0);
00199 }
00200
00201 printf("PARSING SUCCESSFUL\n");
00202 printf("%d amplitude terms\n",_amp.size());
00203 printf("%d conj amplitude terms\n",_ampConj.size());
00204 }
00205
00206
00207
00208 void EvtMultiChannelParser::parseComplexCoef(int& i, const std::vector<std::string>& v,
00209 EvtComplex& c, int& format)
00210 {
00211
00212 char** tc = 0;
00213
00214 assert(v[i++] == std::string("COEFFICIENT"));
00215
00216 if(v[i] == std::string("POLAR_DEG")) {
00217
00218 double mag = strtod(v[i+1].c_str(),tc);
00219 double phaseRad = strtod(v[i+2].c_str(),tc)*EvtConst::pi/180.0;
00220 i += 3;
00221 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
00222 format = POLAR_DEG;
00223 }
00224 else if(v[i] == std::string("POLAR_RAD")) {
00225
00226 double mag = strtod(v[i+1].c_str(),tc);
00227 double phaseRad = strtod(v[i+2].c_str(),tc);
00228 i += 3;
00229 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
00230 format = POLAR_RAD;
00231 }
00232 else if(v[i] == std::string("CARTESIAN")) {
00233
00234 double re = strtod(v[i+1].c_str(),tc);
00235 double im = strtod(v[i+2].c_str(),tc);
00236 i += 3;
00237 c = EvtComplex(re,im);
00238 format = CARTESIAN;
00239 }
00240 else {
00241
00242 printf("Invalid format %s for complex coefficient\n",v[i].c_str());
00243 exit(0);
00244 }
00245 }
00246
00247
00248 double EvtMultiChannelParser::parseRealCoef(int& i, const std::vector<std::string>& v)
00249 {
00250
00251 char** tc = 0;
00252 double value = 0;
00253
00254 if(v[i] == std::string("COEFFICIENT")) {
00255
00256 value = strtod(v[i+1].c_str(),tc);
00257 }
00258 else assert(0);
00259
00260 i += 2;
00261
00262 assert(value > 0.);
00263 return value;
00264 }
00265
00266
00267 bool EvtMultiChannelParser::isKeyword(const std::string& s)
00268 {
00269 if(s == std::string("AMPLITUDE")) return true;
00270 if(s == std::string("CONJUGATE")) return true;
00271 if(s == std::string("COEFFICIENT")) return true;
00272 return false;
00273 }
00274
00275
00276