Skip to content

pybes3.digi_id

Warning

The pybes3.digi_id module is deprecated and will be removed in a future release. Use the pybes3.identifier module instead.

Parsing methods

These methods parse the given ID and return the corresponding components. They are useful for retrieving the components of an ID when you only have the ID itself.

parse_mdc_digi(mdc_digi, with_pos=False)

Parse MDC raw digi array. The raw digi array should contain [m_intId, m_timeChannel, m_chargeChannel, m_trackIndex, m_overflow] fields.

Fields of the output:

  • gid: Global ID of the wire.
  • wire: Local wire number.
  • layer: Layer number.
  • stereo: Stereo type. 0 for axial, -1 for phi_west < phi_east, 1 for phi_west > phi_east.
  • is_stereo: Whether the wire is a stereo wire.
  • superlayer: Superlayer number.
  • charge_channel: Charge channel.
  • time_channel: Time channel.
  • track_index: Track index.
  • overflow: Overflow flag.
  • digi_id: Raw digi ID.

Optional fields of the output when with_pos is True:

  • mid_x: x position of the wire at z=0.
  • mid_y: y position of the wire at z=0.
  • west_x: x position of the west end of the wire.
  • west_y: y position of the west end of the wire.
  • west_z: z position of the west end of the wire.
  • east_x: x position of the east end of the wire.
  • east_y: y position of the east end of the wire.
  • east_z: z position of the east end of the wire.

Parameters:

Name Type Description Default
mdc_digi Record

The MDC raw digi array.

required
with_pos bool

Whether to include the position information.

False

Returns:

Type Description
Record

The parsed MDC digi array.

Source code in src/pybes3/digi_id.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def parse_mdc_digi(mdc_digi: ak.Record, with_pos: bool = False) -> ak.Record:
    """
    Parse MDC raw digi array. The raw digi array should contain [`m_intId`,
    `m_timeChannel`, `m_chargeChannel`, `m_trackIndex`, `m_overflow`] fields.

    Fields of the output:

    - `gid`: Global ID of the wire.
    - `wire`: Local wire number.
    - `layer`: Layer number.
    - `stereo`: Stereo type. 0 for axial, -1 for `phi_west < phi_east`, 1 for `phi_west > phi_east`.
    - `is_stereo`: Whether the wire is a stereo wire.
    - `superlayer`: Superlayer number.
    - `charge_channel`: Charge channel.
    - `time_channel`: Time channel.
    - `track_index`: Track index.
    - `overflow`: Overflow flag.
    - `digi_id`: Raw digi ID.

    Optional fields of the output when `with_pos` is `True`:

    - `mid_x`: x position of the wire at `z=0`.
    - `mid_y`: y position of the wire at `z=0`.
    - `west_x`: x position of the west end of the wire.
    - `west_y`: y position of the west end of the wire.
    - `west_z`: z position of the west end of the wire.
    - `east_x`: x position of the east end of the wire.
    - `east_y`: y position of the east end of the wire.
    - `east_z`: z position of the east end of the wire.

    Parameters:
        mdc_digi: The MDC raw digi array.
        with_pos: Whether to include the position information.

    Returns:
        The parsed MDC digi array.
    """
    gid = parse_mdc_digi_id(mdc_digi["m_intId"], with_pos=with_pos)

    res = {
        "gid": gid["gid"],
        "wire": gid["wire"],
        "layer": gid["layer"],
        "stereo": gid["stereo"],
        "is_stereo": gid["is_stereo"],
        "superlayer": gid["superlayer"],
        "charge_channel": mdc_digi["m_chargeChannel"],
        "time_channel": mdc_digi["m_timeChannel"],
        "track_index": mdc_digi["m_trackIndex"],
        "overflow": mdc_digi["m_overflow"],
        "digi_id": mdc_digi["m_intId"],
    }

    if with_pos:
        res["mid_x"] = gid["mid_x"]
        res["mid_y"] = gid["mid_y"]
        res["west_x"] = gid["west_x"]
        res["west_y"] = gid["west_y"]
        res["west_z"] = gid["west_z"]
        res["east_x"] = gid["east_x"]
        res["east_y"] = gid["east_y"]
        res["east_z"] = gid["east_z"]

    return ak.zip(res)

parse_emc_digi(emc_digi, with_pos=False)

Parse EMC raw digi array. The raw digi array should contain [m_intId, m_timeChannel, m_chargeChannel, m_trackIndex, m_measure] fields.

Fields of the output:

  • gid: Global ID of the crystal.
  • part: Part number, 0 for endcap0, 1 for barrel, 2 for endcap1.
  • theta: Theta number.
  • phi: Phi number.
  • charge_channel: Charge channel.
  • time_channel: Time channel.
  • track_index: Track index.
  • measure: Measure value.
  • digi_id: Raw digi ID.

Optional fields of the output when with_pos is True:

  • front_center_x: x position of the front center of the crystal.
  • front_center_y: y position of the front center of the crystal.
  • front_center_z: z position of the front center of the crystal.
  • center_x: x position of the center of the crystal.
  • center_y: y position of the center of the crystal.
  • center_z: z position of the center of the crystal.

Parameters:

Name Type Description Default
emc_digi Record

The EMC raw digi array.

required
with_pos bool

Whether to include the position information.

False

Returns:

Type Description
Record

The parsed EMC digi array.

Source code in src/pybes3/digi_id.py
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
def parse_emc_digi(emc_digi: ak.Record, with_pos: bool = False) -> ak.Record:
    """
    Parse EMC raw digi array. The raw digi array should contain [`m_intId`,
    `m_timeChannel`, `m_chargeChannel`, `m_trackIndex`, `m_measure`] fields.

    Fields of the output:

    - `gid`: Global ID of the crystal.
    - `part`: Part number, 0 for endcap0, 1 for barrel, 2 for endcap1.
    - `theta`: Theta number.
    - `phi`: Phi number.
    - `charge_channel`: Charge channel.
    - `time_channel`: Time channel.
    - `track_index`: Track index.
    - `measure`: Measure value.
    - `digi_id`: Raw digi ID.

    Optional fields of the output when `with_pos` is `True`:

    - `front_center_x`: x position of the front center of the crystal.
    - `front_center_y`: y position of the front center of the crystal.
    - `front_center_z`: z position of the front center of the crystal.
    - `center_x`: x position of the center of the crystal.
    - `center_y`: y position of the center of the crystal.
    - `center_z`: z position of the center of the crystal.

    Parameters:
        emc_digi: The EMC raw digi array.
        with_pos: Whether to include the position information.

    Returns:
        The parsed EMC digi array.
    """
    gid = parse_emc_digi_id(emc_digi["m_intId"], with_pos=with_pos)

    res = {
        "gid": gid["gid"],
        "part": gid["part"],
        "theta": gid["theta"],
        "phi": gid["phi"],
        "charge_channel": emc_digi["m_chargeChannel"],
        "time_channel": emc_digi["m_timeChannel"],
        "track_index": emc_digi["m_trackIndex"],
        "measure": emc_digi["m_measure"],
        "digi_id": emc_digi["m_intId"],
    }

    if with_pos:
        res["front_center_x"] = gid["front_center_x"]
        res["front_center_y"] = gid["front_center_y"]
        res["front_center_z"] = gid["front_center_z"]
        res["center_x"] = gid["center_x"]
        res["center_y"] = gid["center_y"]
        res["center_z"] = gid["center_z"]

    return ak.zip(res)

parse_mdc_digi_id(mdc_digi_id, with_pos=False)

Parse MDC digi ID.

When mdc_digi_id is an ak.Array, the result is an ak.Array, otherwise it is a dict.

Keys of the output:

  • gid: Global ID of the wire.
  • wire: Local wire number.
  • layer: Layer number.
  • stereo: Stereo type. 0 for axial, -1 for phi_west < phi_east, 1 for phi_west > phi_east.
  • is_stereo: Whether the wire is a stereo wire.
  • superlayer: Superlayer number.

Optional keys of the output when with_pos is True:

  • mid_x: x position of the wire at z=0.
  • mid_y: y position of the wire at z=0.
  • west_x: x position of the west end of the wire.
  • west_y: y position of the west end of the wire.
  • west_z: z position of the west end of the wire.
  • east_x: x position of the east end of the wire.
  • east_y: y position of the east end of the wire.
  • east_z: z position of the east end of the wire.

Parameters:

Name Type Description Default
mdc_digi_id IntLike

The MDC digi ID.

required
with_pos bool

Whether to include the position information.

False

Returns:

Type Description
Array | dict[str, Any]

The parsed result.

Source code in src/pybes3/digi_id.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def parse_mdc_digi_id(
    mdc_digi_id: IntLike,
    with_pos: bool = False,
) -> ak.Array | dict[str, Any]:
    """
    Parse MDC digi ID.

    When `mdc_digi_id` is an `ak.Array`, the result is an `ak.Array`, otherwise it is a `dict`.

    Keys of the output:

    - `gid`: Global ID of the wire.
    - `wire`: Local wire number.
    - `layer`: Layer number.
    - `stereo`: Stereo type. 0 for axial, -1 for `phi_west < phi_east`, 1 for `phi_west > phi_east`.
    - `is_stereo`: Whether the wire is a stereo wire.
    - `superlayer`: Superlayer number.

    Optional keys of the output when `with_pos` is `True`:

    - `mid_x`: x position of the wire at `z=0`.
    - `mid_y`: y position of the wire at `z=0`.
    - `west_x`: x position of the west end of the wire.
    - `west_y`: y position of the west end of the wire.
    - `west_z`: z position of the west end of the wire.
    - `east_x`: x position of the east end of the wire.
    - `east_y`: y position of the east end of the wire.
    - `east_z`: z position of the east end of the wire.

    Parameters:
        mdc_digi_id: The MDC digi ID.
        with_pos: Whether to include the position information.

    Returns:
        The parsed result.
    """
    wire = mdc_id_to_wire(mdc_digi_id)
    layer = mdc_id_to_layer(mdc_digi_id)
    gid = det.get_mdc_gid(layer, wire)
    return det.parse_mdc_gid(gid, with_pos)

parse_emc_digi_id(emc_digi_id, with_pos=False)

Parse EMC digi ID.

When emc_digi_id is an ak.Array, the result is an ak.Array, otherwise it is a dict.

Keys of the output:

  • gid: Global ID of the crystal.
  • part: Part number, 0 for endcap0, 1 for barrel, 2 for endcap1.
  • theta: Theta number.
  • phi: Phi number.

Optional keys of the output when with_pos is True:

  • front_center_x: x position of the front center of the crystal.
  • front_center_y: y position of the front center of the crystal.
  • front_center_z: z position of the front center of the crystal.
  • center_x: x position of the center of the crystal.
  • center_y: y position of the center of the crystal.
  • center_z: z position of the center of the crystal.

Info

The 8 points of the crystal will not be returned here. If you need the 8 points of the crystal, use emc_gid_to_point_x, emc_gid_to_point_y and emc_gid_to_point_z.

Parameters:

Name Type Description Default
emc_digi_id IntLike

The EMC digi ID.

required
with_pos bool

Whether to include the position information.

False

Returns:

Type Description
Array | dict[str, Any]

The parsed EMC digi ID.

Source code in src/pybes3/digi_id.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def parse_emc_digi_id(
    emc_digi_id: IntLike,
    with_pos: bool = False,
) -> ak.Array | dict[str, Any]:
    """
    Parse EMC digi ID.

    When `emc_digi_id` is an `ak.Array`, the result is an `ak.Array`, otherwise it is a `dict`.

    Keys of the output:

    - `gid`: Global ID of the crystal.
    - `part`: Part number, 0 for endcap0, 1 for barrel, 2 for endcap1.
    - `theta`: Theta number.
    - `phi`: Phi number.

    Optional keys of the output when `with_pos` is `True`:

    - `front_center_x`: x position of the front center of the crystal.
    - `front_center_y`: y position of the front center of the crystal.
    - `front_center_z`: z position of the front center of the crystal.
    - `center_x`: x position of the center of the crystal.
    - `center_y`: y position of the center of the crystal.
    - `center_z`: z position of the center of the crystal.

    !!! info
        The 8 points of the crystal will not be returned here.
        If you need the 8 points of the crystal, use `emc_gid_to_point_x`, `emc_gid_to_point_y`
        and `emc_gid_to_point_z`.

    Parameters:
        emc_digi_id: The EMC digi ID.
        with_pos: Whether to include the position information.

    Returns:
        The parsed EMC digi ID.

    """
    part = emc_id_to_module(emc_digi_id)
    theta = emc_id_to_theta(emc_digi_id)
    phi = emc_id_to_phi(emc_digi_id)
    gid = det.get_emc_gid(part, theta, phi)
    return det.parse_emc_gid(gid, with_pos)

