Skip to content

Commit c7d31e6

Browse files
Add lhe numbering to allow get correct matching between lhe and herwig events
Read lhe event numbers in, if present Add HadroniserFilter to Herwig which correctly matches LHE numbers between CMSSW and herwig Add option to Herwig input fragements to use LHE numbering Change test examples to use new HadroniserFilter+ LHE numbering code style code style Call addLHEnumbers from mergeLHE.py if asked to number events and not using the DefaultLHEMerger Number events before merge (so numbers are also available to LHEReader) Include evtnum in LHEEventProduct (necesary for multithreading)
1 parent 3d761d8 commit c7d31e6

File tree

16 files changed

+139
-19
lines changed

16 files changed

+139
-19
lines changed

Configuration/Generator/python/DYToLL01234Jets_5FS_TuneCH3_13TeV_madgraphMLM_herwig7_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from Configuration.Generator.Herwig7Settings.Herwig7MGMergingSettings_cfi import *
77

88

9-
generator = cms.EDFilter("Herwig7GeneratorFilter",
9+
generator = cms.EDFilter("Herwig7HadronizerFilter",
1010
herwig7CH3SettingsBlock,
1111
herwig7StableParticlesForDetectorBlock,
1212
herwig7MGMergingSettingsBlock,

Configuration/Generator/python/DYToLL012Jets_5FS_TuneCH3_13TeV_amcatnloFxFx_herwig7_cff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from Configuration.Generator.Herwig7Settings.Herwig7MGMergingSettings_cfi import *
66

77

8-
generator = cms.EDFilter("Herwig7GeneratorFilter",
8+
generator = cms.EDFilter("Herwig7HadronizerFilter",
99
herwig7CH3SettingsBlock,
1010
herwig7StableParticlesForDetectorBlock,
1111
herwig7MGMergingSettingsBlock,
@@ -40,7 +40,7 @@
4040
outputFile = cms.string('cmsgrid_final.lhe'),
4141
scriptName = cms.FileInPath('GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh'),
4242
generateConcurrently = cms.untracked.bool(True),
43-
postGenerationCommand = cms.untracked.vstring('mergeLHE.py', '-i', 'thread*/cmsgrid_final.lhe', '-o', 'cmsgrid_final.lhe')
43+
postGenerationCommand = cms.untracked.vstring('mergeLHE.py', '-n', '-i', 'thread*/cmsgrid_final.lhe', '-o', 'cmsgrid_final.lhe')
4444
)
4545

4646

Configuration/Generator/python/DYToll01234Jets_5f_LO_MLM_Madgraph_LHE_13TeV_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
args = cms.vstring('/cvmfs/cms.cern.ch/phys_generator/gridpacks/UL/13TeV/madgraph/V5_2.6.5/dyellell01234j_5f_LO_MLM_v2/DYJets_HT-incl_slc6_amd64_gcc630_CMSSW_9_3_16_tarball.tar.xz','false','slc6_amd64_gcc630','CMSSW_9_3_16'),
88
nEvents = cms.untracked.uint32(10),
99
generateConcurrently = cms.untracked.bool(True),
10-
postGenerationCommand = cms.untracked.vstring('mergeLHE.py', '-i', 'thread*/cmsgrid_final.lhe', '-o', 'cmsgrid_final.lhe'),
10+
postGenerationCommand = cms.untracked.vstring('mergeLHE.py', '-n', '-i', 'thread*/cmsgrid_final.lhe', '-o', 'cmsgrid_final.lhe'),
1111
)

Configuration/Generator/python/Herwig7Settings/Herwig7LHECommonSettings_cfi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# set the weight option (e.g. for MC@NLO)
1616
'set LesHouchesHandler:WeightOption VarNegWeight',
17+
'set LesHouchesHandler:EventNumbering LHE',
1718

1819
'set /Herwig/Generators/EventGenerator:EventHandler /Herwig/EventHandlers/LesHouchesHandler',
1920
'create ThePEG::Cuts /Herwig/Cuts/NoCuts',

Configuration/Generator/python/Herwig7Settings/Herwig7MGMergingSettings_cfi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'set LesHouchesHandler:HadronizationHandler /Herwig/Hadronization/ClusterHadHandler',
1515
'set LesHouchesHandler:DecayHandler /Herwig/Decays/DecayHandler',
1616
'set LesHouchesHandler:WeightOption VarNegWeight',
17+
'set LesHouchesHandler:EventNumbering LHE',
1718
'set /Herwig/Generators/EventGenerator:EventHandler /Herwig/EventHandlers/LesHouchesHandler',
1819
'create ThePEG::Cuts /Herwig/Cuts/NoCuts',
1920
'cd /Herwig/EventHandlers',

Configuration/Generator/python/TT_13TeV_Pow_Herwig7_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from Configuration.Generator.Herwig7Settings.Herwig7LHEPowhegSettings_cfi import *
88

99

10-
generator = cms.EDFilter("Herwig7GeneratorFilter",
10+
generator = cms.EDFilter("Herwig7HadronizerFilter",
1111
herwig7CH3SettingsBlock,
1212
herwig7StableParticlesForDetectorBlock,
1313
herwig7LHECommonSettingsBlock,

Configuration/Generator/python/TTbar_Pow_LHE_13TeV_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
outputFile = cms.string('cmsgrid_final.lhe'),
88
scriptName = cms.FileInPath('GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh'),
99
generateConcurrently = cms.untracked.bool(True),
10-
postGenerationCommand = cms.untracked.vstring('mergeLHE.py', '-i', 'thread*/cmsgrid_final.lhe', '-o', 'cmsgrid_final.lhe'),
10+
postGenerationCommand = cms.untracked.vstring('mergeLHE.py', '-n', '-i', 'thread*/cmsgrid_final.lhe', '-o', 'cmsgrid_final.lhe'),
1111
)
1212

1313
#Link to datacards:

GeneratorInterface/Herwig7Interface/plugins/Herwig7Hadronizer.cc

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Herwig7Hadronizer : public Herwig7Interface, public gen::BaseHadronizer {
6363
unsigned int eventsToPrint;
6464

6565
ThePEG::EventPtr thepegEvent;
66+
bool haveEvt = false;
6667

6768
std::shared_ptr<lhef::LHEProxy> proxy_;
6869
const std::string handlerDirectory_;
@@ -101,9 +102,18 @@ bool Herwig7Hadronizer::initializeForInternalPartons() {
101102
}
102103

103104
bool Herwig7Hadronizer::initializeForExternalPartons() {
104-
edm::LogError("Herwig7 interface")
105-
<< "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
106-
return false;
105+
if (currentLumiBlock == firstLumiBlock) {
106+
std::ifstream runFile(runFileName + ".run");
107+
if (runFile.fail()) //required for showering of LHE files
108+
{
109+
initRepository(paramSettings);
110+
}
111+
if (!initGenerator()) {
112+
edm::LogInfo("Generator|Herwig7Hadronizer") << "No run step for Herwig chosen. Program will be aborted.";
113+
exit(0);
114+
}
115+
}
116+
return true;
107117
}
108118

109119
bool Herwig7Hadronizer::declareStableParticles(const std::vector<int>& pdgIds) { return false; }
@@ -141,8 +151,41 @@ bool Herwig7Hadronizer::generatePartonsAndHadronize() {
141151
}
142152

143153
bool Herwig7Hadronizer::hadronize() {
144-
edm::LogError("Herwig7 interface")
145-
<< "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
154+
if (!haveEvt) {
155+
try {
156+
thepegEvent = eg_->shoot();
157+
haveEvt = true;
158+
} catch (std::exception& exc) {
159+
edm::LogWarning("Generator|Herwig7Hadronizer")
160+
<< "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
161+
return false;
162+
}
163+
}
164+
int evtnum = lheEvent()->evtnum();
165+
if (evtnum == -1) {
166+
edm::LogError("Generator|Herwig7Hadronizer")
167+
<< "Event number not set in lhe file, needed for correctly aligning Herwig and LHE events!";
168+
return false;
169+
}
170+
if (thepegEvent->number() < evtnum) {
171+
edm::LogError("Herwig7 interface") << "Herwig does not seem to be generating events in order, did you set "
172+
"/Herwig/EventHandlers/FxFxLHReader:AllowedToReOpen Yes?";
173+
return false;
174+
} else if (thepegEvent->number() == evtnum) {
175+
haveEvt = false;
176+
if (!thepegEvent) {
177+
edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
178+
return false;
179+
}
180+
181+
event() = convert(thepegEvent);
182+
if (!event().get()) {
183+
edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
184+
return false;
185+
}
186+
return true;
187+
}
188+
edm::LogWarning("Generator|Herwig7Hadronizer") << "Event " << evtnum << " not generated (likely skipped in merging)";
146189
return false;
147190
}
148191

GeneratorInterface/LHEInterface/interface/LHEEvent.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ namespace lhef {
5252

5353
int npLO() const { return npLO_; }
5454
int npNLO() const { return npNLO_; }
55+
int evtnum() const { return evtnum_; }
5556

5657
void setNpLO(int n) { npLO_ = n; }
5758
void setNpNLO(int n) { npNLO_ = n; }
59+
void setEvtNum(int n) { evtnum_ = n; }
5860

5961
void addComment(const std::string &line) { comments.push_back(line); }
6062

@@ -93,6 +95,7 @@ namespace lhef {
9395
std::vector<float> scales_; //scale value used to exclude EWK-produced partons from matching
9496
int npLO_; //number of partons for LO process (used to steer matching/merging)
9597
int npNLO_; //number of partons for NLO process (used to steer matching/merging)
98+
int evtnum_; //The number of the event (needed to ensure the correct LHE events are saved for MG +Herwig)
9699
};
97100

98101
} // namespace lhef

GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
192192
partonLevel_->weights().end(),
193193
std::bind(&LHEEventProduct::addWeight, product.get(), std::placeholders::_1));
194194
product->setScales(partonLevel_->scales());
195+
product->setEvtNum(partonLevel_->evtnum());
195196
if (nPartonMapping_.empty()) {
196197
product->setNpLO(partonLevel_->npLO());
197198
product->setNpNLO(partonLevel_->npNLO());

0 commit comments

Comments
 (0)