diff --git a/src/cosima/inc/MCParameterFile.hh b/src/cosima/inc/MCParameterFile.hh index a6904e26..b3c07c25 100644 --- a/src/cosima/inc/MCParameterFile.hh +++ b/src/cosima/inc/MCParameterFile.hh @@ -124,6 +124,11 @@ public: bool DiscretizeHits() const { return m_DiscretizeHits; } /// Return the watched volumes list vector GetStoreSimulationInfoWatchedVolumes() const { return m_StoreSimulationInfoWatchedVolumes; } + /// Return true if you want to set a maximum number of IA per event (e.g 10000) + bool AllowMaxNbofIAs() const { return m_AllowMaxNbofIAs; } + /// Return the maximum number of IA allowed by event + int MaxNIAs() const { return m_MaxNIAs; } + /// Set the pre-trigger mode (either store everything, only events with hits, or fully pretriggered events) void SetPreTriggerMode(const int PreTriggerMode) { m_PreTriggerMode = PreTriggerMode; } @@ -259,6 +264,12 @@ private: /// The activation time constant: The time during which decays are consindered coincident double m_DetectorTimeConstant; + + ///If you want to set a maximum number of IA + bool m_AllowMaxNbofIAs; + /// Maximum number of IA for an event + int m_MaxNIAs; + }; #endif diff --git a/src/cosima/src/MCEventAction.cc b/src/cosima/src/MCEventAction.cc index f646f166..6bdd2776 100644 --- a/src/cosima/src/MCEventAction.cc +++ b/src/cosima/src/MCEventAction.cc @@ -76,6 +76,10 @@ MCEventAction::MCEventAction(MCParameterFile& RunParameters, const bool Zip, con m_PreTriggerMode = RunParameters.GetPreTriggerMode(); + m_AllowMaxNbofIAs = RunParameters.AllowMaxNbofIAs(); + m_MaxNIAs = RunParameters.MaxNIAs(); + + if (RunParameters.StoreScientific() == true) { m_StoreScientificPrecision = RunParameters.StoreScientificPrecision(); } else { @@ -450,6 +454,19 @@ void MCEventAction::AddIA(G4String ProcessID, if (ProcessID == "ESCP") { AddEnergyLoss(NewKin); } + + + //If the number of IA is too much we abort the event + //This prevent to have event with 50K or even more hits + if(m_AllowMaxNbofIAs==true){ + if(m_Event->GetNIAs() > m_MaxNIAs){ + mdebug<<"Number of IA is > "<ToString()<(G4RunManager::GetRunManager()->GetCurrentEvent())->SetEventAborted(); + m_IsAborted = true; + } + } + } /****************************************************************************** @@ -522,7 +539,7 @@ void MCEventAction::AbortEvent() void MCEventAction::EndOfEventAction(const G4Event* Event) { // Let's store the events... - size_t h; + G4int h; G4String Text; MCRun& Run = m_RunParameters.GetCurrentRun(); diff --git a/src/cosima/src/MCParameterFile.cc b/src/cosima/src/MCParameterFile.cc index 4cdb2ea6..7c582b8c 100644 --- a/src/cosima/src/MCParameterFile.cc +++ b/src/cosima/src/MCParameterFile.cc @@ -74,7 +74,9 @@ MCParameterFile::MCParameterFile() : MParser(' ', true), m_CreateCrossSectionFiles(false), m_CrossSectionFileDirectory(""), m_ActiveRun(0), - m_DetectorTimeConstant(1*ns) + m_DetectorTimeConstant(1*ns), + m_AllowMaxNbofIAs(false), + m_MaxNIAs(1000000) { // Intentionally left blank } @@ -395,6 +397,18 @@ bool MCParameterFile::Parse() " Number of tokens is not correct!"); return false; } + } else if (T->IsTokenAt(0, "AllowMaxNbofIAs", true) == true) { + if (T->GetNTokens() == 3) { + m_AllowMaxNbofIAs = T->GetTokenAtAsBoolean(1); + if (m_AllowMaxNbofIAs == true) { + m_MaxNIAs = T->GetTokenAtAsInt(2); + } + mdebug<<"Allow a maximum number of "<< m_MaxNIAs <<" IA per events : "<<((m_StoreSimulationInfoIonization == true) ? "true" : "false")<IsTokenAt(0, "StoreSimulationInfoWatchedVolumes", true) == true || T->IsTokenAt(0, "StoreSimulationInfoWatchedVolume", true) == true) { if (T->GetNTokens() >= 2) {