From 35eb953f704e3314b95c6113b5bbdd741e319a13 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wouter.deconinck@umanitoba.ca>
Date: Tue, 10 Aug 2021 21:59:33 +0000
Subject: [PATCH] Patch for DD4Hep #862

---
 ...nge-momentum-in-getParticleDirection.patch | 36 +++++++++++++++++++
 spack/packages/dd4hep/package.py              |  2 ++
 2 files changed, 38 insertions(+)
 create mode 100644 spack/packages/dd4hep/0001-do-not-change-momentum-in-getParticleDirection.patch

diff --git a/spack/packages/dd4hep/0001-do-not-change-momentum-in-getParticleDirection.patch b/spack/packages/dd4hep/0001-do-not-change-momentum-in-getParticleDirection.patch
new file mode 100644
index 000000000..1c81166f1
--- /dev/null
+++ b/spack/packages/dd4hep/0001-do-not-change-momentum-in-getParticleDirection.patch
@@ -0,0 +1,36 @@
+diff --git a/DDG4/src/Geant4IsotropeGenerator.cpp b/DDG4/src/Geant4IsotropeGenerator.cpp
+index 54588aaf..f63b29b4 100644
+--- a/DDG4/src/Geant4IsotropeGenerator.cpp
++++ b/DDG4/src/Geant4IsotropeGenerator.cpp
+@@ -48,7 +48,6 @@ void Geant4IsotropeGenerator::getParticleDirectionUniform(int, ROOT::Math::XYZVe
+   double x3 = std::cos(theta);
+ 
+   direction.SetXYZ(x1,x2,x3);
+-  momentum = rnd.rndm()*momentum;
+ }
+ 
+ /// Particle distribution ~ cos(theta)
+@@ -63,7 +62,6 @@ void Geant4IsotropeGenerator::getParticleDirectionCosTheta(int, ROOT::Math::XYZV
+   double x3 = cos_theta;
+ 
+   direction.SetXYZ(x1,x2,x3);
+-  momentum = rnd.rndm()*momentum;
+ }
+ 
+ /// Particle distribution flat in eta (pseudo rapidity)
+@@ -84,7 +82,6 @@ void Geant4IsotropeGenerator::getParticleDirectionEta(int, ROOT::Math::XYZVector
+   double x3         = std::sinh(eta);
+   double r          = std::sqrt(1.0+x3*x3);
+   direction.SetXYZ(x1/r,x2/r,x3/r);
+-  momentum = rnd.rndm()*momentum;
+ }
+ 
+ /// e+e- --> ffbar particle distribution ~ 1 + cos^2(theta)
+@@ -110,7 +107,6 @@ void Geant4IsotropeGenerator::getParticleDirectionFFbar(int, ROOT::Math::XYZVect
+       double x2 = std::sin(theta)*std::sin(phi);
+       double x3 = std::cos(theta);
+       direction.SetXYZ(x1,x2,x3);
+-      momentum = rnd.rndm()*momentum;
+       return;
+     }
+   }
diff --git a/spack/packages/dd4hep/package.py b/spack/packages/dd4hep/package.py
index 5934c56f5..d2fc644cd 100644
--- a/spack/packages/dd4hep/package.py
+++ b/spack/packages/dd4hep/package.py
@@ -54,6 +54,8 @@ class Dd4hep(CMakePackage):
     # https://github.com/AIDASoft/DD4hep/pull/849
     # https://github.com/AIDASoft/DD4hep/pull/851
     patch('2021-07-27.patch', when='@1.17p1')
+    # patch for https://github.com/AIDASoft/DD4hep/issues/862
+    patch('0001-do-not-change-momentum-in-getParticleDirection.patch', when='@1.17p1')
 
     variant('xercesc', default=False, description="Enable 'Detector Builders' based on XercesC")
     variant('geant4', default=False, description="Enable the simulation part based on Geant4")
-- 
GitLab