Skip to content

Commit

Permalink
refactor: Always order by event number for ROOT input in Examples (ac…
Browse files Browse the repository at this point in the history
…ts-project#3046)

This is a pitfall when using multi-threading. I think we can afford sorting by default.

Also cleans out some IO code and renames the whiteboard prop names.
  • Loading branch information
andiwand authored and EleniXoch committed May 6, 2024
1 parent 03228ce commit 77a4e98
Show file tree
Hide file tree
Showing 32 changed files with 420 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
#include <utility>
#include <vector>

namespace ActsExamples {
class IMaterialWriter;
struct AlgorithmContext;
} // namespace ActsExamples

namespace Acts {

class TrackingGeometry;
Expand Down Expand Up @@ -81,7 +76,7 @@ class MaterialMapping : public IAlgorithm {
std::reference_wrapper<const Acts::MagneticFieldContext> magFieldContext;

/// Input collection
std::string collection = "material_tracks";
std::string inputMaterialTracks = "material_tracks";

/// The material collection to be stored
std::string mappingMaterialCollection = "mapped_material_tracks";
Expand Down
24 changes: 11 additions & 13 deletions Examples/Algorithms/MaterialMapping/src/MaterialMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
#include <unordered_map>

namespace ActsExamples {
struct AlgorithmContext;
} // namespace ActsExamples

ActsExamples::MaterialMapping::MaterialMapping(
const ActsExamples::MaterialMapping::Config& cfg,
Acts::Logging::Level level)
: ActsExamples::IAlgorithm("MaterialMapping", level),
MaterialMapping::MaterialMapping(const MaterialMapping::Config& cfg,
Acts::Logging::Level level)
: IAlgorithm("MaterialMapping", level),
m_cfg(cfg),
m_mappingState(cfg.geoContext, cfg.magFieldContext),
m_mappingStateVol(cfg.geoContext, cfg.magFieldContext) {
Expand All @@ -33,7 +30,7 @@ ActsExamples::MaterialMapping::MaterialMapping(
throw std::invalid_argument("Missing tracking geometry");
}

m_inputMaterialTracks.initialize(m_cfg.collection);
m_inputMaterialTracks.initialize(m_cfg.inputMaterialTracks);
m_outputMaterialTracks.initialize(m_cfg.mappingMaterialCollection);

ACTS_INFO("This algorithm requires inter-event information, "
Expand All @@ -51,7 +48,7 @@ ActsExamples::MaterialMapping::MaterialMapping(
}
}

ActsExamples::MaterialMapping::~MaterialMapping() {
MaterialMapping::~MaterialMapping() {
Acts::DetectorMaterialMaps detectorMaterial;

if (m_cfg.materialSurfaceMapper && m_cfg.materialVolumeMapper) {
Expand Down Expand Up @@ -98,8 +95,7 @@ ActsExamples::MaterialMapping::~MaterialMapping() {
}
}

ActsExamples::ProcessCode ActsExamples::MaterialMapping::execute(
const ActsExamples::AlgorithmContext& context) const {
ProcessCode MaterialMapping::execute(const AlgorithmContext& context) const {
// Take the collection from the EventStore
std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
mtrackCollection = m_inputMaterialTracks(context);
Expand All @@ -125,11 +121,11 @@ ActsExamples::ProcessCode ActsExamples::MaterialMapping::execute(
}
// Write take the collection to the EventStore
m_outputMaterialTracks(context, std::move(mtrackCollection));
return ActsExamples::ProcessCode::SUCCESS;
return ProcessCode::SUCCESS;
}

std::vector<std::pair<double, int>>
ActsExamples::MaterialMapping::scoringParameters(uint64_t surfaceID) {
std::vector<std::pair<double, int>> MaterialMapping::scoringParameters(
uint64_t surfaceID) {
std::vector<std::pair<double, int>> scoringParameters;

if (m_cfg.materialSurfaceMapper) {
Expand All @@ -151,3 +147,5 @@ ActsExamples::MaterialMapping::scoringParameters(uint64_t surfaceID) {
}
return scoringParameters;
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2017-2022 CERN for the benefit of the Acts project
// Copyright (C) 2022-2024 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Material/MaterialInteraction.hpp"
#include "Acts/Propagator/MaterialInteractor.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IReader.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"
#include <Acts/Definitions/Algebra.hpp>
#include <Acts/Propagator/MaterialInteractor.hpp>
#include <Acts/Utilities/Logger.hpp>

#include <cstddef>
#include <cstdint>
Expand All @@ -28,7 +28,6 @@
class TChain;

namespace ActsExamples {
struct AlgorithmContext;

/// @class RootMaterialTrackReader
///
Expand All @@ -39,13 +38,13 @@ class RootMaterialTrackReader : public IReader {
public:
/// @brief The nested configuration struct
struct Config {
std::string collection =
"material-tracks"; ///< material collection to read
std::string treeName = "material-tracks"; ///< name of the output tree
std::vector<std::string> fileList; ///< List of input files
/// material collection to read
std::string outputMaterialTracks = "material-tracks";
/// name of the output tree
std::string treeName = "material-tracks";
/// List of input files
std::vector<std::string> fileList;

/// Whether the events are ordered or not
bool orderedEvents = true;
// Read surface information for the root file
bool readCachedSurfaceInformation = false;
};
Expand Down Expand Up @@ -104,46 +103,62 @@ class RootMaterialTrackReader : public IReader {
/// multiple entries corresponding to one event number)
std::vector<long long> m_entryNumbers = {};

float m_v_x = 0; ///< start global x
float m_v_y = 0; ///< start global y
float m_v_z = 0; ///< start global z
float m_v_px = 0; ///< start global momentum x
float m_v_py = 0; ///< start global momentum y
float m_v_pz = 0; ///< start global momentum z
float m_v_phi = 0; ///< start phi direction
float m_v_eta = 0; ///< start eta direction
float m_tX0 = 0; ///< thickness in X0/L0
float m_tL0 = 0; ///< thickness in X0/L0

std::vector<float>* m_step_x = new std::vector<float>; ///< step x position
std::vector<float>* m_step_y = new std::vector<float>; ///< step y position
std::vector<float>* m_step_z = new std::vector<float>; ///< step z position
std::vector<float>* m_step_dx = new std::vector<float>; ///< step x direction
std::vector<float>* m_step_dy = new std::vector<float>; ///< step y direction
std::vector<float>* m_step_dz = new std::vector<float>; ///< step z direction
std::vector<float>* m_step_length = new std::vector<float>; ///< step length
std::vector<float>* m_step_X0 = new std::vector<float>; ///< step material x0
std::vector<float>* m_step_L0 = new std::vector<float>; ///< step material l0
std::vector<float>* m_step_A = new std::vector<float>; ///< step material A
std::vector<float>* m_step_Z = new std::vector<float>; ///< step material Z
std::vector<float>* m_step_rho =
new std::vector<float>; ///< step material rho

std::vector<std::uint64_t>* m_sur_id =
new std::vector<std::uint64_t>; ///< ID of the surface associated with
///< the step
std::vector<float>* m_sur_x =
new std::vector<float>; ///< x position of the center of the surface
///< associated with the step
std::vector<float>* m_sur_y =
new std::vector<float>; ///< y position of the center of the surface
///< associated with the step
std::vector<float>* m_sur_z =
new std::vector<float>; ///< z position of the center of the surface
///< associated with the step
std::vector<float>* m_sur_pathCorrection =
new std::vector<float>; ///< path correction when associating
///< material to the given surface
/// start global x
float m_v_x = 0;
/// start global y
float m_v_y = 0;
/// start global z
float m_v_z = 0;
/// start global momentum x
float m_v_px = 0;
/// start global momentum y
float m_v_py = 0;
/// start global momentum z
float m_v_pz = 0;
/// start phi direction
float m_v_phi = 0;
/// start eta direction
float m_v_eta = 0;
/// thickness in X0/L0
float m_tX0 = 0;
/// thickness in X0/L0
float m_tL0 = 0;

/// step x position
std::vector<float>* m_step_x = new std::vector<float>;
/// step y position
std::vector<float>* m_step_y = new std::vector<float>;
/// step z position
std::vector<float>* m_step_z = new std::vector<float>;
/// step x direction
std::vector<float>* m_step_dx = new std::vector<float>;
/// step y direction
std::vector<float>* m_step_dy = new std::vector<float>;
/// step z direction
std::vector<float>* m_step_dz = new std::vector<float>;
/// step length
std::vector<float>* m_step_length = new std::vector<float>;
/// step material x0
std::vector<float>* m_step_X0 = new std::vector<float>;
/// step material l0
std::vector<float>* m_step_L0 = new std::vector<float>;
/// step material A
std::vector<float>* m_step_A = new std::vector<float>;
/// step material Z
std::vector<float>* m_step_Z = new std::vector<float>;
/// step material rho
std::vector<float>* m_step_rho = new std::vector<float>;

/// ID of the surface associated with the step
std::vector<std::uint64_t>* m_sur_id = new std::vector<std::uint64_t>;
/// x position of the center of the surface associated with the step
std::vector<float>* m_sur_x = new std::vector<float>;
/// y position of the center of the surface associated with the step
std::vector<float>* m_sur_y = new std::vector<float>;
/// z position of the center of the surface associated with the step
std::vector<float>* m_sur_z = new std::vector<float>;
/// path correction when associating material to the given surface
std::vector<float>* m_sur_pathCorrection = new std::vector<float>;
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ class RootMaterialTrackWriter
std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>> {
public:
struct Config {
std::string collection =
"material-tracks"; ///< material collection to write
std::string filePath = ""; ///< path of the output file
std::string fileMode = "RECREATE"; ///< file access mode
std::string treeName = "material-tracks"; ///< name of the output tree
/// material collection to write
std::string inputMaterialTracks = "material-tracks";
/// path of the output file
std::string filePath = "";
/// file access mode
std::string fileMode = "RECREATE";
/// name of the output tree
std::string treeName = "material-tracks";

/// Re-calculate total values from individual steps (for cross-checks)
bool recalculateTotals = false;
Expand Down Expand Up @@ -110,56 +113,83 @@ class RootMaterialTrackWriter
/// Event identifier.
uint32_t m_eventId = 0;

float m_v_x = 0; ///< start global x
float m_v_y = 0; ///< start global y
float m_v_z = 0; ///< start global z
float m_v_px = 0; ///< start global momentum x
float m_v_py = 0; ///< start global momentum y
float m_v_pz = 0; ///< start global momentum z
float m_v_phi = 0; ///< start phi direction
float m_v_eta = 0; ///< start eta direction
float m_tX0 = 0; ///< thickness in X0/L0
float m_tL0 = 0; ///< thickness in X0/L0

std::vector<float> m_step_sx; ///< step x (start) position (optional)
std::vector<float> m_step_sy; ///< step y (start) position (optional)
std::vector<float> m_step_sz; ///< step z (start) position (optional)
std::vector<float> m_step_x; ///< step x position
std::vector<float> m_step_y; ///< step y position
std::vector<float> m_step_z; ///< step z position
std::vector<float> m_step_ex; ///< step x (end) position (optional)
std::vector<float> m_step_ey; ///< step y (end) position (optional)
std::vector<float> m_step_ez; ///< step z (end) position (optional)
std::vector<float> m_step_dx; ///< step x direction
std::vector<float> m_step_dy; ///< step y direction
std::vector<float> m_step_dz; ///< step z direction
std::vector<float> m_step_length; ///< step length
std::vector<float> m_step_X0; ///< step material x0
std::vector<float> m_step_L0; ///< step material l0
std::vector<float> m_step_A; ///< step material A
std::vector<float> m_step_Z; ///< step material Z
std::vector<float> m_step_rho; ///< step material rho

std::vector<std::uint64_t>
m_sur_id; ///< ID of the surface associated with the step
std::vector<int32_t>
m_sur_type; ///< Type of the surface associated with the step
std::vector<float> m_sur_x; ///< x position of the center of the surface
///< associated with the step
std::vector<float> m_sur_y; ///< y position of the center of the surface
///< associated with the step
std::vector<float> m_sur_z; ///< z position of the center of the surface
///< associated with the step
std::vector<float>
m_sur_pathCorrection; ///< path correction when associating
///< material to the given surface
std::vector<float>
m_sur_range_min; ///< Min range of the surface associated with the step
std::vector<float>
m_sur_range_max; ///< Max range of the surface associated with the step

std::vector<std::uint64_t>
m_vol_id; ///< ID of the volume associated with the step
/// start global x
float m_v_x = 0;
/// start global y
float m_v_y = 0;
/// start global z
float m_v_z = 0;
/// start global momentum x
float m_v_px = 0;
/// start global momentum y
float m_v_py = 0;
/// start global momentum z
float m_v_pz = 0;
/// start phi direction
float m_v_phi = 0;
/// start eta direction
float m_v_eta = 0;
/// thickness in X0/L0
float m_tX0 = 0;
/// thickness in X0/L0
float m_tL0 = 0;

/// step x (start) position (optional)
std::vector<float> m_step_sx;
/// step y (start) position (optional)
std::vector<float> m_step_sy;
/// step z (start) position (optional)
std::vector<float> m_step_sz;
/// step x position
std::vector<float> m_step_x;
/// step y position
std::vector<float> m_step_y;
/// step z position
std::vector<float> m_step_z;
/// step x (end) position (optional)
std::vector<float> m_step_ex;
/// step y (end) position (optional)
std::vector<float> m_step_ey;
/// step z (end) position (optional)
std::vector<float> m_step_ez;
/// step x direction
std::vector<float> m_step_dx;
/// step y direction
std::vector<float> m_step_dy;
/// step z direction
std::vector<float> m_step_dz;
/// step length
std::vector<float> m_step_length;
/// step material x0
std::vector<float> m_step_X0;
/// step material l0
std::vector<float> m_step_L0;
/// step material A
std::vector<float> m_step_A;
/// step material Z
std::vector<float> m_step_Z;
/// step material rho
std::vector<float> m_step_rho;

/// ID of the surface associated with the step
std::vector<std::uint64_t> m_sur_id;
/// Type of the surface associated with the step
std::vector<int32_t> m_sur_type;
/// x position of the center of the surface associated with the step
std::vector<float> m_sur_x;
/// y position of the center of the surface associated with the step
std::vector<float> m_sur_y;
/// z position of the center of the surface associated with the step
std::vector<float> m_sur_z;
/// path correction when associating material to the given surface
std::vector<float> m_sur_pathCorrection;
/// Min range of the surface associated with the step
std::vector<float> m_sur_range_min;
/// Max range of the surface associated with the step
std::vector<float> m_sur_range_max;

/// ID of the volume associated with the step
std::vector<std::uint64_t> m_vol_id;
};

} // namespace ActsExamples
Loading

0 comments on commit 77a4e98

Please sign in to comment.