From f41944ca04a2829c4b94aaa1de320cf58ce079f5 Mon Sep 17 00:00:00 2001
From: Fang Wenxing <wxfang@lxslc614.ihep.ac.cn>
Date: Tue, 23 Jun 2020 09:36:30 +0800
Subject: [PATCH] update GtGunTool with E range

---
 Examples/options/tut_detsim_pan_matrix.py | 3 ++-
 Generator/src/GtGunTool.cpp               | 4 ++--
 Generator/src/GtGunTool.h                 | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/Examples/options/tut_detsim_pan_matrix.py b/Examples/options/tut_detsim_pan_matrix.py
index 4da9e96c..1d5bd456 100644
--- a/Examples/options/tut_detsim_pan_matrix.py
+++ b/Examples/options/tut_detsim_pan_matrix.py
@@ -63,7 +63,8 @@ from Configurables import GenPrinter
 
 gun = GtGunTool("GtGunTool")
 gun.Particles = ["gamma","gamma"]
-gun.Energies =  [10, 10] # GeV
+gun.EnergyMins= [10, 10] # GeV
+gun.EnergyMaxs= [10, 10] # GeV
 gun.ThetaMins = [90, 90] # degree
 gun.ThetaMaxs = [90, 90] # degree
 gun.PhiMins   = [0,  1 ] # degree
diff --git a/Generator/src/GtGunTool.cpp b/Generator/src/GtGunTool.cpp
index 9af8c82f..df29f4a2 100644
--- a/Generator/src/GtGunTool.cpp
+++ b/Generator/src/GtGunTool.cpp
@@ -16,7 +16,7 @@ GtGunTool::initialize() {
         return StatusCode::FAILURE;
     }
     
-    if (m_energies.value().size() != m_particles.value().size()) {
+    if (m_energymins.value().size() != m_particles.value().size()) {
         error() << "Mismatched energies and particles." << endmsg;
         return StatusCode::FAILURE;
     }
@@ -79,7 +79,7 @@ GtGunTool::mutate(MyHepMC::GenEvent& event) {
             }
         }
 
-        double energy = m_energies.value()[i];
+        double energy = m_energymins.value()[i]==m_energymaxs.value()[i] ? m_energymins.value()[i] : CLHEP::RandFlat::shoot(m_energymins.value()[i], m_energymaxs.value()[i]);
 
         // create the MC particle
         edm4hep::MCParticle mcp = event.m_mc_vec.create();
diff --git a/Generator/src/GtGunTool.h b/Generator/src/GtGunTool.h
index 22b02a81..388c14d4 100644
--- a/Generator/src/GtGunTool.h
+++ b/Generator/src/GtGunTool.h
@@ -34,7 +34,8 @@ private:
 
     Gaudi::Property<std::vector<std::string>> m_particles{this, "Particles"};
 
-    Gaudi::Property<std::vector<double>> m_energies{this, "Energies"};
+    Gaudi::Property<std::vector<double>> m_energymins{this, "EnergyMins"};
+    Gaudi::Property<std::vector<double>> m_energymaxs{this, "EnergyMaxs"};
 
     Gaudi::Property<std::vector<double>> m_thetamins{this, "ThetaMins"};
     Gaudi::Property<std::vector<double>> m_thetamaxs{this, "ThetaMaxs"};
-- 
GitLab