JETM7.py 12.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#====================================================================
# JETM7.py 
# reductionConf flag JETM7 in Reco_tf.py   
#====================================================================

from DerivationFrameworkCore.DerivationFrameworkMaster import *
from DerivationFrameworkInDet.InDetCommon import *
from DerivationFrameworkJetEtMiss.JetCommon import *
from DerivationFrameworkJetEtMiss.ExtendedJetCommon import *
from DerivationFrameworkEGamma.EGammaCommon import *
from DerivationFrameworkMuons.MuonsCommon import *
from DerivationFrameworkJetEtMiss.METCommon import *
13
14
#

15
#
16
if DerivationFrameworkIsMonteCarlo:
17
18
19
20
21
22
23
    from DerivationFrameworkMCTruth.MCTruthCommon import *
    from DerivationFrameworkTau.TauTruthCommon import *

#====================================================================
# SKIMMING TOOL 
#====================================================================

24
25
26
from DerivationFrameworkJetEtMiss.TriggerLists import *
electronTriggers = singleElTriggers
muonTriggers = singleMuTriggers
27
28
29
30
31

orstr  = ' || '
andstr = ' && '
eltrigsel = '(EventInfo.eventTypeBitmask==1) || '+orstr.join(electronTriggers)
elofflinesel = andstr.join(['count((Electrons.pt > 25*GeV) && (Electrons.DFCommonElectronsLHMedium)) >= 1',
32
33
                            'count(AntiKt4EMTopoJets.DFCommonJets_Calib_pt>20*GeV && AntiKt4EMTopoJets.DFCommonJets_FixedCutBEff_77) >= 1'
                            ])
34
35
36
electronSelection = '( (' + eltrigsel + ') && (' + elofflinesel + ') )'

mutrigsel = '(EventInfo.eventTypeBitmask==1) || '+orstr.join(muonTriggers)
37
38
39
muofflinesel = andstr.join(['count((Muons.pt > 25*GeV) && (Muons.DFCommonMuonsPreselection)) >= 1',
                            'count(AntiKt4EMTopoJets.DFCommonJets_Calib_pt>20*GeV && AntiKt4EMTopoJets.DFCommonJets_FixedCutBEff_77) >= 1'
                            ])
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
muonSelection = ' ( (' + mutrigsel + ') && (' + muofflinesel + ') )'
expression = '( ' + electronSelection + ' || ' + muonSelection + ' )'

from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__xAODStringSkimmingTool
JETM7SkimmingTool = DerivationFramework__xAODStringSkimmingTool( name = "JETM7SkimmingTool1",
                                                                 expression = expression)
ToolSvc += JETM7SkimmingTool

#====================================================================
# SET UP STREAM   
#====================================================================
streamName = derivationFlags.WriteDAOD_JETM7Stream.StreamName
fileName   = buildFileName( derivationFlags.WriteDAOD_JETM7Stream )
JETM7Stream = MSMgr.NewPoolRootStream( streamName, fileName )
JETM7Stream.AcceptAlgs(["JETM7Kernel"])

56
57
58
59
60
61
62
63
64
65
#====================================================================
# AUGMENTATION
#====================================================================

applyJetCalibration_xAODColl("AntiKt4EMTopo") # adds this to DerivationFrameworkJob by default
updateJVT_xAODColl("AntiKt4EMTopo") # adds this to DerivationFrameworkJob by default

from DerivationFrameworkFlavourTag.FlavourTagCommon import applyBTagging_xAODColl
applyBTagging_xAODColl("AntiKt4EMTopo")

66
67
68
69
70
71
#=======================================
# ESTABLISH THE THINNING HELPER
#=======================================

from DerivationFrameworkCore.ThinningHelper import ThinningHelper
JETM7ThinningHelper = ThinningHelper( "JETM7ThinningHelper" )
72
# JETM7ThinningHelper.TriggerChains = orstr.join(electronTriggers+muonTriggers)
73
74
75
76
77
78
79
80
81
82
JETM7ThinningHelper.AppendToStream( JETM7Stream )

#====================================================================
# THINNING TOOLS 
#====================================================================
thinningTools = []

