Skip to content

Commit

Permalink
Modify NANOGEN to use autoNANO.
Browse files Browse the repository at this point in the history
  • Loading branch information
hqucms committed Jul 10, 2024
1 parent db3008e commit e193249
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 63 deletions.
14 changes: 0 additions & 14 deletions Configuration/Applications/python/ConfigBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,6 @@ def define_Configs(self):
self.RECOSIMDefaultCFF="Configuration/StandardSequences/RecoSim_cff"
self.PATDefaultCFF="Configuration/StandardSequences/PAT_cff"
self.NANODefaultCFF="PhysicsTools/NanoAOD/nano_cff"
self.NANOGENDefaultCFF="PhysicsTools/NanoAOD/nanogen_cff"
self.SKIMDefaultCFF="Configuration/StandardSequences/Skims_cff"
self.POSTRECODefaultCFF="Configuration/StandardSequences/PostRecoGenerator_cff"
self.VALIDATIONDefaultCFF="Configuration/StandardSequences/Validation_cff"
Expand Down Expand Up @@ -1057,7 +1056,6 @@ def define_Configs(self):
self.PATDefaultSeq='miniAOD'
self.PATGENDefaultSeq='miniGEN'
#TODO: Check based of file input
self.NANOGENDefaultSeq='nanogenSequence'
self.NANODefaultSeq='nanoSequence'
self.NANODefaultCustom='nanoAOD_customizeCommon'

Expand Down Expand Up @@ -1844,18 +1842,6 @@ def prepare_NANO(self, stepSpec = '' ):
self._options.customise_commands = self._options.customise_commands + " \n"
self._options.customise_commands = self._options.customise_commands + "process.unpackedPatTrigger.triggerResults= cms.InputTag( 'TriggerResults::"+self._options.hltProcess+"' )\n"

def prepare_NANOGEN(self, stepSpec = "nanoAOD"):
''' Enrich the schedule with NANOGEN '''
# TODO: Need to modify this based on the input file type
fromGen = any([x in self.stepMap for x in ['LHE', 'GEN', 'AOD']])
_,_nanogenSeq,_nanogenCff = self.loadDefaultOrSpecifiedCFF(stepSpec,self.NANOGENDefaultCFF)
self.scheduleSequence(_nanogenSeq,'nanoAOD_step')
custom = "customizeNanoGEN" if fromGen else "customizeNanoGENFromMini"
if self._options.runUnscheduled:
self._options.customisation_file_unsch.insert(0, '.'.join([_nanogenCff, custom]))
else:
self._options.customisation_file.insert(0, '.'.join([_nanogenCff, custom]))

def prepare_SKIM(self, stepSpec = "all"):
''' Enrich the schedule with skimming fragments'''
skimConfig,sequence,_ = self.loadDefaultOrSpecifiedCFF(stepSpec,self.SKIMDefaultCFF)
Expand Down
9 changes: 0 additions & 9 deletions PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,3 @@
compressionLevel = cms.untracked.int32(9),
compressionAlgorithm = cms.untracked.string("LZMA"),
)

NanoGenOutput = NanoAODEDMEventContent.outputCommands[:]
NanoGenOutput.remove("keep edmTriggerResults_*_*_*")

NANOAODGENEventContent = cms.PSet(
compressionLevel = cms.untracked.int32(9),
compressionAlgorithm = cms.untracked.string("LZMA"),
outputCommands = cms.untracked.vstring(NanoGenOutput)
)
89 changes: 49 additions & 40 deletions PhysicsTools/NanoAOD/python/autoNANO.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,76 @@
def expandNanoMapping(seqList, mapping, key):
maxLevel=30
level=0
while '@' in repr(seqList) and level<maxLevel:
level+=1
maxLevel = 30
level = 0
while '@' in repr(seqList) and level < maxLevel:
level += 1
for specifiedCommand in seqList:
if specifiedCommand.startswith('@'):
location=specifiedCommand[1:]
location = specifiedCommand[1:]
if not location in mapping:
raise Exception("Impossible to map "+location+" from "+repr(mapping))
mappedTo=mapping[location]
raise Exception("Impossible to map " + location + " from " + repr(mapping))
mappedTo = mapping[location]
# no mapping for specified key
# NOTE: mising key of key=None is interpreted differently than empty string:
# - An empty string recalls the default for the given key
# - None is interpreted as "ignore this"
insertAt=seqList.index(specifiedCommand)
insertAt = seqList.index(specifiedCommand)
seqList.remove(specifiedCommand)
if key in mappedTo and mappedTo[key] is not None:
allToInsert=mappedTo[key].split('+')
for offset,toInsert in enumerate(allToInsert):
seqList.insert(insertAt+offset,toInsert)
break;
if level==maxLevel:
raise Exception("Could not fully expand "+repr(seqList)+" from "+repr(mapping))
allToInsert = mappedTo[key].split('+')
for offset, toInsert in enumerate(allToInsert):
seqList.insert(insertAt + offset, toInsert)
break
if level == maxLevel:
raise Exception("Could not fully expand " + repr(seqList) + " from " + repr(mapping))


