From 813745fed746bc2afcb7930bf5c66a2d310c6290 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 25 Nov 2020 18:49:25 +0100
Subject: [PATCH 01/24] Fast Simulation 1st draft

---
 .../GiGaMTFactories/GiGaMTFastSimModelFAC.h   | 32 ++++++++++++++
 .../src/det/GiGaMTDetectorConstructionFAC.cpp |  9 ++++
 .../src/det/GiGaMTDetectorConstructionFAC.h   |  6 +++
 .../src/phys/GiGaMTFastSimPhysFAC.cpp         | 44 +++++++++++++++++++
 4 files changed, 91 insertions(+)
 create mode 100644 Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
 create mode 100644 Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp

diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
new file mode 100644
index 00000000..9117aecb
--- /dev/null
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "GiGaMTFactories/GiGaFactoryBase.h"
+#include "GiGaMTFactories/GiGaTool.h"
+#include "Geant4/G4VFastSimulationModel.hh"
+#include "Geant4/G4RegionStore.hh"
+
+template <typename FastSimModel>
+class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSimulationModel>>
+{
+  static_assert( std::is_base_of<G4VFastSimulationModel, FastSimModel>::value );
+
+    public:
+  
+  using extends::extends;
+  G4VFastSimulationModel* construct() const override
+  {
+    
+    debug() << "Loading fast simulation region " << m_region.value() << endmsg; 
+    G4Region* region = G4RegionStore::GetInstance()->GetRegion( m_region.value() );
+
+    debug() << "Loading Fast Sim Model " << m_model.value() << endmsg; 
+    auto tmp = new FastSimModel{m_model.value(), region};
+    tmp->SetMessageInterface(message_interface());
+    debug() << "Loaded Fast Sim Model " << m_model.value() << endmsg; 
+    return tmp;
+  }
+
+  Gaudi::Property<std::string> m_region {this, "RegionName", ""};
+  Gaudi::Property<std::string> m_model {this, "ModelName", ""};
+};
+
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
index 1d4d6cf3..a1ac448d 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
@@ -26,6 +26,7 @@ G4VUserDetectorConstruction* GiGaMTDetectorConstructionFAC::construct() const {
     debug() << "Calling SD and Field constructor" << endmsg;
     m_geoSvc->constructSDandField();
     DressVolumes();
+    BuildFastModels();
   } );
 
   return detconst;
@@ -52,6 +53,14 @@ void GiGaMTDetectorConstructionFAC::DressVolumes() const {
   }
 }
 
+void GiGaMTDetectorConstructionFAC::BuildFastModels() const {
+    for(auto& fastModelName : m_fastModelConstrs) {
+        debug() << "Running fast simulation constructor " << fastModelName << endmsg;
+        tool<FastModelFactory>(fastModelName, this)->construct();
+    }   
+}
+
+
 #include "Geant4/G4GDMLParser.hh"
 
 void GiGaMTDetectorConstructionFAC::SaveGDML( G4LogicalVolume* world ) const {
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
index faab00ad..337c7e96 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
@@ -5,6 +5,7 @@
 #include "GaudiAlg/FunctionalDetails.h"
 #include "GaudiAlg/FunctionalUtilities.h"
 #include "Utils/ToolProperty.h"
+#include "Geant4/G4VFastSimulationModel.hh"
 
 class IGiGaMTGeoSvc;
 class IGaussinoTool;
@@ -27,7 +28,11 @@ protected:
   typedef ToolHandle<GiGaFactoryBase<G4VSensitiveDetector>> SensDetFac;
   typedef std::map<std::string, SensDetFac> SensDetVolumeMap;
 
+  using FastModelFactory = GiGaFactoryBase<G4VFastSimulationModel>;
+
   void DressVolumes() const;
+  void BuildFastModels() const;
+
   void SaveGDML(G4LogicalVolume*) const;
   ServiceHandle<IGiGaMTGeoSvc> m_geoSvc{this, "GiGaMTGeoSvc", "GiGaMTGeo"};
   ToolHandleArray<IGaussinoTool> m_afterGeo{this};
@@ -37,6 +42,7 @@ protected:
       Gaudi::Details::Property::ImmediatelyInvokeHandler{true}};
 
   Gaudi::Property<std::string> m_schema{this, "Schema", "$GDML_base/src/GDMLSchema/gdml.xsd"};
+  Gaudi::Property<std::vector<std::string>> m_fastModelConstrs{this, "FastModelConstructors", {}};
   Gaudi::Property<std::string> m_outfile{this, "Output", ""};
 private:
   SensDetVolumeMap m_sens_dets;
diff --git a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
new file mode 100644
index 00000000..4e61eb72
--- /dev/null
+++ b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
@@ -0,0 +1,44 @@
+#include "Geant4/G4VPhysicsConstructor.hh"
+#include "GiGaMTCoreMessage/IGiGaMessage.h" 
+#include "Geant4/G4FastSimulationManagerProcess.hh"
+#include "Geant4/G4ProcessManager.hh"
+#include "GiGaMTFactories/GiGaMTG4PhysicsConstrFAC.h"
+
+class GiGaMTFastSimPhys : public G4VPhysicsConstructor, public GiGaMessage
+{
+public:
+  GiGaMTFastSimPhys() = default;
+  void ConstructParticle () override {};
+  void ConstructProcess  () override
+  {
+    debug("Constructing a manager for fast simulation models"); 
+    G4FastSimulationManagerProcess* fastSimProcess = new G4FastSimulationManagerProcess("G4FSMP");
+    auto theParticleIterator = GetParticleIterator();
+    theParticleIterator->reset();
+    // Fast simulation manager process is available for all the particles
+    while ((*theParticleIterator)()) {
+        G4ParticleDefinition* particle = theParticleIterator->value();
+        G4ProcessManager* process_manager = particle->GetProcessManager();
+        process_manager->AddDiscreteProcess(fastSimProcess);
+    }
+  }
+};
+
+class GiGaMTFastSimPhysFAC : public extends<GiGaMTPhysConstr, GiGaFactoryBase<G4VPhysicsConstructor>>
+{
+public:
+  using extends::extends;
+  GiGaMTFastSimPhys* construct() const override
+  {
+    debug() << "Constructing fast simulation physics" << endmsg;
+    auto tmp = new GiGaMTFastSimPhys{};
+    tmp->SetMessageInterface(message_interface());
+    tmp->SetVerboseLevel(verbosity());
+    tmp->SetPhysicsName(name());
+    debug() << "Constructed fast simulation physics" << endmsg;
+    return tmp;
+   }
+};
+DECLARE_COMPONENT_WITH_ID(GiGaMTFastSimPhysFAC, "GiGaMTFastSimPhysFAC")
+
+
-- 
GitLab


From 12221e5c51f0c9e297ab8e4c0d209513a0fa41b2 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Fri, 29 Jan 2021 09:30:17 +0100
Subject: [PATCH 02/24] Add conditions on debug messages.

---
 .../GiGaMTFactories/GiGaMTFastSimModelFAC.h     | 17 +++++++++++------
 .../src/det/GiGaMTDetectorConstructionFAC.cpp   |  4 +++-
 .../src/phys/GiGaMTFastSimPhysFAC.cpp           | 11 ++++++++---
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
index 9117aecb..8b8374c7 100644
--- a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
@@ -13,16 +13,21 @@ class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSi
     public:
   
   using extends::extends;
