@@ -59,82 +59,51 @@ def track(coll, particles):
5959
6060 start = time .time ()
6161
62- coll_everest = xc .EverestCollimator (length = coll .length , material = xc .materials .MolybdenumGraphite )
63- coll_everest .jaw = coll .jaw
64-
65- part_everest = particles .copy ()
66- coll_everest .track (part_everest )
67-
68- mask_hit_base = (
69- (abs (particles .px - part_everest .px ) > 1e-12 ) |
70- (abs (particles .py - part_everest .py ) > 1e-12 ) |
71- (particles .pdg_id == - 999999999 )
72- )
62+ # Checking particles that hit the collimator
63+ coll_blackabsorber = xc .BlackAbsorber (length = coll .length + coll .length_front + coll .length_back )
64+ part_blackabsorber = particles .copy ()
65+ coll_blackabsorber .track (part_blackabsorber )
7366
7467 end = time .time ()
75- print (f"Tracking Everest collimator took { end - start :.4f} seconds" )
68+ print (f"Tracking black absorber collimator took { end - start :.4f} seconds" )
7669
70+ mask_capacity = particles .pdg_id != - 999999999
7771
78- start = time .time ()
72+ # Mask for particles that hit the collimator
73+ mask_hit = ((part_blackabsorber .state != 1 ) & (particles .state == 1 )) | (particles .pdg_id == - 999999999 )
74+
75+ # Mask for particles already lost
7976 mask_lost = (particles .state != 1 ) & (particles .pdg_id != - 999999999 )
8077
8178 # Final hit mask includes both
82- mask_hit = mask_hit_base # | mask_lost
83-
84-
85- # mask_hit = ((abs(particles.px - part_everest.px) > 1e-12) | (abs(particles.py - part_everest.py) >1e-12) | (particles.pdg_id == -999999999))
86- #
87- # mask_lost = ((particles.state != 1) & (particles.pdg_id != -999999999))
88- mask_miss_no_lost = ~ ((abs (particles .px - part_everest .px ) > 1e-12 ) | (abs (particles .py - part_everest .py ) > 1e-12 )) & (particles .pdg_id != - 999999999 )
79+ mask_miss_no_lost = ~ mask_hit
8980 mask_miss = mask_miss_no_lost | mask_lost
9081
9182
9283 hit_id = particles .particle_id [mask_hit ]
93- miss_id = particles .particle_id [mask_miss ]
9484 is_hit = np .isin (particles .particle_id , hit_id )
85+ miss_id = particles .particle_id [mask_miss ]
9586 is_miss = np .isin (particles .particle_id , miss_id )
9687
97- if mask_lost .any ():
98- particles_lost = particles .filter (mask_lost )
99- else :
100- particles_lost = None
101-
10288 particles_hit = 0
10389 particles_miss = 0
10490 particles_hit = particles .filter (is_hit )
105- end = time .time ()
106- print (f"Tracking Everest collimator took { end - start :.4f} seconds" )
10791
10892 print (f"Tracking { particles ._num_active_particles } particles (FLUKA)... " , end = '' )
10993 print (f"Hit: { particles_hit ._num_active_particles } " )
11094 print (f"Collimator: { coll .name } " )
111-
112-
113- # if ((particles_hit._num_active_particles == 0) & (particles_miss == 0)):
114- # # track_core(coll, particles)
115- # _drift(coll, particles, coll.length)
116- # return
117-
11895
11996 # check if ~is_hit has any true value
12097 if np .any (~ is_hit ):
121- particles_miss = particles .filter (~ is_hit )
98+ miss_id = particles .particle_id [mask_miss ]
99+ is_miss = np .isin (particles .particle_id , miss_id )
100+ particles_miss = particles .filter (is_miss )
122101 elif (particles_hit ._num_active_particles == 0 ) and (particles ._num_active_particles > 0 ):
123- # import pdb; pdb.set_trace()
124102 print ("Could not find any particles that hit the collimator, but some particles are still active. " )
125103 print ("This is likely due to a bug in the collimator tracking code. Please report this issue." )
126104
127- # particles_miss = particles.filter(~is_hit) if np.any(is_miss) else 0
128- # particles_miss = particles.filter(is_miss) if np.any(is_miss) else 0
129- # particles_miss = particles_miss.filter(particles_miss.state == 1) if np.any(is_miss) else 0
130-
131- # missing_capacity = 0
132- # if particles_miss:
133- # miss_part = particles_miss._num_active_particles
134- # more_capacity = particles.filter([False] * (particles._capacity - miss_part) + [True] * miss_part)
135105 start = time .time ()
136106
137-
138107 if particles_miss :
139108 _drift (coll , particles_miss , coll .length )
140109 if particles_hit ._num_active_particles > 0 :
0 commit comments