ATLAS Offline Software
Loading...
Searching...
No Matches
python.EventSelectionConfig.EventSelectionConfig Class Reference
Inheritance diagram for python.EventSelectionConfig.EventSelectionConfig:
Collaboration diagram for python.EventSelectionConfig.EventSelectionConfig:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeAlgs (self, config)
 interpret (self, text, cfg)
 raise_misconfig (self, text, keyword)
 raise_missinginput (self, collection)
 check_float (self, test, requirePositive=True)
 check_int (self, test, requirePositive=True)
 check_string (self, test)
 check_sign (self, test)
 check_btagging (self, test)
 check_ghosts (self, test)
 getCutflow (self)
 setDecorationName (self, algorithm, config, decoration)
 checkDecorationName (self, decoration)
 extendObjectSelection (self, config, container, oldSelection, newSelection)
 add_IMPORT (self, text, config)
 add_NBJET_selector (self, text, config)
 add_SUMNELNMU_selector (self, text, config)
 add_SUMNLEPTONS_selector (self, text, config)
 add_NLJETMASS_selector (self, text, config)
 add_NLJETMASSWINDOW_selector (self, text, config)
 add_NJETGHOST_selector (self, text, config)
 add_NLJETGHOST_selector (self, text, config)
 add_NOBJ_selector (self, text, config)
 add_MET_selector (self, text, config)
 add_MWT_selector (self, text, config)
 add_METMWT_selector (self, text, config)
 add_MLL_selector (self, text, config)
 add_MLLWINDOW_selector (self, text, config)
 add_MLL_OSSF_selector (self, text, config)
 add_EVENTFLAG (self, text, config)
 add_GLOBALTRIGMATCH (self, text, config)
 add_RUNNUMBER (self, text, config)
 add_EXPR_selector (self, text, config)
 add_EVENTVAR_selector (self, text, config)
 add_SAVE (self, text, config)

Public Attributes

int step = 0
str currentDecoration = ''
list cutflow = []
 selectionName
 debugMode
 jets
 muons
 electrons
 taus
 met
 btagDecoration

Protected Member Functions

 _build_dispatch (self)
 _check_args (self, items, keyword, validCounts)
 _maybe_dressed (self, alg, *specs)
 _val_sign_count (self, items, config, alg, container)
 _route_lepton (self, alg, config, spec, reco, truth)
 _add_nobject (self, text, config, *, attr, tag)
 _add_charge (self, text, config, *, osMode, tag)
 _expr_tokenize (self, text)
 _expr_peek (self)
 _expr_advance (self)
 _expr_expect (self, kind)
 _expr_parse (self, tokens)
 _expr_parse_funcall (self)
 _expr_parse_operand (self)
 _expr_parse_sign (self)
 _expr_parse_value (self)
 _expr_validate (self, variable, separator, operands)
 _emit_save (self, config)

Protected Attributes

 _dispatch = self._build_dispatch()
 _exprTokens = tokens
int _exprPos = 0

Static Protected Attributes

dict _NOBJECT
dict _EXPR_COLL
dict _EXPR_VARS
 _EXPR_TOKEN_RE = re.compile(, re.VERBOSE)
dict _EVENTVAR_TYPES = {"float": "floatVariable", "int": "intVariable", "double": "doubleVariable"}

Detailed Description

ConfigBlock for interpreting text-based event selections

Definition at line 59 of file EventSelectionConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.EventSelectionConfig.EventSelectionConfig.__init__ ( self)

Definition at line 73 of file EventSelectionConfig.py.

73 def __init__(self):
74 super(EventSelectionConfig, self).__init__()
75 self.setBlockName('EventSelection')
76 self.addOption('selectionName', '', type=str,
77 noneAction='error',
78 info="the name of the event selection, used to uniquely identify "
79 "the `EventSelectionConfig` block.")
80 self.addOption('electrons', "", type=str,
81 info="the input electron container, with a possible selection, in "
82 "the format `container` or `container.selection`.")
83 self.addOption('muons', "", type=str,
84 info="the input muon container, with a possible selection, in the "
85 "format `container` or `container.selection`.")
86 self.addOption('jets', "", type=str,
87 info="the input jet container, with a possible selection, in the "
88 "format `container` or `container.selection`.")
89 self.addOption('largeRjets', "", type=str,
90 info="the large-R jet container, with a possible selection, in "
91 "the format `container` or `container.selection`.")
92 self.addOption('photons', "", type=str,
93 info="the input photon container, with a possible selection, in "
94 "the format `container` or `container.selection`.")
95 self.addOption('taus', "", type=str,
96 info="the input tau-jet container, with a possible selection, in "
97 "the format `container` or `container.selection`.")
98 self.addOption('met', "", type=str,
99 info="the input MET container.")
100 self.addOption('metTerm', "Final", type=str,
101 info="the MET term to use when computing MET-based quantities.")
102 self.addOption('btagDecoration', "", type=str,
103 info="the b-tagging decoration to use when defining b-jets.")
104 self.addOption('preselection', "", type=str,
105 info="the event-wise selection flag to start this event selection "
106 "from.")
107 self.addOption('selectionCuts', "", type=str,
108 noneAction='error',
109 info="a single string listing one selection cut per line. "
110 "See [available keywords](https://topcptoolkit.docs.cern.ch/latest/settings/eventselection/#available-keywords).")
111 self.addOption('debugMode', False, type=bool,
112 info="whether to create an output branch for every single line "
113 "of the selection cuts. Setting it to `False` only saves the"
114 " final decision.")
115 self.addOption('useDressedProperties', True, type=bool,
116 info="whether to use dressed truth electron and truth muon "
117 "kinematics rather than simple 4-vector kinematics.")
118 self.step = 0
119 self.currentDecoration = ''
120 self.cutflow = []
121 self._dispatch = self._build_dispatch()
122

Member Function Documentation

◆ _add_charge()

python.EventSelectionConfig.EventSelectionConfig._add_charge ( self,
text,
config,
* ,
osMode,
tag )
protected
Builder shared by OS and SS: same algorithm, opposite charge mode.

Definition at line 669 of file EventSelectionConfig.py.

669 def _add_charge(self, text, config, *, osMode, tag):
670 """Builder shared by OS and SS: same algorithm, opposite charge mode."""
671 items = text.split()
672 if not items or len(items) > 4:
673 self.raise_misconfig(text, "number of arguments")
674 if not self.electrons and not self.muons and not self.taus:
675 self.raise_missinginput("electrons or muons or taus")
676 thisalg = f'{self.selectionName}_{tag}_{self.step}'
677 alg = config.createAlgorithm('CP::ChargeSelectorAlg', thisalg)
678 allLeptons = (len(items) == 1)
679 if self.electrons and (allLeptons or "el" in items):
680 self._route_lepton(alg, config, self.electrons,
681 ('electrons', 'electronSelection'),
682 ('truthElectrons', 'truthElectronSelection'))
683 if self.muons and (allLeptons or "mu" in items):
684 self._route_lepton(alg, config, self.muons,
685 ('muons', 'muonSelection'),
686 ('truthMuons', 'truthMuonSelection'))
687 if self.taus and (allLeptons or "tau" in items):
688 self._route_lepton(alg, config, self.taus,
689 ('taus', 'tauSelection'),
690 ('truthTaus', 'truthTauSelection'))
691 alg.OS = osMode
692 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
693 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
694 return
695

