6 from importlib
import import_module
9 from basf2
import B2ERROR
11 from tabulate
import tabulate
16 (
"10000000",
"systematics",
"Random"),
18 (
"10600300",
"systematics",
"SystematicsTracking"),
19 (
"10600400",
"systematics",
"Resonance"),
20 (
"10600500",
"systematics",
"SystematicsRadMuMu"),
21 (
"10600600",
"systematics",
"SystematicsEELL"),
22 (
"10600700",
"systematics",
"SystematicsRadEE"),
23 (
"10620200",
"systematics",
"SystematicsLambda"),
24 (
"11640100",
"systematics",
"SystematicsPhiGamma"),
25 (
"10600800",
"systematics",
"SystematicsFourLeptonFromHLTFlag"),
26 (
"10600900",
"systematics",
"SystematicsRadMuMuFromHLTFlag"),
27 (
"10611000",
"systematics",
"SystematicsJpsi"),
28 (
"10611100",
"systematics",
"SystematicsKshort"),
29 (
"10601200",
"systematics",
"SystematicsBhabha"),
30 (
"10601300",
"systematics",
"SystematicsCombinedHadronic"),
31 (
"10601400",
"systematics",
"SystematicsCombinedLowMulti"),
32 (
"10601500",
"systematics",
"SystematicsDstar"),
36 (
"11110100",
"semileptonic",
"PRsemileptonicUntagged"),
37 (
"11130300",
"leptonic",
"LeptonicUntagged"),
38 (
"11130301",
"leptonic",
"dilepton"),
39 (
"11160200",
"semileptonic",
"SLUntagged"),
40 (
"11160201",
"semileptonic",
"B0toDstarl_Kpi_Kpipi0_Kpipipi"),
41 (
"11180100",
"fei",
"feiHadronicB0"),
42 (
"11180200",
"fei",
"feiHadronicBplus"),
43 (
"11180300",
"fei",
"feiSLB0"),
44 (
"11180400",
"fei",
"feiSLBplus"),
45 (
"11180500",
"fei",
"feiHadronic"),
46 (
"11180600",
"fei",
"feiSL"),
49 (
"12160100",
"ewp",
"BtoXgamma"),
50 (
"12160200",
"ewp",
"BtoXll"),
51 (
"12160300",
"ewp",
"BtoXll_LFV"),
52 (
"12160400",
"ewp",
"inclusiveBplusToKplusNuNu"),
55 (
"13160200",
"tdcpv",
"TDCPV_ccs"),
56 (
"13160300",
"tdcpv",
"TDCPV_qqs"),
59 (
"14120300",
"btocharm",
"BtoD0h_Kspi0"),
60 (
"14120400",
"btocharm",
"BtoD0h_Kspipipi0"),
63 (
"14120600",
"btocharm",
"B0toDpi_Kpipi"),
64 (
"14120601",
"btocharm",
"B0toDpi_Kspi"),
66 (
"14120700",
"btocharm",
"B0toDstarPi_D0pi_Kpi"),
69 (
"14120800",
"btocharm",
"B0toDstarPi_D0pi_Kpipipi_Kpipi0"),
70 (
"14121100",
"btocharm",
"B0toDrho_Kpipi"),
71 (
"14121101",
"btocharm",
"B0toDrho_Kspi"),
72 (
"14121200",
"btocharm",
"B0toDstarRho_D0pi_Kpi"),
73 (
"14121201",
"btocharm",
"B0toDstarRho_D0pi_Kpipipi_Kpipi0"),
74 (
"14140100",
"btocharm",
"BtoD0h_hh"),
75 (
"14140101",
"btocharm",
"BtoD0h_Kpi"),
77 (
"14140102",
"btocharm",
"BtoD0h_Kpipipi_Kpipi0"),
78 (
"14140200",
"btocharm",
"BtoD0h_Kshh"),
79 (
"14141000",
"btocharm",
"BtoD0rho_Kpi"),
80 (
"14141001",
"btocharm",
"BtoD0rho_Kpipipi_Kpipi0"),
81 (
"14141002",
"btocharm",
"B0toDD_Kpipi_Kspi"),
82 (
"14141003",
"btocharm",
"B0toDstarD"),
83 (
"14121300",
"btocharm",
"B0toD0Kpipi0_pi0"),
87 (
"15410300",
"quarkonium",
"InclusiveLambda"),
88 (
"15420100",
"quarkonium",
"BottomoniumEtabExclusive"),
89 (
"15440100",
"quarkonium",
"BottomoniumUpsilon"),
91 (
"16460200",
"quarkonium",
"CharmoniumPsi"),
94 (
"17230100",
"charm",
"XToD0_D0ToHpJm"),
97 (
"17230200",
"charm",
"XToD0_D0ToNeutrals"),
98 (
"17230300",
"charm",
"DstToD0Pi_D0ToRare"),
99 (
"17230400",
"charm",
"XToDp_DpToKsHp"),
100 (
"17230500",
"charm",
"XToDp_DpToHpHmJp"),
101 (
"17230600",
"charm",
"LambdacTopHpJm"),
102 (
"17240100",
"charm",
"DstToD0Pi_D0ToHpJm"),
104 (
"17240200",
"charm",
"DstToD0Pi_D0ToHpJmPi0"),
105 (
"17240300",
"charm",
"DstToD0Pi_D0ToHpHmPi0"),
107 (
"17240400",
"charm",
"DstToD0Pi_D0ToKsOmega"),
109 (
"17240500",
"charm",
"DstToD0Pi_D0ToHpJmEta"),
111 (
"17240600",
"charm",
"DstToD0Pi_D0ToNeutrals"),
112 (
"17240700",
"charm",
"DstToD0Pi_D0ToHpJmKs"),
114 (
"17240800",
"charm",
"EarlyData_DstToD0Pi_D0ToHpJmPi0"),
115 (
"17240900",
"charm",
"EarlyData_DstToD0Pi_D0ToHpHmPi0"),
116 (
"17241000",
"charm",
"DstToDpPi0_DpToHpPi0"),
117 (
"17241100",
"charm",
"DstToD0Pi_D0ToHpHmHpJm"),
120 (
"18020100",
"dark",
"SinglePhotonDark"),
121 (
"18020200",
"dark",
"GammaGammaControlKLMDark"),
122 (
"18020300",
"dark",
"ALP3Gamma"),
123 (
"18020400",
"dark",
"EGammaControlDark"),
124 (
"18000000",
"dark",
"InelasticDarkMatter"),
125 (
"18000001",
"dark",
"RadBhabhaV0Control"),
126 (
"18360100",
"taupair",
"TauLFV"),
127 (
"18520100",
"dark",
"DimuonPlusMissingEnergy"),
128 (
"18520200",
"dark",
"ElectronMuonPlusMissingEnergy"),
129 (
"18520300",
"dark",
"DielectronPlusMissingEnergy"),
130 (
"18520400",
"dark",
"LFVZpVisible"),
131 (
"18570600",
"taupair",
"TauGeneric"),
132 (
"18570700",
"taupair",
"TauThrust"),
133 (
"18530100",
"lowMulti",
"TwoTrackLeptonsForLuminosity"),
134 (
"18520500",
"lowMulti",
"LowMassTwoTrack"),
135 (
"18530200",
"lowMulti",
"SingleTagPseudoScalar"),
138 (
"19120100",
"btocharmless",
"BtoPi0Pi0"),
139 (
"19130201",
"btocharmless",
"BtoHadTracks"),
140 (
"19130300",
"btocharmless",
"BtoHad1Pi0"),
141 (
"19130310",
"btocharmless",
"BtoHad3Tracks1Pi0"),
142 (
"19120400",
"btocharmless",
"BtoRhopRhom"),
145 A list of all official registered skims and their skim code and parent module. Entries
146 must be of the form ``(code, module, name)``.
150 def _add_skim_registry_table(SkimRegistry):
152 Decorator to add a Sphinx table to the docstring of the skim registry.
154 Inserts table wherever '<TABLE>' is in the docstring.
157 df = pd.DataFrame(_RegisteredSkims, columns=[
"Skim code",
"Module",
"Skim name"])
158 df = df[[
"Module",
"Skim name",
"Skim code"]].sort_values(by=[
"Module",
"Skim code"])
159 table = tabulate(df, showindex=
"never", tablefmt=
"grid", headers=df.columns)
162 OriginalLines = table.split(
"\n")
163 header, OriginalLines, footer = OriginalLines[:2], OriginalLines[2:-1], OriginalLines[-1]
166 lines.append(
"\n ".join(header))
167 for BorderLine, TextLine
in zip(OriginalLines[::2], OriginalLines[1::2]):
168 segments = TextLine.split(
"|")
169 module = segments[1].lstrip().rstrip()
170 if CurrentModule == module:
171 segments[1] =
" " * len(segments[1])
172 BorderLine =
"|" +
" " * len(segments[1]) + BorderLine.lstrip(
"+").lstrip(
"-")
174 CurrentModule = module
175 lines.append(BorderLine)
176 lines.append(
"|".join(segments))
179 SkimRegistry.__doc__ = SkimRegistry.__doc__.replace(
"<TABLE>",
"\n ".join(lines))
184 @_add_skim_registry_table
187 Class containing information on all official registered skims. This class also
188 contains helper functions for getting information from the registry. For
189 convenience, an instance of this class is provided: `skim.registry.Registry`.
191 The table below lists all registered skims and their skim codes:
195 _registry = _RegisteredSkims
204 """A list of all registered skim names."""
209 """A list of all registered skim codes."""
214 """A list of all registered skim modules."""
218 """Retrieve the skim module name from the registry which contains the given
222 SkimName (str): Name of the skim as it appears in the skim registry.
225 The name of the skim module which contains the skim.
227 lookup = {name: module
for _, module, name
in self.
_registry}
229 return lookup[SkimName]
232 f
"Unrecognised skim name {SkimName}. "
233 "Please add your skim to the list in `skim/scripts/skim/registry.py`."
235 raise LookupError(SkimName)
238 """Retrieve a list of the skims listed in the registry as existing in
239 the given skim module.
242 SkimModule (str): The name of the module, *e.g.* ``btocharmless`` (not
243 ``skim.btocharmless`` or ``btocharmless.py``).
246 The skims listed in the registry as belonging to ``SkimModule``.
248 if SkimModule
not in self.
modules:
249 B2ERROR(f
"Unrecognised skim module {SkimModule}.")
250 raise LookupError(SkimModule)
252 ModuleLookup = {name: module
for _, module, name
in self.
_registry}
254 module: [name
for name
in self.
names if ModuleLookup[name] == module]
257 return NameLookup[SkimModule]
260 """Get the skim class constructor for the given skim.
262 This is achieved by importing the module listed alongside the skim name in the
266 SkimName (str): Name of the skim to be found.
269 The class constructor for the given skim.
272 SkimModule = import_module(f
"skim.{ModuleName}")
273 return getattr(SkimModule, SkimName)
276 """Find the 8 digit skim code assigned to the skim with the provided name.
279 SkimName (str): Name of the corresponding skim as it appears in the skim registry.
282 8 digit skim code assigned to the given skim.
284 lookup = {name: code
for code, _, name
in self.
_registry}
286 return lookup[SkimName]
289 f
"Unrecognised skim name {SkimName}. "
290 "Please add your skim to the list in `skim/scripts/skim/registry.py`."
292 raise LookupError(SkimName)
295 """Find the name of the skim which corresponds to the provided skim code.
297 This is useful to determine the skim script used to produce a specific uDST
298 file, given the 8-digit code name of the file itself.
301 SkimCode (str): 8 digit skim code assigned to some skim.
304 Name of the corresponding skim as it appears in the skim registry.
306 lookup = {code: name
for code, _, name
in self.
_registry}
308 return lookup[SkimCode]
311 f
"Unrecognised skim code {SkimCode}. "
312 "Please add your skim to the list in `skim/scripts/skim/registry.py`."
314 raise LookupError(SkimCode)
319 An instance of `skim.registry.SkimRegistryClass`. Use this in your script to get
320 information from the registry.
322 >>> from skim.registry import Registry
323 >>> Registry.encode_skim_name("SinglePhotonDark")