Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 17 commits into from
Jul 11, 2024

Conversation

edcallaghan
Copy link
Contributor

@edcallaghan edcallaghan commented Jun 24, 2024

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?

…aterials:

  - define base classes for sampling elements from a composite material and coordinates of (pre)stopped particles
  - implement the above in the form of sampling elements via their atomic volume, and coordinates via randomly choosing one negative muon
  - add in approximate DIO spectra for carbon and hydrogen by scaling the energy coordinate of the calculated aluminum spectrum
@FNALbuild
Copy link
Collaborator

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

  • ConditionsService
  • EventGenerator
  • GlobalConstantsService
  • Trigger

which require these tests: build.

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

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

About FNALbuild. Code review on Mu2e/Offline.

@edcallaghan edcallaghan changed the title implement a StagedParticle generator which is aware of heterogenous materials implement a StageParticle generator which is aware of heterogenous materials Jun 24, 2024
@FNALbuild
Copy link
Collaborator

☀️ The build tests passed at 830cbc7.

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

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

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.

Copy link
Collaborator

@brownd1978 brownd1978 left a comment

Choose a reason for hiding this comment

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

This PR adds important new capability for capture on heterogenous materials, directly relevant for several applications. A presentation on the physics inputs underlying this is needed, for instance the assumptions behind using the Heeck spectrum outside of aluminum, and why atomic radius is the right scaling for relative capture rates. I have a few minor technical questions as well, but basically this looks really good.

@brownd1978 brownd1978 self-assigned this Jun 26, 2024
@brownd1978 brownd1978 requested a review from sdifalco June 26, 2024 19:58
#include <vector>

// art
#include <art/Framework/Principal/Event.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about < vs " as in the other PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -13,6 +13,8 @@ helper=mu2e_helper(env);

cryinc = os.environ['CRYHOME'] + '/src'
crylib = os.environ['CRY_LIB']
g4inc = os.environ['G4INCLUDE']
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to keep all references to G4 within Mu2eG4. The motivation is to be able to make G4-free builds which are required by the trigger. We eventually want to get to MC-free builds but we are not there yet.

One generator module is already in G4 for this reason:

Mu2eG4/src/GammaConvGenerator_module.cc

Please look into what that would require for this PR.

Maybe it's time to make a new top level directory for event generators that depend on G4.?

Copy link
Contributor Author

@edcallaghan edcallaghan Jun 27, 2024

Choose a reason for hiding this comment

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

The fundamental "problem" is that materials are defined via hard-codes in Mu2e/src/ConstructMaterials.cc, so that interfacing with G4 is the only way to query what they are comprised of. If there were a Mu2e-owned Service/interface which maintained a table of configurable materials and their compositions, which G4 queried when constructing G4Materials, then that would provide the functionality I'm looking for and simplify that construction routine (and also, presumably, obviate the delayed-initialization tricks I've had to use here).

But I imagine that there is a reason that things are done the way they are (and, if not, implementing the kind of ting I'm imagining is a separate project). In that case, I don't particularly care whether the generator lives under EventGenerator/, Mu2eG4/, or somewhere new. Unless there is some subtly in crossing project boundaries that I'm not aware of, just moving it into Mu2eG4 would probably satisfy the separation you'd like.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please move it into Mu2eG4 and revert the changes to EventGenerator/src/SConscript.

Implementing a complete parallel materials system seemed like far too much work for something that would never be used except to feed G4. And we did not have a use case to drive making a simplified materials system. It's only been in the past year or so that we have had a use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok --- CompositeMaterialGenerator, ElementSamplerTool, and AtomicVolumeSamplerTool, which depend directly or indirectly on G4, now live under Mu2eG4, and the uses of G4 libraries or Mu2eG4 in EventGenerator/src/SConscript have been removed. PositionSamplerTool and MuStopPositionSamplerTool, which do not depend on G4, still live under EventGenerator.

Copy link
Contributor

@kutschke kutschke left a comment

Choose a reason for hiding this comment

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

See inline comments.

@edcallaghan
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Collaborator

@FNALbuild run build test

@FNALbuild
Copy link
Collaborator

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

@FNALbuild
Copy link
Collaborator

☀️ The build tests passed at 5cf58c0.

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

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

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
Copy link
Collaborator

📝 The HEAD of main has changed to 00eabab. Tests are now out of date.

Copy link
Contributor

@kutschke kutschke left a comment

Choose a reason for hiding this comment

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

Thanks for updating the use of random engines and distributions to conform with our standards. And thanks for responding to the other requests.

It good to go.

@brownd1978
Copy link
Collaborator

@FNALbuild run build test

@FNALbuild
Copy link
Collaborator

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

@FNALbuild
Copy link
Collaborator

☀️ The build tests passed at 5cf58c0.

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

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

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.

@brownd1978 brownd1978 merged commit 8ab0f62 into Mu2e:main Jul 11, 2024
14 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants