diff --git a/Simulation/DetSimFastEcal/CMakeLists.txt b/Simulation/DetSimFastEcal/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5b16718ec0642d517058e91803fde28357151992 --- /dev/null +++ b/Simulation/DetSimFastEcal/CMakeLists.txt @@ -0,0 +1,13 @@ + +find_package(Geant4 REQUIRED ui_all vis_all) +include(${Geant4_USE_FILE}) + + +gaudi_add_module(DetSimFastEcal + SOURCES src/EcalFastSimG4Tool.cpp + src/EcalFastSimG4Model.cpp + LINK DetSimInterface + ${DD4hep_COMPONENT_LIBRARIES} + Gaudi::GaudiKernel +) + diff --git a/Simulation/DetSimFastEcal/src/EcalFastSimG4Model.cpp b/Simulation/DetSimFastEcal/src/EcalFastSimG4Model.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8bb1234a75e6c06ce01ff533e48df7c80c9a32e9 --- /dev/null +++ b/Simulation/DetSimFastEcal/src/EcalFastSimG4Model.cpp @@ -0,0 +1,39 @@ +#include "EcalFastSimG4Model.h" + +#include "G4Track.hh" +#include "G4FastTrack.hh" + +EcalFastSimG4Model::EcalFastSimG4Model(G4String aModelName, G4Region* aEnvelope) + : G4VFastSimulationModel(aModelName, aEnvelope) { + +} + +EcalFastSimG4Model::~EcalFastSimG4Model() { + +} + +G4bool EcalFastSimG4Model::IsApplicable(const G4ParticleDefinition& aParticle) { + return aParticle.GetPDGCharge() != 0; +} + +G4bool EcalFastSimG4Model::ModelTrigger(const G4FastTrack& aFastTrack) { + //G4cout << __FILE__ << __LINE__ << ": ModelTrigger." << G4endl; + +// bool istrigged = false; + bool istrigged = true; + // only select the secondaries + const G4Track* track = aFastTrack.GetPrimaryTrack(); + // secondaries +//G4cout << "trackID = " << track->GetTrackID() <<G4endl; +// if (track->GetTrackID() != 0) { +// istrigged = true; +// } +//G4cout << "istrigged = " << istrigged <<G4endl; + return istrigged; +} + +void EcalFastSimG4Model::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastStep) { + //G4cout << __FILE__ << __LINE__ << ": DoIt." << G4endl; + + aFastStep.ProposeTrackStatus(fStopAndKill); +} diff --git a/Simulation/DetSimFastEcal/src/EcalFastSimG4Model.h b/Simulation/DetSimFastEcal/src/EcalFastSimG4Model.h new file mode 100644 index 0000000000000000000000000000000000000000..fc378343cbc47a4eae75be07aaccd5381c53807b --- /dev/null +++ b/Simulation/DetSimFastEcal/src/EcalFastSimG4Model.h @@ -0,0 +1,19 @@ +#ifndef EcalFastSimG4Model_h +#define EcalFastSimG4Model_h + +#include "G4VFastSimulationModel.hh" + +class EcalFastSimG4Model: public G4VFastSimulationModel { +public: + + EcalFastSimG4Model(G4String aModelName, G4Region* aEnvelope); + ~EcalFastSimG4Model(); + + virtual G4bool IsApplicable( const G4ParticleDefinition& aParticle ); + virtual G4bool ModelTrigger( const G4FastTrack& aFastTrack ); + virtual void DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ); + +}; + +#endif + diff --git a/Simulation/DetSimFastEcal/src/EcalFastSimG4Tool.cpp b/Simulation/DetSimFastEcal/src/EcalFastSimG4Tool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ac48086b8bdb4909ca4c98d3c913cc14feecc01 --- /dev/null +++ b/Simulation/DetSimFastEcal/src/EcalFastSimG4Tool.cpp @@ -0,0 +1,41 @@ +#include "EcalFastSimG4Tool.h" + +#include "G4Region.hh" +#include "G4RegionStore.hh" + +#include "G4VFastSimulationModel.hh" +#include "EcalFastSimG4Model.h" + +DECLARE_COMPONENT(EcalFastSimG4Tool); + +StatusCode EcalFastSimG4Tool::initialize() { + StatusCode sc; + + return sc; +} + +StatusCode EcalFastSimG4Tool::finalize() { + StatusCode sc; + + return sc; +} + +bool EcalFastSimG4Tool::CreateFastSimulationModel() { + // In this method: + // * Retrieve the G4Region + // * Create Model + // * Associate model and region + + G4String model_name = "EcalFastSimG4Model"; + for (auto region_name: m_regions.value()) { + G4Region* aEnvelope = G4RegionStore::GetInstance()->GetRegion(region_name); + if (!aEnvelope) { + error() << "Failed to find G4Region '" << region_name << "'" << endmsg; + return false; + } + + EcalFastSimG4Model* model = new EcalFastSimG4Model(model_name+region_name, aEnvelope); + info() << "Create Model " << model_name << " for G4Region " << region_name << endmsg; + } + return true; +} diff --git a/Simulation/DetSimFastEcal/src/EcalFastSimG4Tool.h b/Simulation/DetSimFastEcal/src/EcalFastSimG4Tool.h new file mode 100644 index 0000000000000000000000000000000000000000..4f21f8cfb8124cd42bfcf547d34b044f4ee9026d --- /dev/null +++ b/Simulation/DetSimFastEcal/src/EcalFastSimG4Tool.h @@ -0,0 +1,21 @@ +#ifndef EcalFastSimG4Tool_h +#define EcalFastSimG4Tool_h + +#include "GaudiKernel/AlgTool.h" +#include "DetSimInterface/IFastSimG4Tool.h" + +class EcalFastSimG4Tool: public extends<AlgTool, IFastSimG4Tool> { +public: + using extends::extends; + + StatusCode initialize() override; + StatusCode finalize() override; + + bool CreateFastSimulationModel() override; + +private: + // the regions will be associated with the fast sim model + Gaudi::Property<std::vector<std::string>> m_regions{this, "Regions"}; +}; + +#endif