From 17397200030076b587f3903a0b4f96411864fa7e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 16 Sep 2025 16:05:46 +0000 Subject: [PATCH 01/95] Started implementing code in C++ --- RecoTracker/LSTCore/BuildFile.xml | 1 + .../LSTCore/interface/LSTGeometry/Common.h | 15 + .../interface/LSTGeometry/CornerFunctions.h | 105 ++++ .../interface/LSTGeometry/ModuleDetIdParser.h | 472 ++++++++++++++++++ .../interface/LSTGeometry/ModuleInfo.h | 37 ++ .../interface/LSTGeometry/SensorInfo.h | 20 + RecoTracker/LSTCore/src/LSTGeometry.cc | 4 + 7 files changed, 654 insertions(+) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/Common.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h create mode 100644 RecoTracker/LSTCore/src/LSTGeometry.cc diff --git a/RecoTracker/LSTCore/BuildFile.xml b/RecoTracker/LSTCore/BuildFile.xml index e9cbb2cccf046..dbfe1a9fcda87 100644 --- a/RecoTracker/LSTCore/BuildFile.xml +++ b/RecoTracker/LSTCore/BuildFile.xml @@ -5,6 +5,7 @@ + diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h new file mode 100644 index 0000000000000..925eb12ed5f65 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -0,0 +1,15 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Common_h +#define RecoTracker_LSTCore_interface_LSTGeometry_Common_h + +#include + +namespace lst { + + using MatrixD3x3 = Eigen::Matrix; + using MatrixD8x3 = Eigen::Matrix; + using ColVectorD3 = Eigen::Matrix; + using RowVectorD3 = Eigen::Matrix; + +} // namespace lst + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h new file mode 100644 index 0000000000000..8b4663111457d --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h @@ -0,0 +1,105 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_h +#define RecoTracker_LSTCore_interface_LSTGeometry_h + +#include +#include + +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" + +namespace lst { + + double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } + + MatrixD3x3 rodriguesRotationMatrix(Eigen::Matrix axis, double theta) { + axis.normalize(); + + MatrixD3x3 k{{0, -axis(2), axis(1)}, {axis(2), 0, -axis(0)}, {-axis(1), axis(0), 0}}; + + MatrixD3x3 rotationMatrix = MatrixD3x3::Identity() + sin(theta) * k + (1 - cos(theta)) * (k * k); + + return rotationMatrix; + } + + MatrixD3x3 tangentialRotationMatrix(double phi, double theta) { + ColVectorD3 axis; + axis << -sin(phi), cos(phi), 0; + + return rodriguesRotationMatrix(axis, theta); + } + + MatrixD3x3 rotationMatrix(double tilt_deg, double skew_deg, double yaw_deg, double phi_deg) { + if (skew_deg != 0 || yaw_deg != 0) + throw std::invalid_argument("Skew and yaw angles are not currently supported."); + double tilt_rad = degToRad(tilt_deg); + double phi_rad = degToRad(phi_deg); + + // Rotation around Z-axis that makes the sensor "face towards" the beamline (i.e. towards z-axis) + // So for example if phi=0 then R is the identity (i.e. already facing), or if phi=90deg + // then R becomes (x,y,z)->(-y,x,z) so the sensor is rotated 90 degrees to face the beamline + MatrixD3x3 initialR{{cos(phi_rad), -sin(phi_rad), 0}, {sin(phi_rad), cos(phi_rad), 0}, {0, 0, 1}}; + + // The tilt angle given in the CSV files is with respect to a module that is facing + // the beamline, meaning after R_initial is applied. From there we tilt the module according + // to the rotation below. Note that because this tilt angle is not with respect to the X,Y,Z + // axes and is instead around an arbitrary axis (defined from the rotation above) we have to apply + // the Rodrigues' rotation formula + MatrixD3x3 rTilt = tangentialRotationMatrix(phi_rad, -tilt_rad); + + MatrixD3x3 finalR = rTilt * initialR; + + return finalR; + } + + void transformSensorCorners(ModuleInfo &moduleInfo) { + auto module_z = moduleInfo.sensorCenterZ_mm; + auto module_rho = moduleInfo.sensorCenterRho_mm; + auto module_phi = moduleInfo.phi_deg; + auto sensor_spacing = moduleInfo.sensorSpacing_mm; + auto sensor_width = moduleInfo.meanWidth_mm; + auto sensor_length = moduleInfo.length_mm; + + auto phi_rad = degToRad(module_phi); + auto module_x = module_rho * cos(phi_rad); + auto module_y = module_rho * sin(phi_rad); + + auto half_width = sensor_width / 2; + auto half_length = sensor_length / 2; + auto half_spacing = sensor_spacing / 2; + + // Make the module sizes consistent with hit-based method. + // FIXME: Using the real (smaller) sizes specified by CSV file increases + // fake rate significantly and lowers efficiency between abs(eta) 1 to 2. + auto width_extension = 50.0 - half_width; + auto length_extension = (half_length > 40 ? 50.0 : 25.0) - half_length; + + half_width += width_extension; + half_length += length_extension; + + MatrixD8x3 corners{{-half_spacing, -half_width, -half_length}, + {-half_spacing, -half_width, half_length}, + {-half_spacing, half_width, half_length}, + {-half_spacing, half_width, -half_length}, + {half_spacing, -half_width, -half_length}, + {half_spacing, -half_width, half_length}, + {half_spacing, half_width, half_length}, + {half_spacing, half_width, -half_length}}; + + MatrixD3x3 rotation_matrix = + rotationMatrix(moduleInfo.tiltAngle_deg, moduleInfo.skewAngle_deg, moduleInfo.yawAngle_deg, moduleInfo.phi_deg); + MatrixD8x3 rotated_corners = (rotation_matrix * corners.transpose()).transpose(); + + rotated_corners.rowwise() += RowVectorD3{module_x, module_y, module_z}; + + rotated_corners /= 10; + + // Coordinate reorder before saving (x,y,z)->(z,x,y) + moduleInfo.transformedCorners.col(0) = rotated_corners.col(2); + moduleInfo.transformedCorners.col(1) = rotated_corners.col(0); + moduleInfo.transformedCorners.col(2) = rotated_corners.col(1); + } + +} // namespace lst + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h new file mode 100644 index 0000000000000..762f825c66df7 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h @@ -0,0 +1,472 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleDetIdParser_h +#define RecoTracker_LSTCore_interface_LSTGeometry_ModuleDetIdParser_h + +#include +#include + +namespace lst { + + class Module { + private: + // Decoding DetId + // + // detId comes in 29 bits. There are two formats depending on which sub detector it is. + // + // 29 bits total + // + // left to right index (useful python, i.e. string[idx:jdx]) + // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 + // + // right to left index (useful when C++ style, i.e. bit shifting) + // 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 + // + // x x x x x x x x x x x x x x x x x x x x x x x x x x x x x + // + // -subdet- -layer-- -side --------rod--------- -------module------- # if subdet == 5 + // -subdet- -side --layer- ----ring--- -------module------- # if subdet == 4 + // + // + + //---------- + // * detId * + //---------- + // The unique detector ID for this module layer + unsigned int detId_; + + // The unique detector ID to its partner + unsigned int partnerDetId_; + + //----------- + // * subdet * + //----------- + // bits 27 to 25 + // subdet = (detId & (7 << 25)) >> 25; + // subdet can take either 4 or 5 + // 4: endcap + // 5: barrel + public: + enum SubDet { Barrel = 5, Endcap = 4 }; + + private: + unsigned short subdet_; + + //--------- + // * Side * + //--------- + // bits 24 to 23 + // if (subdet_ == 4) + // { + // side_ = (detId_ & (3 << 23)) >> 23; + // } + // else if (subdet_ == 5) + // { + // side_ = (detId_ & (3 << 18)) >> 18; + // } + // 1 = -z side of the endcap modules AND -z side of tilted modules + // 2 = +z side of the endcap modules AND +z side of tilted modules + // 3 = barrel modules (determined via checking subdet) + public: + enum Side { NegZ = 1, PosZ = 2, Center = 3 }; + + private: + unsigned short side_; + + //---------- + // * Layer * + //---------- + // either bits 22 to 20 or 20 to 18 + // if (subdet_ == 4) + // { + // layer_ = (detId_ & (7 << 18)) >> 18; + // } + // else if (subdet_ == 5) + // { + // layer_ = (detId_ & (7 << 20)) >> 20; + // } + // depending on whether it is subdet = 4 or 5, the position of layer information is different + // layer = detId_bits[06:08] if subdet = 5 + // layer = detId_bits[08:10] if subdet = 4 + unsigned short layer_; + + //-------- + // * Rod * + //-------- + // bits 16 to 10 only when subdet = 5 + // if (subdet_ == 5) + // { + // rod_ = (detId_ & (127 << 10)) >> 10; + // } + // else if (subdet_ == 4) + // { + // rod_ = 0; + // } + // Index of which rod in the barrel + // Closest to the positive x-axis line is rod = 1, and it goes counter-clockwise in x-y plane projection + // total number of rods for each layer: 18, 26, 36, 48, 60, and 78 + unsigned short rod_; + + //--------- + // * Ring * + //--------- + // bits 15 to 12 only when subdet = 4 + // if (subdet_ == 5) + // { + // ring_ = 0; + // } + // else if (subdet_ == 4) + // { + // ring_ = (detId_ & (15 << 12)) >> 12; + // } + // Index of which ring in the endcap + // For the layer 1 and 2, there are 15 rings, first 10 are PS, the latter 5 are 2S + // For the layer 3, 4, and 5, there are 12 rings, first 7 are PS, the latter 5 are 2S + unsigned short ring_; + + //----------- + // * Module * + //----------- + // bits 8 to 2 + // module_ = (detId_ & (127 << 2)) >> 2; + // For subdet==4 the # of module depends on how far away from beam spot, + // module 1 is closest to the positive x-axis line and it goes counter-clockwise in x-y plane projection + // layer 1 or 2, ring 1: 20 modules + // layer 1 or 2, ring 2: 24 modules + // layer 1 or 2, ring 3: 24 modules + // layer 1 or 2, ring 4: 28 modules + // layer 1 or 2, ring 5: 32 modules + // layer 1 or 2, ring 6: 32 modules + // layer 1 or 2, ring 7: 36 modules + // layer 1 or 2, ring 8: 40 modules + // layer 1 or 2, ring 9: 40 modules + // layer 1 or 2, ring 10: 44 modules + // layer 1 or 2, ring 11: 52 modules + // layer 1 or 2, ring 12: 60 modules + // layer 1 or 2, ring 13: 64 modules + // layer 1 or 2, ring 14: 72 modules + // layer 1 or 2, ring 15: 76 modules + // layer 3, 4, or 5, ring 1: 28 modules + // layer 3, 4, or 5, ring 2: 28 modules + // layer 3, 4, or 5, ring 3: 32 modules + // layer 3, 4, or 5, ring 4: 36 modules + // layer 3, 4, or 5, ring 5: 36 modules + // layer 3, 4, or 5, ring 6: 40 modules + // layer 3, 4, or 5, ring 7: 44 modules + // layer 3, 4, or 5, ring 8: 52 modules + // layer 3, 4, or 5, ring 9: 56 modules + // layer 3, 4, or 5, ring 10: 64 modules + // layer 3, 4, or 5, ring 11: 72 modules + // layer 3, 4, or 5, ring 12: 76 modules + // + // For subdet==5, the # of module depends on how far away from beam spot, + // for side==3: module 1 has lowest z (starting from the negative value) + // layer 1, side 3: 7 modules + // layer 2, side 3: 11 modules + // layer 3, side 3: 15 modules + // layer 4, 5, or 6, side 3: 24 modules + // for side==1,2 (i.e. tilted): module 1 is along x-axis + // layer 1, side 1, or 2: 18 modules + // layer 2, side 1, or 2: 26 modules + // layer 3, side 1, or 2: 36 modules + unsigned short module_; + + //------------ + // * isLower * + //------------ + // bit 28 + // isLower_ = (detId_ & 1); + // isLower is always the pixel if it's a PS module, if it's a 2S module it's whichever is the protruding side when 2S are staggered + unsigned short isLower_; + + // The modules are put in alternating order where the modules are inverted every other one + bool isInverted_; + + // To hold information whether it is a 2S or PS + public: + enum ModuleType { PS, TwoS }; + + private: + ModuleType moduleType_; + + // To hold information whether it is a Pixel or Strip + // Pixel + // Strip + public: + enum ModuleLayerType { Pixel, Strip }; + + private: + ModuleLayerType moduleLayerType_; + + void setDerivedQuantities(); + void setDerivedQuantities(unsigned int moduleTypeInfo); + void setDerivedQuantities(ModuleType moduleType, ModuleLayerType moduleLayerType); + + public: + // constructor/destructor + Module(); + Module(unsigned int detId); + Module(unsigned int detId, unsigned int moduleTypeInfo); + Module(unsigned int detId, ModuleType moduleType, ModuleLayerType moduleLayerType); + Module(const Module&); + ~Module(); + + // accessor functions + const unsigned int& detId() const; + const unsigned int& partnerDetId() const; + const unsigned short& subdet() const; + const unsigned short& side() const; + const unsigned short& layer() const; + const unsigned short& rod() const; + const unsigned short& ring() const; + const unsigned short& module() const; + const unsigned short& isLower() const; + const bool& isInverted() const; + const ModuleType& moduleType() const; + const ModuleLayerType& moduleLayerType() const; + + // modifying the class content + void setDetId(unsigned int); + void setDetId(unsigned int, unsigned int); + void setDetId(unsigned int, ModuleType, ModuleLayerType); + + // static functions to parse detId + static unsigned short parseSubdet(unsigned int); + static unsigned short parseSide(unsigned int); + static unsigned short parseLayer(unsigned int); + static unsigned short parseRod(unsigned int); + static unsigned short parseRing(unsigned int); + static unsigned short parseModule(unsigned int); + static unsigned short parseIsLower(unsigned int); + static bool parseIsInverted(unsigned int); + static unsigned int parsePartnerDetId(unsigned int); + static ModuleType parseModuleType(unsigned int); + static ModuleLayerType parseModuleLayerType(unsigned int); + }; + +} // namespace lst + +lst::Module::Module() { setDetId(0); } + +lst::Module::Module(unsigned int detId) { setDetId(detId); } + +lst::Module::Module(unsigned int detId, unsigned int moduleTypeInfo) { setDetId(detId, moduleTypeInfo); } + +lst::Module::Module(const Module& module) { setDetId(module.detId(), module.moduleType(), module.moduleLayerType()); } + +lst::Module::~Module() {} + +const unsigned short& lst::Module::subdet() const { return subdet_; } + +const unsigned short& lst::Module::side() const { return side_; } + +const unsigned short& lst::Module::layer() const { return layer_; } + +const unsigned short& lst::Module::rod() const { return rod_; } + +const unsigned short& lst::Module::ring() const { return ring_; } + +const unsigned short& lst::Module::module() const { return module_; } + +const unsigned short& lst::Module::isLower() const { return isLower_; } + +const unsigned int& lst::Module::detId() const { return detId_; } + +const unsigned int& lst::Module::partnerDetId() const { return partnerDetId_; } + +const bool& lst::Module::isInverted() const { return isInverted_; } + +const lst::Module::ModuleType& lst::Module::moduleType() const { return moduleType_; } + +const lst::Module::ModuleLayerType& lst::Module::moduleLayerType() const { return moduleLayerType_; } + +void lst::Module::setDetId(unsigned int detId) { + detId_ = detId; + setDerivedQuantities(); +} + +void lst::Module::setDetId(unsigned int detId, unsigned int moduleTypeInfo) { + detId_ = detId; + setDerivedQuantities(moduleTypeInfo); +} + +void lst::Module::setDetId(unsigned int detId, ModuleType moduleType, ModuleLayerType moduleLayerType) { + detId_ = detId; + setDerivedQuantities(moduleType, moduleLayerType); +} + +void lst::Module::setDerivedQuantities() { + subdet_ = parseSubdet(detId_); + side_ = parseSide(detId_); + layer_ = parseLayer(detId_); + rod_ = parseRod(detId_); + ring_ = parseRing(detId_); + module_ = parseModule(detId_); + isLower_ = parseIsLower(detId_); + isInverted_ = parseIsInverted(detId_); + partnerDetId_ = parsePartnerDetId(detId_); + moduleType_ = parseModuleType(detId_); + moduleLayerType_ = parseModuleLayerType(detId_); +} + +void lst::Module::setDerivedQuantities(unsigned int moduleTypeInfo) { + subdet_ = parseSubdet(detId_); + side_ = parseSide(detId_); + layer_ = parseLayer(detId_); + rod_ = parseRod(detId_); + ring_ = parseRing(detId_); + module_ = parseModule(detId_); + isLower_ = parseIsLower(detId_); + isInverted_ = parseIsInverted(detId_); + partnerDetId_ = parsePartnerDetId(detId_); + moduleType_ = (moduleTypeInfo == 25 ? lst::Module::TwoS : lst::Module::PS); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS + moduleLayerType_ = + (moduleTypeInfo == 23 ? lst::Module::Pixel : lst::Module::Strip); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS +} + +void lst::Module::setDerivedQuantities(ModuleType moduleType, ModuleLayerType moduleLayerType) { + subdet_ = parseSubdet(detId_); + side_ = parseSide(detId_); + layer_ = parseLayer(detId_); + rod_ = parseRod(detId_); + ring_ = parseRing(detId_); + module_ = parseModule(detId_); + isLower_ = parseIsLower(detId_); + isInverted_ = parseIsInverted(detId_); + partnerDetId_ = parsePartnerDetId(detId_); + moduleType_ = moduleType; + moduleLayerType_ = moduleLayerType; +} + +unsigned short lst::Module::parseSubdet(unsigned int detId) { return (detId & (7 << 25)) >> 25; } + +unsigned short lst::Module::parseSide(unsigned int detId) { + if (parseSubdet(detId) == lst::Module::Endcap) { + return (detId & (3 << 23)) >> 23; + } else if (parseSubdet(detId) == lst::Module::Barrel) { + return (detId & (3 << 18)) >> 18; + } else { + return 0; + } +} + +unsigned short lst::Module::parseLayer(unsigned int detId) { + if (parseSubdet(detId) == lst::Module::Endcap) { + return (detId & (7 << 18)) >> 18; + } else if (parseSubdet(detId) == lst::Module::Barrel) { + return (detId & (7 << 20)) >> 20; + } else { + return 0; + } +} + +unsigned short lst::Module::parseRod(unsigned int detId) { + if (parseSubdet(detId) == lst::Module::Endcap) { + return 0; + } else if (parseSubdet(detId) == lst::Module::Barrel) { + return (detId & (127 << 10)) >> 10; + } else { + return 0; + } +} + +unsigned short lst::Module::parseRing(unsigned int detId) { + if (parseSubdet(detId) == lst::Module::Endcap) { + return (detId & (15 << 12)) >> 12; + } else if (parseSubdet(detId) == lst::Module::Barrel) { + return 0; + } else { + return 0; + } +} + +unsigned short lst::Module::parseModule(unsigned int detId) { return (detId & (127 << 2)) >> 2; } + +unsigned short lst::Module::parseIsLower(unsigned int detId) { + return ((parseIsInverted(detId)) ? !(detId & 1) : (detId & 1)); +} + +bool lst::Module::parseIsInverted(unsigned int detId) { + if (detId == 1) // "1" detId means "pixel module" where we store all pixel hits/mini/segments into one bucket + return 0; + if (parseSubdet(detId) == lst::Module::Endcap) { + if (parseSide(detId) == lst::Module::NegZ) { + return parseModule(detId) % 2 == 1; + } else if (parseSide(detId) == lst::Module::PosZ) { + return parseModule(detId) % 2 == 0; + } else { + std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; + return 0; + } + } else if (parseSubdet(detId) == lst::Module::Barrel) { + if (parseSide(detId) == lst::Module::Center) { + if (parseLayer(detId) <= 3) { + return parseModule(detId) % 2 == 1; + } else if (parseLayer(detId) >= 4) { + return parseModule(detId) % 2 == 0; + } else { + std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; + return 0; + } + } else if (parseSide(detId) == lst::Module::NegZ or parseSide(detId) == lst::Module::PosZ) { + if (parseLayer(detId) <= 2) { + return parseModule(detId) % 2 == 1; + } else if (parseLayer(detId) == 3) { + return parseModule(detId) % 2 == 0; + } else { + std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; + return 0; + } + } else { + std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; + return 0; + } + } else { + std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; + return 0; + } +} + +unsigned int lst::Module::parsePartnerDetId(unsigned int detId) { + if (parseIsLower(detId)) + return ((parseIsInverted(detId)) ? detId - 1 : detId + 1); + else + return ((parseIsInverted(detId)) ? detId + 1 : detId - 1); +} + +lst::Module::ModuleType lst::Module::parseModuleType(unsigned int detId) { + if (parseSubdet(detId) == lst::Module::Barrel) { + if (parseLayer(detId) <= 3) + return lst::Module::PS; + else + return lst::Module::TwoS; + } else { + if (parseLayer(detId) <= 2) { + if (parseRing(detId) <= 10) + return lst::Module::PS; + else + return lst::Module::TwoS; + } else { + if (parseRing(detId) <= 7) + return lst::Module::PS; + else + return lst::Module::TwoS; + } + } +} + +lst::Module::ModuleLayerType lst::Module::parseModuleLayerType(unsigned int detId) { + if (parseModuleType(detId) == lst::Module::TwoS) + return lst::Module::Strip; + if (parseIsInverted(detId)) { + if (parseIsLower(detId)) + return lst::Module::Strip; + else + return lst::Module::Pixel; + } else { + if (parseIsLower(detId)) + return lst::Module::Pixel; + else + return lst::Module::Strip; + } +} + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h new file mode 100644 index 0000000000000..bb64619ee7b43 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h @@ -0,0 +1,37 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleInfo_h +#define RecoTracker_LSTCore_interface_LSTGeometry_ModuleInfo_h + +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" + +namespace lst { + + struct ModuleInfo { + unsigned int detId; + char binaryDetId; + std::string section; + int layer; + int ring; + double sensorCenterRho_mm; + double sensorCenterZ_mm; + double tiltAngle_deg; + double skewAngle_deg; + double yawAngle_deg; + double phi_deg; + double vtxOneX_mm; + double vtxOneY_mm; + double vtxTwoX_mm; + double vtxTwoY_mm; + double vtxThreeX_mm; + double vtxThreeY_mm; + double vtxFourX_mm; + double vtxFourY_mm; + double meanWidth_mm; + double length_mm; + double sensorSpacing_mm; + double sensorThickness_mm; + MatrixD8x3 transformedCorners; + }; + +} // namespace lst + +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h new file mode 100644 index 0000000000000..610ee10fed4a1 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h @@ -0,0 +1,20 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_SensorInfo_h +#define RecoTracker_LSTCore_interface_LSTGeometry_SensorInfo_h + +#include + +namespace lst { + + struct SensorInfo { + unsigned int DetId; + char BinaryDetId; + std::string Section; + int Layer; + int Ring; + double sensorCenterRho_mm; + double sensorCenterZ_mm; + double phi_deg; + }; +} // namespace lst + +#endif diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc new file mode 100644 index 0000000000000..edb2b2f56190d --- /dev/null +++ b/RecoTracker/LSTCore/src/LSTGeometry.cc @@ -0,0 +1,4 @@ +// This is just a placeholder file to see if the code compiles +// + +#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h" \ No newline at end of file From 887816705b0ed3345190dc74c5c1ae65302b89a3 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 14:17:16 -0400 Subject: [PATCH 02/95] Finished with corners --- .../LSTCore/interface/LSTGeometry/Common.h | 1 + .../interface/LSTGeometry/CornerFunctions.h | 79 ++++++++++++++++++- .../interface/LSTGeometry/SensorInfo.h | 10 +-- 3 files changed, 84 insertions(+), 6 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 925eb12ed5f65..43ef8030bbf41 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -6,6 +6,7 @@ namespace lst { using MatrixD3x3 = Eigen::Matrix; + using MatrixD4x3 = Eigen::Matrix; using MatrixD8x3 = Eigen::Matrix; using ColVectorD3 = Eigen::Matrix; using RowVectorD3 = Eigen::Matrix; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h index 8b4663111457d..0173d35595071 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h @@ -3,6 +3,7 @@ #include #include +#include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" @@ -12,6 +13,7 @@ namespace lst { double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } + //Calculates the Rodrigues' rotation matrix for rotating a vector around an arbitrary axis. MatrixD3x3 rodriguesRotationMatrix(Eigen::Matrix axis, double theta) { axis.normalize(); @@ -22,6 +24,7 @@ namespace lst { return rotationMatrix; } + // Generates a rotation matrix for rotating around the tangential direction in cylindrical coordinates. MatrixD3x3 tangentialRotationMatrix(double phi, double theta) { ColVectorD3 axis; axis << -sin(phi), cos(phi), 0; @@ -29,6 +32,11 @@ namespace lst { return rodriguesRotationMatrix(axis, theta); } + // Computes the final rotation matrix based on tilt and phi angles. + // Note: + // Only the tilt angles are non-zero for the current geometry. If the other + // angles get used, implement their rotations using the tangentialRotationMatrix + // function above as an example. MatrixD3x3 rotationMatrix(double tilt_deg, double skew_deg, double yaw_deg, double phi_deg) { if (skew_deg != 0 || yaw_deg != 0) throw std::invalid_argument("Skew and yaw angles are not currently supported."); @@ -52,7 +60,8 @@ namespace lst { return finalR; } - void transformSensorCorners(ModuleInfo &moduleInfo) { + // Calculates the transformed corners of each sensor + void transformSensorCorners(ModuleInfo& moduleInfo) { auto module_z = moduleInfo.sensorCenterZ_mm; auto module_rho = moduleInfo.sensorCenterRho_mm; auto module_phi = moduleInfo.phi_deg; @@ -100,6 +109,74 @@ namespace lst { moduleInfo.transformedCorners.col(2) = rotated_corners.col(1); } + // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. + std::unordered_map assignCornersToSensors(std::vector modules, + std::vector sensors) { + std::unordered_map transformed_corners_dict; + + for (auto const& moduleInfo : modules) { + unsigned int module_det_id = moduleInfo.detId; + unsigned int sensor_det_id_1 = module_det_id + 1; + unsigned int sensor_det_id_2 = module_det_id + 2; + + auto& transformed_corners = moduleInfo.transformedCorners; + RowVectorD3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); + RowVectorD3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); + + bool found_sensor_1 = false; + bool found_sensor_2 = false; + unsigned int sensor_index_1 = 0; + unsigned int sensor_index_2 = 0; + + for (unsigned int i = 0; i < sensors.size(); i++) { + if (!found_sensor_1 && sensors[i].detId == sensor_det_id_1) { + sensor_index_1 = i; + found_sensor_1 = true; + } + if (!found_sensor_2 && sensors[i].detId == sensor_det_id_2) { + sensor_index_2 = i; + found_sensor_2 = true; + } + if (found_sensor_1 && found_sensor_2) + break; + } + + if (!found_sensor_1 || !found_sensor_2) { + throw std::runtime_error("Sensor not found"); + } + + double sensor1_center_z = sensors[sensor_index_1].sensorCenterZ_mm; + double sensor1_center_x = + sensors[sensor_index_1].sensorCenterRho_mm * cos(degToRad(sensors[sensor_index_1].phi_deg)); + double sensor1_center_y = + sensors[sensor_index_1].sensorCenterRho_mm * sin(degToRad(sensors[sensor_index_1].phi_deg)); + double sensor2_center_z = sensors[sensor_index_2].sensorCenterZ_mm; + double sensor2_center_x = + sensors[sensor_index_2].sensorCenterRho_mm * cos(degToRad(sensors[sensor_index_2].phi_deg)); + double sensor2_center_y = + sensors[sensor_index_2].sensorCenterRho_mm * sin(degToRad(sensors[sensor_index_2].phi_deg)); + + RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; + RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; + + sensor_centroid_1 /= 10; + sensor_centroid_2 /= 10; + + double distance_to_sensor_1 = (centroid_sensor_1 - sensor_centroid_1).norm(); + double distance_to_sensor_2 = (centroid_sensor_2 - sensor_centroid_2).norm(); + + if (distance_to_sensor_1 < distance_to_sensor_2) { + transformed_corners_dict[sensor_det_id_1] = transformed_corners.topRows(4); + transformed_corners_dict[sensor_det_id_2] = transformed_corners.bottomRows(4); + } else { + transformed_corners_dict[sensor_det_id_2] = transformed_corners.topRows(4); + transformed_corners_dict[sensor_det_id_1] = transformed_corners.bottomRows(4); + } + } + + return transformed_corners_dict; + } + } // namespace lst #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h index 610ee10fed4a1..087b68c8a9e55 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h @@ -6,11 +6,11 @@ namespace lst { struct SensorInfo { - unsigned int DetId; - char BinaryDetId; - std::string Section; - int Layer; - int Ring; + unsigned int detId; + char binaryDetId; + std::string section; + int layer; + int ring; double sensorCenterRho_mm; double sensorCenterZ_mm; double phi_deg; From bd63e47a6fa872c2f80c7a2fe0854fdd18ee8743 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 15:19:33 -0400 Subject: [PATCH 03/95] Added IO --- .../interface/LSTGeometry/CentroidMethods.h | 6 + .../{CornerFunctions.h => CornerMethods.h} | 4 +- .../LSTCore/interface/LSTGeometry/IO.h | 121 ++++++++++++++++++ .../interface/LSTGeometry/ModuleInfo.h | 2 +- .../interface/LSTGeometry/SensorInfo.h | 2 +- RecoTracker/LSTCore/src/LSTGeometry.cc | 3 +- 6 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h rename RecoTracker/LSTCore/interface/LSTGeometry/{CornerFunctions.h => CornerMethods.h} (98%) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/IO.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h new file mode 100644 index 0000000000000..25db93f5a9c00 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -0,0 +1,6 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h +#define RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h + + + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h similarity index 98% rename from RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h rename to RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 0173d35595071..a615f54b3419e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_h -#define RecoTracker_LSTCore_interface_LSTGeometry_h +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_CornerMethods_h +#define RecoTracker_LSTCore_interface_LSTGeometry_CornerMethods_h #include #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h new file mode 100644 index 0000000000000..d03e1f16df2d5 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -0,0 +1,121 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_IO_h +#define RecoTracker_LSTCore_interface_LSTGeometry_IO_h + +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" + +#include +#include +#include +#include +#include + +namespace lst { + +std::string trim(const std::string& str) { + size_t first = str.find_first_not_of(" \t\r\n"); + if (first == std::string::npos) return ""; + size_t last = str.find_last_not_of(" \t\r\n"); + return str.substr(first, (last - first + 1)); +} + +std::vector parseCSVLine(const std::string& line) { + std::vector tokens; + std::stringstream ss(line); + std::string token; + + while (std::getline(ss, token, ',')) { + tokens.push_back(trim(token)); + } + + return tokens; +} + +std::vector readModuleInfo(const std::string& filename) { + std::vector modules; + std::string line; + std::ifstream file(filename); + + if (!file.is_open()) { + throw std::runtime_error("Could not open file " + filename); + } + + // Skip header line + std::getline(file, line); + + while (std::getline(file, line)) { + if (line.empty()) continue; + + std::vector tokens = parseCSVLine(line); + if (tokens.size() != 23) continue; + + ModuleInfo m; + + m.detId = std::stoul(tokens[0]); + m.binaryDetId = std::stoul(tokens[1], nullptr, 2); + m.section = tokens[2]; + m.layer = std::stoi(tokens[3]); + m.ring = std::stoi(tokens[4]); + m.sensorCenterRho_mm = std::stod(tokens[5]); + m.sensorCenterZ_mm = std::stod(tokens[6]); + m.tiltAngle_deg = std::stod(tokens[7]); + m.skewAngle_deg = std::stod(tokens[8]); + m.yawAngle_deg = std::stod(tokens[9]); + m.phi_deg = std::stod(tokens[10]); + m.vtxOneX_mm = std::stod(tokens[11]); + m.vtxOneY_mm = std::stod(tokens[12]); + m.vtxTwoX_mm = std::stod(tokens[13]); + m.vtxTwoY_mm = std::stod(tokens[14]); + m.vtxThreeX_mm = std::stod(tokens[15]); + m.vtxThreeY_mm = std::stod(tokens[16]); + m.vtxFourX_mm = std::stod(tokens[17]); + m.vtxFourY_mm = std::stod(tokens[18]); + m.meanWidth_mm = std::stod(tokens[19]); + m.length_mm = std::stod(tokens[20]); + m.sensorSpacing_mm = std::stod(tokens[21]); + m.sensorThickness_mm = std::stod(tokens[22]); + + modules.push_back(m); + } + + return modules; +} + +std::vector readSensorInfo(const std::string& filename) { + std::vector sensors; + std::string line; + std::ifstream file(filename); + + if (!file.is_open()) { + throw std::runtime_error("Could not open file " + filename); + } + + // Skip header line + std::getline(file, line); + + while (std::getline(file, line)) { + if (line.empty()) continue; + + std::vector tokens = parseCSVLine(line); + if (tokens.size() != 8) continue; + + SensorInfo s; + + s.detId = std::stoul(tokens[0]); + s.binaryDetId = std::stoul(tokens[1], nullptr, 2); + s.section = tokens[2]; + s.layer = std::stoi(tokens[3]); + s.ring = std::stoi(tokens[4]); + s.sensorCenterRho_mm = std::stod(tokens[5]); + s.sensorCenterZ_mm = std::stod(tokens[6]); + s.phi_deg = std::stod(tokens[7]); + + sensors.push_back(s); + } + + return sensors; +} + +} + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h index bb64619ee7b43..51734e4b3e835 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h @@ -7,7 +7,7 @@ namespace lst { struct ModuleInfo { unsigned int detId; - char binaryDetId; + unsigned int binaryDetId; std::string section; int layer; int ring; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h index 087b68c8a9e55..9f5ccba9a7757 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h @@ -7,7 +7,7 @@ namespace lst { struct SensorInfo { unsigned int detId; - char binaryDetId; + unsigned int binaryDetId; std::string section; int layer; int ring; diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc index edb2b2f56190d..18c91b93d1a96 100644 --- a/RecoTracker/LSTCore/src/LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/LSTGeometry.cc @@ -1,4 +1,5 @@ // This is just a placeholder file to see if the code compiles // -#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerFunctions.h" \ No newline at end of file +#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" \ No newline at end of file From b6950816776682079febf8706e8c35e10e726465 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 15:33:28 -0400 Subject: [PATCH 04/95] Format --- .../interface/LSTGeometry/CentroidMethods.h | 2 - .../LSTCore/interface/LSTGeometry/IO.h | 153 +++++++++--------- 2 files changed, 79 insertions(+), 76 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 25db93f5a9c00..d958c12815e15 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -1,6 +1,4 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h #define RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h - - #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index d03e1f16df2d5..889e231c4f93d 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -12,110 +12,115 @@ namespace lst { -std::string trim(const std::string& str) { + std::string trim(const std::string& str) { size_t first = str.find_first_not_of(" \t\r\n"); - if (first == std::string::npos) return ""; + if (first == std::string::npos) + return ""; size_t last = str.find_last_not_of(" \t\r\n"); return str.substr(first, (last - first + 1)); -} + } -std::vector parseCSVLine(const std::string& line) { + std::vector parseCSVLine(const std::string& line) { std::vector tokens; std::stringstream ss(line); std::string token; - + while (std::getline(ss, token, ',')) { - tokens.push_back(trim(token)); + tokens.push_back(trim(token)); } - + return tokens; -} + } -std::vector readModuleInfo(const std::string& filename) { + std::vector readModuleInfo(const std::string& filename) { std::vector modules; std::string line; std::ifstream file(filename); - + if (!file.is_open()) { - throw std::runtime_error("Could not open file " + filename); - } - + throw std::runtime_error("Could not open file " + filename); + } + // Skip header line std::getline(file, line); - + while (std::getline(file, line)) { - if (line.empty()) continue; - - std::vector tokens = parseCSVLine(line); - if (tokens.size() != 23) continue; - - ModuleInfo m; - - m.detId = std::stoul(tokens[0]); - m.binaryDetId = std::stoul(tokens[1], nullptr, 2); - m.section = tokens[2]; - m.layer = std::stoi(tokens[3]); - m.ring = std::stoi(tokens[4]); - m.sensorCenterRho_mm = std::stod(tokens[5]); - m.sensorCenterZ_mm = std::stod(tokens[6]); - m.tiltAngle_deg = std::stod(tokens[7]); - m.skewAngle_deg = std::stod(tokens[8]); - m.yawAngle_deg = std::stod(tokens[9]); - m.phi_deg = std::stod(tokens[10]); - m.vtxOneX_mm = std::stod(tokens[11]); - m.vtxOneY_mm = std::stod(tokens[12]); - m.vtxTwoX_mm = std::stod(tokens[13]); - m.vtxTwoY_mm = std::stod(tokens[14]); - m.vtxThreeX_mm = std::stod(tokens[15]); - m.vtxThreeY_mm = std::stod(tokens[16]); - m.vtxFourX_mm = std::stod(tokens[17]); - m.vtxFourY_mm = std::stod(tokens[18]); - m.meanWidth_mm = std::stod(tokens[19]); - m.length_mm = std::stod(tokens[20]); - m.sensorSpacing_mm = std::stod(tokens[21]); - m.sensorThickness_mm = std::stod(tokens[22]); - - modules.push_back(m); + if (line.empty()) + continue; + + std::vector tokens = parseCSVLine(line); + if (tokens.size() != 23) + continue; + + ModuleInfo m; + + m.detId = std::stoul(tokens[0]); + m.binaryDetId = std::stoul(tokens[1], nullptr, 2); + m.section = tokens[2]; + m.layer = std::stoi(tokens[3]); + m.ring = std::stoi(tokens[4]); + m.sensorCenterRho_mm = std::stod(tokens[5]); + m.sensorCenterZ_mm = std::stod(tokens[6]); + m.tiltAngle_deg = std::stod(tokens[7]); + m.skewAngle_deg = std::stod(tokens[8]); + m.yawAngle_deg = std::stod(tokens[9]); + m.phi_deg = std::stod(tokens[10]); + m.vtxOneX_mm = std::stod(tokens[11]); + m.vtxOneY_mm = std::stod(tokens[12]); + m.vtxTwoX_mm = std::stod(tokens[13]); + m.vtxTwoY_mm = std::stod(tokens[14]); + m.vtxThreeX_mm = std::stod(tokens[15]); + m.vtxThreeY_mm = std::stod(tokens[16]); + m.vtxFourX_mm = std::stod(tokens[17]); + m.vtxFourY_mm = std::stod(tokens[18]); + m.meanWidth_mm = std::stod(tokens[19]); + m.length_mm = std::stod(tokens[20]); + m.sensorSpacing_mm = std::stod(tokens[21]); + m.sensorThickness_mm = std::stod(tokens[22]); + + modules.push_back(m); } - + return modules; -} + } -std::vector readSensorInfo(const std::string& filename) { + std::vector readSensorInfo(const std::string& filename) { std::vector sensors; std::string line; std::ifstream file(filename); - + if (!file.is_open()) { - throw std::runtime_error("Could not open file " + filename); - } - + throw std::runtime_error("Could not open file " + filename); + } + // Skip header line std::getline(file, line); - + while (std::getline(file, line)) { - if (line.empty()) continue; - - std::vector tokens = parseCSVLine(line); - if (tokens.size() != 8) continue; - - SensorInfo s; - - s.detId = std::stoul(tokens[0]); - s.binaryDetId = std::stoul(tokens[1], nullptr, 2); - s.section = tokens[2]; - s.layer = std::stoi(tokens[3]); - s.ring = std::stoi(tokens[4]); - s.sensorCenterRho_mm = std::stod(tokens[5]); - s.sensorCenterZ_mm = std::stod(tokens[6]); - s.phi_deg = std::stod(tokens[7]); - - sensors.push_back(s); + if (line.empty()) + continue; + + std::vector tokens = parseCSVLine(line); + if (tokens.size() != 8) + continue; + + SensorInfo s; + + s.detId = std::stoul(tokens[0]); + s.binaryDetId = std::stoul(tokens[1], nullptr, 2); + s.section = tokens[2]; + s.layer = std::stoi(tokens[3]); + s.ring = std::stoi(tokens[4]); + s.sensorCenterRho_mm = std::stod(tokens[5]); + s.sensorCenterZ_mm = std::stod(tokens[6]); + s.phi_deg = std::stod(tokens[7]); + + sensors.push_back(s); } - + return sensors; -} + } -} +} // namespace lst #endif \ No newline at end of file From a121d4482eff76344f84e7c87a03372fbe2c462a Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 16:59:02 -0400 Subject: [PATCH 05/95] Added centroid methods --- .../LSTCore/interface/LSTGeometry/Centroid.h | 16 ++++ .../interface/LSTGeometry/CentroidMethods.h | 76 +++++++++++++++++++ .../LSTCore/interface/LSTGeometry/Common.h | 6 ++ .../interface/LSTGeometry/CornerMethods.h | 2 - .../interface/LSTGeometry/ModuleDetIdParser.h | 2 +- RecoTracker/LSTCore/src/LSTGeometry.cc | 1 + 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h b/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h new file mode 100644 index 0000000000000..c685abd5f52df --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h @@ -0,0 +1,16 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h +#define RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h + +namespace lst { + + struct Centroid { + unsigned int detId; + unsigned int moduleType; + double x; + double y; + double z; + }; + +} // namespace lst + +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index d958c12815e15..96eba4ff8dc67 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -1,4 +1,80 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h #define RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h +#include +#include + +#include "Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" + +namespace lst { + + unsigned int extractBits(unsigned int value, unsigned int start, unsigned int end) { + unsigned int mask = (1 << (end - start + 1)) - 1; + return (value >> start) & mask; + } + + unsigned int firstDigit(unsigned int n) { + while (n >= 10) { + n /= 10; + } + return n; + } + + // TODO: refactor to use Module class better + int parseModuleType(unsigned int detId) { + // Check if the first digit of detId is '3' for inner tracker + if (firstDigit(detId) == 3) + return -1; + + unsigned int subdet = extractBits(detId, 25, 27); + unsigned int layer = subdet == Module::SubDet::Barrel ? extractBits(detId, 20, 22) : extractBits(detId, 18, 20); + unsigned int ring = subdet == Module::SubDet::Endcap ? extractBits(detId, 12, 15) : 0; + + bool is_even_det_id = detId % 2 == 0; + if (subdet == Module::SubDet::Barrel) { + if (layer <= 3) + return is_even_det_id ? Module::ModuleType::PSS : Module::ModuleType::PSP; + else + return Module::ModuleType::TwoS; + } else if (subdet == Module::SubDet::Endcap) { + if (layer <= 2) + return is_even_det_id && ring <= 10 ? Module::ModuleType::PSS + : (ring <= 10 ? Module::ModuleType::PSP : Module::ModuleType::TwoS); + else + return is_even_det_id && ring <= 7 ? Module::ModuleType::PSS + : (ring <= 7 ? Module::ModuleType::PSP : Module::ModuleType::TwoS); + } else { + throw std::runtime_error("Invalid subdetector type"); + } + } + + std::unordered_map compute_centroids(std::vector sensors) { + std::unordered_map centroids; + for (const auto& sensor : sensors) { + unsigned int detId = sensor.detId; + int moduleType = parseModuleType(detId); + + // Remove sensors from inner tracker + if (moduleType == -1) { + continue; + } + + // Convert from mm to cm + double z = sensor.sensorCenterZ_mm / 10.0; + double rho = sensor.sensorCenterRho_mm / 10.0; + double phi = degToRad(sensor.phi_deg); + double x = rho * cos(phi); + double y = rho * sin(phi); + + Centroid centroid{detId, static_cast(moduleType), x, y, z}; + centroids[detId] = centroid; + } + return centroids; + } + +} // namespace lst + #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 43ef8030bbf41..c3d09f4e45409 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -2,6 +2,7 @@ #define RecoTracker_LSTCore_interface_LSTGeometry_Common_h #include +#include namespace lst { @@ -11,6 +12,11 @@ namespace lst { using ColVectorD3 = Eigen::Matrix; using RowVectorD3 = Eigen::Matrix; + // This is defined as a constant in case the legacy value (123456789) needs to be used + double kDefaultSlope = std::numeric_limits::infinity(); + + double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } + } // namespace lst #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index a615f54b3419e..d481a6b50752b 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -11,8 +11,6 @@ namespace lst { - double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } - //Calculates the Rodrigues' rotation matrix for rotating a vector around an arbitrary axis. MatrixD3x3 rodriguesRotationMatrix(Eigen::Matrix axis, double theta) { axis.normalize(); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h index 762f825c66df7..8c3296b25ef3a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h @@ -182,7 +182,7 @@ namespace lst { // To hold information whether it is a 2S or PS public: - enum ModuleType { PS, TwoS }; + enum ModuleType { PS, PSP = 23, PSS = 24, TwoS = 25 }; private: ModuleType moduleType_; diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc index 18c91b93d1a96..d2668b1179950 100644 --- a/RecoTracker/LSTCore/src/LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/LSTGeometry.cc @@ -2,4 +2,5 @@ // #include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" \ No newline at end of file From 7c75d07e2bd160c7ecd70b7d4956d7153a8ed1d7 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 19 Sep 2025 19:33:00 +0000 Subject: [PATCH 06/95] Added orientation methods --- .../interface/LSTGeometry/CentroidMethods.h | 2 +- .../{ModuleDetIdParser.h => Module.h} | 0 .../LSTGeometry/OrientationMethods.h | 60 +++++++++++++++++++ RecoTracker/LSTCore/src/LSTGeometry.cc | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) rename RecoTracker/LSTCore/interface/LSTGeometry/{ModuleDetIdParser.h => Module.h} (100%) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 96eba4ff8dc67..6a271bca43180 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -5,7 +5,7 @@ #include #include "Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h similarity index 100% rename from RecoTracker/LSTCore/interface/LSTGeometry/ModuleDetIdParser.h rename to RecoTracker/LSTCore/interface/LSTGeometry/Module.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h new file mode 100644 index 0000000000000..edb5f47e73bae --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -0,0 +1,60 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_OrientationMethods_h +#define RecoTracker_LSTCore_interface_LSTGeometry_OrientationMethods_h + +#include +#include +#include + +#include "CentroidMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" + +namespace lst { + + struct SlopeData { + double drdz_slope; + double drdy_slope; + }; + + // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. + SlopeData calculateSlope(double dx, double dy, double dz) { + double dr = sqrt(dx * dx + dy * dy); + double drdz_slope = dz != 0 ? dr / dz : kDefaultSlope; + double drdy_slope = dy != 0 ? -dx / dy : kDefaultSlope; + return SlopeData{drdz_slope, drdy_slope}; + } + + // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. + std::tuple, std::unordered_map> process_corners( + std::unordered_map corners) { + std::unordered_map barrel_slopes; + std::unordered_map endcap_slopes; + + for (const auto& [detId, corners] : corners) { + double dx = corners(1, 1) - corners(0, 1); + double dy = corners(1, 2) - corners(0, 2); + double dz = corners(1, 0) - corners(0, 0); + + SlopeData slope = calculateSlope(dx, dy, dz); + + unsigned int module_type = static_cast(parseModuleType(detId)); + Module module(detId, module_type); + + unsigned short subdet = module.subdet(); + bool is_tilted = module.side() != 3; + bool is_strip = module.moduleLayerType() == 1; + + if (!is_strip) + continue; + + if (subdet == Module::SubDet::Barrel and is_tilted) + barrel_slopes[detId] = slope; + else if (subdet == Module::SubDet::Endcap) + endcap_slopes[detId] = slope; + } + + return std::make_tuple(barrel_slopes, endcap_slopes); + } +} // namespace lst + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc index d2668b1179950..eaee97616567c 100644 --- a/RecoTracker/LSTCore/src/LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/LSTGeometry.cc @@ -3,4 +3,5 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" \ No newline at end of file From 662f7d237d198e378ee6fa8fea5c555d6b087717 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 24 Sep 2025 15:04:27 -0400 Subject: [PATCH 07/95] Started implementing pixel maps --- .../LSTCore/interface/LSTGeometry/Common.h | 2 + .../interface/LSTGeometry/DetectorGeometry.h | 54 ++++++++++++++ .../LSTCore/interface/LSTGeometry/Module.h | 4 +- .../interface/LSTGeometry/PixelMapMethods.h | 71 +++++++++++++++++++ RecoTracker/LSTCore/src/LSTGeometry.cc | 3 +- 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index c3d09f4e45409..b3139f9f2ab83 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -12,6 +12,8 @@ namespace lst { using ColVectorD3 = Eigen::Matrix; using RowVectorD3 = Eigen::Matrix; + constexpr double kPtThreshold = 0.8; + // This is defined as a constant in case the legacy value (123456789) needs to be used double kDefaultSlope = std::numeric_limits::infinity(); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h new file mode 100644 index 0000000000000..3bc29338cc6d6 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -0,0 +1,54 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_DetectorGeometry_h +#define RecoTracker_LSTCore_interface_LSTGeometry_DetectorGeometry_h + +#include + +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" + +namespace lst { + + class DetectorGeometry { + private: + std::unordered_map corners; + std::vector avg_radii; + std::vector avg_z; + + public: + DetectorGeometry(std::unordered_map corners_in, + std::vector avg_radii_in, + std::vector avg_z_in) + : corners(corners_in), avg_radii(avg_radii_in), avg_z(avg_z_in) {} + + std::vector getDetIds() const { + std::vector detIds; + for (const auto& entry : corners) { + detIds.push_back(entry.first); + } + return detIds; + } + + double getMinR(unsigned int detId) const { + auto const& corners = this->corners.at(detId); + double minR = std::numeric_limits::max(); + for (int i = 0; i < corners.rows(); i++) { + double x = corners(i, 1); + double y = corners(i, 2); + minR = std::min(minR, std::sqrt(x * x + y * y)); + } + return minR; + } + + double getMaxR(unsigned int detId) const { + auto const& corners = this->corners.at(detId); + double maxR = std::numeric_limits::min(); + for (int i = 0; i < corners.rows(); i++) { + double x = corners(i, 1); + double y = corners(i, 2); + maxR = std::max(maxR, std::sqrt(x * x + y * y)); + } + return maxR; + } + }; +} // namespace lst + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h index 8c3296b25ef3a..3eb58a89e1451 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleDetIdParser_h -#define RecoTracker_LSTCore_interface_LSTGeometry_ModuleDetIdParser_h +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Module_h +#define RecoTracker_LSTCore_interface_LSTGeometry_Module_h #include #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h new file mode 100644 index 0000000000000..d59a3e7835678 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -0,0 +1,71 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h +#define RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h + +#include +#include +#include +#include + +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" + +namespace lst { + + using PtEtaPhiZChargeKey = std::tuple; + using LayerSubdetKey = std::tuple; + using LayerSubdetMap = std::unordered_map, boost::hash>; + using PtEtaPhiZChargeMap = std::unordered_map>; + + PtEtaPhiZChargeMap computePixelMap(std::unordered_map const& centroids, + DetectorGeometry const& det_geom) { + constexpr unsigned int kNEta = 25; + constexpr unsigned int kNPhi = 72; + constexpr unsigned int kNZ = 25; + constexpr double kPtBounds[] = {kPtThreshold, 2.0, 10'000.0}; + + PtEtaPhiZChargeMap maps; + + // Initialize empty lists for the pixel map + for (unsigned int ipt = 0; ipt < sizeof(kPtBounds) / sizeof(kPtBounds[0]); ipt++) { + for (unsigned int ieta = 0; ieta < kNEta; ieta++) { + for (unsigned int iphi = 0; iphi < kNPhi; iphi++) { + for (unsigned int iz = 0; iz < kNZ; iz++) { + maps[{ipt, ieta, iphi, iz, 1}] = LayerSubdetMap(); + maps[{ipt, ieta, iphi, iz, -1}] = LayerSubdetMap(); + auto& map_pos = maps.at({ipt, ieta, iphi, iz, 1}); + auto& map_neg = maps.at({ipt, ieta, iphi, iz, -1}); + for (unsigned int layer : {1, 2}) { + for (unsigned int subdet : {4, 5}) { + map_pos[{layer, subdet}] = {}; + map_neg[{layer, subdet}] = {}; + } + } + } + } + } + } + + // Loop over the detids and for each detid compute which superbins it is connected to + for (auto detId : det_geom.getDetIds()) { + auto centroid = centroids.at(detId); + + // Parse the layer and subdet + auto module = Module(detId, centroid.moduleType); + auto layer = module.layer(); + if (layer > 2) + continue; + auto subdet = module.subdet(); + + // Skip if the module is not PS module and is not lower module + if (module.isLower() != 1 || module.moduleType() != 0) + continue; + } + + return maps; + } + +} // namespace lst + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc index eaee97616567c..b82599940683c 100644 --- a/RecoTracker/LSTCore/src/LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/LSTGeometry.cc @@ -4,4 +4,5 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" \ No newline at end of file +#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" \ No newline at end of file From 38b87359e2345d09b27a40970c03c95baee83b71 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 25 Sep 2025 10:49:09 -0400 Subject: [PATCH 08/95] Finished with pixel maps --- .../LSTCore/interface/LSTGeometry/Common.h | 11 ++ .../interface/LSTGeometry/DetectorGeometry.h | 124 ++++++++++++++++-- .../interface/LSTGeometry/PixelMapMethods.h | 62 ++++++++- 3 files changed, 186 insertions(+), 11 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index b3139f9f2ab83..53d305b84606b 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -12,13 +12,24 @@ namespace lst { using ColVectorD3 = Eigen::Matrix; using RowVectorD3 = Eigen::Matrix; + // TODO: These should be moved to ../Common.h constexpr double kPtThreshold = 0.8; + constexpr double k2Rinv1GeVf = 0.00299792458; + constexpr double kB = 3.8112; // This is defined as a constant in case the legacy value (123456789) needs to be used double kDefaultSlope = std::numeric_limits::infinity(); double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } + double phi_mpi_pi(double phi) { + while (phi > std::numbers::pi_v) + phi -= 2 * std::numbers::pi_v; + while (phi < -std::numbers::pi_v) + phi += 2 * std::numbers::pi_v; + return phi; + } + } // namespace lst #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 3bc29338cc6d6..5121254b01d86 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -1,6 +1,7 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_DetectorGeometry_h #define RecoTracker_LSTCore_interface_LSTGeometry_DetectorGeometry_h +#include #include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" @@ -9,26 +10,26 @@ namespace lst { class DetectorGeometry { private: - std::unordered_map corners; - std::vector avg_radii; - std::vector avg_z; + std::unordered_map corners_; + std::vector avg_radii_; + std::vector avg_z_; public: - DetectorGeometry(std::unordered_map corners_in, - std::vector avg_radii_in, - std::vector avg_z_in) - : corners(corners_in), avg_radii(avg_radii_in), avg_z(avg_z_in) {} + DetectorGeometry(std::unordered_map corners, + std::vector avg_radii, + std::vector avg_z) + : corners_(corners), avg_radii_(avg_radii), avg_z_(avg_z) {} std::vector getDetIds() const { std::vector detIds; - for (const auto& entry : corners) { + for (const auto& entry : corners_) { detIds.push_back(entry.first); } return detIds; } double getMinR(unsigned int detId) const { - auto const& corners = this->corners.at(detId); + auto const& corners = corners_.at(detId); double minR = std::numeric_limits::max(); for (int i = 0; i < corners.rows(); i++) { double x = corners(i, 1); @@ -39,7 +40,7 @@ namespace lst { } double getMaxR(unsigned int detId) const { - auto const& corners = this->corners.at(detId); + auto const& corners = corners_.at(detId); double maxR = std::numeric_limits::min(); for (int i = 0; i < corners.rows(); i++) { double x = corners(i, 1); @@ -48,6 +49,109 @@ namespace lst { } return maxR; } + + double getMinz(unsigned int detId) const { + auto const& corners = corners_.at(detId); + double minZ = std::numeric_limits::max(); + for (int i = 0; i < corners.rows(); i++) { + double z = corners(i, 0); + minZ = std::min(minZ, z); + } + return minZ; + } + + double getMaxz(unsigned int detId) const { + auto const& corners = corners_.at(detId); + double maxZ = std::numeric_limits::min(); + for (int i = 0; i < corners.rows(); i++) { + double z = corners(i, 0); + maxZ = std::max(maxZ, z); + } + return maxZ; + } + + double getMinPhi(unsigned int detId) const { + auto const& corners = corners_.at(detId); + double minPhi = std::numeric_limits::max(); + double minPosPhi = std::numeric_limits::max(); + double minNegPhi = std::numeric_limits::max(); + unsigned int nPos = 0; + unsigned int nOverPi2 = 0; + for (int i = 0; i < corners.rows(); i++) { + double phi = phi_mpi_pi(std::numbers::pi_v + std::atan2(-corners(i, 2), -corners(i, 1))); + minPhi = std::min(minPhi, phi); + if (phi > 0) { + minPosPhi = std::min(minPosPhi, phi); + nPos++; + } else { + minNegPhi = std::min(minNegPhi, phi); + } + if (std::fabs(phi) > std::numbers::pi_v / 2.) { + nOverPi2++; + } + } + if (nPos == 4 || nPos == 0) + return minPhi; + if (nOverPi2 == 4) + return minPosPhi; + return minPhi; + } + + double getMaxPhi(unsigned int detId) const { + auto const& corners = corners_.at(detId); + double maxPhi = std::numeric_limits::min(); + double maxPosPhi = std::numeric_limits::min(); + double maxNegPhi = std::numeric_limits::min(); + unsigned int nPos = 0; + unsigned int nOverPi2 = 0; + for (int i = 0; i < corners.rows(); i++) { + double phi = phi_mpi_pi(std::numbers::pi_v + std::atan2(-corners(i, 2), -corners(i, 1))); + maxPhi = std::max(maxPhi, phi); + if (phi > 0) { + maxPosPhi = std::max(maxPosPhi, phi); + nPos++; + } else { + maxNegPhi = std::max(maxNegPhi, phi); + } + if (std::fabs(phi) > std::numbers::pi_v / 2.) { + nOverPi2++; + } + } + if (nPos == 4 || nPos == 0) + return maxPhi; + if (nOverPi2 == 4) + return maxNegPhi; + return maxPhi; + } + + std::pair getCompatibleEtaRange(unsigned int detId, double zmin_bound, double zmax_bound) const { + double minr = getMinR(detId); + double maxr = getMaxR(detId); + double minz = getMinz(detId); + double maxz = getMaxz(detId); + double mineta = -std::log(std::tan(std::atan2(minz > 0 ? maxr : minr, minz - zmin_bound) / 2.)); + double maxeta = -std::log(std::tan(std::atan2(maxz > 0 ? minr : maxr, maxz - zmax_bound) / 2.)); + + if (maxeta < mineta) + std::swap(maxeta, mineta); + return std::make_pair(mineta, maxeta); + } + + std::pair, std::pair> getCompatiblePhiRange(unsigned int detId, + double ptmin, + double ptmax) const { + double minr = getMinR(detId); + double maxr = getMaxR(detId); + double minphi = getMinPhi(detId); + double maxphi = getMaxPhi(detId); + double A = k2Rinv1GeVf * kB / 2.; + double pos_q_phi_lo_bound = phi_mpi_pi(A * minr / ptmax + minphi); + double pos_q_phi_hi_bound = phi_mpi_pi(A * maxr / ptmin + maxphi); + double neg_q_phi_lo_bound = phi_mpi_pi(-A * maxr / ptmin + minphi); + double neg_q_phi_hi_bound = phi_mpi_pi(-A * minr / ptmax + maxphi); + return std::make_pair(std::make_pair(pos_q_phi_lo_bound, pos_q_phi_hi_bound), + std::make_pair(neg_q_phi_lo_bound, neg_q_phi_hi_bound)); + } }; } // namespace lst diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index d59a3e7835678..6960b81565bbf 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -28,7 +28,7 @@ namespace lst { PtEtaPhiZChargeMap maps; // Initialize empty lists for the pixel map - for (unsigned int ipt = 0; ipt < sizeof(kPtBounds) / sizeof(kPtBounds[0]); ipt++) { + for (unsigned int ipt = 0; ipt < sizeof(kPtBounds) / sizeof(kPtBounds[0]) - 1; ipt++) { for (unsigned int ieta = 0; ieta < kNEta; ieta++) { for (unsigned int iphi = 0; iphi < kNPhi; iphi++) { for (unsigned int iz = 0; iz < kNZ; iz++) { @@ -61,6 +61,66 @@ namespace lst { // Skip if the module is not PS module and is not lower module if (module.isLower() != 1 || module.moduleType() != 0) continue; + + // For this module, now compute which super bins they belong to + // To compute which super bins it belongs to, one needs to provide at least pt and z window to compute compatible eta and phi range + // So we have a loop in pt and Z + for (unsigned int ipt = 0; ipt < sizeof(kPtBounds) / sizeof(kPtBounds[0]) - 1; ipt++) { + for (unsigned int iz = 0; iz < kNZ; iz++) { + // The zmin, zmax of consideration + double zmin = -30 + iz * (60. / kNZ); + double zmax = -30 + (iz + 1) * (60. / kNZ); + + zmin -= 0.05; + zmin += 0.05; + + // The ptmin, ptmax of consideration + double pt_lo = kPtBounds[ipt]; + double pt_hi = kPtBounds[ipt + 1]; + + auto [etamin, etamax] = det_geom.getCompatibleEtaRange(detId, zmin, zmax); + + etamin -= 0.05; + etamax += 0.05; + + if (layer == 2 && subdet == 4) { + if (etamax < 2.3) + continue; + if (etamin < 2.3) + etamin = 2.3; + } + + // Compute the indices of the compatible eta range + unsigned int ietamin = static_cast(std::max((etamin + 2.6) / (5.2 / kNEta), 0.0)); + unsigned int ietamax = + static_cast(std::min((etamax + 2.6) / (5.2 / kNEta), static_cast(kNEta))); + + auto phi_ranges = det_geom.getCompatiblePhiRange(detId, pt_lo, pt_hi); + + int iphimin_pos = static_cast((phi_ranges.first.first + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + int iphimax_pos = static_cast((phi_ranges.first.second + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + int iphimin_neg = static_cast((phi_ranges.second.first + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + int iphimax_neg = static_cast((phi_ranges.second.second + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + + unsigned int phibins_pos_start = iphimin_pos <= iphimax_pos ? iphimin_pos : 0; + unsigned int phibins_pos_end = iphimin_pos <= iphimax_pos ? iphimax_pos : kNPhi; + unsigned int phibins_neg_start = iphimin_neg <= iphimax_neg ? iphimin_neg : 0; + unsigned int phibins_neg_end = iphimin_neg <= iphimax_neg ? iphimax_neg : kNPhi; + + for (unsigned int ieta = ietamin; ieta <= ietamax; ieta++) { + for (unsigned int iphi = phibins_pos_start; iphi < phibins_pos_end; iphi++) { + maps[{ipt, ieta, iphi, iz, 1}][{layer, subdet}].push_back(detId); + } + for (unsigned int iphi = phibins_neg_start; iphi < phibins_neg_end; iphi++) { + maps[{ipt, ieta, iphi, iz, 1}][{layer, subdet}].push_back(detId); + } + } + } + } } return maps; From 3b2e3a2d17467f8e5f3e0a79d0c2e1be6263bf91 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 25 Sep 2025 14:51:58 -0400 Subject: [PATCH 09/95] Started implementing module maps --- .../LSTCore/interface/LSTGeometry/Common.h | 2 + .../interface/LSTGeometry/CornerMethods.h | 2 +- .../LSTCore/interface/LSTGeometry/LSTMath.h | 77 +++++++++++++++++++ .../interface/LSTGeometry/ModuleMapMethods.h | 6 ++ RecoTracker/LSTCore/src/LSTGeometry.cc | 3 +- 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 53d305b84606b..17f6bf3c64681 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -7,8 +7,10 @@ namespace lst { using MatrixD3x3 = Eigen::Matrix; + using MatrixD4x2 = Eigen::Matrix; using MatrixD4x3 = Eigen::Matrix; using MatrixD8x3 = Eigen::Matrix; + using RowVectorD2 = Eigen::Matrix; using ColVectorD3 = Eigen::Matrix; using RowVectorD3 = Eigen::Matrix; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index d481a6b50752b..78807d7cad21a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -12,7 +12,7 @@ namespace lst { //Calculates the Rodrigues' rotation matrix for rotating a vector around an arbitrary axis. - MatrixD3x3 rodriguesRotationMatrix(Eigen::Matrix axis, double theta) { + MatrixD3x3 rodriguesRotationMatrix(ColVectorD3 axis, double theta) { axis.normalize(); MatrixD3x3 k{{0, -axis(2), axis(1)}, {axis(2), 0, -axis(0)}, {-axis(1), axis(0), 0}}; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h new file mode 100644 index 0000000000000..cb16f7a557535 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -0,0 +1,77 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTMath_h +#define RecoTracker_LSTCore_interface_LSTGeometry_LSTMath_h + +#include + +#include +#include + +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" + +namespace lst { + + std::pair getEtaPhi(double x, double y, double z, double refphi = 0) { + if (refphi != 0) { + double xnew = x * std::cos(-refphi) - y * std::sin(-refphi); + double ynew = x * std::sin(-refphi) + y * std::cos(-refphi); + x = xnew; + y = ynew; + } + double phi = std::atan2(y, x); + double eta = std::copysign(-std::log(std::tan(std::atan(std::sqrt(x * x + y * y) / std::abs(z)) / 2.)), z); + return std::make_pair(eta, phi); + } + + bool moduleOverlapsInEtaPhi(MatrixD4x3 const& ref_mod_boundaries, + MatrixD4x3 const& tar_mod_boundaries, + double refphi = 0, + double zshift = 0) { + RowVectorD3 ref_center = ref_mod_boundaries.colwise().sum(); + ref_center /= 4.; + RowVectorD3 tar_center = tar_mod_boundaries.colwise().sum(); + tar_center /= 4.; + + double ref_center_phi = std::atan2(ref_center(2), ref_center(1)); + double tar_center_phi = std::atan2(tar_center(2), tar_center(1)); + + if (std::fabs(phi_mpi_pi(ref_center_phi - tar_center_phi)) > std::numbers::pi_v / 2.) + return false; + + MatrixD4x2 ref_mod_boundaries_etaphi; + MatrixD4x2 tar_mod_boundaries_etaphi; + + for (int i = 0; i < 4; ++i) { + auto ref_etaphi = getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0), refphi); + auto tar_etaphi = getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0), refphi); + ref_mod_boundaries_etaphi(i, 0) = ref_etaphi.first; + ref_mod_boundaries_etaphi(i, 1) = ref_etaphi.second; + tar_mod_boundaries_etaphi(i, 0) = tar_etaphi.first; + tar_mod_boundaries_etaphi(i, 1) = tar_etaphi.second; + } + + // Quick cut + RowVectorD2 diff = ref_mod_boundaries_etaphi.row(0) - ref_mod_boundaries_etaphi.row(0); + if (std::fabs(diff(0)) > 0.5) + return false; + if (std::fabs(phi_mpi_pi(diff(1))) > 1.) + return false; + + // TODO: It might be easy enough to implement this without Boost polygon + using Point = boost::geometry::model::d2::point_xy; + using Polygon = boost::geometry::model::polygon; + + Polygon ref_poly, tar_poly; + + // <= 4 because we need to close the polygon with the first point + for (int i = 0; i <= 4; ++i) { + boost::geometry::append(ref_poly, + Point(ref_mod_boundaries_etaphi(i % 4, 0), ref_mod_boundaries_etaphi(i % 4, 1))); + boost::geometry::append(tar_poly, + Point(tar_mod_boundaries_etaphi(i % 4, 0), tar_mod_boundaries_etaphi(i % 4, 1))); + } + + return boost::geometry::intersects(ref_poly, tar_poly); + } + +} // namespace lst +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h new file mode 100644 index 0000000000000..fe777ae97a543 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -0,0 +1,6 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h +#define RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h + +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc index b82599940683c..7be5e3909910a 100644 --- a/RecoTracker/LSTCore/src/LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/LSTGeometry.cc @@ -5,4 +5,5 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" \ No newline at end of file +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" \ No newline at end of file From 6b39965aaac44cf310eaea69990e17fbcc2ded5b Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 26 Sep 2025 10:28:08 -0400 Subject: [PATCH 10/95] Some progress on module maps --- .../interface/LSTGeometry/DetectorGeometry.h | 40 ++++++++++++++++++- .../LSTCore/interface/LSTGeometry/Helix.h | 18 +++++++++ .../interface/LSTGeometry/ModuleMapMethods.h | 38 ++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/Helix.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 5121254b01d86..fac9dd569cc04 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -3,8 +3,10 @@ #include #include +#include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" namespace lst { @@ -13,6 +15,8 @@ namespace lst { std::unordered_map corners_; std::vector avg_radii_; std::vector avg_z_; + std::vector> barrel_lower_det_ids_; + std::vector> endcap_lower_det_ids_; public: DetectorGeometry(std::unordered_map corners, @@ -20,14 +24,46 @@ namespace lst { std::vector avg_z) : corners_(corners), avg_radii_(avg_radii), avg_z_(avg_z) {} - std::vector getDetIds() const { + MatrixD4x3 const& getCorners(unsigned int detId) const { return corners_.at(detId); } + + std::vector getDetIds(std::function&)> filter = + [](const auto&) { return true; }) const { std::vector detIds; for (const auto& entry : corners_) { - detIds.push_back(entry.first); + if (filter(entry)) { + detIds.push_back(entry.first); + } } return detIds; } + void buildByLayer() { + // Clear just in case they were already built + barrel_lower_det_ids_.clear(); + endcap_lower_det_ids_.clear(); + + for (unsigned int layer = 1; layer < 7; layer++) { + barrel_lower_det_ids_.push_back(getDetIds([&layer](const auto& x) { + Module m(x.first); + return m.subdet() == 5 && m.layer() == layer && m.isLower() == 1; + })); + } + for (unsigned int layer = 1; layer < 6; layer++) { + barrel_lower_det_ids_.push_back(getDetIds([&layer](const auto& x) { + Module m(x.first); + return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; + })); + } + } + + std::vector const& getBarrelLayerDetIds(unsigned int layer) const { + return barrel_lower_det_ids_[layer - 1]; + } + + std::vector const& getEndcapLayerDetIds(unsigned int layer) const { + return endcap_lower_det_ids_[layer - 1]; + } + double getMinR(unsigned int detId) const { auto const& corners = corners_.at(detId); double minR = std::numeric_limits::max(); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h new file mode 100644 index 0000000000000..a973585ab9062 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h @@ -0,0 +1,18 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h +#define RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h + +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" + +namespace lst { + + struct Helix { + ColVectorD3 center; + double radius; + double phi; + double lam; + int charge; + }; + +} + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index fe777ae97a543..6095e618e553a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -1,6 +1,44 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h #define RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h +#include +#include + #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" + +namespace lst { + + std::vector getStraightLineConnections(unsigned int ref_detid, + std::unordered_map const& centroids, + DetectorGeometry const& det_geom) { + auto centroid = centroids.at(ref_detid); + + double refphi = std::atan2(centroid.y, centroid.x); + + Module refmodule(ref_detid); + + unsigned short ref_layer = refmodule.layer(); + unsigned short ref_subdet = refmodule.subdet(); + + auto const& tar_detids_to_be_considered = + ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1) : det_geom.getEndcapLayerDetIds(ref_layer + 1); + + std::vector list_of_detids_etaphi_layer_tar; + for (unsigned int tar_detid : tar_detids_to_be_considered) { + if (moduleOverlapsInEtaPhi(det_geom.getCorners(ref_detid), det_geom.getCorners(tar_detid), refphi, 0) || + moduleOverlapsInEtaPhi(det_geom.getCorners(ref_detid), det_geom.getCorners(tar_detid), refphi, 10) || + moduleOverlapsInEtaPhi(det_geom.getCorners(ref_detid), det_geom.getCorners(tar_detid), refphi, -10)) + list_of_detids_etaphi_layer_tar.push_back(tar_detid); + } + + // Consider barrel to endcap connections if the intersection area is > 0 + + return list_of_detids_etaphi_layer_tar; + } + +} // namespace lst #endif \ No newline at end of file From fe7c81df0550dfc809c696a4ed8fd377c044244b Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 26 Sep 2025 10:30:33 -0400 Subject: [PATCH 11/95] Switched namespace to lstgeometry --- .../LSTCore/interface/LSTGeometry/Centroid.h | 4 ++-- .../interface/LSTGeometry/CentroidMethods.h | 4 ++-- .../LSTCore/interface/LSTGeometry/Common.h | 4 ++-- .../interface/LSTGeometry/CornerMethods.h | 4 ++-- .../interface/LSTGeometry/DetectorGeometry.h | 4 ++-- .../LSTCore/interface/LSTGeometry/Helix.h | 20 +++++++++---------- .../LSTCore/interface/LSTGeometry/IO.h | 4 ++-- .../LSTCore/interface/LSTGeometry/LSTMath.h | 4 ++-- .../LSTCore/interface/LSTGeometry/Module.h | 4 ++-- .../interface/LSTGeometry/ModuleInfo.h | 4 ++-- .../interface/LSTGeometry/ModuleMapMethods.h | 4 ++-- .../LSTGeometry/OrientationMethods.h | 4 ++-- .../interface/LSTGeometry/PixelMapMethods.h | 4 ++-- .../interface/LSTGeometry/SensorInfo.h | 4 ++-- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h b/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h index c685abd5f52df..22876bc3f051d 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h #define RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h -namespace lst { +namespace lstgeometry { struct Centroid { unsigned int detId; @@ -11,6 +11,6 @@ namespace lst { double z; }; -} // namespace lst +} // namespace lstgeometry #endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 6a271bca43180..8e2fcc692ee03 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -9,7 +9,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" -namespace lst { +namespace lstgeometry { unsigned int extractBits(unsigned int value, unsigned int start, unsigned int end) { unsigned int mask = (1 << (end - start + 1)) - 1; @@ -75,6 +75,6 @@ namespace lst { return centroids; } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 17f6bf3c64681..a0d8196dcc6ae 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -4,7 +4,7 @@ #include #include -namespace lst { +namespace lstgeometry { using MatrixD3x3 = Eigen::Matrix; using MatrixD4x2 = Eigen::Matrix; @@ -32,6 +32,6 @@ namespace lst { return phi; } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 78807d7cad21a..2110826384b99 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -9,7 +9,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" -namespace lst { +namespace lstgeometry { //Calculates the Rodrigues' rotation matrix for rotating a vector around an arbitrary axis. MatrixD3x3 rodriguesRotationMatrix(ColVectorD3 axis, double theta) { @@ -175,6 +175,6 @@ namespace lst { return transformed_corners_dict; } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index fac9dd569cc04..efce536d4aa06 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -8,7 +8,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -namespace lst { +namespace lstgeometry { class DetectorGeometry { private: @@ -189,6 +189,6 @@ namespace lst { std::make_pair(neg_q_phi_lo_bound, neg_q_phi_hi_bound)); } }; -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h index a973585ab9062..aa05eababe3ae 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h @@ -3,16 +3,16 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -namespace lst { - - struct Helix { - ColVectorD3 center; - double radius; - double phi; - double lam; - int charge; - }; +namespace lstgeometry { -} + struct Helix { + ColVectorD3 center; + double radius; + double phi; + double lam; + int charge; + }; + +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 889e231c4f93d..8a9fed1e86928 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -10,7 +10,7 @@ #include #include -namespace lst { +namespace lstgeometry { std::string trim(const std::string& str) { size_t first = str.find_first_not_of(" \t\r\n"); @@ -121,6 +121,6 @@ namespace lst { return sensors; } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index cb16f7a557535..e215c62572078 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -8,7 +8,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -namespace lst { +namespace lstgeometry { std::pair getEtaPhi(double x, double y, double z, double refphi = 0) { if (refphi != 0) { @@ -73,5 +73,5 @@ namespace lst { return boost::geometry::intersects(ref_poly, tar_poly); } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h index 3eb58a89e1451..4a6d2b4281230 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h @@ -4,7 +4,7 @@ #include #include -namespace lst { +namespace lstgeometry { class Module { private: @@ -242,7 +242,7 @@ namespace lst { static ModuleLayerType parseModuleLayerType(unsigned int); }; -} // namespace lst +} // namespace lstgeometry lst::Module::Module() { setDetId(0); } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h index 51734e4b3e835..1500dd143d051 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h @@ -3,7 +3,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -namespace lst { +namespace lstgeometry { struct ModuleInfo { unsigned int detId; @@ -32,6 +32,6 @@ namespace lst { MatrixD8x3 transformedCorners; }; -} // namespace lst +} // namespace lstgeometry #endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 6095e618e553a..b8dc93f824a03 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -9,7 +9,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" -namespace lst { +namespace lstgeometry { std::vector getStraightLineConnections(unsigned int ref_detid, std::unordered_map const& centroids, @@ -39,6 +39,6 @@ namespace lst { return list_of_detids_etaphi_layer_tar; } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h index edb5f47e73bae..b841ddd8b1b63 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -9,7 +9,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" -namespace lst { +namespace lstgeometry { struct SlopeData { double drdz_slope; @@ -55,6 +55,6 @@ namespace lst { return std::make_tuple(barrel_slopes, endcap_slopes); } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index 6960b81565bbf..d2c83f1836393 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -11,7 +11,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -namespace lst { +namespace lstgeometry { using PtEtaPhiZChargeKey = std::tuple; using LayerSubdetKey = std::tuple; @@ -126,6 +126,6 @@ namespace lst { return maps; } -} // namespace lst +} // namespace lstgeometry #endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h index 9f5ccba9a7757..f2a6e1ca50cb6 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h @@ -3,7 +3,7 @@ #include -namespace lst { +namespace lstgeometry { struct SensorInfo { unsigned int detId; @@ -15,6 +15,6 @@ namespace lst { double sensorCenterZ_mm; double phi_deg; }; -} // namespace lst +} // namespace lstgeometry #endif From 17b90b224a6381281ae1a389b5abe7a46e9d174e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 26 Sep 2025 11:28:20 -0400 Subject: [PATCH 12/95] A couple of fixes --- .../LSTCore/interface/LSTGeometry/LSTMath.h | 23 ++- .../LSTCore/interface/LSTGeometry/Module.h | 131 +++++++++--------- .../interface/LSTGeometry/ModuleMapMethods.h | 33 +++++ .../interface/LSTGeometry/PixelMapMethods.h | 7 +- 4 files changed, 123 insertions(+), 71 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index e215c62572078..7821d26f050a2 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -10,6 +10,9 @@ namespace lstgeometry { + using Point = boost::geometry::model::d2::point_xy; + using Polygon = boost::geometry::model::polygon; + std::pair getEtaPhi(double x, double y, double z, double refphi = 0) { if (refphi != 0) { double xnew = x * std::cos(-refphi) - y * std::sin(-refphi); @@ -22,6 +25,22 @@ namespace lstgeometry { return std::make_pair(eta, phi); } + Polygon getEtaPhiPolygon(MatrixD4x3 const& mod_boundaries, double refphi, double zshift = 0) { + MatrixD4x2 mod_boundaries_etaphi; + for (int i = 0; i < 4; ++i) { + auto ref_etaphi = getEtaPhi(mod_boundaries(i, 1), mod_boundaries(i, 2), mod_boundaries(i, 0) + zshift, refphi); + mod_boundaries_etaphi(i, 0) = ref_etaphi.first; + mod_boundaries_etaphi(i, 1) = ref_etaphi.second; + } + + Polygon poly; + // <= 4 because we need to close the polygon with the first point + for (int i = 0; i <= 4; ++i) { + boost::geometry::append(poly, Point(mod_boundaries_etaphi(i % 4, 0), mod_boundaries_etaphi(i % 4, 1))); + } + return poly; + } + bool moduleOverlapsInEtaPhi(MatrixD4x3 const& ref_mod_boundaries, MatrixD4x3 const& tar_mod_boundaries, double refphi = 0, @@ -56,10 +75,6 @@ namespace lstgeometry { if (std::fabs(phi_mpi_pi(diff(1))) > 1.) return false; - // TODO: It might be easy enough to implement this without Boost polygon - using Point = boost::geometry::model::d2::point_xy; - using Polygon = boost::geometry::model::polygon; - Polygon ref_poly, tar_poly; // <= 4 because we need to close the polygon with the first point diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h index 4a6d2b4281230..9307f29b965f0 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h @@ -244,56 +244,58 @@ namespace lstgeometry { } // namespace lstgeometry -lst::Module::Module() { setDetId(0); } +lstgeometry::Module::Module() { setDetId(0); } -lst::Module::Module(unsigned int detId) { setDetId(detId); } +lstgeometry::Module::Module(unsigned int detId) { setDetId(detId); } -lst::Module::Module(unsigned int detId, unsigned int moduleTypeInfo) { setDetId(detId, moduleTypeInfo); } +lstgeometry::Module::Module(unsigned int detId, unsigned int moduleTypeInfo) { setDetId(detId, moduleTypeInfo); } -lst::Module::Module(const Module& module) { setDetId(module.detId(), module.moduleType(), module.moduleLayerType()); } +lstgeometry::Module::Module(const Module& module) { + setDetId(module.detId(), module.moduleType(), module.moduleLayerType()); +} -lst::Module::~Module() {} +lstgeometry::Module::~Module() {} -const unsigned short& lst::Module::subdet() const { return subdet_; } +const unsigned short& lstgeometry::Module::subdet() const { return subdet_; } -const unsigned short& lst::Module::side() const { return side_; } +const unsigned short& lstgeometry::Module::side() const { return side_; } -const unsigned short& lst::Module::layer() const { return layer_; } +const unsigned short& lstgeometry::Module::layer() const { return layer_; } -const unsigned short& lst::Module::rod() const { return rod_; } +const unsigned short& lstgeometry::Module::rod() const { return rod_; } -const unsigned short& lst::Module::ring() const { return ring_; } +const unsigned short& lstgeometry::Module::ring() const { return ring_; } -const unsigned short& lst::Module::module() const { return module_; } +const unsigned short& lstgeometry::Module::module() const { return module_; } -const unsigned short& lst::Module::isLower() const { return isLower_; } +const unsigned short& lstgeometry::Module::isLower() const { return isLower_; } -const unsigned int& lst::Module::detId() const { return detId_; } +const unsigned int& lstgeometry::Module::detId() const { return detId_; } -const unsigned int& lst::Module::partnerDetId() const { return partnerDetId_; } +const unsigned int& lstgeometry::Module::partnerDetId() const { return partnerDetId_; } -const bool& lst::Module::isInverted() const { return isInverted_; } +const bool& lstgeometry::Module::isInverted() const { return isInverted_; } -const lst::Module::ModuleType& lst::Module::moduleType() const { return moduleType_; } +const lstgeometry::Module::ModuleType& lstgeometry::Module::moduleType() const { return moduleType_; } -const lst::Module::ModuleLayerType& lst::Module::moduleLayerType() const { return moduleLayerType_; } +const lstgeometry::Module::ModuleLayerType& lstgeometry::Module::moduleLayerType() const { return moduleLayerType_; } -void lst::Module::setDetId(unsigned int detId) { +void lstgeometry::Module::setDetId(unsigned int detId) { detId_ = detId; setDerivedQuantities(); } -void lst::Module::setDetId(unsigned int detId, unsigned int moduleTypeInfo) { +void lstgeometry::Module::setDetId(unsigned int detId, unsigned int moduleTypeInfo) { detId_ = detId; setDerivedQuantities(moduleTypeInfo); } -void lst::Module::setDetId(unsigned int detId, ModuleType moduleType, ModuleLayerType moduleLayerType) { +void lstgeometry::Module::setDetId(unsigned int detId, ModuleType moduleType, ModuleLayerType moduleLayerType) { detId_ = detId; setDerivedQuantities(moduleType, moduleLayerType); } -void lst::Module::setDerivedQuantities() { +void lstgeometry::Module::setDerivedQuantities() { subdet_ = parseSubdet(detId_); side_ = parseSide(detId_); layer_ = parseLayer(detId_); @@ -307,7 +309,7 @@ void lst::Module::setDerivedQuantities() { moduleLayerType_ = parseModuleLayerType(detId_); } -void lst::Module::setDerivedQuantities(unsigned int moduleTypeInfo) { +void lstgeometry::Module::setDerivedQuantities(unsigned int moduleTypeInfo) { subdet_ = parseSubdet(detId_); side_ = parseSide(detId_); layer_ = parseLayer(detId_); @@ -317,12 +319,13 @@ void lst::Module::setDerivedQuantities(unsigned int moduleTypeInfo) { isLower_ = parseIsLower(detId_); isInverted_ = parseIsInverted(detId_); partnerDetId_ = parsePartnerDetId(detId_); - moduleType_ = (moduleTypeInfo == 25 ? lst::Module::TwoS : lst::Module::PS); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS - moduleLayerType_ = - (moduleTypeInfo == 23 ? lst::Module::Pixel : lst::Module::Strip); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS + moduleType_ = (moduleTypeInfo == 25 ? lstgeometry::Module::TwoS + : lstgeometry::Module::PS); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS + moduleLayerType_ = (moduleTypeInfo == 23 ? lstgeometry::Module::Pixel + : lstgeometry::Module::Strip); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS } -void lst::Module::setDerivedQuantities(ModuleType moduleType, ModuleLayerType moduleLayerType) { +void lstgeometry::Module::setDerivedQuantities(ModuleType moduleType, ModuleLayerType moduleLayerType) { subdet_ = parseSubdet(detId_); side_ = parseSide(detId_); layer_ = parseLayer(detId_); @@ -336,68 +339,68 @@ void lst::Module::setDerivedQuantities(ModuleType moduleType, ModuleLayerType mo moduleLayerType_ = moduleLayerType; } -unsigned short lst::Module::parseSubdet(unsigned int detId) { return (detId & (7 << 25)) >> 25; } +unsigned short lstgeometry::Module::parseSubdet(unsigned int detId) { return (detId & (7 << 25)) >> 25; } -unsigned short lst::Module::parseSide(unsigned int detId) { - if (parseSubdet(detId) == lst::Module::Endcap) { +unsigned short lstgeometry::Module::parseSide(unsigned int detId) { + if (parseSubdet(detId) == lstgeometry::Module::Endcap) { return (detId & (3 << 23)) >> 23; - } else if (parseSubdet(detId) == lst::Module::Barrel) { + } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { return (detId & (3 << 18)) >> 18; } else { return 0; } } -unsigned short lst::Module::parseLayer(unsigned int detId) { - if (parseSubdet(detId) == lst::Module::Endcap) { +unsigned short lstgeometry::Module::parseLayer(unsigned int detId) { + if (parseSubdet(detId) == lstgeometry::Module::Endcap) { return (detId & (7 << 18)) >> 18; - } else if (parseSubdet(detId) == lst::Module::Barrel) { + } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { return (detId & (7 << 20)) >> 20; } else { return 0; } } -unsigned short lst::Module::parseRod(unsigned int detId) { - if (parseSubdet(detId) == lst::Module::Endcap) { +unsigned short lstgeometry::Module::parseRod(unsigned int detId) { + if (parseSubdet(detId) == lstgeometry::Module::Endcap) { return 0; - } else if (parseSubdet(detId) == lst::Module::Barrel) { + } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { return (detId & (127 << 10)) >> 10; } else { return 0; } } -unsigned short lst::Module::parseRing(unsigned int detId) { - if (parseSubdet(detId) == lst::Module::Endcap) { +unsigned short lstgeometry::Module::parseRing(unsigned int detId) { + if (parseSubdet(detId) == lstgeometry::Module::Endcap) { return (detId & (15 << 12)) >> 12; - } else if (parseSubdet(detId) == lst::Module::Barrel) { + } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { return 0; } else { return 0; } } -unsigned short lst::Module::parseModule(unsigned int detId) { return (detId & (127 << 2)) >> 2; } +unsigned short lstgeometry::Module::parseModule(unsigned int detId) { return (detId & (127 << 2)) >> 2; } -unsigned short lst::Module::parseIsLower(unsigned int detId) { +unsigned short lstgeometry::Module::parseIsLower(unsigned int detId) { return ((parseIsInverted(detId)) ? !(detId & 1) : (detId & 1)); } -bool lst::Module::parseIsInverted(unsigned int detId) { +bool lstgeometry::Module::parseIsInverted(unsigned int detId) { if (detId == 1) // "1" detId means "pixel module" where we store all pixel hits/mini/segments into one bucket return 0; - if (parseSubdet(detId) == lst::Module::Endcap) { - if (parseSide(detId) == lst::Module::NegZ) { + if (parseSubdet(detId) == lstgeometry::Module::Endcap) { + if (parseSide(detId) == lstgeometry::Module::NegZ) { return parseModule(detId) % 2 == 1; - } else if (parseSide(detId) == lst::Module::PosZ) { + } else if (parseSide(detId) == lstgeometry::Module::PosZ) { return parseModule(detId) % 2 == 0; } else { std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; return 0; } - } else if (parseSubdet(detId) == lst::Module::Barrel) { - if (parseSide(detId) == lst::Module::Center) { + } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { + if (parseSide(detId) == lstgeometry::Module::Center) { if (parseLayer(detId) <= 3) { return parseModule(detId) % 2 == 1; } else if (parseLayer(detId) >= 4) { @@ -406,7 +409,7 @@ bool lst::Module::parseIsInverted(unsigned int detId) { std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; return 0; } - } else if (parseSide(detId) == lst::Module::NegZ or parseSide(detId) == lst::Module::PosZ) { + } else if (parseSide(detId) == lstgeometry::Module::NegZ or parseSide(detId) == lstgeometry::Module::PosZ) { if (parseLayer(detId) <= 2) { return parseModule(detId) % 2 == 1; } else if (parseLayer(detId) == 3) { @@ -425,47 +428,47 @@ bool lst::Module::parseIsInverted(unsigned int detId) { } } -unsigned int lst::Module::parsePartnerDetId(unsigned int detId) { +unsigned int lstgeometry::Module::parsePartnerDetId(unsigned int detId) { if (parseIsLower(detId)) return ((parseIsInverted(detId)) ? detId - 1 : detId + 1); else return ((parseIsInverted(detId)) ? detId + 1 : detId - 1); } -lst::Module::ModuleType lst::Module::parseModuleType(unsigned int detId) { - if (parseSubdet(detId) == lst::Module::Barrel) { +lstgeometry::Module::ModuleType lstgeometry::Module::parseModuleType(unsigned int detId) { + if (parseSubdet(detId) == lstgeometry::Module::Barrel) { if (parseLayer(detId) <= 3) - return lst::Module::PS; + return lstgeometry::Module::PS; else - return lst::Module::TwoS; + return lstgeometry::Module::TwoS; } else { if (parseLayer(detId) <= 2) { if (parseRing(detId) <= 10) - return lst::Module::PS; + return lstgeometry::Module::PS; else - return lst::Module::TwoS; + return lstgeometry::Module::TwoS; } else { if (parseRing(detId) <= 7) - return lst::Module::PS; + return lstgeometry::Module::PS; else - return lst::Module::TwoS; + return lstgeometry::Module::TwoS; } } } -lst::Module::ModuleLayerType lst::Module::parseModuleLayerType(unsigned int detId) { - if (parseModuleType(detId) == lst::Module::TwoS) - return lst::Module::Strip; +lstgeometry::Module::ModuleLayerType lstgeometry::Module::parseModuleLayerType(unsigned int detId) { + if (parseModuleType(detId) == lstgeometry::Module::TwoS) + return lstgeometry::Module::Strip; if (parseIsInverted(detId)) { if (parseIsLower(detId)) - return lst::Module::Strip; + return lstgeometry::Module::Strip; else - return lst::Module::Pixel; + return lstgeometry::Module::Pixel; } else { if (parseIsLower(detId)) - return lst::Module::Pixel; + return lstgeometry::Module::Pixel; else - return lst::Module::Strip; + return lstgeometry::Module::Strip; } } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index b8dc93f824a03..bd0226a166bb7 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -2,7 +2,12 @@ #define RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h #include +#include #include +#include +#include +#include +#include #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" @@ -35,6 +40,34 @@ namespace lstgeometry { } // Consider barrel to endcap connections if the intersection area is > 0 + if (ref_subdet == 5) { + std::unordered_set barrel_endcap_connected_tar_detids; + + for (int zshift : {0, 10, -10}) { + std::optional ref_polygon = getEtaPhiPolygon(det_geom.getCorners(ref_detid), refphi, zshift); + + // Check whether there is still significant non-zero area + for (unsigned int tar_detid : list_of_detids_etaphi_layer_tar) { + if (!ref_polygon) + break; + Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); + + std::vector difference; + boost::geometry::difference(ref_polygon.value(), tar_polygon, difference); + + // I think this is always true, but if not there needs to be a bit of extra logic + assert(difference.size() < 2); + + if (difference.size()) + ref_polygon = difference[0]; + else + ref_polygon.reset(); + } + + if (!ref_polygon || boost::geometry::area(ref_polygon.value()) <= 0.0001) + continue; + } + } return list_of_detids_etaphi_layer_tar; } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index d2c83f1836393..7e6598da53c9c 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" @@ -23,12 +24,12 @@ namespace lstgeometry { constexpr unsigned int kNEta = 25; constexpr unsigned int kNPhi = 72; constexpr unsigned int kNZ = 25; - constexpr double kPtBounds[] = {kPtThreshold, 2.0, 10'000.0}; + constexpr std::array kPtBounds = {{kPtThreshold, 2.0, 10'000.0}}; PtEtaPhiZChargeMap maps; // Initialize empty lists for the pixel map - for (unsigned int ipt = 0; ipt < sizeof(kPtBounds) / sizeof(kPtBounds[0]) - 1; ipt++) { + for (unsigned int ipt = 0; ipt < kPtBounds.size() - 1; ipt++) { for (unsigned int ieta = 0; ieta < kNEta; ieta++) { for (unsigned int iphi = 0; iphi < kNPhi; iphi++) { for (unsigned int iz = 0; iz < kNZ; iz++) { @@ -65,7 +66,7 @@ namespace lstgeometry { // For this module, now compute which super bins they belong to // To compute which super bins it belongs to, one needs to provide at least pt and z window to compute compatible eta and phi range // So we have a loop in pt and Z - for (unsigned int ipt = 0; ipt < sizeof(kPtBounds) / sizeof(kPtBounds[0]) - 1; ipt++) { + for (unsigned int ipt = 0; ipt < kPtBounds.size() - 1; ipt++) { for (unsigned int iz = 0; iz < kNZ; iz++) { // The zmin, zmax of consideration double zmin = -30 + iz * (60. / kNZ); From 0256927b6eb8327a0cc7fce56fc2949c48cba594 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 30 Sep 2025 14:01:20 -0400 Subject: [PATCH 13/95] Finished module maps --- .../LSTCore/interface/LSTGeometry/Common.h | 2 + .../interface/LSTGeometry/DetectorGeometry.h | 4 + .../LSTCore/interface/LSTGeometry/Helix.h | 10 +- .../LSTCore/interface/LSTGeometry/LSTMath.h | 74 ++++++- .../interface/LSTGeometry/ModuleMapMethods.h | 180 ++++++++++++++++++ 5 files changed, 259 insertions(+), 11 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index a0d8196dcc6ae..5c33044604bc4 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -10,6 +10,8 @@ namespace lstgeometry { using MatrixD4x2 = Eigen::Matrix; using MatrixD4x3 = Eigen::Matrix; using MatrixD8x3 = Eigen::Matrix; + using MatrixDNx2 = Eigen::Matrix; + using MatrixDNx3 = Eigen::Matrix; using RowVectorD2 = Eigen::Matrix; using ColVectorD3 = Eigen::Matrix; using RowVectorD3 = Eigen::Matrix; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index efce536d4aa06..2a4dbe8b57fa0 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -64,6 +64,10 @@ namespace lstgeometry { return endcap_lower_det_ids_[layer - 1]; } + double getBarrelLayerAverageRadius(unsigned int layer) const { return avg_radii_[layer - 1]; } + + double getEndcapLayerAverageAbsZ(unsigned int layer) const { return avg_z_[layer - 1]; } + double getMinR(unsigned int detId) const { auto const& corners = corners_.at(detId); double minR = std::numeric_limits::max(); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h index aa05eababe3ae..bedb40985f745 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h @@ -1,12 +1,12 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h -#define RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h - -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Helix_h +#define RecoTracker_LSTCore_interface_LSTGeometry_Helix_h namespace lstgeometry { struct Helix { - ColVectorD3 center; + double center_x; + double center_y; + double center_z; double radius; double phi; double lam; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index 7821d26f050a2..ae9109409d68e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -5,14 +5,74 @@ #include #include +#include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Helix.h" namespace lstgeometry { using Point = boost::geometry::model::d2::point_xy; using Polygon = boost::geometry::model::polygon; + // Clarification : phi was derived assuming a negatively charged particle would start + // at the first quadrant. However the way signs are set up in the get_track_point function + // implies the particle actually starts out in the fourth quadrant, and phi is measured from + // the y axis as opposed to x axis in the expression provided in this function. Hence I tucked + // in an extra pi/2 to account for these effects + Helix constructHelixFromPoints( + double pt, double vx, double vy, double vz, double mx, double my, double mz, int charge) { + double radius = pt / (k2Rinv1GeVf * kB); + double r = std::fabs(radius); // TODO: Is this needed? + + double t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * r)); + double phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + + ((vy - my) / (vx - mx) < 0) * (std::numbers::pi_v)+charge * t / 2. + + (my - vy < 0) * (std::numbers::pi_v / 2.) - (my - vy > 0) * (std::numbers::pi_v / 2.); + + double cx = vx + charge * radius * std::sin(phi); + double cy = vy - charge * radius * std::cos(phi); + double cz = vz; + double lam = std::atan((mz - vz) / (radius * t)); + + return Helix(cx, cy, cz, radius, phi, lam, charge); + } + + std::tuple getHelixPointFromRadius(Helix const& helix, double target_r) { + auto objective_function = [&helix, target_r](double t) { + double x = helix.center_x - helix.charge * helix.radius * std::sin(helix.phi - helix.charge * t); + double y = helix.center_y + helix.charge * helix.radius * std::cos(helix.phi - helix.charge * t); + return std::fabs(std::sqrt(x * x + y * y) - target_r); + }; + int bits = std::numeric_limits::digits; + auto result = boost::math::tools::brent_find_minima(objective_function, 0.0, std::numbers::pi_v, bits); + double t = result.first; + + double x = helix.center_x - helix.charge * helix.radius * std::sin(helix.phi - helix.charge * t); + double y = helix.center_y + helix.charge * helix.radius * std::cos(helix.phi - helix.charge * t); + double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; + double r = std::sqrt(x * x + y * y); + + return std::make_tuple(x, y, z, r); + } + + std::tuple getHelixPointFromZ(Helix const& helix, double target_z) { + auto objective_function = [&helix, target_z](double t) { + double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; + return std::fabs(std::sqrt(z * z) - target_z); + }; + int bits = std::numeric_limits::digits; + auto result = boost::math::tools::brent_find_minima(objective_function, 0.0, std::numbers::pi_v, bits); + double t = result.first; + + double x = helix.center_x - helix.charge * helix.radius * std::sin(helix.phi - helix.charge * t); + double y = helix.center_y + helix.charge * helix.radius * std::cos(helix.phi - helix.charge * t); + double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; + double r = std::sqrt(x * x + y * y); + + return std::make_tuple(x, y, z, r); + } + std::pair getEtaPhi(double x, double y, double z, double refphi = 0) { if (refphi != 0) { double xnew = x * std::cos(-refphi) - y * std::sin(-refphi); @@ -25,18 +85,20 @@ namespace lstgeometry { return std::make_pair(eta, phi); } - Polygon getEtaPhiPolygon(MatrixD4x3 const& mod_boundaries, double refphi, double zshift = 0) { - MatrixD4x2 mod_boundaries_etaphi; - for (int i = 0; i < 4; ++i) { + Polygon getEtaPhiPolygon(MatrixDNx3 const& mod_boundaries, double refphi, double zshift = 0) { + int npoints = mod_boundaries.rows(); + MatrixDNx2 mod_boundaries_etaphi(npoints, 2); + for (int i = 0; i < npoints; ++i) { auto ref_etaphi = getEtaPhi(mod_boundaries(i, 1), mod_boundaries(i, 2), mod_boundaries(i, 0) + zshift, refphi); mod_boundaries_etaphi(i, 0) = ref_etaphi.first; mod_boundaries_etaphi(i, 1) = ref_etaphi.second; } Polygon poly; - // <= 4 because we need to close the polygon with the first point - for (int i = 0; i <= 4; ++i) { - boost::geometry::append(poly, Point(mod_boundaries_etaphi(i % 4, 0), mod_boundaries_etaphi(i % 4, 1))); + // <= because we need to close the polygon with the first point + for (int i = 0; i <= npoints; ++i) { + boost::geometry::append(poly, + Point(mod_boundaries_etaphi(i % npoints, 0), mod_boundaries_etaphi(i % npoints, 1))); } return poly; } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index bd0226a166bb7..117b3b82d5ec7 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -3,12 +3,15 @@ #include #include +#include #include #include +#include #include #include #include +#include "LSTMath.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" @@ -66,7 +69,184 @@ namespace lstgeometry { if (!ref_polygon || boost::geometry::area(ref_polygon.value()) <= 0.0001) continue; + + auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); + + for (unsigned int tar_detid : new_tar_detids_to_be_considered) { + auto centroid_target = centroids.at(tar_detid); + double tarphi = std::atan2(centroid_target.y, centroid_target.x); + + if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) + continue; + + Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); + + if (boost::geometry::intersects(ref_polygon.value(), tar_polygon)) + barrel_endcap_connected_tar_detids.insert(tar_detid); + } + } + list_of_detids_etaphi_layer_tar.insert(list_of_detids_etaphi_layer_tar.end(), + barrel_endcap_connected_tar_detids.begin(), + barrel_endcap_connected_tar_detids.end()); + } + + return list_of_detids_etaphi_layer_tar; + } + + std::vector> boundsAfterCurved( + unsigned int ref_detid, + std::unordered_map const& centroids, + DetectorGeometry const& det_geom, + bool doR = true) { + auto bounds = det_geom.getCorners(ref_detid); + auto centroid = centroids.at(ref_detid); + int charge = 1; + double theta = + std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); // TODO: Is this right? + double refphi = std::atan2(centroid.y, centroid.x); + Module refmodule(ref_detid); + unsigned short ref_layer = refmodule.layer(); + unsigned short ref_subdet = refmodule.subdet(); + std::vector> next_layer_bound_points; + + for (int i = 0; i < bounds.rows(); i++) { + Helix helix_p10 = + constructHelixFromPoints(kPtThreshold, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); + Helix helix_m10 = + constructHelixFromPoints(kPtThreshold, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); + Helix helix_p10_pos = + constructHelixFromPoints(kPtThreshold, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); + Helix helix_m10_pos = + constructHelixFromPoints(kPtThreshold, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); + double bound_theta = + std::atan2(std::sqrt(bounds(i, 1) * bounds(i, 1) + bounds(i, 2) * bounds(i, 2)), bounds(i, 0)); + double bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); + double phi_diff = phi_mpi_pi(bound_phi - refphi); + + // TODO: Check if the copysign arguments are correct + std::tuple next_point; + if (ref_subdet == 5) { + if (doR) { + double tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); + if (bound_theta > theta) { + next_point = getHelixPointFromRadius(phi_diff > 0 ? helix_p10 : helix_p10_pos, tar_layer_radius); + } else { + next_point = getHelixPointFromRadius(phi_diff > 0 ? helix_m10 : helix_m10_pos, tar_layer_radius); + } + } else { + double tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(1); + if (bound_theta > theta) { + if (phi_diff > 0) { + next_point = getHelixPointFromZ(helix_p10, std::copysign(tar_layer_z, helix_p10.lam)); + } else { + next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10.lam)); + } + } else { + if (phi_diff > 0) { + next_point = getHelixPointFromZ(helix_m10, std::copysign(tar_layer_z, helix_p10.lam)); + } else { + next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_p10.lam)); + } + } + } + } else { + double tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(ref_layer + 1); + if (bound_theta > theta) { + if (phi_diff > 0) { + next_point = getHelixPointFromZ(helix_p10, std::copysign(tar_layer_z, helix_p10.lam)); + } else { + next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10.lam)); + } + } else { + if (phi_diff > 0) { + next_point = getHelixPointFromZ(helix_m10, std::copysign(tar_layer_z, helix_m10.lam)); + } else { + next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_m10.lam)); + } + } + } + next_layer_bound_points.push_back({std::get<2>(next_point), std::get<0>(next_point), std::get<1>(next_point)}); + } + + return next_layer_bound_points; + } + + std::vector getCurvedLineConnections(unsigned int ref_detid, + std::unordered_map const& centroids, + DetectorGeometry const& det_geom) { + auto centroid = centroids.at(ref_detid); + + double refphi = std::atan2(centroid.y, centroid.x); + + Module refmodule(ref_detid); + + unsigned short ref_layer = refmodule.layer(); + unsigned short ref_subdet = refmodule.subdet(); + + auto const& tar_detids_to_be_considered = + ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1) : det_geom.getEndcapLayerDetIds(ref_layer + 1); + + std::vector> next_layer_bound_points = + boundsAfterCurved(ref_detid, centroids, det_geom); + MatrixDNx3 next_layer_bound_points_matrix(next_layer_bound_points.size(), 3); + for (size_t i = 0; i < next_layer_bound_points.size(); i++) { + next_layer_bound_points_matrix(i, 0) = std::get<0>(next_layer_bound_points[i]); + next_layer_bound_points_matrix(i, 1) = std::get<1>(next_layer_bound_points[i]); + next_layer_bound_points_matrix(i, 2) = std::get<2>(next_layer_bound_points[i]); + } + + std::vector list_of_detids_etaphi_layer_tar; + for (unsigned int tar_detid : tar_detids_to_be_considered) { + if (moduleOverlapsInEtaPhi(det_geom.getCorners(ref_detid), det_geom.getCorners(tar_detid), refphi, 0)) + list_of_detids_etaphi_layer_tar.push_back(tar_detid); + } + + // Consider barrel to endcap connections if the intersection area is > 0 + if (ref_subdet == 5) { + std::unordered_set barrel_endcap_connected_tar_detids; + + int zshift = 0; + + std::optional ref_polygon = getEtaPhiPolygon(next_layer_bound_points_matrix, refphi, zshift); + + // Check whether there is still significant non-zero area + for (unsigned int tar_detid : list_of_detids_etaphi_layer_tar) { + if (!ref_polygon) + break; + Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); + + std::vector difference; + boost::geometry::difference(ref_polygon.value(), tar_polygon, difference); + + // I think this is always true, but if not there needs to be a bit of extra logic + assert(difference.size() < 2); + + if (difference.size()) + ref_polygon = difference[0]; + else + ref_polygon.reset(); + } + + if (ref_polygon && boost::geometry::area(ref_polygon.value()) > 0.0001) { + auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); + + for (unsigned int tar_detid : new_tar_detids_to_be_considered) { + auto centroid_target = centroids.at(tar_detid); + double tarphi = std::atan2(centroid_target.y, centroid_target.x); + + if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) + continue; + + Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); + + if (boost::geometry::intersects(ref_polygon.value(), tar_polygon)) + barrel_endcap_connected_tar_detids.insert(tar_detid); + } } + + list_of_detids_etaphi_layer_tar.insert(list_of_detids_etaphi_layer_tar.end(), + barrel_endcap_connected_tar_detids.begin(), + barrel_endcap_connected_tar_detids.end()); } return list_of_detids_etaphi_layer_tar; From f5a44efd159760cce3c0dc192f75619efe05c678 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 Oct 2025 11:33:46 -0400 Subject: [PATCH 14/95] Added standalone binary --- .../interface/LSTGeometry/CentroidMethods.h | 2 +- .../interface/LSTGeometry/CornerMethods.h | 4 +- .../interface/LSTGeometry/DetectorGeometry.h | 2 +- .../LSTCore/interface/LSTGeometry/IO.h | 23 ++++++ .../interface/LSTGeometry/ModuleMapMethods.h | 71 ++++++++++------ .../LSTGeometry/OrientationMethods.h | 4 +- RecoTracker/LSTCore/src/LSTGeometry.cc | 9 --- RecoTracker/LSTCore/standalone/.gitignore | 1 + RecoTracker/LSTCore/standalone/Makefile | 16 ++-- .../standalone/bin/lst_make_geometry.cc | 81 +++++++++++++++++++ RecoTracker/LSTCore/standalone/setup.sh | 1 + 11 files changed, 169 insertions(+), 45 deletions(-) delete mode 100644 RecoTracker/LSTCore/src/LSTGeometry.cc create mode 100644 RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 8e2fcc692ee03..f3a7e7d00b77f 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -51,7 +51,7 @@ namespace lstgeometry { } } - std::unordered_map compute_centroids(std::vector sensors) { + std::unordered_map computeCentroids(std::vector &sensors) { std::unordered_map centroids; for (const auto& sensor : sensors) { unsigned int detId = sensor.detId; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 2110826384b99..143e1548e1172 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -108,8 +108,8 @@ namespace lstgeometry { } // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. - std::unordered_map assignCornersToSensors(std::vector modules, - std::vector sensors) { + std::unordered_map assignCornersToSensors(std::vector& modules, + std::vector& sensors) { std::unordered_map transformed_corners_dict; for (auto const& moduleInfo : modules) { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 2a4dbe8b57fa0..41e73e169f3d0 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -49,7 +49,7 @@ namespace lstgeometry { })); } for (unsigned int layer = 1; layer < 6; layer++) { - barrel_lower_det_ids_.push_back(getDetIds([&layer](const auto& x) { + endcap_lower_det_ids_.push_back(getDetIds([&layer](const auto& x) { Module m(x.first); return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; })); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 8a9fed1e86928..8924c55d66b3e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -120,6 +120,29 @@ namespace lstgeometry { return sensors; } + + std::vector readAverages(const std::string& filename) { + std::vector averages; + std::string line; + std::ifstream file(filename); + + if (!file.is_open()) { + throw std::runtime_error("Could not open file " + filename); + } + + while (std::getline(file, line)) { + if (line.empty()) + continue; + + std::vector tokens = parseCSVLine(line); + if (tokens.size() != 1) + continue; + + averages.push_back(std::stod(tokens[0])); + } + + return averages; + } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 117b3b82d5ec7..0e9a0a7ff3bfb 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -47,27 +46,30 @@ namespace lstgeometry { std::unordered_set barrel_endcap_connected_tar_detids; for (int zshift : {0, 10, -10}) { - std::optional ref_polygon = getEtaPhiPolygon(det_geom.getCorners(ref_detid), refphi, zshift); + std::vector ref_polygon; + ref_polygon.push_back(getEtaPhiPolygon(det_geom.getCorners(ref_detid), refphi, zshift)); // Check whether there is still significant non-zero area for (unsigned int tar_detid : list_of_detids_etaphi_layer_tar) { - if (!ref_polygon) + if (!ref_polygon.size()) break; Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); std::vector difference; - boost::geometry::difference(ref_polygon.value(), tar_polygon, difference); - - // I think this is always true, but if not there needs to be a bit of extra logic - assert(difference.size() < 2); + for (auto &ref_polygon_piece : ref_polygon) { + std::vector tmp_difference; + boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); + difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); + } - if (difference.size()) - ref_polygon = difference[0]; - else - ref_polygon.reset(); + ref_polygon = std::move(difference); } - if (!ref_polygon || boost::geometry::area(ref_polygon.value()) <= 0.0001) + double area = 0.; + for (auto &ref_polygon_piece : ref_polygon) + area += boost::geometry::area(ref_polygon_piece); + + if (area <= 0.0001) continue; auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); @@ -81,7 +83,15 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); - if (boost::geometry::intersects(ref_polygon.value(), tar_polygon)) + bool intersects = false; + for (auto &ref_polygon_piece : ref_polygon){ + if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { + intersects = true; + break; + } + } + + if (intersects) barrel_endcap_connected_tar_detids.insert(tar_detid); } } @@ -207,27 +217,30 @@ namespace lstgeometry { int zshift = 0; - std::optional ref_polygon = getEtaPhiPolygon(next_layer_bound_points_matrix, refphi, zshift); + std::vector ref_polygon; + ref_polygon.push_back(getEtaPhiPolygon(next_layer_bound_points_matrix, refphi, zshift)); // Check whether there is still significant non-zero area for (unsigned int tar_detid : list_of_detids_etaphi_layer_tar) { - if (!ref_polygon) + if (!ref_polygon.size()) break; Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); std::vector difference; - boost::geometry::difference(ref_polygon.value(), tar_polygon, difference); - - // I think this is always true, but if not there needs to be a bit of extra logic - assert(difference.size() < 2); + for (auto &ref_polygon_piece : ref_polygon) { + std::vector tmp_difference; + boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); + difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); + } - if (difference.size()) - ref_polygon = difference[0]; - else - ref_polygon.reset(); + ref_polygon = std::move(difference); } + + double area = 0.; + for (auto &ref_polygon_piece : ref_polygon) + area += boost::geometry::area(ref_polygon_piece); - if (ref_polygon && boost::geometry::area(ref_polygon.value()) > 0.0001) { + if (area > 0.0001) { auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { @@ -239,7 +252,15 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); - if (boost::geometry::intersects(ref_polygon.value(), tar_polygon)) + bool intersects = false; + for (auto &ref_polygon_piece : ref_polygon){ + if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { + intersects = true; + break; + } + } + + if (intersects) barrel_endcap_connected_tar_detids.insert(tar_detid); } } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h index b841ddd8b1b63..fb375a8ff2c93 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -25,8 +25,8 @@ namespace lstgeometry { } // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. - std::tuple, std::unordered_map> process_corners( - std::unordered_map corners) { + std::tuple, std::unordered_map> processCorners( + std::unordered_map& corners) { std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; diff --git a/RecoTracker/LSTCore/src/LSTGeometry.cc b/RecoTracker/LSTCore/src/LSTGeometry.cc deleted file mode 100644 index 7be5e3909910a..0000000000000 --- a/RecoTracker/LSTCore/src/LSTGeometry.cc +++ /dev/null @@ -1,9 +0,0 @@ -// This is just a placeholder file to see if the code compiles -// - -#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" \ No newline at end of file diff --git a/RecoTracker/LSTCore/standalone/.gitignore b/RecoTracker/LSTCore/standalone/.gitignore index 3d27afd0c4469..5925b5aefc296 100644 --- a/RecoTracker/LSTCore/standalone/.gitignore +++ b/RecoTracker/LSTCore/standalone/.gitignore @@ -15,6 +15,7 @@ bin/lst bin/lst_cuda bin/lst_cpu bin/lst_rocm +bin/lst_make_geometry code/rooutil/librooutil.so code/rooutil/rooutil.so .gitversion.txt diff --git a/RecoTracker/LSTCore/standalone/Makefile b/RecoTracker/LSTCore/standalone/Makefile index f06bf0bfffba4..7d29eefe4f446 100644 --- a/RecoTracker/LSTCore/standalone/Makefile +++ b/RecoTracker/LSTCore/standalone/Makefile @@ -1,6 +1,7 @@ # Simple makefile EXES := bin/lst_cpu bin/lst_cuda +GEOMETRY_EXES := bin/lst_make_geometry SOURCES=$(wildcard code/core/*.cc) OBJECTS_CPU=$(SOURCES:.cc=_cpu.o) @@ -10,7 +11,7 @@ OBJECTS=$(OBJECTS_CPU) $(OBJECTS_CUDA) $(OBJECTS_ROCM) CXX = g++ CXXFLAGS = -g -O2 -Wall -fPIC -Woverloaded-virtual -Wno-unused-function -fno-var-tracking -std=c++20 -INCLUDEFLAGS= -ILST -I$(shell pwd) -Icode -Icode/core -I${ALPAKA_ROOT}/include -I/${BOOST_ROOT}/include $(shell rooutil-config --include) -I$(shell root-config --incdir) -I${TRACKLOOPERDIR}/../../../ -I${CMSSW_BASE}/src -I${FMT_ROOT}/include -I../interface/ -I../interface/alpaka/ -I../src/ -I../src/alpaka/ +INCLUDEFLAGS= -ILST -I$(shell pwd) -Icode -Icode/core -I${ALPAKA_ROOT}/include -I/${BOOST_ROOT}/include -I/${EIGEN_ROOT}/include/eigen3 $(shell rooutil-config --include) -I$(shell root-config --incdir) -I${TRACKLOOPERDIR}/../../../ -I${CMSSW_BASE}/src -I${FMT_ROOT}/include -I../interface/ -I../interface/alpaka/ -I../src/ -I../src/alpaka/ ifdef CMSSW_RELEASE_BASE INCLUDEFLAGS:= ${INCLUDEFLAGS} -I${CMSSW_RELEASE_BASE}/src endif @@ -31,17 +32,17 @@ CUTVALUEFLAG_FLAGS = -DCUT_VALUE_DEBUG PRIMITIVEFLAG = PRIMITIVEFLAG_FLAGS = -DPRIMITIVE_STUDY -all: rooutil efficiency $(EXES) +all: rooutil efficiency $(GEOMETRY_EXES) $(EXES) cutvalue: CUTVALUEFLAG = ${CUTVALUEFLAG_FLAGS} -cutvalue: rooutil efficiency $(EXES) +cutvalue: rooutil efficiency $(GEOMETRY_EXES) $(EXES) primitive: PRIMITIVEFLAG = ${PRIMITIVEFLAG_FLAGS} -primitive: rooutil efficiency $(EXES) +primitive: rooutil efficiency $(GEOMETRY_EXES) $(EXES) cutvalue_primitive: CUTVALUEFLAG = ${CUTVALUEFLAG_FLAGS} cutvalue_primitive: PRIMITIVEFLAG = ${PRIMITIVEFLAG_FLAGS} -cutvalue_primitive: rooutil efficiency $(EXES) +cutvalue_primitive: rooutil efficiency $(GEOMETRY_EXES) $(EXES) bin/lst_cpu: LSTLIB=-llst_cpu @@ -61,6 +62,11 @@ bin/lst_rocm: bin/lst_rocm.o $(OBJECTS_ROCM) %_rocm.o: %.cc rooutil $(CXX) $(CXXFLAGS) $(EXTRAFLAGS) $(INCLUDEFLAGS) $(ALPAKAFLAGS) $(CUTVALUEFLAG) $(PRIMITIVEFLAG) $(DOQUINTUPLET) $(ALPAKA_ROCM) $(ROCMINCLUDE) $< -c -o $@ +bin/lst_make_geometry: bin/lst_make_geometry.o + $(CXX) $(LDFLAGS) $(EXTRAFLAGS) $(INCLUDEFLAGS) $(ALPAKAFLAGS) $^ -o $@ +%_geometry.o: %_geometry.cc + $(CXX) $(CXXFLAGS) $(INCLUDEFLAGS) $< -c -o $@ + rooutil: $(MAKE) -C code/rooutil/ diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc new file mode 100644 index 0000000000000..93c5dda3e74dd --- /dev/null +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -0,0 +1,81 @@ +#include + +#include "cxxopts.h" + +#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" + +using namespace lstgeometry; + +int main(int argc, char **argv) { + + cxxopts::Options options("\nLST Geometry\n\n"); + options.add_options()( + "module_info_file", + "The path to the csv file containing module information.", + cxxopts::value()->default_value("../data/module_info_OT800_IT711.csv"))( + "sensor_info_file", + "The path to the csv file containing sensor information.", + cxxopts::value()->default_value("../data/DetId_sensors_list_OT800_IT711.csv"))( + "average_r_file", + "The path to the text file containing the average r positions of the Barrel layers.", + cxxopts::value()->default_value("../data/average_r_OT800_IT711.txt"))( + "average_z_file", + "The path to the text file containing the average z positions of the Endcap layers.", + cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt")); + + auto result = options.parse(argc, argv); + + std::string module_info_file = result["module_info_file"].as(); + std::string sensor_info_file = result["sensor_info_file"].as(); + std::string average_r_file = result["average_r_file"].as(); + std::string average_z_file = result["average_z_file"].as(); + + auto modules_info = readModuleInfo(module_info_file); + auto sensors_info = readSensorInfo(sensor_info_file); + auto average_r = readAverages(average_r_file); + auto average_z = readAverages(average_z_file); + + for (auto& mod : modules_info) + transformSensorCorners(mod); + + auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); + + auto centroids = computeCentroids(sensors_info); + + auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); + + auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); + det_geom.buildByLayer(); + + auto pixel_map = computePixelMap(centroids, det_geom); + + auto detids_etaphi_layer_ref = det_geom.getDetIds( + [](const auto& x){ + auto mod = Module(x.first); + return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || + (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && + !(mod.ring() == 15 && mod.layer() == 1) && + !(mod.ring() == 15 && mod.layer() == 2) && + !(mod.ring() == 12 && mod.layer() == 3) && + !(mod.ring() == 12 && mod.layer() == 4) + )); + } + ); + + std::unordered_map> straight_line_connections; + std::unordered_map> curved_line_connections; + + for (auto ref_detid : detids_etaphi_layer_ref) { + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); + } + + std::cout << "Done!" << std::endl; + + return 0; +} \ No newline at end of file diff --git a/RecoTracker/LSTCore/standalone/setup.sh b/RecoTracker/LSTCore/standalone/setup.sh index f08180201192d..8b89aeba001f8 100644 --- a/RecoTracker/LSTCore/standalone/setup.sh +++ b/RecoTracker/LSTCore/standalone/setup.sh @@ -25,6 +25,7 @@ fi # Export paths to libraries we need export ALPAKA_ROOT=$(scram tool info alpaka | grep ALPAKA_BASE | cut -d'=' -f2) export BOOST_ROOT=$(scram tool info boost | grep BOOST_BASE | cut -d'=' -f2) +export EIGEN_ROOT=$(scram tool info eigen | grep EIGEN_BASE | cut -d'=' -f2) export CUDA_HOME=$(scram tool info cuda | grep CUDA_BASE | cut -d'=' -f2) export FMT_ROOT=$(scram tool info fmt | grep FMT_BASE | cut -d'=' -f2) export ROCM_ROOT=$(scram tool info rocm | grep ROCM_BASE | cut -d'=' -f2) From 2038d28627c31473bb4eb055d87e5aff87b0c25f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 Oct 2025 14:17:17 -0400 Subject: [PATCH 15/95] Added a couple of outputs --- .../interface/LSTGeometry/CentroidMethods.h | 5 +- .../interface/LSTGeometry/CornerMethods.h | 38 +++------- .../LSTCore/interface/LSTGeometry/IO.h | 69 +++++++++++++++++-- .../LSTGeometry/OrientationMethods.h | 6 +- .../standalone/bin/lst_make_geometry.cc | 9 ++- 5 files changed, 83 insertions(+), 44 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index f3a7e7d00b77f..0bd958706e541 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -51,10 +51,9 @@ namespace lstgeometry { } } - std::unordered_map computeCentroids(std::vector &sensors) { + std::unordered_map computeCentroids(std::unordered_map const& sensors) { std::unordered_map centroids; - for (const auto& sensor : sensors) { - unsigned int detId = sensor.detId; + for (auto const& [detId, sensor] : sensors) { int moduleType = parseModuleType(detId); // Remove sensors from inner tracker diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 143e1548e1172..19da85eae1f2c 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -108,8 +108,8 @@ namespace lstgeometry { } // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. - std::unordered_map assignCornersToSensors(std::vector& modules, - std::vector& sensors) { + std::unordered_map assignCornersToSensors(std::vector const& modules, + std::unordered_map const& sensors) { std::unordered_map transformed_corners_dict; for (auto const& moduleInfo : modules) { @@ -121,38 +121,16 @@ namespace lstgeometry { RowVectorD3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); RowVectorD3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); - bool found_sensor_1 = false; - bool found_sensor_2 = false; - unsigned int sensor_index_1 = 0; - unsigned int sensor_index_2 = 0; - - for (unsigned int i = 0; i < sensors.size(); i++) { - if (!found_sensor_1 && sensors[i].detId == sensor_det_id_1) { - sensor_index_1 = i; - found_sensor_1 = true; - } - if (!found_sensor_2 && sensors[i].detId == sensor_det_id_2) { - sensor_index_2 = i; - found_sensor_2 = true; - } - if (found_sensor_1 && found_sensor_2) - break; - } - - if (!found_sensor_1 || !found_sensor_2) { - throw std::runtime_error("Sensor not found"); - } - - double sensor1_center_z = sensors[sensor_index_1].sensorCenterZ_mm; + double sensor1_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_mm; double sensor1_center_x = - sensors[sensor_index_1].sensorCenterRho_mm * cos(degToRad(sensors[sensor_index_1].phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(degToRad(sensors.at(sensor_det_id_1).phi_deg)); double sensor1_center_y = - sensors[sensor_index_1].sensorCenterRho_mm * sin(degToRad(sensors[sensor_index_1].phi_deg)); - double sensor2_center_z = sensors[sensor_index_2].sensorCenterZ_mm; + sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(degToRad(sensors.at(sensor_det_id_1).phi_deg)); + double sensor2_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_mm; double sensor2_center_x = - sensors[sensor_index_2].sensorCenterRho_mm * cos(degToRad(sensors[sensor_index_2].phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(degToRad(sensors.at(sensor_det_id_1).phi_deg)); double sensor2_center_y = - sensors[sensor_index_2].sensorCenterRho_mm * sin(degToRad(sensors[sensor_index_2].phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(degToRad(sensors.at(sensor_det_id_1).phi_deg)); RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 8924c55d66b3e..0676d92b3044a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -1,6 +1,7 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_IO_h #define RecoTracker_LSTCore_interface_LSTGeometry_IO_h +#include "Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" @@ -12,7 +13,7 @@ namespace lstgeometry { - std::string trim(const std::string& str) { + std::string trim(std::string const& str) { size_t first = str.find_first_not_of(" \t\r\n"); if (first == std::string::npos) return ""; @@ -20,7 +21,7 @@ namespace lstgeometry { return str.substr(first, (last - first + 1)); } - std::vector parseCSVLine(const std::string& line) { + std::vector parseCSVLine(std::string const& line) { std::vector tokens; std::stringstream ss(line); std::string token; @@ -32,7 +33,7 @@ namespace lstgeometry { return tokens; } - std::vector readModuleInfo(const std::string& filename) { + std::vector readModuleInfo(std::string const& filename) { std::vector modules; std::string line; std::ifstream file(filename); @@ -84,8 +85,8 @@ namespace lstgeometry { return modules; } - std::vector readSensorInfo(const std::string& filename) { - std::vector sensors; + std::unordered_map readSensorInfo(std::string const& filename) { + std::unordered_map sensors; std::string line; std::ifstream file(filename); @@ -115,13 +116,13 @@ namespace lstgeometry { s.sensorCenterZ_mm = std::stod(tokens[6]); s.phi_deg = std::stod(tokens[7]); - sensors.push_back(s); + sensors[s.detId] = s; } return sensors; } - std::vector readAverages(const std::string& filename) { + std::vector readAverages(std::string const& filename) { std::vector averages; std::string line; std::ifstream file(filename); @@ -143,6 +144,60 @@ namespace lstgeometry { return averages; } + + void writeCentroids(std::unordered_map const& centroids, std::string const& filename, bool binary = true) { + std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); + + if(binary) { + for (auto& [detid, centroid] : centroids) { + float x = centroid.x; + float y = centroid.y; + float z = centroid.z; + unsigned int moduleType = centroid.moduleType; + file.write(reinterpret_cast(&detid), sizeof(detid)); + file.write(reinterpret_cast(&x), sizeof(x)); + file.write(reinterpret_cast(&y), sizeof(y)); + file.write(reinterpret_cast(&z), sizeof(z)); + file.write(reinterpret_cast(&moduleType), sizeof(moduleType)); + } + } else { + for (auto& [detid, centroid] : centroids) { + file << detid << "," << centroid.x << "," << centroid.y << "," << centroid.z << "," << centroid.moduleType << std::endl; + } + } + } + + void writeSlopes(std::unordered_map const& slopes, std::unordered_map const& sensors, std::string const& filename, bool binary = true) { + std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); + + if(binary) { + for (auto& [detid, slope] : slopes) { + float drdz_slope = slope.drdz_slope; + float dxdy_slope = slope.dxdy_slope; + float phi = degToRad(sensors.at(detid).phi_deg); + file.write(reinterpret_cast(&detid), sizeof(detid)); + if (drdz_slope != kDefaultSlope) { + file.write(reinterpret_cast(&drdz_slope), sizeof(drdz_slope)); + file.write(reinterpret_cast(&dxdy_slope), sizeof(dxdy_slope)); + } else { + file.write(reinterpret_cast(&dxdy_slope), sizeof(dxdy_slope)); + file.write(reinterpret_cast(&phi), sizeof(phi)); + } + } + } else { + for (auto& [detid, slope] : slopes) { + float drdz_slope = slope.drdz_slope; + float dxdy_slope = slope.dxdy_slope; + float phi = degToRad(sensors.at(detid).phi_deg); + file << detid << ","; + if (drdz_slope != kDefaultSlope) { + file << drdz_slope << "," << dxdy_slope << std::endl; + } else { + file << dxdy_slope << "," << phi << std::endl; + } + } + } + } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h index fb375a8ff2c93..ab6b4d9650049 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -13,15 +13,15 @@ namespace lstgeometry { struct SlopeData { double drdz_slope; - double drdy_slope; + double dxdy_slope; }; // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. SlopeData calculateSlope(double dx, double dy, double dz) { double dr = sqrt(dx * dx + dy * dy); double drdz_slope = dz != 0 ? dr / dz : kDefaultSlope; - double drdy_slope = dy != 0 ? -dx / dy : kDefaultSlope; - return SlopeData{drdz_slope, drdy_slope}; + double dxdy_slope = dy != 0 ? -dx / dy : kDefaultSlope; + return SlopeData{drdz_slope, dxdy_slope}; } // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 93c5dda3e74dd..0488c3d99a600 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -26,7 +26,10 @@ int main(int argc, char **argv) { cxxopts::value()->default_value("../data/average_r_OT800_IT711.txt"))( "average_z_file", "The path to the text file containing the average z positions of the Endcap layers.", - cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt")); + cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt"))( + "output_dir", + "The path to the output directory.", + cxxopts::value()->default_value("../data/")); auto result = options.parse(argc, argv); @@ -34,6 +37,7 @@ int main(int argc, char **argv) { std::string sensor_info_file = result["sensor_info_file"].as(); std::string average_r_file = result["average_r_file"].as(); std::string average_z_file = result["average_z_file"].as(); + std::string output_dir = result["output_dir"].as(); auto modules_info = readModuleInfo(module_info_file); auto sensors_info = readSensorInfo(sensor_info_file); @@ -46,8 +50,11 @@ int main(int argc, char **argv) { auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); auto centroids = computeCentroids(sensors_info); + writeCentroids(centroids, output_dir + "output_centroids.bin", false); auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); + writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation.bin", false); + writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation.bin", false); auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); det_geom.buildByLayer(); From 61e33ea2b76a01c5be698ba021ec1430dab4f26a Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 09:21:16 -0400 Subject: [PATCH 16/95] Write module maps --- .../LSTCore/interface/LSTGeometry/IO.h | 23 +++++++++++++++++++ .../interface/LSTGeometry/ModuleMapMethods.h | 16 +++++++++++++ .../standalone/bin/lst_make_geometry.cc | 16 +++++++++++++ 3 files changed, 55 insertions(+) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 0676d92b3044a..3c92662e981f6 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -198,6 +198,29 @@ namespace lstgeometry { } } } + + void writeModuleConnections(std::unordered_map> const& connections, std::string const& filename, bool binary = true) { + std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); + + if(binary) { + for (auto& [detid, set] : connections) { + file.write(reinterpret_cast(&detid), sizeof(detid)); + unsigned int length = set.size(); + file.write(reinterpret_cast(&length), sizeof(length)); + for (unsigned int i : set) { + file.write(reinterpret_cast(&i), sizeof(i)); + } + } + } else { + for (auto& [detid, set] : connections) { + file << detid << "," << set.size(); + for (unsigned int i : set) { + file << "," << i; + } + file << std::endl; + } + } + } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 0e9a0a7ff3bfb..f84c3b50250f8 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -272,6 +274,20 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } + + std::unordered_map> + mergeLineConnections(std::initializer_list>*> connections_list) { + std::unordered_map> merged; + + for (auto* connections : connections_list) { + for (const auto& [detid, list] : *connections) { + auto& target = merged[detid]; + target.insert(list.begin(), list.end()); + } + } + + return merged; + } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 0488c3d99a600..de48cb3b9e15c 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -44,23 +44,36 @@ int main(int argc, char **argv) { auto average_r = readAverages(average_r_file); auto average_z = readAverages(average_z_file); + std::cout << "Transforming corners" << std::endl; for (auto& mod : modules_info) transformSensorCorners(mod); + std::cout << "Transforming corners done" << std::endl; + std::cout << "Assigning corners" << std::endl; auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); + std::cout << "Assigning corners done" << std::endl; + std::cout << "Computing centroids" << std::endl; auto centroids = computeCentroids(sensors_info); writeCentroids(centroids, output_dir + "output_centroids.bin", false); + std::cout << "Computing centroids done" << std::endl; + std::cout << "Processing corners" << std::endl; auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation.bin", false); writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation.bin", false); + std::cout << "Processing corners done" << std::endl; + std::cout << "Building detector geometry" << std::endl; auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); det_geom.buildByLayer(); + std::cout << "Building detector geometry done" << std::endl; + std::cout << "Computing pixel map" << std::endl; auto pixel_map = computePixelMap(centroids, det_geom); + std::cout << "Computing pixel map done" << std::endl; + std::cout << "Computing module maps" << std::endl; auto detids_etaphi_layer_ref = det_geom.getDetIds( [](const auto& x){ auto mod = Module(x.first); @@ -81,6 +94,9 @@ int main(int argc, char **argv) { straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); } + auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); + writeModuleConnections(merged_line_connections, output_dir + "module_connection_tracing_merged.bin", false); + std::cout << "Computing module maps done" << std::endl; std::cout << "Done!" << std::endl; From 0d505667435302aafa20b9cedaa960962846df00 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 10:36:13 -0400 Subject: [PATCH 17/95] Some progress, but need to switch to gcc13 --- .../LSTCore/interface/LSTGeometry/Common.h | 6 +++ .../LSTCore/interface/LSTGeometry/IO.h | 41 +++++++++++++++++-- .../interface/LSTGeometry/PixelMapMethods.h | 41 ++++++++----------- 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 5c33044604bc4..8a1ae46f6115a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -20,6 +20,12 @@ namespace lstgeometry { constexpr double kPtThreshold = 0.8; constexpr double k2Rinv1GeVf = 0.00299792458; constexpr double kB = 3.8112; + + // For pixel maps + constexpr unsigned int kNEta = 25; + constexpr unsigned int kNPhi = 72; + constexpr unsigned int kNZ = 25; + constexpr std::array kPtBounds = {{kPtThreshold, 2.0, 10'000.0}}; // This is defined as a constant in case the legacy value (123456789) needs to be used double kDefaultSlope = std::numeric_limits::infinity(); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 3c92662e981f6..b52e5ae64e2b0 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -4,12 +4,15 @@ #include "Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" #include #include #include #include #include +#include +#include namespace lstgeometry { @@ -145,7 +148,8 @@ namespace lstgeometry { return averages; } - void writeCentroids(std::unordered_map const& centroids, std::string const& filename, bool binary = true) { + void writeCentroids(std::unordered_map const& centroids, std::string const& base_filename, bool binary = true) { + std::string filename = base_filename + (binary ? ".bin" : ".txt"); std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if(binary) { @@ -167,7 +171,8 @@ namespace lstgeometry { } } - void writeSlopes(std::unordered_map const& slopes, std::unordered_map const& sensors, std::string const& filename, bool binary = true) { + void writeSlopes(std::unordered_map const& slopes, std::unordered_map const& sensors, std::string const& base_filename, bool binary = true) { + std::string filename = base_filename + (binary ? ".bin" : ".txt"); std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if(binary) { @@ -199,7 +204,8 @@ namespace lstgeometry { } } - void writeModuleConnections(std::unordered_map> const& connections, std::string const& filename, bool binary = true) { + void writeModuleConnections(std::unordered_map> const& connections, std::string const& base_filename, bool binary = true) { + std::string filename = base_filename + (binary ? ".bin" : ".txt"); std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if(binary) { @@ -221,6 +227,35 @@ namespace lstgeometry { } } } + + void writePixelMaps(PixelMap const& maps, std::string const& base_filename, bool binary = true) { + std::filesystem::path filepath(base_filename); + std::filesystem::create_directories(filepath.parent_path()); + + if(binary) { + for (auto& [layersubdet, map] : maps) { + auto& [layer, subdet] = layersubdet; + + std::string filename_all = std::format("{}_layer{}_subdet{}.bin", base_filename, layer, subdet); + std::string filename_pos = std::format("{}_pos_layer{}_subdet{}.bin", base_filename, layer, subdet); + std::string filename_neg = std::format("{}_neg_layer{}_subdet{}.bin", base_filename, layer, subdet); + + std::ofstream file_all(filename_all, std::ios::binary); + std::ofstream file_pos(filename_pos, std::ios::binary); + std::ofstream file_neg(filename_neg, std::ios::binary); + + for (auto& [key, list] : map) { + auto& [ipt, ieta, iphi, iz, charge] = key; + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + + } + } + } else { + for (auto& [layersubdet, map] : maps) { + + } + } + } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index 7e6598da53c9c..89142958fe0ea 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -1,9 +1,9 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h #define RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h -#include #include #include +#include #include #include @@ -16,31 +16,26 @@ namespace lstgeometry { using PtEtaPhiZChargeKey = std::tuple; using LayerSubdetKey = std::tuple; - using LayerSubdetMap = std::unordered_map, boost::hash>; - using PtEtaPhiZChargeMap = std::unordered_map>; + using PtEtaPhiZChargeMap = std::unordered_map, boost::hash>; + using LayerSubdetMap = std::unordered_map>; + using PixelMap = LayerSubdetMap; - PtEtaPhiZChargeMap computePixelMap(std::unordered_map const& centroids, + PixelMap computePixelMap(std::unordered_map const& centroids, DetectorGeometry const& det_geom) { - constexpr unsigned int kNEta = 25; - constexpr unsigned int kNPhi = 72; - constexpr unsigned int kNZ = 25; - constexpr std::array kPtBounds = {{kPtThreshold, 2.0, 10'000.0}}; - PtEtaPhiZChargeMap maps; + LayerSubdetMap maps; // Initialize empty lists for the pixel map - for (unsigned int ipt = 0; ipt < kPtBounds.size() - 1; ipt++) { - for (unsigned int ieta = 0; ieta < kNEta; ieta++) { - for (unsigned int iphi = 0; iphi < kNPhi; iphi++) { - for (unsigned int iz = 0; iz < kNZ; iz++) { - maps[{ipt, ieta, iphi, iz, 1}] = LayerSubdetMap(); - maps[{ipt, ieta, iphi, iz, -1}] = LayerSubdetMap(); - auto& map_pos = maps.at({ipt, ieta, iphi, iz, 1}); - auto& map_neg = maps.at({ipt, ieta, iphi, iz, -1}); - for (unsigned int layer : {1, 2}) { - for (unsigned int subdet : {4, 5}) { - map_pos[{layer, subdet}] = {}; - map_neg[{layer, subdet}] = {}; + for (unsigned int layer : {1, 2}) { + for (unsigned int subdet : {4, 5}) { + maps[{layer, subdet}] = PtEtaPhiZChargeMap(); + auto& map = maps.at({layer, subdet}); + for (unsigned int ipt = 0; ipt < kPtBounds.size() - 1; ipt++) { + for (unsigned int ieta = 0; ieta < kNEta; ieta++) { + for (unsigned int iphi = 0; iphi < kNPhi; iphi++) { + for (unsigned int iz = 0; iz < kNZ; iz++) { + map.try_emplace({ipt, ieta, iphi, iz, 1}); + map.try_emplace({ipt, ieta, iphi, iz, -1}); } } } @@ -114,10 +109,10 @@ namespace lstgeometry { for (unsigned int ieta = ietamin; ieta <= ietamax; ieta++) { for (unsigned int iphi = phibins_pos_start; iphi < phibins_pos_end; iphi++) { - maps[{ipt, ieta, iphi, iz, 1}][{layer, subdet}].push_back(detId); + maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); } for (unsigned int iphi = phibins_neg_start; iphi < phibins_neg_end; iphi++) { - maps[{ipt, ieta, iphi, iz, 1}][{layer, subdet}].push_back(detId); + maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); } } } From 33ec364ad2bc4a8e3411b12675f3769ec6d058ae Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 18:14:57 +0000 Subject: [PATCH 18/95] Write pixel maps --- .../LSTCore/interface/LSTGeometry/IO.h | 34 ++++++++++++++++++- .../interface/LSTGeometry/PixelMapMethods.h | 2 +- .../standalone/bin/lst_make_geometry.cc | 9 ++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index b52e5ae64e2b0..e9c784c54a14d 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -244,15 +244,47 @@ namespace lstgeometry { std::ofstream file_pos(filename_pos, std::ios::binary); std::ofstream file_neg(filename_neg, std::ios::binary); - for (auto& [key, list] : map) { + for (auto& [key, set] : map) { auto& [ipt, ieta, iphi, iz, charge] = key; unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + file_all.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); + (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); + unsigned int length = set.size(); + file_all.write(reinterpret_cast(&length), sizeof(length)); + (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&length), sizeof(length)); + for (unsigned int i : set) { + file_all.write(reinterpret_cast(&i), sizeof(i)); + (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&i), sizeof(i)); + } } } } else { for (auto& [layersubdet, map] : maps) { + auto& [layer, subdet] = layersubdet; + std::string filename_all = std::format("{}_layer{}_subdet{}.txt", base_filename, layer, subdet); + std::string filename_pos = std::format("{}_pos_layer{}_subdet{}.txt", base_filename, layer, subdet); + std::string filename_neg = std::format("{}_neg_layer{}_subdet{}.txt", base_filename, layer, subdet); + + std::ofstream file_all(filename_all); + std::ofstream file_pos(filename_pos); + std::ofstream file_neg(filename_neg); + + for (auto& [key, set] : map) { + auto& [ipt, ieta, iphi, iz, charge] = key; + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + + unsigned int length = set.size(); + file_all << isuperbin << "," << length; + (charge > 0 ? file_pos : file_neg) << isuperbin << "," << length; + for (unsigned int i : set) { + file_all << "," << i; + (charge > 0 ? file_pos : file_neg) << "," << i; + } + file_all << std::endl; + (charge > 0 ? file_pos : file_neg) << std::endl; + } } } } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index 89142958fe0ea..5327be813a0fd 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -112,7 +112,7 @@ namespace lstgeometry { maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); } for (unsigned int iphi = phibins_neg_start; iphi < phibins_neg_end; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); } } } diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index de48cb3b9e15c..4cfb28a21b754 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -55,13 +55,13 @@ int main(int argc, char **argv) { std::cout << "Computing centroids" << std::endl; auto centroids = computeCentroids(sensors_info); - writeCentroids(centroids, output_dir + "output_centroids.bin", false); + writeCentroids(centroids, output_dir + "sensor_centroids", false); std::cout << "Computing centroids done" << std::endl; std::cout << "Processing corners" << std::endl; auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); - writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation.bin", false); - writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation.bin", false); + writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation", false); + writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation", false); std::cout << "Processing corners done" << std::endl; std::cout << "Building detector geometry" << std::endl; @@ -71,6 +71,7 @@ int main(int argc, char **argv) { std::cout << "Computing pixel map" << std::endl; auto pixel_map = computePixelMap(centroids, det_geom); + writePixelMaps(pixel_map, output_dir + "pixelmap/pLS_map", false); std::cout << "Computing pixel map done" << std::endl; std::cout << "Computing module maps" << std::endl; @@ -95,7 +96,7 @@ int main(int argc, char **argv) { curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); } auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); - writeModuleConnections(merged_line_connections, output_dir + "module_connection_tracing_merged.bin", false); + writeModuleConnections(merged_line_connections, output_dir + "module_connection_tracing_merged", false); std::cout << "Computing module maps done" << std::endl; std::cout << "Done!" << std::endl; From 074e368bcb99721f25e9f48ef5d9f93bfab22f8c Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 16:16:29 -0400 Subject: [PATCH 19/95] Fixed pixel maps --- .../LSTCore/interface/LSTGeometry/Common.h | 2 +- .../interface/LSTGeometry/DetectorGeometry.h | 16 ++++----- .../LSTCore/interface/LSTGeometry/IO.h | 29 +++++++++++---- .../interface/LSTGeometry/PixelMapMethods.h | 35 +++++++++++++------ 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 8a1ae46f6115a..f3e553c4a9381 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -33,7 +33,7 @@ namespace lstgeometry { double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } double phi_mpi_pi(double phi) { - while (phi > std::numbers::pi_v) + while (phi >= std::numbers::pi_v) phi -= 2 * std::numbers::pi_v; while (phi < -std::numbers::pi_v) phi += 2 * std::numbers::pi_v; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 41e73e169f3d0..999cc442ae313 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -90,7 +90,7 @@ namespace lstgeometry { return maxR; } - double getMinz(unsigned int detId) const { + double getMinZ(unsigned int detId) const { auto const& corners = corners_.at(detId); double minZ = std::numeric_limits::max(); for (int i = 0; i < corners.rows(); i++) { @@ -100,9 +100,9 @@ namespace lstgeometry { return minZ; } - double getMaxz(unsigned int detId) const { + double getMaxZ(unsigned int detId) const { auto const& corners = corners_.at(detId); - double maxZ = std::numeric_limits::min(); + double maxZ = std::numeric_limits::lowest(); for (int i = 0; i < corners.rows(); i++) { double z = corners(i, 0); maxZ = std::max(maxZ, z); @@ -139,9 +139,9 @@ namespace lstgeometry { double getMaxPhi(unsigned int detId) const { auto const& corners = corners_.at(detId); - double maxPhi = std::numeric_limits::min(); - double maxPosPhi = std::numeric_limits::min(); - double maxNegPhi = std::numeric_limits::min(); + double maxPhi = std::numeric_limits::lowest(); + double maxPosPhi = std::numeric_limits::lowest(); + double maxNegPhi = std::numeric_limits::lowest(); unsigned int nPos = 0; unsigned int nOverPi2 = 0; for (int i = 0; i < corners.rows(); i++) { @@ -167,8 +167,8 @@ namespace lstgeometry { std::pair getCompatibleEtaRange(unsigned int detId, double zmin_bound, double zmax_bound) const { double minr = getMinR(detId); double maxr = getMaxR(detId); - double minz = getMinz(detId); - double maxz = getMaxz(detId); + double minz = getMinZ(detId); + double maxz = getMaxZ(detId); double mineta = -std::log(std::tan(std::atan2(minz > 0 ? maxr : minr, minz - zmin_bound) / 2.)); double maxeta = -std::log(std::tan(std::atan2(maxz > 0 ? minr : maxr, maxz - zmax_bound) / 2.)); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index e9c784c54a14d..d92b880262f41 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -248,15 +248,23 @@ namespace lstgeometry { auto& [ipt, ieta, iphi, iz, charge] = key; unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - file_all.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); unsigned int length = set.size(); - file_all.write(reinterpret_cast(&length), sizeof(length)); (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&length), sizeof(length)); for (unsigned int i : set) { - file_all.write(reinterpret_cast(&i), sizeof(i)); (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&i), sizeof(i)); } + if (charge > 0) { + file_all.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); + auto full_set = std::set(set.begin(), set.end()); + auto& negative_set = map.at({ipt, ieta, iphi, iz, -1}); + full_set.insert(negative_set.begin(), negative_set.end()); + unsigned int full_length = full_set.size(); + file_all.write(reinterpret_cast(&full_length), sizeof(full_length)); + for (unsigned int i : full_set) { + file_all.write(reinterpret_cast(&i), sizeof(i)); + } + } } } } else { @@ -276,14 +284,23 @@ namespace lstgeometry { unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; unsigned int length = set.size(); - file_all << isuperbin << "," << length; (charge > 0 ? file_pos : file_neg) << isuperbin << "," << length; for (unsigned int i : set) { - file_all << "," << i; (charge > 0 ? file_pos : file_neg) << "," << i; } - file_all << std::endl; (charge > 0 ? file_pos : file_neg) << std::endl; + if (charge > 0) {; + auto full_set = std::set(set.begin(), set.end()); + auto& negative_set = map.at({ipt, ieta, iphi, iz, -1}); + full_set.insert(negative_set.begin(), negative_set.end()); + unsigned int full_length = full_set.size(); + file_all << isuperbin << "," << full_length; + for (unsigned int i : full_set) { + file_all << "," << i; + } + file_all << std::endl; + } + } } } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index 5327be813a0fd..edc57932b183c 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -89,7 +89,7 @@ namespace lstgeometry { // Compute the indices of the compatible eta range unsigned int ietamin = static_cast(std::max((etamin + 2.6) / (5.2 / kNEta), 0.0)); unsigned int ietamax = - static_cast(std::min((etamax + 2.6) / (5.2 / kNEta), static_cast(kNEta))); + static_cast(std::min((etamax + 2.6) / (5.2 / kNEta), static_cast(kNEta-1))); auto phi_ranges = det_geom.getCompatiblePhiRange(detId, pt_lo, pt_hi); @@ -102,17 +102,32 @@ namespace lstgeometry { int iphimax_neg = static_cast((phi_ranges.second.second + std::numbers::pi_v) / (2. * std::numbers::pi_v / kNPhi)); - unsigned int phibins_pos_start = iphimin_pos <= iphimax_pos ? iphimin_pos : 0; - unsigned int phibins_pos_end = iphimin_pos <= iphimax_pos ? iphimax_pos : kNPhi; - unsigned int phibins_neg_start = iphimin_neg <= iphimax_neg ? iphimin_neg : 0; - unsigned int phibins_neg_end = iphimin_neg <= iphimax_neg ? iphimax_neg : kNPhi; - + // <= to cover some inefficiencies for (unsigned int ieta = ietamin; ieta <= ietamax; ieta++) { - for (unsigned int iphi = phibins_pos_start; iphi < phibins_pos_end; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + // if the range is crossing the -pi v. pi boundary special care is needed + if (iphimin_pos <= iphimax_pos) { + for (unsigned int iphi = iphimin_pos; iphi < iphimax_pos; iphi++) { + maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + } + } else { + for (unsigned int iphi = 0; iphi < iphimax_pos; iphi++) { + maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + } + for (unsigned int iphi = iphimin_pos; iphi < kNPhi; iphi++) { + maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + } } - for (unsigned int iphi = phibins_neg_start; iphi < phibins_neg_end; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + if (iphimin_neg <= iphimax_neg) { + for (unsigned int iphi = iphimin_neg; iphi < iphimax_neg; iphi++) { + maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + } + } else { + for (unsigned int iphi = 0; iphi < iphimax_neg; iphi++) { + maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + } + for (unsigned int iphi = iphimin_neg; iphi < kNPhi; iphi++) { + maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + } } } } From 03b24e69fc0317fcf789700f8c3d09fb456b435e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 27 Oct 2025 12:10:08 -0400 Subject: [PATCH 20/95] Simplify pixel maps creation --- .../LSTCore/interface/LSTGeometry/IO.h | 71 ++++++------------- .../interface/LSTGeometry/PixelMapMethods.h | 52 +++++++------- 2 files changed, 48 insertions(+), 75 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index d92b880262f41..d7ebfc35aa649 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -233,74 +233,43 @@ namespace lstgeometry { std::filesystem::create_directories(filepath.parent_path()); if(binary) { - for (auto& [layersubdet, map] : maps) { - auto& [layer, subdet] = layersubdet; + for (auto& [layersubdetcharge, map] : maps) { + auto& [layer, subdet, charge] = layersubdetcharge; - std::string filename_all = std::format("{}_layer{}_subdet{}.bin", base_filename, layer, subdet); - std::string filename_pos = std::format("{}_pos_layer{}_subdet{}.bin", base_filename, layer, subdet); - std::string filename_neg = std::format("{}_neg_layer{}_subdet{}.bin", base_filename, layer, subdet); + std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); + std::string filename = std::format("{}{}_layer{}_subdet{}.bin", base_filename, charge_str, layer, subdet); - std::ofstream file_all(filename_all, std::ios::binary); - std::ofstream file_pos(filename_pos, std::ios::binary); - std::ofstream file_neg(filename_neg, std::ios::binary); + std::ofstream file(filename, std::ios::binary); - for (auto& [key, set] : map) { - auto& [ipt, ieta, iphi, iz, charge] = key; - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { + auto const& set = map.at(isuperbin); - (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); + file.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); unsigned int length = set.size(); - (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&length), sizeof(length)); + file.write(reinterpret_cast(&length), sizeof(length)); for (unsigned int i : set) { - (charge > 0 ? file_pos : file_neg).write(reinterpret_cast(&i), sizeof(i)); - } - if (charge > 0) { - file_all.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); - auto full_set = std::set(set.begin(), set.end()); - auto& negative_set = map.at({ipt, ieta, iphi, iz, -1}); - full_set.insert(negative_set.begin(), negative_set.end()); - unsigned int full_length = full_set.size(); - file_all.write(reinterpret_cast(&full_length), sizeof(full_length)); - for (unsigned int i : full_set) { - file_all.write(reinterpret_cast(&i), sizeof(i)); - } + file.write(reinterpret_cast(&i), sizeof(i)); } } } } else { - for (auto& [layersubdet, map] : maps) { - auto& [layer, subdet] = layersubdet; + for (auto& [layersubdetcharge, map] : maps) { + auto& [layer, subdet, charge] = layersubdetcharge; - std::string filename_all = std::format("{}_layer{}_subdet{}.txt", base_filename, layer, subdet); - std::string filename_pos = std::format("{}_pos_layer{}_subdet{}.txt", base_filename, layer, subdet); - std::string filename_neg = std::format("{}_neg_layer{}_subdet{}.txt", base_filename, layer, subdet); + std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); + std::string filename = std::format("{}{}_layer{}_subdet{}.txt", base_filename, charge_str, layer, subdet); - std::ofstream file_all(filename_all); - std::ofstream file_pos(filename_pos); - std::ofstream file_neg(filename_neg); + std::ofstream file(filename); - for (auto& [key, set] : map) { - auto& [ipt, ieta, iphi, iz, charge] = key; - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { + auto const& set = map.at(isuperbin); unsigned int length = set.size(); - (charge > 0 ? file_pos : file_neg) << isuperbin << "," << length; + file << isuperbin << "," << length; for (unsigned int i : set) { - (charge > 0 ? file_pos : file_neg) << "," << i; - } - (charge > 0 ? file_pos : file_neg) << std::endl; - if (charge > 0) {; - auto full_set = std::set(set.begin(), set.end()); - auto& negative_set = map.at({ipt, ieta, iphi, iz, -1}); - full_set.insert(negative_set.begin(), negative_set.end()); - unsigned int full_length = full_set.size(); - file_all << isuperbin << "," << full_length; - for (unsigned int i : full_set) { - file_all << "," << i; - } - file_all << std::endl; + file << "," << i; } - + file << std::endl; } } } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index edc57932b183c..a1cea4abe00db 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -14,31 +14,23 @@ namespace lstgeometry { - using PtEtaPhiZChargeKey = std::tuple; - using LayerSubdetKey = std::tuple; - using PtEtaPhiZChargeMap = std::unordered_map, boost::hash>; - using LayerSubdetMap = std::unordered_map>; - using PixelMap = LayerSubdetMap; + using LayerSubdetChargeKey = std::tuple; + using LayerSubdetChargeMap = std::unordered_map>, boost::hash>; + using PixelMap = LayerSubdetChargeMap; PixelMap computePixelMap(std::unordered_map const& centroids, DetectorGeometry const& det_geom) { - - LayerSubdetMap maps; + + // Charge 0 is the union of charge 1 and charge -1 + PixelMap maps; + + std::size_t nSuperbin = (kPtBounds.size()-1) * kNPhi * kNEta * kNZ; // Initialize empty lists for the pixel map for (unsigned int layer : {1, 2}) { for (unsigned int subdet : {4, 5}) { - maps[{layer, subdet}] = PtEtaPhiZChargeMap(); - auto& map = maps.at({layer, subdet}); - for (unsigned int ipt = 0; ipt < kPtBounds.size() - 1; ipt++) { - for (unsigned int ieta = 0; ieta < kNEta; ieta++) { - for (unsigned int iphi = 0; iphi < kNPhi; iphi++) { - for (unsigned int iz = 0; iz < kNZ; iz++) { - map.try_emplace({ipt, ieta, iphi, iz, 1}); - map.try_emplace({ipt, ieta, iphi, iz, -1}); - } - } - } + for (int charge : {-1, 0, 1}) { + maps.try_emplace({layer, subdet, charge}, nSuperbin); } } } @@ -107,26 +99,38 @@ namespace lstgeometry { // if the range is crossing the -pi v. pi boundary special care is needed if (iphimin_pos <= iphimax_pos) { for (unsigned int iphi = iphimin_pos; iphi < iphimax_pos; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, 1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); } } else { for (unsigned int iphi = 0; iphi < iphimax_pos; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, 1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); } for (unsigned int iphi = iphimin_pos; iphi < kNPhi; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, 1}].insert(detId); + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, 1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); } } if (iphimin_neg <= iphimax_neg) { for (unsigned int iphi = iphimin_neg; iphi < iphimax_neg; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, -1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); } } else { for (unsigned int iphi = 0; iphi < iphimax_neg; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, -1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); } for (unsigned int iphi = iphimin_neg; iphi < kNPhi; iphi++) { - maps[{layer, subdet}][{ipt, ieta, iphi, iz, -1}].insert(detId); + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, -1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); } } } From b78a982d37fe94c98c2a01826afd194ca9434c11 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 27 Oct 2025 16:56:14 -0400 Subject: [PATCH 21/95] Fixed straight line connections --- RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h | 7 +++++-- .../LSTCore/interface/LSTGeometry/ModuleMapMethods.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index ae9109409d68e..9295aa1d0e6f4 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -100,6 +100,7 @@ namespace lstgeometry { boost::geometry::append(poly, Point(mod_boundaries_etaphi(i % npoints, 0), mod_boundaries_etaphi(i % npoints, 1))); } + boost::geometry::correct(poly); return poly; } @@ -122,8 +123,8 @@ namespace lstgeometry { MatrixD4x2 tar_mod_boundaries_etaphi; for (int i = 0; i < 4; ++i) { - auto ref_etaphi = getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0), refphi); - auto tar_etaphi = getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0), refphi); + auto ref_etaphi = getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0)+zshift, refphi); + auto tar_etaphi = getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0)+zshift, refphi); ref_mod_boundaries_etaphi(i, 0) = ref_etaphi.first; ref_mod_boundaries_etaphi(i, 1) = ref_etaphi.second; tar_mod_boundaries_etaphi(i, 0) = tar_etaphi.first; @@ -146,6 +147,8 @@ namespace lstgeometry { boost::geometry::append(tar_poly, Point(tar_mod_boundaries_etaphi(i % 4, 0), tar_mod_boundaries_etaphi(i % 4, 1))); } + boost::geometry::correct(ref_poly); + boost::geometry::correct(tar_poly); return boost::geometry::intersects(ref_poly, tar_poly); } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index f84c3b50250f8..b3103e1266ab5 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -209,7 +209,7 @@ namespace lstgeometry { std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { - if (moduleOverlapsInEtaPhi(det_geom.getCorners(ref_detid), det_geom.getCorners(tar_detid), refphi, 0)) + if (moduleOverlapsInEtaPhi(next_layer_bound_points_matrix, det_geom.getCorners(tar_detid), refphi, 0)) list_of_detids_etaphi_layer_tar.push_back(tar_detid); } From d3dba4069ff76af987f16e95413b604dee748e08 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 28 Oct 2025 14:07:36 -0400 Subject: [PATCH 22/95] Fixed curved line connections --- .../LSTCore/interface/LSTGeometry/LSTMath.h | 2 +- .../interface/LSTGeometry/ModuleMapMethods.h | 23 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index 9295aa1d0e6f4..b2e75b44554f2 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -59,7 +59,7 @@ namespace lstgeometry { std::tuple getHelixPointFromZ(Helix const& helix, double target_z) { auto objective_function = [&helix, target_z](double t) { double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; - return std::fabs(std::sqrt(z * z) - target_z); + return std::fabs(z - target_z); }; int bits = std::numeric_limits::digits; auto result = boost::math::tools::brent_find_minima(objective_function, 0.0, std::numbers::pi_v, bits); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index b3103e1266ab5..4407ef26f4b05 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -105,7 +105,7 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } - std::vector> boundsAfterCurved( + MatrixD4x3 boundsAfterCurved( unsigned int ref_detid, std::unordered_map const& centroids, DetectorGeometry const& det_geom, @@ -114,12 +114,12 @@ namespace lstgeometry { auto centroid = centroids.at(ref_detid); int charge = 1; double theta = - std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); // TODO: Is this right? + std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); double refphi = std::atan2(centroid.y, centroid.x); Module refmodule(ref_detid); unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); - std::vector> next_layer_bound_points; + MatrixD4x3 next_layer_bound_points; for (int i = 0; i < bounds.rows(); i++) { Helix helix_p10 = @@ -177,7 +177,9 @@ namespace lstgeometry { } } } - next_layer_bound_points.push_back({std::get<2>(next_point), std::get<0>(next_point), std::get<1>(next_point)}); + next_layer_bound_points(i, 0) = std::get<2>(next_point); + next_layer_bound_points(i, 1) = std::get<0>(next_point); + next_layer_bound_points(i, 2) = std::get<1>(next_point); } return next_layer_bound_points; @@ -198,18 +200,11 @@ namespace lstgeometry { auto const& tar_detids_to_be_considered = ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1) : det_geom.getEndcapLayerDetIds(ref_layer + 1); - std::vector> next_layer_bound_points = - boundsAfterCurved(ref_detid, centroids, det_geom); - MatrixDNx3 next_layer_bound_points_matrix(next_layer_bound_points.size(), 3); - for (size_t i = 0; i < next_layer_bound_points.size(); i++) { - next_layer_bound_points_matrix(i, 0) = std::get<0>(next_layer_bound_points[i]); - next_layer_bound_points_matrix(i, 1) = std::get<1>(next_layer_bound_points[i]); - next_layer_bound_points_matrix(i, 2) = std::get<2>(next_layer_bound_points[i]); - } + auto next_layer_bound_points = boundsAfterCurved(ref_detid, centroids, det_geom); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { - if (moduleOverlapsInEtaPhi(next_layer_bound_points_matrix, det_geom.getCorners(tar_detid), refphi, 0)) + if (moduleOverlapsInEtaPhi(next_layer_bound_points, det_geom.getCorners(tar_detid), refphi, 0)) list_of_detids_etaphi_layer_tar.push_back(tar_detid); } @@ -220,7 +215,7 @@ namespace lstgeometry { int zshift = 0; std::vector ref_polygon; - ref_polygon.push_back(getEtaPhiPolygon(next_layer_bound_points_matrix, refphi, zshift)); + ref_polygon.push_back(getEtaPhiPolygon(next_layer_bound_points, refphi, zshift)); // Check whether there is still significant non-zero area for (unsigned int tar_detid : list_of_detids_etaphi_layer_tar) { From 4a0ef90ad4c2b01273dc21fc0dd87468a411c590 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 28 Oct 2025 14:23:21 -0400 Subject: [PATCH 23/95] Format code --- .../interface/LSTGeometry/CentroidMethods.h | 3 +- .../LSTCore/interface/LSTGeometry/Common.h | 2 +- .../interface/LSTGeometry/CornerMethods.h | 4 +- .../LSTCore/interface/LSTGeometry/IO.h | 238 +++++++++--------- .../LSTCore/interface/LSTGeometry/LSTMath.h | 6 +- .../interface/LSTGeometry/ModuleMapMethods.h | 88 ++++--- .../interface/LSTGeometry/PixelMapMethods.h | 75 +++--- .../standalone/bin/lst_make_geometry.cc | 171 ++++++------- 8 files changed, 294 insertions(+), 293 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 0bd958706e541..fe2dbb94aa643 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -51,7 +51,8 @@ namespace lstgeometry { } } - std::unordered_map computeCentroids(std::unordered_map const& sensors) { + std::unordered_map computeCentroids( + std::unordered_map const& sensors) { std::unordered_map centroids; for (auto const& [detId, sensor] : sensors) { int moduleType = parseModuleType(detId); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index f3e553c4a9381..c9cf56da0e388 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -20,7 +20,7 @@ namespace lstgeometry { constexpr double kPtThreshold = 0.8; constexpr double k2Rinv1GeVf = 0.00299792458; constexpr double kB = 3.8112; - + // For pixel maps constexpr unsigned int kNEta = 25; constexpr unsigned int kNPhi = 72; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 19da85eae1f2c..2de903b0c725f 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -108,8 +108,8 @@ namespace lstgeometry { } // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. - std::unordered_map assignCornersToSensors(std::vector const& modules, - std::unordered_map const& sensors) { + std::unordered_map assignCornersToSensors( + std::vector const& modules, std::unordered_map const& sensors) { std::unordered_map transformed_corners_dict; for (auto const& moduleInfo : modules) { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index d7ebfc35aa649..f7a1aeba648c4 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -124,7 +124,7 @@ namespace lstgeometry { return sensors; } - + std::vector readAverages(std::string const& filename) { std::vector averages; std::string line; @@ -147,131 +147,139 @@ namespace lstgeometry { return averages; } - - void writeCentroids(std::unordered_map const& centroids, std::string const& base_filename, bool binary = true) { - std::string filename = base_filename + (binary ? ".bin" : ".txt"); - std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); - - if(binary) { - for (auto& [detid, centroid] : centroids) { - float x = centroid.x; - float y = centroid.y; - float z = centroid.z; - unsigned int moduleType = centroid.moduleType; - file.write(reinterpret_cast(&detid), sizeof(detid)); - file.write(reinterpret_cast(&x), sizeof(x)); - file.write(reinterpret_cast(&y), sizeof(y)); - file.write(reinterpret_cast(&z), sizeof(z)); - file.write(reinterpret_cast(&moduleType), sizeof(moduleType)); - } - } else { - for (auto& [detid, centroid] : centroids) { - file << detid << "," << centroid.x << "," << centroid.y << "," << centroid.z << "," << centroid.moduleType << std::endl; - } + + void writeCentroids(std::unordered_map const& centroids, + std::string const& base_filename, + bool binary = true) { + std::string filename = base_filename + (binary ? ".bin" : ".txt"); + std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); + + if (binary) { + for (auto& [detid, centroid] : centroids) { + float x = centroid.x; + float y = centroid.y; + float z = centroid.z; + unsigned int moduleType = centroid.moduleType; + file.write(reinterpret_cast(&detid), sizeof(detid)); + file.write(reinterpret_cast(&x), sizeof(x)); + file.write(reinterpret_cast(&y), sizeof(y)); + file.write(reinterpret_cast(&z), sizeof(z)); + file.write(reinterpret_cast(&moduleType), sizeof(moduleType)); } + } else { + for (auto& [detid, centroid] : centroids) { + file << detid << "," << centroid.x << "," << centroid.y << "," << centroid.z << "," << centroid.moduleType + << std::endl; + } + } } - - void writeSlopes(std::unordered_map const& slopes, std::unordered_map const& sensors, std::string const& base_filename, bool binary = true) { - std::string filename = base_filename + (binary ? ".bin" : ".txt"); - std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); - - if(binary) { - for (auto& [detid, slope] : slopes) { - float drdz_slope = slope.drdz_slope; - float dxdy_slope = slope.dxdy_slope; - float phi = degToRad(sensors.at(detid).phi_deg); - file.write(reinterpret_cast(&detid), sizeof(detid)); - if (drdz_slope != kDefaultSlope) { - file.write(reinterpret_cast(&drdz_slope), sizeof(drdz_slope)); - file.write(reinterpret_cast(&dxdy_slope), sizeof(dxdy_slope)); - } else { - file.write(reinterpret_cast(&dxdy_slope), sizeof(dxdy_slope)); - file.write(reinterpret_cast(&phi), sizeof(phi)); - } - } - } else { - for (auto& [detid, slope] : slopes) { - float drdz_slope = slope.drdz_slope; - float dxdy_slope = slope.dxdy_slope; - float phi = degToRad(sensors.at(detid).phi_deg); - file << detid << ","; - if (drdz_slope != kDefaultSlope) { - file << drdz_slope << "," << dxdy_slope << std::endl; - } else { - file << dxdy_slope << "," << phi << std::endl; - } + + void writeSlopes(std::unordered_map const& slopes, + std::unordered_map const& sensors, + std::string const& base_filename, + bool binary = true) { + std::string filename = base_filename + (binary ? ".bin" : ".txt"); + std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); + + if (binary) { + for (auto& [detid, slope] : slopes) { + float drdz_slope = slope.drdz_slope; + float dxdy_slope = slope.dxdy_slope; + float phi = degToRad(sensors.at(detid).phi_deg); + file.write(reinterpret_cast(&detid), sizeof(detid)); + if (drdz_slope != kDefaultSlope) { + file.write(reinterpret_cast(&drdz_slope), sizeof(drdz_slope)); + file.write(reinterpret_cast(&dxdy_slope), sizeof(dxdy_slope)); + } else { + file.write(reinterpret_cast(&dxdy_slope), sizeof(dxdy_slope)); + file.write(reinterpret_cast(&phi), sizeof(phi)); } } + } else { + for (auto& [detid, slope] : slopes) { + float drdz_slope = slope.drdz_slope; + float dxdy_slope = slope.dxdy_slope; + float phi = degToRad(sensors.at(detid).phi_deg); + file << detid << ","; + if (drdz_slope != kDefaultSlope) { + file << drdz_slope << "," << dxdy_slope << std::endl; + } else { + file << dxdy_slope << "," << phi << std::endl; + } + } + } } - - void writeModuleConnections(std::unordered_map> const& connections, std::string const& base_filename, bool binary = true) { - std::string filename = base_filename + (binary ? ".bin" : ".txt"); - std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); - - if(binary) { - for (auto& [detid, set] : connections) { - file.write(reinterpret_cast(&detid), sizeof(detid)); - unsigned int length = set.size(); - file.write(reinterpret_cast(&length), sizeof(length)); - for (unsigned int i : set) { - file.write(reinterpret_cast(&i), sizeof(i)); - } - } - } else { - for (auto& [detid, set] : connections) { - file << detid << "," << set.size(); - for (unsigned int i : set) { - file << "," << i; - } - file << std::endl; + + void writeModuleConnections(std::unordered_map> const& connections, + std::string const& base_filename, + bool binary = true) { + std::string filename = base_filename + (binary ? ".bin" : ".txt"); + std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); + + if (binary) { + for (auto& [detid, set] : connections) { + file.write(reinterpret_cast(&detid), sizeof(detid)); + unsigned int length = set.size(); + file.write(reinterpret_cast(&length), sizeof(length)); + for (unsigned int i : set) { + file.write(reinterpret_cast(&i), sizeof(i)); + } + } + } else { + for (auto& [detid, set] : connections) { + file << detid << "," << set.size(); + for (unsigned int i : set) { + file << "," << i; } + file << std::endl; } + } } - + void writePixelMaps(PixelMap const& maps, std::string const& base_filename, bool binary = true) { - std::filesystem::path filepath(base_filename); - std::filesystem::create_directories(filepath.parent_path()); - - if(binary) { - for (auto& [layersubdetcharge, map] : maps) { - auto& [layer, subdet, charge] = layersubdetcharge; - - std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); - std::string filename = std::format("{}{}_layer{}_subdet{}.bin", base_filename, charge_str, layer, subdet); - - std::ofstream file(filename, std::ios::binary); - - for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { - auto const& set = map.at(isuperbin); - - file.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); - unsigned int length = set.size(); - file.write(reinterpret_cast(&length), sizeof(length)); - for (unsigned int i : set) { - file.write(reinterpret_cast(&i), sizeof(i)); - } - } + std::filesystem::path filepath(base_filename); + std::filesystem::create_directories(filepath.parent_path()); + + if (binary) { + for (auto& [layersubdetcharge, map] : maps) { + auto& [layer, subdet, charge] = layersubdetcharge; + + std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); + std::string filename = std::format("{}{}_layer{}_subdet{}.bin", base_filename, charge_str, layer, subdet); + + std::ofstream file(filename, std::ios::binary); + + for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { + auto const& set = map.at(isuperbin); + + file.write(reinterpret_cast(&isuperbin), sizeof(isuperbin)); + unsigned int length = set.size(); + file.write(reinterpret_cast(&length), sizeof(length)); + for (unsigned int i : set) { + file.write(reinterpret_cast(&i), sizeof(i)); } - } else { - for (auto& [layersubdetcharge, map] : maps) { - auto& [layer, subdet, charge] = layersubdetcharge; - - std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); - std::string filename = std::format("{}{}_layer{}_subdet{}.txt", base_filename, charge_str, layer, subdet); - - std::ofstream file(filename); - - for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { - auto const& set = map.at(isuperbin); - - unsigned int length = set.size(); - file << isuperbin << "," << length; - for (unsigned int i : set) { - file << "," << i; - } - file << std::endl; - } } + } + } else { + for (auto& [layersubdetcharge, map] : maps) { + auto& [layer, subdet, charge] = layersubdetcharge; + + std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); + std::string filename = std::format("{}{}_layer{}_subdet{}.txt", base_filename, charge_str, layer, subdet); + + std::ofstream file(filename); + + for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { + auto const& set = map.at(isuperbin); + + unsigned int length = set.size(); + file << isuperbin << "," << length; + for (unsigned int i : set) { + file << "," << i; + } + file << std::endl; + } + } } } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index b2e75b44554f2..f7aafbf2e1bce 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -123,8 +123,10 @@ namespace lstgeometry { MatrixD4x2 tar_mod_boundaries_etaphi; for (int i = 0; i < 4; ++i) { - auto ref_etaphi = getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0)+zshift, refphi); - auto tar_etaphi = getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0)+zshift, refphi); + auto ref_etaphi = + getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0) + zshift, refphi); + auto tar_etaphi = + getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0) + zshift, refphi); ref_mod_boundaries_etaphi(i, 0) = ref_etaphi.first; ref_mod_boundaries_etaphi(i, 1) = ref_etaphi.second; tar_mod_boundaries_etaphi(i, 0) = tar_etaphi.first; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 4407ef26f4b05..9cac883c0a920 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -58,19 +58,19 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); std::vector difference; - for (auto &ref_polygon_piece : ref_polygon) { - std::vector tmp_difference; - boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); - difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); + for (auto& ref_polygon_piece : ref_polygon) { + std::vector tmp_difference; + boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); + difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); } ref_polygon = std::move(difference); } double area = 0.; - for (auto &ref_polygon_piece : ref_polygon) - area += boost::geometry::area(ref_polygon_piece); - + for (auto& ref_polygon_piece : ref_polygon) + area += boost::geometry::area(ref_polygon_piece); + if (area <= 0.0001) continue; @@ -86,13 +86,13 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); bool intersects = false; - for (auto &ref_polygon_piece : ref_polygon){ - if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { - intersects = true; - break; - } + for (auto& ref_polygon_piece : ref_polygon) { + if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { + intersects = true; + break; + } } - + if (intersects) barrel_endcap_connected_tar_detids.insert(tar_detid); } @@ -105,16 +105,14 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } - MatrixD4x3 boundsAfterCurved( - unsigned int ref_detid, - std::unordered_map const& centroids, - DetectorGeometry const& det_geom, - bool doR = true) { + MatrixD4x3 boundsAfterCurved(unsigned int ref_detid, + std::unordered_map const& centroids, + DetectorGeometry const& det_geom, + bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); auto centroid = centroids.at(ref_detid); int charge = 1; - double theta = - std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); + double theta = std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); double refphi = std::atan2(centroid.y, centroid.x); Module refmodule(ref_detid); unsigned short ref_layer = refmodule.layer(); @@ -219,23 +217,23 @@ namespace lstgeometry { // Check whether there is still significant non-zero area for (unsigned int tar_detid : list_of_detids_etaphi_layer_tar) { - if (!ref_polygon.size()) + if (!ref_polygon.size()) break; Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); std::vector difference; - for (auto &ref_polygon_piece : ref_polygon) { - std::vector tmp_difference; - boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); - difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); + for (auto& ref_polygon_piece : ref_polygon) { + std::vector tmp_difference; + boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); + difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); } ref_polygon = std::move(difference); } - + double area = 0.; - for (auto &ref_polygon_piece : ref_polygon) - area += boost::geometry::area(ref_polygon_piece); + for (auto& ref_polygon_piece : ref_polygon) + area += boost::geometry::area(ref_polygon_piece); if (area > 0.0001) { auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); @@ -250,13 +248,13 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); bool intersects = false; - for (auto &ref_polygon_piece : ref_polygon){ - if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { - intersects = true; - break; - } + for (auto& ref_polygon_piece : ref_polygon) { + if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { + intersects = true; + break; + } } - + if (intersects) barrel_endcap_connected_tar_detids.insert(tar_detid); } @@ -269,19 +267,19 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } - - std::unordered_map> - mergeLineConnections(std::initializer_list>*> connections_list) { - std::unordered_map> merged; - - for (auto* connections : connections_list) { - for (const auto& [detid, list] : *connections) { - auto& target = merged[detid]; - target.insert(list.begin(), list.end()); - } + + std::unordered_map> mergeLineConnections( + std::initializer_list>*> connections_list) { + std::unordered_map> merged; + + for (auto* connections : connections_list) { + for (const auto& [detid, list] : *connections) { + auto& target = merged[detid]; + target.insert(list.begin(), list.end()); } + } - return merged; + return merged; } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index a1cea4abe00db..544e1d7bbc6ca 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -15,16 +15,17 @@ namespace lstgeometry { using LayerSubdetChargeKey = std::tuple; - using LayerSubdetChargeMap = std::unordered_map>, boost::hash>; + using LayerSubdetChargeMap = std::unordered_map>, + boost::hash>; using PixelMap = LayerSubdetChargeMap; PixelMap computePixelMap(std::unordered_map const& centroids, - DetectorGeometry const& det_geom) { - + DetectorGeometry const& det_geom) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; - - std::size_t nSuperbin = (kPtBounds.size()-1) * kNPhi * kNEta * kNZ; + + std::size_t nSuperbin = (kPtBounds.size() - 1) * kNPhi * kNEta * kNZ; // Initialize empty lists for the pixel map for (unsigned int layer : {1, 2}) { @@ -81,7 +82,7 @@ namespace lstgeometry { // Compute the indices of the compatible eta range unsigned int ietamin = static_cast(std::max((etamin + 2.6) / (5.2 / kNEta), 0.0)); unsigned int ietamax = - static_cast(std::min((etamax + 2.6) / (5.2 / kNEta), static_cast(kNEta-1))); + static_cast(std::min((etamax + 2.6) / (5.2 / kNEta), static_cast(kNEta - 1))); auto phi_ranges = det_geom.getCompatiblePhiRange(detId, pt_lo, pt_hi); @@ -96,42 +97,42 @@ namespace lstgeometry { // <= to cover some inefficiencies for (unsigned int ieta = ietamin; ieta <= ietamax; ieta++) { - // if the range is crossing the -pi v. pi boundary special care is needed + // if the range is crossing the -pi v. pi boundary special care is needed if (iphimin_pos <= iphimax_pos) { - for (unsigned int iphi = iphimin_pos; iphi < iphimax_pos; iphi++) { - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - maps[{layer, subdet, 1}][isuperbin].insert(detId); - maps[{layer, subdet, 0}][isuperbin].insert(detId); - } + for (unsigned int iphi = iphimin_pos; iphi < iphimax_pos; iphi++) { + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, 1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); + } } else { - for (unsigned int iphi = 0; iphi < iphimax_pos; iphi++) { - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - maps[{layer, subdet, 1}][isuperbin].insert(detId); - maps[{layer, subdet, 0}][isuperbin].insert(detId); - } - for (unsigned int iphi = iphimin_pos; iphi < kNPhi; iphi++) { - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - maps[{layer, subdet, 1}][isuperbin].insert(detId); - maps[{layer, subdet, 0}][isuperbin].insert(detId); - } + for (unsigned int iphi = 0; iphi < iphimax_pos; iphi++) { + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, 1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); + } + for (unsigned int iphi = iphimin_pos; iphi < kNPhi; iphi++) { + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, 1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); + } } if (iphimin_neg <= iphimax_neg) { - for (unsigned int iphi = iphimin_neg; iphi < iphimax_neg; iphi++) { - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - maps[{layer, subdet, -1}][isuperbin].insert(detId); - maps[{layer, subdet, 0}][isuperbin].insert(detId); - } + for (unsigned int iphi = iphimin_neg; iphi < iphimax_neg; iphi++) { + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, -1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); + } } else { - for (unsigned int iphi = 0; iphi < iphimax_neg; iphi++) { - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - maps[{layer, subdet, -1}][isuperbin].insert(detId); - maps[{layer, subdet, 0}][isuperbin].insert(detId); - } - for (unsigned int iphi = iphimin_neg; iphi < kNPhi; iphi++) { - unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; - maps[{layer, subdet, -1}][isuperbin].insert(detId); - maps[{layer, subdet, 0}][isuperbin].insert(detId); - } + for (unsigned int iphi = 0; iphi < iphimax_neg; iphi++) { + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, -1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); + } + for (unsigned int iphi = iphimin_neg; iphi < kNPhi; iphi++) { + unsigned int isuperbin = (ipt * kNPhi * kNEta * kNZ) + (ieta * kNPhi * kNZ) + (iphi * kNZ) + iz; + maps[{layer, subdet, -1}][isuperbin].insert(detId); + maps[{layer, subdet, 0}][isuperbin].insert(detId); + } } } } diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 4cfb28a21b754..08b205cfe3c01 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -11,95 +11,86 @@ using namespace lstgeometry; -int main(int argc, char **argv) { - - cxxopts::Options options("\nLST Geometry\n\n"); - options.add_options()( - "module_info_file", - "The path to the csv file containing module information.", - cxxopts::value()->default_value("../data/module_info_OT800_IT711.csv"))( - "sensor_info_file", - "The path to the csv file containing sensor information.", - cxxopts::value()->default_value("../data/DetId_sensors_list_OT800_IT711.csv"))( - "average_r_file", - "The path to the text file containing the average r positions of the Barrel layers.", - cxxopts::value()->default_value("../data/average_r_OT800_IT711.txt"))( - "average_z_file", - "The path to the text file containing the average z positions of the Endcap layers.", - cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt"))( - "output_dir", - "The path to the output directory.", - cxxopts::value()->default_value("../data/")); - - auto result = options.parse(argc, argv); - - std::string module_info_file = result["module_info_file"].as(); - std::string sensor_info_file = result["sensor_info_file"].as(); - std::string average_r_file = result["average_r_file"].as(); - std::string average_z_file = result["average_z_file"].as(); - std::string output_dir = result["output_dir"].as(); - - auto modules_info = readModuleInfo(module_info_file); - auto sensors_info = readSensorInfo(sensor_info_file); - auto average_r = readAverages(average_r_file); - auto average_z = readAverages(average_z_file); - - std::cout << "Transforming corners" << std::endl; - for (auto& mod : modules_info) - transformSensorCorners(mod); - std::cout << "Transforming corners done" << std::endl; - - std::cout << "Assigning corners" << std::endl; - auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); - std::cout << "Assigning corners done" << std::endl; - - std::cout << "Computing centroids" << std::endl; - auto centroids = computeCentroids(sensors_info); - writeCentroids(centroids, output_dir + "sensor_centroids", false); - std::cout << "Computing centroids done" << std::endl; - - std::cout << "Processing corners" << std::endl; - auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); - writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation", false); - writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation", false); - std::cout << "Processing corners done" << std::endl; - - std::cout << "Building detector geometry" << std::endl; - auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); - det_geom.buildByLayer(); - std::cout << "Building detector geometry done" << std::endl; - - std::cout << "Computing pixel map" << std::endl; - auto pixel_map = computePixelMap(centroids, det_geom); - writePixelMaps(pixel_map, output_dir + "pixelmap/pLS_map", false); - std::cout << "Computing pixel map done" << std::endl; - - std::cout << "Computing module maps" << std::endl; - auto detids_etaphi_layer_ref = det_geom.getDetIds( - [](const auto& x){ - auto mod = Module(x.first); - return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || - (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && - !(mod.ring() == 15 && mod.layer() == 1) && - !(mod.ring() == 15 && mod.layer() == 2) && - !(mod.ring() == 12 && mod.layer() == 3) && - !(mod.ring() == 12 && mod.layer() == 4) - )); - } - ); - - std::unordered_map> straight_line_connections; - std::unordered_map> curved_line_connections; - - for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); - } - auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); - writeModuleConnections(merged_line_connections, output_dir + "module_connection_tracing_merged", false); - std::cout << "Computing module maps done" << std::endl; - - std::cout << "Done!" << std::endl; - +int main(int argc, char** argv) { + cxxopts::Options options("\nLST Geometry\n\n"); + options.add_options()("module_info_file", + "The path to the csv file containing module information.", + cxxopts::value()->default_value("../data/module_info_OT800_IT711.csv"))( + "sensor_info_file", + "The path to the csv file containing sensor information.", + cxxopts::value()->default_value("../data/DetId_sensors_list_OT800_IT711.csv"))( + "average_r_file", + "The path to the text file containing the average r positions of the Barrel layers.", + cxxopts::value()->default_value("../data/average_r_OT800_IT711.txt"))( + "average_z_file", + "The path to the text file containing the average z positions of the Endcap layers.", + cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt"))( + "output_dir", "The path to the output directory.", cxxopts::value()->default_value("../data/")); + + auto result = options.parse(argc, argv); + + std::string module_info_file = result["module_info_file"].as(); + std::string sensor_info_file = result["sensor_info_file"].as(); + std::string average_r_file = result["average_r_file"].as(); + std::string average_z_file = result["average_z_file"].as(); + std::string output_dir = result["output_dir"].as(); + + auto modules_info = readModuleInfo(module_info_file); + auto sensors_info = readSensorInfo(sensor_info_file); + auto average_r = readAverages(average_r_file); + auto average_z = readAverages(average_z_file); + + std::cout << "Transforming corners" << std::endl; + for (auto& mod : modules_info) + transformSensorCorners(mod); + std::cout << "Transforming corners done" << std::endl; + + std::cout << "Assigning corners" << std::endl; + auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); + std::cout << "Assigning corners done" << std::endl; + + std::cout << "Computing centroids" << std::endl; + auto centroids = computeCentroids(sensors_info); + writeCentroids(centroids, output_dir + "sensor_centroids", false); + std::cout << "Computing centroids done" << std::endl; + + std::cout << "Processing corners" << std::endl; + auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); + writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation", false); + writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation", false); + std::cout << "Processing corners done" << std::endl; + + std::cout << "Building detector geometry" << std::endl; + auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); + det_geom.buildByLayer(); + std::cout << "Building detector geometry done" << std::endl; + + std::cout << "Computing pixel map" << std::endl; + auto pixel_map = computePixelMap(centroids, det_geom); + writePixelMaps(pixel_map, output_dir + "pixelmap/pLS_map", false); + std::cout << "Computing pixel map done" << std::endl; + + std::cout << "Computing module maps" << std::endl; + auto detids_etaphi_layer_ref = det_geom.getDetIds([](const auto& x) { + auto mod = Module(x.first); + return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || + (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && !(mod.ring() == 15 && mod.layer() == 1) && + !(mod.ring() == 15 && mod.layer() == 2) && !(mod.ring() == 12 && mod.layer() == 3) && + !(mod.ring() == 12 && mod.layer() == 4))); + }); + + std::unordered_map> straight_line_connections; + std::unordered_map> curved_line_connections; + + for (auto ref_detid : detids_etaphi_layer_ref) { + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); + } + auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); + writeModuleConnections(merged_line_connections, output_dir + "module_connection_tracing_merged", false); + std::cout << "Computing module maps done" << std::endl; + + std::cout << "Done!" << std::endl; + return 0; } \ No newline at end of file From 218dffd3ccbbc5b3b7f993a28f5f7fc316b6304f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 31 Oct 2025 10:28:58 -0400 Subject: [PATCH 24/95] A bit of cleanup --- RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h | 8 +------- .../LSTCore/interface/LSTGeometry/ModuleMapMethods.h | 10 ++++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index f7aafbf2e1bce..44bbae9c563aa 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -74,13 +74,7 @@ namespace lstgeometry { } std::pair getEtaPhi(double x, double y, double z, double refphi = 0) { - if (refphi != 0) { - double xnew = x * std::cos(-refphi) - y * std::sin(-refphi); - double ynew = x * std::sin(-refphi) + y * std::cos(-refphi); - x = xnew; - y = ynew; - } - double phi = std::atan2(y, x); + double phi = phi_mpi_pi(std::atan2(y, x) - refphi); double eta = std::copysign(-std::log(std::tan(std::atan(std::sqrt(x * x + y * y) / std::abs(z)) / 2.)), z); return std::make_pair(eta, phi); } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 9cac883c0a920..e082386abb4a6 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -12,7 +12,6 @@ #include #include -#include "LSTMath.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" @@ -133,7 +132,6 @@ namespace lstgeometry { double bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); double phi_diff = phi_mpi_pi(bound_phi - refphi); - // TODO: Check if the copysign arguments are correct std::tuple next_point; if (ref_subdet == 5) { if (doR) { @@ -149,13 +147,13 @@ namespace lstgeometry { if (phi_diff > 0) { next_point = getHelixPointFromZ(helix_p10, std::copysign(tar_layer_z, helix_p10.lam)); } else { - next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10.lam)); + next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10_pos.lam)); } } else { if (phi_diff > 0) { next_point = getHelixPointFromZ(helix_m10, std::copysign(tar_layer_z, helix_p10.lam)); } else { - next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_p10.lam)); + next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_p10_pos.lam)); } } } @@ -165,13 +163,13 @@ namespace lstgeometry { if (phi_diff > 0) { next_point = getHelixPointFromZ(helix_p10, std::copysign(tar_layer_z, helix_p10.lam)); } else { - next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10.lam)); + next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10_pos.lam)); } } else { if (phi_diff > 0) { next_point = getHelixPointFromZ(helix_m10, std::copysign(tar_layer_z, helix_m10.lam)); } else { - next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_m10.lam)); + next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_m10_pos.lam)); } } } From fedf5a3c33076229d1c8d610277ba7b06fbf25a5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 3 Nov 2025 15:18:49 -0500 Subject: [PATCH 25/95] Added eta-phi binning --- .../interface/LSTGeometry/DetectorGeometry.h | 140 ++++++++++++++++-- .../interface/LSTGeometry/ModuleMapMethods.h | 14 +- 2 files changed, 136 insertions(+), 18 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 999cc442ae313..4155b147cdd12 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -7,16 +7,87 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" namespace lstgeometry { + + using LayerEtaBinPhiBinKey = std::tuple; + + // We split modules into overlapping eta-phi bins so that it's easier to construct module maps + // These values are just guesses and can be optimized later + constexpr unsigned int kNEtaBins = 4; + constexpr double kEtaBinRad = std::numbers::pi_v / kNEtaBins; + constexpr unsigned int kNPhiBins = 6; + constexpr double kPhiBinWidth = 2*std::numbers::pi_v / kNPhiBins; + + bool isInEtaPhiBin(double eta, double phi, unsigned int eta_bin, unsigned int phi_bin) { + double theta = 2. * std::atan(std::exp(-eta)); + + if (eta_bin == 0) { + if (theta > 3.*kEtaBinRad/2.) + return false; + } else if (eta_bin == kNPhiBins-1) { + if (theta < (2*(kNPhiBins-1) - 1)*kEtaBinRad/2.) + return false; + } else if (theta < (2*eta_bin - 1) * kEtaBinRad/2. || theta > (2*(eta_bin+1) + 1) * kEtaBinRad/2.) { + return false; + } + + double pi = std::numbers::pi_v; + if (phi_bin == 0) { + if (phi > -pi + kPhiBinWidth && phi < pi - kPhiBinWidth) + return false; + } else { + if (phi < -pi + (phi_bin - 1) * kPhiBinWidth || phi > -pi + (phi_bin+1) * kPhiBinWidth) + return false; + } + + return true; + } + + std::pair getEtaPhiBins(double eta, double phi) { + double theta = 2. * std::atan(std::exp(-eta)); + + unsigned int eta_bin = 0; + if (theta <= kEtaBinRad) { + eta_bin = 0; + } else if (theta >= (kNEtaBins-1)*kEtaBinRad) { + eta_bin = kNEtaBins-1; + } else { + for (unsigned int i = 1; i < kNEtaBins-1; i++) { + if (theta >= i * kEtaBinRad && theta <= (i + 1) * kEtaBinRad) { + eta_bin = i; + break; + } + } + } + + unsigned int phi_bin = 0; + double pi = std::numbers::pi_v; + + if (phi <= -pi + kPhiBinWidth/2. || phi >= pi - kPhiBinWidth/2.){ + phi_bin = 0; + } + else { + for (unsigned int i = 1; i < kNPhiBins; i++) { + if (phi >= -pi + ((2*i - 1) * kPhiBinWidth)/2. && phi <= -pi + ((2*i + 1) * kPhiBinWidth)/2.) { + phi_bin = i; + break; + } + } + } + + + return std::make_pair(eta_bin, phi_bin); + } class DetectorGeometry { private: std::unordered_map corners_; std::vector avg_radii_; std::vector avg_z_; - std::vector> barrel_lower_det_ids_; - std::vector> endcap_lower_det_ids_; + std::unordered_map, boost::hash> barrel_lower_det_ids_; + std::unordered_map, boost::hash> endcap_lower_det_ids_; public: DetectorGeometry(std::unordered_map corners, @@ -41,27 +112,68 @@ namespace lstgeometry { // Clear just in case they were already built barrel_lower_det_ids_.clear(); endcap_lower_det_ids_.clear(); + + // Initialize all vectors + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + for (unsigned int layer = 1; layer < 7; layer++) { + barrel_lower_det_ids_[{layer, etabin, phibin}] = {}; + } + for (unsigned int layer = 1; layer < 6; layer++) { + endcap_lower_det_ids_[{layer, etabin, phibin}] = {}; + } + } + } for (unsigned int layer = 1; layer < 7; layer++) { - barrel_lower_det_ids_.push_back(getDetIds([&layer](const auto& x) { - Module m(x.first); - return m.subdet() == 5 && m.layer() == layer && m.isLower() == 1; - })); + auto detids = getDetIds([&layer](const auto& x) { + Module m(x.first); + return m.subdet() == 5 && m.layer() == layer && m.isLower() == 1; + }); + for (auto detid : detids) { + auto corners = getCorners(detid); + RowVectorD3 center = corners.colwise().mean(); + center /= 4.; + //double ref_phi = std::atan2(center(2), center(1)); + auto etaphi = getEtaPhi(center(1), center(2), center(0)); + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { + barrel_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); + } + } + } + } } for (unsigned int layer = 1; layer < 6; layer++) { - endcap_lower_det_ids_.push_back(getDetIds([&layer](const auto& x) { - Module m(x.first); - return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; - })); + auto detids = getDetIds([&layer](const auto& x) { + Module m(x.first); + return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; + }); + for (auto detid : detids) { + auto corners = getCorners(detid); + RowVectorD3 center = corners.colwise().mean(); + center /= 4.; + //double ref_phi = std::atan2(center(2), center(1)); + auto etaphi = getEtaPhi(center(1), center(2), center(0)); + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { + endcap_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); + } + } + } + } } + } - std::vector const& getBarrelLayerDetIds(unsigned int layer) const { - return barrel_lower_det_ids_[layer - 1]; + std::vector const& getBarrelLayerDetIds(unsigned int layer, unsigned int etabin, unsigned int phibin) const { + return barrel_lower_det_ids_.at({layer, etabin, phibin}); } - std::vector const& getEndcapLayerDetIds(unsigned int layer) const { - return endcap_lower_det_ids_[layer - 1]; + std::vector const& getEndcapLayerDetIds(unsigned int layer, unsigned int etabin, unsigned int phibin) const { + return endcap_lower_det_ids_.at({layer, etabin, phibin}); } double getBarrelLayerAverageRadius(unsigned int layer) const { return avg_radii_[layer - 1]; } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index e082386abb4a6..6c9034630d57b 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -30,9 +30,12 @@ namespace lstgeometry { unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); + + auto etaphi = getEtaPhi(centroid.x, centroid.y, centroid.z); + auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = - ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1) : det_geom.getEndcapLayerDetIds(ref_layer + 1); + ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -73,7 +76,7 @@ namespace lstgeometry { if (area <= 0.0001) continue; - auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); + auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto centroid_target = centroids.at(tar_detid); @@ -193,8 +196,11 @@ namespace lstgeometry { unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); + auto etaphi = getEtaPhi(centroid.x, centroid.y, centroid.z); + auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); + auto const& tar_detids_to_be_considered = - ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1) : det_geom.getEndcapLayerDetIds(ref_layer + 1); + ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); auto next_layer_bound_points = boundsAfterCurved(ref_detid, centroids, det_geom); @@ -234,7 +240,7 @@ namespace lstgeometry { area += boost::geometry::area(ref_polygon_piece); if (area > 0.0001) { - auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1); + auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto centroid_target = centroids.at(tar_detid); From ca59512476dc9f1e19624bf65842755e071cd9d5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 3 Nov 2025 20:20:03 +0000 Subject: [PATCH 26/95] format --- .../interface/LSTGeometry/DetectorGeometry.h | 209 +++++++++--------- .../interface/LSTGeometry/ModuleMapMethods.h | 16 +- 2 files changed, 116 insertions(+), 109 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 4155b147cdd12..5ac0acf44fd68 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -10,84 +10,84 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" namespace lstgeometry { - - using LayerEtaBinPhiBinKey = std::tuple; - - // We split modules into overlapping eta-phi bins so that it's easier to construct module maps - // These values are just guesses and can be optimized later - constexpr unsigned int kNEtaBins = 4; - constexpr double kEtaBinRad = std::numbers::pi_v / kNEtaBins; - constexpr unsigned int kNPhiBins = 6; - constexpr double kPhiBinWidth = 2*std::numbers::pi_v / kNPhiBins; - - bool isInEtaPhiBin(double eta, double phi, unsigned int eta_bin, unsigned int phi_bin) { - double theta = 2. * std::atan(std::exp(-eta)); - - if (eta_bin == 0) { - if (theta > 3.*kEtaBinRad/2.) - return false; - } else if (eta_bin == kNPhiBins-1) { - if (theta < (2*(kNPhiBins-1) - 1)*kEtaBinRad/2.) - return false; - } else if (theta < (2*eta_bin - 1) * kEtaBinRad/2. || theta > (2*(eta_bin+1) + 1) * kEtaBinRad/2.) { - return false; - } - - double pi = std::numbers::pi_v; - if (phi_bin == 0) { - if (phi > -pi + kPhiBinWidth && phi < pi - kPhiBinWidth) - return false; - } else { - if (phi < -pi + (phi_bin - 1) * kPhiBinWidth || phi > -pi + (phi_bin+1) * kPhiBinWidth) - return false; - } - - return true; + + using LayerEtaBinPhiBinKey = std::tuple; + + // We split modules into overlapping eta-phi bins so that it's easier to construct module maps + // These values are just guesses and can be optimized later + constexpr unsigned int kNEtaBins = 4; + constexpr double kEtaBinRad = std::numbers::pi_v / kNEtaBins; + constexpr unsigned int kNPhiBins = 6; + constexpr double kPhiBinWidth = 2 * std::numbers::pi_v / kNPhiBins; + + bool isInEtaPhiBin(double eta, double phi, unsigned int eta_bin, unsigned int phi_bin) { + double theta = 2. * std::atan(std::exp(-eta)); + + if (eta_bin == 0) { + if (theta > 3. * kEtaBinRad / 2.) + return false; + } else if (eta_bin == kNPhiBins - 1) { + if (theta < (2 * (kNPhiBins - 1) - 1) * kEtaBinRad / 2.) + return false; + } else if (theta < (2 * eta_bin - 1) * kEtaBinRad / 2. || theta > (2 * (eta_bin + 1) + 1) * kEtaBinRad / 2.) { + return false; } - - std::pair getEtaPhiBins(double eta, double phi) { - double theta = 2. * std::atan(std::exp(-eta)); - - unsigned int eta_bin = 0; - if (theta <= kEtaBinRad) { - eta_bin = 0; - } else if (theta >= (kNEtaBins-1)*kEtaBinRad) { - eta_bin = kNEtaBins-1; - } else { - for (unsigned int i = 1; i < kNEtaBins-1; i++) { - if (theta >= i * kEtaBinRad && theta <= (i + 1) * kEtaBinRad) { - eta_bin = i; - break; - } - } - } - - unsigned int phi_bin = 0; - double pi = std::numbers::pi_v; - - if (phi <= -pi + kPhiBinWidth/2. || phi >= pi - kPhiBinWidth/2.){ - phi_bin = 0; + + double pi = std::numbers::pi_v; + if (phi_bin == 0) { + if (phi > -pi + kPhiBinWidth && phi < pi - kPhiBinWidth) + return false; + } else { + if (phi < -pi + (phi_bin - 1) * kPhiBinWidth || phi > -pi + (phi_bin + 1) * kPhiBinWidth) + return false; + } + + return true; + } + + std::pair getEtaPhiBins(double eta, double phi) { + double theta = 2. * std::atan(std::exp(-eta)); + + unsigned int eta_bin = 0; + if (theta <= kEtaBinRad) { + eta_bin = 0; + } else if (theta >= (kNEtaBins - 1) * kEtaBinRad) { + eta_bin = kNEtaBins - 1; + } else { + for (unsigned int i = 1; i < kNEtaBins - 1; i++) { + if (theta >= i * kEtaBinRad && theta <= (i + 1) * kEtaBinRad) { + eta_bin = i; + break; } - else { - for (unsigned int i = 1; i < kNPhiBins; i++) { - if (phi >= -pi + ((2*i - 1) * kPhiBinWidth)/2. && phi <= -pi + ((2*i + 1) * kPhiBinWidth)/2.) { - phi_bin = i; - break; - } - } + } + } + + unsigned int phi_bin = 0; + double pi = std::numbers::pi_v; + + if (phi <= -pi + kPhiBinWidth / 2. || phi >= pi - kPhiBinWidth / 2.) { + phi_bin = 0; + } else { + for (unsigned int i = 1; i < kNPhiBins; i++) { + if (phi >= -pi + ((2 * i - 1) * kPhiBinWidth) / 2. && phi <= -pi + ((2 * i + 1) * kPhiBinWidth) / 2.) { + phi_bin = i; + break; } - - - return std::make_pair(eta_bin, phi_bin); + } } + return std::make_pair(eta_bin, phi_bin); + } + class DetectorGeometry { private: std::unordered_map corners_; std::vector avg_radii_; std::vector avg_z_; - std::unordered_map, boost::hash> barrel_lower_det_ids_; - std::unordered_map, boost::hash> endcap_lower_det_ids_; + std::unordered_map, boost::hash> + barrel_lower_det_ids_; + std::unordered_map, boost::hash> + endcap_lower_det_ids_; public: DetectorGeometry(std::unordered_map corners, @@ -112,9 +112,9 @@ namespace lstgeometry { // Clear just in case they were already built barrel_lower_det_ids_.clear(); endcap_lower_det_ids_.clear(); - + // Initialize all vectors - for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { for (unsigned int layer = 1; layer < 7; layer++) { barrel_lower_det_ids_[{layer, etabin, phibin}] = {}; @@ -126,53 +126,56 @@ namespace lstgeometry { } for (unsigned int layer = 1; layer < 7; layer++) { - auto detids = getDetIds([&layer](const auto& x) { - Module m(x.first); - return m.subdet() == 5 && m.layer() == layer && m.isLower() == 1; - }); + auto detids = getDetIds([&layer](const auto& x) { + Module m(x.first); + return m.subdet() == 5 && m.layer() == layer && m.isLower() == 1; + }); for (auto detid : detids) { - auto corners = getCorners(detid); - RowVectorD3 center = corners.colwise().mean(); - center /= 4.; - //double ref_phi = std::atan2(center(2), center(1)); - auto etaphi = getEtaPhi(center(1), center(2), center(0)); - for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { - for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { - if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { - barrel_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); - } + auto corners = getCorners(detid); + RowVectorD3 center = corners.colwise().mean(); + center /= 4.; + //double ref_phi = std::atan2(center(2), center(1)); + auto etaphi = getEtaPhi(center(1), center(2), center(0)); + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { + barrel_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); } } + } } } for (unsigned int layer = 1; layer < 6; layer++) { - auto detids = getDetIds([&layer](const auto& x) { - Module m(x.first); - return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; - }); - for (auto detid : detids) { - auto corners = getCorners(detid); - RowVectorD3 center = corners.colwise().mean(); - center /= 4.; - //double ref_phi = std::atan2(center(2), center(1)); - auto etaphi = getEtaPhi(center(1), center(2), center(0)); - for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { - for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { - if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { - endcap_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); - } - } + auto detids = getDetIds([&layer](const auto& x) { + Module m(x.first); + return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; + }); + for (auto detid : detids) { + auto corners = getCorners(detid); + RowVectorD3 center = corners.colwise().mean(); + center /= 4.; + //double ref_phi = std::atan2(center(2), center(1)); + auto etaphi = getEtaPhi(center(1), center(2), center(0)); + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { + endcap_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); } + } } + } } - } - std::vector const& getBarrelLayerDetIds(unsigned int layer, unsigned int etabin, unsigned int phibin) const { + std::vector const& getBarrelLayerDetIds(unsigned int layer, + unsigned int etabin, + unsigned int phibin) const { return barrel_lower_det_ids_.at({layer, etabin, phibin}); } - std::vector const& getEndcapLayerDetIds(unsigned int layer, unsigned int etabin, unsigned int phibin) const { + std::vector const& getEndcapLayerDetIds(unsigned int layer, + unsigned int etabin, + unsigned int phibin) const { return endcap_lower_det_ids_.at({layer, etabin, phibin}); } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 6c9034630d57b..fe21ae6f2c2d8 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -30,12 +30,13 @@ namespace lstgeometry { unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); - + auto etaphi = getEtaPhi(centroid.x, centroid.y, centroid.z); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = - ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); + ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) + : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -76,7 +77,8 @@ namespace lstgeometry { if (area <= 0.0001) continue; - auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); + auto const& new_tar_detids_to_be_considered = + det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto centroid_target = centroids.at(tar_detid); @@ -198,9 +200,10 @@ namespace lstgeometry { auto etaphi = getEtaPhi(centroid.x, centroid.y, centroid.z); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); - + auto const& tar_detids_to_be_considered = - ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); + ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) + : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); auto next_layer_bound_points = boundsAfterCurved(ref_detid, centroids, det_geom); @@ -240,7 +243,8 @@ namespace lstgeometry { area += boost::geometry::area(ref_polygon_piece); if (area > 0.0001) { - auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); + auto const& new_tar_detids_to_be_considered = + det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto centroid_target = centroids.at(tar_detid); From 9ff260d6e11facf101cedbc6831c2592b14ea7ab Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 18 Feb 2026 15:53:52 -0500 Subject: [PATCH 27/95] Added cmssw scaffoling --- .../interface/LSTGeometry/PixelMapMethods.h | 16 ++--- RecoTracker/LSTCore/plugins/BuildFile.xml | 35 +++++++++++ .../LSTCore/plugins/LSTGeometryESProducer.cc | 62 +++++++++++++++++++ RecoTracker/LSTCore/test/BuildFile.xml | 10 ++- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 24 +++++++ RecoTracker/LSTCore/test/dumpLSTGeometry.py | 50 +++++++++++++++ .../LSTCore/test/testDumpLSTGeometry.sh | 10 +++ 7 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 RecoTracker/LSTCore/plugins/BuildFile.xml create mode 100644 RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc create mode 100644 RecoTracker/LSTCore/test/DumpLSTGeometry.cc create mode 100644 RecoTracker/LSTCore/test/dumpLSTGeometry.py create mode 100644 RecoTracker/LSTCore/test/testDumpLSTGeometry.sh diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index 544e1d7bbc6ca..d3826e1e5b76a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -86,14 +86,14 @@ namespace lstgeometry { auto phi_ranges = det_geom.getCompatiblePhiRange(detId, pt_lo, pt_hi); - int iphimin_pos = static_cast((phi_ranges.first.first + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); - int iphimax_pos = static_cast((phi_ranges.first.second + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); - int iphimin_neg = static_cast((phi_ranges.second.first + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); - int iphimax_neg = static_cast((phi_ranges.second.second + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimin_pos = static_cast((phi_ranges.first.first + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimax_pos = static_cast((phi_ranges.first.second + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimin_neg = static_cast((phi_ranges.second.first + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimax_neg = static_cast((phi_ranges.second.second + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); // <= to cover some inefficiencies for (unsigned int ieta = ietamin; ieta <= ietamax; ieta++) { diff --git a/RecoTracker/LSTCore/plugins/BuildFile.xml b/RecoTracker/LSTCore/plugins/BuildFile.xml new file mode 100644 index 0000000000000..0b73a4fffed62 --- /dev/null +++ b/RecoTracker/LSTCore/plugins/BuildFile.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc new file mode 100644 index 0000000000000..e8da6ba48ff6e --- /dev/null +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -0,0 +1,62 @@ +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/ESProducer.h" + +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" +#include "DataFormats/TrackerCommon/interface/TrackerDetSide.h" +#include "Geometry/Records/interface/TrackerTopologyRcd.h" +#include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h" +#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" + +#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" +#include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h" + +#include "DataFormats/SiStripDetId/interface/SiStripEnums.h" + +// temporary +#include "FWCore/Utilities/interface/typelookup.h" +#include + +TYPELOOKUP_DATA_REG(std::string); + +// LST includes + +class LSTGeometryESProducer : public edm::ESProducer { +public: + LSTGeometryESProducer(const edm::ParameterSet &iConfig); + + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); + + std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); + +private: + edm::ESGetToken geomToken_; + edm::ESGetToken ttopoToken_; + edm::ESGetToken trackerToken_; + + const TrackerTopology *trackerTopo_ = nullptr; + const TrackerGeometry *trackerGeom_ = nullptr; +}; + +LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) { + auto cc = setWhatProduced(this); + geomToken_ = cc.consumes(); + ttopoToken_ = cc.consumes(); + trackerToken_ = cc.consumes(); +} + +void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + edm::ParameterSetDescription desc; + descriptions.addWithDefaultLabel(desc); +} + +std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { + trackerGeom_ = &iRecord.get(geomToken_); + trackerTopo_ = &iRecord.get(ttopoToken_); + + // placeholder + return std::make_unique("LSTGeometryESProducer"); +} + +DEFINE_FWK_EVENTSETUP_MODULE(LSTGeometryESProducer); diff --git a/RecoTracker/LSTCore/test/BuildFile.xml b/RecoTracker/LSTCore/test/BuildFile.xml index eb1012b409f32..6728daccf7b88 100644 --- a/RecoTracker/LSTCore/test/BuildFile.xml +++ b/RecoTracker/LSTCore/test/BuildFile.xml @@ -1 +1,9 @@ - + + + + + + + + + \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc new file mode 100644 index 0000000000000..13b88a11460a7 --- /dev/null +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -0,0 +1,24 @@ +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/ESTransientHandle.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" + +#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" + +class DumpLSTGeometry : public edm::one::EDAnalyzer<> { +public: + explicit DumpLSTGeometry(const edm::ParameterSet& config); + +private: + void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override; + + std::string outputDirectory_; +}; + +DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) + : outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")) {} + +void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {} + +DEFINE_FWK_MODULE(DumpLSTGeometry); \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py new file mode 100644 index 0000000000000..59c3e807f9f2d --- /dev/null +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -0,0 +1,50 @@ +import FWCore.ParameterSet.Config as cms + +# from Configuration.ProcessModifiers.trackingMkFit_cff import trackingMkFit +from Configuration.ProcessModifiers.trackingMkFitCommon_cff import trackingMkFitCommon as trackingLSTCommon +trackingLST = cms.ModifierChain(trackingLSTCommon) + +################################################################### +# Set default phase-2 settings +################################################################### +import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings +_PH2_GLOBAL_TAG, _PH2_ERA = _settings.get_era_and_conditions(_settings.DEFAULT_VERSION) + +# No era in Fireworks/Geom reco dumper +process = cms.Process('DUMP', _PH2_ERA, trackingLST) + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.Geometry.GeometryExtendedRun4DefaultReco_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') +process.load('Configuration.StandardSequences.Reconstruction_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, _PH2_GLOBAL_TAG, '') + +# In Fireworks/Geom reco dumper: +# from Configuration.AlCa.autoCond import autoCond +# process.GlobalTag.globaltag = autoCond['phase2_realistic'] + +process.MessageLogger.cerr.threshold = "INFO" +process.MessageLogger.cerr.MkFitGeometryESProducer = dict(limit=-1) + +process.source = cms.Source("EmptySource") +process.maxEvents.input = 1 + + +process.add_(cms.ESProducer("LSTGeometryESProducer")) + +defaultOutputDirectory="lstgeometry" + +# level: 0 - no printout; 1 - print layers, 2 - print shapes and modules +# outputFileName: binary dump file; no dump if empty string +process.dump = cms.EDAnalyzer("DumpLSTGeometry", + level = cms.untracked.int32(1), + outputDirectory = cms.untracked.string(defaultOutputDirectory) + ) + +print("Requesting LST geometry dump into directory:", defaultOutputDirectory, "\n"); +process.p = cms.Path(process.dump) \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh new file mode 100644 index 0000000000000..51762c16212ce --- /dev/null +++ b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +function die { echo $1: status $2; exit $2; } + +if [ "${SCRAM_TEST_NAME}" != "" ] ; then + mkdir ${SCRAM_TEST_NAME} + cd ${SCRAM_TEST_NAME} +fi + +(cmsRun ${SCRAM_TEST_PATH}/dumpLSTGeometry.py) || die "failed to run dumpLSTGeometry.py" $? From cf2ed78bf1686f5c13860fd57194964a6c955976 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 19 Nov 2025 18:32:55 +0000 Subject: [PATCH 28/95] Some progress getting required data --- .../LSTCore/plugins/LSTGeometryESProducer.cc | 56 +++++++++++++++++++ RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 16 +++++- RecoTracker/LSTCore/test/dumpLSTGeometry.py | 3 +- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index e8da6ba48ff6e..68953c899ae03 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -54,6 +54,62 @@ void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &des std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { trackerGeom_ = &iRecord.get(geomToken_); trackerTopo_ = &iRecord.get(ttopoToken_); + + // Maybe limit it to a subset of dets + for (auto &det : trackerGeom_->dets()) { + const DetId detId = det->geographicalId(); + + const auto &surface = det->surface(); + const Bounds *b = &(surface).bounds(); + const auto &position = surface.position(); + + const double rho_mm = position.perp() * 10; + const double z_mm = position.z() * 10; + const double phi_rad = position.phi(); + + // if (detId() != 441201726) + // continue; + + // std::cout << "DetId " << detId() << "\n"; + // std::cout << "det " << detId.det() << "\n"; + // std::cout << "subdet " << detId.subdetId() << "\n"; + // std::cout << "layer " << trackerTopo_->layer(detId) << "\n"; + // std::cout << "print " << trackerTopo_->print(detId) << "\n"; + + double vtxOneX_mm, vtxOneY_mm, vtxTwoX_mm, vtxTwoY_mm, vtxThreeX_mm, vtxThreeY_mm, vtxFourX_mm, vtxFourY_mm; + + if (const TrapezoidalPlaneBounds *b2 = dynamic_cast(b)) { + // See sec. "TrapezoidalPlaneBounds parameters" in doc/reco-geom-notes.txt + std::array const &par = b2->parameters(); + vtxOneX_mm = rho_mm * cos(phi_rad) -par[0]* 10 * sin(phi_rad); + vtxOneY_mm = rho_mm * sin(phi_rad) -par[3]* 10 * cos(phi_rad); + vtxTwoX_mm = rho_mm * cos(phi_rad) -par[1]* 10 * sin(phi_rad); + vtxTwoY_mm = rho_mm * sin(phi_rad) + par[3]* 10 * cos(phi_rad); + vtxThreeX_mm = rho_mm * cos(phi_rad) + par[1]* 10 * sin(phi_rad); + vtxThreeY_mm = rho_mm * sin(phi_rad) + par[3]* 10 * cos(phi_rad); + vtxFourX_mm = rho_mm * cos(phi_rad) + par[0]* 10 * sin(phi_rad); + vtxFourY_mm = rho_mm * sin(phi_rad) + -par[3]* 10 * cos(phi_rad); + //dz = par[2]; + //ms.round_assign(par[0], par[1], par[3], par[2]); + } else if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { + // Rectangular + float dx = b2->width()* 10 * 0.5; // half width + float dy = b2->length()* 10 * 0.5; // half length + vtxOneX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); + vtxOneY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); + vtxTwoX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); + vtxTwoY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); + vtxThreeX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); + vtxThreeY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); + vtxFourX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); + vtxFourY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); + //dz = b2->thickness() * 0.5; // half thickness + //ms.round_assign(dx, 0.0f, dy, dz); + } else { + throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; + } + // std::cout << detId() << " " << rho_mm << " " << z_mm << " " << phi_rad << " " << vtxOneX_mm << " " << vtxOneY_mm << " " << vtxTwoX_mm << " " << vtxTwoY_mm << " " << vtxThreeX_mm << " " << vtxThreeY_mm << " " << vtxFourX_mm << " " << vtxFourY_mm << std::endl; + } // placeholder return std::make_unique("LSTGeometryESProducer"); diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index 13b88a11460a7..cb0bf2985b6b3 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -6,19 +6,31 @@ #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" +// temporary +#include +#include "FWCore/Utilities/interface/typelookup.h" +TYPELOOKUP_DATA_REG(std::string); +// end temporary + class DumpLSTGeometry : public edm::one::EDAnalyzer<> { public: explicit DumpLSTGeometry(const edm::ParameterSet& config); private: void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override; + + edm::ESGetToken lstGeoToken_; std::string outputDirectory_; }; DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) - : outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")) {} + : lstGeoToken_{esConsumes()}, outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")) {} -void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {} +void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + const auto& lstg = iSetup.getData(lstGeoToken_); + + edm::LogInfo("DumpLSTGeometry") << lstg << std::endl; +} DEFINE_FWK_MODULE(DumpLSTGeometry); \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py index 59c3e807f9f2d..591bbb3d10542 100644 --- a/RecoTracker/LSTCore/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -1,7 +1,6 @@ import FWCore.ParameterSet.Config as cms -# from Configuration.ProcessModifiers.trackingMkFit_cff import trackingMkFit -from Configuration.ProcessModifiers.trackingMkFitCommon_cff import trackingMkFitCommon as trackingLSTCommon +trackingLSTCommon = cms.Modifier() trackingLST = cms.ModifierChain(trackingLSTCommon) ################################################################### From 386cf93e74eadef333bdfe54f7240d471d76b925 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 19 Nov 2025 18:58:06 +0000 Subject: [PATCH 29/95] Removed unused struct members --- .../interface/LSTGeometry/CentroidMethods.h | 2 +- .../interface/LSTGeometry/CornerMethods.h | 23 ++++++++---------- .../LSTCore/interface/LSTGeometry/IO.h | 24 +++++++------------ .../interface/LSTGeometry/ModuleInfo.h | 13 ++++------ .../interface/LSTGeometry/SensorInfo.h | 6 +---- 5 files changed, 24 insertions(+), 44 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index fe2dbb94aa643..99f4010c93d0a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -65,7 +65,7 @@ namespace lstgeometry { // Convert from mm to cm double z = sensor.sensorCenterZ_mm / 10.0; double rho = sensor.sensorCenterRho_mm / 10.0; - double phi = degToRad(sensor.phi_deg); + double phi = sensor.phi_rad; double x = rho * cos(phi); double y = rho * sin(phi); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 2de903b0c725f..6bd223790abba 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -35,11 +35,9 @@ namespace lstgeometry { // Only the tilt angles are non-zero for the current geometry. If the other // angles get used, implement their rotations using the tangentialRotationMatrix // function above as an example. - MatrixD3x3 rotationMatrix(double tilt_deg, double skew_deg, double yaw_deg, double phi_deg) { - if (skew_deg != 0 || yaw_deg != 0) + MatrixD3x3 rotationMatrix(double tilt_rad, double skew_rad, double yaw_rad, double phi_rad) { + if (skew_rad != 0 || yaw_rad != 0) throw std::invalid_argument("Skew and yaw angles are not currently supported."); - double tilt_rad = degToRad(tilt_deg); - double phi_rad = degToRad(phi_deg); // Rotation around Z-axis that makes the sensor "face towards" the beamline (i.e. towards z-axis) // So for example if phi=0 then R is the identity (i.e. already facing), or if phi=90deg @@ -62,14 +60,13 @@ namespace lstgeometry { void transformSensorCorners(ModuleInfo& moduleInfo) { auto module_z = moduleInfo.sensorCenterZ_mm; auto module_rho = moduleInfo.sensorCenterRho_mm; - auto module_phi = moduleInfo.phi_deg; + auto module_phi = moduleInfo.phi_rad; auto sensor_spacing = moduleInfo.sensorSpacing_mm; auto sensor_width = moduleInfo.meanWidth_mm; auto sensor_length = moduleInfo.length_mm; - auto phi_rad = degToRad(module_phi); - auto module_x = module_rho * cos(phi_rad); - auto module_y = module_rho * sin(phi_rad); + auto module_x = module_rho * cos(module_phi); + auto module_y = module_rho * sin(module_phi); auto half_width = sensor_width / 2; auto half_length = sensor_length / 2; @@ -94,7 +91,7 @@ namespace lstgeometry { {half_spacing, half_width, -half_length}}; MatrixD3x3 rotation_matrix = - rotationMatrix(moduleInfo.tiltAngle_deg, moduleInfo.skewAngle_deg, moduleInfo.yawAngle_deg, moduleInfo.phi_deg); + rotationMatrix(moduleInfo.tiltAngle_rad, moduleInfo.skewAngle_rad, moduleInfo.yawAngle_rad, moduleInfo.phi_rad); MatrixD8x3 rotated_corners = (rotation_matrix * corners.transpose()).transpose(); rotated_corners.rowwise() += RowVectorD3{module_x, module_y, module_z}; @@ -123,14 +120,14 @@ namespace lstgeometry { double sensor1_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_mm; double sensor1_center_x = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(degToRad(sensors.at(sensor_det_id_1).phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(sensors.at(sensor_det_id_1).phi_rad); double sensor1_center_y = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(degToRad(sensors.at(sensor_det_id_1).phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(sensors.at(sensor_det_id_1).phi_rad); double sensor2_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_mm; double sensor2_center_x = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(degToRad(sensors.at(sensor_det_id_1).phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(sensors.at(sensor_det_id_1).phi_rad); double sensor2_center_y = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(degToRad(sensors.at(sensor_det_id_1).phi_deg)); + sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(sensors.at(sensor_det_id_1).phi_rad); RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index f7a1aeba648c4..82f8c7e171fe9 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -2,6 +2,7 @@ #define RecoTracker_LSTCore_interface_LSTGeometry_IO_h #include "Common.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" @@ -59,16 +60,12 @@ namespace lstgeometry { ModuleInfo m; m.detId = std::stoul(tokens[0]); - m.binaryDetId = std::stoul(tokens[1], nullptr, 2); - m.section = tokens[2]; - m.layer = std::stoi(tokens[3]); - m.ring = std::stoi(tokens[4]); m.sensorCenterRho_mm = std::stod(tokens[5]); m.sensorCenterZ_mm = std::stod(tokens[6]); - m.tiltAngle_deg = std::stod(tokens[7]); - m.skewAngle_deg = std::stod(tokens[8]); - m.yawAngle_deg = std::stod(tokens[9]); - m.phi_deg = std::stod(tokens[10]); + m.tiltAngle_rad = degToRad(std::stod(tokens[7])); + m.skewAngle_rad = degToRad(std::stod(tokens[8])); + m.yawAngle_rad = degToRad(std::stod(tokens[9])); + m.phi_rad = degToRad(std::stod(tokens[10])); m.vtxOneX_mm = std::stod(tokens[11]); m.vtxOneY_mm = std::stod(tokens[12]); m.vtxTwoX_mm = std::stod(tokens[13]); @@ -80,7 +77,6 @@ namespace lstgeometry { m.meanWidth_mm = std::stod(tokens[19]); m.length_mm = std::stod(tokens[20]); m.sensorSpacing_mm = std::stod(tokens[21]); - m.sensorThickness_mm = std::stod(tokens[22]); modules.push_back(m); } @@ -111,13 +107,9 @@ namespace lstgeometry { SensorInfo s; s.detId = std::stoul(tokens[0]); - s.binaryDetId = std::stoul(tokens[1], nullptr, 2); - s.section = tokens[2]; - s.layer = std::stoi(tokens[3]); - s.ring = std::stoi(tokens[4]); s.sensorCenterRho_mm = std::stod(tokens[5]); s.sensorCenterZ_mm = std::stod(tokens[6]); - s.phi_deg = std::stod(tokens[7]); + s.phi_rad = degToRad(std::stod(tokens[7])); sensors[s.detId] = s; } @@ -185,7 +177,7 @@ namespace lstgeometry { for (auto& [detid, slope] : slopes) { float drdz_slope = slope.drdz_slope; float dxdy_slope = slope.dxdy_slope; - float phi = degToRad(sensors.at(detid).phi_deg); + float phi = sensors.at(detid).phi_rad; file.write(reinterpret_cast(&detid), sizeof(detid)); if (drdz_slope != kDefaultSlope) { file.write(reinterpret_cast(&drdz_slope), sizeof(drdz_slope)); @@ -199,7 +191,7 @@ namespace lstgeometry { for (auto& [detid, slope] : slopes) { float drdz_slope = slope.drdz_slope; float dxdy_slope = slope.dxdy_slope; - float phi = degToRad(sensors.at(detid).phi_deg); + float phi = sensors.at(detid).phi_rad; file << detid << ","; if (drdz_slope != kDefaultSlope) { file << drdz_slope << "," << dxdy_slope << std::endl; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h index 1500dd143d051..a356afb5f68d5 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h @@ -7,16 +7,12 @@ namespace lstgeometry { struct ModuleInfo { unsigned int detId; - unsigned int binaryDetId; - std::string section; - int layer; - int ring; double sensorCenterRho_mm; double sensorCenterZ_mm; - double tiltAngle_deg; - double skewAngle_deg; - double yawAngle_deg; - double phi_deg; + double tiltAngle_rad; + double skewAngle_rad; + double yawAngle_rad; + double phi_rad; double vtxOneX_mm; double vtxOneY_mm; double vtxTwoX_mm; @@ -28,7 +24,6 @@ namespace lstgeometry { double meanWidth_mm; double length_mm; double sensorSpacing_mm; - double sensorThickness_mm; MatrixD8x3 transformedCorners; }; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h index f2a6e1ca50cb6..ac26042266d0b 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h @@ -7,13 +7,9 @@ namespace lstgeometry { struct SensorInfo { unsigned int detId; - unsigned int binaryDetId; - std::string section; - int layer; - int ring; double sensorCenterRho_mm; double sensorCenterZ_mm; - double phi_deg; + double phi_rad; }; } // namespace lstgeometry From fcc5aa96fc9b8d392edea1ec315b942674fc82c7 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 21 Nov 2025 21:41:57 +0000 Subject: [PATCH 30/95] Everything mostly matches up now, but need to clean up --- .../LSTCore/interface/LSTGeometry/Module.h | 4 +- .../LSTCore/plugins/LSTGeometryESProducer.cc | 139 +++++++++++++----- 2 files changed, 106 insertions(+), 37 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h index 9307f29b965f0..de65a28e0746b 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h @@ -22,8 +22,8 @@ namespace lstgeometry { // // x x x x x x x x x x x x x x x x x x x x x x x x x x x x x // - // -subdet- -layer-- -side --------rod--------- -------module------- # if subdet == 5 - // -subdet- -side --layer- ----ring--- -------module------- # if subdet == 4 + // -subdet- -layer-- -side --------rod--------- -------module------- # if subdet == 5 + // -subdet- -side --layer- ----ring--- -------module------- # if subdet == 4 // // diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 68953c899ae03..904536db5eb04 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -14,6 +14,14 @@ #include "DataFormats/SiStripDetId/interface/SiStripEnums.h" +#include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" + +#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" + +#include +#include + // temporary #include "FWCore/Utilities/interface/typelookup.h" #include @@ -55,60 +63,121 @@ std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeo trackerGeom_ = &iRecord.get(geomToken_); trackerTopo_ = &iRecord.get(ttopoToken_); - // Maybe limit it to a subset of dets + std::vector sensors; + std::vector modules; + for (auto &det : trackerGeom_->dets()) { + const DetId detId = det->geographicalId(); const auto &surface = det->surface(); const Bounds *b = &(surface).bounds(); const auto &position = surface.position(); - const double rho_mm = position.perp() * 10; - const double z_mm = position.z() * 10; + double rho_mm = position.perp() * 10; + double z_mm = position.z() * 10; const double phi_rad = position.phi(); - // if (detId() != 441201726) + if (det->isLeaf()) { + // Leafs are the sensors + lstgeometry::SensorInfo sensor; + sensor.detId = detId(); + sensor.sensorCenterRho_mm = rho_mm; + sensor.sensorCenterZ_mm = z_mm; + sensor.phi_rad = phi_rad; + sensors.push_back(sensor); + continue; + } + + double tiltAngle_rad = std::asin(det->rotation().zz()); + + double meanWidth_mm = 0.0; + double length_mm = 0.0; + + if (det->components().size() != 2) { + std::cout << "Not equal to 2! " << det->components().size() << "\n"; + continue; + } + + double sensorSpacing_mm = det->components()[0]->toLocal(det->components()[1]->position()).mag() * 10; + + // if (detId() != 438043652) // continue; // std::cout << "DetId " << detId() << "\n"; + // std::cout << "rho_mm " << rho_mm << "\n"; + // std::cout << "z_mm " << z_mm << "\n"; // std::cout << "det " << detId.det() << "\n"; // std::cout << "subdet " << detId.subdetId() << "\n"; // std::cout << "layer " << trackerTopo_->layer(detId) << "\n"; // std::cout << "print " << trackerTopo_->print(detId) << "\n"; double vtxOneX_mm, vtxOneY_mm, vtxTwoX_mm, vtxTwoY_mm, vtxThreeX_mm, vtxThreeY_mm, vtxFourX_mm, vtxFourY_mm; + double vtxOneX_mm_tmp, vtxOneY_mm_tmp, vtxTwoX_mm_tmp, vtxTwoY_mm_tmp, vtxThreeX_mm_tmp, vtxThreeY_mm_tmp, vtxFourX_mm_tmp, vtxFourY_mm_tmp; + + if (GeomDetEnumerators::isBarrel(det->subDetector())) { + if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { + // Rectangular + meanWidth_mm = b2->width() * 10; + length_mm = b2->length() * 10; + float dx = b2->width()* 10 * 0.5; // half width + float dy = b2->length()* 10 * 0.5; // half length + // std::cout << "Rectangle parameters " << b2->width() << " " << b2->length() << "\n"; + // std::cout << std::sin(phi_rad) << "\n"; + // vtxOneX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); + // vtxOneY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); + // vtxTwoX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); + // vtxTwoY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); + // vtxThreeX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); + // vtxThreeY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); + // vtxFourX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); + // vtxFourY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); + vtxOneX_mm_tmp = rho_mm - dy * std::sin(tiltAngle_rad); + vtxOneY_mm_tmp = dx; + vtxTwoX_mm_tmp = rho_mm + dy * std::sin(tiltAngle_rad); + vtxTwoY_mm_tmp = dx; + vtxThreeX_mm_tmp = rho_mm - dy * std::sin(tiltAngle_rad); + vtxThreeY_mm_tmp = -dx; + vtxFourX_mm_tmp = rho_mm + dy * std::sin(tiltAngle_rad); + vtxFourY_mm_tmp = -dx; + } else { + throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; + } + // rho_mm -= sensorSpacing_mm/2.0; + } else { + if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { + // Rectangular + meanWidth_mm = b2->width() * 10; + length_mm = b2->length() * 10; + float dx = b2->width()* 10 * 0.5; // half width + float dy = b2->length()* 10 * 0.5; // half length + // std::cout << "Rectangle parameters " << b2->width() << " " << b2->length() << "\n"; + vtxOneX_mm_tmp = rho_mm + dy; + vtxOneY_mm_tmp = dx; + vtxTwoX_mm_tmp = rho_mm - dy; + vtxTwoY_mm_tmp = dx; + vtxThreeX_mm_tmp = rho_mm - dy; + vtxThreeY_mm_tmp = -dx; + vtxFourX_mm_tmp = rho_mm + dy; + vtxFourY_mm_tmp = -dx; + std::cout << detId() << " " << vtxOneX_mm_tmp << " " << vtxOneY_mm_tmp << " " << vtxTwoX_mm_tmp << " " << vtxTwoY_mm_tmp << " " << vtxThreeX_mm_tmp << " " << vtxThreeY_mm_tmp << " " << vtxFourX_mm_tmp << " " << vtxFourY_mm_tmp << std::endl; + } else { + throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; + } + + // z_mm -= sensorSpacing_mm/2.0; // Not sure why + } + + vtxOneX_mm = vtxOneX_mm_tmp * cos(phi_rad) + vtxOneY_mm_tmp * sin(phi_rad); + vtxOneY_mm = vtxOneX_mm_tmp * sin(phi_rad) - vtxOneY_mm_tmp * cos(phi_rad); + vtxTwoX_mm = vtxTwoX_mm_tmp * cos(phi_rad) + vtxTwoY_mm_tmp * sin(phi_rad); + vtxTwoY_mm = vtxTwoX_mm_tmp * sin(phi_rad) - vtxTwoY_mm_tmp * cos(phi_rad); + vtxThreeX_mm = vtxThreeX_mm_tmp * cos(phi_rad) + vtxThreeY_mm_tmp * sin(phi_rad); + vtxThreeY_mm = vtxThreeX_mm_tmp * sin(phi_rad) - vtxThreeY_mm_tmp * cos(phi_rad); + vtxFourX_mm = vtxFourX_mm_tmp * cos(phi_rad) + vtxFourY_mm_tmp * sin(phi_rad); + vtxFourY_mm = vtxFourX_mm_tmp * sin(phi_rad) - vtxFourY_mm_tmp * cos(phi_rad); - if (const TrapezoidalPlaneBounds *b2 = dynamic_cast(b)) { - // See sec. "TrapezoidalPlaneBounds parameters" in doc/reco-geom-notes.txt - std::array const &par = b2->parameters(); - vtxOneX_mm = rho_mm * cos(phi_rad) -par[0]* 10 * sin(phi_rad); - vtxOneY_mm = rho_mm * sin(phi_rad) -par[3]* 10 * cos(phi_rad); - vtxTwoX_mm = rho_mm * cos(phi_rad) -par[1]* 10 * sin(phi_rad); - vtxTwoY_mm = rho_mm * sin(phi_rad) + par[3]* 10 * cos(phi_rad); - vtxThreeX_mm = rho_mm * cos(phi_rad) + par[1]* 10 * sin(phi_rad); - vtxThreeY_mm = rho_mm * sin(phi_rad) + par[3]* 10 * cos(phi_rad); - vtxFourX_mm = rho_mm * cos(phi_rad) + par[0]* 10 * sin(phi_rad); - vtxFourY_mm = rho_mm * sin(phi_rad) + -par[3]* 10 * cos(phi_rad); - //dz = par[2]; - //ms.round_assign(par[0], par[1], par[3], par[2]); - } else if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { - // Rectangular - float dx = b2->width()* 10 * 0.5; // half width - float dy = b2->length()* 10 * 0.5; // half length - vtxOneX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); - vtxOneY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); - vtxTwoX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); - vtxTwoY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); - vtxThreeX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); - vtxThreeY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); - vtxFourX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); - vtxFourY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); - //dz = b2->thickness() * 0.5; // half thickness - //ms.round_assign(dx, 0.0f, dy, dz); - } else { - throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; - } - // std::cout << detId() << " " << rho_mm << " " << z_mm << " " << phi_rad << " " << vtxOneX_mm << " " << vtxOneY_mm << " " << vtxTwoX_mm << " " << vtxTwoY_mm << " " << vtxThreeX_mm << " " << vtxThreeY_mm << " " << vtxFourX_mm << " " << vtxFourY_mm << std::endl; + std::cout << detId() << " " << rho_mm << " " << z_mm << " " << phi_rad << " " << vtxOneX_mm << " " << vtxOneY_mm << " " << vtxTwoX_mm << " " << vtxTwoY_mm << " " << vtxThreeX_mm << " " << vtxThreeY_mm << " " << vtxFourX_mm << " " << vtxFourY_mm << " " << meanWidth_mm << " " << length_mm << " " << sensorSpacing_mm << " " << tiltAngle_rad << std::endl; } // placeholder From eecb9bc4d3121e5f6455949932845fcf140730a6 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 24 Nov 2025 14:34:31 -0500 Subject: [PATCH 31/95] Switched from mm to cm --- .../interface/LSTGeometry/CentroidMethods.h | 4 +- .../interface/LSTGeometry/CornerMethods.h | 31 +++-- .../LSTCore/interface/LSTGeometry/IO.h | 30 ++--- .../interface/LSTGeometry/ModuleInfo.h | 26 ++--- .../interface/LSTGeometry/ModuleMapMethods.h | 6 +- .../interface/LSTGeometry/SensorInfo.h | 4 +- .../LSTCore/plugins/LSTGeometryESProducer.cc | 110 +++++++++--------- 7 files changed, 103 insertions(+), 108 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 99f4010c93d0a..b16c7780bcbed 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -63,8 +63,8 @@ namespace lstgeometry { } // Convert from mm to cm - double z = sensor.sensorCenterZ_mm / 10.0; - double rho = sensor.sensorCenterRho_mm / 10.0; + double z = sensor.sensorCenterZ_cm; + double rho = sensor.sensorCenterRho_cm; double phi = sensor.phi_rad; double x = rho * cos(phi); double y = rho * sin(phi); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 6bd223790abba..8bf88aaad7ad8 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -58,12 +58,12 @@ namespace lstgeometry { // Calculates the transformed corners of each sensor void transformSensorCorners(ModuleInfo& moduleInfo) { - auto module_z = moduleInfo.sensorCenterZ_mm; - auto module_rho = moduleInfo.sensorCenterRho_mm; + auto module_z = moduleInfo.sensorCenterZ_cm; + auto module_rho = moduleInfo.sensorCenterRho_cm; auto module_phi = moduleInfo.phi_rad; - auto sensor_spacing = moduleInfo.sensorSpacing_mm; - auto sensor_width = moduleInfo.meanWidth_mm; - auto sensor_length = moduleInfo.length_mm; + auto sensor_spacing = moduleInfo.sensorSpacing_cm; + auto sensor_width = moduleInfo.meanWidth_cm; + auto sensor_length = moduleInfo.length_cm; auto module_x = module_rho * cos(module_phi); auto module_y = module_rho * sin(module_phi); @@ -75,8 +75,8 @@ namespace lstgeometry { // Make the module sizes consistent with hit-based method. // FIXME: Using the real (smaller) sizes specified by CSV file increases // fake rate significantly and lowers efficiency between abs(eta) 1 to 2. - auto width_extension = 50.0 - half_width; - auto length_extension = (half_length > 40 ? 50.0 : 25.0) - half_length; + auto width_extension = 5.0 - half_width; + auto length_extension = (half_length > 4 ? 5.0 : 2.5) - half_length; half_width += width_extension; half_length += length_extension; @@ -96,8 +96,6 @@ namespace lstgeometry { rotated_corners.rowwise() += RowVectorD3{module_x, module_y, module_z}; - rotated_corners /= 10; - // Coordinate reorder before saving (x,y,z)->(z,x,y) moduleInfo.transformedCorners.col(0) = rotated_corners.col(2); moduleInfo.transformedCorners.col(1) = rotated_corners.col(0); @@ -118,23 +116,20 @@ namespace lstgeometry { RowVectorD3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); RowVectorD3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); - double sensor1_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_mm; + double sensor1_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_cm; double sensor1_center_x = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(sensors.at(sensor_det_id_1).phi_rad); + sensors.at(sensor_det_id_1).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_1).phi_rad); double sensor1_center_y = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(sensors.at(sensor_det_id_1).phi_rad); - double sensor2_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_mm; + sensors.at(sensor_det_id_1).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_1).phi_rad); + double sensor2_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_cm; double sensor2_center_x = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * cos(sensors.at(sensor_det_id_1).phi_rad); + sensors.at(sensor_det_id_1).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_1).phi_rad); double sensor2_center_y = - sensors.at(sensor_det_id_1).sensorCenterRho_mm * sin(sensors.at(sensor_det_id_1).phi_rad); + sensors.at(sensor_det_id_1).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_1).phi_rad); RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; - sensor_centroid_1 /= 10; - sensor_centroid_2 /= 10; - double distance_to_sensor_1 = (centroid_sensor_1 - sensor_centroid_1).norm(); double distance_to_sensor_2 = (centroid_sensor_2 - sensor_centroid_2).norm(); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 82f8c7e171fe9..c8f63bfc34ef8 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -60,23 +60,23 @@ namespace lstgeometry { ModuleInfo m; m.detId = std::stoul(tokens[0]); - m.sensorCenterRho_mm = std::stod(tokens[5]); - m.sensorCenterZ_mm = std::stod(tokens[6]); + m.sensorCenterRho_cm = std::stod(tokens[5]) / 10.0; + m.sensorCenterZ_cm = std::stod(tokens[6]) / 10.0; m.tiltAngle_rad = degToRad(std::stod(tokens[7])); m.skewAngle_rad = degToRad(std::stod(tokens[8])); m.yawAngle_rad = degToRad(std::stod(tokens[9])); m.phi_rad = degToRad(std::stod(tokens[10])); - m.vtxOneX_mm = std::stod(tokens[11]); - m.vtxOneY_mm = std::stod(tokens[12]); - m.vtxTwoX_mm = std::stod(tokens[13]); - m.vtxTwoY_mm = std::stod(tokens[14]); - m.vtxThreeX_mm = std::stod(tokens[15]); - m.vtxThreeY_mm = std::stod(tokens[16]); - m.vtxFourX_mm = std::stod(tokens[17]); - m.vtxFourY_mm = std::stod(tokens[18]); - m.meanWidth_mm = std::stod(tokens[19]); - m.length_mm = std::stod(tokens[20]); - m.sensorSpacing_mm = std::stod(tokens[21]); + m.vtxOneX_cm = std::stod(tokens[11]) / 10.0; + m.vtxOneY_cm = std::stod(tokens[12]) / 10.0; + m.vtxTwoX_cm = std::stod(tokens[13]) / 10.0; + m.vtxTwoY_cm = std::stod(tokens[14]) / 10.0; + m.vtxThreeX_cm = std::stod(tokens[15]) / 10.0; + m.vtxThreeY_cm = std::stod(tokens[16]) / 10.0; + m.vtxFourX_cm = std::stod(tokens[17]) / 10.0; + m.vtxFourY_cm = std::stod(tokens[18]) / 10.0; + m.meanWidth_cm = std::stod(tokens[19]) / 10.0; + m.length_cm = std::stod(tokens[20]) / 10.0; + m.sensorSpacing_cm = std::stod(tokens[21]) / 10.0; modules.push_back(m); } @@ -107,8 +107,8 @@ namespace lstgeometry { SensorInfo s; s.detId = std::stoul(tokens[0]); - s.sensorCenterRho_mm = std::stod(tokens[5]); - s.sensorCenterZ_mm = std::stod(tokens[6]); + s.sensorCenterRho_cm = std::stod(tokens[5]) / 10.0; + s.sensorCenterZ_cm = std::stod(tokens[6]) / 10.0; s.phi_rad = degToRad(std::stod(tokens[7])); sensors[s.detId] = s; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h index a356afb5f68d5..64a4639d2318f 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h @@ -7,23 +7,23 @@ namespace lstgeometry { struct ModuleInfo { unsigned int detId; - double sensorCenterRho_mm; - double sensorCenterZ_mm; + double sensorCenterRho_cm; + double sensorCenterZ_cm; double tiltAngle_rad; double skewAngle_rad; double yawAngle_rad; double phi_rad; - double vtxOneX_mm; - double vtxOneY_mm; - double vtxTwoX_mm; - double vtxTwoY_mm; - double vtxThreeX_mm; - double vtxThreeY_mm; - double vtxFourX_mm; - double vtxFourY_mm; - double meanWidth_mm; - double length_mm; - double sensorSpacing_mm; + double vtxOneX_cm; + double vtxOneY_cm; + double vtxTwoX_cm; + double vtxTwoY_cm; + double vtxThreeX_cm; + double vtxThreeY_cm; + double vtxFourX_cm; + double vtxFourY_cm; + double meanWidth_cm; + double length_cm; + double sensorSpacing_cm; MatrixD8x3 transformedCorners; }; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index fe21ae6f2c2d8..e88306a8cc449 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -50,7 +50,7 @@ namespace lstgeometry { if (ref_subdet == 5) { std::unordered_set barrel_endcap_connected_tar_detids; - for (int zshift : {0, 10, -10}) { + for (float zshift : {0, 10, -10}) { std::vector ref_polygon; ref_polygon.push_back(getEtaPhiPolygon(det_geom.getCorners(ref_detid), refphi, zshift)); @@ -74,7 +74,7 @@ namespace lstgeometry { for (auto& ref_polygon_piece : ref_polygon) area += boost::geometry::area(ref_polygon_piece); - if (area <= 0.0001) + if (area <= 1e-6) continue; auto const& new_tar_detids_to_be_considered = @@ -242,7 +242,7 @@ namespace lstgeometry { for (auto& ref_polygon_piece : ref_polygon) area += boost::geometry::area(ref_polygon_piece); - if (area > 0.0001) { + if (area > 1e-6) { auto const& new_tar_detids_to_be_considered = det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h index ac26042266d0b..ffd6f336e3d4d 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h @@ -7,8 +7,8 @@ namespace lstgeometry { struct SensorInfo { unsigned int detId; - double sensorCenterRho_mm; - double sensorCenterZ_mm; + double sensorCenterRho_cm; + double sensorCenterZ_cm; double phi_rad; }; } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 904536db5eb04..a6d0da69ad2c2 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -74,16 +74,16 @@ std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeo const Bounds *b = &(surface).bounds(); const auto &position = surface.position(); - double rho_mm = position.perp() * 10; - double z_mm = position.z() * 10; + double rho_cm = position.perp(); + double z_cm = position.z(); const double phi_rad = position.phi(); if (det->isLeaf()) { // Leafs are the sensors lstgeometry::SensorInfo sensor; sensor.detId = detId(); - sensor.sensorCenterRho_mm = rho_mm; - sensor.sensorCenterZ_mm = z_mm; + sensor.sensorCenterRho_cm = rho_cm; + sensor.sensorCenterZ_cm = z_cm; sensor.phi_rad = phi_rad; sensors.push_back(sensor); continue; @@ -91,93 +91,93 @@ std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeo double tiltAngle_rad = std::asin(det->rotation().zz()); - double meanWidth_mm = 0.0; - double length_mm = 0.0; + double meanWidth_cm = 0.0; + double length_cm = 0.0; if (det->components().size() != 2) { std::cout << "Not equal to 2! " << det->components().size() << "\n"; continue; } - double sensorSpacing_mm = det->components()[0]->toLocal(det->components()[1]->position()).mag() * 10; + double sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag() * 10; // if (detId() != 438043652) // continue; // std::cout << "DetId " << detId() << "\n"; - // std::cout << "rho_mm " << rho_mm << "\n"; - // std::cout << "z_mm " << z_mm << "\n"; + // std::cout << "rho_cm " << rho_cm << "\n"; + // std::cout << "z_cm " << z_cm << "\n"; // std::cout << "det " << detId.det() << "\n"; // std::cout << "subdet " << detId.subdetId() << "\n"; // std::cout << "layer " << trackerTopo_->layer(detId) << "\n"; // std::cout << "print " << trackerTopo_->print(detId) << "\n"; - double vtxOneX_mm, vtxOneY_mm, vtxTwoX_mm, vtxTwoY_mm, vtxThreeX_mm, vtxThreeY_mm, vtxFourX_mm, vtxFourY_mm; - double vtxOneX_mm_tmp, vtxOneY_mm_tmp, vtxTwoX_mm_tmp, vtxTwoY_mm_tmp, vtxThreeX_mm_tmp, vtxThreeY_mm_tmp, vtxFourX_mm_tmp, vtxFourY_mm_tmp; + double vtxOneX_cm, vtxOneY_cm, vtxTwoX_cm, vtxTwoY_cm, vtxThreeX_cm, vtxThreeY_cm, vtxFourX_cm, vtxFourY_cm; + double vtxOneX_cm_tmp, vtxOneY_cm_tmp, vtxTwoX_cm_tmp, vtxTwoY_cm_tmp, vtxThreeX_cm_tmp, vtxThreeY_cm_tmp, vtxFourX_cm_tmp, vtxFourY_cm_tmp; if (GeomDetEnumerators::isBarrel(det->subDetector())) { if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { // Rectangular - meanWidth_mm = b2->width() * 10; - length_mm = b2->length() * 10; - float dx = b2->width()* 10 * 0.5; // half width - float dy = b2->length()* 10 * 0.5; // half length + meanWidth_cm = b2->width(); + length_cm = b2->length(); + float dx = b2->width() * 0.5; // half width + float dy = b2->length() * 0.5; // half length // std::cout << "Rectangle parameters " << b2->width() << " " << b2->length() << "\n"; // std::cout << std::sin(phi_rad) << "\n"; - // vtxOneX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); - // vtxOneY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); - // vtxTwoX_mm = rho_mm * cos(phi_rad) -dx * sin(phi_rad); - // vtxTwoY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); - // vtxThreeX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); - // vtxThreeY_mm = rho_mm * sin(phi_rad) + dy * cos(phi_rad); - // vtxFourX_mm = rho_mm * cos(phi_rad) + dx * sin(phi_rad); - // vtxFourY_mm = rho_mm * sin(phi_rad) -dy * cos(phi_rad); - vtxOneX_mm_tmp = rho_mm - dy * std::sin(tiltAngle_rad); - vtxOneY_mm_tmp = dx; - vtxTwoX_mm_tmp = rho_mm + dy * std::sin(tiltAngle_rad); - vtxTwoY_mm_tmp = dx; - vtxThreeX_mm_tmp = rho_mm - dy * std::sin(tiltAngle_rad); - vtxThreeY_mm_tmp = -dx; - vtxFourX_mm_tmp = rho_mm + dy * std::sin(tiltAngle_rad); - vtxFourY_mm_tmp = -dx; + // vtxOneX_cm = rho_cm * cos(phi_rad) -dx * sin(phi_rad); + // vtxOneY_cm = rho_cm * sin(phi_rad) -dy * cos(phi_rad); + // vtxTwoX_cm = rho_cm * cos(phi_rad) -dx * sin(phi_rad); + // vtxTwoY_cm = rho_cm * sin(phi_rad) + dy * cos(phi_rad); + // vtxThreeX_cm = rho_cm * cos(phi_rad) + dx * sin(phi_rad); + // vtxThreeY_cm = rho_cm * sin(phi_rad) + dy * cos(phi_rad); + // vtxFourX_cm = rho_cm * cos(phi_rad) + dx * sin(phi_rad); + // vtxFourY_cm = rho_cm * sin(phi_rad) -dy * cos(phi_rad); + vtxOneX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); + vtxOneY_cm_tmp = dx; + vtxTwoX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); + vtxTwoY_cm_tmp = dx; + vtxThreeX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); + vtxThreeY_cm_tmp = -dx; + vtxFourX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); + vtxFourY_cm_tmp = -dx; } else { throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; } - // rho_mm -= sensorSpacing_mm/2.0; + // rho_cm -= sensorSpacing_cm/2.0; } else { if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { // Rectangular - meanWidth_mm = b2->width() * 10; - length_mm = b2->length() * 10; - float dx = b2->width()* 10 * 0.5; // half width - float dy = b2->length()* 10 * 0.5; // half length + meanWidth_cm = b2->width(); + length_cm = b2->length(); + float dx = b2->width() * 0.5; // half width + float dy = b2->length() * 0.5; // half length // std::cout << "Rectangle parameters " << b2->width() << " " << b2->length() << "\n"; - vtxOneX_mm_tmp = rho_mm + dy; - vtxOneY_mm_tmp = dx; - vtxTwoX_mm_tmp = rho_mm - dy; - vtxTwoY_mm_tmp = dx; - vtxThreeX_mm_tmp = rho_mm - dy; - vtxThreeY_mm_tmp = -dx; - vtxFourX_mm_tmp = rho_mm + dy; - vtxFourY_mm_tmp = -dx; - std::cout << detId() << " " << vtxOneX_mm_tmp << " " << vtxOneY_mm_tmp << " " << vtxTwoX_mm_tmp << " " << vtxTwoY_mm_tmp << " " << vtxThreeX_mm_tmp << " " << vtxThreeY_mm_tmp << " " << vtxFourX_mm_tmp << " " << vtxFourY_mm_tmp << std::endl; + vtxOneX_cm_tmp = rho_cm + dy; + vtxOneY_cm_tmp = dx; + vtxTwoX_cm_tmp = rho_cm - dy; + vtxTwoY_cm_tmp = dx; + vtxThreeX_cm_tmp = rho_cm - dy; + vtxThreeY_cm_tmp = -dx; + vtxFourX_cm_tmp = rho_cm + dy; + vtxFourY_cm_tmp = -dx; + std::cout << detId() << " " << vtxOneX_cm_tmp << " " << vtxOneY_cm_tmp << " " << vtxTwoX_cm_tmp << " " << vtxTwoY_cm_tmp << " " << vtxThreeX_cm_tmp << " " << vtxThreeY_cm_tmp << " " << vtxFourX_cm_tmp << " " << vtxFourY_cm_tmp << std::endl; } else { throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; } - // z_mm -= sensorSpacing_mm/2.0; // Not sure why + // z_cm -= sensorSpacing_cm/2.0; // Not sure why } - vtxOneX_mm = vtxOneX_mm_tmp * cos(phi_rad) + vtxOneY_mm_tmp * sin(phi_rad); - vtxOneY_mm = vtxOneX_mm_tmp * sin(phi_rad) - vtxOneY_mm_tmp * cos(phi_rad); - vtxTwoX_mm = vtxTwoX_mm_tmp * cos(phi_rad) + vtxTwoY_mm_tmp * sin(phi_rad); - vtxTwoY_mm = vtxTwoX_mm_tmp * sin(phi_rad) - vtxTwoY_mm_tmp * cos(phi_rad); - vtxThreeX_mm = vtxThreeX_mm_tmp * cos(phi_rad) + vtxThreeY_mm_tmp * sin(phi_rad); - vtxThreeY_mm = vtxThreeX_mm_tmp * sin(phi_rad) - vtxThreeY_mm_tmp * cos(phi_rad); - vtxFourX_mm = vtxFourX_mm_tmp * cos(phi_rad) + vtxFourY_mm_tmp * sin(phi_rad); - vtxFourY_mm = vtxFourX_mm_tmp * sin(phi_rad) - vtxFourY_mm_tmp * cos(phi_rad); + vtxOneX_cm = vtxOneX_cm_tmp * cos(phi_rad) + vtxOneY_cm_tmp * sin(phi_rad); + vtxOneY_cm = vtxOneX_cm_tmp * sin(phi_rad) - vtxOneY_cm_tmp * cos(phi_rad); + vtxTwoX_cm = vtxTwoX_cm_tmp * cos(phi_rad) + vtxTwoY_cm_tmp * sin(phi_rad); + vtxTwoY_cm = vtxTwoX_cm_tmp * sin(phi_rad) - vtxTwoY_cm_tmp * cos(phi_rad); + vtxThreeX_cm = vtxThreeX_cm_tmp * cos(phi_rad) + vtxThreeY_cm_tmp * sin(phi_rad); + vtxThreeY_cm = vtxThreeX_cm_tmp * sin(phi_rad) - vtxThreeY_cm_tmp * cos(phi_rad); + vtxFourX_cm = vtxFourX_cm_tmp * cos(phi_rad) + vtxFourY_cm_tmp * sin(phi_rad); + vtxFourY_cm = vtxFourX_cm_tmp * sin(phi_rad) - vtxFourY_cm_tmp * cos(phi_rad); - std::cout << detId() << " " << rho_mm << " " << z_mm << " " << phi_rad << " " << vtxOneX_mm << " " << vtxOneY_mm << " " << vtxTwoX_mm << " " << vtxTwoY_mm << " " << vtxThreeX_mm << " " << vtxThreeY_mm << " " << vtxFourX_mm << " " << vtxFourY_mm << " " << meanWidth_mm << " " << length_mm << " " << sensorSpacing_mm << " " << tiltAngle_rad << std::endl; + std::cout << detId() << " " << rho_cm << " " << z_cm << " " << phi_rad << " " << vtxOneX_cm << " " << vtxOneY_cm << " " << vtxTwoX_cm << " " << vtxTwoY_cm << " " << vtxThreeX_cm << " " << vtxThreeY_cm << " " << vtxFourX_cm << " " << vtxFourY_cm << " " << meanWidth_cm << " " << length_cm << " " << sensorSpacing_cm << " " << tiltAngle_rad << std::endl; } // placeholder From 2a0858f07a7664cfbb3899208584abc9f94f3cea Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 24 Nov 2025 21:45:34 +0000 Subject: [PATCH 32/95] All CMSSW inputs work --- .../LSTCore/plugins/LSTGeometryESProducer.cc | 213 ++++++++---------- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 11 +- 2 files changed, 105 insertions(+), 119 deletions(-) diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index a6d0da69ad2c2..3597a98eb0a26 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -18,6 +18,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" #include #include @@ -62,125 +63,109 @@ void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &des std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { trackerGeom_ = &iRecord.get(geomToken_); trackerTopo_ = &iRecord.get(ttopoToken_); - + std::vector sensors; std::vector modules; - + + std::vector avg_r_cm(6, 0.0); + std::vector avg_z_cm(5, 0.0); + std::vector avg_r_counter(6, 0); + std::vector avg_z_counter(5, 0); + for (auto &det : trackerGeom_->dets()) { - - const DetId detId = det->geographicalId(); - - const auto &surface = det->surface(); - const Bounds *b = &(surface).bounds(); - const auto &position = surface.position(); - - double rho_cm = position.perp(); - double z_cm = position.z(); - const double phi_rad = position.phi(); - - if (det->isLeaf()) { - // Leafs are the sensors - lstgeometry::SensorInfo sensor; - sensor.detId = detId(); - sensor.sensorCenterRho_cm = rho_cm; - sensor.sensorCenterZ_cm = z_cm; - sensor.phi_rad = phi_rad; - sensors.push_back(sensor); - continue; - } - - double tiltAngle_rad = std::asin(det->rotation().zz()); - - double meanWidth_cm = 0.0; - double length_cm = 0.0; - - if (det->components().size() != 2) { - std::cout << "Not equal to 2! " << det->components().size() << "\n"; - continue; - } - - double sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag() * 10; - - // if (detId() != 438043652) - // continue; - - // std::cout << "DetId " << detId() << "\n"; - // std::cout << "rho_cm " << rho_cm << "\n"; - // std::cout << "z_cm " << z_cm << "\n"; - // std::cout << "det " << detId.det() << "\n"; - // std::cout << "subdet " << detId.subdetId() << "\n"; - // std::cout << "layer " << trackerTopo_->layer(detId) << "\n"; - // std::cout << "print " << trackerTopo_->print(detId) << "\n"; - - double vtxOneX_cm, vtxOneY_cm, vtxTwoX_cm, vtxTwoY_cm, vtxThreeX_cm, vtxThreeY_cm, vtxFourX_cm, vtxFourY_cm; - double vtxOneX_cm_tmp, vtxOneY_cm_tmp, vtxTwoX_cm_tmp, vtxTwoY_cm_tmp, vtxThreeX_cm_tmp, vtxThreeY_cm_tmp, vtxFourX_cm_tmp, vtxFourY_cm_tmp; - - if (GeomDetEnumerators::isBarrel(det->subDetector())) { - if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { - // Rectangular - meanWidth_cm = b2->width(); - length_cm = b2->length(); - float dx = b2->width() * 0.5; // half width - float dy = b2->length() * 0.5; // half length - // std::cout << "Rectangle parameters " << b2->width() << " " << b2->length() << "\n"; - // std::cout << std::sin(phi_rad) << "\n"; - // vtxOneX_cm = rho_cm * cos(phi_rad) -dx * sin(phi_rad); - // vtxOneY_cm = rho_cm * sin(phi_rad) -dy * cos(phi_rad); - // vtxTwoX_cm = rho_cm * cos(phi_rad) -dx * sin(phi_rad); - // vtxTwoY_cm = rho_cm * sin(phi_rad) + dy * cos(phi_rad); - // vtxThreeX_cm = rho_cm * cos(phi_rad) + dx * sin(phi_rad); - // vtxThreeY_cm = rho_cm * sin(phi_rad) + dy * cos(phi_rad); - // vtxFourX_cm = rho_cm * cos(phi_rad) + dx * sin(phi_rad); - // vtxFourY_cm = rho_cm * sin(phi_rad) -dy * cos(phi_rad); - vtxOneX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); - vtxOneY_cm_tmp = dx; - vtxTwoX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); - vtxTwoY_cm_tmp = dx; - vtxThreeX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); - vtxThreeY_cm_tmp = -dx; - vtxFourX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); - vtxFourY_cm_tmp = -dx; - } else { - throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; - } - // rho_cm -= sensorSpacing_cm/2.0; - } else { - if (const RectangularPlaneBounds *b2 = dynamic_cast(b)) { - // Rectangular - meanWidth_cm = b2->width(); - length_cm = b2->length(); - float dx = b2->width() * 0.5; // half width - float dy = b2->length() * 0.5; // half length - // std::cout << "Rectangle parameters " << b2->width() << " " << b2->length() << "\n"; - vtxOneX_cm_tmp = rho_cm + dy; - vtxOneY_cm_tmp = dx; - vtxTwoX_cm_tmp = rho_cm - dy; - vtxTwoY_cm_tmp = dx; - vtxThreeX_cm_tmp = rho_cm - dy; - vtxThreeY_cm_tmp = -dx; - vtxFourX_cm_tmp = rho_cm + dy; - vtxFourY_cm_tmp = -dx; - std::cout << detId() << " " << vtxOneX_cm_tmp << " " << vtxOneY_cm_tmp << " " << vtxTwoX_cm_tmp << " " << vtxTwoY_cm_tmp << " " << vtxThreeX_cm_tmp << " " << vtxThreeY_cm_tmp << " " << vtxFourX_cm_tmp << " " << vtxFourY_cm_tmp << std::endl; - } else { - throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; - } - - // z_cm -= sensorSpacing_cm/2.0; // Not sure why - } - - vtxOneX_cm = vtxOneX_cm_tmp * cos(phi_rad) + vtxOneY_cm_tmp * sin(phi_rad); - vtxOneY_cm = vtxOneX_cm_tmp * sin(phi_rad) - vtxOneY_cm_tmp * cos(phi_rad); - vtxTwoX_cm = vtxTwoX_cm_tmp * cos(phi_rad) + vtxTwoY_cm_tmp * sin(phi_rad); - vtxTwoY_cm = vtxTwoX_cm_tmp * sin(phi_rad) - vtxTwoY_cm_tmp * cos(phi_rad); - vtxThreeX_cm = vtxThreeX_cm_tmp * cos(phi_rad) + vtxThreeY_cm_tmp * sin(phi_rad); - vtxThreeY_cm = vtxThreeX_cm_tmp * sin(phi_rad) - vtxThreeY_cm_tmp * cos(phi_rad); - vtxFourX_cm = vtxFourX_cm_tmp * cos(phi_rad) + vtxFourY_cm_tmp * sin(phi_rad); - vtxFourY_cm = vtxFourX_cm_tmp * sin(phi_rad) - vtxFourY_cm_tmp * cos(phi_rad); - - std::cout << detId() << " " << rho_cm << " " << z_cm << " " << phi_rad << " " << vtxOneX_cm << " " << vtxOneY_cm << " " << vtxTwoX_cm << " " << vtxTwoY_cm << " " << vtxThreeX_cm << " " << vtxThreeY_cm << " " << vtxFourX_cm << " " << vtxFourY_cm << " " << meanWidth_cm << " " << length_cm << " " << sensorSpacing_cm << " " << tiltAngle_rad << std::endl; + const DetId detId = det->geographicalId(); + + const auto &surface = det->surface(); + const Bounds *b = &(surface).bounds(); + const auto &position = surface.position(); + + double rho_cm = position.perp(); + double z_cm = position.z(); + const double phi_rad = position.phi(); + + if (det->isLeaf()) { + // Leafs are the sensors + lstgeometry::SensorInfo sensor; + sensor.detId = detId(); + sensor.sensorCenterRho_cm = rho_cm; + sensor.sensorCenterZ_cm = z_cm; + sensor.phi_rad = phi_rad; + sensors.push_back(sensor); + continue; + } + + const RectangularPlaneBounds *b2 = dynamic_cast(b); + if (!b2) { + throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; + } + + double tiltAngle_rad = std::asin(det->rotation().zz()); + + double meanWidth_cm = b2->width(); + double length_cm = b2->length(); + double dx = b2->width() * 0.5; + double dy = b2->length() * 0.5; + + double sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag(); + + double vtxOneX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); + double vtxOneY_cm_tmp = dx; + double vtxTwoX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); + double vtxTwoY_cm_tmp = dx; + double vtxThreeX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); + double vtxThreeY_cm_tmp = -dx; + double vtxFourX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); + double vtxFourY_cm_tmp = -dx; + + double vtxOneX_cm = vtxOneX_cm_tmp * cos(phi_rad) + vtxOneY_cm_tmp * sin(phi_rad); + double vtxOneY_cm = vtxOneX_cm_tmp * sin(phi_rad) - vtxOneY_cm_tmp * cos(phi_rad); + double vtxTwoX_cm = vtxTwoX_cm_tmp * cos(phi_rad) + vtxTwoY_cm_tmp * sin(phi_rad); + double vtxTwoY_cm = vtxTwoX_cm_tmp * sin(phi_rad) - vtxTwoY_cm_tmp * cos(phi_rad); + double vtxThreeX_cm = vtxThreeX_cm_tmp * cos(phi_rad) + vtxThreeY_cm_tmp * sin(phi_rad); + double vtxThreeY_cm = vtxThreeX_cm_tmp * sin(phi_rad) - vtxThreeY_cm_tmp * cos(phi_rad); + double vtxFourX_cm = vtxFourX_cm_tmp * cos(phi_rad) + vtxFourY_cm_tmp * sin(phi_rad); + double vtxFourY_cm = vtxFourX_cm_tmp * sin(phi_rad) - vtxFourY_cm_tmp * cos(phi_rad); + + unsigned int detid = detId(); + + unsigned short layer = lstgeometry::Module::parseLayer(detid); + if (lstgeometry::Module::parseSubdet(detid) == lstgeometry::Module::SubDet::Barrel) { + avg_r_cm[layer - 1] += rho_cm; + avg_r_counter[layer - 1] += 1; + } else { + avg_z_cm[layer - 1] += std::fabs(z_cm); + avg_z_counter[layer - 1] += 1; + } + + lstgeometry::ModuleInfo module; + module.detId = detid; + module.sensorCenterRho_cm = rho_cm; + module.sensorCenterZ_cm = z_cm; + module.tiltAngle_rad = tiltAngle_rad; + module.skewAngle_rad = 0.0; + module.yawAngle_rad = 0.0; + module.phi_rad = phi_rad; + module.vtxOneX_cm = vtxOneX_cm; + module.vtxOneY_cm = vtxOneY_cm; + module.vtxTwoX_cm = vtxTwoX_cm; + module.vtxTwoY_cm = vtxTwoY_cm; + module.vtxThreeX_cm = vtxThreeX_cm; + module.vtxThreeY_cm = vtxThreeY_cm; + module.vtxFourX_cm = vtxFourX_cm; + module.vtxFourY_cm = vtxFourY_cm; + module.meanWidth_cm = meanWidth_cm; + module.length_cm = length_cm; + module.sensorSpacing_cm = sensorSpacing_cm; + modules.push_back(module); + } + + for (size_t i = 0; i < avg_r_cm.size(); ++i) { + avg_r_cm[i] /= avg_r_counter[i]; + } + for (size_t i = 0; i < avg_z_cm.size(); ++i) { + avg_z_cm[i] /= avg_z_counter[i]; } - // placeholder return std::make_unique("LSTGeometryESProducer"); } diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index cb0bf2985b6b3..b11ca84a7dc03 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -18,19 +18,20 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { private: void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override; - + edm::ESGetToken lstGeoToken_; std::string outputDirectory_; }; DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) - : lstGeoToken_{esConsumes()}, outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")) {} + : lstGeoToken_{esConsumes()}, + outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")) {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { - const auto& lstg = iSetup.getData(lstGeoToken_); - - edm::LogInfo("DumpLSTGeometry") << lstg << std::endl; + const auto& lstg = iSetup.getData(lstGeoToken_); + + edm::LogInfo("DumpLSTGeometry") << lstg << std::endl; } DEFINE_FWK_MODULE(DumpLSTGeometry); \ No newline at end of file From 78b86ca06fa43aa32b7ea7f343d0152d6b27bc4a Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 25 Nov 2025 18:52:23 +0000 Subject: [PATCH 33/95] Added LSTGeometry struct and moved constuctor to common place --- .../LSTCore/interface/LSTGeometry/IO.h | 1 + .../interface/LSTGeometry/LSTGeometry.h | 22 ++++++ .../LSTGeometry/LSTGeometryMethods.h | 54 +++++++++++++++ .../LSTCore/plugins/LSTGeometryESProducer.cc | 30 ++++---- .../standalone/bin/lst_make_geometry.cc | 69 ++++--------------- 5 files changed, 105 insertions(+), 71 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index c8f63bfc34ef8..1389c90c52ad1 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -6,6 +6,7 @@ #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" #include #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h new file mode 100644 index 0000000000000..89b1dc989f81e --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h @@ -0,0 +1,22 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometry_h +#define RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometry_h + +#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" + +namespace lstgeometry { + + struct LSTGeometry { + std::unordered_map centroids; + std::unordered_map barrel_slopes; + std::unordered_map endcap_slopes; + PixelMap pixel_map; + std::unordered_map> merged_line_connections; + }; + +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h new file mode 100644 index 0000000000000..6d33b36e250a2 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h @@ -0,0 +1,54 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometryMethods_h +#define RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometryMethods_h + +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" + +namespace lstgeometry { + + std::unique_ptr makeLSTGeometry(std::vector &modules_info, + std::unordered_map &sensors_info, + std::vector &average_r, + std::vector &average_z) { + for (auto &mod : modules_info) + transformSensorCorners(mod); + + auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); + + auto centroids = computeCentroids(sensors_info); + + auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); + + auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); + det_geom.buildByLayer(); + + auto pixel_map = computePixelMap(centroids, det_geom); + + auto detids_etaphi_layer_ref = det_geom.getDetIds([](const auto &x) { + auto mod = Module(x.first); + return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || + (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && !(mod.ring() == 15 && mod.layer() == 1) && + !(mod.ring() == 15 && mod.layer() == 2) && !(mod.ring() == 12 && mod.layer() == 3) && + !(mod.ring() == 12 && mod.layer() == 4))); + }); + + std::unordered_map> straight_line_connections; + std::unordered_map> curved_line_connections; + + for (auto ref_detid : detids_etaphi_layer_ref) { + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); + } + auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); + + auto lstGeometry = std::make_unique(std::move(centroids), + std::move(barrel_slopes), + std::move(endcap_slopes), + std::move(pixel_map), + std::move(merged_line_connections)); + + return lstGeometry; + } + +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 3597a98eb0a26..b39fec153e007 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -16,20 +16,15 @@ #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" +// LST includes #include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h" #include #include - -// temporary -#include "FWCore/Utilities/interface/typelookup.h" -#include - -TYPELOOKUP_DATA_REG(std::string); - -// LST includes +#include class LSTGeometryESProducer : public edm::ESProducer { public: @@ -37,7 +32,7 @@ class LSTGeometryESProducer : public edm::ESProducer { static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); + std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); private: edm::ESGetToken geomToken_; @@ -60,15 +55,15 @@ void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &des descriptions.addWithDefaultLabel(desc); } -std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { +std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { trackerGeom_ = &iRecord.get(geomToken_); trackerTopo_ = &iRecord.get(ttopoToken_); - std::vector sensors; std::vector modules; + std::unordered_map sensors; - std::vector avg_r_cm(6, 0.0); - std::vector avg_z_cm(5, 0.0); + std::vector avg_r_cm(6, 0.0); + std::vector avg_z_cm(5, 0.0); std::vector avg_r_counter(6, 0); std::vector avg_z_counter(5, 0); @@ -90,7 +85,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeo sensor.sensorCenterRho_cm = rho_cm; sensor.sensorCenterZ_cm = z_cm; sensor.phi_rad = phi_rad; - sensors.push_back(sensor); + sensors[detId()] = std::move(sensor); continue; } @@ -166,7 +161,12 @@ std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeo avg_z_cm[i] /= avg_z_counter[i]; } - return std::make_unique("LSTGeometryESProducer"); + auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm); + + return lstGeometry; } DEFINE_FWK_EVENTSETUP_MODULE(LSTGeometryESProducer); + +#include "FWCore/Utilities/interface/typelookup.h" +TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); \ No newline at end of file diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 08b205cfe3c01..d31099dbd40c9 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -2,12 +2,8 @@ #include "cxxopts.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h" using namespace lstgeometry; @@ -25,7 +21,10 @@ int main(int argc, char** argv) { "average_z_file", "The path to the text file containing the average z positions of the Endcap layers.", cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt"))( - "output_dir", "The path to the output directory.", cxxopts::value()->default_value("../data/")); + "output_dir", "The path to the output directory.", cxxopts::value()->default_value("../data/"))( + "output_as_binary", + "Boolean flag specifying whether to write outputs as binary or text files.", + cxxopts::value()->default_value("true")); auto result = options.parse(argc, argv); @@ -34,63 +33,21 @@ int main(int argc, char** argv) { std::string average_r_file = result["average_r_file"].as(); std::string average_z_file = result["average_z_file"].as(); std::string output_dir = result["output_dir"].as(); + bool output_as_bin = result["output_as_binary"].as(); auto modules_info = readModuleInfo(module_info_file); auto sensors_info = readSensorInfo(sensor_info_file); auto average_r = readAverages(average_r_file); auto average_z = readAverages(average_z_file); - std::cout << "Transforming corners" << std::endl; - for (auto& mod : modules_info) - transformSensorCorners(mod); - std::cout << "Transforming corners done" << std::endl; + auto lstGeometry = makeLSTGeometry(modules_info, sensors_info, average_r, average_z); - std::cout << "Assigning corners" << std::endl; - auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); - std::cout << "Assigning corners done" << std::endl; - - std::cout << "Computing centroids" << std::endl; - auto centroids = computeCentroids(sensors_info); - writeCentroids(centroids, output_dir + "sensor_centroids", false); - std::cout << "Computing centroids done" << std::endl; - - std::cout << "Processing corners" << std::endl; - auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); - writeSlopes(barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation", false); - writeSlopes(endcap_slopes, sensors_info, output_dir + "endcap_orientation", false); - std::cout << "Processing corners done" << std::endl; - - std::cout << "Building detector geometry" << std::endl; - auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); - det_geom.buildByLayer(); - std::cout << "Building detector geometry done" << std::endl; - - std::cout << "Computing pixel map" << std::endl; - auto pixel_map = computePixelMap(centroids, det_geom); - writePixelMaps(pixel_map, output_dir + "pixelmap/pLS_map", false); - std::cout << "Computing pixel map done" << std::endl; - - std::cout << "Computing module maps" << std::endl; - auto detids_etaphi_layer_ref = det_geom.getDetIds([](const auto& x) { - auto mod = Module(x.first); - return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || - (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && !(mod.ring() == 15 && mod.layer() == 1) && - !(mod.ring() == 15 && mod.layer() == 2) && !(mod.ring() == 12 && mod.layer() == 3) && - !(mod.ring() == 12 && mod.layer() == 4))); - }); - - std::unordered_map> straight_line_connections; - std::unordered_map> curved_line_connections; - - for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); - } - auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); - writeModuleConnections(merged_line_connections, output_dir + "module_connection_tracing_merged", false); - std::cout << "Computing module maps done" << std::endl; - - std::cout << "Done!" << std::endl; + writeCentroids(lstGeometry->centroids, output_dir + "sensor_centroids", output_as_bin); + writeSlopes(lstGeometry->barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation", output_as_bin); + writeSlopes(lstGeometry->endcap_slopes, sensors_info, output_dir + "endcap_orientation", output_as_bin); + writePixelMaps(lstGeometry->pixel_map, output_dir + "pixelmap/pLS_map", output_as_bin); + writeModuleConnections( + lstGeometry->merged_line_connections, output_dir + "module_connection_tracing_merged", output_as_bin); return 0; } \ No newline at end of file From 51ba97bfce6f3a83fdc827976badaa0eb1b95adb Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 1 Dec 2025 19:19:04 +0000 Subject: [PATCH 34/95] Finished dump test --- .../interface/LSTGeometry/LSTGeometry.h | 1 + .../LSTGeometry/LSTGeometryMethods.h | 7 +++--- RecoTracker/LSTCore/src/ES_LSTGeometry.cc | 3 +++ .../standalone/bin/lst_make_geometry.cc | 5 ++-- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 24 ++++++++++++------- RecoTracker/LSTCore/test/dumpLSTGeometry.py | 11 ++------- .../LSTCore/test/testDumpLSTGeometry.sh | 0 7 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 RecoTracker/LSTCore/src/ES_LSTGeometry.cc mode change 100644 => 100755 RecoTracker/LSTCore/test/testDumpLSTGeometry.sh diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h index 89b1dc989f81e..7bc5588bc0d80 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h @@ -15,6 +15,7 @@ namespace lstgeometry { std::unordered_map endcap_slopes; PixelMap pixel_map; std::unordered_map> merged_line_connections; + std::unordered_map sensor_info; }; } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h index 6d33b36e250a2..dc25aaa8f0380 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h @@ -7,8 +7,8 @@ namespace lstgeometry { std::unique_ptr makeLSTGeometry(std::vector &modules_info, std::unordered_map &sensors_info, - std::vector &average_r, - std::vector &average_z) { + std::vector const &average_r, + std::vector const &average_z) { for (auto &mod : modules_info) transformSensorCorners(mod); @@ -44,7 +44,8 @@ namespace lstgeometry { std::move(barrel_slopes), std::move(endcap_slopes), std::move(pixel_map), - std::move(merged_line_connections)); + std::move(merged_line_connections), + std::move(sensors_info)); return lstGeometry; } diff --git a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc new file mode 100644 index 0000000000000..401b547ca2978 --- /dev/null +++ b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc @@ -0,0 +1,3 @@ +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "FWCore/Utilities/interface/typelookup.h" +TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); \ No newline at end of file diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index d31099dbd40c9..71242b3053ae7 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -43,8 +43,9 @@ int main(int argc, char** argv) { auto lstGeometry = makeLSTGeometry(modules_info, sensors_info, average_r, average_z); writeCentroids(lstGeometry->centroids, output_dir + "sensor_centroids", output_as_bin); - writeSlopes(lstGeometry->barrel_slopes, sensors_info, output_dir + "tilted_barrel_orientation", output_as_bin); - writeSlopes(lstGeometry->endcap_slopes, sensors_info, output_dir + "endcap_orientation", output_as_bin); + writeSlopes( + lstGeometry->barrel_slopes, lstGeometry->sensor_info, output_dir + "tilted_barrel_orientation", output_as_bin); + writeSlopes(lstGeometry->endcap_slopes, lstGeometry->sensor_info, output_dir + "endcap_orientation", output_as_bin); writePixelMaps(lstGeometry->pixel_map, output_dir + "pixelmap/pLS_map", output_as_bin); writeModuleConnections( lstGeometry->merged_line_connections, output_dir + "module_connection_tracing_merged", output_as_bin); diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index b11ca84a7dc03..3dc9b69369dd9 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -6,11 +6,8 @@ #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" -// temporary -#include -#include "FWCore/Utilities/interface/typelookup.h" -TYPELOOKUP_DATA_REG(std::string); -// end temporary +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" class DumpLSTGeometry : public edm::one::EDAnalyzer<> { public: @@ -19,19 +16,30 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { private: void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override; - edm::ESGetToken lstGeoToken_; + edm::ESGetToken lstGeoToken_; std::string outputDirectory_; + bool binaryOutput_; }; DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) : lstGeoToken_{esConsumes()}, - outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")) {} + outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")), + binaryOutput_(config.getUntrackedParameter("output_as_binary", true)) {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); - edm::LogInfo("DumpLSTGeometry") << lstg << std::endl; + lstgeometry::writeCentroids(lstg.centroids, outputDirectory_ + "sensor_centroids", binaryOutput_); + lstgeometry::writeSlopes( + lstg.barrel_slopes, lstg.sensor_info, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); + lstgeometry::writeSlopes( + lstg.endcap_slopes, lstg.sensor_info, outputDirectory_ + "endcap_orientation", binaryOutput_); + lstgeometry::writePixelMaps(lstg.pixel_map, outputDirectory_ + "pixelmap/pLS_map", binaryOutput_); + lstgeometry::writeModuleConnections( + lstg.merged_line_connections, outputDirectory_ + "module_connection_tracing_merged", binaryOutput_); + + edm::LogInfo("DumpLSTGeometry") << "Centroids size: " << lstg.centroids.size() << std::endl; } DEFINE_FWK_MODULE(DumpLSTGeometry); \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py index 591bbb3d10542..99152788a2319 100644 --- a/RecoTracker/LSTCore/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -23,12 +23,8 @@ from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, _PH2_GLOBAL_TAG, '') -# In Fireworks/Geom reco dumper: -# from Configuration.AlCa.autoCond import autoCond -# process.GlobalTag.globaltag = autoCond['phase2_realistic'] - process.MessageLogger.cerr.threshold = "INFO" -process.MessageLogger.cerr.MkFitGeometryESProducer = dict(limit=-1) +process.MessageLogger.cerr.LSTGeometryESProducer = dict(limit=-1) process.source = cms.Source("EmptySource") process.maxEvents.input = 1 @@ -36,12 +32,9 @@ process.add_(cms.ESProducer("LSTGeometryESProducer")) -defaultOutputDirectory="lstgeometry" +defaultOutputDirectory="data" -# level: 0 - no printout; 1 - print layers, 2 - print shapes and modules -# outputFileName: binary dump file; no dump if empty string process.dump = cms.EDAnalyzer("DumpLSTGeometry", - level = cms.untracked.int32(1), outputDirectory = cms.untracked.string(defaultOutputDirectory) ) diff --git a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh old mode 100644 new mode 100755 From 9acfea6a9acbcea50d86521afdaeb1d3a7a8fd14 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 1 Dec 2025 21:47:12 +0000 Subject: [PATCH 35/95] A few fixes --- RecoTracker/LSTCore/interface/LSTGeometry/IO.h | 9 +++++++++ RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc | 5 +---- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 2 +- RecoTracker/LSTCore/test/dumpLSTGeometry.py | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 1389c90c52ad1..208123308d905 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -144,6 +144,9 @@ namespace lstgeometry { void writeCentroids(std::unordered_map const& centroids, std::string const& base_filename, bool binary = true) { + std::filesystem::path filepath(base_filename); + std::filesystem::create_directories(filepath.parent_path()); + std::string filename = base_filename + (binary ? ".bin" : ".txt"); std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); @@ -171,6 +174,9 @@ namespace lstgeometry { std::unordered_map const& sensors, std::string const& base_filename, bool binary = true) { + std::filesystem::path filepath(base_filename); + std::filesystem::create_directories(filepath.parent_path()); + std::string filename = base_filename + (binary ? ".bin" : ".txt"); std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); @@ -206,6 +212,9 @@ namespace lstgeometry { void writeModuleConnections(std::unordered_map> const& connections, std::string const& base_filename, bool binary = true) { + std::filesystem::path filepath(base_filename); + std::filesystem::create_directories(filepath.parent_path()); + std::string filename = base_filename + (binary ? ".bin" : ".txt"); std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index b39fec153e007..0728c5a94e5cd 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -166,7 +166,4 @@ std::unique_ptr LSTGeometryESProducer::produce(const T return lstGeometry; } -DEFINE_FWK_EVENTSETUP_MODULE(LSTGeometryESProducer); - -#include "FWCore/Utilities/interface/typelookup.h" -TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); \ No newline at end of file +DEFINE_FWK_EVENTSETUP_MODULE(LSTGeometryESProducer); \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index 3dc9b69369dd9..4141f1374db0d 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -24,7 +24,7 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) : lstGeoToken_{esConsumes()}, - outputDirectory_(config.getUntrackedParameter("outputDirectory", "data")), + outputDirectory_(config.getUntrackedParameter("outputDirectory", "data/")), binaryOutput_(config.getUntrackedParameter("output_as_binary", true)) {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py index 99152788a2319..7c89c822b4a60 100644 --- a/RecoTracker/LSTCore/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -32,7 +32,7 @@ process.add_(cms.ESProducer("LSTGeometryESProducer")) -defaultOutputDirectory="data" +defaultOutputDirectory="data/" process.dump = cms.EDAnalyzer("DumpLSTGeometry", outputDirectory = cms.untracked.string(defaultOutputDirectory) From a4663d89bd5f59330582d4eabec9429f01a8c42e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 2 Dec 2025 13:09:11 -0500 Subject: [PATCH 36/95] Fixed orientations --- .../LSTCore/interface/LSTGeometry/Common.h | 21 +++++++++++++++++++ .../LSTGeometry/OrientationMethods.h | 6 +++--- .../LSTCore/plugins/LSTGeometryESProducer.cc | 8 +++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index c9cf56da0e388..eac8b5970b78c 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -39,6 +39,27 @@ namespace lstgeometry { phi += 2 * std::numbers::pi_v; return phi; } + + double roundAngle(double angle, double tol = 1e-3) { + const double pi = std::numbers::pi_v; + if (std::fabs(angle) < tol) { + return 0.0; + } else if (std::fabs(angle - pi/2) < tol) { + return pi / 2; + } else if (std::fabs(angle + pi/2) < tol) { + return - pi / 2; + } else if (std::fabs(angle - pi) < tol || std::fabs(angle + pi) < tol) { + return -pi; + } + return angle; + } + + double roundCoordinate(double coord, double tol = 1e-3) { + if (std::fabs(coord) < tol) { + return 0.0; + } + return coord; + } } // namespace lstgeometry diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h index ab6b4d9650049..67a1cde26d554 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -31,9 +31,9 @@ namespace lstgeometry { std::unordered_map endcap_slopes; for (const auto& [detId, corners] : corners) { - double dx = corners(1, 1) - corners(0, 1); - double dy = corners(1, 2) - corners(0, 2); - double dz = corners(1, 0) - corners(0, 0); + double dx = roundCoordinate(corners(1, 1) - corners(0, 1)); + double dy = roundCoordinate(corners(1, 2) - corners(0, 2)); + double dz = roundCoordinate(corners(1, 0) - corners(0, 0)); SlopeData slope = calculateSlope(dx, dy, dz); diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 0728c5a94e5cd..ebbcc8210c169 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -74,9 +74,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const T const Bounds *b = &(surface).bounds(); const auto &position = surface.position(); - double rho_cm = position.perp(); - double z_cm = position.z(); - const double phi_rad = position.phi(); + const double rho_cm = position.perp(); + const double z_cm = lstgeometry::roundCoordinate(position.z()); + const double phi_rad = lstgeometry::roundAngle(position.phi()); if (det->isLeaf()) { // Leafs are the sensors @@ -94,7 +94,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const T throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; } - double tiltAngle_rad = std::asin(det->rotation().zz()); + double tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); double meanWidth_cm = b2->width(); double length_cm = b2->length(); From 08889355128ef6c62491d300247cea3fe7c86ab7 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 3 Dec 2025 17:23:34 +0000 Subject: [PATCH 37/95] Adapted the LST ES producer --- .../plugins/alpaka/LSTModulesDevESProducer.cc | 8 +- .../LSTCore/interface/EndcapGeometry.h | 4 + RecoTracker/LSTCore/interface/LSTESData.h | 2 + .../LSTCore/interface/LSTGeometry/Common.h | 12 +-- .../interface/LSTGeometry/DetectorGeometry.h | 1 + .../interface/LSTGeometry/LSTGeometry.h | 9 +- .../LSTGeometry/LSTGeometryMethods.h | 6 ++ .../LSTGeometry/OrientationMethods.h | 7 +- .../LSTCore/interface/LSTGeometry/PixelMap.h | 19 +++++ .../interface/LSTGeometry/PixelMapMethods.h | 11 +-- .../LSTCore/interface/LSTGeometry/SlopeData.h | 13 +++ .../LSTCore/interface/ModuleConnectionMap.h | 2 + .../LSTCore/interface/TiltedGeometry.h | 3 + RecoTracker/LSTCore/src/ES_LSTGeometry.cc | 6 +- RecoTracker/LSTCore/src/EndcapGeometry.cc | 13 +++ RecoTracker/LSTCore/src/LSTESData.cc | 82 +++++++++++++++++++ .../LSTCore/src/ModuleConnectionMap.cc | 8 ++ RecoTracker/LSTCore/src/ModuleMethods.h | 47 ++++++++--- RecoTracker/LSTCore/src/TiltedGeometry.cc | 10 +++ 19 files changed, 220 insertions(+), 43 deletions(-) create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h create mode 100644 RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index 7152da9ed13c7..049c6f3f56c9b 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -1,5 +1,6 @@ // LST includes #include "RecoTracker/LSTCore/interface/alpaka/LST.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -15,11 +16,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { class LSTModulesDevESProducer : public ESProducer { private: std::string ptCutLabel_; + edm::ESGetToken lstGeoToken_; public: LSTModulesDevESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig), ptCutLabel_(iConfig.getParameter("ptCutLabel")) { - setWhatProduced(this, ptCutLabel_); + auto cc = setWhatProduced(this, ptCutLabel_); + lstGeoToken_ = cc.consumes(); } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -29,7 +32,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } std::unique_ptr> produce(TrackerRecoGeometryRecord const& iRecord) { - return lst::loadAndFillESHost(ptCutLabel_); + const auto& lstg = iRecord.get(lstGeoToken_); + return lst::loadAndFillESHost(lstg); } }; diff --git a/RecoTracker/LSTCore/interface/EndcapGeometry.h b/RecoTracker/LSTCore/interface/EndcapGeometry.h index b8c44c14fb143..91891e1292e2e 100644 --- a/RecoTracker/LSTCore/interface/EndcapGeometry.h +++ b/RecoTracker/LSTCore/interface/EndcapGeometry.h @@ -1,6 +1,8 @@ #ifndef RecoTracker_LSTCore_interface_EndcapGeometry_h #define RecoTracker_LSTCore_interface_EndcapGeometry_h +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" + #include #include #include @@ -21,6 +23,8 @@ namespace lst { EndcapGeometry(std::string const& filename); void load(std::string const&); + void load(std::unordered_map const&, + std::unordered_map const&); void fillGeoMapArraysExplicit(); float getdxdy_slope(unsigned int detid) const; }; diff --git a/RecoTracker/LSTCore/interface/LSTESData.h b/RecoTracker/LSTCore/interface/LSTESData.h index 5131d013a4279..b8cfb101272e1 100644 --- a/RecoTracker/LSTCore/interface/LSTESData.h +++ b/RecoTracker/LSTCore/interface/LSTESData.h @@ -5,6 +5,7 @@ #include "RecoTracker/LSTCore/interface/EndcapGeometryDevHostCollection.h" #include "RecoTracker/LSTCore/interface/ModulesHostCollection.h" #include "RecoTracker/LSTCore/interface/PixelMap.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" #include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" @@ -41,6 +42,7 @@ namespace lst { }; std::unique_ptr> loadAndFillESHost(std::string& ptCutLabel); + std::unique_ptr> loadAndFillESHost(lstgeometry::LSTGeometry const& lstg); } // namespace lst diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index eac8b5970b78c..4e2f19222d71f 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -39,21 +39,21 @@ namespace lstgeometry { phi += 2 * std::numbers::pi_v; return phi; } - + double roundAngle(double angle, double tol = 1e-3) { const double pi = std::numbers::pi_v; if (std::fabs(angle) < tol) { return 0.0; - } else if (std::fabs(angle - pi/2) < tol) { - return pi / 2; - } else if (std::fabs(angle + pi/2) < tol) { - return - pi / 2; + } else if (std::fabs(angle - pi / 2) < tol) { + return pi / 2; + } else if (std::fabs(angle + pi / 2) < tol) { + return -pi / 2; } else if (std::fabs(angle - pi) < tol || std::fabs(angle + pi) < tol) { return -pi; } return angle; } - + double roundCoordinate(double coord, double tol = 1e-3) { if (std::fabs(coord) < tol) { return 0.0; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 5ac0acf44fd68..090fb6108473e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h index 7bc5588bc0d80..87e75ba3e2533 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h @@ -1,11 +1,10 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometry_h #define RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometry_h -#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h index dc25aaa8f0380..c9e42852ca2b7 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h @@ -2,6 +2,12 @@ #define RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometryMethods_h #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h index 67a1cde26d554..9107314cdc450 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -5,17 +5,12 @@ #include #include -#include "CentroidMethods.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h" namespace lstgeometry { - struct SlopeData { - double drdz_slope; - double dxdy_slope; - }; - // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. SlopeData calculateSlope(double dx, double dy, double dz) { double dr = sqrt(dx * dx + dy * dy); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h new file mode 100644 index 0000000000000..392cd6ef022b6 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h @@ -0,0 +1,19 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_PixelMap_h +#define RecoTracker_LSTCore_interface_LSTGeometry_PixelMap_h + +#include +#include +#include +#include + +namespace lstgeometry { + + using LayerSubdetChargeKey = std::tuple; + using LayerSubdetChargeMap = std::unordered_map>, + boost::hash>; + using PixelMap = LayerSubdetChargeMap; + +} // namespace lstgeometry + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index d3826e1e5b76a..9006895e5a636 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -1,25 +1,16 @@ #ifndef RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h #define RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h -#include -#include -#include #include -#include #include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" #include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" +#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h" namespace lstgeometry { - using LayerSubdetChargeKey = std::tuple; - using LayerSubdetChargeMap = std::unordered_map>, - boost::hash>; - using PixelMap = LayerSubdetChargeMap; - PixelMap computePixelMap(std::unordered_map const& centroids, DetectorGeometry const& det_geom) { // Charge 0 is the union of charge 1 and charge -1 diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h b/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h new file mode 100644 index 0000000000000..9ec93e9655cd3 --- /dev/null +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h @@ -0,0 +1,13 @@ +#ifndef RecoTracker_LSTCore_interface_LSTGeometry_SlopeData_h +#define RecoTracker_LSTCore_interface_LSTGeometry_SlopeData_h + +namespace lstgeometry { + + struct SlopeData { + double drdz_slope; + double dxdy_slope; + }; + +} // namespace lstgeometry + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/ModuleConnectionMap.h b/RecoTracker/LSTCore/interface/ModuleConnectionMap.h index 63c3496523c0d..7df14a0d0cf34 100644 --- a/RecoTracker/LSTCore/interface/ModuleConnectionMap.h +++ b/RecoTracker/LSTCore/interface/ModuleConnectionMap.h @@ -14,8 +14,10 @@ namespace lst { public: ModuleConnectionMap(); ModuleConnectionMap(std::string const& filename); + ModuleConnectionMap(std::map> const&); void load(std::string const&); + void load(std::map> const&); void add(std::string const&); void print(); diff --git a/RecoTracker/LSTCore/interface/TiltedGeometry.h b/RecoTracker/LSTCore/interface/TiltedGeometry.h index 7a17106195522..2545ff4c0d11e 100644 --- a/RecoTracker/LSTCore/interface/TiltedGeometry.h +++ b/RecoTracker/LSTCore/interface/TiltedGeometry.h @@ -1,6 +1,8 @@ #ifndef RecoTracker_LSTCore_interface_TiltedGeometry_h #define RecoTracker_LSTCore_interface_TiltedGeometry_h +#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" + #include #include #include @@ -16,6 +18,7 @@ namespace lst { TiltedGeometry(std::string const& filename); void load(std::string const&); + void load(std::unordered_map const&); float getDrDz(unsigned int detid) const; float getDxDy(unsigned int detid) const; diff --git a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc index 401b547ca2978..ac3672f4299d2 100644 --- a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc @@ -1,3 +1,7 @@ +#ifndef LST_STANDALONE + #include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" #include "FWCore/Utilities/interface/typelookup.h" -TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); \ No newline at end of file +TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); + +#endif \ No newline at end of file diff --git a/RecoTracker/LSTCore/src/EndcapGeometry.cc b/RecoTracker/LSTCore/src/EndcapGeometry.cc index 17e72379bb2ec..549c8f501e859 100644 --- a/RecoTracker/LSTCore/src/EndcapGeometry.cc +++ b/RecoTracker/LSTCore/src/EndcapGeometry.cc @@ -39,6 +39,19 @@ void lst::EndcapGeometry::load(std::string const& filename) { fillGeoMapArraysExplicit(); } +void lst::EndcapGeometry::load(std::unordered_map const& slopes, + std::unordered_map const& sensors) { + dxdy_slope_.clear(); + centroid_phis_.clear(); + + for (const auto& [detId, slopeData] : slopes) { + dxdy_slope_[detId] = slopeData.dxdy_slope; + centroid_phis_[detId] = sensors.at(detId).phi_rad; + } + + fillGeoMapArraysExplicit(); +} + void lst::EndcapGeometry::fillGeoMapArraysExplicit() { nEndCapMap = centroid_phis_.size(); diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 93cf76be6312f..c493ccdc81e9d 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -7,6 +7,8 @@ #include "ModuleMethods.h" #include +#include +#include namespace { std::string geometryDataDir() { @@ -119,3 +121,83 @@ std::unique_ptr> lst::loadAndFillESHost(s std::move(endcapGeometryDev), pixelMappingPtr); } + +std::unique_ptr> lst::loadAndFillESHost(lstgeometry::LSTGeometry const& lstg) { + uint16_t nModules; + uint16_t nLowerModules; + unsigned int nPixels; + MapPLStoLayer pLStoLayer; + EndcapGeometry endcapGeometry; + TiltedGeometry tiltedGeometry; + PixelMap pixelMapping; + ModuleConnectionMap moduleConnectionMap; + + endcapGeometry.load(lstg.endcap_slopes, lstg.sensor_info); + auto endcapGeometryDev = + std::make_shared(endcapGeometry.nEndCapMap, cms::alpakatools::host()); + std::memcpy(endcapGeometryDev->view().geoMapDetId().data(), + endcapGeometry.geoMapDetId_buf.data(), + endcapGeometry.nEndCapMap * sizeof(unsigned int)); + std::memcpy(endcapGeometryDev->view().geoMapPhi().data(), + endcapGeometry.geoMapPhi_buf.data(), + endcapGeometry.nEndCapMap * sizeof(float)); + + tiltedGeometry.load(lstg.barrel_slopes); + + std::map> final_modulemap; + for (auto const& [detId, connections] : lstg.merged_line_connections) { + final_modulemap[detId] = std::vector(connections.begin(), connections.end()); + } + moduleConnectionMap.load(final_modulemap); + + for (auto& [layersubdetcharge, map] : lstg.pixel_map) { + auto& [layer, subdet, charge] = layersubdetcharge; + + std::map> final_pixelmap; + for (unsigned int isuperbin = 0; isuperbin < map.size(); isuperbin++) { + auto const& set = map.at(isuperbin); + final_pixelmap[isuperbin] = std::vector(set.begin(), set.end()); + } + + if (charge == 0) { + pLStoLayer[0][layer - 1 + (subdet == 4 ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); + } else if (charge > 0) { + pLStoLayer[1][layer - 1 + (subdet == 4 ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); + } else { + pLStoLayer[2][layer - 1 + (subdet == 4 ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); + } + } + + ModuleMetaData mmd; + unsigned int counter = 0; + for (auto const& [detId, centroid] : lstg.centroids) { + mmd.detIdToIndex[detId] = counter; + mmd.module_x[detId] = centroid.x; + mmd.module_y[detId] = centroid.y; + mmd.module_z[detId] = centroid.z; + mmd.module_type[detId] = centroid.moduleType; + counter++; + } + mmd.detIdToIndex[1] = counter; //pixel module is the last module in the module list + counter++; + nModules = counter; + + auto modulesBuffers = constructModuleCollection(pLStoLayer, + mmd, + nModules, + nLowerModules, + nPixels, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap); + + auto pixelMappingPtr = std::make_shared(std::move(pixelMapping)); + return std::make_unique>(nModules, + nLowerModules, + nPixels, + endcapGeometry.nEndCapMap, + std::move(modulesBuffers), + std::move(endcapGeometryDev), + pixelMappingPtr); +} diff --git a/RecoTracker/LSTCore/src/ModuleConnectionMap.cc b/RecoTracker/LSTCore/src/ModuleConnectionMap.cc index 0da0f4cc4ac6f..ca1c39a895ea4 100644 --- a/RecoTracker/LSTCore/src/ModuleConnectionMap.cc +++ b/RecoTracker/LSTCore/src/ModuleConnectionMap.cc @@ -9,6 +9,10 @@ lst::ModuleConnectionMap::ModuleConnectionMap() {} lst::ModuleConnectionMap::ModuleConnectionMap(std::string const& filename) { load(filename); } +lst::ModuleConnectionMap::ModuleConnectionMap(std::map> const& map) { + load(map); +} + void lst::ModuleConnectionMap::load(std::string const& filename) { moduleConnections_.clear(); @@ -53,6 +57,10 @@ void lst::ModuleConnectionMap::load(std::string const& filename) { } } +void lst::ModuleConnectionMap::load(std::map> const& map) { + moduleConnections_ = map; +} + void lst::ModuleConnectionMap::add(std::string const& filename) { std::ifstream ifile; ifile.open(filename.c_str()); diff --git a/RecoTracker/LSTCore/src/ModuleMethods.h b/RecoTracker/LSTCore/src/ModuleMethods.h index 1d5d75f18ac2b..b9f9431ff012c 100644 --- a/RecoTracker/LSTCore/src/ModuleMethods.h +++ b/RecoTracker/LSTCore/src/ModuleMethods.h @@ -218,19 +218,16 @@ namespace lst { nModules = counter; } - inline std::shared_ptr loadModulesFromFile(MapPLStoLayer const& pLStoLayer, - const char* moduleMetaDataFilePath, - uint16_t& nModules, - uint16_t& nLowerModules, - unsigned int& nPixels, - PixelMap& pixelMapping, - const EndcapGeometry& endcapGeometry, - const TiltedGeometry& tiltedGeometry, - const ModuleConnectionMap& moduleConnectionMap) { - ModuleMetaData mmd; - - loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); - + inline std::shared_ptr constructModuleCollection( + MapPLStoLayer const& pLStoLayer, + ModuleMetaData& mmd, + uint16_t& nModules, + uint16_t& nLowerModules, + unsigned int& nPixels, + PixelMap& pixelMapping, + const EndcapGeometry& endcapGeometry, + const TiltedGeometry& tiltedGeometry, + const ModuleConnectionMap& moduleConnectionMap) { // TODO: this whole section could use some refactoring auto [totalSizes, connectedModuleDetIds, @@ -402,5 +399,29 @@ namespace lst { return modulesHC; } + + inline std::shared_ptr loadModulesFromFile(MapPLStoLayer const& pLStoLayer, + const char* moduleMetaDataFilePath, + uint16_t& nModules, + uint16_t& nLowerModules, + unsigned int& nPixels, + PixelMap& pixelMapping, + const EndcapGeometry& endcapGeometry, + const TiltedGeometry& tiltedGeometry, + const ModuleConnectionMap& moduleConnectionMap) { + ModuleMetaData mmd; + + loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); + return constructModuleCollection(pLStoLayer, + mmd, + nModules, + nLowerModules, + nPixels, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap); + } + } // namespace lst #endif diff --git a/RecoTracker/LSTCore/src/TiltedGeometry.cc b/RecoTracker/LSTCore/src/TiltedGeometry.cc index d65a9a4a5f7b9..2c579cfed2020 100644 --- a/RecoTracker/LSTCore/src/TiltedGeometry.cc +++ b/RecoTracker/LSTCore/src/TiltedGeometry.cc @@ -37,6 +37,16 @@ void lst::TiltedGeometry::load(std::string const& filename) { } } +void lst::TiltedGeometry::load(std::unordered_map const& slopes) { + drdzs_.clear(); + dxdys_.clear(); + + for (const auto& [detId, slopeData] : slopes) { + drdzs_[detId] = slopeData.drdz_slope; + dxdys_[detId] = slopeData.dxdy_slope; + } +} + float lst::TiltedGeometry::getDrDz(unsigned int detid) const { auto res = drdzs_.find(detid); return res == drdzs_.end() ? 0.f : res->second; From 78215021f8568a02faad23ad8a3f5dd819855725 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 3 Dec 2025 18:39:24 +0000 Subject: [PATCH 38/95] Fixed python file --- RecoTracker/LST/python/lstProducerTask_cff.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RecoTracker/LST/python/lstProducerTask_cff.py b/RecoTracker/LST/python/lstProducerTask_cff.py index 588b354788635..ae6fa34ec58c3 100644 --- a/RecoTracker/LST/python/lstProducerTask_cff.py +++ b/RecoTracker/LST/python/lstProducerTask_cff.py @@ -4,4 +4,6 @@ from RecoTracker.LST.lstModulesDevESProducer_cfi import lstModulesDevESProducer -lstProducerTask = cms.Task(lstModulesDevESProducer, lstProducer) +from RecoTracker.LSTCore.lstGeometryESProducer_cfi import lstGeometryDevESProducer + +lstProducerTask = cms.Task(lstGeometryDevESProducer, lstModulesDevESProducer, lstProducer) From 61369ba96edc615dc90059e8a0b9b338a48ba115 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 4 Dec 2025 10:49:44 -0500 Subject: [PATCH 39/95] Fixed typo --- RecoTracker/LST/python/lstProducerTask_cff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoTracker/LST/python/lstProducerTask_cff.py b/RecoTracker/LST/python/lstProducerTask_cff.py index ae6fa34ec58c3..5caae9506f6ca 100644 --- a/RecoTracker/LST/python/lstProducerTask_cff.py +++ b/RecoTracker/LST/python/lstProducerTask_cff.py @@ -4,6 +4,6 @@ from RecoTracker.LST.lstModulesDevESProducer_cfi import lstModulesDevESProducer -from RecoTracker.LSTCore.lstGeometryESProducer_cfi import lstGeometryDevESProducer +from RecoTracker.LSTCore.lstGeometryESProducer_cfi import lstGeometryESProducer -lstProducerTask = cms.Task(lstGeometryDevESProducer, lstModulesDevESProducer, lstProducer) +lstProducerTask = cms.Task(lstGeometryESProducer, lstModulesDevESProducer, lstProducer) From c56a823b5752f375b1f4a25742b14a6b8946c49d Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 18:08:17 +0000 Subject: [PATCH 40/95] Make pt cutoff selectable --- .../plugins/alpaka/LSTModulesDevESProducer.cc | 10 +++++----- RecoTracker/LST/plugins/alpaka/LSTProducer.cc | 5 ++--- .../interface/LSTGeometry/CentroidMethods.h | 2 +- .../LSTCore/interface/LSTGeometry/Common.h | 5 ++--- .../interface/LSTGeometry/CornerMethods.h | 2 +- .../interface/LSTGeometry/DetectorGeometry.h | 2 +- .../LSTCore/interface/LSTGeometry/Helix.h | 2 +- .../LSTCore/interface/LSTGeometry/IO.h | 2 +- .../LSTGeometry/LSTGeometryMethods.h | 7 ++++--- .../LSTCore/interface/LSTGeometry/LSTMath.h | 2 +- .../LSTCore/interface/LSTGeometry/Module.h | 2 +- .../interface/LSTGeometry/ModuleMapMethods.h | 19 +++++++++---------- .../LSTGeometry/OrientationMethods.h | 2 +- .../LSTCore/interface/LSTGeometry/PixelMap.h | 2 +- .../interface/LSTGeometry/PixelMapMethods.h | 13 +++++++------ .../LSTCore/interface/LSTGeometry/SlopeData.h | 2 +- .../LSTCore/plugins/LSTGeometryESProducer.cc | 13 +++++++++---- RecoTracker/LSTCore/src/ES_LSTGeometry.cc | 2 +- .../standalone/bin/lst_make_geometry.cc | 8 +++++--- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 2 +- 20 files changed, 55 insertions(+), 49 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index 049c6f3f56c9b..653550295a113 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -15,19 +15,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { class LSTModulesDevESProducer : public ESProducer { private: - std::string ptCutLabel_; + std::string ptCut_; edm::ESGetToken lstGeoToken_; public: LSTModulesDevESProducer(edm::ParameterSet const& iConfig) - : ESProducer(iConfig), ptCutLabel_(iConfig.getParameter("ptCutLabel")) { - auto cc = setWhatProduced(this, ptCutLabel_); - lstGeoToken_ = cc.consumes(); + : ESProducer(iConfig), ptCut_(iConfig.getParameter("ptCut")) { + auto cc = setWhatProduced(this, ptCut_); + lstGeoToken_ = cc.consumes(edm::ESInputTag("", ptCut_)); } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("ptCutLabel", "0.8"); + desc.add("ptCut", " 0.8"); descriptions.addWithDefaultLabel(desc); } diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index 496c1ae1182b0..1fd91ab530f62 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -26,7 +26,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { LSTProducer(edm::ParameterSet const& config) : EDProducer(config), lstInputToken_{consumes(config.getParameter("lstInput"))}, - lstESToken_{esConsumes(edm::ESInputTag("", config.getParameter("ptCutLabel")))}, + lstESToken_{esConsumes(edm::ESInputTag("", config.getParameter("ptCut")))}, verbose_(config.getParameter("verbose")), ptCut_(config.getParameter("ptCut")), clustSizeCut_(static_cast(config.getParameter("clustSizeCut"))), @@ -58,9 +58,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { edm::ParameterSetDescription desc; desc.add("lstInput", edm::InputTag{"lstInputProducer"}); desc.add("verbose", false); - desc.add("ptCut", 0.8); + desc.add("ptCut", "0.8"); desc.add("clustSizeCut", 16); - desc.add("ptCutLabel", "0.8"); desc.add("nopLSDupClean", false); desc.add("tcpLSTriplets", false); descriptions.addWithDefaultLabel(desc); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index b16c7780bcbed..7dc105db928d3 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -77,4 +77,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h index 4e2f19222d71f..3535b98bde387 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Common.h @@ -17,7 +17,6 @@ namespace lstgeometry { using RowVectorD3 = Eigen::Matrix; // TODO: These should be moved to ../Common.h - constexpr double kPtThreshold = 0.8; constexpr double k2Rinv1GeVf = 0.00299792458; constexpr double kB = 3.8112; @@ -25,7 +24,7 @@ namespace lstgeometry { constexpr unsigned int kNEta = 25; constexpr unsigned int kNPhi = 72; constexpr unsigned int kNZ = 25; - constexpr std::array kPtBounds = {{kPtThreshold, 2.0, 10'000.0}}; + constexpr std::array kPtBounds = {{2.0, 10'000.0}}; // This is defined as a constant in case the legacy value (123456789) needs to be used double kDefaultSlope = std::numeric_limits::infinity(); @@ -63,4 +62,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 8bf88aaad7ad8..6b4d9fff1d895 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -147,4 +147,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 090fb6108473e..04112d712cf52 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -311,4 +311,4 @@ namespace lstgeometry { }; } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h index bedb40985f745..ca15660f3dfff 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h @@ -15,4 +15,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 208123308d905..1f9b45b117ad2 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -287,4 +287,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h index c9e42852ca2b7..338ff0e0c7e07 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h @@ -14,7 +14,8 @@ namespace lstgeometry { std::unique_ptr makeLSTGeometry(std::vector &modules_info, std::unordered_map &sensors_info, std::vector const &average_r, - std::vector const &average_z) { + std::vector const &average_z, + double ptCut) { for (auto &mod : modules_info) transformSensorCorners(mod); @@ -27,7 +28,7 @@ namespace lstgeometry { auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); det_geom.buildByLayer(); - auto pixel_map = computePixelMap(centroids, det_geom); + auto pixel_map = computePixelMap(centroids, det_geom, ptCut); auto detids_etaphi_layer_ref = det_geom.getDetIds([](const auto &x) { auto mod = Module(x.first); @@ -42,7 +43,7 @@ namespace lstgeometry { for (auto ref_detid : detids_etaphi_layer_ref) { straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom, ptCut); } auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index 44bbae9c563aa..399d0b3133d72 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -150,4 +150,4 @@ namespace lstgeometry { } } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h index de65a28e0746b..51aa7d4e5ae57 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Module.h @@ -472,4 +472,4 @@ lstgeometry::Module::ModuleLayerType lstgeometry::Module::parseModuleLayerType(u } } -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index e88306a8cc449..7571d608fd407 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -112,6 +112,7 @@ namespace lstgeometry { MatrixD4x3 boundsAfterCurved(unsigned int ref_detid, std::unordered_map const& centroids, DetectorGeometry const& det_geom, + double ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); auto centroid = centroids.at(ref_detid); @@ -124,14 +125,11 @@ namespace lstgeometry { MatrixD4x3 next_layer_bound_points; for (int i = 0; i < bounds.rows(); i++) { - Helix helix_p10 = - constructHelixFromPoints(kPtThreshold, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); - Helix helix_m10 = - constructHelixFromPoints(kPtThreshold, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); - Helix helix_p10_pos = - constructHelixFromPoints(kPtThreshold, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); + Helix helix_p10 = constructHelixFromPoints(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); + Helix helix_m10 = constructHelixFromPoints(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); + Helix helix_p10_pos = constructHelixFromPoints(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); Helix helix_m10_pos = - constructHelixFromPoints(kPtThreshold, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); + constructHelixFromPoints(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); double bound_theta = std::atan2(std::sqrt(bounds(i, 1) * bounds(i, 1) + bounds(i, 2) * bounds(i, 2)), bounds(i, 0)); double bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); @@ -188,7 +186,8 @@ namespace lstgeometry { std::vector getCurvedLineConnections(unsigned int ref_detid, std::unordered_map const& centroids, - DetectorGeometry const& det_geom) { + DetectorGeometry const& det_geom, + double ptCut) { auto centroid = centroids.at(ref_detid); double refphi = std::atan2(centroid.y, centroid.x); @@ -205,7 +204,7 @@ namespace lstgeometry { ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); - auto next_layer_bound_points = boundsAfterCurved(ref_detid, centroids, det_geom); + auto next_layer_bound_points = boundsAfterCurved(ref_detid, centroids, det_geom, ptCut); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -292,4 +291,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h index 9107314cdc450..5e2b128a41887 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h @@ -52,4 +52,4 @@ namespace lstgeometry { } } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h index 392cd6ef022b6..8a9fba984c0e2 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h @@ -16,4 +16,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index 9006895e5a636..f04f537012ab6 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -12,11 +12,12 @@ namespace lstgeometry { PixelMap computePixelMap(std::unordered_map const& centroids, - DetectorGeometry const& det_geom) { + DetectorGeometry const& det_geom, + double ptCut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; - std::size_t nSuperbin = (kPtBounds.size() - 1) * kNPhi * kNEta * kNZ; + std::size_t nSuperbin = kPtBounds.size() * kNPhi * kNEta * kNZ; // Initialize empty lists for the pixel map for (unsigned int layer : {1, 2}) { @@ -45,7 +46,7 @@ namespace lstgeometry { // For this module, now compute which super bins they belong to // To compute which super bins it belongs to, one needs to provide at least pt and z window to compute compatible eta and phi range // So we have a loop in pt and Z - for (unsigned int ipt = 0; ipt < kPtBounds.size() - 1; ipt++) { + for (unsigned int ipt = 0; ipt < kPtBounds.size(); ipt++) { for (unsigned int iz = 0; iz < kNZ; iz++) { // The zmin, zmax of consideration double zmin = -30 + iz * (60. / kNZ); @@ -55,8 +56,8 @@ namespace lstgeometry { zmin += 0.05; // The ptmin, ptmax of consideration - double pt_lo = kPtBounds[ipt]; - double pt_hi = kPtBounds[ipt + 1]; + double pt_lo = ipt == 0 ? ptCut : kPtBounds[ipt - 1]; + double pt_hi = kPtBounds[ipt]; auto [etamin, etamax] = det_geom.getCompatibleEtaRange(detId, zmin, zmax); @@ -135,4 +136,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h b/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h index 9ec93e9655cd3..84d4aa4503ea1 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h @@ -10,4 +10,4 @@ namespace lstgeometry { } // namespace lstgeometry -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index ebbcc8210c169..99921ade81e68 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -35,6 +35,8 @@ class LSTGeometryESProducer : public edm::ESProducer { std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); private: + std::string ptCut_; + edm::ESGetToken geomToken_; edm::ESGetToken ttopoToken_; edm::ESGetToken trackerToken_; @@ -43,8 +45,9 @@ class LSTGeometryESProducer : public edm::ESProducer { const TrackerGeometry *trackerGeom_ = nullptr; }; -LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) { - auto cc = setWhatProduced(this); +LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) + : ptCut_(iConfig.getParameter("ptCut")) { + auto cc = setWhatProduced(this, ptCut_); geomToken_ = cc.consumes(); ttopoToken_ = cc.consumes(); trackerToken_ = cc.consumes(); @@ -52,6 +55,7 @@ LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) { void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { edm::ParameterSetDescription desc; + desc.add("ptCut", "0.8"); descriptions.addWithDefaultLabel(desc); } @@ -161,9 +165,10 @@ std::unique_ptr LSTGeometryESProducer::produce(const T avg_z_cm[i] /= avg_z_counter[i]; } - auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm); + double ptCut = std::stod(ptCut_); + auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut); return lstGeometry; } -DEFINE_FWK_EVENTSETUP_MODULE(LSTGeometryESProducer); \ No newline at end of file +DEFINE_FWK_EVENTSETUP_MODULE(LSTGeometryESProducer); diff --git a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc index ac3672f4299d2..5254589aa904e 100644 --- a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc +++ b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc @@ -4,4 +4,4 @@ #include "FWCore/Utilities/interface/typelookup.h" TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); -#endif \ No newline at end of file +#endif diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 71242b3053ae7..b11a3886d0dda 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -24,7 +24,8 @@ int main(int argc, char** argv) { "output_dir", "The path to the output directory.", cxxopts::value()->default_value("../data/"))( "output_as_binary", "Boolean flag specifying whether to write outputs as binary or text files.", - cxxopts::value()->default_value("true")); + cxxopts::value()->default_value("true"))( + "pt_cut", "pT cutoff value.", cxxopts::value()->default_value("0.8")); auto result = options.parse(argc, argv); @@ -34,13 +35,14 @@ int main(int argc, char** argv) { std::string average_z_file = result["average_z_file"].as(); std::string output_dir = result["output_dir"].as(); bool output_as_bin = result["output_as_binary"].as(); + double ptCut = result["pt_cut"].as(); auto modules_info = readModuleInfo(module_info_file); auto sensors_info = readSensorInfo(sensor_info_file); auto average_r = readAverages(average_r_file); auto average_z = readAverages(average_z_file); - auto lstGeometry = makeLSTGeometry(modules_info, sensors_info, average_r, average_z); + auto lstGeometry = makeLSTGeometry(modules_info, sensors_info, average_r, average_z, ptCut); writeCentroids(lstGeometry->centroids, output_dir + "sensor_centroids", output_as_bin); writeSlopes( @@ -51,4 +53,4 @@ int main(int argc, char** argv) { lstGeometry->merged_line_connections, output_dir + "module_connection_tracing_merged", output_as_bin); return 0; -} \ No newline at end of file +} diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index 4141f1374db0d..42fc8e9f43b8c 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -42,4 +42,4 @@ void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& i edm::LogInfo("DumpLSTGeometry") << "Centroids size: " << lstg.centroids.size() << std::endl; } -DEFINE_FWK_MODULE(DumpLSTGeometry); \ No newline at end of file +DEFINE_FWK_MODULE(DumpLSTGeometry); From 94368d418b4983378f8a4e3439fc45c9cb68e541 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:05:29 -0500 Subject: [PATCH 41/95] A bit of cleanup --- .../plugins/alpaka/LSTModulesDevESProducer.cc | 2 +- .../LSTCore/interface/LSTGeometry/Centroid.h | 1 - .../interface/LSTGeometry/CentroidMethods.h | 2 +- .../LSTCore/interface/LSTGeometry/IO.h | 51 +++++++++---------- .../LSTCore/plugins/LSTGeometryESProducer.cc | 18 +------ 5 files changed, 28 insertions(+), 46 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index 653550295a113..467d75ccb94e1 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -27,7 +27,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("ptCut", " 0.8"); + desc.add("ptCut", "0.8"); descriptions.addWithDefaultLabel(desc); } diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h b/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h index 22876bc3f051d..0fc9bb661896f 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h @@ -4,7 +4,6 @@ namespace lstgeometry { struct Centroid { - unsigned int detId; unsigned int moduleType; double x; double y; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h index 7dc105db928d3..bb66bc15a79ff 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h @@ -69,7 +69,7 @@ namespace lstgeometry { double x = rho * cos(phi); double y = rho * sin(phi); - Centroid centroid{detId, static_cast(moduleType), x, y, z}; + Centroid centroid{static_cast(moduleType), x, y, z}; centroids[detId] = centroid; } return centroids; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 1f9b45b117ad2..1c9cb3835612d 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -58,26 +58,25 @@ namespace lstgeometry { if (tokens.size() != 23) continue; - ModuleInfo m; - - m.detId = std::stoul(tokens[0]); - m.sensorCenterRho_cm = std::stod(tokens[5]) / 10.0; - m.sensorCenterZ_cm = std::stod(tokens[6]) / 10.0; - m.tiltAngle_rad = degToRad(std::stod(tokens[7])); - m.skewAngle_rad = degToRad(std::stod(tokens[8])); - m.yawAngle_rad = degToRad(std::stod(tokens[9])); - m.phi_rad = degToRad(std::stod(tokens[10])); - m.vtxOneX_cm = std::stod(tokens[11]) / 10.0; - m.vtxOneY_cm = std::stod(tokens[12]) / 10.0; - m.vtxTwoX_cm = std::stod(tokens[13]) / 10.0; - m.vtxTwoY_cm = std::stod(tokens[14]) / 10.0; - m.vtxThreeX_cm = std::stod(tokens[15]) / 10.0; - m.vtxThreeY_cm = std::stod(tokens[16]) / 10.0; - m.vtxFourX_cm = std::stod(tokens[17]) / 10.0; - m.vtxFourY_cm = std::stod(tokens[18]) / 10.0; - m.meanWidth_cm = std::stod(tokens[19]) / 10.0; - m.length_cm = std::stod(tokens[20]) / 10.0; - m.sensorSpacing_cm = std::stod(tokens[21]) / 10.0; + ModuleInfo m{static_cast(std::stoul(tokens[0])), + std::stod(tokens[5]) / 10.0, + std::stod(tokens[6]) / 10.0, + degToRad(std::stod(tokens[7])), + degToRad(std::stod(tokens[8])), + degToRad(std::stod(tokens[9])), + degToRad(std::stod(tokens[10])), + std::stod(tokens[11]) / 10.0, + std::stod(tokens[12]) / 10.0, + std::stod(tokens[13]) / 10.0, + std::stod(tokens[14]) / 10.0, + std::stod(tokens[15]) / 10.0, + std::stod(tokens[16]) / 10.0, + std::stod(tokens[17]) / 10.0, + std::stod(tokens[18]) / 10.0, + std::stod(tokens[19]) / 10.0, + std::stod(tokens[20]) / 10.0, + std::stod(tokens[21]) / 10.0, + MatrixD8x3::Zero()}; modules.push_back(m); } @@ -105,12 +104,12 @@ namespace lstgeometry { if (tokens.size() != 8) continue; - SensorInfo s; - - s.detId = std::stoul(tokens[0]); - s.sensorCenterRho_cm = std::stod(tokens[5]) / 10.0; - s.sensorCenterZ_cm = std::stod(tokens[6]) / 10.0; - s.phi_rad = degToRad(std::stod(tokens[7])); + SensorInfo s{ + static_cast(std::stoul(tokens[0])), + std::stod(tokens[5]) / 10.0, + std::stod(tokens[6]) / 10.0, + degToRad(std::stod(tokens[7])), + }; sensors[s.detId] = s; } diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 99921ade81e68..c5ab7ccfef06f 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -1,19 +1,9 @@ #include "FWCore/Framework/interface/ModuleFactory.h" #include "FWCore/Framework/interface/ESProducer.h" -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "DataFormats/TrackerCommon/interface/TrackerDetSide.h" -#include "Geometry/Records/interface/TrackerTopologyRcd.h" -#include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h" -#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" - +#include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" -#include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h" - -#include "DataFormats/SiStripDetId/interface/SiStripEnums.h" - #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" // LST includes @@ -38,10 +28,7 @@ class LSTGeometryESProducer : public edm::ESProducer { std::string ptCut_; edm::ESGetToken geomToken_; - edm::ESGetToken ttopoToken_; - edm::ESGetToken trackerToken_; - const TrackerTopology *trackerTopo_ = nullptr; const TrackerGeometry *trackerGeom_ = nullptr; }; @@ -49,8 +36,6 @@ LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) : ptCut_(iConfig.getParameter("ptCut")) { auto cc = setWhatProduced(this, ptCut_); geomToken_ = cc.consumes(); - ttopoToken_ = cc.consumes(); - trackerToken_ = cc.consumes(); } void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { @@ -61,7 +46,6 @@ void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &des std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { trackerGeom_ = &iRecord.get(geomToken_); - trackerTopo_ = &iRecord.get(ttopoToken_); std::vector modules; std::unordered_map sensors; From 74f2e9e76ff1a67f68807ed81724e35380041111 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:20:02 -0500 Subject: [PATCH 42/95] Fix typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h index 6b4d9fff1d895..242e09c765e5e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h @@ -121,11 +121,11 @@ namespace lstgeometry { sensors.at(sensor_det_id_1).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_1).phi_rad); double sensor1_center_y = sensors.at(sensor_det_id_1).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_1).phi_rad); - double sensor2_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_cm; + double sensor2_center_z = sensors.at(sensor_det_id_2).sensorCenterZ_cm; double sensor2_center_x = - sensors.at(sensor_det_id_1).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_1).phi_rad); + sensors.at(sensor_det_id_2).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_2).phi_rad); double sensor2_center_y = - sensors.at(sensor_det_id_1).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_1).phi_rad); + sensors.at(sensor_det_id_2).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_2).phi_rad); RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; From 283fd59f1b2789b83686f681cf3d756385d8e068 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:22:55 -0500 Subject: [PATCH 43/95] Fix bug from original code Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h index f04f537012ab6..9a05c6ca7fc4f 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h @@ -53,7 +53,7 @@ namespace lstgeometry { double zmax = -30 + (iz + 1) * (60. / kNZ); zmin -= 0.05; - zmin += 0.05; + zmax += 0.05; // The ptmin, ptmax of consideration double pt_lo = ipt == 0 ? ptCut : kPtBounds[ipt - 1]; From 74cd74dfbfd1986f8a4ca666a0decb57d4b5b0ff Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:24:34 -0500 Subject: [PATCH 44/95] Fix typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 04112d712cf52..1f1c05aa6a14a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -27,8 +27,8 @@ namespace lstgeometry { if (eta_bin == 0) { if (theta > 3. * kEtaBinRad / 2.) return false; - } else if (eta_bin == kNPhiBins - 1) { - if (theta < (2 * (kNPhiBins - 1) - 1) * kEtaBinRad / 2.) + } else if (eta_bin == kNEtaBins - 1) { + if (theta < (2 * (kNEtaBins - 1) - 1) * kEtaBinRad / 2.) return false; } else if (theta < (2 * eta_bin - 1) * kEtaBinRad / 2. || theta > (2 * (eta_bin + 1) + 1) * kEtaBinRad / 2.) { return false; From 5dafbad9309438ee61b2d9d6cabb8de86cdfdb29 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:26:17 -0500 Subject: [PATCH 45/95] Fix typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index 399d0b3133d72..ca01344179b00 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -128,7 +128,7 @@ namespace lstgeometry { } // Quick cut - RowVectorD2 diff = ref_mod_boundaries_etaphi.row(0) - ref_mod_boundaries_etaphi.row(0); + RowVectorD2 diff = ref_mod_boundaries_etaphi.row(0) - tar_mod_boundaries_etaphi.row(0); if (std::fabs(diff(0)) > 0.5) return false; if (std::fabs(phi_mpi_pi(diff(1))) > 1.) From 6ac6e042a13165356f1486a1c337ef3d05c1667b Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 18:12:09 -0500 Subject: [PATCH 46/95] Fixed type issue --- RecoTracker/LST/plugins/alpaka/LSTProducer.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index 1fd91ab530f62..ca0ab8e483c56 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -28,7 +28,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { lstInputToken_{consumes(config.getParameter("lstInput"))}, lstESToken_{esConsumes(edm::ESInputTag("", config.getParameter("ptCut")))}, verbose_(config.getParameter("verbose")), - ptCut_(config.getParameter("ptCut")), + ptCut_(config.getParameter("ptCut")), clustSizeCut_(static_cast(config.getParameter("clustSizeCut"))), nopLSDupClean_(config.getParameter("nopLSDupClean")), tcpLSTriplets_(config.getParameter("tcpLSTriplets")), @@ -42,7 +42,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { lst.run(iEvent.queue(), verbose_, - static_cast(ptCut_), + std::stof(ptCut_), clustSizeCut_, &lstESDeviceData, &lstInputDC, @@ -69,7 +69,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { const device::EDGetToken lstInputToken_; const device::ESGetToken, TrackerRecoGeometryRecord> lstESToken_; const bool verbose_; - const double ptCut_; + const std::string ptCut_; const uint16_t clustSizeCut_; const bool nopLSDupClean_; const bool tcpLSTriplets_; From 5c395e86ed8b2738adbfe35264820826c4a260e3 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 18 Feb 2026 15:55:50 -0500 Subject: [PATCH 47/95] Remove kVerticalModuleSlope --- RecoTracker/LSTCore/interface/alpaka/Common.h | 2 -- RecoTracker/LSTCore/src/alpaka/MiniDoublet.h | 6 ++---- RecoTracker/LSTCore/src/alpaka/Quintuplet.h | 10 ++++------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/RecoTracker/LSTCore/interface/alpaka/Common.h b/RecoTracker/LSTCore/interface/alpaka/Common.h index 5ed0546351490..84c0083b53403 100644 --- a/RecoTracker/LSTCore/interface/alpaka/Common.h +++ b/RecoTracker/LSTCore/interface/alpaka/Common.h @@ -43,8 +43,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { HOST_DEVICE_CONSTANT float kWidthPS = 0.01; HOST_DEVICE_CONSTANT float kPt_betaMax = 7.0; HOST_DEVICE_CONSTANT int kNTripletThreshold = 1000; - // To be updated with std::numeric_limits::infinity() in the code and data files - HOST_DEVICE_CONSTANT float kVerticalModuleSlope = 123456789.0; HOST_DEVICE_CONSTANT int kLogicalOTLayers = 11; // logical OT layers are 1..11 HOST_DEVICE_CONSTANT float kMiniDeltaTilted[3] = {0.26f, 0.26f, 0.26f}; diff --git a/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h b/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h index 806869522e062..d6bbe192ab07e 100644 --- a/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h +++ b/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h @@ -304,8 +304,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { drprime = (moduleSeparation / alpaka::math::sin(acc, angleA + angleB)) * alpaka::math::sin(acc, angleA); // Compute arctan of the slope and take care of the slope = infinity case - absArctanSlope = - ((slope != kVerticalModuleSlope && edm::isFinite(slope)) ? fabs(alpaka::math::atan(acc, slope)) : kPi / 2.f); + absArctanSlope = (edm::isFinite(slope) ? fabs(alpaka::math::atan(acc, slope)) : kPi / 2.f); // Depending on which quadrant the pixel hit lies, we define the angleM by shifting them slightly differently if (xp > 0 and yp > 0) { @@ -328,8 +327,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { ya = yp + drprime_y; // Compute the new strip hit position (if the slope value is in special condition take care of the exceptions) - if (slope == kVerticalModuleSlope || - edm::isNotFinite(slope)) // Designated for tilted module when the slope is infinity (module lying along y-axis) + if (edm::isNotFinite(slope)) // Designated for tilted module when the slope is infinity (module lying along y-axis) { xn = xa; // New x point is simply where the anchor is yn = yo; // No shift in y diff --git a/RecoTracker/LSTCore/src/alpaka/Quintuplet.h b/RecoTracker/LSTCore/src/alpaka/Quintuplet.h index 15b0aa1f7f405..70fdaef7d8ec6 100644 --- a/RecoTracker/LSTCore/src/alpaka/Quintuplet.h +++ b/RecoTracker/LSTCore/src/alpaka/Quintuplet.h @@ -667,9 +667,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { // Computing sigmas is a very tricky affair // if the module is tilted or endcap, we need to use the slopes properly! - absArctanSlope = ((slopes[i] != kVerticalModuleSlope && edm::isFinite(slopes[i])) - ? alpaka::math::abs(acc, alpaka::math::atan(acc, slopes[i])) - : kPi / 2.f); + absArctanSlope = + (edm::isFinite(slopes[i]) ? alpaka::math::abs(acc, alpaka::math::atan(acc, slopes[i])) : kPi / 2.f); if (xs[i] > 0 and ys[i] > 0) { angleM = kPi / 2.f - absArctanSlope; @@ -751,9 +750,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { float chiSquared = 0.f; float absArctanSlope, angleM, xPrime, yPrime, sigma2; for (size_t i = 0; i < nPoints; i++) { - absArctanSlope = ((slopes[i] != kVerticalModuleSlope && edm::isFinite(slopes[i])) - ? alpaka::math::abs(acc, alpaka::math::atan(acc, slopes[i])) - : kPi / 2.f); + absArctanSlope = + (edm::isFinite(slopes[i]) ? alpaka::math::abs(acc, alpaka::math::atan(acc, slopes[i])) : kPi / 2.f); if (xs[i] > 0 and ys[i] > 0) { angleM = kPi / 2.f - absArctanSlope; } else if (xs[i] < 0 and ys[i] > 0) { From 75e1af877f4b123efee1ef773875c911a57ecee2 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 8 Dec 2025 21:18:00 +0000 Subject: [PATCH 48/95] Minor cleanup --- RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h index ca01344179b00..7a7137a874cd3 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h @@ -23,9 +23,8 @@ namespace lstgeometry { Helix constructHelixFromPoints( double pt, double vx, double vy, double vz, double mx, double my, double mz, int charge) { double radius = pt / (k2Rinv1GeVf * kB); - double r = std::fabs(radius); // TODO: Is this needed? - double t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * r)); + double t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * radius)); double phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + ((vy - my) / (vx - mx) < 0) * (std::numbers::pi_v)+charge * t / 2. + (my - vy < 0) * (std::numbers::pi_v / 2.) - (my - vy > 0) * (std::numbers::pi_v / 2.); From cc7baf99727d8d5b996a1b35f0e6ddfe5a86cfd6 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 16 Dec 2025 16:35:01 +0000 Subject: [PATCH 49/95] Add ptCut parameter to test --- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 10 ++++++---- RecoTracker/LSTCore/test/dumpLSTGeometry.py | 4 +++- RecoTracker/LSTCore/test/testDumpLSTGeometry.sh | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index 42fc8e9f43b8c..a682df2c1d0f8 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -16,16 +16,18 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { private: void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override; - edm::ESGetToken lstGeoToken_; - + std::string ptCut_; std::string outputDirectory_; bool binaryOutput_; + + edm::ESGetToken lstGeoToken_; }; DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) - : lstGeoToken_{esConsumes()}, + : ptCut_(config.getParameter("ptCut")), outputDirectory_(config.getUntrackedParameter("outputDirectory", "data/")), - binaryOutput_(config.getUntrackedParameter("output_as_binary", true)) {} + binaryOutput_(config.getUntrackedParameter("output_as_binary", true)), + lstGeoToken_{esConsumes(edm::ESInputTag("", ptCut_))} {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py index 7c89c822b4a60..3a900ef1e58f7 100644 --- a/RecoTracker/LSTCore/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -33,9 +33,11 @@ process.add_(cms.ESProducer("LSTGeometryESProducer")) defaultOutputDirectory="data/" +defaultPtCut="0.8" process.dump = cms.EDAnalyzer("DumpLSTGeometry", - outputDirectory = cms.untracked.string(defaultOutputDirectory) + outputDirectory = cms.untracked.string(defaultOutputDirectory), + ptCut = cms.string(defaultPtCut) ) print("Requesting LST geometry dump into directory:", defaultOutputDirectory, "\n"); diff --git a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh index 51762c16212ce..6fb35cb84969f 100755 --- a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh +++ b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh @@ -7,4 +7,4 @@ if [ "${SCRAM_TEST_NAME}" != "" ] ; then cd ${SCRAM_TEST_NAME} fi -(cmsRun ${SCRAM_TEST_PATH}/dumpLSTGeometry.py) || die "failed to run dumpLSTGeometry.py" $? +(cmsRun ${SCRAM_TEST_PATH}/dumpLSTGeometry.py --conditions auto:phase2_realistic_T33 --geometry ExtendedRun4D110 --era Phase2C17I13M9) || die "failed to run dumpLSTGeometry.py" $? From 0053ffc80e387c0c367edecb6035a278ac27cd67 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Dec 2025 15:18:21 -0500 Subject: [PATCH 50/95] Add binary output option --- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 2 +- RecoTracker/LSTCore/test/dumpLSTGeometry.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index a682df2c1d0f8..084fc158db0bc 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -26,7 +26,7 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) : ptCut_(config.getParameter("ptCut")), outputDirectory_(config.getUntrackedParameter("outputDirectory", "data/")), - binaryOutput_(config.getUntrackedParameter("output_as_binary", true)), + binaryOutput_(config.getUntrackedParameter("outputAsBinary", true)), lstGeoToken_{esConsumes(edm::ESInputTag("", ptCut_))} {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py index 3a900ef1e58f7..cb1a90a512c3c 100644 --- a/RecoTracker/LSTCore/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -34,10 +34,12 @@ defaultOutputDirectory="data/" defaultPtCut="0.8" +defaultToBinary=True process.dump = cms.EDAnalyzer("DumpLSTGeometry", outputDirectory = cms.untracked.string(defaultOutputDirectory), - ptCut = cms.string(defaultPtCut) + ptCut = cms.string(defaultPtCut), + outputAsBinary = cms.untracked.bool(defaultToBinary), ) print("Requesting LST geometry dump into directory:", defaultOutputDirectory, "\n"); From 2076b5b99544abced74acaeda8af80788a8b7e3e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Dec 2025 15:33:57 -0500 Subject: [PATCH 51/95] Didn't actually need corner coordinates --- .../LSTCore/interface/LSTGeometry/IO.h | 8 -- .../interface/LSTGeometry/ModuleInfo.h | 8 -- .../LSTCore/plugins/LSTGeometryESProducer.cc | 78 ++++++++----------- RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 2 +- 4 files changed, 35 insertions(+), 61 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h index 1c9cb3835612d..ea20bd3d70907 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/IO.h @@ -65,14 +65,6 @@ namespace lstgeometry { degToRad(std::stod(tokens[8])), degToRad(std::stod(tokens[9])), degToRad(std::stod(tokens[10])), - std::stod(tokens[11]) / 10.0, - std::stod(tokens[12]) / 10.0, - std::stod(tokens[13]) / 10.0, - std::stod(tokens[14]) / 10.0, - std::stod(tokens[15]) / 10.0, - std::stod(tokens[16]) / 10.0, - std::stod(tokens[17]) / 10.0, - std::stod(tokens[18]) / 10.0, std::stod(tokens[19]) / 10.0, std::stod(tokens[20]) / 10.0, std::stod(tokens[21]) / 10.0, diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h index 64a4639d2318f..d3fea87091ed4 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h @@ -13,14 +13,6 @@ namespace lstgeometry { double skewAngle_rad; double yawAngle_rad; double phi_rad; - double vtxOneX_cm; - double vtxOneY_cm; - double vtxTwoX_cm; - double vtxTwoY_cm; - double vtxThreeX_cm; - double vtxThreeY_cm; - double vtxFourX_cm; - double vtxFourY_cm; double meanWidth_cm; double length_cm; double sensorSpacing_cm; diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index c5ab7ccfef06f..c22047d6b8abd 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -68,11 +68,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const T if (det->isLeaf()) { // Leafs are the sensors - lstgeometry::SensorInfo sensor; - sensor.detId = detId(); - sensor.sensorCenterRho_cm = rho_cm; - sensor.sensorCenterZ_cm = z_cm; - sensor.phi_rad = phi_rad; + lstgeometry::SensorInfo sensor{detId(), rho_cm, z_cm, phi_rad}; sensors[detId()] = std::move(sensor); continue; } @@ -86,29 +82,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const T double meanWidth_cm = b2->width(); double length_cm = b2->length(); - double dx = b2->width() * 0.5; - double dy = b2->length() * 0.5; double sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag(); - double vtxOneX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); - double vtxOneY_cm_tmp = dx; - double vtxTwoX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); - double vtxTwoY_cm_tmp = dx; - double vtxThreeX_cm_tmp = rho_cm - dy * std::sin(tiltAngle_rad); - double vtxThreeY_cm_tmp = -dx; - double vtxFourX_cm_tmp = rho_cm + dy * std::sin(tiltAngle_rad); - double vtxFourY_cm_tmp = -dx; - - double vtxOneX_cm = vtxOneX_cm_tmp * cos(phi_rad) + vtxOneY_cm_tmp * sin(phi_rad); - double vtxOneY_cm = vtxOneX_cm_tmp * sin(phi_rad) - vtxOneY_cm_tmp * cos(phi_rad); - double vtxTwoX_cm = vtxTwoX_cm_tmp * cos(phi_rad) + vtxTwoY_cm_tmp * sin(phi_rad); - double vtxTwoY_cm = vtxTwoX_cm_tmp * sin(phi_rad) - vtxTwoY_cm_tmp * cos(phi_rad); - double vtxThreeX_cm = vtxThreeX_cm_tmp * cos(phi_rad) + vtxThreeY_cm_tmp * sin(phi_rad); - double vtxThreeY_cm = vtxThreeX_cm_tmp * sin(phi_rad) - vtxThreeY_cm_tmp * cos(phi_rad); - double vtxFourX_cm = vtxFourX_cm_tmp * cos(phi_rad) + vtxFourY_cm_tmp * sin(phi_rad); - double vtxFourY_cm = vtxFourX_cm_tmp * sin(phi_rad) - vtxFourY_cm_tmp * cos(phi_rad); - unsigned int detid = detId(); unsigned short layer = lstgeometry::Module::parseLayer(detid); @@ -120,25 +96,17 @@ std::unique_ptr LSTGeometryESProducer::produce(const T avg_z_counter[layer - 1] += 1; } - lstgeometry::ModuleInfo module; - module.detId = detid; - module.sensorCenterRho_cm = rho_cm; - module.sensorCenterZ_cm = z_cm; - module.tiltAngle_rad = tiltAngle_rad; - module.skewAngle_rad = 0.0; - module.yawAngle_rad = 0.0; - module.phi_rad = phi_rad; - module.vtxOneX_cm = vtxOneX_cm; - module.vtxOneY_cm = vtxOneY_cm; - module.vtxTwoX_cm = vtxTwoX_cm; - module.vtxTwoY_cm = vtxTwoY_cm; - module.vtxThreeX_cm = vtxThreeX_cm; - module.vtxThreeY_cm = vtxThreeY_cm; - module.vtxFourX_cm = vtxFourX_cm; - module.vtxFourY_cm = vtxFourY_cm; - module.meanWidth_cm = meanWidth_cm; - module.length_cm = length_cm; - module.sensorSpacing_cm = sensorSpacing_cm; + lstgeometry::ModuleInfo module{detid, + rho_cm, + z_cm, + tiltAngle_rad, + 0.0, + 0.0, + phi_rad, + meanWidth_cm, + length_cm, + sensorSpacing_cm, + lstgeometry::MatrixD8x3::Zero()}; modules.push_back(module); } @@ -149,6 +117,28 @@ std::unique_ptr LSTGeometryESProducer::produce(const T avg_z_cm[i] /= avg_z_counter[i]; } + // For debugging + for (auto &m : modules) { + std::cout << "module," << m.detId << "," << m.sensorCenterRho_cm << "," << m.sensorCenterZ_cm << "," + << m.tiltAngle_rad << "," << m.phi_rad << "," << m.meanWidth_cm << "," << m.length_cm << "," + << m.sensorSpacing_cm << std::endl; + } + for (auto &[detid, s] : sensors) { + std::cout << "sensor," << s.detId << "," << s.sensorCenterRho_cm << "," << s.sensorCenterZ_cm << "," << s.phi_rad + << std::endl; + } + std::cout << "avg_r_cm,"; + for (auto &r : avg_r_cm) { + std::cout << r << ","; + } + std::cout << std::endl; + std::cout << "avg_z_cm,"; + for (auto &z : avg_z_cm) { + std::cout << z << ","; + } + std::cout << std::endl; + // end debugging + double ptCut = std::stod(ptCut_); auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut); diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc index 084fc158db0bc..451fc20382688 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTCore/test/DumpLSTGeometry.cc @@ -19,7 +19,7 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { std::string ptCut_; std::string outputDirectory_; bool binaryOutput_; - + edm::ESGetToken lstGeoToken_; }; From f2236b327a680bf8975e9c46994c64e723e2a9cf Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 18 Dec 2025 16:16:41 +0000 Subject: [PATCH 52/95] Fixed sign of some angles --- .../LSTCore/plugins/LSTGeometryESProducer.cc | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index c22047d6b8abd..4db4018e7aaa8 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -79,6 +79,11 @@ std::unique_ptr LSTGeometryESProducer::produce(const T } double tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); + if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { + tiltAngle_rad = std::numbers::pi_v / 2; + } else if (std::fabs(tiltAngle_rad) > 1e-3) { + tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); + } double meanWidth_cm = b2->width(); double length_cm = b2->length(); @@ -117,28 +122,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const T avg_z_cm[i] /= avg_z_counter[i]; } - // For debugging - for (auto &m : modules) { - std::cout << "module," << m.detId << "," << m.sensorCenterRho_cm << "," << m.sensorCenterZ_cm << "," - << m.tiltAngle_rad << "," << m.phi_rad << "," << m.meanWidth_cm << "," << m.length_cm << "," - << m.sensorSpacing_cm << std::endl; - } - for (auto &[detid, s] : sensors) { - std::cout << "sensor," << s.detId << "," << s.sensorCenterRho_cm << "," << s.sensorCenterZ_cm << "," << s.phi_rad - << std::endl; - } - std::cout << "avg_r_cm,"; - for (auto &r : avg_r_cm) { - std::cout << r << ","; - } - std::cout << std::endl; - std::cout << "avg_z_cm,"; - for (auto &z : avg_z_cm) { - std::cout << z << ","; - } - std::cout << std::endl; - // end debugging - double ptCut = std::stod(ptCut_); auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut); From 72cb6bdc6bc1f6522cc62279196d067e3067301b Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 19 Dec 2025 17:08:58 +0000 Subject: [PATCH 53/95] Leave a note on how to match the csv files --- .../LSTCore/plugins/LSTGeometryESProducer.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 4db4018e7aaa8..2b70fccbb91e5 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -79,11 +79,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const T } double tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); - if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { - tiltAngle_rad = std::numbers::pi_v / 2; - } else if (std::fabs(tiltAngle_rad) > 1e-3) { - tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); - } double meanWidth_cm = b2->width(); double length_cm = b2->length(); @@ -93,6 +88,19 @@ std::unique_ptr LSTGeometryESProducer::produce(const T unsigned int detid = detId(); unsigned short layer = lstgeometry::Module::parseLayer(detid); + + // This part is a little weird, but this is how to match the csv files + // z_cm += sensorSpacing_cm / 2.0 * std::sin(tiltAngle_rad); + // rho_cm += s * sensorSpacing_cm / 2.0 * std::cos(tiltAngle_rad); + // The way to determine the sign s is still a mystery to me + + // Fix angles of some modules + if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { + tiltAngle_rad = std::numbers::pi_v / 2; + } else if (std::fabs(tiltAngle_rad) > 1e-3) { + tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); + } + if (lstgeometry::Module::parseSubdet(detid) == lstgeometry::Module::SubDet::Barrel) { avg_r_cm[layer - 1] += rho_cm; avg_r_counter[layer - 1] += 1; From 7540ca06b65ea44d89c09c69b05d5bf9339c6fdf Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 19 Dec 2025 15:15:35 -0500 Subject: [PATCH 54/95] Figured out the sign --- RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 2b70fccbb91e5..6ad63e7230b6d 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -89,10 +89,13 @@ std::unique_ptr LSTGeometryESProducer::produce(const T unsigned short layer = lstgeometry::Module::parseLayer(detid); - // This part is a little weird, but this is how to match the csv files + // This part is a little weird, but this is how to match the csv files. + // I think it might be better to not do this since other parts of the code + // assume the center of the module is at (rho_cm, z_cm). + // // z_cm += sensorSpacing_cm / 2.0 * std::sin(tiltAngle_rad); - // rho_cm += s * sensorSpacing_cm / 2.0 * std::cos(tiltAngle_rad); - // The way to determine the sign s is still a mystery to me + // bool isFlipped = surface.normalVector().basicVector().dot(position.basicVector()) < 0; + // rho_cm += (isFlipped ? -1 : 1) * signsensorSpacing_cm / 2.0 * std::cos(tiltAngle_rad); // Fix angles of some modules if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { From 69834072a572ed17d4a89515edc31c08a8bc6343 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 6 Jan 2026 17:56:05 +0000 Subject: [PATCH 55/95] Added cli options to test --- RecoTracker/LSTCore/test/dumpLSTGeometry.py | 64 +++++++++++++------ .../LSTCore/test/testDumpLSTGeometry.sh | 2 +- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTCore/test/dumpLSTGeometry.py index cb1a90a512c3c..1988ce88d15df 100644 --- a/RecoTracker/LSTCore/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTCore/test/dumpLSTGeometry.py @@ -1,4 +1,7 @@ import FWCore.ParameterSet.Config as cms +from Configuration.AlCa.GlobalTag import GlobalTag +import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings +import FWCore.ParameterSet.VarParsing as VarParsing trackingLSTCommon = cms.Modifier() trackingLST = cms.ModifierChain(trackingLSTCommon) @@ -6,22 +9,20 @@ ################################################################### # Set default phase-2 settings ################################################################### -import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings _PH2_GLOBAL_TAG, _PH2_ERA = _settings.get_era_and_conditions(_settings.DEFAULT_VERSION) # No era in Fireworks/Geom reco dumper -process = cms.Process('DUMP', _PH2_ERA, trackingLST) +process = cms.Process("DUMP", _PH2_ERA, trackingLST) # import of standard configurations -process.load('Configuration.StandardSequences.Services_cff') -process.load('FWCore.MessageService.MessageLogger_cfi') -process.load('Configuration.Geometry.GeometryExtendedRun4DefaultReco_cff') -process.load('Configuration.StandardSequences.MagneticField_cff') -process.load('Configuration.StandardSequences.Reconstruction_cff') -process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +process.load("Configuration.StandardSequences.Services_cff") +process.load("FWCore.MessageService.MessageLogger_cfi") +process.load("Configuration.Geometry.GeometryExtendedRun4DefaultReco_cff") +process.load("Configuration.StandardSequences.MagneticField_cff") +process.load("Configuration.StandardSequences.Reconstruction_cff") +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, _PH2_GLOBAL_TAG, '') +process.GlobalTag = GlobalTag(process.GlobalTag, _PH2_GLOBAL_TAG, "") process.MessageLogger.cerr.threshold = "INFO" process.MessageLogger.cerr.LSTGeometryESProducer = dict(limit=-1) @@ -29,18 +30,39 @@ process.source = cms.Source("EmptySource") process.maxEvents.input = 1 - process.add_(cms.ESProducer("LSTGeometryESProducer")) -defaultOutputDirectory="data/" -defaultPtCut="0.8" -defaultToBinary=True +options = VarParsing.VarParsing() +options.register( + "outputDirectory", + "data/", + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.string, + "Output directory for LST geometry files", +) +options.register( + "ptCut", + 0.8, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.float, + "pT cut for LST module maps", +) +options.register( + "binaryOutput", + True, + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.bool, + "Dump LST geometry as binary files", +) +options.parseArguments() + -process.dump = cms.EDAnalyzer("DumpLSTGeometry", - outputDirectory = cms.untracked.string(defaultOutputDirectory), - ptCut = cms.string(defaultPtCut), - outputAsBinary = cms.untracked.bool(defaultToBinary), - ) +process.dump = cms.EDAnalyzer( + "DumpLSTGeometry", + outputDirectory = cms.untracked.string(options.outputDirectory), + ptCut = cms.string(str(options.ptCut)), + outputAsBinary = cms.untracked.bool(options.binaryOutput), +) -print("Requesting LST geometry dump into directory:", defaultOutputDirectory, "\n"); -process.p = cms.Path(process.dump) \ No newline at end of file +print(f"Requesting LST geometry dump into directory: {options.outputDirectory}\n") +process.p = cms.Path(process.dump) diff --git a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh index 6fb35cb84969f..f3a7524015b53 100755 --- a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh +++ b/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh @@ -7,4 +7,4 @@ if [ "${SCRAM_TEST_NAME}" != "" ] ; then cd ${SCRAM_TEST_NAME} fi -(cmsRun ${SCRAM_TEST_PATH}/dumpLSTGeometry.py --conditions auto:phase2_realistic_T33 --geometry ExtendedRun4D110 --era Phase2C17I13M9) || die "failed to run dumpLSTGeometry.py" $? +(cmsRun ${SCRAM_TEST_PATH}/dumpLSTGeometry.py outputDirectory="data/" ptCut=0.8 binaryOutput=true) || die "failed to run dumpLSTGeometry.py" $? From 180bb05eafc0170d93d9cbe5232e79e7a4ff5fad Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 8 Jan 2026 15:29:17 +0000 Subject: [PATCH 56/95] Tweak cmssw config --- RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc | 8 ++++---- RecoTracker/LST/python/lstProducerTask_cff.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc index 600a0d929624a..bdccdcc0ec33e 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc @@ -36,7 +36,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { private: void produce(edm::StreamID, device::Event& iEvent, const device::EventSetup& iSetup) const override; - const double ptCut_; + const std::string ptCut_; const edm::EDGetTokenT phase2OTRecHitToken_; @@ -50,7 +50,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { LSTInputProducer::LSTInputProducer(edm::ParameterSet const& iConfig) : EDProducer<>(iConfig), - ptCut_(iConfig.getParameter("ptCut")), + ptCut_(iConfig.getParameter("ptCut")), phase2OTRecHitToken_(consumes(iConfig.getParameter("phase2OTRecHits"))), mfToken_(esConsumes()), beamSpotToken_(consumes(iConfig.getParameter("beamSpot"))), @@ -63,7 +63,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { void LSTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("ptCut", 0.8); + desc.add("ptCut", "0.8"); desc.add("phase2OTRecHits", edm::InputTag("siPhase2RecHits")); @@ -224,7 +224,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { ph2_y, ph2_z, ph2_hits, - ptCut_, + std::stof(ptCut_), iEvent.queue()); iEvent.emplace(lstInputPutToken_, std::move(lstInputHC)); diff --git a/RecoTracker/LST/python/lstProducerTask_cff.py b/RecoTracker/LST/python/lstProducerTask_cff.py index 5caae9506f6ca..2847f06178ba9 100644 --- a/RecoTracker/LST/python/lstProducerTask_cff.py +++ b/RecoTracker/LST/python/lstProducerTask_cff.py @@ -4,6 +4,8 @@ from RecoTracker.LST.lstModulesDevESProducer_cfi import lstModulesDevESProducer +from RecoTracker.LST.lstInputProducer_cfi import lstInputProducer + from RecoTracker.LSTCore.lstGeometryESProducer_cfi import lstGeometryESProducer -lstProducerTask = cms.Task(lstGeometryESProducer, lstModulesDevESProducer, lstProducer) +lstProducerTask = cms.Task(lstGeometryESProducer, lstModulesDevESProducer, lstInputProducer, lstProducer) From 1c3a72e0f03a2ad9cf2bb44c3c752d296af85e82 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 9 Jan 2026 12:33:25 -0500 Subject: [PATCH 57/95] Switch to numerical parameters --- RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc | 8 ++++---- .../LST/plugins/alpaka/LSTModulesDevESProducer.cc | 10 +++++----- RecoTracker/LST/plugins/alpaka/LSTProducer.cc | 10 +++++----- RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc | 11 +++++------ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc index bdccdcc0ec33e..600a0d929624a 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTInputProducer.cc @@ -36,7 +36,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { private: void produce(edm::StreamID, device::Event& iEvent, const device::EventSetup& iSetup) const override; - const std::string ptCut_; + const double ptCut_; const edm::EDGetTokenT phase2OTRecHitToken_; @@ -50,7 +50,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { LSTInputProducer::LSTInputProducer(edm::ParameterSet const& iConfig) : EDProducer<>(iConfig), - ptCut_(iConfig.getParameter("ptCut")), + ptCut_(iConfig.getParameter("ptCut")), phase2OTRecHitToken_(consumes(iConfig.getParameter("phase2OTRecHits"))), mfToken_(esConsumes()), beamSpotToken_(consumes(iConfig.getParameter("beamSpot"))), @@ -63,7 +63,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { void LSTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("ptCut", "0.8"); + desc.add("ptCut", 0.8); desc.add("phase2OTRecHits", edm::InputTag("siPhase2RecHits")); @@ -224,7 +224,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { ph2_y, ph2_z, ph2_hits, - std::stof(ptCut_), + ptCut_, iEvent.queue()); iEvent.emplace(lstInputPutToken_, std::move(lstInputHC)); diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index 467d75ccb94e1..618b10b6ec09d 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -15,19 +15,19 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { class LSTModulesDevESProducer : public ESProducer { private: - std::string ptCut_; + double ptCut_; edm::ESGetToken lstGeoToken_; public: LSTModulesDevESProducer(edm::ParameterSet const& iConfig) - : ESProducer(iConfig), ptCut_(iConfig.getParameter("ptCut")) { - auto cc = setWhatProduced(this, ptCut_); - lstGeoToken_ = cc.consumes(edm::ESInputTag("", ptCut_)); + : ESProducer(iConfig), ptCut_(iConfig.getParameter("ptCut")) { + auto cc = setWhatProduced(this, "LSTModuleMaps"); + lstGeoToken_ = cc.consumes(edm::ESInputTag("", "LSTGeometry")); } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("ptCut", "0.8"); + desc.add("ptCut", 0.8); descriptions.addWithDefaultLabel(desc); } diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index ca0ab8e483c56..eed5fb75c9427 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -26,9 +26,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { LSTProducer(edm::ParameterSet const& config) : EDProducer(config), lstInputToken_{consumes(config.getParameter("lstInput"))}, - lstESToken_{esConsumes(edm::ESInputTag("", config.getParameter("ptCut")))}, + lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps"))}, verbose_(config.getParameter("verbose")), - ptCut_(config.getParameter("ptCut")), + ptCut_(config.getParameter("ptCut")), clustSizeCut_(static_cast(config.getParameter("clustSizeCut"))), nopLSDupClean_(config.getParameter("nopLSDupClean")), tcpLSTriplets_(config.getParameter("tcpLSTriplets")), @@ -42,7 +42,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { lst.run(iEvent.queue(), verbose_, - std::stof(ptCut_), + ptCut_, clustSizeCut_, &lstESDeviceData, &lstInputDC, @@ -58,7 +58,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { edm::ParameterSetDescription desc; desc.add("lstInput", edm::InputTag{"lstInputProducer"}); desc.add("verbose", false); - desc.add("ptCut", "0.8"); + desc.add("ptCut", 0.8); desc.add("clustSizeCut", 16); desc.add("nopLSDupClean", false); desc.add("tcpLSTriplets", false); @@ -69,7 +69,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { const device::EDGetToken lstInputToken_; const device::ESGetToken, TrackerRecoGeometryRecord> lstESToken_; const bool verbose_; - const std::string ptCut_; + const double ptCut_; const uint16_t clustSizeCut_; const bool nopLSDupClean_; const bool tcpLSTriplets_; diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc index 6ad63e7230b6d..f579da887a9b8 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc @@ -25,7 +25,7 @@ class LSTGeometryESProducer : public edm::ESProducer { std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); private: - std::string ptCut_; + double ptCut_; edm::ESGetToken geomToken_; @@ -33,14 +33,14 @@ class LSTGeometryESProducer : public edm::ESProducer { }; LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) - : ptCut_(iConfig.getParameter("ptCut")) { - auto cc = setWhatProduced(this, ptCut_); + : ptCut_(iConfig.getParameter("ptCut")) { + auto cc = setWhatProduced(this, "LSTGeometry"); geomToken_ = cc.consumes(); } void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { edm::ParameterSetDescription desc; - desc.add("ptCut", "0.8"); + desc.add("ptCut", 0.8); descriptions.addWithDefaultLabel(desc); } @@ -133,8 +133,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const T avg_z_cm[i] /= avg_z_counter[i]; } - double ptCut = std::stod(ptCut_); - auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut); + auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut_); return lstGeometry; } From 40f8659ffbbb94166e8103ec3c187a25b8bd1011 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 13 Jan 2026 14:54:36 +0000 Subject: [PATCH 58/95] Minor cleanup --- RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h | 2 -- RecoTracker/LSTCore/standalone/Makefile | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h index 1f1c05aa6a14a..ff8370e5cbc39 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h @@ -135,7 +135,6 @@ namespace lstgeometry { auto corners = getCorners(detid); RowVectorD3 center = corners.colwise().mean(); center /= 4.; - //double ref_phi = std::atan2(center(2), center(1)); auto etaphi = getEtaPhi(center(1), center(2), center(0)); for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { @@ -155,7 +154,6 @@ namespace lstgeometry { auto corners = getCorners(detid); RowVectorD3 center = corners.colwise().mean(); center /= 4.; - //double ref_phi = std::atan2(center(2), center(1)); auto etaphi = getEtaPhi(center(1), center(2), center(0)); for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { diff --git a/RecoTracker/LSTCore/standalone/Makefile b/RecoTracker/LSTCore/standalone/Makefile index 7d29eefe4f446..3aa498c6f1d6c 100644 --- a/RecoTracker/LSTCore/standalone/Makefile +++ b/RecoTracker/LSTCore/standalone/Makefile @@ -74,7 +74,7 @@ efficiency: rooutil $(MAKE) -C efficiency/ clean: - rm -f $(OBJECTS) bin/*.o $(EXES) bin/lst + rm -f $(OBJECTS) bin/*.o $(EXES) bin/lst $(GEOMETRY_EXES) rm -f code/rooutil/*.so code/rooutil/*.o rm -f bin/lst.o rm -f LST/*.o From 5bf6f99edc05c64501d304c19bacbfea48eccc22 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 13 Jan 2026 15:44:59 +0000 Subject: [PATCH 59/95] Added help option --- RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index b11a3886d0dda..586f5256fe58e 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -25,10 +25,15 @@ int main(int argc, char** argv) { "output_as_binary", "Boolean flag specifying whether to write outputs as binary or text files.", cxxopts::value()->default_value("true"))( - "pt_cut", "pT cutoff value.", cxxopts::value()->default_value("0.8")); + "pt_cut", "pT cutoff value.", cxxopts::value()->default_value("0.8"))("h,help", "Print help"); auto result = options.parse(argc, argv); + if (result.count("help")) { + std::cout << options.help() << std::endl; + exit(1); + } + std::string module_info_file = result["module_info_file"].as(); std::string sensor_info_file = result["sensor_info_file"].as(); std::string average_r_file = result["average_r_file"].as(); From a328d7cffe0fea22900367730839e13b436e3433 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 13 Jan 2026 11:29:09 -0500 Subject: [PATCH 60/95] Improve explanation of procedure --- RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h index 7571d608fd407..856a27bc67a6c 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h @@ -47,6 +47,8 @@ namespace lstgeometry { } // Consider barrel to endcap connections if the intersection area is > 0 + // We construct the reference polygon as a vector of polygons because the boost::geometry::difference + // function can return multiple polygons if the difference results in disjoint pieces if (ref_subdet == 5) { std::unordered_set barrel_endcap_connected_tar_detids; @@ -213,6 +215,8 @@ namespace lstgeometry { } // Consider barrel to endcap connections if the intersection area is > 0 + // We construct the reference polygon as a vector of polygons because the boost::geometry::difference + // function can return multiple polygons if the difference results in disjoint pieces if (ref_subdet == 5) { std::unordered_set barrel_endcap_connected_tar_detids; From 6deaf046ee103c26904d85f91e171a84020abeb7 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 18 Feb 2026 16:46:20 -0500 Subject: [PATCH 61/95] Rename ES functions for different payloads --- RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc | 2 +- RecoTracker/LSTCore/interface/LSTESData.h | 4 ++-- RecoTracker/LSTCore/src/LSTESData.cc | 6 +++--- RecoTracker/LSTCore/standalone/bin/lst.cc | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index 618b10b6ec09d..7a5131f1ddb0b 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -33,7 +33,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { std::unique_ptr> produce(TrackerRecoGeometryRecord const& iRecord) { const auto& lstg = iRecord.get(lstGeoToken_); - return lst::loadAndFillESHost(lstg); + return lst::fillESDataHost(lstg); } }; diff --git a/RecoTracker/LSTCore/interface/LSTESData.h b/RecoTracker/LSTCore/interface/LSTESData.h index b8cfb101272e1..2f122f8598b4d 100644 --- a/RecoTracker/LSTCore/interface/LSTESData.h +++ b/RecoTracker/LSTCore/interface/LSTESData.h @@ -41,8 +41,8 @@ namespace lst { pixelMapping(pixelMappingIn) {} }; - std::unique_ptr> loadAndFillESHost(std::string& ptCutLabel); - std::unique_ptr> loadAndFillESHost(lstgeometry::LSTGeometry const& lstg); + std::unique_ptr> loadAndFillESDataHost(std::string& ptCutLabel); + std::unique_ptr> fillESDataHost(lstgeometry::LSTGeometry const& lstg); } // namespace lst diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index c493ccdc81e9d..1352c3d64e23e 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -81,7 +81,7 @@ namespace { } } // namespace -std::unique_ptr> lst::loadAndFillESHost(std::string& ptCutLabel) { +std::unique_ptr> lst::loadAndFillESDataHost(std::string& ptCutLabel) { uint16_t nModules; uint16_t nLowerModules; unsigned int nPixels; @@ -122,7 +122,7 @@ std::unique_ptr> lst::loadAndFillESHost(s pixelMappingPtr); } -std::unique_ptr> lst::loadAndFillESHost(lstgeometry::LSTGeometry const& lstg) { +std::unique_ptr> lst::fillESDataHost(lstgeometry::LSTGeometry const& lstg) { uint16_t nModules; uint16_t nLowerModules; unsigned int nPixels; @@ -134,7 +134,7 @@ std::unique_ptr> lst::loadAndFillESHost(l endcapGeometry.load(lstg.endcap_slopes, lstg.sensor_info); auto endcapGeometryDev = - std::make_shared(endcapGeometry.nEndCapMap, cms::alpakatools::host()); + std::make_shared(cms::alpakatools::host(), endcapGeometry.nEndCapMap); std::memcpy(endcapGeometryDev->view().geoMapDetId().data(), endcapGeometry.geoMapDetId_buf.data(), endcapGeometry.nEndCapMap * sizeof(unsigned int)); diff --git a/RecoTracker/LSTCore/standalone/bin/lst.cc b/RecoTracker/LSTCore/standalone/bin/lst.cc index bd1d2825309c1..191a601bae0db 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst.cc @@ -369,7 +369,7 @@ void run_lst() { full_timer.Start(); // Determine which maps to use based on given pt cut for standalone. std::string ptCutString = (ana.ptCut >= 0.8) ? "0.8" : "0.6"; - auto hostESData = lst::loadAndFillESHost(ptCutString); + auto hostESData = lst::loadAndFillESDataHost(ptCutString); auto deviceESData = cms::alpakatools::CopyToDevice>::copyAsync(queues[0], *hostESData.get()); float timeForMapLoading = full_timer.RealTime() * 1000; From cc91d499f28a34f772d6650ac16723a7dd9b3d55 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Feb 2026 19:00:39 +0000 Subject: [PATCH 62/95] Moved things to a new LSTGeometry package --- .../plugins/alpaka/LSTModulesDevESProducer.cc | 6 ++--- RecoTracker/LSTCore/BuildFile.xml | 2 +- .../LSTCore/interface/EndcapGeometry.h | 2 +- RecoTracker/LSTCore/interface/LSTESData.h | 4 ++-- .../LSTCore/interface/TiltedGeometry.h | 2 +- RecoTracker/LSTCore/src/ES_LSTGeometry.cc | 7 ------ RecoTracker/LSTCore/src/LSTESData.cc | 2 +- .../standalone/bin/lst_make_geometry.cc | 6 ++--- RecoTracker/LSTCore/test/BuildFile.xml | 8 ------- RecoTracker/LSTGeometry/BuildFile.xml | 6 +++++ .../interface}/Centroid.h | 4 ++-- .../interface}/CentroidMethods.h | 12 +++++----- .../interface}/Common.h | 4 ++-- .../interface}/CornerMethods.h | 10 ++++----- .../interface}/DetectorGeometry.h | 10 ++++----- .../interface/Geometry.h} | 14 ++++++------ .../interface/GeometryMethods.h} | 22 +++++++++---------- .../interface}/Helix.h | 4 ++-- .../interface}/IO.h | 17 +++++++------- .../interface/Math.h} | 8 +++---- .../interface}/Module.h | 4 ++-- .../interface}/ModuleInfo.h | 6 ++--- .../interface}/ModuleMapMethods.h | 12 +++++----- .../interface}/OrientationMethods.h | 10 ++++----- .../interface}/PixelMap.h | 4 ++-- .../interface}/PixelMapMethods.h | 15 ++++++------- .../interface}/SensorInfo.h | 4 ++-- .../interface}/SlopeData.h | 4 ++-- .../plugins/BuildFile.xml | 0 .../plugins/LSTGeometryESProducer.cc | 15 ++++++------- RecoTracker/LSTGeometry/src/Geometry.cc | 3 +++ RecoTracker/LSTGeometry/test/BuildFile.xml | 9 ++++++++ .../test/DumpLSTGeometry.cc | 6 ++--- .../test/dumpLSTGeometry.py | 0 .../LSTGeometry/test/runCompilationTest.sh | 8 +++++++ .../test/testDumpLSTGeometry.sh | 0 36 files changed, 129 insertions(+), 121 deletions(-) delete mode 100644 RecoTracker/LSTCore/src/ES_LSTGeometry.cc create mode 100644 RecoTracker/LSTGeometry/BuildFile.xml rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/Centroid.h (56%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/CentroidMethods.h (87%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/Common.h (94%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/CornerMethods.h (95%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/DetectorGeometry.h (97%) rename RecoTracker/{LSTCore/interface/LSTGeometry/LSTGeometry.h => LSTGeometry/interface/Geometry.h} (51%) rename RecoTracker/{LSTCore/interface/LSTGeometry/LSTGeometryMethods.h => LSTGeometry/interface/GeometryMethods.h} (74%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/Helix.h (64%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/IO.h (95%) rename RecoTracker/{LSTCore/interface/LSTGeometry/LSTMath.h => LSTGeometry/interface/Math.h} (96%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/Module.h (99%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/ModuleInfo.h (67%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/ModuleMapMethods.h (96%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/OrientationMethods.h (83%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/PixelMap.h (81%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/PixelMapMethods.h (92%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/SensorInfo.h (62%) rename RecoTracker/{LSTCore/interface/LSTGeometry => LSTGeometry/interface}/SlopeData.h (52%) rename RecoTracker/{LSTCore => LSTGeometry}/plugins/BuildFile.xml (100%) rename RecoTracker/{LSTCore => LSTGeometry}/plugins/LSTGeometryESProducer.cc (88%) create mode 100644 RecoTracker/LSTGeometry/src/Geometry.cc create mode 100644 RecoTracker/LSTGeometry/test/BuildFile.xml rename RecoTracker/{LSTCore => LSTGeometry}/test/DumpLSTGeometry.cc (90%) rename RecoTracker/{LSTCore => LSTGeometry}/test/dumpLSTGeometry.py (100%) create mode 100755 RecoTracker/LSTGeometry/test/runCompilationTest.sh rename RecoTracker/{LSTCore => LSTGeometry}/test/testDumpLSTGeometry.sh (100%) diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index 7a5131f1ddb0b..aa91e8e322d69 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -1,6 +1,6 @@ // LST includes #include "RecoTracker/LSTCore/interface/alpaka/LST.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -16,13 +16,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { class LSTModulesDevESProducer : public ESProducer { private: double ptCut_; - edm::ESGetToken lstGeoToken_; + edm::ESGetToken lstGeoToken_; public: LSTModulesDevESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig), ptCut_(iConfig.getParameter("ptCut")) { auto cc = setWhatProduced(this, "LSTModuleMaps"); - lstGeoToken_ = cc.consumes(edm::ESInputTag("", "LSTGeometry")); + lstGeoToken_ = cc.consumes(edm::ESInputTag("", "LSTGeometry")); } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { diff --git a/RecoTracker/LSTCore/BuildFile.xml b/RecoTracker/LSTCore/BuildFile.xml index dbfe1a9fcda87..4c062cae70ebf 100644 --- a/RecoTracker/LSTCore/BuildFile.xml +++ b/RecoTracker/LSTCore/BuildFile.xml @@ -5,7 +5,7 @@ - + diff --git a/RecoTracker/LSTCore/interface/EndcapGeometry.h b/RecoTracker/LSTCore/interface/EndcapGeometry.h index 91891e1292e2e..e2727c29ba7e3 100644 --- a/RecoTracker/LSTCore/interface/EndcapGeometry.h +++ b/RecoTracker/LSTCore/interface/EndcapGeometry.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_LSTCore_interface_EndcapGeometry_h #define RecoTracker_LSTCore_interface_EndcapGeometry_h -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" #include #include diff --git a/RecoTracker/LSTCore/interface/LSTESData.h b/RecoTracker/LSTCore/interface/LSTESData.h index 2f122f8598b4d..2c0a0458b3530 100644 --- a/RecoTracker/LSTCore/interface/LSTESData.h +++ b/RecoTracker/LSTCore/interface/LSTESData.h @@ -5,7 +5,7 @@ #include "RecoTracker/LSTCore/interface/EndcapGeometryDevHostCollection.h" #include "RecoTracker/LSTCore/interface/ModulesHostCollection.h" #include "RecoTracker/LSTCore/interface/PixelMap.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" #include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" @@ -42,7 +42,7 @@ namespace lst { }; std::unique_ptr> loadAndFillESDataHost(std::string& ptCutLabel); - std::unique_ptr> fillESDataHost(lstgeometry::LSTGeometry const& lstg); + std::unique_ptr> fillESDataHost(lstgeometry::Geometry const& lstg); } // namespace lst diff --git a/RecoTracker/LSTCore/interface/TiltedGeometry.h b/RecoTracker/LSTCore/interface/TiltedGeometry.h index 2545ff4c0d11e..caeb2689e2f2b 100644 --- a/RecoTracker/LSTCore/interface/TiltedGeometry.h +++ b/RecoTracker/LSTCore/interface/TiltedGeometry.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_LSTCore_interface_TiltedGeometry_h #define RecoTracker_LSTCore_interface_TiltedGeometry_h -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" #include #include diff --git a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc b/RecoTracker/LSTCore/src/ES_LSTGeometry.cc deleted file mode 100644 index 5254589aa904e..0000000000000 --- a/RecoTracker/LSTCore/src/ES_LSTGeometry.cc +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef LST_STANDALONE - -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" -#include "FWCore/Utilities/interface/typelookup.h" -TYPELOOKUP_DATA_REG(lstgeometry::LSTGeometry); - -#endif diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 1352c3d64e23e..509584489fdb7 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -122,7 +122,7 @@ std::unique_ptr> lst::loadAndFillESDataHo pixelMappingPtr); } -std::unique_ptr> lst::fillESDataHost(lstgeometry::LSTGeometry const& lstg) { +std::unique_ptr> lst::fillESDataHost(lstgeometry::Geometry const& lstg) { uint16_t nModules; uint16_t nLowerModules; unsigned int nPixels; diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 586f5256fe58e..0754f18b12832 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -2,8 +2,8 @@ #include "cxxopts.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h" +#include "RecoTracker/LSTGeometry/interface/IO.h" +#include "RecoTracker/LSTGeometry/interface/GeometryMethods.h" using namespace lstgeometry; @@ -47,7 +47,7 @@ int main(int argc, char** argv) { auto average_r = readAverages(average_r_file); auto average_z = readAverages(average_z_file); - auto lstGeometry = makeLSTGeometry(modules_info, sensors_info, average_r, average_z, ptCut); + auto lstGeometry = makeGeometry(modules_info, sensors_info, average_r, average_z, ptCut); writeCentroids(lstGeometry->centroids, output_dir + "sensor_centroids", output_as_bin); writeSlopes( diff --git a/RecoTracker/LSTCore/test/BuildFile.xml b/RecoTracker/LSTCore/test/BuildFile.xml index 6728daccf7b88..6b090deadfb2b 100644 --- a/RecoTracker/LSTCore/test/BuildFile.xml +++ b/RecoTracker/LSTCore/test/BuildFile.xml @@ -1,9 +1 @@ - - - - - - - - \ No newline at end of file diff --git a/RecoTracker/LSTGeometry/BuildFile.xml b/RecoTracker/LSTGeometry/BuildFile.xml new file mode 100644 index 0000000000000..9e8dceec3362a --- /dev/null +++ b/RecoTracker/LSTGeometry/BuildFile.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h b/RecoTracker/LSTGeometry/interface/Centroid.h similarity index 56% rename from RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h rename to RecoTracker/LSTGeometry/interface/Centroid.h index 0fc9bb661896f..ae2d8919bc74e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h +++ b/RecoTracker/LSTGeometry/interface/Centroid.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h -#define RecoTracker_LSTCore_interface_LSTGeometry_Centroid_h +#ifndef RecoTracker_LSTGeometry_interface_Centroid_h +#define RecoTracker_LSTGeometry_interface_Centroid_h namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h b/RecoTracker/LSTGeometry/interface/CentroidMethods.h similarity index 87% rename from RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h rename to RecoTracker/LSTGeometry/interface/CentroidMethods.h index bb66bc15a79ff..a17458762e235 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h +++ b/RecoTracker/LSTGeometry/interface/CentroidMethods.h @@ -1,13 +1,13 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h -#define RecoTracker_LSTCore_interface_LSTGeometry_CentroidMethods_h +#ifndef RecoTracker_LSTGeometry_interface_CentroidMethods_h +#define RecoTracker_LSTGeometry_interface_CentroidMethods_h #include #include -#include "Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h b/RecoTracker/LSTGeometry/interface/Common.h similarity index 94% rename from RecoTracker/LSTCore/interface/LSTGeometry/Common.h rename to RecoTracker/LSTGeometry/interface/Common.h index 3535b98bde387..0f46eed5e4b55 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Common_h -#define RecoTracker_LSTCore_interface_LSTGeometry_Common_h +#ifndef RecoTracker_LSTGeometry_interface_Common_h +#define RecoTracker_LSTGeometry_interface_Common_h #include #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h b/RecoTracker/LSTGeometry/interface/CornerMethods.h similarity index 95% rename from RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h rename to RecoTracker/LSTGeometry/interface/CornerMethods.h index 242e09c765e5e..d7d6dd7996ce4 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h +++ b/RecoTracker/LSTGeometry/interface/CornerMethods.h @@ -1,13 +1,13 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_CornerMethods_h -#define RecoTracker_LSTCore_interface_LSTGeometry_CornerMethods_h +#ifndef RecoTracker_LSTGeometry_interface_CornerMethods_h +#define RecoTracker_LSTGeometry_interface_CornerMethods_h #include #include #include -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h similarity index 97% rename from RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h rename to RecoTracker/LSTGeometry/interface/DetectorGeometry.h index ff8370e5cbc39..cf2a134c99c3a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -1,14 +1,14 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_DetectorGeometry_h -#define RecoTracker_LSTCore_interface_LSTGeometry_DetectorGeometry_h +#ifndef RecoTracker_LSTGeometry_interface_DetectorGeometry_h +#define RecoTracker_LSTGeometry_interface_DetectorGeometry_h #include #include #include #include -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/Math.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h similarity index 51% rename from RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h rename to RecoTracker/LSTGeometry/interface/Geometry.h index 87e75ba3e2533..d2b534f9543c9 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -1,14 +1,14 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometry_h -#define RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometry_h +#ifndef RecoTracker_LSTGeometry_interface_Geometry_h +#define RecoTracker_LSTGeometry_interface_Geometry_h -#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/SlopeData.h" +#include "RecoTracker/LSTGeometry/interface/PixelMap.h" +#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" namespace lstgeometry { - struct LSTGeometry { + struct Geometry { std::unordered_map centroids; std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h b/RecoTracker/LSTGeometry/interface/GeometryMethods.h similarity index 74% rename from RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h rename to RecoTracker/LSTGeometry/interface/GeometryMethods.h index 338ff0e0c7e07..2f2fa49342460 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h +++ b/RecoTracker/LSTGeometry/interface/GeometryMethods.h @@ -1,17 +1,17 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometryMethods_h -#define RecoTracker_LSTCore_interface_LSTGeometry_LSTGeometryMethods_h +#ifndef RecoTracker_LSTGeometry_interface_GeometryMethods_h +#define RecoTracker_LSTGeometry_interface_GeometryMethods_h -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CornerMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include "RecoTracker/LSTGeometry/interface/CornerMethods.h" +#include "RecoTracker/LSTGeometry/interface/CentroidMethods.h" +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" +#include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" +#include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" +#include "RecoTracker/LSTGeometry/interface/ModuleMapMethods.h" namespace lstgeometry { - std::unique_ptr makeLSTGeometry(std::vector &modules_info, + std::unique_ptr makeGeometry(std::vector &modules_info, std::unordered_map &sensors_info, std::vector const &average_r, std::vector const &average_z, @@ -47,7 +47,7 @@ namespace lstgeometry { } auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); - auto lstGeometry = std::make_unique(std::move(centroids), + auto lstGeometry = std::make_unique(std::move(centroids), std::move(barrel_slopes), std::move(endcap_slopes), std::move(pixel_map), diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h b/RecoTracker/LSTGeometry/interface/Helix.h similarity index 64% rename from RecoTracker/LSTCore/interface/LSTGeometry/Helix.h rename to RecoTracker/LSTGeometry/interface/Helix.h index ca15660f3dfff..2ce1278c269d9 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Helix.h +++ b/RecoTracker/LSTGeometry/interface/Helix.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Helix_h -#define RecoTracker_LSTCore_interface_LSTGeometry_Helix_h +#ifndef RecoTracker_LSTGeometry_interface_Helix_h +#define RecoTracker_LSTGeometry_interface_Helix_h namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h b/RecoTracker/LSTGeometry/interface/IO.h similarity index 95% rename from RecoTracker/LSTCore/interface/LSTGeometry/IO.h rename to RecoTracker/LSTGeometry/interface/IO.h index ea20bd3d70907..4f3ec886def74 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -1,12 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_IO_h -#define RecoTracker_LSTCore_interface_LSTGeometry_IO_h - -#include "Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h" +#ifndef RecoTracker_LSTGeometry_interface_IO_h +#define RecoTracker_LSTGeometry_interface_IO_h #include #include @@ -16,6 +9,12 @@ #include #include +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" +#include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" + namespace lstgeometry { std::string trim(std::string const& str) { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h b/RecoTracker/LSTGeometry/interface/Math.h similarity index 96% rename from RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h rename to RecoTracker/LSTGeometry/interface/Math.h index 7a7137a874cd3..d9831e24c69cf 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h +++ b/RecoTracker/LSTGeometry/interface/Math.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_LSTMath_h -#define RecoTracker_LSTCore_interface_LSTGeometry_LSTMath_h +#ifndef RecoTracker_LSTGeometry_interface_Math_h +#define RecoTracker_LSTGeometry_interface_Math_h #include @@ -7,8 +7,8 @@ #include #include -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Helix.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Helix.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h b/RecoTracker/LSTGeometry/interface/Module.h similarity index 99% rename from RecoTracker/LSTCore/interface/LSTGeometry/Module.h rename to RecoTracker/LSTGeometry/interface/Module.h index 51aa7d4e5ae57..c5a761a3bcdb3 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/Module.h +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_Module_h -#define RecoTracker_LSTCore_interface_LSTGeometry_Module_h +#ifndef RecoTracker_LSTGeometry_interface_Module_h +#define RecoTracker_LSTGeometry_interface_Module_h #include #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h b/RecoTracker/LSTGeometry/interface/ModuleInfo.h similarity index 67% rename from RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h rename to RecoTracker/LSTGeometry/interface/ModuleInfo.h index d3fea87091ed4..0ae86ea15c58e 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h +++ b/RecoTracker/LSTGeometry/interface/ModuleInfo.h @@ -1,7 +1,7 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleInfo_h -#define RecoTracker_LSTCore_interface_LSTGeometry_ModuleInfo_h +#ifndef RecoTracker_LSTGeometry_interface_ModuleInfo_h +#define RecoTracker_LSTGeometry_interface_ModuleInfo_h -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h similarity index 96% rename from RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h rename to RecoTracker/LSTGeometry/interface/ModuleMapMethods.h index 856a27bc67a6c..46dd86c82fa74 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/ModuleMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h -#define RecoTracker_LSTCore_interface_LSTGeometry_ModuleMapMethods_h +#ifndef RecoTracker_LSTGeometry_interface_ModuleMapMethods_h +#define RecoTracker_LSTGeometry_interface_ModuleMapMethods_h #include #include @@ -12,10 +12,10 @@ #include #include -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTMath.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Math.h" +#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h similarity index 83% rename from RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h rename to RecoTracker/LSTGeometry/interface/OrientationMethods.h index 5e2b128a41887..a931a65a374e0 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -1,13 +1,13 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_OrientationMethods_h -#define RecoTracker_LSTCore_interface_LSTGeometry_OrientationMethods_h +#ifndef RecoTracker_LSTGeometry_interface_OrientationMethods_h +#define RecoTracker_LSTGeometry_interface_OrientationMethods_h #include #include #include -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/CentroidMethods.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/CentroidMethods.h" +#include "RecoTracker/LSTGeometry/interface/SlopeData.h" namespace lstgeometry { diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h b/RecoTracker/LSTGeometry/interface/PixelMap.h similarity index 81% rename from RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h rename to RecoTracker/LSTGeometry/interface/PixelMap.h index 8a9fba984c0e2..41741a63f7578 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h +++ b/RecoTracker/LSTGeometry/interface/PixelMap.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_PixelMap_h -#define RecoTracker_LSTCore_interface_LSTGeometry_PixelMap_h +#ifndef RecoTracker_LSTGeometry_interface_PixelMap_h +#define RecoTracker_LSTGeometry_interface_PixelMap_h #include #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h similarity index 92% rename from RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h rename to RecoTracker/LSTGeometry/interface/PixelMapMethods.h index 9a05c6ca7fc4f..c6601ec00fcf6 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/PixelMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h @@ -1,14 +1,13 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h -#define RecoTracker_LSTCore_interface_LSTGeometry_PixelMapMethods_h +#ifndef RecoTracker_LSTGeometry_interface_PixelMapMethods_h +#define RecoTracker_LSTGeometry_interface_PixelMapMethods_h #include -#include "RecoTracker/LSTCore/interface/LSTGeometry/Common.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Centroid.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/DetectorGeometry.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/PixelMap.h" - +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/PixelMap.h" namespace lstgeometry { PixelMap computePixelMap(std::unordered_map const& centroids, diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h b/RecoTracker/LSTGeometry/interface/SensorInfo.h similarity index 62% rename from RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h rename to RecoTracker/LSTGeometry/interface/SensorInfo.h index ffd6f336e3d4d..7905044a4df6d 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h +++ b/RecoTracker/LSTGeometry/interface/SensorInfo.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_SensorInfo_h -#define RecoTracker_LSTCore_interface_LSTGeometry_SensorInfo_h +#ifndef RecoTracker_LSTGeometry_interface_SensorInfo_h +#define RecoTracker_LSTGeometry_interface_SensorInfo_h #include diff --git a/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h b/RecoTracker/LSTGeometry/interface/SlopeData.h similarity index 52% rename from RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h rename to RecoTracker/LSTGeometry/interface/SlopeData.h index 84d4aa4503ea1..e769f4978d21a 100644 --- a/RecoTracker/LSTCore/interface/LSTGeometry/SlopeData.h +++ b/RecoTracker/LSTGeometry/interface/SlopeData.h @@ -1,5 +1,5 @@ -#ifndef RecoTracker_LSTCore_interface_LSTGeometry_SlopeData_h -#define RecoTracker_LSTCore_interface_LSTGeometry_SlopeData_h +#ifndef RecoTracker_LSTGeometry_interface_SlopeData_h +#define RecoTracker_LSTGeometry_interface_SlopeData_h namespace lstgeometry { diff --git a/RecoTracker/LSTCore/plugins/BuildFile.xml b/RecoTracker/LSTGeometry/plugins/BuildFile.xml similarity index 100% rename from RecoTracker/LSTCore/plugins/BuildFile.xml rename to RecoTracker/LSTGeometry/plugins/BuildFile.xml diff --git a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc similarity index 88% rename from RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc rename to RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index f579da887a9b8..4175a7203c875 100644 --- a/RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -6,11 +6,10 @@ #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" -// LST includes -#include "RecoTracker/LSTCore/interface/LSTGeometry/SensorInfo.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/ModuleInfo.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/Module.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometryMethods.h" +#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/GeometryMethods.h" #include #include @@ -22,7 +21,7 @@ class LSTGeometryESProducer : public edm::ESProducer { static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); + std::unique_ptr produce(const TrackerRecoGeometryRecord &iRecord); private: double ptCut_; @@ -44,7 +43,7 @@ void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &des descriptions.addWithDefaultLabel(desc); } -std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { +std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { trackerGeom_ = &iRecord.get(geomToken_); std::vector modules; @@ -133,7 +132,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const T avg_z_cm[i] /= avg_z_counter[i]; } - auto lstGeometry = makeLSTGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut_); + auto lstGeometry = lstgeometry::makeGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut_); return lstGeometry; } diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc new file mode 100644 index 0000000000000..5780012381ed2 --- /dev/null +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -0,0 +1,3 @@ +#include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include "FWCore/Utilities/interface/typelookup.h" +TYPELOOKUP_DATA_REG(lstgeometry::Geometry); diff --git a/RecoTracker/LSTGeometry/test/BuildFile.xml b/RecoTracker/LSTGeometry/test/BuildFile.xml new file mode 100644 index 0000000000000..6728daccf7b88 --- /dev/null +++ b/RecoTracker/LSTGeometry/test/BuildFile.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc similarity index 90% rename from RecoTracker/LSTCore/test/DumpLSTGeometry.cc rename to RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index 451fc20382688..63fc2af2cc535 100644 --- a/RecoTracker/LSTCore/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -6,8 +6,8 @@ #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/LSTGeometry.h" -#include "RecoTracker/LSTCore/interface/LSTGeometry/IO.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include "RecoTracker/LSTGeometry/interface/IO.h" class DumpLSTGeometry : public edm::one::EDAnalyzer<> { public: @@ -20,7 +20,7 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { std::string outputDirectory_; bool binaryOutput_; - edm::ESGetToken lstGeoToken_; + edm::ESGetToken lstGeoToken_; }; DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) diff --git a/RecoTracker/LSTCore/test/dumpLSTGeometry.py b/RecoTracker/LSTGeometry/test/dumpLSTGeometry.py similarity index 100% rename from RecoTracker/LSTCore/test/dumpLSTGeometry.py rename to RecoTracker/LSTGeometry/test/dumpLSTGeometry.py diff --git a/RecoTracker/LSTGeometry/test/runCompilationTest.sh b/RecoTracker/LSTGeometry/test/runCompilationTest.sh new file mode 100755 index 0000000000000..a1aa288b90d74 --- /dev/null +++ b/RecoTracker/LSTGeometry/test/runCompilationTest.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cp -r $CMSSW_BASE/src/RecoTracker/LSTCore ./ +find LSTCore -type d | xargs chmod +w +cd LSTCore/standalone +source setup.sh +echo "Building LST CPU backend..." +lst_make_tracklooper -mCs diff --git a/RecoTracker/LSTCore/test/testDumpLSTGeometry.sh b/RecoTracker/LSTGeometry/test/testDumpLSTGeometry.sh similarity index 100% rename from RecoTracker/LSTCore/test/testDumpLSTGeometry.sh rename to RecoTracker/LSTGeometry/test/testDumpLSTGeometry.sh From 8c42aea04b49ea13ccf77c46858bd5cbbdd867d8 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Feb 2026 19:53:16 +0000 Subject: [PATCH 63/95] Renamed Centroid to SensorCentroid --- RecoTracker/LSTCore/src/LSTESData.cc | 2 +- .../standalone/bin/lst_make_geometry.cc | 2 +- RecoTracker/LSTGeometry/interface/Centroid.h | 15 --------- RecoTracker/LSTGeometry/interface/Geometry.h | 4 +-- .../LSTGeometry/interface/GeometryMethods.h | 20 ++++++------ RecoTracker/LSTGeometry/interface/IO.h | 6 ++-- .../LSTGeometry/interface/ModuleMapMethods.h | 32 ++++++++++--------- .../interface/OrientationMethods.h | 2 +- .../LSTGeometry/interface/PixelMapMethods.h | 6 ++-- .../LSTGeometry/interface/SensorCentroid.h | 15 +++++++++ ...troidMethods.h => SensorCentroidMethods.h} | 12 +++---- .../LSTGeometry/test/DumpLSTGeometry.cc | 4 +-- 12 files changed, 61 insertions(+), 59 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/Centroid.h create mode 100644 RecoTracker/LSTGeometry/interface/SensorCentroid.h rename RecoTracker/LSTGeometry/interface/{CentroidMethods.h => SensorCentroidMethods.h} (85%) diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 509584489fdb7..7c6b20416ba04 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -170,7 +170,7 @@ std::unique_ptr> lst::fillESDataHost(lstg ModuleMetaData mmd; unsigned int counter = 0; - for (auto const& [detId, centroid] : lstg.centroids) { + for (auto const& [detId, centroid] : lstg.sensor_centroids) { mmd.detIdToIndex[detId] = counter; mmd.module_x[detId] = centroid.x; mmd.module_y[detId] = centroid.y; diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc index 0754f18b12832..ce237e073d8d6 100644 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc @@ -49,7 +49,7 @@ int main(int argc, char** argv) { auto lstGeometry = makeGeometry(modules_info, sensors_info, average_r, average_z, ptCut); - writeCentroids(lstGeometry->centroids, output_dir + "sensor_centroids", output_as_bin); + writeCentroids(lstGeometry->sensor_centroids, output_dir + "sensor_centroids", output_as_bin); writeSlopes( lstGeometry->barrel_slopes, lstGeometry->sensor_info, output_dir + "tilted_barrel_orientation", output_as_bin); writeSlopes(lstGeometry->endcap_slopes, lstGeometry->sensor_info, output_dir + "endcap_orientation", output_as_bin); diff --git a/RecoTracker/LSTGeometry/interface/Centroid.h b/RecoTracker/LSTGeometry/interface/Centroid.h deleted file mode 100644 index ae2d8919bc74e..0000000000000 --- a/RecoTracker/LSTGeometry/interface/Centroid.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_Centroid_h -#define RecoTracker_LSTGeometry_interface_Centroid_h - -namespace lstgeometry { - - struct Centroid { - unsigned int moduleType; - double x; - double y; - double z; - }; - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index d2b534f9543c9..978e52ed21abd 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_LSTGeometry_interface_Geometry_h #define RecoTracker_LSTGeometry_interface_Geometry_h -#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" #include "RecoTracker/LSTGeometry/interface/SlopeData.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/SensorInfo.h" @@ -9,7 +9,7 @@ namespace lstgeometry { struct Geometry { - std::unordered_map centroids; + std::unordered_map sensor_centroids; std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; PixelMap pixel_map; diff --git a/RecoTracker/LSTGeometry/interface/GeometryMethods.h b/RecoTracker/LSTGeometry/interface/GeometryMethods.h index 2f2fa49342460..832e12fafaab6 100644 --- a/RecoTracker/LSTGeometry/interface/GeometryMethods.h +++ b/RecoTracker/LSTGeometry/interface/GeometryMethods.h @@ -3,7 +3,7 @@ #include "RecoTracker/LSTGeometry/interface/Geometry.h" #include "RecoTracker/LSTGeometry/interface/CornerMethods.h" -#include "RecoTracker/LSTGeometry/interface/CentroidMethods.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" #include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" @@ -12,10 +12,10 @@ namespace lstgeometry { std::unique_ptr makeGeometry(std::vector &modules_info, - std::unordered_map &sensors_info, - std::vector const &average_r, - std::vector const &average_z, - double ptCut) { + std::unordered_map &sensors_info, + std::vector const &average_r, + std::vector const &average_z, + double ptCut) { for (auto &mod : modules_info) transformSensorCorners(mod); @@ -48,11 +48,11 @@ namespace lstgeometry { auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); auto lstGeometry = std::make_unique(std::move(centroids), - std::move(barrel_slopes), - std::move(endcap_slopes), - std::move(pixel_map), - std::move(merged_line_connections), - std::move(sensors_info)); + std::move(barrel_slopes), + std::move(endcap_slopes), + std::move(pixel_map), + std::move(merged_line_connections), + std::move(sensors_info)); return lstGeometry; } diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 4f3ec886def74..050a5a8c3822a 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -131,7 +131,7 @@ namespace lstgeometry { return averages; } - void writeCentroids(std::unordered_map const& centroids, + void writeCentroids(std::unordered_map const& sensor_centroids, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); @@ -141,7 +141,7 @@ namespace lstgeometry { std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if (binary) { - for (auto& [detid, centroid] : centroids) { + for (auto& [detid, centroid] : sensor_centroids) { float x = centroid.x; float y = centroid.y; float z = centroid.z; @@ -153,7 +153,7 @@ namespace lstgeometry { file.write(reinterpret_cast(&moduleType), sizeof(moduleType)); } } else { - for (auto& [detid, centroid] : centroids) { + for (auto& [detid, centroid] : sensor_centroids) { file << detid << "," << centroid.x << "," << centroid.y << "," << centroid.z << "," << centroid.moduleType << std::endl; } diff --git a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h index 46dd86c82fa74..ce28dfdc8b040 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h @@ -13,16 +13,17 @@ #include #include "RecoTracker/LSTGeometry/interface/Math.h" -#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" namespace lstgeometry { - std::vector getStraightLineConnections(unsigned int ref_detid, - std::unordered_map const& centroids, - DetectorGeometry const& det_geom) { - auto centroid = centroids.at(ref_detid); + std::vector getStraightLineConnections( + unsigned int ref_detid, + std::unordered_map const& sensor_centroids, + DetectorGeometry const& det_geom) { + auto centroid = sensor_centroids.at(ref_detid); double refphi = std::atan2(centroid.y, centroid.x); @@ -83,7 +84,7 @@ namespace lstgeometry { det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { - auto centroid_target = centroids.at(tar_detid); + auto centroid_target = sensor_centroids.at(tar_detid); double tarphi = std::atan2(centroid_target.y, centroid_target.x); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) @@ -112,12 +113,12 @@ namespace lstgeometry { } MatrixD4x3 boundsAfterCurved(unsigned int ref_detid, - std::unordered_map const& centroids, + std::unordered_map const& sensor_centroids, DetectorGeometry const& det_geom, double ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); - auto centroid = centroids.at(ref_detid); + auto centroid = sensor_centroids.at(ref_detid); int charge = 1; double theta = std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); double refphi = std::atan2(centroid.y, centroid.x); @@ -186,11 +187,12 @@ namespace lstgeometry { return next_layer_bound_points; } - std::vector getCurvedLineConnections(unsigned int ref_detid, - std::unordered_map const& centroids, - DetectorGeometry const& det_geom, - double ptCut) { - auto centroid = centroids.at(ref_detid); + std::vector getCurvedLineConnections( + unsigned int ref_detid, + std::unordered_map const& sensor_centroids, + DetectorGeometry const& det_geom, + double ptCut) { + auto centroid = sensor_centroids.at(ref_detid); double refphi = std::atan2(centroid.y, centroid.x); @@ -206,7 +208,7 @@ namespace lstgeometry { ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); - auto next_layer_bound_points = boundsAfterCurved(ref_detid, centroids, det_geom, ptCut); + auto next_layer_bound_points = boundsAfterCurved(ref_detid, sensor_centroids, det_geom, ptCut); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -250,7 +252,7 @@ namespace lstgeometry { det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { - auto centroid_target = centroids.at(tar_detid); + auto centroid_target = sensor_centroids.at(tar_detid); double tarphi = std::atan2(centroid_target.y, centroid_target.x); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index a931a65a374e0..182739f3cd432 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -6,7 +6,7 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/CentroidMethods.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h" #include "RecoTracker/LSTGeometry/interface/SlopeData.h" namespace lstgeometry { diff --git a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h index c6601ec00fcf6..7bdc2e898e747 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h @@ -4,13 +4,13 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" namespace lstgeometry { - PixelMap computePixelMap(std::unordered_map const& centroids, + PixelMap computePixelMap(std::unordered_map const& sensor_centroids, DetectorGeometry const& det_geom, double ptCut) { // Charge 0 is the union of charge 1 and charge -1 @@ -29,7 +29,7 @@ namespace lstgeometry { // Loop over the detids and for each detid compute which superbins it is connected to for (auto detId : det_geom.getDetIds()) { - auto centroid = centroids.at(detId); + auto centroid = sensor_centroids.at(detId); // Parse the layer and subdet auto module = Module(detId, centroid.moduleType); diff --git a/RecoTracker/LSTGeometry/interface/SensorCentroid.h b/RecoTracker/LSTGeometry/interface/SensorCentroid.h new file mode 100644 index 0000000000000..3462df7652853 --- /dev/null +++ b/RecoTracker/LSTGeometry/interface/SensorCentroid.h @@ -0,0 +1,15 @@ +#ifndef RecoTracker_LSTGeometry_interface_SensorCentroid_h +#define RecoTracker_LSTGeometry_interface_SensorCentroid_h + +namespace lstgeometry { + + struct SensorCentroid { + unsigned int moduleType; + double x; + double y; + double z; + }; + +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTGeometry/interface/CentroidMethods.h b/RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h similarity index 85% rename from RecoTracker/LSTGeometry/interface/CentroidMethods.h rename to RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h index a17458762e235..196a2681b5553 100644 --- a/RecoTracker/LSTGeometry/interface/CentroidMethods.h +++ b/RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h @@ -1,12 +1,12 @@ -#ifndef RecoTracker_LSTGeometry_interface_CentroidMethods_h -#define RecoTracker_LSTGeometry_interface_CentroidMethods_h +#ifndef RecoTracker_LSTGeometry_interface_SensorCentroidMethods_h +#define RecoTracker_LSTGeometry_interface_SensorCentroidMethods_h #include #include #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/Module.h" -#include "RecoTracker/LSTGeometry/interface/Centroid.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" #include "RecoTracker/LSTGeometry/interface/SensorInfo.h" namespace lstgeometry { @@ -51,9 +51,9 @@ namespace lstgeometry { } } - std::unordered_map computeCentroids( + std::unordered_map computeCentroids( std::unordered_map const& sensors) { - std::unordered_map centroids; + std::unordered_map centroids; for (auto const& [detId, sensor] : sensors) { int moduleType = parseModuleType(detId); @@ -69,7 +69,7 @@ namespace lstgeometry { double x = rho * cos(phi); double y = rho * sin(phi); - Centroid centroid{static_cast(moduleType), x, y, z}; + SensorCentroid centroid{static_cast(moduleType), x, y, z}; centroids[detId] = centroid; } return centroids; diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index 63fc2af2cc535..df1100091c8e7 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -32,7 +32,7 @@ DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); - lstgeometry::writeCentroids(lstg.centroids, outputDirectory_ + "sensor_centroids", binaryOutput_); + lstgeometry::writeCentroids(lstg.sensor_centroids, outputDirectory_ + "sensor_centroids", binaryOutput_); lstgeometry::writeSlopes( lstg.barrel_slopes, lstg.sensor_info, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); lstgeometry::writeSlopes( @@ -41,7 +41,7 @@ void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& i lstgeometry::writeModuleConnections( lstg.merged_line_connections, outputDirectory_ + "module_connection_tracing_merged", binaryOutput_); - edm::LogInfo("DumpLSTGeometry") << "Centroids size: " << lstg.centroids.size() << std::endl; + edm::LogInfo("DumpLSTGeometry") << "Geometry data was successfully dumped." << std::endl; } DEFINE_FWK_MODULE(DumpLSTGeometry); From 413cb2931aed8ad122f76eaf23ca2189c5bf5ca9 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Feb 2026 19:56:16 +0000 Subject: [PATCH 64/95] Fixed python config --- RecoTracker/LST/python/lstProducerTask_cff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LST/python/lstProducerTask_cff.py b/RecoTracker/LST/python/lstProducerTask_cff.py index 2847f06178ba9..3de184640b97c 100644 --- a/RecoTracker/LST/python/lstProducerTask_cff.py +++ b/RecoTracker/LST/python/lstProducerTask_cff.py @@ -6,6 +6,6 @@ from RecoTracker.LST.lstInputProducer_cfi import lstInputProducer -from RecoTracker.LSTCore.lstGeometryESProducer_cfi import lstGeometryESProducer +from RecoTracker.LSTGeometry.lstGeometryESProducer_cfi import lstGeometryESProducer lstProducerTask = cms.Task(lstGeometryESProducer, lstModulesDevESProducer, lstInputProducer, lstProducer) From b3a405f654d5a43012b9f131e161e5b3f446cb50 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Feb 2026 20:11:40 +0000 Subject: [PATCH 65/95] Removed code for standalone generation from csv files --- RecoTracker/LSTCore/standalone/.gitignore | 1 - RecoTracker/LSTCore/standalone/Makefile | 18 +-- .../standalone/bin/lst_make_geometry.cc | 61 --------- RecoTracker/LSTCore/standalone/setup.sh | 1 - RecoTracker/LSTGeometry/interface/IO.h | 116 +----------------- RecoTracker/LSTGeometry/test/BuildFile.xml | 4 +- .../LSTGeometry/test/DumpLSTGeometry.cc | 2 +- 7 files changed, 9 insertions(+), 194 deletions(-) delete mode 100644 RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc diff --git a/RecoTracker/LSTCore/standalone/.gitignore b/RecoTracker/LSTCore/standalone/.gitignore index 5925b5aefc296..3d27afd0c4469 100644 --- a/RecoTracker/LSTCore/standalone/.gitignore +++ b/RecoTracker/LSTCore/standalone/.gitignore @@ -15,7 +15,6 @@ bin/lst bin/lst_cuda bin/lst_cpu bin/lst_rocm -bin/lst_make_geometry code/rooutil/librooutil.so code/rooutil/rooutil.so .gitversion.txt diff --git a/RecoTracker/LSTCore/standalone/Makefile b/RecoTracker/LSTCore/standalone/Makefile index 3aa498c6f1d6c..f06bf0bfffba4 100644 --- a/RecoTracker/LSTCore/standalone/Makefile +++ b/RecoTracker/LSTCore/standalone/Makefile @@ -1,7 +1,6 @@ # Simple makefile EXES := bin/lst_cpu bin/lst_cuda -GEOMETRY_EXES := bin/lst_make_geometry SOURCES=$(wildcard code/core/*.cc) OBJECTS_CPU=$(SOURCES:.cc=_cpu.o) @@ -11,7 +10,7 @@ OBJECTS=$(OBJECTS_CPU) $(OBJECTS_CUDA) $(OBJECTS_ROCM) CXX = g++ CXXFLAGS = -g -O2 -Wall -fPIC -Woverloaded-virtual -Wno-unused-function -fno-var-tracking -std=c++20 -INCLUDEFLAGS= -ILST -I$(shell pwd) -Icode -Icode/core -I${ALPAKA_ROOT}/include -I/${BOOST_ROOT}/include -I/${EIGEN_ROOT}/include/eigen3 $(shell rooutil-config --include) -I$(shell root-config --incdir) -I${TRACKLOOPERDIR}/../../../ -I${CMSSW_BASE}/src -I${FMT_ROOT}/include -I../interface/ -I../interface/alpaka/ -I../src/ -I../src/alpaka/ +INCLUDEFLAGS= -ILST -I$(shell pwd) -Icode -Icode/core -I${ALPAKA_ROOT}/include -I/${BOOST_ROOT}/include $(shell rooutil-config --include) -I$(shell root-config --incdir) -I${TRACKLOOPERDIR}/../../../ -I${CMSSW_BASE}/src -I${FMT_ROOT}/include -I../interface/ -I../interface/alpaka/ -I../src/ -I../src/alpaka/ ifdef CMSSW_RELEASE_BASE INCLUDEFLAGS:= ${INCLUDEFLAGS} -I${CMSSW_RELEASE_BASE}/src endif @@ -32,17 +31,17 @@ CUTVALUEFLAG_FLAGS = -DCUT_VALUE_DEBUG PRIMITIVEFLAG = PRIMITIVEFLAG_FLAGS = -DPRIMITIVE_STUDY -all: rooutil efficiency $(GEOMETRY_EXES) $(EXES) +all: rooutil efficiency $(EXES) cutvalue: CUTVALUEFLAG = ${CUTVALUEFLAG_FLAGS} -cutvalue: rooutil efficiency $(GEOMETRY_EXES) $(EXES) +cutvalue: rooutil efficiency $(EXES) primitive: PRIMITIVEFLAG = ${PRIMITIVEFLAG_FLAGS} -primitive: rooutil efficiency $(GEOMETRY_EXES) $(EXES) +primitive: rooutil efficiency $(EXES) cutvalue_primitive: CUTVALUEFLAG = ${CUTVALUEFLAG_FLAGS} cutvalue_primitive: PRIMITIVEFLAG = ${PRIMITIVEFLAG_FLAGS} -cutvalue_primitive: rooutil efficiency $(GEOMETRY_EXES) $(EXES) +cutvalue_primitive: rooutil efficiency $(EXES) bin/lst_cpu: LSTLIB=-llst_cpu @@ -62,11 +61,6 @@ bin/lst_rocm: bin/lst_rocm.o $(OBJECTS_ROCM) %_rocm.o: %.cc rooutil $(CXX) $(CXXFLAGS) $(EXTRAFLAGS) $(INCLUDEFLAGS) $(ALPAKAFLAGS) $(CUTVALUEFLAG) $(PRIMITIVEFLAG) $(DOQUINTUPLET) $(ALPAKA_ROCM) $(ROCMINCLUDE) $< -c -o $@ -bin/lst_make_geometry: bin/lst_make_geometry.o - $(CXX) $(LDFLAGS) $(EXTRAFLAGS) $(INCLUDEFLAGS) $(ALPAKAFLAGS) $^ -o $@ -%_geometry.o: %_geometry.cc - $(CXX) $(CXXFLAGS) $(INCLUDEFLAGS) $< -c -o $@ - rooutil: $(MAKE) -C code/rooutil/ @@ -74,7 +68,7 @@ efficiency: rooutil $(MAKE) -C efficiency/ clean: - rm -f $(OBJECTS) bin/*.o $(EXES) bin/lst $(GEOMETRY_EXES) + rm -f $(OBJECTS) bin/*.o $(EXES) bin/lst rm -f code/rooutil/*.so code/rooutil/*.o rm -f bin/lst.o rm -f LST/*.o diff --git a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc b/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc deleted file mode 100644 index ce237e073d8d6..0000000000000 --- a/RecoTracker/LSTCore/standalone/bin/lst_make_geometry.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#include "cxxopts.h" - -#include "RecoTracker/LSTGeometry/interface/IO.h" -#include "RecoTracker/LSTGeometry/interface/GeometryMethods.h" - -using namespace lstgeometry; - -int main(int argc, char** argv) { - cxxopts::Options options("\nLST Geometry\n\n"); - options.add_options()("module_info_file", - "The path to the csv file containing module information.", - cxxopts::value()->default_value("../data/module_info_OT800_IT711.csv"))( - "sensor_info_file", - "The path to the csv file containing sensor information.", - cxxopts::value()->default_value("../data/DetId_sensors_list_OT800_IT711.csv"))( - "average_r_file", - "The path to the text file containing the average r positions of the Barrel layers.", - cxxopts::value()->default_value("../data/average_r_OT800_IT711.txt"))( - "average_z_file", - "The path to the text file containing the average z positions of the Endcap layers.", - cxxopts::value()->default_value("../data/average_z_OT800_IT711.txt"))( - "output_dir", "The path to the output directory.", cxxopts::value()->default_value("../data/"))( - "output_as_binary", - "Boolean flag specifying whether to write outputs as binary or text files.", - cxxopts::value()->default_value("true"))( - "pt_cut", "pT cutoff value.", cxxopts::value()->default_value("0.8"))("h,help", "Print help"); - - auto result = options.parse(argc, argv); - - if (result.count("help")) { - std::cout << options.help() << std::endl; - exit(1); - } - - std::string module_info_file = result["module_info_file"].as(); - std::string sensor_info_file = result["sensor_info_file"].as(); - std::string average_r_file = result["average_r_file"].as(); - std::string average_z_file = result["average_z_file"].as(); - std::string output_dir = result["output_dir"].as(); - bool output_as_bin = result["output_as_binary"].as(); - double ptCut = result["pt_cut"].as(); - - auto modules_info = readModuleInfo(module_info_file); - auto sensors_info = readSensorInfo(sensor_info_file); - auto average_r = readAverages(average_r_file); - auto average_z = readAverages(average_z_file); - - auto lstGeometry = makeGeometry(modules_info, sensors_info, average_r, average_z, ptCut); - - writeCentroids(lstGeometry->sensor_centroids, output_dir + "sensor_centroids", output_as_bin); - writeSlopes( - lstGeometry->barrel_slopes, lstGeometry->sensor_info, output_dir + "tilted_barrel_orientation", output_as_bin); - writeSlopes(lstGeometry->endcap_slopes, lstGeometry->sensor_info, output_dir + "endcap_orientation", output_as_bin); - writePixelMaps(lstGeometry->pixel_map, output_dir + "pixelmap/pLS_map", output_as_bin); - writeModuleConnections( - lstGeometry->merged_line_connections, output_dir + "module_connection_tracing_merged", output_as_bin); - - return 0; -} diff --git a/RecoTracker/LSTCore/standalone/setup.sh b/RecoTracker/LSTCore/standalone/setup.sh index 8b89aeba001f8..f08180201192d 100644 --- a/RecoTracker/LSTCore/standalone/setup.sh +++ b/RecoTracker/LSTCore/standalone/setup.sh @@ -25,7 +25,6 @@ fi # Export paths to libraries we need export ALPAKA_ROOT=$(scram tool info alpaka | grep ALPAKA_BASE | cut -d'=' -f2) export BOOST_ROOT=$(scram tool info boost | grep BOOST_BASE | cut -d'=' -f2) -export EIGEN_ROOT=$(scram tool info eigen | grep EIGEN_BASE | cut -d'=' -f2) export CUDA_HOME=$(scram tool info cuda | grep CUDA_BASE | cut -d'=' -f2) export FMT_ROOT=$(scram tool info fmt | grep FMT_BASE | cut -d'=' -f2) export ROCM_ROOT=$(scram tool info rocm | grep ROCM_BASE | cut -d'=' -f2) diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 050a5a8c3822a..7c86de48db081 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -17,121 +17,7 @@ namespace lstgeometry { - std::string trim(std::string const& str) { - size_t first = str.find_first_not_of(" \t\r\n"); - if (first == std::string::npos) - return ""; - size_t last = str.find_last_not_of(" \t\r\n"); - return str.substr(first, (last - first + 1)); - } - - std::vector parseCSVLine(std::string const& line) { - std::vector tokens; - std::stringstream ss(line); - std::string token; - - while (std::getline(ss, token, ',')) { - tokens.push_back(trim(token)); - } - - return tokens; - } - - std::vector readModuleInfo(std::string const& filename) { - std::vector modules; - std::string line; - std::ifstream file(filename); - - if (!file.is_open()) { - throw std::runtime_error("Could not open file " + filename); - } - - // Skip header line - std::getline(file, line); - - while (std::getline(file, line)) { - if (line.empty()) - continue; - - std::vector tokens = parseCSVLine(line); - if (tokens.size() != 23) - continue; - - ModuleInfo m{static_cast(std::stoul(tokens[0])), - std::stod(tokens[5]) / 10.0, - std::stod(tokens[6]) / 10.0, - degToRad(std::stod(tokens[7])), - degToRad(std::stod(tokens[8])), - degToRad(std::stod(tokens[9])), - degToRad(std::stod(tokens[10])), - std::stod(tokens[19]) / 10.0, - std::stod(tokens[20]) / 10.0, - std::stod(tokens[21]) / 10.0, - MatrixD8x3::Zero()}; - - modules.push_back(m); - } - - return modules; - } - - std::unordered_map readSensorInfo(std::string const& filename) { - std::unordered_map sensors; - std::string line; - std::ifstream file(filename); - - if (!file.is_open()) { - throw std::runtime_error("Could not open file " + filename); - } - - // Skip header line - std::getline(file, line); - - while (std::getline(file, line)) { - if (line.empty()) - continue; - - std::vector tokens = parseCSVLine(line); - if (tokens.size() != 8) - continue; - - SensorInfo s{ - static_cast(std::stoul(tokens[0])), - std::stod(tokens[5]) / 10.0, - std::stod(tokens[6]) / 10.0, - degToRad(std::stod(tokens[7])), - }; - - sensors[s.detId] = s; - } - - return sensors; - } - - std::vector readAverages(std::string const& filename) { - std::vector averages; - std::string line; - std::ifstream file(filename); - - if (!file.is_open()) { - throw std::runtime_error("Could not open file " + filename); - } - - while (std::getline(file, line)) { - if (line.empty()) - continue; - - std::vector tokens = parseCSVLine(line); - if (tokens.size() != 1) - continue; - - averages.push_back(std::stod(tokens[0])); - } - - return averages; - } - - void writeCentroids(std::unordered_map const& sensor_centroids, + void writeSensorCentroids(std::unordered_map const& sensor_centroids, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); diff --git a/RecoTracker/LSTGeometry/test/BuildFile.xml b/RecoTracker/LSTGeometry/test/BuildFile.xml index 6728daccf7b88..9d8b669367f6f 100644 --- a/RecoTracker/LSTGeometry/test/BuildFile.xml +++ b/RecoTracker/LSTGeometry/test/BuildFile.xml @@ -4,6 +4,4 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index df1100091c8e7..f65afefcee2ea 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -32,7 +32,7 @@ DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); - lstgeometry::writeCentroids(lstg.sensor_centroids, outputDirectory_ + "sensor_centroids", binaryOutput_); + lstgeometry::writeSensorCentroids(lstg.sensor_centroids, outputDirectory_ + "sensor_centroids", binaryOutput_); lstgeometry::writeSlopes( lstg.barrel_slopes, lstg.sensor_info, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); lstgeometry::writeSlopes( From 91fc203e249fc94089e8f1fbe75a52637f3d192e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Feb 2026 15:22:36 -0500 Subject: [PATCH 66/95] Add newline back --- RecoTracker/LSTCore/test/BuildFile.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LSTCore/test/BuildFile.xml b/RecoTracker/LSTCore/test/BuildFile.xml index 6b090deadfb2b..eb1012b409f32 100644 --- a/RecoTracker/LSTCore/test/BuildFile.xml +++ b/RecoTracker/LSTCore/test/BuildFile.xml @@ -1 +1 @@ - \ No newline at end of file + From 154533b3c6ce87cb4095c4a1daf7788f38947eb9 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Feb 2026 20:34:41 +0000 Subject: [PATCH 67/95] Minor tweaks --- RecoTracker/LSTGeometry/interface/GeometryMethods.h | 1 + RecoTracker/LSTGeometry/interface/IO.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RecoTracker/LSTGeometry/interface/GeometryMethods.h b/RecoTracker/LSTGeometry/interface/GeometryMethods.h index 832e12fafaab6..6703fbc40f9dc 100644 --- a/RecoTracker/LSTGeometry/interface/GeometryMethods.h +++ b/RecoTracker/LSTGeometry/interface/GeometryMethods.h @@ -32,6 +32,7 @@ namespace lstgeometry { auto detids_etaphi_layer_ref = det_geom.getDetIds([](const auto &x) { auto mod = Module(x.first); + // exclude the outermost modules that do not have connections to other modules return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && !(mod.ring() == 15 && mod.layer() == 1) && !(mod.ring() == 15 && mod.layer() == 2) && !(mod.ring() == 12 && mod.layer() == 3) && diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 7c86de48db081..0054d7cdbf84c 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -18,8 +18,8 @@ namespace lstgeometry { void writeSensorCentroids(std::unordered_map const& sensor_centroids, - std::string const& base_filename, - bool binary = true) { + std::string const& base_filename, + bool binary = true) { std::filesystem::path filepath(base_filename); std::filesystem::create_directories(filepath.parent_path()); From ae28cf9e9fb7cf697c241d997f2044ea529e70d3 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 20 Feb 2026 09:38:07 -0500 Subject: [PATCH 68/95] Fixed test --- RecoTracker/LSTGeometry/test/BuildFile.xml | 2 +- RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoTracker/LSTGeometry/test/BuildFile.xml b/RecoTracker/LSTGeometry/test/BuildFile.xml index 9d8b669367f6f..8ce20e183e2f0 100644 --- a/RecoTracker/LSTGeometry/test/BuildFile.xml +++ b/RecoTracker/LSTGeometry/test/BuildFile.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index f65afefcee2ea..bf13b76998c34 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -27,7 +27,7 @@ DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) : ptCut_(config.getParameter("ptCut")), outputDirectory_(config.getUntrackedParameter("outputDirectory", "data/")), binaryOutput_(config.getUntrackedParameter("outputAsBinary", true)), - lstGeoToken_{esConsumes(edm::ESInputTag("", ptCut_))} {} + lstGeoToken_{esConsumes(edm::ESInputTag("", "LSTGeometry"))} {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); From 99ad8e1d7fa57e1214858a002279826c3a95dfbd Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 24 Feb 2026 14:36:03 +0000 Subject: [PATCH 69/95] Started removing Module.h --- RecoTracker/LSTGeometry/BuildFile.xml | 2 + .../LSTGeometry/interface/CornerMethods.h | 7 +-- .../LSTGeometry/interface/DetectorGeometry.h | 16 +++--- .../LSTGeometry/interface/GeometryMethods.h | 20 ++++---- .../LSTGeometry/interface/ModuleInfo.h | 11 ++++- .../LSTGeometry/interface/SensorInfo.h | 2 +- .../plugins/LSTGeometryESProducer.cc | 49 ++++++++++++------- 7 files changed, 67 insertions(+), 40 deletions(-) diff --git a/RecoTracker/LSTGeometry/BuildFile.xml b/RecoTracker/LSTGeometry/BuildFile.xml index 9e8dceec3362a..5b5d221c0d5a4 100644 --- a/RecoTracker/LSTGeometry/BuildFile.xml +++ b/RecoTracker/LSTGeometry/BuildFile.xml @@ -1,6 +1,8 @@ + + \ No newline at end of file diff --git a/RecoTracker/LSTGeometry/interface/CornerMethods.h b/RecoTracker/LSTGeometry/interface/CornerMethods.h index d7d6dd7996ce4..7bc973b112b7e 100644 --- a/RecoTracker/LSTGeometry/interface/CornerMethods.h +++ b/RecoTracker/LSTGeometry/interface/CornerMethods.h @@ -104,11 +104,12 @@ namespace lstgeometry { // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. std::unordered_map assignCornersToSensors( - std::vector const& modules, std::unordered_map const& sensors) { + std::unordered_map const& modules, + std::unordered_map const& sensors) { std::unordered_map transformed_corners_dict; - for (auto const& moduleInfo : modules) { - unsigned int module_det_id = moduleInfo.detId; + for (auto const& [detId, moduleInfo] : modules) { + unsigned int module_det_id = detId; unsigned int sensor_det_id_1 = module_det_id + 1; unsigned int sensor_det_id_2 = module_det_id + 2; diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index cf2a134c99c3a..2add0232c88b8 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -7,7 +7,6 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Math.h" namespace lstgeometry { @@ -109,7 +108,8 @@ namespace lstgeometry { return detIds; } - void buildByLayer() { + void buildByLayer(std::unordered_map const& modules_info, + std::unordered_map const& sensors_info) { // Clear just in case they were already built barrel_lower_det_ids_.clear(); endcap_lower_det_ids_.clear(); @@ -127,9 +127,9 @@ namespace lstgeometry { } for (unsigned int layer = 1; layer < 7; layer++) { - auto detids = getDetIds([&layer](const auto& x) { - Module m(x.first); - return m.subdet() == 5 && m.layer() == layer && m.isLower() == 1; + auto detids = getDetIds([&modules_info, &sensors_info, &layer](const auto& x) { + auto m = modules_info.at(sensors_info.at(x.first).moduleDetId); + return m.subdet == 5 && m.layer == layer && m.isLower; }); for (auto detid : detids) { auto corners = getCorners(detid); @@ -146,9 +146,9 @@ namespace lstgeometry { } } for (unsigned int layer = 1; layer < 6; layer++) { - auto detids = getDetIds([&layer](const auto& x) { - Module m(x.first); - return m.subdet() == 4 && m.layer() == layer && m.isLower() == 1; + auto detids = getDetIds([&modules_info, &sensors_info, &layer](const auto& x) { + auto m = modules_info.at(sensors_info.at(x.first).moduleDetId); + return m.subdet == 4 && m.layer == layer && m.isLower; }); for (auto detid : detids) { auto corners = getCorners(detid); diff --git a/RecoTracker/LSTGeometry/interface/GeometryMethods.h b/RecoTracker/LSTGeometry/interface/GeometryMethods.h index 6703fbc40f9dc..904ba2e5a99af 100644 --- a/RecoTracker/LSTGeometry/interface/GeometryMethods.h +++ b/RecoTracker/LSTGeometry/interface/GeometryMethods.h @@ -11,12 +11,12 @@ namespace lstgeometry { - std::unique_ptr makeGeometry(std::vector &modules_info, - std::unordered_map &sensors_info, + std::unique_ptr makeGeometry(std::unordered_map &modules_info, + std::unordered_map const &sensors_info, std::vector const &average_r, std::vector const &average_z, double ptCut) { - for (auto &mod : modules_info) + for (auto &[_, mod] : modules_info) transformSensorCorners(mod); auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); @@ -26,17 +26,17 @@ namespace lstgeometry { auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); - det_geom.buildByLayer(); + det_geom.buildByLayer(modules_info, sensors_info); auto pixel_map = computePixelMap(centroids, det_geom, ptCut); - auto detids_etaphi_layer_ref = det_geom.getDetIds([](const auto &x) { - auto mod = Module(x.first); + auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_info](const auto &x) { + auto mod = modules_info.at(sensors_info.at(x.first).moduleDetId); // exclude the outermost modules that do not have connections to other modules - return ((mod.subdet() == 5 && mod.isLower() == 1 && mod.layer() != 6) || - (mod.subdet() == 4 && mod.isLower() == 1 && mod.layer() != 5 && !(mod.ring() == 15 && mod.layer() == 1) && - !(mod.ring() == 15 && mod.layer() == 2) && !(mod.ring() == 12 && mod.layer() == 3) && - !(mod.ring() == 12 && mod.layer() == 4))); + return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || + (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && + !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && + !(mod.ring == 12 && mod.layer == 4))); }); std::unordered_map> straight_line_connections; diff --git a/RecoTracker/LSTGeometry/interface/ModuleInfo.h b/RecoTracker/LSTGeometry/interface/ModuleInfo.h index 0ae86ea15c58e..bd062a2a8580d 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleInfo.h +++ b/RecoTracker/LSTGeometry/interface/ModuleInfo.h @@ -1,12 +1,21 @@ #ifndef RecoTracker_LSTGeometry_interface_ModuleInfo_h #define RecoTracker_LSTGeometry_interface_ModuleInfo_h +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" +#include "DataFormats/SiStripDetId/interface/SiStripEnums.h" + #include "RecoTracker/LSTGeometry/interface/Common.h" namespace lstgeometry { struct ModuleInfo { - unsigned int detId; + TrackerGeometry::ModuleType moduleType; + GeomDetEnumerators::SubDetector subdet; + Phase2Tracker::BarrelModuleTilt side; + unsigned int layer; + unsigned int ring; + bool isLower; double sensorCenterRho_cm; double sensorCenterZ_cm; double tiltAngle_rad; diff --git a/RecoTracker/LSTGeometry/interface/SensorInfo.h b/RecoTracker/LSTGeometry/interface/SensorInfo.h index 7905044a4df6d..5f2c00d7eea53 100644 --- a/RecoTracker/LSTGeometry/interface/SensorInfo.h +++ b/RecoTracker/LSTGeometry/interface/SensorInfo.h @@ -6,7 +6,7 @@ namespace lstgeometry { struct SensorInfo { - unsigned int detId; + unsigned int moduleDetId; double sensorCenterRho_cm; double sensorCenterZ_cm; double phi_rad; diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index 4175a7203c875..f60732be81903 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -2,6 +2,8 @@ #include "FWCore/Framework/interface/ESProducer.h" #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/Records/interface/TrackerTopologyRcd.h" +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h" #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" @@ -27,14 +29,17 @@ class LSTGeometryESProducer : public edm::ESProducer { double ptCut_; edm::ESGetToken geomToken_; + edm::ESGetToken ttopoToken_; const TrackerGeometry *trackerGeom_ = nullptr; + const TrackerTopology *trackerTopo_ = nullptr; }; LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) : ptCut_(iConfig.getParameter("ptCut")) { auto cc = setWhatProduced(this, "LSTGeometry"); geomToken_ = cc.consumes(); + ttopoToken_ = cc.consumes(); } void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { @@ -45,8 +50,9 @@ void LSTGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions &des std::unique_ptr LSTGeometryESProducer::produce(const TrackerRecoGeometryRecord &iRecord) { trackerGeom_ = &iRecord.get(geomToken_); + trackerTopo_ = &iRecord.get(ttopoToken_); - std::vector modules; + std::unordered_map modules; std::unordered_map sensors; std::vector avg_r_cm(6, 0.0); @@ -56,6 +62,15 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac for (auto &det : trackerGeom_->dets()) { const DetId detId = det->geographicalId(); + const auto moduleType = trackerGeom_->getDetectorType(detId); + + // TODO: Is there a more straightforward way to only loop through these? + if (moduleType != TrackerGeometry::ModuleType::Ph2PSP && moduleType != TrackerGeometry::ModuleType::Ph2PSS && + moduleType != TrackerGeometry::ModuleType::Ph2SS) { + continue; + } + + const unsigned int detid = detId(); const auto &surface = det->surface(); const Bounds *b = &(surface).bounds(); @@ -67,8 +82,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac if (det->isLeaf()) { // Leafs are the sensors - lstgeometry::SensorInfo sensor{detId(), rho_cm, z_cm, phi_rad}; - sensors[detId()] = std::move(sensor); + const unsigned int moduleDetId = detid & ~0b11; // TODO: Is there a CMSSW method for this? + lstgeometry::SensorInfo sensor{moduleDetId, rho_cm, z_cm, phi_rad}; + sensors[detid] = std::move(sensor); continue; } @@ -77,6 +93,12 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; } + const auto subdet = static_cast(detId.subdetId()); + const auto side = static_cast(trackerTopo_->side(detId)); + const unsigned int layer = trackerTopo_->layer(detId); + const unsigned int ring = trackerTopo_->endcapRingP2(detId); + const bool isLower = trackerTopo_->isLower(detId); + double tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); double meanWidth_cm = b2->width(); @@ -84,18 +106,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac double sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag(); - unsigned int detid = detId(); - - unsigned short layer = lstgeometry::Module::parseLayer(detid); - - // This part is a little weird, but this is how to match the csv files. - // I think it might be better to not do this since other parts of the code - // assume the center of the module is at (rho_cm, z_cm). - // - // z_cm += sensorSpacing_cm / 2.0 * std::sin(tiltAngle_rad); - // bool isFlipped = surface.normalVector().basicVector().dot(position.basicVector()) < 0; - // rho_cm += (isFlipped ? -1 : 1) * signsensorSpacing_cm / 2.0 * std::cos(tiltAngle_rad); - // Fix angles of some modules if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { tiltAngle_rad = std::numbers::pi_v / 2; @@ -111,7 +121,12 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac avg_z_counter[layer - 1] += 1; } - lstgeometry::ModuleInfo module{detid, + lstgeometry::ModuleInfo module{moduleType, + subdet, + side, + layer, + ring, + isLower, rho_cm, z_cm, tiltAngle_rad, @@ -122,7 +137,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac length_cm, sensorSpacing_cm, lstgeometry::MatrixD8x3::Zero()}; - modules.push_back(module); + modules[detid] = std::move(module); } for (size_t i = 0; i < avg_r_cm.size(); ++i) { From b76a391351730fe050336ec8a822be374e92e8bc Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 24 Feb 2026 16:07:09 +0000 Subject: [PATCH 70/95] Started moving implementations to cc files --- RecoTracker/LSTGeometry/interface/Common.h | 36 ++--------- RecoTracker/LSTGeometry/interface/Geometry.h | 7 +++ .../LSTGeometry/interface/GeometryMethods.h | 63 ------------------- RecoTracker/LSTGeometry/plugins/BuildFile.xml | 1 + .../plugins/LSTGeometryESProducer.cc | 4 +- RecoTracker/LSTGeometry/src/Common.cc | 36 +++++++++++ RecoTracker/LSTGeometry/src/Geometry.cc | 53 +++++++++++++++- 7 files changed, 103 insertions(+), 97 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/GeometryMethods.h create mode 100644 RecoTracker/LSTGeometry/src/Common.cc diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index 0f46eed5e4b55..6b7a014615c2e 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -27,38 +27,12 @@ namespace lstgeometry { constexpr std::array kPtBounds = {{2.0, 10'000.0}}; // This is defined as a constant in case the legacy value (123456789) needs to be used - double kDefaultSlope = std::numeric_limits::infinity(); + constexpr double kDefaultSlope = std::numeric_limits::infinity(); - double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } - - double phi_mpi_pi(double phi) { - while (phi >= std::numbers::pi_v) - phi -= 2 * std::numbers::pi_v; - while (phi < -std::numbers::pi_v) - phi += 2 * std::numbers::pi_v; - return phi; - } - - double roundAngle(double angle, double tol = 1e-3) { - const double pi = std::numbers::pi_v; - if (std::fabs(angle) < tol) { - return 0.0; - } else if (std::fabs(angle - pi / 2) < tol) { - return pi / 2; - } else if (std::fabs(angle + pi / 2) < tol) { - return -pi / 2; - } else if (std::fabs(angle - pi) < tol || std::fabs(angle + pi) < tol) { - return -pi; - } - return angle; - } - - double roundCoordinate(double coord, double tol = 1e-3) { - if (std::fabs(coord) < tol) { - return 0.0; - } - return coord; - } + double degToRad(double degrees); + double phi_mpi_pi(double phi); + double roundAngle(double angle, double tol = 1e-3); + double roundCoordinate(double coord, double tol = 1e-3); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 978e52ed21abd..12aed8d9145b8 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -5,6 +5,7 @@ #include "RecoTracker/LSTGeometry/interface/SlopeData.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" namespace lstgeometry { @@ -15,6 +16,12 @@ namespace lstgeometry { PixelMap pixel_map; std::unordered_map> merged_line_connections; std::unordered_map sensor_info; + + Geometry(std::unordered_map &modules_info, + std::unordered_map &sensors_info, + std::vector const &average_r, + std::vector const &average_z, + double ptCut); }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/GeometryMethods.h b/RecoTracker/LSTGeometry/interface/GeometryMethods.h deleted file mode 100644 index 904ba2e5a99af..0000000000000 --- a/RecoTracker/LSTGeometry/interface/GeometryMethods.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_GeometryMethods_h -#define RecoTracker_LSTGeometry_interface_GeometryMethods_h - -#include "RecoTracker/LSTGeometry/interface/Geometry.h" -#include "RecoTracker/LSTGeometry/interface/CornerMethods.h" -#include "RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h" -#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" -#include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" -#include "RecoTracker/LSTGeometry/interface/ModuleMapMethods.h" - -namespace lstgeometry { - - std::unique_ptr makeGeometry(std::unordered_map &modules_info, - std::unordered_map const &sensors_info, - std::vector const &average_r, - std::vector const &average_z, - double ptCut) { - for (auto &[_, mod] : modules_info) - transformSensorCorners(mod); - - auto assigned_corners = assignCornersToSensors(modules_info, sensors_info); - - auto centroids = computeCentroids(sensors_info); - - auto [barrel_slopes, endcap_slopes] = processCorners(assigned_corners); - - auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); - det_geom.buildByLayer(modules_info, sensors_info); - - auto pixel_map = computePixelMap(centroids, det_geom, ptCut); - - auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_info](const auto &x) { - auto mod = modules_info.at(sensors_info.at(x.first).moduleDetId); - // exclude the outermost modules that do not have connections to other modules - return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || - (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && - !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && - !(mod.ring == 12 && mod.layer == 4))); - }); - - std::unordered_map> straight_line_connections; - std::unordered_map> curved_line_connections; - - for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, centroids, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, centroids, det_geom, ptCut); - } - auto merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); - - auto lstGeometry = std::make_unique(std::move(centroids), - std::move(barrel_slopes), - std::move(endcap_slopes), - std::move(pixel_map), - std::move(merged_line_connections), - std::move(sensors_info)); - - return lstGeometry; - } - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/plugins/BuildFile.xml b/RecoTracker/LSTGeometry/plugins/BuildFile.xml index 0b73a4fffed62..b6605e7f1930c 100644 --- a/RecoTracker/LSTGeometry/plugins/BuildFile.xml +++ b/RecoTracker/LSTGeometry/plugins/BuildFile.xml @@ -31,5 +31,6 @@ + \ No newline at end of file diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index f60732be81903..dc527a030ec04 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -11,7 +11,7 @@ #include "RecoTracker/LSTGeometry/interface/SensorInfo.h" #include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" #include "RecoTracker/LSTGeometry/interface/Module.h" -#include "RecoTracker/LSTGeometry/interface/GeometryMethods.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" #include #include @@ -147,7 +147,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac avg_z_cm[i] /= avg_z_counter[i]; } - auto lstGeometry = lstgeometry::makeGeometry(modules, sensors, avg_r_cm, avg_z_cm, ptCut_); + auto lstGeometry = std::make_unique(modules, sensors, avg_r_cm, avg_z_cm, ptCut_); return lstGeometry; } diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc new file mode 100644 index 0000000000000..a0b3359f901fa --- /dev/null +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -0,0 +1,36 @@ +#include "RecoTracker/LSTGeometry/interface/Common.h" + +namespace lstgeometry { + + double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } + + double phi_mpi_pi(double phi) { + while (phi >= std::numbers::pi_v) + phi -= 2 * std::numbers::pi_v; + while (phi < -std::numbers::pi_v) + phi += 2 * std::numbers::pi_v; + return phi; + } + + double roundAngle(double angle, double tol) { + const double pi = std::numbers::pi_v; + if (std::fabs(angle) < tol) { + return 0.0; + } else if (std::fabs(angle - pi / 2) < tol) { + return pi / 2; + } else if (std::fabs(angle + pi / 2) < tol) { + return -pi / 2; + } else if (std::fabs(angle - pi) < tol || std::fabs(angle + pi) < tol) { + return -pi; + } + return angle; + } + + double roundCoordinate(double coord, double tol) { + if (std::fabs(coord) < tol) { + return 0.0; + } + return coord; + } + +} // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 5780012381ed2..814cdfe96d5f3 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -1,3 +1,54 @@ #include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include "RecoTracker/LSTGeometry/interface/CornerMethods.h" +#include "RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h" +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" +#include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" +#include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" +#include "RecoTracker/LSTGeometry/interface/ModuleMapMethods.h" + +using namespace lstgeometry; + +Geometry::Geometry(std::unordered_map &modules_info, + std::unordered_map &sensors_info_in, + std::vector const &average_r, + std::vector const &average_z, + double ptCut) { + for (auto &[_, mod] : modules_info) + transformSensorCorners(mod); + + auto assigned_corners = assignCornersToSensors(modules_info, sensors_info_in); + + sensor_centroids = computeCentroids(sensors_info_in); + + auto slopes = processCorners(assigned_corners); + barrel_slopes = std::move(std::get<0>(slopes)); + endcap_slopes = std::move(std::get<1>(slopes)); + + auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); + det_geom.buildByLayer(modules_info, sensors_info_in); + + pixel_map = computePixelMap(sensor_centroids, det_geom, ptCut); + + auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_info_in](const auto &x) { + auto mod = modules_info.at(sensors_info_in.at(x.first).moduleDetId); + // exclude the outermost modules that do not have connections to other modules + return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || + (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && + !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && + !(mod.ring == 12 && mod.layer == 4))); + }); + + std::unordered_map> straight_line_connections; + std::unordered_map> curved_line_connections; + + for (auto ref_detid : detids_etaphi_layer_ref) { + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, sensor_centroids, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, sensor_centroids, det_geom, ptCut); + } + merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); + + sensor_info = sensors_info_in; +} + #include "FWCore/Utilities/interface/typelookup.h" -TYPELOOKUP_DATA_REG(lstgeometry::Geometry); +TYPELOOKUP_DATA_REG(Geometry); From 1b48eb38685ae72a1ea1e85e72b96b1f2f329c37 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 24 Feb 2026 19:10:23 +0000 Subject: [PATCH 71/95] Refactored Sensor --- .../LSTCore/interface/EndcapGeometry.h | 2 +- RecoTracker/LSTCore/src/EndcapGeometry.cc | 4 +- RecoTracker/LSTCore/src/LSTESData.cc | 12 +-- .../LSTGeometry/interface/CornerMethods.h | 16 ++-- .../LSTGeometry/interface/DetectorGeometry.h | 10 +-- RecoTracker/LSTGeometry/interface/Geometry.h | 8 +- RecoTracker/LSTGeometry/interface/IO.h | 26 +++--- .../LSTGeometry/interface/ModuleMapMethods.h | 49 ++++++------ .../interface/OrientationMethods.h | 5 +- .../LSTGeometry/interface/PixelMapMethods.h | 9 +-- RecoTracker/LSTGeometry/interface/Sensor.h | 27 +++++++ .../LSTGeometry/interface/SensorCentroid.h | 15 ---- .../interface/SensorCentroidMethods.h | 80 ------------------- .../LSTGeometry/interface/SensorInfo.h | 16 ---- .../plugins/LSTGeometryESProducer.cc | 9 +-- RecoTracker/LSTGeometry/src/Geometry.cc | 21 +++-- RecoTracker/LSTGeometry/src/Sensor.cc | 18 +++++ .../LSTGeometry/test/DumpLSTGeometry.cc | 7 +- 18 files changed, 127 insertions(+), 207 deletions(-) create mode 100644 RecoTracker/LSTGeometry/interface/Sensor.h delete mode 100644 RecoTracker/LSTGeometry/interface/SensorCentroid.h delete mode 100644 RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h delete mode 100644 RecoTracker/LSTGeometry/interface/SensorInfo.h create mode 100644 RecoTracker/LSTGeometry/src/Sensor.cc diff --git a/RecoTracker/LSTCore/interface/EndcapGeometry.h b/RecoTracker/LSTCore/interface/EndcapGeometry.h index e2727c29ba7e3..27ebc8109457f 100644 --- a/RecoTracker/LSTCore/interface/EndcapGeometry.h +++ b/RecoTracker/LSTCore/interface/EndcapGeometry.h @@ -24,7 +24,7 @@ namespace lst { void load(std::string const&); void load(std::unordered_map const&, - std::unordered_map const&); + std::unordered_map const&); void fillGeoMapArraysExplicit(); float getdxdy_slope(unsigned int detid) const; }; diff --git a/RecoTracker/LSTCore/src/EndcapGeometry.cc b/RecoTracker/LSTCore/src/EndcapGeometry.cc index 549c8f501e859..4e3f2630984d6 100644 --- a/RecoTracker/LSTCore/src/EndcapGeometry.cc +++ b/RecoTracker/LSTCore/src/EndcapGeometry.cc @@ -40,13 +40,13 @@ void lst::EndcapGeometry::load(std::string const& filename) { } void lst::EndcapGeometry::load(std::unordered_map const& slopes, - std::unordered_map const& sensors) { + std::unordered_map const& sensors) { dxdy_slope_.clear(); centroid_phis_.clear(); for (const auto& [detId, slopeData] : slopes) { dxdy_slope_[detId] = slopeData.dxdy_slope; - centroid_phis_[detId] = sensors.at(detId).phi_rad; + centroid_phis_[detId] = sensors.at(detId).centerPhi_rad; } fillGeoMapArraysExplicit(); diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 7c6b20416ba04..8cbab925618d7 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -132,7 +132,7 @@ std::unique_ptr> lst::fillESDataHost(lstg PixelMap pixelMapping; ModuleConnectionMap moduleConnectionMap; - endcapGeometry.load(lstg.endcap_slopes, lstg.sensor_info); + endcapGeometry.load(lstg.endcap_slopes, lstg.sensors); auto endcapGeometryDev = std::make_shared(cms::alpakatools::host(), endcapGeometry.nEndCapMap); std::memcpy(endcapGeometryDev->view().geoMapDetId().data(), @@ -170,12 +170,12 @@ std::unique_ptr> lst::fillESDataHost(lstg ModuleMetaData mmd; unsigned int counter = 0; - for (auto const& [detId, centroid] : lstg.sensor_centroids) { + for (auto const& [detId, sensor] : lstg.sensors) { mmd.detIdToIndex[detId] = counter; - mmd.module_x[detId] = centroid.x; - mmd.module_y[detId] = centroid.y; - mmd.module_z[detId] = centroid.z; - mmd.module_type[detId] = centroid.moduleType; + mmd.module_x[detId] = sensor.centerX_cm; + mmd.module_y[detId] = sensor.centerY_cm; + mmd.module_z[detId] = sensor.centerZ_cm; + mmd.module_type[detId] = static_cast(sensor.moduleType); counter++; } mmd.detIdToIndex[1] = counter; //pixel module is the last module in the module list diff --git a/RecoTracker/LSTGeometry/interface/CornerMethods.h b/RecoTracker/LSTGeometry/interface/CornerMethods.h index 7bc973b112b7e..d9cebe26594ea 100644 --- a/RecoTracker/LSTGeometry/interface/CornerMethods.h +++ b/RecoTracker/LSTGeometry/interface/CornerMethods.h @@ -7,7 +7,7 @@ #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" -#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { @@ -105,7 +105,7 @@ namespace lstgeometry { // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. std::unordered_map assignCornersToSensors( std::unordered_map const& modules, - std::unordered_map const& sensors) { + std::unordered_map const& sensors) { std::unordered_map transformed_corners_dict; for (auto const& [detId, moduleInfo] : modules) { @@ -117,16 +117,16 @@ namespace lstgeometry { RowVectorD3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); RowVectorD3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); - double sensor1_center_z = sensors.at(sensor_det_id_1).sensorCenterZ_cm; + double sensor1_center_z = sensors.at(sensor_det_id_1).centerZ_cm; double sensor1_center_x = - sensors.at(sensor_det_id_1).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_1).phi_rad); + sensors.at(sensor_det_id_1).centerRho_cm * cos(sensors.at(sensor_det_id_1).centerPhi_rad); double sensor1_center_y = - sensors.at(sensor_det_id_1).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_1).phi_rad); - double sensor2_center_z = sensors.at(sensor_det_id_2).sensorCenterZ_cm; + sensors.at(sensor_det_id_1).centerRho_cm * sin(sensors.at(sensor_det_id_1).centerPhi_rad); + double sensor2_center_z = sensors.at(sensor_det_id_2).centerZ_cm; double sensor2_center_x = - sensors.at(sensor_det_id_2).sensorCenterRho_cm * cos(sensors.at(sensor_det_id_2).phi_rad); + sensors.at(sensor_det_id_2).centerRho_cm * cos(sensors.at(sensor_det_id_2).centerPhi_rad); double sensor2_center_y = - sensors.at(sensor_det_id_2).sensorCenterRho_cm * sin(sensors.at(sensor_det_id_2).phi_rad); + sensors.at(sensor_det_id_2).centerRho_cm * sin(sensors.at(sensor_det_id_2).centerPhi_rad); RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index 2add0232c88b8..05f50bdaa0199 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -109,7 +109,7 @@ namespace lstgeometry { } void buildByLayer(std::unordered_map const& modules_info, - std::unordered_map const& sensors_info) { + std::unordered_map const& sensors) { // Clear just in case they were already built barrel_lower_det_ids_.clear(); endcap_lower_det_ids_.clear(); @@ -127,8 +127,8 @@ namespace lstgeometry { } for (unsigned int layer = 1; layer < 7; layer++) { - auto detids = getDetIds([&modules_info, &sensors_info, &layer](const auto& x) { - auto m = modules_info.at(sensors_info.at(x.first).moduleDetId); + auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { + auto& m = modules_info.at(sensors.at(x.first).moduleDetId); return m.subdet == 5 && m.layer == layer && m.isLower; }); for (auto detid : detids) { @@ -146,8 +146,8 @@ namespace lstgeometry { } } for (unsigned int layer = 1; layer < 6; layer++) { - auto detids = getDetIds([&modules_info, &sensors_info, &layer](const auto& x) { - auto m = modules_info.at(sensors_info.at(x.first).moduleDetId); + auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { + auto& m = modules_info.at(sensors.at(x.first).moduleDetId); return m.subdet == 4 && m.layer == layer && m.isLower; }); for (auto detid : detids) { diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 12aed8d9145b8..8f5ab36132d3e 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -1,24 +1,22 @@ #ifndef RecoTracker_LSTGeometry_interface_Geometry_h #define RecoTracker_LSTGeometry_interface_Geometry_h -#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" #include "RecoTracker/LSTGeometry/interface/SlopeData.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" -#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" namespace lstgeometry { struct Geometry { - std::unordered_map sensor_centroids; + std::unordered_map sensors; std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; PixelMap pixel_map; std::unordered_map> merged_line_connections; - std::unordered_map sensor_info; Geometry(std::unordered_map &modules_info, - std::unordered_map &sensors_info, + std::unordered_map &sensors_input, std::vector const &average_r, std::vector const &average_z, double ptCut); diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 0054d7cdbf84c..2e9a9b9485153 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -11,13 +11,13 @@ #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" -#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" namespace lstgeometry { - void writeSensorCentroids(std::unordered_map const& sensor_centroids, + void writeSensorCentroids(std::unordered_map const& sensors, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); @@ -27,11 +27,11 @@ namespace lstgeometry { std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if (binary) { - for (auto& [detid, centroid] : sensor_centroids) { - float x = centroid.x; - float y = centroid.y; - float z = centroid.z; - unsigned int moduleType = centroid.moduleType; + for (auto& [detid, sensor] : sensors) { + float x = sensor.centerX_cm; + float y = sensor.centerY_cm; + float z = sensor.centerZ_cm; + unsigned int moduleType = static_cast(sensor.moduleType); file.write(reinterpret_cast(&detid), sizeof(detid)); file.write(reinterpret_cast(&x), sizeof(x)); file.write(reinterpret_cast(&y), sizeof(y)); @@ -39,15 +39,15 @@ namespace lstgeometry { file.write(reinterpret_cast(&moduleType), sizeof(moduleType)); } } else { - for (auto& [detid, centroid] : sensor_centroids) { - file << detid << "," << centroid.x << "," << centroid.y << "," << centroid.z << "," << centroid.moduleType - << std::endl; + for (auto& [detid, sensor] : sensors) { + file << detid << "," << sensor.centerX_cm << "," << sensor.centerY_cm << "," << sensor.centerZ_cm << "," + << static_cast(sensor.moduleType) << std::endl; } } } void writeSlopes(std::unordered_map const& slopes, - std::unordered_map const& sensors, + std::unordered_map const& sensors, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); @@ -60,7 +60,7 @@ namespace lstgeometry { for (auto& [detid, slope] : slopes) { float drdz_slope = slope.drdz_slope; float dxdy_slope = slope.dxdy_slope; - float phi = sensors.at(detid).phi_rad; + float phi = sensors.at(detid).centerPhi_rad; file.write(reinterpret_cast(&detid), sizeof(detid)); if (drdz_slope != kDefaultSlope) { file.write(reinterpret_cast(&drdz_slope), sizeof(drdz_slope)); @@ -74,7 +74,7 @@ namespace lstgeometry { for (auto& [detid, slope] : slopes) { float drdz_slope = slope.drdz_slope; float dxdy_slope = slope.dxdy_slope; - float phi = sensors.at(detid).phi_rad; + float phi = sensors.at(detid).centerPhi_rad; file << detid << ","; if (drdz_slope != kDefaultSlope) { file << drdz_slope << "," << dxdy_slope << std::endl; diff --git a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h index ce28dfdc8b040..8d85df2435929 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h @@ -13,26 +13,25 @@ #include #include "RecoTracker/LSTGeometry/interface/Math.h" -#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" namespace lstgeometry { - std::vector getStraightLineConnections( - unsigned int ref_detid, - std::unordered_map const& sensor_centroids, - DetectorGeometry const& det_geom) { - auto centroid = sensor_centroids.at(ref_detid); + std::vector getStraightLineConnections(unsigned int ref_detid, + std::unordered_map const& sensors, + DetectorGeometry const& det_geom) { + auto& sensor = sensors.at(ref_detid); - double refphi = std::atan2(centroid.y, centroid.x); + double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); Module refmodule(ref_detid); unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); - auto etaphi = getEtaPhi(centroid.x, centroid.y, centroid.z); + auto etaphi = getEtaPhi(sensor.centerX_cm, sensor.centerY_cm, sensor.centerZ_cm); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = @@ -84,8 +83,8 @@ namespace lstgeometry { det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { - auto centroid_target = sensor_centroids.at(tar_detid); - double tarphi = std::atan2(centroid_target.y, centroid_target.x); + auto& sensor_target = sensors.at(tar_detid); + double tarphi = std::atan2(sensor_target.centerY_cm, sensor_target.centerX_cm); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) continue; @@ -113,15 +112,16 @@ namespace lstgeometry { } MatrixD4x3 boundsAfterCurved(unsigned int ref_detid, - std::unordered_map const& sensor_centroids, + std::unordered_map const& sensors, DetectorGeometry const& det_geom, double ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); - auto centroid = sensor_centroids.at(ref_detid); + auto& sensor = sensors.at(ref_detid); int charge = 1; - double theta = std::atan2(std::sqrt(centroid.x * centroid.x + centroid.y * centroid.y), centroid.z); - double refphi = std::atan2(centroid.y, centroid.x); + double theta = std::atan2(std::sqrt(sensor.centerX_cm * sensor.centerX_cm + sensor.centerY_cm * sensor.centerY_cm), + sensor.centerZ_cm); + double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); Module refmodule(ref_detid); unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); @@ -187,28 +187,27 @@ namespace lstgeometry { return next_layer_bound_points; } - std::vector getCurvedLineConnections( - unsigned int ref_detid, - std::unordered_map const& sensor_centroids, - DetectorGeometry const& det_geom, - double ptCut) { - auto centroid = sensor_centroids.at(ref_detid); + std::vector getCurvedLineConnections(unsigned int ref_detid, + std::unordered_map const& sensors, + DetectorGeometry const& det_geom, + double ptCut) { + auto& sensor = sensors.at(ref_detid); - double refphi = std::atan2(centroid.y, centroid.x); + double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); Module refmodule(ref_detid); unsigned short ref_layer = refmodule.layer(); unsigned short ref_subdet = refmodule.subdet(); - auto etaphi = getEtaPhi(centroid.x, centroid.y, centroid.z); + auto etaphi = getEtaPhi(sensor.centerX_cm, sensor.centerY_cm, sensor.centerZ_cm); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); - auto next_layer_bound_points = boundsAfterCurved(ref_detid, sensor_centroids, det_geom, ptCut); + auto next_layer_bound_points = boundsAfterCurved(ref_detid, sensors, det_geom, ptCut); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -252,8 +251,8 @@ namespace lstgeometry { det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { - auto centroid_target = sensor_centroids.at(tar_detid); - double tarphi = std::atan2(centroid_target.y, centroid_target.x); + auto& sensor_target = sensors.at(tar_detid); + double tarphi = std::atan2(sensor_target.centerY_cm, sensor_target.centerX_cm); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) continue; diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index 182739f3cd432..d1d6ae1d3ef26 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -6,7 +6,7 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/SlopeData.h" namespace lstgeometry { @@ -32,8 +32,7 @@ namespace lstgeometry { SlopeData slope = calculateSlope(dx, dy, dz); - unsigned int module_type = static_cast(parseModuleType(detId)); - Module module(detId, module_type); + Module module(detId); unsigned short subdet = module.subdet(); bool is_tilted = module.side() != 3; diff --git a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h index 7bdc2e898e747..51affbbf98c93 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h @@ -4,15 +4,12 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" namespace lstgeometry { - PixelMap computePixelMap(std::unordered_map const& sensor_centroids, - DetectorGeometry const& det_geom, - double ptCut) { + PixelMap computePixelMap(DetectorGeometry const& det_geom, double ptCut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; @@ -29,10 +26,8 @@ namespace lstgeometry { // Loop over the detids and for each detid compute which superbins it is connected to for (auto detId : det_geom.getDetIds()) { - auto centroid = sensor_centroids.at(detId); - // Parse the layer and subdet - auto module = Module(detId, centroid.moduleType); + auto module = Module(detId); auto layer = module.layer(); if (layer > 2) continue; diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h new file mode 100644 index 0000000000000..1bd300b6c905d --- /dev/null +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -0,0 +1,27 @@ +#ifndef RecoTracker_LSTGeometry_interface_Sensor_h +#define RecoTracker_LSTGeometry_interface_Sensor_h + +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" + +namespace lstgeometry { + + struct Sensor { + unsigned int moduleDetId; + float centerRho_cm; + float centerZ_cm; + float centerPhi_rad; + // Redundant, but convenient to have them + TrackerGeometry::ModuleType moduleType; + float centerX_cm; + float centerY_cm; + + Sensor() = default; + Sensor(unsigned int moduleDetId, + float centerRho_cm, + float centerZ_cm, + float centerPhi_rad, + TrackerGeometry::ModuleType moduleType); + }; +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTGeometry/interface/SensorCentroid.h b/RecoTracker/LSTGeometry/interface/SensorCentroid.h deleted file mode 100644 index 3462df7652853..0000000000000 --- a/RecoTracker/LSTGeometry/interface/SensorCentroid.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_SensorCentroid_h -#define RecoTracker_LSTGeometry_interface_SensorCentroid_h - -namespace lstgeometry { - - struct SensorCentroid { - unsigned int moduleType; - double x; - double y; - double z; - }; - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h b/RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h deleted file mode 100644 index 196a2681b5553..0000000000000 --- a/RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_SensorCentroidMethods_h -#define RecoTracker_LSTGeometry_interface_SensorCentroidMethods_h - -#include -#include - -#include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" -#include "RecoTracker/LSTGeometry/interface/SensorCentroid.h" -#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" - -namespace lstgeometry { - - unsigned int extractBits(unsigned int value, unsigned int start, unsigned int end) { - unsigned int mask = (1 << (end - start + 1)) - 1; - return (value >> start) & mask; - } - - unsigned int firstDigit(unsigned int n) { - while (n >= 10) { - n /= 10; - } - return n; - } - - // TODO: refactor to use Module class better - int parseModuleType(unsigned int detId) { - // Check if the first digit of detId is '3' for inner tracker - if (firstDigit(detId) == 3) - return -1; - - unsigned int subdet = extractBits(detId, 25, 27); - unsigned int layer = subdet == Module::SubDet::Barrel ? extractBits(detId, 20, 22) : extractBits(detId, 18, 20); - unsigned int ring = subdet == Module::SubDet::Endcap ? extractBits(detId, 12, 15) : 0; - - bool is_even_det_id = detId % 2 == 0; - if (subdet == Module::SubDet::Barrel) { - if (layer <= 3) - return is_even_det_id ? Module::ModuleType::PSS : Module::ModuleType::PSP; - else - return Module::ModuleType::TwoS; - } else if (subdet == Module::SubDet::Endcap) { - if (layer <= 2) - return is_even_det_id && ring <= 10 ? Module::ModuleType::PSS - : (ring <= 10 ? Module::ModuleType::PSP : Module::ModuleType::TwoS); - else - return is_even_det_id && ring <= 7 ? Module::ModuleType::PSS - : (ring <= 7 ? Module::ModuleType::PSP : Module::ModuleType::TwoS); - } else { - throw std::runtime_error("Invalid subdetector type"); - } - } - - std::unordered_map computeCentroids( - std::unordered_map const& sensors) { - std::unordered_map centroids; - for (auto const& [detId, sensor] : sensors) { - int moduleType = parseModuleType(detId); - - // Remove sensors from inner tracker - if (moduleType == -1) { - continue; - } - - // Convert from mm to cm - double z = sensor.sensorCenterZ_cm; - double rho = sensor.sensorCenterRho_cm; - double phi = sensor.phi_rad; - double x = rho * cos(phi); - double y = rho * sin(phi); - - SensorCentroid centroid{static_cast(moduleType), x, y, z}; - centroids[detId] = centroid; - } - return centroids; - } - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/SensorInfo.h b/RecoTracker/LSTGeometry/interface/SensorInfo.h deleted file mode 100644 index 5f2c00d7eea53..0000000000000 --- a/RecoTracker/LSTGeometry/interface/SensorInfo.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_SensorInfo_h -#define RecoTracker_LSTGeometry_interface_SensorInfo_h - -#include - -namespace lstgeometry { - - struct SensorInfo { - unsigned int moduleDetId; - double sensorCenterRho_cm; - double sensorCenterZ_cm; - double phi_rad; - }; -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index dc527a030ec04..414e9f831bcc2 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -8,7 +8,7 @@ #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" -#include "RecoTracker/LSTGeometry/interface/SensorInfo.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Geometry.h" @@ -53,7 +53,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac trackerTopo_ = &iRecord.get(ttopoToken_); std::unordered_map modules; - std::unordered_map sensors; + std::unordered_map sensors; std::vector avg_r_cm(6, 0.0); std::vector avg_z_cm(5, 0.0); @@ -67,7 +67,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac // TODO: Is there a more straightforward way to only loop through these? if (moduleType != TrackerGeometry::ModuleType::Ph2PSP && moduleType != TrackerGeometry::ModuleType::Ph2PSS && moduleType != TrackerGeometry::ModuleType::Ph2SS) { - continue; + //continue; } const unsigned int detid = detId(); @@ -83,8 +83,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac if (det->isLeaf()) { // Leafs are the sensors const unsigned int moduleDetId = detid & ~0b11; // TODO: Is there a CMSSW method for this? - lstgeometry::SensorInfo sensor{moduleDetId, rho_cm, z_cm, phi_rad}; - sensors[detid] = std::move(sensor); + sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, moduleType); continue; } diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 814cdfe96d5f3..edb07f0c9c6f8 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -1,6 +1,5 @@ #include "RecoTracker/LSTGeometry/interface/Geometry.h" #include "RecoTracker/LSTGeometry/interface/CornerMethods.h" -#include "RecoTracker/LSTGeometry/interface/SensorCentroidMethods.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" #include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" @@ -9,28 +8,26 @@ using namespace lstgeometry; Geometry::Geometry(std::unordered_map &modules_info, - std::unordered_map &sensors_info_in, + std::unordered_map &sensors_input, std::vector const &average_r, std::vector const &average_z, double ptCut) { for (auto &[_, mod] : modules_info) transformSensorCorners(mod); - auto assigned_corners = assignCornersToSensors(modules_info, sensors_info_in); - - sensor_centroids = computeCentroids(sensors_info_in); + auto assigned_corners = assignCornersToSensors(modules_info, sensors_input); auto slopes = processCorners(assigned_corners); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); - det_geom.buildByLayer(modules_info, sensors_info_in); + det_geom.buildByLayer(modules_info, sensors_input); - pixel_map = computePixelMap(sensor_centroids, det_geom, ptCut); + pixel_map = computePixelMap(det_geom, ptCut); - auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_info_in](const auto &x) { - auto mod = modules_info.at(sensors_info_in.at(x.first).moduleDetId); + auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_input](const auto &x) { + auto mod = modules_info.at(sensors_input.at(x.first).moduleDetId); // exclude the outermost modules that do not have connections to other modules return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && @@ -42,12 +39,12 @@ Geometry::Geometry(std::unordered_map &modules_info, std::unordered_map> curved_line_connections; for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, sensor_centroids, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, sensor_centroids, det_geom, ptCut); + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, sensors_input, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, sensors_input, det_geom, ptCut); } merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); - sensor_info = sensors_info_in; + sensors = sensors_input; } #include "FWCore/Utilities/interface/typelookup.h" diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc new file mode 100644 index 0000000000000..d0ad3889623e7 --- /dev/null +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -0,0 +1,18 @@ +#include + +#include "RecoTracker/LSTGeometry/interface/Sensor.h" + +using namespace lstgeometry; + +Sensor::Sensor(unsigned int moduleDetId, + float centerRho_cm, + float centerZ_cm, + float centerPhi_rad, + TrackerGeometry::ModuleType moduleType) + : moduleDetId(moduleDetId), + centerRho_cm(centerRho_cm), + centerZ_cm(centerZ_cm), + centerPhi_rad(centerPhi_rad), + moduleType(moduleType), + centerX_cm(centerRho_cm * std::cos(centerPhi_rad)), + centerY_cm(centerRho_cm * std::sin(centerPhi_rad)) {} diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index bf13b76998c34..0f5fbbe524178 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -32,11 +32,10 @@ DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); - lstgeometry::writeSensorCentroids(lstg.sensor_centroids, outputDirectory_ + "sensor_centroids", binaryOutput_); + lstgeometry::writeSensorCentroids(lstg.sensors, outputDirectory_ + "sensor_centroids", binaryOutput_); lstgeometry::writeSlopes( - lstg.barrel_slopes, lstg.sensor_info, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); - lstgeometry::writeSlopes( - lstg.endcap_slopes, lstg.sensor_info, outputDirectory_ + "endcap_orientation", binaryOutput_); + lstg.barrel_slopes, lstg.sensors, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); + lstgeometry::writeSlopes(lstg.endcap_slopes, lstg.sensors, outputDirectory_ + "endcap_orientation", binaryOutput_); lstgeometry::writePixelMaps(lstg.pixel_map, outputDirectory_ + "pixelmap/pLS_map", binaryOutput_); lstgeometry::writeModuleConnections( lstg.merged_line_connections, outputDirectory_ + "module_connection_tracing_merged", binaryOutput_); From 5b61e02d8a57fdffc7443d0945a14e8c7f96bc5e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 24 Feb 2026 21:23:07 +0000 Subject: [PATCH 72/95] Removed Module.h --- .../LSTGeometry/interface/CornerMethods.h | 17 +- .../LSTGeometry/interface/DetectorGeometry.h | 24 +- RecoTracker/LSTGeometry/interface/Module.h | 475 ------------------ .../LSTGeometry/interface/ModuleInfo.h | 1 + .../LSTGeometry/interface/ModuleMapMethods.h | 25 +- .../interface/OrientationMethods.h | 28 +- .../LSTGeometry/interface/PixelMapMethods.h | 23 +- RecoTracker/LSTGeometry/interface/Sensor.h | 3 + .../plugins/LSTGeometryESProducer.cc | 10 +- RecoTracker/LSTGeometry/src/Geometry.cc | 13 +- RecoTracker/LSTGeometry/src/Sensor.cc | 1 + 11 files changed, 79 insertions(+), 541 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/Module.h diff --git a/RecoTracker/LSTGeometry/interface/CornerMethods.h b/RecoTracker/LSTGeometry/interface/CornerMethods.h index d9cebe26594ea..f6ee8a794cbc6 100644 --- a/RecoTracker/LSTGeometry/interface/CornerMethods.h +++ b/RecoTracker/LSTGeometry/interface/CornerMethods.h @@ -103,11 +103,8 @@ namespace lstgeometry { } // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. - std::unordered_map assignCornersToSensors( - std::unordered_map const& modules, - std::unordered_map const& sensors) { - std::unordered_map transformed_corners_dict; - + void assignCornersToSensors(std::unordered_map const& modules, + std::unordered_map& sensors) { for (auto const& [detId, moduleInfo] : modules) { unsigned int module_det_id = detId; unsigned int sensor_det_id_1 = module_det_id + 1; @@ -135,15 +132,13 @@ namespace lstgeometry { double distance_to_sensor_2 = (centroid_sensor_2 - sensor_centroid_2).norm(); if (distance_to_sensor_1 < distance_to_sensor_2) { - transformed_corners_dict[sensor_det_id_1] = transformed_corners.topRows(4); - transformed_corners_dict[sensor_det_id_2] = transformed_corners.bottomRows(4); + sensors[sensor_det_id_1].corners = transformed_corners.topRows(4); + sensors[sensor_det_id_2].corners = transformed_corners.bottomRows(4); } else { - transformed_corners_dict[sensor_det_id_2] = transformed_corners.topRows(4); - transformed_corners_dict[sensor_det_id_1] = transformed_corners.bottomRows(4); + sensors[sensor_det_id_2].corners = transformed_corners.topRows(4); + sensors[sensor_det_id_1].corners = transformed_corners.bottomRows(4); } } - - return transformed_corners_dict; } } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index 05f50bdaa0199..8ac4d55b73720 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -81,7 +81,7 @@ namespace lstgeometry { class DetectorGeometry { private: - std::unordered_map corners_; + std::unordered_map& sensors_; std::vector avg_radii_; std::vector avg_z_; std::unordered_map, boost::hash> @@ -90,17 +90,17 @@ namespace lstgeometry { endcap_lower_det_ids_; public: - DetectorGeometry(std::unordered_map corners, + DetectorGeometry(std::unordered_map sensors, std::vector avg_radii, std::vector avg_z) - : corners_(corners), avg_radii_(avg_radii), avg_z_(avg_z) {} + : sensors_(sensors), avg_radii_(avg_radii), avg_z_(avg_z) {} - MatrixD4x3 const& getCorners(unsigned int detId) const { return corners_.at(detId); } + MatrixD4x3 const& getCorners(unsigned int detId) const { return sensors_.at(detId).corners; } - std::vector getDetIds(std::function&)> filter = + std::vector getDetIds(std::function&)> filter = [](const auto&) { return true; }) const { std::vector detIds; - for (const auto& entry : corners_) { + for (const auto& entry : sensors_) { if (filter(entry)) { detIds.push_back(entry.first); } @@ -183,7 +183,7 @@ namespace lstgeometry { double getEndcapLayerAverageAbsZ(unsigned int layer) const { return avg_z_[layer - 1]; } double getMinR(unsigned int detId) const { - auto const& corners = corners_.at(detId); + auto const& corners = getCorners(detId); double minR = std::numeric_limits::max(); for (int i = 0; i < corners.rows(); i++) { double x = corners(i, 1); @@ -194,7 +194,7 @@ namespace lstgeometry { } double getMaxR(unsigned int detId) const { - auto const& corners = corners_.at(detId); + auto const& corners = getCorners(detId); double maxR = std::numeric_limits::min(); for (int i = 0; i < corners.rows(); i++) { double x = corners(i, 1); @@ -205,7 +205,7 @@ namespace lstgeometry { } double getMinZ(unsigned int detId) const { - auto const& corners = corners_.at(detId); + auto const& corners = getCorners(detId); double minZ = std::numeric_limits::max(); for (int i = 0; i < corners.rows(); i++) { double z = corners(i, 0); @@ -215,7 +215,7 @@ namespace lstgeometry { } double getMaxZ(unsigned int detId) const { - auto const& corners = corners_.at(detId); + auto const& corners = getCorners(detId); double maxZ = std::numeric_limits::lowest(); for (int i = 0; i < corners.rows(); i++) { double z = corners(i, 0); @@ -225,7 +225,7 @@ namespace lstgeometry { } double getMinPhi(unsigned int detId) const { - auto const& corners = corners_.at(detId); + auto const& corners = getCorners(detId); double minPhi = std::numeric_limits::max(); double minPosPhi = std::numeric_limits::max(); double minNegPhi = std::numeric_limits::max(); @@ -252,7 +252,7 @@ namespace lstgeometry { } double getMaxPhi(unsigned int detId) const { - auto const& corners = corners_.at(detId); + auto const& corners = getCorners(detId); double maxPhi = std::numeric_limits::lowest(); double maxPosPhi = std::numeric_limits::lowest(); double maxNegPhi = std::numeric_limits::lowest(); diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h deleted file mode 100644 index c5a761a3bcdb3..0000000000000 --- a/RecoTracker/LSTGeometry/interface/Module.h +++ /dev/null @@ -1,475 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_Module_h -#define RecoTracker_LSTGeometry_interface_Module_h - -#include -#include - -namespace lstgeometry { - - class Module { - private: - // Decoding DetId - // - // detId comes in 29 bits. There are two formats depending on which sub detector it is. - // - // 29 bits total - // - // left to right index (useful python, i.e. string[idx:jdx]) - // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 - // - // right to left index (useful when C++ style, i.e. bit shifting) - // 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 - // - // x x x x x x x x x x x x x x x x x x x x x x x x x x x x x - // - // -subdet- -layer-- -side --------rod--------- -------module------- # if subdet == 5 - // -subdet- -side --layer- ----ring--- -------module------- # if subdet == 4 - // - // - - //---------- - // * detId * - //---------- - // The unique detector ID for this module layer - unsigned int detId_; - - // The unique detector ID to its partner - unsigned int partnerDetId_; - - //----------- - // * subdet * - //----------- - // bits 27 to 25 - // subdet = (detId & (7 << 25)) >> 25; - // subdet can take either 4 or 5 - // 4: endcap - // 5: barrel - public: - enum SubDet { Barrel = 5, Endcap = 4 }; - - private: - unsigned short subdet_; - - //--------- - // * Side * - //--------- - // bits 24 to 23 - // if (subdet_ == 4) - // { - // side_ = (detId_ & (3 << 23)) >> 23; - // } - // else if (subdet_ == 5) - // { - // side_ = (detId_ & (3 << 18)) >> 18; - // } - // 1 = -z side of the endcap modules AND -z side of tilted modules - // 2 = +z side of the endcap modules AND +z side of tilted modules - // 3 = barrel modules (determined via checking subdet) - public: - enum Side { NegZ = 1, PosZ = 2, Center = 3 }; - - private: - unsigned short side_; - - //---------- - // * Layer * - //---------- - // either bits 22 to 20 or 20 to 18 - // if (subdet_ == 4) - // { - // layer_ = (detId_ & (7 << 18)) >> 18; - // } - // else if (subdet_ == 5) - // { - // layer_ = (detId_ & (7 << 20)) >> 20; - // } - // depending on whether it is subdet = 4 or 5, the position of layer information is different - // layer = detId_bits[06:08] if subdet = 5 - // layer = detId_bits[08:10] if subdet = 4 - unsigned short layer_; - - //-------- - // * Rod * - //-------- - // bits 16 to 10 only when subdet = 5 - // if (subdet_ == 5) - // { - // rod_ = (detId_ & (127 << 10)) >> 10; - // } - // else if (subdet_ == 4) - // { - // rod_ = 0; - // } - // Index of which rod in the barrel - // Closest to the positive x-axis line is rod = 1, and it goes counter-clockwise in x-y plane projection - // total number of rods for each layer: 18, 26, 36, 48, 60, and 78 - unsigned short rod_; - - //--------- - // * Ring * - //--------- - // bits 15 to 12 only when subdet = 4 - // if (subdet_ == 5) - // { - // ring_ = 0; - // } - // else if (subdet_ == 4) - // { - // ring_ = (detId_ & (15 << 12)) >> 12; - // } - // Index of which ring in the endcap - // For the layer 1 and 2, there are 15 rings, first 10 are PS, the latter 5 are 2S - // For the layer 3, 4, and 5, there are 12 rings, first 7 are PS, the latter 5 are 2S - unsigned short ring_; - - //----------- - // * Module * - //----------- - // bits 8 to 2 - // module_ = (detId_ & (127 << 2)) >> 2; - // For subdet==4 the # of module depends on how far away from beam spot, - // module 1 is closest to the positive x-axis line and it goes counter-clockwise in x-y plane projection - // layer 1 or 2, ring 1: 20 modules - // layer 1 or 2, ring 2: 24 modules - // layer 1 or 2, ring 3: 24 modules - // layer 1 or 2, ring 4: 28 modules - // layer 1 or 2, ring 5: 32 modules - // layer 1 or 2, ring 6: 32 modules - // layer 1 or 2, ring 7: 36 modules - // layer 1 or 2, ring 8: 40 modules - // layer 1 or 2, ring 9: 40 modules - // layer 1 or 2, ring 10: 44 modules - // layer 1 or 2, ring 11: 52 modules - // layer 1 or 2, ring 12: 60 modules - // layer 1 or 2, ring 13: 64 modules - // layer 1 or 2, ring 14: 72 modules - // layer 1 or 2, ring 15: 76 modules - // layer 3, 4, or 5, ring 1: 28 modules - // layer 3, 4, or 5, ring 2: 28 modules - // layer 3, 4, or 5, ring 3: 32 modules - // layer 3, 4, or 5, ring 4: 36 modules - // layer 3, 4, or 5, ring 5: 36 modules - // layer 3, 4, or 5, ring 6: 40 modules - // layer 3, 4, or 5, ring 7: 44 modules - // layer 3, 4, or 5, ring 8: 52 modules - // layer 3, 4, or 5, ring 9: 56 modules - // layer 3, 4, or 5, ring 10: 64 modules - // layer 3, 4, or 5, ring 11: 72 modules - // layer 3, 4, or 5, ring 12: 76 modules - // - // For subdet==5, the # of module depends on how far away from beam spot, - // for side==3: module 1 has lowest z (starting from the negative value) - // layer 1, side 3: 7 modules - // layer 2, side 3: 11 modules - // layer 3, side 3: 15 modules - // layer 4, 5, or 6, side 3: 24 modules - // for side==1,2 (i.e. tilted): module 1 is along x-axis - // layer 1, side 1, or 2: 18 modules - // layer 2, side 1, or 2: 26 modules - // layer 3, side 1, or 2: 36 modules - unsigned short module_; - - //------------ - // * isLower * - //------------ - // bit 28 - // isLower_ = (detId_ & 1); - // isLower is always the pixel if it's a PS module, if it's a 2S module it's whichever is the protruding side when 2S are staggered - unsigned short isLower_; - - // The modules are put in alternating order where the modules are inverted every other one - bool isInverted_; - - // To hold information whether it is a 2S or PS - public: - enum ModuleType { PS, PSP = 23, PSS = 24, TwoS = 25 }; - - private: - ModuleType moduleType_; - - // To hold information whether it is a Pixel or Strip - // Pixel - // Strip - public: - enum ModuleLayerType { Pixel, Strip }; - - private: - ModuleLayerType moduleLayerType_; - - void setDerivedQuantities(); - void setDerivedQuantities(unsigned int moduleTypeInfo); - void setDerivedQuantities(ModuleType moduleType, ModuleLayerType moduleLayerType); - - public: - // constructor/destructor - Module(); - Module(unsigned int detId); - Module(unsigned int detId, unsigned int moduleTypeInfo); - Module(unsigned int detId, ModuleType moduleType, ModuleLayerType moduleLayerType); - Module(const Module&); - ~Module(); - - // accessor functions - const unsigned int& detId() const; - const unsigned int& partnerDetId() const; - const unsigned short& subdet() const; - const unsigned short& side() const; - const unsigned short& layer() const; - const unsigned short& rod() const; - const unsigned short& ring() const; - const unsigned short& module() const; - const unsigned short& isLower() const; - const bool& isInverted() const; - const ModuleType& moduleType() const; - const ModuleLayerType& moduleLayerType() const; - - // modifying the class content - void setDetId(unsigned int); - void setDetId(unsigned int, unsigned int); - void setDetId(unsigned int, ModuleType, ModuleLayerType); - - // static functions to parse detId - static unsigned short parseSubdet(unsigned int); - static unsigned short parseSide(unsigned int); - static unsigned short parseLayer(unsigned int); - static unsigned short parseRod(unsigned int); - static unsigned short parseRing(unsigned int); - static unsigned short parseModule(unsigned int); - static unsigned short parseIsLower(unsigned int); - static bool parseIsInverted(unsigned int); - static unsigned int parsePartnerDetId(unsigned int); - static ModuleType parseModuleType(unsigned int); - static ModuleLayerType parseModuleLayerType(unsigned int); - }; - -} // namespace lstgeometry - -lstgeometry::Module::Module() { setDetId(0); } - -lstgeometry::Module::Module(unsigned int detId) { setDetId(detId); } - -lstgeometry::Module::Module(unsigned int detId, unsigned int moduleTypeInfo) { setDetId(detId, moduleTypeInfo); } - -lstgeometry::Module::Module(const Module& module) { - setDetId(module.detId(), module.moduleType(), module.moduleLayerType()); -} - -lstgeometry::Module::~Module() {} - -const unsigned short& lstgeometry::Module::subdet() const { return subdet_; } - -const unsigned short& lstgeometry::Module::side() const { return side_; } - -const unsigned short& lstgeometry::Module::layer() const { return layer_; } - -const unsigned short& lstgeometry::Module::rod() const { return rod_; } - -const unsigned short& lstgeometry::Module::ring() const { return ring_; } - -const unsigned short& lstgeometry::Module::module() const { return module_; } - -const unsigned short& lstgeometry::Module::isLower() const { return isLower_; } - -const unsigned int& lstgeometry::Module::detId() const { return detId_; } - -const unsigned int& lstgeometry::Module::partnerDetId() const { return partnerDetId_; } - -const bool& lstgeometry::Module::isInverted() const { return isInverted_; } - -const lstgeometry::Module::ModuleType& lstgeometry::Module::moduleType() const { return moduleType_; } - -const lstgeometry::Module::ModuleLayerType& lstgeometry::Module::moduleLayerType() const { return moduleLayerType_; } - -void lstgeometry::Module::setDetId(unsigned int detId) { - detId_ = detId; - setDerivedQuantities(); -} - -void lstgeometry::Module::setDetId(unsigned int detId, unsigned int moduleTypeInfo) { - detId_ = detId; - setDerivedQuantities(moduleTypeInfo); -} - -void lstgeometry::Module::setDetId(unsigned int detId, ModuleType moduleType, ModuleLayerType moduleLayerType) { - detId_ = detId; - setDerivedQuantities(moduleType, moduleLayerType); -} - -void lstgeometry::Module::setDerivedQuantities() { - subdet_ = parseSubdet(detId_); - side_ = parseSide(detId_); - layer_ = parseLayer(detId_); - rod_ = parseRod(detId_); - ring_ = parseRing(detId_); - module_ = parseModule(detId_); - isLower_ = parseIsLower(detId_); - isInverted_ = parseIsInverted(detId_); - partnerDetId_ = parsePartnerDetId(detId_); - moduleType_ = parseModuleType(detId_); - moduleLayerType_ = parseModuleLayerType(detId_); -} - -void lstgeometry::Module::setDerivedQuantities(unsigned int moduleTypeInfo) { - subdet_ = parseSubdet(detId_); - side_ = parseSide(detId_); - layer_ = parseLayer(detId_); - rod_ = parseRod(detId_); - ring_ = parseRing(detId_); - module_ = parseModule(detId_); - isLower_ = parseIsLower(detId_); - isInverted_ = parseIsInverted(detId_); - partnerDetId_ = parsePartnerDetId(detId_); - moduleType_ = (moduleTypeInfo == 25 ? lstgeometry::Module::TwoS - : lstgeometry::Module::PS); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS - moduleLayerType_ = (moduleTypeInfo == 23 ? lstgeometry::Module::Pixel - : lstgeometry::Module::Strip); // 23 : Ph2PSP, 24 : Ph2PSS, 25 : Ph2SS -} - -void lstgeometry::Module::setDerivedQuantities(ModuleType moduleType, ModuleLayerType moduleLayerType) { - subdet_ = parseSubdet(detId_); - side_ = parseSide(detId_); - layer_ = parseLayer(detId_); - rod_ = parseRod(detId_); - ring_ = parseRing(detId_); - module_ = parseModule(detId_); - isLower_ = parseIsLower(detId_); - isInverted_ = parseIsInverted(detId_); - partnerDetId_ = parsePartnerDetId(detId_); - moduleType_ = moduleType; - moduleLayerType_ = moduleLayerType; -} - -unsigned short lstgeometry::Module::parseSubdet(unsigned int detId) { return (detId & (7 << 25)) >> 25; } - -unsigned short lstgeometry::Module::parseSide(unsigned int detId) { - if (parseSubdet(detId) == lstgeometry::Module::Endcap) { - return (detId & (3 << 23)) >> 23; - } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { - return (detId & (3 << 18)) >> 18; - } else { - return 0; - } -} - -unsigned short lstgeometry::Module::parseLayer(unsigned int detId) { - if (parseSubdet(detId) == lstgeometry::Module::Endcap) { - return (detId & (7 << 18)) >> 18; - } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { - return (detId & (7 << 20)) >> 20; - } else { - return 0; - } -} - -unsigned short lstgeometry::Module::parseRod(unsigned int detId) { - if (parseSubdet(detId) == lstgeometry::Module::Endcap) { - return 0; - } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { - return (detId & (127 << 10)) >> 10; - } else { - return 0; - } -} - -unsigned short lstgeometry::Module::parseRing(unsigned int detId) { - if (parseSubdet(detId) == lstgeometry::Module::Endcap) { - return (detId & (15 << 12)) >> 12; - } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { - return 0; - } else { - return 0; - } -} - -unsigned short lstgeometry::Module::parseModule(unsigned int detId) { return (detId & (127 << 2)) >> 2; } - -unsigned short lstgeometry::Module::parseIsLower(unsigned int detId) { - return ((parseIsInverted(detId)) ? !(detId & 1) : (detId & 1)); -} - -bool lstgeometry::Module::parseIsInverted(unsigned int detId) { - if (detId == 1) // "1" detId means "pixel module" where we store all pixel hits/mini/segments into one bucket - return 0; - if (parseSubdet(detId) == lstgeometry::Module::Endcap) { - if (parseSide(detId) == lstgeometry::Module::NegZ) { - return parseModule(detId) % 2 == 1; - } else if (parseSide(detId) == lstgeometry::Module::PosZ) { - return parseModule(detId) % 2 == 0; - } else { - std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; - return 0; - } - } else if (parseSubdet(detId) == lstgeometry::Module::Barrel) { - if (parseSide(detId) == lstgeometry::Module::Center) { - if (parseLayer(detId) <= 3) { - return parseModule(detId) % 2 == 1; - } else if (parseLayer(detId) >= 4) { - return parseModule(detId) % 2 == 0; - } else { - std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; - return 0; - } - } else if (parseSide(detId) == lstgeometry::Module::NegZ or parseSide(detId) == lstgeometry::Module::PosZ) { - if (parseLayer(detId) <= 2) { - return parseModule(detId) % 2 == 1; - } else if (parseLayer(detId) == 3) { - return parseModule(detId) % 2 == 0; - } else { - std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; - return 0; - } - } else { - std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; - return 0; - } - } else { - std::cout << "Warning: parseIsInverted() categorization failed" << std::endl; - return 0; - } -} - -unsigned int lstgeometry::Module::parsePartnerDetId(unsigned int detId) { - if (parseIsLower(detId)) - return ((parseIsInverted(detId)) ? detId - 1 : detId + 1); - else - return ((parseIsInverted(detId)) ? detId + 1 : detId - 1); -} - -lstgeometry::Module::ModuleType lstgeometry::Module::parseModuleType(unsigned int detId) { - if (parseSubdet(detId) == lstgeometry::Module::Barrel) { - if (parseLayer(detId) <= 3) - return lstgeometry::Module::PS; - else - return lstgeometry::Module::TwoS; - } else { - if (parseLayer(detId) <= 2) { - if (parseRing(detId) <= 10) - return lstgeometry::Module::PS; - else - return lstgeometry::Module::TwoS; - } else { - if (parseRing(detId) <= 7) - return lstgeometry::Module::PS; - else - return lstgeometry::Module::TwoS; - } - } -} - -lstgeometry::Module::ModuleLayerType lstgeometry::Module::parseModuleLayerType(unsigned int detId) { - if (parseModuleType(detId) == lstgeometry::Module::TwoS) - return lstgeometry::Module::Strip; - if (parseIsInverted(detId)) { - if (parseIsLower(detId)) - return lstgeometry::Module::Strip; - else - return lstgeometry::Module::Pixel; - } else { - if (parseIsLower(detId)) - return lstgeometry::Module::Pixel; - else - return lstgeometry::Module::Strip; - } -} - -#endif diff --git a/RecoTracker/LSTGeometry/interface/ModuleInfo.h b/RecoTracker/LSTGeometry/interface/ModuleInfo.h index bd062a2a8580d..79f467c052069 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleInfo.h +++ b/RecoTracker/LSTGeometry/interface/ModuleInfo.h @@ -12,6 +12,7 @@ namespace lstgeometry { struct ModuleInfo { TrackerGeometry::ModuleType moduleType; GeomDetEnumerators::SubDetector subdet; + GeomDetEnumerators::Location location; Phase2Tracker::BarrelModuleTilt side; unsigned int layer; unsigned int ring; diff --git a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h index 8d85df2435929..fd492ab929dd1 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h @@ -14,22 +14,23 @@ #include "RecoTracker/LSTGeometry/interface/Math.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" namespace lstgeometry { std::vector getStraightLineConnections(unsigned int ref_detid, + std::unordered_map const& modules_info, std::unordered_map const& sensors, DetectorGeometry const& det_geom) { auto& sensor = sensors.at(ref_detid); double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); - Module refmodule(ref_detid); + auto refmodule = modules_info.at(sensors.at(ref_detid).moduleDetId); - unsigned short ref_layer = refmodule.layer(); - unsigned short ref_subdet = refmodule.subdet(); + unsigned short ref_layer = refmodule.layer; + unsigned short ref_subdet = refmodule.subdet; auto etaphi = getEtaPhi(sensor.centerX_cm, sensor.centerY_cm, sensor.centerZ_cm); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); @@ -112,6 +113,7 @@ namespace lstgeometry { } MatrixD4x3 boundsAfterCurved(unsigned int ref_detid, + std::unordered_map const& modules_info, std::unordered_map const& sensors, DetectorGeometry const& det_geom, double ptCut, @@ -122,9 +124,9 @@ namespace lstgeometry { double theta = std::atan2(std::sqrt(sensor.centerX_cm * sensor.centerX_cm + sensor.centerY_cm * sensor.centerY_cm), sensor.centerZ_cm); double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); - Module refmodule(ref_detid); - unsigned short ref_layer = refmodule.layer(); - unsigned short ref_subdet = refmodule.subdet(); + auto refmodule = modules_info.at(sensors.at(ref_detid).moduleDetId); + unsigned short ref_layer = refmodule.layer; + unsigned short ref_subdet = refmodule.subdet; MatrixD4x3 next_layer_bound_points; for (int i = 0; i < bounds.rows(); i++) { @@ -188,6 +190,7 @@ namespace lstgeometry { } std::vector getCurvedLineConnections(unsigned int ref_detid, + std::unordered_map const& modules_info, std::unordered_map const& sensors, DetectorGeometry const& det_geom, double ptCut) { @@ -195,10 +198,10 @@ namespace lstgeometry { double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); - Module refmodule(ref_detid); + auto refmodule = modules_info.at(sensors.at(ref_detid).moduleDetId); - unsigned short ref_layer = refmodule.layer(); - unsigned short ref_subdet = refmodule.subdet(); + unsigned short ref_layer = refmodule.layer; + unsigned short ref_subdet = refmodule.subdet; auto etaphi = getEtaPhi(sensor.centerX_cm, sensor.centerY_cm, sensor.centerZ_cm); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); @@ -207,7 +210,7 @@ namespace lstgeometry { ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); - auto next_layer_bound_points = boundsAfterCurved(ref_detid, sensors, det_geom, ptCut); + auto next_layer_bound_points = boundsAfterCurved(ref_detid, modules_info, sensors, det_geom, ptCut); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index d1d6ae1d3ef26..b8ae1ff61677b 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -6,7 +6,8 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/SlopeData.h" namespace lstgeometry { @@ -21,29 +22,28 @@ namespace lstgeometry { // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. std::tuple, std::unordered_map> processCorners( - std::unordered_map& corners) { + std::unordered_map const& modules_info, + std::unordered_map& sensors) { std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; - for (const auto& [detId, corners] : corners) { - double dx = roundCoordinate(corners(1, 1) - corners(0, 1)); - double dy = roundCoordinate(corners(1, 2) - corners(0, 2)); - double dz = roundCoordinate(corners(1, 0) - corners(0, 0)); + for (const auto& [detId, sensor] : sensors) { + double dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); + double dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); + double dz = roundCoordinate(sensor.corners(1, 0) - sensor.corners(0, 0)); SlopeData slope = calculateSlope(dx, dy, dz); - Module module(detId); + auto& module = modules_info.at(sensor.moduleDetId); - unsigned short subdet = module.subdet(); - bool is_tilted = module.side() != 3; - bool is_strip = module.moduleLayerType() == 1; + auto location = module.location; + bool is_tilted = module.side != Phase2Tracker::BarrelModuleTilt::flat; - if (!is_strip) - continue; + // TODO: Do we need to skip strips? - if (subdet == Module::SubDet::Barrel and is_tilted) + if (location == GeomDetEnumerators::Location::barrel and is_tilted) barrel_slopes[detId] = slope; - else if (subdet == Module::SubDet::Endcap) + else if (location == GeomDetEnumerators::Location::endcap) endcap_slopes[detId] = slope; } diff --git a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h index 51affbbf98c93..8a2292d219774 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h @@ -5,11 +5,13 @@ #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" namespace lstgeometry { - PixelMap computePixelMap(DetectorGeometry const& det_geom, double ptCut) { + PixelMap computePixelMap(std::unordered_map const& modules_info, + DetectorGeometry const& det_geom, + double ptCut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; @@ -26,15 +28,20 @@ namespace lstgeometry { // Loop over the detids and for each detid compute which superbins it is connected to for (auto detId : det_geom.getDetIds()) { - // Parse the layer and subdet - auto module = Module(detId); - auto layer = module.layer(); + // Skip if the detId is not in the modules_info + if (!modules_info.contains(detId)) + continue; + + auto module = modules_info.at(detId); + auto subdet = static_cast(module.subdet); + auto layer = module.layer; if (layer > 2) continue; - auto subdet = module.subdet(); + auto location = module.location; // Skip if the module is not PS module and is not lower module - if (module.isLower() != 1 || module.moduleType() != 0) + if (!module.isLower || (module.moduleType != TrackerGeometry::ModuleType::Ph2PSP && + module.moduleType != TrackerGeometry::ModuleType::Ph2PSS)) continue; // For this module, now compute which super bins they belong to @@ -58,7 +65,7 @@ namespace lstgeometry { etamin -= 0.05; etamax += 0.05; - if (layer == 2 && subdet == 4) { + if (layer == 2 && location == GeomDetEnumerators::Location::endcap) { if (etamax < 2.3) continue; if (etamin < 2.3) diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index 1bd300b6c905d..4aca5810c0b3d 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -3,6 +3,8 @@ #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" + namespace lstgeometry { struct Sensor { @@ -10,6 +12,7 @@ namespace lstgeometry { float centerRho_cm; float centerZ_cm; float centerPhi_rad; + MatrixD4x3 corners; // Redundant, but convenient to have them TrackerGeometry::ModuleType moduleType; float centerX_cm; diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index 414e9f831bcc2..1676aced25b41 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -10,7 +10,6 @@ #include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Geometry.h" #include @@ -67,7 +66,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac // TODO: Is there a more straightforward way to only loop through these? if (moduleType != TrackerGeometry::ModuleType::Ph2PSP && moduleType != TrackerGeometry::ModuleType::Ph2PSS && moduleType != TrackerGeometry::ModuleType::Ph2SS) { - //continue; + continue; } const unsigned int detid = detId(); @@ -93,7 +92,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac } const auto subdet = static_cast(detId.subdetId()); - const auto side = static_cast(trackerTopo_->side(detId)); + const auto side = trackerTopo_->barrelTiltTypeP2(detId); + const auto location = (GeomDetEnumerators::isBarrel(subdet) ? GeomDetEnumerators::Location::barrel + : GeomDetEnumerators::Location::endcap); const unsigned int layer = trackerTopo_->layer(detId); const unsigned int ring = trackerTopo_->endcapRingP2(detId); const bool isLower = trackerTopo_->isLower(detId); @@ -112,7 +113,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); } - if (lstgeometry::Module::parseSubdet(detid) == lstgeometry::Module::SubDet::Barrel) { + if (location == GeomDetEnumerators::Location::barrel) { avg_r_cm[layer - 1] += rho_cm; avg_r_counter[layer - 1] += 1; } else { @@ -122,6 +123,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac lstgeometry::ModuleInfo module{moduleType, subdet, + location, side, layer, ring, diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index edb07f0c9c6f8..7d0ad2f4cbed3 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -15,16 +15,16 @@ Geometry::Geometry(std::unordered_map &modules_info, for (auto &[_, mod] : modules_info) transformSensorCorners(mod); - auto assigned_corners = assignCornersToSensors(modules_info, sensors_input); + assignCornersToSensors(modules_info, sensors_input); - auto slopes = processCorners(assigned_corners); + auto slopes = processCorners(modules_info, sensors_input); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); - auto det_geom = DetectorGeometry(assigned_corners, average_r, average_z); + auto det_geom = DetectorGeometry(sensors_input, average_r, average_z); det_geom.buildByLayer(modules_info, sensors_input); - pixel_map = computePixelMap(det_geom, ptCut); + pixel_map = computePixelMap(modules_info, det_geom, ptCut); auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_input](const auto &x) { auto mod = modules_info.at(sensors_input.at(x.first).moduleDetId); @@ -39,8 +39,9 @@ Geometry::Geometry(std::unordered_map &modules_info, std::unordered_map> curved_line_connections; for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, sensors_input, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, sensors_input, det_geom, ptCut); + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, modules_info, sensors_input, det_geom); + curved_line_connections[ref_detid] = + getCurvedLineConnections(ref_detid, modules_info, sensors_input, det_geom, ptCut); } merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc index d0ad3889623e7..8741ec3994b1c 100644 --- a/RecoTracker/LSTGeometry/src/Sensor.cc +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -13,6 +13,7 @@ Sensor::Sensor(unsigned int moduleDetId, centerRho_cm(centerRho_cm), centerZ_cm(centerZ_cm), centerPhi_rad(centerPhi_rad), + corners(MatrixD4x3::Zero()), moduleType(moduleType), centerX_cm(centerRho_cm * std::cos(centerPhi_rad)), centerY_cm(centerRho_cm * std::sin(centerPhi_rad)) {} From a62d0a6e34aeee23881a009695dab69d8422f373 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 25 Feb 2026 19:28:27 +0000 Subject: [PATCH 73/95] Useful renamings --- RecoTracker/LSTCore/src/EndcapGeometry.cc | 2 +- RecoTracker/LSTCore/src/LSTESData.cc | 6 +- RecoTracker/LSTGeometry/interface/Common.h | 43 ++++---- .../LSTGeometry/interface/CornerMethods.h | 98 +++++++++---------- .../LSTGeometry/interface/DetectorGeometry.h | 21 ++-- RecoTracker/LSTGeometry/interface/Geometry.h | 12 +-- RecoTracker/LSTGeometry/interface/Helix.h | 12 +-- RecoTracker/LSTGeometry/interface/IO.h | 20 ++-- RecoTracker/LSTGeometry/interface/Math.h | 18 ++-- RecoTracker/LSTGeometry/interface/Module.h | 33 +++++++ .../LSTGeometry/interface/ModuleInfo.h | 34 ------- .../LSTGeometry/interface/ModuleMapMethods.h | 44 ++++----- .../interface/OrientationMethods.h | 7 +- .../LSTGeometry/interface/PixelMapMethods.h | 12 +-- RecoTracker/LSTGeometry/interface/Sensor.h | 25 ++--- .../plugins/LSTGeometryESProducer.cc | 62 ++++++------ RecoTracker/LSTGeometry/src/Common.cc | 18 ++-- RecoTracker/LSTGeometry/src/Geometry.cc | 27 +++-- RecoTracker/LSTGeometry/src/Sensor.cc | 18 ++-- 19 files changed, 252 insertions(+), 260 deletions(-) create mode 100644 RecoTracker/LSTGeometry/interface/Module.h delete mode 100644 RecoTracker/LSTGeometry/interface/ModuleInfo.h diff --git a/RecoTracker/LSTCore/src/EndcapGeometry.cc b/RecoTracker/LSTCore/src/EndcapGeometry.cc index 4e3f2630984d6..9d23517cfb3fe 100644 --- a/RecoTracker/LSTCore/src/EndcapGeometry.cc +++ b/RecoTracker/LSTCore/src/EndcapGeometry.cc @@ -46,7 +46,7 @@ void lst::EndcapGeometry::load(std::unordered_map> lst::fillESDataHost(lstg unsigned int counter = 0; for (auto const& [detId, sensor] : lstg.sensors) { mmd.detIdToIndex[detId] = counter; - mmd.module_x[detId] = sensor.centerX_cm; - mmd.module_y[detId] = sensor.centerY_cm; - mmd.module_z[detId] = sensor.centerZ_cm; + mmd.module_x[detId] = sensor.centerX; + mmd.module_y[detId] = sensor.centerY; + mmd.module_z[detId] = sensor.centerZ; mmd.module_type[detId] = static_cast(sensor.moduleType); counter++; } diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index 6b7a014615c2e..a4dfec60b7559 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -1,38 +1,47 @@ #ifndef RecoTracker_LSTGeometry_interface_Common_h #define RecoTracker_LSTGeometry_interface_Common_h +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" +#include "DataFormats/SiStripDetId/interface/SiStripEnums.h" + #include #include namespace lstgeometry { - using MatrixD3x3 = Eigen::Matrix; - using MatrixD4x2 = Eigen::Matrix; - using MatrixD4x3 = Eigen::Matrix; - using MatrixD8x3 = Eigen::Matrix; - using MatrixDNx2 = Eigen::Matrix; - using MatrixDNx3 = Eigen::Matrix; - using RowVectorD2 = Eigen::Matrix; - using ColVectorD3 = Eigen::Matrix; - using RowVectorD3 = Eigen::Matrix; + using MatrixF3x3 = Eigen::Matrix; + using MatrixF4x2 = Eigen::Matrix; + using MatrixF4x3 = Eigen::Matrix; + using MatrixF8x3 = Eigen::Matrix; + using MatrixFNx2 = Eigen::Matrix; + using MatrixFNx3 = Eigen::Matrix; + using RowVectorF2 = Eigen::Matrix; + using ColVectorF3 = Eigen::Matrix; + using RowVectorF3 = Eigen::Matrix; + + using ModuleType = TrackerGeometry::ModuleType; + using SubDetector = GeomDetEnumerators::SubDetector; + using Location = GeomDetEnumerators::Location; + using BarrelModuleTilt = Phase2Tracker::BarrelModuleTilt; // TODO: These should be moved to ../Common.h - constexpr double k2Rinv1GeVf = 0.00299792458; - constexpr double kB = 3.8112; + constexpr float k2Rinv1GeVf = 0.00299792458; + constexpr float kB = 3.8112; // For pixel maps constexpr unsigned int kNEta = 25; constexpr unsigned int kNPhi = 72; constexpr unsigned int kNZ = 25; - constexpr std::array kPtBounds = {{2.0, 10'000.0}}; + constexpr std::array kPtBounds = {{2.0, 10'000.0}}; // This is defined as a constant in case the legacy value (123456789) needs to be used - constexpr double kDefaultSlope = std::numeric_limits::infinity(); + constexpr float kDefaultSlope = std::numeric_limits::infinity(); - double degToRad(double degrees); - double phi_mpi_pi(double phi); - double roundAngle(double angle, double tol = 1e-3); - double roundCoordinate(double coord, double tol = 1e-3); + float degToRad(float degrees); + float phi_mpi_pi(float phi); + float roundAngle(float angle, float tol = 1e-3); + float roundCoordinate(float coord, float tol = 1e-3); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/CornerMethods.h b/RecoTracker/LSTGeometry/interface/CornerMethods.h index f6ee8a794cbc6..df6a974130f92 100644 --- a/RecoTracker/LSTGeometry/interface/CornerMethods.h +++ b/RecoTracker/LSTGeometry/interface/CornerMethods.h @@ -6,26 +6,26 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { //Calculates the Rodrigues' rotation matrix for rotating a vector around an arbitrary axis. - MatrixD3x3 rodriguesRotationMatrix(ColVectorD3 axis, double theta) { + MatrixF3x3 rodriguesRotationMatrix(ColVectorF3 axis, float theta) { axis.normalize(); - MatrixD3x3 k{{0, -axis(2), axis(1)}, {axis(2), 0, -axis(0)}, {-axis(1), axis(0), 0}}; + MatrixF3x3 k{{0, -axis(2), axis(1)}, {axis(2), 0, -axis(0)}, {-axis(1), axis(0), 0}}; - MatrixD3x3 rotationMatrix = MatrixD3x3::Identity() + sin(theta) * k + (1 - cos(theta)) * (k * k); + MatrixF3x3 rotationMatrix = MatrixF3x3::Identity() + std::sin(theta) * k + (1 - std::cos(theta)) * (k * k); return rotationMatrix; } // Generates a rotation matrix for rotating around the tangential direction in cylindrical coordinates. - MatrixD3x3 tangentialRotationMatrix(double phi, double theta) { - ColVectorD3 axis; - axis << -sin(phi), cos(phi), 0; + MatrixF3x3 tangentialRotationMatrix(float phi, float theta) { + ColVectorF3 axis; + axis << -std::sin(phi), std::cos(phi), 0; return rodriguesRotationMatrix(axis, theta); } @@ -35,38 +35,38 @@ namespace lstgeometry { // Only the tilt angles are non-zero for the current geometry. If the other // angles get used, implement their rotations using the tangentialRotationMatrix // function above as an example. - MatrixD3x3 rotationMatrix(double tilt_rad, double skew_rad, double yaw_rad, double phi_rad) { - if (skew_rad != 0 || yaw_rad != 0) + MatrixF3x3 rotationMatrix(float tilt, float skew, float yaw, float phi) { + if (skew != 0 || yaw != 0) throw std::invalid_argument("Skew and yaw angles are not currently supported."); // Rotation around Z-axis that makes the sensor "face towards" the beamline (i.e. towards z-axis) // So for example if phi=0 then R is the identity (i.e. already facing), or if phi=90deg // then R becomes (x,y,z)->(-y,x,z) so the sensor is rotated 90 degrees to face the beamline - MatrixD3x3 initialR{{cos(phi_rad), -sin(phi_rad), 0}, {sin(phi_rad), cos(phi_rad), 0}, {0, 0, 1}}; + MatrixF3x3 initialR{{std::cos(phi), -std::sin(phi), 0}, {std::sin(phi), std::cos(phi), 0}, {0, 0, 1}}; // The tilt angle given in the CSV files is with respect to a module that is facing // the beamline, meaning after R_initial is applied. From there we tilt the module according // to the rotation below. Note that because this tilt angle is not with respect to the X,Y,Z // axes and is instead around an arbitrary axis (defined from the rotation above) we have to apply // the Rodrigues' rotation formula - MatrixD3x3 rTilt = tangentialRotationMatrix(phi_rad, -tilt_rad); + MatrixF3x3 rTilt = tangentialRotationMatrix(phi, -tilt); - MatrixD3x3 finalR = rTilt * initialR; + MatrixF3x3 finalR = rTilt * initialR; return finalR; } // Calculates the transformed corners of each sensor - void transformSensorCorners(ModuleInfo& moduleInfo) { - auto module_z = moduleInfo.sensorCenterZ_cm; - auto module_rho = moduleInfo.sensorCenterRho_cm; - auto module_phi = moduleInfo.phi_rad; - auto sensor_spacing = moduleInfo.sensorSpacing_cm; - auto sensor_width = moduleInfo.meanWidth_cm; - auto sensor_length = moduleInfo.length_cm; + void transformSensorCorners(Module& module) { + auto module_z = module.centerZ; + auto module_rho = module.centerRho; + auto module_phi = module.centerPhi; + auto sensor_spacing = module.spacing; + auto sensor_width = module.meanWidth; + auto sensor_length = module.length; - auto module_x = module_rho * cos(module_phi); - auto module_y = module_rho * sin(module_phi); + auto module_x = module_rho * std::cos(module_phi); + auto module_y = module_rho * std::sin(module_phi); auto half_width = sensor_width / 2; auto half_length = sensor_length / 2; @@ -81,7 +81,7 @@ namespace lstgeometry { half_width += width_extension; half_length += length_extension; - MatrixD8x3 corners{{-half_spacing, -half_width, -half_length}, + MatrixF8x3 corners{{-half_spacing, -half_width, -half_length}, {-half_spacing, -half_width, half_length}, {-half_spacing, half_width, half_length}, {-half_spacing, half_width, -half_length}, @@ -90,46 +90,40 @@ namespace lstgeometry { {half_spacing, half_width, half_length}, {half_spacing, half_width, -half_length}}; - MatrixD3x3 rotation_matrix = - rotationMatrix(moduleInfo.tiltAngle_rad, moduleInfo.skewAngle_rad, moduleInfo.yawAngle_rad, moduleInfo.phi_rad); - MatrixD8x3 rotated_corners = (rotation_matrix * corners.transpose()).transpose(); + MatrixF3x3 rotation_matrix = rotationMatrix(module.tiltAngle, module.skewAngle, module.yawAngle, module.centerPhi); + MatrixF8x3 rotated_corners = (rotation_matrix * corners.transpose()).transpose(); - rotated_corners.rowwise() += RowVectorD3{module_x, module_y, module_z}; + rotated_corners.rowwise() += RowVectorF3{module_x, module_y, module_z}; // Coordinate reorder before saving (x,y,z)->(z,x,y) - moduleInfo.transformedCorners.col(0) = rotated_corners.col(2); - moduleInfo.transformedCorners.col(1) = rotated_corners.col(0); - moduleInfo.transformedCorners.col(2) = rotated_corners.col(1); + module.transformedCorners.col(0) = rotated_corners.col(2); + module.transformedCorners.col(1) = rotated_corners.col(0); + module.transformedCorners.col(2) = rotated_corners.col(1); } // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. - void assignCornersToSensors(std::unordered_map const& modules, - std::unordered_map& sensors) { - for (auto const& [detId, moduleInfo] : modules) { + void assignCornersToSensors(Modules const& modules, Sensors& sensors) { + for (auto const& [detId, module] : modules) { unsigned int module_det_id = detId; unsigned int sensor_det_id_1 = module_det_id + 1; unsigned int sensor_det_id_2 = module_det_id + 2; - auto& transformed_corners = moduleInfo.transformedCorners; - RowVectorD3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); - RowVectorD3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); - - double sensor1_center_z = sensors.at(sensor_det_id_1).centerZ_cm; - double sensor1_center_x = - sensors.at(sensor_det_id_1).centerRho_cm * cos(sensors.at(sensor_det_id_1).centerPhi_rad); - double sensor1_center_y = - sensors.at(sensor_det_id_1).centerRho_cm * sin(sensors.at(sensor_det_id_1).centerPhi_rad); - double sensor2_center_z = sensors.at(sensor_det_id_2).centerZ_cm; - double sensor2_center_x = - sensors.at(sensor_det_id_2).centerRho_cm * cos(sensors.at(sensor_det_id_2).centerPhi_rad); - double sensor2_center_y = - sensors.at(sensor_det_id_2).centerRho_cm * sin(sensors.at(sensor_det_id_2).centerPhi_rad); - - RowVectorD3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; - RowVectorD3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; - - double distance_to_sensor_1 = (centroid_sensor_1 - sensor_centroid_1).norm(); - double distance_to_sensor_2 = (centroid_sensor_2 - sensor_centroid_2).norm(); + auto& transformed_corners = module.transformedCorners; + RowVectorF3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); + RowVectorF3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); + + float sensor1_center_z = sensors.at(sensor_det_id_1).centerZ; + float sensor1_center_x = sensors.at(sensor_det_id_1).centerRho * cos(sensors.at(sensor_det_id_1).centerPhi); + float sensor1_center_y = sensors.at(sensor_det_id_1).centerRho * sin(sensors.at(sensor_det_id_1).centerPhi); + float sensor2_center_z = sensors.at(sensor_det_id_2).centerZ; + float sensor2_center_x = sensors.at(sensor_det_id_2).centerRho * cos(sensors.at(sensor_det_id_2).centerPhi); + float sensor2_center_y = sensors.at(sensor_det_id_2).centerRho * sin(sensors.at(sensor_det_id_2).centerPhi); + + RowVectorF3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; + RowVectorF3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; + + float distance_to_sensor_1 = (centroid_sensor_1 - sensor_centroid_1).norm(); + float distance_to_sensor_2 = (centroid_sensor_2 - sensor_centroid_2).norm(); if (distance_to_sensor_1 < distance_to_sensor_2) { sensors[sensor_det_id_1].corners = transformed_corners.topRows(4); diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index 8ac4d55b73720..40d5ed070938b 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -7,6 +7,8 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/Math.h" namespace lstgeometry { @@ -81,21 +83,19 @@ namespace lstgeometry { class DetectorGeometry { private: - std::unordered_map& sensors_; - std::vector avg_radii_; - std::vector avg_z_; + Sensors& sensors_; + std::vector avg_radii_; + std::vector avg_z_; std::unordered_map, boost::hash> barrel_lower_det_ids_; std::unordered_map, boost::hash> endcap_lower_det_ids_; public: - DetectorGeometry(std::unordered_map sensors, - std::vector avg_radii, - std::vector avg_z) + DetectorGeometry(Sensors sensors, std::vector avg_radii, std::vector avg_z) : sensors_(sensors), avg_radii_(avg_radii), avg_z_(avg_z) {} - MatrixD4x3 const& getCorners(unsigned int detId) const { return sensors_.at(detId).corners; } + MatrixF4x3 const& getCorners(unsigned int detId) const { return sensors_.at(detId).corners; } std::vector getDetIds(std::function&)> filter = [](const auto&) { return true; }) const { @@ -108,8 +108,7 @@ namespace lstgeometry { return detIds; } - void buildByLayer(std::unordered_map const& modules_info, - std::unordered_map const& sensors) { + void buildByLayer(Modules const& modules_info, Sensors const& sensors) { // Clear just in case they were already built barrel_lower_det_ids_.clear(); endcap_lower_det_ids_.clear(); @@ -133,7 +132,7 @@ namespace lstgeometry { }); for (auto detid : detids) { auto corners = getCorners(detid); - RowVectorD3 center = corners.colwise().mean(); + RowVectorF3 center = corners.colwise().mean(); center /= 4.; auto etaphi = getEtaPhi(center(1), center(2), center(0)); for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { @@ -152,7 +151,7 @@ namespace lstgeometry { }); for (auto detid : detids) { auto corners = getCorners(detid); - RowVectorD3 center = corners.colwise().mean(); + RowVectorF3 center = corners.colwise().mean(); center /= 4.; auto etaphi = getEtaPhi(center(1), center(2), center(0)); for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 8f5ab36132d3e..4b4fbce9a279f 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -3,22 +3,22 @@ #include "RecoTracker/LSTGeometry/interface/SlopeData.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" namespace lstgeometry { struct Geometry { - std::unordered_map sensors; + Sensors sensors; std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; PixelMap pixel_map; std::unordered_map> merged_line_connections; - Geometry(std::unordered_map &modules_info, - std::unordered_map &sensors_input, - std::vector const &average_r, - std::vector const &average_z, + Geometry(Modules &modules, + Sensors &sensors_input, + std::vector const &average_r, + std::vector const &average_z, double ptCut); }; diff --git a/RecoTracker/LSTGeometry/interface/Helix.h b/RecoTracker/LSTGeometry/interface/Helix.h index 2ce1278c269d9..3ceb9cc728a8b 100644 --- a/RecoTracker/LSTGeometry/interface/Helix.h +++ b/RecoTracker/LSTGeometry/interface/Helix.h @@ -4,12 +4,12 @@ namespace lstgeometry { struct Helix { - double center_x; - double center_y; - double center_z; - double radius; - double phi; - double lam; + float center_x; + float center_y; + float center_z; + float radius; + float phi; + float lam; int charge; }; diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 2e9a9b9485153..667d61c68c435 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -10,16 +10,14 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" namespace lstgeometry { - void writeSensorCentroids(std::unordered_map const& sensors, - std::string const& base_filename, - bool binary = true) { + void writeSensorCentroids(Sensors const& sensors, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); std::filesystem::create_directories(filepath.parent_path()); @@ -28,9 +26,9 @@ namespace lstgeometry { if (binary) { for (auto& [detid, sensor] : sensors) { - float x = sensor.centerX_cm; - float y = sensor.centerY_cm; - float z = sensor.centerZ_cm; + float x = sensor.centerX; + float y = sensor.centerY; + float z = sensor.centerZ; unsigned int moduleType = static_cast(sensor.moduleType); file.write(reinterpret_cast(&detid), sizeof(detid)); file.write(reinterpret_cast(&x), sizeof(x)); @@ -40,14 +38,14 @@ namespace lstgeometry { } } else { for (auto& [detid, sensor] : sensors) { - file << detid << "," << sensor.centerX_cm << "," << sensor.centerY_cm << "," << sensor.centerZ_cm << "," + file << detid << "," << sensor.centerX << "," << sensor.centerY << "," << sensor.centerZ << "," << static_cast(sensor.moduleType) << std::endl; } } } void writeSlopes(std::unordered_map const& slopes, - std::unordered_map const& sensors, + Sensors const& sensors, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); @@ -60,7 +58,7 @@ namespace lstgeometry { for (auto& [detid, slope] : slopes) { float drdz_slope = slope.drdz_slope; float dxdy_slope = slope.dxdy_slope; - float phi = sensors.at(detid).centerPhi_rad; + float phi = sensors.at(detid).centerPhi; file.write(reinterpret_cast(&detid), sizeof(detid)); if (drdz_slope != kDefaultSlope) { file.write(reinterpret_cast(&drdz_slope), sizeof(drdz_slope)); @@ -74,7 +72,7 @@ namespace lstgeometry { for (auto& [detid, slope] : slopes) { float drdz_slope = slope.drdz_slope; float dxdy_slope = slope.dxdy_slope; - float phi = sensors.at(detid).centerPhi_rad; + float phi = sensors.at(detid).centerPhi; file << detid << ","; if (drdz_slope != kDefaultSlope) { file << drdz_slope << "," << dxdy_slope << std::endl; diff --git a/RecoTracker/LSTGeometry/interface/Math.h b/RecoTracker/LSTGeometry/interface/Math.h index d9831e24c69cf..07104a65ec70f 100644 --- a/RecoTracker/LSTGeometry/interface/Math.h +++ b/RecoTracker/LSTGeometry/interface/Math.h @@ -78,9 +78,9 @@ namespace lstgeometry { return std::make_pair(eta, phi); } - Polygon getEtaPhiPolygon(MatrixDNx3 const& mod_boundaries, double refphi, double zshift = 0) { + Polygon getEtaPhiPolygon(MatrixFNx3 const& mod_boundaries, double refphi, double zshift = 0) { int npoints = mod_boundaries.rows(); - MatrixDNx2 mod_boundaries_etaphi(npoints, 2); + MatrixFNx2 mod_boundaries_etaphi(npoints, 2); for (int i = 0; i < npoints; ++i) { auto ref_etaphi = getEtaPhi(mod_boundaries(i, 1), mod_boundaries(i, 2), mod_boundaries(i, 0) + zshift, refphi); mod_boundaries_etaphi(i, 0) = ref_etaphi.first; @@ -97,13 +97,13 @@ namespace lstgeometry { return poly; } - bool moduleOverlapsInEtaPhi(MatrixD4x3 const& ref_mod_boundaries, - MatrixD4x3 const& tar_mod_boundaries, + bool moduleOverlapsInEtaPhi(MatrixF4x3 const& ref_mod_boundaries, + MatrixF4x3 const& tar_mod_boundaries, double refphi = 0, double zshift = 0) { - RowVectorD3 ref_center = ref_mod_boundaries.colwise().sum(); + RowVectorF3 ref_center = ref_mod_boundaries.colwise().sum(); ref_center /= 4.; - RowVectorD3 tar_center = tar_mod_boundaries.colwise().sum(); + RowVectorF3 tar_center = tar_mod_boundaries.colwise().sum(); tar_center /= 4.; double ref_center_phi = std::atan2(ref_center(2), ref_center(1)); @@ -112,8 +112,8 @@ namespace lstgeometry { if (std::fabs(phi_mpi_pi(ref_center_phi - tar_center_phi)) > std::numbers::pi_v / 2.) return false; - MatrixD4x2 ref_mod_boundaries_etaphi; - MatrixD4x2 tar_mod_boundaries_etaphi; + MatrixF4x2 ref_mod_boundaries_etaphi; + MatrixF4x2 tar_mod_boundaries_etaphi; for (int i = 0; i < 4; ++i) { auto ref_etaphi = @@ -127,7 +127,7 @@ namespace lstgeometry { } // Quick cut - RowVectorD2 diff = ref_mod_boundaries_etaphi.row(0) - tar_mod_boundaries_etaphi.row(0); + RowVectorF2 diff = ref_mod_boundaries_etaphi.row(0) - tar_mod_boundaries_etaphi.row(0); if (std::fabs(diff(0)) > 0.5) return false; if (std::fabs(phi_mpi_pi(diff(1))) > 1.) diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h new file mode 100644 index 0000000000000..befc251c19c20 --- /dev/null +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -0,0 +1,33 @@ +#ifndef RecoTracker_LSTGeometry_interface_Module_h +#define RecoTracker_LSTGeometry_interface_Module_h + +#include + +#include "RecoTracker/LSTGeometry/interface/Common.h" + +namespace lstgeometry { + + struct Module { + ModuleType moduleType; + SubDetector subdet; + Location location; + BarrelModuleTilt side; + unsigned int layer; + unsigned int ring; + bool isLower; + float centerRho; + float centerZ; + float centerPhi; + float tiltAngle; + float skewAngle; + float yawAngle; + float meanWidth; + float length; + float spacing; + MatrixF8x3 transformedCorners; + }; + + using Modules = std::unordered_map; +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTGeometry/interface/ModuleInfo.h b/RecoTracker/LSTGeometry/interface/ModuleInfo.h deleted file mode 100644 index 79f467c052069..0000000000000 --- a/RecoTracker/LSTGeometry/interface/ModuleInfo.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_ModuleInfo_h -#define RecoTracker_LSTGeometry_interface_ModuleInfo_h - -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" -#include "DataFormats/SiStripDetId/interface/SiStripEnums.h" - -#include "RecoTracker/LSTGeometry/interface/Common.h" - -namespace lstgeometry { - - struct ModuleInfo { - TrackerGeometry::ModuleType moduleType; - GeomDetEnumerators::SubDetector subdet; - GeomDetEnumerators::Location location; - Phase2Tracker::BarrelModuleTilt side; - unsigned int layer; - unsigned int ring; - bool isLower; - double sensorCenterRho_cm; - double sensorCenterZ_cm; - double tiltAngle_rad; - double skewAngle_rad; - double yawAngle_rad; - double phi_rad; - double meanWidth_cm; - double length_cm; - double sensorSpacing_cm; - MatrixD8x3 transformedCorners; - }; - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h index fd492ab929dd1..172c91195ede7 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h @@ -13,26 +13,26 @@ #include #include "RecoTracker/LSTGeometry/interface/Math.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" namespace lstgeometry { std::vector getStraightLineConnections(unsigned int ref_detid, - std::unordered_map const& modules_info, - std::unordered_map const& sensors, + Modules const& modules, + Sensors const& sensors, DetectorGeometry const& det_geom) { auto& sensor = sensors.at(ref_detid); - double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); + double refphi = std::atan2(sensor.centerY, sensor.centerX); - auto refmodule = modules_info.at(sensors.at(ref_detid).moduleDetId); + auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; unsigned short ref_subdet = refmodule.subdet; - auto etaphi = getEtaPhi(sensor.centerX_cm, sensor.centerY_cm, sensor.centerZ_cm); + auto etaphi = getEtaPhi(sensor.centerX, sensor.centerY, sensor.centerZ); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = @@ -85,7 +85,7 @@ namespace lstgeometry { for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto& sensor_target = sensors.at(tar_detid); - double tarphi = std::atan2(sensor_target.centerY_cm, sensor_target.centerX_cm); + double tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) continue; @@ -112,22 +112,22 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } - MatrixD4x3 boundsAfterCurved(unsigned int ref_detid, - std::unordered_map const& modules_info, - std::unordered_map const& sensors, + MatrixF4x3 boundsAfterCurved(unsigned int ref_detid, + Modules const& modules, + Sensors const& sensors, DetectorGeometry const& det_geom, double ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); auto& sensor = sensors.at(ref_detid); int charge = 1; - double theta = std::atan2(std::sqrt(sensor.centerX_cm * sensor.centerX_cm + sensor.centerY_cm * sensor.centerY_cm), - sensor.centerZ_cm); - double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); - auto refmodule = modules_info.at(sensors.at(ref_detid).moduleDetId); + double theta = + std::atan2(std::sqrt(sensor.centerX * sensor.centerX + sensor.centerY * sensor.centerY), sensor.centerZ); + double refphi = std::atan2(sensor.centerY, sensor.centerX); + auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; unsigned short ref_subdet = refmodule.subdet; - MatrixD4x3 next_layer_bound_points; + MatrixF4x3 next_layer_bound_points; for (int i = 0; i < bounds.rows(); i++) { Helix helix_p10 = constructHelixFromPoints(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); @@ -190,27 +190,27 @@ namespace lstgeometry { } std::vector getCurvedLineConnections(unsigned int ref_detid, - std::unordered_map const& modules_info, - std::unordered_map const& sensors, + Modules const& modules, + Sensors const& sensors, DetectorGeometry const& det_geom, double ptCut) { auto& sensor = sensors.at(ref_detid); - double refphi = std::atan2(sensor.centerY_cm, sensor.centerX_cm); + double refphi = std::atan2(sensor.centerY, sensor.centerX); - auto refmodule = modules_info.at(sensors.at(ref_detid).moduleDetId); + auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; unsigned short ref_subdet = refmodule.subdet; - auto etaphi = getEtaPhi(sensor.centerX_cm, sensor.centerY_cm, sensor.centerZ_cm); + auto etaphi = getEtaPhi(sensor.centerX, sensor.centerY, sensor.centerZ); auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); - auto next_layer_bound_points = boundsAfterCurved(ref_detid, modules_info, sensors, det_geom, ptCut); + auto next_layer_bound_points = boundsAfterCurved(ref_detid, modules, sensors, det_geom, ptCut); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -255,7 +255,7 @@ namespace lstgeometry { for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto& sensor_target = sensors.at(tar_detid); - double tarphi = std::atan2(sensor_target.centerY_cm, sensor_target.centerX_cm); + double tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) continue; diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index b8ae1ff61677b..58fb97ff5a6be 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -6,7 +6,7 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/SlopeData.h" @@ -22,8 +22,7 @@ namespace lstgeometry { // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. std::tuple, std::unordered_map> processCorners( - std::unordered_map const& modules_info, - std::unordered_map& sensors) { + Modules const& modules, Sensors const& sensors) { std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; @@ -34,7 +33,7 @@ namespace lstgeometry { SlopeData slope = calculateSlope(dx, dy, dz); - auto& module = modules_info.at(sensor.moduleDetId); + auto& module = modules.at(sensor.moduleDetId); auto location = module.location; bool is_tilted = module.side != Phase2Tracker::BarrelModuleTilt::flat; diff --git a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h index 8a2292d219774..56ac22d0d2ca5 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h +++ b/RecoTracker/LSTGeometry/interface/PixelMapMethods.h @@ -5,13 +5,11 @@ #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" namespace lstgeometry { - PixelMap computePixelMap(std::unordered_map const& modules_info, - DetectorGeometry const& det_geom, - double ptCut) { + PixelMap computePixelMap(Modules const& modules, DetectorGeometry const& det_geom, double ptCut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; @@ -28,11 +26,11 @@ namespace lstgeometry { // Loop over the detids and for each detid compute which superbins it is connected to for (auto detId : det_geom.getDetIds()) { - // Skip if the detId is not in the modules_info - if (!modules_info.contains(detId)) + // Skip if the detId is not in the modules + if (!modules.contains(detId)) continue; - auto module = modules_info.at(detId); + auto module = modules.at(detId); auto subdet = static_cast(module.subdet); auto layer = module.layer; if (layer > 2) diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index 4aca5810c0b3d..a2f6a8f13f465 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -1,6 +1,8 @@ #ifndef RecoTracker_LSTGeometry_interface_Sensor_h #define RecoTracker_LSTGeometry_interface_Sensor_h +#include + #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "RecoTracker/LSTGeometry/interface/Common.h" @@ -9,22 +11,21 @@ namespace lstgeometry { struct Sensor { unsigned int moduleDetId; - float centerRho_cm; - float centerZ_cm; - float centerPhi_rad; - MatrixD4x3 corners; + float centerRho; + float centerZ; + float centerPhi; + MatrixF4x3 corners; // Redundant, but convenient to have them - TrackerGeometry::ModuleType moduleType; - float centerX_cm; - float centerY_cm; + ModuleType moduleType; + float centerX; + float centerY; Sensor() = default; - Sensor(unsigned int moduleDetId, - float centerRho_cm, - float centerZ_cm, - float centerPhi_rad, - TrackerGeometry::ModuleType moduleType); + Sensor(unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, ModuleType moduleType); }; + + using Sensors = std::unordered_map; + } // namespace lstgeometry #endif diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index 1676aced25b41..e275607ab55fe 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -8,8 +8,8 @@ #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/ModuleInfo.h" #include "RecoTracker/LSTGeometry/interface/Geometry.h" #include @@ -51,11 +51,11 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac trackerGeom_ = &iRecord.get(geomToken_); trackerTopo_ = &iRecord.get(ttopoToken_); - std::unordered_map modules; - std::unordered_map sensors; + lstgeometry::Modules modules; + lstgeometry::Sensors sensors; - std::vector avg_r_cm(6, 0.0); - std::vector avg_z_cm(5, 0.0); + std::vector avg_r_cm(6, 0.0); + std::vector avg_z_cm(5, 0.0); std::vector avg_r_counter(6, 0); std::vector avg_z_counter(5, 0); @@ -75,9 +75,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const Bounds *b = &(surface).bounds(); const auto &position = surface.position(); - const double rho_cm = position.perp(); - const double z_cm = lstgeometry::roundCoordinate(position.z()); - const double phi_rad = lstgeometry::roundAngle(position.phi()); + const float rho_cm = position.perp(); + const float z_cm = lstgeometry::roundCoordinate(position.z()); + const float phi_rad = lstgeometry::roundAngle(position.phi()); if (det->isLeaf()) { // Leafs are the sensors @@ -99,16 +99,16 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const unsigned int ring = trackerTopo_->endcapRingP2(detId); const bool isLower = trackerTopo_->isLower(detId); - double tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); + float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); - double meanWidth_cm = b2->width(); - double length_cm = b2->length(); + float meanWidth_cm = b2->width(); + float length_cm = b2->length(); - double sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag(); + float sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag(); // Fix angles of some modules - if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { - tiltAngle_rad = std::numbers::pi_v / 2; + if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { + tiltAngle_rad = std::numbers::pi_v / 2; } else if (std::fabs(tiltAngle_rad) > 1e-3) { tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); } @@ -121,23 +121,23 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac avg_z_counter[layer - 1] += 1; } - lstgeometry::ModuleInfo module{moduleType, - subdet, - location, - side, - layer, - ring, - isLower, - rho_cm, - z_cm, - tiltAngle_rad, - 0.0, - 0.0, - phi_rad, - meanWidth_cm, - length_cm, - sensorSpacing_cm, - lstgeometry::MatrixD8x3::Zero()}; + lstgeometry::Module module{moduleType, + subdet, + location, + side, + layer, + ring, + isLower, + rho_cm, + z_cm, + phi_rad, + tiltAngle_rad, + 0.0, + 0.0, + meanWidth_cm, + length_cm, + sensorSpacing_cm, + lstgeometry::MatrixF8x3::Zero()}; modules[detid] = std::move(module); } diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc index a0b3359f901fa..baf0fd719bd4a 100644 --- a/RecoTracker/LSTGeometry/src/Common.cc +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -2,18 +2,18 @@ namespace lstgeometry { - double degToRad(double degrees) { return degrees * (std::numbers::pi_v / 180); } + float degToRad(float degrees) { return degrees * (std::numbers::pi_v / 180); } - double phi_mpi_pi(double phi) { - while (phi >= std::numbers::pi_v) - phi -= 2 * std::numbers::pi_v; - while (phi < -std::numbers::pi_v) - phi += 2 * std::numbers::pi_v; + float phi_mpi_pi(float phi) { + while (phi >= std::numbers::pi_v) + phi -= 2 * std::numbers::pi_v; + while (phi < -std::numbers::pi_v) + phi += 2 * std::numbers::pi_v; return phi; } - double roundAngle(double angle, double tol) { - const double pi = std::numbers::pi_v; + float roundAngle(float angle, float tol) { + const float pi = std::numbers::pi_v; if (std::fabs(angle) < tol) { return 0.0; } else if (std::fabs(angle - pi / 2) < tol) { @@ -26,7 +26,7 @@ namespace lstgeometry { return angle; } - double roundCoordinate(double coord, double tol) { + float roundCoordinate(float coord, float tol) { if (std::fabs(coord) < tol) { return 0.0; } diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 7d0ad2f4cbed3..2021e830ce86f 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -7,27 +7,27 @@ using namespace lstgeometry; -Geometry::Geometry(std::unordered_map &modules_info, - std::unordered_map &sensors_input, - std::vector const &average_r, - std::vector const &average_z, +Geometry::Geometry(Modules &modules, + Sensors &sensors_input, + std::vector const &average_r, + std::vector const &average_z, double ptCut) { - for (auto &[_, mod] : modules_info) + for (auto &[_, mod] : modules) transformSensorCorners(mod); - assignCornersToSensors(modules_info, sensors_input); + assignCornersToSensors(modules, sensors_input); - auto slopes = processCorners(modules_info, sensors_input); + auto slopes = processCorners(modules, sensors_input); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); auto det_geom = DetectorGeometry(sensors_input, average_r, average_z); - det_geom.buildByLayer(modules_info, sensors_input); + det_geom.buildByLayer(modules, sensors_input); - pixel_map = computePixelMap(modules_info, det_geom, ptCut); + pixel_map = computePixelMap(modules, det_geom, ptCut); - auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules_info, &sensors_input](const auto &x) { - auto mod = modules_info.at(sensors_input.at(x.first).moduleDetId); + auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules, &sensors_input](const auto &x) { + auto mod = modules.at(sensors_input.at(x.first).moduleDetId); // exclude the outermost modules that do not have connections to other modules return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && @@ -39,9 +39,8 @@ Geometry::Geometry(std::unordered_map &modules_info, std::unordered_map> curved_line_connections; for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, modules_info, sensors_input, det_geom); - curved_line_connections[ref_detid] = - getCurvedLineConnections(ref_detid, modules_info, sensors_input, det_geom, ptCut); + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, modules, sensors_input, det_geom); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, modules, sensors_input, det_geom, ptCut); } merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc index 8741ec3994b1c..5bcddab4995a7 100644 --- a/RecoTracker/LSTGeometry/src/Sensor.cc +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -4,16 +4,12 @@ using namespace lstgeometry; -Sensor::Sensor(unsigned int moduleDetId, - float centerRho_cm, - float centerZ_cm, - float centerPhi_rad, - TrackerGeometry::ModuleType moduleType) +Sensor::Sensor(unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, ModuleType moduleType) : moduleDetId(moduleDetId), - centerRho_cm(centerRho_cm), - centerZ_cm(centerZ_cm), - centerPhi_rad(centerPhi_rad), - corners(MatrixD4x3::Zero()), + centerRho(centerRho), + centerZ(centerZ), + centerPhi(centerPhi), + corners(MatrixF4x3::Zero()), moduleType(moduleType), - centerX_cm(centerRho_cm * std::cos(centerPhi_rad)), - centerY_cm(centerRho_cm * std::sin(centerPhi_rad)) {} + centerX(centerRho * std::cos(centerPhi)), + centerY(centerRho * std::sin(centerPhi)) {} From 90c2e79a30375a4c3d27f942822b4aa3343bb97b Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 25 Feb 2026 20:25:12 +0000 Subject: [PATCH 74/95] Temporary fix for segfault --- RecoTracker/LSTGeometry/interface/DetectorGeometry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index 40d5ed070938b..a8f4171d04803 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -83,7 +83,7 @@ namespace lstgeometry { class DetectorGeometry { private: - Sensors& sensors_; + Sensors sensors_; // TODO: Refactor to avoid a copy std::vector avg_radii_; std::vector avg_z_; std::unordered_map, boost::hash> From 25385e7ff5eca61f3ef2c5d3fe4cd3c59ba0767f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 26 Feb 2026 17:54:25 +0000 Subject: [PATCH 75/95] Moved more implementations to cc files --- RecoTracker/LSTCore/src/LSTESData.cc | 2 +- RecoTracker/LSTGeometry/interface/Common.h | 8 +- .../LSTGeometry/interface/DetectorGeometry.h | 288 ++---------------- RecoTracker/LSTGeometry/interface/Geometry.h | 3 +- RecoTracker/LSTGeometry/interface/Helix.h | 8 +- RecoTracker/LSTGeometry/interface/IO.h | 2 +- RecoTracker/LSTGeometry/interface/Math.h | 152 --------- RecoTracker/LSTGeometry/interface/ModuleMap.h | 22 ++ RecoTracker/LSTGeometry/interface/PixelMap.h | 5 + .../plugins/LSTGeometryESProducer.cc | 4 + RecoTracker/LSTGeometry/src/Common.cc | 6 + .../LSTGeometry/src/DetectorGeometry.cc | 278 +++++++++++++++++ RecoTracker/LSTGeometry/src/Geometry.cc | 26 +- RecoTracker/LSTGeometry/src/Helix.cc | 68 +++++ .../ModuleMapMethods.h => src/ModuleMap.cc} | 150 +++++++-- .../PixelMapMethods.h => src/PixelMap.cc} | 43 ++- .../LSTGeometry/test/DumpLSTGeometry.cc | 2 +- 17 files changed, 567 insertions(+), 500 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/Math.h create mode 100644 RecoTracker/LSTGeometry/interface/ModuleMap.h create mode 100644 RecoTracker/LSTGeometry/src/DetectorGeometry.cc create mode 100644 RecoTracker/LSTGeometry/src/Helix.cc rename RecoTracker/LSTGeometry/{interface/ModuleMapMethods.h => src/ModuleMap.cc} (64%) rename RecoTracker/LSTGeometry/{interface/PixelMapMethods.h => src/PixelMap.cc} (79%) diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 5d02f780fa52b..559d8e3902ca3 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -145,7 +145,7 @@ std::unique_ptr> lst::fillESDataHost(lstg tiltedGeometry.load(lstg.barrel_slopes); std::map> final_modulemap; - for (auto const& [detId, connections] : lstg.merged_line_connections) { + for (auto const& [detId, connections] : lstg.module_map) { final_modulemap[detId] = std::vector(connections.begin(), connections.end()); } moduleConnectionMap.load(final_modulemap); diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index a4dfec60b7559..f43f33d95dcc3 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -1,13 +1,14 @@ #ifndef RecoTracker_LSTGeometry_interface_Common_h #define RecoTracker_LSTGeometry_interface_Common_h +#include +#include +#include + #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" #include "DataFormats/SiStripDetId/interface/SiStripEnums.h" -#include -#include - namespace lstgeometry { using MatrixF3x3 = Eigen::Matrix; @@ -42,6 +43,7 @@ namespace lstgeometry { float phi_mpi_pi(float phi); float roundAngle(float angle, float tol = 1e-3); float roundCoordinate(float coord, float tol = 1e-3); + std::pair getEtaPhi(float x, float y, float z, float refphi = 0); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index a8f4171d04803..ce1e39b816dac 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -9,81 +9,14 @@ #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/Math.h" namespace lstgeometry { using LayerEtaBinPhiBinKey = std::tuple; - // We split modules into overlapping eta-phi bins so that it's easier to construct module maps - // These values are just guesses and can be optimized later - constexpr unsigned int kNEtaBins = 4; - constexpr double kEtaBinRad = std::numbers::pi_v / kNEtaBins; - constexpr unsigned int kNPhiBins = 6; - constexpr double kPhiBinWidth = 2 * std::numbers::pi_v / kNPhiBins; - - bool isInEtaPhiBin(double eta, double phi, unsigned int eta_bin, unsigned int phi_bin) { - double theta = 2. * std::atan(std::exp(-eta)); - - if (eta_bin == 0) { - if (theta > 3. * kEtaBinRad / 2.) - return false; - } else if (eta_bin == kNEtaBins - 1) { - if (theta < (2 * (kNEtaBins - 1) - 1) * kEtaBinRad / 2.) - return false; - } else if (theta < (2 * eta_bin - 1) * kEtaBinRad / 2. || theta > (2 * (eta_bin + 1) + 1) * kEtaBinRad / 2.) { - return false; - } - - double pi = std::numbers::pi_v; - if (phi_bin == 0) { - if (phi > -pi + kPhiBinWidth && phi < pi - kPhiBinWidth) - return false; - } else { - if (phi < -pi + (phi_bin - 1) * kPhiBinWidth || phi > -pi + (phi_bin + 1) * kPhiBinWidth) - return false; - } - - return true; - } - - std::pair getEtaPhiBins(double eta, double phi) { - double theta = 2. * std::atan(std::exp(-eta)); - - unsigned int eta_bin = 0; - if (theta <= kEtaBinRad) { - eta_bin = 0; - } else if (theta >= (kNEtaBins - 1) * kEtaBinRad) { - eta_bin = kNEtaBins - 1; - } else { - for (unsigned int i = 1; i < kNEtaBins - 1; i++) { - if (theta >= i * kEtaBinRad && theta <= (i + 1) * kEtaBinRad) { - eta_bin = i; - break; - } - } - } - - unsigned int phi_bin = 0; - double pi = std::numbers::pi_v; - - if (phi <= -pi + kPhiBinWidth / 2. || phi >= pi - kPhiBinWidth / 2.) { - phi_bin = 0; - } else { - for (unsigned int i = 1; i < kNPhiBins; i++) { - if (phi >= -pi + ((2 * i - 1) * kPhiBinWidth) / 2. && phi <= -pi + ((2 * i + 1) * kPhiBinWidth) / 2.) { - phi_bin = i; - break; - } - } - } - - return std::make_pair(eta_bin, phi_bin); - } - class DetectorGeometry { private: - Sensors sensors_; // TODO: Refactor to avoid a copy + Sensors sensors_; // TODO: Refactor to avoid a copy std::vector avg_radii_; std::vector avg_z_; std::unordered_map, boost::hash> @@ -92,219 +25,54 @@ namespace lstgeometry { endcap_lower_det_ids_; public: - DetectorGeometry(Sensors sensors, std::vector avg_radii, std::vector avg_z) - : sensors_(sensors), avg_radii_(avg_radii), avg_z_(avg_z) {} + DetectorGeometry(Sensors sensors, std::vector avg_radii, std::vector avg_z); - MatrixF4x3 const& getCorners(unsigned int detId) const { return sensors_.at(detId).corners; } + MatrixF4x3 const& getCorners(unsigned int detId) const; std::vector getDetIds(std::function&)> filter = - [](const auto&) { return true; }) const { - std::vector detIds; - for (const auto& entry : sensors_) { - if (filter(entry)) { - detIds.push_back(entry.first); - } - } - return detIds; - } + [](const auto&) { return true; }) const; - void buildByLayer(Modules const& modules_info, Sensors const& sensors) { - // Clear just in case they were already built - barrel_lower_det_ids_.clear(); - endcap_lower_det_ids_.clear(); - - // Initialize all vectors - for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { - for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { - for (unsigned int layer = 1; layer < 7; layer++) { - barrel_lower_det_ids_[{layer, etabin, phibin}] = {}; - } - for (unsigned int layer = 1; layer < 6; layer++) { - endcap_lower_det_ids_[{layer, etabin, phibin}] = {}; - } - } - } - - for (unsigned int layer = 1; layer < 7; layer++) { - auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { - auto& m = modules_info.at(sensors.at(x.first).moduleDetId); - return m.subdet == 5 && m.layer == layer && m.isLower; - }); - for (auto detid : detids) { - auto corners = getCorners(detid); - RowVectorF3 center = corners.colwise().mean(); - center /= 4.; - auto etaphi = getEtaPhi(center(1), center(2), center(0)); - for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { - for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { - if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { - barrel_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); - } - } - } - } - } - for (unsigned int layer = 1; layer < 6; layer++) { - auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { - auto& m = modules_info.at(sensors.at(x.first).moduleDetId); - return m.subdet == 4 && m.layer == layer && m.isLower; - }); - for (auto detid : detids) { - auto corners = getCorners(detid); - RowVectorF3 center = corners.colwise().mean(); - center /= 4.; - auto etaphi = getEtaPhi(center(1), center(2), center(0)); - for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { - for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { - if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { - endcap_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); - } - } - } - } - } - } + void buildByLayer(Modules const& modules_info, Sensors const& sensors); std::vector const& getBarrelLayerDetIds(unsigned int layer, unsigned int etabin, - unsigned int phibin) const { - return barrel_lower_det_ids_.at({layer, etabin, phibin}); - } + unsigned int phibin) const; std::vector const& getEndcapLayerDetIds(unsigned int layer, unsigned int etabin, - unsigned int phibin) const { - return endcap_lower_det_ids_.at({layer, etabin, phibin}); - } + unsigned int phibin) const; + + float getBarrelLayerAverageRadius(unsigned int layer) const; - double getBarrelLayerAverageRadius(unsigned int layer) const { return avg_radii_[layer - 1]; } + float getEndcapLayerAverageAbsZ(unsigned int layer) const; - double getEndcapLayerAverageAbsZ(unsigned int layer) const { return avg_z_[layer - 1]; } + float getMinR(unsigned int detId) const; - double getMinR(unsigned int detId) const { - auto const& corners = getCorners(detId); - double minR = std::numeric_limits::max(); - for (int i = 0; i < corners.rows(); i++) { - double x = corners(i, 1); - double y = corners(i, 2); - minR = std::min(minR, std::sqrt(x * x + y * y)); - } - return minR; - } + float getMaxR(unsigned int detId) const; - double getMaxR(unsigned int detId) const { - auto const& corners = getCorners(detId); - double maxR = std::numeric_limits::min(); - for (int i = 0; i < corners.rows(); i++) { - double x = corners(i, 1); - double y = corners(i, 2); - maxR = std::max(maxR, std::sqrt(x * x + y * y)); - } - return maxR; - } + float getMinZ(unsigned int detId) const; - double getMinZ(unsigned int detId) const { - auto const& corners = getCorners(detId); - double minZ = std::numeric_limits::max(); - for (int i = 0; i < corners.rows(); i++) { - double z = corners(i, 0); - minZ = std::min(minZ, z); - } - return minZ; - } + float getMaxZ(unsigned int detId) const; - double getMaxZ(unsigned int detId) const { - auto const& corners = getCorners(detId); - double maxZ = std::numeric_limits::lowest(); - for (int i = 0; i < corners.rows(); i++) { - double z = corners(i, 0); - maxZ = std::max(maxZ, z); - } - return maxZ; - } + float getMinPhi(unsigned int detId) const; - double getMinPhi(unsigned int detId) const { - auto const& corners = getCorners(detId); - double minPhi = std::numeric_limits::max(); - double minPosPhi = std::numeric_limits::max(); - double minNegPhi = std::numeric_limits::max(); - unsigned int nPos = 0; - unsigned int nOverPi2 = 0; - for (int i = 0; i < corners.rows(); i++) { - double phi = phi_mpi_pi(std::numbers::pi_v + std::atan2(-corners(i, 2), -corners(i, 1))); - minPhi = std::min(minPhi, phi); - if (phi > 0) { - minPosPhi = std::min(minPosPhi, phi); - nPos++; - } else { - minNegPhi = std::min(minNegPhi, phi); - } - if (std::fabs(phi) > std::numbers::pi_v / 2.) { - nOverPi2++; - } - } - if (nPos == 4 || nPos == 0) - return minPhi; - if (nOverPi2 == 4) - return minPosPhi; - return minPhi; - } + float getMaxPhi(unsigned int detId) const; - double getMaxPhi(unsigned int detId) const { - auto const& corners = getCorners(detId); - double maxPhi = std::numeric_limits::lowest(); - double maxPosPhi = std::numeric_limits::lowest(); - double maxNegPhi = std::numeric_limits::lowest(); - unsigned int nPos = 0; - unsigned int nOverPi2 = 0; - for (int i = 0; i < corners.rows(); i++) { - double phi = phi_mpi_pi(std::numbers::pi_v + std::atan2(-corners(i, 2), -corners(i, 1))); - maxPhi = std::max(maxPhi, phi); - if (phi > 0) { - maxPosPhi = std::max(maxPosPhi, phi); - nPos++; - } else { - maxNegPhi = std::max(maxNegPhi, phi); - } - if (std::fabs(phi) > std::numbers::pi_v / 2.) { - nOverPi2++; - } - } - if (nPos == 4 || nPos == 0) - return maxPhi; - if (nOverPi2 == 4) - return maxNegPhi; - return maxPhi; - } + std::pair getCompatibleEtaRange(unsigned int detId, float zmin_bound, float zmax_bound) const; - std::pair getCompatibleEtaRange(unsigned int detId, double zmin_bound, double zmax_bound) const { - double minr = getMinR(detId); - double maxr = getMaxR(detId); - double minz = getMinZ(detId); - double maxz = getMaxZ(detId); - double mineta = -std::log(std::tan(std::atan2(minz > 0 ? maxr : minr, minz - zmin_bound) / 2.)); - double maxeta = -std::log(std::tan(std::atan2(maxz > 0 ? minr : maxr, maxz - zmax_bound) / 2.)); + std::pair, std::pair> getCompatiblePhiRange(unsigned int detId, + float ptmin, + float ptmax) const; - if (maxeta < mineta) - std::swap(maxeta, mineta); - return std::make_pair(mineta, maxeta); - } + // We split modules into overlapping eta-phi bins so that it's easier to construct module maps + // These values are just guesses and can be optimized later + static constexpr unsigned int kNEtaBins = 4; + static constexpr float kEtaBinRad = std::numbers::pi_v / kNEtaBins; + static constexpr unsigned int kNPhiBins = 6; + static constexpr float kPhiBinWidth = 2 * std::numbers::pi_v / kNPhiBins; - std::pair, std::pair> getCompatiblePhiRange(unsigned int detId, - double ptmin, - double ptmax) const { - double minr = getMinR(detId); - double maxr = getMaxR(detId); - double minphi = getMinPhi(detId); - double maxphi = getMaxPhi(detId); - double A = k2Rinv1GeVf * kB / 2.; - double pos_q_phi_lo_bound = phi_mpi_pi(A * minr / ptmax + minphi); - double pos_q_phi_hi_bound = phi_mpi_pi(A * maxr / ptmin + maxphi); - double neg_q_phi_lo_bound = phi_mpi_pi(-A * maxr / ptmin + minphi); - double neg_q_phi_hi_bound = phi_mpi_pi(-A * minr / ptmax + maxphi); - return std::make_pair(std::make_pair(pos_q_phi_lo_bound, pos_q_phi_hi_bound), - std::make_pair(neg_q_phi_lo_bound, neg_q_phi_hi_bound)); - } + static bool isInEtaPhiBin(float eta, float phi, unsigned int eta_bin, unsigned int phi_bin); + static std::pair getEtaPhiBins(float eta, float phi); }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 4b4fbce9a279f..6eca418b720c0 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -3,6 +3,7 @@ #include "RecoTracker/LSTGeometry/interface/SlopeData.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" +#include "RecoTracker/LSTGeometry/interface/ModuleMap.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" @@ -13,7 +14,7 @@ namespace lstgeometry { std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; PixelMap pixel_map; - std::unordered_map> merged_line_connections; + ModuleMap module_map; Geometry(Modules &modules, Sensors &sensors_input, diff --git a/RecoTracker/LSTGeometry/interface/Helix.h b/RecoTracker/LSTGeometry/interface/Helix.h index 3ceb9cc728a8b..e60a20c89137d 100644 --- a/RecoTracker/LSTGeometry/interface/Helix.h +++ b/RecoTracker/LSTGeometry/interface/Helix.h @@ -9,8 +9,14 @@ namespace lstgeometry { float center_z; float radius; float phi; - float lam; + float lambda; int charge; + + Helix(float center_x, float center_y, float center_z, float radius, float phi, float lam, int charge); + Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge); + + std::tuple pointFromRadius(float target_r); + std::tuple pointFromZ(float target_z); }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 667d61c68c435..ca09283852963 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -12,7 +12,7 @@ #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" +#include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" namespace lstgeometry { diff --git a/RecoTracker/LSTGeometry/interface/Math.h b/RecoTracker/LSTGeometry/interface/Math.h deleted file mode 100644 index 07104a65ec70f..0000000000000 --- a/RecoTracker/LSTGeometry/interface/Math.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_Math_h -#define RecoTracker_LSTGeometry_interface_Math_h - -#include - -#include -#include -#include - -#include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Helix.h" - -namespace lstgeometry { - - using Point = boost::geometry::model::d2::point_xy; - using Polygon = boost::geometry::model::polygon; - - // Clarification : phi was derived assuming a negatively charged particle would start - // at the first quadrant. However the way signs are set up in the get_track_point function - // implies the particle actually starts out in the fourth quadrant, and phi is measured from - // the y axis as opposed to x axis in the expression provided in this function. Hence I tucked - // in an extra pi/2 to account for these effects - Helix constructHelixFromPoints( - double pt, double vx, double vy, double vz, double mx, double my, double mz, int charge) { - double radius = pt / (k2Rinv1GeVf * kB); - - double t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * radius)); - double phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + - ((vy - my) / (vx - mx) < 0) * (std::numbers::pi_v)+charge * t / 2. + - (my - vy < 0) * (std::numbers::pi_v / 2.) - (my - vy > 0) * (std::numbers::pi_v / 2.); - - double cx = vx + charge * radius * std::sin(phi); - double cy = vy - charge * radius * std::cos(phi); - double cz = vz; - double lam = std::atan((mz - vz) / (radius * t)); - - return Helix(cx, cy, cz, radius, phi, lam, charge); - } - - std::tuple getHelixPointFromRadius(Helix const& helix, double target_r) { - auto objective_function = [&helix, target_r](double t) { - double x = helix.center_x - helix.charge * helix.radius * std::sin(helix.phi - helix.charge * t); - double y = helix.center_y + helix.charge * helix.radius * std::cos(helix.phi - helix.charge * t); - return std::fabs(std::sqrt(x * x + y * y) - target_r); - }; - int bits = std::numeric_limits::digits; - auto result = boost::math::tools::brent_find_minima(objective_function, 0.0, std::numbers::pi_v, bits); - double t = result.first; - - double x = helix.center_x - helix.charge * helix.radius * std::sin(helix.phi - helix.charge * t); - double y = helix.center_y + helix.charge * helix.radius * std::cos(helix.phi - helix.charge * t); - double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; - double r = std::sqrt(x * x + y * y); - - return std::make_tuple(x, y, z, r); - } - - std::tuple getHelixPointFromZ(Helix const& helix, double target_z) { - auto objective_function = [&helix, target_z](double t) { - double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; - return std::fabs(z - target_z); - }; - int bits = std::numeric_limits::digits; - auto result = boost::math::tools::brent_find_minima(objective_function, 0.0, std::numbers::pi_v, bits); - double t = result.first; - - double x = helix.center_x - helix.charge * helix.radius * std::sin(helix.phi - helix.charge * t); - double y = helix.center_y + helix.charge * helix.radius * std::cos(helix.phi - helix.charge * t); - double z = helix.center_z + helix.radius * std::tan(helix.lam) * t; - double r = std::sqrt(x * x + y * y); - - return std::make_tuple(x, y, z, r); - } - - std::pair getEtaPhi(double x, double y, double z, double refphi = 0) { - double phi = phi_mpi_pi(std::atan2(y, x) - refphi); - double eta = std::copysign(-std::log(std::tan(std::atan(std::sqrt(x * x + y * y) / std::abs(z)) / 2.)), z); - return std::make_pair(eta, phi); - } - - Polygon getEtaPhiPolygon(MatrixFNx3 const& mod_boundaries, double refphi, double zshift = 0) { - int npoints = mod_boundaries.rows(); - MatrixFNx2 mod_boundaries_etaphi(npoints, 2); - for (int i = 0; i < npoints; ++i) { - auto ref_etaphi = getEtaPhi(mod_boundaries(i, 1), mod_boundaries(i, 2), mod_boundaries(i, 0) + zshift, refphi); - mod_boundaries_etaphi(i, 0) = ref_etaphi.first; - mod_boundaries_etaphi(i, 1) = ref_etaphi.second; - } - - Polygon poly; - // <= because we need to close the polygon with the first point - for (int i = 0; i <= npoints; ++i) { - boost::geometry::append(poly, - Point(mod_boundaries_etaphi(i % npoints, 0), mod_boundaries_etaphi(i % npoints, 1))); - } - boost::geometry::correct(poly); - return poly; - } - - bool moduleOverlapsInEtaPhi(MatrixF4x3 const& ref_mod_boundaries, - MatrixF4x3 const& tar_mod_boundaries, - double refphi = 0, - double zshift = 0) { - RowVectorF3 ref_center = ref_mod_boundaries.colwise().sum(); - ref_center /= 4.; - RowVectorF3 tar_center = tar_mod_boundaries.colwise().sum(); - tar_center /= 4.; - - double ref_center_phi = std::atan2(ref_center(2), ref_center(1)); - double tar_center_phi = std::atan2(tar_center(2), tar_center(1)); - - if (std::fabs(phi_mpi_pi(ref_center_phi - tar_center_phi)) > std::numbers::pi_v / 2.) - return false; - - MatrixF4x2 ref_mod_boundaries_etaphi; - MatrixF4x2 tar_mod_boundaries_etaphi; - - for (int i = 0; i < 4; ++i) { - auto ref_etaphi = - getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0) + zshift, refphi); - auto tar_etaphi = - getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0) + zshift, refphi); - ref_mod_boundaries_etaphi(i, 0) = ref_etaphi.first; - ref_mod_boundaries_etaphi(i, 1) = ref_etaphi.second; - tar_mod_boundaries_etaphi(i, 0) = tar_etaphi.first; - tar_mod_boundaries_etaphi(i, 1) = tar_etaphi.second; - } - - // Quick cut - RowVectorF2 diff = ref_mod_boundaries_etaphi.row(0) - tar_mod_boundaries_etaphi.row(0); - if (std::fabs(diff(0)) > 0.5) - return false; - if (std::fabs(phi_mpi_pi(diff(1))) > 1.) - return false; - - Polygon ref_poly, tar_poly; - - // <= 4 because we need to close the polygon with the first point - for (int i = 0; i <= 4; ++i) { - boost::geometry::append(ref_poly, - Point(ref_mod_boundaries_etaphi(i % 4, 0), ref_mod_boundaries_etaphi(i % 4, 1))); - boost::geometry::append(tar_poly, - Point(tar_mod_boundaries_etaphi(i % 4, 0), tar_mod_boundaries_etaphi(i % 4, 1))); - } - boost::geometry::correct(ref_poly); - boost::geometry::correct(tar_poly); - - return boost::geometry::intersects(ref_poly, tar_poly); - } - -} // namespace lstgeometry -#endif diff --git a/RecoTracker/LSTGeometry/interface/ModuleMap.h b/RecoTracker/LSTGeometry/interface/ModuleMap.h new file mode 100644 index 0000000000000..a86cd80631842 --- /dev/null +++ b/RecoTracker/LSTGeometry/interface/ModuleMap.h @@ -0,0 +1,22 @@ +#ifndef RecoTracker_LSTGeometry_interface_ModuleMapMethods_h +#define RecoTracker_LSTGeometry_interface_ModuleMapMethods_h + +#include +#include + +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" + +namespace lstgeometry { + + using ModuleMap = std::unordered_map>; + + ModuleMap buildModuleMap(Modules const& modules, + Sensors const& sensors, + DetectorGeometry const& det_geom, + float pt_cut); + +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTGeometry/interface/PixelMap.h b/RecoTracker/LSTGeometry/interface/PixelMap.h index 41741a63f7578..c2d9ab7888158 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMap.h +++ b/RecoTracker/LSTGeometry/interface/PixelMap.h @@ -6,6 +6,9 @@ #include #include +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" +#include "RecoTracker/LSTGeometry/interface/Module.h" + namespace lstgeometry { using LayerSubdetChargeKey = std::tuple; @@ -14,6 +17,8 @@ namespace lstgeometry { boost::hash>; using PixelMap = LayerSubdetChargeMap; + PixelMap buildPixelMap(Modules const& modules, DetectorGeometry const& det_geom, float pt_cut); + } // namespace lstgeometry #endif diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index e275607ab55fe..44d4990225f8c 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -15,6 +15,7 @@ #include #include #include +#include /////////////////////// remove class LSTGeometryESProducer : public edm::ESProducer { public: @@ -99,6 +100,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const unsigned int ring = trackerTopo_->endcapRingP2(detId); const bool isLower = trackerTopo_->isLower(detId); + std::cout << "Processing detId " << detid << " with subdet " << subdet << " layer " << layer << " ring " << ring + << " side " << side << std::endl; ////////////////////// remove + float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); float meanWidth_cm = b2->width(); diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc index baf0fd719bd4a..df92dc20baeca 100644 --- a/RecoTracker/LSTGeometry/src/Common.cc +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -33,4 +33,10 @@ namespace lstgeometry { return coord; } + std::pair getEtaPhi(float x, float y, float z, float refphi) { + float phi = phi_mpi_pi(std::atan2(y, x) - refphi); + float eta = std::copysign(-std::log(std::tan(std::atan(std::sqrt(x * x + y * y) / std::abs(z)) / 2.)), z); + return std::make_pair(eta, phi); + } + } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc new file mode 100644 index 0000000000000..25d1d593633a8 --- /dev/null +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -0,0 +1,278 @@ +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" + +namespace lstgeometry { + + bool DetectorGeometry::isInEtaPhiBin(float eta, float phi, unsigned int eta_bin, unsigned int phi_bin) { + float theta = 2. * std::atan(std::exp(-eta)); + + if (eta_bin == 0) { + if (theta > 3. * kEtaBinRad / 2.) + return false; + } else if (eta_bin == kNEtaBins - 1) { + if (theta < (2 * (kNEtaBins - 1) - 1) * kEtaBinRad / 2.) + return false; + } else if (theta < (2 * eta_bin - 1) * kEtaBinRad / 2. || theta > (2 * (eta_bin + 1) + 1) * kEtaBinRad / 2.) { + return false; + } + + float pi = std::numbers::pi_v; + if (phi_bin == 0) { + if (phi > -pi + kPhiBinWidth && phi < pi - kPhiBinWidth) + return false; + } else { + if (phi < -pi + (phi_bin - 1) * kPhiBinWidth || phi > -pi + (phi_bin + 1) * kPhiBinWidth) + return false; + } + + return true; + } + + std::pair DetectorGeometry::getEtaPhiBins(float eta, float phi) { + float theta = 2. * std::atan(std::exp(-eta)); + + unsigned int eta_bin = 0; + if (theta <= kEtaBinRad) { + eta_bin = 0; + } else if (theta >= (kNEtaBins - 1) * kEtaBinRad) { + eta_bin = kNEtaBins - 1; + } else { + for (unsigned int i = 1; i < kNEtaBins - 1; i++) { + if (theta >= i * kEtaBinRad && theta <= (i + 1) * kEtaBinRad) { + eta_bin = i; + break; + } + } + } + + unsigned int phi_bin = 0; + float pi = std::numbers::pi_v; + + if (phi <= -pi + kPhiBinWidth / 2. || phi >= pi - kPhiBinWidth / 2.) { + phi_bin = 0; + } else { + for (unsigned int i = 1; i < kNPhiBins; i++) { + if (phi >= -pi + ((2 * i - 1) * kPhiBinWidth) / 2. && phi <= -pi + ((2 * i + 1) * kPhiBinWidth) / 2.) { + phi_bin = i; + break; + } + } + } + + return std::make_pair(eta_bin, phi_bin); + } + + DetectorGeometry::DetectorGeometry(Sensors sensors, std::vector avg_radii, std::vector avg_z) + : sensors_(sensors), avg_radii_(avg_radii), avg_z_(avg_z) {} + + MatrixF4x3 const& DetectorGeometry::getCorners(unsigned int detId) const { return sensors_.at(detId).corners; } + + std::vector DetectorGeometry::getDetIds( + std::function&)> filter) const { + std::vector detIds; + for (const auto& entry : sensors_) { + if (filter(entry)) { + detIds.push_back(entry.first); + } + } + return detIds; + } + + void DetectorGeometry::buildByLayer(Modules const& modules_info, Sensors const& sensors) { + // Clear just in case they were already built + barrel_lower_det_ids_.clear(); + endcap_lower_det_ids_.clear(); + + // Initialize all vectors + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + for (unsigned int layer = 1; layer < 7; layer++) { + barrel_lower_det_ids_[{layer, etabin, phibin}] = {}; + } + for (unsigned int layer = 1; layer < 6; layer++) { + endcap_lower_det_ids_[{layer, etabin, phibin}] = {}; + } + } + } + + for (unsigned int layer = 1; layer < 7; layer++) { + auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { + auto& m = modules_info.at(sensors.at(x.first).moduleDetId); + return m.subdet == 5 && m.layer == layer && m.isLower; + }); + for (auto detid : detids) { + auto corners = getCorners(detid); + RowVectorF3 center = corners.colwise().mean(); + center /= 4.; + auto etaphi = getEtaPhi(center(1), center(2), center(0)); + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { + barrel_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); + } + } + } + } + } + for (unsigned int layer = 1; layer < 6; layer++) { + auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { + auto& m = modules_info.at(sensors.at(x.first).moduleDetId); + return m.subdet == 4 && m.layer == layer && m.isLower; + }); + for (auto detid : detids) { + auto corners = getCorners(detid); + RowVectorF3 center = corners.colwise().mean(); + center /= 4.; + auto etaphi = getEtaPhi(center(1), center(2), center(0)); + for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { + for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { + if (isInEtaPhiBin(etaphi.first, etaphi.second, etabin, phibin)) { + endcap_lower_det_ids_[{layer, etabin, phibin}].push_back(detid); + } + } + } + } + } + } + + std::vector const& DetectorGeometry::getBarrelLayerDetIds(unsigned int layer, + unsigned int etabin, + unsigned int phibin) const { + return barrel_lower_det_ids_.at({layer, etabin, phibin}); + } + + std::vector const& DetectorGeometry::getEndcapLayerDetIds(unsigned int layer, + unsigned int etabin, + unsigned int phibin) const { + return endcap_lower_det_ids_.at({layer, etabin, phibin}); + } + + float DetectorGeometry::getBarrelLayerAverageRadius(unsigned int layer) const { return avg_radii_[layer - 1]; } + + float DetectorGeometry::getEndcapLayerAverageAbsZ(unsigned int layer) const { return avg_z_[layer - 1]; } + + float DetectorGeometry::getMinR(unsigned int detId) const { + auto const& corners = getCorners(detId); + float minR = std::numeric_limits::max(); + for (int i = 0; i < corners.rows(); i++) { + float x = corners(i, 1); + float y = corners(i, 2); + minR = std::min(minR, std::sqrt(x * x + y * y)); + } + return minR; + } + + float DetectorGeometry::getMaxR(unsigned int detId) const { + auto const& corners = getCorners(detId); + float maxR = std::numeric_limits::min(); + for (int i = 0; i < corners.rows(); i++) { + float x = corners(i, 1); + float y = corners(i, 2); + maxR = std::max(maxR, std::sqrt(x * x + y * y)); + } + return maxR; + } + + float DetectorGeometry::getMinZ(unsigned int detId) const { + auto const& corners = getCorners(detId); + float minZ = std::numeric_limits::max(); + for (int i = 0; i < corners.rows(); i++) { + float z = corners(i, 0); + minZ = std::min(minZ, z); + } + return minZ; + } + + float DetectorGeometry::getMaxZ(unsigned int detId) const { + auto const& corners = getCorners(detId); + float maxZ = std::numeric_limits::lowest(); + for (int i = 0; i < corners.rows(); i++) { + float z = corners(i, 0); + maxZ = std::max(maxZ, z); + } + return maxZ; + } + + float DetectorGeometry::getMinPhi(unsigned int detId) const { + auto const& corners = getCorners(detId); + float minPhi = std::numeric_limits::max(); + float minPosPhi = std::numeric_limits::max(); + float minNegPhi = std::numeric_limits::max(); + unsigned int nPos = 0; + unsigned int nOverPi2 = 0; + for (int i = 0; i < corners.rows(); i++) { + float phi = phi_mpi_pi(std::numbers::pi_v + std::atan2(-corners(i, 2), -corners(i, 1))); + minPhi = std::min(minPhi, phi); + if (phi > 0) { + minPosPhi = std::min(minPosPhi, phi); + nPos++; + } else { + minNegPhi = std::min(minNegPhi, phi); + } + if (std::fabs(phi) > std::numbers::pi_v / 2.) { + nOverPi2++; + } + } + if (nPos == 4 || nPos == 0) + return minPhi; + if (nOverPi2 == 4) + return minPosPhi; + return minPhi; + } + + float DetectorGeometry::getMaxPhi(unsigned int detId) const { + auto const& corners = getCorners(detId); + float maxPhi = std::numeric_limits::lowest(); + float maxPosPhi = std::numeric_limits::lowest(); + float maxNegPhi = std::numeric_limits::lowest(); + unsigned int nPos = 0; + unsigned int nOverPi2 = 0; + for (int i = 0; i < corners.rows(); i++) { + float phi = phi_mpi_pi(std::numbers::pi_v + std::atan2(-corners(i, 2), -corners(i, 1))); + maxPhi = std::max(maxPhi, phi); + if (phi > 0) { + maxPosPhi = std::max(maxPosPhi, phi); + nPos++; + } else { + maxNegPhi = std::max(maxNegPhi, phi); + } + if (std::fabs(phi) > std::numbers::pi_v / 2.) { + nOverPi2++; + } + } + if (nPos == 4 || nPos == 0) + return maxPhi; + if (nOverPi2 == 4) + return maxNegPhi; + return maxPhi; + } + + std::pair DetectorGeometry::getCompatibleEtaRange(unsigned int detId, + float zmin_bound, + float zmax_bound) const { + float minr = getMinR(detId); + float maxr = getMaxR(detId); + float minz = getMinZ(detId); + float maxz = getMaxZ(detId); + float mineta = -std::log(std::tan(std::atan2(minz > 0 ? maxr : minr, minz - zmin_bound) / 2.)); + float maxeta = -std::log(std::tan(std::atan2(maxz > 0 ? minr : maxr, maxz - zmax_bound) / 2.)); + + if (maxeta < mineta) + std::swap(maxeta, mineta); + return std::make_pair(mineta, maxeta); + } + + std::pair, std::pair> DetectorGeometry::getCompatiblePhiRange( + unsigned int detId, float ptmin, float ptmax) const { + float minr = getMinR(detId); + float maxr = getMaxR(detId); + float minphi = getMinPhi(detId); + float maxphi = getMaxPhi(detId); + float A = k2Rinv1GeVf * kB / 2.; + float pos_q_phi_lo_bound = phi_mpi_pi(A * minr / ptmax + minphi); + float pos_q_phi_hi_bound = phi_mpi_pi(A * maxr / ptmin + maxphi); + float neg_q_phi_lo_bound = phi_mpi_pi(-A * maxr / ptmin + minphi); + float neg_q_phi_hi_bound = phi_mpi_pi(-A * minr / ptmax + maxphi); + return std::make_pair(std::make_pair(pos_q_phi_lo_bound, pos_q_phi_hi_bound), + std::make_pair(neg_q_phi_lo_bound, neg_q_phi_hi_bound)); + } +} // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 2021e830ce86f..8b2d3a8a87d1f 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -2,8 +2,6 @@ #include "RecoTracker/LSTGeometry/interface/CornerMethods.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" -#include "RecoTracker/LSTGeometry/interface/PixelMapMethods.h" -#include "RecoTracker/LSTGeometry/interface/ModuleMapMethods.h" using namespace lstgeometry; @@ -11,7 +9,7 @@ Geometry::Geometry(Modules &modules, Sensors &sensors_input, std::vector const &average_r, std::vector const &average_z, - double ptCut) { + double pt_cut) { for (auto &[_, mod] : modules) transformSensorCorners(mod); @@ -24,25 +22,9 @@ Geometry::Geometry(Modules &modules, auto det_geom = DetectorGeometry(sensors_input, average_r, average_z); det_geom.buildByLayer(modules, sensors_input); - pixel_map = computePixelMap(modules, det_geom, ptCut); - - auto detids_etaphi_layer_ref = det_geom.getDetIds([&modules, &sensors_input](const auto &x) { - auto mod = modules.at(sensors_input.at(x.first).moduleDetId); - // exclude the outermost modules that do not have connections to other modules - return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || - (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && - !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && - !(mod.ring == 12 && mod.layer == 4))); - }); - - std::unordered_map> straight_line_connections; - std::unordered_map> curved_line_connections; - - for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, modules, sensors_input, det_geom); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, modules, sensors_input, det_geom, ptCut); - } - merged_line_connections = mergeLineConnections({&straight_line_connections, &curved_line_connections}); + pixel_map = buildPixelMap(modules, det_geom, pt_cut); + + module_map = buildModuleMap(modules, sensors_input, det_geom, pt_cut); sensors = sensors_input; } diff --git a/RecoTracker/LSTGeometry/src/Helix.cc b/RecoTracker/LSTGeometry/src/Helix.cc new file mode 100644 index 0000000000000..b1c2ec17ac02d --- /dev/null +++ b/RecoTracker/LSTGeometry/src/Helix.cc @@ -0,0 +1,68 @@ +#ifndef RecoTracker_LSTGeometry_interface_Math_h +#define RecoTracker_LSTGeometry_interface_Math_h + +#include + +#include + +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Helix.h" + +namespace lstgeometry { + + // Clarification : phi was derived assuming a negatively charged particle would start + // at the first quadrant. However the way signs are set up in the get_track_point function + // implies the particle actually starts out in the fourth quadrant, and phi is measured from + // the y axis as opposed to x axis in the expression provided in this function. Hence I tucked + // in an extra pi/2 to account for these effects + Helix::Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge) : charge(charge) { + radius = pt / (k2Rinv1GeVf * kB); + + float t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * radius)); + phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + + ((vy - my) / (vx - mx) < 0) * (std::numbers::pi_v)+charge * t / 2. + + (my - vy < 0) * (std::numbers::pi_v / 2.) - (my - vy > 0) * (std::numbers::pi_v / 2.); + + center_x = vx + charge * radius * std::sin(phi); + center_y = vy - charge * radius * std::cos(phi); + center_z = vz; + lambda = std::atan((mz - vz) / (radius * t)); + } + + std::tuple Helix::pointFromRadius(float target_r) { + auto objective_function = [this, target_r](float t) { + float x = this->center_x - this->charge * this->radius * std::sin(this->phi - this->charge * t); + float y = this->center_y + this->charge * this->radius * std::cos(this->phi - this->charge * t); + return std::fabs(std::sqrt(x * x + y * y) - target_r); + }; + int bits = std::numeric_limits::digits; + auto result = boost::math::tools::brent_find_minima(objective_function, 0.0f, std::numbers::pi_v, bits); + float t = result.first; + + float x = center_x - charge * radius * std::sin(phi - charge * t); + float y = center_y + charge * radius * std::cos(phi - charge * t); + float z = center_z + radius * std::tan(lambda) * t; + float r = std::sqrt(x * x + y * y); + + return std::make_tuple(x, y, z, r); + } + + std::tuple Helix::pointFromZ(float target_z) { + auto objective_function = [this, target_z](float t) { + float z = this->center_z + this->radius * std::tan(this->lambda) * t; + return std::fabs(z - target_z); + }; + int bits = std::numeric_limits::digits; + auto result = boost::math::tools::brent_find_minima(objective_function, 0.0f, std::numbers::pi_v, bits); + float t = result.first; + + float x = center_x - charge * radius * std::sin(phi - charge * t); + float y = center_y + charge * radius * std::cos(phi - charge * t); + float z = center_z + radius * std::tan(lambda) * t; + float r = std::sqrt(x * x + y * y); + + return std::make_tuple(x, y, z, r); + } + +} // namespace lstgeometry +#endif diff --git a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h b/RecoTracker/LSTGeometry/src/ModuleMap.cc similarity index 64% rename from RecoTracker/LSTGeometry/interface/ModuleMapMethods.h rename to RecoTracker/LSTGeometry/src/ModuleMap.cc index 172c91195ede7..0092e7aa894ce 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMapMethods.h +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -1,24 +1,88 @@ -#ifndef RecoTracker_LSTGeometry_interface_ModuleMapMethods_h -#define RecoTracker_LSTGeometry_interface_ModuleMapMethods_h - -#include -#include #include #include #include -#include -#include #include #include #include -#include "RecoTracker/LSTGeometry/interface/Math.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" -#include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" +#include "RecoTracker/LSTGeometry/interface/ModuleMap.h" +#include "RecoTracker/LSTGeometry/interface/Helix.h" namespace lstgeometry { + using Point = boost::geometry::model::d2::point_xy; + using Polygon = boost::geometry::model::polygon; + + Polygon getEtaPhiPolygon(MatrixFNx3 const& mod_boundaries, float refphi, float zshift = 0) { + int npoints = mod_boundaries.rows(); + MatrixFNx2 mod_boundaries_etaphi(npoints, 2); + for (int i = 0; i < npoints; ++i) { + auto ref_etaphi = getEtaPhi(mod_boundaries(i, 1), mod_boundaries(i, 2), mod_boundaries(i, 0) + zshift, refphi); + mod_boundaries_etaphi(i, 0) = ref_etaphi.first; + mod_boundaries_etaphi(i, 1) = ref_etaphi.second; + } + + Polygon poly; + // <= because we need to close the polygon with the first point + for (int i = 0; i <= npoints; ++i) { + boost::geometry::append(poly, + Point(mod_boundaries_etaphi(i % npoints, 0), mod_boundaries_etaphi(i % npoints, 1))); + } + boost::geometry::correct(poly); + return poly; + } + + bool moduleOverlapsInEtaPhi(MatrixF4x3 const& ref_mod_boundaries, + MatrixF4x3 const& tar_mod_boundaries, + float refphi = 0, + float zshift = 0) { + RowVectorF3 ref_center = ref_mod_boundaries.colwise().sum(); + ref_center /= 4.; + RowVectorF3 tar_center = tar_mod_boundaries.colwise().sum(); + tar_center /= 4.; + + float ref_center_phi = std::atan2(ref_center(2), ref_center(1)); + float tar_center_phi = std::atan2(tar_center(2), tar_center(1)); + + if (std::fabs(phi_mpi_pi(ref_center_phi - tar_center_phi)) > std::numbers::pi_v / 2.) + return false; + + MatrixF4x2 ref_mod_boundaries_etaphi; + MatrixF4x2 tar_mod_boundaries_etaphi; + + for (int i = 0; i < 4; ++i) { + auto ref_etaphi = + getEtaPhi(ref_mod_boundaries(i, 1), ref_mod_boundaries(i, 2), ref_mod_boundaries(i, 0) + zshift, refphi); + auto tar_etaphi = + getEtaPhi(tar_mod_boundaries(i, 1), tar_mod_boundaries(i, 2), tar_mod_boundaries(i, 0) + zshift, refphi); + ref_mod_boundaries_etaphi(i, 0) = ref_etaphi.first; + ref_mod_boundaries_etaphi(i, 1) = ref_etaphi.second; + tar_mod_boundaries_etaphi(i, 0) = tar_etaphi.first; + tar_mod_boundaries_etaphi(i, 1) = tar_etaphi.second; + } + + // Quick cut + RowVectorF2 diff = ref_mod_boundaries_etaphi.row(0) - tar_mod_boundaries_etaphi.row(0); + if (std::fabs(diff(0)) > 0.5) + return false; + if (std::fabs(phi_mpi_pi(diff(1))) > 1.) + return false; + + Polygon ref_poly, tar_poly; + + // <= 4 because we need to close the polygon with the first point + for (int i = 0; i <= 4; ++i) { + boost::geometry::append(ref_poly, + Point(ref_mod_boundaries_etaphi(i % 4, 0), ref_mod_boundaries_etaphi(i % 4, 1))); + boost::geometry::append(tar_poly, + Point(tar_mod_boundaries_etaphi(i % 4, 0), tar_mod_boundaries_etaphi(i % 4, 1))); + } + boost::geometry::correct(ref_poly); + boost::geometry::correct(tar_poly); + + return boost::geometry::intersects(ref_poly, tar_poly); + } + std::vector getStraightLineConnections(unsigned int ref_detid, Modules const& modules, Sensors const& sensors, @@ -33,7 +97,7 @@ namespace lstgeometry { unsigned short ref_subdet = refmodule.subdet; auto etaphi = getEtaPhi(sensor.centerX, sensor.centerY, sensor.centerZ); - auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); + auto etaphibins = DetectorGeometry::getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) @@ -130,11 +194,10 @@ namespace lstgeometry { MatrixF4x3 next_layer_bound_points; for (int i = 0; i < bounds.rows(); i++) { - Helix helix_p10 = constructHelixFromPoints(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); - Helix helix_m10 = constructHelixFromPoints(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); - Helix helix_p10_pos = constructHelixFromPoints(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); - Helix helix_m10_pos = - constructHelixFromPoints(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); + auto helix_p10 = Helix(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); + auto helix_m10 = Helix(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); + auto helix_p10_pos = Helix(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); + auto helix_m10_pos = Helix(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); double bound_theta = std::atan2(std::sqrt(bounds(i, 1) * bounds(i, 1) + bounds(i, 2) * bounds(i, 2)), bounds(i, 0)); double bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); @@ -145,23 +208,25 @@ namespace lstgeometry { if (doR) { double tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); if (bound_theta > theta) { - next_point = getHelixPointFromRadius(phi_diff > 0 ? helix_p10 : helix_p10_pos, tar_layer_radius); + auto& h = phi_diff > 0 ? helix_p10 : helix_p10_pos; + next_point = h.pointFromRadius(tar_layer_radius); } else { - next_point = getHelixPointFromRadius(phi_diff > 0 ? helix_m10 : helix_m10_pos, tar_layer_radius); + auto& h = phi_diff > 0 ? helix_m10 : helix_m10_pos; + next_point = h.pointFromRadius(tar_layer_radius); } } else { double tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(1); if (bound_theta > theta) { if (phi_diff > 0) { - next_point = getHelixPointFromZ(helix_p10, std::copysign(tar_layer_z, helix_p10.lam)); + next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); } else { - next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10_pos.lam)); + next_point = helix_p10_pos.pointFromZ(std::copysign(tar_layer_z, helix_p10_pos.lambda)); } } else { if (phi_diff > 0) { - next_point = getHelixPointFromZ(helix_m10, std::copysign(tar_layer_z, helix_p10.lam)); + next_point = helix_m10.pointFromZ(std::copysign(tar_layer_z, helix_m10.lambda)); } else { - next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_p10_pos.lam)); + next_point = helix_m10_pos.pointFromZ(std::copysign(tar_layer_z, helix_m10_pos.lambda)); } } } @@ -169,15 +234,15 @@ namespace lstgeometry { double tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(ref_layer + 1); if (bound_theta > theta) { if (phi_diff > 0) { - next_point = getHelixPointFromZ(helix_p10, std::copysign(tar_layer_z, helix_p10.lam)); + next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); } else { - next_point = getHelixPointFromZ(helix_p10_pos, std::copysign(tar_layer_z, helix_p10_pos.lam)); + next_point = helix_p10_pos.pointFromZ(std::copysign(tar_layer_z, helix_p10_pos.lambda)); } } else { if (phi_diff > 0) { - next_point = getHelixPointFromZ(helix_m10, std::copysign(tar_layer_z, helix_m10.lam)); + next_point = helix_m10.pointFromZ(std::copysign(tar_layer_z, helix_m10.lambda)); } else { - next_point = getHelixPointFromZ(helix_m10_pos, std::copysign(tar_layer_z, helix_m10_pos.lam)); + next_point = helix_m10_pos.pointFromZ(std::copysign(tar_layer_z, helix_m10_pos.lambda)); } } } @@ -204,7 +269,7 @@ namespace lstgeometry { unsigned short ref_subdet = refmodule.subdet; auto etaphi = getEtaPhi(sensor.centerX, sensor.centerY, sensor.centerZ); - auto etaphibins = getEtaPhiBins(etaphi.first, etaphi.second); + auto etaphibins = DetectorGeometry::getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) @@ -283,9 +348,9 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } - std::unordered_map> mergeLineConnections( + ModuleMap mergeLineConnections( std::initializer_list>*> connections_list) { - std::unordered_map> merged; + ModuleMap merged; for (auto* connections : connections_list) { for (const auto& [detid, list] : *connections) { @@ -297,6 +362,27 @@ namespace lstgeometry { return merged; } -} // namespace lstgeometry + ModuleMap buildModuleMap(Modules const& modules, + Sensors const& sensors, + DetectorGeometry const& det_geo, + float pt_cut) { + auto detids_etaphi_layer_ref = det_geo.getDetIds([&modules, &sensors](const auto& x) { + auto mod = modules.at(sensors.at(x.first).moduleDetId); + // exclude the outermost modules that do not have connections to other modules + return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || + (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && + !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && + !(mod.ring == 12 && mod.layer == 4))); + }); + + std::unordered_map> straight_line_connections; + std::unordered_map> curved_line_connections; + + for (auto ref_detid : detids_etaphi_layer_ref) { + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, modules, sensors, det_geo); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, modules, sensors, det_geo, pt_cut); + } + return mergeLineConnections({&straight_line_connections, &curved_line_connections}); + } -#endif +} // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h b/RecoTracker/LSTGeometry/src/PixelMap.cc similarity index 79% rename from RecoTracker/LSTGeometry/interface/PixelMapMethods.h rename to RecoTracker/LSTGeometry/src/PixelMap.cc index 56ac22d0d2ca5..a7c55e3faf424 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMapMethods.h +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -1,15 +1,9 @@ -#ifndef RecoTracker_LSTGeometry_interface_PixelMapMethods_h -#define RecoTracker_LSTGeometry_interface_PixelMapMethods_h - -#include - #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" + namespace lstgeometry { - PixelMap computePixelMap(Modules const& modules, DetectorGeometry const& det_geom, double ptCut) { + PixelMap buildPixelMap(Modules const& modules, DetectorGeometry const& det_geom, float pt_cut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; @@ -38,8 +32,7 @@ namespace lstgeometry { auto location = module.location; // Skip if the module is not PS module and is not lower module - if (!module.isLower || (module.moduleType != TrackerGeometry::ModuleType::Ph2PSP && - module.moduleType != TrackerGeometry::ModuleType::Ph2PSS)) + if (!module.isLower || (module.moduleType != ModuleType::Ph2PSP && module.moduleType != ModuleType::Ph2PSS)) continue; // For this module, now compute which super bins they belong to @@ -48,15 +41,15 @@ namespace lstgeometry { for (unsigned int ipt = 0; ipt < kPtBounds.size(); ipt++) { for (unsigned int iz = 0; iz < kNZ; iz++) { // The zmin, zmax of consideration - double zmin = -30 + iz * (60. / kNZ); - double zmax = -30 + (iz + 1) * (60. / kNZ); + float zmin = -30 + iz * (60. / kNZ); + float zmax = -30 + (iz + 1) * (60. / kNZ); zmin -= 0.05; zmax += 0.05; // The ptmin, ptmax of consideration - double pt_lo = ipt == 0 ? ptCut : kPtBounds[ipt - 1]; - double pt_hi = kPtBounds[ipt]; + float pt_lo = ipt == 0 ? pt_cut : kPtBounds[ipt - 1]; + float pt_hi = kPtBounds[ipt]; auto [etamin, etamax] = det_geom.getCompatibleEtaRange(detId, zmin, zmax); @@ -71,20 +64,20 @@ namespace lstgeometry { } // Compute the indices of the compatible eta range - unsigned int ietamin = static_cast(std::max((etamin + 2.6) / (5.2 / kNEta), 0.0)); + unsigned int ietamin = static_cast(std::max((etamin + 2.6f) / (5.2f / kNEta), 0.0f)); unsigned int ietamax = - static_cast(std::min((etamax + 2.6) / (5.2 / kNEta), static_cast(kNEta - 1))); + static_cast(std::min((etamax + 2.6f) / (5.2f / kNEta), static_cast(kNEta - 1))); auto phi_ranges = det_geom.getCompatiblePhiRange(detId, pt_lo, pt_hi); - unsigned int iphimin_pos = static_cast((phi_ranges.first.first + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); - unsigned int iphimax_pos = static_cast((phi_ranges.first.second + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); - unsigned int iphimin_neg = static_cast((phi_ranges.second.first + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); - unsigned int iphimax_neg = static_cast((phi_ranges.second.second + std::numbers::pi_v) / - (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimin_pos = static_cast((phi_ranges.first.first + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimax_pos = static_cast((phi_ranges.first.second + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimin_neg = static_cast((phi_ranges.second.first + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); + unsigned int iphimax_neg = static_cast((phi_ranges.second.second + std::numbers::pi_v) / + (2. * std::numbers::pi_v / kNPhi)); // <= to cover some inefficiencies for (unsigned int ieta = ietamin; ieta <= ietamax; ieta++) { @@ -134,5 +127,3 @@ namespace lstgeometry { } } // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index 0f5fbbe524178..250386a12202d 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -38,7 +38,7 @@ void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& i lstgeometry::writeSlopes(lstg.endcap_slopes, lstg.sensors, outputDirectory_ + "endcap_orientation", binaryOutput_); lstgeometry::writePixelMaps(lstg.pixel_map, outputDirectory_ + "pixelmap/pLS_map", binaryOutput_); lstgeometry::writeModuleConnections( - lstg.merged_line_connections, outputDirectory_ + "module_connection_tracing_merged", binaryOutput_); + lstg.module_map, outputDirectory_ + "module_connection_tracing_merged", binaryOutput_); edm::LogInfo("DumpLSTGeometry") << "Geometry data was successfully dumped." << std::endl; } From 5e10176b4a382ea7812c5f30a32cdf93c19dc7b5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 26 Feb 2026 19:03:32 +0000 Subject: [PATCH 76/95] GeomDetEnumerators::isBarrel doesn't work --- .../LSTGeometry/plugins/LSTGeometryESProducer.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index 44d4990225f8c..af07dd9071888 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -94,14 +94,15 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const auto subdet = static_cast(detId.subdetId()); const auto side = trackerTopo_->barrelTiltTypeP2(detId); - const auto location = (GeomDetEnumerators::isBarrel(subdet) ? GeomDetEnumerators::Location::barrel - : GeomDetEnumerators::Location::endcap); + // GeomDetEnumerators::isBarrel doesn't give the right answer + const auto location = (subdet == SubDetector::TEC ? lstgeometry::Location::barrel : lstgeometry::Location::endcap); const unsigned int layer = trackerTopo_->layer(detId); const unsigned int ring = trackerTopo_->endcapRingP2(detId); const bool isLower = trackerTopo_->isLower(detId); - std::cout << "Processing detId " << detid << " with subdet " << subdet << " layer " << layer << " ring " << ring - << " side " << side << std::endl; ////////////////////// remove + std::cout << "Processing detId " << detid << " with subdet " << subdet << ", " << static_cast(subdet) + << " layer " << layer << " ring " << ring << " side " << side << ", isbarrel " + << GeomDetEnumerators::isBarrel(subdet) << std::endl; ////////////////////// remove float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); @@ -117,7 +118,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); } - if (location == GeomDetEnumerators::Location::barrel) { + if (location == lstgeometry::Location::barrel) { avg_r_cm[layer - 1] += rho_cm; avg_r_counter[layer - 1] += 1; } else { From 81ef9455045db8cad224c5a607afe151f664194c Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 26 Feb 2026 19:42:51 +0000 Subject: [PATCH 77/95] Missed namespace --- RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index af07dd9071888..e5b206a5f4628 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -95,7 +95,8 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const auto subdet = static_cast(detId.subdetId()); const auto side = trackerTopo_->barrelTiltTypeP2(detId); // GeomDetEnumerators::isBarrel doesn't give the right answer - const auto location = (subdet == SubDetector::TEC ? lstgeometry::Location::barrel : lstgeometry::Location::endcap); + const auto location = + (subdet == lstgeometry::SubDetector::TEC ? lstgeometry::Location::barrel : lstgeometry::Location::endcap); const unsigned int layer = trackerTopo_->layer(detId); const unsigned int ring = trackerTopo_->endcapRingP2(detId); const bool isLower = trackerTopo_->isLower(detId); From 43e8b03ab4fdee46f8030ed9c4ed2f347350ea68 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 27 Feb 2026 14:37:51 +0000 Subject: [PATCH 78/95] Minor tweaks --- .../interface/OrientationMethods.h | 6 ++-- .../plugins/LSTGeometryESProducer.cc | 30 ++++++++++++++++--- .../LSTGeometry/src/DetectorGeometry.cc | 4 +-- RecoTracker/LSTGeometry/src/Geometry.cc | 5 ++++ RecoTracker/LSTGeometry/src/ModuleMap.cc | 22 +++++++------- RecoTracker/LSTGeometry/src/PixelMap.cc | 2 +- 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index 58fb97ff5a6be..8e27006997e9f 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -36,13 +36,13 @@ namespace lstgeometry { auto& module = modules.at(sensor.moduleDetId); auto location = module.location; - bool is_tilted = module.side != Phase2Tracker::BarrelModuleTilt::flat; + bool is_tilted = module.side != BarrelModuleTilt::flat; // TODO: Do we need to skip strips? - if (location == GeomDetEnumerators::Location::barrel and is_tilted) + if (location == Location::barrel and is_tilted) barrel_slopes[detId] = slope; - else if (location == GeomDetEnumerators::Location::endcap) + else if (location == Location::endcap) endcap_slopes[detId] = slope; } diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index e5b206a5f4628..f48ff05a24143 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -84,6 +84,28 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac // Leafs are the sensors const unsigned int moduleDetId = detid & ~0b11; // TODO: Is there a CMSSW method for this? sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, moduleType); + + ///////////// tmp + // const RectangularPlaneBounds *sensor_bounds = dynamic_cast(b); + // float wid = sensor_bounds->width(); + // float len = sensor_bounds->length(); + // auto c1 = GloballyPositioned::LocalPoint(wid / 2, len / 2, 0); + // auto c2 = GloballyPositioned::LocalPoint(-wid / 2, len / 2, 0); + // auto c3 = GloballyPositioned::LocalPoint(-wid / 2, -len / 2, 0); + // auto c4 = GloballyPositioned::LocalPoint(wid / 2, -len / 2, 0); + // auto c1g = surface.toGlobal(c1); + // auto c2g = surface.toGlobal(c2); + // auto c3g = surface.toGlobal(c3); + // auto c4g = surface.toGlobal(c4); + // if (detid == 440165400 + 1) { + // std::cout << "Corners for detid " << detid << ": " << std::endl; + // std::cout << c1g << std::endl; + // std::cout << c2g << std::endl; + // std::cout << c3g << std::endl; + // std::cout << c4g << std::endl; + // } + /// + continue; } @@ -92,7 +114,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; } - const auto subdet = static_cast(detId.subdetId()); + const auto subdet = trackerGeom_->geomDetSubDetector(detId.subdetId()); const auto side = trackerTopo_->barrelTiltTypeP2(detId); // GeomDetEnumerators::isBarrel doesn't give the right answer const auto location = @@ -101,9 +123,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const unsigned int ring = trackerTopo_->endcapRingP2(detId); const bool isLower = trackerTopo_->isLower(detId); - std::cout << "Processing detId " << detid << " with subdet " << subdet << ", " << static_cast(subdet) - << " layer " << layer << " ring " << ring << " side " << side << ", isbarrel " - << GeomDetEnumerators::isBarrel(subdet) << std::endl; ////////////////////// remove + // std::cout << "Processing detId " << detid << " with subdet " << subdet << ", " << static_cast(subdet) + // << " layer " << layer << " ring " << ring << " side " << side << ", isbarrel " + // << GeomDetEnumerators::isBarrel(subdet) << std::endl; ////////////////////// remove float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 25d1d593633a8..772e4678f1e7c 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -97,7 +97,7 @@ namespace lstgeometry { for (unsigned int layer = 1; layer < 7; layer++) { auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { auto& m = modules_info.at(sensors.at(x.first).moduleDetId); - return m.subdet == 5 && m.layer == layer && m.isLower; + return m.location == Location::barrel && m.layer == layer && m.isLower; }); for (auto detid : detids) { auto corners = getCorners(detid); @@ -116,7 +116,7 @@ namespace lstgeometry { for (unsigned int layer = 1; layer < 6; layer++) { auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { auto& m = modules_info.at(sensors.at(x.first).moduleDetId); - return m.subdet == 4 && m.layer == layer && m.isLower; + return m.location == Location::endcap && m.layer == layer && m.isLower; }); for (auto detid : detids) { auto corners = getCorners(detid); diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 8b2d3a8a87d1f..40aa830b44b70 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -3,6 +3,8 @@ #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" +#include /////////////////////// remove + using namespace lstgeometry; Geometry::Geometry(Modules &modules, @@ -15,6 +17,9 @@ Geometry::Geometry(Modules &modules, assignCornersToSensors(modules, sensors_input); + // std::cout << "Corners are " << std::endl; + // std::cout << sensors_input.at(440165400 + 1).corners << std::endl; /////////////////////// remove + auto slopes = processCorners(modules, sensors_input); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index 0092e7aa894ce..ed69746610405 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -94,13 +94,13 @@ namespace lstgeometry { auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; - unsigned short ref_subdet = refmodule.subdet; + auto ref_location = refmodule.location; auto etaphi = getEtaPhi(sensor.centerX, sensor.centerY, sensor.centerZ); auto etaphibins = DetectorGeometry::getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = - ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) + ref_location == Location::barrel ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); std::vector list_of_detids_etaphi_layer_tar; @@ -114,7 +114,7 @@ namespace lstgeometry { // Consider barrel to endcap connections if the intersection area is > 0 // We construct the reference polygon as a vector of polygons because the boost::geometry::difference // function can return multiple polygons if the difference results in disjoint pieces - if (ref_subdet == 5) { + if (ref_location == Location::barrel) { std::unordered_set barrel_endcap_connected_tar_detids; for (float zshift : {0, 10, -10}) { @@ -190,7 +190,7 @@ namespace lstgeometry { double refphi = std::atan2(sensor.centerY, sensor.centerX); auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; - unsigned short ref_subdet = refmodule.subdet; + auto ref_location = refmodule.location; MatrixF4x3 next_layer_bound_points; for (int i = 0; i < bounds.rows(); i++) { @@ -204,7 +204,7 @@ namespace lstgeometry { double phi_diff = phi_mpi_pi(bound_phi - refphi); std::tuple next_point; - if (ref_subdet == 5) { + if (ref_location == Location::barrel) { if (doR) { double tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); if (bound_theta > theta) { @@ -266,14 +266,14 @@ namespace lstgeometry { auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; - unsigned short ref_subdet = refmodule.subdet; + auto ref_location = refmodule.location; auto etaphi = getEtaPhi(sensor.centerX, sensor.centerY, sensor.centerZ); auto etaphibins = DetectorGeometry::getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = - ref_subdet == 5 ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) - : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); + ref_location == Location::barrel ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) + : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); auto next_layer_bound_points = boundsAfterCurved(ref_detid, modules, sensors, det_geom, ptCut); @@ -286,7 +286,7 @@ namespace lstgeometry { // Consider barrel to endcap connections if the intersection area is > 0 // We construct the reference polygon as a vector of polygons because the boost::geometry::difference // function can return multiple polygons if the difference results in disjoint pieces - if (ref_subdet == 5) { + if (ref_location == Location::barrel) { std::unordered_set barrel_endcap_connected_tar_detids; int zshift = 0; @@ -369,8 +369,8 @@ namespace lstgeometry { auto detids_etaphi_layer_ref = det_geo.getDetIds([&modules, &sensors](const auto& x) { auto mod = modules.at(sensors.at(x.first).moduleDetId); // exclude the outermost modules that do not have connections to other modules - return ((mod.subdet == 5 && mod.isLower && mod.layer != 6) || - (mod.subdet == 4 && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && + return ((mod.location == Location::barrel && mod.isLower && mod.layer != 6) || + (mod.location == Location::endcap && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && !(mod.ring == 12 && mod.layer == 4))); }); diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index a7c55e3faf424..ea09377cd4493 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -56,7 +56,7 @@ namespace lstgeometry { etamin -= 0.05; etamax += 0.05; - if (layer == 2 && location == GeomDetEnumerators::Location::endcap) { + if (layer == 2 && location == Location::endcap) { if (etamax < 2.3) continue; if (etamin < 2.3) From f76e1f721c6bb7301eea809e10977d571605ce2f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 27 Feb 2026 20:58:52 +0000 Subject: [PATCH 79/95] Fixed side, isLower and isStrip --- RecoTracker/LSTGeometry/interface/Common.h | 8 ++++- RecoTracker/LSTGeometry/interface/Module.h | 4 +-- .../interface/OrientationMethods.h | 27 +++++++++++++++- RecoTracker/LSTGeometry/interface/Sensor.h | 4 ++- .../plugins/LSTGeometryESProducer.cc | 31 +++++++++---------- RecoTracker/LSTGeometry/src/Common.cc | 30 ++++++++++++++++++ .../LSTGeometry/src/DetectorGeometry.cc | 10 +++--- RecoTracker/LSTGeometry/src/Geometry.cc | 2 +- RecoTracker/LSTGeometry/src/ModuleMap.cc | 20 ++++++------ RecoTracker/LSTGeometry/src/PixelMap.cc | 2 +- RecoTracker/LSTGeometry/src/Sensor.cc | 4 ++- 11 files changed, 105 insertions(+), 37 deletions(-) diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index f43f33d95dcc3..9467e260b3f1e 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -24,7 +24,8 @@ namespace lstgeometry { using ModuleType = TrackerGeometry::ModuleType; using SubDetector = GeomDetEnumerators::SubDetector; using Location = GeomDetEnumerators::Location; - using BarrelModuleTilt = Phase2Tracker::BarrelModuleTilt; + + enum Side { NegZ = 1, PosZ = 2, Center = 3 }; // TODO: These should be moved to ../Common.h constexpr float k2Rinv1GeVf = 0.00299792458; @@ -45,6 +46,11 @@ namespace lstgeometry { float roundCoordinate(float coord, float tol = 1e-3); std::pair getEtaPhi(float x, float y, float z, float refphi = 0); + // Not sure if there is functionality for this already in CMSSW + bool isInverted(unsigned int moduleId, Location location, Side side, unsigned int layer); + // This differs from TrackerTopology::isLower since it considers if the module is inverted + bool isLower(unsigned int moduleId, Location location, Side side, unsigned int layer, unsigned int detId); + } // namespace lstgeometry #endif diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h index befc251c19c20..e628b3a2d0bc3 100644 --- a/RecoTracker/LSTGeometry/interface/Module.h +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -11,10 +11,10 @@ namespace lstgeometry { ModuleType moduleType; SubDetector subdet; Location location; - BarrelModuleTilt side; + Side side; + unsigned int moduleId; unsigned int layer; unsigned int ring; - bool isLower; float centerRho; float centerZ; float centerPhi; diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index 8e27006997e9f..ed6293fb157ce 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -4,6 +4,7 @@ #include #include #include +#include /////////////////////// remove #include "RecoTracker/LSTGeometry/interface/Common.h" #include "RecoTracker/LSTGeometry/interface/Module.h" @@ -12,6 +13,14 @@ namespace lstgeometry { + bool isStripLayer(Module module, bool isLower) { + if (module.moduleType == ModuleType::Ph2SS) + return true; + if (isInverted(module.moduleId, module.location, module.side, module.layer)) + return isLower; + return !isLower; + } + // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. SlopeData calculateSlope(double dx, double dy, double dz) { double dr = sqrt(dx * dx + dy * dy); @@ -26,6 +35,8 @@ namespace lstgeometry { std::unordered_map barrel_slopes; std::unordered_map endcap_slopes; + std::cout << "Number of sensors: " << sensors.size() << std::endl; /////////////////////// remove + for (const auto& [detId, sensor] : sensors) { double dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); double dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); @@ -36,9 +47,23 @@ namespace lstgeometry { auto& module = modules.at(sensor.moduleDetId); auto location = module.location; - bool is_tilted = module.side != BarrelModuleTilt::flat; + bool is_tilted = module.side != Side::Center; + + std::cout << "Processing detId " << detId + << ", location: " << (location == Location::barrel ? "barrel" : "endcap") + << ", is_tilted: " << is_tilted << ", isstrip: " << isStripLayer(module, sensor.isLower) + << ", isLower: " << sensor.isLower << ", moduleId: " << module.moduleId << ", layer: " << module.layer + << ", isInverted: " << isInverted(module.moduleId, module.location, module.side, module.layer) + << ", drdz_slope: " << slope.drdz_slope << ", dxdy_slope: " << slope.dxdy_slope + << std::endl; /////////////////////// remove // TODO: Do we need to skip strips? + if (isStripLayer(module, sensor.isLower)) + continue; + + std::cout << "DetId: " << detId << ", location: " << (location == Location::barrel ? "barrel" : "endcap") + << ", is_tilted: " << is_tilted << ", drdz_slope: " << slope.drdz_slope + << ", dxdy_slope: " << slope.dxdy_slope << std::endl; /////////////////////// remove if (location == Location::barrel and is_tilted) barrel_slopes[detId] = slope; diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index a2f6a8f13f465..bbb3215adb5ca 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -14,6 +14,7 @@ namespace lstgeometry { float centerRho; float centerZ; float centerPhi; + bool isLower; MatrixF4x3 corners; // Redundant, but convenient to have them ModuleType moduleType; @@ -21,7 +22,8 @@ namespace lstgeometry { float centerY; Sensor() = default; - Sensor(unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, ModuleType moduleType); + Sensor( + unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType); }; using Sensors = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index f48ff05a24143..dea1b8dff0f83 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -80,10 +80,22 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const float z_cm = lstgeometry::roundCoordinate(position.z()); const float phi_rad = lstgeometry::roundAngle(position.phi()); + const auto subdet = trackerGeom_->geomDetSubDetector(detId.subdetId()); + const auto location = + GeomDetEnumerators::isBarrel(subdet) ? lstgeometry::Location::barrel : lstgeometry::Location::endcap; + const auto side = static_cast( + location == lstgeometry::Location::barrel ? static_cast(trackerTopo_->barrelTiltTypeP2(detId)) + : trackerTopo_->side(detId)); + const unsigned int moduleId = trackerTopo_->module(detId); + const unsigned int layer = trackerTopo_->layer(detId); + const unsigned int ring = trackerTopo_->endcapRingP2(detId); + if (det->isLeaf()) { // Leafs are the sensors - const unsigned int moduleDetId = detid & ~0b11; // TODO: Is there a CMSSW method for this? - sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, moduleType); + const unsigned int moduleDetId = detid & ~0b11; // I don't think there is there a CMSSW method for this + // Can't use TrackerTopology::isLower since it doesn't consider if the module is inverted + const bool isLow = isLower(moduleId, location, side, layer, detid); + sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType); ///////////// tmp // const RectangularPlaneBounds *sensor_bounds = dynamic_cast(b); @@ -114,19 +126,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; } - const auto subdet = trackerGeom_->geomDetSubDetector(detId.subdetId()); - const auto side = trackerTopo_->barrelTiltTypeP2(detId); - // GeomDetEnumerators::isBarrel doesn't give the right answer - const auto location = - (subdet == lstgeometry::SubDetector::TEC ? lstgeometry::Location::barrel : lstgeometry::Location::endcap); - const unsigned int layer = trackerTopo_->layer(detId); - const unsigned int ring = trackerTopo_->endcapRingP2(detId); - const bool isLower = trackerTopo_->isLower(detId); - - // std::cout << "Processing detId " << detid << " with subdet " << subdet << ", " << static_cast(subdet) - // << " layer " << layer << " ring " << ring << " side " << side << ", isbarrel " - // << GeomDetEnumerators::isBarrel(subdet) << std::endl; ////////////////////// remove - float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); float meanWidth_cm = b2->width(); @@ -153,9 +152,9 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac subdet, location, side, + moduleId, layer, ring, - isLower, rho_cm, z_cm, phi_rad, diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc index df92dc20baeca..2b6ff82b1825f 100644 --- a/RecoTracker/LSTGeometry/src/Common.cc +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -39,4 +39,34 @@ namespace lstgeometry { return std::make_pair(eta, phi); } + bool isInverted(unsigned int moduleId, Location location, Side side, unsigned int layer) { + bool moduleIdIsEven = moduleId % 2 == 0; + if (location == Location::endcap) { + if (side == Side::NegZ) { + return !moduleIdIsEven; + } else if (side == Side::PosZ) { + return moduleIdIsEven; + } + } else if (location == Location::barrel) { + if (side == Side::Center) { + if (layer <= 3) { + return !moduleIdIsEven; + } else if (layer >= 4) { + return moduleIdIsEven; + } + } else if (side == Side::NegZ || side == Side::PosZ) { + if (layer <= 2) { + return !moduleIdIsEven; + } else if (layer == 3) { + return moduleIdIsEven; + } + } + } + return false; + } + + bool isLower(unsigned int moduleId, Location location, Side side, unsigned int layer, unsigned int detId) { + return isInverted(moduleId, location, side, layer) ? !(detId & 1) : (detId & 1); + } + } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 772e4678f1e7c..8e791dfc6e0ea 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -96,8 +96,9 @@ namespace lstgeometry { for (unsigned int layer = 1; layer < 7; layer++) { auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { - auto& m = modules_info.at(sensors.at(x.first).moduleDetId); - return m.location == Location::barrel && m.layer == layer && m.isLower; + auto& s = sensors.at(x.first); + auto& m = modules_info.at(s.moduleDetId); + return m.location == Location::barrel && m.layer == layer && s.isLower; }); for (auto detid : detids) { auto corners = getCorners(detid); @@ -115,8 +116,9 @@ namespace lstgeometry { } for (unsigned int layer = 1; layer < 6; layer++) { auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { - auto& m = modules_info.at(sensors.at(x.first).moduleDetId); - return m.location == Location::endcap && m.layer == layer && m.isLower; + auto& s = sensors.at(x.first); + auto& m = modules_info.at(s.moduleDetId); + return m.location == Location::endcap && m.layer == layer && s.isLower; }); for (auto detid : detids) { auto corners = getCorners(detid); diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 40aa830b44b70..802092ee6f871 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -18,7 +18,7 @@ Geometry::Geometry(Modules &modules, assignCornersToSensors(modules, sensors_input); // std::cout << "Corners are " << std::endl; - // std::cout << sensors_input.at(440165400 + 1).corners << std::endl; /////////////////////// remove + // std::cout << sensors_input.at(440165400 + 1).corners << std::endl; /////////////////////// remove auto slopes = processCorners(modules, sensors_input); barrel_slopes = std::move(std::get<0>(slopes)); diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index ed69746610405..b0aaff6cdcbdc 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -100,8 +100,9 @@ namespace lstgeometry { auto etaphibins = DetectorGeometry::getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = - ref_location == Location::barrel ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) - : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); + ref_location == Location::barrel + ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) + : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -272,8 +273,9 @@ namespace lstgeometry { auto etaphibins = DetectorGeometry::getEtaPhiBins(etaphi.first, etaphi.second); auto const& tar_detids_to_be_considered = - ref_location == Location::barrel ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) - : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); + ref_location == Location::barrel + ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) + : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); auto next_layer_bound_points = boundsAfterCurved(ref_detid, modules, sensors, det_geom, ptCut); @@ -367,12 +369,12 @@ namespace lstgeometry { DetectorGeometry const& det_geo, float pt_cut) { auto detids_etaphi_layer_ref = det_geo.getDetIds([&modules, &sensors](const auto& x) { - auto mod = modules.at(sensors.at(x.first).moduleDetId); + auto& s = sensors.at(x.first); + auto& m = modules.at(s.moduleDetId); // exclude the outermost modules that do not have connections to other modules - return ((mod.location == Location::barrel && mod.isLower && mod.layer != 6) || - (mod.location == Location::endcap && mod.isLower && mod.layer != 5 && !(mod.ring == 15 && mod.layer == 1) && - !(mod.ring == 15 && mod.layer == 2) && !(mod.ring == 12 && mod.layer == 3) && - !(mod.ring == 12 && mod.layer == 4))); + return ((m.location == Location::barrel && s.isLower && m.layer != 6) || + (m.location == Location::endcap && s.isLower && m.layer != 5 && !(m.ring == 15 && m.layer == 1) && + !(m.ring == 15 && m.layer == 2) && !(m.ring == 12 && m.layer == 3) && !(m.ring == 12 && m.layer == 4))); }); std::unordered_map> straight_line_connections; diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index ea09377cd4493..bca0d831c09ce 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -32,7 +32,7 @@ namespace lstgeometry { auto location = module.location; // Skip if the module is not PS module and is not lower module - if (!module.isLower || (module.moduleType != ModuleType::Ph2PSP && module.moduleType != ModuleType::Ph2PSS)) + if (module.moduleType == ModuleType::Ph2SS) continue; // For this module, now compute which super bins they belong to diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc index 5bcddab4995a7..3ed9fc99413a2 100644 --- a/RecoTracker/LSTGeometry/src/Sensor.cc +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -4,11 +4,13 @@ using namespace lstgeometry; -Sensor::Sensor(unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, ModuleType moduleType) +Sensor::Sensor( + unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType) : moduleDetId(moduleDetId), centerRho(centerRho), centerZ(centerZ), centerPhi(centerPhi), + isLower(isLower), corners(MatrixF4x3::Zero()), moduleType(moduleType), centerX(centerRho * std::cos(centerPhi)), From a4916ad7bfcfab19aa4e8e76c75590b0bbf5c299 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 2 Mar 2026 14:47:03 +0000 Subject: [PATCH 80/95] Fixed slopes --- RecoTracker/LSTGeometry/interface/OrientationMethods.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index ed6293fb157ce..435b932a6ce4c 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -48,17 +48,17 @@ namespace lstgeometry { auto location = module.location; bool is_tilted = module.side != Side::Center; + bool is_strip = isStripLayer(module, sensor.isLower); std::cout << "Processing detId " << detId << ", location: " << (location == Location::barrel ? "barrel" : "endcap") - << ", is_tilted: " << is_tilted << ", isstrip: " << isStripLayer(module, sensor.isLower) + << ", is_tilted: " << is_tilted << ", isstrip: " << is_strip << ", isLower: " << sensor.isLower << ", moduleId: " << module.moduleId << ", layer: " << module.layer << ", isInverted: " << isInverted(module.moduleId, module.location, module.side, module.layer) << ", drdz_slope: " << slope.drdz_slope << ", dxdy_slope: " << slope.dxdy_slope << std::endl; /////////////////////// remove - // TODO: Do we need to skip strips? - if (isStripLayer(module, sensor.isLower)) + if (!is_strip) continue; std::cout << "DetId: " << detId << ", location: " << (location == Location::barrel ? "barrel" : "endcap") From a4999bfb231040c85d8310e51ba25713551bb08c Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 2 Mar 2026 18:40:48 +0000 Subject: [PATCH 81/95] Fixed subdet for pixelmap --- RecoTracker/LSTGeometry/src/PixelMap.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index bca0d831c09ce..0cd796d496d9e 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -25,7 +25,8 @@ namespace lstgeometry { continue; auto module = modules.at(detId); - auto subdet = static_cast(module.subdet); + // Phase-2 enum differs from the legacy one used here + unsigned int subdet = module.subdet == SubDetector::P2OTB ? 5 : 4; auto layer = module.layer; if (layer > 2) continue; From 460e347e26feee5f4784ed82a92eb91e7957b480 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 2 Mar 2026 15:01:53 -0500 Subject: [PATCH 82/95] Tweaked constants and types --- RecoTracker/LSTGeometry/interface/Common.h | 3 +- RecoTracker/LSTGeometry/interface/Geometry.h | 2 +- .../interface/OrientationMethods.h | 18 ++++----- RecoTracker/LSTGeometry/interface/SlopeData.h | 4 +- .../LSTGeometry/src/DetectorGeometry.cc | 2 +- RecoTracker/LSTGeometry/src/Geometry.cc | 2 +- RecoTracker/LSTGeometry/src/Helix.cc | 2 +- RecoTracker/LSTGeometry/src/ModuleMap.cc | 38 +++++++++---------- 8 files changed, 35 insertions(+), 36 deletions(-) diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index 9467e260b3f1e..a4e18acccdd8a 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -27,8 +27,7 @@ namespace lstgeometry { enum Side { NegZ = 1, PosZ = 2, Center = 3 }; - // TODO: These should be moved to ../Common.h - constexpr float k2Rinv1GeVf = 0.00299792458; + constexpr float kC = 0.00299792458; constexpr float kB = 3.8112; // For pixel maps diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 6eca418b720c0..5e2f251d8760d 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -20,7 +20,7 @@ namespace lstgeometry { Sensors &sensors_input, std::vector const &average_r, std::vector const &average_z, - double ptCut); + float ptCut); }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h index 435b932a6ce4c..d6ef1bfb0583f 100644 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ b/RecoTracker/LSTGeometry/interface/OrientationMethods.h @@ -22,10 +22,10 @@ namespace lstgeometry { } // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. - SlopeData calculateSlope(double dx, double dy, double dz) { - double dr = sqrt(dx * dx + dy * dy); - double drdz_slope = dz != 0 ? dr / dz : kDefaultSlope; - double dxdy_slope = dy != 0 ? -dx / dy : kDefaultSlope; + SlopeData calculateSlope(float dx, float dy, float dz) { + float dr = sqrt(dx * dx + dy * dy); + float drdz_slope = dz != 0 ? dr / dz : kDefaultSlope; + float dxdy_slope = dy != 0 ? -dx / dy : kDefaultSlope; return SlopeData{drdz_slope, dxdy_slope}; } @@ -38,9 +38,9 @@ namespace lstgeometry { std::cout << "Number of sensors: " << sensors.size() << std::endl; /////////////////////// remove for (const auto& [detId, sensor] : sensors) { - double dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); - double dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); - double dz = roundCoordinate(sensor.corners(1, 0) - sensor.corners(0, 0)); + float dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); + float dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); + float dz = roundCoordinate(sensor.corners(1, 0) - sensor.corners(0, 0)); SlopeData slope = calculateSlope(dx, dy, dz); @@ -52,8 +52,8 @@ namespace lstgeometry { std::cout << "Processing detId " << detId << ", location: " << (location == Location::barrel ? "barrel" : "endcap") - << ", is_tilted: " << is_tilted << ", isstrip: " << is_strip - << ", isLower: " << sensor.isLower << ", moduleId: " << module.moduleId << ", layer: " << module.layer + << ", is_tilted: " << is_tilted << ", isstrip: " << is_strip << ", isLower: " << sensor.isLower + << ", moduleId: " << module.moduleId << ", layer: " << module.layer << ", isInverted: " << isInverted(module.moduleId, module.location, module.side, module.layer) << ", drdz_slope: " << slope.drdz_slope << ", dxdy_slope: " << slope.dxdy_slope << std::endl; /////////////////////// remove diff --git a/RecoTracker/LSTGeometry/interface/SlopeData.h b/RecoTracker/LSTGeometry/interface/SlopeData.h index e769f4978d21a..97c14826a6407 100644 --- a/RecoTracker/LSTGeometry/interface/SlopeData.h +++ b/RecoTracker/LSTGeometry/interface/SlopeData.h @@ -4,8 +4,8 @@ namespace lstgeometry { struct SlopeData { - double drdz_slope; - double dxdy_slope; + float drdz_slope; + float dxdy_slope; }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 8e791dfc6e0ea..3e03b6a56dde5 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -269,7 +269,7 @@ namespace lstgeometry { float maxr = getMaxR(detId); float minphi = getMinPhi(detId); float maxphi = getMaxPhi(detId); - float A = k2Rinv1GeVf * kB / 2.; + float A = kC * kB / 2.; float pos_q_phi_lo_bound = phi_mpi_pi(A * minr / ptmax + minphi); float pos_q_phi_hi_bound = phi_mpi_pi(A * maxr / ptmin + maxphi); float neg_q_phi_lo_bound = phi_mpi_pi(-A * maxr / ptmin + minphi); diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 802092ee6f871..9ed174780e6e3 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -11,7 +11,7 @@ Geometry::Geometry(Modules &modules, Sensors &sensors_input, std::vector const &average_r, std::vector const &average_z, - double pt_cut) { + float pt_cut) { for (auto &[_, mod] : modules) transformSensorCorners(mod); diff --git a/RecoTracker/LSTGeometry/src/Helix.cc b/RecoTracker/LSTGeometry/src/Helix.cc index b1c2ec17ac02d..a984d755028af 100644 --- a/RecoTracker/LSTGeometry/src/Helix.cc +++ b/RecoTracker/LSTGeometry/src/Helix.cc @@ -16,7 +16,7 @@ namespace lstgeometry { // the y axis as opposed to x axis in the expression provided in this function. Hence I tucked // in an extra pi/2 to account for these effects Helix::Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge) : charge(charge) { - radius = pt / (k2Rinv1GeVf * kB); + radius = pt / (kC * kB); float t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * radius)); phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index b0aaff6cdcbdc..733808c7421af 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -89,7 +89,7 @@ namespace lstgeometry { DetectorGeometry const& det_geom) { auto& sensor = sensors.at(ref_detid); - double refphi = std::atan2(sensor.centerY, sensor.centerX); + float refphi = std::atan2(sensor.centerY, sensor.centerX); auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); @@ -138,7 +138,7 @@ namespace lstgeometry { ref_polygon = std::move(difference); } - double area = 0.; + float area = 0.; for (auto& ref_polygon_piece : ref_polygon) area += boost::geometry::area(ref_polygon_piece); @@ -150,9 +150,9 @@ namespace lstgeometry { for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto& sensor_target = sensors.at(tar_detid); - double tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); + float tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); - if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) + if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) continue; Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); @@ -181,14 +181,14 @@ namespace lstgeometry { Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, - double ptCut, + float ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); auto& sensor = sensors.at(ref_detid); int charge = 1; - double theta = + float theta = std::atan2(std::sqrt(sensor.centerX * sensor.centerX + sensor.centerY * sensor.centerY), sensor.centerZ); - double refphi = std::atan2(sensor.centerY, sensor.centerX); + float refphi = std::atan2(sensor.centerY, sensor.centerX); auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; auto ref_location = refmodule.location; @@ -199,15 +199,15 @@ namespace lstgeometry { auto helix_m10 = Helix(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); auto helix_p10_pos = Helix(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); auto helix_m10_pos = Helix(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); - double bound_theta = + float bound_theta = std::atan2(std::sqrt(bounds(i, 1) * bounds(i, 1) + bounds(i, 2) * bounds(i, 2)), bounds(i, 0)); - double bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); - double phi_diff = phi_mpi_pi(bound_phi - refphi); + float bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); + float phi_diff = phi_mpi_pi(bound_phi - refphi); - std::tuple next_point; + std::tuple next_point; if (ref_location == Location::barrel) { if (doR) { - double tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); + float tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); if (bound_theta > theta) { auto& h = phi_diff > 0 ? helix_p10 : helix_p10_pos; next_point = h.pointFromRadius(tar_layer_radius); @@ -216,7 +216,7 @@ namespace lstgeometry { next_point = h.pointFromRadius(tar_layer_radius); } } else { - double tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(1); + float tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(1); if (bound_theta > theta) { if (phi_diff > 0) { next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); @@ -232,7 +232,7 @@ namespace lstgeometry { } } } else { - double tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(ref_layer + 1); + float tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(ref_layer + 1); if (bound_theta > theta) { if (phi_diff > 0) { next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); @@ -259,10 +259,10 @@ namespace lstgeometry { Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, - double ptCut) { + float ptCut) { auto& sensor = sensors.at(ref_detid); - double refphi = std::atan2(sensor.centerY, sensor.centerX); + float refphi = std::atan2(sensor.centerY, sensor.centerX); auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); @@ -312,7 +312,7 @@ namespace lstgeometry { ref_polygon = std::move(difference); } - double area = 0.; + float area = 0.; for (auto& ref_polygon_piece : ref_polygon) area += boost::geometry::area(ref_polygon_piece); @@ -322,9 +322,9 @@ namespace lstgeometry { for (unsigned int tar_detid : new_tar_detids_to_be_considered) { auto& sensor_target = sensors.at(tar_detid); - double tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); + float tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); - if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) + if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) continue; Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); From 9a86f17d256a83bb6e0c9b254c6d8277560026a8 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 4 Mar 2026 09:29:50 -0500 Subject: [PATCH 83/95] Fixed pixel map --- RecoTracker/LSTGeometry/interface/PixelMap.h | 3 ++- RecoTracker/LSTGeometry/src/Geometry.cc | 2 +- RecoTracker/LSTGeometry/src/PixelMap.cc | 12 +++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/RecoTracker/LSTGeometry/interface/PixelMap.h b/RecoTracker/LSTGeometry/interface/PixelMap.h index c2d9ab7888158..2bf72858c6501 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMap.h +++ b/RecoTracker/LSTGeometry/interface/PixelMap.h @@ -8,6 +8,7 @@ #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { @@ -17,7 +18,7 @@ namespace lstgeometry { boost::hash>; using PixelMap = LayerSubdetChargeMap; - PixelMap buildPixelMap(Modules const& modules, DetectorGeometry const& det_geom, float pt_cut); + PixelMap buildPixelMap(Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 9ed174780e6e3..a5312efe8dc01 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -27,7 +27,7 @@ Geometry::Geometry(Modules &modules, auto det_geom = DetectorGeometry(sensors_input, average_r, average_z); det_geom.buildByLayer(modules, sensors_input); - pixel_map = buildPixelMap(modules, det_geom, pt_cut); + pixel_map = buildPixelMap(modules, sensors_input, det_geom, pt_cut); module_map = buildModuleMap(modules, sensors_input, det_geom, pt_cut); diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index 0cd796d496d9e..7706b34ad75e9 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -3,7 +3,7 @@ namespace lstgeometry { - PixelMap buildPixelMap(Modules const& modules, DetectorGeometry const& det_geom, float pt_cut) { + PixelMap buildPixelMap(Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; @@ -20,11 +20,9 @@ namespace lstgeometry { // Loop over the detids and for each detid compute which superbins it is connected to for (auto detId : det_geom.getDetIds()) { - // Skip if the detId is not in the modules - if (!modules.contains(detId)) - continue; + auto& sensor = sensors.at(detId); - auto module = modules.at(detId); + auto module = modules.at(sensor.moduleDetId); // Phase-2 enum differs from the legacy one used here unsigned int subdet = module.subdet == SubDetector::P2OTB ? 5 : 4; auto layer = module.layer; @@ -32,8 +30,8 @@ namespace lstgeometry { continue; auto location = module.location; - // Skip if the module is not PS module and is not lower module - if (module.moduleType == ModuleType::Ph2SS) + // Skip if the module is not PS module and is not lower sensor + if (module.moduleType == ModuleType::Ph2SS || !sensor.isLower) continue; // For this module, now compute which super bins they belong to From 2a6791d5232f6574ba58edeb63b9607f9c33a361 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 4 Mar 2026 12:06:35 -0500 Subject: [PATCH 84/95] Refactored slopes --- .../LSTCore/interface/EndcapGeometry.h | 3 +- .../LSTCore/interface/TiltedGeometry.h | 2 +- RecoTracker/LSTCore/src/EndcapGeometry.cc | 7 +- RecoTracker/LSTCore/src/TiltedGeometry.cc | 8 +- RecoTracker/LSTGeometry/interface/Geometry.h | 6 +- RecoTracker/LSTGeometry/interface/IO.h | 15 ++-- .../interface/OrientationMethods.h | 78 ------------------- RecoTracker/LSTGeometry/interface/Slope.h | 25 ++++++ RecoTracker/LSTGeometry/interface/SlopeData.h | 13 ---- RecoTracker/LSTGeometry/src/Geometry.cc | 9 +-- RecoTracker/LSTGeometry/src/PixelMap.cc | 5 +- RecoTracker/LSTGeometry/src/Slope.cc | 52 +++++++++++++ .../LSTGeometry/test/runCompilationTest.sh | 8 -- 13 files changed, 101 insertions(+), 130 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/OrientationMethods.h create mode 100644 RecoTracker/LSTGeometry/interface/Slope.h delete mode 100644 RecoTracker/LSTGeometry/interface/SlopeData.h create mode 100644 RecoTracker/LSTGeometry/src/Slope.cc delete mode 100755 RecoTracker/LSTGeometry/test/runCompilationTest.sh diff --git a/RecoTracker/LSTCore/interface/EndcapGeometry.h b/RecoTracker/LSTCore/interface/EndcapGeometry.h index 27ebc8109457f..e97240c0f3690 100644 --- a/RecoTracker/LSTCore/interface/EndcapGeometry.h +++ b/RecoTracker/LSTCore/interface/EndcapGeometry.h @@ -23,8 +23,7 @@ namespace lst { EndcapGeometry(std::string const& filename); void load(std::string const&); - void load(std::unordered_map const&, - std::unordered_map const&); + void load(lstgeometry::Slopes const&, lstgeometry::Sensors const&); void fillGeoMapArraysExplicit(); float getdxdy_slope(unsigned int detid) const; }; diff --git a/RecoTracker/LSTCore/interface/TiltedGeometry.h b/RecoTracker/LSTCore/interface/TiltedGeometry.h index caeb2689e2f2b..a5d2c73ebbfc9 100644 --- a/RecoTracker/LSTCore/interface/TiltedGeometry.h +++ b/RecoTracker/LSTCore/interface/TiltedGeometry.h @@ -18,7 +18,7 @@ namespace lst { TiltedGeometry(std::string const& filename); void load(std::string const&); - void load(std::unordered_map const&); + void load(lstgeometry::Slopes const&); float getDrDz(unsigned int detid) const; float getDxDy(unsigned int detid) const; diff --git a/RecoTracker/LSTCore/src/EndcapGeometry.cc b/RecoTracker/LSTCore/src/EndcapGeometry.cc index 9d23517cfb3fe..f29002f555ee5 100644 --- a/RecoTracker/LSTCore/src/EndcapGeometry.cc +++ b/RecoTracker/LSTCore/src/EndcapGeometry.cc @@ -39,13 +39,12 @@ void lst::EndcapGeometry::load(std::string const& filename) { fillGeoMapArraysExplicit(); } -void lst::EndcapGeometry::load(std::unordered_map const& slopes, - std::unordered_map const& sensors) { +void lst::EndcapGeometry::load(lstgeometry::Slopes const& slopes, lstgeometry::Sensors const& sensors) { dxdy_slope_.clear(); centroid_phis_.clear(); - for (const auto& [detId, slopeData] : slopes) { - dxdy_slope_[detId] = slopeData.dxdy_slope; + for (const auto& [detId, slope] : slopes) { + dxdy_slope_[detId] = slope.dxdy; centroid_phis_[detId] = sensors.at(detId).centerPhi; } diff --git a/RecoTracker/LSTCore/src/TiltedGeometry.cc b/RecoTracker/LSTCore/src/TiltedGeometry.cc index 2c579cfed2020..cf5138d4fb384 100644 --- a/RecoTracker/LSTCore/src/TiltedGeometry.cc +++ b/RecoTracker/LSTCore/src/TiltedGeometry.cc @@ -37,13 +37,13 @@ void lst::TiltedGeometry::load(std::string const& filename) { } } -void lst::TiltedGeometry::load(std::unordered_map const& slopes) { +void lst::TiltedGeometry::load(lstgeometry::Slopes const& slopes) { drdzs_.clear(); dxdys_.clear(); - for (const auto& [detId, slopeData] : slopes) { - drdzs_[detId] = slopeData.drdz_slope; - dxdys_[detId] = slopeData.dxdy_slope; + for (const auto& [detId, slope] : slopes) { + drdzs_[detId] = slope.drdz; + dxdys_[detId] = slope.dxdy; } } diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 5e2f251d8760d..99a633642ab24 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_LSTGeometry_interface_Geometry_h #define RecoTracker_LSTGeometry_interface_Geometry_h -#include "RecoTracker/LSTGeometry/interface/SlopeData.h" +#include "RecoTracker/LSTGeometry/interface/Slope.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/ModuleMap.h" #include "RecoTracker/LSTGeometry/interface/Module.h" @@ -11,8 +11,8 @@ namespace lstgeometry { struct Geometry { Sensors sensors; - std::unordered_map barrel_slopes; - std::unordered_map endcap_slopes; + Slopes barrel_slopes; + Slopes endcap_slopes; PixelMap pixel_map; ModuleMap module_map; diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index ca09283852963..ccfb39d0c6bc4 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -13,7 +13,7 @@ #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" -#include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" +#include "RecoTracker/LSTGeometry/interface/Slope.h" namespace lstgeometry { @@ -44,10 +44,7 @@ namespace lstgeometry { } } - void writeSlopes(std::unordered_map const& slopes, - Sensors const& sensors, - std::string const& base_filename, - bool binary = true) { + void writeSlopes(Slopes const& slopes, Sensors const& sensors, std::string const& base_filename, bool binary = true) { std::filesystem::path filepath(base_filename); std::filesystem::create_directories(filepath.parent_path()); @@ -56,8 +53,8 @@ namespace lstgeometry { if (binary) { for (auto& [detid, slope] : slopes) { - float drdz_slope = slope.drdz_slope; - float dxdy_slope = slope.dxdy_slope; + float drdz_slope = slope.drdz; + float dxdy_slope = slope.dxdy; float phi = sensors.at(detid).centerPhi; file.write(reinterpret_cast(&detid), sizeof(detid)); if (drdz_slope != kDefaultSlope) { @@ -70,8 +67,8 @@ namespace lstgeometry { } } else { for (auto& [detid, slope] : slopes) { - float drdz_slope = slope.drdz_slope; - float dxdy_slope = slope.dxdy_slope; + float drdz_slope = slope.drdz; + float dxdy_slope = slope.dxdy; float phi = sensors.at(detid).centerPhi; file << detid << ","; if (drdz_slope != kDefaultSlope) { diff --git a/RecoTracker/LSTGeometry/interface/OrientationMethods.h b/RecoTracker/LSTGeometry/interface/OrientationMethods.h deleted file mode 100644 index d6ef1bfb0583f..0000000000000 --- a/RecoTracker/LSTGeometry/interface/OrientationMethods.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_OrientationMethods_h -#define RecoTracker_LSTGeometry_interface_OrientationMethods_h - -#include -#include -#include -#include /////////////////////// remove - -#include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" -#include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/SlopeData.h" - -namespace lstgeometry { - - bool isStripLayer(Module module, bool isLower) { - if (module.moduleType == ModuleType::Ph2SS) - return true; - if (isInverted(module.moduleId, module.location, module.side, module.layer)) - return isLower; - return !isLower; - } - - // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. - SlopeData calculateSlope(float dx, float dy, float dz) { - float dr = sqrt(dx * dx + dy * dy); - float drdz_slope = dz != 0 ? dr / dz : kDefaultSlope; - float dxdy_slope = dy != 0 ? -dx / dy : kDefaultSlope; - return SlopeData{drdz_slope, dxdy_slope}; - } - - // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. - std::tuple, std::unordered_map> processCorners( - Modules const& modules, Sensors const& sensors) { - std::unordered_map barrel_slopes; - std::unordered_map endcap_slopes; - - std::cout << "Number of sensors: " << sensors.size() << std::endl; /////////////////////// remove - - for (const auto& [detId, sensor] : sensors) { - float dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); - float dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); - float dz = roundCoordinate(sensor.corners(1, 0) - sensor.corners(0, 0)); - - SlopeData slope = calculateSlope(dx, dy, dz); - - auto& module = modules.at(sensor.moduleDetId); - - auto location = module.location; - bool is_tilted = module.side != Side::Center; - bool is_strip = isStripLayer(module, sensor.isLower); - - std::cout << "Processing detId " << detId - << ", location: " << (location == Location::barrel ? "barrel" : "endcap") - << ", is_tilted: " << is_tilted << ", isstrip: " << is_strip << ", isLower: " << sensor.isLower - << ", moduleId: " << module.moduleId << ", layer: " << module.layer - << ", isInverted: " << isInverted(module.moduleId, module.location, module.side, module.layer) - << ", drdz_slope: " << slope.drdz_slope << ", dxdy_slope: " << slope.dxdy_slope - << std::endl; /////////////////////// remove - - if (!is_strip) - continue; - - std::cout << "DetId: " << detId << ", location: " << (location == Location::barrel ? "barrel" : "endcap") - << ", is_tilted: " << is_tilted << ", drdz_slope: " << slope.drdz_slope - << ", dxdy_slope: " << slope.dxdy_slope << std::endl; /////////////////////// remove - - if (location == Location::barrel and is_tilted) - barrel_slopes[detId] = slope; - else if (location == Location::endcap) - endcap_slopes[detId] = slope; - } - - return std::make_tuple(barrel_slopes, endcap_slopes); - } -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/Slope.h b/RecoTracker/LSTGeometry/interface/Slope.h new file mode 100644 index 0000000000000..82dc4a243d258 --- /dev/null +++ b/RecoTracker/LSTGeometry/interface/Slope.h @@ -0,0 +1,25 @@ +#ifndef RecoTracker_LSTGeometry_interface_Slope_h +#define RecoTracker_LSTGeometry_interface_Slope_h + +#include + +#include "RecoTracker/LSTGeometry/interface/Module.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" + +namespace lstgeometry { + + struct Slope { + float drdz; + float dxdy; + + Slope() = default; + Slope(float dx, float dy, float dz); + }; + + using Slopes = std::unordered_map; + + std::tuple computeSlopes(Modules const& modules, Sensors const& sensors); + +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTGeometry/interface/SlopeData.h b/RecoTracker/LSTGeometry/interface/SlopeData.h deleted file mode 100644 index 97c14826a6407..0000000000000 --- a/RecoTracker/LSTGeometry/interface/SlopeData.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_SlopeData_h -#define RecoTracker_LSTGeometry_interface_SlopeData_h - -namespace lstgeometry { - - struct SlopeData { - float drdz_slope; - float dxdy_slope; - }; - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index a5312efe8dc01..9813a18657709 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -1,9 +1,7 @@ #include "RecoTracker/LSTGeometry/interface/Geometry.h" #include "RecoTracker/LSTGeometry/interface/CornerMethods.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/OrientationMethods.h" - -#include /////////////////////// remove +#include "RecoTracker/LSTGeometry/interface/Slope.h" using namespace lstgeometry; @@ -17,10 +15,7 @@ Geometry::Geometry(Modules &modules, assignCornersToSensors(modules, sensors_input); - // std::cout << "Corners are " << std::endl; - // std::cout << sensors_input.at(440165400 + 1).corners << std::endl; /////////////////////// remove - - auto slopes = processCorners(modules, sensors_input); + auto slopes = computeSlopes(modules, sensors_input); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index 7706b34ad75e9..45fe19f32baba 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -3,7 +3,10 @@ namespace lstgeometry { - PixelMap buildPixelMap(Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut) { + PixelMap buildPixelMap(Modules const& modules, + Sensors const& sensors, + DetectorGeometry const& det_geom, + float pt_cut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; diff --git a/RecoTracker/LSTGeometry/src/Slope.cc b/RecoTracker/LSTGeometry/src/Slope.cc new file mode 100644 index 0000000000000..aa558cc747de6 --- /dev/null +++ b/RecoTracker/LSTGeometry/src/Slope.cc @@ -0,0 +1,52 @@ +#include +#include + +#include "RecoTracker/LSTGeometry/interface/Common.h" +#include "RecoTracker/LSTGeometry/interface/Slope.h" + +namespace lstgeometry { + + Slope::Slope(float dx, float dy, float dz) { + float dr = sqrt(dx * dx + dy * dy); + drdz = dz != 0 ? dr / dz : kDefaultSlope; + dxdy = dy != 0 ? -dx / dy : kDefaultSlope; + } + + bool isStripLayer(Module module, bool isLower) { + if (module.moduleType == ModuleType::Ph2SS) + return true; + if (isInverted(module.moduleId, module.location, module.side, module.layer)) + return isLower; + return !isLower; + } + + // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. + std::tuple computeSlopes(Modules const& modules, Sensors const& sensors) { + Slopes barrel_slopes; + Slopes endcap_slopes; + + for (const auto& [detId, sensor] : sensors) { + float dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); + float dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); + float dz = roundCoordinate(sensor.corners(1, 0) - sensor.corners(0, 0)); + + Slope slope(dx, dy, dz); + + auto& module = modules.at(sensor.moduleDetId); + + auto location = module.location; + bool is_tilted = module.side != Side::Center; + bool is_strip = isStripLayer(module, sensor.isLower); + + if (!is_strip) + continue; + + if (location == Location::barrel and is_tilted) + barrel_slopes[detId] = slope; + else if (location == Location::endcap) + endcap_slopes[detId] = slope; + } + + return std::make_tuple(barrel_slopes, endcap_slopes); + } +} // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/test/runCompilationTest.sh b/RecoTracker/LSTGeometry/test/runCompilationTest.sh deleted file mode 100755 index a1aa288b90d74..0000000000000 --- a/RecoTracker/LSTGeometry/test/runCompilationTest.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -cp -r $CMSSW_BASE/src/RecoTracker/LSTCore ./ -find LSTCore -type d | xargs chmod +w -cd LSTCore/standalone -source setup.sh -echo "Building LST CPU backend..." -lst_make_tracklooper -mCs From 0ff7265da7222334e66897ecaf0c561864c3c1e5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 5 Mar 2026 11:03:41 -0500 Subject: [PATCH 85/95] Find corners with CMSSW functionality --- .../LSTGeometry/interface/CornerMethods.h | 140 ------------------ RecoTracker/LSTGeometry/interface/Module.h | 4 - RecoTracker/LSTGeometry/interface/Sensor.h | 3 +- .../plugins/LSTGeometryESProducer.cc | 40 +---- RecoTracker/LSTGeometry/src/Geometry.cc | 5 - RecoTracker/LSTGeometry/src/Sensor.cc | 22 ++- 6 files changed, 23 insertions(+), 191 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/CornerMethods.h diff --git a/RecoTracker/LSTGeometry/interface/CornerMethods.h b/RecoTracker/LSTGeometry/interface/CornerMethods.h deleted file mode 100644 index df6a974130f92..0000000000000 --- a/RecoTracker/LSTGeometry/interface/CornerMethods.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_CornerMethods_h -#define RecoTracker_LSTGeometry_interface_CornerMethods_h - -#include -#include -#include - -#include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" -#include "RecoTracker/LSTGeometry/interface/Sensor.h" - -namespace lstgeometry { - - //Calculates the Rodrigues' rotation matrix for rotating a vector around an arbitrary axis. - MatrixF3x3 rodriguesRotationMatrix(ColVectorF3 axis, float theta) { - axis.normalize(); - - MatrixF3x3 k{{0, -axis(2), axis(1)}, {axis(2), 0, -axis(0)}, {-axis(1), axis(0), 0}}; - - MatrixF3x3 rotationMatrix = MatrixF3x3::Identity() + std::sin(theta) * k + (1 - std::cos(theta)) * (k * k); - - return rotationMatrix; - } - - // Generates a rotation matrix for rotating around the tangential direction in cylindrical coordinates. - MatrixF3x3 tangentialRotationMatrix(float phi, float theta) { - ColVectorF3 axis; - axis << -std::sin(phi), std::cos(phi), 0; - - return rodriguesRotationMatrix(axis, theta); - } - - // Computes the final rotation matrix based on tilt and phi angles. - // Note: - // Only the tilt angles are non-zero for the current geometry. If the other - // angles get used, implement their rotations using the tangentialRotationMatrix - // function above as an example. - MatrixF3x3 rotationMatrix(float tilt, float skew, float yaw, float phi) { - if (skew != 0 || yaw != 0) - throw std::invalid_argument("Skew and yaw angles are not currently supported."); - - // Rotation around Z-axis that makes the sensor "face towards" the beamline (i.e. towards z-axis) - // So for example if phi=0 then R is the identity (i.e. already facing), or if phi=90deg - // then R becomes (x,y,z)->(-y,x,z) so the sensor is rotated 90 degrees to face the beamline - MatrixF3x3 initialR{{std::cos(phi), -std::sin(phi), 0}, {std::sin(phi), std::cos(phi), 0}, {0, 0, 1}}; - - // The tilt angle given in the CSV files is with respect to a module that is facing - // the beamline, meaning after R_initial is applied. From there we tilt the module according - // to the rotation below. Note that because this tilt angle is not with respect to the X,Y,Z - // axes and is instead around an arbitrary axis (defined from the rotation above) we have to apply - // the Rodrigues' rotation formula - MatrixF3x3 rTilt = tangentialRotationMatrix(phi, -tilt); - - MatrixF3x3 finalR = rTilt * initialR; - - return finalR; - } - - // Calculates the transformed corners of each sensor - void transformSensorCorners(Module& module) { - auto module_z = module.centerZ; - auto module_rho = module.centerRho; - auto module_phi = module.centerPhi; - auto sensor_spacing = module.spacing; - auto sensor_width = module.meanWidth; - auto sensor_length = module.length; - - auto module_x = module_rho * std::cos(module_phi); - auto module_y = module_rho * std::sin(module_phi); - - auto half_width = sensor_width / 2; - auto half_length = sensor_length / 2; - auto half_spacing = sensor_spacing / 2; - - // Make the module sizes consistent with hit-based method. - // FIXME: Using the real (smaller) sizes specified by CSV file increases - // fake rate significantly and lowers efficiency between abs(eta) 1 to 2. - auto width_extension = 5.0 - half_width; - auto length_extension = (half_length > 4 ? 5.0 : 2.5) - half_length; - - half_width += width_extension; - half_length += length_extension; - - MatrixF8x3 corners{{-half_spacing, -half_width, -half_length}, - {-half_spacing, -half_width, half_length}, - {-half_spacing, half_width, half_length}, - {-half_spacing, half_width, -half_length}, - {half_spacing, -half_width, -half_length}, - {half_spacing, -half_width, half_length}, - {half_spacing, half_width, half_length}, - {half_spacing, half_width, -half_length}}; - - MatrixF3x3 rotation_matrix = rotationMatrix(module.tiltAngle, module.skewAngle, module.yawAngle, module.centerPhi); - MatrixF8x3 rotated_corners = (rotation_matrix * corners.transpose()).transpose(); - - rotated_corners.rowwise() += RowVectorF3{module_x, module_y, module_z}; - - // Coordinate reorder before saving (x,y,z)->(z,x,y) - module.transformedCorners.col(0) = rotated_corners.col(2); - module.transformedCorners.col(1) = rotated_corners.col(0); - module.transformedCorners.col(2) = rotated_corners.col(1); - } - - // Assigns each set of four corners to the correct sensor DetID based on the closest centroid. - void assignCornersToSensors(Modules const& modules, Sensors& sensors) { - for (auto const& [detId, module] : modules) { - unsigned int module_det_id = detId; - unsigned int sensor_det_id_1 = module_det_id + 1; - unsigned int sensor_det_id_2 = module_det_id + 2; - - auto& transformed_corners = module.transformedCorners; - RowVectorF3 centroid_sensor_1 = transformed_corners.topRows(4).colwise().mean(); - RowVectorF3 centroid_sensor_2 = transformed_corners.bottomRows(4).colwise().mean(); - - float sensor1_center_z = sensors.at(sensor_det_id_1).centerZ; - float sensor1_center_x = sensors.at(sensor_det_id_1).centerRho * cos(sensors.at(sensor_det_id_1).centerPhi); - float sensor1_center_y = sensors.at(sensor_det_id_1).centerRho * sin(sensors.at(sensor_det_id_1).centerPhi); - float sensor2_center_z = sensors.at(sensor_det_id_2).centerZ; - float sensor2_center_x = sensors.at(sensor_det_id_2).centerRho * cos(sensors.at(sensor_det_id_2).centerPhi); - float sensor2_center_y = sensors.at(sensor_det_id_2).centerRho * sin(sensors.at(sensor_det_id_2).centerPhi); - - RowVectorF3 sensor_centroid_1{sensor1_center_z, sensor1_center_x, sensor1_center_y}; - RowVectorF3 sensor_centroid_2{sensor2_center_z, sensor2_center_x, sensor2_center_y}; - - float distance_to_sensor_1 = (centroid_sensor_1 - sensor_centroid_1).norm(); - float distance_to_sensor_2 = (centroid_sensor_2 - sensor_centroid_2).norm(); - - if (distance_to_sensor_1 < distance_to_sensor_2) { - sensors[sensor_det_id_1].corners = transformed_corners.topRows(4); - sensors[sensor_det_id_2].corners = transformed_corners.bottomRows(4); - } else { - sensors[sensor_det_id_2].corners = transformed_corners.topRows(4); - sensors[sensor_det_id_1].corners = transformed_corners.bottomRows(4); - } - } - } - -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h index e628b3a2d0bc3..2edfb8d996360 100644 --- a/RecoTracker/LSTGeometry/interface/Module.h +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -21,10 +21,6 @@ namespace lstgeometry { float tiltAngle; float skewAngle; float yawAngle; - float meanWidth; - float length; - float spacing; - MatrixF8x3 transformedCorners; }; using Modules = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index bbb3215adb5ca..879cf370c58bb 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -4,6 +4,7 @@ #include #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "DataFormats/GeometrySurface/interface/Surface.h" #include "RecoTracker/LSTGeometry/interface/Common.h" @@ -23,7 +24,7 @@ namespace lstgeometry { Sensor() = default; Sensor( - unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType); + unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType, Surface const& surface); }; using Sensors = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index dea1b8dff0f83..3a15b97540b26 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -73,7 +73,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const unsigned int detid = detId(); const auto &surface = det->surface(); - const Bounds *b = &(surface).bounds(); const auto &position = surface.position(); const float rho_cm = position.perp(); @@ -95,44 +94,13 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const unsigned int moduleDetId = detid & ~0b11; // I don't think there is there a CMSSW method for this // Can't use TrackerTopology::isLower since it doesn't consider if the module is inverted const bool isLow = isLower(moduleId, location, side, layer, detid); - sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType); - - ///////////// tmp - // const RectangularPlaneBounds *sensor_bounds = dynamic_cast(b); - // float wid = sensor_bounds->width(); - // float len = sensor_bounds->length(); - // auto c1 = GloballyPositioned::LocalPoint(wid / 2, len / 2, 0); - // auto c2 = GloballyPositioned::LocalPoint(-wid / 2, len / 2, 0); - // auto c3 = GloballyPositioned::LocalPoint(-wid / 2, -len / 2, 0); - // auto c4 = GloballyPositioned::LocalPoint(wid / 2, -len / 2, 0); - // auto c1g = surface.toGlobal(c1); - // auto c2g = surface.toGlobal(c2); - // auto c3g = surface.toGlobal(c3); - // auto c4g = surface.toGlobal(c4); - // if (detid == 440165400 + 1) { - // std::cout << "Corners for detid " << detid << ": " << std::endl; - // std::cout << c1g << std::endl; - // std::cout << c2g << std::endl; - // std::cout << c3g << std::endl; - // std::cout << c4g << std::endl; - // } - /// + sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType, surface); continue; } - const RectangularPlaneBounds *b2 = dynamic_cast(b); - if (!b2) { - throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class"; - } - float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); - float meanWidth_cm = b2->width(); - float length_cm = b2->length(); - - float sensorSpacing_cm = det->components()[0]->toLocal(det->components()[1]->position()).mag(); - // Fix angles of some modules if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { tiltAngle_rad = std::numbers::pi_v / 2; @@ -160,11 +128,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac phi_rad, tiltAngle_rad, 0.0, - 0.0, - meanWidth_cm, - length_cm, - sensorSpacing_cm, - lstgeometry::MatrixF8x3::Zero()}; + 0.0}; modules[detid] = std::move(module); } diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 9813a18657709..26b3c89b92c3d 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -1,5 +1,4 @@ #include "RecoTracker/LSTGeometry/interface/Geometry.h" -#include "RecoTracker/LSTGeometry/interface/CornerMethods.h" #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/Slope.h" @@ -10,10 +9,6 @@ Geometry::Geometry(Modules &modules, std::vector const &average_r, std::vector const &average_z, float pt_cut) { - for (auto &[_, mod] : modules) - transformSensorCorners(mod); - - assignCornersToSensors(modules, sensors_input); auto slopes = computeSlopes(modules, sensors_input); barrel_slopes = std::move(std::get<0>(slopes)); diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc index 3ed9fc99413a2..c39e996d31b29 100644 --- a/RecoTracker/LSTGeometry/src/Sensor.cc +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -1,17 +1,33 @@ #include +#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" + #include "RecoTracker/LSTGeometry/interface/Sensor.h" using namespace lstgeometry; Sensor::Sensor( - unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType) + unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType, Surface const& surface) : moduleDetId(moduleDetId), centerRho(centerRho), centerZ(centerZ), centerPhi(centerPhi), isLower(isLower), - corners(MatrixF4x3::Zero()), moduleType(moduleType), centerX(centerRho * std::cos(centerPhi)), - centerY(centerRho * std::sin(centerPhi)) {} + centerY(centerRho * std::sin(centerPhi)) { + const Bounds &bounds = surface.bounds(); + const RectangularPlaneBounds &plane_bounds = dynamic_cast(bounds); + float wid = plane_bounds.width(); + float len = plane_bounds.length(); + auto c1 = GloballyPositioned::LocalPoint(-wid / 2, -len / 2, 0); + auto c2 = GloballyPositioned::LocalPoint(-wid / 2, len / 2, 0); + auto c3 = GloballyPositioned::LocalPoint(wid / 2, len / 2, 0); + auto c4 = GloballyPositioned::LocalPoint(wid / 2, -len / 2, 0); + auto c1g = surface.toGlobal(c1); + auto c2g = surface.toGlobal(c2); + auto c3g = surface.toGlobal(c3); + auto c4g = surface.toGlobal(c4); + // store corners with z, x, y ordering + corners << c1g.z(), c1g.x(), c1g.y(), c2g.z(), c2g.x(), c2g.y(), c3g.z(), c3g.x(), c3g.y(), c4g.z(), c4g.x(), c4g.y(); + } From 17c4e6d808206d11fceb0f3d0028712d7d13641f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 6 Mar 2026 17:00:51 +0000 Subject: [PATCH 86/95] Cleanup --- .../LSTCore/interface/EndcapGeometry.h | 6 ++- .../LSTCore/interface/ModuleConnectionMap.h | 4 +- .../LSTCore/interface/TiltedGeometry.h | 5 ++- RecoTracker/LSTCore/src/EndcapGeometry.cc | 4 ++ RecoTracker/LSTCore/src/LSTESData.cc | 4 +- .../LSTCore/src/ModuleConnectionMap.cc | 2 - RecoTracker/LSTCore/src/ModuleMethods.h | 2 + RecoTracker/LSTCore/src/TiltedGeometry.cc | 2 + .../LSTGeometry/interface/DetectorGeometry.h | 5 ++- RecoTracker/LSTGeometry/interface/Geometry.h | 6 ++- RecoTracker/LSTGeometry/interface/Module.h | 3 -- RecoTracker/LSTGeometry/interface/Sensor.h | 9 ++++- RecoTracker/LSTGeometry/plugins/BuildFile.xml | 21 ---------- .../plugins/LSTGeometryESProducer.cc | 28 ++----------- .../LSTGeometry/src/DetectorGeometry.cc | 8 ++-- RecoTracker/LSTGeometry/src/Geometry.cc | 18 ++++----- RecoTracker/LSTGeometry/src/Sensor.cc | 39 +++++++++++-------- 17 files changed, 71 insertions(+), 95 deletions(-) diff --git a/RecoTracker/LSTCore/interface/EndcapGeometry.h b/RecoTracker/LSTCore/interface/EndcapGeometry.h index e97240c0f3690..8772cbc4a7bf2 100644 --- a/RecoTracker/LSTCore/interface/EndcapGeometry.h +++ b/RecoTracker/LSTCore/interface/EndcapGeometry.h @@ -1,7 +1,8 @@ #ifndef RecoTracker_LSTCore_interface_EndcapGeometry_h #define RecoTracker_LSTCore_interface_EndcapGeometry_h -#include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include "RecoTracker/LSTGeometry/interface/Slope.h" +#include "RecoTracker/LSTGeometry/interface/Sensor.h" #include #include @@ -20,7 +21,8 @@ namespace lst { unsigned int nEndCapMap; EndcapGeometry() = default; - EndcapGeometry(std::string const& filename); + EndcapGeometry(std::string const&); + EndcapGeometry(lstgeometry::Slopes const&, lstgeometry::Sensors const&); void load(std::string const&); void load(lstgeometry::Slopes const&, lstgeometry::Sensors const&); diff --git a/RecoTracker/LSTCore/interface/ModuleConnectionMap.h b/RecoTracker/LSTCore/interface/ModuleConnectionMap.h index 7df14a0d0cf34..ecc04f2ad5d0b 100644 --- a/RecoTracker/LSTCore/interface/ModuleConnectionMap.h +++ b/RecoTracker/LSTCore/interface/ModuleConnectionMap.h @@ -12,8 +12,8 @@ namespace lst { std::map> moduleConnections_; public: - ModuleConnectionMap(); - ModuleConnectionMap(std::string const& filename); + ModuleConnectionMap() = default; + ModuleConnectionMap(std::string const&); ModuleConnectionMap(std::map> const&); void load(std::string const&); diff --git a/RecoTracker/LSTCore/interface/TiltedGeometry.h b/RecoTracker/LSTCore/interface/TiltedGeometry.h index a5d2c73ebbfc9..b5ce91de0d08c 100644 --- a/RecoTracker/LSTCore/interface/TiltedGeometry.h +++ b/RecoTracker/LSTCore/interface/TiltedGeometry.h @@ -1,7 +1,7 @@ #ifndef RecoTracker_LSTCore_interface_TiltedGeometry_h #define RecoTracker_LSTCore_interface_TiltedGeometry_h -#include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include "RecoTracker/LSTGeometry/interface/Slope.h" #include #include @@ -15,7 +15,8 @@ namespace lst { public: TiltedGeometry() = default; - TiltedGeometry(std::string const& filename); + TiltedGeometry(std::string const&); + TiltedGeometry(lstgeometry::Slopes const&); void load(std::string const&); void load(lstgeometry::Slopes const&); diff --git a/RecoTracker/LSTCore/src/EndcapGeometry.cc b/RecoTracker/LSTCore/src/EndcapGeometry.cc index f29002f555ee5..cfdebea6bd7d2 100644 --- a/RecoTracker/LSTCore/src/EndcapGeometry.cc +++ b/RecoTracker/LSTCore/src/EndcapGeometry.cc @@ -7,6 +7,10 @@ lst::EndcapGeometry::EndcapGeometry(std::string const& filename) { load(filename); } +lst::EndcapGeometry::EndcapGeometry(lstgeometry::Slopes const& slopes, lstgeometry::Sensors const& sensors) { + load(slopes, sensors); +} + void lst::EndcapGeometry::load(std::string const& filename) { dxdy_slope_.clear(); centroid_phis_.clear(); diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 559d8e3902ca3..4bf8f4e6b0aae 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -132,7 +132,7 @@ std::unique_ptr> lst::fillESDataHost(lstg PixelMap pixelMapping; ModuleConnectionMap moduleConnectionMap; - endcapGeometry.load(lstg.endcap_slopes, lstg.sensors); + endcapGeometry.load(lstg.endcap_slopes, *lstg.sensors); auto endcapGeometryDev = std::make_shared(cms::alpakatools::host(), endcapGeometry.nEndCapMap); std::memcpy(endcapGeometryDev->view().geoMapDetId().data(), @@ -170,7 +170,7 @@ std::unique_ptr> lst::fillESDataHost(lstg ModuleMetaData mmd; unsigned int counter = 0; - for (auto const& [detId, sensor] : lstg.sensors) { + for (auto const& [detId, sensor] : *lstg.sensors) { mmd.detIdToIndex[detId] = counter; mmd.module_x[detId] = sensor.centerX; mmd.module_y[detId] = sensor.centerY; diff --git a/RecoTracker/LSTCore/src/ModuleConnectionMap.cc b/RecoTracker/LSTCore/src/ModuleConnectionMap.cc index ca1c39a895ea4..64fcb0769886f 100644 --- a/RecoTracker/LSTCore/src/ModuleConnectionMap.cc +++ b/RecoTracker/LSTCore/src/ModuleConnectionMap.cc @@ -5,8 +5,6 @@ #include #include -lst::ModuleConnectionMap::ModuleConnectionMap() {} - lst::ModuleConnectionMap::ModuleConnectionMap(std::string const& filename) { load(filename); } lst::ModuleConnectionMap::ModuleConnectionMap(std::map> const& map) { diff --git a/RecoTracker/LSTCore/src/ModuleMethods.h b/RecoTracker/LSTCore/src/ModuleMethods.h index b9f9431ff012c..b100044d25de2 100644 --- a/RecoTracker/LSTCore/src/ModuleMethods.h +++ b/RecoTracker/LSTCore/src/ModuleMethods.h @@ -16,6 +16,8 @@ #include "HeterogeneousCore/AlpakaInterface/interface/memory.h" namespace lst { + // TODO: At some point it might be good to move some of these things to LSTGeometry + struct ModuleMetaData { std::map detIdToIndex; std::map module_x; diff --git a/RecoTracker/LSTCore/src/TiltedGeometry.cc b/RecoTracker/LSTCore/src/TiltedGeometry.cc index cf5138d4fb384..049bddfbd34d1 100644 --- a/RecoTracker/LSTCore/src/TiltedGeometry.cc +++ b/RecoTracker/LSTCore/src/TiltedGeometry.cc @@ -7,6 +7,8 @@ lst::TiltedGeometry::TiltedGeometry(std::string const& filename) { load(filename); } +lst::TiltedGeometry::TiltedGeometry(lstgeometry::Slopes const& slopes) { load(slopes); } + void lst::TiltedGeometry::load(std::string const& filename) { drdzs_.clear(); dxdys_.clear(); diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index ce1e39b816dac..c6eba412ab900 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "RecoTracker/LSTGeometry/interface/Common.h" @@ -16,7 +17,7 @@ namespace lstgeometry { class DetectorGeometry { private: - Sensors sensors_; // TODO: Refactor to avoid a copy + std::shared_ptr sensors_; std::vector avg_radii_; std::vector avg_z_; std::unordered_map, boost::hash> @@ -25,7 +26,7 @@ namespace lstgeometry { endcap_lower_det_ids_; public: - DetectorGeometry(Sensors sensors, std::vector avg_radii, std::vector avg_z); + DetectorGeometry(std::shared_ptr sensors, std::vector avg_radii, std::vector avg_z); MatrixF4x3 const& getCorners(unsigned int detId) const; diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 99a633642ab24..b7d5739e7e52b 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -1,6 +1,8 @@ #ifndef RecoTracker_LSTGeometry_interface_Geometry_h #define RecoTracker_LSTGeometry_interface_Geometry_h +#include + #include "RecoTracker/LSTGeometry/interface/Slope.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/ModuleMap.h" @@ -10,14 +12,14 @@ namespace lstgeometry { struct Geometry { - Sensors sensors; + std::shared_ptr sensors; Slopes barrel_slopes; Slopes endcap_slopes; PixelMap pixel_map; ModuleMap module_map; Geometry(Modules &modules, - Sensors &sensors_input, + std::shared_ptr sensors, std::vector const &average_r, std::vector const &average_z, float ptCut); diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h index 2edfb8d996360..f5e240bbf26d1 100644 --- a/RecoTracker/LSTGeometry/interface/Module.h +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -18,9 +18,6 @@ namespace lstgeometry { float centerRho; float centerZ; float centerPhi; - float tiltAngle; - float skewAngle; - float yawAngle; }; using Modules = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index 879cf370c58bb..b184359817007 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -23,8 +23,13 @@ namespace lstgeometry { float centerY; Sensor() = default; - Sensor( - unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType, Surface const& surface); + Sensor(unsigned int moduleDetId, + float centerRho, + float centerZ, + float centerPhi, + bool isLower, + ModuleType moduleType, + Surface const& surface); }; using Sensors = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/plugins/BuildFile.xml b/RecoTracker/LSTGeometry/plugins/BuildFile.xml index b6605e7f1930c..426d05870b1e2 100644 --- a/RecoTracker/LSTGeometry/plugins/BuildFile.xml +++ b/RecoTracker/LSTGeometry/plugins/BuildFile.xml @@ -1,36 +1,15 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index 3a15b97540b26..5162a8ea11b23 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -15,7 +15,6 @@ #include #include #include -#include /////////////////////// remove class LSTGeometryESProducer : public edm::ESProducer { public: @@ -53,7 +52,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac trackerTopo_ = &iRecord.get(ttopoToken_); lstgeometry::Modules modules; - lstgeometry::Sensors sensors; + auto sensors = std::make_shared(); std::vector avg_r_cm(6, 0.0); std::vector avg_z_cm(5, 0.0); @@ -94,20 +93,11 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac const unsigned int moduleDetId = detid & ~0b11; // I don't think there is there a CMSSW method for this // Can't use TrackerTopology::isLower since it doesn't consider if the module is inverted const bool isLow = isLower(moduleId, location, side, layer, detid); - sensors[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType, surface); + (*sensors)[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType, surface); continue; } - float tiltAngle_rad = lstgeometry::roundAngle(std::asin(det->rotation().zz())); - - // Fix angles of some modules - if (std::fabs(std::fabs(tiltAngle_rad) - std::numbers::pi_v / 2) < 1e-3) { - tiltAngle_rad = std::numbers::pi_v / 2; - } else if (std::fabs(tiltAngle_rad) > 1e-3) { - tiltAngle_rad = std::copysign(tiltAngle_rad, z_cm); - } - if (location == lstgeometry::Location::barrel) { avg_r_cm[layer - 1] += rho_cm; avg_r_counter[layer - 1] += 1; @@ -116,19 +106,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac avg_z_counter[layer - 1] += 1; } - lstgeometry::Module module{moduleType, - subdet, - location, - side, - moduleId, - layer, - ring, - rho_cm, - z_cm, - phi_rad, - tiltAngle_rad, - 0.0, - 0.0}; + lstgeometry::Module module{moduleType, subdet, location, side, moduleId, layer, ring, rho_cm, z_cm, phi_rad}; modules[detid] = std::move(module); } diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 3e03b6a56dde5..67d999f8affb0 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -61,15 +61,17 @@ namespace lstgeometry { return std::make_pair(eta_bin, phi_bin); } - DetectorGeometry::DetectorGeometry(Sensors sensors, std::vector avg_radii, std::vector avg_z) + DetectorGeometry::DetectorGeometry(std::shared_ptr sensors, + std::vector avg_radii, + std::vector avg_z) : sensors_(sensors), avg_radii_(avg_radii), avg_z_(avg_z) {} - MatrixF4x3 const& DetectorGeometry::getCorners(unsigned int detId) const { return sensors_.at(detId).corners; } + MatrixF4x3 const& DetectorGeometry::getCorners(unsigned int detId) const { return sensors_->at(detId).corners; } std::vector DetectorGeometry::getDetIds( std::function&)> filter) const { std::vector detIds; - for (const auto& entry : sensors_) { + for (const auto& entry : *sensors_) { if (filter(entry)) { detIds.push_back(entry.first); } diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 26b3c89b92c3d..c69720275953d 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -5,23 +5,21 @@ using namespace lstgeometry; Geometry::Geometry(Modules &modules, - Sensors &sensors_input, + std::shared_ptr sensors, std::vector const &average_r, std::vector const &average_z, - float pt_cut) { - - auto slopes = computeSlopes(modules, sensors_input); + float pt_cut) + : sensors(sensors) { + auto slopes = computeSlopes(modules, *sensors); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); - auto det_geom = DetectorGeometry(sensors_input, average_r, average_z); - det_geom.buildByLayer(modules, sensors_input); - - pixel_map = buildPixelMap(modules, sensors_input, det_geom, pt_cut); + auto det_geom = DetectorGeometry(sensors, average_r, average_z); + det_geom.buildByLayer(modules, *sensors); - module_map = buildModuleMap(modules, sensors_input, det_geom, pt_cut); + pixel_map = buildPixelMap(modules, *sensors, det_geom, pt_cut); - sensors = sensors_input; + module_map = buildModuleMap(modules, *sensors, det_geom, pt_cut); } #include "FWCore/Utilities/interface/typelookup.h" diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc index c39e996d31b29..2b057a91e3e59 100644 --- a/RecoTracker/LSTGeometry/src/Sensor.cc +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -6,8 +6,13 @@ using namespace lstgeometry; -Sensor::Sensor( - unsigned int moduleDetId, float centerRho, float centerZ, float centerPhi, bool isLower, ModuleType moduleType, Surface const& surface) +Sensor::Sensor(unsigned int moduleDetId, + float centerRho, + float centerZ, + float centerPhi, + bool isLower, + ModuleType moduleType, + Surface const &surface) : moduleDetId(moduleDetId), centerRho(centerRho), centerZ(centerZ), @@ -16,18 +21,18 @@ Sensor::Sensor( moduleType(moduleType), centerX(centerRho * std::cos(centerPhi)), centerY(centerRho * std::sin(centerPhi)) { - const Bounds &bounds = surface.bounds(); - const RectangularPlaneBounds &plane_bounds = dynamic_cast(bounds); - float wid = plane_bounds.width(); - float len = plane_bounds.length(); - auto c1 = GloballyPositioned::LocalPoint(-wid / 2, -len / 2, 0); - auto c2 = GloballyPositioned::LocalPoint(-wid / 2, len / 2, 0); - auto c3 = GloballyPositioned::LocalPoint(wid / 2, len / 2, 0); - auto c4 = GloballyPositioned::LocalPoint(wid / 2, -len / 2, 0); - auto c1g = surface.toGlobal(c1); - auto c2g = surface.toGlobal(c2); - auto c3g = surface.toGlobal(c3); - auto c4g = surface.toGlobal(c4); - // store corners with z, x, y ordering - corners << c1g.z(), c1g.x(), c1g.y(), c2g.z(), c2g.x(), c2g.y(), c3g.z(), c3g.x(), c3g.y(), c4g.z(), c4g.x(), c4g.y(); - } + const Bounds &bounds = surface.bounds(); + const RectangularPlaneBounds &plane_bounds = dynamic_cast(bounds); + float wid = plane_bounds.width(); + float len = plane_bounds.length(); + auto c1 = GloballyPositioned::LocalPoint(-wid / 2, -len / 2, 0); + auto c2 = GloballyPositioned::LocalPoint(-wid / 2, len / 2, 0); + auto c3 = GloballyPositioned::LocalPoint(wid / 2, len / 2, 0); + auto c4 = GloballyPositioned::LocalPoint(wid / 2, -len / 2, 0); + auto c1g = surface.toGlobal(c1); + auto c2g = surface.toGlobal(c2); + auto c3g = surface.toGlobal(c3); + auto c4g = surface.toGlobal(c4); + // store corners with z, x, y ordering + corners << c1g.z(), c1g.x(), c1g.y(), c2g.z(), c2g.x(), c2g.y(), c3g.z(), c3g.x(), c3g.y(), c4g.z(), c4g.x(), c4g.y(); +} From b9b0db95f168b45bd4d951dafb3784cf2b604371 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 6 Mar 2026 20:03:00 +0000 Subject: [PATCH 87/95] Tried to fix producer labels --- .../plugins/alpaka/LSTModulesDevESProducer.cc | 10 ++++++++-- RecoTracker/LST/plugins/alpaka/LSTProducer.cc | 18 +++++++++++++---- .../plugins/LSTGeometryESProducer.cc | 7 ++++++- .../LSTGeometry/test/DumpLSTGeometry.cc | 20 +++++++++++++------ .../LSTGeometry/test/dumpLSTGeometry.py | 2 +- 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc index aa91e8e322d69..47771e7041d20 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTModulesDevESProducer.cc @@ -1,3 +1,5 @@ +#include + // LST includes #include "RecoTracker/LSTCore/interface/alpaka/LST.h" #include "RecoTracker/LSTGeometry/interface/Geometry.h" @@ -21,8 +23,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { public: LSTModulesDevESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig), ptCut_(iConfig.getParameter("ptCut")) { - auto cc = setWhatProduced(this, "LSTModuleMaps"); - lstGeoToken_ = cc.consumes(edm::ESInputTag("", "LSTGeometry")); + std::ostringstream ptCutOSS; + ptCutOSS << std::setprecision(1) << ptCut_; + std::string ptCutStr = ptCutOSS.str(); + + auto cc = setWhatProduced(this, "LSTModuleMaps_" + ptCutStr); + lstGeoToken_ = cc.consumes(edm::ESInputTag("", "LSTGeometry_" + ptCutStr)); } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index eed5fb75c9427..652a6bb63222c 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -1,5 +1,7 @@ #include +#include + #include "RecoTracker/LSTCore/interface/alpaka/LST.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -25,13 +27,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { public: LSTProducer(edm::ParameterSet const& config) : EDProducer(config), - lstInputToken_{consumes(config.getParameter("lstInput"))}, - lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps"))}, verbose_(config.getParameter("verbose")), ptCut_(config.getParameter("ptCut")), + ptCutStr_(getPtCutStr(ptCut_)), clustSizeCut_(static_cast(config.getParameter("clustSizeCut"))), nopLSDupClean_(config.getParameter("nopLSDupClean")), tcpLSTriplets_(config.getParameter("tcpLSTriplets")), + lstInputToken_{consumes(config.getParameter("lstInput"))}, + lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps_"+ptCutStr_)))}, lstOutputToken_{produces()} {} void produce(edm::StreamID sid, device::Event& iEvent, const device::EventSetup& iSetup) const override { @@ -66,14 +69,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } private: - const device::EDGetToken lstInputToken_; - const device::ESGetToken, TrackerRecoGeometryRecord> lstESToken_; const bool verbose_; const double ptCut_; + const std::string ptCutStr_; const uint16_t clustSizeCut_; const bool nopLSDupClean_; const bool tcpLSTriplets_; + const device::EDGetToken lstInputToken_; + const device::ESGetToken, TrackerRecoGeometryRecord> lstESToken_; const device::EDPutToken lstOutputToken_; + + static std::string getPtCutStr(double ptCut) { + std::ostringstream ptCutOSS; + ptCutOSS << std::setprecision(1) << ptCut; + return ptCutOSS.str(); + } }; } // namespace ALPAKA_ACCELERATOR_NAMESPACE diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index 5162a8ea11b23..fdff13e2dde55 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -15,6 +15,7 @@ #include #include #include +#include class LSTGeometryESProducer : public edm::ESProducer { public: @@ -36,7 +37,11 @@ class LSTGeometryESProducer : public edm::ESProducer { LSTGeometryESProducer::LSTGeometryESProducer(const edm::ParameterSet &iConfig) : ptCut_(iConfig.getParameter("ptCut")) { - auto cc = setWhatProduced(this, "LSTGeometry"); + std::ostringstream ptCutOSS; + ptCutOSS << std::setprecision(1) << ptCut_; + std::string ptCutStr = ptCutOSS.str(); + + auto cc = setWhatProduced(this, "LSTGeometry_" + ptCutStr); geomToken_ = cc.consumes(); ttopoToken_ = cc.consumes(); } diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index 250386a12202d..4528ad59f8a71 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -16,26 +16,34 @@ class DumpLSTGeometry : public edm::one::EDAnalyzer<> { private: void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override; - std::string ptCut_; + double ptCut_; + std::string ptCutStr_; std::string outputDirectory_; bool binaryOutput_; edm::ESGetToken lstGeoToken_; + + static std::string getPtCutStr(double ptCut) { + std::ostringstream ptCutOSS; + ptCutOSS << std::setprecision(1) << ptCut; + return ptCutOSS.str(); + } }; DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) - : ptCut_(config.getParameter("ptCut")), + : ptCut_(config.getParameter("ptCut")), + ptCutStr_(getPtCutStr(ptCut_)), outputDirectory_(config.getUntrackedParameter("outputDirectory", "data/")), binaryOutput_(config.getUntrackedParameter("outputAsBinary", true)), - lstGeoToken_{esConsumes(edm::ESInputTag("", "LSTGeometry"))} {} + lstGeoToken_{esConsumes(edm::ESInputTag("", "LSTGeometry_" + ptCutStr_))} {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { const auto& lstg = iSetup.getData(lstGeoToken_); - lstgeometry::writeSensorCentroids(lstg.sensors, outputDirectory_ + "sensor_centroids", binaryOutput_); + lstgeometry::writeSensorCentroids(*lstg.sensors, outputDirectory_ + "sensor_centroids", binaryOutput_); lstgeometry::writeSlopes( - lstg.barrel_slopes, lstg.sensors, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); - lstgeometry::writeSlopes(lstg.endcap_slopes, lstg.sensors, outputDirectory_ + "endcap_orientation", binaryOutput_); + lstg.barrel_slopes, *lstg.sensors, outputDirectory_ + "tilted_barrel_orientation", binaryOutput_); + lstgeometry::writeSlopes(lstg.endcap_slopes, *lstg.sensors, outputDirectory_ + "endcap_orientation", binaryOutput_); lstgeometry::writePixelMaps(lstg.pixel_map, outputDirectory_ + "pixelmap/pLS_map", binaryOutput_); lstgeometry::writeModuleConnections( lstg.module_map, outputDirectory_ + "module_connection_tracing_merged", binaryOutput_); diff --git a/RecoTracker/LSTGeometry/test/dumpLSTGeometry.py b/RecoTracker/LSTGeometry/test/dumpLSTGeometry.py index 1988ce88d15df..7082a094333a3 100644 --- a/RecoTracker/LSTGeometry/test/dumpLSTGeometry.py +++ b/RecoTracker/LSTGeometry/test/dumpLSTGeometry.py @@ -60,7 +60,7 @@ process.dump = cms.EDAnalyzer( "DumpLSTGeometry", outputDirectory = cms.untracked.string(options.outputDirectory), - ptCut = cms.string(str(options.ptCut)), + ptCut = cms.double(options.ptCut), outputAsBinary = cms.untracked.bool(options.binaryOutput), ) From fda1b75b3b9c75332a49c9f5db37788c5adaff27 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 6 Mar 2026 20:27:24 +0000 Subject: [PATCH 88/95] Fixed typo --- RecoTracker/LST/plugins/alpaka/LSTProducer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index 652a6bb63222c..4708ea86e0513 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -34,7 +34,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { nopLSDupClean_(config.getParameter("nopLSDupClean")), tcpLSTriplets_(config.getParameter("tcpLSTriplets")), lstInputToken_{consumes(config.getParameter("lstInput"))}, - lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps_"+ptCutStr_)))}, + lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps_"+ptCutStr_))}, lstOutputToken_{produces()} {} void produce(edm::StreamID sid, device::Event& iEvent, const device::EventSetup& iSetup) const override { From 0bef46d4a044efd20d2a9e8acdc362b37f742461 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 10 Mar 2026 14:44:11 -0400 Subject: [PATCH 89/95] Started addressing review comments --- RecoTracker/LSTCore/interface/Common.h | 7 ++++ .../LSTCore/interface/EndcapGeometry.h | 2 +- RecoTracker/LSTCore/interface/alpaka/Common.h | 4 +- RecoTracker/LSTCore/src/LSTESData.cc | 8 ++-- RecoTracker/LSTCore/src/ModuleMethods.h | 5 ++- RecoTracker/LSTGeometry/interface/Common.h | 2 +- .../LSTGeometry/interface/DetectorGeometry.h | 2 +- RecoTracker/LSTGeometry/interface/Helix.h | 4 +- RecoTracker/LSTGeometry/interface/IO.h | 20 +++++----- .../LSTGeometry/src/DetectorGeometry.cc | 14 +++---- RecoTracker/LSTGeometry/src/Helix.cc | 4 +- RecoTracker/LSTGeometry/src/ModuleMap.cc | 38 +++++++++---------- RecoTracker/LSTGeometry/src/PixelMap.cc | 4 +- RecoTracker/LSTGeometry/src/Slope.cc | 4 +- .../LSTGeometry/test/DumpLSTGeometry.cc | 2 +- 15 files changed, 64 insertions(+), 56 deletions(-) diff --git a/RecoTracker/LSTCore/interface/Common.h b/RecoTracker/LSTCore/interface/Common.h index b5dece7656b2d..b03a50e5553a2 100644 --- a/RecoTracker/LSTCore/interface/Common.h +++ b/RecoTracker/LSTCore/interface/Common.h @@ -4,6 +4,8 @@ #include "DataFormats/Common/interface/StdArray.h" #include "HeterogeneousCore/AlpakaInterface/interface/config.h" +#include "RecoTracker/LSTGeometry/interface/Common.h" + #if defined(FP16_Base) #if defined ALPAKA_ACC_GPU_CUDA_ENABLED #include @@ -42,6 +44,11 @@ namespace lst { constexpr uint16_t kTCEmptyLowerModule = 0xFFFF; // Sentinel for empty lowerModule index constexpr unsigned int kTCEmptyHitIdx = 0xFFFFFFFF; // Sentinel for empty hit slots + constexpr unsigned int kPixelModuleId = 1; + + constexpr float kB = lstgeometry::kB; + constexpr float kC = lstgeometry::kC; + // Half precision wrapper functions. #if defined(FP16_Base) #define __F2H __float2half diff --git a/RecoTracker/LSTCore/interface/EndcapGeometry.h b/RecoTracker/LSTCore/interface/EndcapGeometry.h index 8772cbc4a7bf2..fe4af4186c287 100644 --- a/RecoTracker/LSTCore/interface/EndcapGeometry.h +++ b/RecoTracker/LSTCore/interface/EndcapGeometry.h @@ -1,8 +1,8 @@ #ifndef RecoTracker_LSTCore_interface_EndcapGeometry_h #define RecoTracker_LSTCore_interface_EndcapGeometry_h -#include "RecoTracker/LSTGeometry/interface/Slope.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" +#include "RecoTracker/LSTGeometry/interface/Slope.h" #include #include diff --git a/RecoTracker/LSTCore/interface/alpaka/Common.h b/RecoTracker/LSTCore/interface/alpaka/Common.h index 84c0083b53403..f4dc33268f8fd 100644 --- a/RecoTracker/LSTCore/interface/alpaka/Common.h +++ b/RecoTracker/LSTCore/interface/alpaka/Common.h @@ -32,8 +32,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { 25.007152356, 37.2186993757, 52.3104270826, 68.6658656666, 85.9770373007, 108.301772384}; HOST_DEVICE_CONSTANT float kMiniRminMeanEndcap[5] = { 130.992832231, 154.813883559, 185.352604327, 221.635123002, 265.022076742}; - HOST_DEVICE_CONSTANT float k2Rinv1GeVf = (2.99792458e-3 * 3.8) / 2; - HOST_DEVICE_CONSTANT float kR1GeVf = 1. / (2.99792458e-3 * 3.8); + HOST_DEVICE_CONSTANT float k2Rinv1GeVf = (kC * kB) / 2; + HOST_DEVICE_CONSTANT float kR1GeVf = 1. / (kC * kB); HOST_DEVICE_CONSTANT float kSinAlphaMax = 0.95; HOST_DEVICE_CONSTANT float kDeltaZLum = 15.0; HOST_DEVICE_CONSTANT float kPixelPSZpitch = 0.15; diff --git a/RecoTracker/LSTCore/src/LSTESData.cc b/RecoTracker/LSTCore/src/LSTESData.cc index 4bf8f4e6b0aae..204940babf0e0 100644 --- a/RecoTracker/LSTCore/src/LSTESData.cc +++ b/RecoTracker/LSTCore/src/LSTESData.cc @@ -160,11 +160,11 @@ std::unique_ptr> lst::fillESDataHost(lstg } if (charge == 0) { - pLStoLayer[0][layer - 1 + (subdet == 4 ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); + pLStoLayer[0][layer - 1 + (subdet == Endcap ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); } else if (charge > 0) { - pLStoLayer[1][layer - 1 + (subdet == 4 ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); + pLStoLayer[1][layer - 1 + (subdet == Endcap ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); } else { - pLStoLayer[2][layer - 1 + (subdet == 4 ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); + pLStoLayer[2][layer - 1 + (subdet == Endcap ? 2 : 0)] = lst::ModuleConnectionMap(final_pixelmap); } } @@ -178,7 +178,7 @@ std::unique_ptr> lst::fillESDataHost(lstg mmd.module_type[detId] = static_cast(sensor.moduleType); counter++; } - mmd.detIdToIndex[1] = counter; //pixel module is the last module in the module list + mmd.detIdToIndex[kPixelModuleId] = counter; //pixel module is the last module in the module list counter++; nModules = counter; diff --git a/RecoTracker/LSTCore/src/ModuleMethods.h b/RecoTracker/LSTCore/src/ModuleMethods.h index b100044d25de2..5ef07f3594c65 100644 --- a/RecoTracker/LSTCore/src/ModuleMethods.h +++ b/RecoTracker/LSTCore/src/ModuleMethods.h @@ -17,6 +17,7 @@ namespace lst { // TODO: At some point it might be good to move some of these things to LSTGeometry + // or replace the functions with values computed from standard geometry/topology methods struct ModuleMetaData { std::map detIdToIndex; @@ -215,7 +216,7 @@ namespace lst { } } - mmd.detIdToIndex[1] = counter; //pixel module is the last module in the module list + mmd.detIdToIndex[kPixelModuleId] = counter; //pixel module is the last module in the module list counter++; nModules = counter; } @@ -381,7 +382,7 @@ namespace lst { *host_nLowerModules = nLowerModules; // Fill pixel part - pixelMapping.pixelModuleIndex = mmd.detIdToIndex.at(1); + pixelMapping.pixelModuleIndex = mmd.detIdToIndex.at(kPixelModuleId); auto modulesPixel_view = modulesHC->view().modulesPixel(); auto connectedPixels = diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index a4e18acccdd8a..906e85c1695b5 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -27,8 +27,8 @@ namespace lstgeometry { enum Side { NegZ = 1, PosZ = 2, Center = 3 }; + constexpr float kB = 3.8; constexpr float kC = 0.00299792458; - constexpr float kB = 3.8112; // For pixel maps constexpr unsigned int kNEta = 25; diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index c6eba412ab900..3540c94ecd7ce 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -31,7 +31,7 @@ namespace lstgeometry { MatrixF4x3 const& getCorners(unsigned int detId) const; std::vector getDetIds(std::function&)> filter = - [](const auto&) { return true; }) const; + [](auto const&) { return true; }) const; void buildByLayer(Modules const& modules_info, Sensors const& sensors); diff --git a/RecoTracker/LSTGeometry/interface/Helix.h b/RecoTracker/LSTGeometry/interface/Helix.h index e60a20c89137d..14ce955ac0a46 100644 --- a/RecoTracker/LSTGeometry/interface/Helix.h +++ b/RecoTracker/LSTGeometry/interface/Helix.h @@ -15,8 +15,8 @@ namespace lstgeometry { Helix(float center_x, float center_y, float center_z, float radius, float phi, float lam, int charge); Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge); - std::tuple pointFromRadius(float target_r); - std::tuple pointFromZ(float target_z); + std::tuple pointFromRadius(float target_r) const; + std::tuple pointFromZ(float target_z) const; }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index ccfb39d0c6bc4..15c148df4b5a2 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -25,7 +25,7 @@ namespace lstgeometry { std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if (binary) { - for (auto& [detid, sensor] : sensors) { + for (auto const& [detid, sensor] : sensors) { float x = sensor.centerX; float y = sensor.centerY; float z = sensor.centerZ; @@ -37,7 +37,7 @@ namespace lstgeometry { file.write(reinterpret_cast(&moduleType), sizeof(moduleType)); } } else { - for (auto& [detid, sensor] : sensors) { + for (auto const& [detid, sensor] : sensors) { file << detid << "," << sensor.centerX << "," << sensor.centerY << "," << sensor.centerZ << "," << static_cast(sensor.moduleType) << std::endl; } @@ -52,7 +52,7 @@ namespace lstgeometry { std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if (binary) { - for (auto& [detid, slope] : slopes) { + for (auto const& [detid, slope] : slopes) { float drdz_slope = slope.drdz; float dxdy_slope = slope.dxdy; float phi = sensors.at(detid).centerPhi; @@ -66,7 +66,7 @@ namespace lstgeometry { } } } else { - for (auto& [detid, slope] : slopes) { + for (auto const& [detid, slope] : slopes) { float drdz_slope = slope.drdz; float dxdy_slope = slope.dxdy; float phi = sensors.at(detid).centerPhi; @@ -90,7 +90,7 @@ namespace lstgeometry { std::ofstream file(filename, binary ? std::ios::binary : std::ios::out); if (binary) { - for (auto& [detid, set] : connections) { + for (auto const& [detid, set] : connections) { file.write(reinterpret_cast(&detid), sizeof(detid)); unsigned int length = set.size(); file.write(reinterpret_cast(&length), sizeof(length)); @@ -99,7 +99,7 @@ namespace lstgeometry { } } } else { - for (auto& [detid, set] : connections) { + for (auto const& [detid, set] : connections) { file << detid << "," << set.size(); for (unsigned int i : set) { file << "," << i; @@ -114,8 +114,8 @@ namespace lstgeometry { std::filesystem::create_directories(filepath.parent_path()); if (binary) { - for (auto& [layersubdetcharge, map] : maps) { - auto& [layer, subdet, charge] = layersubdetcharge; + for (auto const& [layersubdetcharge, map] : maps) { + auto const& [layer, subdet, charge] = layersubdetcharge; std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); std::string filename = std::format("{}{}_layer{}_subdet{}.bin", base_filename, charge_str, layer, subdet); @@ -134,8 +134,8 @@ namespace lstgeometry { } } } else { - for (auto& [layersubdetcharge, map] : maps) { - auto& [layer, subdet, charge] = layersubdetcharge; + for (auto const& [layersubdetcharge, map] : maps) { + auto const& [layer, subdet, charge] = layersubdetcharge; std::string charge_str = charge > 0 ? "_pos" : (charge < 0 ? "_neg" : ""); std::string filename = std::format("{}{}_layer{}_subdet{}.txt", base_filename, charge_str, layer, subdet); diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 67d999f8affb0..cfa94016a7b51 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -71,7 +71,7 @@ namespace lstgeometry { std::vector DetectorGeometry::getDetIds( std::function&)> filter) const { std::vector detIds; - for (const auto& entry : *sensors_) { + for (auto const& entry : *sensors_) { if (filter(entry)) { detIds.push_back(entry.first); } @@ -97,9 +97,9 @@ namespace lstgeometry { } for (unsigned int layer = 1; layer < 7; layer++) { - auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { - auto& s = sensors.at(x.first); - auto& m = modules_info.at(s.moduleDetId); + auto detids = getDetIds([&modules_info, &sensors, &layer](auto const& x) { + auto const& s = sensors.at(x.first); + auto const& m = modules_info.at(s.moduleDetId); return m.location == Location::barrel && m.layer == layer && s.isLower; }); for (auto detid : detids) { @@ -117,9 +117,9 @@ namespace lstgeometry { } } for (unsigned int layer = 1; layer < 6; layer++) { - auto detids = getDetIds([&modules_info, &sensors, &layer](const auto& x) { - auto& s = sensors.at(x.first); - auto& m = modules_info.at(s.moduleDetId); + auto detids = getDetIds([&modules_info, &sensors, &layer](auto const& x) { + auto const& s = sensors.at(x.first); + auto const& m = modules_info.at(s.moduleDetId); return m.location == Location::endcap && m.layer == layer && s.isLower; }); for (auto detid : detids) { diff --git a/RecoTracker/LSTGeometry/src/Helix.cc b/RecoTracker/LSTGeometry/src/Helix.cc index a984d755028af..28f53a2cb175a 100644 --- a/RecoTracker/LSTGeometry/src/Helix.cc +++ b/RecoTracker/LSTGeometry/src/Helix.cc @@ -29,7 +29,7 @@ namespace lstgeometry { lambda = std::atan((mz - vz) / (radius * t)); } - std::tuple Helix::pointFromRadius(float target_r) { + std::tuple Helix::pointFromRadius(float target_r) const { auto objective_function = [this, target_r](float t) { float x = this->center_x - this->charge * this->radius * std::sin(this->phi - this->charge * t); float y = this->center_y + this->charge * this->radius * std::cos(this->phi - this->charge * t); @@ -47,7 +47,7 @@ namespace lstgeometry { return std::make_tuple(x, y, z, r); } - std::tuple Helix::pointFromZ(float target_z) { + std::tuple Helix::pointFromZ(float target_z) const { auto objective_function = [this, target_z](float t) { float z = this->center_z + this->radius * std::tan(this->lambda) * t; return std::fabs(z - target_z); diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index 733808c7421af..e55fc53d65fab 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -87,7 +87,7 @@ namespace lstgeometry { Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom) { - auto& sensor = sensors.at(ref_detid); + auto const& sensor = sensors.at(ref_detid); float refphi = std::atan2(sensor.centerY, sensor.centerX); @@ -129,7 +129,7 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); std::vector difference; - for (auto& ref_polygon_piece : ref_polygon) { + for (auto const& ref_polygon_piece : ref_polygon) { std::vector tmp_difference; boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); @@ -139,7 +139,7 @@ namespace lstgeometry { } float area = 0.; - for (auto& ref_polygon_piece : ref_polygon) + for (auto const& ref_polygon_piece : ref_polygon) area += boost::geometry::area(ref_polygon_piece); if (area <= 1e-6) @@ -149,7 +149,7 @@ namespace lstgeometry { det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { - auto& sensor_target = sensors.at(tar_detid); + auto const& sensor_target = sensors.at(tar_detid); float tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) @@ -158,7 +158,7 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); bool intersects = false; - for (auto& ref_polygon_piece : ref_polygon) { + for (auto const& ref_polygon_piece : ref_polygon) { if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { intersects = true; break; @@ -184,12 +184,12 @@ namespace lstgeometry { float ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); - auto& sensor = sensors.at(ref_detid); + auto const& sensor = sensors.at(ref_detid); int charge = 1; float theta = std::atan2(std::sqrt(sensor.centerX * sensor.centerX + sensor.centerY * sensor.centerY), sensor.centerZ); float refphi = std::atan2(sensor.centerY, sensor.centerX); - auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); + auto const& refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; auto ref_location = refmodule.location; MatrixF4x3 next_layer_bound_points; @@ -209,10 +209,10 @@ namespace lstgeometry { if (doR) { float tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); if (bound_theta > theta) { - auto& h = phi_diff > 0 ? helix_p10 : helix_p10_pos; + auto const& h = phi_diff > 0 ? helix_p10 : helix_p10_pos; next_point = h.pointFromRadius(tar_layer_radius); } else { - auto& h = phi_diff > 0 ? helix_m10 : helix_m10_pos; + auto const& h = phi_diff > 0 ? helix_m10 : helix_m10_pos; next_point = h.pointFromRadius(tar_layer_radius); } } else { @@ -260,11 +260,11 @@ namespace lstgeometry { Sensors const& sensors, DetectorGeometry const& det_geom, float ptCut) { - auto& sensor = sensors.at(ref_detid); + auto const& sensor = sensors.at(ref_detid); float refphi = std::atan2(sensor.centerY, sensor.centerX); - auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); + auto const& refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; auto ref_location = refmodule.location; @@ -303,7 +303,7 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); std::vector difference; - for (auto& ref_polygon_piece : ref_polygon) { + for (auto const& ref_polygon_piece : ref_polygon) { std::vector tmp_difference; boost::geometry::difference(ref_polygon_piece, tar_polygon, tmp_difference); difference.insert(difference.end(), tmp_difference.begin(), tmp_difference.end()); @@ -313,7 +313,7 @@ namespace lstgeometry { } float area = 0.; - for (auto& ref_polygon_piece : ref_polygon) + for (auto const& ref_polygon_piece : ref_polygon) area += boost::geometry::area(ref_polygon_piece); if (area > 1e-6) { @@ -321,7 +321,7 @@ namespace lstgeometry { det_geom.getEndcapLayerDetIds(1, etaphibins.first, etaphibins.second); for (unsigned int tar_detid : new_tar_detids_to_be_considered) { - auto& sensor_target = sensors.at(tar_detid); + auto const& sensor_target = sensors.at(tar_detid); float tarphi = std::atan2(sensor_target.centerY, sensor_target.centerX); if (std::fabs(phi_mpi_pi(tarphi - refphi)) > std::numbers::pi_v / 2.) @@ -330,7 +330,7 @@ namespace lstgeometry { Polygon tar_polygon = getEtaPhiPolygon(det_geom.getCorners(tar_detid), refphi, zshift); bool intersects = false; - for (auto& ref_polygon_piece : ref_polygon) { + for (auto const& ref_polygon_piece : ref_polygon) { if (boost::geometry::intersects(ref_polygon_piece, tar_polygon)) { intersects = true; break; @@ -355,7 +355,7 @@ namespace lstgeometry { ModuleMap merged; for (auto* connections : connections_list) { - for (const auto& [detid, list] : *connections) { + for (auto const& [detid, list] : *connections) { auto& target = merged[detid]; target.insert(list.begin(), list.end()); } @@ -368,9 +368,9 @@ namespace lstgeometry { Sensors const& sensors, DetectorGeometry const& det_geo, float pt_cut) { - auto detids_etaphi_layer_ref = det_geo.getDetIds([&modules, &sensors](const auto& x) { - auto& s = sensors.at(x.first); - auto& m = modules.at(s.moduleDetId); + auto detids_etaphi_layer_ref = det_geo.getDetIds([&modules, &sensors](auto const& x) { + auto const& s = sensors.at(x.first); + auto const& m = modules.at(s.moduleDetId); // exclude the outermost modules that do not have connections to other modules return ((m.location == Location::barrel && s.isLower && m.layer != 6) || (m.location == Location::endcap && s.isLower && m.layer != 5 && !(m.ring == 15 && m.layer == 1) && diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index 45fe19f32baba..5b4c0e065d30b 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -23,9 +23,9 @@ namespace lstgeometry { // Loop over the detids and for each detid compute which superbins it is connected to for (auto detId : det_geom.getDetIds()) { - auto& sensor = sensors.at(detId); + auto const& sensor = sensors.at(detId); - auto module = modules.at(sensor.moduleDetId); + auto const& module = modules.at(sensor.moduleDetId); // Phase-2 enum differs from the legacy one used here unsigned int subdet = module.subdet == SubDetector::P2OTB ? 5 : 4; auto layer = module.layer; diff --git a/RecoTracker/LSTGeometry/src/Slope.cc b/RecoTracker/LSTGeometry/src/Slope.cc index aa558cc747de6..f35cf41ffdb67 100644 --- a/RecoTracker/LSTGeometry/src/Slope.cc +++ b/RecoTracker/LSTGeometry/src/Slope.cc @@ -25,14 +25,14 @@ namespace lstgeometry { Slopes barrel_slopes; Slopes endcap_slopes; - for (const auto& [detId, sensor] : sensors) { + for (auto const& [detId, sensor] : sensors) { float dx = roundCoordinate(sensor.corners(1, 1) - sensor.corners(0, 1)); float dy = roundCoordinate(sensor.corners(1, 2) - sensor.corners(0, 2)); float dz = roundCoordinate(sensor.corners(1, 0) - sensor.corners(0, 0)); Slope slope(dx, dy, dz); - auto& module = modules.at(sensor.moduleDetId); + auto const& module = modules.at(sensor.moduleDetId); auto location = module.location; bool is_tilted = module.side != Side::Center; diff --git a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc index 4528ad59f8a71..ed9690e1c1817 100644 --- a/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc +++ b/RecoTracker/LSTGeometry/test/DumpLSTGeometry.cc @@ -38,7 +38,7 @@ DumpLSTGeometry::DumpLSTGeometry(const edm::ParameterSet& config) lstGeoToken_{esConsumes(edm::ESInputTag("", "LSTGeometry_" + ptCutStr_))} {} void DumpLSTGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { - const auto& lstg = iSetup.getData(lstGeoToken_); + auto const& lstg = iSetup.getData(lstGeoToken_); lstgeometry::writeSensorCentroids(*lstg.sensors, outputDirectory_ + "sensor_centroids", binaryOutput_); lstgeometry::writeSlopes( From a3b60a0ce4c6f906e14400f5bc9a843b6f163773 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 10 Mar 2026 16:28:23 -0400 Subject: [PATCH 90/95] Addressed some more review issues --- RecoTracker/LST/plugins/alpaka/LSTProducer.cc | 2 +- RecoTracker/LSTGeometry/BuildFile.xml | 2 +- RecoTracker/LSTGeometry/interface/Common.h | 4 ++ .../LSTGeometry/interface/DetectorGeometry.h | 8 ++-- RecoTracker/LSTGeometry/interface/Geometry.h | 5 ++- RecoTracker/LSTGeometry/interface/Module.h | 4 +- RecoTracker/LSTGeometry/interface/ModuleMap.h | 2 +- RecoTracker/LSTGeometry/interface/Sensor.h | 1 + RecoTracker/LSTGeometry/plugins/BuildFile.xml | 2 +- .../plugins/LSTGeometryESProducer.cc | 37 ++++++++-------- RecoTracker/LSTGeometry/src/Common.cc | 2 +- .../LSTGeometry/src/DetectorGeometry.cc | 42 +++++-------------- RecoTracker/LSTGeometry/src/Geometry.cc | 6 +-- RecoTracker/LSTGeometry/src/ModuleMap.cc | 14 +++---- RecoTracker/LSTGeometry/src/PixelMap.cc | 4 +- RecoTracker/LSTGeometry/test/BuildFile.xml | 2 +- 16 files changed, 60 insertions(+), 77 deletions(-) diff --git a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc index 4708ea86e0513..bf7a5658196a0 100644 --- a/RecoTracker/LST/plugins/alpaka/LSTProducer.cc +++ b/RecoTracker/LST/plugins/alpaka/LSTProducer.cc @@ -34,7 +34,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { nopLSDupClean_(config.getParameter("nopLSDupClean")), tcpLSTriplets_(config.getParameter("tcpLSTriplets")), lstInputToken_{consumes(config.getParameter("lstInput"))}, - lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps_"+ptCutStr_))}, + lstESToken_{esConsumes(edm::ESInputTag("", "LSTModuleMaps_" + ptCutStr_))}, lstOutputToken_{produces()} {} void produce(edm::StreamID sid, device::Event& iEvent, const device::EventSetup& iSetup) const override { diff --git a/RecoTracker/LSTGeometry/BuildFile.xml b/RecoTracker/LSTGeometry/BuildFile.xml index 5b5d221c0d5a4..be1beb06995d9 100644 --- a/RecoTracker/LSTGeometry/BuildFile.xml +++ b/RecoTracker/LSTGeometry/BuildFile.xml @@ -5,4 +5,4 @@ - \ No newline at end of file + diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index 906e85c1695b5..595c14964904c 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -25,11 +25,15 @@ namespace lstgeometry { using SubDetector = GeomDetEnumerators::SubDetector; using Location = GeomDetEnumerators::Location; + enum SubDet { InnerPixel = 0, Barrel = 5, Endcap = 4 }; enum Side { NegZ = 1, PosZ = 2, Center = 3 }; constexpr float kB = 3.8; constexpr float kC = 0.00299792458; + constexpr unsigned int kBarrelLayers = 6; + constexpr unsigned int kEndcapLayers = 5; + // For pixel maps constexpr unsigned int kNEta = 25; constexpr unsigned int kNPhi = 72; diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index 3540c94ecd7ce..e55b90ebd9c02 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -18,15 +18,17 @@ namespace lstgeometry { class DetectorGeometry { private: std::shared_ptr sensors_; - std::vector avg_radii_; - std::vector avg_z_; + std::array avg_radii_; + std::array avg_z_; std::unordered_map, boost::hash> barrel_lower_det_ids_; std::unordered_map, boost::hash> endcap_lower_det_ids_; public: - DetectorGeometry(std::shared_ptr sensors, std::vector avg_radii, std::vector avg_z); + DetectorGeometry(std::shared_ptr sensors, + std::array const& avg_radii, + std::array const& avg_z); MatrixF4x3 const& getCorners(unsigned int detId) const; diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index b7d5739e7e52b..9b9c604adce94 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -1,6 +1,7 @@ #ifndef RecoTracker_LSTGeometry_interface_Geometry_h #define RecoTracker_LSTGeometry_interface_Geometry_h +#include #include #include "RecoTracker/LSTGeometry/interface/Slope.h" @@ -20,8 +21,8 @@ namespace lstgeometry { Geometry(Modules &modules, std::shared_ptr sensors, - std::vector const &average_r, - std::vector const &average_z, + std::array const &average_r_barrel, + std::array const &average_z_endcap, float ptCut); }; diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h index f5e240bbf26d1..f28f31afe2a8e 100644 --- a/RecoTracker/LSTGeometry/interface/Module.h +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -7,6 +7,7 @@ namespace lstgeometry { + // A module contains 2 sensors. The common properties of the 2 sensors are stored in the Module struct, and the sensor-specific properties are stored in the Sensor struct. struct Module { ModuleType moduleType; SubDetector subdet; @@ -15,9 +16,6 @@ namespace lstgeometry { unsigned int moduleId; unsigned int layer; unsigned int ring; - float centerRho; - float centerZ; - float centerPhi; }; using Modules = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/interface/ModuleMap.h b/RecoTracker/LSTGeometry/interface/ModuleMap.h index a86cd80631842..33827a5586b23 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMap.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMap.h @@ -4,9 +4,9 @@ #include #include +#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" namespace lstgeometry { diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index b184359817007..0af9a5c38da85 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -10,6 +10,7 @@ namespace lstgeometry { + // A sensor is a component of a module. The common properties of the 2 sensors are stored in the Module struct, and the sensor-specific properties are stored in the Sensor struct. struct Sensor { unsigned int moduleDetId; float centerRho; diff --git a/RecoTracker/LSTGeometry/plugins/BuildFile.xml b/RecoTracker/LSTGeometry/plugins/BuildFile.xml index 426d05870b1e2..6eaca7a7e2d77 100644 --- a/RecoTracker/LSTGeometry/plugins/BuildFile.xml +++ b/RecoTracker/LSTGeometry/plugins/BuildFile.xml @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index fdff13e2dde55..a1c375bb2b20c 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -8,14 +8,15 @@ #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" +#include "RecoTracker/LSTGeometry/interface/Geometry.h" #include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" -#include "RecoTracker/LSTGeometry/interface/Geometry.h" +#include #include -#include -#include #include +#include +#include class LSTGeometryESProducer : public edm::ESProducer { public: @@ -59,10 +60,10 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac lstgeometry::Modules modules; auto sensors = std::make_shared(); - std::vector avg_r_cm(6, 0.0); - std::vector avg_z_cm(5, 0.0); - std::vector avg_r_counter(6, 0); - std::vector avg_z_counter(5, 0); + std::array avg_r_barrel{}; + std::array avg_z_endcap{}; + std::array avg_r_barrel_counter{}; + std::array avg_z_endcap_counter{}; for (auto &det : trackerGeom_->dets()) { const DetId detId = det->geographicalId(); @@ -95,7 +96,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac if (det->isLeaf()) { // Leafs are the sensors - const unsigned int moduleDetId = detid & ~0b11; // I don't think there is there a CMSSW method for this + const unsigned int moduleDetId = detid & ~0b11; // Can't use TrackerTopology::isLower since it doesn't consider if the module is inverted const bool isLow = isLower(moduleId, location, side, layer, detid); (*sensors)[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType, surface); @@ -104,25 +105,25 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac } if (location == lstgeometry::Location::barrel) { - avg_r_cm[layer - 1] += rho_cm; - avg_r_counter[layer - 1] += 1; + avg_r_barrel[layer - 1] += rho_cm; + avg_r_barrel_counter[layer - 1] += 1; } else { - avg_z_cm[layer - 1] += std::fabs(z_cm); - avg_z_counter[layer - 1] += 1; + avg_z_endcap[layer - 1] += std::fabs(z_cm); + avg_z_endcap_counter[layer - 1] += 1; } - lstgeometry::Module module{moduleType, subdet, location, side, moduleId, layer, ring, rho_cm, z_cm, phi_rad}; + lstgeometry::Module module{moduleType, subdet, location, side, moduleId, layer, ring}; modules[detid] = std::move(module); } - for (size_t i = 0; i < avg_r_cm.size(); ++i) { - avg_r_cm[i] /= avg_r_counter[i]; + for (size_t i = 0; i < avg_r_barrel.size(); ++i) { + avg_r_barrel[i] /= avg_r_barrel_counter[i]; } - for (size_t i = 0; i < avg_z_cm.size(); ++i) { - avg_z_cm[i] /= avg_z_counter[i]; + for (size_t i = 0; i < avg_z_endcap.size(); ++i) { + avg_z_endcap[i] /= avg_z_endcap_counter[i]; } - auto lstGeometry = std::make_unique(modules, sensors, avg_r_cm, avg_z_cm, ptCut_); + auto lstGeometry = std::make_unique(modules, sensors, avg_r_barrel, avg_z_endcap, ptCut_); return lstGeometry; } diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc index 2b6ff82b1825f..a89df6e4980f0 100644 --- a/RecoTracker/LSTGeometry/src/Common.cc +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -35,7 +35,7 @@ namespace lstgeometry { std::pair getEtaPhi(float x, float y, float z, float refphi) { float phi = phi_mpi_pi(std::atan2(y, x) - refphi); - float eta = std::copysign(-std::log(std::tan(std::atan(std::sqrt(x * x + y * y) / std::abs(z)) / 2.)), z); + float eta = std::asinh(std::sqrt(x * x + y * y) / z); return std::make_pair(eta, phi); } diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index cfa94016a7b51..824f5fed5bfbb 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -29,41 +29,18 @@ namespace lstgeometry { std::pair DetectorGeometry::getEtaPhiBins(float eta, float phi) { float theta = 2. * std::atan(std::exp(-eta)); + unsigned int eta_bin = std::clamp(static_cast(theta / kEtaBinRad), 0u, kNEtaBins - 1); - unsigned int eta_bin = 0; - if (theta <= kEtaBinRad) { - eta_bin = 0; - } else if (theta >= (kNEtaBins - 1) * kEtaBinRad) { - eta_bin = kNEtaBins - 1; - } else { - for (unsigned int i = 1; i < kNEtaBins - 1; i++) { - if (theta >= i * kEtaBinRad && theta <= (i + 1) * kEtaBinRad) { - eta_bin = i; - break; - } - } - } - - unsigned int phi_bin = 0; float pi = std::numbers::pi_v; - - if (phi <= -pi + kPhiBinWidth / 2. || phi >= pi - kPhiBinWidth / 2.) { - phi_bin = 0; - } else { - for (unsigned int i = 1; i < kNPhiBins; i++) { - if (phi >= -pi + ((2 * i - 1) * kPhiBinWidth) / 2. && phi <= -pi + ((2 * i + 1) * kPhiBinWidth) / 2.) { - phi_bin = i; - break; - } - } - } + unsigned int raw = static_cast((phi + pi) / kPhiBinWidth); + unsigned int phi_bin = (raw == 0 || raw >= kNPhiBins) ? 0u : raw; return std::make_pair(eta_bin, phi_bin); } DetectorGeometry::DetectorGeometry(std::shared_ptr sensors, - std::vector avg_radii, - std::vector avg_z) + std::array const& avg_radii, + std::array const& avg_z) : sensors_(sensors), avg_radii_(avg_radii), avg_z_(avg_z) {} MatrixF4x3 const& DetectorGeometry::getCorners(unsigned int detId) const { return sensors_->at(detId).corners; } @@ -71,6 +48,7 @@ namespace lstgeometry { std::vector DetectorGeometry::getDetIds( std::function&)> filter) const { std::vector detIds; + detIds.reserve(sensors_->size()); for (auto const& entry : *sensors_) { if (filter(entry)) { detIds.push_back(entry.first); @@ -87,16 +65,16 @@ namespace lstgeometry { // Initialize all vectors for (unsigned int etabin = 0; etabin < kNEtaBins; etabin++) { for (unsigned int phibin = 0; phibin < kNPhiBins; phibin++) { - for (unsigned int layer = 1; layer < 7; layer++) { + for (unsigned int layer = 1; layer <= kBarrelLayers; layer++) { barrel_lower_det_ids_[{layer, etabin, phibin}] = {}; } - for (unsigned int layer = 1; layer < 6; layer++) { + for (unsigned int layer = 1; layer <= kEndcapLayers; layer++) { endcap_lower_det_ids_[{layer, etabin, phibin}] = {}; } } } - for (unsigned int layer = 1; layer < 7; layer++) { + for (unsigned int layer = 1; layer <= kBarrelLayers; layer++) { auto detids = getDetIds([&modules_info, &sensors, &layer](auto const& x) { auto const& s = sensors.at(x.first); auto const& m = modules_info.at(s.moduleDetId); @@ -116,7 +94,7 @@ namespace lstgeometry { } } } - for (unsigned int layer = 1; layer < 6; layer++) { + for (unsigned int layer = 1; layer <= kEndcapLayers; layer++) { auto detids = getDetIds([&modules_info, &sensors, &layer](auto const& x) { auto const& s = sensors.at(x.first); auto const& m = modules_info.at(s.moduleDetId); diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index c69720275953d..9f5ed1aafb54b 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -6,15 +6,15 @@ using namespace lstgeometry; Geometry::Geometry(Modules &modules, std::shared_ptr sensors, - std::vector const &average_r, - std::vector const &average_z, + std::array const &average_r_barrel, + std::array const &average_z_endcap, float pt_cut) : sensors(sensors) { auto slopes = computeSlopes(modules, *sensors); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); - auto det_geom = DetectorGeometry(sensors, average_r, average_z); + auto det_geom = DetectorGeometry(sensors, average_r_barrel, average_z_endcap); det_geom.buildByLayer(modules, *sensors); pixel_map = buildPixelMap(modules, *sensors, det_geom, pt_cut); diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index e55fc53d65fab..582e6dc489c0d 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -5,8 +5,8 @@ #include #include -#include "RecoTracker/LSTGeometry/interface/ModuleMap.h" #include "RecoTracker/LSTGeometry/interface/Helix.h" +#include "RecoTracker/LSTGeometry/interface/ModuleMap.h" namespace lstgeometry { @@ -186,8 +186,7 @@ namespace lstgeometry { auto bounds = det_geom.getCorners(ref_detid); auto const& sensor = sensors.at(ref_detid); int charge = 1; - float theta = - std::atan2(std::sqrt(sensor.centerX * sensor.centerX + sensor.centerY * sensor.centerY), sensor.centerZ); + float z_r = sensor.centerZ / std::sqrt(sensor.centerX * sensor.centerX + sensor.centerY * sensor.centerY); float refphi = std::atan2(sensor.centerY, sensor.centerX); auto const& refmodule = modules.at(sensors.at(ref_detid).moduleDetId); unsigned short ref_layer = refmodule.layer; @@ -199,8 +198,7 @@ namespace lstgeometry { auto helix_m10 = Helix(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), -charge); auto helix_p10_pos = Helix(ptCut, 0, 0, 10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); auto helix_m10_pos = Helix(ptCut, 0, 0, -10, bounds(i, 1), bounds(i, 2), bounds(i, 0), charge); - float bound_theta = - std::atan2(std::sqrt(bounds(i, 1) * bounds(i, 1) + bounds(i, 2) * bounds(i, 2)), bounds(i, 0)); + float bound_z_r = bounds(i, 0) / std::sqrt(bounds(i, 1) * bounds(i, 1) + bounds(i, 2) * bounds(i, 2)); float bound_phi = std::atan2(bounds(i, 2), bounds(i, 1)); float phi_diff = phi_mpi_pi(bound_phi - refphi); @@ -208,7 +206,7 @@ namespace lstgeometry { if (ref_location == Location::barrel) { if (doR) { float tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); - if (bound_theta > theta) { + if (bound_z_r > z_r) { auto const& h = phi_diff > 0 ? helix_p10 : helix_p10_pos; next_point = h.pointFromRadius(tar_layer_radius); } else { @@ -217,7 +215,7 @@ namespace lstgeometry { } } else { float tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(1); - if (bound_theta > theta) { + if (bound_z_r > z_r) { if (phi_diff > 0) { next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); } else { @@ -233,7 +231,7 @@ namespace lstgeometry { } } else { float tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(ref_layer + 1); - if (bound_theta > theta) { + if (bound_z_r > z_r) { if (phi_diff > 0) { next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); } else { diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index 5b4c0e065d30b..b1f05b2c2ab41 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -14,7 +14,7 @@ namespace lstgeometry { // Initialize empty lists for the pixel map for (unsigned int layer : {1, 2}) { - for (unsigned int subdet : {4, 5}) { + for (unsigned int subdet : {SubDet::Barrel, SubDet::Endcap}) { for (int charge : {-1, 0, 1}) { maps.try_emplace({layer, subdet, charge}, nSuperbin); } @@ -27,7 +27,7 @@ namespace lstgeometry { auto const& module = modules.at(sensor.moduleDetId); // Phase-2 enum differs from the legacy one used here - unsigned int subdet = module.subdet == SubDetector::P2OTB ? 5 : 4; + unsigned int subdet = module.subdet == SubDetector::P2OTB ? SubDet::Barrel : SubDet::Endcap; auto layer = module.layer; if (layer > 2) continue; diff --git a/RecoTracker/LSTGeometry/test/BuildFile.xml b/RecoTracker/LSTGeometry/test/BuildFile.xml index 8ce20e183e2f0..339b55f111d07 100644 --- a/RecoTracker/LSTGeometry/test/BuildFile.xml +++ b/RecoTracker/LSTGeometry/test/BuildFile.xml @@ -4,4 +4,4 @@ - \ No newline at end of file + From 6b154d6579229b5fe6250457c6034612ecdea722 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 11 Mar 2026 14:21:48 +0000 Subject: [PATCH 91/95] Removed Module struct --- RecoTracker/LSTCore/interface/Common.h | 2 - RecoTracker/LSTGeometry/interface/Common.h | 5 -- .../LSTGeometry/interface/DetectorGeometry.h | 3 +- RecoTracker/LSTGeometry/interface/Geometry.h | 4 +- RecoTracker/LSTGeometry/interface/IO.h | 1 - RecoTracker/LSTGeometry/interface/Module.h | 24 ------- RecoTracker/LSTGeometry/interface/ModuleMap.h | 6 +- RecoTracker/LSTGeometry/interface/PixelMap.h | 3 +- RecoTracker/LSTGeometry/interface/Sensor.h | 31 ++++++--- RecoTracker/LSTGeometry/interface/Slope.h | 3 +- .../plugins/LSTGeometryESProducer.cc | 13 +--- RecoTracker/LSTGeometry/src/Common.cc | 30 --------- .../LSTGeometry/src/DetectorGeometry.cc | 12 ++-- RecoTracker/LSTGeometry/src/Geometry.cc | 11 ++-- RecoTracker/LSTGeometry/src/ModuleMap.cc | 36 ++++------- RecoTracker/LSTGeometry/src/PixelMap.cc | 14 ++-- RecoTracker/LSTGeometry/src/Sensor.cc | 64 +++++++++++++++++-- RecoTracker/LSTGeometry/src/Slope.cc | 18 ++---- 18 files changed, 120 insertions(+), 160 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/interface/Module.h diff --git a/RecoTracker/LSTCore/interface/Common.h b/RecoTracker/LSTCore/interface/Common.h index b03a50e5553a2..b675caa29b221 100644 --- a/RecoTracker/LSTCore/interface/Common.h +++ b/RecoTracker/LSTCore/interface/Common.h @@ -44,8 +44,6 @@ namespace lst { constexpr uint16_t kTCEmptyLowerModule = 0xFFFF; // Sentinel for empty lowerModule index constexpr unsigned int kTCEmptyHitIdx = 0xFFFFFFFF; // Sentinel for empty hit slots - constexpr unsigned int kPixelModuleId = 1; - constexpr float kB = lstgeometry::kB; constexpr float kC = lstgeometry::kC; diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index 595c14964904c..db7a755c4518d 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -49,11 +49,6 @@ namespace lstgeometry { float roundCoordinate(float coord, float tol = 1e-3); std::pair getEtaPhi(float x, float y, float z, float refphi = 0); - // Not sure if there is functionality for this already in CMSSW - bool isInverted(unsigned int moduleId, Location location, Side side, unsigned int layer); - // This differs from TrackerTopology::isLower since it considers if the module is inverted - bool isLower(unsigned int moduleId, Location location, Side side, unsigned int layer, unsigned int detId); - } // namespace lstgeometry #endif diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index e55b90ebd9c02..983f1bea6fe47 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -8,7 +8,6 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { @@ -35,7 +34,7 @@ namespace lstgeometry { std::vector getDetIds(std::function&)> filter = [](auto const&) { return true; }) const; - void buildByLayer(Modules const& modules_info, Sensors const& sensors); + void buildByLayer(Sensors const& sensors); std::vector const& getBarrelLayerDetIds(unsigned int layer, unsigned int etabin, diff --git a/RecoTracker/LSTGeometry/interface/Geometry.h b/RecoTracker/LSTGeometry/interface/Geometry.h index 9b9c604adce94..ba466842618b4 100644 --- a/RecoTracker/LSTGeometry/interface/Geometry.h +++ b/RecoTracker/LSTGeometry/interface/Geometry.h @@ -7,7 +7,6 @@ #include "RecoTracker/LSTGeometry/interface/Slope.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/ModuleMap.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { @@ -19,8 +18,7 @@ namespace lstgeometry { PixelMap pixel_map; ModuleMap module_map; - Geometry(Modules &modules, - std::shared_ptr sensors, + Geometry(std::shared_ptr sensors, std::array const &average_r_barrel, std::array const &average_z_endcap, float ptCut); diff --git a/RecoTracker/LSTGeometry/interface/IO.h b/RecoTracker/LSTGeometry/interface/IO.h index 15c148df4b5a2..62cae47ce652d 100644 --- a/RecoTracker/LSTGeometry/interface/IO.h +++ b/RecoTracker/LSTGeometry/interface/IO.h @@ -10,7 +10,6 @@ #include #include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" #include "RecoTracker/LSTGeometry/interface/PixelMap.h" #include "RecoTracker/LSTGeometry/interface/Slope.h" diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h deleted file mode 100644 index f28f31afe2a8e..0000000000000 --- a/RecoTracker/LSTGeometry/interface/Module.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_Module_h -#define RecoTracker_LSTGeometry_interface_Module_h - -#include - -#include "RecoTracker/LSTGeometry/interface/Common.h" - -namespace lstgeometry { - - // A module contains 2 sensors. The common properties of the 2 sensors are stored in the Module struct, and the sensor-specific properties are stored in the Sensor struct. - struct Module { - ModuleType moduleType; - SubDetector subdet; - Location location; - Side side; - unsigned int moduleId; - unsigned int layer; - unsigned int ring; - }; - - using Modules = std::unordered_map; -} // namespace lstgeometry - -#endif diff --git a/RecoTracker/LSTGeometry/interface/ModuleMap.h b/RecoTracker/LSTGeometry/interface/ModuleMap.h index 33827a5586b23..53ba71fc6f100 100644 --- a/RecoTracker/LSTGeometry/interface/ModuleMap.h +++ b/RecoTracker/LSTGeometry/interface/ModuleMap.h @@ -5,17 +5,13 @@ #include #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { using ModuleMap = std::unordered_map>; - ModuleMap buildModuleMap(Modules const& modules, - Sensors const& sensors, - DetectorGeometry const& det_geom, - float pt_cut); + ModuleMap buildModuleMap(Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/PixelMap.h b/RecoTracker/LSTGeometry/interface/PixelMap.h index 2bf72858c6501..a8ced0c0a8a67 100644 --- a/RecoTracker/LSTGeometry/interface/PixelMap.h +++ b/RecoTracker/LSTGeometry/interface/PixelMap.h @@ -7,7 +7,6 @@ #include #include "RecoTracker/LSTGeometry/interface/DetectorGeometry.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { @@ -18,7 +17,7 @@ namespace lstgeometry { boost::hash>; using PixelMap = LayerSubdetChargeMap; - PixelMap buildPixelMap(Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut); + PixelMap buildPixelMap(Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index 0af9a5c38da85..bb92a5db004bc 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -10,27 +10,40 @@ namespace lstgeometry { - // A sensor is a component of a module. The common properties of the 2 sensors are stored in the Module struct, and the sensor-specific properties are stored in the Sensor struct. struct Sensor { - unsigned int moduleDetId; + // Module-level properties + ModuleType moduleType; + SubDetector subdet; + Location location; + Side side; + unsigned int moduleId; + unsigned int layer; + unsigned int ring; + bool inverted; + // Sensor-level properties float centerRho; float centerZ; float centerPhi; - bool isLower; + bool lower; + bool strip; MatrixF4x3 corners; - // Redundant, but convenient to have them - ModuleType moduleType; + // Redundant, but convenient to avoid repeated computations float centerX; float centerY; Sensor() = default; - Sensor(unsigned int moduleDetId, + Sensor(unsigned int detId, + ModuleType moduleType, + SubDetector subdet, + Location location, + Side side, + unsigned int moduleId, + unsigned int layer, + unsigned int ring, float centerRho, float centerZ, float centerPhi, - bool isLower, - ModuleType moduleType, - Surface const& surface); + Surface const &surface); }; using Sensors = std::unordered_map; diff --git a/RecoTracker/LSTGeometry/interface/Slope.h b/RecoTracker/LSTGeometry/interface/Slope.h index 82dc4a243d258..d873f853c71d3 100644 --- a/RecoTracker/LSTGeometry/interface/Slope.h +++ b/RecoTracker/LSTGeometry/interface/Slope.h @@ -3,7 +3,6 @@ #include -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" namespace lstgeometry { @@ -18,7 +17,7 @@ namespace lstgeometry { using Slopes = std::unordered_map; - std::tuple computeSlopes(Modules const& modules, Sensors const& sensors); + std::tuple computeSlopes(Sensors const& sensors); } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc index a1c375bb2b20c..d0b3f06564971 100644 --- a/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc +++ b/RecoTracker/LSTGeometry/plugins/LSTGeometryESProducer.cc @@ -9,7 +9,6 @@ #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" #include "RecoTracker/LSTGeometry/interface/Geometry.h" -#include "RecoTracker/LSTGeometry/interface/Module.h" #include "RecoTracker/LSTGeometry/interface/Sensor.h" #include @@ -57,7 +56,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac trackerGeom_ = &iRecord.get(geomToken_); trackerTopo_ = &iRecord.get(ttopoToken_); - lstgeometry::Modules modules; auto sensors = std::make_shared(); std::array avg_r_barrel{}; @@ -96,10 +94,8 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac if (det->isLeaf()) { // Leafs are the sensors - const unsigned int moduleDetId = detid & ~0b11; - // Can't use TrackerTopology::isLower since it doesn't consider if the module is inverted - const bool isLow = isLower(moduleId, location, side, layer, detid); - (*sensors)[detid] = lstgeometry::Sensor(moduleDetId, rho_cm, z_cm, phi_rad, isLow, moduleType, surface); + (*sensors)[detid] = lstgeometry::Sensor( + detid, moduleType, subdet, location, side, moduleId, layer, ring, rho_cm, z_cm, phi_rad, surface); continue; } @@ -111,9 +107,6 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac avg_z_endcap[layer - 1] += std::fabs(z_cm); avg_z_endcap_counter[layer - 1] += 1; } - - lstgeometry::Module module{moduleType, subdet, location, side, moduleId, layer, ring}; - modules[detid] = std::move(module); } for (size_t i = 0; i < avg_r_barrel.size(); ++i) { @@ -123,7 +116,7 @@ std::unique_ptr LSTGeometryESProducer::produce(const Trac avg_z_endcap[i] /= avg_z_endcap_counter[i]; } - auto lstGeometry = std::make_unique(modules, sensors, avg_r_barrel, avg_z_endcap, ptCut_); + auto lstGeometry = std::make_unique(sensors, avg_r_barrel, avg_z_endcap, ptCut_); return lstGeometry; } diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc index a89df6e4980f0..f5708b4d4413f 100644 --- a/RecoTracker/LSTGeometry/src/Common.cc +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -39,34 +39,4 @@ namespace lstgeometry { return std::make_pair(eta, phi); } - bool isInverted(unsigned int moduleId, Location location, Side side, unsigned int layer) { - bool moduleIdIsEven = moduleId % 2 == 0; - if (location == Location::endcap) { - if (side == Side::NegZ) { - return !moduleIdIsEven; - } else if (side == Side::PosZ) { - return moduleIdIsEven; - } - } else if (location == Location::barrel) { - if (side == Side::Center) { - if (layer <= 3) { - return !moduleIdIsEven; - } else if (layer >= 4) { - return moduleIdIsEven; - } - } else if (side == Side::NegZ || side == Side::PosZ) { - if (layer <= 2) { - return !moduleIdIsEven; - } else if (layer == 3) { - return moduleIdIsEven; - } - } - } - return false; - } - - bool isLower(unsigned int moduleId, Location location, Side side, unsigned int layer, unsigned int detId) { - return isInverted(moduleId, location, side, layer) ? !(detId & 1) : (detId & 1); - } - } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 824f5fed5bfbb..0b0244f7f9c33 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -57,7 +57,7 @@ namespace lstgeometry { return detIds; } - void DetectorGeometry::buildByLayer(Modules const& modules_info, Sensors const& sensors) { + void DetectorGeometry::buildByLayer(Sensors const& sensors) { // Clear just in case they were already built barrel_lower_det_ids_.clear(); endcap_lower_det_ids_.clear(); @@ -75,10 +75,9 @@ namespace lstgeometry { } for (unsigned int layer = 1; layer <= kBarrelLayers; layer++) { - auto detids = getDetIds([&modules_info, &sensors, &layer](auto const& x) { + auto detids = getDetIds([&sensors, &layer](auto const& x) { auto const& s = sensors.at(x.first); - auto const& m = modules_info.at(s.moduleDetId); - return m.location == Location::barrel && m.layer == layer && s.isLower; + return s.location == Location::barrel && s.layer == layer && s.lower; }); for (auto detid : detids) { auto corners = getCorners(detid); @@ -95,10 +94,9 @@ namespace lstgeometry { } } for (unsigned int layer = 1; layer <= kEndcapLayers; layer++) { - auto detids = getDetIds([&modules_info, &sensors, &layer](auto const& x) { + auto detids = getDetIds([&sensors, &layer](auto const& x) { auto const& s = sensors.at(x.first); - auto const& m = modules_info.at(s.moduleDetId); - return m.location == Location::endcap && m.layer == layer && s.isLower; + return s.location == Location::endcap && s.layer == layer && s.lower; }); for (auto detid : detids) { auto corners = getCorners(detid); diff --git a/RecoTracker/LSTGeometry/src/Geometry.cc b/RecoTracker/LSTGeometry/src/Geometry.cc index 9f5ed1aafb54b..631760a079c4f 100644 --- a/RecoTracker/LSTGeometry/src/Geometry.cc +++ b/RecoTracker/LSTGeometry/src/Geometry.cc @@ -4,22 +4,21 @@ using namespace lstgeometry; -Geometry::Geometry(Modules &modules, - std::shared_ptr sensors, +Geometry::Geometry(std::shared_ptr sensors, std::array const &average_r_barrel, std::array const &average_z_endcap, float pt_cut) : sensors(sensors) { - auto slopes = computeSlopes(modules, *sensors); + auto slopes = computeSlopes(*sensors); barrel_slopes = std::move(std::get<0>(slopes)); endcap_slopes = std::move(std::get<1>(slopes)); auto det_geom = DetectorGeometry(sensors, average_r_barrel, average_z_endcap); - det_geom.buildByLayer(modules, *sensors); + det_geom.buildByLayer(*sensors); - pixel_map = buildPixelMap(modules, *sensors, det_geom, pt_cut); + pixel_map = buildPixelMap(*sensors, det_geom, pt_cut); - module_map = buildModuleMap(modules, *sensors, det_geom, pt_cut); + module_map = buildModuleMap(*sensors, det_geom, pt_cut); } #include "FWCore/Utilities/interface/typelookup.h" diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index 582e6dc489c0d..34bc7a3e741e3 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -84,14 +84,13 @@ namespace lstgeometry { } std::vector getStraightLineConnections(unsigned int ref_detid, - Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom) { auto const& sensor = sensors.at(ref_detid); float refphi = std::atan2(sensor.centerY, sensor.centerX); - auto refmodule = modules.at(sensors.at(ref_detid).moduleDetId); + auto refmodule = sensors.at(ref_detid); unsigned short ref_layer = refmodule.layer; auto ref_location = refmodule.location; @@ -177,18 +176,14 @@ namespace lstgeometry { return list_of_detids_etaphi_layer_tar; } - MatrixF4x3 boundsAfterCurved(unsigned int ref_detid, - Modules const& modules, - Sensors const& sensors, - DetectorGeometry const& det_geom, - float ptCut, - bool doR = true) { + MatrixF4x3 boundsAfterCurved( + unsigned int ref_detid, Sensors const& sensors, DetectorGeometry const& det_geom, float ptCut, bool doR = true) { auto bounds = det_geom.getCorners(ref_detid); auto const& sensor = sensors.at(ref_detid); int charge = 1; float z_r = sensor.centerZ / std::sqrt(sensor.centerX * sensor.centerX + sensor.centerY * sensor.centerY); float refphi = std::atan2(sensor.centerY, sensor.centerX); - auto const& refmodule = modules.at(sensors.at(ref_detid).moduleDetId); + auto const& refmodule = sensors.at(ref_detid); unsigned short ref_layer = refmodule.layer; auto ref_location = refmodule.location; MatrixF4x3 next_layer_bound_points; @@ -254,7 +249,6 @@ namespace lstgeometry { } std::vector getCurvedLineConnections(unsigned int ref_detid, - Modules const& modules, Sensors const& sensors, DetectorGeometry const& det_geom, float ptCut) { @@ -262,7 +256,7 @@ namespace lstgeometry { float refphi = std::atan2(sensor.centerY, sensor.centerX); - auto const& refmodule = modules.at(sensors.at(ref_detid).moduleDetId); + auto const& refmodule = sensors.at(ref_detid); unsigned short ref_layer = refmodule.layer; auto ref_location = refmodule.location; @@ -275,7 +269,7 @@ namespace lstgeometry { ? det_geom.getBarrelLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second) : det_geom.getEndcapLayerDetIds(ref_layer + 1, etaphibins.first, etaphibins.second); - auto next_layer_bound_points = boundsAfterCurved(ref_detid, modules, sensors, det_geom, ptCut); + auto next_layer_bound_points = boundsAfterCurved(ref_detid, sensors, det_geom, ptCut); std::vector list_of_detids_etaphi_layer_tar; for (unsigned int tar_detid : tar_detids_to_be_considered) { @@ -362,25 +356,21 @@ namespace lstgeometry { return merged; } - ModuleMap buildModuleMap(Modules const& modules, - Sensors const& sensors, - DetectorGeometry const& det_geo, - float pt_cut) { - auto detids_etaphi_layer_ref = det_geo.getDetIds([&modules, &sensors](auto const& x) { + ModuleMap buildModuleMap(Sensors const& sensors, DetectorGeometry const& det_geo, float pt_cut) { + auto detids_etaphi_layer_ref = det_geo.getDetIds([&sensors](auto const& x) { auto const& s = sensors.at(x.first); - auto const& m = modules.at(s.moduleDetId); // exclude the outermost modules that do not have connections to other modules - return ((m.location == Location::barrel && s.isLower && m.layer != 6) || - (m.location == Location::endcap && s.isLower && m.layer != 5 && !(m.ring == 15 && m.layer == 1) && - !(m.ring == 15 && m.layer == 2) && !(m.ring == 12 && m.layer == 3) && !(m.ring == 12 && m.layer == 4))); + return ((s.location == Location::barrel && s.lower && s.layer != 6) || + (s.location == Location::endcap && s.lower && s.layer != 5 && !(s.ring == 15 && s.layer == 1) && + !(s.ring == 15 && s.layer == 2) && !(s.ring == 12 && s.layer == 3) && !(s.ring == 12 && s.layer == 4))); }); std::unordered_map> straight_line_connections; std::unordered_map> curved_line_connections; for (auto ref_detid : detids_etaphi_layer_ref) { - straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, modules, sensors, det_geo); - curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, modules, sensors, det_geo, pt_cut); + straight_line_connections[ref_detid] = getStraightLineConnections(ref_detid, sensors, det_geo); + curved_line_connections[ref_detid] = getCurvedLineConnections(ref_detid, sensors, det_geo, pt_cut); } return mergeLineConnections({&straight_line_connections, &curved_line_connections}); } diff --git a/RecoTracker/LSTGeometry/src/PixelMap.cc b/RecoTracker/LSTGeometry/src/PixelMap.cc index b1f05b2c2ab41..20b191703bc4b 100644 --- a/RecoTracker/LSTGeometry/src/PixelMap.cc +++ b/RecoTracker/LSTGeometry/src/PixelMap.cc @@ -3,10 +3,7 @@ namespace lstgeometry { - PixelMap buildPixelMap(Modules const& modules, - Sensors const& sensors, - DetectorGeometry const& det_geom, - float pt_cut) { + PixelMap buildPixelMap(Sensors const& sensors, DetectorGeometry const& det_geom, float pt_cut) { // Charge 0 is the union of charge 1 and charge -1 PixelMap maps; @@ -25,16 +22,15 @@ namespace lstgeometry { for (auto detId : det_geom.getDetIds()) { auto const& sensor = sensors.at(detId); - auto const& module = modules.at(sensor.moduleDetId); // Phase-2 enum differs from the legacy one used here - unsigned int subdet = module.subdet == SubDetector::P2OTB ? SubDet::Barrel : SubDet::Endcap; - auto layer = module.layer; + unsigned int subdet = sensor.subdet == SubDetector::P2OTB ? SubDet::Barrel : SubDet::Endcap; + auto layer = sensor.layer; if (layer > 2) continue; - auto location = module.location; + auto location = sensor.location; // Skip if the module is not PS module and is not lower sensor - if (module.moduleType == ModuleType::Ph2SS || !sensor.isLower) + if (sensor.moduleType == ModuleType::Ph2SS || !sensor.lower) continue; // For this module, now compute which super bins they belong to diff --git a/RecoTracker/LSTGeometry/src/Sensor.cc b/RecoTracker/LSTGeometry/src/Sensor.cc index 2b057a91e3e59..8ad711b9bf8b0 100644 --- a/RecoTracker/LSTGeometry/src/Sensor.cc +++ b/RecoTracker/LSTGeometry/src/Sensor.cc @@ -6,19 +6,71 @@ using namespace lstgeometry; -Sensor::Sensor(unsigned int moduleDetId, +// Not sure if there is functionality for this already in CMSSW +bool isInverted(unsigned int moduleId, Location location, Side side, unsigned int layer) { + bool moduleIdIsEven = moduleId % 2 == 0; + if (location == Location::endcap) { + if (side == Side::NegZ) { + return !moduleIdIsEven; + } else if (side == Side::PosZ) { + return moduleIdIsEven; + } + } else if (location == Location::barrel) { + if (side == Side::Center) { + if (layer <= 3) { + return !moduleIdIsEven; + } else if (layer >= 4) { + return moduleIdIsEven; + } + } else if (side == Side::NegZ || side == Side::PosZ) { + if (layer <= 2) { + return !moduleIdIsEven; + } else if (layer == 3) { + return moduleIdIsEven; + } + } + } + return false; +} + +// This differs from TrackerTopology::isLower since it considers if the module is inverted +bool isLower(unsigned int moduleId, Location location, Side side, unsigned int layer, unsigned int detId) { + return isInverted(moduleId, location, side, layer) ? !(detId & 1) : (detId & 1); +} + +bool isStrip(ModuleType moduleType, bool isInverted, bool isLower) { + if (moduleType == ModuleType::Ph2SS) + return true; + if (isInverted) + return isLower; + return !isLower; +} + +Sensor::Sensor(unsigned int detId, + ModuleType moduleType, + SubDetector subdet, + Location location, + Side side, + unsigned int moduleId, + unsigned int layer, + unsigned int ring, float centerRho, float centerZ, float centerPhi, - bool isLower, - ModuleType moduleType, Surface const &surface) - : moduleDetId(moduleDetId), + : moduleType(moduleType), + subdet(subdet), + location(location), + side(side), + moduleId(moduleId), + layer(layer), + ring(ring), + inverted(isInverted(moduleId, location, side, layer)), centerRho(centerRho), centerZ(centerZ), centerPhi(centerPhi), - isLower(isLower), - moduleType(moduleType), + lower(isLower(moduleId, location, side, layer, detId)), + strip(isStrip(moduleType, inverted, lower)), centerX(centerRho * std::cos(centerPhi)), centerY(centerRho * std::sin(centerPhi)) { const Bounds &bounds = surface.bounds(); diff --git a/RecoTracker/LSTGeometry/src/Slope.cc b/RecoTracker/LSTGeometry/src/Slope.cc index f35cf41ffdb67..eab4161cbec38 100644 --- a/RecoTracker/LSTGeometry/src/Slope.cc +++ b/RecoTracker/LSTGeometry/src/Slope.cc @@ -12,16 +12,8 @@ namespace lstgeometry { dxdy = dy != 0 ? -dx / dy : kDefaultSlope; } - bool isStripLayer(Module module, bool isLower) { - if (module.moduleType == ModuleType::Ph2SS) - return true; - if (isInverted(module.moduleId, module.location, module.side, module.layer)) - return isLower; - return !isLower; - } - // Use each sensor's corners to calculate and categorize drdz and dxdy slopes. - std::tuple computeSlopes(Modules const& modules, Sensors const& sensors) { + std::tuple computeSlopes(Sensors const& sensors) { Slopes barrel_slopes; Slopes endcap_slopes; @@ -32,11 +24,9 @@ namespace lstgeometry { Slope slope(dx, dy, dz); - auto const& module = modules.at(sensor.moduleDetId); - - auto location = module.location; - bool is_tilted = module.side != Side::Center; - bool is_strip = isStripLayer(module, sensor.isLower); + auto location = sensor.location; + bool is_tilted = sensor.side != Side::Center; + bool is_strip = sensor.strip; if (!is_strip) continue; From 373f78d1273ce0fb97f7c0e6347e6bc81832e498 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 11 Mar 2026 13:04:20 -0400 Subject: [PATCH 92/95] Revert to previous value of kB --- RecoTracker/LSTGeometry/interface/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index db7a755c4518d..b3383f97ff0bb 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -28,7 +28,7 @@ namespace lstgeometry { enum SubDet { InnerPixel = 0, Barrel = 5, Endcap = 4 }; enum Side { NegZ = 1, PosZ = 2, Center = 3 }; - constexpr float kB = 3.8; + constexpr float kB = 3.8112; constexpr float kC = 0.00299792458; constexpr unsigned int kBarrelLayers = 6; From 4c0f52e7415f98779906d217fd8f17a3f33c31bd Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 11 Mar 2026 16:04:27 -0400 Subject: [PATCH 93/95] Back to 3.8, but fixed sign in module maps --- RecoTracker/LSTGeometry/interface/Common.h | 2 +- RecoTracker/LSTGeometry/interface/Module.h | 24 ++++++++++++++++++++++ RecoTracker/LSTGeometry/src/ModuleMap.cc | 6 +++--- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 RecoTracker/LSTGeometry/interface/Module.h diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index b3383f97ff0bb..db7a755c4518d 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -28,7 +28,7 @@ namespace lstgeometry { enum SubDet { InnerPixel = 0, Barrel = 5, Endcap = 4 }; enum Side { NegZ = 1, PosZ = 2, Center = 3 }; - constexpr float kB = 3.8112; + constexpr float kB = 3.8; constexpr float kC = 0.00299792458; constexpr unsigned int kBarrelLayers = 6; diff --git a/RecoTracker/LSTGeometry/interface/Module.h b/RecoTracker/LSTGeometry/interface/Module.h new file mode 100644 index 0000000000000..f28f31afe2a8e --- /dev/null +++ b/RecoTracker/LSTGeometry/interface/Module.h @@ -0,0 +1,24 @@ +#ifndef RecoTracker_LSTGeometry_interface_Module_h +#define RecoTracker_LSTGeometry_interface_Module_h + +#include + +#include "RecoTracker/LSTGeometry/interface/Common.h" + +namespace lstgeometry { + + // A module contains 2 sensors. The common properties of the 2 sensors are stored in the Module struct, and the sensor-specific properties are stored in the Sensor struct. + struct Module { + ModuleType moduleType; + SubDetector subdet; + Location location; + Side side; + unsigned int moduleId; + unsigned int layer; + unsigned int ring; + }; + + using Modules = std::unordered_map; +} // namespace lstgeometry + +#endif diff --git a/RecoTracker/LSTGeometry/src/ModuleMap.cc b/RecoTracker/LSTGeometry/src/ModuleMap.cc index 34bc7a3e741e3..b58f8a2875c22 100644 --- a/RecoTracker/LSTGeometry/src/ModuleMap.cc +++ b/RecoTracker/LSTGeometry/src/ModuleMap.cc @@ -201,7 +201,7 @@ namespace lstgeometry { if (ref_location == Location::barrel) { if (doR) { float tar_layer_radius = det_geom.getBarrelLayerAverageRadius(ref_layer + 1); - if (bound_z_r > z_r) { + if (bound_z_r < z_r) { auto const& h = phi_diff > 0 ? helix_p10 : helix_p10_pos; next_point = h.pointFromRadius(tar_layer_radius); } else { @@ -210,7 +210,7 @@ namespace lstgeometry { } } else { float tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(1); - if (bound_z_r > z_r) { + if (bound_z_r < z_r) { if (phi_diff > 0) { next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); } else { @@ -226,7 +226,7 @@ namespace lstgeometry { } } else { float tar_layer_z = det_geom.getEndcapLayerAverageAbsZ(ref_layer + 1); - if (bound_z_r > z_r) { + if (bound_z_r < z_r) { if (phi_diff > 0) { next_point = helix_p10.pointFromZ(std::copysign(tar_layer_z, helix_p10.lambda)); } else { From 20449700b0559b2b0e57e26ea92c178b89b41d4f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 12 Mar 2026 11:10:38 -0400 Subject: [PATCH 94/95] Fixed eta computation and phi binning --- RecoTracker/LSTGeometry/src/Common.cc | 2 +- RecoTracker/LSTGeometry/src/DetectorGeometry.cc | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/RecoTracker/LSTGeometry/src/Common.cc b/RecoTracker/LSTGeometry/src/Common.cc index f5708b4d4413f..5d2bdbf809eff 100644 --- a/RecoTracker/LSTGeometry/src/Common.cc +++ b/RecoTracker/LSTGeometry/src/Common.cc @@ -35,7 +35,7 @@ namespace lstgeometry { std::pair getEtaPhi(float x, float y, float z, float refphi) { float phi = phi_mpi_pi(std::atan2(y, x) - refphi); - float eta = std::asinh(std::sqrt(x * x + y * y) / z); + float eta = std::asinh(z / std::sqrt(x * x + y * y)); return std::make_pair(eta, phi); } diff --git a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc index 0b0244f7f9c33..322418f71ce28 100644 --- a/RecoTracker/LSTGeometry/src/DetectorGeometry.cc +++ b/RecoTracker/LSTGeometry/src/DetectorGeometry.cc @@ -32,8 +32,10 @@ namespace lstgeometry { unsigned int eta_bin = std::clamp(static_cast(theta / kEtaBinRad), 0u, kNEtaBins - 1); float pi = std::numbers::pi_v; - unsigned int raw = static_cast((phi + pi) / kPhiBinWidth); - unsigned int phi_bin = (raw == 0 || raw >= kNPhiBins) ? 0u : raw; + unsigned int phi_bin = + std::clamp(static_cast((phi + pi + kPhiBinWidth / 2.) / kPhiBinWidth), 0u, kNPhiBins - 1); + if (phi >= pi - kPhiBinWidth / 2) + phi_bin = 0; // The 0 bin wraps around return std::make_pair(eta_bin, phi_bin); } From 9f84e805100121f69492b5e076d648553b97969e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 19 Mar 2026 13:59:50 +0000 Subject: [PATCH 95/95] Moved Helix out of standalone --- .../LSTCore/standalone/code/core/lst_math.h | 84 +----------- .../LSTCore/standalone/code/core/trkCore.cc | 14 +- RecoTracker/LSTGeometry/interface/Common.h | 4 + .../LSTGeometry/interface/DetectorGeometry.h | 3 +- RecoTracker/LSTGeometry/interface/Helix.h | 121 +++++++++++++++++- RecoTracker/LSTGeometry/interface/Sensor.h | 2 + RecoTracker/LSTGeometry/src/Helix.cc | 68 ---------- 7 files changed, 134 insertions(+), 162 deletions(-) delete mode 100644 RecoTracker/LSTGeometry/src/Helix.cc diff --git a/RecoTracker/LSTCore/standalone/code/core/lst_math.h b/RecoTracker/LSTCore/standalone/code/core/lst_math.h index 3d31efcabb21b..cd4ef9d57f206 100644 --- a/RecoTracker/LSTCore/standalone/code/core/lst_math.h +++ b/RecoTracker/LSTCore/standalone/code/core/lst_math.h @@ -4,7 +4,12 @@ #include #include +#include "RecoTracker/LSTGeometry/interface/Helix.h" + namespace lst_math { + + using Helix = lstgeometry::Helix; + inline float Phi_mpi_pi(float x) { if (std::isnan(x)) { std::cout << "MathUtil::Phi_mpi_pi() function called with NaN" << std::endl; @@ -33,85 +38,6 @@ namespace lst_math { inline float ptEstimateFromRadius(float radius) { return 2.99792458e-3 * 3.8 * radius; }; - class Helix { - public: - std::vector center_; - float radius_; - float phi_; - float lam_; - float charge_; - - Helix(std::vector c, float r, float p, float l, float q) { - center_ = c; - radius_ = r; - phi_ = Phi_mpi_pi(p); - lam_ = l; - charge_ = q; - } - - Helix(float pt, float eta, float phi, float vx, float vy, float vz, float charge) { - // Radius based on pt - radius_ = pt / (2.99792458e-3 * 3.8); - phi_ = phi; - charge_ = charge; - - // reference point vector which for sim track is the vertex point - float ref_vec_x = vx; - float ref_vec_y = vy; - float ref_vec_z = vz; - - // The reference to center vector - float inward_radial_vec_x = charge_ * radius_ * sin(phi_); - float inward_radial_vec_y = charge_ * radius_ * -cos(phi_); - float inward_radial_vec_z = 0; - - // Center point - float center_vec_x = ref_vec_x + inward_radial_vec_x; - float center_vec_y = ref_vec_y + inward_radial_vec_y; - float center_vec_z = ref_vec_z + inward_radial_vec_z; - center_.push_back(center_vec_x); - center_.push_back(center_vec_y); - center_.push_back(center_vec_z); - - // Lambda - lam_ = copysign(M_PI / 2. - 2. * atan(exp(-std::abs(eta))), eta); - } - - const std::vector center() { return center_; } - const float radius() { return radius_; } - const float phi() { return phi_; } - const float lam() { return lam_; } - const float charge() { return charge_; } - - std::tuple get_helix_point(float t) { - float x = center()[0] - charge() * radius() * sin(phi() - (charge()) * t); - float y = center()[1] + charge() * radius() * cos(phi() - (charge()) * t); - float z = center()[2] + radius() * tan(lam()) * t; - float r = sqrt(x * x + y * y); - return std::make_tuple(x, y, z, r); - } - - float infer_t(const std::vector point) { - // Solve for t based on z position - float t = (point[2] - center()[2]) / (radius() * tan(lam())); - return t; - } - - float compare_radius(const std::vector point) { - float t = infer_t(point); - auto [x, y, z, r] = get_helix_point(t); - float point_r = sqrt(point[0] * point[0] + point[1] * point[1]); - return (point_r - r); - } - - float compare_xy(const std::vector point) { - float t = infer_t(point); - auto [x, y, z, r] = get_helix_point(t); - float xy_dist = sqrt(pow(point[0] - x, 2) + pow(point[1] - y, 2)); - return xy_dist; - } - }; - class Hit { public: float x_, y_, z_; diff --git a/RecoTracker/LSTCore/standalone/code/core/trkCore.cc b/RecoTracker/LSTCore/standalone/code/core/trkCore.cc index 7dc9026ea766b..343d78b60b85a 100644 --- a/RecoTracker/LSTCore/standalone/code/core/trkCore.cc +++ b/RecoTracker/LSTCore/standalone/code/core/trkCore.cc @@ -658,20 +658,20 @@ float drfracSimHitConsistentWithHelix(lst_math::Helix& helix, std::vector const& trk_simhit_y, std::vector const& trk_simhit_z) { // Sim hit vector - std::vector point = {trk_simhit_x[isimhitidx], trk_simhit_y[isimhitidx], trk_simhit_z[isimhitidx]}; + std::array point = {trk_simhit_x[isimhitidx], trk_simhit_y[isimhitidx], trk_simhit_z[isimhitidx]}; // Inferring parameter t of helix parametric function via z position - float t = helix.infer_t(point); + float t = helix.inferT(point); // If the best fit is more than pi parameter away then it's a returning hit and should be ignored if (not(t <= M_PI)) return 999; // Expected hit position with given z - auto [x, y, z, r] = helix.get_helix_point(t); + auto [x, y, z, r] = helix.point(t); // ( expected_r - simhit_r ) / expected_r - float drfrac = std::abs(helix.compare_radius(point)) / r; + float drfrac = std::abs(helix.compareRadius(point)) / r; return drfrac; } @@ -711,10 +711,10 @@ float distxySimHitConsistentWithHelix(lst_math::Helix& helix, std::vector const& trk_simhit_y, std::vector const& trk_simhit_z) { // Sim hit vector - std::vector point = {trk_simhit_x[isimhitidx], trk_simhit_y[isimhitidx], trk_simhit_z[isimhitidx]}; + std::array point = {trk_simhit_x[isimhitidx], trk_simhit_y[isimhitidx], trk_simhit_z[isimhitidx]}; // Inferring parameter t of helix parametric function via z position - float t = helix.infer_t(point); + float t = helix.inferT(point); // If the best fit is more than pi parameter away then it's a returning hit and should be ignored if (not(t <= M_PI)) @@ -724,7 +724,7 @@ float distxySimHitConsistentWithHelix(lst_math::Helix& helix, //auto [x, y, z, r] = helix.get_helix_point(t); // ( expected_r - simhit_r ) / expected_r - float distxy = helix.compare_xy(point); + float distxy = helix.compareXY(point); return distxy; } diff --git a/RecoTracker/LSTGeometry/interface/Common.h b/RecoTracker/LSTGeometry/interface/Common.h index db7a755c4518d..d4af3f35d997c 100644 --- a/RecoTracker/LSTGeometry/interface/Common.h +++ b/RecoTracker/LSTGeometry/interface/Common.h @@ -3,7 +3,9 @@ #include #include +#ifndef LST_STANDALONE #include +#endif #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "Geometry/CommonTopologies/interface/GeomDetEnumerators.h" @@ -11,6 +13,7 @@ namespace lstgeometry { +#ifndef LST_STANDALONE using MatrixF3x3 = Eigen::Matrix; using MatrixF4x2 = Eigen::Matrix; using MatrixF4x3 = Eigen::Matrix; @@ -20,6 +23,7 @@ namespace lstgeometry { using RowVectorF2 = Eigen::Matrix; using ColVectorF3 = Eigen::Matrix; using RowVectorF3 = Eigen::Matrix; +#endif using ModuleType = TrackerGeometry::ModuleType; using SubDetector = GeomDetEnumerators::SubDetector; diff --git a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h index 983f1bea6fe47..2e91641026f85 100644 --- a/RecoTracker/LSTGeometry/interface/DetectorGeometry.h +++ b/RecoTracker/LSTGeometry/interface/DetectorGeometry.h @@ -28,8 +28,9 @@ namespace lstgeometry { DetectorGeometry(std::shared_ptr sensors, std::array const& avg_radii, std::array const& avg_z); - +#ifndef LST_STANDALONE MatrixF4x3 const& getCorners(unsigned int detId) const; +#endif std::vector getDetIds(std::function&)> filter = [](auto const&) { return true; }) const; diff --git a/RecoTracker/LSTGeometry/interface/Helix.h b/RecoTracker/LSTGeometry/interface/Helix.h index 14ce955ac0a46..66da3e933aa89 100644 --- a/RecoTracker/LSTGeometry/interface/Helix.h +++ b/RecoTracker/LSTGeometry/interface/Helix.h @@ -1,22 +1,129 @@ #ifndef RecoTracker_LSTGeometry_interface_Helix_h #define RecoTracker_LSTGeometry_interface_Helix_h +// This header contains implementations so that the standalone part of LSTCore can use it without having to link some extra library. + +#include +#include + +#include + +//#include "RecoTracker/LSTGeometry/interface/Common.h" + namespace lstgeometry { struct Helix { - float center_x; - float center_y; - float center_z; + std::array center; float radius; float phi; float lambda; int charge; - Helix(float center_x, float center_y, float center_z, float radius, float phi, float lam, int charge); - Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge); + Helix(std::array center, float radius, float phi, float lambda, int charge) + : center(center), radius(radius), phi(phi), lambda(lambda), charge(charge) {} + + // Clarification : phi was derived assuming a negatively charged particle would start + // at the first quadrant. However the way signs are set up in the get_track_point function + // implies the particle actually starts out in the fourth quadrant, and phi is measured from + // the y axis as opposed to x axis in the expression provided in this function. Hence I tucked + // in an extra pi/2 to account for these effects + Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge) : charge(charge) { + radius = pt / (kC * kB); + + float t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * radius)); + phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + + ((vy - my) / (vx - mx) < 0) * (std::numbers::pi_v)+charge * t / 2. + + (my - vy < 0) * (std::numbers::pi_v / 2.) - (my - vy > 0) * (std::numbers::pi_v / 2.); + + center[0] = vx + charge * radius * std::sin(phi); + center[1] = vy - charge * radius * std::cos(phi); + center[2] = vz; + lambda = std::atan((mz - vz) / (radius * t)); + } + + Helix(float pt, float eta, float phi, float vx, float vy, float vz, float charge) : phi(phi), charge(charge) { + // Radius based on pt + radius = pt / (kC * kB); + + // reference point vector which for sim track is the vertex point + float ref_vec_x = vx; + float ref_vec_y = vy; + float ref_vec_z = vz; + + // The reference to center vector + float inward_radial_vec_x = charge * radius * sin(phi); + float inward_radial_vec_y = charge * radius * -cos(phi); + float inward_radial_vec_z = 0; + + // Center point + center[0] = ref_vec_x + inward_radial_vec_x; + center[1] = ref_vec_y + inward_radial_vec_y; + center[2] = ref_vec_z + inward_radial_vec_z; + + // Lambda + lambda = copysign(M_PI / 2. - 2. * atan(exp(-std::abs(eta))), eta); + } + + std::array point(float t) const { + float x = center[0] - charge * radius * std::sin(phi - charge * t); + float y = center[1] + charge * radius * std::cos(phi - charge * t); + float z = center[2] + radius * std::tan(lambda) * t; + float r = std::sqrt(x * x + y * y); + return {x, y, z, r}; + } + + float inferT(std::array const& point) const { + return (point[2] - center[2]) / (radius * std::tan(lambda)); + } + + std::tuple pointFromRadius(float target_r) const { + auto objective_function = [this, target_r](float t) { + float x = this->center[0] - this->charge * this->radius * std::sin(this->phi - this->charge * t); + float y = this->center[1] + this->charge * this->radius * std::cos(this->phi - this->charge * t); + return std::fabs(std::sqrt(x * x + y * y) - target_r); + }; + int bits = std::numeric_limits::digits; + auto result = boost::math::tools::brent_find_minima(objective_function, 0.0f, std::numbers::pi_v, bits); + float t = result.first; + + float x = center[0] - charge * radius * std::sin(phi - charge * t); + float y = center[1] + charge * radius * std::cos(phi - charge * t); + float z = center[2] + radius * std::tan(lambda) * t; + float r = std::sqrt(x * x + y * y); + + return std::make_tuple(x, y, z, r); + } + + std::tuple pointFromZ(float target_z) const { + auto objective_function = [this, target_z](float t) { + float z = this->center[2] + this->radius * std::tan(this->lambda) * t; + return std::fabs(z - target_z); + }; + int bits = std::numeric_limits::digits; + auto result = boost::math::tools::brent_find_minima(objective_function, 0.0f, std::numbers::pi_v, bits); + float t = result.first; + + float x = center[0] - charge * radius * std::sin(phi - charge * t); + float y = center[1] + charge * radius * std::cos(phi - charge * t); + float z = center[2] + radius * std::tan(lambda) * t; + float r = std::sqrt(x * x + y * y); + + return std::make_tuple(x, y, z, r); + } + + float compareRadius(std::array const& pt) const { + float t = inferT(pt); + auto [x, y, z, r] = point(t); + float point_r = std::sqrt(pt[0] * pt[0] + pt[1] * pt[1]); + return (point_r - r); + } - std::tuple pointFromRadius(float target_r) const; - std::tuple pointFromZ(float target_z) const; + float compareXY(std::array const& pt) const { + float t = inferT(pt); + auto [x, y, z, r] = point(t); + float xy_dist = std::sqrt(std::pow(pt[0] - x, 2) + std::pow(pt[1] - y, 2)); + return xy_dist; + } }; } // namespace lstgeometry diff --git a/RecoTracker/LSTGeometry/interface/Sensor.h b/RecoTracker/LSTGeometry/interface/Sensor.h index bb92a5db004bc..15acf01946b49 100644 --- a/RecoTracker/LSTGeometry/interface/Sensor.h +++ b/RecoTracker/LSTGeometry/interface/Sensor.h @@ -26,7 +26,9 @@ namespace lstgeometry { float centerPhi; bool lower; bool strip; +#ifndef LST_STANDALONE MatrixF4x3 corners; +#endif // Redundant, but convenient to avoid repeated computations float centerX; float centerY; diff --git a/RecoTracker/LSTGeometry/src/Helix.cc b/RecoTracker/LSTGeometry/src/Helix.cc deleted file mode 100644 index 28f53a2cb175a..0000000000000 --- a/RecoTracker/LSTGeometry/src/Helix.cc +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef RecoTracker_LSTGeometry_interface_Math_h -#define RecoTracker_LSTGeometry_interface_Math_h - -#include - -#include - -#include "RecoTracker/LSTGeometry/interface/Common.h" -#include "RecoTracker/LSTGeometry/interface/Helix.h" - -namespace lstgeometry { - - // Clarification : phi was derived assuming a negatively charged particle would start - // at the first quadrant. However the way signs are set up in the get_track_point function - // implies the particle actually starts out in the fourth quadrant, and phi is measured from - // the y axis as opposed to x axis in the expression provided in this function. Hence I tucked - // in an extra pi/2 to account for these effects - Helix::Helix(float pt, float vx, float vy, float vz, float mx, float my, float mz, int charge) : charge(charge) { - radius = pt / (kC * kB); - - float t = 2. * std::asin(std::sqrt((vx - mx) * (vx - mx) + (vy - my) * (vy - my)) / (2. * radius)); - phi = std::numbers::pi_v / 2. + std::atan((vy - my) / (vx - mx)) + - ((vy - my) / (vx - mx) < 0) * (std::numbers::pi_v)+charge * t / 2. + - (my - vy < 0) * (std::numbers::pi_v / 2.) - (my - vy > 0) * (std::numbers::pi_v / 2.); - - center_x = vx + charge * radius * std::sin(phi); - center_y = vy - charge * radius * std::cos(phi); - center_z = vz; - lambda = std::atan((mz - vz) / (radius * t)); - } - - std::tuple Helix::pointFromRadius(float target_r) const { - auto objective_function = [this, target_r](float t) { - float x = this->center_x - this->charge * this->radius * std::sin(this->phi - this->charge * t); - float y = this->center_y + this->charge * this->radius * std::cos(this->phi - this->charge * t); - return std::fabs(std::sqrt(x * x + y * y) - target_r); - }; - int bits = std::numeric_limits::digits; - auto result = boost::math::tools::brent_find_minima(objective_function, 0.0f, std::numbers::pi_v, bits); - float t = result.first; - - float x = center_x - charge * radius * std::sin(phi - charge * t); - float y = center_y + charge * radius * std::cos(phi - charge * t); - float z = center_z + radius * std::tan(lambda) * t; - float r = std::sqrt(x * x + y * y); - - return std::make_tuple(x, y, z, r); - } - - std::tuple Helix::pointFromZ(float target_z) const { - auto objective_function = [this, target_z](float t) { - float z = this->center_z + this->radius * std::tan(this->lambda) * t; - return std::fabs(z - target_z); - }; - int bits = std::numeric_limits::digits; - auto result = boost::math::tools::brent_find_minima(objective_function, 0.0f, std::numbers::pi_v, bits); - float t = result.first; - - float x = center_x - charge * radius * std::sin(phi - charge * t); - float y = center_y + charge * radius * std::cos(phi - charge * t); - float z = center_z + radius * std::tan(lambda) * t; - float r = std::sqrt(x * x + y * y); - - return std::make_tuple(x, y, z, r); - } - -} // namespace lstgeometry -#endif