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,
96 if algorithm
not in [
"Kt",
"AntiKt",
"CamKt"]:
97 jetlog.error(
"FastJet algorithm specification was not one of Kt, AntiKt, CamKt!")
98 raise KeyError(
"Invalid fastjet algorithm choice: {0}".format(self.
algorithm))
115 self.
ghostdefs = ghostdefs
if ghostdefs
is not None else []
116 self.
modifiers = modifiers
if modifiers
is not None else []
136 return self.
__hash__() == rhs.__hash__()
139 return (
not self.
__eq__(rhs))
153 result = cls.__new__(cls)
154 memo[id(self)] = result
155 set_without_deepcopy = [
'_cflags']
156 for k, v
in self.__dict__.items():
157 if k
in set_without_deepcopy:
160 setattr(result, k, v)
162 setattr(result, k, deepcopy(v, memo))
206 raise Exception(
"Can NOT set property basename of JetDefinition ",self,
" Change prefix, infix or suffix instead.")
239 if self.
inputdef.basetype == xAODType.CaloCluster:
248 return f
"JetDefinition({self.fullname()})"
256@onlyAttributesAreProperties
258 """Helper to define the config of a IJetModifier tool.
259 Tools that typically have more complex properties set should have
260 their own dedicated helper 'createfn' functions defined"""
264 filterfn=_condAlwaysPass,
265 prereqs=None,modspec=None,
293 self.
prereqs = prereqs
if prereqs
is not None else []
327 return self.
__hash__() == rhs.__hash__()
330 return (
not self.
__eq__(rhs))
339 """returns a real tool instance accoding to this definition : simply instantiating from
340 class self.tooltype and with name self.toolname ( actually : self.toolname.format(modspec) )
341 Since this function will be called as a callback from JetRecConfig as 'func(jetdef, modspec)', it must accept
342 the jetdef argument, even if unused in this case.
344 from AthenaConfiguration.ComponentFactory
import CompFactory
345 name = self.
toolname.format(modspec=modspec)
346 tool = CompFactory.getComp(self.
tooltype)(name)
355@onlyAttributesAreProperties
357 """This class allows to declare primary data sources to jet finding which are typically outside of jet domain.
358 Such sources can be container of particles (ex: clusters, selection of tracks,...) but also
359 other object needed by some JetModifier (ex: EventDensity or track-vertex association map).
361 The class is mainly here to hold a helper function (algoBuilder) in charge of configuring the proper algorithm to build the source.
362 If this function is None, then we expect the container pre-exists in the evt store.
364 Arguments to the constructor :
365 - name : container name in event store
366 - objtype : the xAODType (ex: xAODType.TruthParticle, xAODType.CaloCluster, ...)
367 - algoBuilder [optional] : a function returning a configured algorithm which build the container
368 the function is called as algoBuilder(parentjetdef, specs) where
369 parentjetdef is the JetDefinition for which this input building is called.
371 If omitted, it is assumed the container pre-exists in the event store.
372 - specs [optional] : a string (or anything) which specifies some options, and passed to the algoBuilder function
373 - filterfn : a function taking a CondFlags as argument and deciding if this JetModifier is compatible
374 with the conditions (same as JetModifier.filterfn )
375 The function must return a tuple : (bool, "reason of failure")
376 - prereqs : a list of prerequisites (str) for this input definition. If any, these str must match the name of other existing JetInputExternal instances.
378 def __init__(self, name, objtype, algoBuilder=None, specs=None, containername=None, filterfn= _condAlwaysPass, prereqs=None):
382 self.
algoBuilder = algoBuilder
if algoBuilder
is not None else buildNothing
395 self.
prereqs = prereqs
if prereqs
is not None else []
411 outputname = make_alias(
"name")
415 return f
"JetInputExternal({self.name},type={str(self.basetype)})"
427 return hash(self) == hash(other)
430 return (
not self.
__eq__(rhs))
436from enum
import IntEnum, auto
438 """We reproduce the Enum from in xAODJet/​JetContainerInfo.h, xAOD::JetInput : loading the C++ library
439 can slow down a lot the configuration.
440 Note : this is different from the xAODType which describes *only* c++ types whereas JetInputType describes
441 categories of inputs to jets.
453 EMPFlowByVertex=auto()
458 TrackCaloCluster=auto()
459 TruthDressedWZ=auto()
460 EMTopoOriginSK=auto()
461 EMTopoOriginCS=auto()
462 EMTopoOriginVor=auto()
463 EMTopoOriginCSSK=auto()
464 EMTopoOriginVorSK=auto()
465 LCTopoOriginSK=auto()
466 LCTopoOriginCS=auto()
467 LCTopoOriginVor=auto()
468 LCTopoOriginCSSK=auto()
469 LCTopoOriginVorSK=auto()
476 EMTopoOriginTime=auto()
477 EMTopoOriginSKTime=auto()
478 EMTopoOriginCSSKTime=auto()
479 EMTopoOriginVorSKTime=auto()
482 EMPFlowCSSKTime=auto()
483 EMPFlowVorSKTime=auto()
490 """Returns a default JetInputType for a given xAODType """
491 _xaodTojetinputMap = {
492 xAODType.CaloCluster : JetInputType.LCTopo,
493 xAODType.ParticleFlow : JetInputType.EMPFlow,
494 xAODType.FlowElement : JetInputType.EMPFlow,
495 xAODType.TrackParticle : JetInputType.Track,
496 xAODType.TruthParticle : JetInputType.Truth,
497 xAODType.Jet : JetInputType.Jet,
499 return _xaodTojetinputMap.get(xt, JetInputType.Other)
502@onlyAttributesAreProperties
504 """Configuration for simplest constituents (or ghost constituents) to jets.
505 This describes what can be the input to a PseudoJetAlgorithm.
506 The containername attribute must correspond to an existing JetInputExternal so the system knows how to build this
507 source container (if necessary).
519 filterfn=_condAlwaysPass,
526 self.
prereqs = prereqs
if prereqs
is not None else []
532 jetinputtype = jetinputtype
or JetInputType.fromxAODType(objtype)
533 if isinstance(jetinputtype, str):
534 jetinputtype = JetInputType[jetinputtype]
543 return self.
__hash__() == rhs.__hash__()
546 return (
not self.
__eq__(rhs))
567 inputname = make_alias(
"containername")
571 return f
"JetInputConstit({self.name},type={str(self.basetype)})"
578@onlyAttributesAreProperties
580 """Configuration for JetConstituentModSequence.
581 Describes the constituents which need to be build with a JetConstituentModSequence.
582 Uses a list of aliases to JetConstitModifier to describe the modif steps.
593 filterfn=_condAlwaysPass,
598 _prereqs = prereqs
if prereqs
is not None else []
599 JetInputConstit.__init__(self,name, objtype, outputname, prereqs=_prereqs, jetinputtype=jetinputtype, filterfn=filterfn,label=label,lock=
False, finalinit=
False, byVertex=byVertex)
601 self.
modifiers = modifiers
if modifiers
is not None else []
620 return self.
__hash__() == rhs.__hash__()
623 return (
not self.
__eq__(rhs))
628 return f
"JetInputConstitSeq({self.name}, {self.inputname} , {self.containername})"
635@onlyAttributesAreProperties
637 """Configuration for a constituent modifier tool to be used in a JetConstituentModSequence.
638 See StandardJetConstits.py for usage of this class.
640 the properties argument in __init__ defines directly the properties of the final tool :
641 if the tool has the property "PtMin" then passing 'dict(PtMin=10*GeV)' will result in 'tool.PtMin = 10*GeV'
642 IMPORTANT : If a property is itself an other tool, we can pass a function returning the tool like in 'dict(TheSubTool = mySubToolFunc)'
643 The function will be called only when appropriate in the form 'tool.TheSubTool = mySubToolFunc(constitseq)'
653 self.
properties = properties
if properties
is not None else {}
654 self.
prereqs = prereqs
if prereqs
is not None else []
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
__init__(self, name, tooltype, prereqs=None, properties=None)
__init__(self, algorithm, radius, inputdef, ptmin=5e3 *MeV, ghostdefs=None, modifiers=None, extrainputs=None, 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=None)
__init__(self, tooltype, toolname, createfn=None, filterfn=_condAlwaysPass, prereqs=None, modspec=None, **properties)
getGenericModifier(self, jetdef, modspec)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
buildJetAlgName(finder, mainParam, variableRMassScale=-1.0, variableRMinRadius=-1.0)
_condAlwaysPass(condflags)