From fb3487c637d341ba6b2a558f5ab85dc2a11d6b70 Mon Sep 17 00:00:00 2001
From: Marko Petric <marko.petric@cern.ch>
Date: Fri, 20 Nov 2020 12:09:20 +0100
Subject: [PATCH] fix units and clarify from where they come

---
 DDG4/plugins/Geant4MaterialScanner.cpp | 15 +++++++--------
 DDG4/plugins/Geant4SDActions.cpp       |  1 -
 DDG4/scripts/dumpDDG4.C                | 17 ++++++++---------
 DDG4/src/Geant4ParticleGenerator.cpp   |  2 --
 4 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/DDG4/plugins/Geant4MaterialScanner.cpp b/DDG4/plugins/Geant4MaterialScanner.cpp
index 83d5b853c..76efe6a9f 100644
--- a/DDG4/plugins/Geant4MaterialScanner.cpp
+++ b/DDG4/plugins/Geant4MaterialScanner.cpp
@@ -170,7 +170,6 @@ void Geant4MaterialScanner::begin(const G4Track* track) {
 
 /// End-of-tracking callback
 void Geant4MaterialScanner::end(const G4Track* track) {
-  using namespace CLHEP;
   if ( !m_steps.empty() )  {
     constexpr const char* line = " +--------------------------------------------------------------------------------------------------------------------------------------------------\n";
     constexpr const char* fmt1 = " | %5d %-20s %3.0f %8.3f %8.4f %11.4f  %11.4f %10.3f %8.2f %11.6f %11.6f  (%7.2f,%7.2f,%7.2f)\n";
@@ -179,7 +178,7 @@ void Geant4MaterialScanner::end(const G4Track* track) {
     const Position& post = m_steps[m_steps.size()-1]->post;
 
     ::printf("%s + Material scan between: x_0 = (%7.2f,%7.2f,%7.2f) [cm] and x_1 = (%7.2f,%7.2f,%7.2f) [cm]  TrackID:%d: \n%s",
-             line,pre.X()/cm,pre.Y()/cm,pre.Z()/cm,post.X()/cm,post.Y()/cm,post.Z()/cm,track->GetTrackID(),line);
+             line,pre.X()/CLHEP::cm,pre.Y()/CLHEP::cm,pre.Z()/CLHEP::cm,post.X()/CLHEP::cm,post.Y()/CLHEP::cm,post.Z()/CLHEP::cm,track->GetTrackID(),line);
     ::printf(" |     \\   %-11s        Atomic                 Radiation   Interaction               Path   Integrated  Integrated    Material\n","Material");
     ::printf(" | Num. \\  %-11s   Number/Z   Mass/A  Density    Length       Length    Thickness   Length      X0        Lambda      Endpoint  \n","Name");
     ::printf(" | Layer \\ %-11s            [g/mole]  [g/cm3]     [cm]        [cm]          [cm]      [cm]     [cm]        [cm]     (     cm,     cm,     cm)\n","");
@@ -191,10 +190,10 @@ void Geant4MaterialScanner::end(const G4Track* track) {
       const Position& prePos  = (*i)->pre;
       const Position& postPos = (*i)->post;
       Position direction = postPos - prePos;
-      double length  = direction.R()/cm;
-      double intLen  = material->GetNuclearInterLength()/cm;
-      double radLen  = material->GetRadlen()/cm;
-      double density = material->GetDensity()/(gram/cm3);
+      double length  = direction.R()/CLHEP::cm;
+      double intLen  = material->GetNuclearInterLength()/CLHEP::cm;
+      double radLen  = material->GetRadlen()/CLHEP::cm;
+      double density = material->GetDensity()/(CLHEP::gram/CLHEP::cm3);
       double nLambda = length / intLen;
       double nx0     = length / radLen;
       double Aeff    = 0.0;
@@ -203,7 +202,7 @@ void Geant4MaterialScanner::end(const G4Track* track) {
       const double* fractions = material->GetFractionVector();
       for(size_t j=0; j<material->GetNumberOfElements(); ++j)  {
         Zeff += fractions[j]*(material->GetElement(j)->GetZ());
-        Aeff += fractions[j]*(material->GetElement(j)->GetA())/gram;
+        Aeff += fractions[j]*(material->GetElement(j)->GetA())/CLHEP::gram;
       }
       m_sumX0     += nx0;
       m_sumLambda += nLambda;
@@ -211,7 +210,7 @@ void Geant4MaterialScanner::end(const G4Track* track) {
       ::printf(fmt,count,material->GetName().c_str(),
                Zeff, Aeff, density, radLen, intLen, length,
                m_sumPath,m_sumX0,m_sumLambda,
-               postPos.X()/cm,postPos.Y()/cm,postPos.Z()/cm);
+               postPos.X()/CLHEP::cm,postPos.Y()/CLHEP::cm,postPos.Z()/CLHEP::cm);
       //cout << *m << endl;
     }
     for_each(m_steps.begin(),m_steps.end(),detail::DestroyObject<StepInfo*>());
diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp
index 6b2a769bd..e544b1e9c 100644
--- a/DDG4/plugins/Geant4SDActions.cpp
+++ b/DDG4/plugins/Geant4SDActions.cpp
@@ -17,7 +17,6 @@
 #include "G4OpticalPhoton.hh"
 #include "G4VProcess.hh"
 
-using namespace CLHEP;
 
 /// Namespace for the AIDA detector description toolkit
 namespace dd4hep {
diff --git a/DDG4/scripts/dumpDDG4.C b/DDG4/scripts/dumpDDG4.C
index 4b9c48bbc..030199a5c 100644
--- a/DDG4/scripts/dumpDDG4.C
+++ b/DDG4/scripts/dumpDDG4.C
@@ -28,7 +28,6 @@
 #include "TSystem.h"
 
 using namespace std;
-using namespace CLHEP;
 using namespace dd4hep;
 using namespace dd4hep::detail;
 
@@ -73,9 +72,9 @@ namespace {
         printout(ALWAYS,container,
                  "+++ Track:%3d PDG:%6d Pos:(%+.2e,%+.2e,%+.2e)[mm] Pixel:(%+.2e,%+.2e,%+.2e)[mm] %s Deposit:%7.3f MeV CellID:%16lX",
                  h->truth.trackID,h->truth.pdgID,
-                 pos.x()/mm,pos.y()/mm,pos.z()/mm,
+                 pos.x()/CLHEP::mm,pos.y()/CLHEP::mm,pos.z()/CLHEP::mm,
                  pos_cell.x()/dd4hep::mm,pos_cell.y()/dd4hep::mm,pos_cell.z()/dd4hep::mm,
-                 pv.name(),h->truth.deposit/MeV,h->cellID
+                 pv.name(),h->truth.deposit/CLHEP::MeV,h->cellID
                  );
         delete h;
       }
@@ -87,8 +86,8 @@ namespace {
         printout(ALWAYS,container,
                  "+++ Track:%3d PDG:%6d Pos:(%+.2e,%+.2e,%+.2e)[mm] Deposit:%7.3f MeV CellID:%16lX",
                  h->truth.trackID,h->truth.pdgID,
-                 pos.x()/mm,pos.y()/mm,pos.z()/mm,
-                 h->truth.deposit/MeV,h->cellID
+                 pos.x()/CLHEP::mm,pos.y()/CLHEP::mm,pos.z()/CLHEP::mm,
+                 h->truth.deposit/CLHEP::MeV,h->cellID
                  );
         delete h;
       }
@@ -118,9 +117,9 @@ namespace {
         PlacedVolume pv = vm.lookupPlacement(h->cellID);
         printout(ALWAYS,container,
                  "+++ Pos:(%+.2e,%+.2e,%+.2e)[mm] Pixel:(%+.2e,%+.2e,%+.2e)[mm] %s Deposit:%7.3f MeV CellID:%16lX",
-                 pos.x()/mm,pos.y()/mm,pos.z()/mm,
+                 pos.x()/CLHEP::mm,pos.y()/CLHEP::mm,pos.z()/CLHEP::mm,
                  pos_cell.x()/dd4hep::mm,pos_cell.y()/dd4hep::mm,pos_cell.z()/dd4hep::mm,
-                 pv.name(),h->energyDeposit/MeV,h->cellID
+                 pv.name(),h->energyDeposit/CLHEP::MeV,h->cellID
                  );
         delete h;
       }
@@ -152,8 +151,8 @@ namespace {
                  "+++%s %3d stat:%08X PDG:%6d Mom:(%+.2e,%+.2e,%+.2e)[MeV] "
                  "Vtx:(%+.2e,%+.2e,%+.2e)[mm] #Dau:%3d #Par:%1d%-6s",
                  "",p->id,p->status,p->pdgID,
-                 p->psx/MeV,p->psy/MeV,p->psz/MeV,
-                 p->vsx/mm,p->vsy/mm,p->vsz/mm,
+                 p->psx/CLHEP::MeV,p->psy/CLHEP::MeV,p->psz/CLHEP::MeV,
+                 p->vsx/CLHEP::mm,p->vsy/CLHEP::mm,p->vsz/CLHEP::mm,
                  int(p->daughters.size()),
                  int(p->parents.size()),
                  text);
diff --git a/DDG4/src/Geant4ParticleGenerator.cpp b/DDG4/src/Geant4ParticleGenerator.cpp
index d16cf736c..b847e4193 100644
--- a/DDG4/src/Geant4ParticleGenerator.cpp
+++ b/DDG4/src/Geant4ParticleGenerator.cpp
@@ -27,8 +27,6 @@
 #include <stdexcept>
 #include <cmath>
 
-using CLHEP::MeV;
-using CLHEP::GeV;
 using namespace std;
 using namespace dd4hep::sim;
 
-- 
GitLab