Skip to content

Commit a7144cc

Browse files
authored
Examples for xAOD (#455)
* First go at a very simple xAOD example * Fix up to use a opendata file for the example. * Remove logging * Working example for simple func_adl * Minor updates to spelling corrections * Add a typed example * Fix up the naming of the typed call * Add the examles to `examples1.rst` * Fix up example to properly reference everything!
1 parent 71c7132 commit a7144cc

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
"nqueries",
5656
"ntuples",
5757
"numpy",
58+
"opendata",
5859
"pathlib",
60+
"PHYSLITE",
5961
"pnfs",
6062
"posix",
6163
"Powheg",
@@ -94,6 +96,7 @@
9496
"unittests",
9597
"URL's",
9698
"xaod",
99+
"xaodr",
97100
"xrootd"
98101
],
99102
"python.analysis.typeCheckingMode": "basic",

docs/examples.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@ from the ``CollectionTree`` tree in ATLAS PHYSLITE OpenData Dataset.
5959
:language: yaml
6060

6161

62+
Func_ADL xAOD Query Example
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
65+
The two following examples read columns of data from an ATLAS PHYSLITE xAOD file
66+
(released by the experiment as OpenData). It uses the internal C++ framework, EventLoop, to read this data.
67+
EventLoop can be used to read xAOD files in general, not just PHYSLITE.
68+
69+
THe first example uses the very simple model that is built into ServiceX:
70+
71+
.. tabs::
72+
73+
.. tab:: *Python Dict*
74+
75+
.. literalinclude:: ../examples/func_adl_xAOD_simple.py
76+
:language: python
77+
78+
The second example uses the full type information, allowing one to
79+
access everything that could be translated in the xAOD (including ElementLink following):
80+
81+
.. tabs::
82+
83+
.. tab:: *Python Dict*
84+
85+
.. literalinclude:: ../examples/func_adl_xAOD_typed.py
86+
:language: python
87+
88+
For this second example, make sure the extra package `func_adl_servicex_xaodr22` is installed!
89+
6290
Python Function Query Example
6391
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6492
This example uses an uproot python function to extract the ``AnalysisElectronsAuxDyn.pt`` branch

examples/func_adl_xAOD_simple.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from servicex import query as q, deliver, dataset
2+
3+
4+
def func_adl_xaod_simple():
5+
query = q.FuncADL_ATLASr22() # type: ignore
6+
jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets'))
7+
jet_info_per_event = jets_per_event.Select(
8+
lambda jets: {
9+
'pt': jets.Select(lambda j: j.pt()),
10+
'eta': jets.Select(lambda j: j.eta())
11+
}
12+
)
13+
14+
spec = {
15+
'Sample': [{
16+
'Name': "func_adl_xAOD_simple",
17+
'Dataset': dataset.FileList(
18+
[
19+
"root://eospublic.cern.ch//eos/opendata/atlas/rucio/mc20_13TeV/DAOD_PHYSLITE.37622528._000013.pool.root.1", # noqa: E501
20+
]
21+
),
22+
'Query': jet_info_per_event
23+
}]
24+
}
25+
files = deliver(spec, servicex_name="servicex-uc-af")
26+
assert files is not None, "No files returned from deliver! Internal error"
27+
return files
28+
29+
30+
if __name__ == "__main__":
31+
files = func_adl_xaod_simple()
32+
assert len(files['func_adl_xAOD_simple']) == 1

examples/func_adl_xAOD_typed.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from servicex import deliver, dataset
2+
from func_adl_servicex_xaodr22 import FuncADLQueryPHYSLITE, cpp_float
3+
4+
5+
def func_adl_xaod_typed():
6+
query = FuncADLQueryPHYSLITE() # type: ignore
7+
jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets'))
8+
jet_info_per_event = jets_per_event.Select(
9+
lambda jets: {
10+
'pt': jets.Select(lambda j: j.pt()),
11+
'eta': jets.Select(lambda j: j.eta()),
12+
'emf': jets.Select(lambda j: j.getAttribute[cpp_float]('EMFrac')) # type: ignore
13+
}
14+
)
15+
16+
spec = {
17+
'Sample': [{
18+
'Name': "func_adl_xAOD_simple",
19+
'Dataset': dataset.FileList(
20+
[
21+
"root://eospublic.cern.ch//eos/opendata/atlas/rucio/mc20_13TeV/DAOD_PHYSLITE.37622528._000013.pool.root.1", # noqa: E501
22+
]
23+
),
24+
'Query': jet_info_per_event,
25+
'Codegen': 'atlasr22',
26+
}]
27+
}
28+
files = deliver(spec, servicex_name="servicex-uc-af")
29+
assert files is not None, "No files returned from deliver! Internal error"
30+
return files
31+
32+
33+
if __name__ == "__main__":
34+
files = func_adl_xaod_typed()
35+
assert len(files['func_adl_xAOD_simple']) == 1

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ docs = [
8484
"furo>=2023.5.20",
8585
"sphinx-code-include>=1.4.0",
8686
"myst-parser>=3.0.1",
87+
"func-adl-servicex-xaodr22",
8788
"autodoc-pydantic==2.2.0",
8889
"sphinx-tabs>=3.4.5"
8990
]

0 commit comments

Comments
 (0)