Skip to content
Draft
69 changes: 69 additions & 0 deletions inc/TRestDetectorExperimentalReadout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @file TRestDetectorExperimentalReadout.h
* @brief Defines the TRestDetectorExperimentalReadout class.
*/

#ifndef REST_TRESTDETECTOREXPERIMENTALREADOUT_H
#define REST_TRESTDETECTOREXPERIMENTALREADOUT_H

#include <TNamed.h>

#include <map>

#include "TRestDetectorExperimentalReadoutModule.h"

/**
* @class TRestDetectorExperimentalReadout
* @brief Represents an experimental readout detector.
* @inherits TNamed
* @author Luis Obis
*/
class TRestDetectorExperimentalReadout : public TNamed {
private:
std::vector<TRestDetectorExperimentalReadoutModule> fModules; /**< The modules of the detector. */

public:
/**
* @brief Constructs a TRestDetectorExperimentalReadout object.
*/
TRestDetectorExperimentalReadout() = default;

/**
* @brief Destructor for TRestDetectorExperimentalReadout.
*/
~TRestDetectorExperimentalReadout() override = default;

/**
* @brief Returns the number of modules in the detector.
* @return The number of modules.
*/
size_t GetNumberOfModules() { return fModules.size(); }

/**
* @brief Adds a module to the detector.
* @param module The module to add.
*/
void AddModule(const TRestDetectorExperimentalReadoutModule& module) { fModules.push_back(module); }

/**
* @brief Returns the modules of the detector.
* @return The modules.
*/
std::vector<const TRestDetectorExperimentalReadoutModule*> GetModules() const;

/**
* @brief Returns the modules that contain a given point.
* @param point The point to check.
* @return The modules containing the point.
*/
std::vector<const TRestDetectorExperimentalReadoutModule*> GetModulesForPoint(
const TVector3& point) const;

std::vector<const TRestDetectorExperimentalReadoutPixel*> GetPixelsForPoint(const TVector3& point) const;

std::vector<unsigned short> GetChannelsForPoint(const TVector3& point) const;

ClassDef(TRestDetectorExperimentalReadout, 1);
};

#endif // REST_TRESTDETECTOREXPERIMENTALREADOUT_H
30 changes: 30 additions & 0 deletions inc/TRestDetectorExperimentalReadoutChannel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file TRestDetectorExperimentalReadoutModule.h
* @brief Defines the TRestDetectorExperimentalReadoutModule class.
*/

#ifndef REST_TRESTDETECTOREXPERIMENTALREADOUTCHANNEL_H
#define REST_TRESTDETECTOREXPERIMENTALREADOUTCHANNEL_H

#include <map>

#include "TRestDetectorExperimentalReadoutPixel.h"

/**
* @class TRestDetectorExperimentalReadoutChannel
* @brief Represents a channel in an experimental readout detector.
* @author Luis Obis
*/
class TRestDetectorExperimentalReadoutChannel {
private:
std::vector<TRestDetectorExperimentalReadoutPixel> fPixels; /**< The pixels of the channel. */
unsigned short fChannel; /**< The channel of the pixel. */

public:
TRestDetectorExperimentalReadoutChannel() = default;
~TRestDetectorExperimentalReadoutChannel() = default;

ClassDef(TRestDetectorExperimentalReadoutChannel, 1);
};

#endif // REST_TRESTDETECTOREXPERIMENTALREADOUTCHANNEL_H
139 changes: 139 additions & 0 deletions inc/TRestDetectorExperimentalReadoutModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* @file TRestDetectorExperimentalReadoutModule.h
* @brief Defines the TRestDetectorExperimentalReadoutModule class.
*/

#ifndef REST_TRESTDETECTOREXPERIMENTALREADOUTMODULE_H
#define REST_TRESTDETECTOREXPERIMENTALREADOUTMODULE_H

#include <map>

#include "TRestDetectorExperimentalReadoutPixel.h"

class KDTree;

