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 ) ;
363 HepMC::GenCrossSection xsec;
367 xsec.set_cross_section(cs, cserr);
368 event()->set_cross_section(xsec);
374 event()->weights().push_back(
pyint1.vint[96] * 1.0e9 );
380 event()->weights().push_back( 1./(
pyint1.vint[98]) );
392 eventInfo()->setBinningValues( std::vector<double>(1,
pypars.pari[16]) );
401 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
403 (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
416 <<
"----------------------" << std::endl;
426 std::cout <<
"\n PYPARS \n" << std::endl;
427 std::cout << std::setw(5) << std::fixed <<
"I"
428 << std::setw(10) << std::fixed <<
"MSTP(I)"
429 << std::setw(16) << std::fixed <<
"PARP(I)"
430 << std::setw(10) << std::fixed <<
"MSTI(I)"
431 << std::setw(16) << std::fixed <<
"PARI(I)" << std::endl;
432 for (
unsigned int ind=0; ind < 200; ind++ ) {
433 std::cout << std::setw(5) << std::fixed << ind+1
434 << std::setw(10) << std::fixed <<
pypars.mstp[ind]
435 << std::setw(16) << std::fixed <<
pypars.parp[ind]
436 << std::setw(10) << std::fixed <<
pypars.msti[ind]
437 << std::setw(16) << std::fixed <<
pypars.pari[ind] << std::endl;
478 if (
pyint1.mint[50] != 0 )
549 if (
pyint1.mint[50] != 0 )
581 int NPartsAfterDecays =
event().get()->particles_size();
582 int barcode = NPartsAfterDecays;
592 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
595 int status = part->status();
596 if ( status != 1 )
continue;
598 int pdgid = part->pdg_id();
600 if ( pydat3.mdcy[0][py6ptr-1] != 1 )
continue;
601 int py6id = HepPID::translatePDTtoPythia( pdgid );
607 if ( part->momentum().t() <= part->generated_mass() )
614 for (
int i=0;
i<5;
i++ )
621 pyjets.k[1][0] = py6id;
622 pyjets.p[4][0] = part->generated_mass();
623 pyjets.p[3][0] = part->momentum().t();
624 pyjets.p[0][0] = part->momentum().x();
625 pyjets.p[1][0] = part->momentum().y();
626 pyjets.p[2][0] = part->momentum().z();
627 HepMC::GenVertex* prod_vtx = part->production_vertex();
628 if ( !prod_vtx )
continue;
629 pyjets.v[0][0] = prod_vtx->position().x();
630 pyjets.v[1][0] = prod_vtx->position().y();
631 pyjets.v[2][0] = prod_vtx->position().z();
632 pyjets.v[3][0] = prod_vtx->position().t();
645 for (
int iprt1=1; iprt1<pyjets.n; iprt1++ )
647 part->set_status( 2 );
649 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(pyjets.v[0][iprt1],
652 pyjets.v[3][iprt1]) );
653 DecVtx->add_particle_in( part );
656 HepMC::FourVector pmom(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
657 pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
660 if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
664 else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
668 else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
672 else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
674 dstatus = pyjets.k[0][iprt1];
677 HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
680 daughter->suggest_barcode( barcode );
681 DecVtx->add_particle_out( daughter );
684 for ( iprt2=iprt1+1; iprt2<pyjets.n; iprt2++ )
686 if ( pyjets.k[2][iprt2] != parent )
688 parent = pyjets.k[2][iprt2];
692 HepMC::FourVector pmomN(pyjets.p[0][iprt2],pyjets.p[1][iprt2],
693 pyjets.p[2][iprt2],pyjets.p[3][iprt2] );
696 if ( pyjets.k[0][iprt2] >= 1 && pyjets.k[0][iprt2] <= 10 )
700 else if ( pyjets.k[0][iprt2] >= 11 && pyjets.k[0][iprt2] <= 20 )
704 else if ( pyjets.k[0][iprt2] >= 21 && pyjets.k[0][iprt2] <= 30 )
708 else if ( pyjets.k[0][iprt2] >= 31 && pyjets.k[0][iprt2] <= 100 )
710 dstatus = pyjets.k[0][iprt2];
713 HepPID::translatePythiatoPDT( pyjets.k[1][iprt2] ),
716 daughterN->suggest_barcode( barcode );
717 DecVtx->add_particle_out( daughterN );
723 event().get()->add_vertex( DecVtx );
739 for (
int i=0;
i<5;
i++ )
795 call_pyinit(
"USER",
"",
"", 0.0);
802 <<
"Pythia6 hadronisation found an SLHA header, "
803 <<
"will be passed on to Pythia." << std::endl;
861 call_pyinit(
"3mom",
"e-",
"p", 0.0 );
873 call_pyinit(
"3mom",
"e+",
"p", 0.0 );
879 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
893 for (
unsigned int i=0;
i<pdg.size();
i++ )
895 int PyID = HepPID::translatePDTtoPythia( pdg[
i] );
900 std::ostringstream pyCard ;
901 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
915 for (
unsigned int iss=0; iss<settings.size(); iss++ )
917 if ( settings[iss].
find(
"QED-brem-off") == std::string::npos )
continue;
918 size_t fnd1 = settings[iss].find(
":");
919 if ( fnd1 == std::string::npos )
continue;
923 if ( value ==
"all" )
929 int number = atoi(value.c_str());
930 int PyID = HepPID::translatePDTtoPythia( number );
941 <<
" Fatal conflict: \n mandatory internal directive to set MSTJ(39)=" << pyCode
942 <<
" overrides user setting MSTJ(39)=" <<
pydat1_.mstj[38] <<
" - user will not get expected behaviour \n";
944 std::ostringstream pyCard ;
945 pyCard <<
"MSTJ(39)=" << pyCode ;
962 HepMC::GenEvent::vertex_const_iterator
vbegin =
event()->vertices_begin();
963 HepMC::GenEvent::vertex_const_iterator
vend =
event()->vertices_end();
964 HepMC::GenEvent::vertex_const_iterator vitr =
vbegin;
965 for (; vitr !=
vend; ++vitr )
967 HepMC::GenVertex::particle_iterator pbegin = (*vitr)->particles_begin(HepMC::children);
968 HepMC::GenVertex::particle_iterator pend = (*vitr)->particles_end(HepMC::children);
969 HepMC::GenVertex::particle_iterator pitr = pbegin;
970 for (; pitr != pend; ++pitr)
972 if ((*pitr)->end_vertex())
continue;
973 if ((*pitr)->status()!=1)
continue;
975 int pdgcode=
abs((*pitr)->pdg_id());
977 if ( pydat3.mdcy[0][
pycomp_(pdgcode)-1] !=1 )
continue;
979 double ctau = pydat2.pmas[3][
pycomp_(pdgcode)-1];
980 HepMC::FourVector mom = (*pitr)->momentum();
981 HepMC::FourVector vin = (*vitr)->position();
986 bool decayInRange =
false;
987 while (!decayInRange)
991 double proper_length = - ctau *
log(unif_rand);
992 double factor = proper_length/mom.m();
993 x = vin.x() + factor * mom.px();
994 y = vin.y() + factor * mom.py();
995 z = vin.z() + factor * mom.pz();
996 t = vin.t() + factor * mom.e();
1002 else if (
pydat1.mstj[21]==3) {
1007 decayInRange =
true;
1011 HepMC::GenVertex* vdec =
new HepMC::GenVertex(HepMC::FourVector(x,y,z,t));
1012 event()->add_vertex(vdec);
1013 vdec->add_particle_in((*pitr));
1024 if ( !
runInfo().internalXSec() )
1041 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()
T x() const
Cartesian x coordinate.
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)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
static const std::string kFortranInstance
static FortranCallback * getInstance()
static struct gen::@498 pyjets_local
Pythia6Service * fPy6Service
void setLHEEvent(lhef::LHEEvent *lhee)
bool generatePartonsAndHadronize()
virtual void beforeHadronisationExec()
void setRandomEngine(CLHEP::HepRandomEngine *v)
return(e1-e2)*(e1-e2)+dp *dp
void resetIterationsPerEvent()
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