ATLAS Offline Software
TrigT1Run3ZDC.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 // Constructors and destructors
19 //--------------------------------
20 
21 TrigT1Run3ZDC::TrigT1Run3ZDC(const std::string &name, ISvcLocator *pSvcLocator)
22  : AthAlgorithm(name, pSvcLocator) {}
23 
24 //---------------------------------
25 // initialise()
26 //---------------------------------
27 
29  ATH_CHECK(m_zdcCTPLocation.initialize());
32  // Find the full path to filename:
34  ATH_MSG_INFO("Reading file " << file);
35  std::ifstream fin(file.c_str());
36  if (!fin) {
37  ATH_MSG_ERROR("Can not read file: " << file);
38  return StatusCode::FAILURE;
39  }
41 
42  // Will eventually obtain LUTs from COOL, for now obtain them from calibration
43  // area A data member to hold the side A LUT values
44  std::array<unsigned int, 4096> sideALUTHG =
45  data["LucrodHighGain"]["LUTs"]["sideA"];
46  // A data member to hold the side C LUT values
47  std::array<unsigned int, 4096> sideCLUTHG =
48  data["LucrodHighGain"]["LUTs"]["sideC"];
49  // A data member to hold the Combined LUT values
50  std::array<unsigned int, 256> combLUTHG =
51  data["LucrodHighGain"]["LUTs"]["comb"];
52  // area A data member to hold the side A LUT values
53  std::array<unsigned int, 4096> sideALUTLG =
54  data["LucrodLowGain"]["LUTs"]["sideA"];
55  // A data member to hold the side C LUT values
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  ZDCTriggerSimFADC(sideALUTHG, sideCLUTHG, combLUTHG, deriv2ndHGThresh,
97 
98  m_triggerSimLGPtr = std::make_shared<ZDCTriggerSimFADC>(
99  ZDCTriggerSimFADC(sideALUTLG, sideCLUTLG, combLUTLG, deriv2ndLGThresh,
101 
102  m_hgFADC_ptr =
103  std::make_shared<ZDCTriggerSim::FADCInputs>(ZDCTriggerSim::FADCInputs());
104  m_lgFADC_ptr =
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 
116 
117  const EventContext &ctx = Gaudi::Hive::currentContext();
118 
119  // create uints to hold trigger averages
120  unsigned int trigAvgAHG = 0;
121  unsigned int trigAvgCHG = 0;
122  unsigned int trigAvgALG = 0;
123  unsigned int trigAvgCLG = 0;
124 
125  // create multi-dim array to store event by event flash ADC values
126  std::array<std::array<std::array<unsigned int, 24>, 4>, 2> FADCSamplesHG;
127  std::array<std::array<std::array<unsigned int, 24>, 4>, 2> FADCSamplesLG;
128 
129  // create vectors to store flattened above multi
130  // dim arrays, in order to give the TriggerSimTool
131  // data in the proper format
132  std::vector<unsigned int> FADCFlattenedHG;
133  std::vector<unsigned int> FADCFlattenedLG;
134 
135  // access LUCROD data
136 
137  // use readhandle to retrive lucrodCollection
139 
140  for (const ZdcLucrodData *zld : *lucrodCollection) {
141 
142  // get lucrod board number
143  uint32_t lucrod_id = zld->GetLucrodID();
144 
145  // unpack data for each lucrod
146  for (size_t i = 0; i < zld->GetChanDataSize(); i++) {
147 
148  // create channel object
149  const ZdcLucrodChannel &zlc = zld->GetChanData(i);
150 
151  // figure out which channel we are reading out (0,1)
152  uint16_t lucrod_channel = zlc.id;
153 
154  // variable to hold if it is a ZDC (0) or RPD (1) type
155  // lucrod
157  lucrod_id)["type"][lucrod_channel];
158 
159  // trigger based on ZDC amplitudes, don't use
160  // RPD channels
161  if (type != 0) {
162  continue;
163  }
164 
165  // retrive what side, module, and gain we are reading out
167  lucrod_id)["side"][lucrod_channel];
169  lucrod_id)["module"][lucrod_channel];
171  lucrod_id)["gain"][lucrod_channel];
172 
173  // Fill different flash ADC vectors for Low and High
174  // gain samples
175  if (gain == 0) {
176  unsigned int counter = 0;
177  for (const auto &sample : zlc.waveform) {
178  // fill low gain FADC samples
179  FADCSamplesLG.at((side == 1)).at(module).at(counter) = sample;
180  counter++;
181  }
182  } else if (gain == 1) {
183  unsigned int counter = 0;
184  for (const auto &sample : zlc.waveform) {
185  // fill high gain FADC samples
186  FADCSamplesHG.at((side == 1)).at(module).at(counter) = sample;
187  counter++;
188  }
189  }
190  // retrive Trig Avg amp for debugging
191  // from both LG and HG modules
192  if (side * gain * module == 3) {
193  trigAvgAHG = zld->GetTrigAvgA();
194  trigAvgCHG = zld->GetTrigAvgC();
195  } else if (side * module == 3) {
196  trigAvgALG = zld->GetTrigAvgA();
197  trigAvgCLG = zld->GetTrigAvgC();
198  }
199  }
200  } // end lucrod loop
201 
202  // unpack FADC data into one long vector for both
203  // high and low gain
204  for (int side : {1, 0}) {
205  for (int module : {0, 1, 2, 3}) {
206  for (const auto sample : FADCSamplesLG.at(side).at(module)) {
207  FADCFlattenedLG.push_back(sample);
208  }
209  }
210  }
211 
212  for (int side : {1, 0}) {
213  for (int module : {0, 1, 2, 3}) {
214  for (const auto sample : FADCSamplesHG.at(side).at(module)) {
215  FADCFlattenedHG.push_back(sample);
216  }
217  }
218  }
219 
220  // set data in Trigger Sim Object
221  m_hgFADC_ptr->setData(FADCFlattenedHG);
222  m_lgFADC_ptr->setData(FADCFlattenedLG);
223 
224  // call ZDCTriggerSim to actually get L1 decisions
225  unsigned int wordOutHG = m_triggerSimHGPtr->simLevel1Trig(m_hgFADC_ptr);
226  unsigned int wordOutLG = m_triggerSimLGPtr->simLevel1Trig(m_lgFADC_ptr);
227 
228  // convert int to bitset for ZDC Triggers
229  std::bitset<3> binhg(wordOutHG);
230 
231  // convert int to bitset for ZDC ALT Trigggers
232  std::bitset<3> binlg(wordOutLG);
233 
234  // ZDC L1 items are located on CTPIN SLOT 9
235  // Each slot holds 4 connectors that each carry a 32 bit trigger word
236  // ZDC HG items are located on Connector 1 (CTPCAL)
237  // at bits 25, 26, 27
238  // ZDC LG (UCC) items are located on Connector 3 (NIM3)
239  // at bits 28, 29, 30
240  // for more info see
241  // twiki.cern.ch/twiki/bin/view/Atlas/LevelOneCentralTriggerSetup#CTPIN_Slot_9
242 
243  // load HG output into trigger word on correct bits
244  unsigned int word0 = 0;
245  word0 += (binhg[0] << 25);
246  word0 += (binhg[1] << 26);
247  word0 += (binhg[2] << 27);
248 
249  // load LG output into trigger word on correct bits
250  unsigned int word1 = 0;
251  word1 += (binlg[0] << 28);
252  word1 += (binlg[1] << 29);
253  word1 += (binlg[2] << 30);
254 
255  // form CTP obejct
257 
258  // record CTP object
259  ATH_CHECK(zdcCTP.record(std::make_unique<ZdcCTP>(word0, word1)));
260 
261  // debug output
263  "Stored ZDC CTP object with words "
264  << std::endl
265  << std::hex << word0 << " from hgLUTOutput: " << std::dec << wordOutHG
266  << " AvgAmpA: " << trigAvgAHG << " C: " << trigAvgCHG << std::endl
267  << std::hex << word1 << " from lgLUTOutput: " << std::dec << wordOutLG
268  << " AvgAmpA: " << trigAvgALG << " C: " << trigAvgCLG);
269 
270  return StatusCode::SUCCESS;
271 }
272 } // 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:85
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:101
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:70
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LVL1::TrigT1Run3ZDC::m_triggerSimLGPtr
std::shared_ptr< ZDCTriggerSimFADC > m_triggerSimLGPtr
Definition: TrigT1Run3ZDC.h:96
TrigT1Run3ZDC.h
LVL1::TrigT1Run3ZDC::m_zdcModuleCalibEnergyKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleCalibEnergyKey
Definition: TrigT1Run3ZDC.h:58
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
AthCommonDataStore< AthCommonMsg< 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:65
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:270
python.PyAthena.module
module
Definition: PyAthena.py:131
LVL1::TrigT1Run3ZDC::m_zdcId
const ZdcID * m_zdcId
Definition: TrigT1Run3ZDC.h:63
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:113
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
AthAlgorithm
Definition: AthAlgorithm.h:47
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::counter
Definition: HLTChainList.h:37
LVL1::TrigT1Run3ZDC::TrigT1Run3ZDC
TrigT1Run3ZDC(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigT1Run3ZDC.cxx:21
ZDCTriggerSimData
Definition: ZDCTriggerSim.h:58
LVL1::TrigT1Run3ZDC::m_maxSampleAna
Gaudi::Property< unsigned int > m_maxSampleAna
Definition: TrigT1Run3ZDC.h:80
LVL1::TrigT1Run3ZDC::m_negHG2ndDerivThresh
Gaudi::Property< unsigned int > m_negHG2ndDerivThresh
Definition: TrigT1Run3ZDC.h:82
ZDCTriggerSimFADC
Definition: ZDCTriggerSim.h:306
LVL1::TrigT1Run3ZDC::initialize
virtual StatusCode initialize() override
Definition: TrigT1Run3ZDC.cxx:28
LVL1::TrigT1Run3ZDC::m_baselineDelta
Gaudi::Property< unsigned int > m_baselineDelta
Definition: TrigT1Run3ZDC.h:88
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
ZdcID.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
LVL1::TrigT1Run3ZDC::m_zdcCTPLocation
SG::WriteHandleKey< ZdcCTP > m_zdcCTPLocation
Definition: TrigT1Run3ZDC.h:70
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ZdcLucrodData
Definition: ZdcLucrodData.h:20
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< 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:75
LVL1::TrigT1Run3ZDC::execute
virtual StatusCode execute() override
Definition: TrigT1Run3ZDC.cxx:115
LVL1::TrigT1Run3ZDC::m_lgFADC_ptr
std::shared_ptr< ZDCTriggerSim::FADCInputs > m_lgFADC_ptr
Definition: TrigT1Run3ZDC.h:102
LVL1::TrigT1Run3ZDC::m_minSampleAna
Gaudi::Property< unsigned int > m_minSampleAna
Definition: TrigT1Run3ZDC.h:78
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:95
ZdcLucrodMapRun3::getInstance
static const ZdcLucrodMapRun3 * getInstance()
Definition: ZdcLucrodMapRun3.cxx:10