diff --git a/.vscode/settings.json b/.vscode/settings.json index 7892e616..2c83d14e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -55,7 +55,9 @@ "nqueries", "ntuples", "numpy", + "opendata", "pathlib", + "PHYSLITE", "pnfs", "posix", "Powheg", @@ -94,6 +96,7 @@ "unittests", "URL's", "xaod", + "xaodr", "xrootd" ], "python.analysis.typeCheckingMode": "basic", diff --git a/docs/examples.rst b/docs/examples.rst index 92b031c7..64f8fe7b 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -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 diff --git a/examples/func_adl_xAOD_simple.py b/examples/func_adl_xAOD_simple.py new file mode 100644 index 00000000..353f19f7 --- /dev/null +++ b/examples/func_adl_xAOD_simple.py @@ -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 diff --git a/examples/func_adl_xAOD_typed.py b/examples/func_adl_xAOD_typed.py new file mode 100644 index 00000000..c8588c9e --- /dev/null +++ b/examples/func_adl_xAOD_typed.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 50834bb6..3dbdbff8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" ]