CbmRoot
Loading...
Searching...
No Matches
GeoVolume.h
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#ifndef ALGO_GeoVolume_h
11#define ALGO_GeoVolume_h 1
12
13#include <boost/serialization/access.hpp>
14
15#include <cmath>
16#include <limits>
17#include <string>
18
19namespace cbm::algo
20{
23 // TODO: maybe add translation and rotation of volumes to handle local reconstruction parameters as well
24 // (to be discussed)
25 class GeoVolume {
28 struct Dimension {
29 double lo{+std::numeric_limits<double>::max()};
30 double up{-std::numeric_limits<double>::max()};
31
33 Dimension() = default;
34
36 Dimension(double lo_, double up_) : lo(lo_), up(up_) {}
37
40 {
41 lo = std::min(lo, other.lo);
42 up = std::max(up, other.up);
43 return *this;
44 }
45
47 double Center() const { return (up + lo) * 0.5; }
48
50 bool IsValid() const { return Size() > 0 && std::isfinite(Size()); }
51
54 bool HasOverlapWith(const Dimension& other) const { return (lo - other.up) * (up - other.lo) <= 0; }
55
57 double Size() const { return up - lo; }
58 };
59
60 public:
62 GeoVolume() = default;
63
71 GeoVolume(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax);
72
77 GeoVolume(std::pair<double, double> x, std::pair<double, double> y, std::pair<double, double> z);
78
80 GeoVolume& operator+=(const GeoVolume& other);
81
85 bool IsValid() const { return fX.IsValid() && fY.IsValid() && fZ.IsValid(); }
86
88 double GetCenterX() const { return fX.Center(); }
89
91 double GetCenterY() const { return fY.Center(); }
92
94 double GetCenterZ() const { return fZ.Center(); }
95
97 double GetMaxX() const { return fX.up; }
98
100 double GetMaxY() const { return fY.up; }
101
103 double GetMaxZ() const { return fZ.up; }
104
106 double GetMinX() const { return fX.lo; }
107
109 double GetMinY() const { return fY.lo; }
110
112 double GetMinZ() const { return fZ.lo; }
113
115 double GetSizeX() const { return fX.Size(); }
116
118 double GetSizeY() const { return fY.Size(); }
119
121 double GetSizeZ() const { return fZ.Size(); }
122
125 bool HasOverlapWith(const GeoVolume& other) const;
126
128 std::string ToString() const;
129
130 private:
133 template<class Archive>
134 void serialize(Archive& ar, const unsigned int /*version*/)
135 {
136 ar& fX.lo;
137 ar& fX.up;
138 ar& fY.lo;
139 ar& fY.up;
140 ar& fZ.lo;
141 ar& fZ.up;
142 }
143
147 };
148
149} // namespace cbm::algo
150
151#endif
A representation of a geometrical volume of different tracking stations.
Definition GeoVolume.h:25
double GetSizeX() const
Gets size in x-direction [cm].
Definition GeoVolume.h:115
bool HasOverlapWith(const GeoVolume &other) const
Checks, if the volume overlaps with another volume.
Definition GeoVolume.cxx:44
double GetMaxZ() const
Gets upper bound in z-diretion [cm].
Definition GeoVolume.h:103
Dimension fX
x dimension
Definition GeoVolume.h:144
void serialize(Archive &ar, const unsigned int)
Definition GeoVolume.h:134
double GetSizeY() const
Gets size in y-direction [cm].
Definition GeoVolume.h:118
double GetCenterZ() const
Gets center in z-direction [cm].
Definition GeoVolume.h:94
double GetCenterY() const
Gets center in y-direction [cm].
Definition GeoVolume.h:91
double GetMaxX() const
Gets upper bound in x-direction [cm].
Definition GeoVolume.h:97
double GetMinX() const
Gets lower bound in x-direction [cm].
Definition GeoVolume.h:106
double GetMinZ() const
Gets lower bound in z-diretion [cm].
Definition GeoVolume.h:112
double GetCenterX() const
Gets center in x-direction [cm].
Definition GeoVolume.h:88
Dimension fZ
z dimension
Definition GeoVolume.h:146
Dimension fY
y dimension
Definition GeoVolume.h:145
double GetMinY() const
Gets lower bound in y-direction [cm].
Definition GeoVolume.h:109
double GetMaxY() const
Gets upper bound in y-direction [cm].
Definition GeoVolume.h:100
GeoVolume & operator+=(const GeoVolume &other)
Compound assignment of another volume.
Definition GeoVolume.cxx:34
friend class boost::serialization::access
Serialization method.
Definition GeoVolume.h:132
std::string ToString() const
String representation of the class.
Definition GeoVolume.cxx:51
GeoVolume()=default
Default constructor.
bool IsValid() const
Checks validity of the volume.
Definition GeoVolume.h:85
double GetSizeZ() const
Gets size in z-direction [cm].
Definition GeoVolume.h:121
A volume dimension representation.
Definition GeoVolume.h:28
double lo
Lower bound of the dimension.
Definition GeoVolume.h:29
double up
Upper bound of the dimension.
Definition GeoVolume.h:30
double Center() const
Center of the dimension.
Definition GeoVolume.h:47
bool HasOverlapWith(const Dimension &other) const
Checks, if the dimension has an overlap with another dimension.
Definition GeoVolume.h:54
Dimension & operator+=(const Dimension &other)
Compound assignment of another dimension.
Definition GeoVolume.h:39
Dimension()=default
Default constructor.
double Size() const
Size of the dimension.
Definition GeoVolume.h:57
Dimension(double lo_, double up_)
Constructor.
Definition GeoVolume.h:36
bool IsValid() const
Checks, if the dimension is valid.
Definition GeoVolume.h:50