OverlapAnalysisSequence.py 14.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration

# AnaAlgorithm import(s):
from AnaAlgorithm.AnaAlgSequence import AnaAlgSequence
from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool

def makeOverlapAnalysisSequence( dataType,
                                 inputLabel = '', outputLabel = 'passesOR',
                                 linkOverlapObjects = False, doMuPFJetOR=False,
                                 doEleEleOR = False, doElectrons = True,
                                 doMuons = True, doJets = True, doTaus = True,
                                 doPhotons = True, doFatJets = False,
13
                                 enableUserPriority = False,
14
15
16
                                 bJetLabel = '',
                                 boostedLeptons = False,
                                 postfix = '',
17
                                 shallowViewOutput = True,
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
                                 enableCutflow = False ):
    """Function creating the overlap removal algorithm sequence

    The function sets up a multi-input/multi-output analysis algorithm sequnce,
    which needs to be used in a quite particular way. First off you need to set
    the arguments of this function correctly.

    Then, you need to call the configure(...) method on the algorithm sequence
    returned by this function in the following way:

      overlapSequence.configure(
         inputName = {
            'electrons' : 'AnalysisElectrons_%SYS%',
            'photons'   : 'AnalysisPhotons_%SYS%',
            'muons'     : 'AnalysisMuons_%SYS%',
            'jets'      : 'AnalysisJets_%SYS%',
            'taus'      : 'AnalysisTauJets_%SYS%' },
         outputName = {
            'electrons' : 'AnalysisElectronsOR_%SYS%',
            'photons'   : 'AnalysisPhotonsOR_%SYS%',
            'muons'     : 'AnalysisMuonsOR_%SYS%',
            'jets'      : 'AnalysisJetsOR_%SYS%',
40
            'taus'      : 'AnalysisTauJetsOR_%SYS%' } )
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

    Where:
      - You need to provide input and output names in pairs, you must not skip
        specifying an output name if you specified an input name, and vice
        versa.
      - You only define inputs/outputs that your analysis uses. The "labels" of
        the possible inputs/outputs are: "electrons", "photons", "muons",
        "jets", "taus" and "fatJets".

    Function keyword arguments:
      dataType -- The data type to run on ("data", "mc" or "afii")
      inputLabel -- Any possible label to pick up the selected objects with. If
                    left empty, all objects from the input containers are
                    considered.
      outputLabel -- Decoration put on the output variables. Set to "true" for
                     objects passing the overlap removal.
      linkOverlapObjects -- Set up an element link between overlapping objects
      doMuPFJetOR -- Set up overlap removal for PFlow jets that are acutally muons
      doEleEleOR -- Set up electron-electron overlap removal
      doXXXX     -- these flags enable/disable object types to
                    configure tools for: doElectrons, doMuons,
                    doJets, doTaus, doPhotons, doFatJets.
63
64
65
66
      enableUserPriority -- If enabled, the Ele-, Mu-, Tau- and PhoJetOR tools
                            will respect the user priority in the inputLabel.
                            E.g. SUSYTools assigns all signal objects the
                            priority 2 and pre-selected jets the priority 1.
67
68
69
      bJetLabel -- Flag to select b-jets with. If left empty, no b-jets are used
                   in the overlap removal.
      boostedLeptons -- Set to True to enable boosted lepton overlap removal
70
      shallowViewOutput -- Create a view container if required
71
72
73
74
75
76
77
78
79
80
81
      enableCutflow -- Whether or not to dump the cutflow
    """

    if dataType not in ["data", "mc", "afii"] :
        raise ValueError ("invalid data type: " + dataType)

    # Create the analysis algorithm sequence object:
    seq = AnaAlgSequence( 'OverlapAnalysisSequence' + postfix )

    # Create the overlap removal algorithm:
    alg = createAlgorithm( 'CP::OverlapRemovalAlg', 'OverlapRemovalAlg' + postfix )
82
83
84
85
86
87
88
89
    alg.OutputLabel = outputLabel
    if not shallowViewOutput:
        alg.electronsDecoration = outputLabel + '_%SYS%'
        alg.muonsDecoration = outputLabel + '_%SYS%'
        alg.tausDecoration = outputLabel + '_%SYS%'
        alg.jetsDecoration = outputLabel + '_%SYS%'
        alg.photonsDecoration = outputLabel + '_%SYS%'
        alg.fatJetsDecoration = outputLabel + '_%SYS%'
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

    # Create its main tool, and set its basic properties:
    addPrivateTool( alg, 'overlapTool', 'ORUtils::OverlapRemovalTool' )
    alg.overlapTool.InputLabel = inputLabel
    alg.overlapTool.OutputLabel = outputLabel

    # By default the OverlapRemovalTool would flag objects that need to be
    # suppressed, with a "true" value. But since the analysis algorithms expect
    # the opposite behaviour from selection flags, we need to tell the tool
    # explicitly to use the "true" flag on objects that pass the overlap
    # removal.
    alg.overlapTool.OutputPassValue = True

    # Set up overlap removal for PFlow jets that are acutally muons, if requested.
    if doMuPFJetOR:
       addPrivateTool( alg, 'overlapTool.MuPFJetORT',
                       'ORUtils::MuPFJetOverlapTool' )
       alg.overlapTool.MuPFJetORT.InputLabel = inputLabel
       alg.overlapTool.MuPFJetORT.OutputLabel = outputLabel
