1 //-----------------------------------------------------------------------
2 // File and Version Information:
3 // $Id: EvtMultiChannelParser.cc,v 1.17 2009/02/19 03:22:30 ryd Exp $
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.
10 // Copyright Information:
11 // Copyright (C) 1998 Caltech, UCSB
14 // Alexei Dvoretskii, Caltech, 2001-2002.
15 //-----------------------------------------------------------------------
16 #include "EvtGenBase/EvtPatches.hh"
24 #include "EvtGenBase/EvtParser.hh"
25 #include "EvtGenBase/EvtMultiChannelParser.hh"
26 #include "EvtGenBase/EvtDecayMode.hh"
27 #include "EvtGenBase/EvtPDL.hh"
32 EvtDecayMode EvtMultiChannelParser::getDecayMode(const char* file)
34 // Open file, read tokens
42 int N = parser.getNToken();
45 std::string tok = parser.getToken(i++);
46 if(tok == std::string("Decay")) break;
51 string mother = string(parser.getToken(i++).c_str());
52 std::string bf = parser.getToken(i++);
59 std::string d = parser.getToken(i++);
61 if(EvtPDL::getStdHep(EvtPDL::getId(d.c_str())) == 0) break;
63 dauV.push_back(string(d.c_str()));
66 EvtDecayMode mode(mother,dauV);
67 printf("Decay File defines mode %s\n",mode.mode().c_str());
74 void EvtMultiChannelParser::parse(const char* file, const char* model)
76 // Open file, read tokens
82 // Get parameters (tokens between the model name and ;)
85 int N = parser.getNToken();
87 // Seek the model name
91 std::string tok = parser.getToken(i++);
92 if(tok == std::string(model)) break;
96 printf("No model %s found in decay file %s",model,file);
101 // Add all tokens up to a semicolon to vector
103 std::vector<std::string> v;
106 std::string tok = parser.getToken(i++);
107 if(tok == std::string(";")) break;
108 else v.push_back(tok);
113 printf("No terminating ; found in decay file %s",file);
121 void EvtMultiChannelParser::parse(const std::vector<std::string>& v)
123 // place holder for strtod
127 // Get PDF maximum or number of points to
130 if(v[0] == std::string("MAXPDF")) {
132 _pdfMax = strtod(v[1].c_str(),tc);
133 if(_pdfMax <= 0) { printf("Bad pdfMax=%f\n",_pdfMax); assert(0); }
136 if(v[0] == std::string("SCANPDF")) {
138 _nScan = atoi(v[1].c_str());
142 printf("Error parsing decay file\n");
147 // Now parse the rest of file for amplitude specifications.
149 bool conjugate = false;
151 assert(isKeyword(v[2]));
153 while(i < v.size()) {
157 // Switch to conjugate amplitudes after keyword
158 if(v[i] == std::string("CONJUGATE")) {
160 assert(conjugate == false);
162 assert(!isKeyword(v[++i]));
163 _dm = strtod(v[i++].c_str(),tc);
164 _mixAmpli = strtod(v[i++].c_str(),tc);
165 _mixPhase = strtod(v[i++].c_str(),tc);
168 if (i >= v.size()) break;
169 std::vector<std::string> params;
173 if(!conjugate && v[i] == std::string("AMPLITUDE")) {
175 while(!isKeyword(v[++i])) params.push_back(v[i]);
176 _amp.push_back(params);
178 parseComplexCoef(i,v,c,format);
179 _ampCoef.push_back(c);
180 _coefFormat.push_back(format);
184 if(conjugate && v[i] == std::string("AMPLITUDE")) {
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);
195 printf("Expect keyword, found parameter %s\n",v[i].c_str());
203 printf("PARSING SUCCESSFUL\n");
204 printf("%d amplitude terms\n",(int)_amp.size());
205 printf("%d conj amplitude terms\n",(int)_ampConj.size());
210 void EvtMultiChannelParser::parseComplexCoef(size_t& i, const std::vector<std::string>& v,
211 EvtComplex& c, int& format)
213 // place holder for strtod
216 assert(v[i++] == std::string("COEFFICIENT"));
218 if(v[i] == std::string("POLAR_DEG")) {
220 double mag = strtod(v[i+1].c_str(),tc);
221 double phaseRad = strtod(v[i+2].c_str(),tc)*EvtConst::pi/180.0;
223 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
226 else if(v[i] == std::string("POLAR_RAD")) {
228 double mag = strtod(v[i+1].c_str(),tc);
229 double phaseRad = strtod(v[i+2].c_str(),tc);
231 c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));
234 else if(v[i] == std::string("CARTESIAN")) {
236 double re = strtod(v[i+1].c_str(),tc);
237 double im = strtod(v[i+2].c_str(),tc);
239 c = EvtComplex(re,im);
244 printf("Invalid format %s for complex coefficient\n",v[i].c_str());
250 double EvtMultiChannelParser::parseRealCoef(int& i, const std::vector<std::string>& v)
252 // place holder for strtod
256 if(v[i] == std::string("COEFFICIENT")) {
258 value = strtod(v[i+1].c_str(),tc);
269 bool EvtMultiChannelParser::isKeyword(const std::string& s)
271 if(s == std::string("AMPLITUDE")) return true;
272 if(s == std::string("CONJUGATE")) return true;
273 if(s == std::string("COEFFICIENT")) return true;