Skip to content

BES3 Data Reading

Read ROOT files (rtraw, dst, rec)

To enable uproot to read BES3 ROOT files, import pybes3 before opening any file:

>>> import pybes3
>>> import uproot

Then, open file using uproot:

>>> f = uproot.open("test.rtraw")
>>> evt = f["Event"]

Print information about this event tree:

>>> evt.show(name_width=30)
name                           | typename                 | interpretation
-------------------------------+--------------------------+-------------------------------
TEvtHeader                     | TEvtHeader               | AsGroup(<TBranchElement 'TE...
TEvtHeader/TObject             | unknown                  | <UnknownInterpretation 'non...
TEvtHeader/m_eventId           | int32_t                  | AsDtype('>i4')
TEvtHeader/m_runId             | int32_t                  | AsDtype('>i4')
...
TMcEvent                       | TMcEvent                 | AsGroup(<TBranchElement 'TM...
TMcEvent/TObject               | unknown                  | <UnknownInterpretation 'non...
TMcEvent/m_mdcMcHitCol         | TMdcMc                   | AsBes3(TObjArray[TMdcMc])
TMcEvent/m_emcMcHitCol         | TEmcMc                   | AsBes3(TObjArray[TEmcMc])
TMcEvent/m_tofMcHitCol         | TTofMc                   | AsBes3(TObjArray[TTofMc])
TMcEvent/m_mucMcHitCol         | TMucMc                   | AsBes3(TObjArray[TMucMc])
TMcEvent/m_mcParticleCol       | TMcParticle              | AsBes3(TObjArray[TMcParticle])
TDigiEvent                     | TDigiEvent               | AsGroup(<TBranchElement 'TD...
TDigiEvent/TObject             | unknown                  | <UnknownInterpretation 'non...
TDigiEvent/m_fromMc            | bool                     | AsDtype('bool')
TDigiEvent/m_mdcDigiCol        | TMdcDigi                 | AsBes3(TObjArray[TMdcDigi])
...

Reading sub-trees

To read TMcEvent (note: use arrays() instead of array() here):

>>> mc_evt = evt["TMcEvent"].arrays()
>>> mc_evt.fields
['m_mdcMcHitCol', 'm_emcMcHitCol', 'm_tofMcHitCol', 'm_mucMcHitCol', 'm_mcParticleCol']

Now go to event 0:

>>> evt0 = mc_evt[0]
>>> evt0.m_mcParticleCol.m_particleID
<Array [23, 4, -4, 91, 443, 11, ..., 111, 211, -211, 22, 22] type='12 * int32'>

>>> mc_evt[0].m_mcParticleCol.m_eInitialMomentum
<Array [3.1, 1.55, 1.55, 3.1, ..., 1.23, 0.178, 1.28] type='12 * float64'>

This indicates that event 0 contains 12 MC particles. Their PDGIDs are 23, 4, -3, ... and initial energies are 3.1, 1.55, 1.55, ... (GeV).

Reading specific branches

Tip

It is recommended to read only the branches you need for better performance.

To read a specific branch (note: use array() instead of arrays() here):

>>> pdgid_arr = evt["TMcEvent/m_mcParticleCol/m_particleID"].array()
>>> e_init_arr = evt["TMcEvent/m_mcParticleCol/m_eInitialMomentum"].array()

or retrieve branches from mc_evt:

>>> pdgid_arr = mc_evt["m_mcParticleCol/m_particleID"].array()
>>> e_init_arr = mc_evt["m_mcParticleCol/m_eInitialMomentum"].array()

Read raw data files

BES3 raw data files contain only digit information. To read a raw data file, use pybes3.open_raw:

>>> import pybes3 as p3
>>> reader = p3.open_raw("/bes3fs/offline/data/raw/round17/231117/run_0079017_All_file001_SFO-1.raw")
>>> reader
BesRawReader
- File: /bes3fs/offline/data/raw/round17/231117/run_0079017_All_file001_SFO-1.raw
- Run Number: 79017
- Entries: 100112
- File Size: 2010 MB

To read all data:

>>> all_digi = reader.arrays()
>>> all_digi
<Array [{evt_header: {...}, ...}, ..., {...}] type='100112 * {evt_header: {...'>
>>> all_digi.fields
['evt_header', 'mdc', 'tof', 'emc', 'muc']
>>> all_digi.mdc.fields
['id', 'adc', 'tdc', 'overflow']

To read only specific sub-detectors:

>>> mdc_tof_digi = reader.arrays(sub_detectors=['mdc', 'tof']) # 'emc', 'muc' are also available
>>> mdc_tof_digi.fields
['evt_header', 'mdc', 'tof']

To read a portion of the file:

>>> some_digi = reader.arrays(n_blocks=1000)
>>> some_digi
<Array [{evt_header: {...}, ...}, ..., {...}] type='1000 * {evt_header: {ev...'>

Info

n_blocks is used instead of n_entries because only data blocks are contiguous in memory. In most cases, there is one event per data block.

Warning

Currently, besio can only read original raw digi data without any T-Q matching or post-processing.