ATLAS Offline Software
PpmCoolMappingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cmath>
6 
7 #include "GaudiKernel/IIncidentSvc.h"
8 #include "GaudiKernel/IInterface.h"
9 #include "GaudiKernel/MsgStream.h"
10 #include "GaudiKernel/StatusCode.h"
11 
16 #include "Identifier/Identifier.h"
18 
19 #include "PpmCoolMappingTool.h"
20 
21 namespace LVL1 {
22 
24 
25 
26 // Initialise the mappings
27 
29 {
30  msg(MSG::INFO) << "Initializing " << name() << endmsg;
31 
32  // Retrieve the CaloTriggerTowerService tool
33  StatusCode sc = m_ttSvc.retrieve();
34  if (sc.isFailure()) {
35  msg(MSG::ERROR) << "Failed to retrieve tool " << m_ttSvc << endmsg;
36  return sc;
37  } else msg(MSG::INFO) << "Retrieved tool " << m_ttSvc << endmsg;
38 
39  // Retrieve the CaloIdManager from the detector store
40  const CaloIdManager* caloMgr = 0;
41  sc = detStore()->retrieve(caloMgr);
42  if (sc.isFailure()) {
43  msg(MSG::ERROR) << "Unable to retrieve CaloIdManager from DetectorStore"
44  << endmsg;
45  return sc;
46  }
47 
48  // Use the CaloIdManager to get a pointer to an instance
49  // of the CaloLVL1_ID helper
50  m_lvl1Helper = caloMgr->getLVL1_ID();
51  if (!m_lvl1Helper) {
52  msg(MSG::ERROR) << "Could not access CaloLVL1_ID helper" << endmsg;
53  return StatusCode::FAILURE;
54  }
55 
56  // Use the CaloIdManager to get a pointer to an instance
57  // of the TTOnlineID helper
58  m_l1ttonlineHelper = caloMgr->getTTOnlineID();
59  if (!m_l1ttonlineHelper ) {
60  msg(MSG::ERROR) << "Could not access TTOnlineID helper" << endmsg;
61  return StatusCode::FAILURE;
62  }
63 
64  // Incident Service:
65  IIncidentSvc* incSvc = 0;
66  sc = service("IncidentSvc", incSvc);
67  if (sc.isFailure()) {
68  msg(MSG::ERROR) << "Unable to retrieve pointer to IncidentSvc " << endmsg;
69  return StatusCode::FAILURE;
70  }
71 
72  //start listening to "BeginRun"
73  if (incSvc) incSvc->addListener(this, "BeginRun");
74 
75 
76  return StatusCode::SUCCESS;
77 }
78 
80 {
81 
82  return StatusCode::SUCCESS;
83 }
84 
85 // Reset mapping table at start of run
86 
87 void PpmCoolMappingTool::handle(const Incident& inc)
88 {
89  // FIXME: not thread safe --- won't work if there's more than one run
90  // in the input.
91  if (inc.type()=="BeginRun") {
92  if (msgLvl(MSG::DEBUG)) {
93  msg(MSG::DEBUG) << "Resetting mapping table at start of run" << endmsg;
94  }
95 
96  bool verbose = msgLvl(MSG::VERBOSE);
98  for (int index = 0; index < s_maxTableEntries; ++index) {
99  const int channel = index & 0x3f;
100  const int module = (index >> 6) & 0x0f;
101  const int crate = index >> 10;
102  const int slot = module + 5;
103  const int pin = channel % 16;
104  const int asic = channel / 16;
105 
106  Identifier ttId(0);
107  Identifier invalidId(0);
108  try {
109  if (verbose) {
110  msg(MSG::VERBOSE) << "crate/module/channel " << crate << "/"
111  << module << "/" << channel
112  << " maps to crate/slot/pin/asic " << crate << "/"
113  << slot << "/" << pin << "/" << asic << endmsg;
114  }
115  const HWIdentifier id = m_l1ttonlineHelper->channelId(crate, slot, pin,
116  asic);
117  if (verbose) {
118  msg(MSG::VERBOSE) << "hardware_id: " << id << endmsg;
119  }
120  ttId = m_ttSvc->cnvToIdentifier(id, true);
121  if (verbose) {
122  msg(MSG::VERBOSE) << "tower_id: " << ttId << endmsg;
123  }
124  }
125  catch (const CaloID_Exception&) { ttId = invalidId; }
126  if (ttId == invalidId) {
127  m_idTable[index] = 0;
128  }
129  else {
130  const int side = (m_lvl1Helper->pos_neg_z(ttId) == 1) ? 1 : 2;
131  const int sample = m_lvl1Helper->sampling(ttId);
132  const int region = m_lvl1Helper->region(ttId);
133  const int ieta = m_lvl1Helper->eta(ttId);
134  const int iphi = m_lvl1Helper->phi(ttId);
135  m_idTable[index] = (side<<14)+(sample<<13)+(region<<11)+(ieta<<6)+iphi;
136  }
137  }
138  }
139  return;
140 }
141 
142 // Return eta, phi and layer mapping for given crate/module/channel
143 
144 bool PpmCoolMappingTool::mapping(const int crate, const int module,
145  const int channel, double& eta, double& phi, int& layer) const
146 {
147  if (crate < 0 || crate >= 8 || module < 0 || module >= 16 ||
148  channel < 0 || channel >= 64) return false;
149 
150  int index = (crate<<10) + (module<<6) + channel;
151  if (index >= s_maxTableEntries) return false;
152 
153  bool verbose = msgLvl(MSG::VERBOSE);
154 
155  if (index >= static_cast<int>(m_idTable.size()) || m_idTable[index] == 0) {
156  return false;
157  }
158  const unsigned int entry = m_idTable[index];
159  const int side = ((entry>>14) == 1) ? 1 : -1;
160  const int region = (entry>>11)&0x3;
161  const int ieta = (entry>>6)&0x1f;
162  const int iphi = entry&0x3f;
163  const double etaOffsets[4] = { 0., 2.5, 3.1, 3.2 };
164  const double etaGrans[4] = { 0.1, 0.2, 0.1, 0.425 };
165  const double phiGrans[4] = { M_PI/32., M_PI/16., M_PI/16., M_PI/8. };
166 
167  eta = side * (etaOffsets[region] + etaGrans[region] * (ieta + 0.5));
168  phi = phiGrans[region] * (iphi + 0.5);
169  layer = (entry>>13)&0x1;
170 
171  if (verbose) {
172  msg(MSG::VERBOSE) << "crate/module/channel " << crate << "/" << module
173  << "/" << channel << " maps to eta/phi/layer "
174  << eta << "/" << phi << "/" << layer << endmsg;
175  }
176 
177  return true;
178 }
179 
180 // Return crate, module and channel mapping for given eta/phi/layer
181 
182 bool PpmCoolMappingTool::mapping(const double eta, const double phi,
183  const int layer, int& crate, int& module, int& channel) const
184 {
185  if (eta <= -4.9 || eta >= 4.9 || phi <= 0. || phi >= 2.*M_PI) return false;
186 
187  const double etaOffsets[5] = { 0., 2.5, 3.1, 3.2, 4.9 };
188  const double etaGrans[4] = { 0.1, 0.2, 0.1, 0.425 };
189  const double phiGrans[4] = { M_PI/32., M_PI/16., M_PI/16., M_PI/8. };
190  const int side = (eta < 0.) ? -1 : 1;
191  int region = 0;
192  int ieta = 0;
193  int iphi = 0;
194  const double absEta = fabs(eta);
195  for (int i = 0; i < 4; ++i) {
196  if (absEta < etaOffsets[i+1]) {
197  region = i;
198  ieta = int((absEta - etaOffsets[i]) / etaGrans[i]);
199  iphi = int(phi / phiGrans[i]);
200  break;
201  }
202  }
203 
204  bool verbose = msgLvl(MSG::VERBOSE);
205 
206  HWIdentifier id(0);
207  HWIdentifier invalidId(0);
208  try {
209  if (verbose) {
210  msg(MSG::VERBOSE) << "eta/phi/layer " << eta << "/" << phi << "/"
211  << layer << " maps to side/layer/region/ieta/iphi "
212  << side << "/" << layer << "/" << region << "/"
213  << ieta << "/" << iphi << endmsg;
214  }
215  const Identifier ttId = m_lvl1Helper->tower_id(side, layer, region,
216  ieta, iphi);
217  if (verbose) {
218  msg(MSG::VERBOSE) << "tower_id: " << ttId << endmsg;
219  }
220  id = m_ttSvc->createTTChannelID(ttId, true);
221  if (verbose) {
222  msg(MSG::VERBOSE) << "hardware_id: " << id << endmsg;
223  }
224  }
225  catch (const CaloID_Exception&) { id = invalidId; }
226  if (id == invalidId) return false;
227 
228  const int slot = m_l1ttonlineHelper->module(id);
229  const int pin = m_l1ttonlineHelper->submodule(id);
230  const int asic = m_l1ttonlineHelper->channel(id);
231 
232  crate = m_l1ttonlineHelper->crate(id);
233  module = slot - 5;
234  channel = asic * 16 + pin;
235 
236  if (verbose) {
237  msg(MSG::VERBOSE) << "eta/phi/layer " << eta << "/" << phi << "/" << layer
238  << " maps to crate/module/channel "
239  << crate << "/" << module << "/" << channel << endmsg;
240  }
241 
242  return true;
243 }
244 
245 } // end namespace
LVL1::PpmCoolMappingTool::m_ttSvc
ToolHandle< CaloTriggerTowerService > m_ttSvc
Definition: PpmCoolMappingTool.h:54
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
TTOnlineID::channel
int channel(const HWIdentifier id) const
Definition: TTOnlineID.h:477
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloID_Exception
Exception class for Calo Identifiers.
Definition: CaloID_Exception.h:20
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
index
Definition: index.py:1
LVL1::PpmCoolMappingTool::m_idTable
std::vector< unsigned int > m_idTable
Mapping lookup table.
Definition: PpmCoolMappingTool.h:59
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CaloLVL1_ID::region
int region(const Identifier id) const
return region according to :
Definition: CaloLVL1_ID.h:647
HWIdentifier
Definition: HWIdentifier.h:13
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::PpmCoolMappingTool::mapping
virtual bool mapping(int crate, int module, int channel, double &eta, double &phi, int &layer) const override
Return eta, phi and layer mapping for given crate/module/channel.
Definition: PpmCoolMappingTool.cxx:144
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TRT::Hit::side
@ side
Definition: HitInfo.h:83
CaloLVL1_ID::phi
int phi(const Identifier id) const
return phi according to :
Definition: CaloLVL1_ID.h:659
python.PyAthena.module
module
Definition: PyAthena.py:134
LVL1::PpmCoolMappingTool::initialize
virtual StatusCode initialize() override
Definition: PpmCoolMappingTool.cxx:28
TTOnlineID::module
int module(const HWIdentifier id) const
Definition: TTOnlineID.h:465
CaloIdManager
This class initializes the Calo (LAr and Tile) offline identifiers.
Definition: CaloIdManager.h:45
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LVL1::PpmCoolMappingTool::s_maxTableEntries
static const int s_maxTableEntries
Definition: PpmCoolMappingTool.h:60
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LVL1::PpmCoolMappingTool::finalize
virtual StatusCode finalize() override
Definition: PpmCoolMappingTool.cxx:79
CaloIdManager::getLVL1_ID
const CaloLVL1_ID * getLVL1_ID(void) const
Definition: CaloIdManager.cxx:75
TTOnlineID.h
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
HWIdentifier.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloLVL1_ID::eta
int eta(const Identifier id) const
return eta according to :
Definition: CaloLVL1_ID.h:653
CaloLVL1_ID::pos_neg_z
int pos_neg_z(const Identifier id) const
return pos_neg_z according to :
Definition: CaloLVL1_ID.h:635
PpmCoolMappingTool.h
DeMoScan.index
string index
Definition: DeMoScan.py:362
CaloLVL1_ID.h
TTOnlineID::submodule
int submodule(const HWIdentifier id) const
Definition: TTOnlineID.h:471
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
LVL1::PpmCoolMappingTool::m_lvl1Helper
const CaloLVL1_ID * m_lvl1Helper
Definition: PpmCoolMappingTool.h:55
DEBUG
#define DEBUG
Definition: page_access.h:11
CaloLVL1_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
Definition: CaloLVL1_ID.h:641
TauGNNUtils::Variables::absEta
bool absEta(const xAOD::TauJet &tau, double &out)
Definition: TauGNNUtils.cxx:232
TTOnlineID::channelId
HWIdentifier channelId(int crate, int module, int submodule, int channel) const
(1) create towerId from fields
Definition: TTOnlineID.h:398
CaloIdManager.h
CaloIdManager::getTTOnlineID
const TTOnlineID * getTTOnlineID(void) const
Definition: CaloIdManager.cxx:105
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TTOnlineID::crate
int crate(const HWIdentifier id) const
Definition: TTOnlineID.h:459
CaloID_Exception.h
CaloLVL1_ID::tower_id
Identifier tower_id(int pos_neg_z, int sampling, int region, int eta, int phi) const
build a tower identifier
Definition: CaloLVL1_ID.h:429
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
LVL1::PpmCoolMappingTool::handle
virtual void handle(const Incident &) override
Definition: PpmCoolMappingTool.cxx:87
LVL1::PpmCoolMappingTool::m_l1ttonlineHelper
const TTOnlineID * m_l1ttonlineHelper
Definition: PpmCoolMappingTool.h:56