Ejemplo n.º 1
0
def AddPileUpJetIDVars(proc):

  print("custom_jme_cff::AddPileUpJetIDVars: Recalculate pile-up jet ID variables and save them")

  #
  # Recalculate PUJet ID variables
  #
  from RecoJets.JetProducers.PileupJetID_cfi import pileupJetIdCalculator
  proc.pileupJetIdCalculatorAK4PFCHS = pileupJetIdCalculator.clone(
    jets = "updatedJets",
    vertexes  = "offlineSlimmedPrimaryVertices",
    inputIsCorrected = True,
    applyJec  = False 
  )
  proc.jetSequence.insert(proc.jetSequence.index(proc.updatedJets)+1, proc.pileupJetIdCalculatorAK4PFCHS)

  #
  # Get the variables
  #
  proc.puJetVarAK4PFCHS = cms.EDProducer("PileupJetIDVarProducer",
    srcJet = cms.InputTag("updatedJets"),    
    srcPileupJetId = cms.InputTag("pileupJetIdCalculatorAK4PFCHS")
  )
  proc.jetSequence.insert(proc.jetSequence.index(proc.jercVars)+1, proc.puJetVarAK4PFCHS)

  #
  # Save variables as userFloats and userInts in each jet
  # 
  proc.updatedJetsWithUserData.userFloats.dR2Mean  = cms.InputTag("puJetVarAK4PFCHS:dR2Mean")
  proc.updatedJetsWithUserData.userFloats.majW     = cms.InputTag("puJetVarAK4PFCHS:majW")
  proc.updatedJetsWithUserData.userFloats.minW     = cms.InputTag("puJetVarAK4PFCHS:minW")
  proc.updatedJetsWithUserData.userFloats.frac01   = cms.InputTag("puJetVarAK4PFCHS:frac01")
  proc.updatedJetsWithUserData.userFloats.frac02   = cms.InputTag("puJetVarAK4PFCHS:frac02")
  proc.updatedJetsWithUserData.userFloats.frac03   = cms.InputTag("puJetVarAK4PFCHS:frac03")
  proc.updatedJetsWithUserData.userFloats.frac04   = cms.InputTag("puJetVarAK4PFCHS:frac04")
  proc.updatedJetsWithUserData.userFloats.ptD      = cms.InputTag("puJetVarAK4PFCHS:ptD")
  proc.updatedJetsWithUserData.userFloats.beta     = cms.InputTag("puJetVarAK4PFCHS:beta")
  proc.updatedJetsWithUserData.userFloats.pull     = cms.InputTag("puJetVarAK4PFCHS:pull")
  proc.updatedJetsWithUserData.userFloats.jetR     = cms.InputTag("puJetVarAK4PFCHS:jetR")
  proc.updatedJetsWithUserData.userFloats.jetRchg  = cms.InputTag("puJetVarAK4PFCHS:jetRchg")
  proc.updatedJetsWithUserData.userInts.nCharged   = cms.InputTag("puJetVarAK4PFCHS:nCharged")

  #
  # Specfiy variables in the jetTable to save in NanoAOD
  #
  proc.jetTable.variables.dR2Mean  = Var("userFloat('dR2Mean')", float, doc="pT^2-weighted average square distance of jet constituents from the jet axis", precision= 6)  
  proc.jetTable.variables.majW     = Var("userFloat('majW')",    float, doc="major axis of jet ellipsoid in eta-phi plane", precision= 6)  
  proc.jetTable.variables.minW     = Var("userFloat('minW')",    float, doc="minor axis of jet ellipsoid in eta-phi plane", precision= 6)  
  proc.jetTable.variables.frac01   = Var("userFloat('frac01')",  float, doc="frac of constituents' pT contained within dR<0.1", precision= 6)  
  proc.jetTable.variables.frac02   = Var("userFloat('frac02')",  float, doc="frac of constituents' pT contained within 0.1<dR<0.2", precision= 6) 
  proc.jetTable.variables.frac03   = Var("userFloat('frac03')",  float, doc="frac of constituents' pT contained within 0.2<dR<0.3", precision= 6) 
  proc.jetTable.variables.frac04   = Var("userFloat('frac04')",  float, doc="frac of constituents' pT contained within 0.3<dR<0.4", precision= 6) 
  proc.jetTable.variables.ptD      = Var("userFloat('ptD')",     float, doc="pT-weighted average pT of constituents", precision= 6) 
  proc.jetTable.variables.beta     = Var("userFloat('beta')",    float, doc="fraction of pT of charged constituents associated to PV", precision= 6) 
  proc.jetTable.variables.pull     = Var("userFloat('pull')",    float, doc="magnitude of pull vector", precision= 6) 
  proc.jetTable.variables.jetR     = Var("userFloat('jetR')",    float, doc="fraction of jet pT carried by the leading constituent", precision= 6) 
  proc.jetTable.variables.jetRchg  = Var("userFloat('jetRchg')", float, doc="fraction of jet pT carried by the leading charged constituent", precision= 6) 
  proc.jetTable.variables.nCharged = Var("userInt('nCharged')",  int, doc="number of charged constituents")
