ATLAS Offline Software
FTagAnalysisSequence.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 # AnaAlgorithm import(s):
4 from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool
5 
6 def makeFTagAnalysisSequence( seq, dataType, jetCollection,
7  btagWP = "FixedCutBEff_77",
8  btagger = "DL1r",
9  generator = "default",
10  postfix = "",
11  preselection=None,
12  kinematicSelection = False,
13  noEfficiency = False,
14  enableCutflow = False,
15  minPt = None,
16  makeViewContainer = False):
17  """Create a ftag analysis algorithm sequence
18 
19  for now the sequence is passed in, I'm unsure if I can concatenate
20  two sequences at the moment, or if that blows things up horribly
21 
22  Keyword arguments:
23  dataType -- The data type to run on ("data", "mc" or "afii")
24  jetCollection -- Jet container to run on
25  btagWP -- Flavour tagging working point
26  btagger -- Flavour tagger
27  generator -- Generator for MC/MC scale factors
28  kinematicSelection -- Wether to run kinematic selection
29  noEfficiency -- Wether to run efficiencies calculation
30  enableCutflow -- Whether or not to dump the cutflow
31  minPt -- Kinematic selection for jet calibration validity (depending on jet collection)
32  """
33 
34  # Kinematic selection depending on validity of the calibration
35  # https://twiki.cern.ch/twiki/bin/view/AtlasProtected/BTagCalibrationRecommendationsRelease21
36  if minPt is None:
37  if "EMPFlow" in jetCollection:
38  minPt = 20e3
39  elif "EMTopo" in jetCollection:
40  minPt = 20e3
41  elif "VRTrack" in jetCollection:
42  minPt = 10e3
43 
44  preselectionList = []
45  if preselection is not None and preselection != '' :
46  preselectionList.append (preselection)
47 
48  if dataType not in ["data", "mc", "afii"] :
49  raise ValueError ("invalid data type: " + dataType)
50 
51  if generator not in ["default", "Pythia8", "Sherpa221", "Sherpa2210", "Sherpa2212", "Herwig713", "Herwig721", "amcAtNLOPythia", "amcAtNLOHerwig"]:
52  raise ValueError ("invalid generator type: " + generator)
53 
54  # MC/MC scale factors configuration
55  DSID = "default"
56  if generator == "Sherpa221":
57  DSID = "410250"
58  elif generator == "Sherpa2210":
59  DSID = "700122"
60  elif generator == "Sherpa2212":
61  DSID = "700660"
62  elif generator == "Herwig713":
63  DSID = "411233"
64  elif generator == "Herwig721":
65  DSID = "600666"
66  elif generator == "amcAtNLOPythia":
67  DSID = "410464"
68  elif generator == "amcAtNLOHerwig":
69  DSID = "412116"
70 
71  # CDI file
72  bTagCalibFile = "xAODBTaggingEfficiency/13TeV/2023-22-13TeV-MC20-CDI-2023-09-13_v1.root"
73 
74  # # Create the analysis algorithm sequence object:
75  # seq = AnaAlgSequence( "FTagAnalysisSequence" )
76 
77  if kinematicSelection:
78  # Set up the ftag kinematic selection algorithm(s):
79  alg = createAlgorithm( 'CP::AsgSelectionAlg', 'FTagKinSelectionAlg'+postfix )
80  addPrivateTool( alg, 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
81  alg.selectionTool.minPt = minPt
82  alg.selectionTool.maxEta = 2.5
83  alg.selectionDecoration = 'ftag_kin_select_' + btagger + '_' + btagWP
84  alg.preselection = '&&'.join (preselectionList)
85  preselectionList.append (alg.selectionDecoration)
86  seq.append( alg, inputPropName = 'particles' )
87 
88  if makeViewContainer :
89  # Set up an algorithm that makes a view container using the selections
90  # performed previously:
91  alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
92  'FTagKinViewFromSelectionAlg'+postfix )
93  alg.selection = [ 'ftag_kin_select_' + btagger + '_' + btagWP ]
94  seq.append( alg, inputPropName = 'input', outputPropName = 'output',
95  stageName = 'selection' )
96 
97  # Set up the ftag selection algorithm(s):
98  alg = createAlgorithm( 'CP::AsgSelectionAlg', 'FTagSelectionAlg' + btagger + btagWP + postfix )
99  addPrivateTool( alg, 'selectionTool', 'BTaggingSelectionTool' )
100  alg.selectionTool.TaggerName = btagger
101  alg.selectionTool.OperatingPoint = btagWP
102  alg.selectionTool.JetAuthor = jetCollection
103  alg.selectionTool.FlvTagCutDefinitionsFileName = bTagCalibFile
104  alg.selectionTool.MinPt = 0.
105  alg.preselection = '&&'.join (preselectionList)
106  alg.selectionDecoration = 'ftag_select_' + btagger + '_' + btagWP + ',as_char'
107  seq.append( alg, inputPropName = 'particles',
108  stageName = 'selection' )
109 
110  if btagWP == 'Continuous':
111  alg = createAlgorithm( 'CP::BTaggingInformationDecoratorAlg', 'FTagInfoAlg' + btagger + btagWP + postfix )
112  addPrivateTool( alg, 'selectionTool', 'BTaggingSelectionTool' )
113  alg.selectionTool.TaggerName = btagger
114  alg.selectionTool.OperatingPoint = btagWP
115  alg.selectionTool.JetAuthor = jetCollection
116  alg.selectionTool.FlvTagCutDefinitionsFileName = bTagCalibFile
117  alg.selectionTool.MinPt = 0.
118  alg.preselection = '&&'.join (preselectionList)
119  alg.quantileDecoration = 'ftag_quantile_' + btagger
120  seq.append( alg, inputPropName = 'jets',
121  stageName = 'selection' )
122 
123  if not noEfficiency and dataType != 'data':
124  # Set up the efficiency calculation algorithm:
125  alg = createAlgorithm( 'CP::BTaggingEfficiencyAlg',
126  'FTagEfficiencyScaleFactorAlg' + btagger + btagWP + postfix )
127  addPrivateTool( alg, 'efficiencyTool',
128  'BTaggingEfficiencyTool' )
129  alg.efficiencyTool.TaggerName = btagger
130  alg.efficiencyTool.OperatingPoint = btagWP
131  alg.efficiencyTool.JetAuthor = jetCollection
132  alg.efficiencyTool.ScaleFactorFileName = bTagCalibFile
133  alg.efficiencyTool.SystematicsStrategy = "Envelope"
134  alg.efficiencyTool.MinPt = 0.
135  if DSID != "default":
136  alg.efficiencyTool.EfficiencyBCalibrations = DSID
137  alg.efficiencyTool.EfficiencyTCalibrations = DSID
138  alg.efficiencyTool.EfficiencyCCalibrations = DSID
139  alg.efficiencyTool.EfficiencyLightCalibrations = DSID
140  alg.scaleFactorDecoration = 'ftag_effSF_' + btagger + '_' + btagWP + '_%SYS%'
141  alg.selectionDecoration = 'ftag_select_' + btagger + '_' + btagWP + ',as_char'
142  alg.onlyEfficiency = btagWP == 'Continuous'
143  alg.outOfValidity = 2
144  alg.outOfValidityDeco = 'no_ftag_' + btagger + '_' + btagWP
145  alg.preselection = '&&'.join (preselectionList)
146  seq.append( alg, inputPropName = 'jets',
147  stageName = 'efficiency' )
148  pass
149 
150  # Set up an algorithm used to create f-tag selection cutflow:
151  if enableCutflow:
152  alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg', 'FTagCutFlowDumperAlg' + btagger + btagWP + postfix )
153  alg.histPattern = 'ftag_cflow_' + btagger + '_' + btagWP + '_%SYS%'
154  alg.selections = ['ftag_select_' + btagger + '_' + btagWP + ',as_char']
155  seq.append( alg, inputPropName = 'input',
156  stageName = 'selection' )
157 
158  # Return the sequence:
159  return seq
python.DualUseConfig.addPrivateTool
def addPrivateTool(alg, toolName, typeName)
Definition: DualUseConfig.py:180
python.FTagAnalysisSequence.makeFTagAnalysisSequence
def makeFTagAnalysisSequence(seq, dataType, jetCollection, btagWP="FixedCutBEff_77", btagger="DL1r", generator="default", postfix="", preselection=None, kinematicSelection=False, noEfficiency=False, enableCutflow=False, minPt=None, makeViewContainer=False)
Definition: FTagAnalysisSequence.py:6
python.DualUseConfig.createAlgorithm
def createAlgorithm(typeName, instanceName)
Definition: DualUseConfig.py:56