ATLAS Offline Software
JetGrooming.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 """
3 JetGrooming: A module for classes encoding definitions of objects
4 for configuring jet grooming
5 Author: TJ Khoo. P-A Delsart
6 """
7 
8 __all__ = ["GroomingDefinition","JetTrimming","JetSoftDrop"]
9 
10 from AthenaCommon import Logging
11 from .Utilities import make_lproperty, onlyAttributesAreProperties, clonable, ldict
12 from copy import deepcopy
13 jetlog = Logging.logging.getLogger('JetGrooming')
14 
15 @clonable
16 @onlyAttributesAreProperties
18  """ Base class to define grooming procedure.
19  Concrete classes will have to define the tooltype & groomalg class members
20  and aslo a groomSpecAsStr() function.
21 
22  """
23  _allowedattributes = ['_cflags','_contextDic'] # onlyAttributesAreProperties will add all properties to this list.
24  tooltype = None
25  groomalg = None
26  def __init__(self,
27  ungroomeddef, # Ungroomed JetDefinition
28  modifiers=[], # JetModifiers to run after grooming
29  suffix = '', # allows to tune the full JetContainer name
30  lock=False, # lock the properties of this instance to avoid accidental overwrite after __init__
31  context = None, # describe a context for which this definition will be used. See StandardJetContext
32  **properties # any other argument is expected a grooming tool property
33  ):
34 
35  self._ungroomeddef = ungroomeddef.clone() # clone to avoid messing with external jetdef
36  self.inputdef = self._ungroomeddef.inputdef
37  if lock: properties = ldict(properties) # ldict to freeze the properties
38  self.properties = properties
39 
40  context = context if context is not None else ungroomeddef.context
41  self._context = context
42  self.suffix = suffix
43  self._defineName()
44 
45  self.modifiers = modifiers
46 
47 
48  # used internally to resolve dependencies
49  self._prereqDic = {}
50  self._prereqOrder = []
51  self._locked = lock
52  self._cflags = None # pointer to AthenaConfiguration.ConfigFlags. Mainly to allow to invoke building of input dependencies which are outside Jet domain during std reco
53  self._contextDic = None # pointer to the context dictionnary. Convenient shortcut used to configure input or modifier dependencies
54 
55 
56  def __hash__(self):
57  return hash("")
58 
59  def __eq__(self,rhs):
60  return self.__hash__() == rhs.__hash__()
61 
62  def __ne__(self,rhs):
63  return (not self.__eq__(rhs))
64 
65  def lock(self):
66  if not self._locked:
67  self._locked = True
68 
69  # After dependency solving, we hold a reference to the AthConfigFlags,
70  # which if unmodified is meant to function as a singleton throughout the
71  # configuration. A full deep copy of this is expensive, and slows down
72  # the HLT menu generation a lot due to copies in caches.
73  # So we explicitly avoid the deepcopy of the flags here, and further
74  # check that the flags are locked, to prevent accidental unlocking
75  def __deepcopy__(self, memo):
76  cls = self.__class__
77  result = cls.__new__(cls)
78  memo[id(self)] = result
79  set_without_deepcopy = ['_cflags']
80  for k, v in self.__dict__.items():
81  if k in set_without_deepcopy:
82  if v:
83  assert(v.locked())
84  setattr(result, k, v)
85  else:
86  setattr(result, k, deepcopy(v, memo))
87  return result
88 
89  # Define core attributes as properties, with
90  # custom setter/getter such that if changed, these
91  # force resetting of the jet name
92  @make_lproperty
93  def ungroomeddef(self): pass
94  @ungroomeddef.lsetter
95  def ungroomeddef(self,ungroomeddef):
96  self._ungroomeddef = ungroomeddef.clone()
97  self._defineName()
98 
99 
100  @make_lproperty
101  def properties(self): pass
102  @make_lproperty
103  def modifiers(self): pass
104  @make_lproperty
105  def suffix(self): pass
106 
107  @make_lproperty
108  def context(self): pass
109 
110  # To be overriden in derived classes
111  def groomSpecAsStr(self):
112  raise Exception("Can not use a GroomingDefinition instance : use a derived class")
113 
114  def fullname(self):
115  return self.ungroomeddef.prefix+self.basename+"Jets"+self.suffix
116 
117 
118 
119 
120  def _defineName(self):
121  # chop the label off so we can insert the trimming spec
122  groomedName = self.ungroomeddef.basename + self.groomSpecAsStr()
123  self.basename = groomedName
124 
125  # Define a string conversion for printing
126  def __str__(self):
127  return "JetGrooming({0})".format(self.basename)
128  # Need to override __repr__ for printing in lists etc
129  __repr__ = __str__
130 
131 
133  groomalg = "Trim"
134  tooltype = "JetGrooming::JetTrimming"
135 
136  def groomSpecAsStr(self):
137  ptfrac = int( self.properties["PtFrac"] *100 ) # Not usually smaller than %
138  from .JetDefinition import formatRvalue
139  smallR = formatRvalue(self.properties["RClus"]*10)
140 
141  groomstr = "TrimmedPtFrac{}SmallR{}".format(ptfrac,smallR)
142  return groomstr
143 
144 
146  groomalg = "SoftDrop"
147  tooltype = "JetGrooming::SoftDrop"
148 
149  def groomSpecAsStr(self):
150  beta = int( self.properties["Beta"] *100)
151  zcut = int( self.properties["ZCut"] *100)
152  groomstr = "SoftDropBeta{}Zcut{}".format(beta,zcut)
153  return groomstr
python.JetGrooming.GroomingDefinition.modifiers
modifiers
Definition: JetGrooming.py:38
python.JetGrooming.GroomingDefinition.fullname
def fullname(self)
Definition: JetGrooming.py:114
vtune_athena.format
format
Definition: vtune_athena.py:14
python.JetGrooming.GroomingDefinition.__hash__
def __hash__(self)
Definition: JetGrooming.py:56
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.JetGrooming.GroomingDefinition.ungroomeddef
def ungroomeddef(self)
Definition: JetGrooming.py:93
python.JetGrooming.GroomingDefinition.__str__
def __str__(self)
Definition: JetGrooming.py:126
python.JetGrooming.GroomingDefinition.basename
basename
Definition: JetGrooming.py:123
python.JetGrooming.GroomingDefinition._context
_context
Definition: JetGrooming.py:34
python.JetGrooming.GroomingDefinition._prereqOrder
_prereqOrder
Definition: JetGrooming.py:43
python.JetGrooming.JetSoftDrop
Definition: JetGrooming.py:145
python.JetGrooming.GroomingDefinition.__ne__
def __ne__(self, rhs)
Definition: JetGrooming.py:62
python.JetGrooming.GroomingDefinition._ungroomeddef
_ungroomeddef
Definition: JetGrooming.py:28
python.JetDefinition.formatRvalue
def formatRvalue(parameter)
Definition: JetDefinition.py:34
python.JetGrooming.JetTrimming.groomSpecAsStr
def groomSpecAsStr(self)
Definition: JetGrooming.py:136
python.JetGrooming.GroomingDefinition.context
def context(self)
Definition: JetGrooming.py:108
python.JetGrooming.GroomingDefinition.__init__
def __init__(self, ungroomeddef, modifiers=[], suffix='', lock=False, context=None, **properties)
Definition: JetGrooming.py:26
python.JetGrooming.GroomingDefinition.__deepcopy__
def __deepcopy__(self, memo)
Definition: JetGrooming.py:75
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
python.JetGrooming.GroomingDefinition._defineName
def _defineName(self)
Definition: JetGrooming.py:120
python.JetGrooming.GroomingDefinition.suffix
suffix
Definition: JetGrooming.py:35
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.JetGrooming.JetTrimming
Definition: JetGrooming.py:132
python.Utilities.ldict
Definition: Utilities.py:139
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
python.JetGrooming.GroomingDefinition._contextDic
_contextDic
Definition: JetGrooming.py:46
python.JetGrooming.GroomingDefinition.lock
def lock(self)
Definition: JetGrooming.py:65
python.JetGrooming.GroomingDefinition
Definition: JetGrooming.py:17
pickleTool.object
object
Definition: pickleTool.py:30
python.JetGrooming.GroomingDefinition._locked
_locked
Definition: JetGrooming.py:44
python.JetGrooming.JetSoftDrop.groomSpecAsStr
def groomSpecAsStr(self)
Definition: JetGrooming.py:149
python.JetGrooming.GroomingDefinition._cflags
_cflags
Definition: JetGrooming.py:45
python.JetGrooming.GroomingDefinition.__eq__
def __eq__(self, rhs)
Definition: JetGrooming.py:59
python.JetGrooming.GroomingDefinition.properties
properties
Definition: JetGrooming.py:31
python.JetGrooming.GroomingDefinition._prereqDic
_prereqDic
Definition: JetGrooming.py:42
python.JetGrooming.GroomingDefinition.groomSpecAsStr
def groomSpecAsStr(self)
Definition: JetGrooming.py:111
python.JetGrooming.GroomingDefinition.inputdef
inputdef
Definition: JetGrooming.py:29