Skip to content

Commit

Permalink
Introduce fallible to getID functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tvami committed Sep 4, 2024
1 parent 62b1a63 commit 18db944
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 114 deletions.
61 changes: 32 additions & 29 deletions DetDescr/include/DetDescr/EcalGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,17 @@ class EcalGeometry : public framework::ConditionsObject {
* @param[in] x global x position [mm]
* @param[in] y global y position [mm]
* @param[in] z global z position [mm]
* @return EcalID of the cell
* @param[in] fallible bool to decide if the function should fail
* @return EcalID of the cell (null-id if fallible)
* Example for fallible use case
* ```cpp
* auto id = geometry.getID(x, y, z, true);
* if (id.null()) {
* // position (x,y) is not contained within a cell in layer at z
* }
* ```
*/
EcalID getID(double x, double y, double z) const;
EcalID getID(double x, double y, double z, bool fallible = false) const;

/**
* Get a cell's ID from its x,y global position and layer number
Expand All @@ -129,9 +137,17 @@ class EcalGeometry : public framework::ConditionsObject {
* @param[in] x global x position [mm]
* @param[in] y global y position [mm]
* @param[in] layer_id integer ID of the layer the hit is in
* @return EcalID of the cell
* @param[in] fallible bool to decide if the function should fail
* @return EcalID of the cell (null-id if fallible)
* Example for fallible use case
* ```cpp
* auto id = geometry.getID(x, y, ilayer, true);
* if (id.null()) {
* // position (x,y) is not contained within a cell in layer ilayer
* }
* ```
*/
EcalID getID(double x, double y, int layer_id) const;
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/module numbers
Expand All @@ -145,9 +161,19 @@ class EcalGeometry : public framework::ConditionsObject {
* @param[in] y global y position [mm]
* @param[in] layer_id integer ID of the layer the hit is in
* @param[in] module_id integer ID of the module the hit is in
* @return EcalID of the cell
* @param[in] fallible bool to decide if the function should fail
* @return EcalID of the cell (null-id if fallible)
* Example for fallible use case
* ```cpp
* auto id = geometry.getID(x, y, ilayer, imodule, true);
* if (id.null()) {
* // position (x,y) is not contained within a cell in layer ilayer in
* module imodule
* }
* ```
*/
EcalID getID(double x, double y, int layer_id, int module_id) const;
EcalID getID(double x, double y, int layer_id, int module_id,
bool fallible = false) const;

/**
* Get a cell's position from its ID number
Expand Down Expand Up @@ -309,29 +335,6 @@ class EcalGeometry : public framework::ConditionsObject {
return new EcalGeometry(p);
}

/**
* Is the hit based on its x,y global position and layer numbers
* fiducial in the module?
*
* @param[in] x global x position [mm]
* @param[in] y global y position [mm]
* @param[in] layer_id integer ID of the layer the hit is in
* @return bool if fiducial
*/
bool isFiducialInModule(double x, double y, int layer_id) const;

/**
* Is the hit based on its x,y global position and layer/module numbers
* fiducial in the cell?
*
* @param[in] x global x position [mm]
* @param[in] y global y position [mm]
* @param[in] layer_id integer ID of the layer the hit is in
* @param[in] module_id integer ID of the module the hit is in
* @return bool if fiducial
*/
bool isFiducialInCell(double x, double y, int layer_id, int module_id) const;

private:
/**
* Class constructor, for use only by the provider
Expand Down
111 changes: 37 additions & 74 deletions DetDescr/src/DetDescr/EcalGeometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ EcalGeometry::EcalGeometry(const framework::config::Parameters& ps)
std::cout << "[EcalGeometry] : fully constructed" << std::endl;
}

EcalID EcalGeometry::getID(double x, double y, double z) const {
EcalID EcalGeometry::getID(double x, double y, double z, bool fallible) const {
static const double tolerance = 0.3; // thickness of Si
int layer_id{-1};
for (const auto& [lid, layer_xyz] : layer_pos_xy_) {
Expand All @@ -100,14 +100,19 @@ EcalID EcalGeometry::getID(double x, double y, double z) const {
}
}
if (layer_id < 0) {
EXCEPTION_RAISE("BadConf", "z = " + std::to_string(z) +
" mm is not within any"
" of the configured layers.");
if (fallible) {
return ldmx::EcalID(0);
} else {
EXCEPTION_RAISE("BadConf", "z = " + std::to_string(z) +
" mm is not within any"
" of the configured layers.");
}
}
return getID(x, y, layer_id);
return getID(x, y, layer_id, fallible);
}

EcalID EcalGeometry::getID(double x, double y, int layer_id) const {
EcalID EcalGeometry::getID(double x, double y, int layer_id,
bool fallible) const {
// now assume we know the layer
// shift to center of layer
// and convert to flower coordinates
Expand All @@ -129,21 +134,25 @@ EcalID EcalGeometry::getID(double x, double y, int layer_id) const {
}

if (module_id < 0) {
EXCEPTION_RAISE(
"BadConf",
TString::Format(
"Coordinates relative to layer (p,q) = (%.2f, %.2f) mm "
"derived from world coordinates (%.2f, %.2f) mm with layer = %d "
"are not inside any module.",
p, q, x, y, layer_id)
.Data());
if (fallible) {
return ldmx::EcalID(0);
} else {
EXCEPTION_RAISE(
"BadConf",
TString::Format(
"Coordinates relative to layer (p,q) = (%.2f, %.2f) mm "
"derived from world coordinates (%.2f, %.2f) mm with layer = %d "
"are not inside any module.",
p, q, x, y, layer_id)
.Data());
}
}

return getID(x, y, layer_id, module_id);
}

EcalID EcalGeometry::getID(double x, double y, int layer_id,
int module_id) const {
EcalID EcalGeometry::getID(double x, double y, int layer_id, int module_id,
bool fallible) const {
// now assume we know the layer and module
// shift to center of layer and then center of module
double p{x - std::get<0>(layer_pos_xy_.at(layer_id)) -
Expand All @@ -158,14 +167,18 @@ EcalID EcalGeometry::getID(double x, double y, int layer_id,
int cell_id = cell_id_in_module_.FindBin(p, q) - 1;

if (cell_id < 0) {
EXCEPTION_RAISE(
"BadConf",
TString::Format(
"Relative cell coordinates (%.2f, %.2f) mm "
"derived from world coordinates (%.2f, %.2f) mm with layer = %d "
"and module = %d are outside module hexagon",
p, q, x, y, layer_id, module_id)
.Data());
if (fallible) {
return ldmx::EcalID(0);
} else {
EXCEPTION_RAISE(
"BadConf",
TString::Format(
"Relative cell coordinates (%.2f, %.2f) mm "
"derived from world coordinates (%.2f, %.2f) mm with layer = %d "
"and module = %d are outside module hexagon",
p, q, x, y, layer_id, module_id)
.Data());
}
}

return EcalID(layer_id, module_id, cell_id);
Expand Down Expand Up @@ -629,54 +642,4 @@ bool EcalGeometry::isInside(double normX, double normY) const {
return (dotProd > 0.);
}

bool EcalGeometry::isFiducialInModule(double x, double y, int layer_id) const {
// now assume we know the layer
// shift to center of layer
// and convert to flower coordinates
double p{x - std::get<0>(layer_pos_xy_.at(layer_id))},
q{y - std::get<1>(layer_pos_xy_.at(layer_id))};

// deduce module ID
// there are only 7 modules so we just loop through them
// all and pick out the module ID that we are inside of

int module_id{-1};
for (auto const& [mid, module_xy] : module_pos_xy_) {
double probe_x{p - module_xy.first}, probe_y{q - module_xy.second};
if (cornersSideUp_) rotate(probe_x, probe_y);
if (isInside(probe_x / moduleR_, probe_y / moduleR_)) {
module_id = mid;
break;
}
}

if (module_id < 0) {
return false;
} else {
return true;
}
}

bool EcalGeometry::isFiducialInCell(double x, double y, int layer_id,
int module_id) const {
// now assume we know the layer and module
// shift to center of layer and then center of module
double p{x - std::get<0>(layer_pos_xy_.at(layer_id)) -
module_pos_xy_.at(module_id).first},
q{y - std::get<1>(layer_pos_xy_.at(layer_id)) -
module_pos_xy_.at(module_id).second};

// need to rotate
if (cornersSideUp_) rotate(p, q);

// deduce cell ID
int cell_id = cell_id_in_module_.FindBin(p, q) - 1;

if (cell_id < 0) {
return false;
} else {
return true;
}
}

} // namespace ldmx
21 changes: 10 additions & 11 deletions Ecal/src/Ecal/EcalVetoProcessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,20 @@ void EcalVetoProcessor::produce(framework::Event &event) {
// Check if it's fiducial
bool inside{false};
// At module level
const auto isFiducialInModule = geometry_->isFiducialInModule(
drifted_recoil_x, drifted_recoil_y, recoil_layer_index);
if (isFiducialInModule) {
const auto ecalID = geometry_->getID(drifted_recoil_x, drifted_recoil_y,
recoil_layer_index);
const auto ecalID = geometry_->getID(drifted_recoil_x, drifted_recoil_y,
recoil_layer_index, true);
if (!ecalID.null()) {
// If fiducial at module level, check at cell level
std::cout << " ecalID " << ecalID << std::endl;
inside =
geometry_->isFiducialInCell(drifted_recoil_x, drifted_recoil_y,
recoil_layer_index, ecalID.getModuleID());
const auto cellID =
geometry_->getID(drifted_recoil_x, drifted_recoil_y, recoil_layer_index,
ecalID.getModuleID(), true);
if (!cellID.null()) {
inside = true;
}
}

if (!inside) {
ldmx_log(debug) << "This event is non-fiducial in ECAL";
ldmx_log(info) << "This event is non-fiducial in ECAL";
}

// ------------------------------------------------------
Expand Down Expand Up @@ -799,7 +799,6 @@ void EcalVetoProcessor::produce(framework::Event &event) {
// in v14 minR is 4.17 mm
// while maxR is 4.81 mm
float cellWidth = 2 * geometry_->getCellMaxR();
std::cout << " cellWidth " << cellWidth << std::endl;
for (int iHit = 0; iHit < trackingHitList.size(); iHit++) {
// list of hit numbers in track (34 = maximum theoretical length)
int track[34];
Expand Down

0 comments on commit 18db944

Please sign in to comment.