ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellCont.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include "CaloDetDescr/CaloDetDescrElement.h"
13#include "TileEvent/TileCell.h"
15
18
19#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/ToolHandle.h"
22
23#include <iostream>
24#include <algorithm>
25
26typedef std::pair<int, int> int_pair;
27
28bool sort_pred(const int_pair& left, const int_pair& right) {
29 return left.second < right.second;
30}
31
33 : m_event(0)
34 , m_MBTS(0)
36 , m_src(0) {
37}
38
40
41#ifndef NDEBUG
42 std::cout << "TileCellCont\t\t DEBUG \t constructor" << std::endl;
43#endif
44
45 ISvcLocator* svcLoc = Gaudi::svcLocator();
46
47 SmartIF<StoreGateSvc> detStore{svcLoc->service("DetectorStore")};
48 if (!detStore) {
49 std::cout << "Could not locate DetectorStore" << std::endl;
50 return StatusCode::FAILURE;
51 }
52
53 // Get the TileID helper from the detector store
54 const TileID* tileID = nullptr;
55 if (detStore->retrieve(tileID, "TileID").isFailure()) {
56 std::cout << "Could not get TileID helper !" << std::endl;
57 return StatusCode::FAILURE;
58 }
59 // Get the TileHWID helper from the detector store
60 const TileHWID* tileHWID = nullptr;
61 if (detStore->retrieve(tileHWID, "TileHWID").isFailure()) {
62 std::cout << "Could not get TileHWID helper !" << std::endl;
63 return StatusCode::FAILURE;
64 }
65
66 // Get pointer to TileDetDescrManager
67 const TileDetDescrManager* tileMgr = nullptr;
68 if (detStore->retrieve(tileMgr).isFailure()) {
69 std::cout << "Unable to retrieve TileDetDescrManager from DetectorStore" << std::endl;
70 return StatusCode::FAILURE;
71 }
72
73 // Get pointer to MbtsDetDescrManager
74 const MbtsDetDescrManager* mbtsMgr = nullptr;
75 if (detStore->retrieve(mbtsMgr).isFailure()) {
76 std::cout << "Warning: unable to retrieve MbtsDetDescrManager from DetectorStore" << std::endl;
77 mbtsMgr = 0;
78 }
79
80 if ( !m_src ){ // if nothing set, use 2017
81 std::cout << "TileCellCont::initialize ERROR : TileHid2RESrc has to be initialized before this" << std::endl;
82 return StatusCode::FAILURE;
83 }
84
85 // Get pointer to TileCablingService
87 int maxChannels = cabling->getMaxChannels();
88
89 //m_hash.initialize(0);
90 m_mbts_rods.clear();
91 m_mbts_IDs.clear();
92 int mbts_count = 0;
93 int ID_of_Col = 0;
94 std::vector<int> rodids;
96 for (unsigned int ros = 1; ros < TileCalibUtils::MAX_ROS; ++ros) {
97 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
98 int frag = tileHWID->frag(ros, drawer);
99 int rodid = m_src->getRodID(frag);
100 rodids.push_back(rodid);
101 m_mapMBTS[frag] = 0xFFFF;
102 // One event number per collection
103 m_eventNumber.push_back(0xFFFFFFFF);
104
105 // Tries to find the TileRawChannel -> TileCell correpondence
106 int index, pmt, cell_hash;
107 std::vector<int> Rw2Pmt;
108 Rw2Pmt.resize(maxChannels, -1);
109 std::vector<int> Rw2Cell;
110 Rw2Cell.resize(maxChannels, -1);
111 std::vector<int_pair> tmp;
112
113 for (int channel = 0; channel < maxChannels; ++channel) {
114 HWIdentifier channelID = tileHWID->channel_id(ros, drawer, channel);
115 Identifier cell_id = cabling->h2s_cell_id_index(channelID, index, pmt);
116 if (index == -2) { // MBTS cell, only one per drawer
117 m_mbts_rods.push_back(m_src->getRodID(frag));
118 m_mbts_IDs.push_back(((ros - 1) * TileCalibUtils::MAX_DRAWER + drawer));
119 CaloDetDescrElement * caloDDE = (mbtsMgr) ? mbtsMgr->get_element(cell_id) : NULL;
120 TileCell* myMBTSCell = new TileCell(caloDDE, cell_id, 0.0, 0.0, 0, 0, CaloGain::TILEONELOW);
121 m_MBTS->push_back(myMBTSCell);
122 m_mapMBTS[frag] = mbts_count;
123 mbts_count++;
124 m_MBTS_channel = channel;
125 } else if (index >= 0) { // normal cell
126 Rw2Pmt[channel] = pmt;
127 if (channel > 0 || ros != 2) { // ignoring D0 (first channel) in negative barrel
128 cell_hash = tileID->cell_hash(cell_id);
129 tmp.push_back(int_pair(channel, cell_hash));
130 }
131 }
132 } // End of for over TileRawChannel
133
134
135 // create new cell collection which will own all elements
137 this->push_back(newColl);
138
139 // sort index according to cell hash and put it in Rw2Cell vector
140 // create TileCells in appropriate order and put them in newColl
141 if (tmp.size() > 0) {
142 std::sort(tmp.begin(), tmp.end(), sort_pred); // sort according to cell hash index
143 index = -1;
144 cell_hash = -1;
145 for (unsigned int i = 0; i < tmp.size(); ++i) {
146 if (cell_hash != tmp[i].second) {
147 cell_hash = tmp[i].second;
148 ++index;
149 CaloDetDescrElement * caloDDE = tileMgr->get_cell_element((IdentifierHash) cell_hash);
150 TileCell * pCell = new TileCell(caloDDE, 0.0, 0.0, 0, 0, CaloGain::TILELOWLOW);
151 newColl->push_back(pCell);
152 }
153 Rw2Cell[tmp[i].first] = index;
154 }
155 }
156
157 if (drawer == 0 || ros == 3 || ros == 4) {
158#ifndef NDEBUG
159 int idxraw = 0;
160 for (std::vector<int>::iterator i = Rw2Cell.begin(); i != Rw2Cell.end(); ++i) {
161 if ((*i) != -1) std::cout << "Channel : " << idxraw++ << " connected to cell " << (*i) << std::endl;
162 }
163#endif
164 // One needs to keep track of Rw2Cell
165 for (std::vector<int>::iterator i = Rw2Cell.begin(); i != Rw2Cell.end(); ++i)
166 m_Rw2Cell[ros - 1].push_back(*i);
167 for (std::vector<int>::iterator i = Rw2Pmt.begin(); i != Rw2Pmt.end(); ++i)
168 m_Rw2Pmt[ros - 1].push_back(*i);
169 } // End of if first drawer of Barrel or Ext
170
171 } // end of drawer for
172 } // end of ros for
173#ifndef NDEBUG
174 std::cout << "Number of RODs is : " << m_mbts_rods.size() << std::endl;
175 for (unsigned int k = 0; k < m_mbts_rods.size(); k++)
176 std::cout << " MBTS RODs : " << m_mbts_rods[k] << std::endl;
177#endif
178 m_hash.initialize(0,rodids);
179
180#ifndef NDEBUG
181 for (int i = 0; i < m_hash.max(); ++i) {
182 TileCellCollection *aa = this->at(i);
183 TileCell* bb = aa->at(0);
184 std::cout << "TileCellCont\t\t DEBUG \t" << i << " " << std::hex << m_hash.identifier(i) << std::dec << " " << aa->identify() << " " << bb->eta() << " " << bb->phi() << std::endl;
185 // A collection per ROD/ROB/HashId
186 } // end of for id
187#endif
188
189 return StatusCode::SUCCESS;
190}
191
192// This WILL NOT trigger BSCNV. This assumes BSCNV was done before
193const std::vector<TileCellCollection*>::const_iterator
194TileCellCont::find(const unsigned int& rodid) const {
195 return this->begin() + rodid;
196}
197
199
200 // Delete m_RwCells
201 for (int i = 0; i < 4; i++)
202 m_Rw2Cell[i].clear();
203 for (int i = 0; i < 4; i++)
204 m_Rw2Pmt[i].clear();
205
206 // Delete Collections and cells
207 for (unsigned int i = 0; i < this->size(); i++) {
208 // Delete collections. Own cells -> also destroyed
209 delete ((TileCellCollection*) ((*this)[i]));
210 }
211 // Destroy also MBTS collection
212 delete m_MBTS;
213 m_mapMBTS.clear();
214 m_mbts_rods.clear();
215 m_mbts_IDs.clear();
216 this->clear();
217 return StatusCode::SUCCESS;
218
219}
220
221unsigned int TileCellCont::find_rod(const unsigned int& rodid) const {
222 unsigned int rodidx = m_hash.identifier(rodid);
223 return rodidx;
224}
bool sort_pred(const int_pair &left, const int_pair &right)
std::pair< int, int > int_pair
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition CaloCell.h:375
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition CaloCell.h:382
This class groups all DetDescr information related to a CaloCell.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
This is a "hash" representation of an Identifier.
CaloDetDescrElement * get_element(const Identifier &elementId) const
static const TileCablingService * getInstance()
get pointer to service instance
static const unsigned int MAX_ROS
Number of ROSs.
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
StatusCode initialize(void)
std::vector< unsigned int > m_mbts_IDs
const TileHid2RESrcID * m_src
map Hash ID to ROD
std::vector< int > m_Rw2Cell[4]
unsigned int find_rod(const unsigned int &id) const
unsigned int m_event
this event number
std::vector< unsigned int > m_mbts_rods
TileRodIdHash m_hash
const std::vector< TileCellCollection * >::const_iterator find(const unsigned int &id) const
Finds a collection.
TileCellCollection * m_MBTS
std::vector< int > m_Rw2Pmt[4]
StatusCode finalize(void)
TileCellCont()
constructor
std::vector< unsigned int > m_eventNumber
eventNumber of a given Collection
std::map< unsigned int, unsigned int > m_mapMBTS
CaloDetDescrElement * get_cell_element(unsigned int cell_hash) const
Helper class for TileCal online (hardware) identifiers.
Definition TileHWID.h:49
int frag(const HWIdentifier &id) const
extract frag field from HW identifier
Definition TileHWID.h:181
HWIdentifier channel_id(int ros, int drawer, int channel) const
channel HWIdentifer
Definition TileHWID.cxx:199
Helper class for TileCal offline identifiers.
Definition TileID.h:67
IdentifierHash cell_hash(const Identifier &cell_id) const
fast conversion from ID to hash for cells
@ TILELOWLOW
Definition CaloGain.h:12
@ TILEONELOW
Definition CaloGain.h:16
@ OWN_ELEMENTS
this data object owns its elements
Definition index.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.