51#include "TRestDetectorReadoutModule.h"
52bool RESTREADOUT_DECODINGFILE_ERROR =
false;
126 Int_t totalNumberOfPixels = 0;
135 cout <<
"Performing readout mapping optimization (This might require long "
138 cout <<
"--------------------------------------------------------------------"
141 cout <<
"Total number of pixels : " << totalNumberOfPixels << endl;
160 cout <<
"TRestDetectorReadoutModule. WARNING. Node is already SET!!" << endl;
161 cout <<
"Trying to associate channel : " << ch <<
" Pixel : " << px << endl;
162 cout <<
"Pixel coordinates : ( " << xPix <<
" , " << yPix <<
" ) " << endl;
166 RESTWarning <<
"Already associated channel : " << tempCh <<
" pixel : " << tempPix
170 RESTWarning <<
"Pixel coordinates : ( " << xP <<
" , " << yP <<
" ) " << RESTendl;
173 cout <<
"Increasing the number of mapping of nodes may solve this issue." << endl;
181 printf(
"Completed : %.2lf %%\r",
203 cout <<
"Not all nodes set" << endl;
205 cout <<
"All Nodes set" << endl;
214 cout <<
"Node NOT SET : " << i <<
" , " << j <<
" Mapping x : " << x <<
" y : " << y << endl;
219 cout <<
"X : " << transformedCoordinates.X() <<
" , "
220 << transformedCoordinates.Y() <<
" Is inside channel : " << ch
221 <<
" pixel : " << px << endl;
244 RESTWarning <<
"The decoding file does not exist!" << RESTendl;
245 RESTWarning <<
"--------------------------------" << RESTendl;
247 RESTWarning <<
"Default decoding will be used. readoutChannel=daqChannel" << RESTendl;
248 RESTWarning <<
"To avoid this message and use the default decoding define : "
251 RESTWarning <<
"--------------------------------" << RESTendl;
252 RESTWarning <<
"Press a KEY to continue..." << RESTendl;
255 RESTREADOUT_DECODINGFILE_ERROR =
true;
258 std::vector<std::pair<Int_t, Int_t>> rdChannel;
263 if (fscanf(f,
"%d\t%d\n", &daq, &readout) <= 0) {
264 RESTError <<
"TRestDetectorReadoutModule::UpdateDecoding. Problem reading decoding"
266 RESTError <<
"This error might need support at REST forum" << RESTendl;
279 RESTError <<
"TRestDetectorReadout."
280 <<
" The number of channels defined in the readout is not the same"
281 <<
" as the number of channels found in the decoding." << RESTendl;
293 const auto& [readout, daq] = rdChannel[ch];
295 RESTError <<
"Problem setting readout channel " << readout <<
" with daq id: " << daq << RESTendl;
328 const auto& x = transformedCoordinates.X();
329 const auto& y = transformedCoordinates.Y();
348 if (xAxis == 1 && forward == 1)
350 else if (xAxis == 0 && forward == 1)
352 else if (xAxis == 1 && forward == 0)
354 else if (xAxis == 0 && forward == 0)
359 if (nodeX < 0) nodeX = nNodes - 1;
360 if (nodeY < 0) nodeY = nNodes - 1;
361 if (nodeX >= nNodes) nodeX = 0;
362 if (nodeY >= nNodes) nodeY = 0;
364 if (count >= repeat) {
365 if (xAxis == 1 && forward == 1) {
368 }
else if (xAxis == 0 && forward == 0) {
372 }
else if (xAxis == 1 && forward == 0) {
375 }
else if (xAxis == 0 && forward == 1) {
387 if (count > totalNodes / 10) {
388 RESTWarning <<
"TRestDetectorReadoutModule. I did not find any channel for hit position (" << x
389 <<
"," << y <<
") in internal module coordinates" << RESTendl;
394 cout <<
"( " << x <<
" , " << y <<
") Should be in channel " << ch
395 <<
" pixel : " << px << endl;
399 cout <<
"Channel : " << ch <<
" Pixel : " << px << endl;
418 return (positionRotated.X() >= 0 && positionRotated.X() <=
fSize.X() && positionRotated.Y() >= 0 &&
419 positionRotated.Y() <=
fSize.Y());
441 if (channel < 0 || pixel < 0) {
461 Double_t dx = 0, dy = 0;
462 if (newPos.X() < 0) {
464 }
else if (
fSize.X() - newPos.X() < 0) {
465 dx =
fSize.X() - newPos.X();
467 if (newPos.Y() < 0) {
469 }
else if (
fSize.Y() - newPos.Y() < 0) {
470 dy =
fSize.Y() - newPos.Y();
493 pixPosition = pixPosition.Rotate(
fRotation);
494 pixPosition = pixPosition +
fOrigin;
509 pixCenter = pixCenter +
fOrigin;
531 TVector2 pixPosition = pix->
GetVertex(vertex);
532 pixPosition = pixPosition.Rotate(
fRotation);
533 pixPosition = pixPosition +
fOrigin;
540 TVector2 center = (corner1 + corner2) / 2.;
556 TVector2 vertex(0, 0);
557 const TVector2& origin =
fOrigin;
561 else if (n % 4 == 1) {
562 vertex.Set(
fSize.X(), 0);
565 vertex = vertex + origin;
566 }
else if (n % 4 == 2) {
570 vertex = vertex + origin;
571 }
else if (n % 4 == 3) {
572 vertex.Set(0,
fSize.Y());
575 vertex = vertex + origin;
592 if (oX +
fTolerance < 0 || oY + fTolerance < 0 || sX - fTolerance >
fSize.X() ||
595 cout <<
"REST Warning (AddChannel) pixel outside the module boundaries" << endl;
596 cout <<
"Channel: " <<
fReadoutChannel.size() <<
", Pixel : " << i << endl;
597 cout <<
"Pixel origin = (" << oX <<
" , " << oY <<
")" << endl;
598 cout <<
"Pixel size = (" << sX <<
" , " << sY <<
")" << endl;
599 cout <<
"Module size = (" <<
fSize.X() <<
" , " <<
fSize.Y() <<
")" << endl;
607 if (lastChannel.GetName().empty()) {
608 lastChannel.SetName(fName);
610 if (lastChannel.GetType().empty()) {
611 lastChannel.SetType(fType);
624 if (DetailLevel >= 0) {
625 RESTMetadata <<
"-- Readout module : " <<
GetModuleID() << RESTendl;
626 RESTMetadata <<
"----------------------------------------------------------------" << RESTendl;
627 RESTMetadata <<
"-- Decoding File: " <<
fDecodingFile << RESTendl;
628 RESTMetadata <<
"Decoding was defined : " << (
fDecoding ?
"Yes" :
"No") << RESTendl;
630 RESTMetadata <<
"-- Number of mapping nodes: " <<
fMappingNodes << RESTendl;
631 RESTMetadata <<
"-- Origin position : X = " <<
fOrigin.X() <<
" mm "
632 <<
" Y : " <<
fOrigin.Y() <<
" mm" << RESTendl;
633 RESTMetadata <<
"-- Size : X = " <<
fSize.X() <<
" Y : " <<
fSize.Y() << RESTendl;
634 RESTMetadata <<
"-- Rotation : " <<
fRotation *
units(
"degrees") <<
" degrees" << RESTendl;
636 RESTMetadata <<
"-- Tolerance : " <<
fTolerance << RESTendl;
637 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.
void SetDaqID(Int_t id)
Sets the daq channel number id.
void SetChannelID(Int_t id)
Sets the readout channel number id.
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
void AddChannel(TRestDetectorReadoutChannel &channel)
Adds a new channel to the module.
TVector2 TransformToPlaneCoordinates(const TVector2 &coords) const
Int_t GetModuleID() const
Returns the module id.
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 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.
void Initialize()
TRestDetectorReadoutModule initialization.
*default REST_Warning in TRestDetectorReadout will enable it *Int_t fFirstDaqChannel
First DAQ channel.
TVector2 GetSize() const
Returns the module size (x, y) in mm.
void DoReadoutMapping()
Starts the readout mapping initialization. This process is computationally expensive but it greatly o...
TVector2 fOrigin
The module (x, y) position relative to the readout plane position.
std::string fDecodingFile
Decoding file.
void SetDecodingFile(const std::string &decodingFile)
Set the decoding file in the readout module.
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.
TVector2 TransformToModuleCoordinates(const TVector2 &coords) const
Bool_t GetPixelTriangle(Int_t channel, Int_t pixel)
Returns the pixel type for a given channel and pixel indexes.
Bool_t IsInside(const TVector2 &position) const
Determines if the position x,y relative to the readout plane are inside this readout module.
Int_t FindChannel(const TVector2 &position)
Returns the channel index corresponding to the absolute coordinates (absX, absY), but relative to the...
Bool_t IsInsideChannel(Int_t channel, const TVector2 &position)
Determines if the position TVector2 pos is found in any of the pixels of the readout channel index 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.
TVector2 GetVertex(int n) const
Returns the coordinates of the specified vertex index n. The physical coordinates relative to the rea...
Bool_t IsDaqIDInside(Int_t daqID)
Determines if a given daqID number is in the range of the module.
Double_t fRotation
The rotation of the module around the module origin (fModuleOriginX, fModuleOriginY) in radians.
Int_t fMappingNodes
Number of nodes.
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.
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 IsInside(const TVector2 &pos)
Determines if a given TVector2 pos coordinates are found inside the pixel. The coordinates are refere...
Bool_t GetTriangle() const
Returns true if the pixel is a triangle.
TVector2 GetVertex(int n) const
Returns the specified pixel vertex position.
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.