Xcoll release 0.9.0
What's Changed
General
- Updated
LossMapwith a few new features and to makeinterpolation=Falsework correctly (automatic calculation of the correct length). The height normalisation in plots is now correct (though the bar width should be adapted to represent the length between two consecutive apertures). - Removed
CrystalMaterial; all are now instances ofMaterialonly (exceptRefMaterial). - Added
align_to_beam_divergencetoline.collimatorsAPI for crystal tilt alignment
Interface to FLUKA
(#78, #80, #83, #86, #120, #91, #131, #132, #138, #139, #152 by @freddieknets, @andredonadon, @luillo76)
- Prerequisite: Need a complete installation of FLUKA with its LineBuilder and FlukaIO. Then compile the interface with
xcoll.fluka.environment.compile()while providing either the source withflukaio_pathor the pre-compiled library withflukaio_lib(this needs to be done only once). For compilation, themesonpackage is needed (which can be found on conda-forge). - New elements
FlukaCollimatorandFlukaCrystalwhich work exactly like anEverestCollimatororEverestCrystalbut with FLUKA physics. An important addition is that FLUKA uses geometric definitions for its elements, calledFlukaPrototype(if it is a single body) orFlukaAssembly(if it is made from multiple bodies, like a collimator that has two jaws and sits in a cryogenic tank). In both cases, this is assigned to the collimator by itsassemblyattribute. - As the protoypes/assemblies can be quite complicated to manage, the accessors
xc.fluka.assembliesandxc.fluka.prototypesare provided to inspect all protoypes/assemblies known to Xcoll. If a FEDB (Fluka Element DataBase) is provided, it can be imported withxc.fluka.environment.import_fedb(fedb_path, verbose=False, overwrite=False). To make a custom definition, the correct files have to be generated (see https://gitlab.cern.ch/bmi/fedb/coupling/linebuilder/-/blob/master/README.md), the definition created withassm = xc.FlukaAssembly(...)orprot=xc.FlukaPrototype(...) and the generated files assigned asassm.assembly_file = filename, orprot.body_file = filename1,prot.region_file = filename2, andprot.material_file = filename3which then will copy these files to Xcoll's internal database. For easier scenarios, a FlukaCollimator can be specified without providing anassemblybut by specifyingmaterialandlength(and optionallyside`), in which case a temporary generic assembly is generated. - An prototype or assembly can be inspected with Flair using
coll.assembly.view()(orxc.fluka.assemblies['...'].view()etc), while all geometry to be tracked can be inspected after starting the engine withxc.fluka.engine.view(). - As FLUKA has its internal definition of particle masses, these might sometimes differ from Xsuite's. When the difference of the reference particle mass is too large, this can lead to an accumulation of numerical error. It is for this reason that, when starting the engine, the mass of the reference particle is temporarily overwritten (also in the line) by the FLUKA value. Hence, one should create the
xt.Particlesobject after starting the engine to avoid being out-of-sync. All FLUKA masses known to Xcoll can be inspected with xc.fluka.particle_masses. - If ever needed, the naming of particles in FLUKA can be inspected with xc.fluka.particle_names .
- Before scattering can be active, a connection to FLUKA needs to be made. This is done by starting the engine:
xcoll.fluka.engine.start(). For this, the necessary arguments are eitherelementsorlineto specify which elements are to be linked (with the additional optional argumentnamesif it is only a subset), andparticle_refto describe the beam if not already provided by theline(and in case the line has a different reference particle, this is overwritten by the engine's one and restored when the engine stops). Optional arguments include:seedto set the seed in FLUKAcwdto define a run folder (a random named one is generated by default for the logs etc)cleanto clean up connection and log filescapacityto specify the maximum number of particles transferred to FLUKA (it is the user's responsibility that this is the same as the capacity in the particles object)relative_capacityto auto-size the capacity for efficiency, based on the number of particles that hit (for protons with default physics return settings,relative_capacity=2is adequate; when all particle types are returned,relative_capacityshould be at least in the order of a few hundredsverboseto print out info during the connection setup and input file generationtimeout_secto control how long the interface will wait for a reply from the server before considering it dead (typically not needed to adapt)fortran_debug_levelto control the level of debug information that is printed out from the FLUKA server's sidetouchesto create a file with the FLUKA touches (used as input for follow-up deposition studies in pure FLUKA)prototypes_fileandinclude_filesto manually control the generation of the input file (not trivial as mistakes are difficult to spot)
- Physics settings:
return_photons,return_leptons,return_electrons,return_muons,return_tauons,return_neutrinos,return_baryons,return_protons,return_neutrons,return_other_baryons,return_mesons,return_pions,return_kaons,return_other_mesons,return_ions: Individual flags to define which particle types to return. Where possible, this also limits these particles in the FLUKA calculation itself, strongly decreasing CPU time. Sensible defaults are defined base on the reference particle.return_all,return_all_charged,return_neutral,return_none: These are modifiers that can be combined. E.g. settingreturn_none=True,return_neutral=True, andreturn_pions=True, will only return pi0s.hadron_lower_momentum_cut,photon_lower_momentum_cut,electron_lower_momentum_cut: Particles with momenta larger than these cuts will be instantly killed off in FLUKA.- All settings can be inspected with
xc.fluka.engine.physics_settings().
- Note that engine attributes can be pre-set on the engine before starting. In that case, they keep their value even after stopping the engine (within the same Python session). Otherwise, they are reset to their defaults after stopping the engine.
- FLUKA uses an input file with the geometry definitions and physics settings. This is auto-generated based on the options above, though, for full flexibility, a user-provided file can also be passed to the engine with the
input_fileargument. Note that, to ensure a certain input file is compatible for the set of elements passed to the engine, the input file has an Xcoll header (as comments) with relevant info of the elements. As it is not trivial to manually generate this header, a functionxcoll.fluka.engine.generate_input_file()is available to create the input file (including the header) based on a line or set of elements, which can then be manually adapted to the user's wishes before using this file to start the engine. It takes the same arguments asxcoll.fluka.engine.start()with the additional optional argumentfilename. - The material definition of an element is governed inside Xcoll, and the correct code to define it in FLUKA is auto-generated. If a material already exists in the built-in FLUKA databases but not in Xcoll's, there are two options:
- Define the material in Xcoll the standard way, and set the attribute
fluka_nameto the correct name (case-sensitive). This will essentially ignore the Xcoll parameters and use the material definition in FLUKA. It is the user's responsibility to make sure both definitions represent the same to avoid misunderstandings. - Use a
ReferenceMaterialwhich has no properties exceptfluka_name. This is preferred, as it is clear that no Xcoll definition is used.
- Define the material in Xcoll the standard way, and set the attribute
- See the examples for more info.
Develop Updates
- Bugfix in material: When loading from dict a material that already exists in the db (and which is equal), return the db one (to have memory identity). Also fix in generic assemblies which, if the material does not exist in FLUKA code yet, should not store the fluka_name in the assembly metadata.
- Engines no longer
os.chdirbut run deferred in cwd folders (except the creation of the FLUKA input file ,which needs to temporarily move into the run folder) - Cleaned up
Constantscode and addedstrconstants type. - Streamlined tetst to select FLUKA or Geant4 (or Everest) tests with
pytest -m flukaetc, and automatically skip if the environment is not ready/compiled. LossMap: Added stricter versioning,beam_type, and__eq__.- Updated examples:
- Engine should stop AFTER making loss map to store the correct reference particle.
- Added high-statistics examples and stored the output and plots in git.
- Update LHC example lines to have collimation metadata, and updated loss map examples.
- Added example comparing energy definition of all three scattering codes (Everest, FLUKA, Geant4).
- Created a function
deep_equalto compare two lists/arrays/dicts/objects in any nesting level (meant as an improvement online._dcts_equalin Xtrack). - Created a
PhysicsSettingsclass (always present as an attribute of the engine) to manage all physics settings cleanly. - Fix in loss map plotting; cold/warm regions were something represented wrongly.
- Fix in
BaseCollimator: allow tilts to be set to None.
New Contributors
- @andredonadon made their first contribution in #78
- @luillo76 made their first contribution in #152
Full Changelog: v0.8.0...v0.9.0