ATLAS Offline Software
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"
20 #include "StoreGate/StoreGateSvc.h"
21 #include "GaudiKernel/ToolHandle.h"
22 
23 #include <iostream>
24 #include <algorithm>
25 
26 typedef std::pair<int, int> int_pair;
27 
28 bool 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)
35  , m_MBTS_channel(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;
95  m_MBTS = new TileCellCollection(ID_of_Col, SG::OWN_ELEMENTS);
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++;
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
193 const std::vector<TileCellCollection*>::const_iterator
194 TileCellCont::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 
221 unsigned int TileCellCont::find_rod(const unsigned int& rodid) const {
222  unsigned int rodidx = m_hash.identifier(rodid);
223  return rodidx;
224 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TileCellCont::find_rod
unsigned int find_rod(const unsigned int &id) const
Definition: TileCellCont.cxx:221
TileCell
Definition: TileCell.h:57
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
CaloCell::phi
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition: CaloCell.h:359
TileCellCollection
Definition: TileCellCollection.h:12
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
TileCablingService::getInstance
static const TileCablingService * getInstance()
get pointer to service instance
Definition: TileCablingService.cxx:24
int_pair
std::pair< int, int > int_pair
Definition: TileCellCont.cxx:26
TileCellCont::m_Rw2Cell
std::vector< int > m_Rw2Cell[4]
Definition: TileCellCont.h:87
index
Definition: index.py:1
TileRodIdHash::initialize
void initialize(int offset, int runnum)
initialize
Definition: TileRodIdHash.cxx:23
ReadBchFromCool.pmt
pmt
Definition: ReadBchFromCool.py:62
TileCellCont::m_Rw2Pmt
std::vector< int > m_Rw2Pmt[4]
Definition: TileCellCont.h:89
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TileHWID::frag
int frag(const HWIdentifier &id) const
extract frag field from HW identifier
Definition: TileHWID.h:181
TileCellCont::TileCellCont
TileCellCont()
constructor
Definition: TileCellCont.cxx:32
TileCalibUtils.h
HWIdentifier
Definition: HWIdentifier.h:13
sort_pred
bool sort_pred(const int_pair &left, const int_pair &right)
Definition: TileCellCont.cxx:28
CaloGain::TILELOWLOW
@ TILELOWLOW
Definition: CaloGain.h:12
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
MbtsDetDescrManager
Definition: MbtsDetDescrManager.h:16
TileID.h
TileDetDescrManager.h
MbtsDetDescrManager.h
CaloCell_ID.h
TileCalibUtils::MAX_DRAWER
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
Definition: TileCalibUtils.h:139
TileCellCont::find
const std::vector< TileCellCollection * >::const_iterator find(const unsigned int &id) const
Finds a collection.
Definition: TileCellCont.cxx:194
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TileHWID
Helper class for TileCal online (hardware) identifiers.
Definition: TileHWID.h:49
TileHWID.h
TileHid2RESrcID::getRodID
uint32_t getRodID(int frag_id) const
make a ROD SrcID for a fragment ID
Definition: TileHid2RESrcID.cxx:464
TileCablingService.h
TileCellCont::m_mbts_IDs
std::vector< unsigned int > m_mbts_IDs
Definition: TileCellCont.h:96
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
TileDetDescrManager
Definition: TileDetDescrManager.h:33
python.LArBadChannelDBAlg.xFFFFFFFF
xFFFFFFFF
Definition: LArBadChannelDBAlg.py:73
TileID
Helper class for TileCal offline identifiers.
Definition: TileID.h:68
CaloGain::TILEONELOW
@ TILEONELOW
Definition: CaloGain.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TileCell.h
TileCellCont::m_mbts_rods
std::vector< unsigned int > m_mbts_rods
Definition: TileCellCont.h:95
MbtsDetDescrManager::get_element
CaloDetDescrElement * get_element(const Identifier &elementId) const
Definition: MbtsDetDescrManager.cxx:22
TileCalibUtils::MAX_ROS
static const unsigned int MAX_ROS
Number of ROSs
Definition: TileCalibUtils.h:138
maskDeadModules.ros
ros
Definition: maskDeadModules.py:35
TileCablingService
Definition: TileCablingService.h:23
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TileCellCont::m_MBTS
TileCellCollection * m_MBTS
Definition: TileCellCont.h:97
TileCellCont::m_src
const TileHid2RESrcID * m_src
map Hash ID to ROD
Definition: TileCellCont.h:101
TileDetDescrManager::get_cell_element
CaloDetDescrElement * get_cell_element(unsigned int cell_hash) const
Definition: TileDetDescrManager.h:156
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
TileHid2RESrcID.h
TileHWID::channel_id
HWIdentifier channel_id(int ros, int drawer, int channel) const
channel HWIdentifer
Definition: TileHWID.cxx:199
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DeMoScan.index
string index
Definition: DeMoScan.py:364
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
TileCellCont.h
TileRodIdHash::max
int max() const
return maximum number of IDs
Definition: TileRodIdHash.cxx:129
TileCellCont::initialize
StatusCode initialize(void)
Definition: TileCellCont.cxx:39
Tile_Base_ID::cell_hash
IdentifierHash cell_hash(const Identifier &cell_id) const
fast conversion from ID to hash for cells
Definition: Tile_Base_ID.cxx:1030
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
TileRodIdHash::identifier
ID identifier(int i) const
reverse conversion
Definition: TileRodIdHash.cxx:112
TileCellCont::m_hash
TileRodIdHash m_hash
Definition: TileCellCont.h:85
TileCellCont::m_mapMBTS
std::map< unsigned int, unsigned int > m_mapMBTS
Definition: TileCellCont.h:98
test_AnalysisBaseEventLoopJob.aa
aa
Definition: test_AnalysisBaseEventLoopJob.py:37
StoreGateSvc.h
TileCellCont::finalize
StatusCode finalize(void)
Definition: TileCellCont.cxx:198
TileCellCont::m_MBTS_channel
int m_MBTS_channel
Definition: TileCellCont.h:99
CaloCell::eta
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition: CaloCell.h:366
fitman.k
k
Definition: fitman.py:528
TileCellCont::m_eventNumber
std::vector< unsigned int > m_eventNumber
eventNumber of a given Collection
Definition: TileCellCont.h:91
TileCellCollection.h
Identifier
Definition: IdentifierFieldParser.cxx:14