Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Wfloat-conversion #658

Merged
merged 12 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/traccc-compiler-options-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if( ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" ) OR
traccc_add_flag( CMAKE_CXX_FLAGS "-Wshadow" )
traccc_add_flag( CMAKE_CXX_FLAGS "-Wunused-local-typedefs" )
traccc_add_flag( CMAKE_CXX_FLAGS "-pedantic" )
traccc_add_flag( CMAKE_CXX_FLAGS "-Wfloat-conversion" )

# Fail on warnings, if asked for that behaviour.
if( TRACCC_FAIL_ON_WARNINGS )
Expand Down
4 changes: 2 additions & 2 deletions core/include/traccc/definitions/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ template <typename scalar_t>
using unit = detray::unit<scalar_t>;

// epsilon for float variables
constexpr scalar float_epsilon = 1e-5;
constexpr scalar float_epsilon = 1e-5f;

// pion mass for track parameter estimation
constexpr scalar PION_MASS_MEV = 139.57018 * unit<scalar>::MeV;
constexpr scalar PION_MASS_MEV = 139.57018f * unit<scalar>::MeV;

} // namespace traccc
46 changes: 23 additions & 23 deletions core/include/traccc/seeding/detail/seeding_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ struct seedfinder_config {
// limiting location of collision region in z
scalar collisionRegionMin = -250 * unit<scalar>::mm;
scalar collisionRegionMax = +250 * unit<scalar>::mm;
scalar phiMin = -M_PI;
scalar phiMax = M_PI;
scalar phiMin = static_cast<scalar>(-M_PI);
scalar phiMax = static_cast<scalar>(M_PI);

// Seed Cuts
// lower cutoff for seeds in MeV
scalar minPt = 500. * unit<scalar>::MeV;
scalar minPt = 500.f * unit<scalar>::MeV;
// cot of maximum theta angle
// equivalent to 2.7 eta (pseudorapidity)
scalar cotThetaMax = 7.40627;
scalar cotThetaMax = 7.40627f;
// minimum distance in mm in r between two measurements within one seed
scalar deltaRMin = 1 * unit<scalar>::mm;
// maximum distance in mm in r between two measurements within one seed
Expand All @@ -68,7 +68,7 @@ struct seedfinder_config {
// for how many seeds can one SpacePoint be the middle SpacePoint?
int maxSeedsPerSpM = 20;

scalar bFieldInZ = 1.99724 * unit<scalar>::T;
scalar bFieldInZ = 1.99724f * unit<scalar>::T;
// location of beam in x,y plane.
// used as offset for Space Points
vector2 beamPos{-.0 * unit<scalar>::mm, -.0 * unit<scalar>::mm};
Expand All @@ -77,7 +77,7 @@ struct seedfinder_config {
// scattering.
// default is 5%
// TODO: necessary to make amount of material dependent on detector region?
scalar radLengthPerSeed = 0.05;
scalar radLengthPerSeed = 0.05f;
// alignment uncertainties, used for uncertainties in the
// non-measurement-plane of the modules
// which otherwise would be 0
Expand Down Expand Up @@ -121,19 +121,19 @@ struct seedfinder_config {
// Configure unset parameters
TRACCC_HOST_DEVICE
void setup() {
highland = 13.6 * traccc::unit<traccc::scalar>::MeV *
highland = 13.6f * traccc::unit<traccc::scalar>::MeV *
std::sqrt(radLengthPerSeed) *
(1 + 0.038 * std::log(radLengthPerSeed));
(1.f + 0.038f * std::log(radLengthPerSeed));

float maxScatteringAngle = highland / minPt;
maxScatteringAngle2 = maxScatteringAngle * maxScatteringAngle;

pTPerHelixRadius = bFieldInZ;
minHelixDiameter2 = std::pow(minPt * 2 / pTPerHelixRadius, 2);
minHelixDiameter2 = std::pow(minPt * 2.f / pTPerHelixRadius, 2.f);

// @TODO: This is definitely a bug because highland / pTPerHelixRadius
// is in length unit
pT2perRadius = std::pow(highland / pTPerHelixRadius, 2);
pT2perRadius = std::pow(highland / pTPerHelixRadius, 2.f);
}
};

Expand Down Expand Up @@ -175,9 +175,9 @@ struct spacepoint_grid_config {
// impact parameter in mm
scalar impactMax;
// minimum phi value for phiAxis construction
scalar phiMin = -M_PI;
scalar phiMin = static_cast<scalar>(-M_PI);
// maximum phi value for phiAxis construction
scalar phiMax = M_PI;
scalar phiMax = static_cast<scalar>(M_PI);
// Multiplicator for the number of phi-bins. The minimum number of phi-bins
// depends on min_pt, magnetic field: 2*M_PI/(minPT particle
// phi-deflection). phiBinDeflectionCoverage is a multiplier for this
Expand All @@ -190,15 +190,15 @@ struct spacepoint_grid_config {
struct seedfilter_config {
// the allowed delta between two inverted seed radii for them to be
// considered compatible.
scalar deltaInvHelixDiameter = 0.00003 / unit<scalar>::mm;
scalar deltaInvHelixDiameter = 0.00003f / unit<scalar>::mm;
// the impact parameters (d0) is multiplied by this factor and subtracted
// from weight
scalar impactWeightFactor = 1.;
scalar impactWeightFactor = 1.f;
// seed weight increased by this value if a compatible seed has been found.
scalar compatSeedWeight = 200.;
scalar compatSeedWeight = 200.f;
// minimum distance between compatible seeds to be considered for weight
// boost
scalar deltaRMin = 5. * unit<scalar>::mm;
scalar deltaRMin = 5.f * unit<scalar>::mm;
// in dense environments many seeds may be found per middle space point.
// only seeds with the highest weight will be kept if this limit is reached.
unsigned int maxSeedsPerSpM = 20;
Expand All @@ -210,17 +210,17 @@ struct seedfilter_config {
size_t max_triplets_per_spM = 5;

// seed weight increase
scalar good_spB_min_radius = 150. * unit<scalar>::mm;
scalar good_spB_weight_increase = 400.;
scalar good_spT_max_radius = 150. * unit<scalar>::mm;
scalar good_spT_weight_increase = 200.;
scalar good_spB_min_radius = 150.f * unit<scalar>::mm;
scalar good_spB_weight_increase = 400.f;
scalar good_spT_max_radius = 150.f * unit<scalar>::mm;
scalar good_spT_weight_increase = 200.f;

// bottom sp cut
scalar good_spB_min_weight = 380;
scalar good_spB_min_weight = 380.f;

// seed cut
scalar seed_min_weight = 200;
scalar spB_min_radius = 43. * unit<scalar>::mm;
scalar seed_min_weight = 200.f;
scalar spB_min_radius = 43.f * unit<scalar>::mm;
};

} // namespace traccc
6 changes: 3 additions & 3 deletions core/include/traccc/seeding/spacepoint_binning_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ inline std::pair<detray::axis2::circular<>, detray::axis2::regular<>> get_axes(

// divide 2pi by angle delta to get number of phi-bins
// size is always 2pi even for regions of interest
phiBins = std::ceil(2 * M_PI / deltaPhi);
phiBins = std::llround(2 * M_PI / deltaPhi + 0.5);
// need to scale the number of phi bins accordingly to the number of
// consecutive phi bins in the seed making step.
// Each individual bin should be approximately a fraction (depending on
Expand Down Expand Up @@ -116,8 +116,8 @@ inline TRACCC_HOST_DEVICE size_t is_valid_sp(const seedfinder_config& config,
if (spPhi > config.phiMax || spPhi < config.phiMin) {
return detray::detail::invalid_value<size_t>();
}
size_t r_index = getter::perp(
vector2{sp.x() - config.beamPos[0], sp.y() - config.beamPos[1]});
size_t r_index = static_cast<size_t>(getter::perp(
vector2{sp.x() - config.beamPos[0], sp.y() - config.beamPos[1]}));

if (r_index < config.get_num_rbins()) {
return r_index;
Expand Down
12 changes: 6 additions & 6 deletions core/include/traccc/seeding/track_params_estimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class track_params_estimation
const spacepoint_collection_types::host& spacepoints,
const seed_collection_types::host& seeds, const vector3& bfield,
const std::array<traccc::scalar, traccc::e_bound_size>& stddev = {
0.02 * detray::unit<traccc::scalar>::mm,
0.03 * detray::unit<traccc::scalar>::mm,
1. * detray::unit<traccc::scalar>::degree,
1. * detray::unit<traccc::scalar>::degree,
0.01 / detray::unit<traccc::scalar>::GeV,
1 * detray::unit<traccc::scalar>::ns}) const override;
0.02f * detray::unit<traccc::scalar>::mm,
0.03f * detray::unit<traccc::scalar>::mm,
1.f * detray::unit<traccc::scalar>::degree,
1.f * detray::unit<traccc::scalar>::degree,
0.01f / detray::unit<traccc::scalar>::GeV,
1.f * detray::unit<traccc::scalar>::ns}) const override;

private:
/// The memory resource to use in the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// System include
#include <algorithm>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
Expand Down Expand Up @@ -245,11 +246,12 @@ void greedy_ambiguity_resolution_algorithm::compute_initial_state(
double ratio = static_cast<float>(mcount_idzero) /
static_cast<float>(mcount_all);
if (ratio > warning_threshold) {
std::size_t percent = ratio * 100;
LOG_WARN(std::to_string(percent) +
"% of input measurements have an ID equal to 0 "
"(measurement.measurement_id == 0). This may be "
"suspicious.");
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << (ratio * 100.)
<< "% of input measurements have an ID equal to 0 "
"(measurement.measurement_id == 0). This may be "
"suspicious.";
LOG_WARN(stream.str());
}
}
}
Expand Down
45 changes: 25 additions & 20 deletions core/src/seeding/seed_filtering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,31 @@ void seed_filtering::operator()(
}

// sort seeds based on their weights
std::sort(seeds_per_spM.begin(), seeds_per_spM.end(),
[&](seed& seed1, seed& seed2) {
if (seed1.weight != seed2.weight) {
return seed1.weight > seed2.weight;
} else {
scalar seed1_sum = 0;
scalar seed2_sum = 0;
auto& spB1 = sp_collection.at(seed1.spB_link);
auto& spT1 = sp_collection.at(seed1.spT_link);
auto& spB2 = sp_collection.at(seed2.spB_link);
auto& spT2 = sp_collection.at(seed2.spT_link);

seed1_sum += pow(spB1.y(), 2) + pow(spB1.z(), 2);
seed1_sum += pow(spT1.y(), 2) + pow(spT1.z(), 2);
seed2_sum += pow(spB2.y(), 2) + pow(spB2.z(), 2);
seed2_sum += pow(spT2.y(), 2) + pow(spT2.z(), 2);

return seed1_sum > seed2_sum;
}
});
std::sort(
seeds_per_spM.begin(), seeds_per_spM.end(),
[&](seed& seed1, seed& seed2) {
if (seed1.weight != seed2.weight) {
return seed1.weight > seed2.weight;
} else {
scalar seed1_sum = 0;
scalar seed2_sum = 0;
auto& spB1 = sp_collection.at(seed1.spB_link);
auto& spT1 = sp_collection.at(seed1.spT_link);
auto& spB2 = sp_collection.at(seed2.spB_link);
auto& spT2 = sp_collection.at(seed2.spT_link);

seed1_sum +=
static_cast<scalar>(pow(spB1.y(), 2) + pow(spB1.z(), 2));
seed1_sum +=
static_cast<scalar>(pow(spT1.y(), 2) + pow(spT1.z(), 2));
seed2_sum +=
static_cast<scalar>(pow(spB2.y(), 2) + pow(spB2.z(), 2));
seed2_sum +=
static_cast<scalar>(pow(spT2.y(), 2) + pow(spT2.z(), 2));

return seed1_sum > seed2_sum;
}
});

seed_collection_types::host new_seeds;
if (seeds_per_spM.size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ struct track_params_estimation
const seed_collection_types::const_view& seeds_view,
const vector3& bfield,
const std::array<traccc::scalar, traccc::e_bound_size>& = {
0.02 * detray::unit<traccc::scalar>::mm,
0.03 * detray::unit<traccc::scalar>::mm,
1. * detray::unit<traccc::scalar>::degree,
1. * detray::unit<traccc::scalar>::degree,
0.01 / detray::unit<traccc::scalar>::GeV,
1 * detray::unit<traccc::scalar>::ns}) const override;
0.02f * detray::unit<traccc::scalar>::mm,
0.03f * detray::unit<traccc::scalar>::mm,
1.f * detray::unit<traccc::scalar>::degree,
1.f * detray::unit<traccc::scalar>::degree,
0.01f / detray::unit<traccc::scalar>::GeV,
1.f * detray::unit<traccc::scalar>::ns}) const override;

private:
/// Memory resource used by the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ struct track_params_estimation
const seed_collection_types::const_view& seeds_view,
const vector3& bfield,
const std::array<traccc::scalar, traccc::e_bound_size>& = {
0.02 * detray::unit<traccc::scalar>::mm,
0.03 * detray::unit<traccc::scalar>::mm,
1. * detray::unit<traccc::scalar>::degree,
1. * detray::unit<traccc::scalar>::degree,
0.01 / detray::unit<traccc::scalar>::GeV,
1 * detray::unit<traccc::scalar>::ns}) const override;
0.02f * detray::unit<traccc::scalar>::mm,
0.03f * detray::unit<traccc::scalar>::mm,
1.f * detray::unit<traccc::scalar>::degree,
1.f * detray::unit<traccc::scalar>::degree,
0.01f / detray::unit<traccc::scalar>::GeV,
1.f * detray::unit<traccc::scalar>::ns}) const override;

