Skip to main content

nndm_library

A library design to apply the machine learning and traditional methods to the discovery of new particles.

Installation

pip install nndm_library

Get started

First, for the following examples to work, the files in the directory tests/data_tests/ must be downloaded. In short:

Reading column files o the type data1 data2 data3 v11 v12 v13 . . . . . . . . . vn1 vn2 vn3

print("Read single basic file that contains two rows: particle id and particle name")
file = "tests/data_tests/basic_type/some_particle_names/quarks.txt"
print("Reading %s" % file)
print("*" * 50)
file = ReadFileBase("tests/data_tests/basic_type/some_particle_names/quarks.txt")
print(file.data)

print("\n\nRead all basic files like the one before, but in a given directory")
file = "tests/data_tests/basic_type/some_particle_names/"
print("Reading directory %s" % file)
print("*" * 50)
file = ReadFileBase("tests/data_tests/basic_type/some_particle_names/")
print(file.data)

print("\n\nRead all basic files like the one before, but all found recursively in a given directory")
file = "tests/data_tests/basic_type/"
print("Reading all files found recursively in directory %s" % file)
print("*" * 50)
file = ReadFileBase("tests/data_tests/basic_type/", recursive=True, relabel_events=True)
print(file.data)

Reading lhe files

we will read all data associated with a file in a given data frame by default. In addition to data, there are several options available to filtrate what is intender to be readed exactly.

# Single lhe file
filename = "tests/data_tests/signal/eta_decay_events_mk_0.014980679431428716_eps2_3.8832099149961855e-09.lhe"
print("Reading %s filetring by particle_ids, var_of_interest, and outgoing particles" % filename)
print("*" * 50)
file = ReadLhe(path=filename, particle_ids=[Constants.ELECTRON_ID], var_of_interest=['px'], outgoing=True)
print(file.data)

print("Reading %s filtering by particle_ids, and outgoing particles (all available variables are read" % filename)
print("*" * 50)
file = ReadLhe(path=filename, particle_ids=[Constants.ELECTRON_ID], outgoing=True)
print(file.data)

print("Reading %s filtering by particle_ids (all available variables for particles going in and out are read" % filename)
print("*" * 50)
file = ReadLhe(path=filename, particle_ids=[Constants.ELECTRON_ID])
print(file.data)
print("in out out states")
print(np.unique(file.data["status"]))

print("Reading from %s all particles for all available variables for particles going in and out" % filename)
print("*" * 50)
file = ReadLhe(path=filename)
print(file.data)
print("particle ids")
print(np.unique(file.data["id"]))

# files in a directory
print("\n\nRead all files like the one before, but in a given directory")
filename = "tests/data_tests/signal/"
print("Reading directory %s" % filename)
print("*" * 50)
file = ReadLhe(path=filename)
print(file.data)
print(file.files_dir)
res_dict = file.extract_params_from_path()
print(res_dict)

# files in a directory recursively
print("\n\nRead all basic files like the one before, but all found recursively in a given directory")
filename = "tests/data_tests/signal/"
print("Reading all files found recursively in directory %s" % filename)
print("*" * 50)
file = ReadLhe(filename, recursive=True, relabel_events=True)
print(file.data)
print(file.files_dir)

res_dict = file.extract_params_from_path()
print(res_dict)

Reading root files

Again, we will read all the data in the files and save it in a dataframe by default.

from nndm_library import ReadRoot

# The root file will be readed to the leafs indicated. The pattern_output first indicates that if the a same root file
#   has names like treeout;2, treeout;3, treeout;4, treeout;5,etc. Then, the one with the lest nomber will be chosen.
#   In the and the complete path to the leafst is like this treeout;{lest_number}/output_base_middle_branch/leaf
print("\n" * 2)
print("*" * 50)
print("Read Root file")
file = ReadRoot("tests/data_tests/background/v_e_scattering/onantinuelepton10125.root",
                output_base_tree="treeout", pattern_output="first", output_base_middle_branch = "/e/out",
                leafs = ["out.t", "out.x", "out.y", "out.z", "out._mass"])
print(file.data)

# The reading can be done to all the .root files that are in a given. In the below example they will be
#   somehting like tests/data_tests/background/v_e_scattering/file1.root,
#                  tests/data_tests/background/v_e_scattering/file2.root.

print("\n" * 2)
print("*" * 50)
print("Read background from all the roots in a given directory")
file = ReadRoot("tests/data_tests/background/v_e_scattering/", output_base_tree="treeout", 
                pattern_output="first", output_base_middle_branch = "/e/out",
                leafs = ["out.t", "out.x", "out.y", "out.z", "out._mass"])
print(file.data)
print(file.files_dir)


# Finally, the reading can also be done to all the files in a given directory recursively. In the example below, it is
#   something like tests/data_tests/background/dir1/file1.root, tests/data_tests/background/dir2/file1.root,
#   tests/data_tests/background/file1.root
print("\n" * 2)
print("*" * 50)
print("Read background all the root found walking through all the directories in the directory specified")
file = ReadRoot("tests/data_tests/background/", output_base_tree="treeout", 
                pattern_output="first", output_base_middle_branch = "/e/out",
                leafs = ["out.t", "out.x", "out.y", "out.z", "out._mass"], recursive=True)
print(file.data)

Othe utils.

# Extract param names and values, along with particl type (check Constants class for the last)

name = "tests/data_tests/signal/eta_decay_events_mk_0.014980679431428716_eps2_3.883209914996183e-10.lhe"
read_file = ReadLhe(name)
res_dict = read_file.extract_params_from_path()

print("\n" * 2)
print("*" * 50)
print("Read momenta of set of files")
# Scan data
file_manipulator = FilesManipulator("tests/data_tests/signal/*.lhe", var_of_interest=['e', 'px', 'py', 'pz'])
file_manipulator.fill_up_scan()
print(file_manipulator.scan)

print("\n" * 2)
print("*" * 50)
print("Save scan of files")
from os.path import exists
save_file = "tests/data_tests/signal/signal.pickle"
file_manipulator.save_scan(save_file)
print("file " + save_file + " exists?", "yes" if exists(save_file) else "no")

Release files for nndm-library 0.0.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nndm-library 0.0.26
File Size Uploaded
nndm-library-0.0.26.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nndm-library 0.0.26
File Interpreter ABI Platform
nndm_library-0.0.26-py3-none-any.whl Python 3 none any Details

Total release size: 22.8 kB

Release files / nndm-library-0.0.26.tar.gz

Download URL nndm-library-0.0.26.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5e59217c2c3f024f62abb64a14a81fbd3a6c9d0cb50daa62e2ddbb4b6379b85a
BLAKE2b-256 checksum
How to use checksums
8bea39f79708b8e27f6c3faacfe5edf6581a5bfce181c7e644c72ecac2e5bdb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.8

Release files / nndm_library-0.0.26-py3-none-any.whl

Download URL nndm_library-0.0.26-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d541a6199deaf8997107b43786600013d0dc52c989fa95c0ed76a78a61325708
BLAKE2b-256 checksum
How to use checksums
0a0670f60d821cf9ac2cbf3b01e2be07e494ea14050fd3cbbcd3223888a59170
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.0.26 This release

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page