LDMX Software
|
Translation between real-space positions and cell IDs within the ECal. More...
#include <EcalGeometry.h>
Public Member Functions | |
virtual | ~EcalGeometry ()=default |
Class destructor. | |
EcalID | getID (double x, double y, double z, bool fallible=false) const |
Get a cell's ID number from its position. | |
EcalID | getID (double x, double y, int layer_id, bool fallible=false) const |
Get a cell's ID from its x,y global position and layer number. | |
EcalID | getID (double x, double y, int layer_id, int module_id, bool fallible=false) const |
Get a cell's ID from its x,y global position and layer/module numbers as deduced from GDML copy numbers. | |
std::tuple< double, double, double > | getPosition (EcalID id) const |
Get a cell's position from its ID number. | |
std::pair< double, double > | getPositionInModule (int cell_id) const |
Get a cell's position within a module. | |
double | getZPosition (int layer) const |
Get the z-coordinate given the layer id. | |
int | getNumLayers () const |
Get the number of layers in the Ecal Geometry. | |
int | getNumModulesPerLayer () const |
Get the number of modules in the Ecal flower. | |
int | getNumCellsPerModule () const |
Get the number of cells in each module of the Ecal Geometry. | |
std::vector< EcalID > | getNN (EcalID id) const |
Get the Nearest Neighbors of the input ID. | |
bool | isNN (EcalID centroid, EcalID probe) const |
Check if the probe id is one of the nearest neightbors of the centroid id. | |
std::vector< EcalID > | getNNN (EcalID id) const |
Get the Next-to-Nearest Neighbors of the input ID. | |
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 | getModuleMinR () const |
Get the center-to-flat radius of the module hexagons. | |
double | getModuleMaxR () const |
Get the center-to-corner radius of the module hexagons. | |
double | getCellMinR () const |
Get the center-to-flat radius of the cell hexagons. | |
double | getCellMaxR () const |
Get the center-to-corner radius of the cell hexagons. | |
TH2Poly * | getCellPolyMap () const |
Get a reference to the TH2Poly used for Cell IDs. | |
Public Member Functions inherited from framework::ConditionsObject | |
ConditionsObject (const std::string &name) | |
Class constructor. | |
virtual | ~ConditionsObject () |
Destructor. | |
std::string | getName () const |
Get the name of this object. | |
Static Public Member Functions | |
static EcalGeometry * | debugMake (const framework::config::Parameters &p) |
Static Public Attributes | |
static constexpr const char * | CONDITIONS_OBJECT_NAME {"EcalGeometry"} |
Private Member Functions | |
EcalGeometry (const framework::config::Parameters &ps) | |
Class constructor, for use only by the provider. | |
void | buildLayerMap () |
Constructs the positions of the layers in world coordinates. | |
void | buildModuleMap () |
Constructs the positions of the seven modules (moduleID) relative to the ecal center. | |
void | buildCellMap () |
Constructs the flat-bottomed hexagonal grid (cellID) of corner-down hexagonal cells. | |
void | buildCellModuleMap () |
Constructs the positions of all the cells in a layer relative to the ecal center. | |
void | buildNeighborMaps () |
Construts NNMap and NNNMap. | |
double | distanceToEdge (EcalID id) const |
Distance to module edge, and whether cell is on edge of module. | |
bool | isEdgeCell (EcalID cellModuleID) const |
Check if input cell is on the edge of a module. | |
bool | isInside (double normX, double normY) const |
Determines if point (x,y), already normed to max hexagon radius, lies within a hexagon. | |
Private Attributes | |
double | gap_ |
Gap between module flat sides [mm]. | |
double | cellr_ {0} |
Center-to-Flat Radius of cell hexagon [mm]. | |
double | moduler_ {0} |
Center-to-Flat Radius of module hexagon [mm]. | |
double | cellR_ {0} |
Center-to-Corner Radius of cell hexagon [mm]. | |
double | moduleR_ {0} |
Center-to-Corner Radius of module hexagon [mm]. | |
bool | cornersSideUp_ |
indicator of geometry orientation if true, flower shape's corners side (ie: side with two modules) is at the top | |
double | layer_shift_x_ |
shift of layers in the x-direction [mm] | |
double | layer_shift_y_ |
shift of layers in the y-direction [mm] | |
bool | layer_shift_odd_ |
shift odd layers | |
bool | layer_shift_odd_bilayer_ |
shift odd bi layers | |
double | nCellRHeight_ {0} |
Number of cell center-to-corner radii (one side of the cell) from the bottom to the top of the module. | |
double | ecalFrontZ_ {0} |
Front of ECal relative to world geometry [mm]. | |
std::vector< double > | layerZPositions_ |
The layer Z postions are with respect to the front of the ECal [mm]. | |
int | verbose_ |
verbosity | |
std::map< int, std::tuple< double, double, double > > | layer_pos_xy_ |
Position of layer centers in world coordinates (uses layer ID as key) | |
std::map< int, std::pair< double, double > > | module_pos_xy_ |
Postion of module centers relative to the center of the layer in world coordinates. | |
std::map< int, std::pair< double, double > > | cell_pos_in_module_ |
Position of cell centers relative to center of module in p,q space. | |
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::tuple< double, double, double > > | cell_global_pos_ |
Position of cell centers relative to world geometry. | |
std::map< EcalID, std::vector< EcalID > > | NNMap_ |
Map of cell ID to neighboring cells. | |
std::map< EcalID, std::vector< EcalID > > | NNNMap_ |
Map of cell ID to neighbors of neighbor cells. | |
TH2Poly | cell_id_in_module_ |
Honeycomb Binning from ROOT. | |
Friends | |
class | ecal::EcalGeometryProvider |
Translation between real-space positions and cell IDs within the ECal.
This is the object that does the extra geometry not implemented in the gdml. In order to save time during the simulation, the individual cells in the readout hexagons are not constructed individually in Geant4. This means we have to have a translation between position and cell ID which is accomplished by this class.
Moreover, downstream processors sometimes need access to the cell position when they only know the cell ID. This class can also do this conversion.
Since the whole hexagon flower has changed orientation since previous versions of the detector (which we wish to still support), I am defining an extra set of axes with respect to the flower itself. Below I have drawn the ECal hexagon i flower and defined two axes: p (through the "pointy sides") and q (through the "flat sides"). In some versions of the ECal flower, p == x and q == y while in others p == -y and q == x.
^ | q axis __ __/1 \__ /6 \__/2 \ \__/0 \__/ __ p axis __> /5 \__/3 \ \__/4 \__/ \__/
Now we can define a process for determining the cellular IDs.
The cell radius is calculated from the total number of center-to-corner cell radii that span the module height. This count can have fractional counts to account for the fractions of cell radii at the module edges.
Definition at line 101 of file EcalGeometry.h.
|
virtualdefault |
Class destructor.
Does nothing because the member variables clean up themselves.
|
private |
Class constructor, for use only by the provider.
ps | Parameters to configure the EcalGeometry |
Definition at line 51 of file EcalGeometry.cxx.
References buildCellMap(), buildCellModuleMap(), buildLayerMap(), buildModuleMap(), buildNeighborMaps(), cellr_, cellR_, cornersSideUp_, ecalFrontZ_, gap_, framework::config::Parameters::getParameter(), layer_shift_odd_, layer_shift_odd_bilayer_, layer_shift_x_, layer_shift_y_, layerZPositions_, moduler_, moduleR_, nCellRHeight_, and verbose_.
|
private |
Constructs the flat-bottomed hexagonal grid (cellID) of corner-down hexagonal cells.
Sets ecalMap_ with the defined bins being the ecal cells in coordinates with respect to the module center. Also sets cellPostionMap_ with the keys being the cell ID and the values being the position of the cell with respect to the module center.
Use ROOT's TH2Poly::HoneyComb method to build a large hexagonal grid, then copy the polygons from it which overlap with the module with more than one vertex.
A vertex between three cells is placed at the origin, then the bottom left corner of the honeycomb and the number of x and y cells across the honeycomb is calculated by continuing to decrement the grid x/y point until the module center-to-flat distance is reached.
The hexagons that only have one vertex outside the module hexagon leave a small space un-covered by the tiling, so the vertices adjacent to the external vertex are projected onto the module edge.
[in] | cellr_ | the center-to-flat cell radius |
[in] | cellR_ | the center-to-corner cell radius |
[in] | moduler_ | the center-to-flat module radius |
[in] | moduleR_ | the center-to-flat module radius |
[out] | ecalMap_ | TH2Poly with local cell ID to local cell position mapping |
[out] | cellPostionMap_ | map of local cell ID to cell center position relative to module |
STRATEGY use ROOT HoneyComb method (build large hex grid, copy polygons that cover module)
the sneaky bit is that the center of TH2Poly::HoneyComb is the center of a cell while the center of one of our modules is the corner between three cells. This means some of the hexagons along the edges of the module will not be regular and need to stretched/squashed a bit.
REMEMBER: We are in p,q space for the cells_in_module_ map. i.e.
^ | q axis __ / \ – > p axis __/
TODO is this needed?
Definition at line 271 of file EcalGeometry.cxx.
References cell_id_in_module_, cell_pos_in_module_, cellr_, cellR_, isInside(), moduler_, moduleR_, and verbose_.
Referenced by EcalGeometry().
|
private |
Constructs the positions of all the cells in a layer relative to the ecal center.
This uses the modulePostionMap_ and cellPositionMap_ to calculate the center of all cells relative to the ecal center.
[in] | modulePositionMap_ | map of module IDs to module centers relative to ecal |
[in] | cellPositionMap_ | map of cell IDs to cell centers relative to module |
[out] |
construct map of cell centers relative to layer center
construct map of global cell centers relative to target center
Definition at line 494 of file EcalGeometry.cxx.
References cell_global_pos_, cell_pos_in_layer_, cell_pos_in_module_, cornersSideUp_, layer_pos_xy_, module_pos_xy_, and verbose_.
Referenced by EcalGeometry().
|
private |
Constructs the positions of the layers in world coordinates.
Definition at line 201 of file EcalGeometry.cxx.
References ecalFrontZ_, layer_pos_xy_, layer_shift_odd_, layer_shift_odd_bilayer_, layer_shift_x_, layer_shift_y_, layerZPositions_, and verbose_.
Referenced by EcalGeometry().
|
private |
Constructs the positions of the seven modules (moduleID) relative to the ecal center.
Sets modulePositionMap_ using the module IDs for keys and the centers of the module hexagons for values.
The module IDs are set in the ecal.gdml file and are replicated here.
[in] | gap_ | separation between module flat-sides |
[in] | moduler_ | center-to-flat module radius |
[out] | modulePositionMap_ | map of module IDs to module centers relative to ecal |
Definition at line 237 of file EcalGeometry.cxx.
References cornersSideUp_, gap_, module_pos_xy_, moduler_, and verbose_.
Referenced by EcalGeometry().
|
private |
Construts NNMap and NNNMap.
Since this only occurs once during processing, we can be wasteful. We do a nested loop over the entire cellular position map and calculate neighbors by seeing which cells are within multiples of the cellular radius of each other.
[in] | cellModulePostionMap_ | map of cells to cell centers relative to ecal |
[out] | NNMap_ | map of cell IDs to list of cell IDs that are its nearest neighbors |
[out] | NNNMap_ | map of cell IDs to list of cell IDs that are its next-to-nearest neighbors |
STRATEGY
Neighbors may include from other modules. All this is precomputed. So we can be wasteful here. Gaps may be nonzero, so we simply apply an anulus requirement (r < point <= r+dr) using total x,y positions relative to the ecal center (cell+module positions). This makes the routine portable to future cell layouts. Note that the module centers already take into account a nonzero gap. The number of neighbors is not simple because: edges, and that module edges have cutoff cells. (NN) Center within [1*cellr_, 3*cellr_] (NNN) Center within [3*cellr_, 4.5*cellr_] Chosen b/c in ideal case, centers are at 2*cell_ (NN), and at 3*cellR_=3.46*cellr_ and 4*cellr_ (NNN).
do distance calculation
Definition at line 536 of file EcalGeometry.cxx.
References cell_pos_in_layer_, cellr_, NNMap_, NNNMap_, and verbose_.
Referenced by EcalGeometry().
|
inlinestatic |
Definition at line 334 of file EcalGeometry.h.
|
private |
Distance to module edge, and whether cell is on edge of module.
@TODO Use getNN()/getNNN() + isEdgeCell() to expand functionality.
[in] | cellModuleID | EcalId where all we care about is module and cell |
Definition at line 608 of file EcalGeometry.cxx.
References cell_pos_in_module_, moduler_, and moduleR_.
Referenced by isEdgeCell().
|
inline |
Get the center-to-corner radius of the cell hexagons.
Definition at line 316 of file EcalGeometry.h.
References cellR_.
Referenced by ecal::EcalVetoProcessor::produce().
|
inline |
Get the center-to-flat radius of the cell hexagons.
Definition at line 309 of file EcalGeometry.h.
References cellr_.
|
inline |
Get a reference to the TH2Poly used for Cell IDs.
Definition at line 327 of file EcalGeometry.h.
References cell_id_in_module_, and cell_pos_in_module_.
EcalID ldmx::EcalGeometry::getID | ( | double | x, |
double | y, | ||
double | z, | ||
bool | fallible = false |
||
) | const |
Get a cell's ID number from its position.
[in] | x | global x position [mm] |
[in] | y | global y position [mm] |
[in] | z | global z position [mm] |
[in] | fallible | bool to decide if the function should fail |
Definition at line 94 of file EcalGeometry.cxx.
References getID(), and layer_pos_xy_.
Referenced by getID(), getID(), and ecal::EcalVetoProcessor::produce().
EcalID ldmx::EcalGeometry::getID | ( | double | x, |
double | y, | ||
int | layer_id, | ||
bool | fallible = false |
||
) | const |
Get a cell's ID from its x,y global position and layer number.
This is faster as long as we trust that the layer positions between GDML and the configured parameters of this class match.
[in] | x | global x position [mm] |
[in] | y | global y position [mm] |
[in] | layer_id | integer ID of the layer the hit is in |
[in] | fallible | bool to decide if the function should fail |
Definition at line 115 of file EcalGeometry.cxx.
References cornersSideUp_, getID(), isInside(), layer_pos_xy_, module_pos_xy_, and moduleR_.
EcalID ldmx::EcalGeometry::getID | ( | double | x, |
double | y, | ||
int | layer_id, | ||
int | module_id, | ||
bool | fallible = false |
||
) | const |
Get a cell's ID from its x,y global position and layer/module numbers as deduced from GDML copy numbers.
This is the fastest option but we need to carefully validated that the layer and module positions between the GDML and the configured parameters of this class match.
[in] | x | global x position [mm] |
[in] | y | global y position [mm] |
[in] | layer_id | integer ID of the layer the hit is in |
[in] | module_id | integer ID of the module the hit is in |
[in] | fallible | bool to decide if the function should fail |
Definition at line 155 of file EcalGeometry.cxx.
References cell_id_in_module_, cornersSideUp_, layer_pos_xy_, and module_pos_xy_.
|
inline |
Get the center-to-corner radius of the module hexagons.
Definition at line 302 of file EcalGeometry.h.
References moduleR_.
|
inline |
Get the center-to-flat radius of the module hexagons.
Definition at line 295 of file EcalGeometry.h.
References moduler_.
Get the Nearest Neighbors of the input ID.
id | id to get |
Definition at line 241 of file EcalGeometry.h.
References NNMap_.
Referenced by isNN().
Get the Next-to-Nearest Neighbors of the input ID.
id | id to get |
Definition at line 268 of file EcalGeometry.h.
References NNNMap_.
Referenced by isNNN().
|
inline |
Get the number of cells in each module of the Ecal Geometry.
Definition at line 231 of file EcalGeometry.h.
References cell_id_in_module_.
|
inline |
Get the number of layers in the Ecal Geometry.
Definition at line 209 of file EcalGeometry.h.
References layer_pos_xy_.
|
inline |
Get the number of modules in the Ecal flower.
Definition at line 223 of file EcalGeometry.h.
std::tuple< double, double, double > ldmx::EcalGeometry::getPosition | ( | EcalID | id | ) | const |
Get a cell's position from its ID number.
std::tuple is useful here because you can use C++17's pattern matching to use code like the following
Definition at line 188 of file EcalGeometry.cxx.
References cell_global_pos_.
Referenced by ecal::EcalTriggerGeometry::globalPosition(), ecal::DNNEcalVetoProcessor::make_inputs(), and ecal::EcalVetoProcessor::produce().
std::pair< double, double > ldmx::EcalGeometry::getPositionInModule | ( | int | cell_id | ) | const |
Get a cell's position within a module.
Definition at line 192 of file EcalGeometry.cxx.
References cell_pos_in_module_, and cornersSideUp_.
Referenced by ecal::EcalTriggerGeometry::localPosition().
|
inline |
Get the z-coordinate given the layer id.
[in] | layer | int layer id |
Definition at line 200 of file EcalGeometry.h.
References layer_pos_xy_.
Referenced by ecal::EcalVetoProcessor::produce().
|
inlineprivate |
Check if input cell is on the edge of a module.
[in] | cellModuleID | EcalId where all we care about is module and cell return true if distance to edge is less than max cell radius |
Definition at line 458 of file EcalGeometry.h.
References cellR_, and distanceToEdge().
|
private |
Determines if point (x,y), already normed to max hexagon radius, lies within a hexagon.
Corners are (1,0) and (0.5,sqrt(3)/2). Uses "<", not "<=".
[in] | normX | X-coordinate relative to module hexagon divided by maximum hexagon radius |
[in] | normY | Y-coordinate relative to module hexagon divided by maximum hexagon radius |
Definition at line 622 of file EcalGeometry.cxx.
References verbose_.
Referenced by buildCellMap(), and getID().
Check if the probe id is one of the nearest neightbors of the centroid id.
probe | id to check if it is nearest neighbor |
centroid | id that is center of neighbors |
Definition at line 255 of file EcalGeometry.h.
References getNN().
Check if the probe id is one of the next-to-nearest neightbors of the centroid id.
probe | id to check if it is a next-to-nearest neighbor |
centroid | id that is center of neighbors |
Definition at line 283 of file EcalGeometry.h.
References getNNN().
|
friend |
Definition at line 345 of file EcalGeometry.h.
|
private |
Position of cell centers relative to world geometry.
This is where we convert p,q (flower) space into x,y (world) space by calculating the z-location as well as including rotations and shifts when converting from p,q to x,y.
The key is the full EcalID and the value is the x,y,z tuple.
Definition at line 596 of file EcalGeometry.h.
Referenced by buildCellModuleMap(), and getPosition().
|
mutableprivate |
Honeycomb Binning from ROOT.
Needs to be mutable because ROOT doesn't have good const handling
Lookup a cell ID using its position relative to the center of the module in p,q space.
Definition at line 620 of file EcalGeometry.h.
Referenced by buildCellMap(), getCellPolyMap(), getID(), and getNumCellsPerModule().
|
private |
Position of cell centers relative to center of layer in world coordinates.
Uses EcalID with layer set to zero as key.
Definition at line 585 of file EcalGeometry.h.
Referenced by buildCellModuleMap(), and buildNeighborMaps().
|
private |
Position of cell centers relative to center of module in p,q space.
use cell ID as key
Definition at line 574 of file EcalGeometry.h.
Referenced by buildCellMap(), buildCellModuleMap(), distanceToEdge(), getCellPolyMap(), and getPositionInModule().
|
private |
Center-to-Flat Radius of cell hexagon [mm].
Definition at line 484 of file EcalGeometry.h.
Referenced by buildCellMap(), buildNeighborMaps(), EcalGeometry(), and getCellMinR().
|
private |
Center-to-Corner Radius of cell hexagon [mm].
Definition at line 490 of file EcalGeometry.h.
Referenced by buildCellMap(), EcalGeometry(), getCellMaxR(), and isEdgeCell().
|
staticconstexpr |
Definition at line 103 of file EcalGeometry.h.
|
private |
indicator of geometry orientation if true, flower shape's corners side (ie: side with two modules) is at the top
Definition at line 500 of file EcalGeometry.h.
Referenced by buildCellModuleMap(), buildModuleMap(), EcalGeometry(), getID(), getID(), and getPositionInModule().
|
private |
Front of ECal relative to world geometry [mm].
Definition at line 545 of file EcalGeometry.h.
Referenced by buildLayerMap(), and EcalGeometry().
|
private |
Gap between module flat sides [mm].
Definition at line 481 of file EcalGeometry.h.
Referenced by buildModuleMap(), and EcalGeometry().
|
private |
Position of layer centers in world coordinates (uses layer ID as key)
Definition at line 558 of file EcalGeometry.h.
Referenced by buildCellModuleMap(), buildLayerMap(), getID(), getID(), getID(), getNumLayers(), and getZPosition().
|
private |
shift odd layers
odd layers are the high-z layer in each bi-layer
i.e. We will shift if layer_id_ % 2 == 1
Definition at line 519 of file EcalGeometry.h.
Referenced by buildLayerMap(), and EcalGeometry().
|
private |
shift odd bi layers
NOT IMPLEMENTED IN GDML
This shifts the bi-layer grouping of two sensitive layers together.
i.e. We will shift if (layer_id_ / 2) % 2 == 1
where it is integer division.
Definition at line 533 of file EcalGeometry.h.
Referenced by buildLayerMap(), and EcalGeometry().
|
private |
shift of layers in the x-direction [mm]
Definition at line 505 of file EcalGeometry.h.
Referenced by buildLayerMap(), and EcalGeometry().
|
private |
shift of layers in the y-direction [mm]
Definition at line 510 of file EcalGeometry.h.
Referenced by buildLayerMap(), and EcalGeometry().
|
private |
The layer Z postions are with respect to the front of the ECal [mm].
Definition at line 548 of file EcalGeometry.h.
Referenced by buildLayerMap(), and EcalGeometry().
|
private |
Postion of module centers relative to the center of the layer in world coordinates.
(uses module ID as key)
Definition at line 566 of file EcalGeometry.h.
Referenced by buildCellModuleMap(), buildModuleMap(), getID(), and getID().
|
private |
Center-to-Flat Radius of module hexagon [mm].
Definition at line 487 of file EcalGeometry.h.
Referenced by buildCellMap(), buildModuleMap(), distanceToEdge(), EcalGeometry(), and getModuleMinR().
|
private |
Center-to-Corner Radius of module hexagon [mm].
Definition at line 493 of file EcalGeometry.h.
Referenced by buildCellMap(), distanceToEdge(), EcalGeometry(), getID(), and getModuleMaxR().
|
private |
Number of cell center-to-corner radii (one side of the cell) from the bottom to the top of the module.
Could be fractional depending on how many fractions of a radii are spanning between the center of the top/bottom cell row and the edge of the module
Definition at line 542 of file EcalGeometry.h.
Referenced by EcalGeometry().
Map of cell ID to neighboring cells.
The EcalID's in this map all have layer ID set to zero.
Definition at line 603 of file EcalGeometry.h.
Referenced by buildNeighborMaps(), and getNN().
Map of cell ID to neighbors of neighbor cells.
The EcalID's in this map all have layer ID set to zero.
Definition at line 610 of file EcalGeometry.h.
Referenced by buildNeighborMaps(), and getNNN().
|
private |
verbosity
Definition at line 552 of file EcalGeometry.h.
Referenced by buildCellMap(), buildCellModuleMap(), buildLayerMap(), buildModuleMap(), buildNeighborMaps(), EcalGeometry(), and isInside().