9 #include <boost/shared_ptr.hpp>
10 #include <boost/algorithm/string/classification.hpp>
11 #include <boost/algorithm/string/split.hpp>
13 #include <HepMC/GenEvent.h>
14 #include <HepMC/GenParticle.h>
15 #include <HepMC/GenVertex.h>
16 #include <HepMC/PdfInfo.h>
17 #include <HepMC/HerwigWrapper6_4.h>
18 #include <HepMC/HEPEVT_Wrapper.h>
19 #include <HepMC/IO_HERWIG.h>
20 #include "HepPID/ParticleIDTranslations.hh"
43 void hwuidt_(
int *iopt,
int *ipdg,
int *iwig,
char nwig[8]);
50 static inline bool call_hwmsct()
57 static int pdgToHerwig(
int ipdg,
char *nwig)
61 hwuidt_(&iopt, &ipdg, &iwig, nwig);
62 return ipdg ? iwig : 0;
65 static bool markStable(
int pdgId)
68 if (!pdgToHerwig(pdgId, nwig))
99 const char *
classname()
const {
return "Herwig6Hadronizer"; }
131 void hwwarn_(
const char *method,
int *
id);
137 BaseHadronizer(params),
140 herwigVerbosity(params.getUntrackedParameter<int>(
"herwigVerbosity", 0)),
141 hepmcVerbosity(params.getUntrackedParameter<int>(
"hepmcVerbosity", 0)),
143 printCards(params.getUntrackedParameter<bool>(
"printCards",
false)),
144 emulatePythiaStatusCodes(params.getUntrackedParameter<bool>(
"emulatePythiaStatusCodes",
false)),
145 comEnergy(params.getParameter<double>(
"comEnergy")),
146 useJimmy(params.getParameter<bool>(
"useJimmy")),
147 doMPInteraction(params.getParameter<bool>(
"doMPInteraction")),
148 numTrials(params.getUntrackedParameter<int>(
"numTrialsMPI", 100)),
149 readMCatNLOfile(
false)
153 if ( params.
exists(
"doPDGConvert" ) )
176 const std::vector<std::string> &
lines)
178 std::set<std::string>
blocks;
180 for(std::vector<std::string>::const_iterator iter = lines.begin();
181 iter != lines.end(); ++iter) {
182 std::string
line = *iter;
183 std::transform(line.begin(), line.end(),
184 line.begin(), (int(*)(int))std::toupper);
186 if (pos != std::string::npos)
192 if (!boost::algorithm::is_space()(line[0])) {
193 std::vector<std::string>
tokens;
195 boost::algorithm::is_space(),
196 boost::token_compress_on);
200 if (tokens.size() < 2)
202 if (tokens[0] ==
"BLOCK")
204 else if (tokens[0] ==
"DECAY")
210 if (!blocks.count(block)) {
211 blocks.insert(block);
213 <<
"Unsupported SLHA block \"" << block
214 <<
"\". It will be ignored."
227 std::ostringstream
info;
228 info <<
"---------------------------------------------------\n";
229 info <<
"Initializing Herwig6Hadronizer for "
231 info <<
"---------------------------------------------------\n";
242 hwproc.PBEAM1 = heprup->
EBMUP.first;
243 hwproc.PBEAM2 = heprup->
EBMUP.second;
244 pdgToHerwig(heprup->
IDBMUP.first, hwbmch.PART1);
245 pdgToHerwig(heprup->
IDBMUP.second, hwbmch.PART2);
249 pdgToHerwig(2212, hwbmch.PART1);
250 pdgToHerwig(2212, hwbmch.PART2);
254 info <<
" HERWIG will be using JIMMY for UE/MI.\n";
257 info <<
" JIMMY trying to generate multiple interactions.\n";
263 bool iprocFound=
false;
267 if(!strcmp((
line->substr(0,5)).c_str(),
"IPROC")) {
270 <<
"Herwig 6 did not accept the following: \""
271 << *
line <<
"\"." << std::endl;
272 else iprocFound=
true;
278 <<
"You have to define the process with IPROC." << std::endl;
282 hwevnt.MAXER = 100000000;
290 for(
unsigned int i = 0;
i < 2;
i++) {
291 hwpram.MODPDF[
i] = -111;
292 std::memcpy(
hwprch.AUTPDF[
i],
"HWLHAPDF", 8);
304 info <<
"------------------------------------\n";
305 info <<
"Reading HERWIG parameters\n";
306 info <<
"------------------------------------\n";
312 info <<
" " << *
line <<
"\n";
315 <<
"Herwig 6 did not accept the following: \""
316 << *line <<
"\"." << std::endl;
323 std::vector<std::string> slha =
331 std::pair<int, int> pdfs(-1, -1);
335 if (hwpram.MODPDF[0] != -111 || hwpram.MODPDF[1] != -111) {
336 for(
unsigned int i = 0;
i < 2;
i++)
337 if (hwpram.MODPDF[
i] == -111)
338 hwpram.MODPDF[
i] = -1;
340 if (pdfs.first != -1 || pdfs.second != -1)
342 <<
"Both external Les Houches event and "
343 "config file specify a PDF set. "
344 "User PDF will override external one."
347 pdfs.first = hwpram.MODPDF[0] != -111 ? hwpram.MODPDF[0] : -1;
348 pdfs.second = hwpram.MODPDF[1] != -111 ? hwpram.MODPDF[1] : -1;
351 hwpram.MODPDF[0] = pdfs.first;
352 hwpram.MODPDF[1] = pdfs.second;
396 for(std::vector<int>::const_iterator iter = pdgIds.begin();
397 iter != pdgIds.end(); ++iter)
398 if (!markStable(*iter))
410 if (!
runInfo().internalXSec()) {
415 double RNWGT = 1. / hwevnt.NWGTS;
416 double AVWGT = hwevnt.WGTSUM * RNWGT;
418 double xsec = 1.0e3 * AVWGT;
469 HepMC::PdfInfo pdfInfo;
475 if(
event()->signal_process_id()==0)
476 event()->set_signal_process_id(
abs(hwproc.IPROC) );
487 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
488 (it !=
event()->particles_end() && incomingParton==
NULL); it++)
489 if((*it)->status()==121) incomingParton = (*it);
492 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
493 (it !=
event()->particles_end() && targetParton==
NULL); it++)
494 if((*it)->status()==122) targetParton = (*it);
497 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
498 (it !=
event()->particles_end() && incomingProton==
NULL); it++)
499 if((*it)->status()==101 && (*it)->pdg_id()==2212) incomingProton = (*it);
502 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
503 (it !=
event()->particles_end() && targetProton==
NULL); it++)
504 if((*it)->status()==102 && (*it)->pdg_id()==2212) targetProton = (*it);
507 if( incomingParton && targetParton ) {
509 totMomentum+=incomingParton->momentum();
510 totMomentum+=targetParton->momentum();
511 double evScale = totMomentum.mass();
512 double evScale2 = evScale*evScale;
516 double alphaQCD=
hwualf_(&one,&evScale);
517 double alphaQED=
hwuaem_(&evScale2);
525 pdfInfo.set_id1( incomingParton->pdg_id()==21 ? 0 : incomingParton->pdg_id());
526 pdfInfo.set_id2( targetParton->pdg_id()==21 ? 0 : targetParton->pdg_id());
527 if( incomingProton && targetProton ) {
528 double x1 = incomingParton->momentum().pz()/incomingProton->momentum().pz();
529 double x2 = targetParton->momentum().pz()/targetProton->momentum().pz();
534 pdfInfo.set_scalePDF(evScale);
538 event()->set_pdf_info( pdfInfo );
545 event()->weights().push_back( 1.0e3 * hwevnt.EVWGT );
547 event()->weights().push_back( hwevnt.EVWGT );
552 for(HepMC::GenEvent::particle_const_iterator it =
event()->particles_begin();
553 (it !=
event()->particles_end() && finalParton==
NULL); it++)
554 if((*it)->status()==123) finalParton = (*it);
560 double thisPt=finalParton->momentum().perp();
561 eventInfo()->setBinningValues(std::vector<double>(1, thisPt));
586 event().reset(
new HepMC::GenEvent);
587 if (!
conv.fill_next_event(
event().
get()))
589 <<
"HepMC Conversion problems in event." << std::endl;
593 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
part !=
event()->particles_end(); ++
part) {
594 if ((*part)->pdg_id() != HepPID::translateHerwigtoPDT((*part)->pdg_id()))
595 (*part)->set_pdg_id(HepPID::translateHerwigtoPDT((*part)->pdg_id()));
615 std::string mcnloHeader=
"herwig6header";
617 for(std::vector<lhef::LHERunInfo::Header>::const_iterator hIter=headers.begin();hIter!=headers.end(); ++hIter) {
618 if(hIter->tag()==mcnloHeader){
621 if((lIter->c_str())[0]!=
'#' && (lIter->c_str())[0]!=
'\n') {
624 <<
"Herwig 6 did not accept the following: \""
625 << *lIter <<
"\"." << std::endl;
638 for(std::vector<std::string>::const_iterator iter=
lheEvent()->getComments().
begin();
640 std::string toParse(iter->substr(1));
643 <<
"Herwig 6 did not accept the following: \""
644 << toParse <<
"\"." << std::endl;
655 if (status == 3 && !p->end_vertex())
658 if (status >= 1 && status <= 3)
661 if (!p->end_vertex())
666 int currentId = p->pdg_id();
668 if (status == 123 || status == 124 ||
669 status == 155 || status == 156 || status == 160 ||
670 (status >= 195 && status <= 197)) {
672 const HepMC::GenVertex *vtx =
q->end_vertex();
676 HepMC::GenVertex::particles_out_const_iterator iter;
677 for(iter = vtx->particles_out_const_begin();
678 iter != vtx->particles_out_const_end(); ++iter)
679 if ((*iter)->pdg_id() == currentId)
682 if (iter == vtx->particles_out_const_end())
686 if (
q->status() == 3 ||
687 ((status == 120 || status == 123 ||
688 status == 124) && orig > 124))
695 if ((status >= 120 && status <= 122) || status == 3) {
699 return ((orig >= 121 && orig <= 124) ||
703 (status != 3 && orig <= 124)) ? 3 : 4;
708 if (!(status == 4 || status == 123 || status == 124 ||
709 status == 155 || status == 156 || status == 160 ||
710 (status >= 195 && status <= 197)))
713 const HepMC::GenVertex *vtx = p->production_vertex();
714 if (!vtx || !vtx->particles_in_size())
717 p = *vtx->particles_in_const_begin();
718 status = p->status();
720 int newId = p->pdg_id();
726 if (newId != currentId) {
738 for(HepMC::GenEvent::particle_iterator iter =
739 event()->particles_begin();
740 iter !=
event()->particles_end(); iter++)
743 for(HepMC::GenEvent::particle_iterator iter =
744 event()->particles_begin();
745 iter !=
event()->particles_end(); iter++)
746 if ((*iter)->status() == 4)
747 (*iter)->set_status(2);
T getParameter(std::string const &) const
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 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
const std::vector< Header > & getHeaders() const
block
Formating index page's pieces.
std::auto_ptr< GenEventInfoProduct > & eventInfo()
bool give(const std::string &line)
lhef::LHERunInfo * lheRunInfo()
std::pair< int, int > pdfSetTranslation() const
bool emulatePythiaStatusCodes
bool declareSpecialSettings(const std::vector< std::string >)
const_iterator end() const
Herwig6Hadronizer(const edm::ParameterSet ¶ms)
const_iterator begin() const
std::vector< std::string > findHeader(const std::string &tag) const
gen::ParameterCollector parameters
bool initializeForExternalPartons()
static void fillHEPRUP(const HEPRUP *heprup)
static HepMC::HEPEVT_Wrapper wrapper