# TrackParticles associated with Muons
from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__MuonTrackParticleThinning
JETM7MuonTPThinningTool = DerivationFramework__MuonTrackParticleThinning(name     = "JETM7MuonTPThinningTool",
83
                                                                    StreamName              = streamName,
84
85
86
87
88
89
90
91
                                                                    MuonKey                 = "Muons",
                                                                    InDetTrackParticlesKey  = "InDetTrackParticles")
ToolSvc += JETM7MuonTPThinningTool
thinningTools.append(JETM7MuonTPThinningTool)

# TrackParticles associated with electrons
from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
JETM7ElectronTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(name                    = "JETM7ElectronTPThinningTool",
92
                                                                               StreamName              = streamName,
93
94
95
96
97
                                                                               SGKey                   = "Electrons",
                                                                               InDetTrackParticlesKey  = "InDetTrackParticles")
ToolSvc += JETM7ElectronTPThinningTool
thinningTools.append(JETM7ElectronTPThinningTool)

98
99
# TrackParticles associated with electrons
JETM7PhotonTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(name                    = "JETM7PhotonTPThinningTool",
100
                                                                             StreamName              = streamName,
101
102
103
104
105
                                                                             SGKey                   = "Photons",
                                                                             InDetTrackParticlesKey  = "InDetTrackParticles")
ToolSvc += JETM7PhotonTPThinningTool
thinningTools.append(JETM7PhotonTPThinningTool)

106
107
108
# TrackParticles associated with taus
from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TauTrackParticleThinning
JETM7TauTPThinningTool = DerivationFramework__TauTrackParticleThinning( name            = "JETM7TauTPThinningTool",
109
                                                                        StreamName              = streamName,
110
111
112
113
114
115
116
117
118
                                                                        TauKey          = "TauJets",
                                                                        InDetTrackParticlesKey  = "InDetTrackParticles")
ToolSvc += JETM7TauTPThinningTool
thinningTools.append(JETM7TauTPThinningTool)

# Truth particle thinning
doTruthThinning = True
preserveAllDescendants = False
from AthenaCommon.GlobalFlags import globalflags
119
if doTruthThinning and DerivationFrameworkIsMonteCarlo:
120
121
122
123
124
125
126
127
128
129
    truth_cond_WZH    = "((abs(TruthParticles.pdgId) >= 23) && (abs(TruthParticles.pdgId) <= 25))"            # W, Z and Higgs
    truth_cond_Lepton = "((abs(TruthParticles.pdgId) >= 11) && (abs(TruthParticles.pdgId) <= 16))"            # Leptons
    truth_cond_Quark  = "((abs(TruthParticles.pdgId) <=  5  && (TruthParticles.pt > 10000.)) || (abs(TruthParticles.pdgId) == 6))"                 # Quarks
    truth_cond_Gluon  = "((abs(TruthParticles.pdgId) == 21) && (TruthParticles.pt > 10000.))"                                                # Gluons
    truth_cond_Photon = "((abs(TruthParticles.pdgId) == 22) && (TruthParticles.pt > 10000.) && (TruthParticles.barcode < 200000))"                 # Photon
    
    truth_expression = '('+truth_cond_WZH+' || '+truth_cond_Lepton +' || '+truth_cond_Quark+'||'+truth_cond_Gluon+' || '+truth_cond_Photon+')'
    
    from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
    JETM7TruthThinningTool = DerivationFramework__GenericTruthThinning( name = "JETM7TruthThinningTool",
130
                                                                        StreamName              = streamName,
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
                                                                        ParticleSelectionString = truth_expression,
                                                                        PreserveDescendants     = preserveAllDescendants,
                                                                        PreserveGeneratorDescendants = not preserveAllDescendants,
                                                                        PreserveAncestors = True)
    
    ToolSvc += JETM7TruthThinningTool
    thinningTools.append(JETM7TruthThinningTool)    

#=======================================
# CREATE PRIVATE SEQUENCE
#=======================================

jetm7Seq = CfgMgr.AthSequencer("JETM7Sequence")
DerivationFrameworkJob += jetm7Seq

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#=======================================
# CREATE THE DERIVATION KERNEL ALGORITHM   
#=======================================

from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel
jetm7Seq += CfgMgr.DerivationFramework__DerivationKernel( name = "JETM7Kernel_Skim",
                                                          SkimmingTools = [JETM7SkimmingTool],
                                                          ThinningTools = [],
                                                          AugmentationTools = [])

