ATLAS Offline Software
Loading...
Searching...
No Matches
TrigT1Run3ZDC.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "TrigT1Run3ZDC.h"
5
6
7
10#include "ZdcIdentifier/ZdcID.h"
11#include <bitset>
12#include <fstream>
13#include <array>
14#include <iostream>
15
16using json = nlohmann::json;
17
18namespace LVL1 {
19
20//---------------------------------
21// initialise()
22//---------------------------------
23
25 ATH_CHECK(m_zdcCTPLocation.initialize());
27 ATH_CHECK(m_zldContainerName.initialize());
28 // Find the full path to filename:
30 ATH_MSG_INFO("Reading file " << file);
31 std::ifstream fin(file.c_str());
32 if (!fin) {
33 ATH_MSG_ERROR("Can not read file: " << file);
34 return StatusCode::FAILURE;
35 }
36 json data = json::parse(fin);
37
38 // Will eventually obtain LUTs from COOL, for now obtain them from calibration
39 // area A data member to hold the side A LUT values
40 //coverity[STACK_USE]
41 std::array<unsigned int, 4096> sideALUTHG =
42 data["LucrodHighGain"]["LUTs"]["sideA"];
43 // A data member to hold the side C LUT values
44 //coverity[STACK_USE]
45 std::array<unsigned int, 4096> sideCLUTHG =
46 data["LucrodHighGain"]["LUTs"]["sideC"];
47 // A data member to hold the Combined LUT values
48 std::array<unsigned int, 256> combLUTHG =
49 data["LucrodHighGain"]["LUTs"]["comb"];
50 // area A data member to hold the side A LUT values
51 //coverity[STACK_USE]
52 std::array<unsigned int, 4096> sideALUTLG =
53 data["LucrodLowGain"]["LUTs"]["sideA"];
54 // A data member to hold the side C LUT values
55 //coverity[STACK_USE]
56 std::array<unsigned int, 4096> sideCLUTLG =
57 data["LucrodLowGain"]["LUTs"]["sideC"];
58 // A data member to hold the Combined LUT values
59 std::array<unsigned int, 256> combLUTLG =
60 data["LucrodLowGain"]["LUTs"]["comb"];
61
62 // Access Raw Lucrod Data
63 const ZdcID *zdcId = nullptr;
64 if (detStore()->retrieve(zdcId).isFailure()) {
65 msg(MSG::ERROR)
66 << "execute: Could not retrieve ZdcID object from the detector store"
67 << endmsg;
68 return StatusCode::FAILURE;
69 } else {
70 msg(MSG::DEBUG) << "execute: retrieved ZdcID" << endmsg;
71 }
72 m_zdcId = zdcId;
73
74 std::array<std::array<unsigned int, 4>, 2> deriv2ndHGThresh;
75 std::array<std::array<unsigned int, 4>, 2> deriv2ndLGThresh;
76
77 for (unsigned int side : {0, 1}) {
78 for (unsigned int module : {0, 1, 2, 3}) {
79 deriv2ndHGThresh[side][module] = m_negHG2ndDerivThresh;
80 deriv2ndLGThresh[side][module] = m_negLG2ndDerivThresh;
81 }
82 }
83
84 // We disable the EM module in the LG trigger
85 //
86 deriv2ndLGThresh[0][0] = 4095;
87 deriv2ndLGThresh[1][0] = 4095;
88
89 std::cout << "Trigger simulation will use sample indices: " << m_minSampleAna
90 << " through " << m_maxSampleAna
91 << ", and baselinDelta = " << m_baselineDelta << std::endl;
92
93 // Construct Simulation Objects
94 m_triggerSimHGPtr = std::make_shared<ZDCTriggerSimFADC>(
95 sideALUTHG, sideCLUTHG, combLUTHG, deriv2ndHGThresh,
97
98 m_triggerSimLGPtr = std::make_shared<ZDCTriggerSimFADC>(
99 sideALUTLG, sideCLUTLG, combLUTLG, deriv2ndLGThresh,
101
103 std::make_shared<ZDCTriggerSim::FADCInputs>(ZDCTriggerSim::FADCInputs());
105 std::make_shared<ZDCTriggerSim::FADCInputs>(ZDCTriggerSim::FADCInputs());
106
107 ATH_MSG_DEBUG("TrigT1Run3ZDC initilized");
108 return StatusCode::SUCCESS;
109}
110
111//----------------------------------------------
112// execute() method called once per event
113//----------------------------------------------
114
115StatusCode TrigT1Run3ZDC::execute(const EventContext& ctx) const {
116
117 // create uints to hold trigger averages
118 unsigned int trigAvgAHG = 0;
119 unsigned int trigAvgCHG = 0;
120 unsigned int trigAvgALG = 0;
121 unsigned int trigAvgCLG = 0;
122
123 // create multi-dim array to store event by event flash ADC values
124 std::array<std::array<std::array<unsigned int, 24>, 4>, 2> FADCSamplesHG;
125 std::array<std::array<std::array<unsigned int, 24>, 4>, 2> FADCSamplesLG;
126
127 // create vectors to store flattened above multi
128 // dim arrays, in order to give the TriggerSimTool
129 // data in the proper format
130 std::vector<unsigned int> FADCFlattenedHG;
131 std::vector<unsigned int> FADCFlattenedLG;
132
133 // access LUCROD data
134
135 // use readhandle to retrieve lucrodCollection
137
138 for (const ZdcLucrodData *zld : *lucrodCollection) {
139
140 // get lucrod board number
141 uint32_t lucrod_id = zld->GetLucrodID();
142
143 // unpack data for each lucrod
144 for (size_t i = 0; i < zld->GetChanDataSize(); i++) {
145
146 // create channel object
147 const ZdcLucrodChannel &zlc = zld->GetChanData(i);
148
149 // figure out which channel we are reading out (0,1)
150 uint16_t lucrod_channel = zlc.id;
151
152 // variable to hold if it is a ZDC (0) or RPD (1) type
153 // lucrod
155 lucrod_id)["type"][lucrod_channel];
156
157 // trigger based on ZDC amplitudes, don't use
158 // RPD channels
159 if (type != 0) {
160 continue;
161 }
162
163 // retrieve what side, module, and gain we are reading out
165 lucrod_id)["side"][lucrod_channel];
167 lucrod_id)["module"][lucrod_channel];
169 lucrod_id)["gain"][lucrod_channel];
170 // Fill different flash ADC vectors for Low and High
171 // gain samples
172 if (gain == 0) {
173 unsigned int counter = 0;
174 for (const auto &sample : zlc.waveform) {
175 // fill low gain FADC samples
176 FADCSamplesLG.at((side == 1)).at(module).at(counter) = sample;
177 counter++;
178 }
179 } else if (gain == 1) {
180 unsigned int counter = 0;
181 for (const auto &sample : zlc.waveform) {
182 // fill high gain FADC samples
183 FADCSamplesHG.at((side == 1)).at(module).at(counter) = sample;
184 counter++;
185 }
186 }
187 // retrieve Trig Avg amp for debugging
188 // from both LG and HG modules
189 if (side * gain * module == 3) {
190 trigAvgAHG = zld->GetTrigAvgA();
191 trigAvgCHG = zld->GetTrigAvgC();
192 } else if (side * module == 3) {
193 trigAvgALG = zld->GetTrigAvgA();
194 trigAvgCLG = zld->GetTrigAvgC();
195 }
196 }
197 } // end lucrod loop
198
199 // unpack FADC data into one long vector for both
200 // high and low gain
201 for (int side : {1, 0}) {
202 for (int module : {0, 1, 2, 3}) {
203 for (const auto sample : FADCSamplesLG.at(side).at(module)) {
204 FADCFlattenedLG.push_back(sample);
205 }
206 }
207 }
208
209 for (int side : {1, 0}) {
210 for (int module : {0, 1, 2, 3}) {
211 for (const auto sample : FADCSamplesHG.at(side).at(module)) {
212 FADCFlattenedHG.push_back(sample);
213 }
214 }
215 }
216
217 // set data in Trigger Sim Object
218 m_hgFADC_ptr->setData(FADCFlattenedHG);
219 m_lgFADC_ptr->setData(FADCFlattenedLG);
220
221 // call ZDCTriggerSim to actually get L1 decisions
222 unsigned int wordOutHG = m_triggerSimHGPtr->simLevel1Trig(m_hgFADC_ptr);
223 unsigned int wordOutLG = m_triggerSimLGPtr->simLevel1Trig(m_lgFADC_ptr);
224
225 // convert int to bitset for ZDC Triggers
226 std::bitset<3> binhg(wordOutHG);
227
228 // convert int to bitset for ZDC ALT Trigggers
229 std::bitset<3> binlg(wordOutLG);
230
231 // ZDC L1 items are located on CTPIN SLOT 9
232 // Each slot holds 4 connectors that each carry a 32 bit trigger word
233 // ZDC HG items are located on Connector 1 (CTPCAL)
234 // at bits 25, 26, 27
235 // ZDC LG (UCC) items are located on Connector 3 (NIM3)
236 // at bits 28, 29, 30
237 // for more info see
238 // twiki.cern.ch/twiki/bin/view/Atlas/LevelOneCentralTriggerSetup#CTPIN_Slot_9
239
240 // load HG output into trigger word on correct bits
241 unsigned int word0 = 0;
242 word0 += (binhg[0] << 25);
243 word0 += (binhg[1] << 26);
244 word0 += (binhg[2] << 27);
245
246 // load LG output into trigger word on correct bits
247 unsigned int word1 = 0;
248 word1 += (binlg[0] << 28);
249 word1 += (binlg[1] << 29);
250 word1 += (binlg[2] << 30);
251
252 // form CTP obejct
254
255 // record CTP object
256 ATH_CHECK(zdcCTP.record(std::make_unique<ZdcCTP>(word0, word1)));
257
258 // debug output
260 "Stored ZDC CTP object with words "
261 << std::endl
262 << std::hex << word0 << " from hgLUTOutput: " << std::dec << wordOutHG
263 << " AvgAmpA: " << trigAvgAHG << " C: " << trigAvgCHG << std::endl
264 << std::hex << word1 << " from lgLUTOutput: " << std::dec << wordOutLG
265 << " AvgAmpA: " << trigAvgALG << " C: " << trigAvgCLG);
266 return StatusCode::SUCCESS;
267}
268} // namespace LVL1
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
nlohmann::json json
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
struct ZdcLucrodChannelType ZdcLucrodChannel
const ServiceHandle< StoreGateSvc > & detStore() const
Gaudi::Property< unsigned int > m_maxSampleAna
Gaudi::Property< unsigned int > m_negLG2ndDerivThresh
std::shared_ptr< ZDCTriggerSimFADC > m_triggerSimLGPtr
SG::ReadHandleKey< ZdcLucrodDataContainer > m_zldContainerName
virtual StatusCode initialize() override
Gaudi::Property< unsigned int > m_minSampleAna
SG::WriteHandleKey< ZdcCTP > m_zdcCTPLocation
std::shared_ptr< ZDCTriggerSimFADC > m_triggerSimHGPtr
Two data member to hold the ZDCTrigger Object that computes the LUT logic: shared ptr to ensure clean...
Gaudi::Property< std::string > m_lutFile
std::shared_ptr< ZDCTriggerSim::FADCInputs > m_hgFADC_ptr
A data member to hold the ZDCTrigger Object that stores flash ADC input values: shared ptr to ensure ...
Gaudi::Property< unsigned int > m_negHG2ndDerivThresh
const ZdcID * m_zdcId
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleCalibEnergyKey
Gaudi::Property< unsigned int > m_baselineDelta
std::shared_ptr< ZDCTriggerSim::FADCInputs > m_lgFADC_ptr
virtual StatusCode execute(const EventContext &ctx) const override
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Definition ZdcID.h:25
static const ZdcLucrodMapRun3 * getInstance()
const nlohmann::json & getLucrod(int i) const
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
ZDCTriggerSimData< unsigned int, 8 *24, 12, TFADCInputs > FADCInputs
std::vector< uint16_t > waveform
TFile * file