ATLAS Offline Software
TrigT1ZDC.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #include <fstream>
5 #include <stdexcept>
6 #include <bitset>
7 #include "TrigT1ZDC.h"
8 
9 
11 
12 namespace LVL1 {
13 
14  //--------------------------------
15  // Constructors and destructors
16  //--------------------------------
17 
18  TrigT1ZDC::TrigT1ZDC (const std::string& name, ISvcLocator* pSvcLocator)
19  : AthReentrantAlgorithm( name, pSvcLocator ) {}
20 
21  //---------------------------------
22  // initialise()
23  //---------------------------------
24 
26  {
27  ATH_CHECK(m_zdcCTPLocation.initialize());
28  ATH_CHECK(m_zdcModuleKey.initialize());
30  // Find the full path to filename:
32  ATH_MSG_INFO("Reading file " << file);
33  std::ifstream fin(file.c_str());
34  if(!fin){
35  ATH_MSG_ERROR("Can not read file: " << file);
36  return StatusCode::FAILURE;
37  }
39 
40  // Conversion factor from Run2 Energies (GeV) to dynamic range of LUT (4096 entries)
41  std::vector<float> convfact;
42  // if EnergyToADCScaleFactor is 0, using Run3 Data
43  // this means we make trigger decisions based on real trigger amplitudes
44  convfact.push_back((m_energyToADCScaleFactor) ? static_cast<float>(m_energyToADCScaleFactor) : static_cast<float>(1.0));
45 
46  // Will eventually obtain LUTs from COOL, for now obtain them from calibration area
47  // A data member to hold the side A LUT values
48  std::array<unsigned int, 4096> sideALUT = data["LucrodHighGain"]["LUTs"]["sideA"];
49  // A data member to hold the side C LUT values
50  std::array<unsigned int, 4096> sideCLUT = data["LucrodHighGain"]["LUTs"]["sideC"];
51  // A data member to hold the Combined LUT values
52  std::array<unsigned int, 256> combLUT = data["LucrodHighGain"]["LUTs"]["comb"];
53 
54  // Construct Simulation Objects
55  m_modInputs_p = std::make_shared<ZDCTriggerSim::ModuleAmplInputsFloat>(ZDCTriggerSim::ModuleAmplInputsFloat(convfact));
56  m_simTrig = std::make_shared<ZDCTriggerSimModuleAmpls>(ZDCTriggerSimModuleAmpls(sideALUT, sideCLUT, combLUT));
57 
58  ATH_MSG_DEBUG("TrigT1ZDC initilized");
59  return StatusCode::SUCCESS;
60  }
61 
62  //----------------------------------------------
63  // execute() method called once per event
64  //----------------------------------------------
65 
66  StatusCode TrigT1ZDC::execute(const EventContext &ctx) const
67  {
68  // access ZDC modules
70  // access ZDC aux data
72  // create vector to store module CalibEnergy
73  std::vector<float> moduleEnergy = {0., 0., 0., 0., 0., 0., 0., 0.};
74 
75  // Read Single Modules
76  if (zdcModules.isValid())
77  {
78  for (const auto zdcModule : *zdcModules)
79  {
80  if (zdcModule->zdcType() == 0)
81  { // type = 0 are big modules, type = 1 the pixels
82 
83  ATH_MSG_DEBUG("ZDC Side " << zdcModule->zdcSide() << ", Module: " << zdcModule->zdcModule() << " and Energy: " << zdcModuleCalibEnergyHandle(*zdcModule));
84  // Side A
85  if (zdcModule->zdcSide() > 0)
86  {
87  moduleEnergy.at(zdcModule->zdcModule()) = (!m_energyToADCScaleFactor && zdcModule->isAvailable<uint16_t>("LucrodTriggerAmp")) ? static_cast<float>(zdcModule->auxdataConst<uint16_t>("LucrodTriggerAmp")) : zdcModuleCalibEnergyHandle(*zdcModule);
88  }
89 
90  // Side C
91  if (zdcModule->zdcSide() < 0)
92  {
93  moduleEnergy.at(zdcModule->zdcModule() + 4) = (!m_energyToADCScaleFactor && zdcModule->isAvailable<uint16_t>("LucrodTriggerAmp")) ? static_cast<float>(zdcModule->auxdataConst<uint16_t>("LucrodTriggerAmp")) : zdcModuleCalibEnergyHandle(*zdcModule);
94  }
95  }
96  }
97  }
98 
99  // Get Output as an integer (0-7)
100  m_modInputs_p->setData(moduleEnergy);
101 
102  // call ZDCTriggerSim to actually get ZDC Bits
103  unsigned int wordOut = m_simTrig->simLevel1Trig(ZDCTriggerSim::SimDataCPtr(m_modInputs_p));
104 
105  // convert int to bitset
106  std::bitset<3> bin(wordOut);
107 
108  // load output into trigger word on correct bits
109  unsigned int word0 = 0;
110  word0 += (bin[0] << 25);
111  word0 += (bin[1] << 26);
112  word0 += (bin[2] << 27);
113 
114  // form CTP obejct
116 
117  //record CTP object
118  ATH_CHECK(zdcCTP.record(std::make_unique<ZdcCTP>(word0)));
119  ATH_MSG_DEBUG("Stored ZDC CTP object with words " << std::hex << (zdcCTP->cableWord0()) << " from LUTOutput " << std::dec << wordOut);
120  return StatusCode::SUCCESS;
121  }
122  }
LVL1::TrigT1ZDC::TrigT1ZDC
TrigT1ZDC(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigT1ZDC.cxx:18
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
LVL1::TrigT1ZDC::m_zdcModuleCalibEnergyKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleCalibEnergyKey
Definition: TrigT1ZDC.h:57
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:983
bin
Definition: BinsDiffFromStripMedian.h:43
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
ZDCTriggerSimModuleAmpls
Definition: ForwardDetectors/ZDC/ZdcUtils/ZdcUtils/ZDCTriggerSim.h:262
LVL1::TrigT1ZDC::initialize
virtual StatusCode initialize() override
Definition: TrigT1ZDC.cxx:25
LVL1::TrigT1ZDC::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: TrigT1ZDC.h:69
LVL1::TrigT1ZDC::m_lutFile
Gaudi::Property< std::string > m_lutFile
Definition: TrigT1ZDC.h:65
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigT1ZDC.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
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
json
nlohmann::json json
Definition: TrigT1ZDC.cxx:10
file
TFile * file
Definition: tile_monitor.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ZDCTriggerSim::SimDataCPtr
std::shared_ptr< const ZDCTriggerSimDataBase > SimDataCPtr
Definition: ForwardDetectors/ZDC/ZdcUtils/ZdcUtils/ZDCTriggerSim.h:162
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
ZDCTriggerSimData
Definition: ForwardDetectors/ZDC/ZdcUtils/ZdcUtils/ZDCTriggerSim.h:58
LVL1::TrigT1ZDC::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigT1ZDC.cxx:66
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
LVL1::TrigT1ZDC::m_energyToADCScaleFactor
Gaudi::Property< float > m_energyToADCScaleFactor
Definition: TrigT1ZDC.h:66
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
LVL1::TrigT1ZDC::m_zdcCTPLocation
SG::WriteHandleKey< ZdcCTP > m_zdcCTPLocation
Definition: TrigT1ZDC.h:60
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
compute_lumi.fin
fin
Definition: compute_lumi.py:19
LVL1::TrigT1ZDC::m_zdcModuleKey
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleKey
Definition: TrigT1ZDC.h:52
LVL1::TrigT1ZDC::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: TrigT1ZDC.h:72