diff --git a/source/digits_hits/include/GateBuffer.hh b/source/digits_hits/include/GateBuffer.hh index 35218d9c6..64a4e3268 100644 --- a/source/digits_hits/include/GateBuffer.hh +++ b/source/digits_hits/include/GateBuffer.hh @@ -6,59 +6,80 @@ of the GNU Lesser General Public Licence (LGPL) See LICENSE.md for further details ----------------------*/ +// OK GND 2022 + + +/*! \class GateBuffer + \brief GateBuffer mimics the effect of limited transfer rate + + 5/12/2023 added to GND by kochebina@cea.fr + + \sa GateBuffer, GateBufferMessenger +*/ #ifndef GateBuffer_h #define GateBuffer_h 1 +#include "GateVDigitizerModule.hh" +#include "GateDigi.hh" +#include "GateClockDependent.hh" +#include "GateCrystalSD.hh" + #include "globals.hh" -#include -#include -#include "GateVPulseProcessor.hh" -#include "GatePulse.hh" +#include "GateBufferMessenger.hh" +#include "GateSinglesDigitizer.hh" + -class GateBufferMessenger; -class GateVDistribution; -class GateBuffer : public GateVPulseProcessor +class GateBuffer : public GateVDigitizerModule { - public: - typedef unsigned long long int buffer_t; - - GateBuffer(GatePulseProcessorChain* itsChain, - const G4String& itsName=theTypeName) ; - - //! Destructor - virtual ~GateBuffer() ; - - - //! Implementation of the pure virtual method declared by the base class GateDigitizerComponent - //! print-out the attributes specific of the blurring - void SetBufferSize(buffer_t val) { m_bufferSize = val;} - void SetReadFrequency(G4double val) { m_readFrequency = val;} - void SetDoModifyTime(G4bool val) { m_doModifyTime = val;} - void SetMode(G4int val) { m_mode = val;} - void SetDepth(size_t depth); - virtual void DescribeMyself(size_t indent); - - protected: - //! Implementation of the pure virtual method declared by the base class GateVPulseProcessor - //! This methods processes one input-pulse - //! It is is called by ProcessPulseList() for each of the input pulses - //! The result of the pulse-processing is incorporated into the output pulse-list - - virtual void ProcessOnePulse(const GatePulse* inputPulse,GatePulseList& outputPulseList); - private: - buffer_t m_bufferSize; - std::vector m_bufferPos; - buffer_t m_oldClock; - G4double m_readFrequency; - G4bool m_doModifyTime; - G4int m_mode; - std::vector m_enableList; - GateBufferMessenger *m_messenger; //!< Messenger - - static const G4String& theTypeName; //!< Default type-name for all buffers -}; +public: + + typedef unsigned long long int Buffer_t; + + GateBuffer(GateSinglesDigitizer *digitizer, G4String name); + ~GateBuffer(); + + void Digitize() override; + + //! Implementation of the pure virtual method declared by the base class GateDigitizerComponent + //! print-out the attributes specific of the blurring + void SetBufferSize(Buffer_t val) { m_BufferSize = val;} + void SetReadFrequency(G4double val) { m_readFrequency = val;} + void SetDoModifyTime(G4bool val) { m_doModifyTime = val;} + void SetMode(G4int val) { m_mode = val;} + void SetDepth(size_t depth); + + void DescribeMyself(size_t ); + +protected: + Buffer_t m_BufferSize; + std::vector m_BufferPos; + Buffer_t m_oldClock; + G4double m_readFrequency; + G4bool m_doModifyTime; + G4int m_mode; + std::vector m_enableList; + +private: + GateDigi* m_outputDigi; + GateBufferMessenger *m_Messenger; + + GateDigiCollection* m_OutputDigiCollection; + + GateSinglesDigitizer *m_digitizer; + + static const G4String& theTypeName; //!< Default type-name for all Buffers + +}; #endif + + + + + + + + diff --git a/source/digits_hits/include/GateBufferMessenger.hh b/source/digits_hits/include/GateBufferMessenger.hh index 50054edff..abf40d541 100644 --- a/source/digits_hits/include/GateBufferMessenger.hh +++ b/source/digits_hits/include/GateBufferMessenger.hh @@ -6,33 +6,57 @@ of the GNU Lesser General Public Licence (LGPL) See LICENSE.md for further details ----------------------*/ +// OK GND 2022 + +/*! \class GateBufferMessenger + \brief Messenger for the GateBuffer + + + \sa GateBuffer, GateBufferMessenger +*/ + #ifndef GateBufferMessenger_h #define GateBufferMessenger_h 1 -#include "GatePulseProcessorMessenger.hh" +#include "G4UImessenger.hh" +#include "globals.hh" +#include "GateClockDependentMessenger.hh" +class GateBuffer; +class G4UIcmdWithAString; class G4UIdirectory; class G4UIcmdWithADoubleAndUnit; class G4UIcmdWithABool; -class G4UIcmdWithAnInteger; -class GateBuffer; - -class GateBufferMessenger: public GatePulseProcessorMessenger +class GateBufferMessenger : public GateClockDependentMessenger { - public: - GateBufferMessenger(GateBuffer* itsPulseProcessor); - virtual ~GateBufferMessenger(); - - inline void SetNewValue(G4UIcommand* aCommand, G4String aString); - - private: - G4UIcmdWithADoubleAndUnit *m_bufferSizeCmd; //!< set the buffer size - G4UIcmdWithADoubleAndUnit *m_readFrequencyCmd; //!< set the read frequency - G4UIcmdWithABool *m_modifyTimeCmd; //!< does buffer modify the time of pulses - G4UIcmdWithAnInteger *m_setDepthCmd; //!< the depth of each individual buffer - G4UIcmdWithAnInteger *m_setModeCmd; //!< buffer readout mode +public: + + GateBufferMessenger(GateBuffer*); + ~GateBufferMessenger(); + + void SetNewValue(G4UIcommand*, G4String); + + +private: + GateBuffer* m_Buffer; + + G4UIcmdWithADoubleAndUnit *m_BufferSizeCmd; //!< set the Buffer size + G4UIcmdWithADoubleAndUnit *m_readFrequencyCmd; //!< set the read frequency + G4UIcmdWithABool *m_modifyTimeCmd; //!< does Buffer modify the time of pulses + G4UIcmdWithAnInteger *m_setDepthCmd; //!< the depth of each individual Buffer + G4UIcmdWithAnInteger *m_setModeCmd; //!< Buffer readout mode + + }; #endif + + + + + + + + diff --git a/source/digits_hits/src/GateBuffer.cc b/source/digits_hits/src/GateBuffer.cc index 9d89763df..5cec178cc 100644 --- a/source/digits_hits/src/GateBuffer.cc +++ b/source/digits_hits/src/GateBuffer.cc @@ -1,78 +1,178 @@ + /*---------------------- - Copyright (C): OpenGATE Collaboration + Copyright (C): OpenGATE Collaboration -This software is distributed under the terms -of the GNU Lesser General Public Licence (LGPL) -See LICENSE.md for further details -----------------------*/ + This software is distributed under the terms + of the GNU Lesser General Public Licence (LGPL) + See LICENSE.md for further details + ----------------------*/ +/*! + \class GateBuffer -#include "GateBuffer.hh" -#include "G4UnitsTable.hh" + \brief GateBuffer mimics the effect of limited transfer rate -#include "GateApplicationMgr.hh" + 5/12/2023 added to GND by kochebina@cea.fr + + \sa GateBuffer, GateBufferMessenger +*/ + +#include "GateBuffer.hh" #include "GateBufferMessenger.hh" -#include "GateTools.hh" +#include "GateDigi.hh" + +#include "GateDigitizerMgr.hh" #include "GateSystemListManager.hh" -#include "GateVSystem.hh" -#include - -GateBuffer::GateBuffer(GatePulseProcessorChain* itsChain, - const G4String& itsName) - : GateVPulseProcessor(itsChain,itsName) - , m_bufferSize(1) - , m_bufferPos(1) - , m_oldClock(0) - , m_readFrequency(1) - , m_doModifyTime(false) - , m_mode(0) +#include "GateApplicationMgr.hh" + + +#include "G4SystemOfUnits.hh" +#include "G4EventManager.hh" +#include "G4Event.hh" +#include "G4SDManager.hh" +#include "G4DigiManager.hh" +#include "G4ios.hh" +#include "G4UnitsTable.hh" + + + +GateBuffer::GateBuffer(GateSinglesDigitizer *digitizer, G4String name) + :GateVDigitizerModule(name,"digitizerMgr/"+digitizer->GetSD()->GetName()+"/SinglesDigitizer/"+digitizer->m_digitizerName+"/"+name,digitizer,digitizer->GetSD()), + m_BufferSize(1), + m_BufferPos(1), + m_oldClock(0), + m_readFrequency(1), + m_doModifyTime(false), + m_mode(0), + m_outputDigi(0), + m_OutputDigiCollection(0), + m_digitizer(digitizer) + { + G4String colName = digitizer->GetOutputName() ; + collectionName.push_back(colName); + m_Messenger = new GateBufferMessenger(this); + SetDepth(0); + } + + +GateBuffer::~GateBuffer() { - m_messenger = new GateBufferMessenger(this); - SetDepth(0); + delete m_Messenger; + } -GateBuffer::~GateBuffer() + +void GateBuffer::Digitize() { - delete m_messenger; + + G4String digitizerName = m_digitizer->m_digitizerName; + G4String outputCollName = m_digitizer-> GetOutputName(); + + m_OutputDigiCollection = new GateDigiCollection(GetName(),outputCollName); // to create the Digi Collection + + G4DigiManager* DigiMan = G4DigiManager::GetDMpointer(); + + + + GateDigiCollection* IDC = 0; + IDC = (GateDigiCollection*) (DigiMan->GetDigiCollection(m_DCID)); + + GateDigi* inputDigi; + + std::vector< GateDigi* >* OutputDigiCollectionVector = m_OutputDigiCollection->GetVector (); + std::vector::iterator iter; + +/* + if (nVerboseLevel==1) + { + G4cout << "[ GateBuffer::Digitize]: returning output digi-list with " << m_OutputDigiCollection->entries() << " entries\n"; + for (size_t k=0; kentries();k++) + G4cout << *(*IDC)[k] << Gateendl; + G4cout << Gateendl; + } + */ + + GateVSystem* system = GateSystemListManager::GetInstance()->GetSystem(0); + + + + + + if (IDC) + { + G4int n_digi = IDC->entries(); + + //loop over input digits + for (G4int i=0;iGetTime()-GateApplicationMgr::GetInstance()->GetTimeStart())* m_readFrequency); + Buffer_t deltaClocks = (m_oldClockComputeIdFromVolID(inputDigi->GetOutputVolumeID(),m_enableList); + // m_BufferPos[iBuf] = m_BufferPos[iBuf]>deltaClocks ? m_BufferPos[iBuf]-deltaClocks : 0; + switch (m_mode) + { + case 0 : m_BufferPos[iBuf] = m_BufferPos[iBuf]>deltaClocks ? m_BufferPos[iBuf]-deltaClocks : 0; break; + case 1 : if (deltaClocks>0) m_BufferPos[iBuf]=0;break; + } + + // G4cout<<"Using Buffer "< nothing to do\n\n"; + return; + } + StoreDigiCollection(m_OutputDigiCollection); + } + void GateBuffer::SetDepth(size_t depth) { GateVSystem* system = GateSystemListManager::GetInstance()->GetSystem(0); + m_enableList.resize(system->GetTreeDepth()); - if (depth>system->GetTreeDepth()-1) depth=system->GetTreeDepth()-1; - for (size_t i=0;i<=depth;i++) m_enableList[i]=true; - for (size_t i=depth+1;iGetTreeDepth();i++) m_enableList[i]=false; + + if (depth>system->GetTreeDepth()-1) + depth=system->GetTreeDepth()-1; + + for (size_t i=0;i<=depth;i++) + m_enableList[i]=true; + + for (size_t i=depth+1;iGetTreeDepth();i++) + m_enableList[i]=false; + size_t nofElements = system->ComputeNofSubCrystalsAtLevel(0,m_enableList); - m_bufferPos.resize(nofElements); - for (size_t i=0;iGetSystem(0); - buffer_t clock = (buffer_t)( (inputPulse->GetTime()-GateApplicationMgr::GetInstance()->GetTimeStart())* m_readFrequency); - buffer_t deltaClocks = (m_oldClockComputeIdFromVolID(inputPulse->GetOutputVolumeID(),m_enableList); -// m_bufferPos[iBuf] = m_bufferPos[iBuf]>deltaClocks ? m_bufferPos[iBuf]-deltaClocks : 0; - switch (m_mode){ - case 0 : m_bufferPos[iBuf] = m_bufferPos[iBuf]>deltaClocks ? m_bufferPos[iBuf]-deltaClocks : 0; break; - case 1 : if (deltaClocks>0) m_bufferPos[iBuf]=0;break; - } -// G4cout<<"Using buffer "< -#include +#include "G4UIcmdWithAnInteger.hh" +#include "G4UIcmdWithABool.hh" -GateBufferMessenger::GateBufferMessenger(GateBuffer* itsPulseProcessor) - : GatePulseProcessorMessenger(itsPulseProcessor) +GateBufferMessenger::GateBufferMessenger (GateBuffer* Buffer) +:GateClockDependentMessenger(Buffer), + m_Buffer(Buffer) { - G4String guidance; - G4String cmdName; - - cmdName = GetDirectoryName() + "setBufferSize"; - m_bufferSizeCmd= new G4UIcmdWithADoubleAndUnit(cmdName,this); - m_bufferSizeCmd->SetGuidance("Set the buffer size"); - m_bufferSizeCmd->SetUnitCategory("Memory size"); - - cmdName = GetDirectoryName() + "setReadFrequency"; - m_readFrequencyCmd = new G4UIcmdWithADoubleAndUnit(cmdName,this); - m_readFrequencyCmd->SetGuidance("set the buffer read frequency"); - m_readFrequencyCmd->SetUnitCategory("Frequency"); - - cmdName = GetDirectoryName() + "modifyTime"; - m_modifyTimeCmd = new G4UIcmdWithABool(cmdName,this); - m_modifyTimeCmd->SetGuidance("does the buffer modify the time of pulses"); - - cmdName = GetDirectoryName() + "setDepth"; - m_setDepthCmd = new G4UIcmdWithAnInteger(cmdName,this); - m_setDepthCmd->SetGuidance("the depth of each individual buffer"); - - cmdName = GetDirectoryName() + "setMode"; - m_setModeCmd = new G4UIcmdWithAnInteger(cmdName,this); - m_setModeCmd->SetGuidance("How the buffer is read"); - m_setModeCmd->SetParameterName("mode",false); - m_setModeCmd->SetRange("0<=mode<=1"); + G4String guidance; + G4String cmdName; + + cmdName = GetDirectoryName() + "setBufferSize"; + m_BufferSizeCmd= new G4UIcmdWithADoubleAndUnit(cmdName,this); + m_BufferSizeCmd->SetGuidance("Set the Buffer size"); + m_BufferSizeCmd->SetUnitCategory("Memory size"); + + cmdName = GetDirectoryName() + "setReadFrequency"; + m_readFrequencyCmd = new G4UIcmdWithADoubleAndUnit(cmdName,this); + m_readFrequencyCmd->SetGuidance("set the Buffer read frequency"); + m_readFrequencyCmd->SetUnitCategory("Frequency"); + + cmdName = GetDirectoryName() + "modifyTime"; + m_modifyTimeCmd = new G4UIcmdWithABool(cmdName,this); + m_modifyTimeCmd->SetGuidance("does the Buffer modify the time of pulses"); + + cmdName = GetDirectoryName() + "setDepth"; + m_setDepthCmd = new G4UIcmdWithAnInteger(cmdName,this); + m_setDepthCmd->SetGuidance("the depth of each individual Buffer"); + + cmdName = GetDirectoryName() + "setMode"; + m_setModeCmd = new G4UIcmdWithAnInteger(cmdName,this); + m_setModeCmd->SetGuidance("How the Buffer is read"); + m_setModeCmd->SetParameterName("mode",false); + m_setModeCmd->SetRange("0<=mode<=1"); + + + } GateBufferMessenger::~GateBufferMessenger() { - delete m_bufferSizeCmd; - delete m_readFrequencyCmd; - delete m_modifyTimeCmd; - delete m_setDepthCmd; - delete m_setModeCmd; + delete m_BufferSizeCmd; + delete m_readFrequencyCmd; + delete m_modifyTimeCmd; + delete m_setDepthCmd; + delete m_setModeCmd; } -void GateBufferMessenger::SetNewValue(G4UIcommand* command, G4String newValue) +void GateBufferMessenger::SetNewValue(G4UIcommand * aCommand,G4String newValue) { - GateBuffer* Buffer = static_cast(GetNamedObject()); - if (!Buffer) return; - if (command== m_bufferSizeCmd) - { Buffer->SetBufferSize((long long unsigned int) m_bufferSizeCmd->GetNewDoubleValue(newValue)); } - else if (command == m_readFrequencyCmd) - Buffer->SetReadFrequency(m_readFrequencyCmd->GetNewDoubleValue(newValue)); - else if (command == m_modifyTimeCmd) - Buffer->SetDoModifyTime(m_modifyTimeCmd->GetNewBoolValue(newValue)); - else if (command == m_setDepthCmd) - Buffer->SetDepth(m_setDepthCmd->GetNewIntValue(newValue)); - else if (command == m_setModeCmd) - Buffer->SetMode(m_setModeCmd->GetNewIntValue(newValue)); - else - GatePulseProcessorMessenger::SetNewValue(command,newValue); + + if (aCommand == m_BufferSizeCmd) + { + m_Buffer->SetBufferSize((long long unsigned int) m_BufferSizeCmd->GetNewDoubleValue(newValue)); + } + else if (aCommand == m_readFrequencyCmd) + { + m_Buffer->SetReadFrequency(m_readFrequencyCmd->GetNewDoubleValue(newValue)); + } + else if (aCommand == m_modifyTimeCmd) + { + m_Buffer->SetDoModifyTime(m_modifyTimeCmd->GetNewBoolValue(newValue)); + } + else if (aCommand == m_setDepthCmd) + { + m_Buffer->SetDepth(m_setDepthCmd->GetNewIntValue(newValue)); + } + else if (aCommand == m_setModeCmd) + { + m_Buffer->SetMode(m_setModeCmd->GetNewIntValue(newValue)); + } + else + { + GateClockDependentMessenger::SetNewValue(aCommand,newValue); + } } + + + + + + + + + + + + + diff --git a/source/digits_hits/src/GateSinglesDigitizerMessenger.cc b/source/digits_hits/src/GateSinglesDigitizerMessenger.cc index 3cfe8fdb4..54318c57b 100755 --- a/source/digits_hits/src/GateSinglesDigitizerMessenger.cc +++ b/source/digits_hits/src/GateSinglesDigitizerMessenger.cc @@ -42,9 +42,9 @@ See LICENSE.md for further details #include "GateOpticalAdder.hh" #include "GateNoise.hh" #include "GateDigitizerMerger.hh" +#include "GateBuffer.hh" #include "GateIntrinsicResolution.hh" - #include "GateDoIModels.hh" /* #include "GateLocalTimeDelay.hh" @@ -114,7 +114,8 @@ void GateSinglesDigitizerMessenger::SetNewValue(G4UIcommand* command,G4String ne const G4String& GateSinglesDigitizerMessenger::DumpMap() { - static G4String theList = "readout adder energyFraming timeResolution energyResolution spatialResolution efficiency deadtime pileup adderCompton opticaladder noise merger intrinsicResolution doIModels"; + static G4String theList = "readout adder energyFraming timeResolution energyResolution spatialResolution efficiency deadtime pileup adderCompton opticaladder noise merger intrinsicResolution buffer doIModels"; + return theList; } @@ -202,6 +203,13 @@ void GateSinglesDigitizerMessenger::DoInsertion(const G4String& childTypeName) newDM = new GateDigitizerMerger(m_digitizer, DMname); m_digitizer->AddNewModule(newDM); } + + else if (childTypeName=="buffer") + { + newDM = new GateBuffer(m_digitizer, DMname); + m_digitizer->AddNewModule(newDM); + } + else if (childTypeName=="intrinsicResolution") { newDM = new GateIntrinsicResolution(m_digitizer, DMname);