Mu2e / Offline

Offline software for the Mu2e experiment
Apache License 2.0
8 stars 79 forks source link

implement a StageParticle generator which is aware of heterogenous materials #1290

Closed edcallaghan closed 1 day ago

edcallaghan commented 2 weeks ago

This PR implements an event generator which is aware that materials may be composed of multiple elements, and defers the actual generation of daughters to different routines each associated with a different element. This involves the definition of both base classes defining a somewhat generic interface and concrete implementations of samplers for both i) which element is relevant for a given generator call, and ii) the spacetime coordinates of the generated daughter. To enable the use of these routines for simulating Michel electrons originating in the inner proton absorber, updates are made to the global constants listing, and approximate (read: very approximate) DIO spectra are added to the repository.

Changes to existing build rules: -EventGenerator/src/SConscript: compilation now includes from/links against GEANT4. This is to enforce a "one definition rule" connecting materials as relevant in simulation and in event the new event generators. This is described in more detail below.

Updates to existing functionality: -PhysicsParams: This interface can now be used to query the atomic radius of various elements.

New modules: -CompositeMaterialGenerator: This is the generator described above. The module contains both an art-tool which samples elements from an existing G4Material, and a map from atomic labels to art-tools which sample starting positions/times and PDG/momenta of the generated particle, respectively. At each call, an element is sampled according the configured routine, and the chosen element's tools are then called to actually define the generated particle, which is expressed as a StageParticle. That the elements for which sampling tools are defined and the elements which comprise the chosen G4Material match is verified, but this must be deferred until "runtime" to accommodate out-of-order construction, wherein the G4Materials are not actually defined when the module is initialized. The use of art-tools allows for a very flexible configuration interface --- I was really glad to discover this!

New functionality: -ElementSamplerTool: This base class defines an interface for sampling an element from a G4Material. This is another place with a deferred-initialization pattern, in which the actual access of a G4Material is deferred until the tool is actually called, to ensure that the G4Material has been defined. -AtomicVolumeSamplerTool: A concrete implementation of the above, in which elements are sampled according to their relative volumes. This is relevant to the choice of which element a muon will be atomically captured by; the volumes are computed from the estimated atomic radii, which are supplied by the GlobalConstantsService/PhysicsParams interface. -PositionSamplerTool: This base class defines an interface for sampling spacetime coordinates, given a preexisting collection of SimParticles. A more generic interface would require passing the full art::Event into this class's sampling method, which can cause subtle data corruption involving unresolved pointers into data product collections which may present in downstream modules. Access to the data products should stay at the module-level, so the tool interface can only cover up to collections of particles. This limits its use to the generation of StageParticles, and thus the sampling call returns the chosen SimParticle to be referenced by the generated StageParticle. -MuStopDecayPositionSamplerTool: A concrete implementation of the above. A single muon is chosen from the collection of SimParticles, and its position is used as the starting position of the generated StageParticle. The time coordinate is sampled exponentially according to the bound muon lifetime in the relevant atom.

New auxiliary data: -globalConstants_01.txt: The atomic numbers and radii of carbon and hydrogen, as well the lifetimes and fractions for muons bound therein, have been added. FYI, some of the earlier numbers here are referenced from 2013, and may want to be revisited. There are preexisting entries labeled IPA which are just copies of the values for carbon --- AFAIK these aren't actively used for anything, but I've left them in place nonetheless. A czarneckiCoefficient entry for carbon already existed. A value for hydrogen is ~required to cleanly make use of the existing interface, but a value for hydrogen has not been calculated (to my knowledge). There is currently no intent to make use of the associated functionality, so I've entered a value of zero, but this is admittedly not great. -ConditionsService/data/heeck_finer_binning_2016_szafron-scaled-to-{6C,1H}.tbl: Two new pretabulated spectra have been added, which are duplicates of heeck_finer_binning_2016_szafron.tbl with the abscissa (first column) scaled such that the endpoint value is that of the relevant isotope. This is a crude approximation, but allows us to simulate "a tail" for standard model decays of carbon- or hydrogen-bound muons as a first pass; they can be replaced with improved tabulations as they become needed and available.

One open question I have is this: in a few places, I found it convenient to call a GEANT4-supplied rng, e.g. G4Uniform(), as opposed to sorting through the art interface for that. I'm not expecting a yes, but is that alright?

FNALbuild commented 2 weeks ago

Hi @edcallaghan, You have proposed changes to files in these packages:

which require these tests: build.

@Mu2e/fnalbuild-users, @Mu2e/write have access to CI actions on main.

:hourglass: The following tests have been triggered for 830cbc7723aa2d62e0c474de303b33cb2a02f327: build (Build queue has 1 jobs)

About FNALbuild. Code review on Mu2e/Offline.

FNALbuild commented 2 weeks ago

:sunny: The build tests passed at 830cbc7723aa2d62e0c474de303b33cb2a02f327.

Test Result Details
test with :white_check_mark: Command did not list any other PRs to include
merge :white_check_mark: Merged 830cbc7723aa2d62e0c474de303b33cb2a02f327 at 684bac4f22a1fa29f6bfd661300432e492dccbdd
build (prof) :white_check_mark: Log file. Build time: 08 min 22 sec
ceSimReco :white_check_mark: Log file.
g4test_03MT :white_check_mark: Log file.
transportOnly :white_check_mark: Log file.
POT :white_check_mark: Log file.
g4study :white_check_mark: Log file.
cosmicSimReco :white_check_mark: Log file.
cosmicOffSpill :white_check_mark: Log file.
ceSteps :white_check_mark: Log file.
ceDigi :white_check_mark: Log file.
muDauSteps :white_check_mark: Log file.
ceMix :white_check_mark: Log file.
rootOverlaps :white_check_mark: Log file.
g4surfaceCheck :white_check_mark: Log file.
FIXME, TODO :large_orange_diamond: TODO (1) FIXME (0) in 7 files
clang-tidy :large_orange_diamond: 0 errors 184 warnings
whitespace check :white_check_mark: no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 830cbc7723aa2d62e0c474de303b33cb2a02f327 after being merged into the base branch at 684bac4f22a1fa29f6bfd661300432e492dccbdd.