◆ _add_nobject()

python.EventSelectionConfig.EventSelectionConfig._add_nobject ( self,
text,
config,
* ,
attr,
tag )
protected
Generic builder for the N-object pT selectors (EL_N, MU_N, JET_N,
PH_N, TAU_N, LJET_N): identical except for the source container, which
is always required since the cut acts on it.

Definition at line 346 of file EventSelectionConfig.py.

346 def _add_nobject(self, text, config, *, attr, tag):
347 """Generic builder for the N-object pT selectors (EL_N, MU_N, JET_N,
348 PH_N, TAU_N, LJET_N): identical except for the source container, which
349 is always required since the cut acts on it."""
350 items = text.split()
351 spec = getattr(self, attr)
352 if not spec:
353 self.raise_missinginput(attr)
354 if len(items) not in (4, 5):
355 self.raise_misconfig(text, "number of arguments")
356 thisalg = f'{self.selectionName}_{tag}_{self.step}'
357 alg = config.createAlgorithm('CP::NObjectPtSelectorAlg', thisalg)
358 alg.particles, alg.objectSelection = config.readNameAndSelection(spec)
359 if attr in ("electrons", "muons"):
360 self._maybe_dressed(alg, spec)
361 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
362 alg.minPt, alg.sign, alg.count = self._val_sign_count(
363 items, config, alg, spec.split(".")[0])
364 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
365

◆ _build_dispatch()

python.EventSelectionConfig.EventSelectionConfig._build_dispatch ( self)
protected
Map each keyword to its handler. Dispatch is an exact lookup on the
first token, which removes the ordering fragility of token-membership.

Definition at line 127 of file EventSelectionConfig.py.

127 def _build_dispatch(self):
128 """Map each keyword to its handler. Dispatch is an exact lookup on the
129 first token, which removes the ordering fragility of token-membership."""
130 d = {
131 "JET_N_BTAG": self.add_NBJET_selector,
132 "JET_N_GHOST": self.add_NJETGHOST_selector,
133 "LJET_N_GHOST": self.add_NLJETGHOST_selector,
134 "LJETMASS_N": self.add_NLJETMASS_selector,
135 "LJETMASSWINDOW_N": self.add_NLJETMASSWINDOW_selector,
136 "OBJ_N": self.add_NOBJ_selector,
137 "SUM_EL_N_MU_N": self.add_SUMNELNMU_selector,
138 "SUM_EL_N_MU_N_TAU_N": self.add_SUMNLEPTONS_selector,
139 "MET": self.add_MET_selector,
140 "MWT": self.add_MWT_selector,
141 "MET+MWT": self.add_METMWT_selector,
142 "MLL": self.add_MLL_selector,
143 "MLLWINDOW": self.add_MLLWINDOW_selector,
144 "MLL_OSSF": self.add_MLL_OSSF_selector,
145 "OS": partial(self._add_charge, osMode=True, tag="OS"),
146 "SS": partial(self._add_charge, osMode=False, tag="SS"),
147 "SAVE": self.add_SAVE,
148 "IMPORT": self.add_IMPORT,
149 "EVENTFLAG": self.add_EVENTFLAG,
150 "GLOBALTRIGMATCH": self.add_GLOBALTRIGMATCH,
151 "RUN_NUMBER": self.add_RUNNUMBER,
152 "EXPR": self.add_EXPR_selector,
153 "EVENTVAR": self.add_EVENTVAR_selector,
154 }
155 for kw, (attr, tag) in self._NOBJECT.items():
156 d[kw] = partial(self._add_nobject, attr=attr, tag=tag)
157 return d
158

◆ _check_args()

python.EventSelectionConfig.EventSelectionConfig._check_args ( self,
items,
keyword,
validCounts )
protected
Validate the leading keyword and the number of arguments.

Definition at line 202 of file EventSelectionConfig.py.

202 def _check_args(self, items, keyword, validCounts):
203 """Validate the leading keyword and the number of arguments."""
204 if items[0] != keyword:
205 self.raise_misconfig(' '.join(items), keyword)
206 if len(items) not in validCounts:
207 self.raise_misconfig(' '.join(items), "number of arguments")
208

◆ _emit_save()

python.EventSelectionConfig.EventSelectionConfig._emit_save ( self,
config )
protected
Create the SaveFilterAlg that turns the accumulated event selection
into a named, persisted selection (and ntuple branch). Called once per
block, automatically at the end of makeAlgs.

Definition at line 983 of file EventSelectionConfig.py.

983 def _emit_save(self, config):
984 """Create the SaveFilterAlg that turns the accumulated event selection
985 into a named, persisted selection (and ntuple branch). Called once per
986 block, automatically at the end of makeAlgs."""
987 thisalg = f'{self.selectionName}_SAVE'
988 alg = config.createAlgorithm('CP::SaveFilterAlg', thisalg)
989 alg.FilterDescription = f'events passing < {self.selectionName} >'
990 alg.eventDecisionOutputDecoration = f'ignore_{self.selectionName}_%SYS%'
991 alg.selection = self.checkDecorationName(self.currentDecoration)
992 alg.noFilter = True
993 alg.selectionName = f'pass_{self.selectionName}_%SYS%,as_char' # this one is used as a selection
994 alg.decorationName = f'ntuplepass_{self.selectionName}_%SYS%' # this one is saved to file
995 config.addOutputVar('EventInfo', f'ntuplepass_{self.selectionName}_%SYS%', f'pass_{self.selectionName}')
996 return
997
998
999@groupBlocks

◆ _expr_advance()

python.EventSelectionConfig.EventSelectionConfig._expr_advance ( self)
protected

Definition at line 803 of file EventSelectionConfig.py.

803 def _expr_advance(self):
804 tok = self._exprTokens[self._exprPos]
805 self._exprPos += 1
806 return tok
807

◆ _expr_expect()

python.EventSelectionConfig.EventSelectionConfig._expr_expect ( self,
kind )
protected

Definition at line 808 of file EventSelectionConfig.py.

808 def _expr_expect(self, kind):
809 tok = self._expr_advance()
810 if tok[0] != kind:
811 raise InconsistentSettingsError(
812 f"[EventSelectionConfig] EXPR: expected {kind}, got '{tok[1]}'")
813 return tok
814

◆ _expr_parse()

python.EventSelectionConfig.EventSelectionConfig._expr_parse ( self,
tokens )
protected

Definition at line 815 of file EventSelectionConfig.py.

815 def _expr_parse(self, tokens):
816 self._exprTokens = tokens
817 self._exprPos = 0
818 variable, separator, operands = self._expr_parse_funcall()
819 sign = self._expr_parse_sign()
820 refValue = self._expr_parse_value()
821 self._expr_expect("END")
822 return variable, separator, operands, sign, refValue
823

◆ _expr_parse_funcall()

python.EventSelectionConfig.EventSelectionConfig._expr_parse_funcall ( self)
protected

Definition at line 824 of file EventSelectionConfig.py.

824 def _expr_parse_funcall(self):
825 variable = self._expr_expect("ID")[1]
826 self._expr_expect("LP")
827 operands = [self._expr_parse_operand()]
828 separator = None
829 while self._expr_peek()[0] in ("COMMA", "PLUS"):
830 sep = "," if self._expr_advance()[0] == "COMMA" else "+"
831 if separator is None:
832 separator = sep
833 elif sep != separator:
834 raise InconsistentSettingsError(
835 "[EventSelectionConfig] EXPR: cannot mix ',' and '+' separators")
836 operands.append(self._expr_parse_operand())
837 self._expr_expect("RP")
838 return variable, separator, operands
839

