From 1ee395ebd909be819ff6c70a643f05f88d2f43d0 Mon Sep 17 00:00:00 2001
From: Dave Casper <dcasper@uci.edu>
Date: Sun, 8 Oct 2023 06:16:35 -0700
Subject: [PATCH] Put the HepMC vertex time in length units

---
 .../SimHitExample/src/SimHitAlg.cxx              | 16 +++++++++++++---
 .../CalypsoExample/SimHitExample/src/SimHitAlg.h |  4 ++++
 Generators/DIFGenerator/python/DIFSampler.py     |  4 ++--
 .../FaserCosmicGenerator/python/cosmicSampler.py |  3 +--
 .../FaserParticleGun/python/RadialPosSampler.py  |  3 +--
 Generators/FlukaReader/python/FlukaReaderAlg.py  |  3 +--
 Generators/GenieReader/python/GenieReaderAlg.py  |  5 ++---
 Generators/ParticleGun/python/samplers.py        |  3 +--
 8 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx
index 7fc37147..995578e5 100644
--- a/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx
+++ b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx
@@ -25,6 +25,15 @@ StatusCode SimHitAlg::initialize()
     ATH_CHECK(histSvc()->regHist("/HIST/plate_trigger", m_plate_trigger));
     ATH_CHECK(histSvc()->regHist("/HIST/plate_veto", m_plate_veto));
 
+    m_veto_hitTime = new TH1D("vetoTime", "Veto hit time", 120, -30, 30);
+    m_preshower_hitTime = new TH1D("preshowerTime", "Preshower hit time", 120, -30, 30);
+    m_trigger_hitTime = new TH1D("triggerTime", "Trigger hit time", 120, -30, 30);
+    m_ecal_hitTime = new TH1D("ecalTime", "Ecal hit time", 120, -30, 30);
+    ATH_CHECK(histSvc()->regHist("/HIST/vetoTime", m_veto_hitTime));
+    ATH_CHECK(histSvc()->regHist("/HIST/triggerTime", m_trigger_hitTime));
+    ATH_CHECK(histSvc()->regHist("/HIST/preshowerTime", m_preshower_hitTime));
+    ATH_CHECK(histSvc()->regHist("/HIST/ecalTime", m_ecal_hitTime));
+
     m_ecalEnergy = new TH1D("ecalEnergy", "Ecal Energy Fraction", 100, 0.0, 0.20);
     ATH_CHECK(histSvc()->regHist("/HIST/ecal_energy", m_ecalEnergy));
 
@@ -140,7 +149,7 @@ StatusCode SimHitAlg::execute()
             if (m_printScintillator) hit.print();
             m_hist->Fill(hit.energyLoss());
             m_plate_preshower->Fill(hit.getStation(),hit.getPlate(),hit.energyLoss());
-
+            m_preshower_hitTime->Fill(hit.meanTime(), hit.energyLoss());
         }
     }
 
@@ -150,7 +159,7 @@ StatusCode SimHitAlg::execute()
             if (m_printScintillator) hit.print();
             m_hist->Fill(hit.energyLoss());
             m_plate_trigger->Fill(hit.getStation(),hit.getPlate(),hit.energyLoss());
-
+            m_trigger_hitTime->Fill(hit.meanTime(), hit.energyLoss());
         }
     }
 
@@ -160,7 +169,7 @@ StatusCode SimHitAlg::execute()
             if (m_printScintillator) hit.print();
             m_hist->Fill(hit.energyLoss());
             m_plate_veto->Fill(hit.getStation(),hit.getPlate(),hit.energyLoss());
-
+            m_veto_hitTime->Fill(hit.meanTime(), hit.energyLoss());
         }
     }
 
@@ -171,6 +180,7 @@ StatusCode SimHitAlg::execute()
         {
             if (m_printCalorimeter) hit.print();
             ecalTotal += hit.energyLoss();
+            m_ecal_hitTime->Fill(hit.meanTime(), hit.energyLoss());
         }
         if (ePrimary > 0) m_ecalEnergy->Fill(ecalTotal/ePrimary);
     }