private:
/// Memory resource used by the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ struct track_params_estimation
const seed_collection_types::const_view& seeds_view,
const vector3& bfield,
const std::array<traccc::scalar, traccc::e_bound_size>& stddev = {
0.02 * detray::unit<traccc::scalar>::mm,
0.03 * detray::unit<traccc::scalar>::mm,
1. * detray::unit<traccc::scalar>::degree,
1. * detray::unit<traccc::scalar>::degree,
0.01 / detray::unit<traccc::scalar>::GeV,
1 * detray::unit<traccc::scalar>::ns}) const override;
0.02f * detray::unit<traccc::scalar>::mm,
0.03f * detray::unit<traccc::scalar>::mm,
1.f * detray::unit<traccc::scalar>::degree,
1.f * detray::unit<traccc::scalar>::degree,
0.01f / detray::unit<traccc::scalar>::GeV,
1.f * detray::unit<traccc::scalar>::ns}) const override;

private:
// Private member variables
Expand Down
2 changes: 1 addition & 1 deletion examples/options/src/track_propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ track_propagation::track_propagation()
"Size of the grid surface search window");
m_desc.add_options()(
"rk-tolerance",
po::value(&(config.stepping.rk_error_tol))->default_value(1e-4),
po::value(&(config.stepping.rk_error_tol))->default_value(1e-4f),
"The Runge-Kutta stepper tolerance");
}

