Skip to content

Commit

Permalink
Fix PDGID comparison issues in both primary type comparison and targe…
Browse files Browse the repository at this point in the history
…t type comparisons when in the p-elastic regime for DarkNews
  • Loading branch information
nickkamp1 committed Mar 5, 2024
1 parent 7498ac6 commit 12462d6
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
6 changes: 4 additions & 2 deletions python/LIController.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ def SaveEvents(self, filename, fill_tables_at_exit=True, hdf5=True, parquet=True
for ie, event in enumerate(self.events):
print("Saving Event %d/%d " % (ie, len(self.events)), end="\r")
datasets["event_weight"].append(self.weighter.EventWeight(event))
print("weight:",datasets["event_weight"][-1])
datasets["event_gen_time"].append(self.gen_times[ie])
datasets["event_global_time"].append(self.global_times[ie])
# add empty lists for each per interaction dataset
Expand All @@ -443,9 +442,12 @@ def SaveEvents(self, filename, fill_tables_at_exit=True, hdf5=True, parquet=True
datasets["primary_momentum"][-1].append(np.array(datum.record.primary_momentum, dtype=float))

if self.fid_vol is not None:
pos = _math.Vector3D(datasets["vertex"][-1][-1])
geo_pos = self.detector_model.DetPositionToGeoPosition(pos)
dir = _math.Vector3D(datasets["primary_momentum"][-1][-1][1:])
dir.normalize()
datasets["in_fiducial"][-1].append(self.fid_vol.IsInside(_math.Vector3D(datasets["vertex"][-1][-1]),dir))
geo_dir = self.detector_model.DetDirectionToGeoDirection(dir)
datasets["in_fiducial"][-1].append(self.fid_vol.IsInside(geo_pos.get(),geo_dir.get()))
else:
datasets["in_fiducial"][-1].append(False)

Expand Down
12 changes: 7 additions & 5 deletions python/LIDarkNews.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ def FillInterpolationTables(self, total=True, diff=True, factor=0.8, Emax=None):
increment_factor = 0.5*factor * self.interp_tolerance
Emin = (1.0 + self.tolerance) * self.ups_case.Ethreshold
if Emax is None:
Emax = np.max(self.total_cross_section_table[:, 0])
if (len(self.total_cross_section_table) +
len(self.differential_cross_section_table)) <=0:
return 0
Emax = max(np.max([0] + list(self.total_cross_section_table[:, 0])),
np.max([0] + list(self.differential_cross_section_table[:, 0])))
num_added_points = 0
E = Emin
E_existing_total = np.unique(self.total_cross_section_table[:, 0])
Expand Down Expand Up @@ -521,15 +525,13 @@ def GetPossibleSignaturesFromParents(self, primary_type, target_type):
if (
Particle.ParticleType(self.ups_case.nu_projectile.pdgid) == primary_type
) and (
Particle.ParticleType(self.ups_case.nuclear_target.pdgid) == target_type
(self.target_type == target_type)
):
signature = LI.dataclasses.InteractionSignature()
signature.primary_type = Particle.ParticleType(
self.ups_case.nu_projectile.pdgid
)
signature.target_type = Particle.ParticleType(
self.ups_case.nuclear_target.pdgid
)
signature.target_type = self.target_type
secondary_types = []
secondary_types.append(
Particle.ParticleType(self.ups_case.nu_upscattered.pdgid)
Expand Down
2 changes: 1 addition & 1 deletion resources/Examples/Example1/DIS_ATLAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from leptoninjector.LIController import LIController

# Number of events to inject
events_to_inject = 100000
events_to_inject = int(1e5)

# Expeirment to run
experiment = "ATLAS"
Expand Down
2 changes: 1 addition & 1 deletion resources/Examples/Example1/DIS_DUNE.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from leptoninjector.LIController import LIController

# Number of events to inject
events_to_inject = 100000
events_to_inject = int(1e5)

# Expeirment to run
experiment = "DUNEFD"
Expand Down
5 changes: 1 addition & 4 deletions resources/Examples/Example1/DIS_IceCube.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
import sys
import numpy as np
import functools

import leptoninjector as LI
from leptoninjector.LIController import LIController

# Number of events to inject
events_to_inject = int(1e3)
events_to_inject = int(1e5)

# Expeirment to run
experiment = "IceCube"
Expand Down
2 changes: 1 addition & 1 deletion resources/Examples/Example2/DipolePortal_CCM.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
lower_inj_ddist = LI.distributions.Cone(lower_dir, opening_angle)
phys_ddist = (
LI.distributions.IsotropicDirection()
) # truly we are isotropicprimary_injection_distributions['direction'] = direction_distribution
) # truly we are isotropic
primary_injection_distributions["direction"] = lower_inj_ddist
primary_physical_distributions["direction"] = phys_ddist

Expand Down
17 changes: 11 additions & 6 deletions resources/Examples/Example2/DipolePortal_MINERvA.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Define a DarkNews model
model_kwargs = {
"m4": 0.47, # 0.140,
"mu_tr_mu4": 1.25e-6, # 1e-6, # GeV^-1
"mu_tr_mu4": 2.5e-6, # 1e-6, # GeV^-1
"UD4": 0,
"Umu4": 0,
"epsilon": 0.0,
Expand All @@ -22,7 +22,7 @@
}

# Number of events to inject
events_to_inject = 1000
events_to_inject = 10000

# Expeirment to run
experiment = "MINERvA"
Expand All @@ -41,6 +41,9 @@
)
controller.InputDarkNewsModel(primary_type, table_dir, **model_kwargs, **xs_kwargs)

for xs in controller.DN_processes.cross_sections:
print(xs.GetPossibleTargets())

# Primary distributions
primary_injection_distributions = {}
primary_physical_distributions = {}
Expand All @@ -64,7 +67,8 @@
model_kwargs["m4"], controller.DN_min_decay_width, 3, 240
)
position_distribution = LI.distributions.RangePositionDistribution(
1.24, 5.0, decay_range_func, set(controller.GetDetectorModelTargets()[0])
5, 10.0, decay_range_func, set(controller.GetDetectorModelTargets()[0])
#1.24, 5.0, decay_range_func, set(controller.GetDetectorModelTargets()[0])
)
primary_injection_distributions["position"] = position_distribution

Expand All @@ -81,11 +85,12 @@ def stop(datum, i):

controller.injector.SetStoppingCondition(stop)

events = controller.GenerateEvents(fill_tables)
events = controller.GenerateEvents(fill_tables_at_exit=False)

os.makedirs("output", exist_ok=True)

controller.SaveEvents(
"output/MINERvA_Dipole_M%2.2e_mu%2.2e_example"
% (model_kwargs["m4"], model_kwargs["mu_tr_mu4"])
"output/MINERvA_Dipole_M%2.2e_mu%2.2e_example2"
% (model_kwargs["m4"], model_kwargs["mu_tr_mu4"]),
fill_tables_at_exit=True
)
4 changes: 2 additions & 2 deletions resources/Examples/Example2/DipolePortal_MiniBooNE.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Define a DarkNews model
model_kwargs = {
"m4": 0.47, # 0.140,
"mu_tr_mu4": 1.25e-6, # 1e-6, # GeV^-1
"mu_tr_mu4": 2.50e-6, # 1e-6, # GeV^-1
"UD4": 0,
"Umu4": 0,
"epsilon": 0.0,
Expand All @@ -22,7 +22,7 @@
}

# Number of events to inject
events_to_inject = 1000
events_to_inject = 10000

# Expeirment to run
experiment = "MiniBooNE"
Expand Down

0 comments on commit 12462d6

Please sign in to comment.