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 113 of file TauAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TauAnalysisConfig.TauWorkingPointConfig.__init__ (   self)

Definition at line 118 of file TauAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 185 of file TauAnalysisConfig.py.

185  def instanceName (self) :
186  """Return the instance name for this block"""
187  if self.postfix is not None:
188  return self.containerName + '_' + self.selectionName + self.postfix
189  else:
190  return self.containerName + '_' + self.selectionName
191 

◆ makeAlgs()

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

Definition at line 192 of file TauAnalysisConfig.py.

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

Member Data Documentation

◆ manual_sel_evetowp

python.TauAnalysisConfig.TauWorkingPointConfig.manual_sel_evetowp

Definition at line 296 of file TauAnalysisConfig.py.

◆ manual_sel_gntauwp

python.TauAnalysisConfig.TauWorkingPointConfig.manual_sel_gntauwp

Definition at line 278 of file TauAnalysisConfig.py.

◆ manual_sel_rnnwp

python.TauAnalysisConfig.TauWorkingPointConfig.manual_sel_rnnwp

Definition at line 260 of file TauAnalysisConfig.py.

◆ quality

python.TauAnalysisConfig.TauWorkingPointConfig.quality

Definition at line 350 of file TauAnalysisConfig.py.


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