8 #include <boost/shared_ptr.hpp>
9 #include <boost/algorithm/string/classification.hpp>
10 #include <boost/algorithm/string/split.hpp>
11 #include <HepMC/GenEvent.h>
12 #include <HepMC/GenParticle.h>
13 #include <HepMC/GenVertex.h>
14 #include <HepMC/PdfInfo.h>
15 #include <HepMC/HerwigWrapper.h>
16 #include <HepMC/HEPEVT_Wrapper.h>
17 #include <HepMC/IO_HERWIG.h>
18 #include "HepPID/ParticleIDTranslations.hh"
43 class HepRandomEngine;
47 void hwuidt_(
int *iopt,
int *ipdg,
int *iwig,
char nwig[8]);
54 static inline bool call_hwmatch()
60 static inline bool call_hwmsct()
67 static int pdgToHerwig(
int ipdg,
char *nwig)
71 hwuidt_(&iopt, &ipdg, &iwig, nwig);
72 return ipdg ? iwig : 0;
75 static bool markStable(
int pdgId)
78 if (!pdgToHerwig(pdgId, nwig))
114 const char *
classname()
const {
return "Herwig6Hadronizer"; }
126 virtual void upInit()
override;
127 virtual void upEvnt()
override;
170 BaseHadronizer(params),
173 herwigVerbosity(params.getUntrackedParameter<int>(
"herwigVerbosity", 0)),
174 hepmcVerbosity(params.getUntrackedParameter<int>(
"hepmcVerbosity", 0)),
176 printCards(params.getUntrackedParameter<bool>(
"printCards",
false)),
177 emulatePythiaStatusCodes(params.getUntrackedParameter<bool>(
"emulatePythiaStatusCodes",
false)),
178 comEnergy(params.getParameter<double>(
"comEnergy")),
179 useJimmy(params.getParameter<bool>(
"useJimmy")),
180 doMPInteraction(params.getParameter<bool>(
"doMPInteraction")),
181 numTrials(params.getUntrackedParameter<int>(
"numTrialsMPI", 100)),
182 doMatching(params.getUntrackedParameter<bool>(
"doMatching",
false)),
183 inclusiveMatching(params.getUntrackedParameter<bool>(
"inclusiveMatching",
true)),
184 nMatch(params.getUntrackedParameter<int>(
"nMatch", 0)),
185 matchingScale(params.getUntrackedParameter<double>(
"matchingScale", 0.0)),
186 readMCatNLOfile(
false),
189 particleSpecFileName(params.getUntrackedParameter<std::
string>(
"ParticleSpectrumFileName",
"")),
190 readParticleSpecFile(params.getUntrackedParameter<bool>(
"readParticleSpecFile",
false))
195 if ( params.
exists(
"doPDGConvert" ) )
223 const std::vector<std::string> &
lines)
225 std::set<std::string>
blocks;
227 for(std::vector<std::string>::const_iterator iter = lines.begin();
228 iter != lines.end(); ++iter) {
231 line.begin(), (int(*)(int))std::toupper);
233 if (pos != std::string::npos)
239 if (!boost::algorithm::is_space()(line[0])) {
240 std::vector<std::string> tokens;
242 boost::algorithm::is_space(),
243 boost::token_compress_on);
247 if (tokens.size() < 2)
249 if (tokens[0] ==
"BLOCK")
251 else if (tokens[0] ==
"DECAY")
257 if (!blocks.count(block)) {
258 blocks.insert(block);
260 <<
"Unsupported SLHA block \"" << block
261 <<
"\". It will be ignored."
278 std::ostringstream
info;
279 info <<
"---------------------------------------------------\n";
280 info <<
"Taking in settinsg for Herwig6Hadronizer for "
282 info <<
"---------------------------------------------------\n";
293 hwproc.PBEAM1 = heprup->
EBMUP.first;
294 hwproc.PBEAM2 = heprup->
EBMUP.second;
295 pdgToHerwig(heprup->
IDBMUP.first, hwbmch.PART1);
296 pdgToHerwig(heprup->
IDBMUP.second, hwbmch.PART2);
302 pdgToHerwig(2212, hwbmch.PART1);
303 pdgToHerwig(2212, hwbmch.PART2);
319 info <<
" HERWIG will be using JIMMY for UE/MI.\n";
322 info <<
" JIMMY trying to generate multiple interactions.\n";
328 bool iprocFound=
false;
333 if(!strcmp((
line->substr(0,5)).c_str(),
"IPROC")) {
336 <<
"Herwig 6 did not accept the following: \""
337 << *
line <<
"\"." << std::endl;
338 else iprocFound=
true;
344 <<
"You have to define the process with IPROC." << std::endl;
349 hwevnt.MAXER = 100000000;
355 for(
unsigned int i = 0;
i < 2;
i++) {
356 hwpram.MODPDF[
i] = -111;
357 std::memcpy(
hwprch.AUTPDF[
i],
"HWLHAPDF", 8);
366 info <<
"------------------------------------\n";
367 info <<
"Reading HERWIG parameters\n";
368 info <<
"------------------------------------\n";
374 info <<
" " << *
line <<
"\n";
377 <<
"Herwig 6 did not accept the following: \""
378 << *line <<
"\"." << std::endl;
385 std::vector<std::string> slha =
393 std::pair<int, int> pdfs(-1, -1);
397 if (hwpram.MODPDF[0] != -111 || hwpram.MODPDF[1] != -111) {
398 for(
unsigned int i = 0;
i < 2;
i++)
399 if (hwpram.MODPDF[
i] == -111)
400 hwpram.MODPDF[
i] = -1;
402 if (pdfs.first != -1 || pdfs.second != -1)
404 <<
"Both external Les Houches event and "
405 "config file specify a PDF set. "
406 "User PDF will override external one."
409 pdfs.first = hwpram.MODPDF[0] != -111 ? hwpram.MODPDF[0] : -1;
410 pdfs.second = hwpram.MODPDF[1] != -111 ? hwpram.MODPDF[1] : -1;
413 printf(
"pdfs.first = %i, pdfs.second = %i\n",pdfs.first,pdfs.second);
415 hwpram.MODPDF[0] = pdfs.first;
416 hwpram.MODPDF[1] = pdfs.second;
425 hwpram.EFFMIN = 1
e-5;
460 std::ostringstream
info;
461 info <<
"---------------------------------------------------\n";
462 info <<
"Initializing Herwig6Hadronizer for "
464 info <<
"---------------------------------------------------\n";
475 hwproc.PBEAM1 = heprup->
EBMUP.first;
476 hwproc.PBEAM2 = heprup->
EBMUP.second;
477 pdgToHerwig(heprup->
IDBMUP.first, hwbmch.PART1);
478 pdgToHerwig(heprup->
IDBMUP.second, hwbmch.PART2);
482 pdgToHerwig(2212, hwbmch.PART1);
483 pdgToHerwig(2212, hwbmch.PART2);
487 info <<
" HERWIG will be using JIMMY for UE/MI.\n";
490 info <<
" JIMMY trying to generate multiple interactions.\n";
495 bool iprocFound=
false;
499 if(!strcmp((
line->substr(0,5)).c_str(),
"IPROC")) {
502 <<
"Herwig 6 did not accept the following: \""
503 << *
line <<
"\"." << std::endl;
504 else iprocFound=
true;
510 <<
"You have to define the process with IPROC." << std::endl;
514 hwevnt.MAXER = 100000000;
522 for(
unsigned int i = 0;
i < 2;
i++) {
523 hwpram.MODPDF[
i] = -111;
524 std::memcpy(
hwprch.AUTPDF[
i],
"HWLHAPDF", 8);
536 info <<
"------------------------------------\n";
537 info <<
"Reading HERWIG parameters\n";
538 info <<
"------------------------------------\n";
544 info <<
" " << *
line <<
"\n";
547 <<
"Herwig 6 did not accept the following: \""
548 << *line <<
"\"." << std::endl;
555 std::vector<std::string> slha =
563 std::pair<int, int> pdfs(-1, -1);
567 if (hwpram.MODPDF[0] != -111 || hwpram.MODPDF[1] != -111) {
568 for(
unsigned int i = 0;
i < 2;
i++)
569 if (hwpram.MODPDF[
i] == -111)
570 hwpram.MODPDF[
i] = -1;
572 if (pdfs.first != -1 || pdfs.second != -1)
574 <<
"Both external Les Houches event and "
575 "config file specify a PDF set. "
576 "User PDF will override external one."
579 pdfs.first = hwpram.MODPDF[0] != -111 ? hwpram.MODPDF[0] : -1;
580 pdfs.second = hwpram.MODPDF[1] != -111 ? hwpram.MODPDF[1] : -1;
583 printf(
"pdfs.first = %i, pdfs.second = %i\n",pdfs.first,pdfs.second);
585 hwpram.MODPDF[0] = pdfs.first;
586 hwpram.MODPDF[1] = pdfs.second;
594 hwpram.EFFMIN = 1
e-5;
657 for(std::vector<int>::const_iterator iter = pdgIds.begin();
658 iter != pdgIds.end(); ++iter)
659 if (!markStable(*iter))
671 if (!
runInfo().internalXSec()) {
676 double RNWGT = 1. / hwevnt.NWGTS;
677 double AVWGT = hwevnt.WGTSUM * RNWGT;
679 double xsec = 1.0e3 * AVWGT;
739 bool pass = call_hwmatch();
741 printf(
"Event failed MLM matching\n");
750 if (!
conv.fill_next_event(
event().
get()))
752 <<
"HepMC Conversion problems in event." << std::endl;
756 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
part !=
event()->particles_end(); ++
part) {
757 if ((*part)->pdg_id() != HepPID::translateHerwigtoPDT((*part)->pdg_id()))
758 (*part)->set_pdg_id(HepPID::translateHerwigtoPDT((*part)->pdg_id()));
769 HepMC::PdfInfo pdfInfo;
775 if(
event()->signal_process_id()==0)
776 event()->set_signal_process_id(
abs(hwproc.IPROC) );
787 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
788 (it !=
event()->particles_end() && incomingParton==
NULL); it++)
789 if((*it)->status()==121) incomingParton = (*it);
792 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
793 (it !=
event()->particles_end() && targetParton==
NULL); it++)
794 if((*it)->status()==122) targetParton = (*it);
797 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
798 (it !=
event()->particles_end() && incomingProton==
NULL); it++)
799 if((*it)->status()==101 && (*it)->pdg_id()==2212) incomingProton = (*it);
802 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
803 (it !=
event()->particles_end() && targetProton==
NULL); it++)
804 if((*it)->status()==102 && (*it)->pdg_id()==2212) targetProton = (*it);
807 if( incomingParton && targetParton ) {
809 totMomentum+=incomingParton->momentum();
810 totMomentum+=targetParton->momentum();
811 double evScale = totMomentum.mass();
812 double evScale2 = evScale*evScale;
816 double alphaQCD=
hwualf_(&one,&evScale);
817 double alphaQED=
hwuaem_(&evScale2);
825 pdfInfo.set_id1( incomingParton->pdg_id()==21 ? 0 : incomingParton->pdg_id());
826 pdfInfo.set_id2( targetParton->pdg_id()==21 ? 0 : targetParton->pdg_id());
827 if( incomingProton && targetProton ) {
828 double x1 = incomingParton->momentum().pz()/incomingProton->momentum().pz();
829 double x2 = targetParton->momentum().pz()/targetProton->momentum().pz();
834 pdfInfo.set_scalePDF(evScale);
838 event()->set_pdf_info( pdfInfo );
845 event()->weights().push_back( 1.0e3 * hwevnt.EVWGT );
847 event()->weights().push_back( hwevnt.EVWGT );
852 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
853 (it !=
event()->particles_end() && finalParton==
NULL); it++)
854 if((*it)->status()==123) finalParton = (*it);
860 double thisPt=finalParton->momentum().perp();
861 eventInfo()->setBinningValues(std::vector<double>(1, thisPt));
933 for(std::vector<lhef::LHERunInfo::Header>::const_iterator hIter=headers.begin();hIter!=headers.end(); ++hIter) {
934 if(hIter->tag()==mcnloHeader){
937 if((lIter->c_str())[0]!=
'#' && (lIter->c_str())[0]!=
'\n') {
940 <<
"Herwig 6 did not accept the following: \""
941 << *lIter <<
"\"." << std::endl;
954 for(std::vector<std::string>::const_iterator iter=
lheEvent()->getComments().
begin();
959 <<
"Herwig 6 did not accept the following: \""
960 << toParse <<
"\"." << std::endl;
971 if (status == 3 && !p->end_vertex())
974 if (status >= 1 && status <= 3)
977 if (!p->end_vertex())
982 int currentId = p->pdg_id();
984 if (status == 123 || status == 124 ||
985 status == 155 || status == 156 || status == 160 ||
986 (status >= 195 && status <= 197)) {
988 const HepMC::GenVertex *vtx =
q->end_vertex();
992 HepMC::GenVertex::particles_out_const_iterator iter;
993 for(iter = vtx->particles_out_const_begin();
994 iter != vtx->particles_out_const_end(); ++iter)
995 if ((*iter)->pdg_id() == currentId)
998 if (iter == vtx->particles_out_const_end())
1002 if (
q->status() == 3 ||
1003 ((status == 120 || status == 123 ||
1004 status == 124) && orig > 124))
1011 if ((status >= 120 && status <= 122) || status == 3) {
1015 return ((orig >= 121 && orig <= 124) ||
1019 (status != 3 && orig <= 124)) ? 3 : 4;
1024 if (!(status == 4 || status == 123 || status == 124 ||
1025 status == 155 || status == 156 || status == 160 ||
1026 (status >= 195 && status <= 197)))
1029 const HepMC::GenVertex *vtx = p->production_vertex();
1030 if (!vtx || !vtx->particles_in_size())
1033 p = *vtx->particles_in_const_begin();
1034 status = p->status();
1036 int newId = p->pdg_id();
1042 if (newId != currentId) {
1054 for(HepMC::GenEvent::particle_iterator iter =
1055 event()->particles_begin();
1056 iter !=
event()->particles_end(); iter++)
1059 for(HepMC::GenEvent::particle_iterator iter =
1060 event()->particles_begin();
1061 iter !=
event()->particles_end(); iter++)
1062 if ((*iter)->status() == 4)
1063 (*iter)->set_status(2);
T getParameter(std::string const &) const
bool readParticleSpecFile
void setSLHAFromHeader(const std::vector< std::string > &lines)
bool declareStableParticles(const std::vector< int > &pdgIds)
#define DEFINE_FWK_MODULE(type)
void fillEventInfo(HepMC::GenEvent *hepmc) const
std::pair< double, double > EBMUP
const char * classname() const
edm::HadronizerFilter< Herwig6Hadronizer, gen::ExternalDecayDriver > Herwig6HadronizerFilter
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static void fixHepMCEventTimeOrdering(HepMC::GenEvent *event)
void openParticleSpecFile(const std::string fileName)
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::pair< int, int > IDBMUP
bool generatePartonsAndHadronize()
edm::GeneratorFilter< Herwig6Hadronizer, gen::ExternalDecayDriver > Herwig6GeneratorFilter
bool initialize(const lhef::HEPRUP *heprup)
void setInternalXSec(const XSec &xsec)
std::auto_ptr< HepMC::GenEvent > & event()
int pythiaStatusCode(const HepMC::GenParticle *p) const
double hwualf_(int *mode, double *scale)
double hwuaem_(double *scale)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
GenRunInfoProduct & runInfo()
bool initializeForInternalPartons()
void hwuidt_(int *iopt, int *ipdg, int *iwig, char nwig[8])
const std::vector< std::string > & getComments() const
void mysetpdfpath_(const char *path)
lhef::LHEEvent * lheEvent()
bool callWithTimeout(unsigned int secs, void(*fn)())
virtual std::vector< std::string > const & doSharedResources() const override
void hwwarn_(const char *method, int *id)
static void fillHEPEUP(const HEPEUP *hepeup)
void fillPdfInfo(HepMC::PdfInfo *info) const
Abs< T >::type abs(const T &t)
const std::vector< Header > & getHeaders() const
static const std::vector< std::string > theSharedResources
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::auto_ptr< GenEventInfoProduct > & eventInfo()
bool give(const std::string &line)
lhef::LHERunInfo * lheRunInfo()
static const std::string kFortranInstance
bool declareSpecialSettings(const std::vector< std::string > &)
virtual void upEvnt() override
const HEPRUP * getHEPRUP() const
std::string particleSpecFileName
std::pair< int, int > pdfSetTranslation() const
bool emulatePythiaStatusCodes
const_iterator end() const
Herwig6Hadronizer(const edm::ParameterSet ¶ms)
void setHerwigRandomEngine(CLHEP::HepRandomEngine *v)
const_iterator begin() const
std::vector< std::string > findHeader(const std::string &tag) const
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
volatile std::atomic< bool > shutdown_flag false
static const std::string kHerwig6
gen::ParameterCollector parameters
bool initializeForExternalPartons()
virtual void upInit() override
static void fillHEPRUP(const HEPRUP *heprup)
static HepMC::HEPEVT_Wrapper wrapper