109
       alg.overlapTool.MuPFJetORT.BJetLabel = bJetLabel
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
       alg.overlapTool.MuPFJetORT.LinkOverlapObjects = linkOverlapObjects
       alg.overlapTool.MuPFJetORT.OutputPassValue = True
       pass

    # Set up the electron-electron overlap removal, if requested.
    if doElectrons and doEleEleOR:
        addPrivateTool( alg, 'overlapTool.EleEleORT',
                        'ORUtils::EleEleOverlapTool' )
        alg.overlapTool.EleEleORT.InputLabel = inputLabel
        alg.overlapTool.EleEleORT.OutputLabel = outputLabel
        alg.overlapTool.EleEleORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.EleEleORT.OutputPassValue = True
        pass

    # Set up the electron-muon overlap removal.
    if doElectrons and doMuons:
        addPrivateTool( alg, 'overlapTool.EleMuORT',
                        'ORUtils::EleMuSharedTrkOverlapTool' )
        alg.overlapTool.EleMuORT.InputLabel = inputLabel
        alg.overlapTool.EleMuORT.OutputLabel = outputLabel
        alg.overlapTool.EleMuORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.EleMuORT.OutputPassValue = True
        pass

    # Set up the electron-(narrow-)jet overlap removal.
    if doElectrons and doJets:
        addPrivateTool( alg, 'overlapTool.EleJetORT',
                        'ORUtils::EleJetOverlapTool' )
        alg.overlapTool.EleJetORT.InputLabel = inputLabel
        alg.overlapTool.EleJetORT.OutputLabel = outputLabel
        alg.overlapTool.EleJetORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.EleJetORT.BJetLabel = bJetLabel
        alg.overlapTool.EleJetORT.UseSlidingDR = boostedLeptons
143
        alg.overlapTool.EleJetORT.EnableUserPriority = enableUserPriority
144
145
146
147
148
149
150
151
152
153
154
155
        alg.overlapTool.EleJetORT.OutputPassValue = True
        pass

    # Set up the muon-(narrow-)jet overlap removal.
    if doMuons and doJets:
        addPrivateTool( alg, 'overlapTool.MuJetORT',
                        'ORUtils::MuJetOverlapTool' )
        alg.overlapTool.MuJetORT.InputLabel = inputLabel
        alg.overlapTool.MuJetORT.OutputLabel = outputLabel
        alg.overlapTool.MuJetORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.MuJetORT.BJetLabel = bJetLabel
        alg.overlapTool.MuJetORT.UseSlidingDR = boostedLeptons
