Skip to content
Open
11 changes: 11 additions & 0 deletions src/cosima/inc/MCParameterFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public:
bool DiscretizeHits() const { return m_DiscretizeHits; }
/// Return the watched volumes list
vector<MString> 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; }
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion src/cosima/src/MCEventAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 > "<<m_MaxNIAs<<" Event aborted !"<<endl;
//cout<<m_Event->ToString()<<endl;
const_cast<G4Event*>(G4RunManager::GetRunManager()->GetCurrentEvent())->SetEventAborted();
m_IsAborted = true;
}
}

}

/******************************************************************************
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 15 additions & 1 deletion src/cosima/src/MCParameterFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")<<endl;
} else {
Typo(i, "Cannot parse token AllowMaxNbofIAs correctly:"
" Number of tokens is not correct!");
return false;
}
} else if (T->IsTokenAt(0, "StoreSimulationInfoWatchedVolumes", true) == true ||
T->IsTokenAt(0, "StoreSimulationInfoWatchedVolume", true) == true) {
if (T->GetNTokens() >= 2) {
Expand Down