pueoAnalysisTools
Loading...
Searching...
No Matches
initialise.py
Go to the documentation of this file.
1r"""!
2@file initialise.py
3@brief `main()` shows how to use [load_pueoEvent_Dataset()](#initialise.load_pueoEvent_Dataset),
4 **start here!**.
5
6* The script will first load the library `libpueoEvent.so` in `$PUEO_UTIL_INSTALL_DIR` as soon as you
7 `import` it, even if you don't call the function
8 [load_pueoEvent_Dataset()](#initialise.load_pueoEvent_Dataset),
9 since the loading is done at the global scope.
10 @note no need to set `LD_LIBRARY_PATH`
11
12* As the script tries to load the library, it could error out if the library cannot be found,
13 or if `$PUEO_UTIL_INSTALL_DIR` is not set
14
15* The checks are done via `assert`s, which attempt to provide more meaningful error messages.
16 You can turn them off by running
17 ```
18 python3 -O initialise.py
19 ``` instead of
20 ```
21 python3 initialise.py
22 ```
23 which turns on optimzation.
24
25* P.S. `initialise.py` with an "s" because I like to be annoying.
26"""
27
28import os
29import ROOT
30from pathlib import Path
31
32puid = Path(os.environ["PUEO_UTIL_INSTALL_DIR"])
33assert puid.exists() and not puid == Path("."), "$PUEO_UTIL_INSTALL_DIR has not been set"
34
35# could be in lib or lib64, get the first match
36library_path = next(Path(puid).rglob("lib*/libpueoEvent.so"), None)
37assert library_path is not None, "failed to find libpueoEvent.so in your $PUEO_UTIL_INSTALL_DIR"
38
39ROOT.gSystem.Load(str(library_path))
40
41
42def load_pueoEvent_Dataset(run_number: int, MC=False) -> ROOT.pueo.Dataset:
43 """!Loads the "dual output" dataset whose interface is defined in
44 [pueoEvent](https://github.com/PUEOCollaboration/pueoEvent) repository.
45
46 @param[in] run_number **Must** be discoverable inside @p pueo_mc_data,
47 else an assertion will cause the function to error out.
48 @param[in] MC MC or real data
49 @retval dataset An instance of the class
50 [Dataset](https://github.com/PUEOCollaboration/pueoEvent/blob/main/src/pueo/Dataset.h)
51
52 * Some other functions (eg. #waveform_plots.load_waveforms) require you to
53 **call this function first** to retrive the Dataset instance.
54
55 @note
56 * The "dual output" parallels the "main output" of `simulatePueo`, namely the IceFinal files
57 `IceFinal_<run_number>_allTree.root`.
58 * The dual ouput files mimic the real PUEO data format.
59 * ie. they are the `SimulatedPueo*File<run_number>.root` that live alongside the IceFinal file
60 in the `run<run_number>/` directory.
61 * It might help to check out the
62 [examples](https://github.com/PUEOCollaboration/pueoEvent/tree/main/examples)
63 in the pueoEvent repository.
64
65 * Details:
66 * Technically, as intended by pueoEvent, `PUEO_MC_DATA` or `PUEO_ROOT_DATA` should be an environment variable.
67 * However, `pueo_mc_data` is a `Path` in this function.
68 * It is first used to verify whether
69 `run<run_number>/SimulatedPueoEventFile<run_number>.root` exists.
70 * Then it is used to define a temporary environment variable within the python process,
71 which will not persist beyond the program.
72 * In short, by using this script you are **not** actually using, nor affecting,
73 the environment variable `PUEO_MC_DATA` which you might have defined in your `.bashrc`.
74
75 """
76 if MC:
77 dataset = ROOT.pueo.Dataset(run_number, ROOT.pueo.Dataset.PUEO_MC_DATA)
78 if not MC:
79 dataset = ROOT.pueo.Dataset(run_number, ROOT.pueo.Dataset.PUEO_ROOT_DATA)
80 return dataset
81
82
83if __name__ == "__main__":
84 d = load_pueoEvent_Dataset(run_number=797, MC=False)