/**
* @class TRestDetectorExperimentalReadoutModule
* @brief Represents a module in an experimental readout detector.
* @author Luis Obis
*/
class TRestDetectorExperimentalReadoutModule {
private:
std::vector<TRestDetectorExperimentalReadoutPixel> fPixels; /**< The pixels of the module. */

TVector3 fPosition = {0, 0, 0}; /**< The position of the module in 3D space. */
TVector3 fNormal = {0, 0, 1}; /**< The normal vector to the module. */
double fHeight = 1.0; /**< The height of the module (drift distance). */
std::pair<TVector3, TVector3> fCoordinateAxes = {{1, 0, 0},
{0, 1, 0}}; /**< The coordinate axes of the module. */
double fRotation =
0; /**< The rotation angle of the module with respect to the normal vector in degrees. */
// auxiliary data structures
KDTree* fKDTree = nullptr; /**< The KDTree used for spatial queries. */
double fSearchRadius = 0; /**< The search radius for spatial queries. */
std::vector<TVector2> fConvexHull; /**< The convex hull of the module. */
std::map<unsigned short, std::vector<TRestDetectorExperimentalReadoutPixel*>>
fChannelToPixels; /**< A map from channel to pixels. */
/**
* @brief Builds the KDTree for the module.
*/
void BuildKDTree();

/**
* @brief Computes the convex hull of the module.
* @return The convex hull of the module.
*/
std::vector<TVector2> ComputeConvexHull();

void UpdateAxes();

public:
// needed for root
TRestDetectorExperimentalReadoutModule() = default;
virtual ~TRestDetectorExperimentalReadoutModule() {
// delete fKDTree;
}

void SetPosition(const TVector3& position) { fPosition = position; }
void SetNormal(const TVector3& normal);
void SetHeight(double height);
void SetRotation(double rotationInDegrees);

TVector3 GetPosition() const { return fPosition; }
TVector3 GetNormal() const { return fNormal; }
double GetHeight() const { return fHeight; }
std::pair<TVector3, TVector3> GetCoordinateAxes() const { return fCoordinateAxes; }
double GetRotation() const { return fRotation; }
/**
* @brief Returns the number of pixels in the module.
* @return The number of pixels.
*/
size_t GetNumberOfPixels() const { return fPixels.size(); }

/**
* @brief Returns the pixels of the module.
* @return The pixels.
*/
std::vector<TRestDetectorExperimentalReadoutPixel> GetPixels() const { return fPixels; }

/**
* @brief Sets the pixels of the module.
* @param pixels The pixels to set.
*/
void SetPixels(const std::vector<TRestDetectorExperimentalReadoutPixel>& pixels);

/**
* @brief Returns the convex hull of the module.
* @return The convex hull.
*/
std::vector<TVector2> GetConvexHull() const { return fConvexHull; }

/**
* @brief Returns the pixels that contain a given point.
* @param point The point to check.
* @return The pixels containing the point.
*/
std::vector<const TRestDetectorExperimentalReadoutPixel*> GetPixelsForPoint(const TVector2& point) const;
std::vector<const TRestDetectorExperimentalReadoutPixel*> GetPixelsForPoint(const TVector3& point) const;
std::vector<const TRestDetectorExperimentalReadoutPixel*> GetPixelsForChannel(
unsigned short channel) const;

/**
* @brief Returns the Z coordinate of a given point inside the module.
* @param point The point to check.
* @return The Z coordinate of the point.
*/
double GetZ(const TVector3& point) const;

/**
* @brief Checks if a given point is inside the module in the module's local XY plane.
* @param point The point to check.
* @return True if the point is inside the module, false otherwise.
*/
bool IsInside(const TVector2& point) const;

/**
* @brief Checks if a given point is inside the module in 3D space.
* @param point The point to check.
* @return True if the point is inside the module, false otherwise.
*/
bool IsInside(const TVector3& point) const;

/**
* @brief Transforms a point from 3D space to the module's local XY plane coordinates.
* @param point The point to transform.
* @return The transformed point in the local XY plane.
*/
TVector2 TransformToModuleCoordinates(const TVector3& point) const;

/**
* @brief Transforms a point from the module's local XY plane coordinates to 3D space.
* @param point The point to transform.
* @return The transformed point in 3D space.
*/
TVector3 TransformToAbsoluteCoordinates(const TVector2& point) const;

ClassDef(TRestDetectorExperimentalReadoutModule, 1);
};

#endif // REST_TRESTDETECTOREXPERIMENTALREADOUTMODULE_H
151 changes: 151 additions & 0 deletions inc/TRestDetectorExperimentalReadoutPixel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* @file TRestDetectorExperimentalReadoutPixel.h
* @brief Defines the TRestDetectorExperimentalReadoutPixel class.
*/

#ifndef REST_TRESTDETECTOREXPERIMENTALREADOUTPIXEL_H
#define REST_TRESTDETECTOREXPERIMENTALREADOUTPIXEL_H

