-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsd_cfg.py
134 lines (110 loc) · 4.6 KB
/
gsd_cfg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# coding: utf-8
"""
Config file for running GEN, SIM and DIGI steps with configurable gun / physics process and pileup.
"""
import os
import math
import FWCore.ParameterSet.Config as cms
from FWCore.ParameterSet.VarParsing import VarParsing
from reco_prodtools.templates.GSD_fragment import process
# constants
HGCAL_Z = 319.0
HGCAL_ETA_MIN = 1.52
HGCAL_ETA_MAX = 3.00
# helpers
def calculate_rho(z, eta):
return z * math.tan(2 * math.atan(math.exp(-eta)))
# option parsing
options = VarParsing("python")
options.setDefault("outputFile", "file:gsd.root")
options.setDefault("maxEvents", 1)
options.register("generator", "flatEtaGun:50", VarParsing.multiplicity.singleton,
VarParsing.varType.string, "a string that configures the generator or physics process")
options.register("pileup", 0, VarParsing.multiplicity.singleton, VarParsing.varType.int,
"pileup")
options.register("seed", 1, VarParsing.multiplicity.singleton, VarParsing.varType.int,
"random seed")
options.parseArguments()
# input / output
process.maxEvents.input = cms.untracked.int32(options.maxEvents)
process.FEVTDEBUGHLToutput.fileName = cms.untracked.string(
options.__getattr__("outputFile", noTags=True))
process.source.firstLuminosityBlock = cms.untracked.uint32(1)
# random seeds
seed = int(options.seed) + 1
process.RandomNumberGeneratorService.generator.initialSeed = cms.untracked.uint32(seed)
process.RandomNumberGeneratorService.VtxSmeared.initialSeed = cms.untracked.uint32(seed)
process.RandomNumberGeneratorService.mix.initialSeed = cms.untracked.uint32(seed)
# generator gun or physics process
gen_parts = options.generator.split(":")
if gen_parts[0] == "flatEtaGun":
defaults = ("50", "3.0", "100.0")
gen_parts += defaults[len(gen_parts) - 1:]
process.generator = cms.EDProducer("FlatEtaRangeGunProducer",
# particle ids
particleIDs=cms.vint32(22, 22, 11, -11, 211, -211, 13, -13),
# max number of particles to shoot at a time
nParticles=cms.int32(int(gen_parts[1])),
# shoot exactly the particles defined in particleIDs in that order
exactShoot=cms.bool(False),
# randomly shoot [1, nParticles] particles, each time randomly drawn from particleIDs
randomShoot=cms.bool(False),
# energy range
eMin=cms.double(float(gen_parts[2])),
eMax=cms.double(float(gen_parts[3])),
# phi range
phiMin=cms.double(-math.pi),
phiMax=cms.double(math.pi),
# eta range
etaMin=cms.double(HGCAL_ETA_MIN),
etaMax=cms.double(HGCAL_ETA_MAX),
# misc
debug=cms.untracked.bool(True),
)
elif gen_parts[0] == "flatDeltaRGun":
defaults = ("50", "3.0", "100.0", "0.0", "0.5")
gen_parts += defaults[len(gen_parts) - 1:]
process.generator = cms.EDProducer("CloseByFlatDeltaRGunProducer",
# particle ids
particleIDs=cms.vint32(22, 22, 11, -11, 211, -211, 13, -13),
# max number of particles to shoot at a time
nParticles=cms.int32(int(gen_parts[1])),
# shoot exactly the particles defined in particleIDs in that order
exactShoot=cms.bool(False),
# randomly shoot [1, nParticles] particles, each time randomly drawn from particleIDs
randomShoot=cms.bool(False),
# energy range
eMin=cms.double(float(gen_parts[2])),
eMax=cms.double(float(gen_parts[3])),
# phi range
phiMin=cms.double(-math.pi),
phiMax=cms.double(math.pi),
# eta range
etaMin=cms.double(HGCAL_ETA_MIN),
etaMax=cms.double(HGCAL_ETA_MAX),
# longitudinal gun position in cm
zMin=cms.double(0.),
zMax=cms.double(0.),
# deltaR settings
deltaRMin=cms.double(float(gen_parts[4])),
deltaRMax=cms.double(float(gen_parts[5])),
# misc
debug=cms.untracked.bool(True),
)
else:
raise ValueError("unknown generator type '{}'".format(gen_parts[0]))
# configure pileup
if options.pileup > 0:
process.load("SimGeneral.MixingModule.mix_POISSON_average_cfi")
process.mix.input.nbPileupEvents.averageNumber = cms.double(options.pileup)
local_pu_dir = "/eos/cms/store/cmst3/group/hgcal/CMG_studies/pepr/pu/RelvalMinBias14_106X_upgrade2023_realistic_v3_2023D41noPU-v1" # noqa
process.mix.input.fileNames = cms.untracked.vstring([
"file://" + os.path.abspath(os.path.join(local_pu_dir, elem))
for elem in os.listdir(local_pu_dir)
if elem.endswith(".root")
])
else:
process.load("SimGeneral.MixingModule.mixNoPU_cfi")
# print some stats
print("pileup : {}".format(options.pileup))
print("generator: {}".format(process.generator.dumpConfig()))