Skip to content

Commit 5d0f11b

Browse files
authored
Merge pull request cms-sw#33555 from christopheralanwest/alca-run-dependent-mc_12_0_X
Make run-dependent MC configurable with cmsDriver options
2 parents 92b8b51 + 8c537cb commit 5d0f11b

File tree

12 files changed

+91
-13
lines changed

12 files changed

+91
-13
lines changed

CalibCalorimetry/EcalLaserCorrection/plugins/EcalLaserCorrectionServiceMC.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
#include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosMCRcd.h"
2323
#include "CondFormats/DataRecord/interface/EcalLinearCorrectionsRcd.h"
2424

25+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
26+
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
27+
2528
class EcalLaserCorrectionServiceMC : public edm::ESProducer {
2629
public:
2730
EcalLaserCorrectionServiceMC(const edm::ParameterSet&);
2831
~EcalLaserCorrectionServiceMC() override;
2932

3033
std::shared_ptr<EcalLaserDbService> produce(const EcalLaserDbRecordMC&);
34+
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
3135

3236
private:
3337
using HostType = edm::ESProductHost<EcalLaserDbService,
@@ -64,6 +68,10 @@ EcalLaserCorrectionServiceMC::~EcalLaserCorrectionServiceMC() {}
6468
//
6569
// member functions
6670
//
71+
void EcalLaserCorrectionServiceMC::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
72+
edm::ParameterSetDescription desc;
73+
descriptions.add("EcalLaserCorrectionServiceMC", desc);
74+
}
6775

6876
// ------------ method called to produce the data ------------
6977
std::shared_ptr<EcalLaserDbService> EcalLaserCorrectionServiceMC::produce(const EcalLaserDbRecordMC& record) {

Configuration/Applications/python/ConfigBuilder.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class Options:
8282
defaultOptions.fast=False
8383
defaultOptions.runsAndWeightsForMC = None
8484
defaultOptions.runsScenarioForMC = None
85+
defaultOptions.runsAndWeightsForMCIntegerWeights = None
86+
defaultOptions.runsScenarioForMCIntegerWeights = None
8587
defaultOptions.runUnscheduled = False
8688
defaultOptions.timeoutOutput = False
8789
defaultOptions.nThreads = '1'
@@ -496,6 +498,30 @@ def filesFromOption(self):
496498
self.additionalCommands.append('import SimGeneral.Configuration.ThrowAndSetRandomRun as ThrowAndSetRandomRun')
497499
self.additionalCommands.append('ThrowAndSetRandomRun.throwAndSetRandomRun(process.source,%s)'%(self.runsAndWeights))
498500

501+
# modify source in case of run-dependent MC (Run-3 method)
502+
self.runsAndWeightsInt=None
503+
if self._options.runsAndWeightsForMCIntegerWeights or self._options.runsScenarioForMCIntegerWeights:
504+
if not self._options.isMC :
505+
raise Exception("options --runsAndWeightsForMCIntegerWeights and --runsScenarioForMCIntegerWeights are only valid for MC")
506+
if self._options.runsAndWeightsForMCIntegerWeights:
507+
self.runsAndWeightsInt = eval(self._options.runsAndWeightsForMCIntegerWeights)
508+
else:
509+
from Configuration.StandardSequences.RunsAndWeights import RunsAndWeights
510+
if isinstance(RunsAndWeights[self._options.runsScenarioForMCIntegerWeights], str):
511+
__import__(RunsAndWeights[self._options.runsScenarioForMCIntegerWeights])
512+
self.runsAndWeightsInt = sys.modules[RunsAndWeights[self._options.runsScenarioForMCIntegerWeights]].runProbabilityDistribution
513+
else:
514+
self.runsAndWeightsInt = RunsAndWeights[self._options.runsScenarioForMCIntegerWeights]
515+
516+
if self.runsAndWeightsInt:
517+
if not self._options.relval:
518+
raise Exception("--relval option required when using --runsAndWeightsInt")
519+
if 'DATAMIX' in self._options.step:
520+
from SimGeneral.Configuration.LumiToRun import lumi_to_run
521+
total_events, events_per_job = self._options.relval.split(',')
522+
lumi_to_run_mapping = lumi_to_run(self.runsAndWeightsInt, int(total_events), int(events_per_job))
523+
self.additionalCommands.append("process.source.firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID(*[cms.LuminosityBlockID(x,y) for x,y in " + str(lumi_to_run_mapping) + "])")
524+
499525
return
500526

501527
def addOutput(self):

Configuration/Applications/python/Options.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
default=False)
9090

