Skip to content
Snippets Groups Projects
Commit 4bb4d32b authored by Miha Muskinja's avatar Miha Muskinja
Browse files

User action that sets G4 looper threshold values

parent 76904fc8
No related branches found
No related tags found
9 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!45405updated ART test cron job,!42417Draft: DIRE and VINCIA Base Fragments for Pythia 8.3,!28528Revert 63f845ae,!27054Atr20369 210,!26342Monopole: Handle fractionally charged particles,!20642User action that sets G4 looper threshold values
Showing with 318 additions and 1 deletion
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef G4UserActions_LooperThresholdSet_H
#define G4UserActions_LooperThresholdSet_H
#include "G4UserRunAction.hh"
#include "AthenaBaseComps/AthMessaging.h"
#include "G4Run.hh"
#include "G4ParticleDefinition.hh"
#include "G4Transportation.hh"
#include "G4CoupledTransportation.hh"
#include "G4SystemOfUnits.hh"
namespace G4UA
{
class LooperThresholdSet : public AthMessaging, public G4UserRunAction
{
public:
struct Config
{
double WarningEnergy = 100.0 * CLHEP::MeV;
double ImportantEnergy = 250.0 * CLHEP::MeV;
int NumberOfTrials = 10;
};
LooperThresholdSet( const Config& config );
virtual void BeginOfRunAction( const G4Run* ) override;
private:
Config m_config;
void ChangeLooperParameters( const G4ParticleDefinition* particleDef );
std::pair<G4Transportation*, G4CoupledTransportation*> findTransportation( const G4ParticleDefinition* particleDef );
}; // class LooperThresholdSet
} // namespace G4UA
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef G4USERACTIONS_G4UA_LooperThresholdSetTOOL_H
#define G4USERACTIONS_G4UA_LooperThresholdSetTOOL_H
// System includes
#include <string>
// Infrastructure includes
#include "G4AtlasTools/UserActionToolBase.h"
// Local includes
#include "G4UserActions/LooperThresholdSet.h"
namespace G4UA
{
/// @class LooperThresholdSetTool
/// @brief Tool which manages the Looper Threshold options.
///
/// Create the LooperThresholdSet for each worker thread
///
/// @author Miha Muskinja
///
class LooperThresholdSetTool : public UserActionToolBase<LooperThresholdSet>
{
public:
/// Standard constructor
LooperThresholdSetTool(const std::string& type, const std::string& name,
const IInterface* parent);
virtual StatusCode initialize() override;
virtual StatusCode finalize() override;
protected:
/// Create action for this thread
virtual std::unique_ptr<LooperThresholdSet>
makeAndFillAction(G4AtlasUserActions&) override final;
private:
/// Configuration parameters
LooperThresholdSet::Config m_config;
}; // class LooperThresholdSetTool
} // namespace G4UA
#endif
......@@ -108,3 +108,10 @@ def getRadLengthActionTool(name="G4UA::RadLengthActionTool", **kwargs):
for prop,value in simFlags.UserActionConfig.get_Value()[name].iteritems():
kwargs.setdefault(prop,value)
return CfgMgr.G4UA__RadLengthActionTool(name, **kwargs)
def getLooperThresholdSetTool(name="G4UA::LooperThresholdSetTool", **kwargs):
from G4AtlasApps.SimFlags import simFlags
if name in simFlags.UserActionConfig.get_Value().keys():
for prop,value in simFlags.UserActionConfig.get_Value()[name].iteritems():
kwargs.setdefault(prop,value)
return CfgMgr.G4UA__LooperThresholdSetTool(name, **kwargs)
......@@ -25,4 +25,4 @@ addTool("G4UserActions.G4UserActionsConfig.getScoringPlaneTool", "G4UA::ScoringP
addTool("G4UserActions.G4UserActionsConfig.getRadiationMapsMakerTool", "G4UA::RadiationMapsMakerTool")
addTool("G4UserActions.G4UserActionsConfig.getStoppedParticleActionTool", "G4UA::StoppedParticleActionTool")
addTool("G4UserActions.G4UserActionsConfig.getRadLengthActionTool", "G4UA::RadLengthActionTool")
addTool("G4UserActions.G4UserActionsConfig.getLooperThresholdSetTool", "G4UA::LooperThresholdSetTool")
#########################################################
#
# G4UserActions/preInclude.LooperThresholdSet.py
# @author Miha Muskinja
#
# Sets the looper threshold values in transportation processes
#
#########################################################
from G4AtlasApps.SimFlags import simFlags
simFlags.OptionalUserActionList.addAction('G4UA::LooperThresholdSetTool')
simFlags.UserActionConfig.addConfig('G4UA::LooperThresholdSetTool', 'WarningEnergy', 0)
simFlags.UserActionConfig.addConfig('G4UA::LooperThresholdSetTool', 'ImportantEnergy', 0)
simFlags.UserActionConfig.addConfig('G4UA::LooperThresholdSetTool', 'NumberOfTrials', 10)
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef G4UserActions_LooperThresholdSet_H
#define G4UserActions_LooperThresholdSet_H
#include "G4UserSteppingAction.hh"
#include "AthenaBaseComps/AthMessaging.h"
#include "G4Run.hh"
namespace G4UA
{
/// @brief Kills Monopoles and QBalls with energy < 1 MeV
class LooperThresholdSet : public G4UserSteppingAction, public AthMessaging
{
public:
LooperThresholdSet();
virtual void BeginOfRunAction(const G4Run* aRun) override;
private:
void ChangeLooperParameters(const G4ParticleDefinition* particleDef );
std::pair<G4Transportation*, G4CoupledTransportation*> findTransportation( const G4ParticleDefinition* particleDef, bool reportError );
}; // class LooperThresholdSet
} // namespace G4UA
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "G4UserActions/LooperThresholdSet.h"
#include <iostream>
#include "G4Version.hh"
#include "G4Electron.hh"
#include "G4ProcessManager.hh"
#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IMessageSvc.h"
namespace G4UA
{
//---------------------------------------------------------------------------
LooperThresholdSet::LooperThresholdSet(const Config& config) :
AthMessaging(Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc"), "LooperThresholdSet"),
m_config(config)
{
}
//---------------------------------------------------------------------------
void LooperThresholdSet::BeginOfRunAction(const G4Run*)
{
ChangeLooperParameters( G4Electron::Electron() );
}
void LooperThresholdSet::ChangeLooperParameters(const G4ParticleDefinition* particleDef)
{
if( particleDef == nullptr )
particleDef = G4Electron::Electron();
auto transportPair = findTransportation( particleDef );
auto transport = transportPair.first;
auto coupledTransport = transportPair.second;
if( transport != nullptr )
{
// Change the values of the looping particle parameters of Transportation
ATH_MSG_INFO("Setting looper values of G4Transportation process...");
if( m_config.WarningEnergy >= 0.0 ) {
transport->SetThresholdWarningEnergy( m_config.WarningEnergy );
ATH_MSG_INFO("Set ThresholdWarningEnergy to " << m_config.WarningEnergy);
}
else
ATH_MSG_WARNING("Invalid ThresholdEnergy: " << m_config.WarningEnergy);
if( m_config.ImportantEnergy >= 0.0 ) {
transport->SetThresholdImportantEnergy( m_config.ImportantEnergy );
ATH_MSG_INFO("Set ImportantEnergy to " << m_config.ImportantEnergy);
}
else
ATH_MSG_WARNING("Invalid ImportantEnergy: " << m_config.ImportantEnergy);
if( m_config.NumberOfTrials > 0 ) {
transport->SetThresholdTrials( m_config.NumberOfTrials );
ATH_MSG_INFO("Set NumberOfTrials to " << m_config.NumberOfTrials);
}
else
ATH_MSG_WARNING("Invalid NumberOfTrials: " << m_config.NumberOfTrials);
// Geant4 printout
#if G4VERSION_NUMBER > 1049
transport->ReportLooperThresholds();
#endif
}
else if( coupledTransport != nullptr )
{
// Change the values for Coupled Transport
ATH_MSG_INFO("Setting looper values of G4CoupledTransportation process...");
if( m_config.WarningEnergy >= 0.0 ) {
coupledTransport->SetThresholdWarningEnergy( m_config.WarningEnergy );
ATH_MSG_INFO("Set ThresholdWarningEnergy to " << m_config.WarningEnergy);
}
else
ATH_MSG_WARNING("Invalid ThresholdEnergy: " << m_config.WarningEnergy);
if( m_config.ImportantEnergy >= 0.0 ) {
coupledTransport->SetThresholdImportantEnergy( m_config.ImportantEnergy );
ATH_MSG_INFO("Set ImportantEnergy to " << m_config.ImportantEnergy);
}
else
ATH_MSG_WARNING("Invalid ImportantEnergy: " << m_config.ImportantEnergy);
if( m_config.NumberOfTrials > 0 ) {
coupledTransport->SetThresholdTrials( m_config.NumberOfTrials );
ATH_MSG_INFO("Set NumberOfTrials to " << m_config.NumberOfTrials);
}
else
ATH_MSG_WARNING("Invalid NumberOfTrials: " << m_config.NumberOfTrials);
// Geant4 printout
#if G4VERSION_NUMBER > 1049
transport->ReportLooperThresholds();
#endif
}
}
std::pair<G4Transportation*, G4CoupledTransportation*>
LooperThresholdSet::findTransportation( const G4ParticleDefinition* particleDef )
{
const auto *partPM = particleDef->GetProcessManager();
G4VProcess* partTransport = partPM->GetProcess("Transportation");
auto transport = dynamic_cast<G4Transportation*>(partTransport);
partTransport = partPM->GetProcess("CoupledTransportation");
auto coupledTransport=
dynamic_cast<G4CoupledTransportation*>(partTransport);
return std::make_pair( transport, coupledTransport );
}
} // namespace G4UA
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "G4UserActions/LooperThresholdSetTool.h"
namespace G4UA
{
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
LooperThresholdSetTool::LooperThresholdSetTool(const std::string& type, const std::string& name,
const IInterface* parent) :
UserActionToolBase<LooperThresholdSet>(type, name, parent),
m_config()
{
declareProperty("WarningEnergy", m_config.WarningEnergy);
declareProperty("ImportantEnergy", m_config.ImportantEnergy);
declareProperty("NumberOfTrials", m_config.NumberOfTrials);
}
//---------------------------------------------------------------------------
// Initialize - temporarily here for debugging
//---------------------------------------------------------------------------
StatusCode LooperThresholdSetTool::initialize()
{
ATH_MSG_DEBUG("initialize");
return StatusCode::SUCCESS;
}
StatusCode LooperThresholdSetTool::finalize()
{
ATH_MSG_DEBUG("finalize");
return StatusCode::SUCCESS;
}
//---------------------------------------------------------------------------
// Create the action on request
//---------------------------------------------------------------------------
std::unique_ptr<LooperThresholdSet>
LooperThresholdSetTool::makeAndFillAction(G4AtlasUserActions& actionList)
{
ATH_MSG_DEBUG("Making a LooperThresholdSet action");
auto action = std::make_unique<LooperThresholdSet>(m_config);
actionList.runActions.push_back( action.get() );
return action;
}
}
......@@ -15,6 +15,7 @@
#include "G4UserActions/ScoringPlaneTool.h"
#include "G4UserActions/RadiationMapsMakerTool.h"
#include "G4UserActions/RadLengthActionTool.h"
#include "G4UserActions/LooperThresholdSetTool.h"
#include "../TestActionTool.h"
DECLARE_COMPONENT( G4UA::G4SimTimerTool )
......@@ -34,4 +35,5 @@ DECLARE_COMPONENT( G4UA::FluxRecorderTool )
DECLARE_COMPONENT( G4UA::ScoringPlaneTool )
DECLARE_COMPONENT( G4UA::RadiationMapsMakerTool )
DECLARE_COMPONENT( G4UA::RadLengthActionTool )
DECLARE_COMPONENT( G4UA::LooperThresholdSetTool )
DECLARE_COMPONENT( G4UA::TestActionTool )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment