CbmRoot
Loading...
Searching...
No Matches
StsRecoUtils.h
Go to the documentation of this file.
1/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: David Gutierrez [committer], Dario Ramirez */
4
5#pragma once
6
7#include "Definitions.h"
8
9#include <cassert>
10#include <cstdlib>
11#include <optional>
12
13namespace cbm::algo::sts
14{
17 class Module {
18 public:
19 static constexpr u16 CHANNELS_PER_ASIC = 128;
20 static constexpr u16 ASICS_PER_MODULE = 16;
22
23 static_assert(CHANNELS_PER_ASIC > 0, "ASICs must have at least one chanhel.");
24 static_assert(ASICS_PER_MODULE > 0, "Modules must have at least one asic.");
25
26 static constexpr u16 ZSTRIP_ASIC = 8;
27 static constexpr u16 ZSTRIP_HW_CHANNEL = 127;
28 static constexpr u16 ZSTRIP_SW_CHANNEL = 2046;
29 static constexpr u16 ZSTRIP_OFFSET = ZSTRIP_SW_CHANNEL - 1022;
30
36 static inline std::optional<u16> ChannelInModule(const u16 elink_chn, const u16 asic_idx)
37 {
38 if (elink_chn >= CHANNELS_PER_ASIC || asic_idx >= ASICS_PER_MODULE) return std::nullopt;
39
40 const u16 channel =
41 CHANNELS_PER_ASIC * asic_idx + elink_chn // n side
42 + (2 * asic_idx >= ASICS_PER_MODULE)
43 * ( // p side
44 CHANNELS_PER_ASIC - 1 - 2 * elink_chn // revert channels in asic
45 - (elink_chn & 0b1) * 2 // shift odd channels to the left
46 + (elink_chn == ZSTRIP_HW_CHANNEL && asic_idx == ZSTRIP_ASIC) * ZSTRIP_OFFSET // correct z-strip 1
47 );
48
49 return (channel < CHANNELS_PER_MODULE) ? std::make_optional(channel) : std::nullopt;
50 }
51
58 static inline std::optional<std::pair<u16, u16>> ChannelInAsic(const u16 channel)
59 {
60 if (channel >= CHANNELS_PER_MODULE) return std::nullopt;
61
62 auto [asic_idx, elink_chn] =
63 std::div(channel // n side
64 + (2 * channel >= CHANNELS_PER_MODULE)
65 * ( // p side
66 -(channel == ZSTRIP_SW_CHANNEL) * ZSTRIP_OFFSET // correct z-strip 1
67 + (!(channel & 0b1)) * 2 // shift even channels to the right
68 ),
70
71 elink_chn += (2 * asic_idx >= ASICS_PER_MODULE)
72 * ( // p side
73 CHANNELS_PER_ASIC - 1 - 2 * elink_chn // revert channels in asic
74 );
75
76 return (asic_idx < ASICS_PER_MODULE || elink_chn < CHANNELS_PER_ASIC)
77 ? std::make_optional(std::make_pair(elink_chn, asic_idx))
78 : std::nullopt;
79 }
80 };
81} // namespace cbm::algo::sts
STS Module parameters.
static std::optional< std::pair< u16, u16 > > ChannelInAsic(const u16 channel)
Channel SW to HW conversion.
static constexpr u16 ZSTRIP_OFFSET
static constexpr u16 CHANNELS_PER_MODULE
static constexpr u16 CHANNELS_PER_ASIC
static constexpr u16 ZSTRIP_HW_CHANNEL
static constexpr u16 ASICS_PER_MODULE
static std::optional< u16 > ChannelInModule(const u16 elink_chn, const u16 asic_idx)
Channel HW to SW conversion.
static constexpr u16 ZSTRIP_ASIC
static constexpr u16 ZSTRIP_SW_CHANNEL
std::uint16_t u16
Definition Definitions.h:19