285#include "TRestDetectorReadout.h"
312 cout <<
"Loading readout. This might take few seconds" << endl;
333 cout <<
"Loading readout. This might take few seconds" << endl;
359 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
371 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
372 for (
size_t m = 0; m <
fReadoutPlanes[p].GetNumberOfModules(); m++) {
383 for (
unsigned int i = 0; i < fModuleDefinitions.size(); i++) {
384 if (fModuleDefinitions[i].GetName() == name) {
395 for (
int i = 0; i < this->GetNumberOfReadoutPlanes(); i++) {
410 for (
int i = 0; i < this->GetNumberOfReadoutPlanes(); i++) {
414 if (plane[j].GetModuleID() == id) {
426 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
427 for (
size_t m = 0; m <
fReadoutPlanes[p].GetNumberOfModules(); m++) {
428 for (
size_t c = 0; c <
fReadoutPlanes[p][m].GetNumberOfChannels(); c++) {
442 if (p < GetNumberOfReadoutPlanes())
445 RESTWarning <<
"TRestDetectorReadout::GetReadoutPlane." <<
RESTendl;
446 RESTWarning <<
"Readout plane index exceeded." <<
RESTendl;
447 RESTWarning <<
"Index requested : " << p <<
RESTendl;
448 RESTWarning <<
"Number of readout planes defined : " << GetNumberOfReadoutPlanes() <<
RESTendl;
468 TiXmlElement* moduleDefinition =
GetElement(
"readoutModule");
469 while (moduleDefinition !=
nullptr) {
471 cout <<
"------module-----------------" << endl;
472 cout << moduleDefinition << endl;
473 cout <<
"-----------------------------" << endl;
480 fModuleDefinitions.push_back(module);
484 TiXmlElement* planeDefinition =
GetElement(
"readoutPlane");
485 Int_t addedChannels = 0;
486 vector<TRestDetectorReadoutModule> moduleVector;
487 while (planeDefinition !=
nullptr) {
490 plane.
SetID(GetNumberOfReadoutPlanes());
491 plane.
SetPosition(Get3DVectorParameterWithUnits(
"position", planeDefinition));
492 plane.
SetNormal(Get3DVectorParameterWithUnits(
"normal", planeDefinition));
493 plane.
SetHeight(GetDblParameterWithUnits(
"height", planeDefinition));
495 plane.SetRotation(GetDblParameterWithUnits(
"rotation", planeDefinition, 0));
496 plane.SetName(
GetParameter(
"name", planeDefinition, plane.GetName()));
497 plane.SetType(
GetParameter(
"type", planeDefinition, plane.GetType()));
499 cout <<
"plane name: " << plane.GetName() << endl;
500 cout <<
"plane type: " << plane.GetType() << endl;
502 moduleVector.clear();
503 TiXmlElement* moduleDefinition =
GetElement(
"addReadoutModule", planeDefinition);
504 while (moduleDefinition !=
nullptr) {
509 RESTError <<
"TRestDetectorReadout at <addReadoutModule>. Module name " << modName
511 RESTError <<
"Please, check spelling" <<
RESTendl;
517 fModuleDefinitions[mid].SetRotation(GetDblParameterWithUnits(
"rotation", moduleDefinition));
521 if (firstDaqChannel == -1) {
522 fModuleDefinitions[mid].SetFirstDaqChannel(addedChannels);
524 fModuleDefinitions[mid].SetFirstDaqChannel(firstDaqChannel);
527 string decodingFile =
GetFieldValue(
"decodingFile", moduleDefinition);
528 fModuleDefinitions[mid].SetDecodingFile(decodingFile);
529 addedChannels += fModuleDefinitions[mid].GetNumberOfChannels();
531 moduleVector.push_back(std::move(fModuleDefinitions[mid]));
541 for (
auto& mod : moduleVector) {
561 if (pixelTolerance == -1) pixelTolerance = 1.e-6;
563 vector<TRestDetectorReadoutChannel> channelVector;
564 vector<int> channelIDVector;
565 TiXmlElement* channelDefinition =
GetElement(
"readoutChannel", moduleDefinition);
566 while (channelDefinition !=
nullptr) {
571 channelIDVector.push_back(
id);
575 const string channelName =
GetFieldValue(
"name", channelDefinition);
576 channel.SetChannelName(channelName);
578 vector<TRestDetectorReadoutPixel> pixelVector;
579 vector<int> pixelIDVector;
580 TiXmlElement* pixelDefinition =
GetElement(
"addPixel", channelDefinition);
581 while (pixelDefinition !=
nullptr) {
592 pixelVector.push_back(pixel);
597 if (!pixelIDVector.empty() && pixelIDVector.size() != pixelVector.size()) {
599 <<
"pixel id definition may be wrong! It must be coherent and starts from 0. Check your "
600 "readout module definition!"
607 for (Int_t i(0); i < (Int_t)pixelVector.size(); i++) {
608 for (Int_t j(0); j < (Int_t)pixelVector.size(); j++) {
609 if (pixelIDVector[j] == i) {
617 RESTError <<
"pixel id definition may be wrong! check your "
618 "readout module definition!"
623 channelVector.push_back(channel);
627 if (!channelIDVector.empty() && channelIDVector.size() != channelVector.size()) {
628 RESTError <<
"TRestDetectorReadout::ParseModuleDefinition. Channel id definition may be wrong!"
629 <<
"check your readout module definition!" <<
RESTendl;
631 RESTError <<
"channelIDVector size : " << channelIDVector.size() <<
RESTendl;
632 RESTError <<
"channel vector size : " << channelVector.size() <<
RESTendl;
639 for (Int_t i(0); i < (Int_t)channelVector.size(); i++) {
640 for (Int_t j(0); j < (Int_t)channelVector.size(); j++) {
641 if (channelIDVector[j] == i) {
649 RESTError <<
"TRestDetectorReadout::ParseModuleDefinition. Channel id definition may be wrong!"
650 <<
"check your readout module definition!" <<
RESTendl;
653 RESTError <<
"channel vector size : " << channelVector.size() <<
RESTendl;
666 RESTDebug <<
"--------------------------------------------------" <<
RESTendl;
667 RESTDebug <<
"TRestDetectorReadout::ValidateReadout:: NOT IMPLEMENTED" <<
RESTendl;
668 RESTDebug <<
"This function should crosscheck that there are no repeated "
671 RESTDebug <<
"If any checks are implemented in the future. Those checks should be "
674 RESTDebug <<
"No dead area in the readout module" <<
RESTendl;
675 RESTDebug <<
"And other checks" <<
RESTendl;
676 RESTDebug <<
"--------------------------------------------------" <<
RESTendl;
679void TRestDetectorReadout::GetPlaneModuleChannel(Int_t signalID, Int_t& planeID, Int_t& moduleID,
681 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
687 planeID = plane->
GetID();
695Int_t TRestDetectorReadout::GetHitsDaqChannel(
const TVector3& position, Int_t& planeID, Int_t& moduleID,
697 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
703 Int_t readoutChannel = mod->
FindChannel({position.X(), position.Y()});
704 if (readoutChannel >= 0) {
705 planeID = plane->
GetID();
707 channelID = readoutChannel;
729 const TVector3& position, Int_t planeId) {
730 if (planeId > GetNumberOfReadoutPlanes()) {
731 RESTWarning <<
"TRestDetectorReadout. Fail trying to retrieve planeId : " << planeId <<
RESTendl;
732 RESTWarning <<
"Number of readout planes: " << GetNumberOfReadoutPlanes() <<
RESTendl;
733 return std::make_tuple(-1, -1, -1);
738 Int_t channelID = -1;
746 int channelIndex = -1;
752 channelIndex = mod->
FindChannel({position.X(), position.Y()});
755 if (channel !=
nullptr) {
757 channelID = channelIndex;
762 if (daqIds.empty()) {
763 return std::make_tuple(-1, -1, -1);
764 }
else if (daqIds.size() == 1) {
765 Int_t daqId = *daqIds.begin();
766 return std::make_tuple(daqId, moduleID, channelID);
768 cerr <<
"TRestDetectorReadout::GetHitsDaqChannelAtReadoutPlane. More than one daq channel found for "
769 "the given position. This means there is a problem with the readout definition."
780 Int_t planeID, readoutChannel = -1, readoutModule;
781 GetPlaneModuleChannel(signalID, planeID, readoutModule, readoutChannel);
782 if (readoutChannel == -1) {
783 return std::numeric_limits<Double_t>::quiet_NaN();
785 return GetX(planeID, readoutModule, readoutChannel);
793 Int_t planeID, readoutChannel = -1, readoutModule;
794 GetPlaneModuleChannel(signalID, planeID, readoutModule, readoutChannel);
795 if (readoutChannel == -1) {
796 return std::numeric_limits<Double_t>::quiet_NaN();
798 return GetY(planeID, readoutModule, readoutChannel);
826 if (DetailLevel >= 0) {
829 RESTMetadata <<
"Number of readout planes : " << GetNumberOfReadoutPlanes() <<
RESTendl;
830 RESTMetadata <<
"-----------------------------------" <<
RESTendl;
831 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
834 RESTMetadata <<
"****************************************" <<
RESTendl;
843 cout <<
" TRestDetectorReadout::Draw() is not implemented" << endl;
844 cout <<
" To draw a TRestDetectorReadout class with name \"readoutName\"";
845 cout <<
" stored in a ROOT file \"rootFile.root\"" << endl;
846 cout <<
" You can use the script : REST_Readout_Viewer( \"rootFile.root\", "
850 cout <<
" Or you can access directly a readout plane and draw using : " << endl;
851 cout <<
" readout->GetReadoutPlane( 0 )->Draw( ); " << endl;
859 TFile* f = TFile::Open(fileName.c_str(),
"UPDATE");
863 RESTWarning <<
"Can only export readout as a root file, skipping..." <<
RESTendl;
868 std::vector<int> daqIds;
869 for (
int planeIndex = 0; planeIndex < GetNumberOfReadoutPlanes(); planeIndex++) {
876 daqIds.push_back(daqId);
880 if (daqIds.empty()) {
882 }
else if (daqIds.size() == 1) {
885 cerr <<
"TRestDetectorReadout::GetDaqId. More than one daq channel found for "
886 "the given position. This means there is a problem with the readout definition."
892set<Int_t> TRestDetectorReadout::GetAllDaqIds() {
895 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
896 for (
size_t m = 0; m <
fReadoutPlanes[p].GetNumberOfModules(); m++) {
897 for (
size_t c = 0; c <
fReadoutPlanes[p][m].GetNumberOfChannels(); c++) {
907string TRestDetectorReadout::GetTypeForChannelDaqId(Int_t daqId) {
908 for (
int p = 0; p < GetNumberOfReadoutPlanes(); p++) {
909 for (
size_t m = 0; m <
fReadoutPlanes[p].GetNumberOfModules(); m++) {
910 for (
size_t c = 0; c <
fReadoutPlanes[p][m].GetNumberOfChannels(); c++) {
std::string GetType() const
Returns the channel type.
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.
void SetSize(const TVector2 &size)
Sets the module size by definition using TVector2 input.
void AddChannel(TRestDetectorReadoutChannel &channel)
Adds a new channel to the module.
Int_t GetModuleID() const
Returns the module id.
void SetMappingNodes(Int_t nodes)
Sets number of nodes.
void DoReadoutMapping()
Starts the readout mapping initialization. This process is computationally expensive but it greatly o...
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.
Bool_t IsDaqIDInside(Int_t daqID)
Determines if a given daqID number is in the range of 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.
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 SetOrigin(const TVector2 &origin)
Sets the origin of the pixel using a TVector2.
void SetSize(const TVector2 &size)
Sets the size of the pixel using a TVector2.
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.
Int_t GetModuleIDFromPosition(const TVector3 &position) const
This method returns the module id where pos is found. The z-coordinate must be found in between the c...
void SetChargeCollection(Double_t charge)
Sets the value for the charge collection.
size_t GetNumberOfModules() const
Returns the total number of modules in the readout plane.
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...
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.
void AddModule(const TRestDetectorReadoutModule &module)
Adds a new module to the readout plane.
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.
void AddReadoutPlane(const TRestDetectorReadoutPlane &plane)
Adds a readout plane to the readout.
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.
void Export(const std::string &fileName)
Export readout to a root file.
TRestDetectorReadoutModule * GetReadoutModuleWithID(int id)
Returns a pointer to the readout module by ID.
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.
std::tuple< Int_t, Int_t, Int_t > GetHitsDaqChannelAtReadoutPlane(const TVector3 &position, Int_t planeId=0)
Returns a tuple with the DaqID, ModuleID, ChannelID.
TRestDetectorReadoutChannel * GetReadoutChannelWithDaqID(int daqId)
Returns a pointer to the readout channel by daq id.
void Initialize() override
Initializes the readout members and defines the section name.
*TRestDetectorReadoutModule definitions *void ValidateReadout() const
This method is not implemented yet. But it could do some checks to help verifying the readout.
void Draw()
Draws the readout on screen. Not yet implemented.
Int_t GetModuleDefinitionId(const TString &name)
Returns the id of the readout module with a given name.
Int_t GetDaqId(const TVector3 &position, bool check=true)
Returns the DaqID of the channel for position. If no channel is found returns -1.
@ 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.