8 #ifndef Pythia8_DireBasics_H
9 #define Pythia8_DireBasics_H
11 #define DIRE_BASICS_VERSION "2.002"
13 #include "Pythia8/Event.h"
15 #include <unordered_map>
17 using std::unordered_map;
21 bool checkSIJ(
const Event& e,
double minSIJ=0.0);
22 void printSI(
const Event& e);
23 void printSIJ(
const Event& e);
25 typedef unsigned long ulong;
31 ulong shash(
const string& str);
46 createmap(
const T& key,
const U& val) { m_map[key] = val; }
51 operator map<T, U>() {
return m_map; }
64 unordered_map<T, U> um_map;
73 operator unordered_map<T, U>() {
return um_map; }
92 m_vector.push_back(val);
95 operator vector<T>() {
return m_vector; }
103 double polev(
double x,
double* coef,
int N );
105 double dilog(
double x);
111 double lABC(
double a,
double b,
double c);
112 double bABC(
double a,
double b,
double c);
113 double gABC(
double a,
double b,
double c);
121 virtual double f(
double) {
return 0.; }
122 virtual double f(
double,
double) {
return 0.; }
123 virtual double f(
double, vector<double>) {
return 0.; }
134 double findRootSecant1D(
DireFunction* f,
double xmin,
double xmax,
135 double constant, vector<double> xb = vector<double>(),
int N=10 ) {
139 for (
int i=2; i < N; ++i ) {
141 - ( f->f(x[i-1],xb) - constant)
142 * ( x[i-1] - x[i-2] )
143 / ( f->f(x[i-1],xb) - f->f(x[i-2],xb) );
149 double findRoot1D(
DireFunction* f,
double xmin,
double xmax,
150 double constant, vector<double> xx = vector<double>(),
int N=10,
151 double tol = 1e-10 ) {
153 double a(xmin), b(xmax), c(xmax), d(0.), e(0.),
154 fa(f->f(a,xx)-constant), fb(f->f(b,xx)-constant), fc(fb),
155 p(0.), q(0.), r(0.), s(0.),
157 double EPS = std::numeric_limits<double>::epsilon();
160 if ( (fa>0. && fb>0.) || (fa<0. && fb<0.) ) {
161 cout <<
"no root " << constant <<
" " << f->f(a,xx) <<
" " << f->f(b,xx)
163 return std::numeric_limits<double>::quiet_NaN();
166 for (
int i=0; i < N; ++i ) {
168 if ( (fb>0. && fc>0.) || (fb<0. && fc<0.) ) {
174 if ( abs(fc) < abs(fb) ) {
183 tol1 = 2.*EPS*abs(b) + 0.5*tol;
186 if (abs(xm) <= tol1 || fb == 0.)
return b;
188 if (abs(e) >= tol1 && abs(fa) > abs(fb) ) {
196 p = s*(2.*xm*q*(q-r) - (b-a)*(r-1.));
197 q = (q-1.)*(r-1.)*(s-1.);
201 double min1 = 3.*xm*q - abs(tol1*q);
202 double min2 = abs(e*q);
203 if (2.*p < ((min1 < min2) ? min1 : min2)) {
219 if (abs(d) > tol1) { b += d; }
221 b += (xm> 0.) ? tol1 : -tol1;
223 fb = f->f(b,xx)-constant;
227 return std::numeric_limits<double>::quiet_NaN();
242 int sizeSoftPos ()
const {
return softPosSave.size(); }
243 int getSoftPos(
unsigned int i)
const {
244 return (i > softPosSave.size()-1) ? -1 : softPosSave[i]; }
245 bool isSoft(
int iPos) {
246 vector<int>::iterator it = find( softPosSave.begin(),
247 softPosSave.end(), iPos);
248 return (it != softPosSave.end());
250 void addSoftPos(
int iPos) {
if (!isSoft(iPos)) softPosSave.push_back(iPos); }
251 void removeSoftPos(
int iPos) {
252 vector<int>::iterator it = find( softPosSave.begin(),
253 softPosSave.end(), iPos);
254 if (it != softPosSave.end()) softPosSave.erase(it);
256 void updateSoftPos(
int iPosOld,
int iPosNew) {
257 if (isSoft(iPosOld)) removeSoftPos(iPosOld);
258 if (isSoft(iPosNew)) removeSoftPos(iPosNew);
261 void updateSoftPosIfMatch(
int iPosOld,
int iPosNew) {
262 if (isSoft(iPosOld)) {
263 vector<int>::iterator it
264 = find (softPosSave.begin(), softPosSave.end(), iPosOld);
268 vector<int> softPos ()
const {
return softPosSave; }
269 void clearSoftPos () { softPosSave.clear(); }
270 void listSoft()
const {
271 cout <<
" 'Soft' particles: ";
272 for (
int i=0; i < sizeSoftPos(); ++i) cout << setw(5) << getSoftPos(i);
277 void removeResPos(
int iPos) {
278 vector<int>::iterator it = find (iPosRes.begin(), iPosRes.end(), iPos);
279 if (it == iPosRes.end())
return;
281 sort (iPosRes.begin(), iPosRes.end());
283 void addResPos(
int iPos) {
284 vector<int>::iterator it = find (iPosRes.begin(), iPosRes.end(), iPos);
285 if (it != iPosRes.end())
return;
286 iPosRes.push_back(iPos);
287 sort (iPosRes.begin(), iPosRes.end());
289 void updateResPos(
int iPosOld,
int iPosNew) {
290 vector<int>::iterator it = find (iPosRes.begin(), iPosRes.end(), iPosOld);
291 if (it == iPosRes.end()) iPosRes.push_back(iPosNew);
293 sort (iPosRes.begin(), iPosRes.end());
295 void updateResPosIfMatch(
int iPosOld,
int iPosNew) {
296 vector<int>::iterator it = find (iPosRes.begin(), iPosRes.end(), iPosOld);
297 if (it != iPosRes.end()) {
299 iPosRes.push_back(iPosNew);
300 sort (iPosRes.begin(), iPosRes.end());
303 bool isRes(
int iPos) {
304 vector<int>::iterator it = find (iPosRes.begin(), iPosRes.end(), iPos);
305 return (it != iPosRes.end());
307 int sizeResPos()
const {
return iPosRes.size(); }
308 int getResPos(
unsigned int i)
const {
309 return (i > iPosRes.size()-1) ? -1 : iPosRes[i]; }
310 void clearResPos() { iPosRes.resize(0); }
311 void listRes()
const {
312 cout <<
" 'Resonant' particles: ";
313 for (
int i=0; i < sizeResPos(); ++i) cout << setw(5) << getResPos(i);
318 vector<int> softPosSave;
332 void clearMessages() {
333 messageStream0.str(
"");
334 messageStream1.str(
"");
335 messageStream2.str(
"");
338 void printMessages(
int verbosity = 0) {
340 <<
"*------------------------------------------------------------*\n"
341 <<
"*----------------- Begin diagnostic output ------------------*\n\n";
342 if (verbosity == 0) cout << scientific << setprecision(8)
343 << messageStream0.str();
344 if (verbosity == 1) cout << scientific << setprecision(8)
345 << messageStream1.str();
346 if (verbosity == 2) cout << scientific << setprecision(8)
347 << messageStream2.str();
349 <<
"*----------------- End diagnostic output -------------------*\n"
350 <<
"*-----------------------------------------------------------*"
354 void printHistograms() {}
356 void fillHistograms(
int type,
int nfinal,
double mec,
double pT,
double z) {
357 if (
false) cout << type*nfinal*mec*pT*z;}
360 ostream & message (
int verbosity = 0) {
361 if (verbosity == 0)
return messageStream0;
362 if (verbosity == 1)
return messageStream1;
363 if (verbosity == 2)
return messageStream2;
364 return messageStream0;
368 ostringstream messageStream0, messageStream1, messageStream2;
381 direEventInfo.clearResPos();
382 direEventInfo.clearSoftPos();
383 direDebugInfo.clearMessages();
387 void removeResPos(
int iPos) {
return direEventInfo.removeResPos(iPos); }
388 void addResPos(
int iPos) {
return direEventInfo.addResPos(iPos); }
389 bool isRes(
int iPos) {
return direEventInfo.isRes(iPos); }
390 void clearResPos () {
return direEventInfo.clearResPos(); }
391 int sizeResPos()
const {
return direEventInfo.sizeResPos(); }
392 void listRes()
const {
return direEventInfo.listRes(); }
393 int getResPos(
unsigned int i)
const {
return direEventInfo.getResPos(i); }
394 void updateResPos(
int iPosOld,
int iPosNew) {
395 return direEventInfo.updateResPos(iPosOld,iPosNew); }
396 void updateResPosIfMatch(
int iPosOld,
int iPosNew) {
397 return direEventInfo.updateResPosIfMatch(iPosOld,iPosNew); }
400 void printMessages(
int verbosity = 0) {
401 return direDebugInfo.printMessages(verbosity); }
402 ostream & message (
int verbosity = 0) {
403 return direDebugInfo.message(verbosity); }
404 void clearMessages() { direDebugInfo.clearMessages(); }
406 void fillHistograms(
int type,
int nfinal,
double mec,
double pT,
double z) {
407 direDebugInfo.fillHistograms(type, nfinal, mec, pT, z); }
408 void printHistograms() { direDebugInfo.printHistograms(); }
411 bool isSoft(
int iPos) {
return direEventInfo.isSoft(iPos); }
412 void addSoftPos(
int iPos) {
return direEventInfo.addSoftPos(iPos); }
413 void removeSoftPos(
int iPos) {
return direEventInfo.removeSoftPos(iPos); }
414 vector<int> softPos () {
return direEventInfo.softPos(); }
415 void clearSoftPos () {
return direEventInfo.clearSoftPos(); }
416 int sizeSoftPos ()
const {
return direEventInfo.sizeSoftPos(); }
417 void listSoft()
const {
return direEventInfo.listSoft(); }
418 int getSoftPos(
unsigned int i)
const {
return direEventInfo.getSoftPos(i); }
419 void updateSoftPos(
int iPosOld,
int iPosNew) {
420 return direEventInfo.updateSoftPos(iPosOld, iPosNew);
422 void updateSoftPosIfMatch(
int iPosOld,
int iPosNew) {
423 return direEventInfo.updateSoftPosIfMatch(iPosOld, iPosNew);
435 #endif // end Pythia8_DireBasics_H