ATLAS Offline Software
Loading...
Searching...
No Matches
BPhysPyHelpers.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3#====================================================================
4# BPhysPyHelpers.py
5#
6# Python helper classes for BPHY derivations.
7#
8# authors: W. Walkowiak <wolfgang.walkowiak@cern.ch>, 2016-05-19
9# changed:
10#
11# This file contains a set of Python helper classes for the
12# BPHY derivations.
13#
14# Available helper classes and methods:
15# - BPyWrapper -- wrap configurable to ensure default contents of
16# __slots__ dict are available as attributes
17# Usage example: see BPHY8.py
18# Note: Unfortunately, this doesn't quite work, since the
19# wrapped class is no longer recognized as Configurable
20# - BPhysEnsureAttributes(algtool)
21# -- ensure default contents of __slots__ dict a
22# are available as attributes to the class
23# - BPhysFilterBranches(...)
24# -- create list of isolation or closest track branches
25# to be thinned
26#
27#====================================================================
28
29#--------------------------------------------------------------------
31 __slots__ = {'wclass' : object}
32
33 def __init__(self, wclass, *args, **kargs):
34 object.__setattr__(self, 'wclass', wclass(*args, **kargs))
35 # the important part: make __slot__ variables attributes
36 for n,v in self.wclass.__slots__.items():
37 if not hasattr(self.wclass, n):
38 setattr(self.wclass, n, v)
39
40 def __getattr__(self, attr):
41 return self.wclass.__getattribute__(attr)
42
43 def __setattr__(self, attr, value):
44 setattr(self.wclass, attr, value)
45
46 def __call__(self, *args, **kwargs):
47 return self.wclass(*args, **kwargs)
48#--------------------------------------------------------------------
49#
50# ensure default contents of __slots__ dict are available as attributes
51#
53
54 for n,v in algtool.__slots__.items():
55 if not hasattr(algtool, n):
56 setattr(algtool, n, v)
57 return algtool
58#--------------------------------------------------------------------
59#
60# create list of isolation or closest track branches to be thinned
61# (used by BPHY8)
62#
63def BPhysFilterBranches(name, brPrefixList, brIncludeList, doVertexTypeList,
64 categoryList, trackTypeList, coneOrChi2SetList,
65 forCloseTrack=False):
66 res = ""
67 brIncludes = [tuple(x.split('|',3)) for x in brIncludeList]
68 for bntup in brPrefixList:
69 bn, sep, bnsuf = bntup.partition('+')
70 for i, cstr in enumerate(coneOrChi2SetList):
71 for itt in trackTypeList:
72 ittstr = "T%010d" % itt
73 for itcstr in categoryList:
74 if brIncludes and not (cstr,str(itt),itcstr) in brIncludes:
75 for dvs in doVertexTypeList:
76 if forCloseTrack:
77 fbn = '_'.join(filter(None, [name,bn,ittstr,itcstr,
78 dvs,cstr,bnsuf]))
79 else:
80 fbn = '_'.join(filter(None, [name,bn,cstr,ittstr,
81 itcstr,dvs,bnsuf]))
82 res += ".-"+fbn
83 return res
84#--------------------------------------------------------------------
__setattr__(self, attr, value)
__init__(self, wclass, *args, **kargs)
__call__(self, *args, **kwargs)
BPhysFilterBranches(name, brPrefixList, brIncludeList, doVertexTypeList, categoryList, trackTypeList, coneOrChi2SetList, forCloseTrack=False)
BPhysEnsureAttributes(algtool)