#include <TVector2.h>
#include <TVector3.h>

#include <iostream>
#include <map>
#include <stdexcept>
#include <vector>

/**

* @class TRestDetectorExperimentalReadoutPixel
* @brief Represents a pixel in an experimental readout detector.
* @author Luis Obis

*/
class TRestDetectorExperimentalReadoutPixel {
private:
std::vector<TVector2> fVertices; /**< The vertices of the pixel. */
TVector2 fCenter; /**< The center of the pixel in mm. A pixel is guaranteed to be inside a circle with
center fCenter and radius fRadius. */
double fRadius; /**< The radius of the pixel in mm. A pixel is guaranteed to be inside a circle with
center fCenter and radius fRadius. */

unsigned short fChannel; /**< The channel of the pixel. */
/**

@brief Initializes the vertices of the pixel.
@param vertices The vertices of the pixel.
*/
void InitializeVertices(const std::vector<TVector2>& vertices);
/**

@brief Calculates the vertices of a rectangular pixel.
@param center The center of the pixel.
@param size The size of the pixel (width, height).
@return The vertices of the rectangular pixel.
*/
static std::vector<TVector2> GetRectangularVertices(const TVector2& center,
const std::pair<double, double>& size);

public:
/**

@brief Constructs a TRestDetectorExperimentalReadoutPixel object with given vertices.
@param vertices The vertices of the pixel.
*/
explicit TRestDetectorExperimentalReadoutPixel(const std::vector<TVector2>& vertices,
unsigned short channel = 0);
/**

@brief Constructs a rectangular TRestDetectorExperimentalReadoutPixel object.
@param center The center of the pixel.
@param size The size of the pixel (width, height).
*/
TRestDetectorExperimentalReadoutPixel(const TVector2& center, const std::pair<double, double>& size,
unsigned short channel = 0);
/**

@brief Constructs a square TRestDetectorExperimentalReadoutPixel object.
@param center The center of the pixel.
@param size The size of the pixel (width and height).
*/
TRestDetectorExperimentalReadoutPixel(const TVector2& center, double size, unsigned short channel = 0);
// needed for root
TRestDetectorExperimentalReadoutPixel() = default;
virtual ~TRestDetectorExperimentalReadoutPixel() = default;

/**

@brief Returns the center of the pixel.
@return The center of the pixel.
*/
TVector2 GetCenter() const { return fCenter; }
/**

@brief Returns the radius of the pixel.
@return The radius of the pixel.
*/
double GetRadius() const { return fRadius; }
/**

@brief Returns the vertices of the pixel.
@return The vertices of the pixel.
*/
std::vector<TVector2> GetVertices() const { return fVertices; }
/**

@brief Checks if a given point is inside the pixel.
@param point The point to check.
@return True if the point is inside the pixel, false otherwise.
*/
bool IsInside(const TVector2& point) const;

unsigned short GetChannel() const { return fChannel; }

ClassDef(TRestDetectorExperimentalReadoutPixel, 1);
};

namespace readout {

/**

@brief Calculates the triple product of three vectors.
@param A The first vector.
@param B The second vector.
@param C The third vector.
@return The cross product of the vectors.
*/
double crossProduct(const TVector2& A, const TVector2& B, const TVector2& C);
/**

@brief Calculates the squared distance between two points.
@param A The first point.
@param B The second point.
@return The squared distance between the points.
*/
double squaredDistance(const TVector2& A, const TVector2& B);
/**

@brief Comparator function to compare two points based on their polar angle with respect to the anchor point.
@param A The first point.
@param B The second point.
@param anchor The anchor point.
@return True if point A is smaller than point B, false otherwise.
*/
bool comparePoints(const TVector2& A, const TVector2& B, const TVector2& anchor);
/**

@brief Finds the convex hull of a set of points using the Graham's scan algorithm.
@param _points The input points.
@return The convex hull of the points.
*/
std::vector<TVector2> findConvexHull(const std::vector<TVector2>& _points);
/**

@brief Checks if a given point is inside a convex hull.
@param point The point to check.
@param convexHull The convex hull.
@return True if the point is inside the convex hull, false otherwise.
*/
bool IsPointInsideConvexHull(const TVector2& point, const std::vector<TVector2>& convexHull);
} // namespace readout
#endif // REST_TRESTDETECTOREXPERIMENTALREADOUTPIXEL_H
Loading