Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readout plane upgrade, readout validation and new library version #92

Merged
merged 71 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
8484f5b
TRestDetectorReadoutPlane. Added fAxisX and fAxisY. Renamed fPlaneVec…
jgalan Jun 7, 2023
ecb8590
Increasing library version to 2.0
jgalan Jun 7, 2023
5737989
Adding default values
jgalan Jun 7, 2023
cba956e
TRestDetectorReadoutPlane. Adding Setters/Getters
jgalan Jun 7, 2023
949bb89
TRestDetectorReadout. Reading out plane axis Y and Y
jgalan Jun 7, 2023
14b5923
TRestDetectorReadoutPlane. Updating Print information
jgalan Jun 7, 2023
f0af64b
Updating processes to renamed TRestDetectorReadoutPlane::GetNormal() …
jgalan Jun 7, 2023
6ec8fcc
TRestDetectorReadoutPlane::Print. Fixing typo
jgalan Jun 7, 2023
ca7f8a2
Updating readout
jgalan Jun 7, 2023
87f4cb3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 7, 2023
da5c462
TRestDetectorReadout. X and Y plane axis are determined only by norma…
jgalan Jun 7, 2023
6c633c6
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 7, 2023
6b01b08
fix typos
lobis Jun 8, 2023
507c96d
remove fNModules field
lobis Jun 8, 2023
7fe541f
fix typos
lobis Jun 8, 2023
4f06a6e
Using single parameter height instead of TVector3 cathode position
lobis Jun 8, 2023
af6b85f
simplified initialization
lobis Jun 8, 2023
0368727
remove #pragma region (local IDE settings should not be committed)
lobis Jun 8, 2023
2af0c73
TRestDetectorReadout. Changing the sign of x-axis
jgalan Jun 8, 2023
7a05e4e
Readout updates
jgalan Jun 8, 2023
d003735
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 8, 2023
d1482dd
Fixing compilation issues
jgalan Jun 8, 2023
00ce0c5
compareFiles.py now validates only numeric values
jgalan Jun 8, 2023
536b3e3
compareFiles.py adding debug output
jgalan Jun 8, 2023
84ab6ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2023
131ee1e
compareFiles.py removing color codes
jgalan Jun 8, 2023
6d3dece
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 8, 2023
5c30eee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2023
e998e63
compareFiles.py fixing typo
jgalan Jun 8, 2023
1e0b296
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 8, 2023
c50db37
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2023
7d41f20
updating compareFiles.py
jgalan Jun 8, 2023
7225451
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 8, 2023
33e2a74
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 8, 2023
f062893
Updating pr-badge.yml
jgalan Jun 8, 2023
0e67550
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 8, 2023
318ad25
Updating pipeline branch validation
jgalan Jun 8, 2023
1097ce4
use const refs
lobis Jun 9, 2023
3d21748
add TRestDetectorReadoutPlane::UpdateAxes, update how local reference…
lobis Jun 9, 2023
02348eb
Remove redundant TRestDetectorReadoutPlane::GetDistanceTo method
lobis Jun 9, 2023
05cab64
SetHeight with bad parameter raises exception
lobis Jun 9, 2023
97a0e26
TRestDetectorReadout. Adding rotation parameter
jgalan Jun 9, 2023
db710ad
use radians as angular unit
lobis Jun 9, 2023
6462b9b
TRestDetectorReadoutModule::fModuleRotation is now in radians
jgalan Jun 9, 2023
9babbdf
TRestDetectorReadoutModule::fModuleRotation renamed to fRotation
jgalan Jun 9, 2023
18327cb
TRestDetectorReadoutModule. Increasing class version
jgalan Jun 9, 2023
49679cb
renamed some parameters to be coherent with changes in TRestReadoutPlane
lobis Jun 9, 2023
5db58fd
use single parameter for min and max daq ids (daqidrange)
lobis Jun 9, 2023
844841b
remove confusing `GetSizeZ` method (should be called Y?). Single inte…
lobis Jun 9, 2023
da3356b
TRestDetectorReadoutPlane. Increasing class version
jgalan Jun 9, 2023
9d3b51d
TRestDetectorReadoutPlane. Recovering fAxisX and fAxisY
jgalan Jun 11, 2023
e0f4578
remove #pragma region directive
lobis Jun 12, 2023
d1521c2
TRestDetectorReadoutPlane. Fixing a piece of code where module rotati…
jgalan Jun 12, 2023
e78c227
prevent user from setting zero vector as normal
lobis Jun 12, 2023
8e40b13
verify axes and normal are orthonormal reference frame
lobis Jun 12, 2023
cc014aa
handle case when normal is exactly opposite to originalNormal. Add ad…
lobis Jun 12, 2023
2cd0ca7
update axes initialization. Add tests for axes
lobis Jun 12, 2023
65a2f67
TRestDetectorReadout. Adding default values for rotation and chargeCo…
jgalan Jun 13, 2023
95b166f
generateReadout.rml removing units from normal definition
jgalan Jun 13, 2023
a9831e7
TRestDetectorReadout. Charge collection default value removed
jgalan Jun 13, 2023
9a67237
readout/validation.txt Fixing validation axis orientation
jgalan Jun 13, 2023
05dafc9
pipeline/generateReadout.rml adding units
jgalan Jun 13, 2023
5a21b30
methods to go from/to global/local coords
lobis Jun 13, 2023
0fe6b35
rotation is now saved as a value from 0 to 2pi
lobis Jun 13, 2023
b244133
add method to set plane x-axis explicitly. Add validation
lobis Jun 13, 2023
a5159dc
rename originalNormal to zUnit (internal method)
lobis Jun 13, 2023
92da00a
Transferring basic-readouts validation
jgalan Jun 14, 2023
df24542
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 14, 2023
ee94ffb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2023
4c9606b
Updating to master validation
jgalan Jun 14, 2023
c912c30
Merge branch 'jgalan-readoutplane-update' of github.com:rest-for-phys…
jgalan Jun 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pr-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
message: "Ok: $additions"
color: "green"
when: "$additions < 100"
- imageUrl: "https://github.com/rest-for-physics/detectorlib/actions/workflows/validation.yml/badge.svg?branch=$branchName"
- imageUrl: "https://github.com/rest-for-physics/detectorlib/actions/workflows/frameworkValidation.yml/badge.svg?branch=$branchName"
url: "https://github.com/rest-for-physics/detectorlib/commits/$branchName"
2 changes: 1 addition & 1 deletion .github/workflows/frameworkValidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ defaults:

jobs:
framework-validation:
uses: rest-for-physics/framework/.github/workflows/validation.yml@master
uses: rest-for-physics/framework/.github/workflows/validation.yml@jgalan-readoutplane-update
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(LibraryVersion "1.9")
set(LibraryVersion "2.0")
add_definitions(-DLIBRARY_VERSION="${LibraryVersion}")

# find garfield libs and includes
Expand Down
85 changes: 36 additions & 49 deletions inc/TRestDetectorReadoutModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,19 @@
/// allows to integrate any number of independent readout channels.
class TRestDetectorReadoutModule {
private:
Int_t fModuleID; ///< The module id given by the readout definition.
Int_t fId = -1; ///< The module id given by the readout definition.

TString fModuleName; ///< The assigned module name.
std::string fName; ///< The assigned module name.

TVector2 fModuleOrigin; ///< The module (x, y) position relative to the readout plane position.
TVector2 fOrigin = {0, 0}; ///< The module (x, y) position relative to the readout plane position.

TVector2 fModuleSize; ///< The module (x, y) size. All pixels should be contained within this size.
TVector2 fSize = {0, 0}; ///< The module (x, y) size. All pixels should be contained within this size.

Double_t fModuleRotation; ///< The rotation of the module around the
///< position=(fModuleOriginX, fModuleOriginY) in
///< degrees.
/// The rotation of the module around the module origin (fModuleOriginX, fModuleOriginY) in radians.
Double_t fRotation = 0; //<

Int_t fMinimumDaqId; ///< The minimum daq channel id associated to the
///< module.
Int_t fMaximumDaqId; ///< The maximum daq channel id associated to the module.
std::pair<Int_t, Int_t> fDaqIdRange = {
-1, -1}; ///< The minimum and maximum daq channel ids associated to the module.

std::vector<TRestDetectorReadoutChannel>
fReadoutChannel; ///< A std::vector of the instances of TRestDetectorReadoutChannel
Expand All @@ -68,8 +66,8 @@ class TRestDetectorReadoutModule {
/// Converts the coordinates (xPhys,yPhys) in the readout plane reference
/// system to the readout module reference system.
inline TVector2 TransformToModuleCoordinates(const TVector2& xyPhysical) const {
auto coords = xyPhysical - fModuleOrigin;
TVector2 rot = coords.Rotate(-fModuleRotation * TMath::Pi() / 180.);
auto coords = xyPhysical - fOrigin;
TVector2 rot = coords.Rotate(-fRotation);

return rot;
}
Expand All @@ -79,8 +77,8 @@ class TRestDetectorReadoutModule {
inline TVector2 TransformToPlaneCoordinates(Double_t xMod, Double_t yMod) const {
TVector2 coords(xMod, yMod);

coords = coords.Rotate(fModuleRotation * TMath::Pi() / 180.);
coords += fModuleOrigin;
coords = coords.Rotate(fRotation);
coords += fOrigin;

return coords;
}
Expand All @@ -90,22 +88,19 @@ class TRestDetectorReadoutModule {
// Setters

/// Sets the module by id definition
inline void SetModuleID(Int_t modID) { fModuleID = modID; }
inline void SetModuleID(Int_t modID) { fId = modID; }

/// Sets the module size by definition using TVector2 input
inline void SetSize(const TVector2& size) { fModuleSize = size; }
inline void SetSize(const TVector2& size) { fSize = size; }

/// Sets the module origin by definition using TVector2 input
inline void SetOrigin(const TVector2& origin) { fModuleOrigin = origin; }

/// Sets the module origin by definition using (x,y) coordinates
inline void SetOrigin(Double_t x, Double_t y) { SetOrigin({x, y}); }
inline void SetOrigin(const TVector2& origin) { fOrigin = origin; }

/// Sets the module rotation in degrees
inline void SetRotation(Double_t rotation) { fModuleRotation = rotation; }
inline void SetRotation(Double_t rotation) { fRotation = rotation; }

/// Sets the name of the readout module
inline void SetName(const TString& name) { fModuleName = name; }
inline void SetName(const std::string& name) { fName = name; }

/// Sets the tolerance for independent pixel overlaps
inline void SetTolerance(Double_t tolerance) { fTolerance = tolerance; }
Expand All @@ -114,42 +109,32 @@ class TRestDetectorReadoutModule {
inline Double_t GetTolerance() const { return fTolerance; }

/// Returns the minimum daq id number
inline Int_t GetMinDaqID() const { return fMinimumDaqId; }
inline Int_t GetMinDaqID() const { return fDaqIdRange.first; }

/// Returns the maximum daq id number
inline Int_t GetMaxDaqID() const { return fMaximumDaqId; }
inline Int_t GetMaxDaqID() const { return fDaqIdRange.second; }

/// Returns the physical readout channel index for a given daq id channel
/// number
/// Returns the physical readout channel index for a given daq id channel number
inline Int_t DaqToReadoutChannel(Int_t daqChannel) {
for (size_t n = 0; n < GetNumberOfChannels(); n++)
if (GetChannel(n)->GetDaqID() == daqChannel) return n;
for (size_t n = 0; n < GetNumberOfChannels(); n++) {
if (GetChannel(n)->GetDaqID() == daqChannel) {
return n;
}
}
return -1;
}

/// Returns the module id
inline Int_t GetModuleID() const { return fModuleID; }

/// Returns the module x-coordinate origin
inline Double_t GetModuleOriginX() const { return fModuleOrigin.X(); }

/// Returns the module y-coordinate origin
inline Double_t GetModuleOriginY() const { return fModuleOrigin.Y(); }

/// Returns the module x-coordinate origin
inline Double_t GetOriginX() const { return fModuleOrigin.X(); }

/// Returns the module y-coordinate origin
inline Double_t GetOriginY() const { return fModuleOrigin.Y(); }
inline Int_t GetModuleID() const { return fId; }

/// Returns the module size x-coordinate
inline Double_t GetModuleSizeX() const { return fModuleSize.X(); }
/// Returns the module origin position
inline TVector2 GetOrigin() const { return fOrigin; }

/// Returns the module size y-coordinate
inline Double_t GetModuleSizeY() const { return fModuleSize.Y(); }
/// Returns the module size (x, y) in mm
inline TVector2 GetSize() const { return fSize; }

/// Returns the module rotation in degrees
inline Double_t GetModuleRotation() const { return fModuleRotation; }
inline Double_t GetRotation() const { return fRotation; }

/// Converts the coordinates given by TVector2 in the readout plane reference
/// system to the readout module reference system.
Expand All @@ -160,7 +145,7 @@ class TRestDetectorReadoutModule {
TVector2 GetPlaneCoordinates(const TVector2& p) { return TransformToPlaneCoordinates(p.X(), p.Y()); }

/// Returns the module name
inline const char* GetName() const { return fModuleName.Data(); }
inline const char* GetName() const { return fName.c_str(); }

/// Returns a pointer to the readout mapping
inline TRestDetectorReadoutMapping* GetMapping() { return &fMapping; }
Expand All @@ -169,7 +154,9 @@ class TRestDetectorReadoutModule {

/// Returns a pointer to a readout channel by index
inline TRestDetectorReadoutChannel* GetChannel(size_t n) {
if (n >= GetNumberOfChannels()) return nullptr;
if (n >= GetNumberOfChannels()) {
return nullptr;
}
return &fReadoutChannel[n];
}

Expand Down Expand Up @@ -226,6 +213,6 @@ class TRestDetectorReadoutModule {
// Destructor
virtual ~TRestDetectorReadoutModule();

ClassDef(TRestDetectorReadoutModule, 2);
ClassDef(TRestDetectorReadoutModule, 3);
};
#endif
120 changes: 65 additions & 55 deletions inc/TRestDetectorReadoutPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,79 +35,87 @@
/// allows to integrate any number of independent readout modules.
class TRestDetectorReadoutPlane {
private:
Int_t fPlaneID; ///< The readout plane id. The id number is imposed by the
///< order of creation. Being the first id=0.

TVector3 fPosition; ///< The position of the readout plane. The relative position
///< of the modules will be shifted by this value.
TVector3 fPlaneVector; ///< The plane std::vector defining the plane orientation
///< and the side of the active volume.
TVector3 fCathodePosition; ///< The cathode position which delimites the active
///< volume together with the readout plane.
Double_t fChargeCollection; ///< A parameter between 0 and 1 defining how
///< much charge should be collected from a
///< charge hit. It might be used to distribute
///< the charge between different readout planes.
Double_t fTotalDriftDistance; ///< A parameter storing the total drift distance,
///< defined between cathode and readout plane.

Int_t fNModules; ///< The number of modules that have been added to the
///< readout plane
std::vector<TRestDetectorReadoutModule>
fReadoutModules; ///< A std::vector of the instances of TRestDetectorReadoutModule
///< contained in the readout plane.

void Initialize();

protected:
/// The plane id number imposed by the order of creation. Being the first id=0.
Int_t fId = -1; //<

/// The position of the readout plane that defines the origin (0,0) in plane coordinates
TVector3 fPosition = {0, 0, 0}; //<

/// A vector that defines the plane orientation and the side of the active volume.
TVector3 fNormal = {0, 0, 1}; //<

/// A vector contained in the plane that defines the plane X-axis
TVector3 fAxisX; //<

/// A vector contained in the plane that defines the plane Y-axis
TVector3 fAxisY; //<

/// The fraction of charge/energy this readout plane collects from a hit position.
Double_t fChargeCollection = 1; //<

/// A length in mm that confers a 3rd dimension to the readout plane and defines a volume.
Double_t fHeight = 0; //<

/// Rotation (in radians) of the readout plane around the normal vector.
Double_t fRotation = 0; //<

///< A list of TRestDetectorReadoutModule components contained in the readout plane.
std::vector<TRestDetectorReadoutModule> fReadoutModules; //<

void UpdateAxes();

public:
// Setters
/// Sets the planeId. This is done by TRestDetectorReadout during initialization
void SetID(int id) { fPlaneID = id; }
void SetID(int id) { fId = id; }

/// Sets the readout plane position
void SetPosition(const TVector3& position) { fPosition = position; }

/// Sets the cathode plane position. By default is parallel to the readout
/// plane.
void SetCathodePosition(const TVector3& position) { fCathodePosition = position; }

/// Sets the orientation of the readout plane, and defines the side of the
/// active volume.
void SetPlaneVector(const TVector3& vect) { fPlaneVector = vect.Unit(); }
void SetNormal(const TVector3& normal);

/// Sets the value for the charge collection.
void SetChargeCollection(Double_t charge) { fChargeCollection = charge; }

/// Sets the value for the total drift distance
void SetTotalDriftDistance(Double_t d) { fTotalDriftDistance = d; }
void SetHeight(Double_t d);

void SetRotation(Double_t radians);

void SetAxisX(const TVector3& axis);

// Getters
/// Returns an integer with the plane id number.
inline Int_t GetID() const { return fPlaneID; }
inline Int_t GetID() const { return fId; }

/// Returns a TVector3 with the readout plane position
inline TVector3 GetPosition() const { return fPosition; }

/// Returns the rotation angle in radians of the reference frame with respect to the normal vector
Double_t GetRotation() const { return fRotation; }

/// Returns a TVector3 with the cathode position
inline TVector3 GetCathodePosition() const { return fCathodePosition; }
inline TVector3 GetCathodePosition() const { return fPosition + fHeight * fNormal; }

/// Returns a TVector3 with a std::vector normal to the readout plane
inline TVector3 GetPlaneVector() const { return fPlaneVector; }
/// Returns a TVector3 with a vector normal to the readout plane
inline TVector3 GetNormal() const { return fNormal; }

/// Returns a TVector3 with a vector that defines the X-axis plane coordinate system
inline TVector3 GetAxisX() const { return fAxisX; }

/// Returns a TVector3 with a vector that defines the Y-axis plane coordinate system
inline TVector3 GetAxisY() const { return fAxisY; }

/// Returns the charge collection ratio at this readout plane
inline Double_t GetChargeCollection() const { return fChargeCollection; }

/// Returns the total drift distance
inline Double_t GetTotalDriftDistance() const { return fTotalDriftDistance; }
/// Returns the total drift distance. Equivalent to the height of the readout volume.
inline Double_t GetDriftDistance() const { return fHeight; }

/// Returns the perpendicular distance to the readout plane from a given
/// position *pos*.
Double_t GetDistanceTo(TVector3 position);
/// Returns the height of the readout volume.
inline Double_t GetHeight() const { return fHeight; }

/// Returns the perpendicular distance to the readout plane from a given
/// position *x*, *y*, *z*.
Double_t GetDistanceTo(Double_t x, Double_t y, Double_t z);
/// Returns the perpendicular distance to the readout plane from a given position *pos*.
Double_t GetDistanceTo(const TVector3& pos) const;

/// Returns a TVector2 oriented as the shortest distance of a given position
/// *pos* on the plane to a specific module with id *mod*
Expand All @@ -119,18 +127,17 @@ class TRestDetectorReadoutPlane {

/// Returns a pointer to a readout module using its std::vector index
TRestDetectorReadoutModule* GetModule(size_t mod) {
if (mod >= GetNumberOfModules()) return nullptr;
if (mod >= GetNumberOfModules()) {
return nullptr;
}
return &fReadoutModules[mod];
}

/// Returns the total number of modules in the readout plane
size_t GetNumberOfModules() { return fReadoutModules.size(); }

/// Adds a new module to the readout plane
void AddModule(TRestDetectorReadoutModule& rModule) {
fReadoutModules.push_back(rModule);
fNModules++;
}
void AddModule(TRestDetectorReadoutModule& rModule) { fReadoutModules.push_back(rModule); }

/// Prints the readout plane description
void PrintMetadata() { Print(); }
Expand All @@ -145,11 +152,14 @@ class TRestDetectorReadoutPlane {

Bool_t isDaqIDInside(Int_t daqId);

Int_t GetModuleIDFromPosition(TVector3 position);
Int_t GetModuleIDFromPosition(const TVector3& position);

Int_t GetModuleIDFromPosition(Double_t x, Double_t y, Double_t z);

void SetDriftDistance();
TVector2 GetPositionInPlane(const TVector3& point) const;
Double_t GetDistanceToPlane(const TVector3& point) const;

TVector3 GetPositionInWorld(const TVector2& point, Double_t height = 0) const;

void Draw();

Expand All @@ -168,6 +178,6 @@ class TRestDetectorReadoutPlane {
// Destructor
virtual ~TRestDetectorReadoutPlane();

ClassDef(TRestDetectorReadoutPlane, 2);
ClassDef(TRestDetectorReadoutPlane, 5);
};
#endif
19 changes: 18 additions & 1 deletion pipeline/readout/compareFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@
maxN = 2700
n = 0
for line in file_1_text:
if line.rstrip() != file_2_text[n].rstrip():
# We compare only numeric values
numeric_filter_1 = filter(str.isdigit, line.rstrip())
numeric_string_1 = "".join(numeric_filter_1)

if "[32m" in line:
# removing color codes
numeric_string_1 = numeric_string_1[3 : len(numeric_string_1) - 1]

numeric_filter_2 = filter(str.isdigit, file_2_text[n].rstrip())
numeric_string_2 = "".join(numeric_filter_2)

if "[32m" in file_2_text[n].rstrip():
# removing color codes
numeric_string_2 = numeric_string_2[3 : len(numeric_string_2) - 1]

if numeric_string_1 != numeric_string_2:
print("xx:" + numeric_string_1)
print("yy:" + numeric_string_2)
print("XX:" + line.rstrip())
print("YY:" + file_2_text[n].rstrip())
result = 1
Expand Down
Loading