parse_tof_digi_id(tof_digi_id, flat=False, library='ak')

Parse TOF digi ID. If library is ak, return ak.Array. If library is np, return dict[str, np.ndarray].

Available keys of the output:

  • part: The part number. 0,1,2 for scintillator endcap0, barrel, endcap1; 3,4 for MRPC endcap0, endcap1.
  • layer_or_module: The scintillator layer or MRPC module number, based on the part number.
  • phi_or_strip: The scintillator phi or MRPC strip ID, based on the part number.
  • end: The readout end ID.

The return value is based on the part number.

Rows where part < 3 are scintillator and layer_or_module represents layer number, phi_or_strip represents phi number.

Rows where part >= 3 are MRPC and layer_or_module represents module number, phi_or_strip represents strip ID.

Parameters:

Name Type Description Default
tof_digi_id IntLike

The TOF ID.

required
flat bool

Whether to flatten the output.

False
library Literal['ak', 'np']

The library to use as output.

'ak'

Returns:

Type Description
Array | dict[str, ndarray] | dict[str, int_]

The parsed TOF ID.

Source code in src/pybes3/digi_id.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
def parse_tof_digi_id(
    tof_digi_id: IntLike,
    flat: bool = False,
    library: Literal["ak", "np"] = "ak",
) -> ak.Array | dict[str, np.ndarray] | dict[str, np.int_]:
    """
    Parse TOF digi ID.
    If `library` is `ak`, return `ak.Array`. If `library` is `np`, return `dict[str, np.ndarray]`.

    Available keys of the output:

    - `part`: The part number. `0,1,2` for scintillator endcap0, barrel, endcap1; `3,4` for MRPC endcap0, endcap1.
    - `layer_or_module`: The scintillator layer or MRPC module number, based on the part number.
    - `phi_or_strip`: The scintillator phi or MRPC strip ID, based on the part number.
    - `end`: The readout end ID.

    The return value is based on the part number.

    Rows where `part < 3` are scintillator and `layer_or_module` represents layer number, `phi_or_strip` represents phi number.

    Rows where `part >= 3` are MRPC and `layer_or_module` represents module number, `phi_or_strip` represents strip ID.

    Parameters:
        tof_digi_id: The TOF ID.
        flat: Whether to flatten the output.
        library: The library to use as output.

    Returns:
        The parsed TOF ID.

    """
    if library not in ["ak", "np"]:
        raise ValueError(f"Unsupported library: {library}")

    if flat and isinstance(tof_digi_id, ak.Array):
        tof_digi_id = ak.flatten(tof_digi_id)

    part = tof_id_to_part(tof_digi_id)
    res = {
        "part": part,
        "layer_or_module": tof_id_to_layer_or_module(tof_digi_id, part),
        "phi_or_strip": tof_id_to_phi_or_strip(tof_digi_id, part),
        "end": tof_id_to_end(tof_digi_id),
    }

    if library == "ak":
        return ak.zip(res)
    else:
        return res

parse_muc_digi_id(muc_digi_id, flat=False, library='ak')

Parse MUC digi ID.

If library is ak, return ak.Array. If library is np, return dict[str, np.ndarray].

Available keys of the output:

  • part: The part number.
  • segment: The segment number.
  • layer: The layer number.
  • channel: The channel number.
  • gap: The gap number, which is equivalent to layer number.
  • strip: The strip number, which is equivalent to channel number.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID.

required
flat bool

Whether to flatten the output.

False
library Literal['ak', 'np']

The library to use as output.

'ak'

Returns:

Type Description
Array | dict[str, ndarray] | dict[str, int_]

The parsed MUC digi ID.

Source code in src/pybes3/digi_id.py
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
def parse_muc_digi_id(
    muc_digi_id: IntLike,
    flat: bool = False,
    library: Literal["ak", "np"] = "ak",
) -> ak.Array | dict[str, np.ndarray] | dict[str, np.int_]:
    """
    Parse MUC digi ID.

    If `library` is `ak`, return `ak.Array`. If `library` is `np`, return `dict[str, np.ndarray]`.

    Available keys of the output:

    - `part`: The part number.
    - `segment`: The segment number.
    - `layer`: The layer number.
    - `channel`: The channel number.
    - `gap`: The gap number, which is equivalent to layer number.
    - `strip`: The strip number, which is equivalent to channel number.

    Parameters:
        muc_digi_id: The MUC digi ID.
        flat: Whether to flatten the output.
        library: The library to use as output.

    Returns:
        The parsed MUC digi ID.
    """
    if library not in ["ak", "np"]:
        raise ValueError(f"Unsupported library: {library}")

    if flat and isinstance(muc_digi_id, ak.Array):
        muc_digi_id = ak.flatten(muc_digi_id)

    part = muc_id_to_part(muc_digi_id)
    segment = muc_id_to_segment(muc_digi_id)
    layer = muc_id_to_layer(muc_digi_id)
    channel = muc_id_to_channel(muc_digi_id)

    res = {
        "part": part,
        "segment": segment,
        "layer": layer,
        "channel": channel,
        "gap": layer,
        "strip": channel,
    }

    if library == "ak":
        return ak.zip(res)
    else:
        return res

parse_cgem_digi_id(cgem_digi_id, flat=False, library='ak')

Parse CGEM digi ID.

If library is ak, return ak.Array. If library is np, return dict[str, np.ndarray].

