ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace {
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,
44 const CaloDetDescrManager_Base* mgr)
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,
59 const CaloDetDescrManager_Base* mgr)
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,
80 const CaloDetDescrManager_Base* mgr)
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}
#define M_PI
Scalar phi() const
phi method
Helper class for offline supercell identifiers.
Definition of CaloDetDescrManager.
Definition of CaloDetDescriptor.
Calo Subsystem specific Detector Elements + Dummy element for testing.
void createDescriptors(CaloSuperCellDetDescrManager *mgr)
void createElements(CaloSuperCellDetDescrManager *mgr)
StatusCode updateElements(CaloSuperCellDetDescrManager *mgr, const CaloDetDescrManager *cellmgr, const ICaloSuperCellIDTool *scidTool)
void updateDescriptors(CaloSuperCellDetDescrManager *mgr, const CaloDetDescrManager *cellmgr, const ICaloSuperCellIDTool *scidTool)
This is a collection of helper functions for building Calo Super Cell detector manager,...
#define x
Helper base class for offline cell identifiers.
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
const Tile_Base_ID * tile_idHelper() const
access to Tile idHelper
int sample(const Identifier id) const
Tile field values (NOT_VALID == invalid request)
id_range cell_range() const
Range over full set of Identifiers (LAr + Tiles)
bool is_tile(const Identifier id) const
test if the id belongs to the Tiles
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,...
IdentifierHash subcalo_cell_hash(const Identifier cellId, int &subCalo) const
create hash id from 'global' cell id
id_range reg_range() const
Range over set of region Identifiers (LAr + Tiles)
bool is_supercell(const Identifier id) const
Test if the identifier represents a supercell.
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
This is a base class for LAr and Tile Descriptors The primary goal is to speed up loops over all the ...
double deta() const
delta eta
int n_phi() const
phi granularity
int n_calo_depth() const
number of calo depths
double dphi() const
delta phi
void get_depth_in(std::vector< double > &calo_depth) const
get vector of in depths
const Amg::Transform3D & transform() const
Get the current transformation matrix.
int n_eta() const
eta granularity
void get_depth_out(std::vector< double > &calo_depth) const
get vector of out depths
Element to represent a SuperCell.
StatusCode update(const std::vector< const CaloDetDescrElement * > &fromelts)
Update this element's geometry from the given list of offline elements.
Interface for tool to map between calorimeter cells and supercells.
virtual std::vector< Identifier > superCellToOfflineRegion(const Identifier &reg_id) const =0
Given a supercell region identifier, return the corresponding offline region identifier(s).
virtual std::vector< Identifier > superCellToOfflineID(const Identifier &id) const =0
Given a supercell identifier, return the list of corresponding offline cell identifiers.
This is a "hash" representation of an Identifier.
bool is_valid() const
Check if id is in a valid state.
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55