ATLAS Offline Software
PpmCoolMappingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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  // Retrieve the CaloTriggerTowerService tool
31  ATH_CHECK( m_ttSvc.retrieve() );
32 
33  // Retrieve the CaloIdManager from the detector store
34  const CaloIdManager* caloMgr = 0;
35  ATH_CHECK( detStore()->retrieve(caloMgr) );
36 
37  // Use the CaloIdManager to get a pointer to an instance
38  // of the CaloLVL1_ID helper
39  ATH_CHECK( (m_lvl1Helper = caloMgr->getLVL1_ID()) != nullptr );
40 
41  // Use the CaloIdManager to get a pointer to an instance
42  // of the TTOnlineID helper
43  ATH_CHECK( (m_l1ttonlineHelper = caloMgr->getTTOnlineID()) != nullptr );
44 
45  // Incident Service:
46  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name());
47  ATH_CHECK( incSvc.retrieve() );
48 
49  //start listening to "BeginRun"
50  incSvc->addListener(this, "BeginRun");
51 
52  return StatusCode::SUCCESS;
53 }
54 
55 
56 // Reset mapping table at start of run
57 
58 void PpmCoolMappingTool::handle(const Incident& inc)
59 {
60  // FIXME: not thread safe --- won't work if there's more than one run
61  // in the input.
62  if (inc.type()=="BeginRun") {
63  ATH_MSG_DEBUG("Resetting mapping table at start of run");
64 
66  for (int index = 0; index < s_maxTableEntries; ++index) {
67  const int channel = index & 0x3f;
68  const int module = (index >> 6) & 0x0f;
69  const int crate = index >> 10;
70  const int slot = module + 5;
71  const int pin = channel % 16;
72  const int asic = channel / 16;
73 
74  Identifier ttId(0);
75  Identifier invalidId(0);
76  try {
77  ATH_MSG_VERBOSE("crate/module/channel " << crate << "/"
78  << module << "/" << channel
79  << " maps to crate/slot/pin/asic " << crate << "/"
80  << slot << "/" << pin << "/" << asic);
81  const HWIdentifier id = m_l1ttonlineHelper->channelId(crate, slot, pin,
82  asic);
83  ATH_MSG_VERBOSE("hardware_id: " << id);
84 
85  ttId = m_ttSvc->cnvToIdentifier(id, true);
86  ATH_MSG_VERBOSE("tower_id: " << ttId);
87  }
88  catch (const CaloID_Exception&) { ttId = invalidId; }
89  if (ttId == invalidId) {
90  m_idTable[index] = 0;
91  }
92  else {
93  const int side = (m_lvl1Helper->pos_neg_z(ttId) == 1) ? 1 : 2;
94  const int sample = m_lvl1Helper->sampling(ttId);
95  const int region = m_lvl1Helper->region(ttId);
96  const int ieta = m_lvl1Helper->eta(ttId);
97  const int iphi = m_lvl1Helper->phi(ttId);
98  m_idTable[index] = (side<<14)+(sample<<13)+(region<<11)+(ieta<<6)+iphi;
99  }
100  }
101  }
102  return;
103 }
104 
105 // Return eta, phi and layer mapping for given crate/module/channel
106 
107 bool PpmCoolMappingTool::mapping(const int crate, const int module,
108  const int channel, double& eta, double& phi, int& layer) const
109 {
110  if (crate < 0 || crate >= 8 || module < 0 || module >= 16 ||
111  channel < 0 || channel >= 64) return false;
112 
113  int index = (crate<<10) + (module<<6) + channel;
114  if (index >= s_maxTableEntries) return false;
115 
116  if (index >= static_cast<int>(m_idTable.size()) || m_idTable[index] == 0) {
117  return false;
118  }
119  const unsigned int entry = m_idTable[index];
120  const int side = ((entry>>14) == 1) ? 1 : -1;
121  const int region = (entry>>11)&0x3;
122  const int ieta = (entry>>6)&0x1f;
123  const int iphi = entry&0x3f;
124  const double etaOffsets[4] = { 0., 2.5, 3.1, 3.2 };
125  const double etaGrans[4] = { 0.1, 0.2, 0.1, 0.425 };
126  const double phiGrans[4] = { M_PI/32., M_PI/16., M_PI/16., M_PI/8. };
127 
128  eta = side * (etaOffsets[region] + etaGrans[region] * (ieta + 0.5));
129  phi = phiGrans[region] * (iphi + 0.5);
130  layer = (entry>>13)&0x1;
131 
132  ATH_MSG_VERBOSE("crate/module/channel " << crate << "/" << module
133  << "/" << channel << " maps to eta/phi/layer "
134  << eta << "/" << phi << "/" << layer);
135 
136  return true;
137 }
138 
139 // Return crate, module and channel mapping for given eta/phi/layer
140 
141 bool PpmCoolMappingTool::mapping(const double eta, const double phi,
142  const int layer, int& crate, int& module, int& channel) const
143 {
144  if (eta <= -4.9 || eta >= 4.9 || phi <= 0. || phi >= 2.*M_PI) return false;
145 
146  const double etaOffsets[5] = { 0., 2.5, 3.1, 3.2, 4.9 };
147  const double etaGrans[4] = { 0.1, 0.2, 0.1, 0.425 };
148  const double phiGrans[4] = { M_PI/32., M_PI/16., M_PI/16., M_PI/8. };
149  const int side = (eta < 0.) ? -1 : 1;
150  int region = 0;
151  int ieta = 0;
152  int iphi = 0;
153  const double absEta = fabs(eta);
154  for (int i = 0; i < 4; ++i) {
155  if (absEta < etaOffsets[i+1]) {
156  region = i;
157  ieta = int((absEta - etaOffsets[i]) / etaGrans[i]);
158  iphi = int(phi / phiGrans[i]);
159  break;
160  }
161  }
162 
163  HWIdentifier id(0);
164  HWIdentifier invalidId(0);
165  try {
166  ATH_MSG_VERBOSE("eta/phi/layer " << eta << "/" << phi << "/"
167  << layer << " maps to side/layer/region/ieta/iphi "
168  << side << "/" << layer << "/" << region << "/"
169  << ieta << "/" << iphi);
170  const Identifier ttId = m_lvl1Helper->tower_id(side, layer, region,
171  ieta, iphi);
172  ATH_MSG_VERBOSE("tower_id: " << ttId);
173 
174  id = m_ttSvc->createTTChannelID(ttId, true);
175 
176  ATH_MSG_VERBOSE("hardware_id: " << id);
177 
178  }
179  catch (const CaloID_Exception&) { id = invalidId; }
180  if (id == invalidId) return false;
181 
182  const int slot = m_l1ttonlineHelper->module(id);
183  const int pin = m_l1ttonlineHelper->submodule(id);
184  const int asic = m_l1ttonlineHelper->channel(id);
185 
186  crate = m_l1ttonlineHelper->crate(id);
187  module = slot - 5;
188  channel = asic * 16 + pin;
189 
190  ATH_MSG_VERBOSE("eta/phi/layer " << eta << "/" << phi << "/" << layer
191  << " maps to crate/module/channel "
192  << crate << "/" << module << "/" << channel);
193 
194  return true;
195 }
196 
197 } // end namespace
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LVL1::PpmCoolMappingTool::m_ttSvc
ToolHandle< CaloTriggerTowerService > m_ttSvc
Definition: PpmCoolMappingTool.h:53
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:24
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloID_Exception
Exception class for Calo Identifiers.
Definition: CaloID_Exception.h:20
index
Definition: index.py:1
LVL1::PpmCoolMappingTool::m_idTable
std::vector< unsigned int > m_idTable
Mapping lookup table.
Definition: PpmCoolMappingTool.h:58
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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
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:107
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:131
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:116
lumiFormat.i
int i
Definition: lumiFormat.py:85
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:59
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
CaloIdManager::getLVL1_ID
const CaloLVL1_ID * getLVL1_ID(void) const
Definition: CaloIdManager.cxx:75
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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:220
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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:364
CaloLVL1_ID.h
TTOnlineID::submodule
int submodule(const HWIdentifier id) const
Definition: TTOnlineID.h:471
LVL1::PpmCoolMappingTool::m_lvl1Helper
const CaloLVL1_ID * m_lvl1Helper
Definition: PpmCoolMappingTool.h:54
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:234
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
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
LVL1::PpmCoolMappingTool::handle
virtual void handle(const Incident &) override
Definition: PpmCoolMappingTool.cxx:58
LVL1::PpmCoolMappingTool::m_l1ttonlineHelper
const TTOnlineID * m_l1ttonlineHelper
Definition: PpmCoolMappingTool.h:55
ServiceHandle< IIncidentSvc >
Identifier
Definition: IdentifierFieldParser.cxx:14