#====================================================================
# CUSTOM JET RECONSTRUCTION
#====================================================================

#=======================================
# RESTORE AOD-REDUCED JET COLLECTIONS
#=======================================
reducedJetList = ["AntiKt2PV0TrackJets",
                  "AntiKt4PV0TrackJets",
                  "AntiKt4TruthJets",
                  "AntiKt4TruthWZJets"]
replaceAODReducedJets(reducedJetList,jetm7Seq,"JETM7")

169
170
171
172
173
174
175
176
177
178
179
180
#==============================================================================
# SUSY background generator filters
#==============================================================================
augmentationTools = []
if globalflags.DataSource() == 'geant4':
  ToolSvc += CfgMgr.DerivationFramework__SUSYGenFilterTool(
    "JETM7GenFilt",
    SimBarcodeOffset = DerivationFrameworkSimBarcodeOffset
  )
  augmentationTools.append(ToolSvc.JETM7GenFilt)

from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel
181
182
jetm7Seq += CfgMgr.DerivationFramework__DerivationKernel( name = "JETM7Kernel",
                                                          SkimmingTools = [],
183
184
185
186
187
188
189
                                                          ThinningTools = thinningTools,
                                                          AugmentationTools = augmentationTools)

#=======================================
# SCHEDULE CUSTOM MET RECONSTRUCTION
#=======================================

190
191
192
193
194
if DerivationFrameworkIsMonteCarlo:
    addMETTruthMap('AntiKt4EMTopo',"JETMX")
    addMETTruthMap('AntiKt4LCTopo',"JETMX")
    addMETTruthMap('AntiKt4EMPFlow',"JETMX")
    scheduleMETAssocAlg(jetm7Seq,"JETMX")
195
196
197
198
199
200
201

#====================================================================
# Add the containers to the output stream - slimming done here
#====================================================================
from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper
JETM7SlimmingHelper = SlimmingHelper("JETM7SlimmingHelper")
JETM7SlimmingHelper.SmartCollections = ["Electrons", "Photons", "Muons", "TauJets",
202
203
204
205
                                        "InDetTrackParticles", "PrimaryVertices",
                                        "MET_Reference_AntiKt4EMTopo",
                                        "MET_Reference_AntiKt4LCTopo",
                                        "MET_Reference_AntiKt4EMPFlow",
206
207
208
                                        "AntiKt4EMTopoJets","AntiKt4LCTopoJets","AntiKt4EMPFlowJets",
                                        "BTagging_AntiKt4EMTopo",]
JETM7SlimmingHelper.AllVariables = [# "CaloCalTopoClusters",
209
210
                                    "MuonTruthParticles", "egammaTruthParticles",
                                    "TruthParticles", "TruthEvents", "TruthVertices",
211
212
                                    "MuonSegments",
                                    "Kt4EMTopoOriginEventShape","Kt4LCTopoOriginEventShape","Kt4EMPFlowEventShape",
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
                                    ]
JETM7SlimmingHelper.ExtraVariables = ["Muons.energyLossType.EnergyLoss.ParamEnergyLoss.MeasEnergyLoss.EnergyLossSigma.MeasEnergyLossSigma.ParamEnergyLossSigmaPlus.ParamEnergyLossSigmaMinus"]
for truthc in [
    "TruthMuons",
    "TruthElectrons",
    "TruthPhotons",
    "TruthTaus",
#    "TruthNeutrinos"
    ]:
    JETM7SlimmingHelper.StaticContent.append("xAOD::TruthParticleContainer#"+truthc)
    JETM7SlimmingHelper.StaticContent.append("xAOD::TruthParticleAuxContainer#"+truthc+"Aux.")

# Trigger content
JETM7SlimmingHelper.IncludeMuonTriggerContent = True
JETM7SlimmingHelper.IncludeEGammaTriggerContent = True

# Add the jet containers to the stream
addJetOutputs(JETM7SlimmingHelper,["SmallR"])
# Add the MET containers to the stream
232
addMETOutputs(JETM7SlimmingHelper,["Diagnostic","Assocs","TruthAssocs","Track","JETMX"])
233
234

JETM7SlimmingHelper.AppendContentToStream(JETM7Stream)