4 from AsgAnalysisAlgorithms.AnalysisObjectSharedSequence
import makeSharedObjectSequence
5 from AnaAlgorithm.AnaAlgSequence
import AnaAlgSequence
6 from AnaAlgorithm.DualUseConfig
import createAlgorithm, addPrivateTool
9 deepCopyOutput = False,
10 shallowViewOutput = True,
12 ptSelectionOutput = False,
13 trackSelection = True,
15 qualitySelectionOutput = True,
16 enableCutflow = False,
17 enableKinematicHistograms = False,
19 defineSystObjectLinks = False ):
20 """Create a muon analysis algorithm sequence
23 dataType -- The data type to run on ("data", "mc" or "afii")
24 workingPoint -- The working point to use
25 deepCopyOutput -- If set to 'True', the output containers will be
26 standalone, deep copies (slower, but needed for xAOD
28 shallowViewOutput -- Create a view container if required
29 postfix -- a postfix to apply to decorations and algorithm
30 names. this is mostly used/needed when using this
31 sequence with multiple working points to ensure all
33 ptSelectionOutput -- Whether or not to apply pt selection when creating
35 trackSelection -- apply selection on tracks (d0, z0, siHits, etc.)
36 qualitySelectionOutput -- Whether or not to apply muon quality selection
37 when creating output containers.
38 enableCutflow -- Whether or not to dump the cutflow
39 enableKinematicHistograms -- Whether or not to dump the kinematic histograms
42 if dataType
not in [
"data",
"mc",
"afii"] :
43 raise ValueError (
"invalid data type: " + dataType)
46 postfix =
'_' + postfix
50 seq = AnaAlgSequence(
"MuonAnalysisSequence" + postfix )
52 seq.addMetaConfigDefault (
"selectionDecorNames", [])
53 seq.addMetaConfigDefault (
"selectionDecorNamesOutput", [])
54 seq.addMetaConfigDefault (
"selectionDecorCount", [])
56 makeMuonCalibrationSequence (seq, dataType, postfix=postfix,
57 ptSelectionOutput = ptSelectionOutput,
58 trackSelection = trackSelection,
59 maxEta = maxEta, isRun3Geo = isRun3Geo)
60 makeMuonWorkingPointSequence (seq, dataType, workingPoint, postfix=postfix,
61 qualitySelectionOutput = qualitySelectionOutput, isRun3Geo = isRun3Geo)
62 makeSharedObjectSequence (seq, deepCopyOutput = deepCopyOutput,
63 shallowViewOutput = shallowViewOutput,
64 postfix =
'_Muon' + postfix,
65 enableCutflow = enableCutflow,
66 enableKinematicHistograms = enableKinematicHistograms,
67 defineSystObjectLinks = defineSystObjectLinks )
77 postfix = '', ptSelectionOutput = False, trackSelection = False, maxEta = 2.7, isRun3Geo = False, calibMode = 0):
78 """Create muon calibration analysis algorithms
80 This makes all the algorithms that need to be run first befor
81 all working point specific algorithms and that can be shared
82 between the working points.
85 dataType -- The data type to run on ("data", "mc" or "afii")
86 postfix -- a postfix to apply to decorations and algorithm
87 names. this is mostly used/needed when using this
88 sequence with multiple working points to ensure all
90 ptSelectionOutput -- Whether or not to apply pt selection when creating
94 if dataType
not in [
"data",
"mc",
"afii"] :
95 raise ValueError (
"invalid data type: " + dataType)
98 alg =
createAlgorithm(
'CP::AsgShallowCopyAlg',
'MuonShallowCopyAlg' + postfix )
99 seq.append( alg, inputPropName =
'input',
100 outputPropName =
'output',
101 stageName =
'prepare')
105 'MuonEtaCutAlg' + postfix )
106 addPrivateTool( alg,
'selectionTool',
'CP::AsgPtEtaSelectionTool' )
107 alg.selectionTool.maxEta = maxEta
108 alg.selectionDecoration =
'selectEta' + postfix +
',as_bits'
109 seq.append( alg, inputPropName =
'particles',
110 stageName =
'selection',
111 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
112 'selectionDecorNamesOutput' : [alg.selectionDecoration],
113 'selectionDecorCount' : [2]},
114 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
119 'MuonTrackSelectionAlg' + postfix )
120 alg.selectionDecoration =
'trackSelection' + postfix +
',as_bits'
121 alg.maxD0Significance = 3
122 alg.maxDeltaZ0SinTheta = 0.5
123 seq.append( alg, inputPropName =
'particles',
124 stageName =
'selection',
125 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
126 'selectionDecorNamesOutput' : [alg.selectionDecoration],
127 'selectionDecorCount' : [3]},
128 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
132 'MuonCalibrationAndSmearingAlg' + postfix )
134 'CP::MuonCalibTool' )
136 alg.calibrationAndSmearingTool.IsRun3Geo = isRun3Geo
137 alg.calibrationAndSmearingTool.calibMode = calibMode
138 seq.append( alg, inputPropName =
'muons', outputPropName =
'muonsOut',
139 stageName =
'calibration',
140 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
143 alg =
createAlgorithm(
'CP::AsgSelectionAlg',
'MuonPtCutAlg' + postfix )
144 alg.selectionDecoration =
'selectPt' + postfix +
',as_bits'
145 addPrivateTool( alg,
'selectionTool',
'CP::AsgPtEtaSelectionTool' )
146 alg.selectionTool.minPt = 3e3
147 seq.append( alg, inputPropName =
'particles',
148 stageName =
'selection',
149 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
150 'selectionDecorNamesOutput' : [alg.selectionDecoration]
if ptSelectionOutput
else [],
151 'selectionDecorCount' : [2]},
152 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
160 qualitySelectionOutput = True, isRun3Geo = False):
161 """Create muon analysis algorithms for a single working point
164 dataType -- The data type to run on ("data", "mc" or "afii")
165 workingPoint -- The working point to use
166 postfix -- a postfix to apply to decorations and algorithm
167 names. this is mostly used/needed when using this
168 sequence with multiple working points to ensure all
170 qualitySelectionOutput -- Whether or not to apply muon quality selection
171 when creating output containers.
172 isRun3Geo -- switches the muon selection tool to run 3 geometry
175 if dataType
not in [
"data",
"mc",
"afii"] :
176 raise ValueError (
"invalid data type: " + dataType)
178 splitWP = workingPoint.split (
'.')
179 if len (splitWP) != 2 :
180 raise ValueError (
'working point should be of format "quality.isolation", not ' + workingPoint)
182 sfWorkingPoint = splitWP[0]
183 from xAODMuon.xAODMuonEnums
import xAODMuonEnums
184 if splitWP[0] ==
'Tight' :
185 quality = xAODMuonEnums.Quality.Tight
187 elif splitWP[0] ==
'Medium' :
188 quality = xAODMuonEnums.Quality.Medium
190 elif splitWP[0] ==
'Loose' :
191 quality = xAODMuonEnums.Quality.Loose
193 elif splitWP[0] ==
'VeryLoose' :
194 quality = xAODMuonEnums.Quality.VeryLoose
196 elif splitWP[0] ==
'HighPt' :
199 elif splitWP[0] ==
'LowPtEfficiency' :
203 raise ValueError (
"invalid muon quality: \"" + splitWP[0] +
204 "\", allowed values are Tight, Medium, Loose, " +
205 "VeryLoose, HighPt, LowPtEfficiency")
209 'MuonSelectionAlg' + postfix )
211 alg.selectionTool.MuQuality = quality
212 alg.selectionTool.IsRun3Geo = isRun3Geo
213 alg.selectionDecoration =
'good_muon' + postfix +
',as_bits'
214 alg.badMuonVetoDecoration =
'is_bad' + postfix +
',as_char'
215 seq.append( alg, inputPropName =
'muons',
216 stageName =
'selection',
217 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
218 'selectionDecorNamesOutput' : [alg.selectionDecoration]
if qualitySelectionOutput
else [],
219 'selectionDecorCount' : [4]},
220 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
223 if splitWP[1] !=
'NonIso' :
225 'MuonIsolationAlg' + postfix )
226 addPrivateTool( alg,
'isolationTool',
'CP::IsolationSelectionTool' )
227 alg.isolationTool.MuonWP = splitWP[1]
228 alg.isolationDecoration =
'isolated_muon' + postfix +
',as_bits'
229 seq.append( alg, inputPropName =
'muons',
230 stageName =
'selection',
231 metaConfig = {
'selectionDecorNames' : [alg.isolationDecoration],
232 'selectionDecorNamesOutput' : [alg.isolationDecoration],
233 'selectionDecorCount' : [1]},
234 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
239 'MuonEfficiencyScaleFactorAlg' + postfix )
241 'CP::MuonEfficiencyScaleFactors' )
242 alg.scaleFactorDecoration =
'muon_effSF' + postfix +
"_%SYS%"
243 alg.outOfValidity = 2
244 alg.outOfValidityDeco =
'bad_eff' + postfix
245 alg.efficiencyScaleFactorTool.WorkingPoint = sfWorkingPoint
247 alg.efficiencyScaleFactorTool.CalibrationRelease =
'230309_Preliminary_r22run3'
248 if dataType !=
'data':
249 seq.append( alg, inputPropName =
'muons',
250 stageName =
'efficiency',
251 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])})
255 'MuonSelectionSummary' + postfix )
256 alg.selectionDecoration =
'baselineSelection' + postfix +
',as_char'
257 seq.append( alg, inputPropName =
'particles',
258 stageName =
'selection',
259 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNames"])})