156
        alg.overlapTool.MuJetORT.EnableUserPriority = enableUserPriority
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        alg.overlapTool.MuJetORT.OutputPassValue = True
        pass

    # Set up the tau-electron overlap removal.
    if doTaus and doElectrons:
        addPrivateTool( alg, 'overlapTool.TauEleORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.TauEleORT.InputLabel = inputLabel
        alg.overlapTool.TauEleORT.OutputLabel = outputLabel
        alg.overlapTool.TauEleORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.TauEleORT.DR = 0.2
        alg.overlapTool.TauEleORT.OutputPassValue = True
        pass

    # Set up the tau-muon overlap removal.
    if doTaus and doMuons:
        addPrivateTool( alg, 'overlapTool.TauMuORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.TauMuORT.InputLabel = inputLabel
        alg.overlapTool.TauMuORT.OutputLabel = outputLabel
        alg.overlapTool.TauMuORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.TauMuORT.DR = 0.2
        alg.overlapTool.TauMuORT.OutputPassValue = True
        pass

    # Set up the tau-(narrow-)jet overlap removal.
    if doTaus and doJets:
        addPrivateTool( alg, 'overlapTool.TauJetORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.TauJetORT.InputLabel = inputLabel
        alg.overlapTool.TauJetORT.OutputLabel = outputLabel
        alg.overlapTool.TauJetORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.TauJetORT.DR = 0.2
190
        alg.overlapTool.TauJetORT.EnableUserPriority = enableUserPriority
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
        alg.overlapTool.TauJetORT.OutputPassValue = True
        pass

    # Set up the photon-electron overlap removal.
    if doPhotons and doElectrons:
        addPrivateTool( alg, 'overlapTool.PhoEleORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.PhoEleORT.InputLabel = inputLabel
        alg.overlapTool.PhoEleORT.OutputLabel = outputLabel
        alg.overlapTool.PhoEleORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.PhoEleORT.OutputPassValue = True
        pass

    # Set up the photon-muon overlap removal.
    if doPhotons and doMuons:
        addPrivateTool( alg, 'overlapTool.PhoMuORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.PhoMuORT.InputLabel = inputLabel
        alg.overlapTool.PhoMuORT.OutputLabel = outputLabel
        alg.overlapTool.PhoMuORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.PhoMuORT.OutputPassValue = True
        pass

    # Set up the photon-(narrow-)jet overlap removal.
    if doPhotons and doJets:
        addPrivateTool( alg, 'overlapTool.PhoJetORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.PhoJetORT.InputLabel = inputLabel
        alg.overlapTool.PhoJetORT.OutputLabel = outputLabel
        alg.overlapTool.PhoJetORT.LinkOverlapObjects = linkOverlapObjects
221
        alg.overlapTool.PhoJetORT.EnableUserPriority = enableUserPriority
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
        alg.overlapTool.PhoJetORT.OutputPassValue = True
        pass

    # Set up the electron-fat-jet overlap removal.
    if doElectrons and doFatJets:
        addPrivateTool( alg, 'overlapTool.EleFatJetORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.EleFatJetORT.InputLabel = inputLabel
        alg.overlapTool.EleFatJetORT.OutputLabel = outputLabel
        alg.overlapTool.EleFatJetORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.EleFatJetORT.DR = 1.0
        alg.overlapTool.EleFatJetORT.OutputPassValue = True
        pass

    # Set up the (narrow-)jet-fat-jet overlap removal.
    if doJets and doFatJets:
        addPrivateTool( alg, 'overlapTool.JetFatJetORT',
                        'ORUtils::DeltaROverlapTool' )
        alg.overlapTool.JetFatJetORT.InputLabel = inputLabel
        alg.overlapTool.JetFatJetORT.OutputLabel = outputLabel
        alg.overlapTool.JetFatJetORT.LinkOverlapObjects = linkOverlapObjects
        alg.overlapTool.JetFatJetORT.DR = 1.0
        alg.overlapTool.JetFatJetORT.OutputPassValue = True
        pass

    # Add the algorithm to the analysis sequence.
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    if shallowViewOutput:
        seq.append( alg,
                    inputPropName = { 'electrons' : 'electrons',
                                      'muons'     : 'muons',
                                      'jets'      : 'jets',
                                      'taus'      : 'taus',
                                      'photons'   : 'photons',
                                      'fatJets'   : 'fatJets' },
                    outputPropName = { 'electrons' : 'electronsOut',
                                       'muons'     : 'muonsOut',
                                       'jets'      : 'jetsOut',
                                       'taus'      : 'tausOut',
                                       'photons'   : 'photonsOut',
                                       'fatJets'   : 'fatJetsOut' } )
        pass
    else:
        seq.append( alg,
                    inputPropName = { 'electrons' : 'electrons',
                                      'muons'     : 'muons',
                                      'jets'      : 'jets',
                                      'taus'      : 'taus',
                                      'photons'   : 'photons',
                                      'fatJets'   : 'fatJets' } )
        pass
272
273

    # Add view container creation algorithms for all types.
274
275
276
277
278
279
280
    if shallowViewOutput:
        for container in [ ( 'electrons', doElectrons ),
                           ( 'muons',     doMuons ),
                           ( 'jets',      doJets ),
                           ( 'taus',      doTaus ),
                           ( 'photons',   doPhotons ),
                           ( 'fatJets',   doFatJets ) ]:
281

282
283
284
            # Skip setting up a view container if the type is not being processed.
            if not container[ 1 ]:
                continue
285

286
287
288
289
290
291
292
293
294
295
296
297
298
            # Set up a cutflow alg.
            if enableCutflow:
                alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg',
                                       'OverlapRemovalCutFlowDumperAlg_%s' % container[ 0 ] + postfix )
                alg.histPattern = container[ 0 ] + postfix + '_OR_cflow_%SYS%'
                if inputLabel:
                    alg.selection = [ '%s,as_char' % inputLabel,
                                      '%s,as_char' % outputLabel ]
                    alg.selectionNCuts = [1, 1]
                else:
                    alg.selection = [ '%s,as_char' % outputLabel ]
                    alg.selectionNCuts = [1]
                seq.append( alg, inputPropName = { container[ 0 ] : 'input' } )
299

300
301
302
303
304
305
            # Set up a view container for the type.
            alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
                                   'OverlapRemovalViewMaker_%s' % container[ 0 ] + postfix )
            alg.selection = [ '%s,as_char' % outputLabel ]
            seq.append( alg, inputPropName = { container[ 0 ] : 'input' },
                        outputPropName = { container[ 0 ] : 'output' } )
306
307
308
309
        pass

    # Return the sequence:
    return seq