LDMX Software
EcalGeometry.h
Go to the documentation of this file.
1
15#ifndef DETDESCR_ECALGEOMETRY_H_
16#define DETDESCR_ECALGEOMETRY_H_
17
18#include <assert.h>
19
20#include <map>
21
22#include "DetDescr/EcalID.h"
24#include "Framework/Configure/Parameters.h"
25#include "Framework/Logger.h"
26
27// ROOT
28#include "TH2Poly.h"
29
30namespace ecal {
31class EcalGeometryProvider;
32}
33
34namespace ldmx {
35
102 public:
103 static constexpr const char* CONDITIONS_OBJECT_NAME{"EcalGeometry"};
104
111 virtual ~EcalGeometry() = default;
112
129 EcalID getID(double x, double y, double z, bool fallible = false) const;
130
150 EcalID getID(double x, double y, int layer_id, bool fallible = false) const;
151
175 EcalID getID(double x, double y, int layer_id, int module_id,
176 bool fallible = false) const;
177
187 std::tuple<double, double, double> getPosition(EcalID id) const;
188
192 std::pair<double, double> getPositionInModule(int cell_id) const;
193
200 double getZPosition(int layer) const {
201 return std::get<2>(layer_pos_xy_.at(layer));
202 }
203
208 double getEcalFrontZ() const { return ecal_front_z_; }
209
215 int getNumLayers() const { return layer_pos_xy_.size(); }
216
229 int getNumModulesPerLayer() const { return 7; }
230
238 return cell_id_in_module_.GetNumberOfBins();
239 }
240
247 std::vector<EcalID> getNN(EcalID id) const {
248 auto list = nn_map_.at(EcalID(0, id.module(), id.cell()));
249 for (auto& flat : list)
250 flat = EcalID(id.layer(), flat.module(), flat.cell());
251 return list;
252 }
253
261 bool isNN(EcalID centroid, EcalID probe) const {
262 for (auto& id : getNN(centroid)) {
263 if (id == probe) return true;
264 }
265 return false;
266 }
267
274 std::vector<EcalID> getNNN(EcalID id) const {
275 auto list = nnn_map_.at(EcalID(0, id.module(), id.cell()));
276 for (auto& flat : list)
277 flat = EcalID(id.layer(), flat.module(), flat.cell());
278 return list;
279 }
280
289 bool isNNN(EcalID centroid, EcalID probe) const {
290 for (auto& id : getNNN(centroid)) {
291 if (id == probe) return true;
292 }
293 return false;
294 }
295
301 double getModuleMinR() const { return module_r_min_; }
302
308 double getModuleMaxR() const { return module_r_max_; }
309
315 double getCellMinR() const { return cell_r_min_; }
316
322 double getCellMaxR() const { return cell_r_max_; }
323
333 TH2Poly* getCellPolyMap() const {
334 for (auto const& [cell_id, cell_center] : cell_pos_in_module_) {
335 cell_id_in_module_.Fill(cell_center.first, cell_center.second, cell_id);
336 }
337 return &cell_id_in_module_;
338 }
339
340 static EcalGeometry* debugMake(const framework::config::Parameters& p) {
341 return new EcalGeometry(p);
342 }
343
344 private:
351 friend class ecal::EcalGeometryProvider;
352
356 void buildLayerMap();
357
375 void buildModuleMap();
376
409 void buildCellMap();
410
424 void buildCellModuleMap();
425
444 void buildNeighborMaps();
445
454 double distanceToEdge(EcalID id) const;
455
464 bool isEdgeCell(EcalID cellModuleID) const {
465 return (distanceToEdge(cellModuleID) < cell_r_max_);
466 }
467
483 bool isInside(double normX, double normY) const;
484
485 private:
487 double gap_;
488
490 double cell_r_min_{0};
491
493 double module_r_min_{0};
494
496 double cell_r_max_{0};
497
499 double module_r_max_{0};
500
507
512
517
526
540
548
557
559 double ecal_front_z_{0};
560
562 std::vector<double> layer_z_positions_;
563
564 private:
569 std::map<int, std::tuple<double, double, double>> layer_pos_xy_;
570
577 std::map<int, std::pair<double, double>> module_pos_xy_;
578
585 std::map<int, std::pair<double, double>> cell_pos_in_module_;
586
596 std::map<EcalID, std::pair<double, double>> cell_pos_in_layer_;
597
607 std::map<EcalID, std::tuple<double, double, double>> cell_global_pos_;
608
614 std::map<EcalID, std::vector<EcalID>> nn_map_;
615
621 std::map<EcalID, std::vector<EcalID>> nnn_map_;
622
631 mutable TH2Poly cell_id_in_module_;
632
633 enableLogging("EcalGeometry")
634};
635
636} // namespace ldmx
637
638#endif
Base class for conditions information like pedestals, gains, electronics maps, etc.
Class that defines an ECal detector ID with a cell number.
Base class for all conditions objects, very simple.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
Translation between real-space positions and cell IDs within the ECal.
std::vector< EcalID > getNN(EcalID id) const
Get the Nearest Neighbors of the input ID.
std::map< EcalID, std::tuple< double, double, double > > cell_global_pos_
Position of cell centers relative to world geometry.
std::map< EcalID, std::vector< EcalID > > nnn_map_
Map of cell ID to neighbors of neighbor cells.
EcalID getID(double x, double y, double z, bool fallible=false) const
Get a cell's ID number from its position.
double getModuleMinR() const
Get the center-to-flat radius of the module hexagons.
std::tuple< double, double, double > getPosition(EcalID id) const
Get a cell's position from its ID number.
double getEcalFrontZ() const
Get the z-coordinate of the Ecal face.
int getNumLayers() const
Get the number of layers in the Ecal Geometry.
double getZPosition(int layer) const
Get the z-coordinate given the layer id.
void buildCellModuleMap()
Constructs the positions of all the cells in a layer relative to the ecal center.
double layer_shift_y_
shift of layers in the y-direction [mm]
double distanceToEdge(EcalID id) const
Distance to module edge, and whether cell is on edge of module.
std::pair< double, double > getPositionInModule(int cell_id) const
Get a cell's position within a module.
std::map< int, std::pair< double, double > > module_pos_xy_
Postion of module centers relative to the center of the layer in world coordinates.
void buildCellMap()
Constructs the flat-bottomed hexagonal grid (cellID) of corner-down hexagonal cells.
bool layer_shift_odd_
shift odd layers
int getNumModulesPerLayer() const
Get the number of modules in the Ecal flower.
double module_r_max_
Center-to-Corner Radius of module hexagon [mm].
double cell_r_min_
Center-to-Flat Radius of cell hexagon [mm].
std::map< int, std::tuple< double, double, double > > layer_pos_xy_
Position of layer centers in world coordinates (uses layer ID as key)
int getNumCellsPerModule() const
Get the number of cells in each module of the Ecal Geometry.
double n_cell_r_height_
Number of cell center-to-corner radii (one side of the cell) from the bottom to the top of the module...
std::map< int, std::pair< double, double > > cell_pos_in_module_
Position of cell centers relative to center of module in p,q space.
double layer_shift_x_
shift of layers in the x-direction [mm]
std::vector< EcalID > getNNN(EcalID id) const
Get the Next-to-Nearest Neighbors of the input ID.
double getModuleMaxR() const
Get the center-to-corner radius of the module hexagons.
void buildModuleMap()
Constructs the positions of the seven modules (moduleID) relative to the ecal center.
std::map< EcalID, std::pair< double, double > > cell_pos_in_layer_
Position of cell centers relative to center of layer in world coordinates.
std::map< EcalID, std::vector< EcalID > > nn_map_
Map of cell ID to neighboring cells.
std::vector< double > layer_z_positions_
The layer Z postions are with respect to the front of the ECal [mm].
bool isNNN(EcalID centroid, EcalID probe) const
Check if the probe id is one of the next-to-nearest neightbors of the centroid id.
double getCellMinR() const
Get the center-to-flat radius of the cell hexagons.
bool isInside(double normX, double normY) const
Determines if point (x,y), already normed to max hexagon radius, lies within a hexagon.
double si_thickness_
Thickness of the Si sensitive layer [mm].
bool layer_shift_odd_bilayer_
shift odd bi layers
void buildLayerMap()
Constructs the positions of the layers in world coordinates.
EcalGeometry(const framework::config::Parameters &ps)
Class constructor, for use only by the provider.
double cell_r_max_
Center-to-Corner Radius of cell hexagon [mm].
double ecal_front_z_
Front of ECal relative to world geometry [mm].
double gap_
Gap between module flat sides [mm].
virtual ~EcalGeometry()=default
Class destructor.
double module_r_min_
Center-to-Flat Radius of module hexagon [mm].
TH2Poly cell_id_in_module_
Honeycomb Binning from ROOT.
bool isNN(EcalID centroid, EcalID probe) const
Check if the probe id is one of the nearest neightbors of the centroid id.
double getCellMaxR() const
Get the center-to-corner radius of the cell hexagons.
bool isEdgeCell(EcalID cellModuleID) const
Check if input cell is on the edge of a module.
void buildNeighborMaps()
Construts NNMap and NNNMap.
bool corners_side_up_
indicator of geometry orientation if true, flower shape's corners side (ie: side with two modules) is...
TH2Poly * getCellPolyMap() const
Get a reference to the TH2Poly used for Cell IDs.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20