diff --git a/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h
index b385c87e..881365de 100644
--- a/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h
+++ b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h
@@ -30,9 +30,13 @@ class SimHitAlg : public AthHistogramAlgorithm
     TH2* m_plate_preshower;
     TH2* m_plate_trigger;
     TH2* m_plate_veto;
+    TH1* m_veto_hitTime;
+    TH1* m_preshower_hitTime;
+    TH1* m_trigger_hitTime;
 
     // Ecal histogram
     TH1* m_ecalEnergy;
+    TH1* m_ecal_hitTime;
 
     // Emulsion PDG_ID
     TH1* m_emulsionPDG;
diff --git a/Generators/DIFGenerator/python/DIFSampler.py b/Generators/DIFGenerator/python/DIFSampler.py
index 740fff10..1f82f60d 100644
--- a/Generators/DIFGenerator/python/DIFSampler.py
+++ b/Generators/DIFGenerator/python/DIFSampler.py
@@ -6,7 +6,7 @@ import ParticleGun as PG
 from math import sqrt, sin, cos, acos
 from random import uniform
 from AthenaCommon.SystemOfUnits import TeV, GeV, MeV
-from AthenaCommon.PhysicalConstants import pi, c_light
+from AthenaCommon.PhysicalConstants import pi
 from ROOT import TLorentzVector
 
 class CylinderSampler(PG.Sampler):
@@ -59,7 +59,7 @@ class CylinderSampler(PG.Sampler):
         z   = self.z()
         t   = self.t()
         if self.axialTiming:
-            t += z/c_light
+            t += z
         #print "POS =", x, y, z, t
         return TLorentzVector(r * cos(phi), r * sin(phi), z, t)
 
diff --git a/Generators/FaserCosmicGenerator/python/cosmicSampler.py b/Generators/FaserCosmicGenerator/python/cosmicSampler.py
index dd0c841f..5642de80 100644
--- a/Generators/FaserCosmicGenerator/python/cosmicSampler.py
+++ b/Generators/FaserCosmicGenerator/python/cosmicSampler.py
@@ -5,7 +5,6 @@ from random import random
 from math import pi,sin,cos,acos,asin,sqrt
 import FaserCosmicGenerator.Range as r
 from numpy import array,add
-from AthenaCommon.PhysicalConstants import c_light
 import numpy as np
 
 
@@ -56,7 +55,7 @@ class CosmicSampler(Sampler):
         px, py, pz = CR.mom
 
         # impose vertical timing constraint
-        self.genPosition.SetXYZT(x + self.x0, y + self.y0, z + self.z0, -(y + self.y0)/(c_light * math.fabs(CR.costh)))
+        self.genPosition.SetXYZT(x + self.x0, y + self.y0, z + self.z0, -(y + self.y0)/math.fabs(CR.costh))
         self.genMomentum.SetPxPyPzE(px,py,pz,CR.Efinal)
 
         particles = []
diff --git a/Generators/FaserParticleGun/python/RadialPosSampler.py b/Generators/FaserParticleGun/python/RadialPosSampler.py
index 8e1efdfd..8f2fe2f0 100644
--- a/Generators/FaserParticleGun/python/RadialPosSampler.py
+++ b/Generators/FaserParticleGun/python/RadialPosSampler.py
@@ -1,7 +1,6 @@
 import random
 from math import pi, sin, cos, sqrt, log
 from ParticleGun.samplers import Sampler, mksampler
-from AthenaCommon.PhysicalConstants import c_light
 import ROOT
 
 class RadialPosSampler(Sampler):
@@ -65,7 +64,7 @@ class RadialPosSampler(Sampler):
         z = self.z()
         t = self.t()
         if self.axialTiming:
