Analysis-oriented interface
A higher-level view of the same data: events, antennas and showers as objects, without the caller handling ROOT trees directly.
grand.aoi.event
- grand.aoi.event.GPS_ANTENNA_ORIGIN = (40.95068711, 93.96977396, 1200.0)
Origin (latitude, longitude, height) of the GRANDCS frame in which
Event.fill_antennas()places GP300, GP80 and GP13 antennas computed from their GPS positions. It was an unnamed literal. It is not the run’sorigin_geoid– (40.98456, 93.95225, 1200) in the GP80 files, about 3.8 km away – and nothing records why this point was chosen; which of the two the positions should use is open for the data owners (#215).Event.antennas_originsays which origin an event’s positions are in.
- grand.aoi.event.profile(func)[source]
Returns func unchanged, standing in for
line_profiler.profile.line_profileris an optional development dependency, so the decorator has to keep working when it is absent.- Parameters:
func (callable) – The function that would have been profiled.
- Returns:
funcitself, unmodified.- Return type:
callable
- Event(_file: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, _directory: ~grand.dataio.data_handling.DataDirectory = None, event_number: int = None, run_number: int = None, _entry_number: int = None, antennas: list = None, _all_antennas: dict = None, _all_antennas_key: tuple = None, voltages: list = None, efields: list = None, shower: Shower(primary_type='', energy_em=0, energy_primary=0, Xmax=0, _Xmaxpos=CartesianRepresentation([[0.],
- [0.],
- [0.]]), azimuth=0, zenith=0, magnetic_field=array([0., 0., 0.]), _origin_geoid=CartesianRepresentation([[0.],
- [0.],
- [0.]]), _core_ground_pos=CartesianRepresentation([[0.],
- [0.],
- [0.]])) = None, simshower: Shower(primary_type='', energy_em=0, energy_primary=0, Xmax=0, _Xmaxpos=CartesianRepresentation([[0.],
- [0.],
- [0.]]), azimuth=0, zenith=0, magnetic_field=array([0., 0., 0.]), _origin_geoid=CartesianRepresentation([[0.],
- [0.],
- [0.]]), _core_ground_pos=CartesianRepresentation([[0.],
- [0.],
- [0.]])) = None, antennas_origin: tuple = None, gps_origin: object = None, L: int = 0, t_vector: ~numpy.ndarray = <factory>, is_reconstructed: bool = False, is_wave: bool = False, origin_planewave: ~numpy.ndarray = <factory>, chi2_planewave: ~numpy.ndarray = <factory>, origin_sphere: ~numpy.ndarray = <factory>, chi2_sphere: ~numpy.ndarray = <factory>, is_eas: bool = False, run_mode: ~numpy.uint32 = 0, data_source: str = 'other', data_generator: str = 'GRANDlib', data_generator_version: str = '0.1.0', site: str = 'DummySite', _origin_geoid: ~grand.geo.coordinates.CartesianRepresentation = <factory>, _t_bin_size: int = 2, trun: ~grand.dataio.run_trees.TRun = None, trunrawvoltage: ~grand.dataio.run_trees.TRunRawVoltage = None, tvoltage: ~grand.dataio.event_trees.TVoltage = None, tefield: ~grand.dataio.event_trees.TEfield = None, tshower: ~grand.dataio.event_trees.TShower = None, tsimshower: ~grand.dataio.event_trees.TShower = None, file_trun: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, file_trunrawvoltage: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, file_tvoltage: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, file_tefield: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, file_tshower: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, file_tsimshower: <_ROOTMock name='mock.TFile' id='140595425037296'> = None, is_starshape: bool = False, auto_file_close: bool = True, _run_trees: list = None, _event_trees: list = None, _trees: list = None, tefield_level: int = None, _pending_writes: list = None)
Bases:
CheckedFieldsA class for holding an event
- Parameters:
event_number (int) – The current event in the file number
run_number (int) – The run number of the current event
antennas (list) – Antennas participating in the event
voltages (list) – Voltages from different antennas
efields (list) – Efields from different antennas
shower (Shower()) – Reconstructed shower
simshower (Shower()) – Simulated shower for simulations
antennas_origin (tuple) – (latitude, longitude, height) of the GRANDCS frame the positions in
antennasare given in: the run’sorigin_geoid, orGPS_ANTENNA_ORIGINfor positions computed from GPS.gps_origin (object) – Origin for antenna positions computed from GPS (GP300, GP80, GP13): None for
GPS_ANTENNA_ORIGIN,"run"for the run’sorigin_geoid, or(latitude, longitude, height). Which one the data intend is for their owners to say; the default keeps the positions as they were.L (int) – Event multiplicity
t_vector (np.ndarray) – Time vector - from the start of singla in first DU to the end in last DU
is_reconstructed (bool) – Was this event reconstructed
is_wave (bool) – Is this event associated to a single wave based on reconstruction
origin_planewave (np.ndarray) – Vector of origin of plane wave fit
chi2_planewave (np.ndarray) – Chi2 of plane wave fit
origin_sphere (np.ndarray) – Position of the source according to spherical fit
chi2_sphere (np.ndarray) – Chi2 of spherical fit
is_eas (bool) – Is this an EAS?
run_mode (np.uint32) – Run mode - calibration/test/physics.
data_source (str) – Data source, detector, sim, other
data_generator (str) – Data generator, gtot (in this case)
data_generator_version (str) – Generator version, gtot version (in this case)
site (str) – Site name
trun (TRun) – DOI’s TRun tree containing all run information
trunrawvoltage (TRunRawVoltage) – DOI’s TRunRawVoltage tree containing voltage run information
tvoltage (TVoltage) – DOI’s TVoltage/TRawVoltage tree containing voltage information
tefield (TEfield) – DOI’s TEfield tree containing Efield information
tshower (TShower) – DOI’s TShower tree containing reconstructed shower information
tsimshower (TShower) – DOI’s TShower tree containing simulated shower information
file_trun (ROOT.TFile) – TRun file
file_trunrawvoltage (ROOT.TFile) – TRunRawVoltage file
file_tvoltage (ROOT.TFile) – TVoltage file
file_tefield (ROOT.TFile) – TEfield file
file_tshower (ROOT.TFile) – TShower file
file_tsimshower (ROOT.TFile) – TSimShower file
is_starshape (bool) – Is this event a star shape?
auto_file_close (bool) – Close files automatically after event write? - slower writing but less maitanance by the user
tefield_level (int) – Analysis level of the Efield tree to read (
tefield_l<level>); None takes the directory’s default
- Event.shower: Shower(primary_type='', energy_em=0, energy_primary=0, Xmax=0, _Xmaxpos=CartesianRepresentation([[0.0], [0.0], [0.0]]), azimuth=0, zenith=0, magnetic_field=array([0.0, 0.0, 0.0]), _origin_geoid=CartesianRepresentation([[0.0], [0.0], [0.0]]), _core_ground_pos=CartesianRepresentation([[0.0], [0.0], [0.0]])) = None
Reconstructed shower
- Event.simshower: Shower(primary_type='', energy_em=0, energy_primary=0, Xmax=0, _Xmaxpos=CartesianRepresentation([[0.0], [0.0], [0.0]]), azimuth=0, zenith=0, magnetic_field=array([0.0, 0.0, 0.0]), _origin_geoid=CartesianRepresentation([[0.0], [0.0], [0.0]]), _core_ground_pos=CartesianRepresentation([[0.0], [0.0], [0.0]])) = None
Simulated shower for simulations
- Event.antennas_origin: tuple = None
(latitude, longitude, height) of the GRANDCS frame the positions in
antennasare given in: the run’sorigin_geoid, orGPS_ANTENNA_ORIGINfor positions computed from GPS.
- Event.gps_origin: object = None
Origin for antenna positions computed from GPS (GP300, GP80, GP13): None for
GPS_ANTENNA_ORIGIN,"run"for the run’sorigin_geoid, or(latitude, longitude, height). Which one the data intend is for their owners to say; the default keeps the positions as they were.
- Event.run_mode: uint32 = 0
Run mode - calibration/test/physics.
- Event.trunrawvoltage: TRunRawVoltage = None
DOI’s TRunRawVoltage tree containing voltage run information
- Event.file_trun: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
TRun file
- Event.file_trunrawvoltage: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
TRunRawVoltage file
- Event.file_tvoltage: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
TVoltage file
- Event.file_tefield: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
TEfield file
- Event.file_tshower: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
TShower file
- Event.file_tsimshower: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
TSimShower file
- Event.auto_file_close: bool = True
Close files automatically after event write? - slower writing but less maitanance by the user
- Event.tefield_level: int = None
Analysis level of the Efield tree to read (
tefield_l<level>); None takes the directory’s default
- property Event.file
A single file that contains all the TTrees
- Returns:
Path of the file this event was read from or will be written to.
- Return type:
- property Event.directory
The directory the event’s trees were read from
- Returns:
The directory, or None when the event was read from one file.
- Return type:
DataDirectory or None
- property Event.origin_geoid
Origin of the array frame
- Returns:
Latitude and longitude in degrees and height in meters, as x, y and z;
np.ravelgives three numbers.- Return type:
CartesianRepresentation, shape (3, 1)
- Event.fill_event_from_trees(event_number=None, run_number=None, entry_number=None, simshower=False, use_trawvoltage=False, trawvoltage_channels=[0, 1, 2], init_trees=True, gp300_workaround=True, tefield_level=None)[source]
Fill this event from trees
- Parameters:
event_number (int, optional) – Event number.
run_number (int, optional) – Run number.
entry_number (int, optional) – Entry index, instead of the pair above.
simshower (bool, optional) – Read the simulator-only shower tree.
use_trawvoltage (bool, optional) – Read raw voltages rather than calibrated ones.
trawvoltage_channels (sequence, optional) – Channels to read.
init_trees (bool, optional) – Open the trees before reading.
gp300_workaround (bool, optional) – Apply the GP300 antenna-ordering workaround.
tefield_level (int, optional) – Analysis level of the electric-field tree to read. The level is recorded in the tree’s metadata rather than in its name, so choosing one means choosing a file and needs directory to be set. Without one, the level of the open file is checked against this. None reads whatever is there.
- Returns:
True when the event was found and populated.
- Return type:
- Raises:
ValueError – When tefield_level names a level the data does not hold. Reading a different level than the one asked for would not be visible to the caller, so it is refused instead.
- Event.fill_event_from_runtree(run_entry_number=None)[source]
Populates the run-level fields from the run tree.
- Event.fill_event_from_runrawvoltagetree(run_entry_number=None)[source]
Populates the run-level voltage fields from the raw-voltage run tree.
- Event.fill_antennas(gp300_workaround=True)[source]
Fill event’s antennas
- Parameters:
gp300_workaround (bool, optional) – Apply the GP300 antenna-ordering workaround.
- Event.fill_event_from_voltage_tree(use_trawvoltage=False, trawvoltage_channels=(0, 1, 2))[source]
Populates the voltage traces from the voltage tree.
- Event.fill_event_from_efield_tree()[source]
Populates this event from the electric-field tree.
- Returns:
True when the tree held data for this event.
- Return type:
- Event.fill_event_from_shower_tree(simshower=False)[source]
Populates the shower parameters from the shower tree.
- Event.write(common_filename=None, shower_filename=None, efields_filename=None, voltages_filename=None, run_filename=None, overwrite=False, out_dir=None)[source]
Writes the whole event out, one file per tree kind.
- Parameters:
common_filename (str, optional) – Single destination for every tree. When given, the per-tree names below are ignored.
shower_filename (str, optional) – Individual destinations for each tree.
efields_filename (str, optional) – Individual destinations for each tree.
voltages_filename (str, optional) – Individual destinations for each tree.
run_filename (str, optional) – Individual destinations for each tree.
overwrite (bool, optional) – Replace what this event’s trees would add to: with file names, the trees of those names in those files; with
out_dir, the files of those tree kinds in that directory. Nothing else is removed. Without it, the event is added to what is there.out_dir (str, optional) – Directory to write into.
- Raises:
ValueError – If neither
out_dirnor a file name is given: writing back into the files the event was read from is not supported.
Notes
Writing never changes the trees this event was read from, so the event, and the
EventListit came from, can still be used afterwards. Only the trees with a file name, explicit or throughcommon_filename, are written.
- Event.write_efields(filename, overwrite=False)[source]
Writes the electric-field traces to a ROOT file.
- Event.write_shower(filename, overwrite=False, tree_name='tshower')[source]
Writes the shower parameters to a ROOT file.
- Event.fill_run_tree(overwrite=False, filename=None)[source]
Fills the run tree from this event’s contents, ready to be written.
- Event.fill_voltage_tree(overwrite=False, filename=None)[source]
Fills the voltage tree from this event’s contents, ready to be written.
- Event.fill_efield_tree(overwrite=False, filename=None)[source]
Fills the electric-field tree from this event’s contents, ready to be written.
- Event.fill_shower_tree(overwrite=False, filename=None, tree_name='tshower')[source]
Fills the shower tree from this event’s contents.
- Event.close_files()[source]
Writes and closes the files of the trees written with auto_file_close False.
Only trees this event filled for writing are written: the trees it was read from, and so the input files, are left untouched.
- Event.fill_t_vector(resolution=1)[source]
Fills the event’s time vector with resolution resolution
- Parameters:
resolution (float, optional) – Time step of the common axis, in nanoseconds.
- Event.get_voltage_at_time(t)[source]
Get the voltage signal value in all the DUs at the given time
- Parameters:
t (float) – Time, in nanoseconds.
- Returns:
Voltage of each unit at that time.
- Return type:
ndarray
- Event.get_efield_at_time(t)[source]
Get the efield signal value in all the DUs at the given time
- Parameters:
t (float) – Time, in nanoseconds.
- Returns:
Electric field of each unit at that time.
- Return type:
ndarray
grand.aoi.event_list
- class grand.aoi.event_list.EventList(inp_name, start_event=None, start_entry=None, tefield_level=None, gps_origin=None, **kwargs)[source]
Bases:
objectA class giving access/iteration over multiple events
Every call to
get_event(), and every step of an iteration, fills and returns the sameEventobject, solist(EventList(d))holds that one object several times, showing the last event. Copy what you need from each event before reading the next.See also
grand.aoi.event.EventThe event each iteration gives.
grand.dataio.data_handling.DataDirectoryThe trees of a folder, without joining them into events.
Examples
Loop over the events of a simulation folder. The same
Eventobject is reused, so copy out what you need rather than keepingevent:from pathlib import Path import grand from grand.aoi.event_list import EventList sample = (Path(grand.__file__).parents[1] / "sim2root/Common/sim_Xiaodushan_20221026_000000_RUN1_CD_ZHAireS_0000") for event in EventList(str(sample)): print("event %5d: zenith %5.2f deg, %2d antennas" % (event.event_number, event.simshower.zenith, len(event.antennas)))
event 13790: zenith 79.43 deg, 44 antennas event 1618: zenith 51.64 deg, 5 antennas
- directory: DataDirectory = None
The instance of the directory with files with TTrees containing the event.
- file: <_ROOTMock name='mock.TFile' id='140595425037296'> = None
The instance of the file with TTrees containing the event.
- get_event(event_number=None, run_number=None, entry_number=None, fill_event=True, **kwargs)[source]
Get specified event from the event list
- Parameters:
- Returns:
The event.
- Return type:
Event
- Raises:
ValueError – If both an entry and an event/run number are given, or a run number without an event number.
LookupError – If the input holds no such event.
grand.aoi.antenna
- class grand.aoi.antenna.Antenna(id: int = -1, _position: CartesianRepresentation = <factory>, _tilt: CartesianRepresentation = <factory>, _acceleration: CartesianRepresentation = <factory>, model: Any = 0)[source]
Bases:
CheckedFieldsA class describing a single antenna
- Parameters:
id (int) – Antenna ID - the du_id from the trees
model (Any) – The antenna model
- property position
Antenna position in the array frame (GRANDCS), in meters.
x runs north (magnetic), y west and z up, from the frame’s origin; z is relative to the origin’s height, not to sea level. The origin is the event’s
antennas_origin.- Returns:
The position;
np.ravel(position)gives three numbers.- Return type:
CartesianRepresentation, shape (3, 1)
- property tilt
Antenna tilt
- Returns:
Tilt angles, in degrees.
- Return type:
ndarray
- property acceleration
Antenna acceleration - this comes from hardware.
- Returns:
Measured acceleration components.
- Return type:
ndarray
grand.aoi.shower
- class grand.aoi.shower.Shower(primary_type: str = '', energy_em: float = 0, energy_primary: float = 0, Xmax: float = 0, _Xmaxpos: CartesianRepresentation = <factory>, azimuth: float = 0, zenith: float = 0, magnetic_field: ndarray = <factory>, _origin_geoid: CartesianRepresentation = <factory>, _core_ground_pos: CartesianRepresentation = <factory>)[source]
Bases:
CheckedFieldsA class for holding a shower
- Parameters:
primary_type (str) – Shower primary particle type, such as proton, Fe, etc.
energy_em (float) – Shower from e+- (ie related to radio emission) (GeV)
energy_primary (float) – Total energy of the primary (including muons, neutrinos, …) (GeV)
Xmax (float) – Shower Xmax [g/cm2]
azimuth (float) – Shower azimuth, in degrees, from north toward west (NWU frame, origin at the core); the direction the shower comes from, as in
TShowerzenith (float) – Shower zenith, in degrees (NWU frame, origin at the core); the direction the shower comes from, as in
TShowermagnetic_field (np.ndarray) – Magnetic field parameters: Inclination, Declination, modulus
- azimuth: float = 0
Shower azimuth, in degrees, from north toward west (NWU frame, origin at the core); the direction the shower comes from, as in
TShower
- zenith: float = 0
Shower zenith, in degrees (NWU frame, origin at the core); the direction the shower comes from, as in
TShower
- property Xmaxpos
Shower position in the site’s reference frame
- Returns:
Position of shower maximum, in meters (x north, y west, z up).
- Return type:
CartesianRepresentation, shape (3, 1)
- property origin_geoid
Origin of the array frame the shower’s positions are in
- Returns:
Latitude and longitude in degrees and height in meters, as x, y and z.
- Return type:
CartesianRepresentation, shape (3, 1)
- property core_ground_pos
Position of the core on the ground in the site’s reference frame
- Returns:
Shower core position at ground, in meters (x north, y west, z up).
- Return type:
CartesianRepresentation, shape (3, 1)
grand.aoi.timetrace
- class grand.aoi.timetrace.Timetrace3D(n_points: int = 0, time_step: float = 0, t0: datetime64 = <factory>, trigger_time: datetime64 = <factory>, t_bin_size: float = 2, du_id: int = -1, _trace: CartesianRepresentation = <factory>, t_vector: ndarray = <factory>, _hilbert_trace: CartesianRepresentation = <factory>)[source]
Bases:
CheckedFieldsA class for holding x,y,z single antenna traces over time
- Parameters:
n_points (int) – The trace length
time_step (float) – [ns] n_points x step = total timetrace length
t0 (np.datetime64) – Start time of the trace as unix time with nanoseconds
trigger_time (np.datetime64) – Trigger time as unix time with nanoseconds
t_bin_size (float) – The size of the time bin - the time resolution in ns
du_id (int) – The Detector Unit ID
t_vector (np.ndarray) – The time vector [ns] - generated from the trace length, t0 and t_bin_size
- t0: datetime64
Start time of the trace as unix time with nanoseconds
- trigger_time: datetime64
Trigger time as unix time with nanoseconds
- calculate_t_vector(time_offset)[source]
Calculation of the time vector - should be called manually when all the necessary parameters of the Timetrace3D are set
- Parameters:
time_offset (float) – Subtracted from
t0to give the time of the first sample, in nanoseconds. Required.
- get_value_at_time(time_offset)[source]
Get the signal value at a certain time. Returns 0, if nothing measured at this time
- Parameters:
time_offset (float) – The time, in nanoseconds, on the axis of
t_vector. (The docstring called itt.)- Returns:
The three components at the sample whose time equals time_offset exactly – there is no interpolation – or zeros if no sample falls at that time.
- Return type:
ndarray, shape (3,)
- get_hilbert_value_at_time(time_offset)[source]
Get the signal Hilbert envelope’s value at a certain time. Returns 0, if nothing measured at this time
- Parameters:
time_offset (float) – The time, in nanoseconds, on the axis of
t_vector. (The docstring called itt.)- Returns:
The three components at the sample whose time equals time_offset exactly – there is no interpolation – or zeros if no sample falls at that time.
- Return type:
ndarray, shape (3,)
- property trace
Trace 3D vector (x,y,z)
- Returns:
The three-component trace.
- Return type:
ndarray, shape (3, n_samples)
- property hilbert_trace
Hilbert envelope 3D vector (x,y,z) - not defined in the hardware
- Returns:
Its Hilbert envelope.
- Return type:
ndarray, shape (3, n_samples)
- class grand.aoi.timetrace.Voltage(n_points: int = 0, time_step: float = 0, t0: datetime64 = <factory>, trigger_time: datetime64 = <factory>, t_bin_size: float = 2, du_id: int = -1, _trace: CartesianRepresentation = <factory>, t_vector: ndarray = <factory>, _hilbert_trace: CartesianRepresentation = <factory>, is_triggered: bool = True)[source]
Bases:
Timetrace3DA class for holding voltage traces + additional information
- Parameters:
n_points (int) – The trace length
time_step (float) – [ns] n_points x step = total timetrace length
t0 (np.datetime64) – Start time of the trace as unix time with nanoseconds
trigger_time (np.datetime64) – Trigger time as unix time with nanoseconds
t_bin_size (float) – The size of the time bin - the time resolution in ns
du_id (int) – The Detector Unit ID
t_vector (np.ndarray) – The time vector [ns] - generated from the trace length, t0 and t_bin_size
is_triggered (bool) – Is this a triggered trace? - not sure if it should be here or in Timetrace3D, or perhaps further up in the event
- class grand.aoi.timetrace.Efield(n_points: int = 0, time_step: float = 0, t0: datetime64 = <factory>, trigger_time: datetime64 = <factory>, t_bin_size: float = 2, du_id: int = -1, _trace: CartesianRepresentation = <factory>, t_vector: ndarray = <factory>, _hilbert_trace: CartesianRepresentation = <factory>, eta: float = 0, a_ratio: float = 0)[source]
Bases:
Timetrace3DA class for holding Efield traces + additional information
- Parameters:
n_points (int) – The trace length
time_step (float) – [ns] n_points x step = total timetrace length
t0 (np.datetime64) – Start time of the trace as unix time with nanoseconds
trigger_time (np.datetime64) – Trigger time as unix time with nanoseconds
t_bin_size (float) – The size of the time bin - the time resolution in ns
du_id (int) – The Detector Unit ID
t_vector (np.ndarray) – The time vector [ns] - generated from the trace length, t0 and t_bin_size
eta (float) – Polarization angle of the reconstructed Efield in the shower plane [deg]
a_ratio (float) – Ratio of the geomagnetic to charge excess contributions