JetRecoConfiguration.py 6.34 KB
Newer Older
Teng Jian Khoo's avatar
Teng Jian Khoo committed
1
#
Jonathan Bossio's avatar
Jonathan Bossio committed
2
#  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Teng Jian Khoo's avatar
Teng Jian Khoo committed
3
4
5
6
7
8
9
10
11
#

##########################################################################################
# Helper functions to digest the reconstruction options dictionary
# and translate it into the python configuration objects used by
# jet reco code.

from JetRecConfig.JetDefinition import JetConstit, xAODType, JetDefinition

Teng Jian Khoo's avatar
Teng Jian Khoo committed
12
13
14
15
16
17
18
# Extract the jet reco dict from the chainDict
def extractRecoDict(chainParts):
    # interpret the reco configuration only
    # eventually should just be a subdict in the chainDict
    recoKeys = ['recoAlg','dataType','calib','jetCalib','trkopt','cleaning']
    return { key:chainParts[key] for key in recoKeys }

Teng Jian Khoo's avatar
Teng Jian Khoo committed
19
20
21
22
# Define the jet constituents to be interpreted by JetRecConfig
# When actually specifying the reco, clustersKey should be
# set, but default to None to allow certain checks, in particular
# grooming configuration
Teng Jian Khoo's avatar
Teng Jian Khoo committed
23
24
25
26
27
def defineJetConstit(jetRecoDict,clustersKey=None,pfoPrefix=None):
    constitMods = []
    if "sk" in jetRecoDict["dataType"]:
        constitMods.append("SK")

Teng Jian Khoo's avatar
Teng Jian Khoo committed
28
29
    # Get the details of the constituent definition:
    # type, mods and the input container name
Teng Jian Khoo's avatar
Teng Jian Khoo committed
30
31
32
33
34
35
36
    if jetRecoDict["dataType"]=="pf":
        jetConstit = JetConstit( xAODType.ParticleFlow, constitMods)
        if pfoPrefix is None:
            raise RuntimeError("JetRecoConfiguration: Cannot define PF jets without pfo prefix!")
        jetConstit.rawname = pfoPrefix+"ParticleFlowObjects"
        jetConstit.inputname = pfoPrefix+"CHSParticleFlowObjects"
        
Teng Jian Khoo's avatar
Teng Jian Khoo committed
37
38
39
    if "tc" in jetRecoDict["dataType"]:
        # apply this scale
        if jetRecoDict["calib"] == "em":
Teng Jian Khoo's avatar
Teng Jian Khoo committed
40
            constitMods = ["EM"] + constitMods
Teng Jian Khoo's avatar
Teng Jian Khoo committed
41
        elif jetRecoDict["calib"] == "lcw":
Teng Jian Khoo's avatar
Teng Jian Khoo committed
42
            constitMods = ["LC"] + constitMods
Teng Jian Khoo's avatar
Teng Jian Khoo committed
43
44
        # read from this cluster collection,
        # overriding the standard offline collection
Teng Jian Khoo's avatar
Teng Jian Khoo committed
45
        jetConstit = JetConstit( xAODType.CaloCluster, constitMods)
Teng Jian Khoo's avatar
Teng Jian Khoo committed
46
47
        if clustersKey is not None:
            jetConstit.rawname = clustersKey
Teng Jian Khoo's avatar
Teng Jian Khoo committed
48
49
            if jetRecoDict["dataType"]=="tc":
                jetConstit.inputname = clustersKey
Teng Jian Khoo's avatar
Teng Jian Khoo committed
50
        # apply constituent pileup suppression
Teng Jian Khoo's avatar
Teng Jian Khoo committed
51
52
        if "cs" in jetRecoDict["dataType"]:
            constitMods.append("CS")
Teng Jian Khoo's avatar
Teng Jian Khoo committed
53
54
55
56
57
58
        if "sk" in jetRecoDict["dataType"]:
            constitMods.append("SK")
    return jetConstit

# Arbitrary min pt for fastjet, set to be low enough for MHT(?)
# Could/should adjust higher for large-R
Teng Jian Khoo's avatar
Teng Jian Khoo committed
59
def defineJets(jetRecoDict,clustersKey=None,pfoPrefix=None):
Teng Jian Khoo's avatar
Teng Jian Khoo committed
60
    radius = float(jetRecoDict["recoAlg"].lstrip("a").rstrip("tr"))/10
Teng Jian Khoo's avatar
Teng Jian Khoo committed
61
    jetConstit = defineJetConstit(jetRecoDict,clustersKey,pfoPrefix)
Teng Jian Khoo's avatar
Teng Jian Khoo committed
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
    jetDef = JetDefinition( "AntiKt", radius, jetConstit, ptmin=5000.)
    return jetDef

def defineReclusteredJets(jetRecoDict):
    rcJetConstit = JetConstit( xAODType.Jet, [])
    rcJetDef = JetDefinition( "AntiKt", 1.0, rcJetConstit)
    return rcJetDef