-            t += z/c_light
+            t += z
 
         return ROOT.TLorentzVector(x, y, z, t)
 
diff --git a/Generators/FlukaReader/python/FlukaReaderAlg.py b/Generators/FlukaReader/python/FlukaReaderAlg.py
index ba4837c1..5349e222 100644
--- a/Generators/FlukaReader/python/FlukaReaderAlg.py
+++ b/Generators/FlukaReader/python/FlukaReaderAlg.py
@@ -2,7 +2,6 @@ from AthenaCommon.AppMgr import ServiceMgr as svcMgr
 from GeneratorModules.EvgenAlg import EvgenAlg
 from AthenaPython.PyAthena import StatusCode, EventInfo, EventID, EventType
 from AthenaCommon.SystemOfUnits import GeV, MeV, cm
-from AthenaCommon.PhysicalConstants import c_light
 from AthenaCommon.Constants import DEBUG
 
 from FaserCosmicGenerator import Range
@@ -268,7 +267,7 @@ class FlukaReader(EvgenAlg):
 
         # Create HepMC Vertex
         # Impose axial timing constraint
-        pos = HepMC.FourVector(newentry["x"] * cm, newentry["y"] * cm, self.z, self.z/c_light)
+        pos = HepMC.FourVector(newentry["x"] * cm, newentry["y"] * cm, self.z, self.z)
         gv = HepMC.GenVertex(pos)
 
         ROOT.SetOwnership(gv, False)
diff --git a/Generators/GenieReader/python/GenieReaderAlg.py b/Generators/GenieReader/python/GenieReaderAlg.py
index 373fa709..432d792c 100644
--- a/Generators/GenieReader/python/GenieReaderAlg.py
+++ b/Generators/GenieReader/python/GenieReaderAlg.py
@@ -4,7 +4,6 @@ from AthenaCommon.AppMgr import ServiceMgr as svcMgr
 from GeneratorModules.EvgenAlg import EvgenAlg
 from AthenaPython.PyAthena import StatusCode, EventInfo, EventID, EventType
 from AthenaCommon.SystemOfUnits import GeV, m, nanosecond
-from AthenaCommon.PhysicalConstants import c_light
 import ROOT
 
 __author__ = "Dave Caser <dcasper@uci.edu>"
@@ -38,8 +37,8 @@ class GenieReader(EvgenAlg):
         ROOT.SetOwnership(mcEventId, False)
         ROOT.SetOwnership(mcEventInfo, False)
 
-        # impose axial timing constraint
-        pos = HepMC.FourVector(self.evtStore["vx"]*m, self.evtStore["vy"]*m, self.evtStore["vz"]*m, (self.evtStore["vz"]*m/c_light))
+        # impose axial timing constraint - time is expected in units of length, so just use z position
+        pos = HepMC.FourVector(self.evtStore["vx"]*m, self.evtStore["vy"]*m, self.evtStore["vz"]*m, self.evtStore["vz"]*m)
         gv = HepMC.GenVertex(pos)
         ROOT.SetOwnership(gv, False)
         evt.add_vertex(gv)
diff --git a/Generators/ParticleGun/python/samplers.py b/Generators/ParticleGun/python/samplers.py
index b53848c0..b9edbd6c 100644
--- a/Generators/ParticleGun/python/samplers.py
+++ b/Generators/ParticleGun/python/samplers.py
@@ -2,7 +2,6 @@
 
 import ROOT, math, random
 from ParticleGun.histsampling import TH1,TH2
-from AthenaCommon.PhysicalConstants import c_light
 
 ## For convenience
 PI = math.pi
@@ -355,7 +354,7 @@ class PosSampler(Sampler):
         z = self.z()
         t = self.t()
         if self.axialTiming:
-            t += z/c_light
+            t += z
 
         #print "POS =", x, y, z, t
         return ROOT.TLorentzVector(x, y, z, t)
-- 
GitLab