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