40using std::resetiosflags;
41using std::setiosflags;
46int EvtPythia::njetsetdecays = 0;
48int EvtPythia::ntable = 0;
50int EvtPythia::ncommand = 0;
51int EvtPythia::lcommand = 0;
52std::string* EvtPythia::commands = 0;
55extern void pycontinuum_(
double*,
int*,
int*,
double*,
double*,
double*,
double* );
67extern void pythiadec_(
int*,
double*,
int*,
int*,
int*,
double*,
double*,
double*,
double* );
75extern void pygive_(
const char* cnfgstr,
int length );
99 if ( njetsetdecays == 0 )
106 for ( i = 0; i < njetsetdecays; i++ )
108 if ( jetsetdecays[i] ==
this )
110 jetsetdecays[i] = jetsetdecays[njetsetdecays - 1];
112 if ( njetsetdecays == 0 )
121 report(
ERROR,
"EvtGen" ) <<
"Error in destroying Pythia model!" << endl;
137 report(
ERROR,
"EvtGen" ) <<
"EvtPythia finds that you are decaying the" << endl
139 <<
" with the Pythia model" << endl
140 <<
" this does not work, please modify decay table." << endl;
141 report(
ERROR,
"EvtGen" ) <<
"Will terminate execution!" << endl;
152 if ( ncommand == lcommand )
155 lcommand = 10 + 2 * lcommand;
157 std::string* newcommands =
new std::string[lcommand];
161 for ( i = 0; i < ncommand; i++ ) { newcommands[i] = commands[i]; }
165 commands = newcommands;
168 commands[ncommand] = cmd;
174 double* pz,
double* e ) {
185 if (
pycomp_( &istdheppar ) == 0 )
201 EvtId evtnumstable[100], evtnumparton[100];
202 int stableindex[100], partonindex[100];
211 std::cout <<
"Particle " <<
EvtPDL::name( p->
getId() ) <<
" has zero mass" << std::endl;
216 double px[100], py[100], pz[100], e[100];
223 pythiadec_( &ip, &
mp, &ndaugjs, kf, km, px, py, pz, e );
228 for ( i = 0; i < ndaugjs; i++ )
234 report(
ERROR,
"EvtGen" ) <<
"Pythia returned particle:" << kf[i] << endl;
235 report(
ERROR,
"EvtGen" ) <<
"This can not be translated to evt number" << endl;
236 report(
ERROR,
"EvtGen" ) <<
"and the decay will be rejected!" << endl;
237 report(
ERROR,
"EvtGen" ) <<
"The decay was of particle:" << ip << endl;
243 if (
abs( kf[i] ) <= 6 || kf[i] == 21 )
245 partonindex[numparton] = i;
251 stableindex[numstable] = i;
260 if ( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] >= e[i] * e[i] )
261 { e[i] = sqrt( px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] ) + 0.0000000000001; }
263 p4[i].
set( e[i], px[i], py[i], pz[i] );
268 more = ( channel != -1 );
272 }
while ( more && (
count < 10000 ) );
276 report(
INFO,
"EvtGen" ) <<
"Too many loops in EvtPythia!!!" << endl;
278 for ( i = 0; i < numstable; i++ )
280 report(
INFO,
"EvtGen" ) <<
"Daug(" << i <<
")"
285 if ( numparton == 0 )
290 for ( i = 0; i < numstable; i++ )
291 { p->
getDaug( i )->
init( evtnumstable[i], p4[stableindex[i]] ); }
293 fixPolarizations( p );
304 for ( i = 0; i < numparton; i++ ) { p4string += p4[partonindex[i]]; }
308 for ( i = 0; i < numstable; i++ )
310 if ( km[stableindex[i]] == 0 ) {
type[nprimary++] = evtnumstable[i]; }
319 for ( i = 0; i < numparton; i++ ) { p4partons[i] = p4[partonindex[i]]; }
325 for ( i = 0; i < numstable; i++ )
328 if ( km[stableindex[i]] == 0 )
329 { p->
getDaug( nprimary++ )->
init( evtnumstable[i], p4[stableindex[i]] ); }
333 for ( i = 0; i < numstable; i++ )
335 if ( km[stableindex[i]] != 0 ) {
type[nsecond++] = evtnumstable[i]; }
341 for ( i = 0; i < numstable; i++ )
343 if ( km[stableindex[i]] != 0 )
345 p4[stableindex[i]] =
boostTo( p4[stableindex[i]], p4string );
353 fixPolarizations( p );
359void EvtPythia::fixPolarizations(
EvtParticle* p ) {
369 for ( i = 0; i < ndaug; i++ )
377 rho.
Set( 0, 0, 0.5 );
378 rho.
Set( 0, 1, 0.0 );
379 rho.
Set( 0, 2, 0.0 );
381 rho.
Set( 1, 0, 0.0 );
382 rho.
Set( 1, 1, 1.0 );
383 rho.
Set( 1, 2, 0.0 );
385 rho.
Set( 2, 0, 0.0 );
386 rho.
Set( 2, 1, 0.0 );
387 rho.
Set( 2, 2, 0.5 );
391 double alpha = atan2( p4Psi.
get( 2 ), p4Psi.
get( 1 ) );
392 double beta = acos( p4Psi.
get( 3 ) / p4Psi.
d3mag() );
402 if ( njetsetdecays == ntable )
407 for ( i = 0; i < ntable; i++ ) { newjetsetdecays[i] = jetsetdecays[i]; }
408 ntable = 2 * ntable + 10;
409 delete[] jetsetdecays;
410 jetsetdecays = newjetsetdecays;
413 jetsetdecays[njetsetdecays++] = jsdecay;
416void EvtPythia::WritePythiaEntryHeader( ofstream& outdec,
int lundkc,
EvtId evtnum,
417 std::string name,
int chg,
int cchg,
int spin2,
418 double mass,
double width,
double maxwidth,
419 double ctau,
int stable,
double rawbrfrsum ) {
431 if ( ctau > 1000000.0 ) ctau = 0.0;
433 strcpy( sname, name.c_str() );
437 while ( sname[i] != 0 ) { i++; }
441 if ( evtnum.
getId() >= 0 )
443 if ( sname[i - 1] ==
'+' || sname[i - 1] ==
'-' )
448 if ( sname[i - 1] ==
'+' || sname[i - 1] ==
'-' )
454 if ( sname[i - 1] ==
'0' && sname[i - 2] !=
'_' &&
455 !( sname[0] ==
'c' && sname[1] ==
'h' ) )
462 if ( i > namelength )
464 for ( j = 1; j < namelength; j++ ) { sname[j] = sname[j + i - namelength]; }
465 sname[namelength] = 0;
469 for ( j = 0; j <= namelength; j++ ) ccsname[j] = sname[j];
471 while ( ccsname[i] !=
' ' )
474 if ( ccsname[i] == 0 )
break;
476 if ( i < namelength )
484 if ( evtnum.
getId() >= 0 )
494 outdec <<
" " << setw( 9 ) << lundkc;
496 outdec.width( namelength );
497 outdec << setiosflags( ios::left ) << sname;
502 outdec.width( namelength );
511 outdec << resetiosflags( ios::left );
512 outdec << setw( 3 ) << chg;
513 outdec << setw( 3 ) << cchg;
515 if ( evtnum.
getId() >= 0 )
518 else { outdec << 1; }
520 else { outdec << 0; }
521 outdec.setf( ios::fixed, ios::floatfield );
522 outdec.precision( 5 );
523 outdec << setw( 12 ) <<
mass;
524 outdec.setf( ios::fixed, ios::floatfield );
525 outdec << setw( 12 ) << width;
526 outdec.setf( ios::fixed, ios::floatfield );
528 if ( fabs( width ) < 0.0000000001 ) { outdec << 0.0; }
529 else { outdec << maxwidth; }
531 outdec.setf( ios::scientific, ios::floatfield );
535 if ( evtnum.
getId() >= 0 )
537 if ( ctau > 1.0 || rawbrfrsum < 0.000001 ) { stable = 0; }
549void EvtPythia::WritePythiaParticle( ofstream& outdec,
EvtId ipar,
EvtId iparname,
556 for ( ijetset = 0; ijetset < njetsetdecays; ijetset++ )
559 if ( jetsetdecays[ijetset]->
getParentId() == ipar )
560 { br_sum += jetsetdecays[ijetset]->getBranchingFraction(); }
564 { br_sum += jetsetdecays[ijetset]->getBranchingFraction(); }
567 double br_sum_true = br_sum;
569 if ( br_sum < 0.000001 ) br_sum = 1.0;
571 for ( ijetset = 0; ijetset < njetsetdecays; ijetset++ )
573 if ( jetsetdecays[ijetset]->
getParentId() == ipar )
576 double br = jetsetdecays[ijetset]->getBranchingFraction();
581 for ( i = 0; i < 5; i++ )
584 if ( i < jetsetdecays[ijetset]->
getNDaug() )
589 else { daugs[i] = 0; }
596 jetsetdecays[ijetset]->
getNDaug(), cdaugs, jetsetdecays[ijetset]->
getNArg(),
599 if ( jetsetdecays[ijetset]->
getModelName() ==
"PYTHIA" )
605 WritePythiaEntryHeader( outdec,
619 for ( i = 0; i < jetsetdecays[ijetset]->getNDaug(); i++ )
684 outdec << (int)jetsetdecays[ijetset]->
getArgs()[0];
686 if ( fabs( br ) < 0.000000001 ) { outdec <<
"0.00000"; }
687 else { outdec << br / br_sum; }
706bool EvtPythia::diquark(
int ID ) {
733 case 5503:
return true;
break;
734 default:
return false;
break;
738double EvtPythia::NominalMass(
int ID ) {
742 case 1103:
return 0.77133;
743 case 2101:
return 0.57933;
744 case 2103:
return 0.77133;
745 case 2203:
return 0.77133;
746 case 3101:
return 0.80473;
747 case 3103:
return 0.92953;
748 case 3201:
return 0.80473;
749 case 3203:
return 0.92953;
750 case 3303:
return 1.09361;
751 case 4101:
return 1.96908;
752 case 4103:
return 2.00808;
753 case 4201:
return 1.96908;
754 case 4203:
return 2.00808;
755 case 4301:
return 2.15432;
756 case 4303:
return 2.17967;
757 case 4403:
return 3.27531;
758 case 5101:
return 5.38897;
759 case 5103:
return 5.40145;
760 case 5201:
return 5.38897;
761 case 5203:
return 5.40145;
762 case 5301:
return 5.56725;
763 case 5303:
return 5.57536;
764 case 5401:
return 6.67143;
765 case 5403:
return 6.67397;
766 case 5503:
return 10.07354;
break;
767 default:
return 0.0;
break;
775 case 1103:
return -2;
779 case 3101:
return -2;
780 case 3103:
return -2;
783 case 3303:
return -2;
791 case 5101:
return -2;
792 case 5103:
return -2;
795 case 5301:
return -2;
796 case 5303:
return -2;
799 case 5503:
return -2;
break;
800 default:
return 0;
break;
804void EvtPythia::MakePythiaFile(
char* fname ) {
813 outdec.open( fname );
823 for ( lundkc = 1; lundkc < 500; lundkc++ )
833 ipar = EvtId( iipar, iipar );
837 if ( realId.
isAlias() != 0 )
continue;
850 WritePythiaParticle( outdec, ipar, ipar, first );
854 if ( ipar2 != ipar ) { WritePythiaParticle( outdec, ipar2, ipar, first ); }
858 WritePythiaEntryHeader( outdec,
869 if ( lundkc == 99999 )
873 ipar = EvtId( iipar, iipar );
882 WritePythiaParticle( outdec, ipar, ipar, first );
886 if ( ipar2 != ipar ) { WritePythiaParticle( outdec, ipar2, ipar, first ); }
890 WritePythiaEntryHeader(
911 static int first = 1;
917 report(
INFO,
"EvtGen" ) <<
"Will initialize Pythia." << endl;
918 for (
int i = 0; i < ncommand; i++ )
919 pygive_( commands[i].c_str(), strlen( commands[i].c_str() ) );
923 char hostBuffer[100];
925 if ( gethostname( hostBuffer, 100 ) != 0 )
927 report(
ERROR,
"EvtGen" ) <<
" couldn't get hostname." << endl;
928 strncpy( hostBuffer,
"hostnameNotFound", 100 );
933 int thePid = getpid();
935 if (
sprintf( pid,
"%d", thePid ) == 0 )
937 report(
ERROR,
"EvtGen" ) <<
" couldn't get process ID." << endl;
938 strncpy( pid,
"666", 100 );
941 strcpy( fname,
"jet.d-" );
942 strcat( fname, hostBuffer );
943 strcat( fname,
"-" );
944 strcat( fname, pid );
946 MakePythiaFile( fname );
950 if ( 0 == getenv(
"EVTSAVEJETD" ) )
953 strcpy( delcmd,
"rm -f " );
954 strcat( delcmd, fname );
958 report(
INFO,
"EvtGen" ) <<
"Done initializing Pythia." << endl;
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
EvtDecayBase * EvtDecayBasePtr
EvtDiracSpinor boostTo(const EvtDiracSpinor &sp, const EvtVector4R p4)
DOUBLE_PRECISION count[3]
struct @125167362051102326102214011354340031122345135231 cbbeam_
int NominalCharge(int ID)
void pygive_(const char *cnfgstr, int length)
void pycontinuum_(double *, int *, int *, double *, double *, double *, double *)
void evtpythiainit_(const char *fname, int len)
void pythiadec_(int *, double *, int *, int *, int *, double *, double *, double *, double *)
EvtDecayBase * EvtDecayBasePtr
ostream & report(Severity severity, const char *facility)
************Class m_ypar INTEGER m_KeyWgt INTEGER m_KeyIHVP INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input READ never touch them !$ !debug facility $ !maximum weight $ !inverse alfaQED $ !minimum real photon energy
std::string * getArgsStr()
std::string getModelName()
void checkNArg(int a1, int a2=-1, int a3=-1, int a4=-1)
void setDaughterSpinDensity(int daughter)
static int findChannel(EvtId parent, std::string model, int ndaug, EvtId *daugs, int narg, std::string *args)
static int inChannelList(EvtId parent, int ndaug, EvtId *daugs)
static double getWidth(EvtId i)
static int getStdHep(EvtId id)
static double getMeanMass(EvtId i)
static EvtId evtIdFromStdHep(int stdhep)
static std::string name(EvtId i)
static EvtId chargeConj(EvtId id)
static double getMinMass(EvtId i)
static int getLundKC(EvtId id)
static EvtId getId(const std::string &name)
static double getctau(EvtId i)
void setSpinDensityForwardHelicityBasis(const EvtSpinDensity &rho)
void makeDaughters(int ndaug, EvtId *id)
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
void setDiagonalSpinDensity()
const EvtVector4R & getP4() const
EvtParticle * getDaug(int i)
void deleteDaughters(bool keepChannel=false)
static void pythiaInit(int f)
static void pythiacont(double *, int *, int *, double *, double *, double *, double *)
void command(std::string cmd)
void decay(EvtParticle *p)
void getName(std::string &name)
std::string commandName()
void Set(int i, int j, const EvtComplex &rhoij)
void set(int i, double d)