Available keys of the output:

  • layer: The layer number.
  • sheet: The sheet ID.
  • strip_type: The strip type. 0 for X-strip, 1 for V-strip.
  • strip: The strip ID.

Parameters:

Name Type Description Default
cgem_digi_id IntLike

The CGEM digi ID.

required
flat bool

Whether to flatten the output.

False
library Literal['ak', 'np']

The library to use as output.

'ak'

Returns:

Type Description
Array | dict[str, ndarray] | dict[str, int_]

The parsed CGEM digi ID.

Source code in src/pybes3/digi_id.py
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
def parse_cgem_digi_id(
    cgem_digi_id: IntLike,
    flat: bool = False,
    library: Literal["ak", "np"] = "ak",
) -> ak.Array | dict[str, np.ndarray] | dict[str, np.int_]:
    """
    Parse CGEM digi ID.

    If `library` is `ak`, return `ak.Array`. If `library` is `np`, return `dict[str, np.ndarray]`.

    Available keys of the output:

    - `layer`: The layer number.
    - `sheet`: The sheet ID.
    - `strip_type`: The strip type. 0 for X-strip, 1 for V-strip.
    - `strip`: The strip ID.

    Parameters:
        cgem_digi_id: The CGEM digi ID.
        flat: Whether to flatten the output.
        library: The library to use as output.

    Returns:
        The parsed CGEM digi ID.
    """
    if library not in ["ak", "np"]:
        raise ValueError(f"Unsupported library: {library}")

    if flat and isinstance(cgem_digi_id, ak.Array):
        cgem_digi_id = ak.flatten(cgem_digi_id)

    res = {
        "layer": cgem_id_to_layer(cgem_digi_id),
        "sheet": cgem_id_to_sheet(cgem_digi_id),
        "strip_type": cgem_id_to_strip_type(cgem_digi_id),
        "strip": cgem_id_to_strip(cgem_digi_id),
    }

    if library == "ak":
        return ak.zip(res)
    else:
        return res

MDC

check_mdc_id(mdc_digi_id)

Check if the MDC digi ID is valid.

Parameters:

Name Type Description Default
mdc_digi_id IntLike

The MDC digi ID array or value.

required

Returns:

Type Description
BoolLike

Whether the digi ID is valid.

Source code in src/pybes3/digi_id.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@nb.vectorize(cache=True)
def check_mdc_id(mdc_digi_id: IntLike) -> BoolLike:
    """
    Check if the MDC digi ID is valid.

    Parameters:
        mdc_digi_id: The MDC digi ID array or value.

    Returns:
        Whether the digi ID is valid.
    """
    return (mdc_digi_id & DIGI_FLAG_MASK) >> DIGI_FLAG_OFFSET == DIGI_MDC_FLAG

mdc_id_to_wire(mdc_digi_id)

Convert MDC digi ID to wire number.

Parameters:

Name Type Description Default
mdc_digi_id IntLike

MDC digi ID array or value.

required

Returns:

Type Description
IntLike

The wire number.

Source code in src/pybes3/digi_id.py
104
105
106
107
108
109
110
111
112
113
114
115
@nb.vectorize(cache=True)
def mdc_id_to_wire(mdc_digi_id: IntLike) -> IntLike:
    """
    Convert MDC digi ID to wire number.

    Parameters:
        mdc_digi_id: MDC digi ID array or value.

    Returns:
        The wire number.
    """
    return (mdc_digi_id & DIGI_MDC_WIRE_MASK) >> DIGI_MDC_WIRE_OFFSET

mdc_id_to_layer(mdc_digi_id)

Convert the MDC digi ID to the layer number.

Parameters:

Name Type Description Default
mdc_digi_id IntLike

The MDC digi ID array or value.

required

Returns:

Type Description
IntLike

The layer number.

Source code in src/pybes3/digi_id.py
118
119
120
121
122
123
124
125
126
127
128
129
@nb.vectorize(cache=True)
def mdc_id_to_layer(mdc_digi_id: IntLike) -> IntLike:
    """
    Convert the MDC digi ID to the layer number.

    Parameters:
        mdc_digi_id: The MDC digi ID array or value.

    Returns:
        The layer number.
    """
    return (mdc_digi_id & DIGI_MDC_LAYER_MASK) >> DIGI_MDC_LAYER_OFFSET

mdc_id_to_is_stereo(mdc_digi_id)

Convert the MDC digi ID to whether it is a stereo wire.

Parameters:

Name Type Description Default
mdc_digi_id IntLike

The MDC digi ID array or value.

required

Returns:

Type Description
BoolLike

Whether the wire is a stereo wire.

Source code in src/pybes3/digi_id.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@nb.vectorize(cache=True)
def mdc_id_to_is_stereo(mdc_digi_id: IntLike) -> BoolLike:
    """
    Convert the MDC digi ID to whether it is a stereo wire.

    Parameters:
        mdc_digi_id: The MDC digi ID array or value.

    Returns:
        Whether the wire is a stereo wire.
    """
    return (
        mdc_digi_id & DIGI_MDC_WIRETYPE_MASK
    ) >> DIGI_MDC_WIRETYPE_OFFSET == DIGI_MDC_STEREO_WIRE

get_mdc_digi_id(wire, layer, wire_type)

Generate MDC digi ID based on the wire number, layer number, and wire type.

Parameters:

Name Type Description Default
wire IntLike

The wire number.

required
layer IntLike

The layer number.

required
wire_type IntLike

The wire type.

required

Returns:

Type Description
IntLike

The MDC digi ID.

Source code in src/pybes3/digi_id.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@nb.vectorize(cache=True)
def get_mdc_digi_id(
    wire: IntLike,
    layer: IntLike,
    wire_type: IntLike,
) -> IntLike:
    """
    Generate MDC digi ID based on the wire number, layer number, and wire type.

    Parameters:
        wire: The wire number.
        layer: The layer number.
        wire_type: The wire type.

    Returns:
        The MDC digi ID.
    """
    return np.uint32(
        ((wire << DIGI_MDC_WIRE_OFFSET) & DIGI_MDC_WIRE_MASK)
        | ((layer << DIGI_MDC_LAYER_OFFSET) & DIGI_MDC_LAYER_MASK)
        | ((wire_type << DIGI_MDC_WIRETYPE_OFFSET) & DIGI_MDC_WIRETYPE_MASK)
        | (DIGI_MDC_FLAG << DIGI_FLAG_OFFSET)
    )

