ATLAS Offline Software
Loading...
Searching...
No Matches
Egamma1_OnlineMapNbhood.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5/*
6 This algorithm outputs Calorimeter strip data in the region of
7 eFex RoIs.
8*/
9
12#include "../IO/eEmNbhoodTOB.h"
13
14#include "CaloEvent/CaloCell.h"
16
18
20
21#include <fstream>
22#include <vector>
23#include <algorithm>
24#include <optional>
25#include <ranges>
26
27namespace GlobalSim {
28
29 Egamma1_OnlineMapNbhood::Egamma1_OnlineMapNbhood(const std::string& name, ISvcLocator* pSvcLocator ) :
30 AthReentrantAlgorithm(name, pSvcLocator){
31 }
32
33 //This is not a good hashId. Use this as a dummy/halt point throughout the code.
34 constexpr IdentifierHash hashIdDummy = 999999;
35 //The maximum number of cells (i.e. the ceiling of the IdentifierHash's
36 constexpr int maxIdentifierHash = 187650;
37
38 //Before all events, setup the required variables and tools.
40 ATH_MSG_DEBUG ("Initializing " << name());
41
42 //Input keys
43 CHECK(m_eventInfoKey.initialize());
44 CHECK(m_gblLArCellContainerKey.initialize());
45 CHECK(m_roiAlgTool.retrieve());
46 //Output keys
47 CHECK(m_neighKey.initialize());
48 CHECK(m_eFEXetaKey.initialize());
49 CHECK(m_eFEXphiKey.initialize());
50 CHECK(m_FailedeFEXetaKey.initialize());
51 CHECK(m_FailedeFEXphiKey.initialize());
52
53 // retrieve ID helpers
54 ATH_CHECK(detStore()->retrieve(m_calocell_id, "CaloCell_ID"));
55
56 //Launch the calorimeter ID managers
57 const CaloIdManager* caloIdMgr = nullptr;
58 StatusCode sc = detStore()->retrieve(caloIdMgr);
59 if (sc.isFailure()) {
60 ATH_MSG_ERROR(" Unable to retrieve CaloIdManager from DetectoreStore");
61 return StatusCode::FAILURE;
62 }
63 m_larem_id = caloIdMgr->getEM_ID();
64
65 return StatusCode::SUCCESS;
66 }
67
68 // For each event, read in the event info, GlobalLArCell and eFeXRoI containers.
69 // Ask producers to create windows around each incoming RoI in the event.
70 StatusCode Egamma1_OnlineMapNbhood::execute(const EventContext& ctx) const {
71
72 ATH_MSG_DEBUG ("Executing");
73
74 //Get EventInfo
76 if(!eventInfo.isValid()) {
77 ATH_MSG_ERROR ("Error obtaining EventInfo object");
78 return StatusCode::FAILURE;
79 }
80
81 //Get GlobalLArCells
82 auto h_gblLArCells = SG::makeHandle(m_gblLArCellContainerKey, ctx);
83 CHECK(h_gblLArCells.isValid());
84 const auto & gblLArCells = *h_gblLArCells;
85 ATH_MSG_DEBUG(gblLArCells.size() <<"Cells read in");
86
87 //Get eFeXRoIs
88 std::vector<const xAOD::eFexEMRoI*> rois_in;
89 CHECK(m_roiAlgTool->RoIs(rois_in, ctx));
90 ATH_MSG_DEBUG(rois_in.size() << " RoI(s) read in");
91
92 //Remove the RoIs in the barrel/endcap crack region (hopefully temporary)
93 std::vector<const xAOD::eFexEMRoI*> rois;
94 for(auto roi:rois_in){
95 //Kill rois in the crack
96 if(std::abs(roi->eta()) >= 1.37 && std::abs(roi->eta()) <= 1.52) continue;
97 ATH_MSG_DEBUG ("Roi et " << roi->et());
98 rois.push_back(roi);
99 }
100
101 // find GlobalLArCells in the neighborhood of RoIs.
102 // A neighborhood is a collection of CellData objects which
103 // contain cell eta, phi and Et.
104
105 //Setup a container of TOBs with associated GlobalLArCell windows
106 auto neighborhoodTOBs = std::make_unique<IOBitwise::eEmNbhoodTOBContainer>();
107 //Flags for window finding success/failure
108 std::vector<bool> successes;
109
110 //Finw the windows for all of the valid incoming RoIs
111 CHECK(findNeighborhoods_OnlineMap(rois, gblLArCells, successes, *neighborhoodTOBs));
112
113 //Setup output for eFeXRoI eta/phi debug variables
115 CHECK(h_eFEXeta.record(std::make_unique<std::vector<float> >()));
117 CHECK(h_eFEXphi.record(std::make_unique<std::vector<float> >()));
118
120 CHECK(h_FailedeFEXeta.record(std::make_unique<std::vector<float> >()));
122 CHECK(h_FailedeFEXphi.record(std::make_unique<std::vector<float> >()));
123
124
125 //Fill RoI eta/phi variables for valid windows
126 for(int i=0; auto success:successes){
127 if(success){
128 h_eFEXeta->push_back(rois[i]->eta());
129 h_eFEXphi->push_back(rois[i]->phi());
130 } else {
131 h_FailedeFEXeta->push_back(rois[i]->eta());
132 h_FailedeFEXphi->push_back(rois[i]->phi());
133 }
134 i++;
135 }
136
137 //Setup the write out of the resultant TOBs
139
140 //Dump the window/RoI information to local files (for DEBUG)
142 if(m_dump || m_dumpTerse){
143 if (m_dump) {
144 CHECK(dumper.dump(name(), *eventInfo, *neighborhoodTOBs));
145 }
146
147 if (m_dumpTerse) {
148 CHECK(dumper.dumpTerse(name(), *eventInfo, *neighborhoodTOBs));
149 }
150 }
151
152 //Write out the TOBs
153 CHECK(h_neighborhoodTOBs.record(std::move(neighborhoodTOBs)));
154
155 return StatusCode::SUCCESS;
156 }
157
158 //This member function steps through all RoIs to produce windows for each RoI
159 //There are cases where the window finding can fail (no seed cell found). The
160 //success or failure of the algorithm is recorded here for debug purposes.
161 StatusCode
162 Egamma1_OnlineMapNbhood::findNeighborhoods_OnlineMap(const std::vector<const xAOD::eFexEMRoI*>& rois,
164 std::vector<bool>& successes,
165 IOBitwise::eEmNbhoodTOBContainer& neighborhoodTOBs) const{
166
167 for (const auto& roi : rois) {
168 ATH_MSG_DEBUG("roi et " << roi->et());
169 bool success = false;
170 ATH_CHECK(findNeighborhood_OnlineMap(roi, cells, success, neighborhoodTOBs));
171 successes.push_back(success);
172 }
173
174 return StatusCode::SUCCESS;
175 }
176
177 // This member function constructs an LArStripNeighborhood.
178 //
179 // A neighourhood is constructed from StripData objects constructed
180 // from GlobalLArCells (strips) in the vicinity of an EM RoI the following manner:
181 // The strip seed cell in the vicinity of the RoI is identified. An initial
182 // neighbourhood of strips centered on the seed is formed. The maximum energy
183 // cell within this window is then found. A final neighbourhood is then centered on
184 // this cell.
185 //
186 // In more detail:
187 // The RoI eta/phi coordinate (a supercell coordinate) is used to identify
188 // the seed cell in the strips (EM1) to form the window. This is done by forming
189 // a box in eta/phi space for each cell (using the cells known size and centre)
190 // and asking if the RoI's eta/phi position falls in it.
191 // As the granularity of the strips changes through the detector the search occurs in
192 // differing numbers of strips for each RoI tower range (the crack 1.37-152 is currently
193 // not dealth with).
194 // There are (8,6,4,1) strips per RoI supercell. First, the inner eta central strip
195 // is searched for first, e.g. +eta 4/8 or -eta 6/8. If a cell is found in the collection
196 // its ID is returned. If no cell is found then the search continues inwards, then finally
197 // outwards in eta. If no strips are found then the window finding halts. This halting is
198 // an issue with this method, and a fix is needed.
199 //
200 // A 17x3 eta/phi window is then formed around this seed cell. First the seed cell is found
201 // from a map of CellID->GlobalLArCells. Then the +-8 cells in eta are found using the
202 // m_larem_id->get_neighbours function. If a cell isn't present in the collection a dummy
203 // with the correct cellID is added to the list. If the window is at the edge of the detector
204 // a dummy with cellID 999999 is added, to allow for full sized windows at the edge. Once the
205 // central row has been filled, the process is repeated to fill the phi rows above and below.
206 //
207 // Once an initial window has been formed the maximum energy cell in this window is found.
208 // If the cell maxima for two rows are equal, then the central row is taken.
209 //
210 // This maximum energy cell is then used to repeat the first window finding step to find
211 // the final neighbourhood for this eFeXRoI, and an eEmNbhoodTOB is added to the list.
212 StatusCode
215 bool& success,
216 IOBitwise::eEmNbhoodTOBContainer& neighborhoodTOBs) const {
217
218 // Form the window, and set the vector sizes.
219 auto window = std::vector<std::vector<std::shared_ptr<const GlobalLArCell>>>(3);
220 window[0].resize(17);
221 window[1].resize(17);
222 window[2].resize(17);
223
224 //Setup variables
225 Identifier CellID;
226 float eta = roi->eta();
227 float phi = roi->phi();
228 bool found = false;
229 int strip = 0;
230
231 //Tower position to find strip granularity
232 int iEta = roi->iEta();
233 int iPhi = roi->iPhi();
234 ATH_MSG_DEBUG("Where is this RoI? eta: " << eta << " phi: " << phi << " iEta" << iEta << " iPhi " << iPhi);
235 //There are 1 strips per 0.025 supercell at the edge.
236 //Shouldn't need to shift these?
237 if(iEta == -25 || iEta == 24) {
238 //Just use the eta/phi as is, becasue there is only one strip here.
239 found = findSeedCell(eta, phi, cells, CellID);
240 }
241 //There are 4 strips per 0.025 in these towers
242 else if((iEta > -25 && iEta <= -21) || (iEta < 24 && iEta >= 20)){
243 strip = 4;
244 }
245 //There are 6 strips per 0.025 in these towers
246 else if((iEta > -21 && iEta <= -19) || (iEta < 20 && iEta >= 18)) {
247 strip = 6;
248 }
249 //There are 8 strips per 0.025 in these towers, apart from the crack region where
250 //here be dragons. The crack region is not currently dealt with.
251 else if((iEta > -19 && iEta <=-1) || (iEta < 18 && iEta >=0)) {
252 strip = 8;
253 } else {
254 //We shouldn't get here, but just in case...
255 ATH_MSG_WARNING("Where are we? eta " << eta << " phi " << phi);
256 }
257 //
258 if(strip != 0){
259 //Send the number of strips information along with the eta/phi supercell.
260 found = findHalfStrips(strip, eta, phi, cells, CellID);
261 }
262
263 //If we successfully found the seed cell, then continue.
264 if(found){
265 int ibec = abs(m_larem_id->barrel_ec(CellID)); // 1 barrel 2 EC OW 3 EC IW
266 int sampling = m_larem_id->sampling(CellID);
267 int eta = m_larem_id->eta(CellID);
268 int phi = m_larem_id->phi(CellID);
269 int region = m_larem_id->region(CellID);
270
271 ATH_MSG_DEBUG("Where is this Seed? B/E? " << ibec << " sampling " << sampling << " eta " << eta << " phi " << phi << " region " << region);
272
273 //Need the hash for the neighbours
274 IdentifierHash hashId=m_calocell_id->calo_cell_hash(CellID);
275 IdentifierHash hashIdMax=hashId;
276 //Find the initial 17x3 eta/phi window
277 ATH_CHECK(findWindow(hashId, cells, window));
278 //Find the maxima in the window (only once!)
279 ATH_CHECK(findMaxima(hashIdMax, window));
280 /*Find the new 17x3 eta/phi window around this maxima
281 Don't need to if the max is the seed already */
282 if(hashIdMax != hashId){
283 ATH_CHECK(findWindow(hashIdMax, cells, window));
284 }
285
286 //Rediscover the maximum energy cell
287 auto it = std::ranges::max_element(std::begin(window[1]),
288 std::end(window[1]),
289 [](const auto& l,const auto& r) {
290 return l->getEnergy() < r->getEnergy();
291 });
292
293 std::shared_ptr<const GlobalLArCell> max_cell{*it};
294
295 //Function to fill the StripData for the neighbourhood
296 auto toStripData = [](const auto& fromCells){
297 auto stripdata = std::vector<StripData>();
298 stripdata.reserve(fromCells.size());
299 std::ranges::transform(std::begin(fromCells),
300 std::end(fromCells),
301 back_inserter(stripdata),
302 [](const auto& c) {
303 return StripData(c->eta(),
304 c->phi(),
305 c->getEnergy());});
306 return stripdata;
307 };
308
309 //Check that we didn't lose the maximum energy cell
310 auto max_neigh_cell_it = std::ranges::find(window[1],
311 max_cell);
312 if (max_neigh_cell_it == std::end(window[1])){
313 ATH_MSG_ERROR("Lost the max cell");
314 return StatusCode::FAILURE;
315 }
316
317 //Find the position of the maximum energy cell in the neighbourhood.
318 auto max_neigh_cell_pos{std::distance(std::begin(window[1]),
319 max_neigh_cell_it)};
320
321 //Fill the StripData vectors
322 auto low = toStripData(window[0]);
323 auto center = toStripData(window[1]);
324 auto high = toStripData(window[2]);
325
326 //Fill the neighbourhood seed roi, and maximum cell positions.
327 Coords roi_c{roi->eta(), roi->phi()};
328 Coords cell_c{max_cell->eta(), max_cell->phi()};
329
330 //Form the neighbourhood
331 LArStripNeighborhood neighborhood = LArStripNeighborhood(low, center, high, roi_c, cell_c, max_neigh_cell_pos);
332
333 //Add the neighbourhood to the list.
334 neighborhoodTOBs.push_back(std::make_unique<IOBitwise::eEmNbhoodTOB>(*roi, neighborhood));
335 success = true;
336 } else {
337 //If we didn't find the window, then tell us about it.
338 ATH_MSG_DEBUG("Didn't find the RoI eta: " << roi->eta() << " phi: " << roi->phi());
339 }
340 return StatusCode::SUCCESS;
341 }
342
343 // Function to step through midpoints of the LAr strips, depending on how many strips
344 // there are in the current tower.
346 float eta,
347 float phi,
349 Identifier& CellID) const {
350 //Initialise variables
351 bool found = false;
352 //For each supercell there are different numbers of strips, this finds the midpoints.
353 float half_strip = 0.025/strip/2;
354 //Define the "inwards" direction
355 //int sign = 1;
356 //if(eta < 0) sign = -1;
357 int sign = std::copysign(1, eta);
358 int halt = strip-1;
359 //Starting at the inner centre strip, step through the allowed strips to find the
360 //seed cell.
361 for(int i=1;i<=halt;i+=2){
362 found = findSeedCell(eta-(i*half_strip*sign), phi, cells, CellID);
363 if(found) {
364 ATH_MSG_DEBUG("We found it! Going in by " << (i+1)/2 << " eta: " << eta-(i*half_strip) << " phi: " << phi);
365 return found;
366 }
367 }
368 //If we didn't find the strip going inwards, look outwards instead.
369 if(!found){
370 for(int i=1;i<=halt;i+=2){
371 found = findSeedCell(eta+(i*half_strip*sign), phi, cells, CellID);
372 if(found) {
373 ATH_MSG_DEBUG("We found it! Going out " << (i+1)/2 << " eta: " << eta+(i*half_strip) << " phi: " << phi);
374 return found;
375 }
376 }
377 }
378 //Return if we failed to find a strip.
379 return found;
380 }
381
382 // Function to locate the seed cell for a window from an input eta/phi position.
383 // Loops over the input strips in layer 1 and asks if the input eta/phi position is within
384 // their physical location (i.e. centre +- half width in eta/phi).
385 // Once found it returns the CellID of the located cell for future retrieval.
388 Identifier& CellID) const {
389
390
391 CellID = cells.getIDFromLoc(eta, phi);
392 //Failing to find a match will return a default CellID
393 if((CellID.get_identifier32()).get_compact() != 0xffffffff){
394 ATH_MSG_DEBUG("Found the seed from MAP: " << CellID << " eta "<< eta << " phi " << phi);
395 return true;
396 }
397 ATH_MSG_DEBUG("Didn't find the seed from MAP: eta "<< eta << " phi " << phi);
398 return false;
399 }
400
401 // Function to draw a window around a seed cell starting from the hashID of the seed cell
402 // and a container of all known GlobalLArCells. Returns the window.
405 std::vector<std::vector<std::shared_ptr<const GlobalLArCell>>>& window) const {
406
407 // If we pass in a Dummy ID we cannot start the process, fail gracefully for now.
408 if(hashId == hashIdDummy) return StatusCode::SUCCESS;
409
410 //Setup container for found neighbours.
411 std::vector<IdentifierHash> neighbourList;
412 //Setup next/previous hashIDs
413 IdentifierHash hashIdNext;
414 IdentifierHash hashIdPrev;
415 //Initialise them to the input for the first loop.
416 hashIdNext = hashIdPrev = hashId;
417 //Position of the cell in each 17 long eta row. Defined by position in loop.
418 int shift = 0;
419 //Check if we have hit the edge of the detector.
420 float etaMax = 0;
421
422 ATH_MSG_DEBUG("Seed Hash: " << hashId);
423 //Start loop to fill the central row of the 17x3 eta/phi window.
424 for(int etaOffset = 0; etaOffset <=8; etaOffset++){
425 ATH_MSG_DEBUG("Offset: " << etaOffset);
426 //Rediscover the centre cell for the first step.
427 if(etaOffset == 0){
428 //This retrieves the cell from a hash map in the GlobalLArCell container.
429 auto cell = cells.getCellFromHash(hashId);
430 //Sanity check.
431 if(cell != nullptr){
432 //Fill the central neighbourhood position.
433 window[1][8] = cell;
434 ATH_MSG_DEBUG("Found the middle cell " << cell->getID() << " at eta " << cell->eta() << " phi " << cell->phi());
435 //Start defining where we are in eta.
436 etaMax = cell->eta();
437 } else {
438 //We didn't find the cell in the hash map. Put a dummy in the window.
439 ATH_MSG_DEBUG("Putting in a dummy middle cell with hashId " << hashId);
440 window[1][8] = std::make_shared<GlobalLArCell>(hashId,"",0);
441 //Potential issue if you cannot find the cell... but this cell would be the last in eta?
442 }
443 } else {
444 //If we are not at the edge, and were not previously at the edge. Then...
445 if(std::abs(etaMax) < 2.475 && hashIdNext != hashIdDummy){
446 //Use the previous hashIDNext to look for the next cell in eta
447 m_larem_id->get_neighbours(hashIdNext,LArNeighbours::nextInEta,neighbourList);
448 ATH_MSG_DEBUG("Next in eta " << neighbourList[0] << " HashId " << hashId);
449 //Grab the next cell hashID in eta and store it for the next step.
450 hashIdNext = neighbourList[0];
451 //Try to retrieve the cell from the hash map
452 auto cellNext = cells.getCellFromHash(hashIdNext);
453 //Define how steps we are away from the central cell
454 shift = 8+etaOffset;
455 //If the hash map contained the next cell.
456 if(cellNext != nullptr){
457 ATH_MSG_DEBUG("Found a cell " << cellNext->getID() << " at eta " << cellNext->eta() << " phi " << cellNext->phi());
458 //update the eta position
459 etaMax = cellNext->eta();
460 //Put the found cell in the window
461 window[1][shift] = cellNext;
462 } else {
463 //We didn't find the cell in the hash map. Put a dummy in the window.
464 ATH_MSG_DEBUG("Putting in a next dummy with hashIdNext " << hashIdNext);
465 window[1][shift] = std::make_shared<GlobalLArCell>(hashIdNext,"",0);
466 //Potential issue if you cannot find the cell... but this cell would be the last in eta?
467 }
468 } else {
469 //We are off the edge of the detector. Put in a Dummy cell to keep the window going.
470 shift = 8+etaOffset;
471 ATH_MSG_DEBUG("No next in eta: Putting in an empty DUMMY");
472 window[1][shift] = std::make_shared<GlobalLArCell>(hashIdDummy,"",0);
473 }
474 //Now go inwards, as above, but with prevInEta, and no need to pad for the edge of the detector.
475 m_larem_id->get_neighbours(hashIdPrev,LArNeighbours::prevInEta,neighbourList);
476 ATH_MSG_DEBUG("Previous in eta " << neighbourList[0] << " hashId " << hashId);
477 hashIdPrev = neighbourList[0];
478 auto cellPrev = cells.getCellFromHash(hashIdPrev);
479 shift = 8-etaOffset;
480 if(cellPrev != nullptr){
481 ATH_MSG_DEBUG("Found a cell " << cellPrev->getID() << " at eta " << cellPrev->eta() << " phi " << cellPrev->phi());
482 window[1][shift] = cellPrev;
483 } else {
484 ATH_MSG_DEBUG("Putting in a previous dummy with hasIdPrev " << hashIdPrev);
485 window[1][shift] = std::make_shared<GlobalLArCell>(hashIdPrev,"",0);
486 }
487 }
488 }
489
490 //We now have the central row. Loop to fill the phi rows above and below in phi.
491 for(int phiOffset = 0; phiOffset <=1; phiOffset++){
492 ATH_MSG_DEBUG("Offset: " << phiOffset);
493 //First do nextInPhi
494 if(phiOffset == 0){
495 shift = 0;
496 //Loop over the middle row.
497 for(auto& windowCell:window[1]){
498 ATH_MSG_DEBUG("Cell ID " << shift << " is " << windowCell->getID());
499 //If this isn't a Dummy cell
500 if(windowCell->getID() != hashIdDummy){
501 //Find the cell hashID from its offline ID.
502 IdentifierHash hashIdCurrent = m_calocell_id->calo_cell_hash(static_cast<Identifier>(windowCell->getID()));
503 //There are cases where the CellID is the hashID. Update the hash to this.
504 if(windowCell->getID() <= maxIdentifierHash) hashIdCurrent = windowCell->getID();
505 //Proceed as in eta, finding next in Phi.
506 m_larem_id->get_neighbours(hashIdCurrent,LArNeighbours::nextInPhi,neighbourList);
507 ATH_MSG_DEBUG("Next in phi " << neighbourList[0] << " hashId " << hashIdCurrent);
508 //Find the hashID and use it to look up the cell in the hash map.
509 hashIdCurrent = neighbourList[0];
510 auto cellCurrent = cells.getCellFromHash(hashIdCurrent);
511 //If we find the cell in the hash map
512 if(cellCurrent != nullptr){
513 //Put the cell in the window.
514 ATH_MSG_DEBUG("Found a cell " << cellCurrent->getID() << " at eta " << cellCurrent->eta() << " phi " << cellCurrent->phi());
515 window[0][shift] = cellCurrent;
516 } else {
517 //Put a dummy cell. No need to get the ID right here.
518 ATH_MSG_DEBUG("No next in phi: Last HashIdCurrent " << hashIdCurrent);
519 window[0][shift] = std::make_shared<GlobalLArCell>(hashIdDummy,"",0);
520 }
521 shift++;
522 } else {
523 //We found a Dummy in the middle row, put a dummy in next phi too.
524 ATH_MSG_DEBUG("No next in phi: Putting in a DUMMY");
525 window[0][shift] = std::make_shared<GlobalLArCell>(hashIdDummy,"",0);
526 shift++;
527 }
528 }
529 } else {
530 //Repeat the above for the previous row in Phi
531 shift = 0;
532 for(auto& windowCell:window[1]){
533 ATH_MSG_DEBUG("Cell ID " << shift << " is " << windowCell->getID());
534 if(windowCell->getID() != hashIdDummy){
535 IdentifierHash hashIdCurrent = m_calocell_id->calo_cell_hash(static_cast<Identifier>(windowCell->getID()));
536 if(windowCell->getID() <= maxIdentifierHash) hashIdCurrent = windowCell->getID();
537 m_larem_id->get_neighbours(hashIdCurrent,LArNeighbours::prevInPhi,neighbourList);
538 ATH_MSG_DEBUG("Previous in phi " << neighbourList[0] << " hashId " << hashIdCurrent);
539 hashIdCurrent = neighbourList[0];
540 auto cellCurrent = cells.getCellFromHash(hashIdCurrent);
541 if(cellCurrent != nullptr){
542 ATH_MSG_DEBUG("Found a cell " << cellCurrent->getID() << " at eta " << cellCurrent->eta() << " phi " << cellCurrent->phi());
543 window[2][shift] = cellCurrent;
544 } else {
545 ATH_MSG_DEBUG("No prev in phi: Putting in a DUMMY");
546 window[2][shift] = std::make_shared<GlobalLArCell>(hashIdDummy,"",0);
547 }
548 shift++;
549 } else {
550 ATH_MSG_DEBUG("No prev in phi: Putting in a DUMMY");
551 window[2][shift] = std::make_shared<GlobalLArCell>(hashIdDummy,"",0);
552 shift++;
553 }
554 }
555 }
556 }
557 return StatusCode::SUCCESS;
558 }
559 // Function to find the maximum energy cell within a neighbourhood.
560 // Return its hashID to be used to seed another neighbourhood window.
562 std::vector<std::vector<std::shared_ptr<const GlobalLArCell>>>& window) const {
563
564 //Vector to hold each row's maximum
565 std::vector<std::shared_ptr<const GlobalLArCell>> maxima;
566 //Loop over the rows and find each maximum energy cell.
567 for(uint row = 0;row < window.size();row++){
568 auto max_cell = Egamma1_OnlineMapNbhood::findMax(window[row]);
569 maxima.push_back(max_cell);
570 ATH_MSG_DEBUG("Found a max cell " << max_cell->getID() << " et " << max_cell->getEnergy() << " eta " << max_cell->eta() << " phi " << max_cell->phi());
571 }
572 //If we have two equal maxima, then take the middle row to be consistent.
573 if((maxima[0]->getEnergy() == maxima[1]->getEnergy() && maxima[1]->getEnergy() >= maxima[2]->getEnergy())
574 || (maxima[1]->getEnergy() == maxima[2]->getEnergy() && maxima[1]->getEnergy() >= maxima[0]->getEnergy())){
575 ATH_MSG_DEBUG("Found the max cell " << maxima[1]->getID() << " et " << maxima[1]->getEnergy() << " eta " << maxima[1]->eta() << " phi " << maxima[1]->phi());
576 hashId = m_calocell_id->calo_cell_hash(static_cast<Identifier>(maxima[1]->getID()));
577 return StatusCode::SUCCESS;
578 } else {
579 //Otherwise just take the maximum cell.
580 auto maximum_cell = Egamma1_OnlineMapNbhood::findMax(maxima);
581 ATH_MSG_DEBUG("Found the max cell " << maximum_cell->getID() << " et " << maximum_cell->getEnergy() << " eta " << maximum_cell->eta() << " phi " << maximum_cell->phi());
582 hashId = m_calocell_id->calo_cell_hash(static_cast<Identifier>(maximum_cell->getID()));
583 return StatusCode::SUCCESS;
584 }
585 }
586
587 //Function to find the maximum energy cell in a vector of GlobalLArCells.
588 std::shared_ptr<const GlobalLArCell> Egamma1_OnlineMapNbhood::findMax(std::vector<std::shared_ptr<const GlobalLArCell>>& row) const {
589 auto it = std::max_element(std::begin(row),
590 std::end(row),
591 [](const auto& l,const auto& r) {
592 return l->getEnergy() < r->getEnergy();
593 });
594
595 std::shared_ptr<const GlobalLArCell> max_cell{*it};
596 return max_cell;
597 }
598}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
unsigned int uint
static Double_t sc
int sign(int a)
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
This class initializes the Calo (LAr and Tile) offline identifiers.
const LArEM_ID * getEM_ID(void) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ToolHandle< eFexRoIAlgTool > m_roiAlgTool
ToolHandle for the eFexRoI AlgTool.
SG::WriteHandleKey< std::vector< float > > m_eFEXphiKey
WriteHandle Key for the eFexRoI's phi (for valid windows, for DEBUG).
Egamma1_OnlineMapNbhood(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_dumpTerse
Parameter to toggle dumping of brief information window information.
SG::WriteHandleKey< IOBitwise::eEmNbhoodTOBContainer > m_neighKey
WriteHandle Key for the resulting TOBs.
StatusCode findWindow(IdentifierHash, const GlobalSim::GlobalLArCellContainer &, std::vector< std::vector< std::shared_ptr< const GlobalSim::GlobalLArCell > > > &) const
Function to produce a window around an input seed cell.
std::shared_ptr< const GlobalLArCell > findMax(std::vector< std::shared_ptr< const GlobalLArCell > > &) const
Function to find the maximum energy cell in a vector of cells.
virtual StatusCode execute(const EventContext &) const override
execute function running for every event
SG::WriteHandleKey< std::vector< float > > m_eFEXetaKey
WriteHandle Key for the eFexRoI's eta (for valid windows, for DEBUG).
StatusCode findMaxima(IdentifierHash &, std::vector< std::vector< std::shared_ptr< const GlobalSim::GlobalLArCell > > > &) const
Function to find the maximum energy cell in a window.
SG::WriteHandleKey< std::vector< float > > m_FailedeFEXetaKey
WriteHandle Key for the eFexRoI's eta (for invalid windows, for DEBUG).
virtual StatusCode initialize() override
initialize function running before the first event
StatusCode findNeighborhoods_OnlineMap(const std::vector< const xAOD::eFexEMRoI * > &, const GlobalSim::GlobalLArCellContainer &, std::vector< bool > &, IOBitwise::eEmNbhoodTOBContainer &) const
Function to produce mutliple windows from a vector of incoming eFeX RoIs.
StatusCode findNeighborhood_OnlineMap(const xAOD::eFexEMRoI *, const GlobalSim::GlobalLArCellContainer &, bool &, IOBitwise::eEmNbhoodTOBContainer &) const
Function to produce a window from an incoming eFeX RoI.
SG::WriteHandleKey< std::vector< float > > m_FailedeFEXphiKey
WriteHandle Key for the eFexRoI's phi (for invalid windows, for DEBUG).
Gaudi::Property< bool > m_dump
Parameter to toggle dumping of full information window information.
SG::ReadHandleKey< GlobalSim::GlobalLArCellContainer > m_gblLArCellContainerKey
ReadHandle Key to the GlobalLArCellContainer.
bool findSeedCell(float, float, const GlobalSim::GlobalLArCellContainer &, Identifier &) const
Function to find the seed cell for a window from the eFeX RoI position.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
ReadHandle Key for the EventInfo object.
bool findHalfStrips(int, float, float, const GlobalSim::GlobalLArCellContainer &, Identifier &) const
Function to search for seed cells according to local granularity.
Class to hold windows of LAr strip cells in a the neighbourhood of a eFexRoI.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
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.
float eta() const
setter for the above
int iPhi() const
Setter for the above.
float phi() const
Seed supercell index within central tower (0 -> 3).
int iEta() const
setter for the above
int r
Definition globals.cxx:22
DataVector< GlobalSim::IOBitwise::eEmNbhoodTOB > eEmNbhoodTOBContainer
AlgTool to read in LArStripNeighborhoods, and run the eRatio Algorithm.
constexpr int maxIdentifierHash
std::pair< double, double > Coords
constexpr IdentifierHash hashIdDummy
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
eFexEMRoI_v1 eFexEMRoI
Define the latest version of the eFexEMRoI class.
Definition eFexEMRoI.h:17