ATLAS Offline Software
CaloSuperCellUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
11 #include "CaloDetDescr/CaloDetDescrElement.h"
14 
15 namespace {
16 
17  struct MinMax {
18  MinMax() : min(99999), max(-999999) {}
19  void add (double x, double dx)
20  {
21  if (x - dx < min) min = x - dx;
22  if (x + dx > max) max = x + dx;
23  }
24  double min;
25  double max;
26  };
27 
28  struct DescrMinMax {
29  MinMax eta;
30  MinMax phi;
31  MinMax r;
32  MinMax z;
33  };
34 
35  inline
36  double phi_for_descr (double phi)
37  {
38  if (phi < 0)
39  phi += 2*M_PI;
40  return phi;
41  }
42 
43  int descr_index (const CaloDetDescriptor* desc,
45  {
46  if (desc->is_tile()) {
47  int i= 0;
48  for (const CaloDetDescriptor* d : mgr->tile_descriptors_range()) {
49  if (d == desc) return mgr->calo_descriptors_size() + i;
50  ++i;
51  }
52  return -1;
53  }
54  else
55  return desc->calo_hash();
56  }
57 
58  const CaloDetDescriptor* get_cell_descriptor (Identifier cell_id,
60  {
61  const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID();
62  Identifier reg_id = calo_helper->region_id (cell_id);
63  if (!calo_helper->is_tile (cell_id)) {
64  assert (reg_id.is_valid());
65  return mgr->get_descriptor (reg_id);
66  }
67 
68  int clayer = calo_helper->sample (cell_id);
69  bool is_sc = calo_helper->is_supercell (cell_id);
70  for (const CaloDetDescriptor* d : mgr->tile_descriptors_range()) {
71  if (d->identify() != reg_id) continue;
72  int dlayer = d->layer();
73  if (clayer == dlayer) return d;
74  if (is_sc && dlayer == 0 && clayer != 2) return d;
75  }
76  return nullptr;
77  }
78 
79  const CaloDetDescriptor* get_reg_descriptor (Identifier reg_id,
81  {
82  const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID();
83  if (!calo_helper->is_tile (reg_id)) {
84  assert (reg_id.is_valid());
85  return mgr->get_descriptor (reg_id);
86  }
87 
88  for (const CaloDetDescriptor* d : mgr->tile_descriptors_range()) {
89  if (d->identify() == reg_id) return d;
90  }
91  return nullptr;
92  }
93 
94  void updateDescriptor(CaloDetDescriptor* desc
95  , const DescrMinMax& mm
96  , const CaloDetDescrManager* cellmgr
97  , const ICaloSuperCellIDTool* scidTool)
98  {
99  if (!desc) return;
100 
101  if (desc->calo_eta_max() == 0) {
102  // Only do this the first time.
103  desc->setCaloEtaMin (mm.eta.min);
104  desc->setCaloEtaMax (mm.eta.max);
105  desc->setCaloPhiMin (mm.phi.min);
106  desc->setCaloPhiMax (mm.phi.max);
107  desc->setCaloRMin (mm.r.min);
108  desc->setCaloRMax (mm.r.max);
109  desc->setCaloZMin (mm.z.min);
110  desc->setCaloZMax (mm.z.max);
111 
112  std::vector<Identifier> cell_regions =
113  scidTool->superCellToOfflineRegion (desc->identify());
114  assert (!cell_regions.empty());
115 
116  const CaloDetDescriptor* celldesc =
117  get_reg_descriptor (cell_regions[0], cellmgr);
118 
119  if (celldesc) {
120  if (desc->is_tile()) {
121  desc->set_eta_phi_granularity (celldesc->n_eta(),
122  celldesc->deta(),
123  celldesc->n_phi(),
124  celldesc->dphi());
125  }
126 
127  std::vector<double> depths;
128  desc->set_n_calo_depth (celldesc->n_calo_depth());
129  celldesc->get_depth_in (depths);
130  desc->set_depth_in (depths);
131  celldesc->get_depth_out (depths);
132  desc->set_depth_out (depths);
133 
134  desc->set_transform (celldesc->transform());
135  }
136  }
137 
138  // Do this each realignment.
139  desc->setLArEtaMin (mm.eta.min);
140  desc->setLArPhiMin (mm.phi.min);
141  if (desc->calo_sign() > 0) {
142  desc->setLArRegMin (mm.eta.min);
143  desc->setLArRegMax (mm.eta.max);
144  }
145  else {
146  desc->setLArRegMin (-mm.eta.max);
147  desc->setLArRegMax (-mm.eta.min);
148  }
149  }
150 
151 
152 } // anonymous namespace
153 
154 
156 {
157  const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID();
158  for (Identifier reg_id : calo_helper->reg_range()) {
159  if (! calo_helper->is_tile (reg_id)) {
160  mgr->add (new CaloDetDescriptor (reg_id, nullptr, calo_helper));
161  }
162  else {
163  mgr->add_tile (new CaloDetDescriptor
164  (reg_id, calo_helper->tile_idHelper(), calo_helper,
165  (CaloCell_ID::CaloSample)calo_helper->calo_sample(reg_id), 0));
166  // NB. CaloDetDescrElement::getSampling adds the tile cell sampling
167  // index to the descriptor's sampling, so don't add 2 here
168  // to calo_sample.
169  mgr->add_tile (new CaloDetDescriptor
170  (reg_id, calo_helper->tile_idHelper(), calo_helper,
171  (CaloCell_ID::CaloSample)(calo_helper->calo_sample(reg_id)), 2));
172  }
173  }
174 }
175 
177 {
178  const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID();
179  for (Identifier cell_id : calo_helper->cell_range()) {
180  int subCalo = -1;
181  IdentifierHash subCaloHash =
182  calo_helper->subcalo_cell_hash (cell_id, subCalo);
183 
184  const CaloDetDescriptor* desc = get_cell_descriptor (cell_id, mgr);
185  assert (desc);
186  mgr->add (new CaloSuperCellDetectorElement (subCaloHash, desc));
187  }
188 }
189 
191  , const CaloDetDescrManager* cellmgr
192  , const ICaloSuperCellIDTool* scidTool)
193 {
194  // For each supercell, we make a list of the corresponding cells.
195  // Then we pass that list to the supercell's @c update method.
196 
197  for (CaloDetDescrElement* elt : mgr->element_range_nonconst()) {
198  if (!elt) continue;
200  dynamic_cast<CaloSuperCellDetectorElement*> (elt);
201  if (!selt) continue;
202 
203  std::vector<Identifier> ids =
204  scidTool->superCellToOfflineID (elt->identify());
205  assert (!ids.empty());
206 
207  const CaloCell_Base_ID* idhelper = mgr->getCaloCell_ID();
208  const CaloCell_Base_ID* cell_idhelper = cellmgr->getCaloCell_ID();
209 
210  std::vector<const CaloDetDescrElement*> fromelts;
211  fromelts.reserve (ids.size());
212  for (Identifier id : ids) {
213  // For tile tower sums, exclude D-layer cells
214  // (they have a different size).
215  if (cell_idhelper->sub_calo(id) == CaloCell_Base_ID::TILE &&
216  cell_idhelper->sample(id) == 2 &&
217  idhelper->sample(elt->identify()) != 2)
218  continue;
219  const CaloDetDescrElement* fromelt = cellmgr->get_element (id);
220  assert (fromelt != nullptr);
221  fromelts.push_back (fromelt);
222  }
223  if(selt->update(fromelts).isFailure()) {
224  return StatusCode::FAILURE;
225  }
226  }
227  return StatusCode::SUCCESS;
228 }
229 
231  , const CaloDetDescrManager* cellmgr
232  , const ICaloSuperCellIDTool* scidTool)
233 {
234  size_t maxdesc = mgr->calo_descriptors_size() + mgr->tile_descriptors_size();
235  std::vector<DescrMinMax> descr_minmax (maxdesc);
236 
237  // Loop over cells and record range limits for each descriptor.
238  for (const CaloDetDescrElement* elt : mgr->element_range()) {
239  if (!elt) continue;
240  CaloDetDescriptor* desc = const_cast<CaloDetDescriptor*>(elt->descriptor());
241  int ndx = descr_index (desc, mgr);
242  assert (ndx >= 0 && ndx < (int)descr_minmax.size());
243  DescrMinMax& mm = descr_minmax[ndx];
244 
245  int dz_den = desc->is_lar_hec() ? 1 : 2;
246 
247  mm.eta.add (std::abs(elt->eta_raw()), elt->deta()/2);
248  mm.phi.add (phi_for_descr (elt->phi_raw()), elt->dphi()/2);
249  mm.r.add (elt->r(), elt->dr()/2);
250  mm.z.add (std::abs(elt->z_raw()), elt->dz()/dz_den);
251  }
252 
253  // Loop over each descriptor and update.
254  size_t i = 0;
255  for (CaloDetDescriptor* desc : mgr->calo_descriptors_range_nonconst()) {
256  updateDescriptor (desc, descr_minmax[i], cellmgr, scidTool);
257  ++i;
258  }
259  for (CaloDetDescriptor* desc : mgr->tile_descriptors_range_nonconst()) {
260  updateDescriptor (desc, descr_minmax[i], cellmgr, scidTool);
261  ++i;
262  }
263 }
CaloSuperCellUtils.h
This is a collection of helper functions for building Calo Super Cell detector manager,...
beamspotman.r
def r
Definition: beamspotman.py:676
CaloCell_Base_ID::is_supercell
bool is_supercell(const Identifier id) const
Test if the identifier represents a supercell.
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloDetDescriptor::get_depth_out
void get_depth_out(std::vector< double > &calo_depth) const
get vector of out depths
Definition: CaloDetDescriptor.cxx:332
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
hist_file_dump.d
d
Definition: hist_file_dump.py:137
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloCell_Base_ID::region_id
Identifier region_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy) const
Make a region ID from constituting fields and subCalo index; for (Mini)FCAL and Tiles,...
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
CaloDetDescriptor::dphi
double dphi() const
delta phi
Definition: CaloDetDescriptor.h:593
CaloDetDescriptor::n_calo_depth
int n_calo_depth() const
number of calo depths
Definition: CaloDetDescriptor.cxx:322
ICaloSuperCellIDTool
Interface for tool to map between calorimeter cells and supercells.
Definition: ICaloSuperCellIDTool.h:31
M_PI
#define M_PI
Definition: ActiveFraction.h:11
updateDescriptors
void updateDescriptors(CaloSuperCellDetDescrManager *mgr, const CaloDetDescrManager *cellmgr, const ICaloSuperCellIDTool *scidTool)
Definition: CaloSuperCellUtils.cxx:230
CaloDetDescrManager_Base
Definition: CaloDetDescrManager.h:147
ICaloSuperCellIDTool::superCellToOfflineID
virtual std::vector< Identifier > superCellToOfflineID(const Identifier &id) const =0
Given a supercell identifier, return the list of corresponding offline cell identifiers.
CaloCell_Base_ID::calo_sample
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Definition: CaloCell_Base_ID.cxx:141
CaloCell_Base_ID::is_tile
bool is_tile(const Identifier id) const
test if the id belongs to the Tiles
x
#define x
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
ICaloSuperCellIDTool.h
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
CaloCell_ID.h
CaloSuperCellDetDescrManager
Definition: CaloDetDescrManager.h:490
createElements
void createElements(CaloSuperCellDetDescrManager *mgr)
Definition: CaloSuperCellUtils.cxx:176
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
CaloCell_Base_ID::reg_range
id_range reg_range(void) const
Range over set of region Identifiers (LAr + Tiles)
CaloDetDescriptor.h
Definition of CaloDetDescriptor.
CaloDetDescriptor::get_depth_in
void get_depth_in(std::vector< double > &calo_depth) const
get vector of in depths
Definition: CaloDetDescriptor.cxx:325
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
CaloCell_Base_ID::sample
int sample(const Identifier id) const
Tile field values (NOT_VALID == invalid request)
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloDetDescriptor::n_phi
int n_phi() const
phi granularity
Definition: CaloDetDescriptor.h:603
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
z
#define z
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
ICaloSuperCellIDTool::superCellToOfflineRegion
virtual std::vector< Identifier > superCellToOfflineRegion(const Identifier &reg_id) const =0
Given a supercell region identifier, return the corresponding offline region identifier(s).
createDescriptors
void createDescriptors(CaloSuperCellDetDescrManager *mgr)
Definition: CaloSuperCellUtils.cxx:155
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
CaloCell_Base_ID::sub_calo
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
CaloCell_Base_ID::subcalo_cell_hash
IdentifierHash subcalo_cell_hash(const Identifier cellId, int &subCalo) const
create hash id from 'global' cell id
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
CaloDetDescriptor::deta
double deta() const
delta eta
Definition: CaloDetDescriptor.h:588
CaloCell_Base_ID::cell_range
id_range cell_range(void) const
Range over full set of Identifiers (LAr + Tiles)
min
#define min(a, b)
Definition: cfImp.cxx:40
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
CaloDetDescriptor::transform
const Amg::Transform3D & transform() const
Get the current transformation matrix.
Definition: CaloDetDescriptor.h:689
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
CaloSuperCellDetectorElement
Element to represent a SuperCell.
Definition: CaloDetectorElements.h:423
CaloSuperCellDetectorElement::update
StatusCode update(const std::vector< const CaloDetDescrElement * > &fromelts)
Update this element's geometry from the given list of offline elements.
Definition: CaloDetectorElements.cxx:613
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloDetDescriptor
This is a base class for LAr and Tile Descriptors The primary goal is to speed up loops over all the ...
Definition: CaloDetDescriptor.h:58
CaloDetDescriptor::n_eta
int n_eta() const
eta granularity
Definition: CaloDetDescriptor.h:598
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
CaloDetDescrManager::getCaloCell_ID
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
Definition: CaloDetDescrManager.cxx:1590
updateElements
StatusCode updateElements(CaloSuperCellDetDescrManager *mgr, const CaloDetDescrManager *cellmgr, const ICaloSuperCellIDTool *scidTool)
Definition: CaloSuperCellUtils.cxx:190
IdentifierHash
Definition: IdentifierHash.h:38
CaloCell_Base_ID
Helper base class for offline cell identifiers.
Definition: CaloCell_Base_ID.h:41
CaloCell_Base_ID::tile_idHelper
const Tile_Base_ID * tile_idHelper() const
access to Tile idHelper
Definition: CaloCell_Base_ID.h:355
CaloDetectorElements.h
Calo Subsystem specific Detector Elements + Dummy element for testing.