ATLAS Offline Software
Loading...
Searching...
No Matches
JetCMX.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// JetCMX.cxx - description
7// -------------------
8// begin : Mon Jul 28 2014
9// email : Alan.Watson@CERN.CH
10// ***************************************************************************/
11//
12//
13//================================================
14// JetCMX class Implementation
15// ================================================
16//
17//
18//
19
20// Utilities
21
22// This algorithm includes
23#include "JetCMX.h"
27
29#include "TrigConfL1Data/Menu.h"
30
31
32
33namespace LVL1{
34
35using namespace TrigConf;
36
37//--------------------------------
38// Constructors and destructors
39//--------------------------------
40
41JetCMX::JetCMX(const std::string& name, ISvcLocator* pSvcLocator)
42 : AthReentrantAlgorithm(name, pSvcLocator) {}
43
44//---------------------------------
45// initialise()
46//---------------------------------
47
49{
50 ATH_CHECK( m_JetCMXDataLocation.initialize() );
51 ATH_CHECK( m_CMXJetHitsLocation.initialize() );
52 ATH_CHECK( m_CMXJetTobLocation.initialize() );
53 ATH_CHECK( m_TopoOutputLocation.initialize() );
54 ATH_CHECK( m_CTPOutputLocation.initialize() );
55 ATH_CHECK( m_L1MenuKey.initialize() );
56 return StatusCode::SUCCESS ;
57}
58
59//----------------------------------------------
60// execute() method called once per event
61//----------------------------------------------
62
63StatusCode JetCMX::execute(const EventContext& ctx) const
64{
65
66 /*
67 The idea is that this thing gets the inputs, formats them as required, then
68 uses a port of the online code. Then formats outputs and sends them to the
69 required destinations.
70
71 If that doesn't work, we'll put the processing in here as well.
72 */
73
74 //make a message logging stream
75
76 ATH_MSG_DEBUG ( "starting JetCMX" );
77
80 ATH_CHECK(CMXHits.record(std::make_unique<CMXJetHitsCollection>()));
82 ATH_CHECK(CMXTobs.record(std::make_unique<CMXJetTobCollection>()));
84 ATH_CHECK(topoData.record(std::make_unique<JetCMXTopoDataCollection>()));
85
86
88 std::vector< std::vector<int> > crateHits;
89 std::vector<int> Hits;
90
91 bool jetOverflow = false;
92
93 Hits.resize(25);
94
95 crateHits.resize(2);
96 for (int crate = 0; crate < 2; ++crate) {
97 crateHits[crate].resize(25);
98 }
99
100
101 // Create objects to store TOBs for L1Topo
102 for (int crate = 0; crate < 2; ++crate) {
103 topoData->push_back(std::make_unique<JetCMXTopoData>(crate));
104 }
105
108 if (bpDataVec.isValid()) {
109 // Analyse module results
110 for (const LVL1::JetCMXData* bpData : *bpDataVec) {
111 int crate = bpData->crate();
112 std::vector<unsigned int> tobWords = bpData->TopoTOBs();
113
114 // Store data for L1Topo
115 bool overflow = bpData->overflow();
116 if (overflow) {
117 (*topoData)[crate]->setOverflow(true);
118 jetOverflow = true;
119 }
120
121 for (std::vector<unsigned int>::const_iterator word = tobWords.begin();
122 word != tobWords.end(); ++word) {
123
124 // Push back to Topo link
125 (*topoData)[crate]->addTOB( (*word) );
126
127 // Decode TOB word
128 JetTopoTOB tob( crate, (*word) );
129 int etaindex = tob.etaIndex();
130 int ieta = 2*(etaindex-15) + (etaindex > 15 ? 0 : -1);
131 if (etaindex < 2 || etaindex > 28) {
132 if (etaindex == 0) ieta = -40;
133 else if (etaindex == 1) ieta = -30;
134 else if (etaindex == 29) ieta = 29;
135 else if (etaindex >= 30) ieta = 39;
136 }
137 int iphi = tob.iphi();
138 if (iphi < 0) iphi += 64;
139 int etLarge = tob.etLarge();
140
141 // Now check against trigger thresholds
142 auto l1Menu = SG::makeHandle( m_L1MenuKey, ctx );
143 float jepScale = l1Menu->thrExtraInfo().JET().jetScale();
144
145 std::vector<std::shared_ptr<TrigConf::L1Threshold>> allThresholds = l1Menu->thresholds();
146 // Right type?
147 for ( const auto& thresh : allThresholds ) {
148 if ( thresh->type() != L1DataDef::typeAsString(L1DataDef::JET) ) continue;
149
150 // Does TOB satisfy this threshold?
151 int etCut = thresh->thrValue(ieta)*jepScale;
152 if (etLarge > etCut) {
153 int num = thresh->mapping();
154 if (num < 25) {
155 if ( num < 10 && crateHits[crate][num] < 7 ) crateHits[crate][num]++;
156 else if ( num >= 10 && crateHits[crate][num] < 3 ) crateHits[crate][num]++;
157 if ( num < 10 && Hits[num] < 7 ) Hits[num]++;
158 else if ( num >= 10 && Hits[num] < 3 ) Hits[num]++;
159 }
160 else ATH_MSG_WARNING("Invalid threshold number " << num );
161 } // passes cuts
162 } // Loop over thresholds
163
164 } // Loop over TOBs
165
166 } // Loop over module results
167
168 // Form CTP data objects
169 unsigned int cableWord0 = 0;
170 unsigned int cableWord1 = 0;
171
172 if (!jetOverflow) {
173 for (int i = 0; i < 10; ++i) cableWord0 |= ( Hits[i]<<(3*i) );
174 for (int i = 10; i < 25; ++i) cableWord1 |= ( Hits[i]<<(2*(i-10)) );
175 }
176 else {
177 cableWord0 = 0x3fffffff;
178 cableWord1 = 0x3fffffff;
179 }
180
182 ATH_CHECK(jetCTP.record(std::make_unique<JetCTP>(cableWord0, cableWord1)));
183
184 // Form and store JetCMXHits
185 std::vector<int> error0; // Dummies - there will be no actual errors simulated
186 std::vector<int> error1;
187
188 // Now form hits words from module results and insert into objects
189 std::vector<unsigned int> cratehits0;
190 std::vector<unsigned int> cratehits1;
191 const int peak = 0;
192 const int system_crate = 1;
193
194 // Crate sums (local and remote)
195 for (int crate = 0; crate < 2; ++crate) {
196
197 cratehits0.assign(1,0);
198 cratehits1.assign(1,0);
199 for (int i = 0; i < 5; ++i) {
200 cratehits0[0] |= ( crateHits[crate][i]<<(3*i) );
201 cratehits1[0] |= ( crateHits[crate][i+5]<<(3*i) );
202 }
203 CMXHits->push_back(std::make_unique<CMXJetHits>(crate, LVL1::CMXJetHits::LOCAL_MAIN,
204 cratehits0, cratehits1, error0, error1, peak));
205 if (crate != system_crate) {
206 CMXHits->push_back(std::make_unique<CMXJetHits>(system_crate, LVL1::CMXJetHits::REMOTE_MAIN,
207 cratehits0, cratehits1, error0, error1, peak));
208 }
209
210 cratehits0.assign(1,0);
211 cratehits1.assign(1,0);
212 for (int i = 0; i < 8; ++i) cratehits0[0] |= ( crateHits[crate][i+10]<<(2*i) );
213 for (int i = 0; i < 7; ++i) cratehits1[0] |= ( crateHits[crate][i+18]<<(2*i) );
214 CMXHits->push_back(std::make_unique<CMXJetHits>(crate, LVL1::CMXJetHits::LOCAL_FORWARD,
215 cratehits0, cratehits1, error0, error1, peak));
216 if (crate != system_crate) {
217 CMXHits->push_back(std::make_unique<CMXJetHits>(system_crate, LVL1::CMXJetHits::REMOTE_FORWARD,
218 cratehits0, cratehits1, error0, error1, peak));
219 }
220 } // loop over crates
221
222 // global sums
223 cratehits0.assign(1,0);
224 cratehits1.assign(1,0);
225 for (int i = 0; i < 5; ++i) {
226 cratehits0[0] |= ( Hits[i]<<(3*i) );
227 cratehits1[0] |= ( Hits[i+5]<<(3*i) );
228 }
229 CMXHits->push_back(std::make_unique<CMXJetHits>(system_crate, LVL1::CMXJetHits::TOTAL_MAIN,
230 cratehits0, cratehits1, error0, error1, peak));
231
232 cratehits0.assign(1,0);
233 cratehits1.assign(1,0);
234 for (int i = 0; i < 8; ++i) cratehits0[0] |= ( Hits[i+10]<<(2*i) );
235 for (int i = 0; i < 7; ++i) cratehits1[0] |= ( Hits[i+18]<<(2*i) );
236 CMXHits->push_back(std::make_unique<CMXJetHits>(system_crate, LVL1::CMXJetHits::TOTAL_FORWARD,
237 cratehits0, cratehits1, error0, error1, peak));
238
239 } // Input collection exists in StoreGate
240 else {
241 ATH_MSG_WARNING("No JetCTP found. Creating empty object" );
243 ATH_CHECK(jetCTP.record(std::make_unique<JetCTP>(0, 0)));
244 }
245
246 return StatusCode::SUCCESS ;
247}
248
249
250} // end of namespace bracket
251
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
The JetCMXData object contains the data transferred from the CPM to one of the Jet CMX in the crate.
Definition JetCMXData.h:25
SG::WriteHandleKey< JetCMXTopoDataCollection > m_TopoOutputLocation
Definition JetCMX.h:89
SG::WriteHandleKey< CMXJetTobCollection > m_CMXJetTobLocation
Definition JetCMX.h:86
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
Definition JetCMX.h:75
SG::WriteHandleKey< JetCTP > m_CTPOutputLocation
Definition JetCMX.h:92
virtual StatusCode execute(const EventContext &ctx) const override
Definition JetCMX.cxx:63
SG::ReadHandleKey< JetCMXDataCollection > m_JetCMXDataLocation
Definition JetCMX.h:78
SG::WriteHandleKey< CMXJetHitsCollection > m_CMXJetHitsLocation
Definition JetCMX.h:83
JetCMX(const std::string &name, ISvcLocator *pSvcLocator)
Definition JetCMX.cxx:41
virtual StatusCode initialize() override
Definition JetCMX.cxx:48
Jet TOB data for L1Topo.
Definition JetTopoTOB.h:19
int iphi() const
Extract integer phi coordinate from TOB data.
unsigned int etLarge() const
Large cluster ET value.
Definition JetTopoTOB.h:124
int etaIndex() const
Extract eta index from the TOB data (0-31)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static std::string & typeAsString(TriggerType tt)
Definition L1DataDef.h:53
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())