Expand Down
12 changes: 6 additions & 6 deletions examples/run/cpu/truth_finding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ int seq_run(const traccc::opts::track_finding& finding_opts,

// Standard deviations for seed track parameters
static constexpr std::array<traccc::scalar, traccc::e_bound_size> stddevs =
{1e-4 * detray::unit<traccc::scalar>::mm,
1e-4 * detray::unit<traccc::scalar>::mm,
1e-3,
1e-3,
1e-4 / detray::unit<traccc::scalar>::GeV,
1e-4 * detray::unit<traccc::scalar>::ns};
{1e-4f * detray::unit<traccc::scalar>::mm,
1e-4f * detray::unit<traccc::scalar>::mm,
1e-3f,
1e-3f,
1e-4f / detray::unit<traccc::scalar>::GeV,
1e-4f * detray::unit<traccc::scalar>::ns};

// Propagation configuration
detray::propagation::config propagation_config(propagation_opts);
Expand Down
12 changes: 6 additions & 6 deletions examples/run/cpu/truth_fitting_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ int main(int argc, char* argv[]) {

/// Standard deviations for seed track parameters
static constexpr std::array<scalar, e_bound_size> stddevs = {
0.03 * detray::unit<scalar>::mm,
0.03 * detray::unit<scalar>::mm,
0.017,
0.017,
0.01 / detray::unit<scalar>::GeV,
1 * detray::unit<scalar>::ns};
0.03f * detray::unit<scalar>::mm,
0.03f * detray::unit<scalar>::mm,
0.017f,
0.017f,
0.01f / detray::unit<scalar>::GeV,
1.f * detray::unit<scalar>::ns};

// Fitting algorithm object
typename traccc::fitting_algorithm<host_fitter_type>::config_type fit_cfg;
Expand Down
12 changes: 6 additions & 6 deletions examples/run/cuda/truth_finding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ int seq_run(const traccc::opts::track_finding& finding_opts,

// Standard deviations for seed track parameters
static constexpr std::array<traccc::scalar, traccc::e_bound_size> stddevs =
{1e-4 * detray::unit<traccc::scalar>::mm,
1e-4 * detray::unit<traccc::scalar>::mm,
1e-3,
1e-3,
1e-4 / detray::unit<traccc::scalar>::GeV,
1e-4 * detray::unit<traccc::scalar>::ns};
{1e-4f * detray::unit<traccc::scalar>::mm,
1e-4f * detray::unit<traccc::scalar>::mm,
1e-3f,
1e-3f,
1e-4f / detray::unit<traccc::scalar>::GeV,
1e-4f * detray::unit<traccc::scalar>::ns};

// Propagation configuration
detray::propagation::config propagation_config(propagation_opts);
Expand Down
12 changes: 6 additions & 6 deletions examples/run/cuda/truth_fitting_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ int main(int argc, char* argv[]) {

/// Standard deviations for seed track parameters
static constexpr std::array<scalar, e_bound_size> stddevs = {
0.03 * detray::unit<scalar>::mm,
0.03 * detray::unit<scalar>::mm,
0.017,
0.017,
0.01 / detray::unit<scalar>::GeV,
1 * detray::unit<scalar>::ns};
0.03f * detray::unit<scalar>::mm,
0.03f * detray::unit<scalar>::mm,
0.017f,
0.017f,
0.01f / detray::unit<scalar>::GeV,
1.f * detray::unit<scalar>::ns};

// Fitting algorithm object
typename traccc::fitting_algorithm<host_fitter_type>::config_type fit_cfg;
Expand Down
Loading
Loading