From c103475a8f3c25d60ceb237f304050a685df1f2c Mon Sep 17 00:00:00 2001 From: Dave Casper <dcasper@uci.edu> Date: Sat, 7 Oct 2023 10:40:18 -0700 Subject: [PATCH] Add axial timing to particle gun position samplers --- Generators/DIFGenerator/python/DIFSampler.py | 7 +++++-- .../python/cosmicSampler.py | 4 +++- .../python/FaserParticleGunConfig.py | 20 ++++++++++++------- .../python/RadialPosSampler.py | 6 +++++- .../FlukaReader/python/FlukaReaderAlg.py | 4 +++- .../GenieReader/python/GenieReaderAlg.py | 6 ++++-- Generators/ParticleGun/python/samplers.py | 7 ++++++- 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Generators/DIFGenerator/python/DIFSampler.py b/Generators/DIFGenerator/python/DIFSampler.py index 007830b6..740fff10 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 +from AthenaCommon.PhysicalConstants import pi, c_light from ROOT import TLorentzVector class CylinderSampler(PG.Sampler): @@ -14,11 +14,12 @@ class CylinderSampler(PG.Sampler): Sampler of position 4-vectors within a cylindrical volume. """ - def __init__(self, rsq, phi, z, t=0): + def __init__(self, rsq, phi, z, t=0, axialTiming = True): self.rsq = rsq self.phi = phi self.z = z self.t = t + self.axialTiming = axialTiming @property def rsq(self): @@ -57,6 +58,8 @@ class CylinderSampler(PG.Sampler): phi = self.phi() z = self.z() t = self.t() + if self.axialTiming: + t += z/c_light #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 7a147e43..dd0c841f 100644 --- a/Generators/FaserCosmicGenerator/python/cosmicSampler.py +++ b/Generators/FaserCosmicGenerator/python/cosmicSampler.py @@ -5,6 +5,7 @@ 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 @@ -54,7 +55,8 @@ class CosmicSampler(Sampler): x, y, z = CR.pos px, py, pz = CR.mom - self.genPosition.SetXYZT(x + self.x0, y + self.y0, z + self.z0, 0) + # 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.genMomentum.SetPxPyPzE(px,py,pz,CR.Efinal) particles = [] diff --git a/Generators/FaserParticleGun/python/FaserParticleGunConfig.py b/Generators/FaserParticleGun/python/FaserParticleGunConfig.py index d2e82a88..f75fabf9 100644 --- a/Generators/FaserParticleGun/python/FaserParticleGunConfig.py +++ b/Generators/FaserParticleGun/python/FaserParticleGunConfig.py @@ -50,12 +50,14 @@ def FaserParticleGunSingleParticleCfg(ConfigFlags, **kwargs) : y = kwargs.setdefault("y", 0.0), z = kwargs.setdefault("z", -3750.0), r = kwargs.setdefault("radius", 1.0), - t = kwargs.setdefault("t", 0.0) ) + t = kwargs.setdefault("t", 0.0), + axialTiming = kwargs.setdefault("axialTiming", True) ) else: pg.sampler.pos = PG.PosSampler(x = kwargs.setdefault("x", [-5, 5]), y = kwargs.setdefault("y", [-5, 5]), z = kwargs.setdefault("z", -3750.0), - t = kwargs.setdefault("t", 0.0) ) + t = kwargs.setdefault("t", 0.0), + axialTiming = kwargs.setdefault("axialTiming", True) ) return cfg @@ -75,12 +77,14 @@ def FaserParticleGunSingleEcalParticleCfg(ConfigFlags, **kwargs) : y = kwargs.setdefault("y", 0.0), z = kwargs.setdefault("z", 0.0), r = kwargs.setdefault("radius", 1.0), - t = kwargs.setdefault("t", 0.0) ) + t = kwargs.setdefault("t", 0.0), + axialTiming = kwargs.setdefault("axialTiming", True) ) else: pg.sampler.pos = PG.PosSampler(x = kwargs.setdefault("x", 0.0), y = kwargs.setdefault("y", 0.0), z = kwargs.setdefault("z", 0.0), - t = kwargs.setdefault("t", 0.0) ) + t = kwargs.setdefault("t", 0.0), + axialTiming = kwargs.setdefault("axialTiming", True) ) return cfg @@ -98,7 +102,8 @@ def FaserParticleGunSingleEcalParticleCfg(ConfigFlags, **kwargs) : pg.sampler.pos = PG.PosSampler(x = kwargs.setdefault("x", [-5, 5]), y = kwargs.setdefault("y", [-5, 5]), z = kwargs.setdefault("z", 2730.0), - t = kwargs.setdefault("t", 0.0) ) + t = kwargs.setdefault("t", 0.0), + axialTiming = kwargs.setdefault("axialTiming", True) ) return cfg ''' @@ -150,10 +155,11 @@ def FaserParticleGunDecayInFlightCfg(ConfigFlags, **kwargs) : y = kwargs.setdefault("y", 0.0), z = kwargs.setdefault("z", -3750.0), r = kwargs.setdefault("radius", 1.0), - t = kwargs.setdefault("t", 0.0) ) + t = kwargs.setdefault("t", 0.0), + axialTiming = kwargs.setdefault("axialTiming", True) ) else: from DIFGenerator.DIFSampler import CylinderSampler - kwargs["mother_pos"] = CylinderSampler([0, 100**2], [0, 2*pi], [-1500, 0], 0) + kwargs["mother_pos"] = CylinderSampler([0, 100**2], [0, 2*pi], [-1500, 0], 0, True) if not "mother_mom" in kwargs: kwargs["mother_mom"] = PG.EThetaMPhiSampler(kwargs.setdefault("energy", ((1*TeV)**2 + (500*MeV)**2)**0.5), diff --git a/Generators/FaserParticleGun/python/RadialPosSampler.py b/Generators/FaserParticleGun/python/RadialPosSampler.py index 19b1db11..8e1efdfd 100644 --- a/Generators/FaserParticleGun/python/RadialPosSampler.py +++ b/Generators/FaserParticleGun/python/RadialPosSampler.py @@ -1,6 +1,7 @@ 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): @@ -8,12 +9,13 @@ class RadialPosSampler(Sampler): Sampler of Position 3-vectors, for modelling a beamspot, based on radius. """ - def __init__(self, r, x, y, z, t = 0): + def __init__(self, r, x, y, z, t = 0, axialTiming = True): self.radius = r self.x = x self.y = y self.z = z self.t = t + self.axialTiming = axialTiming @property def z(self): @@ -62,6 +64,8 @@ class RadialPosSampler(Sampler): y = self.y + r * sin(phi) z = self.z() t = self.t() + if self.axialTiming: + t += z/c_light return ROOT.TLorentzVector(x, y, z, t) diff --git a/Generators/FlukaReader/python/FlukaReaderAlg.py b/Generators/FlukaReader/python/FlukaReaderAlg.py index 4cc449e6..ba4837c1 100644 --- a/Generators/FlukaReader/python/FlukaReaderAlg.py +++ b/Generators/FlukaReader/python/FlukaReaderAlg.py @@ -2,6 +2,7 @@ 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 @@ -266,7 +267,8 @@ class FlukaReader(EvgenAlg): ROOT.SetOwnership(mcEventInfo, False) # Create HepMC Vertex - pos = HepMC.FourVector(newentry["x"] * cm, newentry["y"] * cm, self.z, 0) + # Impose axial timing constraint + pos = HepMC.FourVector(newentry["x"] * cm, newentry["y"] * cm, self.z, self.z/c_light) gv = HepMC.GenVertex(pos) ROOT.SetOwnership(gv, False) diff --git a/Generators/GenieReader/python/GenieReaderAlg.py b/Generators/GenieReader/python/GenieReaderAlg.py index c97ea494..373fa709 100644 --- a/Generators/GenieReader/python/GenieReaderAlg.py +++ b/Generators/GenieReader/python/GenieReaderAlg.py @@ -3,7 +3,8 @@ 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 +from AthenaCommon.SystemOfUnits import GeV, m, nanosecond +from AthenaCommon.PhysicalConstants import c_light import ROOT __author__ = "Dave Caser <dcasper@uci.edu>" @@ -37,7 +38,8 @@ class GenieReader(EvgenAlg): ROOT.SetOwnership(mcEventId, False) ROOT.SetOwnership(mcEventInfo, False) - pos = HepMC.FourVector(self.evtStore["vx"]*m, self.evtStore["vy"]*m, self.evtStore["vz"]*m, 0) + # 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)) 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 9126b607..b53848c0 100644 --- a/Generators/ParticleGun/python/samplers.py +++ b/Generators/ParticleGun/python/samplers.py @@ -2,6 +2,7 @@ import ROOT, math, random from ParticleGun.histsampling import TH1,TH2 +from AthenaCommon.PhysicalConstants import c_light ## For convenience PI = math.pi @@ -309,11 +310,12 @@ class PosSampler(Sampler): Sampler of position 3-vectors, for modelling a beamspot. """ - def __init__(self, x, y, z, t=0): + def __init__(self, x, y, z, t=0, axialTiming = False): self.x = x self.y = y self.z = z self.t = t + self.axialTiming = axialTiming @property def x(self): @@ -352,6 +354,9 @@ class PosSampler(Sampler): y = self.y() z = self.z() t = self.t() + if self.axialTiming: + t += z/c_light + #print "POS =", x, y, z, t return ROOT.TLorentzVector(x, y, z, t) -- GitLab