From c2163606d4b0f74acec8cde02d025dc8726e0d77 Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Wed, 1 Apr 2015 15:31:29 +0000
Subject: [PATCH] Enforce sqrt(x) to be taken from cmath via std::sqrt

---
 DDCore/include/DD4hep/Objects.h               |  4 +-
 DDCore/src/FieldTypes.cpp                     |  4 +-
 DDCore/src/MatrixHelpers.cpp                  |  2 +-
 DDCore/src/plugins/LCDDConverter.cpp          |  2 +-
 DDG4/include/DDG4/Geant4Particle.h            |  2 +-
 DDG4/plugins/Geant4EventReaderHepMC.cpp       |  2 +-
 DDG4/plugins/Geant4TCUserParticleHandler.cpp  |  8 +-
 doc/build_doc.sh                              | 33 ++++++++
 doc/dd4hep_LCG.sh                             | 82 +++++++++++++++++++
 doc/external_build.txt                        |  6 ++
 .../ClientTests/scripts/NestedDetectors.py    | 52 ++++++++++++
 .../src/SectorBarrelCalorimeter_geo.cpp       |  4 +-
 12 files changed, 187 insertions(+), 14 deletions(-)
 create mode 100644 doc/build_doc.sh
 create mode 100644 doc/dd4hep_LCG.sh
 create mode 100644 doc/external_build.txt
 create mode 100644 examples/ClientTests/scripts/NestedDetectors.py

diff --git a/DDCore/include/DD4hep/Objects.h b/DDCore/include/DD4hep/Objects.h
index 4643d8aab..83d4bb3e7 100644
--- a/DDCore/include/DD4hep/Objects.h
+++ b/DDCore/include/DD4hep/Objects.h
@@ -40,11 +40,11 @@ class TGeoIdentity;
 
 // C/C++ include files
 #include <set>
+#include <cmath>
 #include <limits>
 #include <vector>
 
 #define _USE_MATH_DEFINES
