Skip to content

Instantly share code, notes, and snippets.

@artlbv
Created October 12, 2023 12:47
Show Gist options
  • Save artlbv/738c7b69a0d1de5a1e628b2b4a5797da to your computer and use it in GitHub Desktop.
Save artlbv/738c7b69a0d1de5a1e628b2b4a5797da to your computer and use it in GitHub Desktop.
Phase2 L1 Menu and GT nano ntupler
import FWCore.ParameterSet.Config as cms
from PhysicsTools.NanoAOD.nano_eras_cff import *
from PhysicsTools.NanoAOD.common_cff import *
##################################################################
### This part can be taken from l1trig_cff starting from 13X
l1_float_precision_=16
l1PtVars = cms.PSet(
pt = Var("pt", float, precision=l1_float_precision_),
phi = Var("phi", float, precision=l1_float_precision_),
)
l1P3Vars = cms.PSet(
l1PtVars,
eta = Var("eta", float, precision=l1_float_precision_),
)
l1ObjVars = cms.PSet(
l1P3Vars,
hwPt = Var("hwPt()",int,doc="hardware pt"),
hwEta = Var("hwEta()",int,doc="hardware eta"),
hwPhi = Var("hwPhi()",int,doc="hardware phi"),
hwQual = Var("hwQual()",int,doc="hardware qual"),
hwIso = Var("hwIso()",int,doc="hardware iso")
)
l1GTObjVars = cms.PSet(
l1P3Vars,
#z0 = Var("z0()",int,doc="z0"),
)
### This above part can be taken from l1trig_cff starting from 13X
##################################################################
### Tables definitions
### EG
gtTkEleTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','CL2Electrons'),
cut = cms.string(""),
name = cms.string("GTtkElectron"),
doc = cms.string("GT tkElectrons"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
#z0 = Var("z0()",int,doc="z0"),
)
)
gtTkPhoTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','CL2Photons'),
cut = cms.string(""),
name = cms.string("GTtkPhoton"),
doc = cms.string("GT tkPhotons"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
#iso = Var("iso()",int,doc="z0"),
)
)
gtTkMuTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','GMTTkMuons'),
cut = cms.string(""),
name = cms.string("GTgmtTkMuon"),
doc = cms.string("GT GMT tkMuon"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
#iso = Var("iso()",int,doc="z0"),
#hwQual = Var("hwQual()",int,doc="hwQual"),
)
)
gtSCJetsTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','CL2Jets'),
cut = cms.string(""),
name = cms.string("GTscJets"),
doc = cms.string("GT seededCone Puppi Jets"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
)
)
gtNNTauTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','CL2Taus'),
cut = cms.string(""),
name = cms.string("GTnnTaus"),
doc = cms.string("GT NNpuppi Taus"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
)
)
gtEtSumTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','CL2EtSum'),
cut = cms.string(""),
name = cms.string("GTetSum"),
doc = cms.string("GT etSum"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
)
)
gtHtSumTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tGTProducer','CL2HtSum'),
cut = cms.string(""),
name = cms.string("GThtSum"),
doc = cms.string("GT htSum"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1GTObjVars,
mht = Var("pt", int, doc="MHT"),
#ht = Var("scasum", int, doc="HT"),
)
)
#### EG
tkEleTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tLayer2EG','L1CtTkElectron'),
cut = cms.string(""),
name = cms.string("tkElectron"),
doc = cms.string("Tk Electrons"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1ObjVars,
charge = Var("charge", int, doc="charge id"),
)
)
tkPhotonTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tLayer2EG','L1CtTkEm'),
cut = cms.string(""),
name = cms.string("tkPhoton"),
doc = cms.string("Tk Photons (EM)"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1ObjVars,
)
)
## standalone EG
staEGbarrelTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tPhase2L1CaloEGammaEmulator','GCTEGammas'),
cut = cms.string(""),
name = cms.string("EGbarrel"),
doc = cms.string("standalone EG barrel"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1ObjVars,
)
)
staEGendcapTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tLayer2EG','L1CtEgEE'),
cut = cms.string(""),
name = cms.string("EGendcap"),
doc = cms.string("standalone EG endcap"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1ObjVars,
)
)
### Muons
gmtTkMuTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tTkMuonsGmt',''),
cut = cms.string(""),
name = cms.string("gmtTkMuons"),
doc = cms.string("GMT Tk Muons"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1ObjVars,
charge = Var("charge", int, doc="charge id"),
)
)
staMuTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tSAMuonsGmt','promptSAMuons'),
cut = cms.string(""),
name = cms.string("StaMu"),
doc = cms.string("GMT STA Muons"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1ObjVars,
charge = Var("charge", int, doc="charge id"),
)
)
### Jets
scJetTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag('l1tSCPFL1PuppiCorrectedEmulator'),
cut = cms.string(""),
name = cms.string("seededConeJet"),
doc = cms.string("SeededCone 0.4 Puppi jet"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1P3Vars,
)
)
histoJetTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag("l1tPhase1JetCalibrator9x9" , "Phase1L1TJetFromPfCandidates"),
cut = cms.string(""),
name = cms.string("histoJet"),
doc = cms.string("Puppi Jets 9x9"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1P3Vars,
)
)
caloJetTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag("l1tCaloJet","L1CaloJetCollectionBXV"),
cut = cms.string(""),
name = cms.string("caloJet"),
doc = cms.string("Calo Jets"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1P3Vars,
)
)
### SUMS
puppiMetTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag("l1tMETPFProducer",""),
# cut = cms.string(""),
name = cms.string("puppiMET"),
doc = cms.string("Puppi MET"),
singleton = cms.bool(True), # the number of entries is variable
variables = cms.PSet(
l1PtVars
)
)
seededConeSumsTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag("l1tSCPFL1PuppiCorrectedEmulatorMHT",""),
cut = cms.string(""),
name = cms.string("seededConeHTMHT"),
doc = cms.string("HT and MHT from SeededCone jets"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1PtVars
)
)
### CHANGE TO TRIMMED WHEN AVAILABLE
### TAG IS l1tPhase1JetSumsProducer9x9trimmed
histoSumsTable = seededConeSumsTable.clone(
src = cms.InputTag("l1tPhase1JetSumsProducer9x9","Sums"),
name = cms.string("histoHTMHT"),
doc = cms.string("HT and MHT from histogrammed jets"),
)
### Taus
caloTauTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag("l1tCaloJet","L1CaloTauCollectionBXV"),
cut = cms.string(""),
name = cms.string("caloTau"),
doc = cms.string("Calo Taus"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1P3Vars,
)
)
nnTauTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
src = cms.InputTag("l1tNNTauProducerPuppi","L1PFTausNN"),
cut = cms.string(""),
name = cms.string("nnTau"),
doc = cms.string("NN Taus"),
singleton = cms.bool(False), # the number of entries is variable
variables = cms.PSet(
l1P3Vars,
)
)
p2L1TablesTask = cms.Task(
# ## muons
# gmtTkMuTable,
# staMuTable,
# ## jets
# # scJetTable,
# histoJetTable,
# caloJetTable,
# ## taus
# puppiMetTable,
# seededConeSumsTable,
# histoSumsTable,
## taus
# caloTauTable,
# nnTauTable,
## EG
gtTkPhoTable,
gtTkEleTable,
gtTkMuTable,
gtSCJetsTable,
gtNNTauTable,
gtEtSumTable,
gtHtSumTable,
#
tkPhotonTable,
tkEleTable,
gmtTkMuTable,
scJetTable,
nnTauTable,
nnTauTable,
seededConeSumsTable,
#staEGbarrelTable,
#staEGendcapTable,
)
@artlbv
Copy link
Author

artlbv commented Oct 12, 2023

HowTo use:

in the cmsRun config where the P2GT producer is called do:

process.load('this_file_cff')                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                            
process.outnano = cms.OutputModule("NanoAODOutputModule",                                                                                                                                                                                                                                                                                                                   
                                   fileName = cms.untracked.string("perfNano_Ph2Menu.root"),                                                                                                                                                                                                                                                                                
                                   outputCommands = cms.untracked.vstring("drop *", "keep nanoaodFlatTable_*Table_*_*"),                                                                                                                                                                                                                                                    
                                   compressionLevel = cms.untracked.int32(4),                                                                                                                                                                                                                                                                                               
                                   compressionAlgorithm = cms.untracked.string("ZLIB"),                                                                                                                                                                                                                                                                                     
)                                                                                                                                                                                                                                                                                                                                                                           
process.end = cms.EndPath(process.outnano)  

and then add to the schedule:

process.schedule = cms.Schedule(       
    ...
    process.end,                                                                                                                                                                                                                                                                                                                                                            
    tasks = [                                                                                                                                                                                                                                                                                                                                                               
        process.p2L1TablesTask                                                                                                                                                                                                                                                                                                                                              
    ],                                                                                                                                                                                                                                                                                                                                                                      
)                     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment