diff --git a/inc/TRestDetectorReadout.h b/inc/TRestDetectorReadout.h index 78855fc5..1947405b 100644 --- a/inc/TRestDetectorReadout.h +++ b/inc/TRestDetectorReadout.h @@ -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); diff --git a/inc/TRestDetectorReadoutModule.h b/inc/TRestDetectorReadoutModule.h index 0a49d646..8f0e1e8e 100644 --- a/inc/TRestDetectorReadoutModule.h +++ b/inc/TRestDetectorReadoutModule.h @@ -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); } /// 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); } protected: @@ -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); } /// Returns the module name inline const char* GetName() const override { return fModuleName.Data(); } @@ -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); @@ -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); diff --git a/inc/TRestDetectorReadoutPlane.h b/inc/TRestDetectorReadoutPlane.h index 09f6f0f6..7aefe27d 100644 --- a/inc/TRestDetectorReadoutPlane.h +++ b/inc/TRestDetectorReadoutPlane.h @@ -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. + /// < 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. @@ -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; } @@ -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; } @@ -105,7 +118,7 @@ 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*. @@ -113,10 +126,12 @@ class TRestDetectorReadoutPlane : public TObject { /// 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; + TRestDetectorReadoutModule& operator[](int mod) { return fReadoutModules[mod]; } /// Returns a pointer to a readout module using its std::vector index @@ -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); 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(); @@ -170,6 +183,6 @@ class TRestDetectorReadoutPlane : public TObject { // Destructor virtual ~TRestDetectorReadoutPlane(); - ClassDef(TRestDetectorReadoutPlane, 1); + ClassDef(TRestDetectorReadoutPlane, 2); }; #endif diff --git a/src/TRestDetectorHitsToSignalProcess.cxx b/src/TRestDetectorHitsToSignalProcess.cxx index 9179c865..3fd3c30c 100644 --- a/src/TRestDetectorHitsToSignalProcess.cxx +++ b/src/TRestDetectorHitsToSignalProcess.cxx @@ -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); diff --git a/src/TRestDetectorReadout.cxx b/src/TRestDetectorReadout.cxx index 3f3ec4fe..a12acbdb 100644 --- a/src/TRestDetectorReadout.cxx +++ b/src/TRestDetectorReadout.cxx @@ -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. @@ -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; @@ -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; @@ -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; diff --git a/src/TRestDetectorReadoutModule.cxx b/src/TRestDetectorReadoutModule.cxx index 920e0bc6..d78d38d8 100644 --- a/src/TRestDetectorReadoutModule.cxx +++ b/src/TRestDetectorReadoutModule.cxx @@ -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++) { @@ -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++) { @@ -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); @@ -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; } @@ -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) { @@ -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) { @@ -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); diff --git a/src/TRestDetectorReadoutPixel.cxx b/src/TRestDetectorReadoutPixel.cxx index 591f55e3..a0421633 100644 --- a/src/TRestDetectorReadoutPixel.cxx +++ b/src/TRestDetectorReadoutPixel.cxx @@ -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); diff --git a/src/TRestDetectorReadoutPlane.cxx b/src/TRestDetectorReadoutPlane.cxx index 6fc4fb3b..1cc60818 100644 --- a/src/TRestDetectorReadoutPlane.cxx +++ b/src/TRestDetectorReadoutPlane.cxx @@ -61,9 +61,13 @@ TRestDetectorReadoutPlane::~TRestDetectorReadoutPlane() {} /// \brief TRestDetectorReadoutPlane initialization /// void TRestDetectorReadoutPlane::Initialize() { - fCathodePosition = TVector3(0, 0, 0); - fPosition = TVector3(0, 0, 0); - fPlaneVector = TVector3(0, 0, 0); + fCathodePosition = {0, 0, 0}; + fPosition = {0, 0, 0}; + fPlaneVector = {0, 0, 1}; + + fPlaneAxisX = {1, 0, 0}; + fPlaneAxisY = {0, 1, 0}; + fPlaneRotationAngle = 0; fNModules = 0; fReadoutModules.clear(); @@ -86,6 +90,37 @@ void TRestDetectorReadoutPlane::SetDriftDistance() { this->SetTotalDriftDistance(tDriftDistance); } +void TRestDetectorReadoutPlane::SetPlaneVector(const TVector3& planeVector) { + fPlaneVector = planeVector; + fPlaneVector = fPlaneVector.Unit(); + + // if the plane vector does not have the correct direction: from anode to cathode, we flip it + + const TVector3 direction = fCathodePosition - fPosition; + if (fPlaneVector.Dot(direction) < 0) { + fPlaneVector *= -1; + RESTWarning << "Plane vector was flipped to point from anode to cathode" << RESTendl; + } + + // rotate the axis X and Y of the plane + + fPlaneAxisX.RotateUz(fPlaneVector); + fPlaneAxisY.RotateUz(fPlaneVector); +} + +/////////////////////////////////////////////// +/// \brief Sets the plane rotation in degrees +/// +void TRestDetectorReadoutPlane::SetPlaneRotation(Double_t rotationAngle) { + fPlaneRotationAngle = rotationAngle; // in degrees + // rotate the axis X and Y of the plane + fPlaneAxisX = {1, 0, 0}; + fPlaneAxisY = {0, 1, 0}; + + fPlaneAxisX.Rotate(fPlaneRotationAngle * TMath::DegToRad(), fPlaneVector); + fPlaneAxisY.Rotate(fPlaneRotationAngle * TMath::DegToRad(), fPlaneVector); +} + /////////////////////////////////////////////// /// \brief Returns a pointer to a module using its internal module id /// @@ -155,7 +190,7 @@ Double_t TRestDetectorReadoutPlane::GetX(Int_t modID, Int_t chID) { if (deltaY < deltaX) x = rModule->GetPixelCenter(chID, 0).X(); } } else { - // we choose to ouput x only when deltaY > deltaX under non-90 deg rotation + // we choose to output x only when deltaY > deltaX under non-90 deg rotation // otherwise it is a y channel and should return nan if (deltaY > deltaX) x = rModule->GetPixelCenter(chID, 0).X(); } @@ -225,7 +260,7 @@ Double_t TRestDetectorReadoutPlane::GetY(Int_t modID, Int_t chID) { if (deltaY > deltaX) y = rModule->GetPixelCenter(chID, 0).Y(); } } else { - // we choose to ouput y only when deltaY < deltaX under non-90 deg rotation + // we choose to output y only when deltaY < deltaX under non-90 deg rotation // otherwise it is a x channel and should return nan if (deltaY < deltaX) y = rModule->GetPixelCenter(chID, 0).Y(); } @@ -250,7 +285,7 @@ Int_t TRestDetectorReadoutPlane::FindChannel(Int_t module, Double_t absX, Double // FindChannel will take a long time to search for the channel if it is not // there. It will be faster - return fReadoutModules[module].FindChannel(modX, modY); + return fReadoutModules[module].FindChannel({modX, modY}); } /////////////////////////////////////////////// @@ -265,7 +300,7 @@ Double_t TRestDetectorReadoutPlane::GetDistanceTo(Double_t x, Double_t y, Double /// \brief Returns the perpendicular distance to the readout plane of a given /// TVector3 position /// -Double_t TRestDetectorReadoutPlane::GetDistanceTo(TVector3 pos) { +Double_t TRestDetectorReadoutPlane::GetDistanceTo(const TVector3& pos) { return (pos - GetPosition()).Dot(GetPlaneVector()); } @@ -291,7 +326,9 @@ Int_t TRestDetectorReadoutPlane::isZInsideDriftVolume(Double_t z) { /// Bool_t TRestDetectorReadoutPlane::isDaqIDInside(Int_t daqId) { for (int m = 0; m < GetNumberOfModules(); m++) - if (fReadoutModules[m].isDaqIDInside(daqId)) return true; + if (fReadoutModules[m].isDaqIDInside(daqId)) { + return true; + } return false; } @@ -300,12 +337,12 @@ Bool_t TRestDetectorReadoutPlane::isDaqIDInside(Int_t daqId) { /// \brief This method determines if the z-coordinate is inside the drift volume /// for this readout plane. /// -/// \param pos A TVector3 definning the position. +/// \param pos A TVector3 defining the position. /// /// \return 1 if the Z-position is found inside the drift volume definition. 0 /// otherwise /// -Int_t TRestDetectorReadoutPlane::isZInsideDriftVolume(TVector3 pos) { +Int_t TRestDetectorReadoutPlane::isZInsideDriftVolume(const TVector3& pos) { TVector3 posNew = TVector3(pos.X() - fPosition.X(), pos.Y() - fPosition.Y(), pos.Z()); Double_t distance = GetDistanceTo(posNew); @@ -321,35 +358,34 @@ Int_t TRestDetectorReadoutPlane::isZInsideDriftVolume(TVector3 pos) { /// the readout plane. The *x* and *y* values must be found inside one of the /// readout modules defined inside the readout plane. /// -/// \param x,y,z Three Double_t definning the position. +/// \param x,y,z Three Double_t defining the position. /// /// \return the module *id* where the hit is found. If no module *id* is found /// it returns -1. /// -Int_t TRestDetectorReadoutPlane::GetModuleIDFromPosition(Double_t x, Double_t y, Double_t z) { - TVector3 pos = TVector3(x, y, z); - return GetModuleIDFromPosition(pos); -} /////////////////////////////////////////////// /// \brief This method returns the module id where *pos* is found. /// The z-coordinate must be found in between /// the cathode and the readout plane. The *x* and *y* values must be found /// inside one of the readout modules defined inside the readout plane. /// -/// \param pos A TVector3 definning the position. +/// \param position A TVector3 defining the position. /// /// \return the module *id* where the hit is found. If no module *id* is found /// it returns -1. /// -Int_t TRestDetectorReadoutPlane::GetModuleIDFromPosition(TVector3 pos) { - TVector3 posNew = TVector3(pos.X() - fPosition.X(), pos.Y() - fPosition.Y(), pos.Z()); +Int_t TRestDetectorReadoutPlane::GetModuleIDFromPosition(const TVector3& position) { + TVector3 posNew = TVector3(position.X() - fPosition.X(), position.Y() - fPosition.Y(), position.Z()); Double_t distance = GetDistanceTo(posNew); if (distance > 0 && distance < fTotalDriftDistance) { - for (int m = 0; m < GetNumberOfModules(); m++) - if (fReadoutModules[m].isInside(posNew.X(), posNew.Y())) return fReadoutModules[m].GetModuleID(); + for (auto& module : fReadoutModules) { + if (module.isInside(posNew.X(), posNew.Y())) { + return module.GetModuleID(); + } + } } return -1; @@ -370,13 +406,19 @@ void TRestDetectorReadoutPlane::Print(Int_t DetailLevel) { RESTMetadata << "-- Cathode Position : X = " << fCathodePosition.X() << " mm, " << " Y : " << fCathodePosition.Y() << " mm, Z : " << fCathodePosition.Z() << " mm" << RESTendl; + RESTMetadata << "-- Local X axis vector (1,0) in 3d space : X = " << fPlaneAxisX.X() + << " mm, Y : " << fPlaneAxisX.Y() << " mm, Z : " << fPlaneAxisX.Z() << " mm" << RESTendl; + RESTMetadata << "-- Local Y axis vector (0,1) in 3d space : X = " << fPlaneAxisY.X() + << " mm, Y : " << fPlaneAxisY.Y() << " mm, Z : " << fPlaneAxisY.Z() << " mm" << RESTendl; RESTMetadata << "-- Total drift distance : " << fTotalDriftDistance << " mm" << RESTendl; RESTMetadata << "-- Charge collection : " << fChargeCollection << RESTendl; RESTMetadata << "-- Total modules : " << GetNumberOfModules() << RESTendl; RESTMetadata << "-- Total channels : " << GetNumberOfChannels() << RESTendl; RESTMetadata << "----------------------------------------------------------------" << RESTendl; - for (int i = 0; i < GetNumberOfModules(); i++) fReadoutModules[i].Print(DetailLevel - 1); + for (int i = 0; i < GetNumberOfModules(); i++) { + fReadoutModules[i].Print(DetailLevel - 1); + } } } @@ -447,3 +489,10 @@ void TRestDetectorReadoutPlane::GetBoundaries(double& xmin, double& xmax, double } } } + +/////////////////////////////////////////////// +/// \brief Returns the position of the point in the local coordinates of the plane +/// +TVector2 TRestDetectorReadoutPlane::GetPositionInReadoutPlane(const TVector3& position) const { + return {position.Dot(fPlaneAxisX), fPosition.Dot(fPlaneAxisX)}; +}