TOF

check_tof_id(tof_digi_id)

Check if the TOF digi ID is valid.

Parameters:

Name Type Description Default
tof_digi_id IntLike

The TOF digi ID array or value.

required

Returns:

Type Description
BoolLike

Whether the digi ID is valid.

Source code in src/pybes3/digi_id.py
284
285
286
287
288
289
290
291
292
293
294
295
@nb.vectorize(cache=True)
def check_tof_id(tof_digi_id: IntLike) -> BoolLike:
    """
    Check if the TOF digi ID is valid.

    Parameters:
        tof_digi_id: The TOF digi ID array or value.

    Returns:
        Whether the digi ID is valid.
    """
    return (tof_digi_id & DIGI_FLAG_MASK) >> DIGI_FLAG_OFFSET == DIGI_TOF_FLAG

tof_id_to_part(tof_digi_id)

Convert TOF digi ID to part number. 0, 1, 2 for scintillator endcap0/barrel/endcap1, 3, 4 for MRPC endcap0/endcap1.

Parameters:

Name Type Description Default
tof_digi_id IntLike

TOF digi ID array or value.

required

Returns:

Type Description
IntLike

The part number.

Source code in src/pybes3/digi_id.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
@nb.vectorize(cache=True)
def tof_id_to_part(tof_digi_id: IntLike) -> IntLike:
    """
    Convert TOF digi ID to part number. 0, 1, 2 for scintillator endcap0/barrel/endcap1,
    3, 4 for MRPC endcap0/endcap1.

    Parameters:
        tof_digi_id: TOF digi ID array or value.

    Returns:
        The part number.
    """
    part = (tof_digi_id & DIGI_TOF_PART_MASK) >> DIGI_TOF_PART_OFFSET
    if part == 3:  # += MRPC endcap number
        part += (tof_digi_id & DIGI_TOF_MRPC_ENDCAP_MASK) >> DIGI_TOF_MRPC_ENDCAP_OFFSET
    return part

tof_id_to_end(tof_digi_id)

Convert the TOF digi ID to the readout end number.

Parameters:

Name Type Description Default
tof_digi_id IntLike

The TOF digi ID array or value.

required

Returns:

Type Description
IntLike

The readout end number.

Source code in src/pybes3/digi_id.py
316
317
318
319
320
321
322
323
324
325
326
327
@nb.vectorize(cache=True)
def tof_id_to_end(tof_digi_id: IntLike) -> IntLike:
    """
    Convert the TOF digi ID to the readout end number.

    Parameters:
        tof_digi_id: The TOF digi ID array or value.

    Returns:
        The readout end number.
    """
    return (tof_digi_id & DIGI_TOF_END_MASK) >> DIGI_TOF_END_OFFSET

tof_id_to_layer_or_module(tof_digi_id, part=None)

Convert the TOF digi ID to the scintillator layer or MRPC module number. If part < 3, it is scintillator and the return value is layer number. Otherwise, it is MRPC and the return value is module number.

Parameters:

Name Type Description Default
tof_digi_id IntLike

The TOF digi ID array or value.

required
part IntLike | None

The part number. If not provided, it will be calculated based on the TOF digi ID.

None

Returns:

Type Description
IntLike

The scintillator layer or MRPC module number.

Source code in src/pybes3/digi_id.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
def tof_id_to_layer_or_module(
    tof_digi_id: IntLike,
    part: IntLike | None = None,
) -> IntLike:
    """
    Convert the TOF digi ID to the scintillator layer or MRPC module number.
    If `part < 3`, it is scintillator and the return value is layer number. Otherwise, it is
    MRPC and the return value is module number.

    Parameters:
        tof_digi_id: The TOF digi ID array or value.
        part: The part number. If not provided, it will be calculated based on the TOF digi ID.

    Returns:
        The scintillator layer or MRPC module number.
    """
    if part is None:
        return _tof_id_to_layer_or_module_1(tof_digi_id)
    else:
        return _tof_id_to_layer_or_module_2(tof_digi_id, part)

tof_id_to_phi_or_strip(tof_digi_id, part=None)

Convert the TOF digi ID to the scintillator phi or MRPC strip number, based on the part number. If part < 3, it is scintillator and the return value is phi number. Otherwise, it is MRPC and the return value is strip number.

Parameters:

Name Type Description Default
tof_digi_id IntLike

The TOF digi ID array or value.

required
part IntLike | None

The part number. If not provided, it will be calculated based on the TOF digi ID.

None

Returns:

Type Description
IntLike

The scintillator phi or MRPC strip number.

Source code in src/pybes3/digi_id.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def tof_id_to_phi_or_strip(
    tof_digi_id: IntLike,
    part: IntLike | None = None,
) -> IntLike:
    """
    Convert the TOF digi ID to the scintillator phi or MRPC strip number, based on the part number.
    If `part < 3`, it is scintillator and the return value is phi number. Otherwise, it is
    MRPC and the return value is strip number.

    Parameters:
        tof_digi_id: The TOF digi ID array or value.
        part: The part number. If not provided, it will be calculated based on the TOF digi ID.

    Returns:
        The scintillator phi or MRPC strip number.
    """
    if part is None:
        return _tof_id_to_phi_or_strip_1(tof_digi_id)
    else:
        return _tof_id_to_phi_or_strip_2(tof_digi_id, part)

get_tof_digi_id(part, layer_or_module, phi_or_strip, end)

Generate TOF scintillator ID based on the part number, layer number, phi number, and readout end number.

Parameters:

Name Type Description Default
part IntLike

The part number.

required
layer_or_module IntLike

The scintillator layer or MRPC module number.

required
phi_or_strip IntLike

The scintillator phi or MRPC strip number.

required
end IntLike

The readout end number.

required

Returns:

Type Description
IntLike

The TOF digi ID.

