49#include "TRestDetectorReadoutModule.h"
113 Int_t totalNumberOfPixels = 0;
118 nodes = TMath::Sqrt(totalNumberOfPixels);
122 cout <<
"Performing readout mapping optimization (This might require long "
125 cout <<
"--------------------------------------------------------------------"
128 cout <<
"Total number of pixels : " << totalNumberOfPixels << endl;
129 cout <<
"Nodes : " << nodes << endl;
147 cout <<
"TRestDetectorReadoutModule. WARNING. Node is already SET!!" << endl;
148 cout <<
"Trying to associate channel : " << ch <<
" Pixel : " << px << endl;
149 cout <<
"Pixel coordinates : ( " << xPix <<
" , " << yPix <<
" ) " << endl;
153 RESTWarning <<
"Already associated channel : " << tempCh <<
" pixel : " << tempPix
157 RESTWarning <<
"Pixel coordinates : ( " << xP <<
" , " << yP <<
" ) " << RESTendl;
160 cout <<
"Increasing the number of mapping of nodes may solve this issue." << endl;
167 for (
int i = 0; i < nodes; i++) {
168 printf(
"Completed : %.2lf %%\r", 100. * (i * (Double_t)nodes) / nodes / nodes);
170 for (
int j = 0; j < nodes; j++) {
189 cout <<
"Not all nodes set" << endl;
191 cout <<
"All Nodes set" << endl;
193 for (
int i = 0; i < nodes; i++)
194 for (
int j = 0; j < nodes; j++) {
200 cout <<
"Node NOT SET : " << i <<
" , " << j <<
" Mapping x : " << x <<
" y : " << y << endl;
205 cout <<
"X : " << transformedCoordinates.X() <<
" , "
206 << transformedCoordinates.Y() <<
" Is inside channel : " << ch
207 <<
" pixel : " << px << endl;
240 const auto& x = transformedCoordinates.X();
241 const auto& y = transformedCoordinates.Y();
260 if (xAxis == 1 && forward == 1)
262 else if (xAxis == 0 && forward == 1)
264 else if (xAxis == 1 && forward == 0)
266 else if (xAxis == 0 && forward == 0)
271 if (nodeX < 0) nodeX = nNodes - 1;
272 if (nodeY < 0) nodeY = nNodes - 1;
273 if (nodeX >= nNodes) nodeX = 0;
274 if (nodeY >= nNodes) nodeY = 0;
276 if (count >= repeat) {
277 if (xAxis == 1 && forward == 1) {
280 }
else if (xAxis == 0 && forward == 0) {
284 }
else if (xAxis == 1 && forward == 0) {
287 }
else if (xAxis == 0 && forward == 1) {
299 if (count > totalNodes / 10) {
300 RESTWarning <<
"TRestDetectorReadoutModule. I did not find any channel for hit position (" << x
301 <<
"," << y <<
") in internal module coordinates" << RESTendl;
306 cout <<
"( " << x <<
" , " << y <<
") Should be in channel " << ch
307 <<
" pixel : " << px << endl;
311 cout <<
"Channel : " << ch <<
" Pixel : " << px << endl;
330 if (positionRotated.X() >= 0 && positionRotated.X() <=
fSize.X() && positionRotated.Y() >= 0 &&
331 positionRotated.Y() <=
fSize.Y())
361 if (channel < 0 || pixel < 0)
return false;
377 Double_t dx = 0, dy = 0;
380 else if (
fSize.X() - newPos.X() < 0)
381 dx =
fSize.X() - newPos.X();
385 else if (
fSize.Y() - newPos.Y() < 0)
386 dy =
fSize.Y() - newPos.Y();
388 TVector2 dist = TVector2(dx, dy);
409 pixPosition = pixPosition.Rotate(
fRotation);
410 pixPosition = pixPosition +
fOrigin;
425 pixCenter = pixCenter +
fOrigin;
447 TVector2 pixPosition = pix->
GetVertex(vertex);
448 pixPosition = pixPosition.Rotate(
fRotation);
449 pixPosition = pixPosition +
fOrigin;
456 TVector2 center = (corner1 + corner2) / 2.;
472 TVector2 vertex(0, 0);
473 const TVector2& origin =
fOrigin;
477 else if (n % 4 == 1) {
478 vertex.Set(
fSize.X(), 0);
481 vertex = vertex + origin;
482 }
else if (n % 4 == 2) {
486 vertex = vertex + origin;
487 }
else if (n % 4 == 3) {
488 vertex.Set(0,
fSize.Y());
491 vertex = vertex + origin;
508 if (oX +
fTolerance < 0 || oY + fTolerance < 0 || sX - fTolerance >
fSize.X() ||
511 cout <<
"REST Warning (AddChannel) pixel outside the module boundaries" << endl;
512 cout <<
"Channel: " <<
fReadoutChannel.size() <<
", Pixel : " << i << endl;
513 cout <<
"Pixel origin = (" << oX <<
" , " << oY <<
")" << endl;
514 cout <<
"Pixel size = (" << sX <<
" , " << sY <<
")" << endl;
515 cout <<
"Module size = (" <<
fSize.X() <<
" , " <<
fSize.Y() <<
")" << endl;
532 if (DetailLevel >= 0) {
533 RESTMetadata <<
"-- Readout module : " <<
GetModuleID() << RESTendl;
534 RESTMetadata <<
"----------------------------------------------------------------" << RESTendl;
535 RESTMetadata <<
"-- Origin position : X = " <<
fOrigin.X() <<
" mm "
536 <<
" Y : " <<
fOrigin.Y() <<
" mm" << RESTendl;
537 RESTMetadata <<
"-- Size : X = " <<
fSize.X() <<
" Y : " <<
fSize.Y() << RESTendl;
538 RESTMetadata <<
"-- Rotation : " <<
fRotation *
units(
"degrees") <<
" degrees" << RESTendl;
540 RESTMetadata <<
"-- Tolerance : " <<
fTolerance << RESTendl;
541 RESTMetadata <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << RESTendl;
Int_t GetDaqID() const
Returns the corresponding daq channel id.
Int_t GetNumberOfPixels()
Returns the total number of pixels inside the readout channel.
TRestDetectorReadoutPixel * GetPixel(int n)
Returns a pointer to the pixel n by index.
void Initialize(Int_t nX, Int_t nY, Double_t sX, Double_t sY)
Resets the matrix values and allocates memory for the given net size.
Int_t GetNodeX(Double_t x)
Gets the nodeX index corresponding to the x coordinate.
Int_t GetNodeX_ForChannelAndPixel(Int_t ch, Int_t px)
Finds the node index in X for a given channel and pixel ids.
Double_t GetX(Int_t nodeX)
Gets the X position of node (i,j)
void SetNode(Int_t i, Int_t j, Int_t ch, Int_t pix)
Sets the readout channel and pixel corresponding to a mapping node.
Bool_t AllNodesSet()
Checks if all the nodes in the net have been defined.
Int_t GetNumberOfNodesNotSet()
Returns the number of nodes that have not been initialized.
Bool_t isNodeSet(Int_t i, Int_t j)
Checks if the node (i,j) is defined.
Int_t GetNodeY(Double_t y)
Gets the nodeY index corresponding to the y coordinate.
Int_t GetPixelByNode(Int_t i, Int_t j)
Gets the pixel id corresponding to a given node (i,j)
Double_t GetY(Int_t nodeY)
Gets the Y position of node (i,j)
Int_t GetNumberOfNodesX() const
Returns the number of nodes in X.
Int_t GetNodeY_ForChannelAndPixel(Int_t ch, Int_t px)
Finds the node index in Y for a given channel and pixel ids.
Int_t GetChannelByNode(Int_t i, Int_t j)
Gets the channel id corresponding to a given node (i,j)
Int_t GetNumberOfNodesY() const
Returns the number of nodes in Y.
TRestDetectorReadoutModule()
Default TRestDetectorReadoutModule constructor.
std::vector< TRestDetectorReadoutChannel > fReadoutChannel
Int_t GetModuleID() const
Returns the module id.
TVector2 TransformToPlaneCoordinates(Double_t xMod, Double_t yMod) const
TVector2 GetPixelCenter(Int_t channel, Int_t pixel)
Returns the center pixel position for a given channel and pixel indexes.
Int_t GetMinDaqID() const
Returns the minimum daq id number.
*default REST_Warning in TRestDetectorReadout will enable it *void Initialize()
TRestDetectorReadoutModule initialization.
TVector2 GetSize() const
Returns the module size (x, y) in mm.
TVector2 fOrigin
The module (x, y) position relative to the readout plane position.
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
TVector2 GetPixelOrigin(Int_t channel, Int_t pixel)
Returns the pixel origin (left-bottom) position for a given channel and pixel indexes.
TVector2 fSize
The module (x, y) size. All pixels should be contained within this size.
Bool_t GetPixelTriangle(Int_t channel, Int_t pixel)
Returns the pixel type for a given channel and pixel indexes.
Int_t FindChannel(const TVector2 &position)
Returns the channel index corresponding to the absolute coordinates (absX, absY), but relative to the...
Bool_t isInsidePixel(Int_t channel, Int_t pixel, const TVector2 &position)
Determines if the position TVector2 pos is found at a specific pixel id inside the readout channel gi...
TVector2 GetPixelVertex(Int_t channel, Int_t pixel, Int_t vertex)
Returns any of the pixel vertex position for a given channel and pixel indexes.
void AddChannel(TRestDetectorReadoutChannel &rChannel)
Adds a new channel to the module.
Bool_t isInsideChannel(Int_t channel, Double_t x, Double_t y)
Determines if the position x,y is found in any of the pixels of the readout channel index given.
TVector2 GetVertex(int n) const
Returns the coordinates of the specified vertex index n. The physical coordinates relative to the rea...
Bool_t isInside(const TVector2 &position)
Determines if the position TVector2 pos relative to the readout plane are inside this readout module.
Double_t fRotation
The rotation of the module around the module origin (fModuleOriginX, fModuleOriginY) in radians.
TVector2 TransformToModuleCoordinates(const TVector2 &xyPhysical) const
Int_t GetMaxDaqID() const
Returns the maximum daq id number.
TRestDetectorReadoutMapping fMapping
The readout module uniform grid mapping.
void SetMinMaxDaqIDs()
Initializes the max and min values for the daq channel number.
Int_t fId
The module id given by the readout definition.
virtual ~TRestDetectorReadoutModule()
Default TRestDetectorReadoutModule destructor.
void Draw()
Not implemented.
void Print(Int_t DetailLevel=0)
Prints the module details and channels if fullDetail is enabled.
size_t GetNumberOfChannels() const
Returns the total number of channels defined inside the module.
Bool_t isDaqIDInside(Int_t daqID)
Determines if a given daqID number is in the range of the module.
void DoReadoutMapping(Int_t nodes=0)
Starts the readout mapping initialization. This process is computationally expensive but it greatly o...
std::pair< Int_t, Int_t > fDaqIdRange
The minimum and maximum daq channel ids associated to the module.
TVector2 GetDistanceToModule(const TVector2 &position)
Creates a TVector2 with shortest norm going from the given position pos to the module....
A class to store the readout pixel definition used in TRestDetectorReadoutChannel.
TVector2 GetCenter() const
Returns the center TVector2 position of the pixel.
Bool_t GetTriangle() const
Returns true if the pixel is a triangle.
Bool_t isInside(TVector2 pos)
Determines if a given TVector2 pos coordinates are found inside the pixel. The coordinates are refere...
TVector2 GetVertex(int n) const
Returns the specified pixel vertex position.