From e36c573730948d68026ead87dd9b1f3dd5c9ef52 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 16 Sep 2025 16:05:46 +0000 Subject: [PATCH 01/57] 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 9c72348746fa18b8b455efcce9dd5685fb781259 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 14:17:16 -0400 Subject: [PATCH 02/57] 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 0219a91f14627038d4cdc748e450dfa04faf6cdd Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 15:19:33 -0400 Subject: [PATCH 03/57] 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 7bac52cd92892881e23a35552107ee182b46804f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 15:33:28 -0400 Subject: [PATCH 04/57] 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 01e5f7d7b23488b6c217c153a8d63d80ab522fda Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Sep 2025 16:59:02 -0400 Subject: [PATCH 05/57] 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 6f5baf4c7c52ea35822c077c2cf32d280903a026 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 19 Sep 2025 19:33:00 +0000 Subject: [PATCH 06/57] 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 e30647c17d265004a943422e693fc726cca439ea Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 24 Sep 2025 15:04:27 -0400 Subject: [PATCH 07/57] 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 0c561d41702bc92179bdaa3c12a3558a6bd08bc1 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 25 Sep 2025 10:49:09 -0400 Subject: [PATCH 08/57] 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 83f4f2ef6d9b84ab90b7ef8db6fc001226cffd55 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 25 Sep 2025 14:51:58 -0400 Subject: [PATCH 09/57] 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 2477131911760a3ce42b0eff8ca6cd45d4d3e907 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 26 Sep 2025 10:28:08 -0400 Subject: [PATCH 10/57] 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 55776977f2d2b339fb0ed1186fa07485393de2ec Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 26 Sep 2025 10:30:33 -0400 Subject: [PATCH 11/57] 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 048ec2b4e095d7c0792c0c3ac51178e552d78bfe Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 26 Sep 2025 11:28:20 -0400 Subject: [PATCH 12/57] 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 650726e600b6e2c3a19887f3636dd50a3028c6b1 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 30 Sep 2025 14:01:20 -0400 Subject: [PATCH 13/57] 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 f61cbbf3d11781232625a0f0d9c67cd882e0e1fc Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 Oct 2025 11:33:46 -0400 Subject: [PATCH 14/57] 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 1a336ebba404c94966d1337ec5f892aeb88ee597 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 Oct 2025 14:17:17 -0400 Subject: [PATCH 15/57] 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 54eca661a1426ce1aa8675a0c26f2035994ced9d Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 09:21:16 -0400 Subject: [PATCH 16/57] 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 5a5f0713877de8437d1723c327400e940579b78c Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 10:36:13 -0400 Subject: [PATCH 17/57] 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 8c9cef1e3427fee0ab481f650568c4117e076443 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 18:14:57 +0000 Subject: [PATCH 18/57] 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 52c73487b196aa31926b688334d23b8da5b388ff Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 22 Oct 2025 16:16:29 -0400 Subject: [PATCH 19/57] 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 e1d8e33d5afb8b258265e059b841d1c198ef5cc7 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 27 Oct 2025 12:10:08 -0400 Subject: [PATCH 20/57] 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 7e14f2088b4352e1999c817a8c6464b1a0c0b57c Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 27 Oct 2025 16:56:14 -0400 Subject: [PATCH 21/57] 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 d0ad74379a7b5f0d887fae087415d97e152425a2 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 28 Oct 2025 14:07:36 -0400 Subject: [PATCH 22/57] 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 7d929254e2242d495cb721a2d081fc285ded40f1 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 28 Oct 2025 14:23:21 -0400 Subject: [PATCH 23/57] 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 7db81b4a71d39894d31475e29cda2aa58995b662 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 31 Oct 2025 10:28:58 -0400 Subject: [PATCH 24/57] 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 3d144d8f07d52c743d961ab850a6ddd66b9397e6 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 3 Nov 2025 15:18:49 -0500 Subject: [PATCH 25/57] 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 a996ea47f5fb0a128527735abf651ea485e53cb9 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 3 Nov 2025 20:20:03 +0000 Subject: [PATCH 26/57] 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 a4770b6ec56bf0cbd137b6c31526d4ab582177a5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 6 Nov 2025 20:47:16 +0000 Subject: [PATCH 27/57] Added cmssw scaffoling --- .../interface/LSTGeometry/PixelMapMethods.h | 16 ++--- RecoTracker/LSTCore/plugins/BuildFile.xml | 35 +++++++++++ .../LSTCore/plugins/LSTGeometryESProducer.cc | 62 +++++++++++++++++++ RecoTracker/LSTCore/test/BuildFile.xml | 8 +++ RecoTracker/LSTCore/test/DumpLSTGeometry.cc | 24 +++++++ RecoTracker/LSTCore/test/dumpLSTGeometry.py | 50 +++++++++++++++ .../LSTCore/test/testDumpLSTGeometry.sh | 10 +++ 7 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 RecoTracker/LSTCore/plugins/BuildFile.xml create mode 100644 RecoTracker/LSTCore/plugins/LSTGeometryESProducer.cc create mode 100644 RecoTracker/LSTCore/test/BuildFile.xml 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 new file mode 100644 index 0000000000000..c5aa2f03a7b62 --- /dev/null +++ b/RecoTracker/LSTCore/test/BuildFile.xml @@ -0,0 +1,8 @@ + + + + + + + + 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 539e085c2138316b707b3b61f3704b51972aa3f5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 19 Nov 2025 18:32:55 +0000 Subject: [PATCH 28/57] 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 b5fb2de9cde54f4be8a22cf11cac96ce44304399 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 19 Nov 2025 18:58:06 +0000 Subject: [PATCH 29/57] 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 317653f42a20d0ce9dd7f0cd4d2b91db9966fa12 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 21 Nov 2025 21:41:57 +0000 Subject: [PATCH 30/57] 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 76dca6046bb9920746523f2dfa35e534e5f494b4 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 24 Nov 2025 14:34:31 -0500 Subject: [PATCH 31/57] 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 6c74ad92c7df0c3670029faee58d6187de7a8a65 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 24 Nov 2025 21:45:34 +0000 Subject: [PATCH 32/57] 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 d4dc0dc21e4f2018a7dc52bd89a616a5eb42d7bd Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 25 Nov 2025 18:52:23 +0000 Subject: [PATCH 33/57] 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 057098a846cfae0bbb816f550d7ec895ccdcb795 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 1 Dec 2025 19:19:04 +0000 Subject: [PATCH 34/57] 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 ed163cf6c80389a64eb4076292e46bac35d65063 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 1 Dec 2025 21:47:12 +0000 Subject: [PATCH 35/57] 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 4bb1bad02024c243e28ec2a81527853c126f3da4 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 2 Dec 2025 13:09:11 -0500 Subject: [PATCH 36/57] 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 84102a5620cf99c2c701ae251b46a2072c372b58 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 3 Dec 2025 17:23:34 +0000 Subject: [PATCH 37/57] 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 bfa10186f8f2e..eb3f3c7906ba1 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 4f74ac486e1b1..8b4f56e693df0 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 05b1ff68eb53c..18c64e6ba4393 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, @@ -404,5 +401,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 14afa6a71043e37c5f3a906b84a06239275e7803 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 3 Dec 2025 18:39:24 +0000 Subject: [PATCH 38/57] 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 d2682a71c8beea67b3339fe22259c324779bf4d5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 4 Dec 2025 10:49:44 -0500 Subject: [PATCH 39/57] 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 ffe91bad679851c2674a634f26d6fa7675d68ebe Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 18:08:17 +0000 Subject: [PATCH 40/57] 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 6f64b0f41a2738b459436ef54096927e50f84a68 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:05:29 -0500 Subject: [PATCH 41/57] 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 2ababcef3ffd915fbba8edf2fe2bb92807dd081a Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:20:02 -0500 Subject: [PATCH 42/57] 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 76ba0956f69c94ebfcd8fb9bc0ee0effd0611027 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:22:55 -0500 Subject: [PATCH 43/57] 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 d609f43ad64297743204edcd872320928efdc60e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:24:34 -0500 Subject: [PATCH 44/57] 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 dcf51e9bc3799b7f728a30855e364e9c8091ce1f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 17:26:17 -0500 Subject: [PATCH 45/57] 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 d860ac2474abd14694018c52148a20a71495899f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 5 Dec 2025 18:12:09 -0500 Subject: [PATCH 46/57] 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 1df1a68fce2c007bcb51f502f1f8bff14a21afbc Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 8 Dec 2025 20:58:48 +0000 Subject: [PATCH 47/57] 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 a69528059177d..95eeccef51803 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 float kMiniDeltaTilted[3] = {0.26f, 0.26f, 0.26f}; HOST_DEVICE_CONSTANT float kMiniDeltaFlat[6] = {0.26f, 0.16f, 0.16f, 0.18f, 0.18f, 0.18f}; diff --git a/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h b/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h index b1404b600a75c..3c294e042edd7 100644 --- a/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h +++ b/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h @@ -300,8 +300,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) { @@ -324,8 +323,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 c4585c62f9f79..c63da0017adc5 100644 --- a/RecoTracker/LSTCore/src/alpaka/Quintuplet.h +++ b/RecoTracker/LSTCore/src/alpaka/Quintuplet.h @@ -663,9 +663,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; @@ -747,9 +746,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 1ea88faf0dcea1fa32ab375208f4b61b95cdb77b Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 8 Dec 2025 21:18:00 +0000 Subject: [PATCH 48/57] 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 5d2a0e6b786799047510612a6488444ebe43632e Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 16 Dec 2025 16:35:01 +0000 Subject: [PATCH 49/57] 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 05177938c5bbf0777066ed9b45fc8a89aef92bba Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Dec 2025 15:18:21 -0500 Subject: [PATCH 50/57] 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 6fb00158d2bbfeed8ff91b3b1375efa2bcfa6e49 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 17 Dec 2025 15:33:57 -0500 Subject: [PATCH 51/57] 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 9d306ca84a8621b8d6c7e8b1d8900fbf447e95d5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 18 Dec 2025 16:16:41 +0000 Subject: [PATCH 52/57] 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 6697a688d0b064f3ab5fb59bf88613159f2e8158 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 19 Dec 2025 17:08:58 +0000 Subject: [PATCH 53/57] 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 a67a6906bbb17f4e86901175d996853ecd6fea25 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 19 Dec 2025 15:15:35 -0500 Subject: [PATCH 54/57] 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 df1995c5022371418736017dcf5ca2c6dd39a537 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 6 Jan 2026 17:56:05 +0000 Subject: [PATCH 55/57] 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 1fba8274f8e3837b045674bfdb992d5d47a2134d Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 8 Jan 2026 15:29:17 +0000 Subject: [PATCH 56/57] 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 ad6092f064ba1..50ebba2f8a51c 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")); @@ -221,7 +221,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 17744c5f1d2f633d463da5e29dd0a2ea544fa5c5 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 9 Jan 2026 12:33:25 -0500 Subject: [PATCH 57/57] 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 50ebba2f8a51c..ad6092f064ba1 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")); @@ -221,7 +221,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; }