-#include <cmath>
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
@@ -545,7 +545,7 @@ namespace ROOT {
     typedef DD4hep::Geometry::Position Position;
     /// Dot product of 3-vectors.
     inline double operator *(const Position& l, const Position& r) {
-      return sqrt(l.X() * r.X() + l.Y() * r.Y() + l.Z() * r.Z());
+      return std::sqrt(l.X() * r.X() + l.Y() * r.Y() + l.Z() * r.Z());
     }
     /// Calculate the mean length of two vectors
     inline double mean_length(const Position& p1, const Position& p2) {
diff --git a/DDCore/src/FieldTypes.cpp b/DDCore/src/FieldTypes.cpp
index 456814e36..65e593c9f 100644
--- a/DDCore/src/FieldTypes.cpp
+++ b/DDCore/src/FieldTypes.cpp
@@ -41,7 +41,7 @@ void SolenoidField::fieldComponents(const double* pos, double* field) {
   double z = pos[2] ;
   //  std::cout << " field z=" << z << " maxZ=" << maxZ << " minZ = " << minZ << std::endl ;
   if( z > minZ && z < maxZ ){
-    double radius = sqrt(pos[0] * pos[0] + pos[1] * pos[1]);
+    double radius = std::sqrt(pos[0] * pos[0] + pos[1] * pos[1]);
     if (radius < innerRadius)
       field[2] += innerField;
     else if (radius < outerRadius)
@@ -57,7 +57,7 @@ DipoleField::DipoleField()
 
 /// Call to access the field components at a given location
 void DipoleField::fieldComponents(const double* pos, double* field) {
-  double z = pos[2], r = sqrt(pos[0] * pos[0] + pos[1] * pos[1]);
+  double z = pos[2], r = std::sqrt(pos[0] * pos[0] + pos[1] * pos[1]);
   // Check if z coordinate is within dipole z bounds.
   if (z > zmin && z < zmax && r < rmax) {
     // Apply all coefficients to this z coordinate.
diff --git a/DDCore/src/MatrixHelpers.cpp b/DDCore/src/MatrixHelpers.cpp
index d112c0f16..8b647b73e 100644
--- a/DDCore/src/MatrixHelpers.cpp
+++ b/DDCore/src/MatrixHelpers.cpp
@@ -95,7 +95,7 @@ DD4hep::Geometry::XYZAngles DD4hep::Geometry::_XYZangles(const TGeoMatrix* m) {
 }
 
 DD4hep::Geometry::XYZAngles DD4hep::Geometry::_XYZangles(const double* r) {
-  Double_t cosb = sqrt(r[0]*r[0] + r[1]*r[1]);
+  Double_t cosb = std::sqrt(r[0]*r[0] + r[1]*r[1]);
   if (cosb > 0.00001) {
     return XYZAngles(atan2(r[5], r[8]), atan2(-r[2], cosb), atan2(r[1], r[0]));
   }
diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp
index b70dad8e6..c40dbced8 100644
--- a/DDCore/src/plugins/LCDDConverter.cpp
+++ b/DDCore/src/plugins/LCDDConverter.cpp
@@ -58,7 +58,7 @@ namespace {
   typedef Position XYZRotation;
 
   XYZRotation getXYZangles(const Double_t* r) {
-    Double_t cosb = sqrt(r[0]*r[0] + r[1]*r[1]);
+    Double_t cosb = std::sqrt(r[0]*r[0] + r[1]*r[1]);
     if (cosb > 0.00001) {
       return XYZRotation(atan2(r[5], r[8]), atan2(-r[2], cosb), atan2(r[1], r[0]));
     }
diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h
index 1ceed2b96..b052e4583 100644
--- a/DDG4/include/DDG4/Geant4Particle.h
+++ b/DDG4/include/DDG4/Geant4Particle.h
@@ -173,7 +173,7 @@ namespace DD4hep {
       /// Scalar particle energy
       double energy() const;
       /// Scalar particle momentum
-      double momentum() const   {  return sqrt(momentum2());       }
+      double momentum() const   {  return std::sqrt(momentum2());  }
       /// Geant4 charge of the particle
       double charge()  const    { return double(particle->charge); }
       /// Geant4 mass of the particle
diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp
index adc712ce2..72d624f64 100644
--- a/DDG4/plugins/Geant4EventReaderHepMC.cpp
+++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp
@@ -337,7 +337,7 @@ int HepMC::read_particle(EventStream &info, istringstream& input, Geant4Particle
     p->mass *= info.mom_unit;
   }
   else   {
-    p->mass = sqrt(fabs(ene*ene - p->psx*p->psx + p->psy*p->psy + p->psz*p->psz));
+    p->mass = std::sqrt(fabs(ene*ene - (p->psx*p->psx + p->psy*p->psy + p->psz*p->psz)));
   }
   // Reuse here the secondaries to store the end-vertex ID
   input >> stat >> theta >> phi >> p->secondaries >> size;
diff --git a/DDG4/plugins/Geant4TCUserParticleHandler.cpp b/DDG4/plugins/Geant4TCUserParticleHandler.cpp
index cd335e68c..c55d49744 100644
--- a/DDG4/plugins/Geant4TCUserParticleHandler.cpp
+++ b/DDG4/plugins/Geant4TCUserParticleHandler.cpp
@@ -82,8 +82,8 @@ Geant4TCUserParticleHandler::Geant4TCUserParticleHandler(Geant4Context* ctxt, co
 
 /// Post-track action callback
 void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p)  {
-  double r_prod = sqrt(p.vsx*p.vsx + p.vsy*p.vsy);
-  double z_prod = fabs(p.vsz);
+  double r_prod = std::sqrt(p.vsx*p.vsx + p.vsy*p.vsy);
+  double z_prod = std::fabs(p.vsz);
   bool starts_in_trk_vol = ( r_prod <= m_rTracker && z_prod <= m_zTracker )  ;
 
   // created in tracking volume but below energy cut
@@ -92,8 +92,8 @@ void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p)
     return;
   }
 
-  double r_end  = sqrt(p.vex*p.vex + p.vey*p.vey);
-  double z_end  = fabs(p.vez);
+  double r_end  = std::sqrt(p.vex*p.vex + p.vey*p.vey);
+  double z_end  = std::fabs(p.vez);
   bool ends_in_trk_vol =  ( r_end <= m_rTracker && z_end <= m_zTracker ) ;
 
   // created and ended in calo
diff --git a/doc/build_doc.sh b/doc/build_doc.sh
new file mode 100644
index 000000000..06e1ed1b2
--- /dev/null
+++ b/doc/build_doc.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+SW=/home/frankm/SW;
+TARGET=${SW}/DD4hep_head_dbg.root_v5.34.10;
+mkdir build_doc;
+cd build_doc;
+#
+#
+cmake -DCMAKE_BUILD_TYPE=Debug \
+    -DCMAKE_INSTALL_PREFIX=${TARGET}/DD4hep \
+    -DCMAKE_MODULE_PATH=:${TARGET}/DD4hep \
+    -DDD4hep_INCLUDE_DIRS=${TARGET}/DD4hep/include \
+    -DDD4HEP_USE_XERCESC=ON \
+    -DXERCESC_ROOT_DIR=${SW}/xercesc \
+    -DDD4HEP_USE_BOOST=ON \
+    -DDD4HEP_USE_LCIO=ON \
+    -DLCIO_DIR=${SW}/lcio/v02-03-03 \
+    -DGeant4_ROOT=${SW}/g4_9.6.p02_dbg \
+    -DDD4HEP_USE_GEANT4=ON \
+    -DDD4HEP_USE_PYROOT=OFF \
+    -DBUILD_TESTING=ON \
+    -DINSTALL_DOC=True \
+    ..
+#
+#
+#
+make -j 5;
+make -j 5 doc;
+cd latex;
+make -j 5;
+cd ..;
+echo "cd build_doc;scp -r ../doc/* ./html ./latex/refman.pdf frankm@lxplus:WWW/DD4hep/"
+#
+#
diff --git a/doc/dd4hep_LCG.sh b/doc/dd4hep_LCG.sh
new file mode 100644
index 000000000..b584af5e4
--- /dev/null
+++ b/doc/dd4hep_LCG.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+export LCGEXTERNAL=/afs/cern.ch/sw/lcg/external
+export LCGRELEASES=/afs/cern.ch/sw/lcg/app/releases
+
+#--------------------------------------------------------------------------------
+# CMAKE
+#--------------------------------------------------------------------------------
+export CMAKE_HOME=$LCGEXTERNAL/CMake/2.8.8/x86_64-slc6-gcc46-opt
+export PATH=${CMAKE_HOME}/bin:$PATH
+
+
+#--------------------------------------------------------------------------------
+#     GCC
+#--------------------------------------------------------------------------------
+
+gcc_config_version=4.8.1
+mpfr_config_version=3.1.2
+gmp_config_version=5.1.1
+LCGPLAT=x86_64-slc6-gcc48-opt
+LCG_lib_name=lib64
+LCG_arch=x86_64
+
+if [ -z $1 ] 
+then LCG_contdir=/afs/cern.ch/sw/lcg/contrib
+else LCG_contdir=$1 
+fi
+LCG_gcc_home=${LCG_contdir}/gcc/${gcc_config_version}/${LCGPLAT}
+LCG_mpfr_home=${LCG_contdir}/mpfr/${mpfr_config_version}/${LCGPLAT}
+LCG_gmp_home=${LCG_contdir}/gmp/${gmp_config_version}/${LCGPLAT}
+
+export PATH=${LCG_gcc_home}/bin:${PATH}
+export COMPILER_PATH=${LCG_gcc_home}/lib/gcc/${LCG_arch}-unknown-linux-gnu/${gcc_config_version}
+
+if [ ${LD_LIBRARY_PATH} ] 
+then
+export LD_LIBRARY_PATH=${LCG_gcc_home}/${LCG_lib_name}:${LCG_mpfr_home}/lib:${LCG_gmp_home}/lib:${LD_LIBRARY_PATH}
+else
+export LD_LIBRARY_PATH=${LCG_gcc_home}/${LCG_lib_name}:${LCG_mpfr_home}/lib:${LCG_gmp_home}/lib
+fi
+
+### ROOT
+source $LCGRELEASES/ROOT/5.34.10/x86_64-slc6-gcc48-dbg/root/bin/thisroot.sh
+
+
+#--------------------------------------------------------------------------------
+#     Geant4
+#--------------------------------------------------------------------------------
+source /afs/cern.ch/sw/lcg/external/geant4/9.6.p01/x86_64-slc6-gcc46-opt/bin/geant4.sh
+#--------------------------------------------------------------------------------
+#     XercesC
+#--------------------------------------------------------------------------------
+export XERCESCSYS=/afs/cern.ch/sw/lcg/external/XercesC/3.1.1p2/x86_64-slc6-gcc46-opt
+export LD_LIBRARY_PATH=${XERCESCSYS}/lib:${LD_LIBRARY_PATH}
+
+# #--------------------------------------------------------------------------------
+# #     CLHEP
+# #--------------------------------------------------------------------------------
+# export CLHEP="/afs/cern.ch/eng/clic/software/x86_64-slc6-gcc48/CLHEP/2.1.3.1"
+# export CLHEP_BASE_DIR="$CLHEP"
+# export CLHEP_INCLUDE_DIR="$CLHEP/include"
+# export PATH="$CLHEP_BASE_DIR/bin:$PATH"
+# export LD_LIBRARY_PATH="$CLHEP_BASE_DIR/lib:$LD_LIBRARY_PATH"
+
+
+#--------------------------------------------------------------------------------
+#     LCIO
+#--------------------------------------------------------------------------------
+export LCIO="/afs/cern.ch/eng/clic/software/x86_64-slc6-gcc48/LCIO/v02-04-01"
+export LCIO_INCLUDE_DIR="$LCIO/include"
+export PATH="$LCIO/bin:$PATH"
+export LD_LIBRARY_PATH="$LCIO/lib:$LD_LIBRARY_PATH"
+
+
+#--------------------------------------------------------------------------------
+#        BOOST
+#--------------------------------------------------------------------------------
+export BOOST_ROOT=/afs/cern.ch/sw/lcg/external/Boost/1.53.0_python2.7/x86_64-slc6-gcc48-opt
+
+
+
+
diff --git a/doc/external_build.txt b/doc/external_build.txt
new file mode 100644
index 000000000..fd22d3005
--- /dev/null
+++ b/doc/external_build.txt
@@ -0,0 +1,6 @@
+rm -rf build;mkdir build;cd build
+
+cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/frankm/SW/DD4hep_head_dbg.root_v5.34.25.g4_10.01/DD4hep -DCMAKE_MODULE_PATH=:/home/frankm/SW/DD4hep_head_dbg.root_v5.34.25.g4_10.01/DD4hep -DDD4hep_INCLUDE_DIRS=/home/frankm/SW/DD4hep_head_dbg.root_v5.34.25.g4_10.01/DD4hep/include -DD4hep_DIR=/home/frankm/SW/DD4hep_head_dbg.root_v5.34.25.g4_10.01/DD4hep -DD4hep_ROOT=/home/frankm/SW/DD4hep_head_dbg.root_v5.34.25.g4_10.01/DD4hep -DDD4HEP_USE_XERCESC=ON -DXERCESC_ROOT_DIR=/home/frankm/SW/xercesc -DDD4HEP_USE_BOOST=ON -DDD4HEP_USE_LCIO=ON -DLCIO_DIR=/home/frankm/SW/lcio/v02-04-03 -DGeant4_ROOT=/home/frankm/SW/g4_10.01_dbg -DDD4HEP_USE_GEANT4=ON -DDD4HEP_USE_PYROOT=OFF -DBUILD_TESTING=ON ..
+  
+
+make -j 5
diff --git a/examples/ClientTests/scripts/NestedDetectors.py b/examples/ClientTests/scripts/NestedDetectors.py
new file mode 100644
index 000000000..bd1768375
--- /dev/null
+++ b/examples/ClientTests/scripts/NestedDetectors.py
@@ -0,0 +1,52 @@
+import os, time, DDG4, sys
+from DDG4 import OutputLevel as Output
+from SystemOfUnits import *
+#
+#
+"""
+
+   DD4hep example setup using the python configuration
+
+   \author  M.Frank
+   \version 1.0
+
+"""
+def run():
+  kernel = DDG4.Kernel()
+  install_dir = os.environ['DD4hepINSTALL']
+  example_dir = install_dir+'/examples/DDG4/examples';
+  kernel.setOutputLevel('Geant4Converter',Output.DEBUG)
+  kernel.setOutputLevel('Gun',Output.INFO)
+  kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/NestedDetectors.xml")
+  kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
+
+  simple = DDG4.Simple(kernel)
+  simple.printDetectors()
+  simple.setupCshUI()
+  if len(sys.argv) >= 2 and sys.argv[1] =="batch":
+    kernel.UI = ''
+
+  # Configure I/O
+  evt_root = simple.setupROOTOutput('RootOutput','Nested_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=True)
+  # Setup particle gun
+  simple.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1)
+  # Now the calorimeters
+  seq,act = simple.setupTracker('SiTrackerBarrel')
+  seq,act = simple.setupTracker('SiVertexBarrel')
+  # And handle the simulation particles.
+  part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler")
+  kernel.generatorAction().adopt(part)
+  part.SaveProcesses = ['conv','Decay']
+  part.MinimalKineticEnergy = 1*MeV
+  part.enableUI()
+
+  # Now build the physics list:
+  phys = kernel.physicsList()
+  phys.extends = 'QGSP_BERT'
+  phys.enableUI()
+  phys.dump()
+  # and run
+  simple.execute()
+
+if __name__ == "__main__":
+  run()
diff --git a/examples/ClientTests/src/SectorBarrelCalorimeter_geo.cpp b/examples/ClientTests/src/SectorBarrelCalorimeter_geo.cpp
index 8056da232..11a7d2d1e 100644
--- a/examples/ClientTests/src/SectorBarrelCalorimeter_geo.cpp
+++ b/examples/ClientTests/src/SectorBarrelCalorimeter_geo.cpp
@@ -91,7 +91,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens)  {
   
   double half_polyFace = rmin * tan_half;
   
-  double innerFaceLen   = sqrt(rmax*rmax - rmin*rmin)+half_polyFace;
+  double innerFaceLen   = std::sqrt(rmax*rmax - rmin*rmin)+half_polyFace;
   //double outerFaceLen   = (rmin+totalThickness) * tan_external;
   double staveThickness = totalThickness;
 
@@ -171,7 +171,7 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens)  {
       layerR += layer_thickness;
       // Increment the layer X dimension.
       layer_pos_x = (layerR-rmin)/tan_external;
-      layer_dim_x =  (sqrt(rmax*rmax - layerR*layerR)+half_polyFace - layer_pos_x)/2.0;
+      layer_dim_x =  (std::sqrt(rmax*rmax - layerR*layerR)+half_polyFace - layer_pos_x)/2.0;
       cout<<"Rmin: "<< rmin<<" Rmax: "<<rmax<<" half_polyFace: "<<half_polyFace<<" Layer " <<layer_num<<" layerR: "<<layerR<<" layer_dim_x:" <<layer_dim_x<<endl;
       // Increment the layer Z position.
       layer_pos_z += layer_thickness / 2;
-- 
GitLab