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

Support arbitrary readout orientation #85

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions inc/TRestDetectorReadout.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class TRestDetectorReadout : public TRestMetadata {
/////////////////////////////////////
TRestDetectorReadoutModule* ParseModuleDefinition(TiXmlElement* moduleDefinition);
void GetPlaneModuleChannel(Int_t daqID, Int_t& planeID, Int_t& moduleID, Int_t& channelID);
Int_t GetHitsDaqChannel(const TVector3& hitPosition, Int_t& planeID, Int_t& moduleID, Int_t& channelID);
Int_t GetHitsDaqChannelAtReadoutPlane(const TVector3& hitPosition, Int_t& moduleID, Int_t& channelID,
Int_t GetHitsDaqChannel(const TVector3& position, Int_t& planeID, Int_t& moduleID, Int_t& channelID);
Int_t GetHitsDaqChannelAtReadoutPlane(const TVector3& position, Int_t& moduleID, Int_t& channelID,
Int_t planeId = 0);
Double_t GetX(Int_t signalID);
Double_t GetY(Int_t signalID);
Expand Down
27 changes: 6 additions & 21 deletions inc/TRestDetectorReadoutModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,13 @@ class TRestDetectorReadoutModule : public TObject {
/// Converts the coordinates given by TVector2 in the readout plane reference
/// system to the readout module reference system.
inline TVector2 TransformToModuleCoordinates(const TVector2& p) {
return TransformToModuleCoordinates(p.X(), p.Y());
}

/// Converts the coordinates (xPhys,yPhys) in the readout plane reference
/// system to the readout module reference system.
inline TVector2 TransformToModuleCoordinates(Double_t xPhys, Double_t yPhys) {
TVector2 coords(xPhys - fModuleOriginX, yPhys - fModuleOriginY);
TVector2 rot = coords.Rotate(-fModuleRotation * TMath::Pi() / 180.);

return rot;
return p - TVector2(fModuleOriginX, fModuleOriginY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rotation has disappeared?

}

/// Converts the coordinates (xMod,yMod) in the readout module reference
/// system to the readout plane reference system.
inline TVector2 TransformToPhysicalCoordinates(Double_t xMod, Double_t yMod) {
TVector2 coords(xMod, yMod);

coords = coords.Rotate(fModuleRotation * TMath::Pi() / 180.);
coords = coords + TVector2(fModuleOriginX, fModuleOriginY);

return coords;
inline TVector2 TransformToReadoutCoordinates(const TVector2& p) {
return p + TVector2(fModuleOriginX, fModuleOriginY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rotation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be TransformToModuleCoordinates and TransformToPlaneCoordinates. The module coordinates define the (0,0) at the left-bottom corner.

}

protected:
Expand Down Expand Up @@ -181,9 +167,7 @@ class TRestDetectorReadoutModule : public TObject {

/// Converts the coordinates given by TVector2 in the readout module reference
/// system to the readout plane reference system.
TVector2 GetPhysicalCoordinates(const TVector2& p) {
return TransformToPhysicalCoordinates(p.X(), p.Y());
}
TVector2 GetPhysicalCoordinates(const TVector2& p) { return TransformToReadoutCoordinates(p); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be GetPlaneCoordinates now.


/// Returns the module name
inline const char* GetName() const override { return fModuleName.Data(); }
Expand Down Expand Up @@ -217,6 +201,7 @@ class TRestDetectorReadoutModule : public TObject {
/// plane are inside this readout module.
///
inline Bool_t isInside(Double_t x, Double_t y) { return isInside({x, y}); }
inline Bool_t isInside(const TVector3& position) const;

Bool_t isInsideChannel(Int_t channel, Double_t x, Double_t y);
Bool_t isInsideChannel(Int_t channel, const TVector2& position);
Expand All @@ -225,7 +210,7 @@ class TRestDetectorReadoutModule : public TObject {
Bool_t isInsidePixel(Int_t channel, Int_t pixel, const TVector2& position);

Bool_t isDaqIDInside(Int_t daqID);
Int_t FindChannel(Double_t x, Double_t y);
Int_t FindChannel(const TVector2& position);
TVector2 GetDistanceToModule(const TVector2& position);

TVector2 GetPixelOrigin(Int_t channel, Int_t pixel);
Expand Down
49 changes: 31 additions & 18 deletions inc/TRestDetectorReadoutPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ class TRestDetectorReadoutPlane : public TObject {
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 definning the plane orientation
///< and the side of the active volume.
TVector3 fCathodePosition; ///< The cathode position which delimites the active
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 fPlaneAxisX; ///< The first coordinate vector of the plane in absolute coordinates.
/// < This vector is contained in the plane and corresponds to the first local
/// coordinate (1,0)
TVector3 fPlaneAxisY; ///< The first coordinate vector of the plane in absolute coordinates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for fPlaneAxisY, this vector is the result of fPlaneAxisX times fPlaneVector.

Also we said to rename them to fAxisY fNormal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Y vector is the second coordinate vector in the plane, it's true that it is redundant as it can be obtained via the cross product (but it's different from the normal).

/// < This vector is contained in the plane and corresponds to the second local
/// coordinate (0,1)
Double_t fPlaneRotationAngle; ///< The angle of rotation of the plane around the planeVector
///< axis. This rotates the planeAxisX and planeAxisY vectors. (degrees)
TVector3 fCathodePosition; ///< The cathode position which delimits the active
///< volume together with the readout plane.
Double_t fChargeCollection; ///< A parameter between 0 and 1 definning how
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.
Expand All @@ -68,15 +76,17 @@ class TRestDetectorReadoutPlane : public TObject {
void SetID(int id) { fPlaneID = id; }

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

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

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

/// Sets the orientation of the readout plane, and defines the side of the active volume.
void SetPlaneRotation(Double_t rotationAngle);

/// Sets the value for the charge collection.
void SetChargeCollection(Double_t charge) { fChargeCollection = charge; }
Expand All @@ -97,6 +107,9 @@ class TRestDetectorReadoutPlane : public TObject {
/// Returns a TVector3 with a std::vector normal to the readout plane
inline TVector3 GetPlaneVector() const { return fPlaneVector; }

/// Returns the plane rotation angle in degrees
inline Double_t GetPlaneRotationAngle() const { return fPlaneRotationAngle; }

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

Expand All @@ -105,18 +118,20 @@ class TRestDetectorReadoutPlane : public TObject {

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

/// 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 a TVector2 oriented as the shortest distance of a given position
/// *pos* on the plane to a specific module with id *mod*
TVector2 GetDistanceToModule(Int_t mod, TVector2 pos) {
TVector2 GetDistanceToModule(Int_t mod, const TVector2& pos) {
return GetModuleByID(mod)->GetDistanceToModule(pos);
}

TVector2 GetPositionInReadoutPlane(const TVector3& position) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be renamed to GetPosition

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now it is not the position, but the projection. So the method could be named GetProjectedCoordinates.


TRestDetectorReadoutModule& operator[](int mod) { return fReadoutModules[mod]; }

/// Returns a pointer to a readout module using its std::vector index
Expand All @@ -143,13 +158,11 @@ class TRestDetectorReadoutPlane : public TObject {

Int_t isZInsideDriftVolume(Double_t z);

Int_t isZInsideDriftVolume(TVector3 pos);
Int_t isZInsideDriftVolume(const TVector3& pos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method must be updated, perhaps now the method should be named IsBetweenCathodeAndReadout


Bool_t isDaqIDInside(Int_t daqId);

Int_t GetModuleIDFromPosition(TVector3 pos);

Int_t GetModuleIDFromPosition(Double_t x, Double_t y, Double_t z);
Int_t GetModuleIDFromPosition(const TVector3& position);

void SetDriftDistance();

Expand All @@ -170,6 +183,6 @@ class TRestDetectorReadoutPlane : public TObject {
// Destructor
virtual ~TRestDetectorReadoutPlane();

ClassDef(TRestDetectorReadoutPlane, 1);
ClassDef(TRestDetectorReadoutPlane, 2);
};
#endif
3 changes: 1 addition & 2 deletions src/TRestDetectorHitsToSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ TRestEvent* TRestDetectorHitsToSignalProcess::ProcessEvent(TRestEvent* inputEven
Int_t channelId = -1;

for (int p = 0; p < fReadout->GetNumberOfReadoutPlanes(); p++) {
Int_t daqId =
fReadout->GetHitsDaqChannelAtReadoutPlane(TVector3(x, y, z), moduleId, channelId, p);
Int_t daqId = fReadout->GetHitsDaqChannelAtReadoutPlane({x, y, z}, moduleId, channelId, p);

TRestDetectorReadoutPlane* plane = fReadout->GetReadoutPlaneWithID(p);

Expand Down
23 changes: 8 additions & 15 deletions src/TRestDetectorReadout.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
/// and the daq channel number defined at the acquisition system.
/// If *no decoding* file is defined the relation between daq and readout
/// channel is assigned *one to one*.
/// The decoding file must be a text file definning two columns with as
/// The decoding file must be a text file defining two columns with as
/// many columns as the number of channels defined in the readout module.
/// The first column is the daq channel number, and the second column is
/// the readout channel defined in the RML file.
Expand Down Expand Up @@ -748,21 +748,13 @@ void TRestDetectorReadout::GetPlaneModuleChannel(Int_t signalID, Int_t& planeID,
}
}

Int_t TRestDetectorReadout::GetHitsDaqChannel(const TVector3& hitpos, Int_t& planeID, Int_t& moduleID,
Int_t TRestDetectorReadout::GetHitsDaqChannel(const TVector3& position, Int_t& planeID, Int_t& moduleID,
Int_t& channelID) {
for (int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
TRestDetectorReadoutPlane* plane = &fReadoutPlanes[p];
int m = plane->GetModuleIDFromPosition(hitpos.X(), hitpos.Y(), hitpos.Z());
int m = plane->GetModuleIDFromPosition(position);
if (m >= 0) {
// TRestDetectorReadoutModule* mod = plane->GetModuleByID(m);
TRestDetectorReadoutModule* mod = plane->GetModuleByID(m);
Int_t readoutChannel = mod->FindChannel(hitpos.X(), hitpos.Y());
if (readoutChannel >= 0) {
planeID = plane->GetID();
moduleID = mod->GetModuleID();
channelID = readoutChannel;
return mod->GetChannel(readoutChannel)->GetDaqID();
}
return GetHitsDaqChannelAtReadoutPlane(position, moduleID, channelID, p);
}
}
return -1;
Expand All @@ -781,7 +773,7 @@ Int_t TRestDetectorReadout::GetHitsDaqChannel(const TVector3& hitpos, Int_t& pla
/// \return the value of the daq id corresponding to the readout channel
//
///
Int_t TRestDetectorReadout::GetHitsDaqChannelAtReadoutPlane(const TVector3& hitpos, Int_t& moduleID,
Int_t TRestDetectorReadout::GetHitsDaqChannelAtReadoutPlane(const TVector3& position, Int_t& moduleID,
Int_t& channelID, Int_t planeId) {
if (planeId > GetNumberOfReadoutPlanes()) {
RESTWarning << "TRestDetectorReadout. Fail trying to retrieve planeId : " << planeId << RESTendl;
Expand All @@ -790,10 +782,11 @@ Int_t TRestDetectorReadout::GetHitsDaqChannelAtReadoutPlane(const TVector3& hitp
}

TRestDetectorReadoutPlane* plane = &fReadoutPlanes[planeId];
int m = plane->GetModuleIDFromPosition(hitpos.X(), hitpos.Y(), hitpos.Z());
int m = plane->GetModuleIDFromPosition(position);
if (m >= 0) {
TRestDetectorReadoutModule* mod = plane->GetModuleByID(m);
Int_t readoutChannel = mod->FindChannel(hitpos.X(), hitpos.Y());
const TVector2 relativePosition = plane->GetPositionInReadoutPlane(position);
Int_t readoutChannel = mod->FindChannel(relativePosition);
if (readoutChannel >= 0) {
moduleID = mod->GetModuleID();
channelID = readoutChannel;
Expand Down
31 changes: 18 additions & 13 deletions src/TRestDetectorReadoutModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ void TRestDetectorReadoutModule::DoReadoutMapping(Int_t nodes) {
for (int j = 0; j < nodes; j++) {
Double_t x = fMapping.GetX(i);
Double_t y = fMapping.GetY(j);
Double_t xAbs = TransformToPhysicalCoordinates(x, y).X();
Double_t yAbs = TransformToPhysicalCoordinates(x, y).Y();
Double_t xAbs = TransformToReadoutCoordinates({x, y}).X();
Double_t yAbs = TransformToReadoutCoordinates({x, y}).Y();

if (!fMapping.isNodeSet(i, j)) {
for (int ch = 0; ch < GetNumberOfChannels() && !fMapping.isNodeSet(i, j); ch++) {
Expand All @@ -198,8 +198,8 @@ void TRestDetectorReadoutModule::DoReadoutMapping(Int_t nodes) {
if (!fMapping.isNodeSet(i, j)) {
Double_t x = fMapping.GetX(i);
Double_t y = fMapping.GetY(j);
Double_t xAbs = TransformToPhysicalCoordinates(x, y).X();
Double_t yAbs = TransformToPhysicalCoordinates(x, y).Y();
Double_t xAbs = TransformToReadoutCoordinates({x, y}).X();
Double_t yAbs = TransformToReadoutCoordinates({x, y}).Y();
cout << "Node NOT SET : " << i << " , " << j << " Mapping x : " << x << " y : " << y << endl;

for (int ch = 0; ch < GetNumberOfChannels(); ch++) {
Expand Down Expand Up @@ -231,11 +231,14 @@ Bool_t TRestDetectorReadoutModule::isDaqIDInside(Int_t daqID) {
/// The readout mapping (see TRestDetectorReadoutMapping) is used to help finding
/// the pixel where coordinates absX and absY fall in.
///
Int_t TRestDetectorReadoutModule::FindChannel(Double_t absX, Double_t absY) {
Int_t TRestDetectorReadoutModule::FindChannel(const TVector2& position) {
const auto& absX = position.X();
const auto& absY = position.Y();

if (!isInside(absX, absY)) return -1;

Double_t x = TransformToModuleCoordinates(absX, absY).X();
Double_t y = TransformToModuleCoordinates(absX, absY).Y();
Double_t x = TransformToModuleCoordinates({absX, absY}).X();
Double_t y = TransformToModuleCoordinates({absX, absY}).Y();

Int_t nodeX = fMapping.GetNodeX(x);
Int_t nodeY = fMapping.GetNodeY(y);
Expand Down Expand Up @@ -325,9 +328,11 @@ Int_t TRestDetectorReadoutModule::FindChannel(Double_t absX, Double_t absY) {
Bool_t TRestDetectorReadoutModule::isInside(const TVector2& position) {
TVector2 rotPos = TransformToModuleCoordinates(position);

if (rotPos.X() >= 0 && rotPos.X() < fModuleSizeX)
if (rotPos.Y() >= 0 && rotPos.Y() < fModuleSizeY) return true;

if (rotPos.X() >= 0 && rotPos.X() < fModuleSizeX) {
if (rotPos.Y() >= 0 && rotPos.Y() < fModuleSizeY) {
return true;
}
}
return false;
}

Expand Down Expand Up @@ -408,7 +413,7 @@ TVector2 TRestDetectorReadoutModule::GetPixelOrigin(Int_t channel, Int_t pixel)
/// \brief Returns any of the pixel vertex position for a given *channel* and
/// *pixel* indexes.
///
/// \param vertex A value between 0-3 definning the vertex position to be
/// \param vertex A value between 0-3 defining the vertex position to be
/// returned
///
TVector2 TRestDetectorReadoutModule::GetPixelVertex(Int_t channel, Int_t pixel, Int_t vertex) {
Expand All @@ -423,7 +428,7 @@ TVector2 TRestDetectorReadoutModule::GetPixelVertex(Int_t channel, Int_t pixel,
/// \brief Returns the center pixel position for a given *channel* and
/// *pixel* indexes.
///
/// \param vertex A value between 0-3 definning the vertex position to be
/// \param vertex A value between 0-3 defining the vertex position to be
/// returned
///
TVector2 TRestDetectorReadoutModule::GetPixelCenter(Int_t channel, Int_t pixel) {
Expand Down Expand Up @@ -474,7 +479,7 @@ Bool_t TRestDetectorReadoutModule::GetPixelTriangle(TRestDetectorReadoutPixel* p
/// physical coordinates relative to the readout plane are returned, including
/// rotation.
///
/// \param n A value between 0-3 definning the vertex position to be returned
/// \param n A value between 0-3 defining the vertex position to be returned
///
TVector2 TRestDetectorReadoutModule::GetVertex(int n) const {
TVector2 vertex(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/TRestDetectorReadoutPixel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TVector2 TRestDetectorReadoutPixel::GetCenter() const {
///////////////////////////////////////////////
/// \brief Returns the specified pixel vertex position
///
/// \param n A value between 0-3 definning the vertex position to be returned.
/// \param n A value between 0-3 defining the vertex position to be returned.
///
TVector2 TRestDetectorReadoutPixel::GetVertex(int n) const {
TVector2 vertex(0, 0);
Expand Down
Loading