Skip to content

Commit

Permalink
Merge pull request #26910 from Andrej-CMS/Herwig7_FixSegFault102
Browse files Browse the repository at this point in the history
Herwig7 fix seg fault102
  • Loading branch information
cmsbuild committed May 28, 2019
2 parents f24285d + 0ded259 commit 12c133a
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'set LesHouchesHandler:DecayHandler /Herwig/Decays/DecayHandler',
'set LesHouchesHandler:HadronizationHandler /Herwig/Hadronization/ClusterHadHandler',
'set LesHouchesHandler:WeightOption VarNegWeight',
'set LesHouchesHandler:Weighted On',
'set /Herwig/Generators/EventGenerator:EventHandler /Herwig/EventHandlers/LesHouchesHandler',
'create ThePEG::Cuts /Herwig/Cuts/NoCuts',
'create ThePEG::LHAPDF /Herwig/Partons/LHAPDF ThePEGLHAPDF.so',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import FWCore.ParameterSet.Config as cms

herwig7PSWeightsSettingsBlock = cms.PSet(
hw_PSWeights_settings = cms.vstring(
'cd /',
'cd /Herwig/Shower',
'do ShowerHandler:AddVariation RedHighAll 1.141 1.141 All',
'do ShowerHandler:AddVariation RedLowAll 0.707 0.707 All',
'do ShowerHandler:AddVariation DefHighAll 2 2 All',
'do ShowerHandler:AddVariation DefLowAll 0.5 0.5 All',
'do ShowerHandler:AddVariation ConHighAll 4 4 All',
'do ShowerHandler:AddVariation ConLowAll 0.25 0.25 All',
'do ShowerHandler:AddVariation RedHighHard 1.141 1.141 Hard',
'do ShowerHandler:AddVariation RedLowHard 0.707 0.707 Hard',
'do ShowerHandler:AddVariation DefHighHard 2 2 Hard',
'do ShowerHandler:AddVariation DefLowHard 0.5 0.5 Hard',
'do ShowerHandler:AddVariation ConHighHard 4 4 Hard',
'do ShowerHandler:AddVariation ConLowHard 0.25 0.25 Hard',
'do ShowerHandler:AddVariation RedHighSecondary 1.141 1.141 Secondary',
'do ShowerHandler:AddVariation RedLowSecondary 0.707 0.707 Secondary',
'do ShowerHandler:AddVariation DefHighSecondary 2 2 Secondary',
'do ShowerHandler:AddVariation DefLowSecondary 0.5 0.5 Secondary',
'do ShowerHandler:AddVariation ConHighSecondary 4 4 Secondary',
'do ShowerHandler:AddVariation ConLowSecondary 0.25 0.25 Secondary',
'set SplittingGenerator:Detuning 2.0',
'cd /',
)
)
3 changes: 2 additions & 1 deletion Configuration/PyReleaseValidation/python/relval_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ def identityFS(wf):
'--conditions':'auto:run2_mc_FULL'
},
step1Defaults])
step1LHEGenDQM = merge([{'-s':'LHE,GEN,VALIDATION:genvalid','--datatier' : 'GEN-SIM,LHE,DQMIO','--eventcontent': 'LHE,RAWSIM,DQM'},step1GenDefaults])