autoNANO = {
# PHYS is a mapping to the default NANO config, i.e. empty strings
'PHYS': {'sequence': '',
'customize': ''},
# L1 flavours: add tables through customize, supposed to be combined with PHYS
'L1' : {'customize': 'PhysicsTools/NanoAOD/l1trig_cff.nanoL1TrigObjCustomize'},
'L1FULL' : {'customize': 'PhysicsTools/NanoAOD/l1trig_cff.nanoL1TrigObjCustomizeFull'},
#scouting nano
'Scout' : {'sequence': 'PhysicsTools/NanoAOD/custom_run3scouting_cff'},
'JME' : { 'sequence': '@PHYS',
'customize': '@PHYS+PhysicsTools/NanoAOD/custom_jme_cff.PrepJMECustomNanoAOD'},
'JMErePuppi' : { 'sequence': '@PHYS',
'customize': '@PHYS+@JME+PhysicsTools/NanoAOD/custom_jme_cff.RecomputePuppiWeightsAndMET'},
'L1': {'customize': 'PhysicsTools/NanoAOD/l1trig_cff.nanoL1TrigObjCustomize'},
'L1FULL': {'customize': 'PhysicsTools/NanoAOD/l1trig_cff.nanoL1TrigObjCustomizeFull'},
# scouting nano
'Scout': {'sequence': 'PhysicsTools/NanoAOD/custom_run3scouting_cff'},
# JME nano
'JME': {'sequence': '@PHYS',
'customize': '@PHYS+PhysicsTools/NanoAOD/custom_jme_cff.PrepJMECustomNanoAOD'},
'JMErePuppi': {'sequence': '@PHYS',
'customize': '@PHYS+@JME+PhysicsTools/NanoAOD/custom_jme_cff.RecomputePuppiWeightsAndMET'},
# L1 DPG (standalone with full calo TP info, L1T reemulation customization)
'L1DPG' : {'sequence': 'DPGAnalysis/L1TNanoAOD/l1tNano_cff.l1tNanoSequence',
'customize': 'PhysicsTools/NanoAOD/l1trig_cff.nanoL1TrigObjCustomizeFull,DPGAnalysis/L1TNanoAOD/l1tNano_cff.addCaloFull,L1Trigger/Configuration/customiseReEmul.L1TReEmulFromRAW'},
'customize': ','.join(['PhysicsTools/NanoAOD/l1trig_cff.nanoL1TrigObjCustomizeFull',
'DPGAnalysis/L1TNanoAOD/l1tNano_cff.addCaloFull',
'L1Trigger/Configuration/customiseReEmul.L1TReEmulFromRAW'])},
# Muon POG flavours : add tables through customize, supposed to be combined with PHYS
'MUPOG' : {'sequence': '@PHYS',
'customize' : '@PHYS+PhysicsTools/NanoAOD/custom_muon_cff.PrepMuonCustomNanoAOD'},
'MUPOG': {'sequence': '@PHYS',
'customize': '@PHYS+PhysicsTools/NanoAOD/custom_muon_cff.PrepMuonCustomNanoAOD'},
# MUDPG flavours: use their own sequence
'MUDPG' : {'sequence': 'DPGAnalysis/MuonTools/muNtupleProducer_cff.muDPGNanoProducer',
'customize': 'DPGAnalysis/MuonTools/muNtupleProducer_cff.muDPGNanoCustomize'},
'MUDPGBKG' : {'sequence': 'DPGAnalysis/MuonTools/muNtupleProducerBkg_cff.muDPGNanoProducerBkg',
'customize': 'DPGAnalysis/MuonTools/muNtupleProducerBkg_cff.muDPGNanoBkgCustomize'},
# HCAL favlours:
'HCAL' : {'sequence': 'DPGAnalysis/HcalNanoAOD/hcalNano_cff.hcalNanoTask'},
'HCALCalib' : { 'sequence': 'DPGAnalysis/HcalNanoAOD/hcalNano_cff.hcalNanoTask',
'customize': 'DPGAnalysis/HcalNanoAOD/hcalNano_cff.customiseHcalCalib'},
#EGM flavours: add variables through customize
'EGM' : {'sequence': '@PHYS',
'customize' : '@PHYS+PhysicsTools/NanoAOD/egamma_custom_cff.addExtraEGammaVarsCustomize'},
'MUDPG': {'sequence': 'DPGAnalysis/MuonTools/muNtupleProducer_cff.muDPGNanoProducer',
'customize': 'DPGAnalysis/MuonTools/muNtupleProducer_cff.muDPGNanoCustomize'},
'MUDPGBKG': {'sequence': 'DPGAnalysis/MuonTools/muNtupleProducerBkg_cff.muDPGNanoProducerBkg',
'customize': 'DPGAnalysis/MuonTools/muNtupleProducerBkg_cff.muDPGNanoBkgCustomize'},
# HCAL flavors:
'HCAL': {'sequence': 'DPGAnalysis/HcalNanoAOD/hcalNano_cff.hcalNanoTask'},
'HCALCalib': {'sequence': 'DPGAnalysis/HcalNanoAOD/hcalNano_cff.hcalNanoTask',
'customize': 'DPGAnalysis/HcalNanoAOD/hcalNano_cff.customiseHcalCalib'},
# EGM flavours: add variables through customize
'EGM': {'sequence': '@PHYS',
'customize': '@PHYS+PhysicsTools/NanoAOD/egamma_custom_cff.addExtraEGammaVarsCustomize'},
# PromptReco config: PHYS+L1
'Prompt' : {'sequence': '@PHYS',
'customize': '@PHYS+@L1'},
'Prompt': {'sequence': '@PHYS',
'customize': '@PHYS+@L1'},
# Add lepton track parameters through customize combined with PHYS
'LepTrackInfo' : {'sequence': '@PHYS',
'customize': '@PHYS+PhysicsTools/NanoAOD/leptonTimeLifeInfo_common_cff.addTrackVarsToTimeLifeInfo'},
# Custom BTV Nano for SF measurements or tagger training
'BTV' : {'sequence': '@PHYS',
'customize':'@PHYS+PhysicsTools/NanoAOD/custom_btv_cff.BTVCustomNanoAOD'}
'BTV': {'sequence': '@PHYS',
'customize': '@PHYS+PhysicsTools/NanoAOD/custom_btv_cff.BTVCustomNanoAOD'},
# NANOGEN (from LHE/GEN/AOD)
'GEN': {'sequence': 'PhysicsTools/NanoAOD/nanogen_cff.nanogenSequence',
'customize': 'PhysicsTools/NanoAOD/nanogen_cff.customizeNanoGEN'},
# NANOGEN (from MiniAOD)
'GENFromMini': {'sequence': 'PhysicsTools/NanoAOD/nanogen_cff.nanogenSequence',
'customize': 'PhysicsTools/NanoAOD/nanogen_cff.customizeNanoGENFromMini'},
}
5 changes: 5 additions & 0 deletions PhysicsTools/NanoAOD/python/nanogen_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def nanoGenCommonCustomize(process):
setGenPhiPrecision(process, CandVars.phi.precision)
setGenMassPrecision(process, CandVars.mass.precision)

for output in ("NANOEDMAODSIMoutput", "NANOAODSIMoutput"):
if hasattr(process, output):
getattr(process, output).outputCommands.append("drop edmTriggerResults_*_*_*")

def customizeNanoGENFromMini(process):
process.nanogenSequence.insert(0, process.genParticles2HepMCHiggsVtx)
process.nanogenSequence.insert(0, process.genParticles2HepMC)
Expand All @@ -71,6 +75,7 @@ def customizeNanoGENFromMini(process):
process.genParticleTable.src = "prunedGenParticles"
process.patJetPartonsNano.particles = "prunedGenParticles"
process.particleLevel.src = "genParticles2HepMC:unsmeared"
process.genIso.genPart = "prunedGenParticles"

process.genJetTable.src = "slimmedGenJets"
process.genJetAK8Table.src = "slimmedGenJetsAK8"
Expand Down

0 comments on commit e193249

Please sign in to comment.