ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.TauAnalysisConfig.TauWorkingPointConfig Class Reference
Inheritance diagram for python.TauAnalysisConfig.TauWorkingPointConfig:
Collaboration diagram for python.TauAnalysisConfig.TauWorkingPointConfig:

Public Member Functions

def __init__ (self)
 
def instanceName (self)
 
def makeAlgs (self, config)
 

Public Attributes

 manual_sel_rnnwp
 
 manual_sel_gntauwp
 
 manual_sel_evetowp
 
 quality
 

Detailed Description

the ConfigBlock for the tau working point

This may at some point be split into multiple blocks (16 Mar 22).

Definition at line 108 of file TauAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TauAnalysisConfig.TauWorkingPointConfig.__init__ (   self)

Definition at line 113 of file TauAnalysisConfig.py.

113  def __init__ (self) :
114  super (TauWorkingPointConfig, self).__init__ ()
115  self.addOption ('containerName', '', type=str,
116  noneAction='error',
117  info="the name of the input container.")
118  self.addOption ('selectionName', '', type=str,
119  noneAction='error',
120  info="the name of the tau-jet selection to define (e.g. tight or "
121  "loose).")
122  self.addOption ('postfix', None, type=str,
123  info="a postfix to apply to decorations and algorithm names. "
124  "Typically not needed here as selectionName is used internally.")
125  self.addOption ('quality', None, type=str,
126  info="the ID WP (string) to use. Supported ID WPs: Tight, Medium, "
127  "Loose, VeryLoose, Baseline, BaselineForFakes.")
128  self.addOption ('use_eVeto', False, type=bool,
129  info="use selection with or without eVeto combined with tauID "
130  "recommendations: set it to True if electron mis-reconstructed as tau is a large background for your analysis")
131  self.addOption ('use_muonOLR', False, type=bool,
132  info="use selection with or without muonOLR with TauID "
133  "recommendations: set it to True if muon mis-reconstructed as tau is a large background for your analysis")
134  self.addOption ('useGNTau', False, type=bool,
135  info="use GNTau based ID instead of RNNTau ID "
136  "recommendations: that's new experimental feature and might come default soon")
137  self.addOption ('dropPtCut', False, type=bool,
138  info="select taus without explicit min Pt cut. For PHYS/PHYSLITE, this would mean selecting taus starting from 13 GeV "
139  "recommendations: that's experimental feature and not supported for all combinations of ID/eVeto WPs")
140  self.addOption ('useLowPt', False, type=bool,
141  info="select taus starting from 15 GeV instead of the default 20 GeV cut "
142  "recommendations: that's experimental feature and not supported for all combinations of ID/eVeto WPs")
143  self.addOption ('useSelectionConfigFile', True, type=bool,
144  info="use pre-defined configuration files for selecting taus "
145  "recommendations: set this to False only if you want to test/optimise the tau selection for selections not already provided through config files")
146  self.addOption ('manual_sel_minpt', 20.0, type=float,
147  info="minimum pt cut used for tau selection when useSelectionConfigFile is set to false")
148  self.addOption ('manual_sel_absetaregion', [0, 1.37, 1.52, 2.5], type=list,
149  info="eta regions cut used for tau selection when useSelectionConfigFile is set to false")
150  self.addOption ('manual_sel_abscharges', [1,], type=list,
151  info="charge of the tau cut used for tau selection when useSelectionConfigFile is set to false")
152  self.addOption ('manual_sel_ntracks', [1,3], type=list,
153  info="number of tau tracks used for tau selection when useSelectionConfigFile is set to false")
154  self.addOption ('manual_sel_minrnnscore', -1, type=float,
155  info="minimum rnn score cut used for tau selection when useSelectionConfigFile is set to false")
156  self.addOption ('manual_sel_mingntauscore', -1, type=float,
157  info="minimum gntau score selection when useSelectionConfigFile is set to false")
158  self.addOption ('manual_sel_rnnwp', None, type=str,
159  info="rnn working point used for tau selection when useSelectionConfigFile is set to false")
160  self.addOption ('manual_sel_gntauwp', None, type=str,
161  info="gntau working point used for tau selection when useSelectionConfigFile is set to false")
162  self.addOption ('manual_sel_evetowp', None, type=str,
163  info="eveto working point used for tau selection when useSelectionConfigFile is set to false")
164  self.addOption ('manual_sel_muonolr', False, type=bool,
165  info="use muonolr used for tau selection when useSelectionConfigFile is set to false")
166  self.addOption ('noEffSF', False, type=bool,
167  info="disables the calculation of efficiencies and scale factors. "
168  "Experimental! only useful to test a new WP for which scale "
169  "factors are not available. The default is False.")
170  self.addOption ('saveDetailedSF', True, type=bool,
171  info="save all the independent detailed object scale factors. "
172  "The default is True.")
173  self.addOption ('saveCombinedSF', False, type=bool,
174  info="save the combined object scale factor. "
175  "The default is False.")
176  self.addOption ('addSelectionToPreselection', True, type=bool,
177  info="whether to retain only tau-jets satisfying the working point "
178  "requirements. The default is True.")
179 

