Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"nqueries",
"ntuples",
"numpy",
"opendata",
"pathlib",
"PHYSLITE",
"pnfs",
"posix",
"Powheg",
Expand Down Expand Up @@ -94,6 +96,7 @@
"unittests",
"URL's",
"xaod",
"xaodr",
"xrootd"
],
"python.analysis.typeCheckingMode": "basic",
Expand Down
28 changes: 28 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ from the ``CollectionTree`` tree in ATLAS PHYSLITE OpenData Dataset.
:language: yaml


Func_ADL xAOD Query Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The two following examples read columns of data from an ATLAS PHYSLITE xAOD file
(released by the experiment as OpenData). It uses the internal C++ framework, EventLoop, to read this data.
EventLoop can be used to read xAOD files in general, not just PHYSLITE.

THe first example uses the very simple model that is built into ServiceX:

.. tabs::

.. tab:: *Python Dict*

.. literalinclude:: ../examples/func_adl_xAOD_simple.py
:language: python

The second example uses the full type information, allowing one to
access everything that could be translated in the xAOD (including ElementLink following):

.. tabs::

.. tab:: *Python Dict*

.. literalinclude:: ../examples/func_adl_xAOD_typed.py
:language: python

For this second example, make sure the extra package `func_adl_servicex_xaodr22` is installed!

Python Function Query Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This example uses an uproot python function to extract the ``AnalysisElectronsAuxDyn.pt`` branch
Expand Down
32 changes: 32 additions & 0 deletions examples/func_adl_xAOD_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from servicex import query as q, deliver, dataset


def func_adl_xaod_simple():
query = q.FuncADL_ATLASr22() # type: ignore
jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets'))
jet_info_per_event = jets_per_event.Select(
lambda jets: {
'pt': jets.Select(lambda j: j.pt()),
'eta': jets.Select(lambda j: j.eta())
}
)

spec = {
'Sample': [{
'Name': "func_adl_xAOD_simple",
'Dataset': dataset.FileList(
[
"root://eospublic.cern.ch//eos/opendata/atlas/rucio/mc20_13TeV/DAOD_PHYSLITE.37622528._000013.pool.root.1", # noqa: E501
]
),
'Query': jet_info_per_event
}]
}
files = deliver(spec, servicex_name="servicex-uc-af")
assert files is not None, "No files returned from deliver! Internal error"
return files


if __name__ == "__main__":
files = func_adl_xaod_simple()
assert len(files['func_adl_xAOD_simple']) == 1
35 changes: 35 additions & 0 deletions examples/func_adl_xAOD_typed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from servicex import deliver, dataset
from func_adl_servicex_xaodr22 import FuncADLQueryPHYSLITE, cpp_float


def func_adl_xaod_typed():
query = FuncADLQueryPHYSLITE() # type: ignore
jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets'))
jet_info_per_event = jets_per_event.Select(
lambda jets: {
'pt': jets.Select(lambda j: j.pt()),
'eta': jets.Select(lambda j: j.eta()),
'emf': jets.Select(lambda j: j.getAttribute[cpp_float]('EMFrac')) # type: ignore
}
)

spec = {
'Sample': [{
'Name': "func_adl_xAOD_simple",
'Dataset': dataset.FileList(
[
"root://eospublic.cern.ch//eos/opendata/atlas/rucio/mc20_13TeV/DAOD_PHYSLITE.37622528._000013.pool.root.1", # noqa: E501
]
),
'Query': jet_info_per_event,
'Codegen': 'atlasr22',
}]
}
files = deliver(spec, servicex_name="servicex-uc-af")
assert files is not None, "No files returned from deliver! Internal error"
return files


if __name__ == "__main__":
files = func_adl_xaod_typed()
assert len(files['func_adl_xAOD_simple']) == 1
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ docs = [
"furo>=2023.5.20",
"sphinx-code-include>=1.4.0",
"myst-parser>=3.0.1",
"func-adl-servicex-xaodr22",
"autodoc-pydantic==2.2.0",
"sphinx-tabs>=3.4.5"
]
Expand Down