Ejemplo n.º 2
0
def AddPileUpJetIDVars(proc,
                       jetName="",
                       jetSrc="",
                       jetTableName="",
                       jetSequenceName=""):
    """
  Setup modules to calculate pileup jet ID input variables for PF jet
  """

    #
    # Calculate pileup jet ID variables
    #
    puJetIdVarsCalculator = "puJetIdCalculator{}".format(jetName)
    setattr(
        proc, puJetIdVarsCalculator,
        pileupJetIdCalculator.clone(
            jets=jetSrc,
            vertexes="offlineSlimmedPrimaryVertices",
            inputIsCorrected=True,
            applyJec=False,
            usePuppi=True if "Puppi" in jetName else False))
    getattr(proc, jetSequenceName).insert(
        getattr(proc, jetSequenceName).index(getattr(proc, jetSrc)) + 1,
        getattr(proc, puJetIdVarsCalculator))

    #
    # Get the variables
    #
    puJetIDVar = "puJetIDVar{}".format(jetName)
    setattr(
        proc, puJetIDVar,
        cms.EDProducer("PileupJetIDVarProducer",
                       srcJet=cms.InputTag(jetSrc),
                       srcPileupJetId=cms.InputTag(puJetIdVarsCalculator)))
    getattr(proc, jetSequenceName).insert(
        getattr(proc, jetSequenceName).index(
            getattr(proc, puJetIdVarsCalculator)) + 1,
        getattr(proc, puJetIDVar))

    #
    # Save variables as userFloats and userInts for each jet
    #
    patJetWithUserData = "{}WithUserData".format(jetSrc)
    getattr(proc, patJetWithUserData).userFloats.puId_dR2Mean = cms.InputTag(
        "{}:dR2Mean".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_majW = cms.InputTag(
        "{}:majW".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_minW = cms.InputTag(
        "{}:minW".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_frac01 = cms.InputTag(
        "{}:frac01".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_frac02 = cms.InputTag(
        "{}:frac02".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_frac03 = cms.InputTag(
        "{}:frac03".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_frac04 = cms.InputTag(
        "{}:frac04".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_ptD = cms.InputTag(
        "{}:ptD".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_beta = cms.InputTag(
        "{}:beta".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_pull = cms.InputTag(
        "{}:pull".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_jetR = cms.InputTag(
        "{}:jetR".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userFloats.puId_jetRchg = cms.InputTag(
        "{}:jetRchg".format(puJetIDVar))
    getattr(proc, patJetWithUserData).userInts.puId_nCharged = cms.InputTag(
        "{}:nCharged".format(puJetIDVar))

    #
    # Specfiy variables in the jet table to save in NanoAOD
    #
    getattr(proc, jetTableName).variables.puId_dR2Mean = PUIDVARS.puId_dR2Mean
    getattr(proc, jetTableName).variables.puId_majW = PUIDVARS.puId_majW
    getattr(proc, jetTableName).variables.puId_minW = PUIDVARS.puId_minW
    getattr(proc, jetTableName).variables.puId_frac01 = PUIDVARS.puId_frac01
    getattr(proc, jetTableName).variables.puId_frac02 = PUIDVARS.puId_frac02
    getattr(proc, jetTableName).variables.puId_frac03 = PUIDVARS.puId_frac03
    getattr(proc, jetTableName).variables.puId_frac04 = PUIDVARS.puId_frac04
    getattr(proc, jetTableName).variables.puId_ptD = PUIDVARS.puId_ptD
    getattr(proc, jetTableName).variables.puId_beta = PUIDVARS.puId_beta
    getattr(proc, jetTableName).variables.puId_pull = PUIDVARS.puId_pull
    getattr(proc, jetTableName).variables.puId_jetR = PUIDVARS.puId_jetR
    getattr(proc, jetTableName).variables.puId_jetRchg = PUIDVARS.puId_jetRchg
    getattr(proc,
            jetTableName).variables.puId_nCharged = PUIDVARS.puId_nCharged

    return proc