src/core/geometry/DetectorField.hpp

Definition of detector fields. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::DetectorField
Field instance of a detector.

Types

Name
enum class FieldType { NONE = 0, CONSTANT, LINEAR, GRID, CUSTOM1D, CUSTOM}
Type of fields.
enum class FieldMapping { PIXEL_FULL = 0, PIXEL_FULL_INVERSE, PIXEL_HALF_LEFT, PIXEL_HALF_RIGHT, PIXEL_HALF_TOP, PIXEL_HALF_BOTTOM, PIXEL_QUADRANT_I, PIXEL_QUADRANT_II, PIXEL_QUADRANT_III, PIXEL_QUADRANT_IV, SENSOR}
Type of field maps.
template
using std::function< T(const ROOT::Math::XYZPoint &pos)>
FieldFunction
Functor returning the field at a given position.

Functions

Name
template <typename T >
void
flip_vector_components(T & field, bool x, bool y)
Helper function to invert the field vector when flipping the field direction at pixel/field boundaries.
void flip_vector_components< ROOT::Math::XYZVector >(ROOT::Math::XYZVector & vec, bool x, bool y)
void flip_vector_components< double >(double & , bool , bool )

Detailed Description

Definition of detector fields.

Copyright: Copyright (c) 2018-2024 CERN and the Allpix Squared authors. This software is distributed under the terms of the MIT License, copied verbatim in the file “LICENSE.md”. In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. SPDX-License-Identifier: MIT

Types Documentation

enum FieldType

Enumerator Value Description
NONE 0 No field is applied.
CONSTANT Constant field.
LINEAR Linear field (linearity determined by function)
GRID Field supplied through a regularized grid.
CUSTOM1D Custom field function, dependent only on z.
CUSTOM Custom field function.

Type of fields.

enum FieldMapping

Enumerator Value Description
PIXEL_FULL 0 The field map spans the full pixel plane.
PIXEL_FULL_INVERSE The field map spans the full pixel plane, but pixel centers are at field corners.
PIXEL_HALF_LEFT The field map spans the left half of the volume and is mirrored along x.
PIXEL_HALF_RIGHT The field map spans the right half of the volume and is mirrored along x.
PIXEL_HALF_TOP The field map spans the top half of the volume and is mirrored along y.
PIXEL_HALF_BOTTOM The field map spans the bottom half of the volume and is mirrored along y.
PIXEL_QUADRANT_I The field map spans the top right quadrant of the volume and is mirrored to the other quadrants
PIXEL_QUADRANT_II The field map spans the top left quadrant of the volume and is mirrored to the other quadrants
PIXEL_QUADRANT_III The field map spans the lower left quadrant of the volume and is mirrored to the other quadrants
PIXEL_QUADRANT_IV The field map spans the lower right quadrant of the volume and is mirrored to the other quadrants
SENSOR The field is mapped to the full sensor, starting at the local coordinate origin. The field is mirrored at its edges.

Type of field maps.

using FieldFunction

template <typename T  =ROOT::Math::XYZVector>
using allpix::FieldFunction = typedef std::function<T(const ROOT::Math::XYZPoint& pos)>;

Functor returning the field at a given position.

Parameters:

  • pos Position in local coordinates at which the field should be evaluated

Functions Documentation

function flip_vector_components

template <typename T >
void flip_vector_components(
    T & field,
    bool x,
    bool y
)

Helper function to invert the field vector when flipping the field direction at pixel/field boundaries.

Parameters:

  • field Field value, templated to support vector fields and scalar fields
  • x Boolean to indicate flipping in x-direction
  • y Boolean to indicate flipping in y-direction

function flip_vector_components< ROOT::Math::XYZVector >

inline void flip_vector_components< ROOT::Math::XYZVector >(
    ROOT::Math::XYZVector & vec,
    bool x,
    bool y
)

function flip_vector_components< double >

inline void flip_vector_components< double >(
    double & ,
    bool ,
    bool 
)

Source code


#ifndef ALLPIX_DETECTOR_FIELD_H
#define ALLPIX_DETECTOR_FIELD_H

#include <array>
#include <functional>
#include <vector>

#include <Math/Point2D.h>
#include <Math/Point3D.h>
#include <Math/Vector2D.h>
#include <Math/Vector3D.h>

#include "DetectorModel.hpp"
#include "objects/Pixel.hpp"
#include "tools/ROOT.h"

namespace allpix {

    enum class FieldType {
        NONE = 0, 
        CONSTANT, 
        LINEAR,   
        GRID,     
        CUSTOM1D, 
        CUSTOM,   
    };

    enum class FieldMapping {
        PIXEL_FULL = 0,     
        PIXEL_FULL_INVERSE, 
        PIXEL_HALF_LEFT,    
        PIXEL_HALF_RIGHT,   
        PIXEL_HALF_TOP,     
        PIXEL_HALF_BOTTOM,  
        PIXEL_QUADRANT_I,   
        PIXEL_QUADRANT_II,  
        PIXEL_QUADRANT_III, 
        PIXEL_QUADRANT_IV,  
        SENSOR, 
    };

    template <typename T = ROOT::Math::XYZVector> using FieldFunction = std::function<T(const ROOT::Math::XYZPoint& pos)>;

    template <typename T> void flip_vector_components(T& field, bool x, bool y);

    /*
     * Vector field template specialization of helper function for field flipping
     */
    template <> inline void flip_vector_components<ROOT::Math::XYZVector>(ROOT::Math::XYZVector& vec, bool x, bool y) {
        vec.SetXYZ((x ? -vec.x() : vec.x()), (y ? -vec.y() : vec.y()), vec.z());
    }

    /*
     * Scalar field template specialization of helper function for field flipping
     * Here, no inversion of the field components is required
     */
    template <> inline void flip_vector_components<double>(double&, bool, bool) {}

    template <typename T, size_t N = 3> class DetectorField {
        friend class Detector;

    public:
        DetectorField() = default;

        bool isValid() const { return function_ || (bins_[0] != 0 && bins_[1] != 0 && bins_[2] != 0); }

        FieldType getType() const { return type_; }

        T get(const ROOT::Math::XYZPoint& local_pos, const bool extrapolate_z = false) const;

        T getRelativeTo(const ROOT::Math::XYZPoint& local_pos,
                        const ROOT::Math::XYPoint& reference,
                        const bool extrapolate_z = false) const;

        void setGrid(std::shared_ptr<std::vector<double>> field,
                     std::array<size_t, 3> bins,
                     std::array<double, 3> size,
                     FieldMapping mapping,
                     std::array<double, 2> scales,
                     std::array<double, 2> offset,
                     std::pair<double, double> thickness_domain);
        void setFunction(FieldFunction<T> function,
                         std::pair<double, double> thickness_domain,
                         FieldType type = FieldType::CUSTOM);

    private:
        void set_model(const std::shared_ptr<DetectorModel>& model) { model_ = model; }

        template <std::size_t... I> inline auto get_impl(size_t offset, std::index_sequence<I...>) const noexcept;

        T get_field_from_grid(const double x, const double y, const double z, const bool extrapolate_z) const noexcept;

        static inline int int_floor(double x) noexcept {
            auto i = static_cast<int>(x);
            return i - static_cast<int>(static_cast<double>(i) > x);
        };

        std::array<size_t, 3> bins_{};
        FieldMapping mapping_{FieldMapping::PIXEL_FULL};
        std::array<double, 2> normalization_{{1., 1.}};
        std::array<double, 2> offset_{{0., 0.}};

        std::shared_ptr<std::vector<double>> field_;
        std::pair<double, double> thickness_domain_{};
        FieldType type_{FieldType::NONE};
        FieldFunction<T> function_;

        /*
         * Relevant parameters from the detector model for this field
         */
        std::shared_ptr<DetectorModel> model_;
    };
} // namespace allpix

// Include template members
#include "DetectorField.tpp"

#endif /* ALLPIX_DETECTOR_FIELD_H */

Updated on 2024-12-13 at 08:31:37 +0000