ATLAS Offline Software
L1CaloMonitoringCaloTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ********************************************************************
6 //
7 // NAME: L1CaloMonitoringCaloTool.cxx
8 // PACKAGE: TrigT1CaloCalibTools
9 //
10 // AUTHOR: Peter Faulkner
11 //
12 // ********************************************************************
13 
14 #include <cmath>
15 
16 #include "GaudiKernel/IInterface.h"
17 #include "GaudiKernel/MsgStream.h"
18 #include "GaudiKernel/StatusCode.h"
19 
20 #include "CaloEvent/CaloCell.h"
22 #include "CaloDetDescr/CaloDetDescrElement.h"
24 
25 #include "TileEvent/TileCell.h"
26 
27 #include "Identifier/Identifier.h"
29 
31 
33 
34 namespace LVL1 {
35 
39 
40 
41 /*---------------------------------------------------------*/
43  asg::AsgTool( name ),
44  m_lvl1Helper(nullptr),
45  m_sinTh(s_nsinThBins, 0.),
46  m_events(0),
47  m_lastRun(0),
48  m_lastEvent(0),
49  m_sideOffset(0),
50  m_layerOffset(0),
51  m_binOffset(s_nregions, 0),
52  m_indexOffset(s_nregions, 0),
53  m_etaShift(s_nregions, 0)
54 /*---------------------------------------------------*/
55 {
56  declareProperty("CaloCellContainer", m_caloCellContainerName = "AllCalo");
57  declareProperty("MappingVectorSize", m_maxCells = 188080);
58 }
59 
60 /*---------------------------------------------------------*/
62 /*---------------------------------------------------------*/
63 {
64  ATH_MSG_INFO("Initializing " << name());
65 
66  ATH_CHECK( m_cellMatch.retrieve() );
67 
68  StatusCode sc;
69 
70  // Get LVL1 idhelper from detector store
71  const CaloLVL1_ID* lvl1_id = 0;
72  sc = detStore()->retrieve(lvl1_id, "CaloLVL1_ID");
73  if (sc.isFailure() || !lvl1_id) {
74  ATH_MSG_ERROR("Could not get CaloLVL1_ID helper !");
75  return sc;
76  }
77  else {
78  //msg(MSG::DEBUG) << " Found the CaloLVL1_ID helper. " << endmsg;
79  m_lvl1Helper = (CaloLVL1_ID*) lvl1_id;
80  }
81 
82  // Set up cell to tt mapping arrays
83  const unsigned int maxCaloCells = 188080;
84  if (m_maxCells > maxCaloCells) m_maxCells = maxCaloCells;
85  if (m_maxCells > 0) {
86  m_cellIds.reserve(m_maxCells);
87  m_cellIds.assign(m_maxCells, 0);
88  m_ttIdx.reserve(m_maxCells);
89  m_ttIdx.assign(m_maxCells, 0);
90  }
91  m_energySums.reserve(s_maxTowers);
92  m_quality.reserve(s_maxTowers);
93  m_denom.reserve(s_maxTowers);
94 
95  // Set up arrays for indexing and sinTh
96  int binsEta[s_nregions] = { 25, 3, 1, 4 };
97  int binsPhi[s_nregions] = { 64, 32, 32, 16 };
98  double grans[s_nregions] = { 0.1, 0.2, 0.1, 0.425 };
99  double etaOffset[s_nregions] = { 0., 2.5, 3.1, 3.2 };
100  int bin = 0;
101  for (int r = 0; r < s_nregions; ++r) {
102  if (r == 0) {
103  m_binOffset[r] = 0;
104  m_indexOffset[r] = 0;
105  } else {
106  m_binOffset[r] = binsEta[r-1] + m_binOffset[r-1];
107  m_indexOffset[r] = binsEta[r-1]*binsPhi[r-1] + m_indexOffset[r-1];
108  }
109  m_etaShift[r] = 0;
110  int shift = binsPhi[r] - 1;
111  while (shift) {
112  m_etaShift[r]++;
113  shift>>=1;
114  }
115  for (int i = 0; i < binsEta[r]; ++i) {
116  double eta = etaOffset[r] + (i+0.5)*grans[r];
117  m_sinTh[bin++] = 1./(1000.*std::cosh(eta)); // include MeV->GeV conversion
118  }
119  }
120  m_sideOffset = binsEta[s_nregions-1]*binsPhi[s_nregions-1] + m_indexOffset[s_nregions-1];
122 
124 
125  return StatusCode::SUCCESS;
126 
127 }
128 
129 /*---------------------------------------------------------*/
131 /*---------------------------------------------------------*/
132 {
133  return StatusCode::SUCCESS;
134 }
135 
136 /*---------------------------------------------------------*/
138 /*---------------------------------------------------------*/
139 {
140  const bool debug = msgLvl(MSG::DEBUG);
141  if (debug) {
142  ATH_MSG_DEBUG("in loadCaloCells()");
143  }
144 
145  StatusCode sc;
146 
147  // Don't run more than once per event
148 
149  const EventContext& ctx = Gaudi::Hive::currentContext();
150  int eventNumber = ctx.eventID().event_number();
151  int runNumber = ctx.eventID().run_number();
153  return StatusCode::SUCCESS;
154  }
157 
158  // Retreive Calo Cell collection from SG
159 
160  const CaloCellContainer* caloCellContainer = 0;
161  sc = evtStore()->retrieve(caloCellContainer, m_caloCellContainerName);
162  if(!sc.isSuccess() || !caloCellContainer) {
163  ATH_MSG_WARNING("No CaloCellContainer found at AllCalo");
164  return StatusCode::SUCCESS;
165  }
166  ++m_events;
167 
168  // Get Et and CaloQuality corresponding to TTs
169 
170  CaloCellContainer::const_iterator CaloCellIterator = caloCellContainer->begin();
171  CaloCellContainer::const_iterator CaloCellIteratorEnd = caloCellContainer->end();
172  m_energySums.assign(s_maxTowers, 0.0);
173  m_quality.assign(s_maxTowers, 0.0);
174  m_denom.assign(s_maxTowers, 0.0);
175  unsigned int cellIdsIndex = 0;
176 
178 
179  for (; CaloCellIterator != CaloCellIteratorEnd; ++CaloCellIterator) {
180 
181  const CaloCell* caloCell(*CaloCellIterator);
182  const Identifier cellId(caloCell->ID());
183  const Identifier invalidId(0);
184  Identifier ttId1(0);
185  Identifier ttId2(0);
186 
187  // Use cell ordering to avoid unnecessary calls to mapping tools
188 
189  int index1 = s_maxTowers;
190  int index2 = s_maxTowers;
191  const unsigned int cellId32 = cellId.get_identifier32().get_compact();
192  if (m_events == 1) {
193  m_cellMatch->matchCell2Tower(**cabling, caloCell, ttId1, ttId2);
194  if (ttId1 != invalidId) index1 = towerIndex(ttId1);
195  if (ttId2 != invalidId) index2 = towerIndex(ttId2);
196  if (cellIdsIndex < m_maxCells-1) {
197  m_cellIds[cellIdsIndex] = cellId32;
198  m_ttIdx[cellIdsIndex++] = index1;
199  if (ttId2 != invalidId) {
200  m_cellIds[cellIdsIndex] = cellId32;
201  m_ttIdx[cellIdsIndex++] = index2;
202  }
203  }
204  } else {
205  if ((cellIdsIndex < m_maxCells-1) && (m_cellIds[cellIdsIndex] == cellId32)) {
206  index1 = m_ttIdx[cellIdsIndex++];
207  if (m_cellIds[cellIdsIndex] == cellId32) index2 = m_ttIdx[cellIdsIndex++];
208  } else {
209  m_cellMatch->matchCell2Tower(**cabling, caloCell, ttId1, ttId2);
210  if (ttId1 != invalidId) index1 = towerIndex(ttId1);
211  if (ttId2 != invalidId) index2 = towerIndex(ttId2);
212  }
213  }
214 
215  // Get Et/Energy and CaloQuality
216 
217  if (index1 < s_maxTowers) {
218  const float energy = caloCell->energy();
219  const CaloDetDescrElement* caloDDE = caloCell->caloDDE();
220  if (index2 < s_maxTowers) { // Tile D cells
221  const float energy2 = energy*0.5;
222  m_energySums[index1] += energy2;
223  m_energySums[index2] += energy2;
224  const TileCell* tileCell = dynamic_cast<const TileCell*>(caloCell);
225  if (tileCell && (tileCell->provenance() & 0x8080)) {
226  const float qual = energy2 * std::max(tileCell->qual1(), tileCell->qual2());
227  m_quality[index1] += qual;
228  m_quality[index2] += qual;
229  m_denom[index1] += energy2;
230  m_denom[index2] += energy2;
231  }
232  } else {
233  if (caloDDE->is_lar_fcal()) {
234  m_energySums[index1] += energy*caloDDE->sinTh();
235  } else m_energySums[index1] += energy;
236  if (caloDDE->is_tile()) {
237  const TileCell* tileCell = dynamic_cast<const TileCell*>(caloCell);
238  if (tileCell && (tileCell->provenance() & 0x8080)) {
239  m_quality[index1] += energy * std::max(tileCell->qual1(), tileCell->qual2());
240  m_denom[index1] += energy;
241  }
242  } else {
243  if (caloCell->provenance() & 0x2000) {
244  m_quality[index1] += (energy * caloCell->quality());
245  m_denom[index1] += energy;
246  }
247  }
248  }
249  }
250  }
251 
252  // Compute final quantities
253 
254  for (int index = 0; index < s_maxTowers; ++index) {
255  if (region(index) == 3) { // FCAL
256  m_energySums[index] *= 1e-3;
257  } else {
258  const int bin = etaBin(index);
260  }
261  if ( m_denom[index] != 0.) {
263  } else {
264  m_quality[index] = -1e6; // error value
265  }
266  }
267 
268  return StatusCode::SUCCESS;
269 }
270 
271 // Return Et
272 
273 float L1CaloMonitoringCaloTool::et(const Identifier& ttId) const
274 {
275  float e = 0.;
276  const int index = towerIndex(ttId);
278  return e;
279 }
280 
281 // Return Calo Quality
282 
284 {
285  float q = -1e6;
286  const int index = towerIndex(ttId);
287  if (index < s_maxTowers) q = m_quality[index];
288  return q;
289 }
290 
291 // Return index to TT-Calo energy sum vector
292 
294 {
295  const int side = m_lvl1Helper->pos_neg_z(ttId);
296  const int layer = m_lvl1Helper->sampling(ttId);
297  const int region = m_lvl1Helper->region(ttId);
298  const int ieta = m_lvl1Helper->eta(ttId);
299  const int iphi = m_lvl1Helper->phi(ttId);
300  int index = 0;
301  index = m_indexOffset[region] + (ieta<<(m_etaShift[region])) + iphi;
302  if (side < 0) index += m_sideOffset;
303  if (layer > 0) index += m_layerOffset;
304  return index;
305 }
306 
307 // Return the region corresponding to index
308 
310 {
311  int rg = 0;
312  int ix = index;
313  if (ix >= m_layerOffset) ix -= m_layerOffset;
314  if (ix >= m_sideOffset) ix -= m_sideOffset;
315  for (int r = s_nregions-1; r >= 0; --r) {
316  if (ix >= m_indexOffset[r]) {
317  rg = r;
318  break;
319  }
320  }
321  return rg;
322 }
323 
324 // Return the eta bin corresponding to index
325 
327 {
328  int bin = 0;
329  int ix = index;
330  if (ix >= m_layerOffset) ix -= m_layerOffset;
331  if (ix >= m_sideOffset) ix -= m_sideOffset;
332  for (int r = s_nregions-1; r >= 0; --r) {
333  if (ix >= m_indexOffset[r]) {
334  const int ieta = (ix - m_indexOffset[r])>>(m_etaShift[r]);
335  bin = m_binOffset[r] + ieta;
336  break;
337  }
338  }
339  return bin;
340 }
341 
342 } // end namespace
TileCell
Definition: TileCell.h:57
beamspotman.r
def r
Definition: beamspotman.py:676
LVL1::L1CaloMonitoringCaloTool::s_nregions
static const int s_nregions
Definition: L1CaloMonitoringCaloTool.h:92
LVL1::L1CaloMonitoringCaloTool::s_nsinThBins
static const int s_nsinThBins
Definition: L1CaloMonitoringCaloTool.h:93
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LVL1::L1CaloMonitoringCaloTool::m_cellMatch
ToolHandle< LVL1::IL1CaloMatchCell2Tower > m_cellMatch
Definition: L1CaloMonitoringCaloTool.h:69
max
#define max(a, b)
Definition: cfImp.cxx:41
LVL1::L1CaloMonitoringCaloTool::m_events
int m_events
Definition: L1CaloMonitoringCaloTool.h:82
LVL1::L1CaloMonitoringCaloTool::m_indexOffset
std::vector< int > m_indexOffset
Definition: L1CaloMonitoringCaloTool.h:88
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
index
Definition: index.py:1
LVL1::L1CaloMonitoringCaloTool::m_denom
std::vector< float > m_denom
Definition: L1CaloMonitoringCaloTool.h:76
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
LVL1::L1CaloMonitoringCaloTool::m_lvl1Helper
const CaloLVL1_ID * m_lvl1Helper
Definition: L1CaloMonitoringCaloTool.h:70
LVL1::L1CaloMonitoringCaloTool::m_sinTh
std::vector< float > m_sinTh
Definition: L1CaloMonitoringCaloTool.h:77
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
asg
Definition: DataHandleTestTool.h:28
LVL1::L1CaloMonitoringCaloTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: L1CaloMonitoringCaloTool.cxx:61
bin
Definition: BinsDiffFromStripMedian.h:43
IL1CaloCells2TriggerTowers.h
CaloCell.h
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
CaloLVL1_ID::region
int region(const Identifier id) const
return region according to :
Definition: CaloLVL1_ID.h:647
LVL1::L1CaloMonitoringCaloTool::m_cellIds
std::vector< unsigned int > m_cellIds
Definition: L1CaloMonitoringCaloTool.h:78
L1CaloMonitoringCaloTool.h
CaloCell::provenance
uint16_t provenance() const
get provenance (data member)
Definition: CaloCell.h:338
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
TRT::Hit::side
@ side
Definition: HitInfo.h:83
LVL1::L1CaloMonitoringCaloTool::finalize
virtual StatusCode finalize()
Definition: L1CaloMonitoringCaloTool.cxx:130
CaloLVL1_ID::phi
int phi(const Identifier id) const
return phi according to :
Definition: CaloLVL1_ID.h:659
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TileCell::qual2
uint8_t qual2(void) const
get quality of second PMT (data member)
Definition: TileCell.h:206
LVL1::L1CaloMonitoringCaloTool::m_etaShift
std::vector< int > m_etaShift
Definition: L1CaloMonitoringCaloTool.h:89
LVL1::L1CaloMonitoringCaloTool::m_maxCells
unsigned int m_maxCells
Definition: L1CaloMonitoringCaloTool.h:80
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::index1
@ index1
Definition: BoundarySurfaceFace.h:48
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
lumiFormat.i
int i
Definition: lumiFormat.py:92
LVL1::L1CaloMonitoringCaloTool::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: L1CaloMonitoringCaloTool.h:66
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LVL1::L1CaloMonitoringCaloTool::m_binOffset
std::vector< int > m_binOffset
Definition: L1CaloMonitoringCaloTool.h:87
TileCell.h
LVL1::L1CaloMonitoringCaloTool::m_layerOffset
int m_layerOffset
Definition: L1CaloMonitoringCaloTool.h:86
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1::L1CaloMonitoringCaloTool::m_ttIdx
std::vector< int > m_ttIdx
Definition: L1CaloMonitoringCaloTool.h:79
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
LVL1::L1CaloMonitoringCaloTool::et
float et(const Identifier &ttid) const
Definition: L1CaloMonitoringCaloTool.cxx:273
LVL1::L1CaloMonitoringCaloTool::s_maxTowers
static const int s_maxTowers
Definition: L1CaloMonitoringCaloTool.h:91
CaloDetDescrElement::is_lar_fcal
bool is_lar_fcal() const
cell belongs to FCAL
Definition: CaloDetDescrElement.cxx:138
CaloCell::quality
uint16_t quality() const
get quality (data member)
Definition: CaloCell.h:332
LVL1::L1CaloMonitoringCaloTool::m_lastEvent
int m_lastEvent
Definition: L1CaloMonitoringCaloTool.h:84
TrigConf::name
Definition: HLTChainList.h:35
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
CaloLVL1_ID
Helper class for offline TT identifiers.
Definition: CaloLVL1_ID.h:66
Trk::index2
@ index2
Definition: BoundarySurfaceFace.h:49
LVL1::L1CaloMonitoringCaloTool::m_lastRun
int m_lastRun
Definition: L1CaloMonitoringCaloTool.h:83
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
CaloLVL1_ID::eta
int eta(const Identifier id) const
return eta according to :
Definition: CaloLVL1_ID.h:653
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition: CaloCell.h:279
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloLVL1_ID::pos_neg_z
int pos_neg_z(const Identifier id) const
return pos_neg_z according to :
Definition: CaloLVL1_ID.h:635
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
DeMoScan.index
string index
Definition: DeMoScan.py:362
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloLVL1_ID.h
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
LVL1::L1CaloMonitoringCaloTool::m_sideOffset
int m_sideOffset
Definition: L1CaloMonitoringCaloTool.h:85
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LVL1::L1CaloMonitoringCaloTool::m_caloCellContainerName
std::string m_caloCellContainerName
Definition: L1CaloMonitoringCaloTool.h:72
LVL1::L1CaloMonitoringCaloTool::loadCaloCells
StatusCode loadCaloCells()
Declare the interface that the class provides.
Definition: L1CaloMonitoringCaloTool.cxx:137
LVL1::L1CaloMonitoringCaloTool::region
int region(const int index) const
Definition: L1CaloMonitoringCaloTool.cxx:309
DEBUG
#define DEBUG
Definition: page_access.h:11
LVL1::L1CaloMonitoringCaloTool::m_quality
std::vector< float > m_quality
Definition: L1CaloMonitoringCaloTool.h:75
LVL1::L1CaloMonitoringCaloTool::towerIndex
int towerIndex(const Identifier &ttId) const
Definition: L1CaloMonitoringCaloTool.cxx:293
CaloLVL1_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
Definition: CaloLVL1_ID.h:641
TileCell::qual1
uint8_t qual1(void) const
get quality of first PMT (data member)
Definition: TileCell.h:203
extractSporadic.q
list q
Definition: extractSporadic.py:98
beamspotman.qual
qual
Definition: beamspotman.py:481
LVL1::L1CaloMonitoringCaloTool::m_energySums
std::vector< float > m_energySums
Definition: L1CaloMonitoringCaloTool.h:74
CaloDetDescrElement::sinTh
float sinTh() const
for algorithm working in transverse Energy
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:383
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
LVL1::L1CaloMonitoringCaloTool::L1CaloMonitoringCaloTool
L1CaloMonitoringCaloTool()=delete
delete the big 4
LVL1::L1CaloMonitoringCaloTool::etaBin
int etaBin(const int index) const
Definition: L1CaloMonitoringCaloTool.cxx:326
Identifier32.h
LVL1::L1CaloMonitoringCaloTool::caloQuality
float caloQuality(const Identifier &ttid) const
Definition: L1CaloMonitoringCaloTool.cxx:283
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.