@@ -69,11 +69,11 @@ def __init__(self, events_to_inject, experiment=None, detector_model_file=None,
6969 self .materials_model_file = materials_model_file
7070 if experiment is not None :
7171 # Find the density and materials files
72- self .materials_model_file = _util .get_material_model_path (experiment )
73- self .detector_model_file = _util .get_detector_model_path (experiment )
72+ detector_dir = _util .get_detector_model_path (experiment )
73+ self .materials_model_file = os .path .join (detector_dir , "materials.dat" )
74+ self .detector_model_file = os .path .join (detector_dir , "densities.dat" )
7475 elif (self .detector_model_file is None or self .materials_model_file is None ):
75- print ("Must provide either an experiment name or both a detector model file and materials model file. Exiting" )
76- exit (0 )
76+ raise ValueError ("Must provide either an experiment name or both a detector model file and materials model file" )
7777
7878 self .detector_model = _detector .DetectorModel ()
7979 self .detector_model .LoadMaterialModel (self .materials_model_file )
@@ -277,20 +277,23 @@ def InputDarkNewsModel(self, primary_type, table_dir, upscattering=True, decay=T
277277 secondary_interaction_collections = []
278278 for secondary_type , decay_list in secondary_decays .items ():
279279
280- # Define a sedcondary injection distribution if necessary
280+ # Define a secondary injection distribution if necessary
281281 inj_sec_defined = False
282282 phys_sec_defined = False
283+ existing_inj_process = None
283284 for secondary_injection_process in self .secondary_injection_processes :
284285 if secondary_injection_process .primary_type == secondary_type :
285286 inj_sec_defined = True
287+ existing_inj_process = secondary_injection_process
286288 for secondary_physical_process in self .secondary_physical_processes :
287289 if secondary_physical_process .primary_type == secondary_type :
288290 phys_sec_defined = True
289291
290- secondary_injection_process = _injection .SecondaryInjectionProcess ()
291- secondary_physical_process = _injection .PhysicalProcess ()
292- secondary_injection_process .primary_type = secondary_type
293- secondary_physical_process .primary_type = secondary_type
292+ if inj_sec_defined :
293+ secondary_injection_process = existing_inj_process
294+ else :
295+ secondary_injection_process = _injection .SecondaryInjectionProcess ()
296+ secondary_injection_process .primary_type = secondary_type
294297
295298 # Add the secondary position distribution
296299 if fid_vol_secondary and self .fid_vol is not None :
@@ -302,8 +305,12 @@ def InputDarkNewsModel(self, primary_type, table_dir, upscattering=True, decay=T
302305 _distributions .SecondaryPhysicalVertexDistribution ()
303306 )
304307
305- if not inj_sec_defined : self .secondary_injection_processes .append (secondary_injection_process )
306- if not phys_sec_defined : self .secondary_physical_processes .append (secondary_physical_process )
308+ if not inj_sec_defined :
309+ self .secondary_injection_processes .append (secondary_injection_process )
310+ if not phys_sec_defined :
311+ secondary_physical_process = _injection .PhysicalProcess ()
312+ secondary_physical_process .primary_type = secondary_type
313+ self .secondary_physical_processes .append (secondary_physical_process )
307314
308315 secondary_interaction_collections .append (
309316 _interactions .InteractionCollection (secondary_type , decay_list )
@@ -343,9 +350,9 @@ def InputDarkNewsDecay(self, primary_type, table_dir, **kwargs):
343350 decay .dec_case .nu_parent .pdgid
344351 ):
345352 primary_decays .append (decay )
346- total_decay_width = decay .TotalDecayWidth (primary_type )
347- if total_decay_width < self .DN_min_decay_width :
348- self .DN_min_decay_width = total_decay_width
353+ total_decay_width = decay .TotalDecayWidth (primary_type )
354+ if total_decay_width > 0 and total_decay_width < self .DN_min_decay_width :
355+ self .DN_min_decay_width = total_decay_width
349356 primary_interaction_collection = _interactions .InteractionCollection (
350357 primary_type , primary_decays
351358 )
@@ -377,8 +384,7 @@ def GetFiducialVolume(self):
377384 def GetVolumePositionDistributionFromSector (self , sector_name ):
378385 geo = self .GetDetectorSectorGeometry (sector_name )
379386 if geo is None :
380- print ("Sector %s not found. Exiting" % sector_name )
381- exit (0 )
387+ raise ValueError ("Sector %s not found" % sector_name )
382388 # the position is in geometry coordinates
383389 # must update to detector coordintes
384390 det_position = self .detector_model .GeoPositionToDetPosition (_detector .GeometryPosition (geo .placement .Position ))
@@ -391,8 +397,7 @@ def GetVolumePositionDistributionFromSector(self, sector_name):
391397 sphere = _geometry .Sphere (det_placement ,geo .Radius ,geo .InnerRadius )
392398 return _distributions .SphereVolumePositionDistribution (sphere )
393399 else :
394- print ("Geometry type %s not supported for position distribution. Exiting" % str (type (geo )))
395- exit (0 )
400+ raise TypeError ("Geometry type %s not supported for position distribution" % str (type (geo )))
396401
397402 def GetDetectorModelTargets (self ):
398403 """
@@ -449,7 +454,7 @@ def SetInteractions(
449454 if self .primary_physical_process .primary_type == _dataclasses .Particle .ParticleType .unknown :
450455 self .primary_physical_process .primary_type = primary_interaction_collection .GetPrimaryType ()
451456 else :
452- assert (self .primary_injection_process .primary_type == primary_interaction_collection .GetPrimaryType ())
457+ assert (self .primary_physical_process .primary_type == primary_interaction_collection .GetPrimaryType ())
453458 if self .primary_physical_process .interactions is None :
454459 self .primary_physical_process .interactions = primary_interaction_collection
455460 else :
@@ -484,11 +489,10 @@ def SetInteractions(
484489 [sec_phys .interactions , sec_ints ])
485490 found_collection = True
486491 if not found_collection and (sec_inj .interactions is None or sec_phys .interactions is None ):
487- print (
488- "Couldn't find cross section collection for secondary particle %s; Exiting "
492+ raise RuntimeError (
493+ "Couldn't find cross section collection for secondary particle %s"
489494 % record .signature .primary_type
490495 )
491- exit (0 )
492496
493497 # set the stopping condition of the injector with a python function
494498 # must accept two arguments, assumes first is datum and the second is the index of the secondary particle
@@ -636,12 +640,16 @@ def SaveEvents(self, filename, fill_tables_at_exit=True,
636640 "parent_idx" ,
637641 "num_daughters" ]:
638642 datasets [k ].append ([])
643+ if save_int_params :
644+ datasets .setdefault ("int_params" , [])
645+ datasets ["int_params" ].append ({})
639646 # loop over interactions
640647 for id , datum in enumerate (event .tree ):
641648 if save_int_params :
642- for param_name ,param_value in datum .record .interaction_parameters .items ():
643- if ie == 0 : datasets [param_name ] = []
644- datasets [param_name ].append (param_value )
649+ for param_name , param_value in datum .record .interaction_parameters .items ():
650+ if param_name not in datasets ["int_params" ][- 1 ]:
651+ datasets ["int_params" ][- 1 ][param_name ] = []
652+ datasets ["int_params" ][- 1 ][param_name ].append (param_value )
645653 datasets ["vertex" ][- 1 ].append (np .array (datum .record .interaction_vertex ,dtype = float ))
646654 datasets ["primary_initial_position" ][- 1 ].append (np .array (datum .record .primary_initial_position ,dtype = float ))
647655
0 commit comments