Skip to content

Commit 388ec50

Browse files
authored
Merge pull request #45367 from mseidel42/Rivet4_PGunFix
Fix HepMC3 conversion on MC without event weights (particle guns)
2 parents 5815534 + f38a6d9 commit 388ec50

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

GeneratorInterface/RivetInterface/plugins/GenParticles2HepMCConverter.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,16 @@ void GenParticles2HepMCConverter::produce(edm::Event& event, const edm::EventSet
9898
hepmc_event->add_attribute("alphaQED", std::make_shared<HepMC3::DoubleAttribute>(genEventInfoHandle->alphaQED()));
9999

100100
hepmc_event->weights() = genEventInfoHandle->weights();
101+
// add dummy weight if necessary
102+
if (hepmc_event->weights().size() == 0) {
103+
hepmc_event->weights().push_back(1.);
104+
}
101105

102106
// resize cross section to number of weights
103-
xsec_->set_cross_section(std::vector<double>(hepmc_event->weights().size(), xsec_->xsec(0)),
104-
std::vector<double>(hepmc_event->weights().size(), xsec_->xsec_err(0)));
107+
if (xsec_->xsecs().size() < hepmc_event->weights().size()) {
108+
xsec_->set_cross_section(std::vector<double>(hepmc_event->weights().size(), xsec_->xsec(0)),
109+
std::vector<double>(hepmc_event->weights().size(), xsec_->xsec_err(0)));
110+
}
105111
hepmc_event->set_cross_section(xsec_);
106112

107113
// Set PDF

GeneratorInterface/RivetInterface/test/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
<test name="test-particleLevel_fromHepMC3" command="cmsRun ${LOCALTOP}/src/GeneratorInterface/RivetInterface/test/particleLevel_fromHepMC3_cfg.py"/>
1313
<test name="test-particleLevel_fromGenParticles" command="cmsRun ${LOCALTOP}/src/GeneratorInterface/RivetInterface/test/particleLevel_fromGenParticles_cfg.py"/>
1414
<test name="test-particleLevel_fromMiniAod" command="cmsRun ${LOCALTOP}/src/GeneratorInterface/RivetInterface/test/particleLevel_cfg.py"/>
15+
<test name="test-particleLevel_fromPtGun" command="cmsRun ${LOCALTOP}/src/GeneratorInterface/RivetInterface/test/particleLevel_fromPtGun_cfg.py"/>
1516
<test name="test-HTXS" command="cmsRun ${LOCALTOP}/src/GeneratorInterface/RivetInterface/test/runRivetHTXS_cfg.py"/>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
process = cms.Process("TQAF")
4+
5+
process.load("FWCore.MessageLogger.MessageLogger_cfi")
6+
process.load("Configuration.StandardSequences.SimulationRandomNumberGeneratorSeeds_cff")
7+
8+
process.source = cms.Source("EmptySource")
9+
10+
process.generator = cms.EDFilter("Pythia8PtGun",
11+
PGunParameters = cms.PSet(
12+
AddAntiParticle = cms.bool(True),
13+
MaxEta = cms.double(2.5),
14+
MaxPhi = cms.double(3.14159265359),
15+
MaxPt = cms.double(10.01),
16+
MinEta = cms.double(-2.5),
17+
MinPhi = cms.double(-3.14159265359),
18+
MinPt = cms.double(9.99),
19+
ParticleID = cms.vint32(11)
20+
),
21+
PythiaParameters = cms.PSet(
22+
parameterSets = cms.vstring()
23+
),
24+
Verbosity = cms.untracked.int32(0),
25+
firstRun = cms.untracked.uint32(1),
26+
psethack = cms.string('single electron pt 10')
27+
)
28+
29+
process.genParticles = cms.EDProducer("GenParticleProducer",
30+
abortOnUnknownPDGCode = cms.untracked.bool(False),
31+
saveBarCodes = cms.untracked.bool(True),
32+
src = cms.InputTag("generator:unsmeared")
33+
)
34+
35+
36+
## define maximal number of events to loop over
37+
process.maxEvents = cms.untracked.PSet(
38+
input = cms.untracked.int32(100)
39+
)
40+
## configure process options
41+
process.options = cms.untracked.PSet(
42+
allowUnscheduled = cms.untracked.bool(True),
43+
wantSummary = cms.untracked.bool(True)
44+
)
45+
46+
process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi')
47+
process.load("GeneratorInterface.RivetInterface.genParticles2HepMC_cfi")
48+
process.load("GeneratorInterface.RivetInterface.particleLevel_cfi")
49+
process.particleLevel.src = cms.InputTag("genParticles2HepMC:unsmeared")
50+
51+
process.path = cms.Path(process.generator*process.genParticles*process.genParticles2HepMC*process.particleLevel)
52+
53+
process.out = cms.OutputModule("PoolOutputModule",
54+
fileName = cms.untracked.string("particleLevel.root"),
55+
outputCommands = cms.untracked.vstring(
56+
"drop *",
57+
"keep *_genParticles_*_*",
58+
"keep *_particleLevel_*_*",
59+
),
60+
)
61+
process.outPath = cms.EndPath(process.out)

0 commit comments

Comments
 (0)