Source code in src/pybes3/digi_id.py
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
@nb.vectorize(cache=True)
def get_tof_digi_id(
    part: IntLike,
    layer_or_module: IntLike,
    phi_or_strip: IntLike,
    end: IntLike,
) -> IntLike:
    """
    Generate TOF scintillator ID based on the part number, layer number, phi number, and readout end number.

    Parameters:
        part: The part number.
        layer_or_module: The scintillator layer or MRPC module number.
        phi_or_strip: The scintillator phi or MRPC strip number.
        end: The readout end number.

    Returns:
        The TOF digi ID.
    """
    if part < 3:
        return np.uint32(
            ((part << DIGI_TOF_PART_OFFSET) & DIGI_TOF_PART_MASK)
            | ((layer_or_module << DIGI_TOF_SCINT_LAYER_OFFSET) & DIGI_TOF_SCINT_LAYER_MASK)
            | ((phi_or_strip << DIGI_TOF_SCINT_PHI_OFFSET) & DIGI_TOF_SCINT_PHI_MASK)
            | ((end << DIGI_TOF_END_OFFSET) & DIGI_TOF_END_MASK)
            | (DIGI_TOF_FLAG << DIGI_FLAG_OFFSET)
        )
    else:
        return np.uint32(
            ((3 << DIGI_TOF_PART_OFFSET) & DIGI_TOF_PART_MASK)
            | (((part - 3) << DIGI_TOF_MRPC_ENDCAP_OFFSET) & DIGI_TOF_MRPC_ENDCAP_MASK)
            | ((layer_or_module << DIGI_TOF_MRPC_MODULE_OFFSET) & DIGI_TOF_MRPC_MODULE_MASK)
            | ((phi_or_strip << DIGI_TOF_MRPC_STRIP_OFFSET) & DIGI_TOF_MRPC_STRIP_MASK)
            | ((end << DIGI_TOF_END_OFFSET) & DIGI_TOF_END_MASK)
            | (DIGI_TOF_FLAG << DIGI_FLAG_OFFSET)
        )

EMC

check_emc_id(emc_digi_id)

Check if the EMC digi ID is valid.

Parameters:

Name Type Description Default
emc_digi_id IntLike

The EMC digi ID array or value.

required

Returns:

Type Description
BoolLike

Whether the digi ID is valid.

Source code in src/pybes3/digi_id.py
552
553
554
555
556
557
558
559
560
561
562
563
@nb.vectorize(cache=True)
def check_emc_id(emc_digi_id: IntLike) -> BoolLike:
    """
    Check if the EMC digi ID is valid.

    Parameters:
        emc_digi_id: The EMC digi ID array or value.

    Returns:
        Whether the digi ID is valid.
    """
    return (emc_digi_id & DIGI_FLAG_MASK) >> DIGI_FLAG_OFFSET == DIGI_EMC_FLAG

emc_id_to_module(emc_digi_id)

Convert EMC digi ID to module number

Parameters:

Name Type Description Default
emc_digi_id IntLike

EMC digi ID array or value.

required

Returns:

Type Description
IntLike

The module number.

Source code in src/pybes3/digi_id.py
566
567
568
569
570
571
572
573
574
575
576
577
@nb.vectorize(cache=True)
def emc_id_to_module(emc_digi_id: IntLike) -> IntLike:
    """
    Convert EMC digi ID to module number

    Parameters:
        emc_digi_id: EMC digi ID array or value.

    Returns:
        The module number.
    """
    return (emc_digi_id & DIGI_EMC_MODULE_MASK) >> DIGI_EMC_MODULE_OFFSET

emc_id_to_theta(emc_digi_id)

Convert the EMC digi ID to the theta number.

Parameters:

Name Type Description Default
emc_digi_id IntLike

The EMC digi ID array or value.

required

Returns:

Type Description
IntLike

The theta number.

Source code in src/pybes3/digi_id.py
580
581
582
583
584
585
586
587
588
589
590
591
@nb.vectorize(cache=True)
def emc_id_to_theta(emc_digi_id: IntLike) -> IntLike:
    """
    Convert the EMC digi ID to the theta number.

    Parameters:
        emc_digi_id: The EMC digi ID array or value.

    Returns:
        The theta number.
    """
    return (emc_digi_id & DIGI_EMC_THETA_MASK) >> DIGI_EMC_THETA_OFFSET

emc_id_to_phi(emc_digi_id)

Convert the EMC digi ID to the phi number.

Parameters:

Name Type Description Default
emc_digi_id IntLike

The EMC digi ID array or value.

required

Returns:

Type Description
IntLike

The phi number.

Source code in src/pybes3/digi_id.py
594
595
596
597
598
599
600
601
602
603
604
605
@nb.vectorize(cache=True)
def emc_id_to_phi(emc_digi_id: IntLike) -> IntLike:
    """
    Convert the EMC digi ID to the phi number.

    Parameters:
        emc_digi_id: The EMC digi ID array or value.

    Returns:
        The phi number.
    """
    return (emc_digi_id & DIGI_EMC_PHI_MASK) >> DIGI_EMC_PHI_OFFSET

get_emc_digi_id(module, theta, phi)

Generate EMC digi ID based on the module number, theta number, and phi number.

Parameters:

Name Type Description Default
module IntLike

The module number.

required
theta IntLike

The theta number.

required
phi IntLike

The phi number.

required

Returns:

Type Description
IntLike

The EMC digi ID.

Source code in src/pybes3/digi_id.py
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
@nb.vectorize(cache=True)
def get_emc_digi_id(
    module: IntLike,
    theta: IntLike,
    phi: IntLike,
) -> IntLike:
    """
    Generate EMC digi ID based on the module number, theta number, and phi number.

    Parameters:
        module: The module number.
        theta: The theta number.
        phi: The phi number.

    Returns:
        The EMC digi ID.
    """
    return np.uint32(
        ((module << DIGI_EMC_MODULE_OFFSET) & DIGI_EMC_MODULE_MASK)
        | ((theta << DIGI_EMC_THETA_OFFSET) & DIGI_EMC_THETA_MASK)
        | ((phi << DIGI_EMC_PHI_OFFSET) & DIGI_EMC_PHI_MASK)
        | (DIGI_EMC_FLAG << DIGI_FLAG_OFFSET)
    )

