Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Allow kaon physics to be configurable at runtime by the user - #108

Merged
tomeichlersmith merged 22 commits into
trunkfrom
106-see-if-kaon-properties-can-be-configured-at-runtime
Nov 20, 2023
Merged

Allow kaon physics to be configurable at runtime by the user#108
tomeichlersmith merged 22 commits into
trunkfrom
106-see-if-kaon-properties-can-be-configured-at-runtime

Conversation

@EinarElen

@EinarElen EinarElen commented Nov 19, 2023

Copy link
Copy Markdown
Contributor

This PR adds the ability to change the kaon physics at runtime by modifying the properties of the G4KaonMinus and G4KaonPlus particle definitions rather than doing it manually in the Geant4 sources. This should significantly simplify the study of challenging kaon backgrounds, especially together with techniques like https://ldmx-software.github.io/Alternative-Photo-Nuclear-Models.html

I also add "Decay" as one of the processes registered in the ProcessMap so that you can tell that a daughter particle came from a decay.

To verify that this works, I used a configuration like the following and some checks in the SimObjects DQM code to check basic things like "if I force only one decay type, I always get daughter particles of that type" etc

from LDMX.Framework import ldmxcfg
p = ldmxcfg.Process('test')

p.maxTriesPerEvent = 1

from LDMX.SimCore import generators as gen
from LDMX.SimCore import simulator
from LDMX.SimCore import kaon_physics
mySim = simulator.simulator('kaon_test')

gun = gen.gun('kaon_gun')
gun.particle='kaon+'
gun.position = [0.,0.,0.]
gun.direction = [0.,0.,1.]
gun.energy = 0.
mySim.setDetector('ldmx-det-v14-8gev')
mySim.beamSpotSmear = [20.,80.,0.]
mySim.description = 'ECal PN Test Simulation'
mySim.generators = [gun]
mySim.kaon_parameters = kaon_physics.KaonPhysics.upKaons()
mySim.kaon_parameters.kplus_lifetime_factor = 1/10000000000000000.
mySim.kaon_parameters.kminus_lifetime_factor = 1/10000000000000000.
mySim.kaon_parameters.kplus_branching_ratios = [0., 1., 0., 0., 0., 0.]
p.sequence = [ mySim ]

##################################################################
# Below should be the same for all sim scenarios

import os
import sys

if 'LDMX_NUM_EVENTS' in os.environ:
    p.maxEvents = int(os.environ['LDMX_NUM_EVENTS'])
else:
    p.maxEvents = int(sys.argv[1])
if 'LDMX_RUN_NUMBER' in os.environ:
    p.run = int(os.environ['LDMX_RUN_NUMBER'])
else:
    p.run = 1

output_base = 'kaon_test'
if len(sys.argv) > 2:
    output_base = sys.argv[2]


p.histogramFile = f'{output_base}_hist.root'
p.outputFiles = [f'{output_base}_events.root']

import LDMX.Ecal.EcalGeometry
import LDMX.Hcal.HcalGeometry


from LDMX.DQM import dqm

p.sequence.extend([
    dqm.SimObjects()
])

This resolves #106 and part of #107

@EinarElen EinarElen linked an issue Nov 19, 2023 that may be closed by this pull request

@bryngemark bryngemark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks like a great, clear implementation of changing kaon properties. I just have the one neutral kaons comment.

Comment thread include/SimCore/KaonPhysics.h Outdated
* produced in the simulation, in particular setting their lifetime and
* branching ratios
*
* @note Only affects charged kaons, but similar changes could be added for the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right here, or in a separate class? Would it make sense to add neutrals while we're at it? If not, should we call this ChargedKaonPhysics? I'm trying to make sure future me is not confused by this and I can imagine several ways. My preference would be to deal with all kaons here if it is easy enough, and just toggle which kaons one would like to modify with a configuration parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's a good point. It won't be as "clean" with the neutral kaons since they don't have symmetric decay channels like the charged ones do but it is straight forward to do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be there now!

@bryngemark bryngemark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, thanks!

@tomeichlersmith tomeichlersmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so cool! Thank you for looking into this so quickly :) I am very excited that we can move this specialization into runtime from compile-time.

Most of my comments are just thoughts and not really necessary changes.

Comment thread include/SimCore/Event/SimParticle.h
Comment thread include/SimCore/KaonPhysics.h Outdated
Comment thread python/kaon_physics.py
Comment thread python/kaon_physics.py
@EinarElen

Copy link
Copy Markdown
Contributor Author

Ok after some minor bugs in the updated python config, I've tested and it handles all the edge cases well (e.g. BR sum > 1, BR sum << 1, negative lifetimes and whatnot) and the upKaons call works!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

See if kaon properties can be configured at runtime

3 participants