Skip to content

Commit

Permalink
Merge branch 'acts-project:main' into gx2f-python
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger authored Oct 6, 2023
2 parents 1ec445f + 577c162 commit d451eb1
Show file tree
Hide file tree
Showing 29 changed files with 1,762 additions and 32 deletions.
17 changes: 17 additions & 0 deletions CI/physmon/phys_perf_mon.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

set -e
set -x


mode=${1:all}
Expand Down Expand Up @@ -296,6 +297,22 @@ if [[ "$mode" == "all" || "$mode" == "fullchains" ]]; then
--config CI/physmon/vertexing_config.yml
ec=$(($ec | $?))

Examples/Scripts/generic_plotter.py \
$outdir/tracksummary_ckf_ttbar.root \
tracksummary \
$outdir/tracksummary_ckf_ttbar_hist.root \
--config CI/physmon/tracksummary_ckf_config.yml
ec=$(($ec | $?))

# remove ntuple file because it's large
rm $outdir/tracksummary_ckf_ttbar.root

run_histcmp \
$outdir/tracksummary_ckf_ttbar_hist.root \
$refdir/tracksummary_ckf_ttbar_hist.root \
"Track Summary CKF ttbar" \
tracksummary_ckf_ttbar

# remove ntuple file because it's large
rm $outdir/performance_amvf_ttbar.root

Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions Core/include/Acts/EventData/ParticleHypothesis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class NonNeutralChargedParticleHypothesis
pion().mass(), absQ);
}