MUC

check_muc_id(muc_digi_id)

Check if the MUC digi ID is valid.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID array or value.

required

Returns:

Type Description
BoolLike

Whether the digi ID is valid.

Source code in src/pybes3/digi_id.py
739
740
741
742
743
744
745
746
747
748
749
750
@nb.vectorize(cache=True)
def check_muc_id(muc_digi_id: IntLike) -> BoolLike:
    """
    Check if the MUC digi ID is valid.

    Parameters:
        muc_digi_id: The MUC digi ID array or value.

    Returns:
        Whether the digi ID is valid.
    """
    return (muc_digi_id & DIGI_FLAG_MASK) >> DIGI_FLAG_OFFSET == DIGI_MUC_FLAG

muc_id_to_part(muc_digi_id)

Convert MUC digi ID to part number

Parameters:

Name Type Description Default
muc_digi_id IntLike

MUC digi ID array or value.

required

Returns:

Type Description
IntLike

The part number.

Source code in src/pybes3/digi_id.py
753
754
755
756
757
758
759
760
761
762
763
764
@nb.vectorize(cache=True)
def muc_id_to_part(muc_digi_id: IntLike) -> IntLike:
    """
    Convert MUC digi ID to part number

    Parameters:
        muc_digi_id: MUC digi ID array or value.

    Returns:
        The part number.
    """
    return (muc_digi_id & DIGI_MUC_PART_MASK) >> DIGI_MUC_PART_OFFSET

muc_id_to_segment(muc_digi_id)

Convert the MUC digi ID to the segment number.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID array or value.

required

Returns:

Type Description
IntLike

The segment number.

Source code in src/pybes3/digi_id.py
767
768
769
770
771
772
773
774
775
776
777
778
@nb.vectorize(cache=True)
def muc_id_to_segment(muc_digi_id: IntLike) -> IntLike:
    """
    Convert the MUC digi ID to the segment number.

    Parameters:
        muc_digi_id: The MUC digi ID array or value.

    Returns:
        The segment number.
    """
    return (muc_digi_id & DIGI_MUC_SEGMENT_MASK) >> DIGI_MUC_SEGMENT_OFFSET

muc_id_to_layer(muc_digi_id)

Convert the MUC digi ID to the layer number.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID array or value.

required

Returns:

Type Description
IntLike

The layer number.

Source code in src/pybes3/digi_id.py
781
782
783
784
785
786
787
788
789
790
791
792
@nb.vectorize(cache=True)
def muc_id_to_layer(muc_digi_id: IntLike) -> IntLike:
    """
    Convert the MUC digi ID to the layer number.

    Parameters:
        muc_digi_id: The MUC digi ID array or value.

    Returns:
        The layer number.
    """
    return (muc_digi_id & DIGI_MUC_LAYER_MASK) >> DIGI_MUC_LAYER_OFFSET

muc_id_to_channel(muc_digi_id)

Convert the MUC digi ID to the channel number.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID array or value.

required

Returns:

Type Description
IntLike

The channel number.

Source code in src/pybes3/digi_id.py
795
796
797
798
799
800
801
802
803
804
805
806
@nb.vectorize(cache=True)
def muc_id_to_channel(muc_digi_id: IntLike) -> IntLike:
    """
    Convert the MUC digi ID to the channel number.

    Parameters:
        muc_digi_id: The MUC digi ID array or value.

    Returns:
        The channel number.
    """
    return (muc_digi_id & DIGI_MUC_CHANNEL_MASK) >> DIGI_MUC_CHANNEL_OFFSET

get_muc_digi_id(part, segment, layer, channel)

Generate MUC digi ID based on the part number, segment number, layer number, and channel number.

Parameters:

Name Type Description Default
part IntLike

The part number.

required
segment IntLike

The segment number.

required
layer IntLike

The layer number.

required
channel IntLike

The channel number.

required

Returns:

Type Description
IntLike

The MUC digi ID.

Source code in src/pybes3/digi_id.py
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
@nb.vectorize(cache=True)
def get_muc_digi_id(
    part: IntLike,
    segment: IntLike,
    layer: IntLike,
    channel: IntLike,
) -> IntLike:
    """
    Generate MUC digi ID based on the part number, segment number, layer number, and channel number.

    Parameters:
        part: The part number.
        segment: The segment number.
        layer: The layer number.
        channel: The channel number.

    Returns:
        The MUC digi ID.
    """
    return np.uint32(
        ((part << DIGI_MUC_PART_OFFSET) & DIGI_MUC_PART_MASK)
        | ((segment << DIGI_MUC_SEGMENT_OFFSET) & DIGI_MUC_SEGMENT_MASK)
        | ((layer << DIGI_MUC_LAYER_OFFSET) & DIGI_MUC_LAYER_MASK)
        | ((channel << DIGI_MUC_CHANNEL_OFFSET) & DIGI_MUC_CHANNEL_MASK)
        | (DIGI_MUC_FLAG << DIGI_FLAG_OFFSET)
    )

muc_id_to_gap(muc_digi_id)

Convert the MUC digi ID to the gap ID, which is equivalent to layer number.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID array or value.

required

Returns:

Type Description
IntLike

The gap ID.

Source code in src/pybes3/digi_id.py
837
838
839
840
841
842
843
844
845
846
847
def muc_id_to_gap(muc_digi_id: IntLike) -> IntLike:
    """
    Convert the MUC digi ID to the gap ID, which is equivalent to layer number.

    Parameters:
        muc_digi_id: The MUC digi ID array or value.

    Returns:
        The gap ID.
    """
    return muc_id_to_layer(muc_digi_id)

muc_id_to_strip(muc_digi_id)

Convert the MUC digi ID to the strip number, which is equivalent to channel number.

Parameters:

Name Type Description Default
muc_digi_id IntLike

The MUC digi ID array or value.

required

Returns:

Type Description
IntLike

The strip number.

Source code in src/pybes3/digi_id.py
850
851
852
853
854
855
856
857
858
859
860
def muc_id_to_strip(muc_digi_id: IntLike) -> IntLike:
    """
    Convert the MUC digi ID to the strip number, which is equivalent to channel number.

    Parameters:
        muc_digi_id: The MUC digi ID array or value.

    Returns:
        The strip number.
    """
    return muc_id_to_channel(muc_digi_id)

