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"
41 void hwuidt_(
int *iopt,
int *ipdg,
int *iwig,
char nwig[8]);
48 static inline bool call_hwmatch()
54 static inline bool call_hwmsct()
61 static int pdgToHerwig(
int ipdg,
char *nwig)
65 hwuidt_(&iopt, &ipdg, &iwig, nwig);
66 return ipdg ? iwig : 0;
69 static bool markStable(
int pdgId)
72 if (!pdgToHerwig(pdgId, nwig))
108 const char *
classname()
const {
return "Herwig6Hadronizer"; }
116 virtual void upInit()
override;
117 virtual void upEvnt()
override;
155 BaseHadronizer(params),
158 herwigVerbosity(params.getUntrackedParameter<int>(
"herwigVerbosity", 0)),
159 hepmcVerbosity(params.getUntrackedParameter<int>(
"hepmcVerbosity", 0)),
161 printCards(params.getUntrackedParameter<bool>(
"printCards",
false)),
162 emulatePythiaStatusCodes(params.getUntrackedParameter<bool>(
"emulatePythiaStatusCodes",
false)),
163 comEnergy(params.getParameter<double>(
"comEnergy")),
164 useJimmy(params.getParameter<bool>(
"useJimmy")),
165 doMPInteraction(params.getParameter<bool>(
"doMPInteraction")),
166 numTrials(params.getUntrackedParameter<int>(
"numTrialsMPI", 100)),
167 doMatching(params.getUntrackedParameter<bool>(
"doMatching",
false)),
168 inclusiveMatching(params.getUntrackedParameter<bool>(
"inclusiveMatching",
true)),
169 nMatch(params.getUntrackedParameter<int>(
"nMatch", 0)),
170 matchingScale(params.getUntrackedParameter<double>(
"matchingScale", 0.0)),
171 readMCatNLOfile(
false),
174 particleSpecFileName(params.getUntrackedParameter<std::
string>(
"ParticleSpectrumFileName",
"")),
175 readParticleSpecFile(params.getUntrackedParameter<bool>(
"readParticleSpecFile",
false))
180 if ( params.
exists(
"doPDGConvert" ) )
203 const std::vector<std::string> &
lines)
205 std::set<std::string>
blocks;
207 for(std::vector<std::string>::const_iterator iter = lines.begin();
208 iter != lines.end(); ++iter) {
211 line.begin(), (int(*)(int))std::toupper);
213 if (pos != std::string::npos)
219 if (!boost::algorithm::is_space()(line[0])) {
220 std::vector<std::string> tokens;
222 boost::algorithm::is_space(),
223 boost::token_compress_on);
227 if (tokens.size() < 2)
229 if (tokens[0] ==
"BLOCK")
231 else if (tokens[0] ==
"DECAY")
237 if (!blocks.count(block)) {
238 blocks.insert(block);
240 <<
"Unsupported SLHA block \"" << block
241 <<
"\". It will be ignored."
258 std::ostringstream
info;
259 info <<
"---------------------------------------------------\n";
260 info <<
"Taking in settinsg for Herwig6Hadronizer for "
262 info <<
"---------------------------------------------------\n";
273 hwproc.PBEAM1 = heprup->
EBMUP.first;
274 hwproc.PBEAM2 = heprup->
EBMUP.second;
275 pdgToHerwig(heprup->
IDBMUP.first, hwbmch.PART1);
276 pdgToHerwig(heprup->
IDBMUP.second, hwbmch.PART2);
282 pdgToHerwig(2212, hwbmch.PART1);
283 pdgToHerwig(2212, hwbmch.PART2);
299 info <<
" HERWIG will be using JIMMY for UE/MI.\n";
302 info <<
" JIMMY trying to generate multiple interactions.\n";
308 bool iprocFound=
false;
313 if(!strcmp((
line->substr(0,5)).c_str(),
"IPROC")) {
316 <<
"Herwig 6 did not accept the following: \""
317 << *
line <<
"\"." << std::endl;
318 else iprocFound=
true;
324 <<
"You have to define the process with IPROC." << std::endl;
329 hwevnt.MAXER = 100000000;
335 for(
unsigned int i = 0;
i < 2;
i++) {
336 hwpram.MODPDF[
i] = -111;
337 std::memcpy(
hwprch.AUTPDF[
i],
"HWLHAPDF", 8);
346 info <<
"------------------------------------\n";
347 info <<
"Reading HERWIG parameters\n";
348 info <<
"------------------------------------\n";
354 info <<
" " << *
line <<
"\n";
357 <<
"Herwig 6 did not accept the following: \""
358 << *line <<
"\"." << std::endl;
365 std::vector<std::string> slha =
373 std::pair<int, int> pdfs(-1, -1);
377 if (hwpram.MODPDF[0] != -111 || hwpram.MODPDF[1] != -111) {
378 for(
unsigned int i = 0;
i < 2;
i++)
379 if (hwpram.MODPDF[
i] == -111)
380 hwpram.MODPDF[
i] = -1;
382 if (pdfs.first != -1 || pdfs.second != -1)
384 <<
"Both external Les Houches event and "
385 "config file specify a PDF set. "
386 "User PDF will override external one."
389 pdfs.first = hwpram.MODPDF[0] != -111 ? hwpram.MODPDF[0] : -1;
390 pdfs.second = hwpram.MODPDF[1] != -111 ? hwpram.MODPDF[1] : -1;
393 printf(
"pdfs.first = %i, pdfs.second = %i\n",pdfs.first,pdfs.second);
395 hwpram.MODPDF[0] = pdfs.first;
396 hwpram.MODPDF[1] = pdfs.second;
405 hwpram.EFFMIN = 1
e-5;
440 std::ostringstream
info;
441 info <<
"---------------------------------------------------\n";
442 info <<
"Initializing Herwig6Hadronizer for "
444 info <<
"---------------------------------------------------\n";
455 hwproc.PBEAM1 = heprup->
EBMUP.first;
456 hwproc.PBEAM2 = heprup->
EBMUP.second;
457 pdgToHerwig(heprup->
IDBMUP.first, hwbmch.PART1);
458 pdgToHerwig(heprup->
IDBMUP.second, hwbmch.PART2);
462 pdgToHerwig(2212, hwbmch.PART1);
463 pdgToHerwig(2212, hwbmch.PART2);
467 info <<
" HERWIG will be using JIMMY for UE/MI.\n";
470 info <<
" JIMMY trying to generate multiple interactions.\n";
475 bool iprocFound=
false;
479 if(!strcmp((
line->substr(0,5)).c_str(),
"IPROC")) {
482 <<
"Herwig 6 did not accept the following: \""
483 << *
line <<
"\"." << std::endl;
484 else iprocFound=
true;
490 <<
"You have to define the process with IPROC." << std::endl;
494 hwevnt.MAXER = 100000000;
502 for(
unsigned int i = 0;
i < 2;
i++) {
503 hwpram.MODPDF[
i] = -111;
504 std::memcpy(
hwprch.AUTPDF[
i],
"HWLHAPDF", 8);
516 info <<
"------------------------------------\n";
517 info <<
"Reading HERWIG parameters\n";
518 info <<
"------------------------------------\n";
524 info <<
" " << *
line <<
"\n";
527 <<
"Herwig 6 did not accept the following: \""
528 << *line <<
"\"." << std::endl;
535 std::vector<std::string> slha =
543 std::pair<int, int> pdfs(-1, -1);
547 if (hwpram.MODPDF[0] != -111 || hwpram.MODPDF[1] != -111) {
548 for(
unsigned int i = 0;
i < 2;
i++)
549 if (hwpram.MODPDF[
i] == -111)
550 hwpram.MODPDF[
i] = -1;
552 if (pdfs.first != -1 || pdfs.second != -1)
554 <<
"Both external Les Houches event and "
555 "config file specify a PDF set. "
556 "User PDF will override external one."
559 pdfs.first = hwpram.MODPDF[0] != -111 ? hwpram.MODPDF[0] : -1;
560 pdfs.second = hwpram.MODPDF[1] != -111 ? hwpram.MODPDF[1] : -1;
563 printf(
"pdfs.first = %i, pdfs.second = %i\n",pdfs.first,pdfs.second);
565 hwpram.MODPDF[0] = pdfs.first;
566 hwpram.MODPDF[1] = pdfs.second;
574 hwpram.EFFMIN = 1
e-5;
637 for(std::vector<int>::const_iterator iter = pdgIds.begin();
638 iter != pdgIds.end(); ++iter)
639 if (!markStable(*iter))
651 if (!
runInfo().internalXSec()) {
656 double RNWGT = 1. / hwevnt.NWGTS;
657 double AVWGT = hwevnt.WGTSUM * RNWGT;
659 double xsec = 1.0e3 * AVWGT;
719 bool pass = call_hwmatch();
721 printf(
"Event failed MLM matching\n");
729 event().reset(
new HepMC::GenEvent);
730 if (!
conv.fill_next_event(
event().
get()))
732 <<
"HepMC Conversion problems in event." << std::endl;
736 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
part !=
event()->particles_end(); ++
part) {
737 if ((*part)->pdg_id() != HepPID::translateHerwigtoPDT((*part)->pdg_id()))
738 (*part)->set_pdg_id(HepPID::translateHerwigtoPDT((*part)->pdg_id()));
749 HepMC::PdfInfo pdfInfo;
755 if(
event()->signal_process_id()==0)
756 event()->set_signal_process_id(
abs(hwproc.IPROC) );
767 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
768 (it !=
event()->particles_end() && incomingParton==
NULL); it++)
769 if((*it)->status()==121) incomingParton = (*it);
772 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
773 (it !=
event()->particles_end() && targetParton==
NULL); it++)
774 if((*it)->status()==122) targetParton = (*it);
777 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
778 (it !=
event()->particles_end() && incomingProton==
NULL); it++)
779 if((*it)->status()==101 && (*it)->pdg_id()==2212) incomingProton = (*it);
782 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
783 (it !=
event()->particles_end() && targetProton==
NULL); it++)
784 if((*it)->status()==102 && (*it)->pdg_id()==2212) targetProton = (*it);
787 if( incomingParton && targetParton ) {
789 totMomentum+=incomingParton->momentum();
790 totMomentum+=targetParton->momentum();
791 double evScale = totMomentum.mass();
792 double evScale2 = evScale*evScale;
796 double alphaQCD=
hwualf_(&one,&evScale);
797 double alphaQED=
hwuaem_(&evScale2);
805 pdfInfo.set_id1( incomingParton->pdg_id()==21 ? 0 : incomingParton->pdg_id());
806 pdfInfo.set_id2( targetParton->pdg_id()==21 ? 0 : targetParton->pdg_id());
807 if( incomingProton && targetProton ) {
808 double x1 = incomingParton->momentum().pz()/incomingProton->momentum().pz();
809 double x2 = targetParton->momentum().pz()/targetProton->momentum().pz();
814 pdfInfo.set_scalePDF(evScale);
818 event()->set_pdf_info( pdfInfo );
825 event()->weights().push_back( 1.0e3 * hwevnt.EVWGT );
827 event()->weights().push_back( hwevnt.EVWGT );
832 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
833 (it !=
event()->particles_end() && finalParton==
NULL); it++)
834 if((*it)->status()==123) finalParton = (*it);
840 double thisPt=finalParton->momentum().perp();
841 eventInfo()->setBinningValues(std::vector<double>(1, thisPt));
913 for(std::vector<lhef::LHERunInfo::Header>::const_iterator hIter=headers.begin();hIter!=headers.end(); ++hIter) {
914 if(hIter->tag()==mcnloHeader){
917 if((lIter->c_str())[0]!=
'#' && (lIter->c_str())[0]!=
'\n') {
920 <<
"Herwig 6 did not accept the following: \""
921 << *lIter <<
"\"." << std::endl;
934 for(std::vector<std::string>::const_iterator iter=
lheEvent()->getComments().
begin();
939 <<
"Herwig 6 did not accept the following: \""
940 << toParse <<
"\"." << std::endl;
951 if (status == 3 && !p->end_vertex())
954 if (status >= 1 && status <= 3)
957 if (!p->end_vertex())
962 int currentId = p->pdg_id();
964 if (status == 123 || status == 124 ||
965 status == 155 || status == 156 || status == 160 ||
966 (status >= 195 && status <= 197)) {
968 const HepMC::GenVertex *vtx =
q->end_vertex();
972 HepMC::GenVertex::particles_out_const_iterator iter;
973 for(iter = vtx->particles_out_const_begin();
974 iter != vtx->particles_out_const_end(); ++iter)
975 if ((*iter)->pdg_id() == currentId)
978 if (iter == vtx->particles_out_const_end())
982 if (
q->status() == 3 ||
983 ((status == 120 || status == 123 ||
984 status == 124) && orig > 124))
991 if ((status >= 120 && status <= 122) || status == 3) {
995 return ((orig >= 121 && orig <= 124) ||
999 (status != 3 && orig <= 124)) ? 3 : 4;
1004 if (!(status == 4 || status == 123 || status == 124 ||
1005 status == 155 || status == 156 || status == 160 ||
1006 (status >= 195 && status <= 197)))
1009 const HepMC::GenVertex *vtx = p->production_vertex();
1010 if (!vtx || !vtx->particles_in_size())
1013 p = *vtx->particles_in_const_begin();
1014 status = p->status();
1016 int newId = p->pdg_id();
1022 if (newId != currentId) {
1034 for(HepMC::GenEvent::particle_iterator iter =
1035 event()->particles_begin();
1036 iter !=
event()->particles_end(); iter++)
1039 for(HepMC::GenEvent::particle_iterator iter =
1040 event()->particles_begin();
1041 iter !=
event()->particles_end(); iter++)
1042 if ((*iter)->status() == 4)
1043 (*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)())
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
std::auto_ptr< GenEventInfoProduct > & eventInfo()
bool give(const std::string &line)
lhef::LHERunInfo * lheRunInfo()
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)
const_iterator begin() const
std::vector< std::string > findHeader(const std::string &tag) const
volatile std::atomic< bool > shutdown_flag false
gen::ParameterCollector parameters
bool initializeForExternalPartons()
virtual void upInit() override
static void fillHEPRUP(const HEPRUP *heprup)
static HepMC::HEPEVT_Wrapper wrapper