ATLAS Offline Software
Loading...
Searching...
No Matches
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
15
16using json = nlohmann::json;
17
18//**********************************************************************
19namespace ZDC{
20ZdcTrigValidTool::ZdcTrigValidTool(const std::string& name)
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 }
53 json data = json::parse(fin);
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
78 ATH_CHECK( m_eventInfoKey.initialize());
79
80 return StatusCode::SUCCESS;
81
82}
83
84
85StatusCode ZdcTrigValidTool::recoZdcModules(const xAOD::ZdcModuleContainer& moduleContainer, const xAOD::ZdcModuleContainer& moduleSumContainer)
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
92 bool zdcErr = eventInfo->isEventFlagBitSet(xAOD::EventInfo::ForwardDet, ZdcEventInfo::ZDCDECODINGERROR );
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
154return StatusCode::SUCCESS;
155}
156} //namespace ZDC
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
nlohmann::json json
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Define enumerations for event-level ZDC data.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
std::map< std::string, unsigned int > m_triggerMap
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleAmp
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_trigValStatus
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.
Gaudi::Property< std::vector< std::string > > m_triggerList
virtual StatusCode recoZdcModules(const xAOD::ZdcModuleContainer &moduleContainer, const xAOD::ZdcModuleContainer &moduleSumContainer) override
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
ZdcTrigValidTool(const std::string &name)
Gaudi::Property< std::string > m_lutFile
virtual ~ZdcTrigValidTool() override
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
std::shared_ptr< ZDCTriggerSimModuleAmpls > m_simTrig
A data member to hold the ZDCTrigger Object that computes the LUT logic: shared ptr to ensure cleanup...
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
@ ForwardDet
The forward detectors.
ZDCTriggerSimData< float, 8, 12, TModAmplsInput > ModuleAmplInputsFloat
std::shared_ptr< const ZDCTriggerSimDataBase > SimDataCPtr
ZdcModuleContainer_v1 ZdcModuleContainer
TFile * file