-  G4VFastSimulationModel* construct() const override
-  {
-    
-    debug() << "Loading fast simulation region " << m_region.value() << endmsg; 
+  G4VFastSimulationModel* construct() const override {
+    if (msgLevel(MSG::DEBUG)) {
+      debug() << "Loading fast simulation region " << m_region.value() << endmsg; 
+    }
     G4Region* region = G4RegionStore::GetInstance()->GetRegion( m_region.value() );
 
-    debug() << "Loading Fast Sim Model " << m_model.value() << endmsg; 
+    if (msgLevel(MSG::DEBUG)) {
+      debug() << "Loading Fast Sim Model " << m_model.value() << endmsg; 
+    }
     auto tmp = new FastSimModel{m_model.value(), region};
     tmp->SetMessageInterface(message_interface());
-    debug() << "Loaded Fast Sim Model " << m_model.value() << endmsg; 
+
+    if (msgLevel(MSG::DEBUG)) {
+      debug() << "Loaded Fast Sim Model " << m_model.value() << endmsg; 
+    }
     return tmp;
   }
 
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
index a1ac448d..94e54cf6 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
@@ -55,8 +55,10 @@ void GiGaMTDetectorConstructionFAC::DressVolumes() const {
 
 void GiGaMTDetectorConstructionFAC::BuildFastModels() const {
     for(auto& fastModelName : m_fastModelConstrs) {
+      if (msgLevel(MSG::DEBUG)) {  
         debug() << "Running fast simulation constructor " << fastModelName << endmsg;
-        tool<FastModelFactory>(fastModelName, this)->construct();
+      }
+      tool<FastModelFactory>(fastModelName, this)->construct();
     }   
 }
 
diff --git a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
index 4e61eb72..b4f6917e 100644
--- a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
+++ b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
@@ -11,7 +11,8 @@ public:
   void ConstructParticle () override {};
   void ConstructProcess  () override
   {
-    debug("Constructing a manager for fast simulation models"); 
+    //TODO: give a possibility to choose a set of particles
+    //TODO: an option to set parallel geometry 
     G4FastSimulationManagerProcess* fastSimProcess = new G4FastSimulationManagerProcess("G4FSMP");
     auto theParticleIterator = GetParticleIterator();
     theParticleIterator->reset();
@@ -30,12 +31,16 @@ public:
   using extends::extends;
   GiGaMTFastSimPhys* construct() const override
   {
-    debug() << "Constructing fast simulation physics" << endmsg;
+    if (msgLevel(MSG::DEBUG)) {
+      debug() << "Constructing fast simulation physics" << endmsg;
+    }
     auto tmp = new GiGaMTFastSimPhys{};
     tmp->SetMessageInterface(message_interface());
     tmp->SetVerboseLevel(verbosity());
     tmp->SetPhysicsName(name());
-    debug() << "Constructed fast simulation physics" << endmsg;
+    if (msgLevel(MSG::DEBUG)) {
+      debug() << "Constructed fast simulation physics" << endmsg;
+    }
     return tmp;
    }
 };
-- 
GitLab


From 77b8822f2e0149b25e1438f0c35405d7f015cedc Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Fri, 29 Jan 2021 09:32:18 +0100
Subject: [PATCH 03/24] Added an examplary exepriment-independent fast
 simulation model: ImmediateDepositModel. It works on a simplified calorimeter
 SimpleCalo.

---
 .../FastSimulationExample/CMakeLists.txt      |  29 ++
 .../ImmediateDepositModel.h                   |  20 ++
 .../src/components/SimpleCaloGeo.cpp          | 265 ++++++++++++++++++
 .../src/components/SimpleCaloGeo.h            |  42 +++
 .../src/components/SimpleCaloHit.cpp          |  14 +
 .../src/components/SimpleCaloHit.h            |  83 ++++++
 .../src/components/SimpleCaloSD.cpp           |  56 ++++
 .../src/components/SimpleCaloSD.h             |  56 ++++
 .../src/components/SimpleCaloSaveHits.cpp     |  37 +++
 .../src/components/SimpleCaloSaveHits.h       |  16 ++
 .../src/lib/ImmediateDepositModel.cpp         |  66 +++++
 .../tests/options/setup_gamma_gun.py          |  21 ++
 .../options/setup_immediate_deposit_model.py  |  37 +++
 .../tests/options/setup_simple_calo.py        |  15 +
 .../tests/qmtest/fast_simulation.qmt          |  30 ++
 15 files changed, 787 insertions(+)
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
 create mode 100755 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
 create mode 100755 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
new file mode 100644
index 00000000..f081aa3a
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -0,0 +1,29 @@
+################################################################################
+# Package: GiGaMTExamples/FastSimulationExample
+# 
+# Package that contains all necessary examples to test experiment-indpendent 
+# Geant4 hooks for fast simulation.
+# 
+#################################################################################
+gaudi_subdir(FastSimulationExample v1r0)
+
+gaudi_depends_on_subdirs(GaudiAlg
+                         Sim/GiGaMTFactories
+                         Sim/GiGaMTCore)
+AddHepMC3()
+if(${Geant4_config_version} VERSION_LESS "10.06")
+  add_definitions(-DG4MULTITHREADED)
+  add_definitions(-DG4USE_STD11)
+endif()
+
+gaudi_add_module(FastSimulationExample
+                  src/lib/*.cpp
+                  src/components/*.cpp
+                  INCLUDE_DIRS GiGaMTFactories
+                  LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
+
+add_dependencies(FastSimulationExample HepMC3Ext)
+
+gaudi_env(SET FASTSIMULATIONEXAMPLETESTS \${FASTSIMULATIONEXAMPLEROOT}/tests)
+
+gaudi_add_test(QMTest QMTEST)
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
new file mode 100644
index 00000000..b2cec486
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Geant4/G4VFastSimulationModel.hh"
+#include "GiGaMTCoreMessage/IGiGaMessage.h"
+
+class ImmediateDepositModel : public G4VFastSimulationModel, public GiGaMessage  {
+	 
+	G4Navigator* m_navigator;
+	G4TouchableHandle m_touchableHandle;
+	bool m_navigatorOn;
+
+	public:
+
+    ImmediateDepositModel(G4String modelName, G4Region* envelope);
+    ~ImmediateDepositModel();
+
+  	G4bool IsApplicable(const G4ParticleDefinition& aParticle) override;
+	G4bool ModelTrigger(const G4FastTrack& aFastTrack) override;
+ 	void DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastStep) override;
+};
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
new file mode 100755
index 00000000..4507659c
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
@@ -0,0 +1,265 @@
+#include "Geant4/G4Box.hh"
+#include "Geant4/G4LogicalVolume.hh"
+#include "Geant4/G4NistManager.hh"
+#include "Geant4/G4PVPlacement.hh"
+#include "Geant4/G4SystemOfUnits.hh"
+#include "Geant4/G4PVReplica.hh"
+#include "Geant4/G4PhysicalConstants.hh"
+#include "Geant4/G4VisAttributes.hh"
+#include "Geant4/G4SDManager.hh"
+#include "Geant4/G4GlobalMagFieldMessenger.hh"
+#include "Geant4/G4AutoDelete.hh"
+#include "Geant4/G4SDChargedFilter.hh"
+#include "Geant4/G4MultiFunctionalDetector.hh"
+#include "Geant4/G4VPrimitiveScorer.hh"
+#include "Geant4/G4PSEnergyDeposit.hh"
+#include "Geant4/G4PSTrackLength.hh"
+#include "Geant4/G4Colour.hh"
+
+#include "SimpleCaloGeo.h"
+#include "SimpleCaloSD.h"
+
+DECLARE_COMPONENT( SimpleCaloGeo )
+
+StatusCode SimpleCaloGeo::queryInterface( const InterfaceID& id, void** ppI )
+{
+  if ( 0 == ppI ) {
+    return StatusCode::FAILURE; //  RETURN !!!
+  } else if ( IGiGaMTGeoSvc::interfaceID() == id ) {
+    *ppI = static_cast<IGiGaMTGeoSvc*>( this );
+  } else {
+    return Service::queryInterface( id, ppI ); //  RETURN !!!
+  }
+
+  addRef();
+
+  return StatusCode::SUCCESS;
+}
+
+
+void SimpleCaloGeo::defineMaterials() {
+  // Lead material defined using NIST Manager
+  auto nistManager = G4NistManager::Instance();
+  nistManager->FindOrBuildMaterial("G4_Pb");
+  
+  // Liquid argon material
+  G4double a;  // mass of a mole;
+  G4double z;  // z=mean number of protons;  
+  G4double density; 
+  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
+         // The argon by NIST Manager is a gas with a different density
+  // Vacuum
+  new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
+                  kStateGas, 2.73*kelvin, 3.e-18*pascal);
+  // Print materials
+  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
+}
+
+
+
+G4VPhysicalVolume* SimpleCaloGeo::constructWorld()
+{
+  // Lead material defined using NIST Manager
+  auto nistManager = G4NistManager::Instance();
+  nistManager->FindOrBuildMaterial("G4_Pb");
+  
+  // Liquid argon material
+  G4double a;  // mass of a mole;
+  G4double z;  // z=mean number of protons;  
+  G4double density; 
+  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
+         // The argon by NIST Manager is a gas with a different density
+
+  // Vacuum
+  new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
+                  kStateGas, 2.73*kelvin, 3.e-18*pascal);
+
+  // Print materials
+  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
+
+  // Geometry parameters
+  G4double  absoThickness = 10.*mm;
+  G4double  gapThickness =  5.*mm;
+  G4double  calorSizeXY  = 10.*cm;
+  auto  layerThickness = absoThickness + gapThickness;
+  auto  calorThickness = m_nofLayers * layerThickness;
+  auto  worldSizeXY = 1.2 * calorSizeXY;
+  auto  worldSizeZ  = 1.2 * calorThickness; 
+  
+  // Get materials
+  auto defaultMaterial = G4Material::GetMaterial("Galactic");
+  auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
+  auto gapMaterial = G4Material::GetMaterial("liquidArgon");
+  
+  if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
+    G4ExceptionDescription msg;
+    msg << "Cannot retrieve materials already defined."; 
+    G4Exception("B4DetectorConstruction::DefineVolumes()",
+      "MyCode0001", FatalException, msg);
+  }  
+   
+  //     
+  // World
+  //
+  auto worldS 
+    = new G4Box("World",           // its name
+                 worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
+                         
+  auto worldLV
+    = new G4LogicalVolume(
+                 worldS,           // its solid
+                 defaultMaterial,  // its material
+                 "World");         // its name
+                                   
+  auto worldPV
+    = new G4PVPlacement(0,
+                 G4ThreeVector(),  // at (0,0,0)
+                 worldLV,          // its logical volume                         
+                 "World",          // its name
+                 0,                // its mother  volume
+                 false,            // no boolean operation
+                 0,                // copy number
+                 m_checkOverlaps);  // checking overlaps 
+  
+  //                               
+  // Calorimeter
+  //  
+  auto calorimeterS
+    = new G4Box("Calorimeter",     // its name
+                 calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
+                         
+  auto calorLV
+    = new G4LogicalVolume(
+                 calorimeterS,    // its solid
+                 defaultMaterial, // its material
+                 "Calorimeter");  // its name
+                                   
+  new G4PVPlacement(
+                 0,                // no rotation
+                 G4ThreeVector(),  // at (0,0,0)
+                 calorLV,          // its logical volume                         
+                 "Calorimeter",    // its name
+                 worldLV,          // its mother  volume
+                 false,            // no boolean operation
+                 0,                // copy number
+                 m_checkOverlaps);  // checking overlaps 
+  
+  //                                 
+  // Layer
+  //
+  auto layerS 
+    = new G4Box("Layer",           // its name
+                 calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
+                         
+  auto layerLV
+    = new G4LogicalVolume(
+                 layerS,           // its solid
+                 defaultMaterial,  // its material
+                 "Layer");         // its name
+  new G4PVReplica(
+                 "Layer",          // its name
+                 layerLV,          // its logical volume
+                 calorLV,          // its mother
+                 kZAxis,           // axis of replication
+                 m_nofLayers,        // number of replica
+                 layerThickness);  // witdth of replica
+  
+  //                               
+  // Absorber
+  //
+  auto absorberS 
+    = new G4Box("Abso",            // its name
+                 calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
+                         
+  m_absorberLV
+    = new G4LogicalVolume(
+                 absorberS,        // its solid
+                 absorberMaterial, // its material
+                 "AbsoLV");          // its name
+                                   
+   new G4PVPlacement(
+                 0,                // no rotation
+                 G4ThreeVector(0., 0., -gapThickness/2), //  its position
+                 m_absorberLV,       // its logical volume                         
+                 "Abso",           // its name
+                 layerLV,          // its mother  volume
+                 false,            // no boolean operation
+                 0,                // copy number
+                 m_checkOverlaps);  // checking overlaps 
+  //                               
+  // Gap
+  //
+  auto gapS 
+    = new G4Box("Gap",             // its name
+                 calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
+                         
+  m_gapLV = new G4LogicalVolume(
+                 gapS,             // its solid
+                 gapMaterial,      // its material
+                 "GapLV");      // its name
+                                   
+  new G4PVPlacement(
+                 0,                // no rotation
+                 G4ThreeVector(0., 0., absoThickness/2), //  its position
+                 m_gapLV,            // its logical volume                         
+                 "Gap",            // its name
+                 layerLV,          // its mother  volume
+                 false,            // no boolean operation
+                 0,                // copy number
+                 m_checkOverlaps);  // checking overlaps 
+  
+  //
+  // print parameters
+  //
+  G4cout
+    << G4endl 
+    << "------------------------------------------------------------" << G4endl
+    << "---> The calorimeter is " << m_nofLayers << " layers of: [ "
+    << absoThickness/mm << "mm of " << absorberMaterial->GetName() 
+    << " + "
+    << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl
+    << "------------------------------------------------------------" << G4endl;
+  
+  //                                        
+  // Visualization attributes
+  //
+  worldLV->SetVisAttributes (G4VisAttributes::GetInvisible());
+  auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
+  simpleBoxVisAtt->SetVisibility(true);
+  calorLV->SetVisAttributes(simpleBoxVisAtt);
+  //
+  // Always return the physical World
+  //
+  return worldPV;
+}
+
+void SimpleCaloGeo::constructSDandField() {
+  // G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
+  // 
+  // Sensitive detectors
+  //
+  
+  auto absoSD = m_absorberFAC->construct();
+  G4SDManager::GetSDMpointer()->AddNewDetector(absoSD);
+  m_absorberLV->SetSensitiveDetector(absoSD);
+
+  
+  auto gapSD = m_gapFAC->construct();
+  G4SDManager::GetSDMpointer()->AddNewDetector(gapSD);
+  m_gapLV->SetSensitiveDetector(gapSD);
+  
+
+  // 
+  // Magnetic field
+  //
+  // Create global magnetic field messenger.
+  // Uniform magnetic field is then created automatically if
+  // the field value is not zero.
+  //G4ThreeVector fieldValue;
+  //fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
+  //fMagFieldMessenger->SetVerboseLevel(1);
+  
+  // Register the field messenger for deleting
+  //G4AutoDelete::Register(fMagFieldMessenger);
+}
+
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
new file mode 100755
index 00000000..83d13ffc
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
@@ -0,0 +1,42 @@
+#pragma once
+
+// from Gaudi
+#include "GaudiKernel/Kernel.h"
+#include "GaudiKernel/Service.h"
+#include "GaudiKernel/StatusCode.h"
+
+// from GiGa
+#include "GiGaMTGeo/IGiGaMTGeoSvc.h"
+#include "SimpleCaloSD.h"
+
+// from G4
+class G4VPhysicalVolume;
+class G4LogicalVolume;
+
+class SimpleCaloGeo : public Service, virtual public IGiGaMTGeoSvc
+{
+
+protected:
+  using Service::Service;
+
+public:
+  StatusCode initialize() override {return Service::initialize();}
+  StatusCode finalize() override { return Service::finalize();}
+
+
+  virtual G4VPhysicalVolume* constructWorld() override;
+  virtual void constructSDandField() override;
+  virtual StatusCode queryInterface( const InterfaceID& iid, void** pI ) override;
+
+private:
+
+    
+  void defineMaterials();
+  Gaudi::Property<bool> m_checkOverlaps{this, "CheckOverlaps", true}; 
+  Gaudi::Property<int> m_nofLayers{this, "LayersNumber", 10};
+  G4LogicalVolume* m_gapLV;
+  G4LogicalVolume* m_absorberLV;
+  ToolHandle<SimpleCaloSDFAC> m_absorberFAC {"AbsorberFAC", this}; 
+  ToolHandle<SimpleCaloSDFAC> m_gapFAC {"GapFAC", this};
+
+};
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
new file mode 100644
index 00000000..43111587
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
@@ -0,0 +1,14 @@
+#include "SimpleCaloHit.h"
+#include "Geant4/G4UnitsTable.hh"
+#include "Geant4/G4VVisManager.hh"
+#include "Geant4/G4Circle.hh"
+#include "Geant4/G4Colour.hh"
+#include "Geant4/G4VisAttributes.hh"
+#include <iomanip>
+G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator = 0;
+
+SimpleCaloHit::SimpleCaloHit() : G4VHit(), m_energy(0.) {}
+
+SimpleCaloHit::~SimpleCaloHit() {}
+
+
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
new file mode 100644
index 00000000..6cb97d3f
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
@@ -0,0 +1,83 @@
+#pragma once
+
+#include "Geant4/G4VHit.hh"
+#include "Geant4/G4THitsCollection.hh"
+#include "Geant4/G4Allocator.hh"
+#include "Geant4/G4ThreeVector.hh"
+#include "Geant4/G4Threading.hh"
+
+/// Calorimeter hit class
+///
+/// It defines data members to store the the energy deposit and track lengths
+/// of charged particles in a selected volume:
+/// - m_energy
+
+class SimpleCaloHit : public G4VHit
+{
+  public:
+    SimpleCaloHit();
+    SimpleCaloHit(const SimpleCaloHit&);
+    virtual ~SimpleCaloHit();
+
+    // operators
+    const SimpleCaloHit& operator=(const SimpleCaloHit&);
+    //G4int operator==(const SimpleCaloHit&) const;
+
+    inline void* operator new(size_t);
+    inline void  operator delete(void*);
+
+    // methods from base class
+    // virtual void Draw() {}
+    //virtual void Print();
+
+    // methods to handle data
+    void Add(G4double de);
+
+    // get methods
+    G4double GetEnergy() const;
+    //G4double GetTrackLength() const;
+      
+  private:
+    G4double m_energy;        ///< Energy deposit in the sensitive volume
+    // G4double fTrackLength; ///< Track length in the  sensitive volume
+};
+
+
+using SimpleCaloHitsCollection = G4THitsCollection<SimpleCaloHit>;
+
+extern G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator;
+
+
+inline void* SimpleCaloHit::operator new(size_t)
+{
+  if (!SimpleCaloHitAllocator) {
+    SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>;
+  }
+  void *hit;
+  hit = (void *) SimpleCaloHitAllocator->MallocSingle();
+  return hit;
+}
+
+inline void SimpleCaloHit::operator delete(void *hit)
+{
+  if (!SimpleCaloHitAllocator) {
+    SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>;
+  }
+  SimpleCaloHitAllocator->FreeSingle((SimpleCaloHit*) hit);
+}
+
+inline void SimpleCaloHit::Add(G4double de) {
+  m_energy += de; 
+  // fTrackLength += dl;
+}
+
+inline G4double SimpleCaloHit::GetEnergy() const { 
+  return m_energy; 
+}
+
+/*
+inline G4double SimpleCaloHit::GetTrackLength() const { 
+  return fTrackLength; 
+}
+*/
+
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
new file mode 100644
index 00000000..074dde5d
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
@@ -0,0 +1,56 @@
+#include "SimpleCaloSD.h"
+#include "Geant4/G4HCofThisEvent.hh"
+#include "Geant4/G4Step.hh"
+#include "Geant4/G4ThreeVector.hh"
+#include "Geant4/G4SDManager.hh"
+#include "Geant4/G4ios.hh"
+
+
+SimpleCaloSD::SimpleCaloSD(const G4String& name) : G4VSensitiveDetector(name) {
+  collectionName.insert(SensitiveDetectorName + "HitsCollection");
+}
+
+
+void SimpleCaloSD::Initialize(G4HCofThisEvent* hce)
+{
+  m_hitsCollection = new SimpleCaloHitsCollection(SensitiveDetectorName, collectionName[0]); 
+  auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
+  hce->AddHitsCollection( hcID, m_hitsCollection ); 
+  for (G4int i=0; i < m_cellsNo; i++ ) {
+    m_hitsCollection->insert(new SimpleCaloHit());
+  }
+}
+
+G4bool SimpleCaloSD::Hit(G4Step * aStep) {
+         G4TouchableHistory* ROhis = 0;
+         if(!isActive()) return false;
+         if(filter)
+         { if(!(filter->Accept(aStep))) return false; }
+         if(ROgeometry)
+         { if(!(ROgeometry->CheckROVolume(aStep,ROhis))) return false; }
+         return ProcessHits(aStep,ROhis);
+}
+
+bool SimpleCaloSD::ProcessHits(G4Step* step, G4TouchableHistory*) {  
+  auto edep = step->GetTotalEnergyDeposit();
+  if ( edep == 0. ) return false;      
+  auto touchable = (step->GetPreStepPoint()->GetTouchable());
+  auto layerNumber = touchable->GetReplicaNumber(1);
+  auto hit = (*m_hitsCollection)[layerNumber];
+  if ( ! hit ) {
+    G4ExceptionDescription msg;
+    msg << "Cannot access hit " << layerNumber; 
+    G4Exception("SimpleCaloSD::ProcessHits()",
+      "MyCode0004", FatalException, msg);
+  }         
+  
+  hit->Add(edep);
+  return true;
+}
+
+void SimpleCaloSD::EndOfEvent(G4HCofThisEvent*) {
+  if (!m_hitsCollection) {
+    warning("There are no hits in the hits collection.");
+    return;
+  }
+}
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
new file mode 100644
index 00000000..4fc01757
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
@@ -0,0 +1,56 @@
+#pragma once
+
+// Gaudi
+#include "Gaudi/Accumulators.h"
+
+// GiGa
+#include "GiGaMTCoreMessage/IGiGaMessage.h"
+#include "GiGaMTFactories/GiGaMTG4SensDetFactory.h"
+
+#include "Geant4/G4VSensitiveDetector.hh"
+#include "SimpleCaloHit.h"
+#include <vector>
+
+class G4Step;
+class G4HCofThisEvent;
+
+
+class SimpleCaloSD : public G4VSensitiveDetector, public virtual GiGaMessage {
+  public:
+    SimpleCaloSD(const G4String& name);
+    virtual ~SimpleCaloSD() = default;
+
+    // methods from base class
+    void   Initialize(G4HCofThisEvent* hitCollection) override;
+    bool ProcessHits(G4Step* step, G4TouchableHistory* history) override;
+    void   EndOfEvent(G4HCofThisEvent* hitCollection) override;
+    G4bool 	Hit (G4Step *aStep);
+
+    SimpleCaloHitsCollection* m_hitsCollection = nullptr;
+    int  m_cellsNo;
+};
+
+class SimpleCaloSDFAC : public GiGaMTG4SensDetFactory<SimpleCaloSD> {
+
+  // TODO: this is the same property as in SimpleCaloGeo
+  Gaudi::Property<int> m_cellsNo {this, "CellsNo", 10};
+
+  public:
+  
+  using base_class = GiGaMTG4SensDetFactory<SimpleCaloSD>;
+  using base_class::GiGaMTG4SensDetFactory;
+
+  virtual ~SimpleCaloSDFAC() = default;
+  virtual SimpleCaloSD* construct() const override {
+    auto tmp = base_class::construct();
+    tmp->SetVerboseLevel( MSG::DEBUG );
+    tmp->SetMessageInterface( message_interface() );
+    tmp->m_cellsNo = m_cellsNo;
+    //tmp->m_nhits = &m_nhits;
+    //tmp->m_energy = &m_energy;
+    return tmp;
+  }
+};
+
+DECLARE_COMPONENT_WITH_ID(SimpleCaloSDFAC, "GapFAC")
+DECLARE_COMPONENT_WITH_ID(SimpleCaloSDFAC, "AbsorberFAC")
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
new file mode 100644
index 00000000..d4f9fcf2
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
@@ -0,0 +1,37 @@
+// Immediate
+#include "SimpleCaloSaveHits.h"
+#include "SimpleCaloHit.h"
+// Gaudi
+#include "GaudiKernel/ITHistSvc.h"
+// Geant4
+#include "Geant4/G4Event.hh"
+
+  
+DECLARE_COMPONENT( SimpleCaloSaveHits )
+
+StatusCode SimpleCaloSaveHits::finalize() {
+  if(msgLevel(MSG::INFO)) {
+    info() << "SimpleCaloHits total energy: " << m_energy.sum()  << endmsg;
+    info() << "SimpleCaloHits energy mean: " << m_energy.mean() << endmsg;
+    info() << "SimpleCaloHits energy mean error: " << m_energy.meanErr() << endmsg;
+  }
+  return extends::finalize();
+}
+
+
+StatusCode SimpleCaloSaveHits::monitor( const G4Event& aEvent ) {
+  G4HCofThisEvent* collections = aEvent.GetHCofThisEvent();
+
+  for ( int iter_coll = 0; iter_coll < collections->GetNumberOfCollections(); iter_coll++ ) {
+      G4VHitsCollection* collection = collections->GetHC( iter_coll );
+      int n_hit = collection->GetSize();
+      if (msgLevel(MSG::DEBUG)) {
+        debug() << "Spotted #" << n_hit << " hits stored in " << collection->GetName() << " collection." << endmsg;
+      }
+      for ( int iter_hit = 0; iter_hit < n_hit; iter_hit++ ) {
+        SimpleCaloHit* hit = dynamic_cast<SimpleCaloHit*>( collection->GetHit( iter_hit ) );
+        if (hit->GetEnergy() > 0.) m_energy += hit->GetEnergy();
+      }
+  }
+  return StatusCode::SUCCESS;
+}
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
new file mode 100644
index 00000000..f49466da
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
@@ -0,0 +1,16 @@
+#pragma once
+// Gaudi
+#include "GaudiAlg/GaudiTool.h"
+#include "SimInterfaces/IG4MonitoringTool.h"
+
+class SimpleCaloSaveHits: public extends<GaudiTool, IG4MonitoringTool> {
+  
+  mutable Gaudi::Accumulators::StatCounter<double> m_energy {this, "energy"};
+
+public:
+  using extends::extends;
+
+  virtual StatusCode finalize() override;
+  virtual StatusCode monitor(const G4Event& aEvent) override;
+};
+
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
new file mode 100644
index 00000000..c2a8dd93
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
@@ -0,0 +1,66 @@
+#include "FastSimulationExample/ImmediateDepositModel.h"
+#include "GiGaMTFactories/GiGaMTFastSimModelFAC.h"
+#include "Geant4/G4TransportationManager.hh"
+#include "Geant4/G4VSensitiveDetector.hh"
+
+ImmediateDepositModel::ImmediateDepositModel(G4String modelName, G4Region* envelope)
+  : G4VFastSimulationModel(modelName, envelope) {
+	m_touchableHandle = new G4TouchableHistory();
+	m_navigator = new G4Navigator();
+	m_navigatorOn = false;
+}
+
+ImmediateDepositModel::~ImmediateDepositModel(){
+	delete m_navigator;
+}
+
+
+G4bool ImmediateDepositModel::IsApplicable(const G4ParticleDefinition&) {
+	return true;
+}
+
+
+G4bool ImmediateDepositModel::ModelTrigger(const G4FastTrack&) {
+	return true;
+}
+
+
+void ImmediateDepositModel::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastStep) {
+	aFastStep.KillPrimaryTrack();
+	G4double Edep = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
+
+	aFastStep.SetTotalEnergyDeposited( Edep );
+	G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
+	if (!m_navigatorOn) {
+	  	auto worldVolume = G4TransportationManager::GetTransportationManager()->
+                       GetNavigatorForTracking()->GetWorldVolume();
+		m_navigator -> SetWorldVolume(worldVolume);
+		m_navigator -> LocateGlobalPointAndUpdateTouchableHandle(position,
+		   														G4ThreeVector(0.,0.,0.),
+																m_touchableHandle,
+																false);
+		m_navigatorOn = true;
+	} else {
+		m_navigator -> LocateGlobalPointAndUpdateTouchableHandle(position,
+		   														G4ThreeVector(0.,0.,0.),
+																m_touchableHandle);
+	}
+
+	
+	G4Step *fakeStep = new G4Step();
+	G4StepPoint* fakePreStepPoint = fakeStep->GetPreStepPoint();
+	fakePreStepPoint->SetTouchableHandle(m_touchableHandle);
+	fakeStep->SetTotalEnergyDeposit(Edep);
+
+	G4VPhysicalVolume* pCurrentVolume = fakeStep->GetPreStepPoint()->GetPhysicalVolume();
+
+  	if( pCurrentVolume) {
+      G4VSensitiveDetector* pSensitive = pCurrentVolume->GetLogicalVolume()->GetSensitiveDetector();
+      if( pSensitive) {
+         pSensitive->Hit(fakeStep);
+      }
+    }
+}
+
+using ImmediateDepositModelFAC = GiGaMTFastSimModelFAC<ImmediateDepositModel>;
+DECLARE_COMPONENT_WITH_ID( ImmediateDepositModelFAC, "ImmediateDepositModel" )
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
new file mode 100644
index 00000000..57de754a
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
@@ -0,0 +1,21 @@
+from Gaussino.Generation import GenPhase
+GenPhase().ParticleGun = True
+GenPhase().ParticleGunUseDefault = False
+
+from Configurables import ParticleGun
+pgun = ParticleGun("ParticleGun")
+
+from Configurables import FixedMomentum
+pgun.ParticleGunTool = "FixedMomentum"
+pgun.addTool(FixedMomentum, name="FixedMomentum")
+from GaudiKernel.SystemOfUnits import GeV
+pgun.FixedMomentum.px = 0. * GeV
+pgun.FixedMomentum.py = 0. * GeV
+pgun.FixedMomentum.pz = 1. * GeV
+pgun.FixedMomentum.PdgCodes = [22]
+
+from Configurables import FlatNParticles
+pgun.NumberOfParticlesTool = "FlatNParticles"
+pgun.addTool( FlatNParticles , name = "FlatNParticles" )
+pgun.FlatNParticles.MinNParticles = 1
+pgun.FlatNParticles.MaxNParticles = 1
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
new file mode 100644
index 00000000..7ae43b9a
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
@@ -0,0 +1,37 @@
+from Configurables import GiGaMT
+from Configurables import GiGaMTModularPhysListFAC
+giga = GiGaMT()
+gmpl = giga.addTool(GiGaMTModularPhysListFAC("ModularPL"), name="ModularPL")
+giga.PhysicsListFactory = "GiGaMTModularPhysListFAC/ModularPL"
+gmpl = giga.ModularPL
+gmpl.PhysicsConstructors = []
+
+from Configurables import GiGaMT_G4EmStandardPhysics
+gmpl.addTool(GiGaMT_G4EmStandardPhysics(), name='EmPhysics')
+gmpl.PhysicsConstructors.append('GiGaMT_G4EmStandardPhysics/EmPhysics')
+
+from Configurables import GiGaMTFastSimPhysFAC
+gmpl.addTool(GiGaMTFastSimPhysFAC(), name='FastSimPhys')
+gmpl.PhysicsConstructors.append('GiGaMTFastSimPhysFAC/FastSimPhys')
+
+from Configurables import GiGaMTDetectorConstructionFAC
+giga.DetectorConstruction = "GiGaMTDetectorConstructionFAC"
+dettool = giga.addTool(GiGaMTDetectorConstructionFAC, "GiGaMTDetectorConstructionFAC")
+dettool.OutputLevel = -10
+
+from Configurables import SimpleCaloGeo
+from Configurables import ApplicationMgr
+SimpleCaloGeo().OutputLevel = 10
+dettool.GiGaMTGeoSvc = "SimpleCaloGeo"
+ApplicationMgr().ExtSvc += [SimpleCaloGeo()]
+
+
+from Configurables import GiGaRegionTool
+from Configurables import ImmediateDepositModel
+giga_region = GiGaRegionTool(Region="ImmediateDepositRegion",
+        Volumes=["AbsoLV", "GapLV"])
+dettool.addTool(giga_region, name='ImmediateDepositRegionTool')
+dettool.AfterGeoConstructionTools.append("GiGaRegionTool/ImmediateDepositRegionTool")
+fastSimModel = ImmediateDepositModel(ModelName="ImmediateDepositModel", RegionName="ImmediateDepositRegion")
+dettool.addTool(fastSimModel, name='ImmediateDepositModelConstr')
+dettool.FastModelConstructors.append('ImmediateDepositModel/ImmediateDepositModelConstr')
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
new file mode 100644
index 00000000..4f634e61
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
@@ -0,0 +1,15 @@
+from multiprocessing import cpu_count
+from Configurables import GiGaMT
+giga = GiGaMT()
+giga.NumberOfWorkerThreads = cpu_count()
+
+from Configurables import Gaussino
+Gaussino().EvtMax = 100
+Gaussino().EnableHive = True
+Gaussino().ThreadPoolSize = 20
+Gaussino().EventSlots = 20
+
+
+from Configurables import SimpleCaloSaveHits
+monitool = giga.addTool(SimpleCaloSaveHits())
+giga.MonitorTools = ["SimpleCaloSaveHits"]
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt b/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
new file mode 100644
index 00000000..87c1c435
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE extension  PUBLIC '-//QM/2.3/Extension//EN'  'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
+
+<extension class="GaudiTest.GaudiExeTest" kind="test">
+<argument name="program"><text>gaudirun.py</text></argument>
+<argument name="args"><set>
+    <text>$FASTSIMULATIONEXAMPLETESTS/options/setup_simple_calo.py</text>
+    <text>$FASTSIMULATIONEXAMPLETESTS/options/setup_gamma_gun.py</text>
+    <text>$FASTSIMULATIONEXAMPLETESTS/options/setup_immediate_deposit_model.py</text>
+</set></argument>
+<argument name="timeout"><integer>60</integer></argument>
+<argument name="use_temp_dir"><enumeral>true</enumeral></argument>
+<argument name="exit_code"><integer>0</integer></argument>
+<argument name="environment"><set/></argument>
+<argument name="unsupported_platforms"><set/></argument>
+<argument name="workdir"><text/></argument>
+<argument name="stderr"><text/></argument>
+<argument name="options"><text></text></argument>
+<argument name="validator"><text>
+results = [&quot;SimpleCaloHits total energy: 100000&quot;,
+   &quot;SimpleCaloHits energy mean: 1000&quot;,
+   &quot;SimpleCaloHits energy mean error: 0&quot;]
+for result in results:
+    if stdout.find(result) == -1:
+        causes.append('missing string')
+        result['GaudiTest.expected_string'] = result.Quote(result)
+</text></argument>
+<argument name="resources"><set/></argument>
+<argument name="stdin"><text/></argument>
+</extension>
+
-- 
GitLab


From bd70041e9dca3402278bbcfd531d5bda4b8fb19a Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Fri, 29 Jan 2021 11:21:58 +0100
Subject: [PATCH 04/24] Add copyright/formatting gitlab-ci check

---
 .gitlab-ci.yml | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..925e5145
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+variables:
+  TARGET_BRANCH: master
+check-copyright:
+  image: gitlab-registry.cern.ch/ci-tools/ci-worker:cc7
+  script:
+    - curl -o lb-check-copyright "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/SourceTools.py?inline=false"
+    - python lb-check-copyright origin/${TARGET_BRANCH}
+check-formatting:
+  image: gitlab-registry.cern.ch/lhcb-docker/style-checker
+  script:
+    - if [ ! -e .clang-format ] ; then
+    -   curl -o .clang-format "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/data/default.clang-format?inline=false"
+    -   echo '.clang-format' >> .gitignore
+    -   git add .gitignore
+    - fi
+    - curl -o lb-format "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/SourceTools.py?inline=false"
+    - python lb-format --format-patch apply-formatting.patch origin/${TARGET_BRANCH}
+  artifacts:
+    paths:
+      - apply-formatting.patch
+    when: on_failure
+    expire_in: 1 week
-- 
GitLab


From cb549d47d9c1dfeef194c82a6c61255248219902 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Fri, 29 Jan 2021 13:47:53 +0100
Subject: [PATCH 05/24] Add copyright statements

---
 .../FastSimulationExample/CMakeLists.txt               | 10 ++++++++++
 .../FastSimulationExample/ImmediateDepositModel.h      | 10 ++++++++++
 .../src/components/SimpleCaloGeo.cpp                   | 10 ++++++++++
 .../src/components/SimpleCaloGeo.h                     | 10 ++++++++++
 .../src/components/SimpleCaloHit.cpp                   | 10 ++++++++++
 .../src/components/SimpleCaloHit.h                     | 10 ++++++++++
 .../src/components/SimpleCaloSD.cpp                    | 10 ++++++++++
 .../src/components/SimpleCaloSD.h                      | 10 ++++++++++
 .../src/components/SimpleCaloSaveHits.cpp              | 10 ++++++++++
 .../src/components/SimpleCaloSaveHits.h                | 10 ++++++++++
 .../src/lib/ImmediateDepositModel.cpp                  | 10 ++++++++++
 .../tests/options/setup_gamma_gun.py                   | 10 ++++++++++
 .../tests/options/setup_immediate_deposit_model.py     | 10 ++++++++++
 .../tests/options/setup_simple_calo.py                 | 10 ++++++++++
 .../tests/qmtest/fast_simulation.qmt                   | 10 ++++++++++
 .../GiGaMTFactories/GiGaMTFastSimModelFAC.h            | 10 ++++++++++
 .../src/det/GiGaMTDetectorConstructionFAC.cpp          | 10 ++++++++++
 .../src/det/GiGaMTDetectorConstructionFAC.h            | 10 ++++++++++
 Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp  | 10 ++++++++++
 19 files changed, 190 insertions(+)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
index f081aa3a..39a352ef 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -1,3 +1,13 @@
+###############################################################################
+# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
 ################################################################################
 # Package: GiGaMTExamples/FastSimulationExample
 # 
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
index b2cec486..2a54cbce 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #pragma once
 
 #include "Geant4/G4VFastSimulationModel.hh"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
index 4507659c..8682a848 100755
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "Geant4/G4Box.hh"
 #include "Geant4/G4LogicalVolume.hh"
 #include "Geant4/G4NistManager.hh"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
index 83d13ffc..9a4a63bf 100755
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #pragma once
 
 // from Gaudi
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
index 43111587..91b9de13 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "SimpleCaloHit.h"
 #include "Geant4/G4UnitsTable.hh"
 #include "Geant4/G4VVisManager.hh"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
index 6cb97d3f..b23b3354 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #pragma once
 
 #include "Geant4/G4VHit.hh"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
index 074dde5d..4f6f662f 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "SimpleCaloSD.h"
 #include "Geant4/G4HCofThisEvent.hh"
 #include "Geant4/G4Step.hh"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
index 4fc01757..e0131a1a 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #pragma once
 
 // Gaudi
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
index d4f9fcf2..9ae82a91 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 // Immediate
 #include "SimpleCaloSaveHits.h"
 #include "SimpleCaloHit.h"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
index f49466da..30ee96f9 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #pragma once
 // Gaudi
 #include "GaudiAlg/GaudiTool.h"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
index c2a8dd93..c96cdacc 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "FastSimulationExample/ImmediateDepositModel.h"
 #include "GiGaMTFactories/GiGaMTFastSimModelFAC.h"
 #include "Geant4/G4TransportationManager.hh"
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
index 57de754a..d13589fb 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
@@ -1,3 +1,13 @@
+###############################################################################
+# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
 from Gaussino.Generation import GenPhase
 GenPhase().ParticleGun = True
 GenPhase().ParticleGunUseDefault = False
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
index 7ae43b9a..ecf2d215 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
@@ -1,3 +1,13 @@
+###############################################################################
+# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
 from Configurables import GiGaMT
 from Configurables import GiGaMTModularPhysListFAC
 giga = GiGaMT()
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
index 4f634e61..70eaab60 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
@@ -1,3 +1,13 @@
+###############################################################################
+# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
 from multiprocessing import cpu_count
 from Configurables import GiGaMT
 giga = GiGaMT()
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt b/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
index 87c1c435..8a30df9e 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
@@ -1,4 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE extension  PUBLIC '-//QM/2.3/Extension//EN'  'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
+<!--
+    (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration
+
+    This software is distributed under the terms of the GNU General Public
+    Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".
+
+    In applying this licence, CERN does not waive the privileges and immunities
+    granted to it by virtue of its status as an Intergovernmental Organization
+    or submit itself to any jurisdiction.
+-->
 
 <extension class="GaudiTest.GaudiExeTest" kind="test">
 <argument name="program"><text>gaudirun.py</text></argument>
diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
index 8b8374c7..2869fca3 100644
--- a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #pragma once
 
 #include "GiGaMTFactories/GiGaFactoryBase.h"
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
index 94e54cf6..44517900 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "GiGaMTDetectorConstructionFAC.h"
 #include "GiGaMTCoreDet/GiGaMTDetectorConstruction.h"
 #include "GiGaMTGeo/IGiGaMTGeoSvc.h"
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
index 337c7e96..92cb7801 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "Geant4/G4VUserDetectorConstruction.hh"
 #include "GiGaMTFactories/GiGaFactoryBase.h"
 #include "GiGaMTFactories/GiGaTool.h"
diff --git a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
index b4f6917e..36ab8c64 100644
--- a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
+++ b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
@@ -1,3 +1,13 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
 #include "Geant4/G4VPhysicsConstructor.hh"
 #include "GiGaMTCoreMessage/IGiGaMessage.h" 
 #include "Geant4/G4FastSimulationManagerProcess.hh"
-- 
GitLab


From 792b4ae699206f7133449f3d9daaaf607f07cc52 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 3 Feb 2021 21:20:56 +0100
Subject: [PATCH 06/24] Fix formatting

---
 .../ImmediateDepositModel.h                   |  21 +-
 .../src/components/SimpleCaloGeo.cpp          | 336 ++++++++----------
 .../src/components/SimpleCaloGeo.h            |  29 +-
 .../src/components/SimpleCaloHit.cpp          |   8 +-
 .../src/components/SimpleCaloHit.h            |  96 +++--
 .../src/components/SimpleCaloSD.cpp           |  68 ++--
 .../src/components/SimpleCaloSD.h             |  34 +-
 .../src/components/SimpleCaloSaveHits.cpp     |  24 +-
 .../src/components/SimpleCaloSaveHits.h       |   9 +-
 .../src/lib/ImmediateDepositModel.cpp         |  81 ++---
 .../tests/options/setup_gamma_gun.py          |   2 +-
 .../options/setup_immediate_deposit_model.py  |  17 +-
 .../tests/options/setup_simple_calo.py        |   1 -
 .../GiGaMTFactories/GiGaMTFastSimModelFAC.h   |  29 +-
 .../src/det/GiGaMTDetectorConstructionFAC.cpp |  10 +-
 .../src/phys/GiGaMTFastSimPhysFAC.cpp         |  54 ++-
 16 files changed, 361 insertions(+), 458 deletions(-)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
index 2a54cbce..b426f583 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
@@ -13,18 +13,17 @@
 #include "Geant4/G4VFastSimulationModel.hh"
 #include "GiGaMTCoreMessage/IGiGaMessage.h"
 
-class ImmediateDepositModel : public G4VFastSimulationModel, public GiGaMessage  {
-	 
-	G4Navigator* m_navigator;
-	G4TouchableHandle m_touchableHandle;
-	bool m_navigatorOn;
+class ImmediateDepositModel : public G4VFastSimulationModel, public GiGaMessage {
 
-	public:
+  G4Navigator*      m_navigator;
+  G4TouchableHandle m_touchableHandle;
+  bool              m_navigatorOn;
 
-    ImmediateDepositModel(G4String modelName, G4Region* envelope);
-    ~ImmediateDepositModel();
+public:
+  ImmediateDepositModel( G4String modelName, G4Region* envelope );
+  ~ImmediateDepositModel();
 
-  	G4bool IsApplicable(const G4ParticleDefinition& aParticle) override;
-	G4bool ModelTrigger(const G4FastTrack& aFastTrack) override;
- 	void DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastStep) override;
+  G4bool IsApplicable( const G4ParticleDefinition& aParticle ) override;
+  G4bool ModelTrigger( const G4FastTrack& aFastTrack ) override;
+  void   DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) override;
 };
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
index 8682a848..e368e105 100755
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
@@ -8,31 +8,30 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
+#include "Geant4/G4AutoDelete.hh"
 #include "Geant4/G4Box.hh"
+#include "Geant4/G4Colour.hh"
+#include "Geant4/G4GlobalMagFieldMessenger.hh"
 #include "Geant4/G4LogicalVolume.hh"
+#include "Geant4/G4MultiFunctionalDetector.hh"
 #include "Geant4/G4NistManager.hh"
+#include "Geant4/G4PSEnergyDeposit.hh"
+#include "Geant4/G4PSTrackLength.hh"
 #include "Geant4/G4PVPlacement.hh"
-#include "Geant4/G4SystemOfUnits.hh"
 #include "Geant4/G4PVReplica.hh"
 #include "Geant4/G4PhysicalConstants.hh"
-#include "Geant4/G4VisAttributes.hh"
-#include "Geant4/G4SDManager.hh"
-#include "Geant4/G4GlobalMagFieldMessenger.hh"
-#include "Geant4/G4AutoDelete.hh"
 #include "Geant4/G4SDChargedFilter.hh"
-#include "Geant4/G4MultiFunctionalDetector.hh"
+#include "Geant4/G4SDManager.hh"
+#include "Geant4/G4SystemOfUnits.hh"
 #include "Geant4/G4VPrimitiveScorer.hh"
-#include "Geant4/G4PSEnergyDeposit.hh"
-#include "Geant4/G4PSTrackLength.hh"
-#include "Geant4/G4Colour.hh"
+#include "Geant4/G4VisAttributes.hh"
 
 #include "SimpleCaloGeo.h"
 #include "SimpleCaloSD.h"
 
 DECLARE_COMPONENT( SimpleCaloGeo )
 
-StatusCode SimpleCaloGeo::queryInterface( const InterfaceID& id, void** ppI )
-{
+StatusCode SimpleCaloGeo::queryInterface( const InterfaceID& id, void** ppI ) {
   if ( 0 == ppI ) {
     return StatusCode::FAILURE; //  RETURN !!!
   } else if ( IGiGaMTGeoSvc::interfaceID() == id ) {
@@ -46,197 +45,169 @@ StatusCode SimpleCaloGeo::queryInterface( const InterfaceID& id, void** ppI )
   return StatusCode::SUCCESS;
 }
 
-
 void SimpleCaloGeo::defineMaterials() {
   // Lead material defined using NIST Manager
   auto nistManager = G4NistManager::Instance();
-  nistManager->FindOrBuildMaterial("G4_Pb");
-  
+  nistManager->FindOrBuildMaterial( "G4_Pb" );
+
   // Liquid argon material
-  G4double a;  // mass of a mole;
-  G4double z;  // z=mean number of protons;  
-  G4double density; 
-  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
-         // The argon by NIST Manager is a gas with a different density
+  G4double a; // mass of a mole;
+  G4double z; // z=mean number of protons;
+  G4double density;
+  new G4Material( "liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3 );
+  // The argon by NIST Manager is a gas with a different density
   // Vacuum
-  new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
-                  kStateGas, 2.73*kelvin, 3.e-18*pascal);
+  new G4Material( "Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density, kStateGas, 2.73 * kelvin,
+                  3.e-18 * pascal );
   // Print materials
-  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
+  G4cout << *( G4Material::GetMaterialTable() ) << G4endl;
 }
 
-
-
-G4VPhysicalVolume* SimpleCaloGeo::constructWorld()
-{
+G4VPhysicalVolume* SimpleCaloGeo::constructWorld() {
   // Lead material defined using NIST Manager
   auto nistManager = G4NistManager::Instance();
-  nistManager->FindOrBuildMaterial("G4_Pb");
-  
+  nistManager->FindOrBuildMaterial( "G4_Pb" );
+
   // Liquid argon material
-  G4double a;  // mass of a mole;
-  G4double z;  // z=mean number of protons;  
-  G4double density; 
-  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
-         // The argon by NIST Manager is a gas with a different density
+  G4double a; // mass of a mole;
+  G4double z; // z=mean number of protons;
+  G4double density;
+  new G4Material( "liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3 );
+  // The argon by NIST Manager is a gas with a different density
 
   // Vacuum
-  new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
-                  kStateGas, 2.73*kelvin, 3.e-18*pascal);
+  new G4Material( "Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density, kStateGas, 2.73 * kelvin,
+                  3.e-18 * pascal );
 
   // Print materials
-  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
+  G4cout << *( G4Material::GetMaterialTable() ) << G4endl;
 
   // Geometry parameters
-  G4double  absoThickness = 10.*mm;
-  G4double  gapThickness =  5.*mm;
-  G4double  calorSizeXY  = 10.*cm;
-  auto  layerThickness = absoThickness + gapThickness;
-  auto  calorThickness = m_nofLayers * layerThickness;
-  auto  worldSizeXY = 1.2 * calorSizeXY;
-  auto  worldSizeZ  = 1.2 * calorThickness; 
-  
+  G4double absoThickness  = 10. * mm;
+  G4double gapThickness   = 5. * mm;
+  G4double calorSizeXY    = 10. * cm;
+  auto     layerThickness = absoThickness + gapThickness;
+  auto     calorThickness = m_nofLayers * layerThickness;
+  auto     worldSizeXY    = 1.2 * calorSizeXY;
+  auto     worldSizeZ     = 1.2 * calorThickness;
+
   // Get materials
-  auto defaultMaterial = G4Material::GetMaterial("Galactic");
-  auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
-  auto gapMaterial = G4Material::GetMaterial("liquidArgon");
-  
-  if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
+  auto defaultMaterial  = G4Material::GetMaterial( "Galactic" );
+  auto absorberMaterial = G4Material::GetMaterial( "G4_Pb" );
+  auto gapMaterial      = G4Material::GetMaterial( "liquidArgon" );
+
+  if ( !defaultMaterial || !absorberMaterial || !gapMaterial ) {
     G4ExceptionDescription msg;
-    msg << "Cannot retrieve materials already defined."; 
-    G4Exception("B4DetectorConstruction::DefineVolumes()",
-      "MyCode0001", FatalException, msg);
-  }  
-   
-  //     
+    msg << "Cannot retrieve materials already defined.";
+    G4Exception( "B4DetectorConstruction::DefineVolumes()", "MyCode0001", FatalException, msg );
+  }
+
+  //
   // World
   //
-  auto worldS 
-    = new G4Box("World",           // its name
-                 worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
-                         
-  auto worldLV
-    = new G4LogicalVolume(
-                 worldS,           // its solid
-                 defaultMaterial,  // its material
-                 "World");         // its name
-                                   
-  auto worldPV
-    = new G4PVPlacement(0,
-                 G4ThreeVector(),  // at (0,0,0)
-                 worldLV,          // its logical volume                         
-                 "World",          // its name
-                 0,                // its mother  volume
-                 false,            // no boolean operation
-                 0,                // copy number
-                 m_checkOverlaps);  // checking overlaps 
-  
-  //                               
+  auto worldS = new G4Box( "World",                                            // its name
+                           worldSizeXY / 2, worldSizeXY / 2, worldSizeZ / 2 ); // its size
+
+  auto worldLV = new G4LogicalVolume( worldS,          // its solid
+                                      defaultMaterial, // its material
+                                      "World" );       // its name
+
+  auto worldPV = new G4PVPlacement( 0,
+                                    G4ThreeVector(),   // at (0,0,0)
+                                    worldLV,           // its logical volume
+                                    "World",           // its name
+                                    0,                 // its mother  volume
+                                    false,             // no boolean operation
+                                    0,                 // copy number
+                                    m_checkOverlaps ); // checking overlaps
+
+  //
   // Calorimeter
-  //  
-  auto calorimeterS
-    = new G4Box("Calorimeter",     // its name
-                 calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
-                         
-  auto calorLV
-    = new G4LogicalVolume(
-                 calorimeterS,    // its solid
-                 defaultMaterial, // its material
-                 "Calorimeter");  // its name
-                                   
-  new G4PVPlacement(
-                 0,                // no rotation
-                 G4ThreeVector(),  // at (0,0,0)
-                 calorLV,          // its logical volume                         
-                 "Calorimeter",    // its name
-                 worldLV,          // its mother  volume
-                 false,            // no boolean operation
-                 0,                // copy number
-                 m_checkOverlaps);  // checking overlaps 
-  
-  //                                 
+  //
+  auto calorimeterS = new G4Box( "Calorimeter",                                          // its name
+                                 calorSizeXY / 2, calorSizeXY / 2, calorThickness / 2 ); // its size
+
+  auto calorLV = new G4LogicalVolume( calorimeterS,    // its solid
+                                      defaultMaterial, // its material
+                                      "Calorimeter" ); // its name
+
+  new G4PVPlacement( 0,                 // no rotation
+                     G4ThreeVector(),   // at (0,0,0)
+                     calorLV,           // its logical volume
+                     "Calorimeter",     // its name
+                     worldLV,           // its mother  volume
+                     false,             // no boolean operation
+                     0,                 // copy number
+                     m_checkOverlaps ); // checking overlaps
+
+  //
   // Layer
   //
-  auto layerS 
-    = new G4Box("Layer",           // its name
-                 calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
-                         
-  auto layerLV
-    = new G4LogicalVolume(
-                 layerS,           // its solid
-                 defaultMaterial,  // its material
-                 "Layer");         // its name
-  new G4PVReplica(
-                 "Layer",          // its name
-                 layerLV,          // its logical volume
-                 calorLV,          // its mother
-                 kZAxis,           // axis of replication
-                 m_nofLayers,        // number of replica
-                 layerThickness);  // witdth of replica
-  
-  //                               
+  auto layerS = new G4Box( "Layer",                                                // its name
+                           calorSizeXY / 2, calorSizeXY / 2, layerThickness / 2 ); // its size
+
+  auto layerLV = new G4LogicalVolume( layerS,          // its solid
+                                      defaultMaterial, // its material
+                                      "Layer" );       // its name
+  new G4PVReplica( "Layer",                            // its name
+                   layerLV,                            // its logical volume
+                   calorLV,                            // its mother
+                   kZAxis,                             // axis of replication
+                   m_nofLayers,                        // number of replica
+                   layerThickness );                   // witdth of replica
+
+  //
   // Absorber
   //
-  auto absorberS 
-    = new G4Box("Abso",            // its name
-                 calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
-                         
-  m_absorberLV
-    = new G4LogicalVolume(
-                 absorberS,        // its solid
-                 absorberMaterial, // its material
-                 "AbsoLV");          // its name
-                                   
-   new G4PVPlacement(
-                 0,                // no rotation
-                 G4ThreeVector(0., 0., -gapThickness/2), //  its position
-                 m_absorberLV,       // its logical volume                         
-                 "Abso",           // its name
-                 layerLV,          // its mother  volume
-                 false,            // no boolean operation
-                 0,                // copy number
-                 m_checkOverlaps);  // checking overlaps 
-  //                               
+  auto absorberS = new G4Box( "Abso",                                                // its name
+                              calorSizeXY / 2, calorSizeXY / 2, absoThickness / 2 ); // its size
+
+  m_absorberLV = new G4LogicalVolume( absorberS,        // its solid
+                                      absorberMaterial, // its material
+                                      "AbsoLV" );       // its name
+
+  new G4PVPlacement( 0,                                          // no rotation
+                     G4ThreeVector( 0., 0., -gapThickness / 2 ), //  its position
+                     m_absorberLV,                               // its logical volume
+                     "Abso",                                     // its name
+                     layerLV,                                    // its mother  volume
+                     false,                                      // no boolean operation
+                     0,                                          // copy number
+                     m_checkOverlaps );                          // checking overlaps
+  //
   // Gap
   //
-  auto gapS 
-    = new G4Box("Gap",             // its name
-                 calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
-                         
-  m_gapLV = new G4LogicalVolume(
-                 gapS,             // its solid
-                 gapMaterial,      // its material
-                 "GapLV");      // its name
-                                   
-  new G4PVPlacement(
-                 0,                // no rotation
-                 G4ThreeVector(0., 0., absoThickness/2), //  its position
-                 m_gapLV,            // its logical volume                         
-                 "Gap",            // its name
-                 layerLV,          // its mother  volume
-                 false,            // no boolean operation
-                 0,                // copy number
-                 m_checkOverlaps);  // checking overlaps 
-  
+  auto gapS = new G4Box( "Gap",                                                // its name
+                         calorSizeXY / 2, calorSizeXY / 2, gapThickness / 2 ); // its size
+
+  m_gapLV = new G4LogicalVolume( gapS,        // its solid
+                                 gapMaterial, // its material
+                                 "GapLV" );   // its name
+
+  new G4PVPlacement( 0,                                          // no rotation
+                     G4ThreeVector( 0., 0., absoThickness / 2 ), //  its position
+                     m_gapLV,                                    // its logical volume
+                     "Gap",                                      // its name
+                     layerLV,                                    // its mother  volume
+                     false,                                      // no boolean operation
+                     0,                                          // copy number
+                     m_checkOverlaps );                          // checking overlaps
+
   //
   // print parameters
   //
-  G4cout
-    << G4endl 
-    << "------------------------------------------------------------" << G4endl
-    << "---> The calorimeter is " << m_nofLayers << " layers of: [ "
-    << absoThickness/mm << "mm of " << absorberMaterial->GetName() 
-    << " + "
-    << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl
-    << "------------------------------------------------------------" << G4endl;
-  
-  //                                        
+  G4cout << G4endl << "------------------------------------------------------------" << G4endl
+         << "---> The calorimeter is " << m_nofLayers << " layers of: [ " << absoThickness / mm << "mm of "
+         << absorberMaterial->GetName() << " + " << gapThickness / mm << "mm of " << gapMaterial->GetName() << " ] "
+         << G4endl << "------------------------------------------------------------" << G4endl;
+
+  //
   // Visualization attributes
   //
-  worldLV->SetVisAttributes (G4VisAttributes::GetInvisible());
-  auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
-  simpleBoxVisAtt->SetVisibility(true);
-  calorLV->SetVisAttributes(simpleBoxVisAtt);
+  worldLV->SetVisAttributes( G4VisAttributes::GetInvisible() );
+  auto simpleBoxVisAtt = new G4VisAttributes( G4Colour( 1.0, 1.0, 1.0 ) );
+  simpleBoxVisAtt->SetVisibility( true );
+  calorLV->SetVisAttributes( simpleBoxVisAtt );
   //
   // Always return the physical World
   //
@@ -245,31 +216,28 @@ G4VPhysicalVolume* SimpleCaloGeo::constructWorld()
 
 void SimpleCaloGeo::constructSDandField() {
   // G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
-  // 
+  //
   // Sensitive detectors
   //
-  
+
   auto absoSD = m_absorberFAC->construct();
-  G4SDManager::GetSDMpointer()->AddNewDetector(absoSD);
-  m_absorberLV->SetSensitiveDetector(absoSD);
+  G4SDManager::GetSDMpointer()->AddNewDetector( absoSD );
+  m_absorberLV->SetSensitiveDetector( absoSD );
 
-  
   auto gapSD = m_gapFAC->construct();
-  G4SDManager::GetSDMpointer()->AddNewDetector(gapSD);
-  m_gapLV->SetSensitiveDetector(gapSD);
-  
+  G4SDManager::GetSDMpointer()->AddNewDetector( gapSD );
+  m_gapLV->SetSensitiveDetector( gapSD );
 
-  // 
+  //
   // Magnetic field
   //
   // Create global magnetic field messenger.
   // Uniform magnetic field is then created automatically if
   // the field value is not zero.
-  //G4ThreeVector fieldValue;
-  //fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
-  //fMagFieldMessenger->SetVerboseLevel(1);
-  
+  // G4ThreeVector fieldValue;
+  // fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
+  // fMagFieldMessenger->SetVerboseLevel(1);
+
   // Register the field messenger for deleting
-  //G4AutoDelete::Register(fMagFieldMessenger);
+  // G4AutoDelete::Register(fMagFieldMessenger);
 }
-
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
index 9a4a63bf..7417ecf6 100755
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
@@ -23,30 +23,25 @@
 class G4VPhysicalVolume;
 class G4LogicalVolume;
 
-class SimpleCaloGeo : public Service, virtual public IGiGaMTGeoSvc
-{
+class SimpleCaloGeo : public Service, virtual public IGiGaMTGeoSvc {
 
 protected:
   using Service::Service;
 
 public:
-  StatusCode initialize() override {return Service::initialize();}
-  StatusCode finalize() override { return Service::finalize();}
-
+  StatusCode initialize() override { return Service::initialize(); }
+  StatusCode finalize() override { return Service::finalize(); }
 
   virtual G4VPhysicalVolume* constructWorld() override;
-  virtual void constructSDandField() override;
-  virtual StatusCode queryInterface( const InterfaceID& iid, void** pI ) override;
+  virtual void               constructSDandField() override;
+  virtual StatusCode         queryInterface( const InterfaceID& iid, void** pI ) override;
 
 private:
-
-    
-  void defineMaterials();
-  Gaudi::Property<bool> m_checkOverlaps{this, "CheckOverlaps", true}; 
-  Gaudi::Property<int> m_nofLayers{this, "LayersNumber", 10};
-  G4LogicalVolume* m_gapLV;
-  G4LogicalVolume* m_absorberLV;
-  ToolHandle<SimpleCaloSDFAC> m_absorberFAC {"AbsorberFAC", this}; 
-  ToolHandle<SimpleCaloSDFAC> m_gapFAC {"GapFAC", this};
-
+  void                        defineMaterials();
+  Gaudi::Property<bool>       m_checkOverlaps{this, "CheckOverlaps", true};
+  Gaudi::Property<int>        m_nofLayers{this, "LayersNumber", 10};
+  G4LogicalVolume*            m_gapLV;
+  G4LogicalVolume*            m_absorberLV;
+  ToolHandle<SimpleCaloSDFAC> m_absorberFAC{"AbsorberFAC", this};
+  ToolHandle<SimpleCaloSDFAC> m_gapFAC{"GapFAC", this};
 };
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
index 91b9de13..ea5a3766 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
@@ -9,16 +9,14 @@
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
 #include "SimpleCaloHit.h"
-#include "Geant4/G4UnitsTable.hh"
-#include "Geant4/G4VVisManager.hh"
 #include "Geant4/G4Circle.hh"
 #include "Geant4/G4Colour.hh"
+#include "Geant4/G4UnitsTable.hh"
+#include "Geant4/G4VVisManager.hh"
 #include "Geant4/G4VisAttributes.hh"
 #include <iomanip>
 G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator = 0;
 
-SimpleCaloHit::SimpleCaloHit() : G4VHit(), m_energy(0.) {}
+SimpleCaloHit::SimpleCaloHit() : G4VHit(), m_energy( 0. ) {}
 
 SimpleCaloHit::~SimpleCaloHit() {}
-
-
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
index b23b3354..be3485b2 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
@@ -10,11 +10,11 @@
 \*****************************************************************************/
 #pragma once
 
-#include "Geant4/G4VHit.hh"
-#include "Geant4/G4THitsCollection.hh"
 #include "Geant4/G4Allocator.hh"
-#include "Geant4/G4ThreeVector.hh"
+#include "Geant4/G4THitsCollection.hh"
 #include "Geant4/G4Threading.hh"
+#include "Geant4/G4ThreeVector.hh"
+#include "Geant4/G4VHit.hh"
 
 /// Calorimeter hit class
 ///
@@ -22,72 +22,60 @@
 /// of charged particles in a selected volume:
 /// - m_energy
 
-class SimpleCaloHit : public G4VHit
-{
-  public:
-    SimpleCaloHit();
-    SimpleCaloHit(const SimpleCaloHit&);
-    virtual ~SimpleCaloHit();
-
-    // operators
-    const SimpleCaloHit& operator=(const SimpleCaloHit&);
-    //G4int operator==(const SimpleCaloHit&) const;
-
-    inline void* operator new(size_t);
-    inline void  operator delete(void*);
-
-    // methods from base class
-    // virtual void Draw() {}
-    //virtual void Print();
-
-    // methods to handle data
-    void Add(G4double de);
-
-    // get methods
-    G4double GetEnergy() const;
-    //G4double GetTrackLength() const;
-      
-  private:
-    G4double m_energy;        ///< Energy deposit in the sensitive volume
-    // G4double fTrackLength; ///< Track length in the  sensitive volume
-};
+class SimpleCaloHit : public G4VHit {
+public:
+  SimpleCaloHit();
+  SimpleCaloHit( const SimpleCaloHit& );
+  virtual ~SimpleCaloHit();
+
+  // operators
+  const SimpleCaloHit& operator=( const SimpleCaloHit& );
+  // G4int operator==(const SimpleCaloHit&) const;
 
+  inline void* operator new( size_t );
+  inline void  operator delete( void* );
+
+  // methods from base class
+  // virtual void Draw() {}
+  // virtual void Print();
+
+  // methods to handle data
+  void Add( G4double de );
+
+  // get methods
+  G4double GetEnergy() const;
+  // G4double GetTrackLength() const;
+
+private:
+  G4double m_energy; ///< Energy deposit in the sensitive volume
+                     // G4double fTrackLength; ///< Track length in the  sensitive volume
+};
 
 using SimpleCaloHitsCollection = G4THitsCollection<SimpleCaloHit>;
 
 extern G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator;
 
-
-inline void* SimpleCaloHit::operator new(size_t)
-{
-  if (!SimpleCaloHitAllocator) {
-    SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>;
-  }
-  void *hit;
-  hit = (void *) SimpleCaloHitAllocator->MallocSingle();
+inline void* SimpleCaloHit::operator new( size_t ) {
+  if ( !SimpleCaloHitAllocator ) { SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>; }
+  void* hit;
+  hit = (void*)SimpleCaloHitAllocator->MallocSingle();
   return hit;
 }
 
-inline void SimpleCaloHit::operator delete(void *hit)
-{
-  if (!SimpleCaloHitAllocator) {
-    SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>;
-  }
-  SimpleCaloHitAllocator->FreeSingle((SimpleCaloHit*) hit);
+inline void SimpleCaloHit::operator delete( void* hit ) {
+  if ( !SimpleCaloHitAllocator ) { SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>; }
+  SimpleCaloHitAllocator->FreeSingle( (SimpleCaloHit*)hit );
 }
 
-inline void SimpleCaloHit::Add(G4double de) {
-  m_energy += de; 
+inline void SimpleCaloHit::Add( G4double de ) {
+  m_energy += de;
   // fTrackLength += dl;
 }
 
-inline G4double SimpleCaloHit::GetEnergy() const { 
-  return m_energy; 
-}
+inline G4double SimpleCaloHit::GetEnergy() const { return m_energy; }
 
 /*
-inline G4double SimpleCaloHit::GetTrackLength() const { 
-  return fTrackLength; 
+inline G4double SimpleCaloHit::GetTrackLength() const {
+  return fTrackLength;
 }
 */
-
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
index 4f6f662f..c8beb846 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
@@ -10,57 +10,53 @@
 \*****************************************************************************/
 #include "SimpleCaloSD.h"
 #include "Geant4/G4HCofThisEvent.hh"
+#include "Geant4/G4SDManager.hh"
 #include "Geant4/G4Step.hh"
 #include "Geant4/G4ThreeVector.hh"
-#include "Geant4/G4SDManager.hh"
 #include "Geant4/G4ios.hh"
 
-
-SimpleCaloSD::SimpleCaloSD(const G4String& name) : G4VSensitiveDetector(name) {
-  collectionName.insert(SensitiveDetectorName + "HitsCollection");
+SimpleCaloSD::SimpleCaloSD( const G4String& name ) : G4VSensitiveDetector( name ) {
+  collectionName.insert( SensitiveDetectorName + "HitsCollection" );
 }
 
-
-void SimpleCaloSD::Initialize(G4HCofThisEvent* hce)
-{
-  m_hitsCollection = new SimpleCaloHitsCollection(SensitiveDetectorName, collectionName[0]); 
-  auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
-  hce->AddHitsCollection( hcID, m_hitsCollection ); 
-  for (G4int i=0; i < m_cellsNo; i++ ) {
-    m_hitsCollection->insert(new SimpleCaloHit());
-  }
+void SimpleCaloSD::Initialize( G4HCofThisEvent* hce ) {
+  m_hitsCollection = new SimpleCaloHitsCollection( SensitiveDetectorName, collectionName[0] );
+  auto hcID        = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[0] );
+  hce->AddHitsCollection( hcID, m_hitsCollection );
+  for ( G4int i = 0; i < m_cellsNo; i++ ) { m_hitsCollection->insert( new SimpleCaloHit() ); }
 }
 
-G4bool SimpleCaloSD::Hit(G4Step * aStep) {
-         G4TouchableHistory* ROhis = 0;
-         if(!isActive()) return false;
-         if(filter)
-         { if(!(filter->Accept(aStep))) return false; }
-         if(ROgeometry)
-         { if(!(ROgeometry->CheckROVolume(aStep,ROhis))) return false; }
-         return ProcessHits(aStep,ROhis);
+G4bool SimpleCaloSD::Hit( G4Step* aStep ) {
+  G4TouchableHistory* ROhis = 0;
+  if ( !isActive() ) return false;
+  if ( filter ) {
+    if ( !( filter->Accept( aStep ) ) ) return false;
+  }
+  if ( ROgeometry ) {
+    if ( !( ROgeometry->CheckROVolume( aStep, ROhis ) ) ) return false;
+  }
+  return ProcessHits( aStep, ROhis );
 }
 
-bool SimpleCaloSD::ProcessHits(G4Step* step, G4TouchableHistory*) {  
+bool SimpleCaloSD::ProcessHits( G4Step* step, G4TouchableHistory* ) {
   auto edep = step->GetTotalEnergyDeposit();
-  if ( edep == 0. ) return false;      
-  auto touchable = (step->GetPreStepPoint()->GetTouchable());
-  auto layerNumber = touchable->GetReplicaNumber(1);
-  auto hit = (*m_hitsCollection)[layerNumber];
-  if ( ! hit ) {
+  if ( edep == 0. ) return false;
+  auto touchable   = ( step->GetPreStepPoint()->GetTouchable() );
+  auto layerNumber = touchable->GetReplicaNumber( 1 );
+  auto hit         = ( *m_hitsCollection )[layerNumber];
+  if ( !hit ) {
     G4ExceptionDescription msg;
-    msg << "Cannot access hit " << layerNumber; 
-    G4Exception("SimpleCaloSD::ProcessHits()",
-      "MyCode0004", FatalException, msg);
-  }         
-  
-  hit->Add(edep);
+    msg << "Cannot access hit " << layerNumber;
+    G4Exception( "SimpleCaloSD::ProcessHits()", "MyCode0004", FatalException, msg );
+  }
+
+  hit->Add( edep );
   return true;
 }
 
-void SimpleCaloSD::EndOfEvent(G4HCofThisEvent*) {
-  if (!m_hitsCollection) {
-    warning("There are no hits in the hits collection.");
+void SimpleCaloSD::EndOfEvent( G4HCofThisEvent* ) {
+  if ( !m_hitsCollection ) {
+    warning( "There are no hits in the hits collection." );
     return;
   }
 }
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
index e0131a1a..6367be8d 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
@@ -24,29 +24,27 @@
 class G4Step;
 class G4HCofThisEvent;
 
-
 class SimpleCaloSD : public G4VSensitiveDetector, public virtual GiGaMessage {
-  public:
-    SimpleCaloSD(const G4String& name);
-    virtual ~SimpleCaloSD() = default;
+public:
+  SimpleCaloSD( const G4String& name );
+  virtual ~SimpleCaloSD() = default;
 
-    // methods from base class
-    void   Initialize(G4HCofThisEvent* hitCollection) override;
-    bool ProcessHits(G4Step* step, G4TouchableHistory* history) override;
-    void   EndOfEvent(G4HCofThisEvent* hitCollection) override;
-    G4bool 	Hit (G4Step *aStep);
+  // methods from base class
+  void   Initialize( G4HCofThisEvent* hitCollection ) override;
+  bool   ProcessHits( G4Step* step, G4TouchableHistory* history ) override;
+  void   EndOfEvent( G4HCofThisEvent* hitCollection ) override;
+  G4bool Hit( G4Step* aStep );
 
-    SimpleCaloHitsCollection* m_hitsCollection = nullptr;
-    int  m_cellsNo;
+  SimpleCaloHitsCollection* m_hitsCollection = nullptr;
+  int                       m_cellsNo;
 };
 
 class SimpleCaloSDFAC : public GiGaMTG4SensDetFactory<SimpleCaloSD> {
 
   // TODO: this is the same property as in SimpleCaloGeo
-  Gaudi::Property<int> m_cellsNo {this, "CellsNo", 10};
+  Gaudi::Property<int> m_cellsNo{this, "CellsNo", 10};
 
-  public:
-  
+public:
   using base_class = GiGaMTG4SensDetFactory<SimpleCaloSD>;
   using base_class::GiGaMTG4SensDetFactory;
 
@@ -56,11 +54,11 @@ class SimpleCaloSDFAC : public GiGaMTG4SensDetFactory<SimpleCaloSD> {
     tmp->SetVerboseLevel( MSG::DEBUG );
     tmp->SetMessageInterface( message_interface() );
     tmp->m_cellsNo = m_cellsNo;
-    //tmp->m_nhits = &m_nhits;
-    //tmp->m_energy = &m_energy;
+    // tmp->m_nhits = &m_nhits;
+    // tmp->m_energy = &m_energy;
     return tmp;
   }
 };
 
-DECLARE_COMPONENT_WITH_ID(SimpleCaloSDFAC, "GapFAC")
-DECLARE_COMPONENT_WITH_ID(SimpleCaloSDFAC, "AbsorberFAC")
+DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "GapFAC" )
+DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "AbsorberFAC" )
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
index 9ae82a91..1b8340f3 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
@@ -16,32 +16,30 @@
 // Geant4
 #include "Geant4/G4Event.hh"
 
-  
 DECLARE_COMPONENT( SimpleCaloSaveHits )
 
 StatusCode SimpleCaloSaveHits::finalize() {
-  if(msgLevel(MSG::INFO)) {
-    info() << "SimpleCaloHits total energy: " << m_energy.sum()  << endmsg;
+  if ( msgLevel( MSG::INFO ) ) {
+    info() << "SimpleCaloHits total energy: " << m_energy.sum() << endmsg;
     info() << "SimpleCaloHits energy mean: " << m_energy.mean() << endmsg;
     info() << "SimpleCaloHits energy mean error: " << m_energy.meanErr() << endmsg;
   }
   return extends::finalize();
 }
 
-
 StatusCode SimpleCaloSaveHits::monitor( const G4Event& aEvent ) {
   G4HCofThisEvent* collections = aEvent.GetHCofThisEvent();
 
   for ( int iter_coll = 0; iter_coll < collections->GetNumberOfCollections(); iter_coll++ ) {
-      G4VHitsCollection* collection = collections->GetHC( iter_coll );
-      int n_hit = collection->GetSize();
-      if (msgLevel(MSG::DEBUG)) {
-        debug() << "Spotted #" << n_hit << " hits stored in " << collection->GetName() << " collection." << endmsg;
-      }
-      for ( int iter_hit = 0; iter_hit < n_hit; iter_hit++ ) {
-        SimpleCaloHit* hit = dynamic_cast<SimpleCaloHit*>( collection->GetHit( iter_hit ) );
-        if (hit->GetEnergy() > 0.) m_energy += hit->GetEnergy();
-      }
+    G4VHitsCollection* collection = collections->GetHC( iter_coll );
+    int                n_hit      = collection->GetSize();
+    if ( msgLevel( MSG::DEBUG ) ) {
+      debug() << "Spotted #" << n_hit << " hits stored in " << collection->GetName() << " collection." << endmsg;
+    }
+    for ( int iter_hit = 0; iter_hit < n_hit; iter_hit++ ) {
+      SimpleCaloHit* hit = dynamic_cast<SimpleCaloHit*>( collection->GetHit( iter_hit ) );
+      if ( hit->GetEnergy() > 0. ) m_energy += hit->GetEnergy();
+    }
   }
   return StatusCode::SUCCESS;
 }
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
index 30ee96f9..e73bf8b6 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
@@ -13,14 +13,13 @@
 #include "GaudiAlg/GaudiTool.h"
 #include "SimInterfaces/IG4MonitoringTool.h"
 
-class SimpleCaloSaveHits: public extends<GaudiTool, IG4MonitoringTool> {
-  
-  mutable Gaudi::Accumulators::StatCounter<double> m_energy {this, "energy"};
+class SimpleCaloSaveHits : public extends<GaudiTool, IG4MonitoringTool> {
+
+  mutable Gaudi::Accumulators::StatCounter<double> m_energy{this, "energy"};
 
 public:
   using extends::extends;
 
   virtual StatusCode finalize() override;
-  virtual StatusCode monitor(const G4Event& aEvent) override;
+  virtual StatusCode monitor( const G4Event& aEvent ) override;
 };
-
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
index c96cdacc..8f0ee29c 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
@@ -9,67 +9,50 @@
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
 #include "FastSimulationExample/ImmediateDepositModel.h"
-#include "GiGaMTFactories/GiGaMTFastSimModelFAC.h"
 #include "Geant4/G4TransportationManager.hh"
 #include "Geant4/G4VSensitiveDetector.hh"
+#include "GiGaMTFactories/GiGaMTFastSimModelFAC.h"
 
-ImmediateDepositModel::ImmediateDepositModel(G4String modelName, G4Region* envelope)
-  : G4VFastSimulationModel(modelName, envelope) {
-	m_touchableHandle = new G4TouchableHistory();
-	m_navigator = new G4Navigator();
-	m_navigatorOn = false;
-}
-
-ImmediateDepositModel::~ImmediateDepositModel(){
-	delete m_navigator;
-}
-
-
-G4bool ImmediateDepositModel::IsApplicable(const G4ParticleDefinition&) {
-	return true;
+ImmediateDepositModel::ImmediateDepositModel( G4String modelName, G4Region* envelope )
+    : G4VFastSimulationModel( modelName, envelope ) {
+  m_touchableHandle = new G4TouchableHistory();
+  m_navigator       = new G4Navigator();
+  m_navigatorOn     = false;
 }
 
+ImmediateDepositModel::~ImmediateDepositModel() { delete m_navigator; }
 
-G4bool ImmediateDepositModel::ModelTrigger(const G4FastTrack&) {
-	return true;
-}
+G4bool ImmediateDepositModel::IsApplicable( const G4ParticleDefinition& ) { return true; }
 
+G4bool ImmediateDepositModel::ModelTrigger( const G4FastTrack& ) { return true; }
 
-void ImmediateDepositModel::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastStep) {
-	aFastStep.KillPrimaryTrack();
-	G4double Edep = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
+void ImmediateDepositModel::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
+  aFastStep.KillPrimaryTrack();
+  G4double Edep = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
 
-	aFastStep.SetTotalEnergyDeposited( Edep );
-	G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
-	if (!m_navigatorOn) {
-	  	auto worldVolume = G4TransportationManager::GetTransportationManager()->
-                       GetNavigatorForTracking()->GetWorldVolume();
-		m_navigator -> SetWorldVolume(worldVolume);
-		m_navigator -> LocateGlobalPointAndUpdateTouchableHandle(position,
-		   														G4ThreeVector(0.,0.,0.),
-																m_touchableHandle,
-																false);
-		m_navigatorOn = true;
-	} else {
-		m_navigator -> LocateGlobalPointAndUpdateTouchableHandle(position,
-		   														G4ThreeVector(0.,0.,0.),
-																m_touchableHandle);
-	}
+  aFastStep.SetTotalEnergyDeposited( Edep );
+  G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
+  if ( !m_navigatorOn ) {
+    auto worldVolume = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
+    m_navigator->SetWorldVolume( worldVolume );
+    m_navigator->LocateGlobalPointAndUpdateTouchableHandle( position, G4ThreeVector( 0., 0., 0. ), m_touchableHandle,
+                                                            false );
+    m_navigatorOn = true;
+  } else {
+    m_navigator->LocateGlobalPointAndUpdateTouchableHandle( position, G4ThreeVector( 0., 0., 0. ), m_touchableHandle );
+  }
 
-	
-	G4Step *fakeStep = new G4Step();
-	G4StepPoint* fakePreStepPoint = fakeStep->GetPreStepPoint();
-	fakePreStepPoint->SetTouchableHandle(m_touchableHandle);
-	fakeStep->SetTotalEnergyDeposit(Edep);
+  G4Step*      fakeStep         = new G4Step();
+  G4StepPoint* fakePreStepPoint = fakeStep->GetPreStepPoint();
+  fakePreStepPoint->SetTouchableHandle( m_touchableHandle );
+  fakeStep->SetTotalEnergyDeposit( Edep );
 
-	G4VPhysicalVolume* pCurrentVolume = fakeStep->GetPreStepPoint()->GetPhysicalVolume();
+  G4VPhysicalVolume* pCurrentVolume = fakeStep->GetPreStepPoint()->GetPhysicalVolume();
 
-  	if( pCurrentVolume) {
-      G4VSensitiveDetector* pSensitive = pCurrentVolume->GetLogicalVolume()->GetSensitiveDetector();
-      if( pSensitive) {
-         pSensitive->Hit(fakeStep);
-      }
-    }
+  if ( pCurrentVolume ) {
+    G4VSensitiveDetector* pSensitive = pCurrentVolume->GetLogicalVolume()->GetSensitiveDetector();
+    if ( pSensitive ) { pSensitive->Hit( fakeStep ); }
+  }
 }
 
 using ImmediateDepositModelFAC = GiGaMTFastSimModelFAC<ImmediateDepositModel>;
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
index d13589fb..63a3c2e0 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_gamma_gun.py
@@ -26,6 +26,6 @@ pgun.FixedMomentum.PdgCodes = [22]
 
 from Configurables import FlatNParticles
 pgun.NumberOfParticlesTool = "FlatNParticles"
-pgun.addTool( FlatNParticles , name = "FlatNParticles" )
+pgun.addTool(FlatNParticles, name="FlatNParticles")
 pgun.FlatNParticles.MinNParticles = 1
 pgun.FlatNParticles.MaxNParticles = 1
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
index ecf2d215..0029d7a8 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
@@ -26,7 +26,8 @@ gmpl.PhysicsConstructors.append('GiGaMTFastSimPhysFAC/FastSimPhys')
 
 from Configurables import GiGaMTDetectorConstructionFAC
 giga.DetectorConstruction = "GiGaMTDetectorConstructionFAC"
-dettool = giga.addTool(GiGaMTDetectorConstructionFAC, "GiGaMTDetectorConstructionFAC")
+dettool = giga.addTool(GiGaMTDetectorConstructionFAC,
+                       "GiGaMTDetectorConstructionFAC")
 dettool.OutputLevel = -10
 
 from Configurables import SimpleCaloGeo
@@ -35,13 +36,15 @@ SimpleCaloGeo().OutputLevel = 10
 dettool.GiGaMTGeoSvc = "SimpleCaloGeo"
 ApplicationMgr().ExtSvc += [SimpleCaloGeo()]
 
-
 from Configurables import GiGaRegionTool
 from Configurables import ImmediateDepositModel
-giga_region = GiGaRegionTool(Region="ImmediateDepositRegion",
-        Volumes=["AbsoLV", "GapLV"])
+giga_region = GiGaRegionTool(
+    Region="ImmediateDepositRegion", Volumes=["AbsoLV", "GapLV"])
 dettool.addTool(giga_region, name='ImmediateDepositRegionTool')
-dettool.AfterGeoConstructionTools.append("GiGaRegionTool/ImmediateDepositRegionTool")
-fastSimModel = ImmediateDepositModel(ModelName="ImmediateDepositModel", RegionName="ImmediateDepositRegion")
+dettool.AfterGeoConstructionTools.append(
+    "GiGaRegionTool/ImmediateDepositRegionTool")
+fastSimModel = ImmediateDepositModel(
+    ModelName="ImmediateDepositModel", RegionName="ImmediateDepositRegion")
 dettool.addTool(fastSimModel, name='ImmediateDepositModelConstr')
-dettool.FastModelConstructors.append('ImmediateDepositModel/ImmediateDepositModelConstr')
+dettool.FastModelConstructors.append(
+    'ImmediateDepositModel/ImmediateDepositModelConstr')
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
index 70eaab60..8e8f5aa8 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
@@ -19,7 +19,6 @@ Gaussino().EnableHive = True
 Gaussino().ThreadPoolSize = 20
 Gaussino().EventSlots = 20
 
-
 from Configurables import SimpleCaloSaveHits
 monitool = giga.addTool(SimpleCaloSaveHits())
 giga.MonitorTools = ["SimpleCaloSaveHits"]
diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
index 2869fca3..643a39f8 100644
--- a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
@@ -10,38 +10,29 @@
 \*****************************************************************************/
 #pragma once
 
+#include "Geant4/G4RegionStore.hh"
+#include "Geant4/G4VFastSimulationModel.hh"
 #include "GiGaMTFactories/GiGaFactoryBase.h"
 #include "GiGaMTFactories/GiGaTool.h"
-#include "Geant4/G4VFastSimulationModel.hh"
-#include "Geant4/G4RegionStore.hh"
 
 template <typename FastSimModel>
-class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSimulationModel>>
-{
+class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSimulationModel>> {
   static_assert( std::is_base_of<G4VFastSimulationModel, FastSimModel>::value );
 
-    public:
-  
+public:
   using extends::extends;
   G4VFastSimulationModel* construct() const override {
-    if (msgLevel(MSG::DEBUG)) {
-      debug() << "Loading fast simulation region " << m_region.value() << endmsg; 
-    }
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Loading fast simulation region " << m_region.value() << endmsg; }
     G4Region* region = G4RegionStore::GetInstance()->GetRegion( m_region.value() );
 
-    if (msgLevel(MSG::DEBUG)) {
-      debug() << "Loading Fast Sim Model " << m_model.value() << endmsg; 
-    }
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Loading Fast Sim Model " << m_model.value() << endmsg; }
     auto tmp = new FastSimModel{m_model.value(), region};
-    tmp->SetMessageInterface(message_interface());
+    tmp->SetMessageInterface( message_interface() );
 
-    if (msgLevel(MSG::DEBUG)) {
-      debug() << "Loaded Fast Sim Model " << m_model.value() << endmsg; 
-    }
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Loaded Fast Sim Model " << m_model.value() << endmsg; }
     return tmp;
   }
 
-  Gaudi::Property<std::string> m_region {this, "RegionName", ""};
-  Gaudi::Property<std::string> m_model {this, "ModelName", ""};
+  Gaudi::Property<std::string> m_region{this, "RegionName", ""};
+  Gaudi::Property<std::string> m_model{this, "ModelName", ""};
 };
-
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
index 44517900..390e0de7 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
@@ -64,12 +64,10 @@ void GiGaMTDetectorConstructionFAC::DressVolumes() const {
 }
 
 void GiGaMTDetectorConstructionFAC::BuildFastModels() const {
-    for(auto& fastModelName : m_fastModelConstrs) {
-      if (msgLevel(MSG::DEBUG)) {  
-        debug() << "Running fast simulation constructor " << fastModelName << endmsg;
-      }
-      tool<FastModelFactory>(fastModelName, this)->construct();
-    }   
+  for ( auto& fastModelName : m_fastModelConstrs ) {
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Running fast simulation constructor " << fastModelName << endmsg; }
+    tool<FastModelFactory>( fastModelName, this )->construct();
+  }
 }
 
 
diff --git a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
index 36ab8c64..c668112f 100644
--- a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
+++ b/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
@@ -8,52 +8,42 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-#include "Geant4/G4VPhysicsConstructor.hh"
-#include "GiGaMTCoreMessage/IGiGaMessage.h" 
 #include "Geant4/G4FastSimulationManagerProcess.hh"
 #include "Geant4/G4ProcessManager.hh"
+#include "Geant4/G4VPhysicsConstructor.hh"
+#include "GiGaMTCoreMessage/IGiGaMessage.h"
 #include "GiGaMTFactories/GiGaMTG4PhysicsConstrFAC.h"
 
-class GiGaMTFastSimPhys : public G4VPhysicsConstructor, public GiGaMessage
-{
+class GiGaMTFastSimPhys : public G4VPhysicsConstructor, public GiGaMessage {
 public:
   GiGaMTFastSimPhys() = default;
-  void ConstructParticle () override {};
-  void ConstructProcess  () override
-  {
-    //TODO: give a possibility to choose a set of particles
-    //TODO: an option to set parallel geometry 
-    G4FastSimulationManagerProcess* fastSimProcess = new G4FastSimulationManagerProcess("G4FSMP");
-    auto theParticleIterator = GetParticleIterator();
+  void ConstructParticle() override{};
+  void ConstructProcess() override {
+    // TODO: give a possibility to choose a set of particles
+    // TODO: an option to set parallel geometry
+    G4FastSimulationManagerProcess* fastSimProcess      = new G4FastSimulationManagerProcess( "G4FSMP" );
+    auto                            theParticleIterator = GetParticleIterator();
     theParticleIterator->reset();
     // Fast simulation manager process is available for all the particles
-    while ((*theParticleIterator)()) {
-        G4ParticleDefinition* particle = theParticleIterator->value();
-        G4ProcessManager* process_manager = particle->GetProcessManager();
-        process_manager->AddDiscreteProcess(fastSimProcess);
+    while ( ( *theParticleIterator )() ) {
+      G4ParticleDefinition* particle        = theParticleIterator->value();
+      G4ProcessManager*     process_manager = particle->GetProcessManager();
+      process_manager->AddDiscreteProcess( fastSimProcess );
     }
   }
 };
 
-class GiGaMTFastSimPhysFAC : public extends<GiGaMTPhysConstr, GiGaFactoryBase<G4VPhysicsConstructor>>
-{
+class GiGaMTFastSimPhysFAC : public extends<GiGaMTPhysConstr, GiGaFactoryBase<G4VPhysicsConstructor>> {
 public:
   using extends::extends;
-  GiGaMTFastSimPhys* construct() const override
-  {
-    if (msgLevel(MSG::DEBUG)) {
-      debug() << "Constructing fast simulation physics" << endmsg;
-    }
+  GiGaMTFastSimPhys* construct() const override {
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Constructing fast simulation physics" << endmsg; }
     auto tmp = new GiGaMTFastSimPhys{};
-    tmp->SetMessageInterface(message_interface());
-    tmp->SetVerboseLevel(verbosity());
-    tmp->SetPhysicsName(name());
-    if (msgLevel(MSG::DEBUG)) {
-      debug() << "Constructed fast simulation physics" << endmsg;
-    }
+    tmp->SetMessageInterface( message_interface() );
+    tmp->SetVerboseLevel( verbosity() );
+    tmp->SetPhysicsName( name() );
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Constructed fast simulation physics" << endmsg; }
     return tmp;
-   }
+  }
 };
-DECLARE_COMPONENT_WITH_ID(GiGaMTFastSimPhysFAC, "GiGaMTFastSimPhysFAC")
-
-
+DECLARE_COMPONENT_WITH_ID( GiGaMTFastSimPhysFAC, "GiGaMTFastSimPhysFAC" )
-- 
GitLab


From 662af3bacec2895f27cdeb41032ab1f6a8c98a4c Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 3 Feb 2021 17:26:56 +0100
Subject: [PATCH 07/24] Fix proprties in GiGaMTFastSimModelFAC.h

---
 Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
index 643a39f8..143047fa 100644
--- a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
@@ -19,6 +19,8 @@ template <typename FastSimModel>
 class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSimulationModel>> {
   static_assert( std::is_base_of<G4VFastSimulationModel, FastSimModel>::value );
 
+  Gaudi::Property<std::string> m_region{this, "RegionName", ""};
+  Gaudi::Property<std::string> m_model{this, "ModelName", ""};
 public:
   using extends::extends;
   G4VFastSimulationModel* construct() const override {
@@ -33,6 +35,4 @@ public:
     return tmp;
   }
 
-  Gaudi::Property<std::string> m_region{this, "RegionName", ""};
-  Gaudi::Property<std::string> m_model{this, "ModelName", ""};
 };
-- 
GitLab


From 05a8faccbe572b067712fc7d40bfd782e91b2a32 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 3 Feb 2021 21:28:14 +0100
Subject: [PATCH 08/24] Added fast region factory

---
 .../GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h

diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h
new file mode 100644
index 00000000..0180da79
--- /dev/null
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h
@@ -0,0 +1,82 @@
+#pragma once
+
+#include "GiGaMTFactories/GiGaTool.h"
+#include "GiGaMTFactories/GiGaFactoryBase.h"
+
+#include "Geant4/G4Region.hh"
+#include "Geant4/G4RegionStore.hh"
+#include "Geant4/G4LogicalVolume.hh"
+#include "Geant4/G4LogicalVolumeStore.hh"
+#include "Geant4/G4SDManager.hh"
+
+class GiGaMTFastG4RegionFAC : public extends<GiGaTool, GiGaFactoryBase<G4Region>> {
+
+  Gaudi::Property<std::string> m_region_name{this, "RegionName", std::string()};
+  Gaudi::Property<std::string> m_det_name{this, "DetName", std::string()};
+  Gaudi::Property<std::string> m_sens_det_name_suffix{this, "SensDetNameSuffix", "SDet"};
+  Gaudi::Property<std::vector<std::string>> m_volumes{this, "Volumes", {}};
+
+public:
+  using extends::extends;
+  virtual G4Region* construct() const override {
+    
+    if ( m_region_name.value().empty() && m_det_name.value().empty() ) {
+      error() << "No name specified for the new fast region." << endmsg;
+    }
+
+    auto sens_det_name = m_det_name.value() + m_sens_det_name_suffix.value();
+    auto region_name = m_region_name.value().empty() ? sens_det_name + "FastRegion" : m_region_name.value() ;
+
+    auto region = G4RegionStore::GetInstance()->GetRegion( region_name );
+    if ( region ) {
+      warning() << "Fast Region '" + region_name + "'  already exists " << endmsg;
+      return region;
+    }
+
+    auto sdmanager = G4SDManager::GetSDMpointer();
+    std::vector<G4LogicalVolume*> lvolumes;
+    auto volume_store = G4LogicalVolumeStore::GetInstance();
+
+    if (!volume_store) {
+        error() << "Cannot access volume store." << endmsg;
+    }
+    if ( !m_det_name.value().empty() ) {
+      auto sens_det = sdmanager->FindSensitiveDetector( sens_det_name );
+      if (!sens_det) {
+        error() << "Cannot access sensitive detector " << sens_det_name << endmsg;
+      }
+      for( auto ivol = volume_store->begin(); volume_store->end() != ivol ; ++ivol ) {
+        auto vol_sens_det = (*ivol)->GetSensitiveDetector();
+        if (vol_sens_det && sens_det == vol_sens_det) {
+          if (msgLevel( MSG::DEBUG )) {
+            debug() << "Found " << (*ivol)->GetName() << " in " << sens_det->GetName() << endmsg;
+          }
+          lvolumes.push_back(*ivol);
+        }
+      } 
+    } else if ( !m_volumes.value().empty() ) {
+      for ( auto& ivolume : m_volumes.value() ) {
+        lvolumes.push_back(volume_store->GetVolume( ivolume ));
+      }
+    } else {
+      error() << "No G4LogicalVolumes provided nor found for the region " << region_name << endmsg;
+    }
+
+    region = new G4Region( region_name );
+    
+    for ( auto& volume : lvolumes ) {
+      if ( !volume ) {
+        error() << "G4LogicalVolume '" + volume->GetName() + "' is invalid ";
+      }
+      if ( volume->GetRegion() ) {
+        error() << "G4LogicalVolume '" + volume->GetName() + "' already belongs to another region '" + volume->GetRegion()->GetName();
+      }
+      volume->SetRegion( region );
+      region->AddRootLogicalVolume( volume );
+    }
+      
+    return region;
+  }
+};
+
+DECLARE_COMPONENT_WITH_ID(GiGaMTFastG4RegionFAC, "FastG4RegionFAC")
-- 
GitLab


From fab94cd5079e27d054b4b640a9d75c166aef6587 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 3 Feb 2021 21:32:20 +0100
Subject: [PATCH 09/24] Dynamic construction of fast regions

---
 .../src/components/SimpleCaloGeo.h            |  4 +--
 .../src/components/SimpleCaloSD.h             |  4 +--
 .../options/setup_immediate_deposit_model.py  | 25 ++++++++++---------
 .../GiGaMTFactories/GiGaMTFastSimModelFAC.h   | 14 +++++++++--
 .../src/det/GiGaMTDetectorConstructionFAC.cpp | 18 ++++++++++---
 .../src/det/GiGaMTDetectorConstructionFAC.h   | 17 ++++++++++---
 6 files changed, 58 insertions(+), 24 deletions(-)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
index 7417ecf6..c2234b80 100755
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
@@ -42,6 +42,6 @@ private:
   Gaudi::Property<int>        m_nofLayers{this, "LayersNumber", 10};
   G4LogicalVolume*            m_gapLV;
   G4LogicalVolume*            m_absorberLV;
-  ToolHandle<SimpleCaloSDFAC> m_absorberFAC{"AbsorberFAC", this};
-  ToolHandle<SimpleCaloSDFAC> m_gapFAC{"GapFAC", this};
+  ToolHandle<SimpleCaloSDFAC> m_absorberFAC{"AbsorberSDet", this};
+  ToolHandle<SimpleCaloSDFAC> m_gapFAC{"GapSDet", this};
 };
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
index 6367be8d..124c8940 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
@@ -60,5 +60,5 @@ public:
   }
 };
 
-DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "GapFAC" )
-DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "AbsorberFAC" )
+DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "GapSDet" )
+DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "AbsorberSDet" )
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
index 0029d7a8..114b9786 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
@@ -31,20 +31,21 @@ dettool = giga.addTool(GiGaMTDetectorConstructionFAC,
 dettool.OutputLevel = -10
 
 from Configurables import SimpleCaloGeo
-from Configurables import ApplicationMgr
 SimpleCaloGeo().OutputLevel = 10
 dettool.GiGaMTGeoSvc = "SimpleCaloGeo"
+
+from Configurables import ApplicationMgr
 ApplicationMgr().ExtSvc += [SimpleCaloGeo()]
 
-from Configurables import GiGaRegionTool
+from Configurables import FastG4RegionFAC
+fast_region = FastG4RegionFAC()
+fast_region.DetName="Absorber"
+dettool.addTool(fast_region, name='FastRegionAbsorber')
+dettool.FastRegionFactories.append("FastG4RegionFAC/FastRegionAbsorber")
+
 from Configurables import ImmediateDepositModel
-giga_region = GiGaRegionTool(
-    Region="ImmediateDepositRegion", Volumes=["AbsoLV", "GapLV"])
-dettool.addTool(giga_region, name='ImmediateDepositRegionTool')
-dettool.AfterGeoConstructionTools.append(
-    "GiGaRegionTool/ImmediateDepositRegionTool")
-fastSimModel = ImmediateDepositModel(
-    ModelName="ImmediateDepositModel", RegionName="ImmediateDepositRegion")
-dettool.addTool(fastSimModel, name='ImmediateDepositModelConstr')
-dettool.FastModelConstructors.append(
-    'ImmediateDepositModel/ImmediateDepositModelConstr')
+fast_model = ImmediateDepositModel()
+fast_model.ModelName="ImmediateDepositModel"
+fast_model.RegionName="AbsorberSDetFastRegion"
+dettool.addTool(fast_model, name='FastModelAbsorber')
+dettool.FastModelFactories.append('ImmediateDepositModel/FastModelAbsorber')
diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
index 143047fa..95743d8a 100644
--- a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
+++ b/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
@@ -19,11 +19,21 @@ template <typename FastSimModel>
 class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSimulationModel>> {
   static_assert( std::is_base_of<G4VFastSimulationModel, FastSimModel>::value );
 
-  Gaudi::Property<std::string> m_region{this, "RegionName", ""};
-  Gaudi::Property<std::string> m_model{this, "ModelName", ""};
+
+  Gaudi::Property<std::string> m_region{this, "RegionName", std::string()};
+  Gaudi::Property<std::string> m_model{this, "ModelName", std::string()};
 public:
   using extends::extends;
   G4VFastSimulationModel* construct() const override {
+
+    if (m_model.value().empty()) {
+      error() << "Fast model name was not provided." << endmsg;
+    }
+
+    if (m_region.value().empty()) {
+      error() << "Fast region name was not provided." << endmsg;
+    }
+
     if ( msgLevel( MSG::DEBUG ) ) { debug() << "Loading fast simulation region " << m_region.value() << endmsg; }
     G4Region* region = G4RegionStore::GetInstance()->GetRegion( m_region.value() );
 
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
index 390e0de7..1d6fccb3 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
@@ -12,6 +12,7 @@
 #include "GiGaMTCoreDet/GiGaMTDetectorConstruction.h"
 #include "GiGaMTGeo/IGiGaMTGeoSvc.h"
 #include "SimInterfaces/IGaussinoTool.h"
+#include "GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h"
 
 DECLARE_COMPONENT( GiGaMTDetectorConstructionFAC )
 
@@ -20,6 +21,9 @@ StatusCode GiGaMTDetectorConstructionFAC::initialize() {
   // Retrieve the factory tools here to avoid the retrieval happening in multiple
   // threads
   for ( auto& keypairs : m_sens_dets ) { sc &= keypairs.second.retrieve(); }
+  for ( auto& fac : m_fast_region_factories ) { sc &= fac.retrieve(); }
+  for ( auto& fac : m_fast_model_factories ) { sc &= fac.retrieve(); }
+
   return sc;
 }
 
@@ -36,6 +40,7 @@ G4VUserDetectorConstruction* GiGaMTDetectorConstructionFAC::construct() const {
     debug() << "Calling SD and Field constructor" << endmsg;
     m_geoSvc->constructSDandField();
     DressVolumes();
+    BuildFastRegions();
     BuildFastModels();
   } );
 
@@ -63,10 +68,17 @@ void GiGaMTDetectorConstructionFAC::DressVolumes() const {
   }
 }
 
+void GiGaMTDetectorConstructionFAC::BuildFastRegions() const {
+  for ( auto& fast_region_factory : m_fast_region_factories ) {
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Running fast region constructor " << fast_region_factory->name() << endmsg; }
+    fast_region_factory->construct();
+  }
+}
+
 void GiGaMTDetectorConstructionFAC::BuildFastModels() const {
-  for ( auto& fastModelName : m_fastModelConstrs ) {
-    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Running fast simulation constructor " << fastModelName << endmsg; }
-    tool<FastModelFactory>( fastModelName, this )->construct();
+  for ( auto& fast_model_factory : m_fast_model_factories ) {
+    if ( msgLevel( MSG::DEBUG ) ) { debug() << "Running fast model constructor " << fast_model_factory->name() << endmsg; }
+    fast_model_factory->construct();
   }
 }
 
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
index 92cb7801..72e2a38f 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.h
@@ -39,8 +39,10 @@ protected:
   typedef std::map<std::string, SensDetFac> SensDetVolumeMap;
 
   using FastModelFactory = GiGaFactoryBase<G4VFastSimulationModel>;
+  using FastRegionFactory = GiGaFactoryBase<G4Region>;
 
   void DressVolumes() const;
+  void BuildFastRegions() const;
   void BuildFastModels() const;
 
   void SaveGDML(G4LogicalVolume*) const;
@@ -51,9 +53,18 @@ protected:
       tool_array_setter(m_afterGeo, m_afterGeoNames),
       Gaudi::Details::Property::ImmediatelyInvokeHandler{true}};
 
-  Gaudi::Property<std::string> m_schema{this, "Schema", "$GDML_base/src/GDMLSchema/gdml.xsd"};
-  Gaudi::Property<std::vector<std::string>> m_fastModelConstrs{this, "FastModelConstructors", {}};
-  Gaudi::Property<std::string> m_outfile{this, "Output", ""};
+  Gaudi::Property<std::string>              m_schema{this, "Schema", "$GDML_base/src/GDMLSchema/gdml.xsd"};
+  Gaudi::Property<std::string>              m_outfile{this, "Output", ""};
+  ToolHandleArray<FastModelFactory>         m_fast_model_factories{this};
+  ToolHandleArray<FastRegionFactory>         m_fast_region_factories{this};
+  Gaudi::Property<std::vector<std::string>> m_fast_model_factories_names{this, "FastModelFactories", {},
+                                                                      tool_array_setter( m_fast_model_factories, m_fast_model_factories_names), 
+                                                                      Gaudi::Details::Property::ImmediatelyInvokeHandler{true}};
+
+  Gaudi::Property<std::vector<std::string>> m_fast_region_factories_names{this, "FastRegionFactories", {},
+                                                                      tool_array_setter( m_fast_region_factories, m_fast_region_factories_names), 
+                                                                      Gaudi::Details::Property::ImmediatelyInvokeHandler{true}};
+
 private:
   SensDetVolumeMap m_sens_dets;
   Gaudi::Property<SensDetNameVolumesMap> m_namemap{this, "SensDetVolumeMap", {},[this]( Gaudi::Details::PropertyBase& ){
-- 
GitLab


From 7056464d64adc1406f94216de5a97561acbba70b Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Mon, 15 Feb 2021 13:27:55 +0100
Subject: [PATCH 10/24] Move SimpleCaloGeo to a separate package

---
 .../components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloGeo.h    | 0
 .../components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloHit.h    | 0
 .../src/components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloSD.h | 0
 .../SimpleCaloGeo}/SimpleCaloSaveHits.h                           | 0
 .../src/components => SimpleCaloGeo/src}/SimpleCaloGeo.cpp        | 0
 .../src/components => SimpleCaloGeo/src}/SimpleCaloHit.cpp        | 0
 .../src/components => SimpleCaloGeo/src}/SimpleCaloSD.cpp         | 0
 .../src/components => SimpleCaloGeo/src}/SimpleCaloSaveHits.cpp   | 0
 8 files changed, 0 insertions(+), 0 deletions(-)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloGeo.h (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloHit.h (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloSD.h (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/SimpleCaloGeo}/SimpleCaloSaveHits.h (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/src}/SimpleCaloGeo.cpp (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/src}/SimpleCaloHit.cpp (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/src}/SimpleCaloSD.cpp (100%)
 rename Sim/GiGaMTExamples/{FastSimulationExample/src/components => SimpleCaloGeo/src}/SimpleCaloSaveHits.cpp (100%)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSaveHits.h
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSaveHits.h
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloGeo.cpp
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloHit.cpp
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSD.cpp
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/components/SimpleCaloSaveHits.cpp
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
-- 
GitLab


From d8f9240e47989da365911193c6c0ccceedf6d13e Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Mon, 15 Feb 2021 14:12:45 +0100
Subject: [PATCH 11/24] Restructure fast simulation examples

---
 .../FastSimulationExample/CMakeLists.txt      |  6 ++---
 .../src/{lib => }/ImmediateDepositModel.cpp   |  0
 .../SimpleCaloGeo/CMakeLists.txt              | 23 +++++++++++++++++++
 .../options/setup_simple_calo.py              |  0
 4 files changed, 26 insertions(+), 3 deletions(-)
 rename Sim/GiGaMTExamples/FastSimulationExample/src/{lib => }/ImmediateDepositModel.cpp (100%)
 create mode 100644 Sim/GiGaMTExamples/SimpleCaloGeo/CMakeLists.txt
 rename Sim/GiGaMTExamples/{FastSimulationExample/tests => SimpleCaloGeo}/options/setup_simple_calo.py (100%)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
index 39a352ef..7c519fa3 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -19,6 +19,7 @@ gaudi_subdir(FastSimulationExample v1r0)
 
 gaudi_depends_on_subdirs(GaudiAlg
                          Sim/GiGaMTFactories
+			 Sim/GiGaMTExamples/SimpleCaloGeo
                          Sim/GiGaMTCore)
 AddHepMC3()
 if(${Geant4_config_version} VERSION_LESS "10.06")
@@ -27,9 +28,8 @@ if(${Geant4_config_version} VERSION_LESS "10.06")
 endif()
 
 gaudi_add_module(FastSimulationExample
-                  src/lib/*.cpp
-                  src/components/*.cpp
-                  INCLUDE_DIRS GiGaMTFactories
+                  src/*.cpp
+		  INCLUDE_DIRS GiGaMTFactories SimpleCaloGeo
                   LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
 
 add_dependencies(FastSimulationExample HepMC3Ext)
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/lib/ImmediateDepositModel.cpp
rename to Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/CMakeLists.txt b/Sim/GiGaMTExamples/SimpleCaloGeo/CMakeLists.txt
new file mode 100644
index 00000000..bb4949ff
--- /dev/null
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/CMakeLists.txt
@@ -0,0 +1,23 @@
+################################################################################
+# Package: GiGaMTExamples/SimpleCaloGeo
+# 
+# Package that sets a simplified version of electromagnetic calorimeter.
+# 
+#################################################################################
+gaudi_subdir(SimpleCaloGeo v1r0)
+
+gaudi_depends_on_subdirs(GaudiAlg
+                         Sim/GiGaMTFactories
+                         Sim/GiGaMTCore)
+AddHepMC3()
+if(${Geant4_config_version} VERSION_LESS "10.06")
+  add_definitions(-DG4MULTITHREADED)
+  add_definitions(-DG4USE_STD11)
+endif()
+
+gaudi_add_module(SimpleCaloGeo
+                  src/*.cpp
+                  INCLUDE_DIRS GiGaMTFactories
+                  LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
+
+add_dependencies(SimpleCaloGeo HepMC3Ext)
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py b/Sim/GiGaMTExamples/SimpleCaloGeo/options/setup_simple_calo.py
similarity index 100%
rename from Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_simple_calo.py
rename to Sim/GiGaMTExamples/SimpleCaloGeo/options/setup_simple_calo.py
-- 
GitLab


From 78426be9001f62391e5904db38f41536cd47a58e Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Mon, 15 Feb 2021 14:24:22 +0100
Subject: [PATCH 12/24] Separate fast-sim-related classes from the rest of
 factories

---
 Sim/GiGaMTFastSimulation/CMakeLists.txt       | 24 +++++++++++++++++++
 .../GiGaMTFastGiGaRegionFAC.h                 |  0
 .../GiGaMTFastSimModelFAC.h                   |  0
 .../src}/GiGaMTFastSimPhysFAC.cpp             |  0
 4 files changed, 24 insertions(+)
 create mode 100644 Sim/GiGaMTFastSimulation/CMakeLists.txt
 rename Sim/{GiGaMTFactories/GiGaMTFactories => GiGaMTFastSimulation/GiGaMTFastSimulation}/GiGaMTFastGiGaRegionFAC.h (100%)
 rename Sim/{GiGaMTFactories/GiGaMTFactories => GiGaMTFastSimulation/GiGaMTFastSimulation}/GiGaMTFastSimModelFAC.h (100%)
 rename Sim/{GiGaMTFactories/src/phys => GiGaMTFastSimulation/src}/GiGaMTFastSimPhysFAC.cpp (100%)

diff --git a/Sim/GiGaMTFastSimulation/CMakeLists.txt b/Sim/GiGaMTFastSimulation/CMakeLists.txt
new file mode 100644
index 00000000..94e13adc
--- /dev/null
+++ b/Sim/GiGaMTFastSimulation/CMakeLists.txt
@@ -0,0 +1,24 @@
+################################################################################
+# Package: GiGaMTFastSimulation
+# 
+# Package that ...
+# 
+#################################################################################
+gaudi_subdir(GiGaMTFastSimulation v1r0)
+
+gaudi_depends_on_subdirs(GaudiAlg
+  #Sim/GiGaMTFactories
+                         Sim/GiGaMTCore)
+AddHepMC3()
+
+if(${Geant4_config_version} VERSION_LESS "10.06")
+  add_definitions(-DG4MULTITHREADED)
+  add_definitions(-DG4USE_STD11)
+endif()
+
+gaudi_add_module(GiGaMTFastSimulation
+                  src/*.cpp
+                  #INCLUDE_DIRS GiGaMTFactories
+                  LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
+
+add_dependencies(GiGaMTFastSimulation HepMC3Ext)
diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h
similarity index 100%
rename from Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h
rename to Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h
diff --git a/Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h
similarity index 100%
rename from Sim/GiGaMTFactories/GiGaMTFactories/GiGaMTFastSimModelFAC.h
rename to Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h
diff --git a/Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp b/Sim/GiGaMTFastSimulation/src/GiGaMTFastSimPhysFAC.cpp
similarity index 100%
rename from Sim/GiGaMTFactories/src/phys/GiGaMTFastSimPhysFAC.cpp
rename to Sim/GiGaMTFastSimulation/src/GiGaMTFastSimPhysFAC.cpp
-- 
GitLab


From a8c0eaf027f73df4a73e7419751343a819ae423c Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Mon, 15 Feb 2021 20:10:17 +0100
Subject: [PATCH 13/24] Restructure fast simulation examples 2

---
 .../FastSimulationExample/CMakeLists.txt      |  4 +-
 .../src/ImmediateDepositModel.cpp             |  2 +-
 .../tests/qmtest/fast_simulation.qmt          |  2 +-
 .../SimpleCaloGeo/SimpleCaloGeo.h             | 24 ++++-----
 .../SimpleCaloGeo/SimpleCaloHit.h             | 50 ++++---------------
 .../SimpleCaloGeo/SimpleCaloSD.h              | 10 +---
 .../SimpleCaloGeo/src/SimpleCaloGeo.cpp       |  4 +-
 .../SimpleCaloGeo/src/SimpleCaloHit.cpp       | 13 ++---
 .../SimpleCaloGeo/src/SimpleCaloSD.cpp        |  8 +--
 .../SimpleCaloGeo/src/SimpleCaloSaveHits.cpp  |  4 +-
 .../src/det/GiGaMTDetectorConstructionFAC.cpp |  1 -
 Sim/GiGaMTFastSimulation/CMakeLists.txt       |  4 +-
 12 files changed, 40 insertions(+), 86 deletions(-)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
index 7c519fa3..2fc84069 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -19,7 +19,7 @@ gaudi_subdir(FastSimulationExample v1r0)
 
 gaudi_depends_on_subdirs(GaudiAlg
                          Sim/GiGaMTFactories
-			 Sim/GiGaMTExamples/SimpleCaloGeo
+			 Sim/GiGaMTFastSimulation
                          Sim/GiGaMTCore)
 AddHepMC3()
 if(${Geant4_config_version} VERSION_LESS "10.06")
@@ -29,7 +29,7 @@ endif()
 
 gaudi_add_module(FastSimulationExample
                   src/*.cpp
-		  INCLUDE_DIRS GiGaMTFactories SimpleCaloGeo
+		  INCLUDE_DIRS GiGaMTFactories GiGaMTFastSimulation
                   LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
 
 add_dependencies(FastSimulationExample HepMC3Ext)
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
index 8f0ee29c..2df38fb6 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
@@ -11,7 +11,7 @@
 #include "FastSimulationExample/ImmediateDepositModel.h"
 #include "Geant4/G4TransportationManager.hh"
 #include "Geant4/G4VSensitiveDetector.hh"
-#include "GiGaMTFactories/GiGaMTFastSimModelFAC.h"
+#include "GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h"
 
 ImmediateDepositModel::ImmediateDepositModel( G4String modelName, G4Region* envelope )
     : G4VFastSimulationModel( modelName, envelope ) {
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt b/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
index 8a30df9e..6f94a0cf 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/qmtest/fast_simulation.qmt
@@ -13,7 +13,7 @@
 <extension class="GaudiTest.GaudiExeTest" kind="test">
 <argument name="program"><text>gaudirun.py</text></argument>
 <argument name="args"><set>
-    <text>$FASTSIMULATIONEXAMPLETESTS/options/setup_simple_calo.py</text>
+    <text>$SIMPLECALOGEOROOT/options/setup_simple_calo.py</text>
     <text>$FASTSIMULATIONEXAMPLETESTS/options/setup_gamma_gun.py</text>
     <text>$FASTSIMULATIONEXAMPLETESTS/options/setup_immediate_deposit_model.py</text>
 </set></argument>
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
index c2234b80..5a5344f0 100755
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
@@ -10,20 +10,27 @@
 \*****************************************************************************/
 #pragma once
 
-// from Gaudi
 #include "GaudiKernel/Kernel.h"
 #include "GaudiKernel/Service.h"
 #include "GaudiKernel/StatusCode.h"
 
-// from GiGa
 #include "GiGaMTGeo/IGiGaMTGeoSvc.h"
-#include "SimpleCaloSD.h"
+#include "SimpleCaloGeo/SimpleCaloSD.h"
 
-// from G4
 class G4VPhysicalVolume;
 class G4LogicalVolume;
 
 class SimpleCaloGeo : public Service, virtual public IGiGaMTGeoSvc {
+  G4LogicalVolume*            m_gapLV;
+  G4LogicalVolume*            m_absorberLV;
+
+  Gaudi::Property<bool>       m_checkOverlaps{this, "CheckOverlaps", true};
+  Gaudi::Property<int>        m_nofLayers{this, "LayersNumber", 10};
+
+  ToolHandle<SimpleCaloSDFAC> m_absorberFAC{"AbsorberSDet", this};
+  ToolHandle<SimpleCaloSDFAC> m_gapFAC{"GapSDet", this};
+
+  void                        defineMaterials();
 
 protected:
   using Service::Service;
@@ -35,13 +42,4 @@ public:
   virtual G4VPhysicalVolume* constructWorld() override;
   virtual void               constructSDandField() override;
   virtual StatusCode         queryInterface( const InterfaceID& iid, void** pI ) override;
-
-private:
-  void                        defineMaterials();
-  Gaudi::Property<bool>       m_checkOverlaps{this, "CheckOverlaps", true};
-  Gaudi::Property<int>        m_nofLayers{this, "LayersNumber", 10};
-  G4LogicalVolume*            m_gapLV;
-  G4LogicalVolume*            m_absorberLV;
-  ToolHandle<SimpleCaloSDFAC> m_absorberFAC{"AbsorberSDet", this};
-  ToolHandle<SimpleCaloSDFAC> m_gapFAC{"GapSDet", this};
 };
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h
index be3485b2..6dff6931 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h
@@ -16,39 +16,22 @@
 #include "Geant4/G4ThreeVector.hh"
 #include "Geant4/G4VHit.hh"
 
-/// Calorimeter hit class
-///
-/// It defines data members to store the the energy deposit and track lengths
-/// of charged particles in a selected volume:
-/// - m_energy
 
 class SimpleCaloHit : public G4VHit {
-public:
-  SimpleCaloHit();
-  SimpleCaloHit( const SimpleCaloHit& );
-  virtual ~SimpleCaloHit();
 
-  // operators
-  const SimpleCaloHit& operator=( const SimpleCaloHit& );
-  // G4int operator==(const SimpleCaloHit&) const;
+  double m_energy;
+
+public:
+  SimpleCaloHit() = default;
+  inline SimpleCaloHit( const SimpleCaloHit& ) : G4VHit(), m_energy( 0. ) {};
+  virtual ~SimpleCaloHit() = default; 
 
   inline void* operator new( size_t );
   inline void  operator delete( void* );
 
-  // methods from base class
-  // virtual void Draw() {}
-  // virtual void Print();
-
-  // methods to handle data
-  void Add( G4double de );
-
-  // get methods
-  G4double GetEnergy() const;
-  // G4double GetTrackLength() const;
+  inline void Add( double de ) { m_energy += de; }
 
-private:
-  G4double m_energy; ///< Energy deposit in the sensitive volume
-                     // G4double fTrackLength; ///< Track length in the  sensitive volume
+  inline double GetEnergy() const { return m_energy; }
 };
 
 using SimpleCaloHitsCollection = G4THitsCollection<SimpleCaloHit>;
@@ -57,25 +40,10 @@ extern G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator;
 
 inline void* SimpleCaloHit::operator new( size_t ) {
   if ( !SimpleCaloHitAllocator ) { SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>; }
-  void* hit;
-  hit = (void*)SimpleCaloHitAllocator->MallocSingle();
-  return hit;
+  return (void*)SimpleCaloHitAllocator->MallocSingle();
 }
 
 inline void SimpleCaloHit::operator delete( void* hit ) {
   if ( !SimpleCaloHitAllocator ) { SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>; }
   SimpleCaloHitAllocator->FreeSingle( (SimpleCaloHit*)hit );
 }
-
-inline void SimpleCaloHit::Add( G4double de ) {
-  m_energy += de;
-  // fTrackLength += dl;
-}
-
-inline G4double SimpleCaloHit::GetEnergy() const { return m_energy; }
-
-/*
-inline G4double SimpleCaloHit::GetTrackLength() const {
-  return fTrackLength;
-}
-*/
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
index 124c8940..b32e72eb 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
@@ -10,16 +10,12 @@
 \*****************************************************************************/
 #pragma once
 
-// Gaudi
-#include "Gaudi/Accumulators.h"
-
-// GiGa
 #include "GiGaMTCoreMessage/IGiGaMessage.h"
 #include "GiGaMTFactories/GiGaMTG4SensDetFactory.h"
 
 #include "Geant4/G4VSensitiveDetector.hh"
-#include "SimpleCaloHit.h"
-#include <vector>
+
+#include "SimpleCaloGeo/SimpleCaloHit.h"
 
 class G4Step;
 class G4HCofThisEvent;
@@ -60,5 +56,3 @@ public:
   }
 };
 
-DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "GapSDet" )
-DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "AbsorberSDet" )
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
index e368e105..a0fdcee7 100755
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
@@ -26,8 +26,8 @@
 #include "Geant4/G4VPrimitiveScorer.hh"
 #include "Geant4/G4VisAttributes.hh"
 
-#include "SimpleCaloGeo.h"
-#include "SimpleCaloSD.h"
+#include "SimpleCaloGeo/SimpleCaloGeo.h"
+#include "SimpleCaloGeo/SimpleCaloSD.h"
 
 DECLARE_COMPONENT( SimpleCaloGeo )
 
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
index ea5a3766..e066488d 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
@@ -8,15 +8,8 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-#include "SimpleCaloHit.h"
-#include "Geant4/G4Circle.hh"
-#include "Geant4/G4Colour.hh"
-#include "Geant4/G4UnitsTable.hh"
-#include "Geant4/G4VVisManager.hh"
-#include "Geant4/G4VisAttributes.hh"
-#include <iomanip>
-G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator = 0;
 
-SimpleCaloHit::SimpleCaloHit() : G4VHit(), m_energy( 0. ) {}
+#include "SimpleCaloGeo/SimpleCaloHit.h"
+
+G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator = 0;
 
-SimpleCaloHit::~SimpleCaloHit() {}
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
index c8beb846..610650cc 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
@@ -8,12 +8,11 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-#include "SimpleCaloSD.h"
+#include "SimpleCaloGeo/SimpleCaloSD.h"
+
 #include "Geant4/G4HCofThisEvent.hh"
 #include "Geant4/G4SDManager.hh"
 #include "Geant4/G4Step.hh"
-#include "Geant4/G4ThreeVector.hh"
-#include "Geant4/G4ios.hh"
 
 SimpleCaloSD::SimpleCaloSD( const G4String& name ) : G4VSensitiveDetector( name ) {
   collectionName.insert( SensitiveDetectorName + "HitsCollection" );
@@ -60,3 +59,6 @@ void SimpleCaloSD::EndOfEvent( G4HCofThisEvent* ) {
     return;
   }
 }
+
+DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "GapSDet" )
+DECLARE_COMPONENT_WITH_ID( SimpleCaloSDFAC, "AbsorberSDet" )
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
index 1b8340f3..288dea86 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
@@ -9,8 +9,8 @@
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
 // Immediate
-#include "SimpleCaloSaveHits.h"
-#include "SimpleCaloHit.h"
+#include "SimpleCaloGeo/SimpleCaloSaveHits.h"
+#include "SimpleCaloGeo/SimpleCaloHit.h"
 // Gaudi
 #include "GaudiKernel/ITHistSvc.h"
 // Geant4
diff --git a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
index 1d6fccb3..add270b4 100644
--- a/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
+++ b/Sim/GiGaMTFactories/src/det/GiGaMTDetectorConstructionFAC.cpp
@@ -12,7 +12,6 @@
 #include "GiGaMTCoreDet/GiGaMTDetectorConstruction.h"
 #include "GiGaMTGeo/IGiGaMTGeoSvc.h"
 #include "SimInterfaces/IGaussinoTool.h"
-#include "GiGaMTFactories/GiGaMTFastGiGaRegionFAC.h"
 
 DECLARE_COMPONENT( GiGaMTDetectorConstructionFAC )
 
diff --git a/Sim/GiGaMTFastSimulation/CMakeLists.txt b/Sim/GiGaMTFastSimulation/CMakeLists.txt
index 94e13adc..70ab6a57 100644
--- a/Sim/GiGaMTFastSimulation/CMakeLists.txt
+++ b/Sim/GiGaMTFastSimulation/CMakeLists.txt
@@ -7,7 +7,7 @@
 gaudi_subdir(GiGaMTFastSimulation v1r0)
 
 gaudi_depends_on_subdirs(GaudiAlg
-  #Sim/GiGaMTFactories
+			 Sim/GiGaMTFactories
                          Sim/GiGaMTCore)
 AddHepMC3()
 
@@ -18,7 +18,7 @@ endif()
 
 gaudi_add_module(GiGaMTFastSimulation
                   src/*.cpp
-                  #INCLUDE_DIRS GiGaMTFactories
+                  INCLUDE_DIRS GiGaMTFactories
                   LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
 
 add_dependencies(GiGaMTFastSimulation HepMC3Ext)
-- 
GitLab


From bd02707194ca8ad57161acc5761d9349a323c241 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Mon, 15 Feb 2021 20:11:08 +0100
Subject: [PATCH 14/24] Split GiGaMTFastGiGaRegionFAC

---
 .../GiGaMTFastGiGaRegionFAC.h                 | 61 +-----------------
 .../src/GiGaMTFastGiGaRegionFAC.cpp           | 62 +++++++++++++++++++
 2 files changed, 63 insertions(+), 60 deletions(-)
 create mode 100644 Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp

diff --git a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h
index 0180da79..494345ef 100644
--- a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h
+++ b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h
@@ -18,65 +18,6 @@ class GiGaMTFastG4RegionFAC : public extends<GiGaTool, GiGaFactoryBase<G4Region>
 
 public:
   using extends::extends;
-  virtual G4Region* construct() const override {
-    
-    if ( m_region_name.value().empty() && m_det_name.value().empty() ) {
-      error() << "No name specified for the new fast region." << endmsg;
-    }
-
-    auto sens_det_name = m_det_name.value() + m_sens_det_name_suffix.value();
-    auto region_name = m_region_name.value().empty() ? sens_det_name + "FastRegion" : m_region_name.value() ;
-
-    auto region = G4RegionStore::GetInstance()->GetRegion( region_name );
-    if ( region ) {
-      warning() << "Fast Region '" + region_name + "'  already exists " << endmsg;
-      return region;
-    }
-
-    auto sdmanager = G4SDManager::GetSDMpointer();
-    std::vector<G4LogicalVolume*> lvolumes;
-    auto volume_store = G4LogicalVolumeStore::GetInstance();
-
-    if (!volume_store) {
-        error() << "Cannot access volume store." << endmsg;
-    }
-    if ( !m_det_name.value().empty() ) {
-      auto sens_det = sdmanager->FindSensitiveDetector( sens_det_name );
-      if (!sens_det) {
-        error() << "Cannot access sensitive detector " << sens_det_name << endmsg;
-      }
-      for( auto ivol = volume_store->begin(); volume_store->end() != ivol ; ++ivol ) {
-        auto vol_sens_det = (*ivol)->GetSensitiveDetector();
-        if (vol_sens_det && sens_det == vol_sens_det) {
-          if (msgLevel( MSG::DEBUG )) {
-            debug() << "Found " << (*ivol)->GetName() << " in " << sens_det->GetName() << endmsg;
-          }
-          lvolumes.push_back(*ivol);
-        }
-      } 
-    } else if ( !m_volumes.value().empty() ) {
-      for ( auto& ivolume : m_volumes.value() ) {
-        lvolumes.push_back(volume_store->GetVolume( ivolume ));
-      }
-    } else {
-      error() << "No G4LogicalVolumes provided nor found for the region " << region_name << endmsg;
-    }
-
-    region = new G4Region( region_name );
-    
-    for ( auto& volume : lvolumes ) {
-      if ( !volume ) {
-        error() << "G4LogicalVolume '" + volume->GetName() + "' is invalid ";
-      }
-      if ( volume->GetRegion() ) {
-        error() << "G4LogicalVolume '" + volume->GetName() + "' already belongs to another region '" + volume->GetRegion()->GetName();
-      }
-      volume->SetRegion( region );
-      region->AddRootLogicalVolume( volume );
-    }
-      
-    return region;
-  }
+  virtual G4Region* construct() const override;
 };
 
-DECLARE_COMPONENT_WITH_ID(GiGaMTFastG4RegionFAC, "FastG4RegionFAC")
diff --git a/Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp b/Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp
new file mode 100644
index 00000000..ccc5b911
--- /dev/null
+++ b/Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp
@@ -0,0 +1,62 @@
+#include "GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h"
+
+G4Region* GiGaMTFastG4RegionFAC::construct() const {
+  if ( m_region_name.value().empty() && m_det_name.value().empty() ) {
+    error() << "No name specified for the new fast region." << endmsg;
+  }
+
+  auto sens_det_name = m_det_name.value() + m_sens_det_name_suffix.value();
+  auto region_name = m_region_name.value().empty() ? sens_det_name + "FastRegion" : m_region_name.value() ;
+
+  auto region = G4RegionStore::GetInstance()->GetRegion( region_name );
+  if ( region ) {
+    warning() << "Fast Region '" + region_name + "'  already exists " << endmsg;
+    return region;
+  }
+
+  auto sdmanager = G4SDManager::GetSDMpointer();
+  std::vector<G4LogicalVolume*> lvolumes;
+  auto volume_store = G4LogicalVolumeStore::GetInstance();
+
+  if (!volume_store) {
+      error() << "Cannot access volume store." << endmsg;
+  }
+  if ( !m_det_name.value().empty() ) {
+    auto sens_det = sdmanager->FindSensitiveDetector( sens_det_name );
+    if (!sens_det) {
+      error() << "Cannot access sensitive detector " << sens_det_name << endmsg;
+    }
+    for( auto ivol = volume_store->begin(); volume_store->end() != ivol ; ++ivol ) {
+      auto vol_sens_det = (*ivol)->GetSensitiveDetector();
+      if (vol_sens_det && sens_det == vol_sens_det) {
+        if (msgLevel( MSG::DEBUG )) {
+          debug() << "Found " << (*ivol)->GetName() << " in " << sens_det->GetName() << endmsg;
+        }
+        lvolumes.push_back(*ivol);
+      }
+    } 
+  } else if ( !m_volumes.value().empty() ) {
+    for ( auto& ivolume : m_volumes.value() ) {
+      lvolumes.push_back(volume_store->GetVolume( ivolume ));
+    }
+  } else {
+    error() << "No G4LogicalVolumes provided nor found for the region " << region_name << endmsg;
+  }
+
+  region = new G4Region( region_name );
+  
+  for ( auto& volume : lvolumes ) {
+    if ( !volume ) {
+      error() << "G4LogicalVolume '" + volume->GetName() + "' is invalid ";
+    }
+    if ( volume->GetRegion() ) {
+      error() << "G4LogicalVolume '" + volume->GetName() + "' already belongs to another region '" + volume->GetRegion()->GetName();
+    }
+    volume->SetRegion( region );
+    region->AddRootLogicalVolume( volume );
+  }
+    
+  return region;
+}
+
+DECLARE_COMPONENT_WITH_ID(GiGaMTFastG4RegionFAC, "FastG4RegionFAC")
-- 
GitLab


From bdca040fd73efce1329e2efc35bc3573702d436b Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Tue, 16 Feb 2021 13:36:32 +0100
Subject: [PATCH 15/24] Introduce namespaces in FastSimulationExample

---
 .../FastSimulationExample/CMakeLists.txt      | 12 +++++------
 .../ImmediateDepositModel.cpp                 | 20 +++++++++----------
 .../ImmediateDeposit}/ImmediateDepositModel.h |  8 +++++---
 .../ImmediateDepositSensitiveDetector.h       |  5 +++++
 .../options/setup_immediate_deposit_model.py  |  6 +++---
 5 files changed, 29 insertions(+), 22 deletions(-)
 rename Sim/GiGaMTExamples/FastSimulationExample/src/{ => ImmediateDeposit}/ImmediateDepositModel.cpp (77%)
 rename Sim/GiGaMTExamples/FastSimulationExample/{FastSimulationExample => src/ImmediateDeposit}/ImmediateDepositModel.h (87%)
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
index 2fc84069..736f0cff 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -19,7 +19,7 @@ gaudi_subdir(FastSimulationExample v1r0)
 
 gaudi_depends_on_subdirs(GaudiAlg
                          Sim/GiGaMTFactories
-			 Sim/GiGaMTFastSimulation
+			             Sim/GiGaMTFastSimulation
                          Sim/GiGaMTCore)
 AddHepMC3()
 if(${Geant4_config_version} VERSION_LESS "10.06")
@@ -27,12 +27,12 @@ if(${Geant4_config_version} VERSION_LESS "10.06")
   add_definitions(-DG4USE_STD11)
 endif()
 
-gaudi_add_module(FastSimulationExample
-                  src/*.cpp
-		  INCLUDE_DIRS GiGaMTFactories GiGaMTFastSimulation
-                  LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
+gaudi_add_module(ImmediateDeposit
+                 src/ImmediateDeposit/*.cpp
+                 INCLUDE_DIRS GiGaMTFactories GiGaMTFastSimulation
+                 LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
 
-add_dependencies(FastSimulationExample HepMC3Ext)
+add_dependencies(ImmediateDeposit HepMC3Ext)
 
 gaudi_env(SET FASTSIMULATIONEXAMPLETESTS \${FASTSIMULATIONEXAMPLEROOT}/tests)
 
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
similarity index 77%
rename from Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
rename to Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
index 2df38fb6..93551538 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
@@ -8,25 +8,25 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-#include "FastSimulationExample/ImmediateDepositModel.h"
+#include "ImmediateDepositModel.h"
 #include "Geant4/G4TransportationManager.hh"
 #include "Geant4/G4VSensitiveDetector.hh"
 #include "GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h"
 
-ImmediateDepositModel::ImmediateDepositModel( G4String modelName, G4Region* envelope )
-    : G4VFastSimulationModel( modelName, envelope ) {
+namespace ImmediateDeposit {
+Model::Model( G4String modelName, G4Region* envelope ) : G4VFastSimulationModel( modelName, envelope ) {
   m_touchableHandle = new G4TouchableHistory();
   m_navigator       = new G4Navigator();
   m_navigatorOn     = false;
 }
 
-ImmediateDepositModel::~ImmediateDepositModel() { delete m_navigator; }
+Model::~Model() { delete m_navigator; }
 
-G4bool ImmediateDepositModel::IsApplicable( const G4ParticleDefinition& ) { return true; }
+G4bool Model::IsApplicable( const G4ParticleDefinition& ) { return true; }
 
-G4bool ImmediateDepositModel::ModelTrigger( const G4FastTrack& ) { return true; }
+G4bool Model::ModelTrigger( const G4FastTrack& ) { return true; }
 
-void ImmediateDepositModel::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
+void Model::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
   aFastStep.KillPrimaryTrack();
   G4double Edep = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
 
@@ -54,6 +54,6 @@ void ImmediateDepositModel::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFa
     if ( pSensitive ) { pSensitive->Hit( fakeStep ); }
   }
 }
-
-using ImmediateDepositModelFAC = GiGaMTFastSimModelFAC<ImmediateDepositModel>;
-DECLARE_COMPONENT_WITH_ID( ImmediateDepositModelFAC, "ImmediateDepositModel" )
+}
+using ImmediateDepositModelFactory = GiGaMTFastSimModelFAC<ImmediateDeposit::Model>;
+DECLARE_COMPONENT_WITH_ID( ImmediateDepositModelFactory, "ImmediateDepositModelFactory" )
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
similarity index 87%
rename from Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
rename to Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
index b426f583..0a987f29 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/FastSimulationExample/ImmediateDepositModel.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
@@ -13,17 +13,19 @@
 #include "Geant4/G4VFastSimulationModel.hh"
 #include "GiGaMTCoreMessage/IGiGaMessage.h"
 
-class ImmediateDepositModel : public G4VFastSimulationModel, public GiGaMessage {
+namespace ImmediateDeposit {
+class Model : public G4VFastSimulationModel, public GiGaMessage {
 
   G4Navigator*      m_navigator;
   G4TouchableHandle m_touchableHandle;
   bool              m_navigatorOn;
 
 public:
-  ImmediateDepositModel( G4String modelName, G4Region* envelope );
-  ~ImmediateDepositModel();
+  Model( G4String modelName, G4Region* envelope );
+  ~Model();
 
   G4bool IsApplicable( const G4ParticleDefinition& aParticle ) override;
   G4bool ModelTrigger( const G4FastTrack& aFastTrack ) override;
   void   DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) override;
 };
+}
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h
new file mode 100644
index 00000000..ffdf7389
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h
@@ -0,0 +1,5 @@
+//#include "SimpleCaloGeo/SimpleCaloSD.h"
+//
+//class ImmediateDepositSimpleCaloFastSimulation : public SimpleCaloSD { 
+//   
+//}
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
index 114b9786..eb2a60a3 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
+++ b/Sim/GiGaMTExamples/FastSimulationExample/tests/options/setup_immediate_deposit_model.py
@@ -43,9 +43,9 @@ fast_region.DetName="Absorber"
 dettool.addTool(fast_region, name='FastRegionAbsorber')
 dettool.FastRegionFactories.append("FastG4RegionFAC/FastRegionAbsorber")
 
-from Configurables import ImmediateDepositModel
-fast_model = ImmediateDepositModel()
+from Configurables import ImmediateDepositModelFactory
+fast_model = ImmediateDepositModelFactory()
 fast_model.ModelName="ImmediateDepositModel"
 fast_model.RegionName="AbsorberSDetFastRegion"
 dettool.addTool(fast_model, name='FastModelAbsorber')
-dettool.FastModelFactories.append('ImmediateDepositModel/FastModelAbsorber')
+dettool.FastModelFactories.append('ImmediateDepositModelFactory/FastModelAbsorber')
-- 
GitLab


From f5ac116f9433fc0b656fdf6c70a95263b4d84b5c Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 17 Feb 2021 19:44:00 +0100
Subject: [PATCH 16/24] move back SimpleCaloGeo to components

---
 Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp        | 4 ++--
 .../SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloGeo.h      | 2 +-
 Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp        | 2 +-
 .../SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloHit.h      | 0
 Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp         | 2 +-
 .../SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloSD.h       | 2 +-
 Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp   | 4 ++--
 .../SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloSaveHits.h | 0
 8 files changed, 8 insertions(+), 8 deletions(-)
 rename Sim/GiGaMTExamples/SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloGeo.h (97%)
 rename Sim/GiGaMTExamples/SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloHit.h (100%)
 rename Sim/GiGaMTExamples/SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloSD.h (98%)
 rename Sim/GiGaMTExamples/SimpleCaloGeo/{SimpleCaloGeo => src}/SimpleCaloSaveHits.h (100%)

diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
index a0fdcee7..e368e105 100755
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.cpp
@@ -26,8 +26,8 @@
 #include "Geant4/G4VPrimitiveScorer.hh"
 #include "Geant4/G4VisAttributes.hh"
 
-#include "SimpleCaloGeo/SimpleCaloGeo.h"
-#include "SimpleCaloGeo/SimpleCaloSD.h"
+#include "SimpleCaloGeo.h"
+#include "SimpleCaloSD.h"
 
 DECLARE_COMPONENT( SimpleCaloGeo )
 
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.h
similarity index 97%
rename from Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.h
index 5a5344f0..8a0e0874 100755
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloGeo.h
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloGeo.h
@@ -15,7 +15,7 @@
 #include "GaudiKernel/StatusCode.h"
 
 #include "GiGaMTGeo/IGiGaMTGeoSvc.h"
-#include "SimpleCaloGeo/SimpleCaloSD.h"
+#include "SimpleCaloSD.h"
 
 class G4VPhysicalVolume;
 class G4LogicalVolume;
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
index e066488d..d25466d1 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.cpp
@@ -9,7 +9,7 @@
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
 
-#include "SimpleCaloGeo/SimpleCaloHit.h"
+#include "SimpleCaloHit.h"
 
 G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator = 0;
 
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.h
similarity index 100%
rename from Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloHit.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloHit.h
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
index 610650cc..6d6bc90d 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.cpp
@@ -8,7 +8,7 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-#include "SimpleCaloGeo/SimpleCaloSD.h"
+#include "SimpleCaloSD.h"
 
 #include "Geant4/G4HCofThisEvent.hh"
 #include "Geant4/G4SDManager.hh"
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.h
similarity index 98%
rename from Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.h
index b32e72eb..349ebdbf 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSD.h
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSD.h
@@ -15,7 +15,7 @@
 
 #include "Geant4/G4VSensitiveDetector.hh"
 
-#include "SimpleCaloGeo/SimpleCaloHit.h"
+#include "SimpleCaloHit.h"
 
 class G4Step;
 class G4HCofThisEvent;
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
index 288dea86..1b8340f3 100644
--- a/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
+++ b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.cpp
@@ -9,8 +9,8 @@
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
 // Immediate
-#include "SimpleCaloGeo/SimpleCaloSaveHits.h"
-#include "SimpleCaloGeo/SimpleCaloHit.h"
+#include "SimpleCaloSaveHits.h"
+#include "SimpleCaloHit.h"
 // Gaudi
 #include "GaudiKernel/ITHistSvc.h"
 // Geant4
diff --git a/Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSaveHits.h b/Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.h
similarity index 100%
rename from Sim/GiGaMTExamples/SimpleCaloGeo/SimpleCaloGeo/SimpleCaloSaveHits.h
rename to Sim/GiGaMTExamples/SimpleCaloGeo/src/SimpleCaloSaveHits.h
-- 
GitLab


From cbc473c32e3a920cf9267aee5702ff60aac91205 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 17 Feb 2021 19:48:16 +0100
Subject: [PATCH 17/24] move fast simulation factories to components

---
 .../src/{ => components}/GiGaMTFastGiGaRegionFAC.cpp            | 2 +-
 .../components}/GiGaMTFastGiGaRegionFAC.h                       | 0
 .../src/{ => components}/GiGaMTFastSimPhysFAC.cpp               | 0
 3 files changed, 1 insertion(+), 1 deletion(-)
 rename Sim/GiGaMTFastSimulation/src/{ => components}/GiGaMTFastGiGaRegionFAC.cpp (97%)
 rename Sim/GiGaMTFastSimulation/{GiGaMTFastSimulation => src/components}/GiGaMTFastGiGaRegionFAC.h (100%)
 rename Sim/GiGaMTFastSimulation/src/{ => components}/GiGaMTFastSimPhysFAC.cpp (100%)

diff --git a/Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp b/Sim/GiGaMTFastSimulation/src/components/GiGaMTFastGiGaRegionFAC.cpp
similarity index 97%
rename from Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp
rename to Sim/GiGaMTFastSimulation/src/components/GiGaMTFastGiGaRegionFAC.cpp
index ccc5b911..e043cc74 100644
--- a/Sim/GiGaMTFastSimulation/src/GiGaMTFastGiGaRegionFAC.cpp
+++ b/Sim/GiGaMTFastSimulation/src/components/GiGaMTFastGiGaRegionFAC.cpp
@@ -1,4 +1,4 @@
-#include "GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h"
+#include "GiGaMTFastGiGaRegionFAC.h"
 
 G4Region* GiGaMTFastG4RegionFAC::construct() const {
   if ( m_region_name.value().empty() && m_det_name.value().empty() ) {
diff --git a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h b/Sim/GiGaMTFastSimulation/src/components/GiGaMTFastGiGaRegionFAC.h
similarity index 100%
rename from Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastGiGaRegionFAC.h
rename to Sim/GiGaMTFastSimulation/src/components/GiGaMTFastGiGaRegionFAC.h
diff --git a/Sim/GiGaMTFastSimulation/src/GiGaMTFastSimPhysFAC.cpp b/Sim/GiGaMTFastSimulation/src/components/GiGaMTFastSimPhysFAC.cpp
similarity index 100%
rename from Sim/GiGaMTFastSimulation/src/GiGaMTFastSimPhysFAC.cpp
rename to Sim/GiGaMTFastSimulation/src/components/GiGaMTFastSimPhysFAC.cpp
-- 
GitLab


From 074d95219954e7e1771ea226dad0e42fd74e6117 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 17 Feb 2021 19:52:08 +0100
Subject: [PATCH 18/24] introduce a fast simulation link to sensitive detectors
 and prepare it for parallel geometry

---
 Sim/GiGaMTFastSimulation/CMakeLists.txt       | 11 +++--
 .../GiGaMTFastSimulation/GiGaMTFastHit.h      | 19 ++++++++
 .../GiGaMTFastSimSensitiveResponse.h          | 29 ++++++++++++
 .../lib/GiGaMTFastSimSensitiveResponse.cpp    | 47 +++++++++++++++++++
 4 files changed, 103 insertions(+), 3 deletions(-)
 create mode 100644 Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastHit.h
 create mode 100644 Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h
 create mode 100644 Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp

diff --git a/Sim/GiGaMTFastSimulation/CMakeLists.txt b/Sim/GiGaMTFastSimulation/CMakeLists.txt
index 70ab6a57..6c3a3a05 100644
--- a/Sim/GiGaMTFastSimulation/CMakeLists.txt
+++ b/Sim/GiGaMTFastSimulation/CMakeLists.txt
@@ -16,9 +16,14 @@ if(${Geant4_config_version} VERSION_LESS "10.06")
   add_definitions(-DG4USE_STD11)
 endif()
 
-gaudi_add_module(GiGaMTFastSimulation
-                  src/*.cpp
+gaudi_add_library(GiGaMTFastSimulationLib
+                  src/lib/*.cpp
+                  PUBLIC_HEADERS GiGaMTFastSimulation
                   INCLUDE_DIRS GiGaMTFactories
                   LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
 
-add_dependencies(GiGaMTFastSimulation HepMC3Ext)
+gaudi_add_module(GiGaMTFastSimulation
+                 src/components/*.cpp
+                 INCLUDE_DIRS GiGaMTFactories
+                 LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
+
diff --git a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastHit.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastHit.h
new file mode 100644
index 00000000..188a4c98
--- /dev/null
+++ b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastHit.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Geant4/G4ThreeVector.hh"
+
+class GiGaMTFastHit {
+
+  double m_Energy = 0;
+  G4ThreeVector m_Position = G4ThreeVector();
+
+ public:
+  inline GiGaMTFastHit() : m_Energy(), m_Position(G4ThreeVector()) {};
+  inline GiGaMTFastHit(const G4ThreeVector& aPosition, double aEnergy) : m_Energy(aEnergy), m_Position(aPosition) {};
+  virtual ~GiGaMTFastHit() = default;
+
+  inline void SetEnergy(const double& aEnergy) { m_Energy = aEnergy; }
+  inline double GetEnergy() const { return m_Energy; }
+  inline void SetPosition(const G4ThreeVector& aPosition) { m_Position = aPosition; }
+  inline G4ThreeVector GetPosition() const { return m_Position; }
+};
diff --git a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h
new file mode 100644
index 00000000..a7bd16cf
--- /dev/null
+++ b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "Geant4/G4TouchableHandle.hh"
+#include "Geant4/G4Navigator.hh"
+#include "Geant4/G4FastTrack.hh"
+
+#include "GiGaMTCoreMessage/IGiGaMessage.h"
+#include "GiGaMTFastSimulation/GiGaMTFastHit.h"
+
+
+class GiGaMTFastSimSensitiveResponse {
+
+  G4Navigator*      m_navigator;
+  G4TouchableHandle m_touchableHandle;
+  bool              m_navigatorOn;
+  std::string       m_worldWithSdName;
+
+public:
+
+  GiGaMTFastSimSensitiveResponse();
+  inline virtual ~GiGaMTFastSimSensitiveResponse() { delete m_navigator; };
+
+  void simulate(const GiGaMTFastHit& aHit, const G4FastTrack& aTrack);
+  inline void SetNameOfWorldWithSD(const std::string& aName) { m_worldWithSdName = aName; }
+
+protected:
+
+  virtual void modifyFakeStep(G4Step* /*fakeStep*/) {};
+};
diff --git a/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp b/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
new file mode 100644
index 00000000..abf99ab7
--- /dev/null
+++ b/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
@@ -0,0 +1,47 @@
+
+#include "GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h"
+
+#include "Geant4/G4TransportationManager.hh"
+#include "Geant4/G4VSensitiveDetector.hh"
+#include "Geant4/G4TouchableHandle.hh"
+
+GiGaMTFastSimSensitiveResponse::GiGaMTFastSimSensitiveResponse() {
+  m_touchableHandle = new G4TouchableHistory();
+  m_navigator       = new G4Navigator();
+  m_navigatorOn     = false;
+  m_worldWithSdName = std::string();
+}
+
+void GiGaMTFastSimSensitiveResponse::simulate(const GiGaMTFastHit& aHit, const G4FastTrack& aTrack) {
+  if(aHit.GetEnergy() <= 0) return;
+
+  if(!m_navigatorOn) {
+    G4VPhysicalVolume* worldWithSD = nullptr;
+    if(m_worldWithSdName.empty()) {
+      worldWithSD = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
+    }
+    else {
+      worldWithSD = G4TransportationManager::GetTransportationManager()->GetParallelWorld(m_worldWithSdName);
+    }
+    m_navigator->SetWorldVolume(worldWithSD);
+    m_navigator->LocateGlobalPointAndUpdateTouchable(aTrack.GetPrimaryTrack()->GetPosition(), m_touchableHandle(), false);
+    m_navigatorOn = true;
+  }
+  else {
+    m_navigator->LocateGlobalPointAndUpdateTouchable(aTrack.GetInverseAffineTransformation()->TransformPoint(aHit.GetPosition()), m_touchableHandle());
+  }
+  G4VPhysicalVolume* currentVolume = m_touchableHandle()->GetVolume();
+  G4VSensitiveDetector* sensitive;
+  if(currentVolume != 0) {
+    sensitive = currentVolume->GetLogicalVolume()->GetSensitiveDetector();
+    if(sensitive && currentVolume->GetLogicalVolume()->GetFastSimulationManager()) {
+      G4Step*      fakeStep         = new G4Step();
+      G4StepPoint* fakePreStepPoint = fakeStep->GetPreStepPoint();
+      fakePreStepPoint->SetTouchableHandle( m_touchableHandle );
+      fakeStep->SetTotalEnergyDeposit(aHit.GetEnergy());
+      fakeStep->SetTrack(const_cast<G4Track*>(aTrack.GetPrimaryTrack()));
+      modifyFakeStep(fakeStep); // if any other custom modifications have to be applied
+      sensitive->Hit(fakeStep);
+    }
+  }
+}
-- 
GitLab


From 4a4c879075d8c5f63f89c7456001b7865b2e9a71 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 17 Feb 2021 20:11:13 +0100
Subject: [PATCH 19/24] move sensitive response out of ImmediateDeposit model

---
 .../FastSimulationExample/CMakeLists.txt      |  4 +-
 .../ImmediateDepositModel.cpp                 | 40 +++++--------------
 .../ImmediateDeposit/ImmediateDepositModel.h  | 18 ++++++---
 .../ImmediateDepositSensitiveDetector.h       |  5 ---
 4 files changed, 24 insertions(+), 43 deletions(-)
 delete mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
index 736f0cff..29f2d5cc 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -29,8 +29,8 @@ endif()
 
 gaudi_add_module(ImmediateDeposit
                  src/ImmediateDeposit/*.cpp
-                 INCLUDE_DIRS GiGaMTFactories GiGaMTFastSimulation
-                 LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib)
+                 INCLUDE_DIRS GiGaMTFactories 
+                 LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib GiGaMTFastSimulationLib)
 
 add_dependencies(ImmediateDeposit HepMC3Ext)
 
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
index 93551538..073efc18 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
@@ -12,47 +12,25 @@
 #include "Geant4/G4TransportationManager.hh"
 #include "Geant4/G4VSensitiveDetector.hh"
 #include "GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h"
+#include "GiGaMTFastSimulation/GiGaMTFastHit.h"
 
 namespace ImmediateDeposit {
-Model::Model( G4String modelName, G4Region* envelope ) : G4VFastSimulationModel( modelName, envelope ) {
-  m_touchableHandle = new G4TouchableHistory();
-  m_navigator       = new G4Navigator();
-  m_navigatorOn     = false;
-}
 
-Model::~Model() { delete m_navigator; }
+Model::Model( G4String modelName, G4Region* envelope ) : G4VFastSimulationModel( modelName, envelope ), m_sensResponse(new SensitiveResponse) {}
 
 G4bool Model::IsApplicable( const G4ParticleDefinition& ) { return true; }
 
-G4bool Model::ModelTrigger( const G4FastTrack& ) { return true; }
+G4bool Model::ModelTrigger( const G4FastTrack& ) {
+  return true;
+}
 
 void Model::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
+  // kill the track so that it will no longer be propagated by G4
   aFastStep.KillPrimaryTrack();
-  G4double Edep = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
-
-  aFastStep.SetTotalEnergyDeposited( Edep );
+  double energyDeposit = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
+  //aFastStep.SetTotalEnergyDeposited( Edep );
   G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
-  if ( !m_navigatorOn ) {
-    auto worldVolume = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
-    m_navigator->SetWorldVolume( worldVolume );
-    m_navigator->LocateGlobalPointAndUpdateTouchableHandle( position, G4ThreeVector( 0., 0., 0. ), m_touchableHandle,
-                                                            false );
-    m_navigatorOn = true;
-  } else {
-    m_navigator->LocateGlobalPointAndUpdateTouchableHandle( position, G4ThreeVector( 0., 0., 0. ), m_touchableHandle );
-  }
-
-  G4Step*      fakeStep         = new G4Step();
-  G4StepPoint* fakePreStepPoint = fakeStep->GetPreStepPoint();
-  fakePreStepPoint->SetTouchableHandle( m_touchableHandle );
-  fakeStep->SetTotalEnergyDeposit( Edep );
-
-  G4VPhysicalVolume* pCurrentVolume = fakeStep->GetPreStepPoint()->GetPhysicalVolume();
-
-  if ( pCurrentVolume ) {
-    G4VSensitiveDetector* pSensitive = pCurrentVolume->GetLogicalVolume()->GetSensitiveDetector();
-    if ( pSensitive ) { pSensitive->Hit( fakeStep ); }
-  }
+  m_sensResponse->simulate(GiGaMTFastHit(position, energyDeposit), aFastTrack);
 }
 }
 using ImmediateDepositModelFactory = GiGaMTFastSimModelFAC<ImmediateDeposit::Model>;
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
index 0a987f29..01194c9f 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
@@ -12,17 +12,25 @@
 
 #include "Geant4/G4VFastSimulationModel.hh"
 #include "GiGaMTCoreMessage/IGiGaMessage.h"
+#include "GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h"
 
 namespace ImmediateDeposit {
+
+class SensitiveResponse : public GiGaMTFastSimSensitiveResponse {
+  inline virtual void modifyFakeStep(G4Step* fakeStep) override {
+    // this is a hack, so that the model will work on detectors
+    // where it the step must be finite 
+    fakeStep->SetStepLength(0.01);
+  }
+};
+  
 class Model : public G4VFastSimulationModel, public GiGaMessage {
 
-  G4Navigator*      m_navigator;
-  G4TouchableHandle m_touchableHandle;
-  bool              m_navigatorOn;
+  std::unique_ptr<SensitiveResponse> m_sensResponse;
 
 public:
-  Model( G4String modelName, G4Region* envelope );
-  ~Model();
+  Model(G4String modelName, G4Region* envelope);
+  ~Model() = default;
 
   G4bool IsApplicable( const G4ParticleDefinition& aParticle ) override;
   G4bool ModelTrigger( const G4FastTrack& aFastTrack ) override;
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h
deleted file mode 100644
index ffdf7389..00000000
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositSensitiveDetector.h
+++ /dev/null
@@ -1,5 +0,0 @@
-//#include "SimpleCaloGeo/SimpleCaloSD.h"
-//
-//class ImmediateDepositSimpleCaloFastSimulation : public SimpleCaloSD { 
-//   
-//}
-- 
GitLab


From 9318456f415f50baa6be75ea7504d4c513c81236 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Thu, 18 Feb 2021 12:38:58 +0100
Subject: [PATCH 20/24] Fix a problem that appears with a complex logical
 volume structure, detected in ECAL

---
 .../GiGaMTFastSimSensitiveResponse.h          |  2 +-
 .../lib/GiGaMTFastSimSensitiveResponse.cpp    | 23 +++++++++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h
index a7bd16cf..f893c900 100644
--- a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h
+++ b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h
@@ -8,7 +8,7 @@
 #include "GiGaMTFastSimulation/GiGaMTFastHit.h"
 
 
-class GiGaMTFastSimSensitiveResponse {
+class GiGaMTFastSimSensitiveResponse : public GiGaMessage {
 
   G4Navigator*      m_navigator;
   G4TouchableHandle m_touchableHandle;
diff --git a/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp b/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
index abf99ab7..eb7a12bd 100644
--- a/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
+++ b/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
@@ -15,6 +15,7 @@ GiGaMTFastSimSensitiveResponse::GiGaMTFastSimSensitiveResponse() {
 void GiGaMTFastSimSensitiveResponse::simulate(const GiGaMTFastHit& aHit, const G4FastTrack& aTrack) {
   if(aHit.GetEnergy() <= 0) return;
 
+  auto position = aTrack.GetPrimaryTrack()->GetPosition();
   if(!m_navigatorOn) {
     G4VPhysicalVolume* worldWithSD = nullptr;
     if(m_worldWithSdName.empty()) {
@@ -24,24 +25,32 @@ void GiGaMTFastSimSensitiveResponse::simulate(const GiGaMTFastHit& aHit, const G
       worldWithSD = G4TransportationManager::GetTransportationManager()->GetParallelWorld(m_worldWithSdName);
     }
     m_navigator->SetWorldVolume(worldWithSD);
-    m_navigator->LocateGlobalPointAndUpdateTouchable(aTrack.GetPrimaryTrack()->GetPosition(), m_touchableHandle(), false);
+    m_navigator->LocateGlobalPointAndUpdateTouchable(position, m_touchableHandle(), false);
     m_navigatorOn = true;
   }
   else {
-    m_navigator->LocateGlobalPointAndUpdateTouchable(aTrack.GetInverseAffineTransformation()->TransformPoint(aHit.GetPosition()), m_touchableHandle());
+    //m_navigator->LocateGlobalPointAndUpdateTouchable(aTrack.GetInverseAffineTransformation()->TransformPoint(aHit.GetPosition()), G4ThreeVector( 0., 0., 0. ) ,m_touchableHandle());
+    m_navigator->LocateGlobalPointAndUpdateTouchable(position, m_touchableHandle());
   }
   G4VPhysicalVolume* currentVolume = m_touchableHandle()->GetVolume();
-  G4VSensitiveDetector* sensitive;
   if(currentVolume != 0) {
-    sensitive = currentVolume->GetLogicalVolume()->GetSensitiveDetector();
-    if(sensitive && currentVolume->GetLogicalVolume()->GetFastSimulationManager()) {
-      G4Step*      fakeStep         = new G4Step();
-      G4StepPoint* fakePreStepPoint = fakeStep->GetPreStepPoint();
+    auto lvol = currentVolume->GetLogicalVolume(); 
+    auto sensitive = lvol->GetSensitiveDetector();
+    // TODO: check whether this is sufficient to make sure that the right volume is chosen
+    // in principle here the problem is when an ancestor volume is linked to the sensitive det
+    if(auto mvol = currentVolume->GetMotherLogical(); !sensitive && mvol->GetRegion() == lvol->GetRegion()) {
+      sensitive = mvol->GetSensitiveDetector();
+    } 
+    if(sensitive) { // && currentVolume->GetLogicalVolume()->GetFastSimulationManager()) {
+      auto      fakeStep         = new G4Step();
+      auto fakePreStepPoint = fakeStep->GetPreStepPoint();
       fakePreStepPoint->SetTouchableHandle( m_touchableHandle );
       fakeStep->SetTotalEnergyDeposit(aHit.GetEnergy());
       fakeStep->SetTrack(const_cast<G4Track*>(aTrack.GetPrimaryTrack()));
       modifyFakeStep(fakeStep); // if any other custom modifications have to be applied
       sensitive->Hit(fakeStep);
+    } else {
+      error("Could not locate sensitive detector for the logical volume: " + lvol->GetName());
     }
   }
 }
-- 
GitLab


From eb78552c0ccf5a97b14ae3126fd75cba5398a69b Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Fri, 19 Feb 2021 09:39:06 +0100
Subject: [PATCH 21/24] Set MaterialsCutCouple in Sensitive Response as default

---
 .../src/lib/GiGaMTFastSimSensitiveResponse.cpp                   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp b/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
index eb7a12bd..cbaa1f47 100644
--- a/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
+++ b/Sim/GiGaMTFastSimulation/src/lib/GiGaMTFastSimSensitiveResponse.cpp
@@ -45,6 +45,7 @@ void GiGaMTFastSimSensitiveResponse::simulate(const GiGaMTFastHit& aHit, const G
       auto      fakeStep         = new G4Step();
       auto fakePreStepPoint = fakeStep->GetPreStepPoint();
       fakePreStepPoint->SetTouchableHandle( m_touchableHandle );
+      fakePreStepPoint->SetMaterialCutsCouple( aTrack.GetPrimaryTrack()->GetMaterialCutsCouple() );
       fakeStep->SetTotalEnergyDeposit(aHit.GetEnergy());
       fakeStep->SetTrack(const_cast<G4Track*>(aTrack.GetPrimaryTrack()));
       modifyFakeStep(fakeStep); // if any other custom modifications have to be applied
-- 
GitLab


From cfa96c7b5b771b4e21c985062e2eeda9c1b87009 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Tue, 23 Feb 2021 17:09:46 +0100
Subject: [PATCH 22/24] Add a template model and alter immediate deposit mdoel
 so that it accepts a configurable step length

---
 .../ImmediateDepositModel.cpp                 | 20 +++++++++++++++++--
 .../ImmediateDeposit/ImmediateDepositModel.h  | 12 ++++++++++-
 .../GiGaMTFastSimModelFAC.h                   |  2 +-
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
index 073efc18..3dc6cfb0 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
@@ -32,6 +32,22 @@ void Model::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
   G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
   m_sensResponse->simulate(GiGaMTFastHit(position, energyDeposit), aFastTrack);
 }
+
+class ModelFactory : public GiGaMTFastSimModelFAC<Model> {
+  
+  Gaudi::Property<double> m_stepLength {this, "FakeStepLength", 0.0 * CLHEP::mm};
+
+  public: 
+  virtual ~ModelFactory() = default;
+  using gaussino_base_class = GiGaMTFastSimModelFAC<Model>;
+  using gaussino_base_class::GiGaMTFastSimModelFAC;
+
+  virtual Model* construct() const override {
+     auto tmp = gaussino_base_class::construct();
+     tmp->SetStepLength(m_stepLength);
+     return tmp;
+  };
+};
 }
-using ImmediateDepositModelFactory = GiGaMTFastSimModelFAC<ImmediateDeposit::Model>;
-DECLARE_COMPONENT_WITH_ID( ImmediateDepositModelFactory, "ImmediateDepositModelFactory" )
+
+DECLARE_COMPONENT_WITH_ID( ImmediateDeposit::ModelFactory, "ImmediateDepositModelFactory" )
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
index 01194c9f..27f43102 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
@@ -17,11 +17,19 @@
 namespace ImmediateDeposit {
 
 class SensitiveResponse : public GiGaMTFastSimSensitiveResponse {
+
+  double m_stepLength {0.0 * CLHEP::mm};
+
   inline virtual void modifyFakeStep(G4Step* fakeStep) override {
     // this is a hack, so that the model will work on detectors
     // where it the step must be finite 
-    fakeStep->SetStepLength(0.01);
+    fakeStep->SetStepLength(m_stepLength);
   }
+
+  public:
+
+  inline void SetStepLength (double stepLength) { m_stepLength = stepLength; }
+  inline double GetStepLength () { return m_stepLength; }
 };
   
 class Model : public G4VFastSimulationModel, public GiGaMessage {
@@ -35,5 +43,7 @@ public:
   G4bool IsApplicable( const G4ParticleDefinition& aParticle ) override;
   G4bool ModelTrigger( const G4FastTrack& aFastTrack ) override;
   void   DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) override;
+
+  inline void SetStepLength(double stepLength) { m_sensResponse->SetStepLength(stepLength); };
 };
 }
diff --git a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h
index 95743d8a..a42c7272 100644
--- a/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h
+++ b/Sim/GiGaMTFastSimulation/GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h
@@ -24,7 +24,7 @@ class GiGaMTFastSimModelFAC : public extends<GiGaTool, GiGaFactoryBase<G4VFastSi
   Gaudi::Property<std::string> m_model{this, "ModelName", std::string()};
 public:
   using extends::extends;
-  G4VFastSimulationModel* construct() const override {
+  FastSimModel* construct() const override {
 
     if (m_model.value().empty()) {
       error() << "Fast model name was not provided." << endmsg;
-- 
GitLab


From 655b22ea471b435431bc82002c3fb5c8231642b0 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Wed, 24 Feb 2021 13:03:43 +0100
Subject: [PATCH 23/24] Linear deposit model

---
 .../ImmediateDepositModel.cpp                 | 28 ++++++++++++++++---
 .../ImmediateDeposit/ImmediateDepositModel.h  |  4 +++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
index 3dc6cfb0..aa7e517c 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.cpp
@@ -27,14 +27,32 @@ G4bool Model::ModelTrigger( const G4FastTrack& ) {
 void Model::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
   // kill the track so that it will no longer be propagated by G4
   aFastStep.KillPrimaryTrack();
-  double energyDeposit = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
-  //aFastStep.SetTotalEnergyDeposited( Edep );
-  G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
-  m_sensResponse->simulate(GiGaMTFastHit(position, energyDeposit), aFastTrack);
+  double initialEnergy = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
+  auto position = aFastTrack.GetPrimaryTrack()->GetPosition();
+  auto rot = G4RotationMatrix();
+  rot.rotateY(position.getTheta());
+
+  if(!(std::fabs(position.x()) < 1e-3 && std::fabs(position.y()) < 1e-3)) {
+    rot.rotateZ(position.getPhi());
+  }
+
+  if ( m_eDepFrac <= 1.0 ) {
+    double tmpEnergyDeposit = initialEnergy * m_eDepFrac;
+    auto tmpPosition = position;
+    while ( tmpEnergyDeposit > m_eKillThr ) {
+      m_sensResponse->simulate(GiGaMTFastHit(tmpPosition, tmpEnergyDeposit), aFastTrack);
+      if (m_eDepFrac == 1.0) break;
+      initialEnergy -= tmpEnergyDeposit;
+      tmpEnergyDeposit = initialEnergy * m_eDepFrac;
+      tmpPosition = tmpPosition + rot * G4ThreeVector(0, 0, m_sensResponse->GetStepLength());
+    } 
+  } 
 }
 
 class ModelFactory : public GiGaMTFastSimModelFAC<Model> {
   
+  Gaudi::Property<double> m_eDepFrac {this, "EnergyDepositFraction", 1.0};
+  Gaudi::Property<double> m_eKillThr {this, "KillEnergyThreshold", 50.0 * CLHEP::MeV};
   Gaudi::Property<double> m_stepLength {this, "FakeStepLength", 0.0 * CLHEP::mm};
 
   public: 
@@ -44,6 +62,8 @@ class ModelFactory : public GiGaMTFastSimModelFAC<Model> {
 
   virtual Model* construct() const override {
      auto tmp = gaussino_base_class::construct();
+     tmp->SetEDepFrac(m_eDepFrac);
+     tmp->SetEKillThr(m_eKillThr);
      tmp->SetStepLength(m_stepLength);
      return tmp;
   };
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
index 27f43102..d851d588 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ImmediateDeposit/ImmediateDepositModel.h
@@ -35,6 +35,8 @@ class SensitiveResponse : public GiGaMTFastSimSensitiveResponse {
 class Model : public G4VFastSimulationModel, public GiGaMessage {
 
   std::unique_ptr<SensitiveResponse> m_sensResponse;
+  double m_eDepFrac {1.0};
+  double m_eKillThr {50.0 * CLHEP::MeV};
 
 public:
   Model(G4String modelName, G4Region* envelope);
@@ -44,6 +46,8 @@ public:
   G4bool ModelTrigger( const G4FastTrack& aFastTrack ) override;
   void   DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) override;
 
+  inline void SetEDepFrac(double eDepFrac) { m_eDepFrac = eDepFrac; };
+  inline void SetEKillThr(double eKillThr) { m_eKillThr = eKillThr; };
   inline void SetStepLength(double stepLength) { m_sensResponse->SetStepLength(stepLength); };
 };
 }
-- 
GitLab


From b5d47373a5db27d492ac60ed35d7b75bf4e82140 Mon Sep 17 00:00:00 2001
From: Michal Mazurek <michal.mazurek@cern.ch>
Date: Thu, 25 Feb 2021 17:47:26 +0100
Subject: [PATCH 24/24] Shower model init

---
 .../FastSimulationExample/CMakeLists.txt      |   7 +
 .../src/ShowerDeposit/ShowerDepositModel.cpp  | 148 ++++++++++++++++++
 .../src/ShowerDeposit/ShowerDepositModel.h    |  72 +++++++++
 3 files changed, 227 insertions(+)
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.cpp
 create mode 100644 Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.h

diff --git a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
index 29f2d5cc..ca3d1e9b 100644
--- a/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
+++ b/Sim/GiGaMTExamples/FastSimulationExample/CMakeLists.txt
@@ -34,6 +34,13 @@ gaudi_add_module(ImmediateDeposit
 
 add_dependencies(ImmediateDeposit HepMC3Ext)
 
+gaudi_add_module(ShowerDeposit
+                 src/ShowerDeposit/*.cpp
+                 INCLUDE_DIRS GiGaMTFactories 
+                 LINK_LIBRARIES GaudiAlgLib GiGaMTCoreRunLib GiGaMTFastSimulationLib)
+
+add_dependencies(ShowerDeposit HepMC3Ext)
+
 gaudi_env(SET FASTSIMULATIONEXAMPLETESTS \${FASTSIMULATIONEXAMPLEROOT}/tests)
 
 gaudi_add_test(QMTest QMTEST)
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.cpp b/Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.cpp
new file mode 100644
index 00000000..a712bc58
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.cpp
@@ -0,0 +1,148 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
+#include "ShowerDepositModel.h"
+#include "Geant4/G4TransportationManager.hh"
+#include "Geant4/G4VSensitiveDetector.hh"
+#include "GiGaMTFastSimulation/GiGaMTFastSimModelFAC.h"
+#include "GiGaMTFastSimulation/GiGaMTFastHit.h"
+
+#include "Geant4/G4Material.hh"
+#include "Geant4/G4Electron.hh"
+#include "Geant4/G4Positron.hh"
+#include "Geant4/G4Gamma.hh"
+#include "Geant4/Randomize.hh"
+
+namespace ShowerDeposit {
+
+Model::Model( G4String modelName, G4Region* envelope ) : G4VFastSimulationModel( modelName, envelope ), m_sensResponse(new SensitiveResponse) {}
+
+G4bool Model::IsApplicable( const G4ParticleDefinition& aParticleType) { 
+  return &aParticleType == G4Electron::ElectronDefinition() ||
+         &aParticleType == G4Positron::PositronDefinition() ||
+         &aParticleType == G4Gamma::GammaDefinition();
+}
+
+G4bool Model::ModelTrigger( const G4FastTrack& ) {
+  return true;
+}
+
+void Model::DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) {
+  // kill the track so that it will no longer be propagated by G4
+  aFastStep.KillPrimaryTrack();
+
+  double energy = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
+  auto particlePosition  = aFastTrack.GetPrimaryTrack()->GetPosition();
+  // Calculate how to create energy deposits
+  // Following PDG 33.5 chapter
+  // material calculation assumes homogeneous detector (true for Par03 example)
+
+  always("**********************");
+  always("Entered DoIt method");
+  auto material = G4Material::GetMaterial(m_material);
+  if(!material) {
+    warning("Material " + m_material + " not found. Using the one that the track is currently in.");
+    material = aFastTrack.GetPrimaryTrack()->GetMaterial();
+  }
+  double materialX0 = material->GetRadlen();
+  double materialZ  = material->GetZ();
+  // EC estimation follows PDG fit to solids in Fig. 33.14 (rms 2.2%)
+  double materialEc = 610 * CLHEP::MeV / (materialZ + 1.24);
+  // RM estimation follows PDG Eq. (33.37) (rms 2.2%)
+  double materialRM = 21.2052 * CLHEP::MeV * materialX0 / materialEc;
+  double particleY  = energy / materialEc;
+  // Estimate shower maximum and alpha parameter of Gamma distribution
+  // that describes the longitudinal profile (PDG Eq. (33.35))
+  // unless alpha is specified by UI command
+  if(m_alpha < 0) {
+    // from PDG Eq. (33.36)
+    G4double particleTmax = std::log(particleY);
+    if(aFastTrack.GetPrimaryTrack()->GetParticleDefinition() == G4Gamma::GammaDefinition()) {
+      particleTmax += 0.5;
+    } else {
+      particleTmax -= 0.5;
+    }
+    m_alpha = particleTmax * m_beta + 1;
+  }
+  // Unless sigma of Gaussian distribution describing the transverse profile
+  // is specified by UI command, use value calculated from Moliere Radius
+  if(m_sigma < 0) {
+    // 90% of shower is contained within 1 * R_M
+    // 1.645 * std dev of Gaussian contains 90%
+    m_sigma = materialRM / 1.645;
+  }
+  // Calculate rotation matrix along the particle momentum direction
+  // It will rotate the shower axes to match the incoming particle direction
+  auto rotMatrix = G4RotationMatrix();
+  double particleTheta       = particlePosition.getTheta();
+  double particlePhi         = particlePosition.getPhi();
+  double epsilon             = 1e-3;
+  rotMatrix.rotateY(particleTheta);
+  // do not use (random) phi if x==y==0
+  if(!(std::fabs(particlePosition.x()) < epsilon && std::fabs(particlePosition.y()) < epsilon)) {
+    rotMatrix.rotateZ(particlePhi);
+  }
+  // Create hits
+  // First use rejecton sampling to sample from Gamma distribution
+  // then get random numbers from uniform distribution for azimuthal angle, and
+  // from Gaussian for radius
+  G4ThreeVector position;
+  double gammaMax   = gamma((m_alpha - 1) / m_beta, m_alpha, m_beta);
+  int generatedHits = 0;
+  while(generatedHits < m_hitsNo) {
+    double random1 = G4UniformRand() * m_longMaxDepth;
+    double random2 = G4UniformRand() * gammaMax;
+    if(gamma(random1, m_alpha, m_beta) >= random2) {
+      // Generate corresponding rho (phi) from Gaussian (flat) distribution
+      double phiPosition = G4UniformRand() * 2 * CLHEP::pi;
+      double rhoPosition = G4RandGauss::shoot(0, m_sigma);
+      position             = particlePosition +
+                 rotMatrix * G4ThreeVector(rhoPosition * std::sin(phiPosition),
+                                           rhoPosition * std::cos(phiPosition),
+                                           random1 * materialX0);
+      // Create energy deposit in the detector
+      // This will call appropriate sensitive detector class
+      always("Generating hit x: " + std::to_string(position.x()) + " y: " + std::to_string(position.y()) + " z: " + std::to_string(position.z()) );
+      m_sensResponse->simulate(GiGaMTFastHit(position, energy / m_hitsNo), aFastTrack);
+      generatedHits++;
+    }
+  }
+}
+
+class ModelFactory : public GiGaMTFastSimModelFAC<Model> {
+  
+  Gaudi::Property<double> m_stepLength {this, "FakeStepLength", 0.0 * CLHEP::mm};
+  Gaudi::Property<double> m_sigma {this, "SigmaMoliereRadius", -1};
+  Gaudi::Property<double> m_alpha {this, "AlphaGammaDistribution", -1};
+  Gaudi::Property<double> m_beta {this, "BetaGammaDistribution", .5};
+  Gaudi::Property<int> m_hitsNo {this, "HitsPerShower", 100};
+  Gaudi::Property<int> m_longMaxDepth {this, "MaxShowerDepth", 30};
+  Gaudi::Property<std::string> m_material {this, "HomogeneousMaterial", std::string()};
+
+  public: 
+  virtual ~ModelFactory() = default;
+  using gaussino_base_class = GiGaMTFastSimModelFAC<Model>;
+  using gaussino_base_class::GiGaMTFastSimModelFAC;
+
+  virtual Model* construct() const override {
+     auto tmp = gaussino_base_class::construct();
+     tmp->SetStepLength(m_stepLength);
+     tmp->SetAlpha(m_alpha);
+     tmp->SetBeta(m_beta);
+     tmp->SetSigma(m_sigma);
+     tmp->SetHitsNo(m_hitsNo);
+     tmp->SetLongMaxDepth(m_longMaxDepth);
+     tmp->SetMaterial(m_material);
+     return tmp;
+  };
+};
+}
+
+DECLARE_COMPONENT_WITH_ID( ShowerDeposit::ModelFactory, "ShowerDepositModelFactory" )
diff --git a/Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.h b/Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.h
new file mode 100644
index 00000000..9b41bc25
--- /dev/null
+++ b/Sim/GiGaMTExamples/FastSimulationExample/src/ShowerDeposit/ShowerDepositModel.h
@@ -0,0 +1,72 @@
+/*****************************************************************************\
+* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           *
+*                                                                             *
+* This software is distributed under the terms of the GNU General Public      *
+* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
+*                                                                             *
+* In applying this licence, CERN does not waive the privileges and immunities *
+* granted to it by virtue of its status as an Intergovernmental Organization  *
+* or submit itself to any jurisdiction.                                       *
+\*****************************************************************************/
+#pragma once
+
+#include "Geant4/G4VFastSimulationModel.hh"
+#include "GiGaMTCoreMessage/IGiGaMessage.h"
+#include "GiGaMTFastSimulation/GiGaMTFastSimSensitiveResponse.h"
+
+namespace ShowerDeposit {
+
+class SensitiveResponse : public GiGaMTFastSimSensitiveResponse {
+
+  double m_stepLength {0.0 * CLHEP::mm};
+
+  inline virtual void modifyFakeStep(G4Step* fakeStep) override {
+    // this is a hack, so that the model will work on detectors
+    // where it the step must be finite 
+    fakeStep->SetStepLength(m_stepLength);
+  }
+
+  public:
+
+  inline void SetStepLength (double stepLength) { m_stepLength = stepLength; }
+  inline double GetStepLength () { return m_stepLength; }
+};
+  
+class Model : public G4VFastSimulationModel, public GiGaMessage {
+
+  std::unique_ptr<SensitiveResponse> m_sensResponse;
+  double m_sigma {-1};
+  double m_alpha {-1};
+  double m_beta  {.5};
+  int m_hitsNo  {100};
+  int m_longMaxDepth  {30};
+  std::string m_material  {std::string()};
+
+  // Gamma distribution
+  inline double gamma(double x, double alpha, double beta) {
+    return (std::pow(beta, alpha) / std::tgamma(alpha) * std::pow(x, alpha - 1) * std::exp(-beta * x));
+  }
+  /// Gaussian distribution
+  inline double gaussian(double x, double sigma = 1, double x0 = 0) {
+    double tmp = (x - x0) / sigma;
+    return (1.0 / (std::sqrt(2 * CLHEP::pi) * sigma)) * std::exp(-tmp * tmp / 2);
+  }
+
+
+public:
+  Model(G4String modelName, G4Region* envelope);
+  ~Model() = default;
+
+  G4bool IsApplicable( const G4ParticleDefinition& aParticle ) override;
+  G4bool ModelTrigger( const G4FastTrack& aFastTrack ) override;
+  void   DoIt( const G4FastTrack& aFastTrack, G4FastStep& aFastStep ) override;
+
+  inline void SetSigma(double eSigma) { m_sigma = eSigma; };
+  inline void SetAlpha(double eAlpha) { m_alpha = eAlpha; };
+  inline void SetBeta(double eBeta) { m_beta = eBeta; };
+  inline void SetHitsNo(int eHitsNo) { m_hitsNo = eHitsNo; };
+  inline void SetLongMaxDepth(double eLongMaxDepth) { m_longMaxDepth = eLongMaxDepth; };
+  inline void SetMaterial(std::string eMaterial) { m_material = eMaterial; };
+  inline void SetStepLength(double stepLength) { m_sensResponse->SetStepLength(stepLength); };
+};
+}
-- 
GitLab