◆ _expr_parse_operand()

python.EventSelectionConfig.EventSelectionConfig._expr_parse_operand ( self)
protected

Definition at line 840 of file EventSelectionConfig.py.

840 def _expr_parse_operand(self):
841 coll = self._expr_expect("ID")[1]
842 index = None
843 if self._expr_peek()[0] == "LB":
844 self._expr_advance()
845 index = int(self._expr_expect("NUM")[1])
846 self._expr_expect("RB")
847 return (coll, index)
848

◆ _expr_parse_sign()

python.EventSelectionConfig.EventSelectionConfig._expr_parse_sign ( self)
protected

Definition at line 849 of file EventSelectionConfig.py.

849 def _expr_parse_sign(self):
850 tok = self._expr_advance()
851 if tok[0] not in ("LT", "GT", "EQ", "GE", "LE"):
852 raise InconsistentSettingsError(
853 f"[EventSelectionConfig] EXPR: expected a comparison operator, got '{tok[1]}'")
854 return tok[0]
855

◆ _expr_parse_value()

python.EventSelectionConfig.EventSelectionConfig._expr_parse_value ( self)
protected

Definition at line 856 of file EventSelectionConfig.py.

856 def _expr_parse_value(self):
857 negative = False
858 if self._expr_peek()[0] == "MINUS":
859 self._expr_advance()
860 negative = True
861 value = float(self._expr_expect("NUM")[1])
862 return -value if negative else value
863

◆ _expr_peek()

python.EventSelectionConfig.EventSelectionConfig._expr_peek ( self)
protected

Definition at line 800 of file EventSelectionConfig.py.

800 def _expr_peek(self):
801 return self._exprTokens[self._exprPos]
802

◆ _expr_tokenize()

python.EventSelectionConfig.EventSelectionConfig._expr_tokenize ( self,
text )
protected

Definition at line 786 of file EventSelectionConfig.py.

786 def _expr_tokenize(self, text):
787 tokens, pos = [], 0
788 while pos < len(text):
789 m = self._EXPR_TOKEN_RE.match(text, pos)
790 if not m:
791 raise InconsistentSettingsError(
792 f"[EventSelectionConfig] EXPR: cannot parse near '{text[pos:]}'")
793 pos = m.end()
794 if m.lastgroup != "WS":
795 tokens.append((m.lastgroup, m.group()))
796 tokens.append(("END", ""))
797 return tokens
798
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359

◆ _expr_validate()

python.EventSelectionConfig.EventSelectionConfig._expr_validate ( self,
variable,
separator,
operands )
protected

Definition at line 864 of file EventSelectionConfig.py.

864 def _expr_validate(self, variable, separator, operands):
865 if variable not in self._EXPR_VARS:
866 raise UnavailableFeatureError(
867 f"[EventSelectionConfig] EXPR: variable '{variable}' is not available. "
868 "Please request it from the EventSelectionAlgorithms developers.")
869 minN, maxN, sep, _needsEta, metOk = self._EXPR_VARS[variable]
870 n = len(operands)
871 if n < minN or (maxN is not None and n > maxN):
872 expected = f"{minN}" if maxN == minN else (f"{minN}+" if maxN is None else f"{minN}-{maxN}")
873 raise InconsistentSettingsError(
874 f"[EventSelectionConfig] EXPR: '{variable}' takes {expected} operand(s), got {n}")
875 if n > 1 and separator != sep:
876 want = {",": "','", "+": "'+'"}.get(sep, str(sep))
877 raise InconsistentSettingsError(
878 f"[EventSelectionConfig] EXPR: '{variable}' operands must be separated by {want}")
879 for coll, index in operands:
880 if coll not in self._EXPR_COLL:
881 raise UnavailableFeatureError(
882 f"[EventSelectionConfig] EXPR: collection '{coll}' is not available. "
883 "Please request it from the EventSelectionAlgorithms developers.")
884 _opt, _btag, isMET = self._EXPR_COLL[coll]
885 if isMET:
886 if not metOk:
887 raise InconsistentSettingsError(
888 f"[EventSelectionConfig] EXPR: 'met' is not valid for '{variable}'")
889 if index is not None:
890 raise InconsistentSettingsError(
891 "[EventSelectionConfig] EXPR: 'met' cannot be indexed")
892 if separator == "+":
893 raise InconsistentSettingsError(
894 "[EventSelectionConfig] EXPR: 'met' cannot be combined in a sum")
895 elif index is None:
896 raise InconsistentSettingsError(
897 f"[EventSelectionConfig] EXPR: '{coll}' must be indexed, e.g. {coll}[0]")
898
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132

◆ _maybe_dressed()

python.EventSelectionConfig.EventSelectionConfig._maybe_dressed ( self,
alg,
* specs )
protected
Enable dressed kinematics when any of the given electron/muon
containers is a truth container. Dressed kinematics only exist for
truth electrons and muons, so only those specs should be passed here.

Definition at line 311 of file EventSelectionConfig.py.

311 def _maybe_dressed(self, alg, *specs):
312 """Enable dressed kinematics when any of the given electron/muon
313 containers is a truth container. Dressed kinematics only exist for
314 truth electrons and muons, so only those specs should be passed here."""
315 if any(spec and ("Particle" in spec or "Truth" in spec) for spec in specs):
316 alg.useDressedProperties = self.useDressedProperties
317

◆ _route_lepton()

python.EventSelectionConfig.EventSelectionConfig._route_lepton ( self,
alg,
config,
spec,
reco,
truth )
protected
Assign (name, selection) to the reco or truth handles of `alg`
depending on whether `spec` points to a truth container.
`reco`/`truth` are (nameAttr, selectionAttr) pairs.

Definition at line 333 of file EventSelectionConfig.py.

333 def _route_lepton(self, alg, config, spec, reco, truth):
334 """Assign (name, selection) to the reco or truth handles of `alg`
335 depending on whether `spec` points to a truth container.
336 `reco`/`truth` are (nameAttr, selectionAttr) pairs."""
337 name, sel = config.readNameAndSelection(spec)
338 nameAttr, selAttr = truth if ("Particle" in spec or "Truth" in spec) else reco
339 setattr(alg, nameAttr, name)
340 setattr(alg, selAttr, sel)
341

◆ _val_sign_count()

python.EventSelectionConfig.EventSelectionConfig._val_sign_count ( self,
items,
config,
alg,
container )
protected
Parse the trailing `[extraSel] value sign count` grammar (4 or 5
tokens), applying the optional extra object selection in place.
Returns (value, sign, count).

Definition at line 318 of file EventSelectionConfig.py.

318 def _val_sign_count(self, items, config, alg, container):
319 """Parse the trailing `[extraSel] value sign count` grammar (4 or 5
320 tokens), applying the optional extra object selection in place.
321 Returns (value, sign, count)."""
322 if len(items) == 5:
323 extraSel = self.check_string(items[1])
324 alg.objectSelection = self.extendObjectSelection(
325 config, container, alg.objectSelection, extraSel)
326 i = 2
327 else: # len == 4, already validated by the caller
328 i = 1
329 return (self.check_float(items[i]),
330 self.check_sign(items[i + 1]),
331 self.check_int(items[i + 2]))
332