For more information, please check the job page here. Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

edcallaghan commented 1 week ago

FYI, a recent commit resolves a lingering deficiency in which, e.g. static CLHEP random sampling methods were called which used a global random number engine. All the random sampling introduced in this PR now relies on an art-backed engine following the usual pattern.

edcallaghan commented 1 week ago

The recent set of pushes address two points.

The first is to update the PhysicsParams listings for carbon --- the bound muon lifetime and decay fraction were inconsistent with each other, and with the reference from which all other values are pulled.

The second is to remedy a deficiency in the implemented element-sampling functionality for the intended use case of IPA Michels --- namely that what matters for choosing which element the Michel came from is not just which atom the muon captured on, but also the different decay fractions for the different elements available (this is fairly small correction for the IPA, at ~1%). To accommodate this, some of the actual sampling functionality from AtomicVolumeSamplerTool was factored out into an intermediate base class WeightedElementSamplerTool; a new BoundMuonDecayFractionTool then subclasses that base class, and contains an AtomicVolumeSamplerTool as a member. This allows AtomicVolumeSamplerTool to offer the same original functionality, which is useful in all non-DIO contexts in which muons stop in composite materials, and BoundMuonDecayFractionSamplerTool to be used for the specific situation of DIO, without duplicating the relevant code for the relative atomic volumes. The random number engine is still propagated correctly.

brownd1978 commented 6 days ago

@FNALbuild run build test

FNALbuild commented 6 days ago

:hourglass: The following tests have been triggered for 5cf58c0874399d3a96366961680dc2c5550534a5: build (Build queue has 2 jobs)

FNALbuild commented 6 days ago

:sunny: The build tests passed at 5cf58c0874399d3a96366961680dc2c5550534a5.

Test Result Details
test with :white_check_mark: Command did not list any other PRs to include
merge :white_check_mark: Merged 5cf58c0874399d3a96366961680dc2c5550534a5 at 53e76f78c89ed80a07ff9ab2737e82cc2d2f972e
build (prof) :white_check_mark: Log file. Build time: 04 min 11 sec
ceSimReco :white_check_mark: Log file.
g4test_03MT :white_check_mark: Log file.
transportOnly :white_check_mark: Log file.
POT :white_check_mark: Log file.
g4study :white_check_mark: Log file.
cosmicSimReco :white_check_mark: Log file.
cosmicOffSpill :white_check_mark: Log file.
ceSteps :white_check_mark: Log file.
ceDigi :white_check_mark: Log file.
muDauSteps :white_check_mark: Log file.
ceMix :white_check_mark: Log file.
rootOverlaps :white_check_mark: Log file.
g4surfaceCheck :white_check_mark: Log file.
FIXME, TODO :white_check_mark: TODO (0) FIXME (0) in 12 files
clang-tidy :large_orange_diamond: 0 errors 242 warnings
whitespace check :white_check_mark: no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 5cf58c0874399d3a96366961680dc2c5550534a5 after being merged into the base branch at 53e76f78c89ed80a07ff9ab2737e82cc2d2f972e.

For more information, please check the job page here. Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

FNALbuild commented 3 days ago

:memo: The HEAD of main has changed to 00eababd9df0cc26380872bebfb9e596f52076f6. Tests are now out of date.

brownd1978 commented 1 day ago

@FNALbuild run build test

FNALbuild commented 1 day ago

:hourglass: The following tests have been triggered for 5cf58c0874399d3a96366961680dc2c5550534a5: build (Build queue has 1 jobs)

FNALbuild commented 1 day ago

:sunny: The build tests passed at 5cf58c0874399d3a96366961680dc2c5550534a5.

Test Result Details
test with :white_check_mark: Command did not list any other PRs to include
merge :white_check_mark: Merged 5cf58c0874399d3a96366961680dc2c5550534a5 at 2d7b0cb9d5263d677a87b31232b433d1f1a26a9f
build (prof) :white_check_mark: Log file. Build time: 04 min 12 sec
ceSimReco :white_check_mark: Log file.
g4test_03MT :white_check_mark: Log file.
transportOnly :white_check_mark: Log file.
POT :white_check_mark: Log file.
g4study :white_check_mark: Log file.
cosmicSimReco :white_check_mark: Log file.
cosmicOffSpill :white_check_mark: Log file.
ceSteps :white_check_mark: Log file.
ceDigi :white_check_mark: Log file.
muDauSteps :white_check_mark: Log file.
ceMix :white_check_mark: Log file.
rootOverlaps :white_check_mark: Log file.
g4surfaceCheck :white_check_mark: Log file.
FIXME, TODO :white_check_mark: TODO (0) FIXME (0) in 12 files
clang-tidy :large_orange_diamond: 0 errors 242 warnings
whitespace check :white_check_mark: no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 5cf58c0874399d3a96366961680dc2c5550534a5 after being merged into the base branch at 2d7b0cb9d5263d677a87b31232b433d1f1a26a9f.

For more information, please check the job page here. Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.