step1HadronizerDefaults=merge([{'--datatier':'GEN-SIM,DQMIO',
'--relval':'200000,5000'
Expand Down Expand Up @@ -1352,7 +1353,7 @@ def lhegensim2017(fragment,howMuch):
steps['sherpa_ZtoEE_0j_OpenLoops_13TeV_MASTER']=genvalid('sherpa_ZtoEE_0j_OpenLoops_13TeV_MASTER_cff',step1GenDefaults)

#Herwig7
steps['TTbar_13TeV_Pow_herwig7']=genvalid('Configuration/Generator/python/TT_13TeV_Pow_Herwig7_cff',step1LHEGenSimDQM)
steps['TTbar_13TeV_Pow_herwig7']=genvalid('Configuration/Generator/python/TT_13TeV_Pow_Herwig7_cff',step1LHEGenDQM)


# Heavy Ion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Herwig7Interface {
std::auto_ptr<HepMC::IO_BaseClass> iobc_;

// HerwigUi contains settings piped to Herwig7
Herwig::HerwigUIProvider* HwUI_;
std::shared_ptr<Herwig::HerwigUIProvider> HwUI_;

/**
* Function calls Herwig event generator via API
Expand Down
113 changes: 79 additions & 34 deletions GeneratorInterface/Herwig7Interface/plugins/Herwig7Hadronizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <ThePEG/Config/ThePEG.h>
#include <ThePEG/LesHouches/LesHouchesReader.h>

#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
Expand All @@ -23,6 +25,8 @@
#include "GeneratorInterface/LHEInterface/interface/LHEProxy.h"

#include "GeneratorInterface/Herwig7Interface/interface/Herwig7Interface.h"
#include <Herwig/API/HerwigAPI.h>
#include "CLHEP/Random/RandomEngine.h"

namespace CLHEP {
class HepRandomEngine;
Expand All @@ -48,6 +52,9 @@ class Herwig7Hadronizer : public Herwig7Interface, public gen::BaseHadronizer {
void finalizeEvent();

const char *classname() const { return "Herwig7Hadronizer"; }
GenLumiInfoHeader *getGenLumiInfoHeader() const override;
void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
void randomizeIndex(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine);

private:

Expand All @@ -57,10 +64,12 @@ class Herwig7Hadronizer : public Herwig7Interface, public gen::BaseHadronizer {

ThePEG::EventPtr thepegEvent;

boost::shared_ptr<lhef::LHEProxy> proxy_;
std::shared_ptr<lhef::LHEProxy> proxy_;
const std::string handlerDirectory_;
edm::ParameterSet paramSettings;
const std::string runFileName;
unsigned int firstLumiBlock=0;
unsigned int currentLumiBlock=0;
};

Herwig7Hadronizer::Herwig7Hadronizer(const edm::ParameterSet &pset) :
Expand All @@ -80,15 +89,18 @@ Herwig7Hadronizer::~Herwig7Hadronizer()

bool Herwig7Hadronizer::initializeForInternalPartons()
{
std::ifstream runFile(runFileName+".run");
if (runFile.fail()) //required for showering of LHE files
if (currentLumiBlock==firstLumiBlock)
{
initRepository(paramSettings);
}
if (!initGenerator())
{
edm::LogInfo("Generator|Herwig7Hadronizer") << "No run step for Herwig chosen. Program will be aborted.";
exit(0);
std::ifstream runFile(runFileName+".run");
if (runFile.fail()) //required for showering of LHE files
{
initRepository(paramSettings);
}
if (!initGenerator())
{
edm::LogInfo("Generator|Herwig7Hadronizer") << "No run step for Herwig chosen. Program will be aborted.";
exit(0);
}
}
return true;
}
Expand All @@ -106,36 +118,35 @@ bool Herwig7Hadronizer::declareStableParticles(const std::vector<int> &pdgIds)

void Herwig7Hadronizer::statistics()
{
runInfo().setInternalXSec(GenRunInfoProduct::XSec(
eg_->integratedXSec() / ThePEG::picobarn,
eg_->integratedXSecErr() / ThePEG::picobarn));
if(eg_){
runInfo().setInternalXSec(GenRunInfoProduct::XSec(
eg_->integratedXSec() / ThePEG::picobarn,
eg_->integratedXSecErr() / ThePEG::picobarn));
}
}

bool Herwig7Hadronizer::generatePartonsAndHadronize()
{
edm::LogInfo("Generator|Herwig7Hadronizer") << "Start production";

flushRandomNumberGenerator();

try {
thepegEvent = eg_->shoot();
} catch (std::exception& exc) {
edm::LogWarning("Generator|Herwig7Hadronizer") << "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
return false;
}

if (!thepegEvent) {
edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
return false;
}

event() = convert(thepegEvent);
if (!event().get()) {
edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
return false;
}

return true;
try {
thepegEvent = eg_->shoot();
} catch (std::exception& exc) {
edm::LogWarning("Generator|Herwig7Hadronizer") << "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
return false;
}

if (!thepegEvent) {
edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
return false;
}

event() = convert(thepegEvent);
if (!event().get()) {
edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
return false;
}

return true;
}

bool Herwig7Hadronizer::hadronize()
Expand Down Expand Up @@ -172,6 +183,40 @@ bool Herwig7Hadronizer::residualDecay()
return true;
}

GenLumiInfoHeader *Herwig7Hadronizer::getGenLumiInfoHeader() const {
GenLumiInfoHeader *genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();

if (thepegEvent)
{
int weights_number = thepegEvent->optionalWeights().size();

if(weights_number > 1){
genLumiInfoHeader->weightNames().reserve(weights_number + 1);
genLumiInfoHeader->weightNames().push_back("nominal");
std::map<std::string,double> weights_map = thepegEvent->optionalWeights();
for (std::map<std::string,double>::iterator it = weights_map.begin(); it != weights_map.end(); it++)
{
genLumiInfoHeader->weightNames().push_back(it->first);
}
}
}

return genLumiInfoHeader;
}

void Herwig7Hadronizer::randomizeIndex(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine)
{
BaseHadronizer::randomizeIndex(lumi, rengine);

if (firstLumiBlock==0)
{
firstLumiBlock=lumi.id().luminosityBlock();
}
currentLumiBlock=lumi.id().luminosityBlock();

}


#include "GeneratorInterface/ExternalDecays/interface/ExternalDecayDriver.h"

typedef edm::GeneratorFilter<Herwig7Hadronizer, gen::ExternalDecayDriver> Herwig7GeneratorFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
from Configuration.Generator.Herwig7Settings.Herwig7StableParticlesForDetector_cfi import *
from Configuration.Generator.Herwig7Settings.Herwig7CH3TuneSettings_cfi import *
from Configuration.Generator.Herwig7Settings.Herwig7LHEPowhegSettings_cfi import *
from Configuration.Generator.Herwig7Settings.Herwig7PSWeightsSettings_cfi import *

generator = cms.EDFilter("Herwig7GeneratorFilter",
herwig7LHECommonSettingsBlock,
herwig7LHEPowhegSettingsBlock,
herwig7StableParticlesForDetectorBlock,
herwig7PSWeightsSettingsBlock,
herwig7CH3SettingsBlock,
configFiles = cms.vstring(),
crossSection = cms.untracked.double(-1),
Expand All @@ -37,9 +39,10 @@
'herwig7CH3AlphaS',
'herwig7CH3MPISettings',
'herwig7StableParticlesForDetector',
'hw_PSWeights_settings',
'hw_user_settings'
),
repository = cms.string('${HERWIGPATH}/HerwigDefaults.rpo'),
run = cms.string('InterfaceMatchboxTest'),
runModeList = cms.untracked.string('read,run'),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Herwig7Interface::initRepository(const edm::ParameterSet &pset)
runModeTemp.erase(0, pos+1);

// construct HerwigUIProvider object and return it as global object
HwUI_ = new Herwig::HerwigUIProvider(pset, dumpConfig_, Herwig::RunMode::READ);
HwUI_.reset(new Herwig::HerwigUIProvider(pset, dumpConfig_, Herwig::RunMode::READ));
edm::LogInfo("Herwig7Interface") << "HerwigUIProvider object with run mode " << HwUI_->runMode() << " created.\n";


Expand Down

0 comments on commit 12c133a

Please sign in to comment.