5JetDefinition: A module for classes encoding definitions of jets and
6related objects for configuring jet reconstruction
8Various classes encode definitions of different types of components used in Jet Reco.
11 - JetInputExternal : describes how to build a source container, typically external to the jet domain. This includes input to jet finding (ex: CaloCluster, Track) but also other sources like EventDensity...
13 - JetInputConstit : describes specifically an input constituents container (an input to a PseudoJetAlgorithm), thus referring to a JetInputExternal as the primary source.
14 - JetInputConstitSeq : a subclass of JetInputConstit, describing how a constituents container is build from a JetConstituentModSequence (ex: PU or Origin correction).
15 - JetConstitModifier : describes a constituent modifier tool to be used in a JetConstituentModSequence
17 - JetDefinition : describes a full jet reco sequence. Uses a JetInputConstit and a list of JetModifier
18 - JetModifier : describes a JetModifier c++ tool.
20Author: TJ Khoo, P-A Delsart
24__all__ = [
"JetDefinition",
"xAODType",
"JetModifier",
"JetConstitModifier" ,
"JetInputConstitSeq",
"JetInputExternal"]
26from AthenaCommon
import Logging
27jetlog = Logging.logging.getLogger(
'JetDefinition')
29from xAODBase.xAODType
import xAODType
30from .Utilities
import make_lproperty, onlyAttributesAreProperties, clonable, make_alias
32from copy
import deepcopy
35 """Define the convention that we write R truncating the decimal point
36 if R>=1, then we write R*10.
37 (Code from JetRecUtils )
40 if int(10*parameter)>=1
and int(100*parameter % 10):
42 raise ValueError(
'Bad radius parameter')
44 return "{0:.0f}".format(10*parameter)
46 return "{0:.1g}".format(10*parameter).
replace(
'.',
'')
51 variableRMassScale= -1.0, variableRMinRadius=-1.0):
52 """variableRMassScale (Rho) in MeV """
53 if ( variableRMassScale >= 0.0
and variableRMinRadius >= 0.0):
56 return f
"{finder}VR{str(int(variableRMassScale/1000))}Rmax{rmaxstr}Rmin{rminstr}"
64from AthenaCommon.SystemOfUnits
import MeV
67@onlyAttributesAreProperties
69 _allowedattributes = [
'_cflags',
'_contextDic']
78 standardRecoMode = False,
93 if algorithm
not in [
"Kt",
"AntiKt",
"CamKt"]:
94 jetlog.error(
"FastJet algorithm specification was not one of Kt, AntiKt, CamKt!")
95 raise KeyError(
"Invalid fastjet algorithm choice: {0}".format(self.
algorithm))
132 return self.
__hash__() == rhs.__hash__()
135 return (
not self.
__eq__(rhs))
149 result = cls.__new__(cls)
150 memo[id(self)] = result
151 set_without_deepcopy = [
'_cflags']
152 for k, v
in self.__dict__.items():
153 if k
in set_without_deepcopy:
156 setattr(result, k, v)
158 setattr(result, k, deepcopy(v, memo))
202 raise Exception(
"Can NOT set property basename of JetDefinition ",self,
" Change prefix, infix or suffix instead.")
235 if self.
inputdef.basetype == xAODType.CaloCluster:
244 return f
"JetDefinition({self.fullname()})"
252@onlyAttributesAreProperties
254 """Helper to define the config of a IJetModifier tool.
255 Tools that typically have more complex properties set should have
256 their own dedicated helper 'createfn' functions defined"""
260 filterfn=_condAlwaysPass,
261 prereqs=[],modspec=None,
323 return self.
__hash__() == rhs.__hash__()
326 return (
not self.
__eq__(rhs))
335 """returns a real tool instance accoding to this definition : simply instantiating from
336 class self.tooltype and with name self.toolname ( actually : self.toolname.format(modspec) )
337 Since this function will be called as a callback from JetRecConfig as 'func(jetdef, modspec)', it must accept
338 the jetdef argument, even if unused in this case.
340 from AthenaConfiguration.ComponentFactory
import CompFactory
341 name = self.
toolname.format(modspec=modspec)
342 tool = CompFactory.getComp(self.
tooltype)(name)
351@onlyAttributesAreProperties
353 """This class allows to declare primary data sources to jet finding which are typically outside of jet domain.
354 Such sources can be container of particles (ex: clusters, selection of tracks,...) but also
355 other object needed by some JetModifier (ex: EventDensity or track-vertex association map).
357 The class is mainly here to hold a helper function (algoBuilder) in charge of configuring the proper algorithm to build the source.
358 If this function is None, then we expect the container pre-exists in the evt store.
360 Arguments to the constructor :
361 - name : container name in event store
362 - objtype : the xAODType (ex: xAODType.TruthParticle, xAODType.CaloCluster, ...)
363 - algoBuilder [optional] : a function returning a configured algorithm which build the container
364 the function is called as algoBuilder(parentjetdef, specs) where
365 parentjetdef is the JetDefinition for which this input building is called.
367 If omitted, it is assumed the container pre-exists in the event store.
368 - specs [optional] : a string (or anything) which specifies some options, and passed to the algoBuilder function
369 - filterfn : a function taking a CondFlags as argument and deciding if this JetModifier is compatible
370 with the conditions (same as JetModifier.filterfn )
371 The function must return a tuple : (bool, "reason of failure")
372 - prereqs : a list of prerequisites (str) for this input definition. If any, these str must match the name of other existing JetInputExternal instances.
374 def __init__(self, name, objtype, algoBuilder=None, specs=None, containername=None, filterfn= _condAlwaysPass, prereqs=[]):
378 self.
algoBuilder = algoBuilder
if algoBuilder
is not None else buildNothing
407 outputname = make_alias(
"name")
411 return f
"JetInputExternal({self.name},type={str(self.basetype)})"
423 return hash(self) == hash(other)
426 return (
not self.
__eq__(rhs))
432from enum
import IntEnum, auto
434 """We reproduce the Enum from in xAODJet/​JetContainerInfo.h, xAOD::JetInput : loading the C++ library
435 can slow down a lot the configuration.
436 Note : this is different from the xAODType which describes *only* c++ types whereas JetInputType describes
437 categories of inputs to jets.
449 EMPFlowByVertex=auto()
454 TrackCaloCluster=auto()
455 TruthDressedWZ=auto()
456 EMTopoOriginSK=auto()
457 EMTopoOriginCS=auto()
458 EMTopoOriginVor=auto()
459 EMTopoOriginCSSK=auto()
460 EMTopoOriginVorSK=auto()
461 LCTopoOriginSK=auto()
462 LCTopoOriginCS=auto()
463 LCTopoOriginVor=auto()
464 LCTopoOriginCSSK=auto()
465 LCTopoOriginVorSK=auto()
472 EMTopoOriginTime=auto()
473 EMTopoOriginSKTime=auto()
474 EMTopoOriginCSSKTime=auto()
475 EMTopoOriginVorSKTime=auto()
478 EMPFlowCSSKTime=auto()
479 EMPFlowVorSKTime=auto()
486 """Returns a default JetInputType for a given xAODType """
487 _xaodTojetinputMap = {
488 xAODType.CaloCluster : JetInputType.LCTopo,
489 xAODType.ParticleFlow : JetInputType.EMPFlow,
490 xAODType.FlowElement : JetInputType.EMPFlow,
491 xAODType.TrackParticle : JetInputType.Track,
492 xAODType.TruthParticle : JetInputType.Truth,
493 xAODType.Jet : JetInputType.Jet,
495 return _xaodTojetinputMap.get(xt, JetInputType.Other)
498@onlyAttributesAreProperties
500 """Configuration for simplest constituents (or ghost constituents) to jets.
501 This describes what can be the input to a PseudoJetAlgorithm.
502 The containername attribute must correspond to an existing JetInputExternal so the system knows how to build this
503 source container (if necessary).
515 filterfn=_condAlwaysPass,
528 jetinputtype = jetinputtype
or JetInputType.fromxAODType(objtype)
529 if isinstance(jetinputtype, str):
530 jetinputtype = JetInputType[jetinputtype]
539 return self.
__hash__() == rhs.__hash__()
542 return (
not self.
__eq__(rhs))
563 inputname = make_alias(
"containername")
567 return f
"JetInputConstit({self.name},type={str(self.basetype)})"
574@onlyAttributesAreProperties
576 """Configuration for JetConstituentModSequence.
577 Describes the constituents which need to be build with a JetConstituentModSequence.
578 Uses a list of aliases to JetConstitModifier to describe the modif steps.
589 filterfn=_condAlwaysPass,
594 JetInputConstit.__init__(self,name, objtype, outputname, prereqs=prereqs, jetinputtype=jetinputtype, filterfn=filterfn,label=label,lock=
False, finalinit=
False, byVertex=byVertex)
615 return self.
__hash__() == rhs.__hash__()
618 return (
not self.
__eq__(rhs))
623 return f
"JetInputConstitSeq({self.name}, {self.inputname} , {self.containername})"
630@onlyAttributesAreProperties
632 """Configuration for a constituent modifier tool to be used in a JetConstituentModSequence.
633 See StandardJetConstits.py for usage of this class.
635 the properties argument in __init__ defines directly the properties of the final tool :
636 if the tool has the property "PtMin" then passing 'dict(PtMin=10*GeV)' will result in 'tool.PtMin = 10*GeV'
637 IMPORTANT : If a property is itself an other tool, we can pass a function returning the tool like in 'dict(TheSubTool = mySubToolFunc)'
638 The function will be called only when appropriate in the form 'tool.TheSubTool = mySubToolFunc(constitseq)'
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
__init__(self, name, tooltype, prereqs=[], properties={})
__init__(self, algorithm, radius, inputdef, ptmin=5e3 *MeV, ghostdefs=[], modifiers=[], extrainputs=[], standardRecoMode=False, prefix="", suffix="", infix="", context="default", VRMinR=-1.0, VRMassSc=-1.0, ghostarea=0.01, byVertex=False, lock=False)
__init__(self, name, objtype, algoBuilder=None, specs=None, containername=None, filterfn=_condAlwaysPass, prereqs=[])
getGenericModifier(self, jetdef, modspec)
__init__(self, tooltype, toolname, createfn=None, filterfn=_condAlwaysPass, prereqs=[], modspec=None, **properties)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
_condAlwaysPass(condflags)
buildJetAlgName(finder, mainParam, variableRMassScale=-1.0, variableRMinRadius=-1.0)