ATLAS Offline Software
Loading...
Searching...
No Matches
L1JEMJetTools.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
5// L1JEMJetTools.cxx,
7
8#include "L1JEMJetTools.h"
13
14// amazurov: For findJEMResults depricated method
16
17#include "TrigConfData/L1Menu.h"
18
19namespace LVL1 {
20
21//================ Constructor =================================================
22
23L1JEMJetTools::L1JEMJetTools(const std::string& t, const std::string& n, const IInterface* p)
24: base_class(t,n,p) {}
25
26//================ Initialisation =================================================
27
29{
30 ATH_CHECK(detStore()->retrieve(m_l1menu).ignore());
31 return StatusCode::SUCCESS;
32}
33
34//================ Finalisation =================================================
35
37{
38 return StatusCode::SUCCESS;
39}
40
41//================ Need to load JetInputs into map before can form clusters =======
42
43void L1JEMJetTools::mapJetInputs(const xAOD::JetElementContainer* jes, std::map<int, JetInput*>* elements, int slice) const {
44
45 // Clear map before filling
46 elements->clear();
47
48 // Step over JEs, form JIs, and put into map
50 JetInputKey testKey(0.0, 0.0);
51
53 JetInput* jetInput;
54 for( it = jes->begin(); it != jes->end(); ++it ){
55 double jetElementPhi=(*it)->phi();
56 double jetElementEta=(*it)->eta();
57 int jetElementET = 0;
58 if (slice < 0) { // Default to using peak slice
59 jetElementET = (*it)->et();
60 }
61 else { // Use user-specified slice
62 jetElementET = (*it)->sliceET(slice);
63 }
64 // Don't waste time & fill the JetInput map with empty elements
65 if (jetElementET == 0) continue;
66
67 if (!testKey.isFCAL(jetElementEta)) { // 1-to-1 JE->JI outside FCAL
68 int key = testKey.jeKey(jetElementPhi,jetElementEta);
69 std::map<int, JetInput*>::iterator test=elements->find( key );
70 if (test == elements->end()){
71 // no JI yet. Create it!
72 ATH_MSG_DEBUG( "Creating JetInput at ("
73 << jetElementPhi << " , " << jetElementEta << "). Key = " << key);
74 jetInput=new JetInput(jetElementPhi,jetElementEta, jetElementET, key);
75 elements->insert(std::map<int, JetInput*>::value_type(key,jetInput)); //and put it in the map.
76 }
77 else{
78 ATH_MSG_ERROR( "JetInput already exists (shouldn't happen!). Coords (" << jetElementEta << ", " << jetElementPhi << "), key = " << key );
79 }
80 }
81 else { // FCAL JEs are divided into 2 JIs
82 // Each gets half of the ET. If value is odd, remainder added to lower JI
83 int jetInputET = (jetElementET>>1);
84 int underflow = jetElementET&0x1;
85 // Modifier: if JetElement is saturated, both "halves" should saturate
86 if ((*it)->isSaturated()) {
87 jetInputET = jetElementET; // don't divide saturated ET
88 underflow = 0; // want both halves set to same value
89 }
90 // Phi coordinates of the two elements
91 double phiOffset = testKey.dPhi(jetElementPhi,jetElementEta)/2.;
92 std::vector<double> phiValues;
93 std::vector<int> etValues;
94 phiValues.push_back(jetElementPhi - phiOffset);
95 etValues.push_back(jetInputET+underflow);
96 phiValues.push_back(jetElementPhi + phiOffset);
97 etValues.push_back(jetInputET);
98 // Calculate keys, create JI, and add (halved) ET to each
99 for (size_t iphi = 0; iphi < phiValues.size(); ++iphi) {
100 int key = testKey.jeKey(phiValues[iphi],jetElementEta);
101 std::map<int, JetInput*>::iterator test=elements->find( key );
102 JetInput* jetInput=0;
103 if (test == elements->end()){
104 // no JI yet. Create it!
105 ATH_MSG_DEBUG( "Creating JetInput at ("
106 << phiValues[iphi] << " , " << jetElementEta << "). Key = " << key);
107 jetInput=new JetInput(phiValues[iphi],jetElementEta, etValues[iphi], key);
108 elements->insert(std::map<int, JetInput*>::value_type(key,jetInput)); //and put it in the map.
109 }
110 else{
111 ATH_MSG_ERROR( "FCAL JetInput already exists (shouldn't happen!). Coords (" << jetElementEta << ", " << jetElementPhi << "), key = " << key );
112 }
113 } // end loop over parts of the JE
114 } // end handling of FCAL JEs
115 }//endfor
116
117}
118
120
121void L1JEMJetTools::findRoIs(const std::map<int, JetInput*>* elements, DataVector<JEMJetAlgorithm>* rois) const {
122
123 // Start with an empty vector
124 rois->clear();
125
132
133 JetInputKey testKey(0.0, 0.0);
134 std::map<int, int> analysed;
135 std::map<int, JetInput*>::const_iterator input = elements->begin();
136 for ( ; input != elements->end(); ++input) {
137 double eta = (*input).second->eta();
138 double startPhi = (*input).second->phi();
139 for (int etaOffset = 0; etaOffset >= -1; etaOffset--) {
140 Coordinate tempCoord(startPhi, eta);
141 for (int phiOffset = 0; phiOffset >= -1; phiOffset--) {
142 int key = testKey.jeKey(tempCoord);
143 std::map<int, int>::iterator test = analysed.find(key);
144 if (test == analysed.end()) {
145 analysed.insert(std::map<int, int>::value_type(key,1));
146 double tempEta = tempCoord.eta();
147 double tempPhi = tempCoord.phi();
148 JEMJetAlgorithm* roi = new JEMJetAlgorithm(tempEta, tempPhi, elements, m_l1menu);
149 if (roi->isRoI()) rois->push_back(roi);
150 else delete roi;
151 }
152 tempCoord = testKey.downPhi(tempCoord); // decrement phi
153 } // phi offset loop
154 tempCoord = testKey.leftEta(tempCoord); // decrement eta
155 eta = tempCoord.eta();
156 if (eta == TrigT1CaloDefs::RegionERROREtaCentre) break; // gone outside detector
157 } // eta offset loop
158 } // loop over JetInput map
159
160}
161
163
165
167 std::map<int, JetInput*>* inputs = new std::map<int, JetInput*>;
168 mapJetInputs(jes, inputs, slice);
169
171 findRoIs(inputs, rois);
172
174 for (std::map<int, JetInput*>::iterator it = inputs->begin(); it != inputs->end(); ++it) {
175 delete (*it).second;
176 }
177 delete inputs;
178
179}
180
181
183
184void L1JEMJetTools::findRoIs(const std::map<int, JetInput*>* elements, xAOD::JEMTobRoIContainer* rois) const {
185
186 // Start with an empty DataVector
187 rois->clear();
188
195
196 JetInputKey testKey(0.0, 0.0);
197 std::map<int, int> analysed;
198 std::map<int, JetInput*>::const_iterator input = elements->begin();
199 for ( ; input != elements->end(); ++input) {
200 double eta = (*input).second->eta();
201 double startPhi = (*input).second->phi();
202 for (int etaOffset = 0; etaOffset >= -1; etaOffset--) {
203 Coordinate tempCoord(startPhi, eta);
204 for (int phiOffset = 0; phiOffset >= -1; phiOffset--) {
205 int key = testKey.jeKey(tempCoord);
206 std::map<int, int>::iterator test = analysed.find(key);
207 if (test == analysed.end()) {
208 analysed.insert(std::map<int, int>::value_type(key,1));
209 double tempEta = tempCoord.eta();
210 double tempPhi = tempCoord.phi();
211 JEMJetAlgorithm roi(tempEta, tempPhi, elements, m_l1menu);
212
213 if (roi.isRoI() != 0) rois->push_back(roi.jemTobRoI());
214
215 }
216 tempCoord = testKey.downPhi(tempCoord); // decrement phi
217 } // phi offset loop
218 tempCoord = testKey.leftEta(tempCoord); // decrement eta
219 eta = tempCoord.eta();
220 if (eta == TrigT1CaloDefs::RegionERROREtaCentre) break; // gone outside detector
221 } // eta offset loop
222 } // loop over JetInput map
223
224}
225
226
228
230
232 std::map<int, JetInput*>* inputs = new std::map<int, JetInput*>;
233 mapJetInputs(jes, inputs, slice);
234
236 findRoIs(inputs, rois);
237
239 for (std::map<int, JetInput*>::iterator it = inputs->begin(); it != inputs->end(); ++it) {
240 delete (*it).second;
241 }
242 delete inputs;
243
244}
245
246
248
249void L1JEMJetTools::findJEMResults(const std::map<int, JetInput*>* inputs, int crate, int module,
250 xAOD::JEMTobRoIContainer* rois, std::vector<unsigned int>& jetCMXData) const {
251
254 jetCMXData.clear();
255 jetCMXData.resize(4);
256
258 int nTobs = 0;
259
260 // Phi coordinates within module
261 float PhiMin = ( crate + ( module>7 ? 2 : 0 ) )*M_PI/2;
262 float PhiCell[8];
263 for (int ip = 0; ip < 8; ++ip) PhiCell[ip] = PhiMin + ip*M_PI/16 + M_PI/32;
264
265 // Eta coordinates within module
266 float EtaCell[4];
267 if ( module%8 == 0 ) {
268 EtaCell[0] = -4.0 ;
269 EtaCell[1] = -3.05 ;
270 EtaCell[2] = -2.8 ;
271 EtaCell[3] = -2.55 ;
272 }
273 else if ( module%8 == 7 ) {
274 EtaCell[0] = 2.55 ;
275 EtaCell[1] = 2.8 ;
276 EtaCell[2] = 3.05 ;
277 EtaCell[3] = 4.0;
278 }
279 else {
280 for (int ie = 0; ie < 4; ++ie) EtaCell[ie] = (module%8)*0.8 - 3.2 + ie*0.2 + 0.1;
281 }
282
285 for (int iFrame = 0; iFrame < 8; ++iFrame) {
286 for (int iPhi = 0; iPhi < 2; ++iPhi) {
287 int ip = 2*(iFrame&3) + + iPhi;
288 for (int iEta = 0; iEta < 2; ++iEta) {
289 int ie = 2*(iFrame>>2) + iEta;
290
293
295 JEMJetAlgorithm tob(EtaCell[ie], PhiCell[ip], inputs, m_l1menu);
296
301 if (tob.isRoI()) {
302 unsigned int etL = tob.ETLarge();
303 unsigned int etS = tob.ETSmall();
304 unsigned int lc = (iPhi << 1) + iEta;
305
307 RoI->makePrivateStore();
308 RoI->initialize(crate, module, iFrame, lc, etL, etS);
309 rois->push_back(RoI);
310
311 jetCMXData[0] |= (1 << iFrame);
312
313 switch (nTobs) {
314 case 0:
315 jetCMXData[0] += ( etL << 13 );
316 jetCMXData[0] += ( (etS&7) << 8 );
317 jetCMXData[1] += ( (etS >> 3) & 0x3f );
318 jetCMXData[0] += ( lc << 11 );
319 break;
320 case 1:
321 jetCMXData[1] += ( etL << 13 );
322 jetCMXData[1] += ( (etS&0x1f) << 6 );
323 jetCMXData[2] += ( (etS >> 5) & 0xf );
324 jetCMXData[1] += ( lc << 11 );
325 break;
326 case 2:
327 jetCMXData[2] += ( etL << 13 );
328 jetCMXData[2] += ( (etS&0x7f) << 4 );
329 jetCMXData[3] += ( (etS >> 7) & 3 );
330 jetCMXData[2] += ( lc << 11 );
331 break;
332 case 3:
333 jetCMXData[3] += ( etL << 13 );
334 jetCMXData[3] += ( etS << 2 );
335 jetCMXData[3] += ( lc << 11 );
336 break;
337 }
338 nTobs++;
339
340 } // Found TOB
341
342 } // eta within frame
343 } // phi within frame
344 } // frame (0-7) within module
345
346 // Finally set parity bits for data words
347 for (unsigned int word = 0; word < 4; ++word) {
348 unsigned int parity = 1;
349 for (unsigned int bit = 0; bit < 24; ++bit) if ( ( (jetCMXData[word]>>bit) & 1) > 0 ) parity++;
350 parity &= 1;
351 jetCMXData[word] |= (parity<<23);
352 }
353
354
355}
356
357void L1JEMJetTools::findJEMResults(const std::map<int, JetInput*>* inputs, int crate, int module,
358 DataVector<JEMTobRoI>* rois, std::vector<unsigned int>& jetCMXData) const {
359
362 jetCMXData.clear();
363 jetCMXData.resize(4);
364
366 int nTobs = 0;
367
368 // Phi coordinates within module
369 float PhiMin = ( crate + ( module>7 ? 2 : 0 ) )*M_PI/2;
370 float PhiCell[8];
371 for (int ip = 0; ip < 8; ++ip) PhiCell[ip] = PhiMin + ip*M_PI/16 + M_PI/32;
372
373 // Eta coordinates within module
374 float EtaCell[4];
375 if ( module%8 == 0 ) {
376 EtaCell[0] = -4.0 ;
377 EtaCell[1] = -3.05 ;
378 EtaCell[2] = -2.8 ;
379 EtaCell[3] = -2.55 ;
380 }
381 else if ( module%8 == 7 ) {
382 EtaCell[0] = 2.55 ;
383 EtaCell[1] = 2.8 ;
384 EtaCell[2] = 3.05 ;
385 EtaCell[3] = 4.0;
386 }
387 else {
388 for (int ie = 0; ie < 4; ++ie) EtaCell[ie] = (module%8)*0.8 - 3.2 + ie*0.2 + 0.1;
389 }
390
393 for (int iFrame = 0; iFrame < 8; ++iFrame) {
394 for (int iPhi = 0; iPhi < 2; ++iPhi) {
395 int ip = 2*(iFrame&3) + + iPhi;
396 for (int iEta = 0; iEta < 2; ++iEta) {
397 int ie = 2*(iFrame>>2) + iEta;
398
401
403 JEMJetAlgorithm tob(EtaCell[ie], PhiCell[ip], inputs, m_l1menu);
404
409 if (tob.isRoI()) {
410 unsigned int etL = tob.ETLarge();
411 unsigned int etS = tob.ETSmall();
412 unsigned int lc = (iPhi << 1) + iEta;
413
414 JEMTobRoI* RoI = new JEMTobRoI(crate, module, iFrame, lc, etL, etS);
415 rois->push_back(RoI);
416
417 jetCMXData[0] |= (1 << iFrame);
418
419 switch (nTobs) {
420 case 0:
421 jetCMXData[0] += ( etL << 13 );
422 jetCMXData[0] += ( (etS&7) << 8 );
423 jetCMXData[1] += ( (etS >> 3) & 0x3f );
424 jetCMXData[0] += ( lc << 11 );
425 break;
426 case 1:
427 jetCMXData[1] += ( etL << 13 );
428 jetCMXData[1] += ( (etS&0x1f) << 6 );
429 jetCMXData[2] += ( (etS >> 5) & 0xf );
430 jetCMXData[1] += ( lc << 11 );
431 break;
432 case 2:
433 jetCMXData[2] += ( etL << 13 );
434 jetCMXData[2] += ( (etS&0x7f) << 4 );
435 jetCMXData[3] += ( (etS >> 7) & 3 );
436 jetCMXData[2] += ( lc << 11 );
437 break;
438 case 3:
439 jetCMXData[3] += ( etL << 13 );
440 jetCMXData[3] += ( etS << 2 );
441 jetCMXData[3] += ( lc << 11 );
442 break;
443 }
444 nTobs++;
445
446 } // Found TOB
447
448 } // eta within frame
449 } // phi within frame
450 } // frame (0-7) within module
451
452 // Finally set parity bits for data words
453 for (unsigned int word = 0; word < 4; ++word) {
454 unsigned int parity = 1;
455 for (unsigned int bit = 0; bit < 24; ++bit) if ( ( (jetCMXData[word]>>bit) & 1) > 0 ) parity++;
456 parity &= 1;
457 jetCMXData[word] |= (parity<<23);
458 }
459}
460
461
462
464
465JEMJetAlgorithm L1JEMJetTools::findRoI(double RoIeta, double RoIphi, const std::map<int, JetInput*>* elements) const {
466 return JEMJetAlgorithm(RoIeta, RoIphi, elements, m_l1menu);
467}
468
470
471JEMJetAlgorithm L1JEMJetTools::formSums(double RoIeta, double RoIphi, const std::map<int, JetInput*>* elements) const {
472 // Performs all processing for this location
473 return JEMJetAlgorithm(RoIeta, RoIphi, elements, m_l1menu);
474}
475
477
478JEMJetAlgorithm L1JEMJetTools::formSums(uint32_t roiWord, const std::map<int, JetInput*>* elements) const {
479 // Find RoI coordinate
480 CoordinateRange coord = m_conv.coordinate(roiWord);
481 float RoIphi = coord.phi();
482 float RoIeta = coord.eta();
483 // For this purpose we need to resolve the 2 possible FJ coordinates at end C
484 if (RoIeta > 3.1 && m_conv.column(roiWord) != 3) RoIeta = 3.1;
485
486 // Performs all processing for this location
487 return JEMJetAlgorithm(RoIeta, RoIphi, elements, m_l1menu);
488}
489
490//============================================================================================
491
492} // end of namespace
#define M_PI
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
double coord
Type of coordination system.
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > 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.
CoordinateRange class declaration.
double phi() const
return phi
double eta() const
return eta
This is an internal class, used in the jet trigger.
int ETSmall()
Returns Small cluster ET.
bool isRoI()
Does this window pass the local ET maximum condition.
int ETLarge()
Returns Large cluster ET.
xAOD::JEMTobRoI * jemTobRoI()
Create JEMTobRoI and return pointers to it.
Coordinate downPhi(const double phi, const double eta)
returns coord of next JE in -ve phi dir.
Coordinate leftEta(const double phi, const double eta)
returns key of JE in -ve eta dir.
double dPhi(const double phi, const double eta) const
return height of JE
virtual unsigned int jeKey(const xAOD::TriggerTower &tower)
returns key of passed tower
bool isFCAL(double eta) const
returns TRUE if this coordinate is in the FCAL
The JetInputKey object provides the key for each JetElement depending on its eta,phi coords (JetEleme...
Definition JetInputKey.h:42
A minimal version of JetElement, containing only eta, phi, ET and a JetInputKey, ie the bare informat...
Definition JetInput.h:34
L1JEMJetTools(const std::string &, const std::string &, const IInterface *)
virtual void findJEMResults(const std::map< int, JetInput * > *inputs, int crate, int module, xAOD::JEMTobRoIContainer *rois, std::vector< unsigned int > &jetCMXData) const override
Form JEM results for specified crate/module using user-supplied map of input towers Adds to DataVecto...
JEPRoIDecoder m_conv
Utility for decoding RoI words.
virtual void findRoIs(const std::map< int, JetInput * > *elements, xAOD::JEMTobRoIContainer *rois) const override
Return vector of TOB RoI objects derived from user-specified inputs.
virtual StatusCode finalize() override
standard Athena-Algorithm method
virtual JEMJetAlgorithm findRoI(double RoIeta, double RoIphi, const std::map< int, JetInput * > *elements) const override
Return RoI object for specified location.
const TrigConf::L1Menu * m_l1menu
virtual JEMJetAlgorithm formSums(double RoIeta, double RoIphi, const std::map< int, JetInput * > *elements) const override
Form jet cluster sums for a given RoI location.
virtual StatusCode initialize() override
standard Athena-Algorithm method
virtual void mapJetInputs(const xAOD::JetElementContainer *jes, std::map< int, JetInput * > *elements, int slice=-1) const override
Convert user-supplied JetElements to map of JetInputs.
static const double RegionERROREtaCentre
void makePrivateStore()
Create a new (empty) private store for this object.
virtual void initialize(const int crate, const int jem, const int frame, const int location, const int energyLarge, const int energySmall)
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
JetElementContainer_v2 JetElementContainer
Define the latest version of the JetElement container.
JEMTobRoI_v1 JEMTobRoI
Define the latest version of the JEMTobRoI class.
JEMTobRoIContainer_v1 JEMTobRoIContainer
Define the latest version of the JEMTobRoI class.