9191
parser.add_option("--runsAndWeightsForMC",
92-
help="Assign run numbers to MC source according to relatieve weights. [(run1,weight1),...,(runN,weightN)])",
92+
help="Assign run numbers to MC source according to relative weights. [(run1,weight1),...,(runN,weightN)])",
9393
default=None,
9494
dest="runsAndWeightsForMC")
9595

@@ -98,6 +98,16 @@
9898
default=None,
9999
dest="runsScenarioForMC")
100100

101+
parser.add_option("--runsAndWeightsForMCIntegerWeights",
102+
help="Assign run numbers to MC source according to relative weights where weighting is determined by the number of times the run number appears. [(run1,run2,...,runN)])",
103+
default=None,
104+
dest="runsAndWeightsForMCIntegerWeights")
105+
106+
parser.add_option("--runsScenarioForMCIntegerWeights",
107+
help="Load a scenario to set run numbers in MC with integer IOV weights.)",
108+
default=None,
109+
dest="runsScenarioForMCIntegerWeights")
110+
101111
parser.add_option("--runUnscheduled",
102112
help="Automatically convert configuration to run unscheduled the EDProducers/EDFilters that were scheduled",
103113
action="store_true",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
# This modifier is for configuration changes specific to run-dependent MC.
4+
# In order to preserve the possibily of multi-year MC, only one run-dependent MC
5+
# modifier should exist and be used for all years.
6+
7+
runDependent = cms.Modifier()

Configuration/PyReleaseValidation/python/relval_premix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
workflows[250202.18]=['',['TTbar_13UP18','DIGIPRMXUP18_PU25','RECOPRMXUP18_PU25','HARVESTUP18_PU25']]
4949
workflows[250202.181]=['',['TTbar_13UP18','PREMIXUP18_PU25','DIGIPRMXLOCALUP18_PU25','RECOPRMXUP18_PU25','HARVESTUP18_PU25']]
5050
workflows[250202.182]=['',['TTbar_13UP18_RD','DIGIPRMXUP18_PU25_RD','RECOPRMXUP18_PU25_RD','HARVESTUP18_PU25_RD']]
51-
workflows[250202.183]=['',['TTbar_13UP18_RD','DIGIPRMXUP18_PU25_RD_IB','RECOPRMXUP18_PU25_RD','HARVESTUP18_PU25_RD']]
51+
workflows[250202.183]=['',['TTbar_13UP18_RD_IB','DIGIPRMXUP18_PU25_RD_IB','RECOPRMXUP18_PU25_RD','HARVESTUP18_PU25_RD']]
5252
workflows[250203.18]=['',['H125GGgluonfusion_13UP18','DIGIPRMXUP18_PU25','RECOPRMXUP18_PU25','HARVESTUP18_PU25']]
5353
workflows[250204.18]=['',['QQH1352T_13UP18','DIGIPRMXUP18_PU25','RECOPRMXUP18_PU25','HARVESTUP18_PU25']]
5454
workflows[250205.18]=['',['ZTT_13UP18','DIGIPRMXUP18_PU25','RECOPRMXUP18_PU25','HARVESTUP18_PU25']]

Configuration/PyReleaseValidation/python/relval_steps.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,13 +1454,17 @@ def lhegensim2018(fragment,howMuch):
14541454
return merge([{'cfg':fragment},howMuch,step1LHEGenSimUp2018Default])
14551455

14561456
# Run-Dependent MC
1457+
kevents_rd = 9
1458+
events_per_job_rd = 50
14571459
def gen2018RD(fragment,howMuch):
14581460
global step1Up2018Defaults
1459-
return merge([{'cfg':fragment},howMuch,{'--conditions':'auto:phase1_2018_realistic_rd','--customise_commands': "\"process.source.numberEventsInLuminosityBlock=cms.untracked.uint32(5) \""},step1Up2018Defaults])
1461+
return merge([{'cfg':fragment},howMuch,{'--conditions':'auto:phase1_2018_realistic_rd','--customise_commands': "\"process.source.numberEventsInLuminosityBlock=cms.untracked.uint32(" + str(events_per_job_rd) + ") \""},step1Up2018Defaults])
14601462

1461-
steps['ZEE_13UP18_RD']=gen2018RD('ZEE_13TeV_TuneCUETP8M1_cfi',Kby(10,50))
1462-
steps['ZMM_13UP18_RD']=gen2018RD('ZMM_13TeV_TuneCUETP8M1_cfi',Kby(10,50))
1463-
steps['TTbar_13UP18_RD']=gen2018RD('TTbar_13TeV_TuneCUETP8M1_cfi',Kby(10,50))
1463+
steps['ZEE_13UP18_RD']=gen2018RD('ZEE_13TeV_TuneCUETP8M1_cfi',Kby(kevents_rd,events_per_job_rd))
1464+
steps['ZMM_13UP18_RD']=gen2018RD('ZMM_13TeV_TuneCUETP8M1_cfi',Kby(kevents_rd,events_per_job_rd))
1465+
steps['TTbar_13UP18_RD']=gen2018RD('TTbar_13TeV_TuneCUETP8M1_cfi',Kby(kevents_rd,events_per_job_rd))
1466+
steps['TTbar_13UP18_RD_IB']=gen2018RD('TTbar_13TeV_TuneCUETP8M1_cfi',Kby(kevents_rd,events_per_job_rd))
1467+
steps['TTbar_13UP18_RD_IB']['--customise_commands'] = "\"process.source.numberEventsInLuminosityBlock=cms.untracked.uint32(5)\""
14641468

14651469
steps['TTbar012Jets_NLO_Mad_py8_Evt_13']=lhegensim('Configuration/Generator/python/TTbar012Jets_5f_NLO_FXFX_Madgraph_LHE_13TeV_cfi.py',Kby(9,50))
14661470
steps['GluGluHToZZTo4L_M125_Pow_py8_Evt_13']=lhegensim('Configuration/Generator/python/GGHZZ4L_JHUGen_Pow_NNPDF30_LHE_13TeV_cfi.py', Kby(9,50))
@@ -1797,16 +1801,17 @@ def lhegensim2018ml(fragment,howMuch):
17971801
steps['DIGIPRMXLOCALUP18_PU25']=merge([digiPremixLocalPileupUp2018Defaults25ns])
17981802

17991803
# Run-Dependent MC: DIGI step; 17 is a dummy test; 2018 with 2000 lumis
1800-
steps['DIGIPRMXUP17_PU25_RD']=merge([digiPremixUp2017Defaults25ns, { '--customise_commands':"\"process.EcalLaserCorrectionServiceMC = cms.ESProducer('EcalLaserCorrectionServiceMC') \\n process.GlobalTag.toGet = cms.VPSet( cms.PSet( record = cms.string('EcalLaserAPDPNRatiosMCRcd'), tag = cms.string('EcalLaserAPDPNRatios_UL_2017_mc'), connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS') ) ) \\n process.mixData.workers.ecal.timeDependent=True\"" } ])
1804+
steps['DIGIPRMXUP17_PU25_RD']=merge([{'--procModifiers':'premix_stage2,runDependent'}, digiPremixUp2017Defaults25ns, { '--customise_commands':"\"process.GlobalTag.toGet = cms.VPSet( cms.PSet( record = cms.string('EcalLaserAPDPNRatiosMCRcd'), tag = cms.string('EcalLaserAPDPNRatios_UL_2017_mc'), connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS') ) )\""} ])
18011805

18021806
digiPremixRD2018 = {
1803-
'--pileup_input':'das:/RelValPREMIXUP18_PU25/%s/PREMIX'%baseDataSetRelease[24]
1807+
'--pileup_input':'das:/RelValPREMIXUP18_PU25/%s/PREMIX'%baseDataSetRelease[24],
1808+
'--procModifiers':'premix_stage2,runDependent'
18041809
}
18051810

1806-
steps['DIGIPRMXUP18_PU25_RD']=merge([digiPremixRD2018, {'--conditions':'auto:phase1_2018_realistic_rd', '--customise_commands':"\"process.EcalLaserCorrectionServiceMC = cms.ESProducer('EcalLaserCorrectionServiceMC') \\n process.mixData.workers.ecal.timeDependent=True \\n process.source.firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID(*[cms.LuminosityBlockID(x,y) for x,y in ((315257, 1), (316082, 222), (316720, 445), (317527, 668), (320917, 890), (321414, 1112), (321973, 1334), (322492, 1556), (324245, 1779))]) \""}, digiPremixUp2018Defaults25ns])
1811+
steps['DIGIPRMXUP18_PU25_RD']=merge([{'--conditions':'auto:phase1_2018_realistic_rd', '--relval': str(kevents_rd*1000) + ',' + str(events_per_job_rd), '--runsScenarioForMCIntegerWeights': 'Run2018_Equal_Lumi_Integer_Weights'}, digiPremixRD2018, digiPremixUp2018Defaults25ns])
18071812

18081813
# configuration to simulate cross run number boundary in IB, given 5 events per lumi
1809-
steps['DIGIPRMXUP18_PU25_RD_IB']=merge([digiPremixRD2018, {'--conditions':'auto:phase1_2018_realistic_rd', '--customise_commands':"\"process.EcalLaserCorrectionServiceMC = cms.ESProducer('EcalLaserCorrectionServiceMC') \\n process.mixData.workers.ecal.timeDependent=True \\n process.source.setRunNumberForEachLumi = cms.untracked.vuint32(315257,316083) \""}, digiPremixUp2018Defaults25ns])
1814+
steps['DIGIPRMXUP18_PU25_RD_IB']=merge([{'--conditions':'auto:phase1_2018_realistic_rd', '--customise_commands':"\"process.source.setRunNumberForEachLumi = cms.untracked.vuint32(315257,316083) \"", '--procModifiers':'premix_stage2,runDependent'}, digiPremixRD2018, digiPremixUp2018Defaults25ns])
18101815

18111816
premixProd25ns = {'-s' : 'DIGI,DATAMIX,L1,DIGI2RAW,HLT:@relval2016',
18121817
'--eventcontent' : 'PREMIXRAW',
@@ -2457,7 +2462,7 @@ def gen2021HiMix(fragment,howMuch):
24572462
steps['RECOPRMXUP18_PU25_L1TMuDQM']=merge([{'-s':'RAW2DIGI,L1Reco,RECO,RECOSIM,EI,PAT,VALIDATION:@standardValidationNoHLT+@miniAODValidation,DQM:@standardDQMFakeHLT+@miniAODDQM+@L1TMuon'},steps['RECOPRMXUP18_PU25']])
24582463

24592464
#Run-Dependent RECO
2460-
step_RECO18_RD = {'--conditions':'auto:phase1_2018_realistic_rd', '--customise_commands':"\"process.EcalLaserCorrectionServiceMC = cms.ESProducer('EcalLaserCorrectionServiceMC') \\n \""}
2465+
step_RECO18_RD = {'--conditions':'auto:phase1_2018_realistic_rd'}
24612466
steps['RECOPRMXUP18_PU25_RD']=merge([step_RECO18_RD, steps['RECOPRMXUP18_PU25']])
24622467
steps['RECOPRMXUP18_PU25_L1TEgDQM_RD']=merge([step_RECO18_RD, steps['RECOPRMXUP18_PU25_L1TEgDQM']])
24632468
steps['RECOPRMXUP18_PU25_L1TMuDQM_RD']=merge([step_RECO18_RD, steps['RECOPRMXUP18_PU25_L1TMuDQM']])
@@ -2981,7 +2986,7 @@ def gen2021HiMix(fragment,howMuch):
29812986
steps['HARVESTUP18_PU25_L1TMuDQM']=steps['HARVESTUP18_L1TMuDQM']
29822987

29832988
#Run-Dependent harvesting; using MultiRun harvesting + force RunNumber=1 for GUI MC
2984-
step_harvest_MRH_RD = {'--harvesting':'AtJobEnd','--customise_commands':'"process.dqmSaver.forceRunNumber = 1"'}
2989+
step_harvest_MRH_RD = {'--harvesting':'AtJobEnd', '--procModifiers':'runDependent'}
29852990
steps['HARVESTUP18_PU25_RD']=merge([step_harvest_MRH_RD,steps['HARVESTUP18']])
29862991
steps['HARVESTUP18_PU25_L1TEgDQM_RD']=merge([step_harvest_MRH_RD,steps['HARVESTUP18_L1TEgDQM']])
29872992
steps['HARVESTUP18_PU25_L1TMuDQM_RD']=merge([step_harvest_MRH_RD,steps['HARVESTUP18_L1TMuDQM']])

Configuration/StandardSequences/python/AdditionalConditions_cff.py

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

33
# the following are needed for non PoolDBESSources
44
from CalibCalorimetry.EcalLaserCorrection.ecalLaserCorrectionService_cfi import *
5+
from CalibCalorimetry.EcalLaserCorrection.EcalLaserCorrectionServiceMC_cfi import *
56
from CalibCalorimetry.HcalPlugins.Hcal_Conditions_forGlobalTag_cff import *
67
from CalibCalorimetry.CastorCalib.CastorDbProducer_cfi import *
78
from CalibTracker.Configuration.Tracker_DependentRecords_forGlobalTag_nofakes_cff import *

Configuration/StandardSequences/python/DQMSaverAtJobEnd_cff.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# needed output
77
from DQMServices.Components.DQMEnvironment_cfi import *
88

9+
# modifications for run-dependent MC
10+
from Configuration.ProcessModifiers.runDependent_cff import runDependent
911

1012
dqmSaver.convention = 'Offline'
1113
dqmSaver.workflow = '/Global/CMSSW_X_Y_Z/RECO'
@@ -17,6 +19,8 @@
1719

1820
DQMSaver = cms.Sequence(dqmSaver)
1921

22+
runDependent.toModify(dqmSaver, forceRunNumber = 1)
23+
2024
# configuration is modified as a side effect, this is just a placeholder
2125
# to allow using this file as a customisation for cmsDriver.
2226
def customise(process):
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
RunsAndWeights = {
22
'Run2012_AB_C_D_oneRunPerEra' : 'SimGeneral.Configuration.RunsAndWeights_Run2012_AB_C_D_oneRunPerEra',
3-
'Run2018_ABCD' : 'SimGeneral.Configuration.RunsAndWeights_Run2018_ABCD'
3+
'Run2018_ABCD' : 'SimGeneral.Configuration.RunsAndWeights_Run2018_ABCD',
4+
'Run2018_Equal_Lumi_Integer_Weights' : 'SimGeneral.Configuration.RunsAndWeights_Run2018_Equal_Lumi_Integer_Weights'
45
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def lumi_to_run(runs, events_in_sample, events_per_job):
2+
'''Print tuple for use in firstLuminosityBlockForEachRun'''
3+
n_iovs = len(runs)
4+
n_lumis = events_in_sample // events_per_job
5+
if n_lumis % n_iovs != 0:
6+
raise Exception('n_lumis should be evenly divisible by n_iovs.')
7+
pairs = []
8+
for i, run in enumerate(runs):
9+
pairs.append((run, 1 + i*n_lumis//n_iovs))
10+
return tuple(pairs)

0 commit comments

Comments
 (0)