CbmRoot
Loading...
Searching...
No Matches
CbmTaskTrdUnpackParWrite.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4
6
7#include "CbmTrdParFasp.h"
8#include "CbmTrdParModAsic.h"
9#include "CbmTrdParModDigi.h"
10#include "CbmTrdParSetAsic.h"
11#include "CbmTrdParSetDigi.h"
12#include "CbmTrdParSpadic.h"
13#include "trd/ReadoutConfig.h"
14#include "trd2d/ReadoutConfig.h"
15#include "yaml/Yaml.h"
16
17#include <FairParamList.h>
18#include <fairlogger/Logger.h>
19
20#include <fstream>
21
22using namespace cbm::algo;
23
25{
26
27 assert(fPars.digi != nullptr);
28 auto& digiparset = *fPars.digi;
29
30 assert(fPars.asic != nullptr);
31 auto& asicparset = *fPars.asic;
32
33
34 // TRD2D ===================================================================
35 {
36 // Output object
38
39 // Map (moduleId) -> (array of crobId)
40 std::map<uint32_t, uint16_t[NCROBMOD]> crobMap;
41 // Map (equipId, asicId, chanId) -> (pad address, mask flag, daq offset [FASP clk])
42 std::map<size_t, std::map<size_t, std::map<size_t, std::tuple<int32_t, bool, uint64_t>>>> channelMap;
43
44 // Loop through a list of module IDs from the .digi file (can in principle contradict crob_map).
45 for (auto entry : digiparset.GetModuleMap()) {
46
47 const auto moduleId = entry.first;
48
49 // Get ASIC parameters for this module
50 CbmTrdParModAsic* setDet = static_cast<CbmTrdParModAsic*>(asicparset.GetModulePar(moduleId));
51 if (!setDet) continue;
52 if (setDet->GetAsicType() != CbmTrdDigi::eCbmTrdAsicType::kFASP) continue;
53 auto digipar = entry.second;
54
55 const int* crobs = setDet->GetCrobAddresses();
56 for (int icrob(0); icrob < NCROBMOD; icrob++)
57 crobMap[moduleId][icrob] = crobs[icrob];
58
59 // Loop through ASICs for this module
60 std::vector<int32_t> addresses;
61 setDet->GetAsicAddresses(&addresses);
62 for (auto add : addresses) {
63 //Get local IDs for this component / equipment.
64 const int32_t fasp_in_mod = add - 1000 * moduleId;
65 const int32_t fasp_in_eq = fasp_in_mod % (NFASPCROB);
66 const int32_t crob_in_mod = fasp_in_mod / (NFASPCROB);
67 const uint16_t eq_id = crobMap[moduleId][crob_in_mod];
68
69 // ASIC parameter set
70 CbmTrdParFasp* fasppar = (CbmTrdParFasp*) setDet->GetAsicPar(add);
71
72 // Loop through channels for this ASIC and fill map
73 for (int chan = 0; chan < fasppar->GetNchannels(); chan++) {
74 const CbmTrdParFaspChannel* faspch = fasppar->GetChannel(chan);
75 const int32_t pad = fasppar->GetPadAddress(chan) * (faspch->HasPairingR() ? 1 : -1);
76 const bool isMasked = faspch->IsMasked();
77 uint64_t daq_offset = 0;
78 if (((CbmTrdParModDigi*) digipar)->GetPadRow(pad) % 2 == 0) daq_offset = 3;
79 channelMap[eq_id][fasp_in_eq][chan] = std::make_tuple(pad, isMasked, daq_offset);
80 }
81 }
82 }
83
84 trd2dConfig.InitComponentMap(crobMap);
85 trd2dConfig.InitChannelMap(channelMap);
86
87 // Apply system time offset
88 // See <source_dir>/macro/run/run_unpack_tsa.C
89 if (fPars.setup == Setup::mCBM2022 || fPars.setup == Setup::mCBM2024_03 || fPars.setup == Setup::mCBM2024_05) {
90 // Ni 2022, Au 2022, Ni 2024
91 trd2dConfig.SetSystemTimeOffset(-510);
92 }
93
94 std::ofstream("Trd2dReadoutSetup.yaml") << yaml::Dump{}(trd2dConfig);
95 }
96
97 // TRD1D ===================================================================
98 {
99 // Output object
101
102 FairParamList parlist;
103 asicparset.putParams(&parlist);
104
105 std::vector<int> moduleIds(asicparset.GetNrOfModules());
106 parlist.fill("ModuleId", moduleIds.data(), moduleIds.size());
107
108 std::map<size_t, std::map<size_t, std::map<size_t, size_t>>> addressMap; //[criId][crobId][elinkId] -> asicAddress
109 std::map<size_t, std::map<size_t, std::map<size_t, std::map<size_t, size_t>>>>
110 channelMap; //[criId][crobId][elinkId][chanId] -> chanAddress
111
112 for (auto module : moduleIds) {
113 CbmTrdParModAsic* moduleSet = (CbmTrdParModAsic*) asicparset.GetModulePar(module);
114
115 // Skip entries for "Fasp" modules in .asic.par file
116 if (moduleSet->GetAsicType() != CbmTrdDigi::eCbmTrdAsicType::kSPADIC) continue;
117
118 std::vector<int> asicAddresses;
119 moduleSet->GetAsicAddresses(&asicAddresses);
120
121 for (auto address : asicAddresses) {
122 CbmTrdParSpadic* asicPar = (CbmTrdParSpadic*) moduleSet->GetAsicPar(address);
123 const uint16_t criId = asicPar->GetCriId();
124 const uint8_t crobId = asicPar->GetCrobId();
125 const uint8_t elinkId = asicPar->GetElinkId(0);
126 if (elinkId >= 98) {
127 continue;
128 } // Don't add not connected asics to the map
129 addressMap[criId][crobId][elinkId] = address;
130 addressMap[criId][crobId][elinkId + 1] = address;
131
132 const uint8_t numChans = 16;
133 for (uint8_t chan = 0; chan < numChans; chan++) {
134 auto asicChannelId = (elinkId % 2) == 0 ? chan : chan + numChans;
135 auto chanAddr = asicPar->GetChannelAddresses().at(asicChannelId);
136 channelMap[criId][crobId][elinkId][chan] = chanAddr;
137 }
138 for (uint8_t chan = 0; chan < numChans; chan++) {
139 auto asicChannelId = (elinkId + 1 % 2) == 0 ? chan : chan + numChans;
140 auto chanAddr = asicPar->GetChannelAddresses().at(asicChannelId);
141 channelMap[criId][crobId][elinkId + 1][chan] = chanAddr;
142 }
143 LOG(debug) << "componentID " << asicPar->GetComponentId() << " "
144 << "address " << address << " key " << criId << " " << unsigned(crobId) << " " << unsigned(elinkId);
145 }
146 }
147 trdConfig.Init(addressMap, channelMap);
148
149 // Apply system time offset
150 // See <source_dir>/macro/run/run_unpack_tsa.C
151 if (fPars.setup == Setup::mCBM2022 || fPars.setup == Setup::mCBM2024_03 || fPars.setup == Setup::mCBM2024_05) {
152 // Ni 2022, Au 2022, Ni 2024
153 trdConfig.SetSystemTimeOffset(1300);
154 }
155
156 // Apply time offset per elink
157 // See: https://git.cbm.gsi.de/computing/cbmroot/-/merge_requests/1751
158 // and <source_dir>/macro/run/run_unpack_tsa.C
159 if (fPars.setup == Setup::mCBM2024_05) {
160 for (int elinkId = 0; elinkId < 36; ++elinkId) {
161 trdConfig.SetElinkTimeOffset(20736, elinkId, -36);
162 trdConfig.SetElinkTimeOffset(20737, elinkId, -37);
163 trdConfig.SetElinkTimeOffset(20738, elinkId, -65);
164 trdConfig.SetElinkTimeOffset(20739, elinkId, -52);
165 trdConfig.SetElinkTimeOffset(20740, elinkId, -50);
166 trdConfig.SetElinkTimeOffset(20741, elinkId, -49);
167
168 //trdConfig.SetElinkTimeOffset(20992, elinkId, 0); //no correlation
169 trdConfig.SetElinkTimeOffset(20993, elinkId, -50);
170 trdConfig.SetElinkTimeOffset(20994, elinkId, -57);
171 trdConfig.SetElinkTimeOffset(20995, elinkId, -52);
172 trdConfig.SetElinkTimeOffset(20996, elinkId, -52);
173 trdConfig.SetElinkTimeOffset(20997, elinkId, -53);
174 }
175 }
176
177 std::ofstream("TrdReadoutSetup.yaml") << yaml::Dump{}(trdConfig);
178 }
179
180 return kSUCCESS;
181}
virtual std::vector< Int_t > GetChannelAddresses() const
virtual size_t GetComponentId() const
Definition of FASP channel calibration container.
Bool_t HasPairingR() const
Query pad pairing type.
bool IsMasked() const
Definition of FASP parameters.
const CbmTrdParFaspChannel * GetChannel(Int_t pad_address, UChar_t pair) const
Query the calibration for one FASP RO channel.
int GetPadAddress(Int_t ich) const
virtual Int_t GetNchannels() const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual void GetAsicAddresses(std::vector< Int_t > *a) const
Query the ASICs in the module for their DAQ address. It applies to the list of ASICs....
virtual CbmTrdDigi::eCbmTrdAsicType GetAsicType() const
Query the type of ASICs in the list.
virtual const CbmTrdParAsic * GetAsicPar(Int_t address) const
Look for the ASIC parameters of a given DAQ id It applies to the list of ASICs.
virtual const int32_t * GetCrobAddresses() const
Query the type of chamber.
Definition of chamber gain conversion for one TRD module.
Definition of SPADIC parameters.
static std::uint16_t GetCriId(size_t componentId)
Extracts the CriId from a given componentId - Remark when the par files are created from geometries t...
static std::uint8_t GetCrobId(size_t componentId)
Extracts the CrobId from a given componentId.
static std::uint8_t GetElinkId(size_t componentId, Int_t channelId)
eLinkId for the given asicAddress and channelId (in the asic coordinates, i.e. 00....
Provides the hardware-to-software address mapping for the CBM-TRD2D.
void SetSystemTimeOffset(int64_t offsetNs)
Get system time offset.
void InitChannelMap(const std::map< size_t, std::map< size_t, std::map< size_t, std::tuple< int32_t, bool, uint64_t > > > > &channelMap)
Initialisation of channel map.
void InitComponentMap(const std::map< uint32_t, uint16_t[NCROBMOD]> &crob_map)
Initialisation of readout map.
Provides the hardware-to-software address mapping for the CBM-TRD.
void Init(const std::map< size_t, std::map< size_t, std::map< size_t, size_t > > > &addressMap, std::map< size_t, std::map< size_t, std::map< size_t, std::map< size_t, size_t > > > > &channelMap)
Initialisation of readout map.
void SetElinkTimeOffset(uint32_t criid, uint8_t elinkid, int32_t offsetNs)
Register a time offeset to be substracted from the digis which come from a specific CRI.
void SetSystemTimeOffset(int64_t offsetNs)
Get system time offset.
CbmTrdParSetAsic * asic
parameter list for ASIC characterization
cbm::algo::Setup setup
Setup type.
CbmTrdParSetDigi * digi
parameter list for read-out geometry
#define NCROBMOD
#define NFASPCROB