Skip to content

Commit

Permalink
add examples and move loggers after imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostert committed Oct 27, 2024
1 parent 1dd0e39 commit 6585443
Show file tree
Hide file tree
Showing 15 changed files with 1,355 additions and 1,108 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ jobs:
pip install tox tox-gh-actions
- name: Test generator and physics output
run: tox
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
# - name: Generate Report
# run: |
# pip install coverage
# coverage run -m pytest
# - name: Setup tmate session
# if: success() || failure()
# uses: mxschmitt/action-tmate@v3
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.2.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml # Specify your coverage file location if needed
flags: unittests # Optional: Helps to tag results for more detail
fail_ci_if_error: false # Optional: Don't fail the CI if Codecov fails
9 changes: 2 additions & 7 deletions examples/Example_0_start_here.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.12 ('base')",
"display_name": "darknews",
"language": "python",
"name": "python3"
},
Expand All @@ -547,12 +547,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"vscode": {
"interpreter": {
"hash": "3067ead486e059ec00ffe7555bdb889e6e264a24dc711bf108106cc7baee8d5d"
}
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
667 changes: 0 additions & 667 deletions examples/Example_1_total_xsecs.ipynb

This file was deleted.

732 changes: 732 additions & 0 deletions examples/Example_1_xsecs.ipynb

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions examples/Example_2_decays.ipynb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
386 changes: 0 additions & 386 deletions examples/Example_5_MB_spectra.ipynb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id": "chinese-isaac",
"metadata": {},
"source": [
"# Example 4\n",
"# Example 1 (FastBNB)\n",
"\n",
"This notebook shows predictions for nueCCQE-like events at MiniBooNE using the \"fastbnb\" module -- installed separately from:\n",
"\n",
Expand All @@ -17,18 +17,27 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"id": "compact-danger",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 7,
"id": "professional-latitude",
"metadata": {},
"outputs": [],
Expand All @@ -50,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 8,
"id": "a54bb01c",
"metadata": {},
"outputs": [],
Expand All @@ -70,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 9,
"id": "5becc5d3",
"metadata": {},
"outputs": [],
Expand All @@ -80,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 10,
"id": "fc5e1894",
"metadata": {},
"outputs": [
Expand Down
386 changes: 386 additions & 0 deletions examples/FastBNB_example_2_MB_spectra.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="1" tests="15" time="78.531" timestamp="2024-10-03T17:30:46.438716-05:00" hostname="matheuss-mbp-2.guest-network.net"><testcase classname="tests.test_inputs" name="test_ModelContainer_default" file="tests/test_inputs.py" line="12" time="0.023" /><testcase classname="tests.test_inputs" name="test_input_parameter_files" file="tests/test_inputs.py" line="27" time="0.036" /><testcase classname="tests.test_inputs" name="test_argparse" file="tests/test_inputs.py" line="35" time="0.075" /><testcase classname="tests.test_physics" name="test_MB_benchmarks" file="tests/test_physics.py" line="19" time="1.398" /><testcase classname="tests.test_physics" name="test_MB_SM" file="tests/test_physics.py" line="37" time="0.452" /><testcase classname="tests.test_physics" name="test_MB_other_final_states" file="tests/test_physics.py" line="43" time="1.841" /><testcase classname="tests.test_physics" name="test_MB_generic_model" file="tests/test_physics.py" line="73" time="10.180" /><testcase classname="tests.test_physics" name="test_MB_dirt" file="tests/test_physics.py" line="91" time="2.592" /><testcase classname="tests.test_physics" name="test_portal_vs_simplified" file="tests/test_physics.py" line="113" time="0.936" /><testcase classname="tests.test_physics" name="test_xsecs" file="tests/test_physics.py" line="122" time="3.096" /><testcase classname="tests.test_physics" name="test_geometries" file="tests/test_physics.py" line="219" time="0.487" /><testcase classname="tests.test_readoutputs" name="test_output" file="tests/test_readoutputs.py" line="11" time="21.431" /><testcase classname="tests.test_scripts" name="test_dn_gen" file="tests/test_scripts.py" line="9" time="29.702" /><testcase classname="tests.test_scripts" name="test_python_call_to_dngen" file="tests/test_scripts.py" line="28" time="6.217" /><testcase classname="tests.test_scripts" name="test_examples_download" file="tests/test_scripts.py" line="33" time="0.003"><skipped type="pytest.skip" message="Still need to find a way to set up git for venvs">/Users/mhostert/Repos/DarkNews-generator/tests/test_scripts.py:34: Still need to find a way to set up git for venvs</skipped></testcase></testsuite></testsuites>
2 changes: 2 additions & 0 deletions src/DarkNews/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
rad_to_deg = 180.0 / np.pi
deg_to_rad = 1 / rad_to_deg

s_in_year = 60 * 60 * 24 * 365.25

invGeV_to_cm = hb * c_LIGHT # hbar c = 197.3269804e-16 GeV.cm
invGeV2_to_cm2 = invGeV_to_cm**2

Expand Down
32 changes: 17 additions & 15 deletions src/DarkNews/model.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import numpy as np
import math

import logging

logger = logging.getLogger("logger." + __name__)
prettyprinter = logging.getLogger("prettyprinter." + __name__)

from particle import literals as lp

from DarkNews import const
from DarkNews import pdg

import logging

logger = logging.getLogger("logger." + __name__)
prettyprinter = logging.getLogger("prettyprinter." + __name__)


class HNLModel:
def __init__(self, model_file=None, **user_input):
Expand Down Expand Up @@ -413,35 +413,37 @@ def set_vertices(self):
# self.tanof2beta = const.sw * self.sinof2chi / (entry_22)

# Mass mixing and kinetic mixing
entry_11 = const.sw * self.sinof2chi + 2 * self.epsilonZ * np.sqrt(self.c2chi)
entry_22 = self.c2chi - const.s2w * self.s2chi - (self.mzprime / const.m_Z) ** 2 - 2 * self.epsilonZ * const.sw * np.sqrt(self.s2chi)
self.tanof2beta = entry_11 / entry_22
self._entry_11 = const.sw * self.sinof2chi + 2 * self.epsilonZ * np.sqrt(self.c2chi)
self._entry_22 = self.c2chi - const.s2w * self.s2chi - (self.mzprime / const.m_Z) ** 2 - 2 * self.epsilonZ * const.sw * np.sqrt(self.s2chi)
self.tanof2beta = self._entry_11 / self._entry_22

# self.beta = const.sw * self.chi
self.sinof2beta = entry_11 / np.sqrt(entry_22**2 + entry_11**2)
self.cosof2beta = entry_22 / np.sqrt(entry_22**2 + entry_11**2)
self.sinof2beta = self._entry_11 / np.sqrt(self._entry_22**2 + self._entry_11**2)
self.cosof2beta = self._entry_22 / np.sqrt(self._entry_22**2 + self._entry_11**2)

# #####################
if self.tanof2beta != 0:
self.tbeta = self.sinof2beta / (1 + self.cosof2beta)
self.cbeta = math.sqrt((1 + self.cosof2beta) / 2.0) # FIX ME -- works only for |beta| < pi/2
self.sbeta = math.sqrt(1 - self.cbeta**2) # FIX ME -- works only for |beta| < pi/2
else:
self.tbeta = 0.0

self.sbeta = math.sqrt((1 - self.cosof2beta) / 2.0) * np.sign(self.sinof2beta) # FIX ME -- works only for |beta| < pi/2
self.cbeta = math.sqrt((1 + self.cosof2beta) / 2.0) # FIX ME -- works only for |beta| < pi/2
self.cbeta = 1.0
self.sbeta = 0.0

# some abbreviations
self._weak_vertex = const.gweak / const.cw / 2.0
self._gschi = self.gD * self.sbeta

# dark couplings acquired by Z boson
self._g_weak_correction = self.cbeta + self.tanchi * const.sw * self.sbeta
self._g_dark_correction = self.cbeta * self.tanchi * const.sw - self.sbeta

# Charged leptons
self.ceV = self._weak_vertex * (self.cbeta * (2 * const.s2w - 0.5) + 3.0 / 2.0 * self.sbeta * const.sw * self.tanchi)
self.ceA = self._weak_vertex * (-(self.cbeta + self.sbeta * const.sw * self.tanchi) / 2.0)
# self.ceV = weak_vertex*(const.gweak/(2*const.cw) * (2*const.s2w - 0.5))
# self.ceA = weak_vertex*(const.gweak/(2*const.cw) * (-1.0/2.0))
# self.ceV = self._weak_vertex * (const.gweak / (2 * const.cw) * (2 * const.s2w - 0.5))
# self.ceA = self._weak_vertex * (const.gweak / (2 * const.cw) * (-1.0 / 2.0))

# quarks
self.cuV = self._weak_vertex * (self.cbeta * (0.5 - 4 * const.s2w / 3.0) - 5.0 / 6.0 * self.sbeta * const.sw * self.tanchi)
Expand Down
25 changes: 11 additions & 14 deletions src/DarkNews/processes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import numpy as np
import vegas as vg
import json
import os

import logging

logger = logging.getLogger("logger." + __name__)

from DarkNews import const
from DarkNews import pdg
Expand All @@ -18,6 +13,10 @@

from . import Cfourvec as Cfv

import logging

logger = logging.getLogger("logger." + __name__)


class UpscatteringProcess:
def __init__(self, nu_projectile, nu_upscattered, nuclear_target, scattering_regime, TheoryModel, helicity):
Expand Down Expand Up @@ -270,14 +269,14 @@ def __init__(self, nu_parent, nu_daughter, final_lepton1, final_lepton2, TheoryM
else:
self.CC_mixing1 = 0
self.CC_mixing2 = 0
## Minus sign important for interference!
# Minus sign important for interference!
self.CC_mixing2 *= -1

if self.m_parent - self.m_daughter - self.mm - self.mp < 0:
logger.error(f"Error! Final states are above the mass of parent particle: mass excess = {self.m_parent - self.m_daughter - self.mm - self.mp}.")
raise ValueError("Energy not conserved.")

## Is the mediator on shell?
# Is the mediator on shell?
self.vector_on_shell = (
(TheoryModel.mzprime is not None) and (self.m_parent - self.m_daughter > TheoryModel.mzprime) and (TheoryModel.mzprime > self.mm + self.mp)
)
Expand All @@ -288,7 +287,7 @@ def __init__(self, nu_parent, nu_daughter, final_lepton1, final_lepton2, TheoryM
)
self.scalar_off_shell = not self.scalar_on_shell

## does it have transition magnetic moment?
# does it have transition magnetic moment?
self.TMM = TheoryModel.has_TMM

def SamplePS(
Expand Down Expand Up @@ -336,13 +335,11 @@ def total_width(self, NINT=MC.NINT, NEVAL=MC.NEVAL, NINT_warmup=MC.NINT_warmup,
logger.error("Vector and scalar simultaneously on shell is not implemented.")
raise NotImplementedError("Feature not implemented.")
elif self.vector_on_shell and self.scalar_off_shell:
return dr.gamma_Ni_to_Nj_V(vertex_ij=self.Dih, mi=self.m_parent, mj=self.m_daughter, mV=self.mzprime, HNLtype=self.HNLtype) * dr.gamma_V_to_ell_ell(
vertex=self.TheoryModel.deV, mV=self.mzprime, m_ell=self.mm
)
return dr.gamma_Ni_to_Nj_V(vertex_ij=self.Dih, mi=self.m_parent, mj=self.m_daughter, mV=self.mzprime, HNLtype=self.HNLtype)
# * dr.gamma_V_to_ell_ell(vertex=self.TheoryModel.deV, mV=self.mzprime, m_ell=self.mm)
elif self.vector_off_shell and self.scalar_on_shell:
return dr.gamma_Ni_to_Nj_S(vertex_ij=self.Sih, mi=self.m_parent, mj=self.m_daughter, mS=self.mhprime, HNLtype=self.HNLtype) * dr.gamma_S_to_ell_ell(
vertex=self.TheoryModel.deS, mS=self.mhprime, m_ell=self.mm
)
return dr.gamma_Ni_to_Nj_S(vertex_ij=self.Sih, mi=self.m_parent, mj=self.m_daughter, mS=self.mhprime, HNLtype=self.HNLtype)
# * dr.gamma_S_to_ell_ell(vertex=self.TheoryModel.deS, mS=self.mhprime, m_ell=self.mm)
elif self.vector_off_shell and self.scalar_off_shell:

# We need to integraate the differential cross section
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ setenv =
PYTHONHASHSEED = 0

commands =
pytest
# pytest --basetemp={envtmpdir} --cov={envtmpdir} --cov-append --cov-report=xml
pytest --basetemp={envtmpdir} --cov={envtmpdir} --cov-append --cov-report=xml --cov --junitxml=junit.xml -o junit_family=legacy
depends =
{py38,py39,py310,py311,py312}: clean
report: py38,py39,py310,py311,py312


[testenv:report]
deps = coverage
skip_install = true
Expand Down

0 comments on commit 6585443

Please sign in to comment.