static NonNeutralChargedParticleHypothesis chargedGeantino() {
return chargedGeantino(Acts::UnitConstants::e);
}
static NonNeutralChargedParticleHypothesis chargedGeantino(float absQ) {
return NonNeutralChargedParticleHypothesis(PdgParticle::eInvalid, 0, absQ);
}
Expand Down Expand Up @@ -154,6 +157,9 @@ class ParticleHypothesis : public GenericParticleHypothesis<AnyCharge> {
static ParticleHypothesis geantino() {
return NeutralParticleHypothesis::geantino();
}
static ParticleHypothesis chargedGeantino() {
return chargedGeantino(Acts::UnitConstants::e);
}
static ParticleHypothesis chargedGeantino(float absQ) {
return ParticleHypothesis(PdgParticle::eInvalid, 0, absQ);
}
Expand Down
9 changes: 9 additions & 0 deletions Core/src/Geometry/CylinderVolumeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ Acts::CylinderVolumeBuilder::trackingVolume(
wConfig.cVolumeConfig = analyzeContent(gctx, centralLayers, centralVolumes);
wConfig.pVolumeConfig = analyzeContent(gctx, positiveLayers, {}); // TODO

bool hasLayers = wConfig.nVolumeConfig.present ||
wConfig.cVolumeConfig.present ||
wConfig.pVolumeConfig.present;

if (!hasLayers) {
ACTS_INFO("No layers present, returning nullptr");
return nullptr;
}

std::string layerConfiguration = "|";
if (wConfig.nVolumeConfig) {
// negative layers are present
Expand Down
9 changes: 8 additions & 1 deletion Core/src/Geometry/TrackingGeometryBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ Acts::TrackingGeometryBuilder::trackingGeometry(
for (auto& volumeBuilder : m_cfg.trackingVolumeBuilders) {
// assign a new highest volume (and potentially wrap around the given
// highest volume so far)
highestVolume = volumeBuilder(gctx, highestVolume, nullptr);
auto volume = volumeBuilder(gctx, highestVolume, nullptr);
if (!volume) {
ACTS_INFO(
"Received nullptr volume from builder, keeping previous highest "
"volume");
} else {
highestVolume = std::move(volume);
}
}

// create the TrackingGeometry & decorate it with the material
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Geant4Handle {
/// Set logging consistently across common Geant4 modules
///
/// Convenience method which calls into Geant4Manager
void tweekLogging(int level) const;
void tweakLogging(int level) const;
};

/// Allows easy instantiation of a Geant4Handle object
Expand All @@ -61,7 +61,9 @@ class Geant4Manager {
static Geant4Manager &instance();

/// Set logging consistently across common Geant4 modules
static void tweekLogging(G4RunManager &runManager, int level);
static void tweakLogging(G4RunManager &runManager, int level);

std::shared_ptr<Geant4Handle> currentHandle() const;

/// This can only be called once due to Geant4 limitations
std::shared_ptr<Geant4Handle> createHandle(int logLevel,
Expand Down
10 changes: 7 additions & 3 deletions Examples/Algorithms/Geant4/src/Geant4Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ Geant4Handle::Geant4Handle(int _logLevel,

Geant4Handle::~Geant4Handle() = default;

void Geant4Handle::tweekLogging(int level) const {
Geant4Manager::tweekLogging(*runManager, level);
void Geant4Handle::tweakLogging(int level) const {
Geant4Manager::tweakLogging(*runManager, level);
}

Geant4Manager& Geant4Manager::instance() {
static Geant4Manager manager;
return manager;
}

void Geant4Manager::tweekLogging(G4RunManager& runManager, int level) {
void Geant4Manager::tweakLogging(G4RunManager& runManager, int level) {
runManager.SetVerboseLevel(level);
G4EventManager::GetEventManager()->SetVerboseLevel(level);
G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(
Expand All @@ -77,6 +77,10 @@ void Geant4Manager::tweekLogging(G4RunManager& runManager, int level) {
#endif
}

std::shared_ptr<Geant4Handle> Geant4Manager::currentHandle() const {
return m_handle.lock();
}

std::shared_ptr<Geant4Handle> Geant4Manager::createHandle(
int logLevel, const std::string& physicsList) {
return createHandle(logLevel, createPhysicsList(physicsList), physicsList);
Expand Down
17 changes: 14 additions & 3 deletions Examples/Python/src/EventData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ void addEventData(Context& ctx) {
[](py::object /* self */) {
return Acts::ParticleHypothesis::pion();
})
.def_property_readonly_static("electron", [](py::object /* self */) {
return Acts::ParticleHypothesis::electron();
});
.def_property_readonly_static(
"electron",
[](py::object /* self */) {
return Acts::ParticleHypothesis::electron();
})
.def_property_readonly_static(
"geantino",
[](py::object /* self */) {
return Acts::ParticleHypothesis::geantino();
})
.def_property_readonly_static(
"chargedGeantino", [](py::object /* self */) {
return Acts::ParticleHypothesis::chargedGeantino();
});
}

} // namespace Acts::Python
9 changes: 8 additions & 1 deletion Examples/Python/src/Geant4Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ PYBIND11_MODULE(ActsPythonBindingsGeant4, mod) {
std::shared_ptr<DetectorConstructionFactory>>(
mod, "DetectorConstructionFactory");

py::class_<Geant4Handle, std::shared_ptr<Geant4Handle>>(mod, "Geant4Handle");
py::class_<Geant4Manager, std::unique_ptr<Geant4Manager, py::nodelete>>(
mod, "Geant4Manager")
.def_static("instance", &Geant4Manager::instance,
py::return_value_policy::reference)
.def("currentHandle", &Geant4Manager::currentHandle);

py::class_<Geant4Handle, std::shared_ptr<Geant4Handle>>(mod, "Geant4Handle")
.def("tweakLogging", &Geant4Handle::tweakLogging);

{
using Algorithm = Geant4SimulationBase;
Expand Down
3 changes: 2 additions & 1 deletion Plugins/DD4hep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ include(FetchContent)
add_library(
ActsPluginDD4hep SHARED
src/ConvertDD4hepDetector.cpp
src/ConvertDD4hepMaterial.cpp
src/DD4hepMaterialHelpers.cpp
src/DD4hepDetectorElement.cpp
src/DD4hepDetectorSurfaceFactory.cpp
src/DD4hepLayerBuilder.cpp
src/DD4hepVolumeBuilder.cpp)
target_include_directories(
Expand Down
166 changes: 166 additions & 0 deletions Plugins/DD4hep/include/Acts/Plugins/DD4hep/DD4hepBinningHelpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Definitions/Units.hpp"
#include "Acts/Detector/ProtoBinning.hpp"
#include "Acts/Plugins/DD4hep/DD4hepConversionHelpers.hpp"
#include "Acts/Utilities/BinningData.hpp"
#include "Acts/Utilities/detail/AxisFwd.hpp"

#include <string>
#include <tuple>
#include <vector>

#include <DD4hep/DD4hepUnits.h>
#include <DD4hep/DetElement.h>
#include <DD4hep/DetFactoryHelper.h>
#include <DD4hep/Objects.h>
#include <DDRec/DetectorData.h>
#include <XML/Utilities.h>

namespace Acts {

static std::vector<std::tuple<std::string, BinningValue>> allowedBinnings = {
{"x", binX}, {"y", binY}, {"z", binZ}, {"phi", binPhi}, {"r", binR}};

/// Helper method to decode the binning from what would appear in the
/// xml into variant parameters, such that it can be understood in the
/// downstream processing.
///
/// This parses the dediced \< surface_binning \> tag
/// - allowed/understood binnings are x,y,z,phi,r
/// - allowed/unserstood types are equidistant/variable (those are
/// auto-detected)
///
/// Example for e.g. bname = \"surface_binning\":
///
/// - Equidistant binning in r and phi:
/// \< surface_binning nr=\"2\" rmin=\"25\" rmax=\"100\" nphi=\"22\"
/// phimin=\"-3.1415\" phimax=\"3.1415\" \/ \>
/// - Variable binning in z:
/// \< surface_binning zboundaries=\"-100,-90,90,100\" \/ \>
///
/// And 2D combinations of this are allowed.
///
/// @param variantParams [in,out] the variant parameters that will be overwritten
/// @param xmlBinning the surface binning
/// @param bname the binning base name, e.g. surface_binning, material_binning
/// @param bvals the boundary values, i.e. x,y,z,phi,r
///
void decodeBinning(dd4hep::rec::VariantParameters &variantParams,
const xml_comp_t &xmlBinning, const std::string &bname,
const std::vector<std::string> &bvals) {
// Set the surface binninng parameter to true
variantParams.set<int>(std::string(bname + "_dim"), bvals.size());
for (const auto &bv : bvals) {
// Gather the number of bins, 0 indicates variable binning
int nBins = Acts::getAttrValueOr<int>(xmlBinning, std::string("n" + bv), 0);
// Gather the bin expansion parameter, expansion of 0 is default
int nExpansion =
Acts::getAttrValueOr<int>(xmlBinning, std::string(bv + "expansion"), 0);
variantParams.set<int>(bname + "_" + bv + "_exp", nExpansion);
// Equidistant binning detected
if (nBins > 0) {
// Set the type identificatio
variantParams.set<std::string>(bname + "_" + bv + "_type", "equidistant");
// Set the number of bins
variantParams.set<int>(bname + "_" + bv + "_n", nBins);
// Set min/max paraeter
variantParams.set<double>(
bname + "_" + bv + "_min",
xmlBinning.attr<double>(std::string(bv + "min").c_str()));
variantParams.set<double>(
bname + "_" + bv + "_max",
xmlBinning.attr<double>(std::string(bv + "max").c_str()));
} else {
// Variable binning detected
variantParams.set<std::string>(bname + "_" + bv + "_type", "variable");
// Get the number of bins explicitly
auto boundaries =
xmlBinning.attr<std::string>(std::string(bv + "boundaries").c_str());
std::string del = ",";
int end = boundaries.find(del);
int ib = 0;
// Unit conversion
double unitScalar = 1.;
if (bv != "phi") {
unitScalar = Acts::UnitConstants::mm / dd4hep::millimeter;
}
// Split and convert
while (end != -1) {
double bR = unitScalar * dd4hep::_toFloat(boundaries.substr(0, end));
variantParams.set<double>(
bname + "_" + bv + "_b" + std::to_string(ib++), bR);
boundaries.erase(boundaries.begin(), boundaries.begin() + end + 1);
end = boundaries.find(del);
}
double bR = unitScalar * std::stod(boundaries.substr(0, end));
variantParams.set<double>(bname + "_" + bv + "_b" + std::to_string(ib),
bR);
// The number of bins are needed to unpack the data
variantParams.set<int>(bname + "_" + bv + "_n", ib);
}
}
}

/// @brief This method converts the DD4hep binning into the Acts ProtoBinning
///
/// @param dd4hepElement the element which has a binning description attached
/// @param bname the binning base name, e.g. surface_binning, material_binning
///
/// @return a vector of proto binning descriptions
std::vector<Acts::Experimental::ProtoBinning> convertBinning(
const dd4hep::DetElement &dd4hepElement, const std::string &bname) {
std::vector<Experimental::ProtoBinning> protoBinnings;
for (const auto &[ab, bVal] : allowedBinnings) {
auto type =
getParamOr<std::string>(bname + "_" + ab + "_type", dd4hepElement, "");
if (not type.empty()) {
// Default binning is bound
auto bType = Acts::detail::AxisBoundaryType::Bound;
// Equidistant or variable binning
detail::AxisType aType = type == "equidistant"
? detail::AxisType::Equidistant
: detail::AxisType::Variable;
int nBins = getParamOr<int>(bname + "_" + ab + "_n", dd4hepElement, 0);
int nExpansion =
getParamOr<int>(bname + "_" + ab + "_exp", dd4hepElement, 0);
if (aType == detail::AxisType::Equidistant) {
// Equidistant binning
auto min = getParamOr<ActsScalar>(bname + "_" + ab + "_min",
dd4hepElement, 0.);
auto max = getParamOr<ActsScalar>(bname + "_" + ab + "_max",
dd4hepElement, 0.);
// Check for closed phi binning
if (bVal == binPhi and (max - min) > 1.9 * M_PI) {
bType = Acts::detail::AxisBoundaryType::Closed;
}
protoBinnings.push_back(Experimental::ProtoBinning(
bVal, bType, min, max, nBins, nExpansion));
} else {
// Variable binning
std::vector<ActsScalar> edges;
for (int ib = 0; ib <= nBins; ++ib) {
edges.push_back(getParamOr<ActsScalar>(
bname + "_" + ab + "_b" + std::to_string(ib), dd4hepElement, 0.));
}
// Check for closed phi binning
if (bVal == binPhi and (edges.back() - edges.front()) > 1.9 * M_PI) {
bType = Acts::detail::AxisBoundaryType::Closed;
}
protoBinnings.push_back(
Experimental::ProtoBinning(bVal, bType, edges, nExpansion));
}
}
}
return protoBinnings;
}

} // namespace Acts
Loading

0 comments on commit d451eb1

Please sign in to comment.