6 #include "HepMC/GenEvent.h"
7 #include "HepMC/PdfInfo.h"
8 #include "HepMC/PythiaWrapper6_4.h"
9 #include "HepMC/HEPEVT_Wrapper.h"
10 #include "HepMC/IO_HEPEVT.h"
27 #include "HepPID/ParticleIDTranslations.hh"
61 class Pythia6ServiceWithCallback :
public Pythia6Service {
95 int n,
npad,
k[5][pyjets_maxn];
96 double p[5][pyjets_maxn],
v[5][pyjets_maxn];
108 fCOMEnergy(ps.getParameter<double>(
"comEnergy")),
109 fHepMCVerbosity(ps.getUntrackedParameter<bool>(
"pythiaHepMCVerbosity",
false)),
110 fMaxEventsToPrint(ps.getUntrackedParameter<int>(
"maxEventsToPrint", 0)),
111 fPythiaListVerbosity(ps.getUntrackedParameter<int>(
"pythiaPylistVerbosity", 0)),
112 fDisplayPythiaBanner(ps.getUntrackedParameter<bool>(
"displayPythiaBanner",
false)),
113 fDisplayPythiaCards(ps.getUntrackedParameter<bool>(
"displayPythiaCards",
false))
119 if ( ps.
exists(
"PPbarInitialState" ) )
125 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
126 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
127 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
128 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
135 else if ( ps.
exists(
"ElectronPositronInitialState" ) )
141 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
142 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
143 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
144 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
151 else if ( ps.
exists(
"ElectronProtonInitialState" ) )
159 <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE. "
160 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
161 std::cout <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE." << std::endl;
162 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
169 else if ( ps.
exists(
"PositronProtonInitialState" ) )
177 <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE. "
178 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
179 std::cout <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE." << std::endl;
180 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
186 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
197 if ( ps.
exists(
"stopHadrons" ) )
201 if ( ps.
exists(
"gluinoHadrons" ) )
205 if ( ps.
exists(
"imposeProperTime" ) )
211 if ( ps.
exists(
"doPDGConvert" ) )
214 if ( ps.
exists(
"jetMatching") )
230 <<
" Pythia did not accept MSTU(12)=12345";
241 <<
" Pythia did not accept MSTU(13)=0";
267 for (
int ip=0; ip<pyjets_maxn; ip++ )
269 for (
int i=0;
i<5;
i++ )
285 for (
int ip=0; ip<pyjets_maxn; ip++ )
287 for (
int i=0;
i<5;
i++ )
318 if (
event()->signal_process_id() <= 0)
event()->set_signal_process_id(
pypars.msti[0] );
319 if (
event()->event_scale() <=0 )
event()->set_event_scale(
pypars.pari[22] );
326 if ( pdf.id1() <= 0) pdf.set_id1(
pyint1.mint[14] == 21 ? 0 :
pyint1.mint[14] );
327 if ( pdf.id2() <= 0) pdf.set_id2(
pyint1.mint[15] == 21 ? 0 :
pyint1.mint[15] );
328 if ( pdf.x1() <= 0) pdf.set_x1(
pyint1.vint[40] );
329 if ( pdf.x2() <= 0) pdf.set_x2(
pyint1.vint[41] );
330 if ( pdf.pdf1() <= 0) pdf.set_pdf1(
pyint1.vint[38] /
pyint1.vint[40] );
331 if ( pdf.pdf2() <= 0) pdf.set_pdf2(
pyint1.vint[39] /
pyint1.vint[41] );
332 if ( pdf.scalePDF() <= 0) pdf.set_scalePDF(
pyint1.vint[50] );
361 event()->set_pdf_info( pdf ) ;
367 event()->weights().push_back(
pyint1.vint[96] * 1.0e9 );
373 event()->weights().push_back( 1./(
pyint1.vint[98]) );
385 eventInfo()->setBinningValues( std::vector<double>(1,
pypars.pari[16]) );
394 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
396 (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
409 <<
"----------------------" << std::endl;
419 std::cout <<
"\n PYPARS \n" << std::endl;
420 std::cout << std::setw(5) << std::fixed <<
"I"
421 << std::setw(10) << std::fixed <<
"MSTP(I)"
422 << std::setw(16) << std::fixed <<
"PARP(I)"
423 << std::setw(10) << std::fixed <<
"MSTI(I)"
424 << std::setw(16) << std::fixed <<
"PARI(I)" << std::endl;
425 for (
unsigned int ind=0; ind < 200; ind++ ) {
426 std::cout << std::setw(5) << std::fixed << ind+1
427 << std::setw(10) << std::fixed <<
pypars.mstp[ind]
428 << std::setw(16) << std::fixed <<
pypars.parp[ind]
429 << std::setw(10) << std::fixed <<
pypars.msti[ind]
430 << std::setw(16) << std::fixed <<
pypars.pari[ind] << std::endl;
471 if (
pyint1.mint[50] != 0 )
542 if (
pyint1.mint[50] != 0 )
574 int NPartsAfterDecays =
event().get()->particles_size();
575 int barcode = NPartsAfterDecays;
585 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
588 int status = part->status();
589 if ( status != 1 )
continue;
591 int pdgid = part->pdg_id();
593 if ( pydat3.mdcy[0][py6ptr-1] != 1 )
continue;
594 int py6id = HepPID::translatePDTtoPythia( pdgid );
600 if ( part->momentum().t() <= part->generated_mass() )
607 for (
int i=0;
i<5;
i++ )
614 pyjets.k[1][0] = py6id;
615 pyjets.p[4][0] = part->generated_mass();
616 pyjets.p[3][0] = part->momentum().t();
617 pyjets.p[0][0] = part->momentum().x();
618 pyjets.p[1][0] = part->momentum().y();
619 pyjets.p[2][0] = part->momentum().z();
620 HepMC::GenVertex* prod_vtx = part->production_vertex();
621 if ( !prod_vtx )
continue;
622 pyjets.v[0][0] = prod_vtx->position().x();
623 pyjets.v[1][0] = prod_vtx->position().y();
624 pyjets.v[2][0] = prod_vtx->position().z();
625 pyjets.v[3][0] = prod_vtx->position().t();
638 for (
int iprt1=1; iprt1<pyjets.n; iprt1++ )
640 part->set_status( 2 );
642 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(pyjets.v[0][iprt1],
645 pyjets.v[3][iprt1]) );
646 DecVtx->add_particle_in( part );
649 HepMC::FourVector pmom(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
650 pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
653 if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
657 else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
661 else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
665 else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
667 dstatus = pyjets.k[0][iprt1];
670 HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
673 daughter->suggest_barcode( barcode );
674 DecVtx->add_particle_out( daughter );
677 for ( iprt2=iprt1+1; iprt2<pyjets.n; iprt2++ )
679 if ( pyjets.k[2][iprt2] != parent )
681 parent = pyjets.k[2][iprt2];
685 HepMC::FourVector pmomN(pyjets.p[0][iprt2],pyjets.p[1][iprt2],
686 pyjets.p[2][iprt2],pyjets.p[3][iprt2] );
689 if ( pyjets.k[0][iprt2] >= 1 && pyjets.k[0][iprt2] <= 10 )
693 else if ( pyjets.k[0][iprt2] >= 11 && pyjets.k[0][iprt2] <= 20 )
697 else if ( pyjets.k[0][iprt2] >= 21 && pyjets.k[0][iprt2] <= 30 )
701 else if ( pyjets.k[0][iprt2] >= 31 && pyjets.k[0][iprt2] <= 100 )
703 dstatus = pyjets.k[0][iprt2];
706 HepPID::translatePythiatoPDT( pyjets.k[1][iprt2] ),
709 daughterN->suggest_barcode( barcode );
710 DecVtx->add_particle_out( daughterN );
716 event().get()->add_vertex( DecVtx );
732 for (
int i=0;
i<5;
i++ )
788 call_pyinit(
"USER",
"",
"", 0.0);
795 <<
"Pythia6 hadronisation found an SLHA header, "
796 <<
"will be passed on to Pythia." << std::endl;
854 call_pyinit(
"3mom",
"e-",
"p", 0.0 );
866 call_pyinit(
"3mom",
"e+",
"p", 0.0 );
872 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
886 for (
unsigned int i=0;
i<pdg.size();
i++ )
888 int PyID = HepPID::translatePDTtoPythia( pdg[
i] );
893 std::ostringstream pyCard ;
894 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
908 for (
unsigned int iss=0; iss<settings.size(); iss++ )
910 if ( settings[iss].
find(
"QED-brem-off") == std::string::npos )
continue;
911 size_t fnd1 = settings[iss].find(
":");
912 if ( fnd1 == std::string::npos )
continue;
916 if ( value ==
"all" )
922 int number = atoi(value.c_str());
923 int PyID = HepPID::translatePDTtoPythia( number );
934 <<
" Fatal conflict: \n mandatory internal directive to set MSTJ(39)=" << pyCode
935 <<
" overrides user setting MSTJ(39)=" <<
pydat1_.mstj[38] <<
" - user will not get expected behaviour \n";
937 std::ostringstream pyCard ;
938 pyCard <<
"MSTJ(39)=" << pyCode ;
955 HepMC::GenEvent::vertex_const_iterator
vbegin =
event()->vertices_begin();
956 HepMC::GenEvent::vertex_const_iterator
vend =
event()->vertices_end();
957 HepMC::GenEvent::vertex_const_iterator vitr =
vbegin;
958 for (; vitr !=
vend; ++vitr )
960 HepMC::GenVertex::particle_iterator pbegin = (*vitr)->particles_begin(HepMC::children);
961 HepMC::GenVertex::particle_iterator pend = (*vitr)->particles_end(HepMC::children);
962 HepMC::GenVertex::particle_iterator pitr = pbegin;
963 for (; pitr != pend; ++pitr)
965 if ((*pitr)->end_vertex())
continue;
966 if ((*pitr)->status()!=1)
continue;
968 int pdgcode=
abs((*pitr)->pdg_id());
970 if ( pydat3.mdcy[0][
pycomp_(pdgcode)-1] !=1 )
continue;
972 double ctau = pydat2.pmas[3][
pycomp_(pdgcode)-1];
973 HepMC::FourVector mom = (*pitr)->momentum();
974 HepMC::FourVector vin = (*vitr)->position();
979 bool decayInRange =
false;
980 while (!decayInRange)
984 double proper_length = - ctau *
log(unif_rand);
985 double factor = proper_length/mom.m();
986 x = vin.x() + factor * mom.px();
987 y = vin.y() + factor * mom.py();
988 z = vin.z() + factor * mom.pz();
989 t = vin.t() + factor * mom.e();
995 else if (
pydat1.mstj[21]==3) {
1000 decayInRange =
true;
1004 HepMC::GenVertex* vdec =
new HepMC::GenVertex(HepMC::FourVector(x,y,z,t));
1005 event()->add_vertex(vdec);
1006 vdec->add_particle_in((*pitr));
1017 if ( !
runInfo().internalXSec() )
1034 return "gen::Pythia6Hadronizer";
T getParameter(std::string const &) const
static std::auto_ptr< JetMatching > create(const edm::ParameterSet ¶ms)
T getUntrackedParameter(std::string const &, T const &) const
auto_ptr< ClusterSequence > cs
unsigned int fPythiaListVerbosity
bool fDisplayPythiaBanner
Pythia6ServiceWithCallback(const edm::ParameterSet &ps)
unsigned int fMaxEventsToPrint
static HepMC::IO_HEPEVT conv
void fillEventInfo(HepMC::GenEvent *hepmc) const
static JetMatching * getJetMatching()
bool call_pygive(const std::string &line)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const char * classname() const
void setLHERunInfo(lhef::LHERunInfo *lheri)
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
virtual void beforeHadronisation(const lhef::LHEEvent *event)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void setInternalXSec(const XSec &xsec)
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::auto_ptr< HepMC::GenEvent > & event()
bool initializeForInternalPartons()
virtual int match(const lhef::LHEEvent *partonLevel, const std::vector< fastjet::PseudoJet > *jetInput)=0
static const std::string kPythia6
GenRunInfoProduct & runInfo()
bool declareStableParticles(const std::vector< int > &)
void call_pylist(int mode)
void resetMatchingStatus()
lhef::LHEEvent * lheEvent()
static const std::vector< std::string > theSharedResources
void setSLHAFromHeader(const std::vector< std::string > &lines)
void fillPdfInfo(HepMC::PdfInfo *info) const
Abs< T >::type abs(const T &t)
void setPYUPDAParams(bool afterPyinit)
bool initializeForExternalPartons()
Pythia6Hadronizer(edm::ParameterSet const &ps)
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
static const std::string kFortranInstance
static FortranCallback * getInstance()
Pythia6Service * fPy6Service
void setLHEEvent(lhef::LHEEvent *lhee)
bool generatePartonsAndHadronize()
virtual void beforeHadronisationExec()
void setRandomEngine(CLHEP::HepRandomEngine *v)
void resetIterationsPerEvent()
static struct gen::@479 pyjets_local
bool fGluinoHadronsEnabled
bool declareSpecialSettings(const std::vector< std::string > &)
std::vector< std::string > findHeader(const std::string &tag) const
volatile std::atomic< bool > shutdown_flag false
virtual void init(const lhef::LHERunInfo *runInfo)
static JetMatching * fJetMatching