◆ add_EVENTFLAG()

python.EventSelectionConfig.EventSelectionConfig.add_EVENTFLAG ( self,
text,
config )

Definition at line 719 of file EventSelectionConfig.py.

719 def add_EVENTFLAG(self, text, config):
720 items = text.split()
721 self._check_args(items, "EVENTFLAG", (2,))
722 existingDecoration = self.check_string(items[1])
723 self.setDecorationName(None, config, existingDecoration)
724 return
725

◆ add_EVENTVAR_selector()

python.EventSelectionConfig.EventSelectionConfig.add_EVENTVAR_selector ( self,
text,
config )

Definition at line 952 of file EventSelectionConfig.py.

952 def add_EVENTVAR_selector(self, text, config):
953 # EVENTVAR <type> <varname> <sign> <threshold>
954 items = text.split()
955 self._check_args(items, "EVENTVAR", (5,))
956 valueType = self.check_string(items[1])
957 if valueType not in self._EVENTVAR_TYPES:
958 self.raise_misconfig(text, f"value type (one of {sorted(self._EVENTVAR_TYPES)})")
959 varname = self.check_string(items[2])
960 thisalg = f'{self.selectionName}_EVENTVAR_{self.step}'
961 alg = config.createAlgorithm('CP::EventScalarSelectorAlg', thisalg)
962 # the variable name is given bare; the systematics suffix is appended here
963 setattr(alg, self._EVENTVAR_TYPES[valueType], f'{varname}_%SYS%')
964 alg.sign = self.check_sign(items[3])
965 alg.refValue = self.check_float(items[4], requirePositive=False) # discriminants may be negative
966 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
967 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
968 return
969

◆ add_EXPR_selector()

python.EventSelectionConfig.EventSelectionConfig.add_EXPR_selector ( self,
text,
config )

Definition at line 899 of file EventSelectionConfig.py.

899 def add_EXPR_selector(self, text, config):
900 body = text[len("EXPR"):].strip()
901 if not body:
902 self.raise_misconfig(text, "EXPR expression")
903 variable, separator, operands, sign, refValue = self._expr_parse(self._expr_tokenize(body))
904 self._expr_validate(variable, separator, operands)
905
906 thisalg = f'{self.selectionName}_EXPR_{self.step}'
907 alg = config.createAlgorithm('CP::ObjectKinematicSelectorAlg', thisalg)
908 alg.variable = variable
909 alg.sign = sign
910 alg.refValue = refValue
911
912 operandKinds, collections, selections, indices = [], [], [], []
913 usesMET = False
914 for coll, index in operands:
915 opt, applyBtag, isMET = self._EXPR_COLL[coll]
916 container = getattr(self, opt)
917 if not container:
918 self.raise_missinginput(opt)
919 if isMET:
920 operandKinds.append("MET")
921 usesMET = True
922 continue
923 operandKinds.append("PARTICLE")
924 name, selection = config.readNameAndSelection(container)
925 if applyBtag:
926 if not self.btagDecoration:
927 self.raise_missinginput("btagDecoration")
928 selection = (f'{selection}&&{self.btagDecoration},as_char'
929 if selection else f'{self.btagDecoration},as_char')
930 collections.append(name)
931 selections.append(selection)
932 indices.append(index)
933
934 alg.operandKinds = operandKinds
935 alg.collections = collections
936 alg.selections = selections
937 alg.indices = indices
938 if usesMET:
939 if not self.met:
940 self.raise_missinginput("met")
941 alg.met = config.readName(self.met)
942 alg.metTerm = self.metTerm
943 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
944 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
945 return
946

◆ add_GLOBALTRIGMATCH()

python.EventSelectionConfig.EventSelectionConfig.add_GLOBALTRIGMATCH ( self,
text,
config )

Definition at line 726 of file EventSelectionConfig.py.

726 def add_GLOBALTRIGMATCH(self, text, config):
727 items = text.split()
728 self._check_args(items, "GLOBALTRIGMATCH", (1, 2))
729 if len(items) == 1:
730 self.setDecorationName(None, config, "globalTriggerMatch_%SYS%,as_char")
731 else:
732 postfix = self.check_string(items[1])
733 self.setDecorationName(None, config, f"globalTriggerMatch{postfix}_%SYS%,as_char")
734 return
735

◆ add_IMPORT()

python.EventSelectionConfig.EventSelectionConfig.add_IMPORT ( self,
text,
config )

Definition at line 366 of file EventSelectionConfig.py.

366 def add_IMPORT(self, text, config):
367 # this is used to import a previous selection
368 items = text.split()
369 self._check_args(items, "IMPORT", (2,))
370 region = self.check_string(items[1])
371 if not self.currentDecoration:
372 self.currentDecoration = f'pass_{region}_%SYS%,as_char'
373 else:
374 self.currentDecoration = f'{self.currentDecoration},as_char&&pass_{region}_%SYS%'
375 # for the cutflow, we need to retrieve all the cuts corresponding to this IMPORT
376 imported_cuts = [cut for cut in config.getSelectionCutFlow('EventInfo', '') if cut.startswith(region)]
377 self.cutflow += imported_cuts
378 return
379

◆ add_MET_selector()

python.EventSelectionConfig.EventSelectionConfig.add_MET_selector ( self,
text,
config )

Definition at line 579 of file EventSelectionConfig.py.

579 def add_MET_selector(self, text, config):
580 items = text.split()
581 self._check_args(items, "MET", (3,))
582 if not self.met:
583 self.raise_missinginput("MET")
584 thisalg = f'{self.selectionName}_MET_{self.step}'
585 alg = config.createAlgorithm('CP::MissingETSelectorAlg', thisalg)
586 alg.met = config.readName(self.met)
587 alg.metTerm = self.metTerm
588 alg.sign = self.check_sign(items[1])
589 alg.refMET = self.check_float(items[2])
590 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
591 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
592 return
593

◆ add_METMWT_selector()

python.EventSelectionConfig.EventSelectionConfig.add_METMWT_selector ( self,
text,
config )

Definition at line 612 of file EventSelectionConfig.py.

612 def add_METMWT_selector(self, text, config):
613 items = text.split()
614 self._check_args(items, "MET+MWT", (3,))
615 if not self.met:
616 self.raise_missinginput("MET")
617 if not self.electrons and not self.muons:
618 self.raise_missinginput("electrons or muons")
619 thisalg = f'{self.selectionName}_METMWT_{self.step}'
620 alg = config.createAlgorithm('CP::MissingETPlusTransverseMassSelectorAlg', thisalg)
621 alg.met = config.readName(self.met)
622 alg.metTerm = self.metTerm
623 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
624 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
625 self._maybe_dressed(alg, self.electrons, self.muons)
626 alg.sign = self.check_sign(items[1])
627 alg.refMETMWT = self.check_float(items[2])
628 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
629 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
630 return
631

◆ add_MLL_OSSF_selector()

python.EventSelectionConfig.EventSelectionConfig.add_MLL_OSSF_selector ( self,
text,
config )

Definition at line 696 of file EventSelectionConfig.py.

