Skip to content

Commit

Permalink
Merge branch 'main' into fix-g4-detector-with-fatras
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger authored Feb 23, 2023
2 parents 2246163 + 0d9f51b commit fc94972
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ auto kalmanHandleMeasurement(
} else {
ACTS_VERBOSE(
"Filtering step successful. But measurement is determined "
"to "
"be an outlier. Stepping state is not updated.")
"to be an outlier. Stepping state is not updated.")
// Set the outlier type flag
typeFlags.set(TrackStateFlag::OutlierFlag);
trackStateProxy.shareFrom(trackStateProxy, TrackStatePropMask::Predicted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ActsExamples::ProcessCode ActsExamples::ParticleSmearing::execute(

ACTS_VERBOSE("Smearing particle (pos, time, phi, theta, q/p):");
ACTS_VERBOSE(" from: " << particle.position().transpose() << ", " << time
<< "," << phi << "," << theta << ","
<< ", " << phi << ", " << theta << ", "
<< (q != 0 ? q / p : 1 / p));
ACTS_VERBOSE(" to: " << perigee
->localToGlobal(
Expand All @@ -96,9 +96,9 @@ ActsExamples::ProcessCode ActsExamples::ParticleSmearing::execute(
params[Acts::eBoundLoc1]},
particle.unitDirection() * p)
.transpose()
<< ", " << params[Acts::eBoundTime] << ","
<< params[Acts::eBoundPhi] << ","
<< params[Acts::eBoundTheta] << ","
<< ", " << params[Acts::eBoundTime] << ", "
<< params[Acts::eBoundPhi] << ", "
<< params[Acts::eBoundTheta] << ", "
<< params[Acts::eBoundQOverP]);

// build the track covariance matrix using the smearing sigmas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GenericDetectorElement : public Acts::IdentifiedDetectorElement {
/// Identifier
Identifier identifier() const final;

/// Return local to global transform associated with this identifier
/// Return local to global transform associated with this detector element
///
/// @param gctx The current geometry context object, e.g. alignment
///
Expand All @@ -80,7 +80,7 @@ class GenericDetectorElement : public Acts::IdentifiedDetectorElement {
const Acts::Transform3& transform(
const Acts::GeometryContext& gctx) const override;

/// Return surface associated with this identifier,
/// Return surface associated with this detector element
const Acts::Surface& surface() const override;

/// Set the identifier after construction (sometimes needed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,12 @@ class RootMeasurementWriter final : public WriterT<MeasurementContainer> {

Acts::BoundSymMatrix fullVar =
m.expander() * m.covariance() * m.expander().transpose();
varBound[Acts::eBoundLoc0] =
std::sqrt(fullVar(Acts::eBoundLoc0, Acts::eBoundLoc0));
varBound[Acts::eBoundLoc1] =
std::sqrt(fullVar(Acts::eBoundLoc1, Acts::eBoundLoc1));
varBound[Acts::eBoundPhi] =
std::sqrt(fullVar(Acts::eBoundPhi, Acts::eBoundPhi));
varBound[Acts::eBoundLoc0] = fullVar(Acts::eBoundLoc0, Acts::eBoundLoc0);
varBound[Acts::eBoundLoc1] = fullVar(Acts::eBoundLoc1, Acts::eBoundLoc1);
varBound[Acts::eBoundPhi] = fullVar(Acts::eBoundPhi, Acts::eBoundPhi);
varBound[Acts::eBoundTheta] =
std::sqrt(fullVar(Acts::eBoundTheta, Acts::eBoundTheta));
varBound[Acts::eBoundTime] =
std::sqrt(fullVar(Acts::eBoundTime, Acts::eBoundTime));
fullVar(Acts::eBoundTheta, Acts::eBoundTheta);
varBound[Acts::eBoundTime] = fullVar(Acts::eBoundTime, Acts::eBoundTime);
}

/// Convenience function to fill the cluster information
Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/python/acts/examples/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def addGeant4(
the output folder for the Root output, None triggers no output
"""

from acts.examples.geant4 import Geant4Simulation, geant4SimulationConfig
from acts.examples.geant4 import Geant4Simulation, makeGeant4SimulationConfig

customLogLevel = acts.examples.defaultLogging(s, logLevel)

Expand All @@ -600,9 +600,10 @@ def addGeant4(
raise AttributeError("detector not given")
g4detectorConstruction = getG4DetectorContruction(detector)

g4conf = geant4SimulationConfig(
g4conf = makeGeant4SimulationConfig(
level=customLogLevel(),
detector=g4detectorConstruction,
randomNumbers=rnd,
inputParticles=particles_selected,
trackingGeometry=trackingGeometry,
magneticField=field,
Expand All @@ -612,7 +613,6 @@ def addGeant4(
g4conf.outputSimHits = "simhits"
g4conf.outputParticlesInitial = "particles_initial"
g4conf.outputParticlesFinal = "particles_final"
g4conf.randomNumbers = rnd

# Simulation
alg = Geant4Simulation(
Expand Down
139 changes: 63 additions & 76 deletions Examples/Python/src/Geant4Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,106 +81,93 @@ PYBIND11_MODULE(ActsPythonBindingsGeant4, mod) {
eventActions, trackingActions, steppingActions, detectorConstruction,
magneticField, sensitiveSurfaceMapper);

mod.def(
"materialRecordingConfig",
[](Acts::Logging::Level level, G4VUserDetectorConstruction* detector,
auto makeGeant4Config =
[](Acts::Logging::Level& level,
std::shared_ptr<const ActsExamples::RandomNumbers> randomNumbers,
const std::string& inputParticles,
const std::string& outputMaterialTracks) {
// The Geant4 actions needed
std::vector<G4UserRunAction*> runActions = {};
std::vector<G4UserEventAction*> eventActions = {};
std::vector<G4UserTrackingAction*> trackingActions = {};

// Set the main Geant4 algorithm, primary generation, detector
// construction
Geant4Simulation::Config g4Cfg;
g4Cfg.randomNumbers = std::move(randomNumbers);
g4Cfg.runManager = std::make_shared<G4RunManager>();
g4Cfg.runManager->SetUserInitialization(new MaterialPhysicsList(
Acts::getDefaultLogger("MaterialPhysicsList", level)));
G4VUserDetectorConstruction* detector, G4VUserPhysicsList* physicsList,
const SimParticleTranslation::Config& prCfg)
-> Geant4Simulation::Config {
Geant4Simulation::Config g4Cfg;

MaterialSteppingAction::Config mStepCfg;
mStepCfg.excludeMaterials = {"Air", "Vacuum"};
std::vector<G4UserSteppingAction*> steppingActions = {
new MaterialSteppingAction(
mStepCfg,
Acts::getDefaultLogger("MaterialSteppingAction", level))};
// Set the main Geant4 algorithm, primary generation, detector
// construction
g4Cfg.randomNumbers = std::move(randomNumbers);
g4Cfg.runManager = std::make_shared<G4RunManager>();
g4Cfg.runManager->SetUserInitialization(physicsList);

// Set the primarty generator
g4Cfg.primaryGeneratorAction = new SimParticleTranslation(
prCfg, Acts::getDefaultLogger("SimParticleTranslation", level));
g4Cfg.detectorConstruction = detector;

return g4Cfg;
};

mod.def(
"makeGeant4MaterialRecordingConfig",
[makeGeant4Config](
Acts::Logging::Level level, G4VUserDetectorConstruction* detector,
std::shared_ptr<const ActsExamples::RandomNumbers> randomNumbers,
const std::string& inputParticles,
const std::string& outputMaterialTracks) {
auto physicsList = new MaterialPhysicsList(
Acts::getDefaultLogger("MaterialPhysicsList", level));

// Read the particle from the generator
SimParticleTranslation::Config g4PrCfg;
g4PrCfg.inputParticles = inputParticles;
g4PrCfg.forceParticle = true;
g4PrCfg.forcedMass = 0.;
g4PrCfg.forcedPdgCode = 999;
// Set the material tracks at output
g4Cfg.outputMaterialTracks = outputMaterialTracks;

// Set the primarty generator
g4Cfg.primaryGeneratorAction = new SimParticleTranslation(
g4PrCfg, Acts::getDefaultLogger("SimParticleTranslation", level));
g4Cfg.detectorConstruction = detector;
auto g4Cfg = makeGeant4Config(level, std::move(randomNumbers), detector,
physicsList, g4PrCfg);

MaterialSteppingAction::Config mStepCfg;
mStepCfg.excludeMaterials = {"Air", "Vacuum"};
auto steppingAction = new MaterialSteppingAction(
mStepCfg, Acts::getDefaultLogger("MaterialSteppingAction", level));
g4Cfg.steppingActions = {steppingAction};

// Set the user actions
g4Cfg.runActions = runActions;
g4Cfg.eventActions = eventActions;
g4Cfg.trackingActions = trackingActions;
g4Cfg.steppingActions = steppingActions;
// Set the material tracks at output
g4Cfg.outputMaterialTracks = outputMaterialTracks;

return g4Cfg;
},
"level"_a, "detector"_a, "randomNumbers"_a, "inputParticles"_a,
"outputMaterialTracks"_a);

mod.def(
"geant4SimulationConfig",
[](Acts::Logging::Level& level, G4VUserDetectorConstruction* detector,
const std::string& inputParticles,
const std::shared_ptr<const Acts::TrackingGeometry>& trackingGeometry,
const std::shared_ptr<const Acts::MagneticFieldProvider>&
magneticField,
const std::vector<std::string>& volumeMappings,
const std::vector<std::string>& materialMappings) {
// The Geant4 actions needed
std::vector<G4UserRunAction*> runActions = {};
std::vector<G4UserEventAction*> eventActions = {};
std::vector<G4UserTrackingAction*> trackingActions = {};
std::vector<G4UserSteppingAction*> steppingActions = {};

// Set the main Geant4 algorithm, primary generation, detector
// construction
Geant4Simulation::Config g4Cfg;

g4Cfg.runManager = std::make_shared<G4RunManager>();
g4Cfg.runManager->SetUserInitialization(new FTFP_BERT());
"makeGeant4SimulationConfig",
[makeGeant4Config](
Acts::Logging::Level& level, G4VUserDetectorConstruction* detector,
std::shared_ptr<const ActsExamples::RandomNumbers> randomNumbers,
const std::string& inputParticles,
const std::shared_ptr<const Acts::TrackingGeometry>& trackingGeometry,
const std::shared_ptr<const Acts::MagneticFieldProvider>&
magneticField,
const std::vector<std::string>& volumeMappings,
const std::vector<std::string>& materialMappings) {
auto physicsList = new FTFP_BERT();

// Read the particle from the generator
SimParticleTranslation::Config g4PrCfg;
g4PrCfg.inputParticles = inputParticles;

auto g4Cfg = makeGeant4Config(level, std::move(randomNumbers), detector,
physicsList, g4PrCfg);

ParticleTrackingAction::Config g4TrackCfg;
ParticleTrackingAction* particleAction = new ParticleTrackingAction(
g4TrackCfg,
Acts::getDefaultLogger("ParticleTrackingAction", level));
trackingActions.push_back(particleAction);
g4Cfg.trackingActions.push_back(particleAction);

SensitiveSteppingAction::Config g4StepCfg;
SensitiveSteppingAction* sensitiveStepping =
new SensitiveSteppingAction(
g4StepCfg,
Acts::getDefaultLogger("SensitiveSteppingAction", level));
steppingActions.push_back(sensitiveStepping);

// Read the particle from the generator
SimParticleTranslation::Config g4PrCfg;
g4PrCfg.inputParticles = inputParticles;

// Set the primarty generator
g4Cfg.primaryGeneratorAction = new SimParticleTranslation(
g4PrCfg, Acts::getDefaultLogger("SimParticleTranslation", level));
g4Cfg.detectorConstruction = detector;

// Set the user actions
g4Cfg.runActions = runActions;
g4Cfg.eventActions = eventActions;
g4Cfg.trackingActions = trackingActions;
g4Cfg.steppingActions = steppingActions;
G4UserSteppingAction* steppingAction = new SensitiveSteppingAction(
g4StepCfg,
Acts::getDefaultLogger("SensitiveSteppingAction", level));
g4Cfg.steppingActions.push_back(steppingAction);

// An ACTS Magnetic field is provided
if (magneticField) {
Expand Down Expand Up @@ -211,7 +198,7 @@ PYBIND11_MODULE(ActsPythonBindingsGeant4, mod) {

return g4Cfg;
},
"level"_a, "detector"_a, "inputParticles"_a,
"level"_a, "detector"_a, "randomNumbers"_a, "inputParticles"_a,
py::arg("trackingGeometry") = nullptr, py::arg("magneticField") = nullptr,
py::arg("volumeMappings") = std::vector<std::string>{},
py::arg("materialMappings") = std::vector<std::string>{});
Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/tests/root_file_hashes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ test_material_mapping__material-map_tracks.root: 2d167433ac10e36e447c26ac9c35eff
test_material_mapping__propagation-material.root: 3015c064835f84f484f09df1a9a56ce8de471a10cce933952db4530969f905aa
test_volume_material_mapping__material-map-volume_tracks.root: 1941c8e6a910c9cfa56ad6df6d9cc8930170d6d4f6e56502cf4cdafda0ce91d1
test_volume_material_mapping__propagation-volume-material.root: 2e3d2685bce1fd75b1d022781e52bcdfd264d8e2fe6bebf05cc280ae78f3f7c6
test_digitization_example__measurements.root: d6fd33d3182bcd669049fe40d13bc7e80fb9009a3ffa964123460db21384a088
test_digitization_example__measurements.root: ae9968a05c14790ba57961a4151a7bdefcd50d38ca2434fbdb498c8e4f5f00c1
test_digitization_example_input__particles.root: b4f74e5a4d9d67d59a6ca7d0e9b42c727aa6baf04c2841bc2d64cc2c4eef8c02
test_digitization_example_input__measurements.root: 0786f3d1652ee1b464d73468f7bb7507d8b146cafa499b28005a32a87d4ab491
test_digitization_example_input__measurements.root: 8dd9e59d7e29a222adb9ee5218baac7e0b3861e3cb26b56889f27cc9e87d9539
test_ckf_tracks_example[generic-full_seeding]__trackstates_ckf.root: 0d5734c60cb1ecee2b830788c839d870d569e4f09e829d491d24eaa3ad679974
test_ckf_tracks_example[generic-full_seeding]__tracksummary_ckf.root: e387abb1764d7fe1d3ecc971129f0b8577a5b479da2a693a463a4655c7942448
test_ckf_tracks_example[generic-full_seeding]__performance_seeding_trees.root: 0d5a0f8d9539563efcca8779bba9c747f0a6f01c9789af41af843b4f0917e6e9
Expand Down Expand Up @@ -80,7 +80,7 @@ test_root_prop_step_writer[kwargsConstructor]__prop_steps.root: 810b1b94fa751128
test_root_particle_writer[configPosConstructor]__particles.root: cdda0a2cc454871b8a3c71aa48ac2e5f17263bde6ed195525b13f790b6b81bdc
test_root_particle_writer[configKwConstructor]__particles.root: cdda0a2cc454871b8a3c71aa48ac2e5f17263bde6ed195525b13f790b6b81bdc
test_root_particle_writer[kwargsConstructor]__particles.root: cdda0a2cc454871b8a3c71aa48ac2e5f17263bde6ed195525b13f790b6b81bdc
test_root_meas_writer__meas.root: 8058397a4165f98eb4fd381d799d19b21b342d67fc756ad0880a7b0d83b47720
test_root_meas_writer__meas.root: 86af06befdbda76ca9bfc8bba5a5971ed0ecf4fc1ace570c2c768d5d968e0742
test_root_simhits_writer[configPosConstructor]__meas.root: 2f1e5dcd0e2e1bf4c1799c6c9d440d3ba78917b92f81eddd2469cd16ddec965b
test_root_simhits_writer[configKwConstructor]__meas.root: 2f1e5dcd0e2e1bf4c1799c6c9d440d3ba78917b92f81eddd2469cd16ddec965b
test_root_simhits_writer[kwargsConstructor]__meas.root: 2f1e5dcd0e2e1bf4c1799c6c9d440d3ba78917b92f81eddd2469cd16ddec965b
Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/Python/material_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def runMaterialRecording(g4geo, outputDir, tracksPerEvent=10000, s=None):

s.addReader(evGen)

g4AlgCfg = acts.examples.geant4.materialRecordingConfig(
g4AlgCfg = acts.examples.geant4.makeGeant4MaterialRecordingConfig(
level=acts.logging.INFO,
detector=g4geo,
inputParticles=evGen.config.outputParticles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ int boundParamResolution(const std::string& inFile, const std::string& treeName,
pull_smt[vlID + paramNames.at(ipar)]->Fit("gaus", "q");
TF1* gauss =
pull_smt[vlID + paramNames.at(ipar)]->GetFunction("gaus");
gauss->SetLineColor(kGreen);
float mu = gauss->GetParameter(1);
float sigma = gauss->GetParameter(2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class TGeoDetectorElement : public IdentifiedDetectorElement {
/// @param gctx The current geometry context object, e.g. alignment
const Transform3& transform(const GeometryContext& gctx) const override;

/// Return surface associated with this identifier, which should come from the
/// Return surface associated with this detector element
const Surface& surface() const override;

/// Retrieve the DigitizationModule
Expand Down

0 comments on commit fc94972

Please sign in to comment.