Member Function Documentation

◆ instanceName()

def python.TauAnalysisConfig.TauWorkingPointConfig.instanceName (   self)
Return the instance name for this block

Definition at line 180 of file TauAnalysisConfig.py.

180  def instanceName (self) :
181  """Return the instance name for this block"""
182  if self.postfix is not None:
183  return self.containerName + '_' + self.selectionName + self.postfix
184  else:
185  return self.containerName + '_' + self.selectionName
186 

◆ makeAlgs()

def python.TauAnalysisConfig.TauWorkingPointConfig.makeAlgs (   self,
  config 
)

Definition at line 187 of file TauAnalysisConfig.py.

187  def makeAlgs (self, config) :
188 
189  selectionPostfix = self.selectionName
190  if selectionPostfix != '' and selectionPostfix[0] != '_' :
191  selectionPostfix = '_' + selectionPostfix
192 
193  postfix = self.postfix
194  if postfix is None :
195  postfix = self.selectionName
196  if postfix != '' and postfix[0] != '_' :
197  postfix = '_' + postfix
198 
199  # do tau seletion through external txt config file
200  if self.useSelectionConfigFile:
201  nameFormat = 'TauAnalysisAlgorithms/tau_selection_'
202  if self.dropPtCut:
203  nameFormat = nameFormat + 'nopt_'
204  if self.useLowPt:
205  nameFormat = nameFormat + 'lowpt_'
206  if self.useGNTau:
207  nameFormat = nameFormat + 'gntau_'
208  nameFormat = nameFormat + '{}_'
209  if self.use_eVeto:
210  nameFormat = nameFormat + 'eleid'
211  else:
212  nameFormat = nameFormat + 'noeleid'
213  if self.use_muonOLR:
214  nameFormat = nameFormat + '_muonolr'
215  nameFormat = nameFormat + '.conf'
216 
217  if self.quality not in ['Tight', 'Medium', 'Loose', 'VeryLoose', 'Baseline', 'BaselineForFakes'] :
218  raise ValueError ("invalid tau quality: \"" + self.quality +
219  "\", allowed values are Tight, Medium, Loose, " +
220  "VeryLoose, Baseline, BaselineForFakes")
221 
222  # Set up the algorithm selecting taus:
223  alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'TauSelectionAlg' )
224  config.addPrivateTool( 'selectionTool', 'TauAnalysisTools::TauSelectionTool' )
225  if self.useSelectionConfigFile:
226  inputfile = nameFormat.format(self.quality.lower())
227  alg.selectionTool.ConfigPath = inputfile
228  else:
229  #build selection from user handmade selection
230  from ROOT import TauAnalysisTools
231  selectioncuts = TauAnalysisTools.SelectionCuts
232  alg.selectionTool.ConfigPath = ""
233  alg.selectionTool.SelectionCuts = int(selectioncuts.CutPt |
234  selectioncuts.CutAbsEta |
235  selectioncuts.CutAbsCharge |
236  selectioncuts.CutNTrack |
237  selectioncuts.CutJetRNNScoreSigTrans |
238  selectioncuts.CutGNTauScoreSigTrans |
239  selectioncuts.CutJetIDWP |
240  selectioncuts.CutEleIDWP |
241  selectioncuts.CutMuonOLR)
242 
243  alg.selectionTool.PtMin = self.manual_sel_minpt
244  alg.selectionTool.AbsEtaRegion = self.manual_sel_absetaregion
245  alg.selectionTool.AbsCharges = self.manual_sel_abscharges
246  alg.selectionTool.NTracks = self.manual_sel_ntracks
247  alg.selectionTool.JetRNNSigTransMin = self.manual_sel_minrnnscore
248  alg.selectionTool.GNTauSigTransMin = self.manual_sel_mingntauscore
249  #cross-check that min rnn score and min gntau score are not both set at the same time
250  if self.manual_sel_minrnnscore != -1 and self.manual_sel_mingntauscore != -1:
251  raise RuntimeError("manual_sel_minrnnscore and manual_sel_mingntauscore have been both set; please choose only one type of ID: RNN or GNTau, not both")
252  # working point following the Enums from https://gitlab.cern.ch/atlas/athena/-/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h
253  if self.manual_sel_rnnwp is None:
254  alg.selectionTool.JetIDWP = 1
255  elif self.manual_sel_rnnwp == "veryloose":
256  alg.selectionTool.JetIDWP = 6
257  elif self.manual_sel_rnnwp == "loose":
258  alg.selectionTool.JetIDWP = 7
259  elif self.manual_sel_rnnwp == "medium":
260  alg.selectionTool.JetIDWP = 8
261  elif self.manual_sel_rnnwp == "tight":
262  alg.selectionTool.JetIDWP = 9
263  else:
264  raise ValueError ("invalid RNN TauID WP: \"" + self.manual_sel_rnnwp + "\". Allowed values are None, veryloose, loose, medium, tight")
265 
266  # cross-check that min rnn score and RNN WPs are not set at the same time
267  if self.manual_sel_minrnnscore != -1 and self.manual_sel_rnnwp is not None:
268  raise RuntimeError("manual_sel_minrnnscore and manual_sel_rnnwp have been both set; please set only one of them")
269 
270  # working point following the Enums from https://gitlab.cern.ch/atlas/athena/-/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h
271  if self.manual_sel_gntauwp is None:
272  alg.selectionTool.JetIDWP = 1
273  elif self.manual_sel_gntauwp == "veryloose":
274  alg.selectionTool.JetIDWP = 10
275  elif self.manual_sel_gntauwp == "loose":
276  alg.selectionTool.JetIDWP = 11
277  elif self.manual_sel_gntauwp == "medium":
278  alg.selectionTool.JetIDWP = 12
279  elif self.manual_sel_gntauwp == "tight":
280  alg.selectionTool.JetIDWP = 13
281  else:
282  raise ValueError ("invalid GNN Tau ID WP: \"" + self.manual_sel_gntauwp + "\". Allowed values are None, veryloose, loose, medium, tight")
283 
284  # cross-check that min gntau score and GNTau WPs are not set at the same time
285  if self.manual_sel_mingntauscore != -1 and self.manual_sel_gntauwp is not None:
286  raise RuntimeError("manual_sel_mingntauscore and manual_sel_gntauwp have been both set; please set only one of them")
287 
288  # working point following the Enums from https://gitlab.cern.ch/atlas/athena/-/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h
289  if self.manual_sel_evetowp is None:
290  alg.selectionTool.EleIDWP = 1
291  elif self.manual_sel_evetowp == "loose":
292  alg.selectionTool.EleIDWP = 2
293  elif self.manual_sel_evetowp == "medium":
294  alg.selectionTool.EleIDWP = 3
295  elif self.manual_sel_evetowp == "tight":
296  alg.selectionTool.EleIDWP = 4
297  else:
298  raise ValueError ("invalid eVeto WP: \"" + self.manual_sel_evetowp + "\". Allowed values are None, loose, medium, tight")
299 
300  # set MuonOLR option:
301  alg.selectionTool.MuonOLR = self.manual_sel_muonolr
302 
303  alg.selectionDecoration = 'selected_tau' + selectionPostfix + ',as_char'
304  alg.particles = config.readName (self.containerName)
305  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
306  config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
307  preselection=self.addSelectionToPreselection)
308 
309  sfList = []
310  # Set up the algorithm calculating the efficiency scale factors for the
311  # taus:
312  if config.dataType() is not DataType.Data and not self.noEffSF:
313  log = logging.getLogger('TauJetSFConfig')
314  # need multiple instances of the TauEfficiencyCorrectionTool
315  # 1) Reco 2) TauID, 3) eVeto for fake tau 4) eVeto for true tau
316  # 3) and 4) are optional if eVeto is used in TauSelectionTool
317 
318  # TauEfficiencyCorrectionTool for Reco, this should be always enabled
319  alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
320  'TauEfficiencyCorrectionsAlgReco' )
321  config.addPrivateTool( 'efficiencyCorrectionsTool',
322  'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
323  alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [0]
324  alg.efficiencyCorrectionsTool.Campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
325  alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
326  alg.scaleFactorDecoration = 'tau_Reco_effSF' + selectionPostfix + '_%SYS%'
327  alg.outOfValidity = 2 #silent
328  alg.outOfValidityDeco = 'bad_Reco_eff' + selectionPostfix
329  alg.taus = config.readName (self.containerName)
330  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
331  if self.saveDetailedSF:
332  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
333  'Reco_effSF' + postfix)
334  sfList += [alg.scaleFactorDecoration]
335 
336  # TauEfficiencyCorrectionTool for Identification, use only in case TauID is requested in TauSelectionTool
337  if self.quality not in ('VeryLoose','Baseline','BaselineForFakes'):
338  if not self.useGNTau: # current recommendations are for RNN ID, so don't use in case of GNTau
339 
340  alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
341  'TauEfficiencyCorrectionsAlgID' )
342  config.addPrivateTool( 'efficiencyCorrectionsTool',
343  'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
344  alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [4]
345  if self.quality=="Loose":
346  JetIDLevel = 7
347  elif self.quality=="Medium":
348  JetIDLevel = 8
349  elif self.quality=="Tight":
350  JetIDLevel = 9
351  else:
352  raise ValueError ("invalid tauID: \"" + self.quality + "\". Allowed values are loose, medium, tight")
353 
354  alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
355  alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
356  alg.efficiencyCorrectionsTool.Campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
357  alg.scaleFactorDecoration = 'tau_ID_effSF' + selectionPostfix + '_%SYS%'
358  alg.outOfValidity = 2 #silent
359  alg.outOfValidityDeco = 'bad_ID_eff' + selectionPostfix
360  alg.taus = config.readName (self.containerName)
361  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
362  if self.saveDetailedSF:
363  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
364  'ID_effSF' + postfix)
365  sfList += [alg.scaleFactorDecoration]
366 
367  # TauEfficiencyCorrectionTool for eVeto both on true tau and fake tau, use only in case eVeto is requested in TauSelectionTool
368  if self.use_eVeto:
369  if not self.useGNTau: # eVeto correction for fake tau are for RNN ID, so don't use them for GNTau
370  # correction for fake tau
371  alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
372  'TauEfficiencyCorrectionsAlgEvetoFakeTau' )
373  config.addPrivateTool( 'efficiencyCorrectionsTool',
374  'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
375  alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [10]
376  # since all TauSelectionTool config files have loose eRNN, code only this option for now
377  alg.efficiencyCorrectionsTool.EleIDLevel = 2
378  alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
379  alg.efficiencyCorrectionsTool.Campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
380  alg.scaleFactorDecoration = 'tau_EvetoFakeTau_effSF' + selectionPostfix + '_%SYS%'
381  # for 2025-prerec, eVeto recommendations are given separately for Loose and Medium RNN
382  if self.quality=="Loose":
383  JetIDLevel = 7
384  elif self.quality=="Medium":
385  JetIDLevel = 8
386  elif self.quality=="Tight":
387  log.warning("eVeto SFs are not available for Tight WP -> fallback to Medium WP")
388  JetIDLevel = 8
389  alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
390  alg.outOfValidity = 2 #silent
391  alg.outOfValidityDeco = 'bad_EvetoFakeTau_eff' + selectionPostfix
392  alg.taus = config.readName (self.containerName)
393  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
394  if self.saveDetailedSF:
395  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
396  'EvetoFakeTau_effSF' + postfix)
397  sfList += [alg.scaleFactorDecoration]
398 
399  # correction for true tau
400  alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
401  'TauEfficiencyCorrectionsAlgEvetoTrueTau' )
402  config.addPrivateTool( 'efficiencyCorrectionsTool',
403  'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
404  alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [8]
405  alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
406  alg.efficiencyCorrectionsTool.Campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
407  alg.scaleFactorDecoration = 'tau_EvetoTrueTau_effSF' + selectionPostfix + '_%SYS%'
408  alg.outOfValidity = 2 #silent
409  alg.outOfValidityDeco = 'bad_EvetoTrueTau_eff' + selectionPostfix
410  alg.taus = config.readName (self.containerName)
411  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
412  if self.saveDetailedSF:
413  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
414  'EvetoTrueTau_effSF' + postfix)
415  sfList += [alg.scaleFactorDecoration]
416 
417  if self.saveCombinedSF:
418  alg = config.createAlgorithm( 'CP::AsgObjectScaleFactorAlg',
419  'TauCombinedEfficiencyScaleFactorAlg' )
420  alg.particles = config.readName (self.containerName)
421  alg.inScaleFactors = sfList
422  alg.outScaleFactor = 'effSF' + postfix + '_%SYS%'
423  config.addOutputVar (self.containerName, alg.outScaleFactor,
424  'effSF' + postfix)
425 
426 

Member Data Documentation

◆ manual_sel_evetowp

python.TauAnalysisConfig.TauWorkingPointConfig.manual_sel_evetowp

Definition at line 291 of file TauAnalysisConfig.py.

◆ manual_sel_gntauwp

python.TauAnalysisConfig.TauWorkingPointConfig.manual_sel_gntauwp

Definition at line 273 of file TauAnalysisConfig.py.

◆ manual_sel_rnnwp

python.TauAnalysisConfig.TauWorkingPointConfig.manual_sel_rnnwp

Definition at line 255 of file TauAnalysisConfig.py.

◆ quality

python.TauAnalysisConfig.TauWorkingPointConfig.quality

Definition at line 345 of file TauAnalysisConfig.py.


The documentation for this class was generated from the following file:
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45