696 def add_MLL_OSSF_selector(self, text, config):
697 items = text.split()
698 self._check_args(items, "MLL_OSSF", (3, 4))
699 if not self.electrons and not self.muons:
700 self.raise_missinginput("electrons or muons")
701 thisalg = f'{self.selectionName}_MLL_OSSF_{self.step}'
702 alg = config.createAlgorithm('CP::DileptonOSSFInvariantMassWindowSelectorAlg', thisalg)
703 if self.electrons:
704 self._route_lepton(alg, config, self.electrons,
705 ('electrons', 'electronSelection'),
706 ('truthElectrons', 'truthElectronSelection'))
707 if self.muons:
708 self._route_lepton(alg, config, self.muons,
709 ('muons', 'muonSelection'),
710 ('truthMuons', 'truthMuonSelection'))
711 self._maybe_dressed(alg, self.electrons, self.muons)
712 alg.lowMll = self.check_float(items[1])
713 alg.highMll = self.check_float(items[2])
714 alg.vetoMode = (len(items) == 4 and self.check_string(items[3]).lower() == "veto")
715 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
716 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
717 return
718

◆ add_MLL_selector()

python.EventSelectionConfig.EventSelectionConfig.add_MLL_selector ( self,
text,
config )

Definition at line 632 of file EventSelectionConfig.py.

632 def add_MLL_selector(self, text, config):
633 items = text.split()
634 self._check_args(items, "MLL", (3,))
635 if not self.electrons and not self.muons:
636 self.raise_missinginput("electrons or muons")
637 thisalg = f'{self.selectionName}_MLL_{self.step}'
638 alg = config.createAlgorithm('CP::DileptonInvariantMassSelectorAlg', thisalg)
639 if self.electrons:
640 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
641 if self.muons:
642 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
643 self._maybe_dressed(alg, self.electrons, self.muons)
644 alg.sign = self.check_sign(items[1])
645 alg.refMLL = self.check_float(items[2])
646 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
647 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
648 return
649

◆ add_MLLWINDOW_selector()

python.EventSelectionConfig.EventSelectionConfig.add_MLLWINDOW_selector ( self,
text,
config )

Definition at line 650 of file EventSelectionConfig.py.

650 def add_MLLWINDOW_selector(self, text, config):
651 items = text.split()
652 self._check_args(items, "MLLWINDOW", (3, 4))
653 if not self.electrons and not self.muons:
654 self.raise_missinginput("electrons or muons")
655 thisalg = f'{self.selectionName}_MLLWINDOW_{self.step}'
656 alg = config.createAlgorithm('CP::DileptonInvariantMassWindowSelectorAlg', thisalg)
657 if self.electrons:
658 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
659 if self.muons:
660 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
661 self._maybe_dressed(alg, self.electrons, self.muons)
662 alg.lowMLL = self.check_float(items[1])
663 alg.highMLL = self.check_float(items[2])
664 alg.vetoMode = (len(items) == 4 and self.check_string(items[3]).lower() == "veto")
665 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
666 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
667 return
668

◆ add_MWT_selector()

python.EventSelectionConfig.EventSelectionConfig.add_MWT_selector ( self,
text,
config )

Definition at line 594 of file EventSelectionConfig.py.

594 def add_MWT_selector(self, text, config):
595 items = text.split()
596 self._check_args(items, "MWT", (3,))
597 if not self.electrons and not self.muons:
598 self.raise_missinginput("electrons or muons")
599 thisalg = f'{self.selectionName}_MWT_{self.step}'
600 alg = config.createAlgorithm('CP::TransverseMassSelectorAlg', thisalg)
601 alg.met = config.readName(self.met)
602 alg.metTerm = self.metTerm
603 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
604 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
605 self._maybe_dressed(alg, self.electrons, self.muons)
606 alg.sign = self.check_sign(items[1])
607 alg.refMWT = self.check_float(items[2])
608 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
609 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
610 return
611

◆ add_NBJET_selector()

python.EventSelectionConfig.EventSelectionConfig.add_NBJET_selector ( self,
text,
config )

Definition at line 380 of file EventSelectionConfig.py.

380 def add_NBJET_selector(self, text, config):
381 items = text.split()
382 self._check_args(items, "JET_N_BTAG", (3, 4, 5))
383 if not self.jets:
384 self.raise_missinginput("jets")
385 thisalg = f'{self.selectionName}_NBJET_{self.step}'
386 alg = config.createAlgorithm('CP::NObjectPtSelectorAlg', thisalg)
387 particles, selection = config.readNameAndSelection(self.jets)
388 alg.particles = particles
389 alg.objectSelection = f'{selection}&&{self.btagDecoration},as_char' if selection else f'{self.btagDecoration},as_char'
390 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
391 if len(items) == 3:
392 alg.sign = self.check_sign(items[1])
393 alg.count = self.check_int(items[2])
394 elif len(items) == 4:
395 if ":" in text:
396 btagger, btagWP = self.check_btagging(items[1])
397 customBtag = f'ftag_select_{btagger}_{btagWP}'
398 alg.objectSelection = f'{selection}&&{customBtag},as_char' if selection else f'{customBtag},as_char'
399 else:
400 extraSel = self.check_string(items[1])
401 alg.objectSelection = self.extendObjectSelection(config, self.jets.split(".")[0], alg.objectSelection, extraSel)
402 alg.sign = self.check_sign(items[2])
403 alg.count = self.check_int(items[3])
404 elif len(items) == 5:
405 extraSel = self.check_string(items[1])
406 btagger, btagWP = self.check_btagging(items[2])
407 customBtag = f'ftag_select_{btagger}_{btagWP}'
408 alg.objectSelection = f'{selection}&&{customBtag},as_char' if selection else f'{customBtag},as_char'
409 alg.objectSelection = self.extendObjectSelection(config, self.jets.split(".")[0], alg.objectSelection, extraSel)
410 alg.sign = self.check_sign(items[3])
411 alg.count = self.check_int(items[4])
412 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
413 return
414
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ add_NJETGHOST_selector()

python.EventSelectionConfig.EventSelectionConfig.add_NJETGHOST_selector ( self,
text,
config )

Definition at line 524 of file EventSelectionConfig.py.

524 def add_NJETGHOST_selector(self, text, config):
525 items = text.split()
526 self._check_args(items, "JET_N_GHOST", (4, 5))
527 thisalg = f'{self.selectionName}_NJETGHOST_{self.step}'
528 alg = config.createAlgorithm('CP::JetNGhostSelectorAlg', thisalg)
529 alg.jets, alg.jetSelection = config.readNameAndSelection(self.jets)
530 ghosts = self.check_ghosts(items[1])
531 alg.ghost = ghosts[0]
532 if len(ghosts) > 1 :
533 alg.veto = ghosts[1]
534 if len(items) == 4:
535 alg.sign = self.check_sign(items[2])
536 alg.count = self.check_int(items[3])
537 elif len(items) == 5:
538 alg.minPt = self.check_float(items[2])
539 alg.sign = self.check_sign(items[3])
540 alg.count = self.check_int(items[4])
541 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
542 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
543 return
544

◆ add_NLJETGHOST_selector()

python.EventSelectionConfig.EventSelectionConfig.add_NLJETGHOST_selector ( self,
text,
config )

Definition at line 545 of file EventSelectionConfig.py.

545 def add_NLJETGHOST_selector(self, text, config):
546 items = text.split()
547 self._check_args(items, "LJET_N_GHOST", (4, 5))
548 thisalg = f'{self.selectionName}_NLJETGHOST_{self.step}'
549 alg = config.createAlgorithm('CP::JetNGhostSelectorAlg', thisalg)
550 alg.jets, alg.jetSelection = config.readNameAndSelection(self.largeRjets)
551 ghosts = self.check_ghosts(items[1])
552 alg.ghost = ghosts[0]
553 if len(ghosts) > 1 :
554 alg.veto = ghosts[1]
555 if len(items) == 4:
556 alg.sign = self.check_sign(items[2])
557 alg.count = self.check_int(items[3])
558 elif len(items) == 5:
559 alg.minPt = self.check_float(items[2])
560 alg.sign = self.check_sign(items[3])
561 alg.count = self.check_int(items[4])
562 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
563 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
564 return
565

◆ add_NLJETMASS_selector()

python.EventSelectionConfig.EventSelectionConfig.add_NLJETMASS_selector ( self,
text,
config )

Definition at line 487 of file EventSelectionConfig.py.

487 def add_NLJETMASS_selector(self, text, config):
488 items = text.split()
489 self._check_args(items, "LJETMASS_N", (4, 5))
490 thisalg = f'{self.selectionName}_NLJETMASS_{self.step}'
491 alg = config.createAlgorithm('CP::NObjectMassSelectorAlg', thisalg)
492 alg.particles, alg.objectSelection = config.readNameAndSelection(self.largeRjets)
493 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
494 alg.minMass, alg.sign, alg.count = self._val_sign_count(
495 items, config, alg, self.largeRjets.split(".")[0])
496 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
497 return
498

◆ add_NLJETMASSWINDOW_selector()

python.EventSelectionConfig.EventSelectionConfig.add_NLJETMASSWINDOW_selector ( self,
text,
config )

Definition at line 499 of file EventSelectionConfig.py.

499 def add_NLJETMASSWINDOW_selector(self, text, config):
500 items = text.split()
501 self._check_args(items, "LJETMASSWINDOW_N", (5, 6, 7))
502 thisalg = f'{self.selectionName}_NLJETMASSWINDOW_{self.step}'
503 alg = config.createAlgorithm('CP::NLargeRJetMassWindowSelectorAlg', thisalg)
504 alg.ljets, alg.ljetSelection = config.readNameAndSelection(self.largeRjets)
505 vetoMode = items[-1] == 'veto' or items[-1] == 'VETO'
506 if len(items) == 5 or (len(items) == 6 and vetoMode):
507 alg.lowMass = self.check_float(items[1])
508 alg.highMass = self.check_float(items[2])
509 alg.sign = self.check_sign(items[3])
510 alg.count = self.check_int(items[4])
511 alg.vetoMode = vetoMode
512 elif (len(items) == 6 and not vetoMode) or len(items) == 7:
513 extraSel = self.check_string(items[1])
514 alg.ljetSelection = self.extendObjectSelection(config, self.largeRjets.split(".")[0], alg.ljetSelection, extraSel)
515 alg.lowMass = self.check_float(items[2])
516 alg.highMass = self.check_float(items[3])
517 alg.sign = self.check_sign(items[4])
518 alg.count = self.check_int(items[5])
519 alg.vetoMode = vetoMode
520 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
521 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
522 return
523

◆ add_NOBJ_selector()

python.EventSelectionConfig.EventSelectionConfig.add_NOBJ_selector ( self,
text,
config )

Definition at line 566 of file EventSelectionConfig.py.

566 def add_NOBJ_selector(self, text, config):
567 items = text.split()
568 self._check_args(items, "OBJ_N", (5,))
569 thisalg = f'{self.selectionName}_NOBJ_{self.step}'
570 alg = config.createAlgorithm('CP::NObjectPtSelectorAlg', thisalg)
571 alg.particles, alg.objectSelection = config.readNameAndSelection(self.check_string(items[1]))
572 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
573 alg.minPt = self.check_float(items[2])
574 alg.sign = self.check_sign(items[3])
575 alg.count = self.check_int(items[4])
576 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
577 return
578

◆ add_RUNNUMBER()

python.EventSelectionConfig.EventSelectionConfig.add_RUNNUMBER ( self,
text,
config )

Definition at line 736 of file EventSelectionConfig.py.

736 def add_RUNNUMBER(self, text, config):
737 items = text.split()
738 self._check_args(items, "RUN_NUMBER", (3,))
739 thisalg = f'{self.selectionName}_RUN_NUMBER_{self.step}'
740 alg = config.createAlgorithm('CP::RunNumberSelectorAlg', thisalg)
741 alg.sign = self.check_sign(items[1])
742 alg.runNumber = self.check_int(items[2])
743 alg.useRandomRunNumber = config.dataType() is not DataType.Data
744 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
745 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
746 return
747

◆ add_SAVE()

python.EventSelectionConfig.EventSelectionConfig.add_SAVE ( self,
text,
config )

Definition at line 970 of file EventSelectionConfig.py.

970 def add_SAVE(self, text, config):
971 # SAVE is deprecated: the event filter is now emitted automatically at
972 # the end of the block (see makeAlgs). The keyword is accepted only to
973 # warn existing configs; it performs no operation itself.
974 items = text.split()
975 self._check_args(items, "SAVE", (1,))
976 warnings.warn(
977 "[EventSelectionConfig] The 'SAVE' keyword is deprecated: the event "
978 "filter is now created automatically at the end of each EventSelection "
979 f"block. Please remove the 'SAVE' line from selection '{self.selectionName}'.",
980 category=ConfigDeprecationWarning, stacklevel=2)
981 return
982

◆ add_SUMNELNMU_selector()

python.EventSelectionConfig.EventSelectionConfig.add_SUMNELNMU_selector ( self,
text,
config )

Definition at line 415 of file EventSelectionConfig.py.

415 def add_SUMNELNMU_selector(self, text, config):
416 items = text.split()
417 self._check_args(items, "SUM_EL_N_MU_N", (4, 5, 7))
418 if not self.electrons and not self.muons:
419 self.raise_missinginput("electrons or muons")
420 thisalg = f'{self.selectionName}_SUMNELNMU_{self.step}'
421 alg = config.createAlgorithm('CP::SumNLeptonPtSelectorAlg', thisalg)
422 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
423 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
424 self._maybe_dressed(alg, self.electrons, self.muons)
425 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
426 if len(items) == 4:
427 alg.minPtEl = self.check_float(items[1])
428 alg.minPtMu = self.check_float(items[1])
429 alg.sign = self.check_sign(items[2])
430 alg.count = self.check_int(items[3])
431 elif len(items) == 5:
432 alg.minPtEl = self.check_float(items[1])
433 alg.minPtMu = self.check_float(items[2])
434 alg.sign = self.check_sign(items[3])
435 alg.count = self.check_int(items[4])
436 elif len(items) == 7:
437 extraSelEl = self.check_string(items[1])
438 extraSelMu = self.check_string(items[2])
439 alg.electronSelection = self.extendObjectSelection(config, self.electrons.split(".")[0], alg.electronSelection, extraSelEl)
440 alg.muonSelection = self.extendObjectSelection(config, self.muons.split(".")[0], alg.muonSelection, extraSelMu)
441 alg.minPtEl = self.check_float(items[3])
442 alg.minPtMu = self.check_float(items[4])
443 alg.sign = self.check_sign(items[5])
444 alg.count = self.check_int(items[6])
445 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
446 return
447

◆ add_SUMNLEPTONS_selector()

python.EventSelectionConfig.EventSelectionConfig.add_SUMNLEPTONS_selector ( self,
text,
config )

Definition at line 448 of file EventSelectionConfig.py.

448 def add_SUMNLEPTONS_selector(self, text, config):
449 items = text.split()
450 self._check_args(items, "SUM_EL_N_MU_N_TAU_N", (4, 6, 9))
451 if not self.electrons and not self.muons and not self.taus:
452 self.raise_missinginput("electrons, muons or taus")
453 thisalg = f'{self.selectionName}_SUMNLEPTONS_{self.step}'
454 alg = config.createAlgorithm('CP::SumNLeptonPtSelectorAlg', thisalg)
455 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
456 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
457 alg.taus, alg.tauSelection = config.readNameAndSelection(self.taus)
458 self._maybe_dressed(alg, self.electrons, self.muons)
459 alg.eventPreselection = self.checkDecorationName(self.currentDecoration)
460 if len(items) == 4:
461 alg.minPtEl = self.check_float(items[1])
462 alg.minPtMu = self.check_float(items[1])
463 alg.minPtTau = self.check_float(items[1])
464 alg.sign = self.check_sign(items[2])
465 alg.count = self.check_int(items[3])
466 elif len(items) == 6:
467 alg.minPtEl = self.check_float(items[1])
468 alg.minPtMu = self.check_float(items[2])
469 alg.minPtTau = self.check_float(items[3])
470 alg.sign = self.check_sign(items[4])
471 alg.count = self.check_int(items[5])
472 elif len(items) == 9:
473 extraSelEl = self.check_string(items[1])
474 extraSelMu = self.check_string(items[2])
475 extraSelTau = self.check_string(items[3])
476 alg.electronSelection = self.extendObjectSelection(config, self.electrons.split(".")[0], alg.electronSelection, extraSelEl)
477 alg.muonSelection = self.extendObjectSelection(config, self.muons.split(".")[0], alg.muonSelection, extraSelMu)
478 alg.tauSelection = self.extendObjectSelection(config, self.taus.split(".")[0], alg.tauSelection, extraSelTau)
479 alg.minPtEl = self.check_float(items[4])
480 alg.minPtMu = self.check_float(items[5])
481 alg.minPtTau = self.check_float(items[6])
482 alg.sign = self.check_sign(items[7])
483 alg.count = self.check_int(items[8])
484 self.setDecorationName(alg, config, f'{thisalg}_%SYS%')
485 return
486

◆ check_btagging()

python.EventSelectionConfig.EventSelectionConfig.check_btagging ( self,
test )

Definition at line 251 of file EventSelectionConfig.py.

251 def check_btagging(self, test):
252 test = test.split(":")
253 if len(test) != 2:
254 raise ValueError (f"[EventSelectionConfig] Misconfiguration! {test} should be provided as 'btagger:btagWP'")
255 else:
256 return test
257

◆ check_float()

python.EventSelectionConfig.EventSelectionConfig.check_float ( self,
test,
requirePositive = True )

Definition at line 209 of file EventSelectionConfig.py.

209 def check_float(self, test, requirePositive=True):
210 try:
211 value = float(test)
212 if not requirePositive or value >= 0:
213 return value
214 else:
215 raise ValueError (f"[EventSelectionConfig] Misconfiguration! Float {test} is not positive!")
216 except ValueError:
217 raise ValueError (f"[EventSelectionConfig] Misconfiguration! {test} should be a float, not {type(test)}!")
218

◆ check_ghosts()

python.EventSelectionConfig.EventSelectionConfig.check_ghosts ( self,
test )

Definition at line 258 of file EventSelectionConfig.py.

258 def check_ghosts(self, test):
259 test = self.check_string(test)
260 values = test.split("!")
261 ghost_map = {
262 "B": "GhostBHadronsFinalCount",
263 "C": "GhostCHadronsFinalCount",
264 "T": "GhostTQuarksFinalCount",
265 "W": "GhostWBosonsCount",
266 "Z": "GhostZBosonsCount",
267 "H": "GhostHBosonsCount",
268 "TAU": "GhostTausFinalCount"
269 }
270 return [ghost_map.get(value.upper(), value) for value in values]
271

◆ check_int()

python.EventSelectionConfig.EventSelectionConfig.check_int ( self,
test,
requirePositive = True )

Definition at line 219 of file EventSelectionConfig.py.

219 def check_int(self, test, requirePositive=True):
220 try:
221 value = int(test)
222 if value == float(test):
223 if not requirePositive or value >= 0:
224 return value
225 else:
226 raise ValueError (f"[EventSelectionConfig] Misconfiguration! Int {test} us not positive!")
227 else:
228 raise ValueError (f"[EventSelectionConfig] Misconfiguration! {test} should be an int, not a float!")
229 except ValueError:
230 raise ValueError (f"[EventSelectionConfig] Misconfiguration! {test} should be an int, not {type(test)}")
231

◆ check_sign()

python.EventSelectionConfig.EventSelectionConfig.check_sign ( self,
test )

Definition at line 238 of file EventSelectionConfig.py.

238 def check_sign(self, test):
239 mapping = {
240 "<" : "LT",
241 ">" : "GT",
242 "==": "EQ",
243 ">=": "GE",
244 "<=": "LE"
245 }
246 try:
247 return mapping[test]
248 except KeyError:
249 raise KeyError (f"[EventSelectionConfig] Misconfiguration! {test} should be one of {list(mapping.keys())}")
250

◆ check_string()

python.EventSelectionConfig.EventSelectionConfig.check_string ( self,
test )

Definition at line 232 of file EventSelectionConfig.py.

232 def check_string(self, test):
233 if not isinstance(test, str):
234 raise ValueError (f"[EventSelectionConfig] Misconfiguration! {test} should be a string, not a number!")
235 else:
236 return test
237

◆ checkDecorationName()

python.EventSelectionConfig.EventSelectionConfig.checkDecorationName ( self,
decoration )

Definition at line 294 of file EventSelectionConfig.py.

294 def checkDecorationName(self, decoration):
295 if decoration == '':
296 return decoration
297 decoration = decoration.split("&&")
298 decoration = [sub + ',as_char' if ',as_char' not in sub else sub for sub in decoration]
299 return '&&'.join(decoration)
300

◆ extendObjectSelection()

python.EventSelectionConfig.EventSelectionConfig.extendObjectSelection ( self,
config,
container,
oldSelection,
newSelection )

Definition at line 301 of file EventSelectionConfig.py.

301 def extendObjectSelection(self, config, container, oldSelection, newSelection):
302 if oldSelection:
303 return oldSelection + "&&" + config.getFullSelection(container, newSelection)
304 else:
305 return config.getFullSelection(container, newSelection)
306

◆ getCutflow()

python.EventSelectionConfig.EventSelectionConfig.getCutflow ( self)

Definition at line 276 of file EventSelectionConfig.py.

276 def getCutflow(self):
277 return self.cutflow
278

◆ instanceName()

python.EventSelectionConfig.EventSelectionConfig.instanceName ( self)
Return the instance name for this block

Definition at line 123 of file EventSelectionConfig.py.

123 def instanceName (self) :
124 """Return the instance name for this block"""
125 return self.selectionName
126

◆ interpret()

python.EventSelectionConfig.EventSelectionConfig.interpret ( self,
text,
cfg )

Definition at line 181 of file EventSelectionConfig.py.

