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 (
"18130100",
"dark",
"BtoKplusLLP"),
132 (
"18570600",
"taupair",
"TauGeneric"),
133 (
"18570700",
"taupair",
"TauThrust"),
134 (
"18530100",
"lowMulti",
"TwoTrackLeptonsForLuminosity"),
135 (
"18520500",
"lowMulti",
"LowMassTwoTrack"),
136 (
"18530200",
"lowMulti",
"SingleTagPseudoScalar"),
139 (
"19120100",
"btocharmless",
"BtoPi0Pi0"),
140 (
"19130201",
"btocharmless",
"BtoHadTracks"),
141 (
"19130300",
"btocharmless",
"BtoHad1Pi0"),
142 (
"19130310",
"btocharmless",
"BtoHad3Tracks1Pi0"),
143 (
"19120400",
"btocharmless",
"BtoRhopRhom"),
146 A list of all official registered skims and their skim code and parent module. Entries
147 must be of the form ``(code, module, name)``.
151 def _add_skim_registry_table(SkimRegistry):
153 Decorator to add a Sphinx table to the docstring of the skim registry.
155 Inserts table wherever '<TABLE>' is in the docstring.
158 df = pd.DataFrame(_RegisteredSkims, columns=[
"Skim code",
"Module",
"Skim name"])
159 df = df[[
"Module",
"Skim name",
"Skim code"]].sort_values(by=[
"Module",
"Skim code"])
160 table = tabulate(df, showindex=
"never", tablefmt=
"grid", headers=df.columns)
163 OriginalLines = table.split(
"\n")
164 header, OriginalLines, footer = OriginalLines[:2], OriginalLines[2:-1], OriginalLines[-1]
167 lines.append(
"\n ".join(header))
168 for BorderLine, TextLine
in zip(OriginalLines[::2], OriginalLines[1::2]):
169 segments = TextLine.split(
"|")
170 module = segments[1].lstrip().rstrip()
171 if CurrentModule == module:
172 segments[1] =
" " * len(segments[1])
173 BorderLine =
"|" +
" " * len(segments[1]) + BorderLine.lstrip(
"+").lstrip(
"-")
175 CurrentModule = module
176 lines.append(BorderLine)
177 lines.append(
"|".join(segments))
180 SkimRegistry.__doc__ = SkimRegistry.__doc__.replace(
"<TABLE>",
"\n ".join(lines))
185 @_add_skim_registry_table
188 Class containing information on all official registered skims. This class also
189 contains helper functions for getting information from the registry. For
190 convenience, an instance of this class is provided: `skim.registry.Registry`.
192 The table below lists all registered skims and their skim codes:
196 _registry = _RegisteredSkims
205 """A list of all registered skim names."""
210 """A list of all registered skim codes."""
215 """A list of all registered skim modules."""
219 """Retrieve the skim module name from the registry which contains the given
223 SkimName (str): Name of the skim as it appears in the skim registry.
226 The name of the skim module which contains the skim.
228 lookup = {name: module
for _, module, name
in self.
_registry}
230 return lookup[SkimName]
233 f
"Unrecognised skim name {SkimName}. "
234 "Please add your skim to the list in `skim/scripts/skim/registry.py`."
236 raise LookupError(SkimName)
239 """Retrieve a list of the skims listed in the registry as existing in
240 the given skim module.
243 SkimModule (str): The name of the module, *e.g.* ``btocharmless`` (not
244 ``skim.btocharmless`` or ``btocharmless.py``).
247 The skims listed in the registry as belonging to ``SkimModule``.
249 if SkimModule
not in self.
modules:
250 B2ERROR(f
"Unrecognised skim module {SkimModule}.")
251 raise LookupError(SkimModule)
253 ModuleLookup = {name: module
for _, module, name
in self.
_registry}
255 module: [name
for name
in self.
names if ModuleLookup[name] == module]
258 return NameLookup[SkimModule]
261 """Get the skim class constructor for the given skim.
263 This is achieved by importing the module listed alongside the skim name in the
267 SkimName (str): Name of the skim to be found.
270 The class constructor for the given skim.
273 SkimModule = import_module(f
"skim.{ModuleName}")
274 return getattr(SkimModule, SkimName)
277 """Find the 8 digit skim code assigned to the skim with the provided name.
280 SkimName (str): Name of the corresponding skim as it appears in the skim registry.
283 8 digit skim code assigned to the given skim.
285 lookup = {name: code
for code, _, name
in self.
_registry}
287 return lookup[SkimName]
290 f
"Unrecognised skim name {SkimName}. "
291 "Please add your skim to the list in `skim/scripts/skim/registry.py`."
293 raise LookupError(SkimName)
296 """Find the name of the skim which corresponds to the provided skim code.
298 This is useful to determine the skim script used to produce a specific uDST
299 file, given the 8-digit code name of the file itself.
302 SkimCode (str): 8 digit skim code assigned to some skim.
305 Name of the corresponding skim as it appears in the skim registry.
307 lookup = {code: name
for code, _, name
in self.
_registry}
309 return lookup[SkimCode]
312 f
"Unrecognised skim code {SkimCode}. "
313 "Please add your skim to the list in `skim/scripts/skim/registry.py`."
315 raise LookupError(SkimCode)
320 An instance of `skim.registry.SkimRegistryClass`. Use this in your script to get
321 information from the registry.
323 >>> from skim.registry import Registry
324 >>> Registry.encode_skim_name("SinglePhotonDark")