ATLAS Offline Software
Loading...
Searching...
No Matches
EnergyCMX.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// /***************************************************************************
6// EnergyCMX.cxx - description
7// -------------------
8 // begin : 04 04 2014
9 // email : Alan.Watson@cern.ch
10// ***************************************************************************/
11//
12//================================================
13// EnergyCMX class Implementation
14// ================================================
15//
16//
17//
18//
19
20// Utilities
21#include <cmath>
22
23
24// This algorithm includes
25#include "EnergyCMX.h"
26
28
29using namespace TrigConf;
30
31namespace LVL1 {
32
33
34//--------------------------------
35// Constructors and destructors
36//--------------------------------
37
38EnergyCMX::EnergyCMX (const std::string& name, ISvcLocator* pSvcLocator)
39 : AthReentrantAlgorithm( name, pSvcLocator ) {}
40
41
42//---------------------------------
43// initialise()
44//---------------------------------
45
47{
48 ATH_CHECK( m_EtTool.retrieve() );
49 ATH_CHECK( m_energyCMXDataLocation.initialize() );
50 ATH_CHECK( m_energyCTPLocation.initialize() );
51 ATH_CHECK( m_energyTopoLocation.initialize() );
52 ATH_CHECK( m_cmxEtsumsLocation.initialize() );
53 ATH_CHECK( m_cmxRoILocation.initialize() );
54 ATH_CHECK( m_L1MenuKey.initialize() );
55 return StatusCode::SUCCESS ;
56}
57
58
59//-------------------------------------------------
60// Set cabling: seems to be required
61//-------------------------------------------------
62
63StatusCode EnergyCMX::start()
64{
66
67 return StatusCode::SUCCESS ;
68}
69
70
71//----------------------------------------------
72// execute() method called once per event
73//----------------------------------------------
74//
75
76
77StatusCode EnergyCMX::execute(const EventContext& ctx) const
78{
79 ATH_MSG_DEBUG( "Executing" );
80
81 // form module sums
83
84 // form crate sums (full eta range)
86 m_EtTool->crateSums(jemContainer.cptr(), cratesFull);
87 // system summation and threshold tests
88 const SystemEnergy resultsFull = m_EtTool->systemSums(cratesFull);
89
93 uint32_t maskXE = 0;
94 uint32_t maskTE = 0;
95 bool maskXESet = false;
96 bool maskTESet = false;
97 const float moduleEta[8] = {-4.,-2.,-1.2,-0.4,0.4,1.2,2.,4.};
98
99 auto l1Menu = SG::makeHandle( m_L1MenuKey, ctx );
100 std::vector<std::shared_ptr<TrigConf::L1Threshold>> allThresholds = l1Menu->thresholds();
101 for ( const auto& thresh : allThresholds ) {
102 if ( ( thresh->type() == L1DataDef::typeAsString(L1DataDef::XE) || thresh->type() == L1DataDef::typeAsString(L1DataDef::TE)) && thresh->mapping() > 7 ) {
103 auto thresh_Calo = static_cast<const TrigConf::L1Threshold_Calo*>(thresh.get());
104 auto tvcs = thresh_Calo->thrValuesCounts();
105 // Make sure only set masks from the first valid threshold in the range (for each type)
106 if (maskXE > 0) maskXESet = true;
107 if (maskTE > 0) maskTESet = true;
108 if (tvcs.size() == 0) {
109 tvcs.addRangeValue(thresh_Calo->thrValueCounts(),-49, 49, 1, true);
110 }
111 for (const auto& tVC : tvcs) {
112 // Bits are set false by default, so ignore thresholds that are just doing that
113 if (tVC.value() >= 0x7fff) continue;
114 // Set bits true if module centre between etaMin and etaMax
115 if ( thresh->type() == L1DataDef::typeAsString(L1DataDef::XE) && !maskXESet ) {
116 for (unsigned int bin = 0; bin < 8; ++bin) {
117 if (moduleEta[bin] > tVC.etaMin()*0.1 && moduleEta[bin] < tVC.etaMax()*0.1)
118 maskXE |= (1<<bin);
119 }
120 }
121 else if ( thresh->type() == L1DataDef::typeAsString(L1DataDef::TE) && !maskTESet ) {
122 for (unsigned int bin = 0; bin < 8; ++bin) {
123 if (moduleEta[bin] > tVC.etaMin()*0.1 && moduleEta[bin] < tVC.etaMax()*0.1)
124 maskTE |= (1<<bin);
125 }
126 }
127 } // loop over TTV
128 } // Is this XE or TE threshold?
129 }
130
131 // form crate sums (restricted eta range). Explicitly set restricted eta flag regardless of eta range
133 m_EtTool->crateSums(jemContainer.cptr(), cratesTrunc, maskXE, maskTE, true);
134 // system summation and threshold tests
135 const SystemEnergy resultsTrunc = m_EtTool->systemSums(cratesTrunc);
136
137 // CTP Data
138 ATH_CHECK(saveCTPObjects(resultsFull, resultsTrunc, ctx));
139
140 // RoI output
141 ATH_CHECK(saveRoIs(resultsFull, resultsTrunc, ctx));
142
143 // Module readout simulation
145 ATH_CHECK(CMXSums.record(std::make_unique<CMXEtSumsCollection>()));
146
147 std::vector<unsigned int> exVec;
148 std::vector<unsigned int> eyVec;
149 std::vector<unsigned int> etVec;
150 std::vector<int> exErr;
151 std::vector<int> eyErr;
152 std::vector<int> etErr;
153 exErr.assign(1,0);
154 eyErr.assign(1,0);
155 etErr.assign(1,0);
156 const int peak = 0;
157 const int system_crate = 1;
158
159 // Full eta range
160 DataVector<CrateEnergy>::const_iterator itCrate = cratesFull->begin();
161 for ( ; itCrate != cratesFull->end(); ++itCrate) {
162 exVec.clear();
163 exVec.push_back((*itCrate)->exTC());
164 eyVec.clear();
165 eyVec.push_back((*itCrate)->eyTC());
166 etVec.clear();
167 etVec.push_back((*itCrate)->et());
168 int crate = (*itCrate)->crate();
169 CMXEtSums* crateEtSumFull = new CMXEtSums(crate, LVL1::CMXEtSums::LOCAL_STANDARD,
170 exVec, eyVec, etVec, exErr, eyErr, etErr, peak);
171 CMXSums->push_back(crateEtSumFull);
172
173 if (crate != system_crate) {
174 CMXEtSums* remoteEtSumFull = new CMXEtSums(system_crate, LVL1::CMXEtSums::REMOTE_STANDARD,
175 exVec, eyVec, etVec, exErr, eyErr, etErr, peak);
176 CMXSums->push_back(remoteEtSumFull);
177 }
178
179 }
180
181 exVec.clear();
182 exVec.push_back(resultsFull.exTC());
183 eyVec.clear();
184 eyVec.push_back(resultsFull.eyTC());
185 etVec.clear();
186 etVec.push_back(resultsFull.et());
187 CMXEtSums* systemEtSumFull = new CMXEtSums(system_crate, LVL1::CMXEtSums::TOTAL_STANDARD,
188 exVec, eyVec, etVec, exErr, eyErr, etErr, peak);
189 CMXSums->push_back(systemEtSumFull);
190
191 // Restricted eta range
192 DataVector<CrateEnergy>::const_iterator itTrunc = cratesTrunc->begin();
193 for ( ; itTrunc != cratesTrunc->end(); ++itTrunc) {
194 exVec.clear();
195 exVec.push_back((*itTrunc)->exTC());
196 eyVec.clear();
197 eyVec.push_back((*itTrunc)->eyTC());
198 etVec.clear();
199 etVec.push_back((*itTrunc)->et());
200 int crate = (*itTrunc)->crate();
201 CMXEtSums* crateEtSumTrunc = new CMXEtSums(crate, LVL1::CMXEtSums::LOCAL_RESTRICTED,
202 exVec, eyVec, etVec, exErr, eyErr, etErr, peak);
203 CMXSums->push_back(crateEtSumTrunc);
204
205 if (crate != system_crate) {
206 CMXEtSums* remoteEtSumTrunc = new CMXEtSums(system_crate, LVL1::CMXEtSums::REMOTE_RESTRICTED,
207 exVec, eyVec, etVec, exErr, eyErr, etErr, peak);
208 CMXSums->push_back(remoteEtSumTrunc);
209 }
210
211 }
212
213 exVec.clear();
214 exVec.push_back(resultsTrunc.exTC());
215 eyVec.clear();
216 eyVec.push_back(resultsTrunc.eyTC());
217 etVec.clear();
218 etVec.push_back(resultsTrunc.et());
219 CMXEtSums* systemEtSumTrunc = new CMXEtSums(system_crate, LVL1::CMXEtSums::TOTAL_RESTRICTED,
220 exVec, eyVec, etVec, exErr, eyErr, etErr, peak);
221
222 CMXSums->push_back(systemEtSumTrunc);
223
224 // Topo data
226 ATH_CHECK(topoData.record(std::make_unique<EnergyTopoData>()));
227
228 topoData->addEx(resultsFull.exTC(), resultsFull.exOverflow(), LVL1::EnergyTopoData::Normal);
229 topoData->addEy(resultsFull.eyTC(), resultsFull.eyOverflow(), LVL1::EnergyTopoData::Normal);
230 topoData->addEt(resultsFull.et(), resultsFull.etOverflow(), LVL1::EnergyTopoData::Normal);
231
232 topoData->addEx(resultsTrunc.exTC(), resultsTrunc.exOverflow(), LVL1::EnergyTopoData::Restricted);
233 topoData->addEy(resultsTrunc.eyTC(), resultsTrunc.eyOverflow(), LVL1::EnergyTopoData::Restricted);
234 topoData->addEt(resultsTrunc.et(), resultsTrunc.etOverflow(), LVL1::EnergyTopoData::Restricted);
235
236 // tidy up at end of event
237 delete cratesFull;
238 delete cratesTrunc;
239
240 return StatusCode::SUCCESS ;
241}
242
243} // end of LVL1 namespace bracket
244
245
247StatusCode LVL1::EnergyCMX::saveRoIs(const SystemEnergy& resultsFull,
248 const SystemEnergy& resultsTrunc,
249 const EventContext& ctx) const {
250 ATH_MSG_DEBUG("saveRoIs");
251
252 // copy values into roi words
253 unsigned int roiWord0 = resultsFull.roiWord0();
254 unsigned int roiWord2 = resultsFull.roiWord1();
255 unsigned int roiWord4 = resultsFull.roiWord2();
256
257 // Truncated eta range
258 unsigned int roiWord1 = resultsTrunc.roiWord0();
259 unsigned int roiWord3 = resultsTrunc.roiWord1();
260 unsigned int roiWord5 = resultsTrunc.roiWord2();
261
262 // DAQ readout object.
264 ATH_CHECK(daqRoI.record(std::make_unique<CMXRoI>()));
265
266 // Add data to RoI object. The object will perform format checks on inputs
267 bool added = daqRoI->setRoiWord(roiWord0);
268 if (!added) ATH_MSG_WARNING("Failed to add RoI Word 0: " << MSG::hex << roiWord0 << MSG::dec);
269 added = daqRoI->setRoiWord(roiWord1);
270 if (!added) ATH_MSG_WARNING("Failed to add RoI Word 1: " << MSG::hex << roiWord1 << MSG::dec);
271 added = daqRoI->setRoiWord(roiWord2);
272 if (!added) ATH_MSG_WARNING( "Failed to add RoI Word 2: " << MSG::hex << roiWord2 << MSG::dec );
273 added = daqRoI->setRoiWord(roiWord3);
274 if (!added) ATH_MSG_WARNING( "Failed to add RoI Word 3: " << MSG::hex << roiWord3 << MSG::dec );
275 added = daqRoI->setRoiWord(roiWord4);
276 if (!added) ATH_MSG_WARNING( "Failed to add RoI Word 4: " << MSG::hex << roiWord4 << MSG::dec );
277 added = daqRoI->setRoiWord(roiWord5);
278 if (!added) ATH_MSG_WARNING( "Failed to add RoI Word 5: " << MSG::hex << roiWord5 << MSG::dec );
279
280 return StatusCode::SUCCESS;
281}
282
284unsigned int LVL1::EnergyCMX::ctpWord(unsigned int metSigPassed,
285 unsigned int etMissPassed,
286 unsigned int etSumPassed) const {
287
289 (etMissPassed<<L1DataDef::typeConfig(L1DataDef::TE).max) + etSumPassed );
290}
291
293StatusCode LVL1::EnergyCMX::saveCTPObjects(const SystemEnergy& resultsFull,
294 const SystemEnergy& resultsTrunc,
295 const EventContext& ctx) const {
296 ATH_MSG_DEBUG("saveCTPObjects");
297
298 // get bit words of thresholds passed
299 unsigned int etSumHitsFull = resultsFull.etSumHits();
300 unsigned int etMissHitsFull = resultsFull.etMissHits();
301 unsigned int metSigHitsFull = resultsFull.metSigHits();
302 unsigned int etSumHitsTrunc = resultsTrunc.etSumHits();
303 unsigned int etMissHitsTrunc = resultsTrunc.etMissHits();
304
305 // form CTP words
306 unsigned int word0 = ctpWord(metSigHitsFull, etMissHitsFull, etSumHitsFull);
307 unsigned int word1 = ctpWord(0, etMissHitsTrunc, etSumHitsTrunc);
308 // Comment out parity generation for now - should be in bit 32 of a 34 bit word
309 //Parity genParity;
310 //temp += (genParity.odd(temp)<<31);
311
312 // form CTP object
314 ATH_CHECK(energyCTP.record(std::make_unique<EnergyCTP>(word0, word1)));
315 ATH_MSG_DEBUG( "Stored energy CTP object with words "<< std::hex
316 << (energyCTP->cableWord0()) << ", " << (energyCTP->cableWord1())<< std::dec);
317
318 return StatusCode::SUCCESS;
319}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define max(a, b)
Definition cfImp.cxx:41
An algorithm that can be simultaneously executed in multiple threads.
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
CMXEtSums object stores Et sums from the Energy CMXs.
SG::WriteHandleKey< EnergyCTP > m_energyCTPLocation
Definition EnergyCMX.h:86
virtual StatusCode start() override
Definition EnergyCMX.cxx:63
EnergyCMX(const std::string &name, ISvcLocator *pSvcLocator)
Definition EnergyCMX.cxx:38
StatusCode saveRoIs(const SystemEnergy &resultsFull, const SystemEnergy &resultsTrunc, const EventContext &ctx) const
put EnergyRoIs into SG
SG::WriteHandleKey< EnergyTopoData > m_energyTopoLocation
Definition EnergyCMX.h:89
SG::ReadHandleKey< EnergyCMXDataCollection > m_energyCMXDataLocation
Definition EnergyCMX.h:81
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
Definition EnergyCMX.h:99
virtual StatusCode initialize() override
Definition EnergyCMX.cxx:46
unsigned int ctpWord(unsigned int metSigPassed, unsigned int etMissPassed, unsigned int etSumPassed) const
returns the Energy CTP word
StatusCode saveCTPObjects(const SystemEnergy &resultsFull, const SystemEnergy &resultsTrunc, const EventContext &ctx) const
form CTP objects and store them in SG.
ToolHandle< LVL1::IL1EtTools > m_EtTool
Definition EnergyCMX.h:77
SG::WriteHandleKey< CMXRoI > m_cmxRoILocation
Definition EnergyCMX.h:95
virtual StatusCode execute(const EventContext &ctx) const override
Definition EnergyCMX.cxx:77
SG::WriteHandleKey< CMXEtSumsCollection > m_cmxEtsumsLocation
Definition EnergyCMX.h:92
SystemEnergy class declaration Simulates behaviour of the Crate-CMM System CMM logic is done in Energ...
unsigned int etOverflow() const
return Et overflow bit
unsigned int exOverflow() const
Overflow bits.
unsigned int etMissHits() const
Trigger Results.
unsigned int roiWord1() const
return RoI word 1 (Ey value & overflow, EtSum hits)
unsigned int roiWord2() const
return RoI word 2 (Et value & overflow, EtMiss hits)
unsigned int eyTC() const
return crate Ey in 15-bit twos-complement format (hardware format)
unsigned int etSumHits() const
return EtSum hits
unsigned int metSigHits() const
return MEtSig hits
unsigned int eyOverflow() const
return Ey overflow bit
unsigned int exTC() const
15 bit twos-complement format
unsigned int roiWord0() const
RoI words.
int et() const
return global et, ex, ey sums
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static TriggerTypeConfig & typeConfig(TriggerType tt)
static void setNewJEP3Cabling()
static std::string & typeAsString(TriggerType tt)
Definition L1DataDef.h:53
virtual ValueWithEtaDependence< unsigned int > thrValuesCounts() const
access to the list of ThresholdValues in energy units
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22