Skip to content
Snippets Groups Projects
Commit 5c1f38f5 authored by Eric Torrence's avatar Eric Torrence
Browse files

Merge branch 'mcgen' into 'master'

Add DIF to MC production scripts

See merge request !325
parents a6a3a924 e4f00107
No related branches found
No related tags found
1 merge request!325Add DIF to MC production scripts
Pipeline #5030705 passed
...@@ -47,6 +47,12 @@ def faser_pgparser(): ...@@ -47,6 +47,12 @@ def faser_pgparser():
parser.add_argument("--zpos", default=None, type=float, parser.add_argument("--zpos", default=None, type=float,
help="Specify z position of particles (in mm) (helpful to avoid FASERnu)") help="Specify z position of particles (in mm) (helpful to avoid FASERnu)")
parser.add_argument("--pidd1", default=None, type=int,
help="Specify PDG ID of daugther 1 for DIF generator")
parser.add_argument("--pidd2", default=None, type=int,
help="Specify PDG ID of daugther 2 for DIF generator")
parser.add_argument("--sampler", default="log", parser.add_argument("--sampler", default="log",
help="Specify energy sampling (log, lin, const, hist, hist2D)") help="Specify energy sampling (log, lin, const, hist, hist2D)")
parser.add_argument("--hist_name", default="log", parser.add_argument("--hist_name", default="log",
......
...@@ -101,8 +101,11 @@ if __name__ == '__main__': ...@@ -101,8 +101,11 @@ if __name__ == '__main__':
from AthenaCommon.PhysicalConstants import pi from AthenaCommon.PhysicalConstants import pi
if isinstance(args.pid, list): if isinstance(args.pid, list):
# Note args.pid is a list, must make this a set for ParticleGun # Note args.pid is a list, must make this a set for ParticleGun if have > 1
pidarg = set(args.pid) if len(args.pid) > 1:
pidarg = set(args.pid)
else:
pidarg = args.pid[0]
else: else:
# Just pass a single value # Just pass a single value
pidarg = args.pid pidarg = args.pid
...@@ -112,13 +115,32 @@ if __name__ == '__main__': ...@@ -112,13 +115,32 @@ if __name__ == '__main__':
# Create the simgun dictionary # Create the simgun dictionary
# Negative radius gives uniform sampling # Negative radius gives uniform sampling
# Positive radius gives Gaussian sampling # Positive radius gives Gaussian sampling
sg_dict = {
"Generator" : "SingleParticle", if args.pidd1:
"pid" : pidarg, "mass" : args.mass, if args.pidd2 is None:
"theta" : PG.GaussianSampler(0, args.angle, oneside = True), args.pidd2 = -args.pidd1
"phi" : [0, 2*pi], "radius" : args.radius,
"randomSeed" : args.outfile sg_dict = {
} "Generator" : "DecayInFlight",
"mother_pid" : pidarg,
"daughter1_pid" : args.pidd1,
"daughter2_pid" : args.pidd2,
"mass" : args.mass,
"theta" : PG.GaussianSampler(0, args.angle, oneside = True) if args.angle is not None and args.angle != "None" else None,
"phi" : [0, 2*pi], "radius" : args.radius,
"randomSeed" : args.outfile
}
else:
sg_dict = {
"Generator" : "SingleParticle",
"pid" : pidarg, "mass" : args.mass,
"theta" : PG.GaussianSampler(0, args.angle, oneside = True) if args.angle is not None and args.angle != "None" else None,
"phi" : [0, 2*pi], "radius" : args.radius,
"randomSeed" : args.outfile
}
# -1000 is safely upstream of detector (to be checked) # -1000 is safely upstream of detector (to be checked)
# Note zpos is in mm! # Note zpos is in mm!
...@@ -132,6 +154,12 @@ if __name__ == '__main__': ...@@ -132,6 +154,12 @@ if __name__ == '__main__':
sg_dict["energy"] = PG.LogSampler(args.minE*GeV, args.maxE*GeV) sg_dict["energy"] = PG.LogSampler(args.minE*GeV, args.maxE*GeV)
elif args.sampler == "const": elif args.sampler == "const":
sg_dict["energy"] = PG.ConstSampler(args.maxE*GeV) sg_dict["energy"] = PG.ConstSampler(args.maxE*GeV)
elif args.sampler == "hist":
fname, hname = args.hist_name.split(":")
sg_dict["energy"] = PG.TH1Sampler(fname, hname)
elif args.sampler == "hist2D":
fname, hname = args.hist_name.split(":")
sg_dict["energy"] = PG.TH2Sampler(fname, hname)
else: else:
print(f"Sampler {args.sampler} not known!") print(f"Sampler {args.sampler} not known!")
sys.exit(1) sys.exit(1)
......
...@@ -93,9 +93,8 @@ class DIFSampler(PG.ParticleSampler): ...@@ -93,9 +93,8 @@ class DIFSampler(PG.ParticleSampler):
# def __init__(self, daughter1_pid = 11, daughter2_pid = -11, mother_pid = None, mother_mom = PG.EThetaMPhiSampler(sqrt((1*TeV)**2 + (10*MeV)**2),0,10*MeV,0),mother_pos = CylinderSampler([0, 100**2],[0, 2*pi],[-1500, 0],0)): # def __init__(self, daughter1_pid = 11, daughter2_pid = -11, mother_pid = None, mother_mom = PG.EThetaMPhiSampler(sqrt((1*TeV)**2 + (10*MeV)**2),0,10*MeV,0),mother_pos = CylinderSampler([0, 100**2],[0, 2*pi],[-1500, 0],0)):
def __init__(self, daughter1_pid=13, daughter2_pid=-13, mother_pid=None, def __init__(self, daughter1_pid=13, daughter2_pid=-13, mother_pid=None,
mother_mom=PG.EThetaMPhiSampler(sqrt((1*TeV)**2 + (500*MeV)**2), [0, 0.0002], 500*MeV, [0, 2*pi]), mother_mom=PG.EThetaMPhiSampler(sqrt((1*TeV)**2 + (500*MeV)**2), [0, 0.0002], 500*MeV, [0, 2*pi]),
my_z_position=-1500): mother_pos=CylinderSampler([0, 100**2], [0, 2*pi], [-1500, 0], 0)):
# mother_pos=CylinderSampler([0, 100**2], [0, 2*pi], [-1500, 0], 0)): self._mother_sampler = PG.ParticleSampler(pid = mother_pid, mom = mother_mom, pos=mother_pos)
self._mother_sampler = PG.ParticleSampler(pid = mother_pid, mom = mother_mom, pos=CylinderSampler([0, 100**2], [0, 2*pi], my_z_position, 0))
self.daughter1 = self.particle(daughter1_pid) self.daughter1 = self.particle(daughter1_pid)
self.daughter2 = self.particle(daughter2_pid) self.daughter2 = self.particle(daughter2_pid)
......
...@@ -9,7 +9,7 @@ import ParticleGun as PG ...@@ -9,7 +9,7 @@ import ParticleGun as PG
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaConfiguration.ComponentFactory import CompFactory from AthenaConfiguration.ComponentFactory import CompFactory
# from AthenaCommon.Constants import VERBOSE, INFO # from AthenaCommon.Constants import VERBOSE, INFO
from AthenaCommon.SystemOfUnits import TeV from AthenaCommon.SystemOfUnits import TeV, GeV, MeV
from AthenaCommon.PhysicalConstants import pi from AthenaCommon.PhysicalConstants import pi
### add radial pos sampler ### with gaussian beam implemented ### add radial pos sampler ### with gaussian beam implemented
...@@ -144,7 +144,31 @@ def FaserParticleGunDecayInFlightCfg(ConfigFlags, **kwargs) : ...@@ -144,7 +144,31 @@ def FaserParticleGunDecayInFlightCfg(ConfigFlags, **kwargs) :
pg = cfg.getPrimary() pg = cfg.getPrimary()
from DIFGenerator import DIFSampler from DIFGenerator import DIFSampler
pg.sampler = DIFSampler(**kwargs)
if "radius" in kwargs:
kwargs["mother_pos"] = RadialPosSampler(x = kwargs.setdefault("x", 0.0),
y = kwargs.setdefault("y", 0.0),
z = kwargs.setdefault("z", -3750.0),
r = kwargs.setdefault("radius", 1.0),
t = kwargs.setdefault("t", 0.0) )
else:
from DIFGenerator.DIFSampler import CylinderSampler
kwargs["mother_pos"] = CylinderSampler([0, 100**2], [0, 2*pi], [-1500, 0], 0)
if not "mother_mom" in kwargs:
kwargs["mother_mom"] = PG.EThetaMPhiSampler(kwargs.setdefault("energy", ((1*TeV)**2 + (500*MeV)**2)**0.5),
kwargs.setdefault("theta", [0, 0.0002]),
kwargs.setdefault("mass", 500*MeV),
kwargs.setdefault("phi", [0, 2*pi]) )
pg.sampler = DIFSampler(kwargs.setdefault("daughter1_pid", 13),
kwargs.setdefault("daughter2_pid", -13),
kwargs.setdefault("mother_pid", None),
kwargs["mother_mom"],
kwargs["mother_pos"] )
return cfg return cfg
...@@ -190,9 +214,12 @@ def FaserParticleGunForeseeCfg(ConfigFlags, **kwargs) : ...@@ -190,9 +214,12 @@ def FaserParticleGunForeseeCfg(ConfigFlags, **kwargs) :
return cfg return cfg
def FaserParticleGunCfg(ConfigFlags) : def FaserParticleGunCfg(ConfigFlags) :
# generator = ConfigFlags.Sim.Gun.setdefault("Generator", "SingleParticle") generator = ConfigFlags.Sim.Gun.setdefault("Generator", "SingleParticle")
generator = ConfigFlags.Sim.Gun.setdefault("Generator", "DecayInFlight") # generator = ConfigFlags.Sim.Gun.setdefault("Generator", "DecayInFlight")
kwargs = ConfigFlags.Sim.Gun kwargs = ConfigFlags.Sim.Gun
del kwargs["Generator"]
if generator == "SingleEcalParticle" : if generator == "SingleEcalParticle" :
return FaserParticleGunSingleEcalParticleCfg(ConfigFlags, **kwargs) return FaserParticleGunSingleEcalParticleCfg(ConfigFlags, **kwargs)
elif generator == "Cosmics" : elif generator == "Cosmics" :
......
...@@ -47,13 +47,13 @@ class ForeseeGenerator(object): ...@@ -47,13 +47,13 @@ class ForeseeGenerator(object):
else: else:
self.foresee = Foresee(path = self.path) self.foresee = Foresee(path = self.path)
# Generate 6 cm high to account for translation from ATLAS to FASER coord. system # Generate 6.5 cm high to account for translation from ATLAS to FASER coord. system
# TODO: relax this a bit as daughters may enter even if mother doesn't # TODO: relax this a bit as daughters may enter even if mother doesn't
# self.foresee.set_detector(selection="np.sqrt(x.x**2 + x.y**2)< 0.1", # self.foresee.set_detector(selection="np.sqrt(x.x**2 + x.y**2)< 0.1",
# channels=[self.mode], distance=480, length=1.5 , # channels=[self.mode], distance=480, length=1.5 ,
# luminosity=1/1000.) # 1 pb-1 # luminosity=1/1000.) # 1 pb-1
self.foresee.set_detector(selection="np.sqrt(x.x**2 + (x.y - 0.06)**2)< 0.1", self.foresee.set_detector(selection="np.sqrt(x.x**2 + (x.y - 0.065)**2)< 0.1",
channels=[self.mode], distance=480, length=1.5 , channels=[self.mode], distance=480, length=1.5 ,
luminosity=1/1000.) # 1 pb-1 luminosity=1/1000.) # 1 pb-1
......
import json import json
import subprocess as proc import subprocess as proc
import os from glob import glob
import os, sys
grid = "../calypso/Generators/ForeseeGenerator/share/points.json" grid = "../calypso/Generators/ForeseeGenerator/share/points.json"
with open(grid) as f: with open(grid) as f:
data = json.load(f) data = json.load(f)
name = "DarkPhotonGrid13p6" name = "DarkPhotonGrid13p6_65mm"
path = f"/bundle/data/FASER/Carl_Output/Foresee/{name}/" path = f"/bundle/data/FASER/Carl_Output/Foresee/{name}/"
ecom = 13.6 ecom = 13.6
pid1 = 11 pid1 = 11
...@@ -15,7 +16,12 @@ pid2 = -11 ...@@ -15,7 +16,12 @@ pid2 = -11
for coup, masses in data["samples"].items(): for coup, masses in data["samples"].items():
for m in masses: for m in masses:
infile = f"{path}events_{ecom}TeV_m{m}GeV_c{float(coup):.1e}to_{pid1}_{pid2}_{name}.hepmc" files = glob(f"{path}events_{ecom}TeV_m{m}GeV_c{float(coup):.1e}to_{pid1}_{pid2}_{name}*.hepmc")
if len(files) != 1:
continue
infile = files[0]
outfile = infile.replace(".hepmc", ".EVNT.pool.root") outfile = infile.replace(".hepmc", ".EVNT.pool.root")
valfile = infile.replace(".hepmc", ".VAL.pool.root") valfile = infile.replace(".hepmc", ".VAL.pool.root")
valdir = infile.replace(".hepmc", "") valdir = infile.replace(".hepmc", "")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment