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 <algorithm>
21#include <iomanip>
22#include <iostream>
23#include <map>
24
25#include "DetDescr/EcalID.h"
27#include "Framework/Configure/Parameters.h"
28#include "Framework/Exception/Exception.h"
29#include "Framework/Logger.h"
30
31// ROOT
32#include "TGeoPolygon.h"
33#include "TGraph.h"
34#include "TH2Poly.h"
35#include "TList.h"
36
37namespace ecal {
38class EcalGeometryProvider;
39}
40
41namespace ldmx {
42
109 public:
110 static constexpr const char* CONDITIONS_OBJECT_NAME{"EcalGeometry"};
111
118 virtual ~EcalGeometry() = default;
119
136 EcalID getID(double x, double y, double z, bool fallible = false) const;
137
157 EcalID getID(double x, double y, int layer_id, bool fallible = false) const;
158
182 EcalID getID(double x, double y, int layer_id, int module_id,
183 bool fallible = false) const;
184
194 std::tuple<double, double, double> getPosition(EcalID id) const;
195
199 std::pair<double, double> getPositionInModule(int cell_id) const;
200
207 double getZPosition(int layer) const {
208 return std::get<2>(layer_pos_xy_.at(layer));
209 }
210
215 double getEcalFrontZ() const { return ecal_front_z_; }
216
222 int getNumLayers() const { return layer_pos_xy_.size(); }
223
236 int getNumModulesPerLayer() const { return 7; }
237
245 return cell_id_in_module_.GetNumberOfBins();
246 }
247
254 std::vector<EcalID> getNN(EcalID id) const {
255 auto list = nn_map_.at(EcalID(0, id.module(), id.cell()));
256 for (auto& flat : list)
257 flat = EcalID(id.layer(), flat.module(), flat.cell());
258 return list;
259 }
260
268 bool isNN(EcalID centroid, EcalID probe) const {
269 for (auto& id : getNN(centroid)) {
270 if (id == probe) return true;
271 }
272 return false;
273 }
274
281 std::vector<EcalID> getNNN(EcalID id) const {
282 auto list = nnn_map_.at(EcalID(0, id.module(), id.cell()));
283 for (auto& flat : list)
284 flat = EcalID(id.layer(), flat.module(), flat.cell());
285 return list;
286 }
287
296 bool isNNN(EcalID centroid, EcalID probe) const {
297 for (auto& id : getNNN(centroid)) {
298 if (id == probe) return true;
299 }
300 return false;
301 }
302
308 double getModuleMinR() const { return module_r_min_; }
309
315 double getModuleMaxR() const { return module_r_max_; }
316
322 double getCellMinR() const { return cell_r_min_; }
323
329 double getCellMaxR() const { return cell_r_max_; }
330
340 TH2Poly* getCellPolyMap() const {
341 for (auto const& [cell_id, cell_center] : cell_pos_in_module_) {
342 cell_id_in_module_.Fill(cell_center.first, cell_center.second, cell_id);
343 }
344 return &cell_id_in_module_;
345 }
346
347 static EcalGeometry* debugMake(const framework::config::Parameters& p) {
348 return new EcalGeometry(p);
349 }
350
351 private:
358 friend class ecal::EcalGeometryProvider;
359
363 void buildLayerMap();
364
382 void buildModuleMap();
383
416 void buildCellMap();
417
431 void buildCellModuleMap();
432
451 void buildNeighborMaps();
452
461 double distanceToEdge(EcalID id) const;
462
471 bool isEdgeCell(EcalID cellModuleID) const {
472 return (distanceToEdge(cellModuleID) < cell_r_max_);
473 }
474
490 bool isInside(double normX, double normY) const;
491
492 private:
494 double gap_;
495
497 double cell_r_min_{0};
498
500 double module_r_min_{0};
501
503 double cell_r_max_{0};
504
506 double module_r_max_{0};
507
514
519
524
533
547
555
564
566 double ecal_front_z_{0};
567
569 std::vector<double> layer_z_positions_;
570
571 private:
576 std::map<int, std::tuple<double, double, double>> layer_pos_xy_;
577
584 std::map<int, std::pair<double, double>> module_pos_xy_;
585
592 std::map<int, std::pair<double, double>> cell_pos_in_module_;
593
603 std::map<EcalID, std::pair<double, double>> cell_pos_in_layer_;
604
614 std::map<EcalID, std::tuple<double, double, double>> cell_global_pos_;
615
621 std::map<EcalID, std::vector<EcalID>> nn_map_;
622
628 std::map<EcalID, std::vector<EcalID>> nnn_map_;
629
638 mutable TH2Poly cell_id_in_module_;
639
640 enableLogging("EcalGeometry")
641};
642
643} // namespace ldmx
644
645#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:29
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