ATLAS Offline Software
ZdcTrigValidTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <fstream>
8 #include <bitset>
9 #include <stdexcept>
12 
14 #include "ZdcUtils/ZdcEventInfo.h"
15 
17 
18 //**********************************************************************
19 namespace ZDC{
21  : asg::AsgTool(name), m_name(name)
22  {
23 
24 #ifndef XAOD_STANDALONE
25  declareInterface<IZdcAnalysisTool>(this);
26 #endif
27  declareProperty("Message", m_msg = "");
28  declareProperty("WriteAux", m_writeAux = true);
29  declareProperty("AuxSuffix", m_auxSuffix = "");
30 }
31 
32 //**********************************************************************
33 
35 {
36  ATH_MSG_DEBUG("Deleting ZdcTrigValidTool named " << m_name);
37 }
38 
40 
41  ATH_MSG_INFO("Initialising tool " << m_name);
42  ATH_CHECK(m_trigDecTool.retrieve());
43  ATH_MSG_INFO("TDT retrieved");
44 
45  // Find the full path to filename:
47  ATH_MSG_INFO("Reading file " << file);
48  std::ifstream fin(file.c_str());
49  if(!fin){
50  ATH_MSG_ERROR("Can not read file: " << file);
51  return StatusCode::FAILURE;
52  }
54 
55  // Obtain LUTs from Calibration Area
56  // A data member to hold the side A LUT values
57  std::array<unsigned int, 4096> sideALUT = data["LucrodHighGain"]["LUTs"]["sideA"];
58  // A data member to hold the side C LUT values
59  std::array<unsigned int, 4096> sideCLUT = data["LucrodHighGain"]["LUTs"]["sideC"];
60  // A data member to hold the Combined LUT values
61  std::array<unsigned int, 256> combLUT = data["LucrodHighGain"]["LUTs"]["comb"];
62 
63  //Construct Trigger Map
64  m_triggerMap.insert({"L1_ZDC_BIT0",0});
65  m_triggerMap.insert({"L1_ZDC_BIT1",1});
66  m_triggerMap.insert({"L1_ZDC_BIT2",2});
67 
68  // Construct Simulation Objects
69  m_modInputs_p = std::make_shared<ZDCTriggerSim::ModuleAmplInputsFloat>(ZDCTriggerSim::ModuleAmplInputsFloat());
70  m_simTrig = std::make_shared<ZDCTriggerSimModuleAmpls>(ZDCTriggerSimModuleAmpls(sideALUT, sideCLUT, combLUT));
71  ATH_MSG_INFO(m_name<<" Initialised");
72 
73  m_zdcModuleAmp = "ZdcModules.Amplitude"+m_auxSuffix;
74  ATH_CHECK(m_zdcModuleAmp.initialize());
75  m_trigValStatus = "ZdcSums.TrigValStatus"+m_auxSuffix;
76  ATH_CHECK(m_trigValStatus.initialize());
77 
79 
80  return StatusCode::SUCCESS;
81 
82 }
83 
84 
86 {
87  std::vector<float> moduleEnergy = {0., 0., 0., 0., 0., 0., 0., 0.};
88 
90  if (!eventInfo.isValid()) return StatusCode::FAILURE;
91  // Check for decoding errors and bail out if ZDC error found
93  if (zdcErr)
94  {
95  ATH_MSG_WARNING("ZDC decoding error found - abandoning ZdcTrigValidTool!");
96  return StatusCode::SUCCESS;
97  }
98 
100 
101  bool trigMatch = false;
102  for (const auto zdcModule : moduleContainer) {
103 
104  if (zdcModule->zdcType() == 1) continue;
105 
106  // Side A
107  if (zdcModule->zdcSide() > 0) {
108  moduleEnergy.at(zdcModule->zdcModule()) = zdcModuleAmp(*zdcModule);
109  }
110 
111  // Side C
112  if (zdcModule->zdcSide() < 0) {
113  moduleEnergy.at(zdcModule->zdcModule() + 4) = zdcModuleAmp(*zdcModule);
114  }
115  }
116  // Get Output as an integer (0-7)
117  m_modInputs_p->setData(moduleEnergy);
118 
119  // call ZDCTriggerSim to actually get ZDC Bits
120  unsigned int wordOut = m_simTrig->simLevel1Trig(ZDCTriggerSim::SimDataCPtr(m_modInputs_p));
121 
122  // convert int to bitset
123  std::bitset<3> bin(wordOut);
124 
125  // get trigger decision tool
126  const auto &trigDecTool = m_trigDecTool;
127  unsigned int wordOutCTP = 0;
128 
129 
130  // iterate through zdc bit output from CTP, validate that they match above bitset
131  for (const auto &trig : m_triggerList)
132  {
133 
134  if (m_triggerMap.find(trig) == m_triggerMap.end())
135  continue;
136  if (not trigDecTool->isPassed(trig, TrigDefs::Physics | TrigDefs::allowResurrectedDecision))
137  {
138  ATH_MSG_DEBUG("Chain " << trig << " is passed: NO");
139  continue;
140  }
141  ATH_MSG_DEBUG("Chain " << trig << " is passed: YES");
142  wordOutCTP += 1 << m_triggerMap[trig];
143  }
144 
145  trigMatch = (wordOut == wordOutCTP) ? 1 : 0;
147 
148  // write 1 if decision from ZDC firmware matches CTP, 0 otherwize
149  for(const auto zdc_sum : moduleSumContainer){
150  if(m_writeAux) trigValStatus(*zdc_sum) = trigMatch;
151  }
152  ATH_MSG_DEBUG("ZDC Trigger Status: " << trigMatch);
153 
154 return StatusCode::SUCCESS;
155 }
156 } //namespace ZDC
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ZDC::ZdcTrigValidTool::m_trigDecTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
Definition: ZdcTrigValidTool.h:46
ZDC::ZdcTrigValidTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: ZdcTrigValidTool.cxx:39
ZDCTriggerSim::SimDataCPtr
std::shared_ptr< const ZDCTriggerSimDataBase > SimDataCPtr
Definition: ZDCTriggerSim.h:170
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ZDC::ZdcTrigValidTool::~ZdcTrigValidTool
virtual ~ZdcTrigValidTool() override
Definition: ZdcTrigValidTool.cxx:34
ZDC::ZdcTrigValidTool::m_triggerMap
std::map< std::string, unsigned int > m_triggerMap
Definition: ZdcTrigValidTool.h:62
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ZDC::ZdcTrigValidTool::m_triggerList
Gaudi::Property< std::vector< std::string > > m_triggerList
Definition: ZdcTrigValidTool.h:51
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
ZDC::ZdcTrigValidTool::m_auxSuffix
std::string m_auxSuffix
Definition: ZdcTrigValidTool.h:63
asg
Definition: DataHandleTestTool.h:28
ZDC::ZdcTrigValidTool::m_modInputs_p
std::shared_ptr< ZDCTriggerSim::ModuleAmplInputsFloat > m_modInputs_p
A data member to hold the ZDCTrigger Object that stores input floats: shared ptr to ensure cleanup.
Definition: ZdcTrigValidTool.h:56
ZDCTriggerSimModuleAmpls
Definition: ZDCTriggerSim.h:279
ZDC::ZdcTrigValidTool::m_simTrig
std::shared_ptr< ZDCTriggerSimModuleAmpls > m_simTrig
A data member to hold the ZDCTrigger Object that computes the LUT logic: shared ptr to ensure cleanup...
Definition: ZdcTrigValidTool.h:59
ZDC::ZdcTrigValidTool::m_name
std::string m_name
Definition: ZdcTrigValidTool.h:64
ZDC::ZdcTrigValidTool::ZdcTrigValidTool
ZdcTrigValidTool(const std::string &name)
Definition: ZdcTrigValidTool.cxx:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
ZDC::ZdcTrigValidTool::m_trigValStatus
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_trigValStatus
Definition: ZdcTrigValidTool.h:68
ZdcEventInfo::ZDCDECODINGERROR
@ ZDCDECODINGERROR
Definition: ZdcEventInfo.h:19
ZDC::ZdcTrigValidTool::recoZdcModules
virtual StatusCode recoZdcModules(const xAOD::ZdcModuleContainer &moduleContainer, const xAOD::ZdcModuleContainer &moduleSumContainer) override
Definition: ZdcTrigValidTool.cxx:85
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ZDC::ZdcTrigValidTool::m_writeAux
bool m_writeAux
Definition: ZdcTrigValidTool.h:65
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::EventInfo_v1::ForwardDet
@ ForwardDet
The forward detectors.
Definition: EventInfo_v1.h:338
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ZDCTriggerSimData
Definition: ZDCTriggerSim.h:58
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
EventInfo.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ZDC
Definition: RPDAnalysisTool.cxx:12
ReadDecorHandle.h
Handle class for reading a decoration on an object.
compute_lumi.fin
fin
Definition: compute_lumi.py:19
xAOD::EventInfo_v1::isEventFlagBitSet
bool isEventFlagBitSet(EventFlagSubDet subDet, size_t bit) const
Check one particular bit of one particular sub-detector.
Definition: EventInfo_v1.cxx:703
ZDC::ZdcTrigValidTool::m_zdcModuleAmp
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleAmp
Definition: ZdcTrigValidTool.h:67
json
nlohmann::json json
Definition: ZdcTrigValidTool.cxx:16
ZDC::ZdcTrigValidTool::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: ZdcTrigValidTool.h:70
ZdcTrigValidTool.h
ZdcEventInfo.h
Define enumerations for event-level ZDC data.
ZDC::ZdcTrigValidTool::m_msg
std::string m_msg
Definition: ZdcTrigValidTool.h:61
ZDC::ZdcTrigValidTool::m_lutFile
Gaudi::Property< std::string > m_lutFile
Definition: ZdcTrigValidTool.h:53