From 12462d62436232d91c18346991b0cd67f53f2651 Mon Sep 17 00:00:00 2001 From: Nicholas Kamp Date: Tue, 5 Mar 2024 00:51:25 -0500 Subject: [PATCH] Fix PDGID comparison issues in both primary type comparison and target type comparisons when in the p-elastic regime for DarkNews --- python/LIController.py | 6 ++++-- python/LIDarkNews.py | 12 +++++++----- resources/Examples/Example1/DIS_ATLAS.py | 2 +- resources/Examples/Example1/DIS_DUNE.py | 2 +- resources/Examples/Example1/DIS_IceCube.py | 5 +---- resources/Examples/Example2/DipolePortal_CCM.py | 2 +- .../Examples/Example2/DipolePortal_MINERvA.py | 17 +++++++++++------ .../Examples/Example2/DipolePortal_MiniBooNE.py | 4 ++-- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/python/LIController.py b/python/LIController.py index aa823f5e..43b901bf 100644 --- a/python/LIController.py +++ b/python/LIController.py @@ -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 @@ -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) diff --git a/python/LIDarkNews.py b/python/LIDarkNews.py index 9628115f..dad567aa 100644 --- a/python/LIDarkNews.py +++ b/python/LIDarkNews.py @@ -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]) @@ -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) diff --git a/resources/Examples/Example1/DIS_ATLAS.py b/resources/Examples/Example1/DIS_ATLAS.py index 9a59c1f5..c4bde57f 100644 --- a/resources/Examples/Example1/DIS_ATLAS.py +++ b/resources/Examples/Example1/DIS_ATLAS.py @@ -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" diff --git a/resources/Examples/Example1/DIS_DUNE.py b/resources/Examples/Example1/DIS_DUNE.py index 2a52eb5c..7fb7bc41 100644 --- a/resources/Examples/Example1/DIS_DUNE.py +++ b/resources/Examples/Example1/DIS_DUNE.py @@ -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" diff --git a/resources/Examples/Example1/DIS_IceCube.py b/resources/Examples/Example1/DIS_IceCube.py index fca5c3a2..1710b279 100644 --- a/resources/Examples/Example1/DIS_IceCube.py +++ b/resources/Examples/Example1/DIS_IceCube.py @@ -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" diff --git a/resources/Examples/Example2/DipolePortal_CCM.py b/resources/Examples/Example2/DipolePortal_CCM.py index 6b169de1..1167cdb4 100644 --- a/resources/Examples/Example2/DipolePortal_CCM.py +++ b/resources/Examples/Example2/DipolePortal_CCM.py @@ -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 diff --git a/resources/Examples/Example2/DipolePortal_MINERvA.py b/resources/Examples/Example2/DipolePortal_MINERvA.py index fcc5e38b..26dc9933 100644 --- a/resources/Examples/Example2/DipolePortal_MINERvA.py +++ b/resources/Examples/Example2/DipolePortal_MINERvA.py @@ -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, @@ -22,7 +22,7 @@ } # Number of events to inject -events_to_inject = 1000 +events_to_inject = 10000 # Expeirment to run experiment = "MINERvA" @@ -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 = {} @@ -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 @@ -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 ) diff --git a/resources/Examples/Example2/DipolePortal_MiniBooNE.py b/resources/Examples/Example2/DipolePortal_MiniBooNE.py index b7dbd374..ec7292bb 100644 --- a/resources/Examples/Example2/DipolePortal_MiniBooNE.py +++ b/resources/Examples/Example2/DipolePortal_MiniBooNE.py @@ -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, @@ -22,7 +22,7 @@ } # Number of events to inject -events_to_inject = 1000 +events_to_inject = 10000 # Expeirment to run experiment = "MiniBooNE"