def defineGroomedJets(jetRecoDict,ungroomedDef,ungroomedJetsName):
    from JetRecConfig.JetGrooming import JetTrimming
    # Only actually one type now, but leave open possibility of others
    groomDef = {
        "t":JetTrimming(ungroomedDef,ungroomedJetsName,smallR=0.2,ptfrac=0.05)
        }[jetRecoDict["recoAlg"][-1]]
    return groomDef

##########################################################################################
# Generation of modifier lists. So far only calib, but can add track, substructure mods

from JetRecConfig.StandardJetMods import jetmoddict

# Make generating the list a bit more comprehensible
def getModSpec(modname,modspec=''):
    return (jetmoddict[modname],str(modspec))

Teng Jian Khoo's avatar
Teng Jian Khoo committed
87
88
89
90
91
92
93
94
def defineTrackMods(trkopt):
    trkmods = [
        (jetmoddict["TrackMoments"],trkopt),
        (jetmoddict["JVF"],trkopt),
        (jetmoddict["JVT"],trkopt)
    ]
    return trkmods

Teng Jian Khoo's avatar
Teng Jian Khoo committed
95
96
# Translate calib specification into something understood by
# the calibration config helper
97
def defineCalibFilterMods(jetRecoDict,dataSource,rhoKey="auto"):
Teng Jian Khoo's avatar
Teng Jian Khoo committed
98
99
100
101
102
103
    # Minimum modifier set for calibration w/o track GSC
    # Should eventually build in more mods, depend on track info etc
    jetalg = jetRecoDict["recoAlg"]
    if jetRecoDict["jetCalib"] == "nojcalib" or jetalg=="a10r":
        calibMods = []
    else:
104
105
        if jetRecoDict["trkopt"]=="notrk" and "gsc" in jetRecoDict["jetCalib"]:
            raise ValueError("Track GSC requested but no track source provided!")
106
107
108

        if jetRecoDict["trkopt"]=="notrk" and "subres" in jetRecoDict["jetCalib"]:
            raise ValueError("Pileup residual calibration requested but no track source provided!")
109

Teng Jian Khoo's avatar
Teng Jian Khoo committed
110
111
112
113
114
        if jetRecoDict["dataType"]=="tc":
            calibContext,calibSeq = {
                ("a4","subjes"):   ("TrigRun2","JetArea_EtaJES_GSC"),        # Calo GSC only
                ("a4","subjesIS"): ("TrigRun2","JetArea_EtaJES_GSC_Insitu"), # Calo GSC only
                ("a4","subjesgscIS"): ("TrigRun2GSC","JetArea_EtaJES_GSC_Insitu"), # Calo+Trk GSC
115
                ("a4","subresjesgscIS"): ("TrigRun2GSC","JetArea_Residual_EtaJES_GSC_Insitu"), # pu residual + calo+trk GSC
Teng Jian Khoo's avatar
Teng Jian Khoo committed
116
117
118
                ("a10","subjes"):  ("TrigUngroomed","JetArea_EtaJES"),
                ("a10t","jes"):    ("TrigTrimmed","EtaJES_JMS"),
                }[(jetRecoDict["recoAlg"],jetRecoDict["jetCalib"])]
Teng Jian Khoo's avatar
Teng Jian Khoo committed
119
120
121
122
123
124
125

            pvname = ""
            gscDepth = "EM3"
            if "gsc" in jetRecoDict["jetCalib"]:
                gscDepth = "trackWIDTH"
                pvname = "HLT_EFHistoPrmVtx"

Teng Jian Khoo's avatar
Teng Jian Khoo committed
126
        elif jetRecoDict["dataType"]=="pf":
Teng Jian Khoo's avatar
Teng Jian Khoo committed
127
128
129
130
131
132
            gscDepth = "auto"
            calibContext = "TrigLS2"
            calibSeq = "JetArea_Residual_EtaJES_GSC"
            if jetRecoDict["jetCalib"].endswith("IS"):
                calibSeq += "_Insitu"
            pvname = "HLT_EFHistoPrmVtx"
133

134
        calibSpec = ":".join( [calibContext, dataSource, calibSeq, rhoKey, pvname, gscDepth] )
scott snyder's avatar
scott snyder committed
135
        from .TriggerJetMods import ConstitFourMom_copy
Teng Jian Khoo's avatar
Teng Jian Khoo committed
136
137
138
139
140
141
142
143
144
145
146
147
        if jetalg=="a4":
            calibMods = [(ConstitFourMom_copy,""),
                         getModSpec("CaloEnergies"), # Needed for GSC
                         getModSpec("Calib",calibSpec),
                         getModSpec("Sort")]
        else:
            calibMods = [(ConstitFourMom_copy,""),
                         getModSpec("Calib",calibSpec),
                         getModSpec("Sort")]

    filtercut = {"a4":5000, "a10":50000, "a10r": 50000, "a10t":100000}[jetalg]
    return calibMods + [getModSpec("Filter",filtercut)]