Skip to content

Commit

Permalink
Merge pull request #27496 from Andrej-CMS/PR_UltraLegacy_PSWeigts
Browse files Browse the repository at this point in the history
Pr ultra legacy ps weigts
  • Loading branch information
cmsbuild authored Aug 6, 2019
2 parents e38c395 + 601889f commit 9f6b0c8
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 31 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 /',
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Herwig7Interface {
std::unique_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
110 changes: 81 additions & 29 deletions GeneratorInterface/Herwig7Interface/plugins/Herwig7Hadronizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <ThePEG/EventRecord/Event.h>
#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"

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 @@ -49,6 +53,11 @@ class Herwig7Hadronizer : public Herwig7Interface, public gen::BaseHadronizer {

const char *classname() const { return "Herwig7Hadronizer"; }

std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader() const override;
void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
void randomizeIndex(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine);


private:

void doSetRandomEngine(CLHEP::HepRandomEngine* v) override { setPEGRandomEngine(v); }
Expand All @@ -57,10 +66,13 @@ 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 +92,24 @@ 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,38 +127,36 @@ bool Herwig7Hadronizer::declareStableParticles(const std::vector<int> &pdgIds)

void Herwig7Hadronizer::statistics()
{
if(eg_) {
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 All @@ -147,6 +166,39 @@ bool Herwig7Hadronizer::hadronize()
return false;
}

std::unique_ptr<GenLumiInfoHeader> Herwig7Hadronizer::getGenLumiInfoHeader() const {
auto 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();

}

void Herwig7Hadronizer::finalizeEvent()
{
eventInfo().reset(new GenEventInfoProduct(event().get()));
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,6 +39,7 @@
'herwig7CH3AlphaS',
'herwig7CH3MPISettings',
'herwig7StableParticlesForDetector',
'hw_PSWeights_settings',
'hw_user_settings'
),
repository = cms.string('${HERWIGPATH}/HerwigDefaults.rpo'),
Expand Down
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 9f6b0c8

Please sign in to comment.