PyLamarr
Pythonizations for the ultra-fast simulation option for the LHCb experiment
Loading...
Searching...
No Matches
RecSummaryMaker.py
1
from
typing
import
Tuple, Optional
2
from
dataclasses
import
dataclass
3
from
pydantic
import
validate_arguments
4
5
from
PyLamarr
import
RemoteResource, Wrapper
6
7
@validate_arguments
8
@dataclass(frozen=True)
9
class
RecSummaryEntry
:
10
name: str
11
table_name: str
12
count_expr: str =
"COUNT (*)"
13
selection: Optional[str] =
None
14
custom_code: Optional[int] =
None
15
16
@property
17
def
code(self):
18
if
self.
custom_code
is
not
None
:
19
return
self.
custom_code
20
21
codes = dict(
22
nPVs = 0,
23
nLongTracks = 10,
24
nDownstreamTracks = 11,
25
nUpstreamTracks = 12,
26
nVeloTracks = 13,
27
nTTracks = 14,
28
nBackTracks = 15,
29
nTracks = 16,
30
nGhosts = 17,
31
nRich1Hits = 20,
32
nRich2Hits = 21,
33
nVeloClusters = 30,
34
nITClusters = 40,
35
nTTClusters = 50,
36
nUTClusters = 51,
37
nOTClusters = 60,
38
nFTClusters = 41,
39
nSPDhits = 70,
40
nMuonCoordsS0 = 80,
41
nMuonCoordsS1 = 91,
42
nMuonCoordsS2 = 92,
43
nMuonCoordsS3 = 93,
44
nMuonCoordsS4 = 94,
45
nMuonTracks = 95,
46
TypeUnknown = 1000
47
)
48
49
if
self.
name
not
in
codes.keys():
50
raise
KeyError(
51
f
"Unknown code for Summary '{self.name}' and no custom_code provided"
52
)
53
54
return
codes[self.
name
]
55
56
def
query(self):
57
return
f
"""
58
SELECT
59
e.datasource_id AS event_id,
60
{self.code} AS data_key,
61
{ self.count_expr } AS data_value
62
FROM {self.table_name} AS my
63
JOIN GenEvents AS e ON my.genevent_id = e.genevent_id
64
{ 'WHERE ' + self.selection if self.selection is not None else '' }
65
GROUP BY e.datasource_id
66
"""
67
68
@validate_arguments
69
@dataclass(frozen=True)
70
class
RecSummaryMaker
(
Wrapper
):
71
output_table: Optional[str] =
"RecSummary"
72
output_columns: Optional[Tuple[str, ...]] = (
73
"event_id"
,
"data_key"
,
"data_value"
,
74
)
75
make_persistent: Optional[bool] =
True
76
77
def
query(self):
78
entries = [
79
RecSummaryEntry
(
"nPVs"
, table_name=
'Vertices'
),
80
RecSummaryEntry
(
81
"nTracks"
,
82
table_name=
'Vertices'
,
83
count_expr=
'exp(4.8703 + random_normal()*0.5921)'
84
),
85
# RecSummaryEntry(
86
# "nTracks",
87
# table_name='GenParticles',
88
# selection=' AND '.join([
89
# 'norm2(my.px, my.py, my.pz) > 2500',
90
# 'norm2(my.px, my.py, 0) > 150',
91
# 'pseudorapidity(my.px, my.py, my.pz) < 5.5',
92
# 'pseudorapidity(my.px, my.py, my.pz) > 1.5',
93
# 'abs(my.pid) in (11, 13, 211, 321, 2212)',
94
# ]),
95
# )
96
]
97
98
return
[e.query()
for
e
in
entries]
99
100
101
implements: str =
"TemporaryTable"
102
103
@property
104
def
config(self):
105
return
dict(
106
output_table=self.
output_table
,
107
outputs=self.
output_columns
,
108
query=self.
query
(),
109
make_persistent=self.
make_persistent
,
110
)
111
112
PyLamarr.LHCb.RecSummaryMaker.RecSummaryEntry
Definition
RecSummaryMaker.py:9
PyLamarr.LHCb.RecSummaryMaker.RecSummaryEntry.custom_code
Optional custom_code
Definition
RecSummaryMaker.py:14
PyLamarr.LHCb.RecSummaryMaker.RecSummaryEntry.name
str name
Definition
RecSummaryMaker.py:10
PyLamarr.LHCb.RecSummaryMaker.RecSummaryMaker
Definition
RecSummaryMaker.py:70
PyLamarr.LHCb.RecSummaryMaker.RecSummaryMaker.output_columns
tuple output_columns
Definition
RecSummaryMaker.py:72
PyLamarr.LHCb.RecSummaryMaker.RecSummaryMaker.output_table
Optional output_table
Definition
RecSummaryMaker.py:71
PyLamarr.LHCb.RecSummaryMaker.RecSummaryMaker.query
query(self)
Definition
RecSummaryMaker.py:77
PyLamarr.LHCb.RecSummaryMaker.RecSummaryMaker.make_persistent
Optional make_persistent
Definition
RecSummaryMaker.py:75
PyLamarr.Wrapper.Wrapper
Definition
Wrapper.py:14
PyLamarr
LHCb
RecSummaryMaker.py
Generated by
1.9.8