ATLAS Offline Software
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 
11 #include "ZdcIdentifier/ZdcID.h"
12 
14 
15 namespace LVL1 {
16 
17 //---------------------------------
18 // initialise()
19 //---------------------------------
20 
22  ATH_CHECK(m_zdcCTPLocation.initialize());
25  // Find the full path to filename:
27  ATH_MSG_INFO("Reading file " << file);
28  std::ifstream fin(file.c_str());
29  if (!fin) {
30  ATH_MSG_ERROR("Can not read file: " << file);
31  return StatusCode::FAILURE;
32  }
34 
35  // Will eventually obtain LUTs from COOL, for now obtain them from calibration
36  // area A data member to hold the side A LUT values
37  std::array<unsigned int, 4096> sideALUTHG =
38  data["LucrodHighGain"]["LUTs"]["sideA"];
39  // A data member to hold the side C LUT values
40  std::array<unsigned int, 4096> sideCLUTHG =
41  data["LucrodHighGain"]["LUTs"]["sideC"];
42  // A data member to hold the Combined LUT values
43  std::array<unsigned int, 256> combLUTHG =
44  data["LucrodHighGain"]["LUTs"]["comb"];
45  // area A data member to hold the side A LUT values
46  std::array<unsigned int, 4096> sideALUTLG =
47  data["LucrodLowGain"]["LUTs"]["sideA"];
48  // A data member to hold the side C LUT values
49  std::array<unsigned int, 4096> sideCLUTLG =
50  data["LucrodLowGain"]["LUTs"]["sideC"];
51  // A data member to hold the Combined LUT values
52  std::array<unsigned int, 256> combLUTLG =
53  data["LucrodLowGain"]["LUTs"]["comb"];
54 
55  // Access Raw Lucrod Data
56  const ZdcID *zdcId = nullptr;
57  if (detStore()->retrieve(zdcId).isFailure()) {
58  msg(MSG::ERROR)
59  << "execute: Could not retrieve ZdcID object from the detector store"
60  << endmsg;
61  return StatusCode::FAILURE;
62  } else {
63  msg(MSG::DEBUG) << "execute: retrieved ZdcID" << endmsg;
64  }
65  m_zdcId = zdcId;
66 
67  std::array<std::array<unsigned int, 4>, 2> deriv2ndHGThresh;
68  std::array<std::array<unsigned int, 4>, 2> deriv2ndLGThresh;
69 
70  for (unsigned int side : {0, 1}) {
71  for (unsigned int module : {0, 1, 2, 3}) {
72  deriv2ndHGThresh[side][module] = m_negHG2ndDerivThresh;
73  deriv2ndLGThresh[side][module] = m_negLG2ndDerivThresh;
74  }
75  }
76 
77  // We disable the EM module in the LG trigger
78  //
79  deriv2ndLGThresh[0][0] = 4095;
80  deriv2ndLGThresh[1][0] = 4095;
81 
82  std::cout << "Trigger simulation will use sample indices: " << m_minSampleAna
83  << " through " << m_maxSampleAna
84  << ", and baselinDelta = " << m_baselineDelta << std::endl;
85 
86  // Construct Simulation Objects
87  m_triggerSimHGPtr = std::make_shared<ZDCTriggerSimFADC>(
88  ZDCTriggerSimFADC(sideALUTHG, sideCLUTHG, combLUTHG, deriv2ndHGThresh,
90 
91  m_triggerSimLGPtr = std::make_shared<ZDCTriggerSimFADC>(
92  ZDCTriggerSimFADC(sideALUTLG, sideCLUTLG, combLUTLG, deriv2ndLGThresh,
94 
95  m_hgFADC_ptr =
96  std::make_shared<ZDCTriggerSim::FADCInputs>(ZDCTriggerSim::FADCInputs());
97  m_lgFADC_ptr =
98  std::make_shared<ZDCTriggerSim::FADCInputs>(ZDCTriggerSim::FADCInputs());
99 
100  ATH_MSG_DEBUG("TrigT1Run3ZDC initilized");
101  return StatusCode::SUCCESS;
102 }
103 
104 //----------------------------------------------
105 // execute() method called once per event
106 //----------------------------------------------
107 
108 StatusCode TrigT1Run3ZDC::execute(const EventContext& ctx) const {
109 
110  // create uints to hold trigger averages
111  unsigned int trigAvgAHG = 0;
112  unsigned int trigAvgCHG = 0;
113  unsigned int trigAvgALG = 0;
114  unsigned int trigAvgCLG = 0;
115 
116  // create multi-dim array to store event by event flash ADC values
117  std::array<std::array<std::array<unsigned int, 24>, 4>, 2> FADCSamplesHG;
118  std::array<std::array<std::array<unsigned int, 24>, 4>, 2> FADCSamplesLG;
119 
120  // create vectors to store flattened above multi
121  // dim arrays, in order to give the TriggerSimTool
122  // data in the proper format
123  std::vector<unsigned int> FADCFlattenedHG;
124  std::vector<unsigned int> FADCFlattenedLG;
125 
126  // access LUCROD data
127 
128  // use readhandle to retrive lucrodCollection
130 
131  for (const ZdcLucrodData *zld : *lucrodCollection) {
132 
133  // get lucrod board number
134  uint32_t lucrod_id = zld->GetLucrodID();
135 
136  // unpack data for each lucrod
137  for (size_t i = 0; i < zld->GetChanDataSize(); i++) {
138 
139  // create channel object
140  const ZdcLucrodChannel &zlc = zld->GetChanData(i);
141 
142  // figure out which channel we are reading out (0,1)
143  uint16_t lucrod_channel = zlc.id;
144 
145  // variable to hold if it is a ZDC (0) or RPD (1) type
146  // lucrod
148  lucrod_id)["type"][lucrod_channel];
149 
150  // trigger based on ZDC amplitudes, don't use
151  // RPD channels
152  if (type != 0) {
153  continue;
154  }
155 
156  // retrive what side, module, and gain we are reading out
158  lucrod_id)["side"][lucrod_channel];
160  lucrod_id)["module"][lucrod_channel];
162  lucrod_id)["gain"][lucrod_channel];
163 
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  // retrive 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 
261  return StatusCode::SUCCESS;
262 }
263 } // namespace LVL1
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LVL1::TrigT1Run3ZDC::m_negLG2ndDerivThresh
Gaudi::Property< unsigned int > m_negLG2ndDerivThresh
Definition: TrigT1Run3ZDC.h:84
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LVL1::TrigT1Run3ZDC::m_hgFADC_ptr
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 ...
Definition: TrigT1Run3ZDC.h:100
json
nlohmann::json json
Definition: TrigT1Run3ZDC.cxx:13
ZdcLucrodChannelType
Definition: ZdcLucrodData.h:12
xAOD::word1
word1
Definition: eFexEMRoI_v1.cxx:87
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1113
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
LVL1::TrigT1Run3ZDC::m_triggerSimLGPtr
std::shared_ptr< ZDCTriggerSimFADC > m_triggerSimLGPtr
Definition: TrigT1Run3ZDC.h:95
TrigT1Run3ZDC.h
LVL1::TrigT1Run3ZDC::m_zdcModuleCalibEnergyKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleCalibEnergyKey
Definition: TrigT1Run3ZDC.h:57
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
ZdcLucrodMapRun3::getLucrod
const nlohmann::json & getLucrod(int i) const
Definition: ZdcLucrodMapRun3.h:23
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LVL1::TrigT1Run3ZDC::m_zldContainerName
SG::ReadHandleKey< ZdcLucrodDataContainer > m_zldContainerName
Definition: TrigT1Run3ZDC.h:64
LVL1::TrigT1Run3ZDC::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigT1Run3ZDC.cxx:108
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
python.PyAthena.module
module
Definition: PyAthena.py:131
LVL1::TrigT1Run3ZDC::m_zdcId
const ZdcID * m_zdcId
Definition: TrigT1Run3ZDC.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
ZdcLucrodChannelType::waveform
std::vector< uint16_t > waveform
Definition: ZdcLucrodData.h:15
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ZdcLucrodMapRun3.h
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TrigConf::counter
Definition: HLTChainList.h:37
ZDCTriggerSimData
Definition: ZDCTriggerSim.h:58
LVL1::TrigT1Run3ZDC::m_maxSampleAna
Gaudi::Property< unsigned int > m_maxSampleAna
Definition: TrigT1Run3ZDC.h:79
LVL1::TrigT1Run3ZDC::m_negHG2ndDerivThresh
Gaudi::Property< unsigned int > m_negHG2ndDerivThresh
Definition: TrigT1Run3ZDC.h:81
ZDCTriggerSimFADC
Definition: ZDCTriggerSim.h:306
LVL1::TrigT1Run3ZDC::initialize
virtual StatusCode initialize() override
Definition: TrigT1Run3ZDC.cxx:21
LVL1::TrigT1Run3ZDC::m_baselineDelta
Gaudi::Property< unsigned int > m_baselineDelta
Definition: TrigT1Run3ZDC.h:87
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:283
ZdcID.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
LVL1::TrigT1Run3ZDC::m_zdcCTPLocation
SG::WriteHandleKey< ZdcCTP > m_zdcCTPLocation
Definition: TrigT1Run3ZDC.h:69
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ZdcLucrodData
Definition: ZdcLucrodData.h:20
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ZdcLucrodChannelType::id
unsigned int id
Definition: ZdcLucrodData.h:14
compute_lumi.fin
fin
Definition: compute_lumi.py:19
LVL1::TrigT1Run3ZDC::m_lutFile
Gaudi::Property< std::string > m_lutFile
Definition: TrigT1Run3ZDC.h:74
LVL1::TrigT1Run3ZDC::m_lgFADC_ptr
std::shared_ptr< ZDCTriggerSim::FADCInputs > m_lgFADC_ptr
Definition: TrigT1Run3ZDC.h:101
LVL1::TrigT1Run3ZDC::m_minSampleAna
Gaudi::Property< unsigned int > m_minSampleAna
Definition: TrigT1Run3ZDC.h:77
ZdcID
Definition: ZdcID.h:25
LVL1::TrigT1Run3ZDC::m_triggerSimHGPtr
std::shared_ptr< ZDCTriggerSimFADC > m_triggerSimHGPtr
Two data member to hold the ZDCTrigger Object that computes the LUT logic: shared ptr to ensure clean...
Definition: TrigT1Run3ZDC.h:94
ZdcLucrodMapRun3::getInstance
static const ZdcLucrodMapRun3 * getInstance()
Definition: ZdcLucrodMapRun3.cxx:10