ATLAS Offline Software
EnergyCMX.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 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 
29 using namespace TrigConf;
30 
31 namespace LVL1 {
32 
33 
34 //--------------------------------
35 // Constructors and destructors
36 //--------------------------------
37 
38 EnergyCMX::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() );
55  return StatusCode::SUCCESS ;
56 }
57 
58 
59 //-------------------------------------------------
60 // Set cabling: seems to be required
61 //-------------------------------------------------
62 
64 {
66 
67  return StatusCode::SUCCESS ;
68 }
69 
70 
71 //----------------------------------------------
72 // execute() method called once per event
73 //----------------------------------------------
74 //
75 
76 
77 StatusCode 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::xeType() || thresh->type() == L1DataDef::teType()) && 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::xeType() && !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::teType() && !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 
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 
284 unsigned int LVL1::EnergyCMX::ctpWord(unsigned int metSigPassed,
285  unsigned int etMissPassed,
286  unsigned int etSumPassed) const {
287 
288  return ( (metSigPassed<<(L1DataDef::max_TE_Threshold_Number()+L1DataDef::max_XE_Threshold_Number())) +
289  (etMissPassed<<L1DataDef::max_TE_Threshold_Number()) + etSumPassed );
290 }
291 
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
313  SG::WriteHandle<EnergyCTP> energyCTP = SG::makeHandle(m_energyCTPLocation, ctx);
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 }
TrigConf::L1Threshold_Calo::thrValuesCounts
virtual ValueWithEtaDependence< unsigned int > thrValuesCounts() const
access to the list of ThresholdValues in energy units
Definition: L1ThresholdBase.cxx:317
LVL1::SystemEnergy::exTC
unsigned int exTC() const
15 bit twos-complement format
Definition: SystemEnergy.cxx:174
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LVL1::SystemEnergy::etMissHits
unsigned int etMissHits() const
Trigger Results.
Definition: SystemEnergy.cxx:186
xAOD::word1
word1
Definition: eFexEMRoI_v1.cxx:87
LVL1::SystemEnergy::metSigHits
unsigned int metSigHits() const
return MEtSig hits
Definition: SystemEnergy.cxx:198
LVL1::EnergyCMX::m_L1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
Definition: EnergyCMX.h:110
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:36
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LVL1::CMXEtSums::LOCAL_RESTRICTED
@ LOCAL_RESTRICTED
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LVL1::EnergyCMX::saveCTPObjects
StatusCode saveCTPObjects(const SystemEnergy &resultsFull, const SystemEnergy &resultsTrunc, const EventContext &ctx) const
form CTP objects and store them in SG.
Definition: EnergyCMX.cxx:293
LVL1::EnergyCMX::start
virtual StatusCode start() override
Definition: EnergyCMX.cxx:63
LVL1::SystemEnergy::roiWord0
unsigned int roiWord0() const
RoI words.
Definition: SystemEnergy.cxx:204
LVL1::EnergyCMX::m_EtTool
ToolHandle< LVL1::IL1EtTools > m_EtTool
Definition: EnergyCMX.h:88
LVL1::EnergyTopoData::Normal
@ Normal
Definition: EnergyTopoData.h:44
LVL1::SystemEnergy::eyTC
unsigned int eyTC() const
return crate Ey in 15-bit twos-complement format (hardware format)
Definition: SystemEnergy.cxx:180
bin
Definition: BinsDiffFromStripMedian.h:43
TrigConf::L1DataDef::setNewJEP3Cabling
static void setNewJEP3Cabling()
Definition: L1DataDef.cxx:166
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
L1Threshold.h
LVL1::EnergyCMX::m_cmxEtsumsLocation
SG::WriteHandleKey< CMXEtSumsCollection > m_cmxEtsumsLocation
Definition: EnergyCMX.h:103
LVL1::SystemEnergy::roiWord2
unsigned int roiWord2() const
return RoI word 2 (Et value & overflow, EtMiss hits)
Definition: SystemEnergy.cxx:238
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigConf::L1Threshold_Calo
Definition: L1ThresholdBase.h:188
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
LVL1::CMXEtSums::REMOTE_RESTRICTED
@ REMOTE_RESTRICTED
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:30
LVL1::SystemEnergy::exOverflow
unsigned int exOverflow() const
Overflow bits.
Definition: SystemEnergy.cxx:162
LVL1::SystemEnergy::etSumHits
unsigned int etSumHits() const
return EtSum hits
Definition: SystemEnergy.cxx:192
LVL1::EnergyCMX::m_energyCTPLocation
SG::WriteHandleKey< EnergyCTP > m_energyCTPLocation
Definition: EnergyCMX.h:97
LVL1::SystemEnergy::etOverflow
unsigned int etOverflow() const
return Et overflow bit
Definition: SystemEnergy.cxx:156
LVL1::EnergyCMX::ctpWord
unsigned int ctpWord(unsigned int metSigPassed, unsigned int etMissPassed, unsigned int etSumPassed) const
returns the Energy CTP word
Definition: EnergyCMX.cxx:284
LVL1::CMXEtSums::TOTAL_RESTRICTED
@ TOTAL_RESTRICTED
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:32
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
LVL1::SystemEnergy::et
int et() const
return global et, ex, ey sums
Definition: SystemEnergy.cxx:138
LVL1::CMXEtSums::TOTAL_STANDARD
@ TOTAL_STANDARD
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:32
LVL1::SystemEnergy::roiWord1
unsigned int roiWord1() const
return RoI word 1 (Ey value & overflow, EtSum hits)
Definition: SystemEnergy.cxx:221
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:794
TrigConf::name
Definition: HLTChainList.h:35
xAOD::CMXEtSums
CMXEtSums_v1 CMXEtSums
Define the latest version of the CMXEtSums class.
Definition: Event/xAOD/xAODTrigL1Calo/xAODTrigL1Calo/CMXEtSums.h:20
LVL1::CMXEtSums::LOCAL_STANDARD
@ LOCAL_STANDARD
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:31
LVL1::EnergyCMX::m_cmxRoILocation
SG::WriteHandleKey< CMXRoI > m_cmxRoILocation
Definition: EnergyCMX.h:106
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::roiWord3
setRoIWord1 roiWord3
Definition: EnergySumRoI_v2.cxx:87
LVL1::CMXEtSums
CMXEtSums object stores Et sums from the Energy CMXs.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:27
LVL1::EnergyTopoData::Restricted
@ Restricted
Definition: EnergyTopoData.h:44
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
LVL1::EnergyCMX::m_energyTopoLocation
SG::WriteHandleKey< EnergyTopoData > m_energyTopoLocation
Definition: EnergyCMX.h:100
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrigConf::ValueWithEtaDependence::addRangeValue
void addRangeValue(const T &value, int etaMin, int etaMax, unsigned int priority, bool symmetric=true)
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LVL1::SystemEnergy::eyOverflow
unsigned int eyOverflow() const
return Ey overflow bit
Definition: SystemEnergy.cxx:168
xAOD::roiWord5
setRoIWord1 setRoIWord3 roiWord5
Definition: EnergySumRoI_v2.cxx:91
LVL1::EnergyCMX::m_energyCMXDataLocation
SG::ReadHandleKey< EnergyCMXDataCollection > m_energyCMXDataLocation
Definition: EnergyCMX.h:92
EnergyCMX.h
LVL1::SystemEnergy
SystemEnergy class declaration Simulates behaviour of the Crate-CMM System CMM logic is done in Energ...
Definition: SystemEnergy.h:35
LVL1::EnergyCMX::initialize
virtual StatusCode initialize() override
Definition: EnergyCMX.cxx:46
LVL1::EnergyCMX::saveRoIs
StatusCode saveRoIs(const SystemEnergy &resultsFull, const SystemEnergy &resultsTrunc, const EventContext &ctx) const
put EnergyRoIs into SG
Definition: EnergyCMX.cxx:247
xAOD::roiWord1
roiWord1
Definition: EnergySumRoI_v1.cxx:49
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LVL1::EnergyCMX::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: EnergyCMX.cxx:77
LVL1::CMXEtSums::REMOTE_STANDARD
@ REMOTE_STANDARD
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMXEtSums.h:30