181 def interpret(self, text, cfg):
182 text = text.strip()
183 if not text or text.startswith("#"):
184 return
185 self.step += 1
186 keyword = text.split()[0]
187 handler = self._dispatch.get(keyword)
188 if handler is None:
189 raise ValueError (f"[EventSelectionConfig] The following selection cut is not recognised! --> {text}")
190 handler(text, cfg)
191
void handler(int sig)
signal handler
Definition rmain.cxx:99

◆ makeAlgs()

python.EventSelectionConfig.EventSelectionConfig.makeAlgs ( self,
config )

Definition at line 159 of file EventSelectionConfig.py.

159 def makeAlgs(self, config):
160 existing = config.getContainerMeta('EventInfo', 'eventSelectionNames', defaultValue=[])
161 config.setContainerMeta('EventInfo', 'eventSelectionNames',
162 existing + [f'pass_{self.selectionName}_%SYS%'], allowOverwrite=True)
163
164 # need to re-initialize here to deal with multiple passes
165 self.step = 0
166 # initialize the pre-selection
167 self.currentDecoration = self.preselection
168 # re-initialize the cutflow
169 self.cutflow = []
170 # read the selection cuts
171 if self.selectionCuts is None:
172 raise ValueError ("[EventSelectionConfig] You must provide the 'selectionCuts' option to 'EventSelectionConfig': "
173 "a single string where each line represents a different selection cut to apply in order.")
174 for line in self.selectionCuts.split("\n"):
175 self.interpret(line, config)
176 # the event filter is always created automatically at the end of the
177 # block; an explicit SAVE line only triggers a deprecation warning
178 self._emit_save(config)
179 config.addEventCutFlow(self.selectionName, self.getCutflow())
180

◆ raise_misconfig()

python.EventSelectionConfig.EventSelectionConfig.raise_misconfig ( self,
text,
keyword )

Definition at line 196 of file EventSelectionConfig.py.

196 def raise_misconfig(self, text, keyword):
197 raise ValueError (f"[EventSelectionConfig] Misconfiguration! Check {keyword} in: {text}")
198

◆ raise_missinginput()

python.EventSelectionConfig.EventSelectionConfig.raise_missinginput ( self,
collection )

Definition at line 199 of file EventSelectionConfig.py.

199 def raise_missinginput(self, collection):
200 raise ValueError (f"[EventSelectionConfig] Misconfiguration! Missing input collection for {collection}")
201

◆ setDecorationName()

python.EventSelectionConfig.EventSelectionConfig.setDecorationName ( self,
algorithm,
config,
decoration )

Definition at line 279 of file EventSelectionConfig.py.

279 def setDecorationName(self, algorithm, config, decoration):
280 self.cutflow.append( decoration )
281 if algorithm is not None:
282 algorithm.decorationName = f'{decoration},as_char'
283 self.currentDecoration = decoration
284 if self.debugMode:
285 config.addOutputVar('EventInfo', decoration, decoration.split("_%SYS%")[0])
286 else:
287 if self.currentDecoration:
288 self.currentDecoration += '&&' + decoration
289 else:
290 self.currentDecoration = decoration
291 config.addSelection('EventInfo', '', decoration)
292 return
293

Member Data Documentation

◆ _dispatch

python.EventSelectionConfig.EventSelectionConfig._dispatch = self._build_dispatch()
protected

Definition at line 121 of file EventSelectionConfig.py.

◆ _EVENTVAR_TYPES

dict python.EventSelectionConfig.EventSelectionConfig._EVENTVAR_TYPES = {"float": "floatVariable", "int": "intVariable", "double": "doubleVariable"}
staticprotected

Definition at line 950 of file EventSelectionConfig.py.

◆ _EXPR_COLL

dict python.EventSelectionConfig.EventSelectionConfig._EXPR_COLL
staticprotected
Initial value:
= {
"jet": ("jets", False, False),
"bjet": ("jets", True, False),
"el": ("electrons", False, False),
"mu": ("muons", False, False),
"tau": ("taus", False, False),
"ph": ("photons", False, False),
"ljet": ("largeRjets", False, False),
"met": ("met", False, True),
}

Definition at line 753 of file EventSelectionConfig.py.

◆ _EXPR_TOKEN_RE

python.EventSelectionConfig.EventSelectionConfig._EXPR_TOKEN_RE = re.compile(, re.VERBOSE)
staticprotected

Definition at line 777 of file EventSelectionConfig.py.

◆ _EXPR_VARS

dict python.EventSelectionConfig.EventSelectionConfig._EXPR_VARS
staticprotected
Initial value:
= {
"dR": (2, 2, ",", True, False),
"dEta": (2, 2, ",", True, False),
"dPhi": (2, 2, ",", False, True),
"m": (1, None, "+", False, False),
"e": (1, None, "+", False, False),
"pt": (1, None, "+", False, True),
"eta": (1, 1, None, True, False),
"phi": (1, 1, None, False, True),
}

Definition at line 766 of file EventSelectionConfig.py.

◆ _exprPos

int python.EventSelectionConfig.EventSelectionConfig._exprPos = 0
protected

Definition at line 817 of file EventSelectionConfig.py.

◆ _exprTokens

python.EventSelectionConfig.EventSelectionConfig._exprTokens = tokens
protected

Definition at line 816 of file EventSelectionConfig.py.

◆ _NOBJECT

dict python.EventSelectionConfig.EventSelectionConfig._NOBJECT
staticprotected
Initial value:
= {
"EL_N": ("electrons", "NEL"),
"MU_N": ("muons", "NMU"),
"JET_N": ("jets", "NJET"),
"PH_N": ("photons", "NPH"),
"TAU_N": ("taus", "NTAU"),
"LJET_N": ("largeRjets", "NLJET"),
}

Definition at line 64 of file EventSelectionConfig.py.

◆ btagDecoration

python.EventSelectionConfig.EventSelectionConfig.btagDecoration

Definition at line 926 of file EventSelectionConfig.py.

◆ currentDecoration

str python.EventSelectionConfig.EventSelectionConfig.currentDecoration = ''

Definition at line 119 of file EventSelectionConfig.py.

◆ cutflow

list python.EventSelectionConfig.EventSelectionConfig.cutflow = []

Definition at line 120 of file EventSelectionConfig.py.

◆ debugMode

python.EventSelectionConfig.EventSelectionConfig.debugMode

Definition at line 284 of file EventSelectionConfig.py.

◆ electrons

python.EventSelectionConfig.EventSelectionConfig.electrons

Definition at line 424 of file EventSelectionConfig.py.

◆ jets

python.EventSelectionConfig.EventSelectionConfig.jets

Definition at line 383 of file EventSelectionConfig.py.

◆ met

python.EventSelectionConfig.EventSelectionConfig.met

Definition at line 582 of file EventSelectionConfig.py.

◆ muons

python.EventSelectionConfig.EventSelectionConfig.muons

Definition at line 418 of file EventSelectionConfig.py.

◆ selectionName

python.EventSelectionConfig.EventSelectionConfig.selectionName

Definition at line 179 of file EventSelectionConfig.py.

◆ step

int python.EventSelectionConfig.EventSelectionConfig.step = 0

Definition at line 118 of file EventSelectionConfig.py.

◆ taus

python.EventSelectionConfig.EventSelectionConfig.taus

Definition at line 451 of file EventSelectionConfig.py.


The documentation for this class was generated from the following file: