267#include "TRestDetectorReadout.h"
269bool RESTREADOUT_DECODINGFILE_ERROR =
false;
292 std::cout <<
"Loading readout. This might take few seconds" << std::endl;
313 std::cout <<
"Loading readout. This might take few seconds" << std::endl;
359 for (
size_t m = 0; m <
fReadoutPlanes[p].GetNumberOfModules(); m++)
368 for (
unsigned int i = 0; i < fModuleDefinitions.size(); i++)
369 if (fModuleDefinitions[i].GetName() == name)
return i;
396 if (plane[j].GetModuleID() == id) {
408 int planeID = -1, moduleID = -1, channelID = -1;
410 GetPlaneModuleChannel(daqId, planeID, moduleID, channelID);
411 if (channelID >= 0) {
425 RESTWarning <<
"TRestDetectorReadout::GetReadoutPlane." <<
RESTendl;
426 RESTWarning <<
"Readout plane index exceeded." <<
RESTendl;
427 RESTWarning <<
"Index requested : " << p <<
RESTendl;
449 TiXmlElement* moduleDefinition =
GetElement(
"readoutModule");
450 while (moduleDefinition !=
nullptr) {
452 std::cout <<
"------module-----------------" << std::endl;
453 std::cout << moduleDefinition << std::endl;
454 std::cout <<
"-----------------------------" << std::endl;
460 fModuleDefinitions.push_back(module);
464 TiXmlElement* planeDefinition =
GetElement(
"readoutPlane");
465 std::vector<TRestDetectorReadoutModule> moduleVector;
466 Int_t addedChannels = 0;
467 while (planeDefinition !=
nullptr) {
471 plane.
SetPosition(Get3DVectorParameterWithUnits(
"position", planeDefinition));
472 plane.
SetNormal(Get3DVectorParameterWithUnits(
"normal", planeDefinition));
473 plane.
SetHeight(GetDblParameterWithUnits(
"height", planeDefinition));
475 plane.SetRotation(GetDblParameterWithUnits(
"rotation", planeDefinition, 0));
477 moduleVector.clear();
478 TiXmlElement* moduleDefinition =
GetElement(
"addReadoutModule", planeDefinition);
479 while (moduleDefinition !=
nullptr) {
484 RESTError <<
"TRestDetectorReadout at <addReadoutModule>. Module name " << modName
486 RESTError <<
"Please, check spelling" <<
RESTendl;
492 fModuleDefinitions[mid].SetRotation(GetDblParameterWithUnits(
"rotation", moduleDefinition));
495 if (firstDaqChannel == -1) firstDaqChannel = addedChannels;
497 std::string decodingFile =
GetFieldValue(
"decodingFile", moduleDefinition);
498 if (decodingFile ==
"Not defined" || decodingFile.empty() || RESTREADOUT_DECODINGFILE_ERROR)
504 RESTWarning <<
"The decoding file does not exist!" <<
RESTendl;
505 RESTWarning <<
"--------------------------------" <<
RESTendl;
506 RESTWarning <<
"File : " << decodingFile <<
RESTendl;
507 RESTWarning <<
"Default decoding will be used. readoutChannel=daqChannel" <<
RESTendl;
508 RESTWarning <<
"To avoid this message and use the default decoding define : "
511 RESTWarning <<
"--------------------------------" <<
RESTendl;
512 RESTWarning <<
"Press a KEY to continue..." <<
RESTendl;
515 RESTREADOUT_DECODINGFILE_ERROR =
true;
518 std::vector<Int_t> rChannel;
519 std::vector<Int_t> dChannel;
521 FILE* f = fopen(decodingFile.c_str(),
"r");
525 if (fscanf(f,
"%d\t%d\n", &daq, &readout) <= 0) {
526 RESTError <<
"TRestDetectorReadout::InitFromConfigFile. Problem reading decoding"
528 RESTError <<
"This error might need support at REST forum" <<
RESTendl;
534 rChannel.push_back(readout);
535 dChannel.push_back(daq + firstDaqChannel);
542 std::cout <<
"------module-----------------" << std::endl;
543 std::cout << moduleDefinition << std::endl;
544 std::cout <<
"-----------------------------" << std::endl;
549 RESTError <<
"TRestDetectorReadout."
550 <<
" The number of channels defined in the readout is not the same"
551 <<
" as the number of channels found in the decoding." <<
RESTendl;
555 for (
size_t ch = 0; ch < fModuleDefinitions[mid].GetNumberOfChannels(); ch++) {
558 rChannel.push_back(
id);
559 dChannel.push_back(
id + firstDaqChannel);
564 if (!fModuleDefinitions[mid].GetChannel(rChannel[ch])) {
565 RESTError <<
"Problem setting readout channel " << rChannel[ch]
566 <<
" with daq id: " << dChannel[ch] <<
RESTendl;
569 fModuleDefinitions[mid].
GetChannel(rChannel[ch])->SetDaqID(dChannel[ch]);
570 fModuleDefinitions[mid].
GetChannel(rChannel[ch])->SetChannelID(rChannel[ch]);
574 fModuleDefinitions[mid].SetMinMaxDaqIDs();
576 moduleVector.push_back(fModuleDefinitions[mid]);
586 for (
auto& i : moduleVector) {
606 if (pixelTolerance == -1) pixelTolerance = 1.e-6;
608 std::vector<TRestDetectorReadoutChannel> channelVector;
609 std::vector<int> channelIDVector;
610 TiXmlElement* channelDefinition =
GetElement(
"readoutChannel", moduleDefinition);
611 while (channelDefinition !=
nullptr) {
615 if (
id != -1) channelIDVector.push_back(
id);
618 std::vector<TRestDetectorReadoutPixel> pixelVector;
619 std::vector<int> pixelIDVector;
620 TiXmlElement* pixelDefinition =
GetElement(
"addPixel", channelDefinition);
621 while (pixelDefinition !=
nullptr) {
632 pixelVector.push_back(pixel);
637 if (!pixelIDVector.empty() && pixelIDVector.size() != pixelVector.size()) {
639 <<
"pixel id definition may be wrong! It must be coherent and starts from 0. Check your "
640 "readout module definition!"
647 for (Int_t i(0); i < (Int_t)pixelVector.size(); i++) {
648 for (Int_t j(0); j < (Int_t)pixelVector.size(); j++) {
649 if (pixelIDVector[j] == i) {
657 RESTError <<
"pixel id definition may be wrong! check your "
658 "readout module definition!"
663 channelVector.push_back(channel);
667 if (!channelIDVector.empty() && channelIDVector.size() != channelVector.size()) {
668 RESTError <<
"TRestDetectorReadout::ParseModuleDefinition. Channel id definition may be wrong!"
669 <<
"check your readout module definition!" <<
RESTendl;
671 RESTError <<
"channelIDVector size : " << channelIDVector.size() <<
RESTendl;
672 RESTError <<
"channel std::vector size : " << channelVector.size() <<
RESTendl;
679 for (Int_t i(0); i < (Int_t)channelVector.size(); i++) {
680 for (Int_t j(0); j < (Int_t)channelVector.size(); j++) {
681 if (channelIDVector[j] == i) {
689 RESTError <<
"TRestDetectorReadout::ParseModuleDefinition. Channel id definition may be wrong!"
690 <<
"check your readout module definition!" <<
RESTendl;
693 RESTError <<
"channel std::vector size : " << channelVector.size() <<
RESTendl;
706 RESTDebug <<
"--------------------------------------------------" <<
RESTendl;
707 RESTDebug <<
"TRestDetectorReadout::ValidateReadout:: NOT IMPLEMENTED" <<
RESTendl;
708 RESTDebug <<
"This function should crosscheck that there are no repeated "
711 RESTDebug <<
"If any checks are implemented in the future. Those checks should be "
714 RESTDebug <<
"No dead area in the readout module" <<
RESTendl;
715 RESTDebug <<
"And other checks" <<
RESTendl;
716 RESTDebug <<
"--------------------------------------------------" <<
RESTendl;
719void TRestDetectorReadout::GetPlaneModuleChannel(Int_t signalID, Int_t& planeID, Int_t& moduleID,
727 planeID = plane->
GetID();
735Int_t TRestDetectorReadout::GetHitsDaqChannel(
const TVector3& position, Int_t& planeID, Int_t& moduleID,
743 Int_t readoutChannel = mod->
FindChannel({position.X(), position.Y()});
744 if (readoutChannel >= 0) {
745 planeID = plane->
GetID();
747 channelID = readoutChannel;
769 Int_t& channelID, Int_t planeId) {
771 RESTWarning <<
"TRestDetectorReadout. Fail trying to retrieve planeId : " << planeId <<
RESTendl;
780 Int_t readoutChannel = mod->
FindChannel({hitpos.X(), hitpos.Y()});
781 if (readoutChannel >= 0) {
783 channelID = readoutChannel;
795 Int_t planeID, readoutChannel = -1, readoutModule;
796 GetPlaneModuleChannel(signalID, planeID, readoutModule, readoutChannel);
797 if (readoutChannel == -1) {
798 return std::numeric_limits<Double_t>::quiet_NaN();
800 return GetX(planeID, readoutModule, readoutChannel);
808 Int_t planeID, readoutChannel = -1, readoutModule;
809 GetPlaneModuleChannel(signalID, planeID, readoutModule, readoutChannel);
810 if (readoutChannel == -1) {
811 return std::numeric_limits<Double_t>::quiet_NaN();
813 return GetY(planeID, readoutModule, readoutChannel);
841 if (DetailLevel >= 0) {
845 RESTMetadata <<
"Decoding was defined : ";
850 RESTMetadata <<
"-----------------------------------" <<
RESTendl;
852 RESTMetadata <<
"****************************************" <<
RESTendl;
853 std::cout << std::endl;
861 std::cout <<
" TRestDetectorReadout::Draw() is not implemented" << std::endl;
862 std::cout <<
" To draw a TRestDetectorReadout class with name \"readoutName\"";
863 std::cout <<
" stored in a ROOT file \"rootFile.root\"" << std::endl;
864 std::cout <<
" You can use the script : REST_Readout_Viewer( \"rootFile.root\", "
867 std::cout << std::endl;
868 std::cout <<
" Or you can access directly a readout plane and draw using : " << std::endl;
869 std::cout <<
" readout->GetReadoutPlane( 0 )->Draw( ); " << std::endl;
Int_t GetDaqID() const
Returns the corresponding daq channel id.
Int_t GetNumberOfPixels()
Returns the total number of pixels inside the readout channel.
void AddPixel(const TRestDetectorReadoutPixel &pixel)
Adds a new pixel to the readout channel.
void SetDaqID(Int_t id)
Sets the daq channel number id.
Int_t GetChannel(Double_t x, Double_t y)
Gets the channel number corresponding to coordinates (x,y)
void SetSize(const TVector2 &size)
Sets the module size by definition using TVector2 input.
Int_t GetModuleID() const
Returns the module id.
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
Int_t FindChannel(const TVector2 &position)
Returns the channel index corresponding to the absolute coordinates (absX, absY), but relative to the...
void EnableWarnings()
Enables warning output.
void AddChannel(TRestDetectorReadoutChannel &rChannel)
Adds a new channel to the module.
void SetTolerance(Double_t tolerance)
Sets the tolerance for independent pixel overlaps.
void SetName(const std::string &name)
Sets the name of the readout module.
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...
Int_t DaqToReadoutChannel(Int_t daqChannel)
Returns the physical readout channel index for a given daq id channel number.
A class to store the readout pixel definition used in TRestDetectorReadoutChannel.
void SetSize(Double_t sx, Double_t sy)
Sets the size of the pixel using the coordinate values sx,sy.
void SetOrigin(Double_t x, Double_t y)
Sets the origin of the pixel using the coordinate values x,y.
void SetTriangle(Bool_t type)
Sets the type of the pixel.
void SetRotation(Double_t rot)
Sets the rotation angle of the pixel in degrees.
void SetTolerance(Double_t tol)
Sets the value of the tolerance in mm. Used in IsInside method.
TRestDetectorReadoutModule * GetModuleByID(Int_t modID)
Returns a pointer to a module using its internal module id.
void SetPosition(const TVector3 &position)
Sets the readout plane position.
void SetNormal(const TVector3 &normal)
It updates the value of the normal vector and recalculates the corresponding X and Y axis.
void AddModule(TRestDetectorReadoutModule &rModule)
Adds a new module to the readout plane.
void SetChargeCollection(Double_t charge)
Sets the value for the charge collection.
void SetID(int id)
Sets the planeId. This is done by TRestDetectorReadout during initialization.
Double_t GetX(Int_t modID, Int_t chID)
Returns the X coordinate of a given channel in a given module using their internal module and channel...
Double_t GetY(Int_t modID, Int_t chID)
Returns the Y coordinate of a given channel in a given module using their internal module and channel...
size_t GetNumberOfModules()
Returns the total number of modules in the readout plane.
void SetHeight(Double_t d)
Used to define the height of the readout volume with sign crosscheck.
Int_t GetID() const
Returns an integer with the plane id number.
Int_t GetModuleIDFromPosition(const TVector3 &position)
This method returns the module id where pos is found. The z-coordinate must be found in between the c...
A metadata class to generate/store a readout description.
std::vector< TRestDetectorReadoutPlane > fReadoutPlanes
A std::vector storing the TRestDetectorReadoutPlane definitions.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
Int_t GetNumberOfChannels()
Returns the total number of channels implemented in all the readout planes and modules.
~TRestDetectorReadout() override
TRestDetectorReadout default destructor.
Int_t GetHitsDaqChannelAtReadoutPlane(const TVector3 &hitPosition, Int_t &moduleID, Int_t &channelID, Int_t planeId=0)
This method recovers the channel daq id corresponding to the (x,y,z) coordinates given by argument....
TRestDetectorReadoutPlane * GetReadoutPlane(int p)
Returns a pointer to the readout plane by index.
TRestDetectorReadoutPlane * GetReadoutPlaneWithID(int id)
Returns a pointer to the readout plane by ID.
Double_t GetY(Int_t signalID)
It returns the physical Y-coordinate corresponding to a given signal id in plane coordinates.
TRestDetectorReadout()
TRestDetectorReadout default constructor.
void InitFromConfigFile() override
Initializes the readout members using the information given in the TRestDetectorReadout RML section.
Int_t fNReadoutPlanes
Number of readout planes present on the readout.
TRestDetectorReadoutModule * GetReadoutModuleWithID(int id)
Returns a pointer to the readout module by ID.
void AddReadoutPlane(TRestDetectorReadoutPlane plane)
Adds a readout plane to the readout.
Double_t GetX(Int_t signalID)
It returns the physical X-coordinate corresponding to a given signal id in plane coordinates.
Int_t GetNumberOfModules()
Returns the total number of modules implemented in all the readout planes.
TRestDetectorReadoutChannel * GetReadoutChannelWithDaqID(int daqId)
Returns a pointer to the readout channel by daq id.
*TRestDetectorReadoutModule definitions *void ValidateReadout()
This method is not implemented yet. But it could do some checks to help verifying the readout.
void Initialize() override
Initializes the readout members and defines the section name.
Int_t GetModuleDefinitionId(TString name)
Returns the id of the readout module with a given name.
Int_t GetNumberOfReadoutPlanes()
Returns the number of readout planes defined on the readout.
void Draw()
Draws the readout on screen. Not yet implemented.
@ REST_Debug
+show the defined debug messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
Double_t StringToDouble(std::string in)
Gets a double from a string.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.