CGEM

check_cgem_id(cgem_digi_id)

Check if the CGEM digi ID is valid.

Parameters:

Name Type Description Default
cgem_digi_id IntLike

The CGEM digi ID array or value.

required

Returns:

Type Description
BoolLike

Whether the digi ID is valid.

Source code in src/pybes3/digi_id.py
919
920
921
922
923
924
925
926
927
928
929
930
@nb.vectorize(cache=True)
def check_cgem_id(cgem_digi_id: IntLike) -> BoolLike:
    """
    Check if the CGEM digi ID is valid.

    Parameters:
        cgem_digi_id: The CGEM digi ID array or value.

    Returns:
        Whether the digi ID is valid.
    """
    return (cgem_digi_id & DIGI_FLAG_MASK) >> DIGI_FLAG_OFFSET == DIGI_CGEM_FLAG

cgem_id_to_layer(cgem_digi_id)

Convert the CGEM digi ID to the layer number.

Parameters:

Name Type Description Default
cgem_digi_id IntLike

The CGEM digi ID array or value.

required

Returns:

Type Description
IntLike

The layer number.

Source code in src/pybes3/digi_id.py
933
934
935
936
937
938
939
940
941
942
943
944
@nb.vectorize(cache=True)
def cgem_id_to_layer(cgem_digi_id: IntLike) -> IntLike:
    """
    Convert the CGEM digi ID to the layer number.

    Parameters:
        cgem_digi_id: The CGEM digi ID array or value.

    Returns:
        The layer number.
    """
    return (cgem_digi_id & DIGI_CGEM_LAYER_MASK) >> DIGI_CGEM_LAYER_OFFSET

cgem_id_to_sheet(cgem_digi_id)

Convert the CGEM digi ID to the sheet number.

Parameters:

Name Type Description Default
cgem_digi_id IntLike

The CGEM digi ID array or value.

required

Returns:

Type Description
IntLike

The sheet number.

Source code in src/pybes3/digi_id.py
947
948
949
950
951
952
953
954
955
956
957
958
@nb.vectorize(cache=True)
def cgem_id_to_sheet(cgem_digi_id: IntLike) -> IntLike:
    """
    Convert the CGEM digi ID to the sheet number.

    Parameters:
        cgem_digi_id: The CGEM digi ID array or value.

    Returns:
        The sheet number.
    """
    return (cgem_digi_id & DIGI_CGEM_SHEET_MASK) >> DIGI_CGEM_SHEET_OFFSET

cgem_id_to_strip_type(cgem_digi_id)

Convert the CGEM digi ID to the strip type. 0 for X-strip, 1 for V-strip.

Parameters:

Name Type Description Default
cgem_digi_id IntLike

The CGEM digi ID array or value.

required

Returns:

Type Description
IntLike

The strip type. 0 for X-strip, 1 for V-strip.

Source code in src/pybes3/digi_id.py
961
962
963
964
965
966
967
968
969
970
971
972
@nb.vectorize(cache=True)
def cgem_id_to_strip_type(cgem_digi_id: IntLike) -> IntLike:
    """
    Convert the CGEM digi ID to the strip type. 0 for X-strip, 1 for V-strip.

    Parameters:
        cgem_digi_id: The CGEM digi ID array or value.

    Returns:
        The strip type. 0 for X-strip, 1 for V-strip.
    """
    return (cgem_digi_id & DIGI_CGEM_STRIPTYPE_MASK) >> DIGI_CGEM_STRIPTYPE_OFFSET

cgem_id_to_strip(cgem_digi_id)

Convert CGEM digi ID to strip number

Parameters:

Name Type Description Default
cgem_digi_id IntLike

CGEM digi ID array or value.

required

Returns:

Type Description
IntLike

The strip number.

Source code in src/pybes3/digi_id.py
975
976
977
978
979
980
981
982
983
984
985
986
@nb.vectorize(cache=True)
def cgem_id_to_strip(cgem_digi_id: IntLike) -> IntLike:
    """
    Convert CGEM digi ID to strip number

    Parameters:
        cgem_digi_id: CGEM digi ID array or value.

    Returns:
        The strip number.
    """
    return (cgem_digi_id & DIGI_CGEM_STRIP_MASK) >> DIGI_CGEM_STRIP_OFFSET

get_cgem_digi_id(layer, sheet, strip_type, strip)

Generate CGEM digi ID based on the strip number, strip type, sheet number, and layer number.

Parameters:

Name Type Description Default
layer IntLike

The layer number.

required
sheet IntLike

The sheet number.

required
strip_type IntLike

The strip type. 0 for X-strip, 1 for V-strip.

required
strip IntLike

The strip number.

required

Returns:

Type Description
IntLike

The CGEM digi ID.

Source code in src/pybes3/digi_id.py
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
@nb.vectorize(cache=True)
def get_cgem_digi_id(
    layer: IntLike,
    sheet: IntLike,
    strip_type: IntLike,
    strip: IntLike,
) -> IntLike:
    """
    Generate CGEM digi ID based on the strip number, strip type, sheet number, and layer number.

    Parameters:
        layer: The layer number.
        sheet: The sheet number.
        strip_type: The strip type. 0 for X-strip, 1 for V-strip.
        strip: The strip number.

    Returns:
        The CGEM digi ID.
    """
    return np.uint32(
        ((strip << DIGI_CGEM_STRIP_OFFSET) & DIGI_CGEM_STRIP_MASK)
        | ((strip_type << DIGI_CGEM_STRIPTYPE_OFFSET) & DIGI_CGEM_STRIPTYPE_MASK)
        | ((sheet << DIGI_CGEM_SHEET_OFFSET) & DIGI_CGEM_SHEET_MASK)
        | ((layer << DIGI_CGEM_LAYER_OFFSET) & DIGI_CGEM_LAYER_MASK)
        | ((DIGI_CGEM_FLAG << DIGI_FLAG_OFFSET) & 0xFF000000)
    )