From d2c6fafb5d26e9c0d75e188c4d75cf65ea3c477c Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Thu, 12 Aug 2021 21:12:58 -0500
Subject: [PATCH] Added dd4pod so all data models are on one page.

	modified:   README.md
	deleted:    dd4hep.yaml
	new file:   dd4pod.yaml
---
 README.md   |   6 +++
 dd4hep.yaml | 102 --------------------------------------
 dd4pod.yaml | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+), 102 deletions(-)
 delete mode 100644 dd4hep.yaml
 create mode 100644 dd4pod.yaml

diff --git a/README.md b/README.md
index 7d1fdb4..87990c0 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,12 @@ The entire data model is defined with a single YAML file. Here is the current de
 \verbinclude eic_data.yaml
 
 
+### dd4pod data model
+
+This is useful for mc truth.
+
+\verbinclude dd4pod.yaml
+
 ## Installing
 
 ```
diff --git a/dd4hep.yaml b/dd4hep.yaml
deleted file mode 100644
index 5c091be..0000000
--- a/dd4hep.yaml
+++ /dev/null
@@ -1,102 +0,0 @@
----
-options :
-  # should getters / setters be prefixed with get / set?
-  getSyntax: False
-  # should POD members be exposed with getters/setters in classes that have them as members?
-  exposePODMembers: False
-  includeSubfolder: True
-
-components:
-  dd4pod::ThreeVector:
-    #Description: "three vector"
-    #Author : "W.Armstrong"
-    Members:
-      - double x
-      - double y
-      - double z
-
-  dd4pod::MonteCarloContrib:
-    #Description: "Podio implementation of dd4hep's dd4hep::sim::MonteCarloContrib class"
-    #Author : "W.Armstrong"
-    Members:
-      - int trackID // track id
-      - int pdgID // pdgID
-      - double deposit // en deposit
-      - double time // time
-      - double length //length
-      - double x // x
-      - double y // x
-      - double z // x
-
-datatypes :
-
-  dd4pod::FourVector :
-    Description: "four vector"
-    Author : "W.Armstrong"
-    Members :
-      - double x // x
-      - double y // y
-      - double z // z
-      - double t // t
-
-
-  dd4pod::Geant4Particle:
-    Description: "Podio implementation of dd4hep's dd4hep::sim::Geant4Particle class"
-    Author : "W.Armstrong"
-    Members:
-      - int ID // x
-      - int g4Parent  // x
-      - int reason // x
-      - int mask // x
-      - int steps // x
-      - int secondaries // x
-      - int pdgID // x
-      - int status // x
-      - std::array<int,2> colorFlow // x
-      - int  genStatus // x
-      - int  charge   // x
-      - std::array<int,1> spare // x
-      - std::array<float,3>  spin  // x
-      - double vsx   // x
-      - double vsy   // x
-      - double vsz  // x
-      - double vex   // x
-      - double vey   // x
-      - double vez  // x
-      - double psx   // x
-      - double psy   // x
-      - double psz  // x
-      - double pex   // x
-      - double pey   // x
-      - double pez  // x
-      - double mass  // x
-      - double time  // x
-      - double properTime // x 
-    OneToManyRelations:
-      - dd4pod::Geant4Particle parents  // x
-      - dd4pod::Geant4Particle daughters  // x
-
-  dd4pod::TrackerHit:
-    Description: "Podio implementation of dd4hep's dd4hep::sim::Geant4Tracker::Hit class"
-    Author : "W.Armstrong"
-    Members:
-      - long cellID  // cellID
-      - long flag    // User flag to classify hits
-      - long g4ID    // Original Geant 4 track identifier of the creating track (debugging)
-      - dd4pod::ThreeVector position // position 
-      - dd4pod::ThreeVector momentum // momentum
-      - double length // length 
-      - dd4pod::MonteCarloContrib truth // truth 
-      - double energyDeposit // energyDeposit
-
-  dd4pod::CalorimeterHit:
-    Description: "Podio implementation of dd4hep's dd4hep::sim::Geant4Calorimeter::Hit class"
-    Author : "W.Armstrong"
-    Members:
-      - long cellID  // cellID 
-      - long flag // User flag to classify hits
-      - long g4ID // Original Geant 4 track identifier of the creating track (debugging)
-      - dd4pod::ThreeVector position // position
-      - dd4pod::MonteCarloContrib truth // truth
-      - double energyDeposit // energyDeposit
-
diff --git a/dd4pod.yaml b/dd4pod.yaml
new file mode 100644
index 0000000..ec626f5
--- /dev/null
+++ b/dd4pod.yaml
@@ -0,0 +1,137 @@
+---
+options :
+  # should getters / setters be prefixed with get / set?
+  getSyntax: False
+  # should POD members be exposed with getters/setters in classes that have them as members?
+  exposePODMembers: False
+  includeSubfolder: True
+
+components:
+
+  dd4pod::VectorXYZ:
+    Members:
+      - double x          // [mm] or [GeV]
+      - double y          //
+      - double z          //
+    ExtraCode:
+      includes: "#include <cmath>\n#include<tuple>"
+      declaration: "
+        VectorXYZ() : x{0}, y{0}, z{0} {}\n
+        VectorXYZ(double xx, double yy, double zz) : x{xx}, y{yy}, z{zz} {}\n
+        double& operator[](unsigned i) {return *(&x + i);}\n
+        const double& operator[](unsigned i) const {return *(&x + i);}\n
+        double mag() const {return std::hypot(x, y, z);}\n
+        double r() const {return mag();}\n
+        double theta() const {return acos(z/mag());}\n
+        double phi() const {return atan2(y,x);}\n
+        double eta() const {return -log(tan(0.5*theta()));}\n
+        operator std::tuple<double, double, double>() {return {x, y, z};}\n
+        double dot(const VectorXYZ& rhs) const {return x*rhs.x + y*rhs.y + z*rhs.z;}\n
+        VectorXYZ add(const VectorXYZ& rhs) const {return {x+rhs.x, y+rhs.y, z+rhs.z};}\n
+        VectorXYZ subtract(const VectorXYZ& rhs) const {return {x-rhs.x, y-rhs.y, z-rhs.z};}\n
+        VectorXYZ scale(double f) const {return {f*x, f*y, f*z};}\n
+      "
+
+  dd4pod::MonteCarloContrib:
+    #Description: "Podio implementation of dd4hep's dd4hep::sim::MonteCarloContrib class"
+    #Author : "W.Armstrong"
+    Members:
+      - int32_t   trackID // track id, -1 if none/invalid
+      - int32_t   pdgID   // PDG Particle ID code 
+      - double    deposit // energy deposit [GeV]
+      - double    time    // time [ns]
+      - double    length  // length [mm]
+      - float     x       // x position [mm]
+      - float     y       // y position [mm]
+      - float     z       // z position [mm]
+    ExtraCode:
+      includes: "#include <cmath>"
+      declaration: "
+        MonteCarloContrib() : trackID{-1}, pdgID{0}, deposit{0}, time{0}, x{0}, y{0}, z{0} {}\n
+        MonteCarloContrib(int32_t id, int32_t pdg, double e, double t,\n
+                          double l, double xx, double yy, double zz)\n
+            : trackID{id}, pdgID{pdg}, deposit{e}, time{t}, length{l}\n
+            , x{static_cast<float>(xx)}, y{static_cast<float>(yy)}, z{static_cast<float>(zz)} {}\n
+        double mag() const {return std::hypot(x, y, z);}\n
+        double r() const {return mag();}\n
+        double theta() const {return acos(z/mag());}\n
+        double phi() const {return atan2(y,x);}\n
+        double eta() const {return -log(tan(0.5*theta()));}
+        bool valid() const {return trackID >= 0;}\n
+        bool empty() const {return trackID < 0;}\n
+      "
+
+datatypes :
+
+  dd4pod::Geant4Particle:
+    Description: "Podio implementation of dd4hep's dd4hep::sim::Geant4Particle class"
+    Author : "W.Armstrong"
+    Members:
+      - int32_t                   ID                // unique identifier for this particle
+      - int32_t                   g4Parent          // g4 parent particle
+      - int32_t                   reason            // TODO document
+      - int32_t                   mask              // TODO document
+      - int32_t                   steps             // TODO document
+      - int32_t                   secondaries       // TODO document
+      - int32_t                   pdgID             // TODO document
+      - int32_t                   status            // TODO document
+      - std::array<int,2>         colorFlow         // TODO document
+      - int32_t                   genStatus         // Generator status code
+      - int32_t                   charge            // Particle charge
+      - int32_t                   _spare            // extra int to have doubles properly aligned at 8 bytes
+      - std::array<float,3>       spin              // Particle spin state
+      - dd4pod::VectorXYZ         vs                // Start vertex [mm]
+      - dd4pod::VectorXYZ         ve                // End vertex [mm]
+      - dd4pod::VectorXYZ         ps                // 3-momentum at start vertex [GeV]
+      - dd4pod::VectorXYZ         pe                // 3-momentum at end vertex [GeV]
+      - double                    mass              // particle mass [GeV]
+      - double                    time              // start vertex time [ns]
+      - double                    properTime        // proper time
+    VectorMembers:
+      - int32_t                   parents           // parent IDs
+      - int32_t                   daughters         // daughter IDs
+    ConstExtraCode :
+      declaration: "
+        double px() const {return ps().x;}\n
+        double py() const {return ps().y;}\n
+        double pz() const {return ps().z;}\n
+        double energy() const {return std::hypot(ps().mag(), mass());}
+      "
+
+  dd4pod::PhotoMultiplierHit:
+    Description: "Podio implementation of a pmt hit "
+    Author : "W.Armstrong"
+    Members:
+      - int64_t                   cellID            // cellID
+      - int32_t                   flag              // User flag to classify hits
+      - int32_t                   g4ID              // Original Geant4 track identifier of the creating track (for debugging)
+      - dd4pod::VectorXYZ         position          // hit position [mm]
+      - dd4pod::VectorXYZ         momentum          // 3-momentum [GeV]
+      - double                    length            // length [mm]
+      - dd4pod::MonteCarloContrib truth             // truth info
+      - double                    energy            // photon energy [GeV]
+
+  dd4pod::TrackerHit:
+    Description: "Podio implementation of dd4hep's dd4hep::sim::Geant4Tracker::Hit class"
+    Author : "W.Armstrong"
+    Members:
+      - int64_t                   cellID            // cellID
+      - int32_t                   flag              // User flag to classify hits
+      - int32_t                   g4ID              // Original Geant4 track identifier of the creating track (debugging)
+      - dd4pod::VectorXYZ         position          // position [mm]
+      - dd4pod::VectorXYZ         momentum          // 3-momentum [GeV]
+      - double                    length            // length [mm]
+      - dd4pod::MonteCarloContrib truth             // truth info
+      - double                    energyDeposit     // energy deposit [GeV]
+
+  dd4pod::CalorimeterHit:
+    Description: "Podio implementation of dd4hep's dd4hep::sim::Geant4Calorimeter::Hit class"
+    Author : "W.Armstrong"
+    Members:
+      - int64_t                   cellID            // cellID 
+      - int32_t                   flag              // User flag to classify hits
+      - int32_t                   g4ID              // Original Geant4 track identifier of the creating track (debugging)
+      - dd4pod::VectorXYZ         position          // position [mm]
+      - dd4pod::MonteCarloContrib truth             // truth-info
+      - double                    energyDeposit     // energy deposit [GeV]
+
-- 
GitLab