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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/parameterisations/Par04/training/utils/observables.py (Version 11.3.0) and /examples/extended/parameterisations/Par04/training/utils/observables.py (Version 10.3.p1)


  1 from dataclasses import dataclass                 
  2 from enum import Enum                             
  3                                                   
  4 import numpy as np                                
  5                                                   
  6 from core.constants import N_CELLS_Z, N_CELLS_    
  7                                                   
  8                                                   
  9 @dataclass                                        
 10 class Observable:                                 
 11     """ An abstract class defining interface o    
 12                                                   
 13     Do not use this class directly.               
 14                                                   
 15     Attributes:                                   
 16           _input: A numpy array with shape = (    
 17     """                                           
 18     _input: np.ndarray                            
 19                                                   
 20                                                   
 21 class ProfileType(Enum):                          
 22     """ Enum class of various profile types.      
 23                                                   
 24     """                                           
 25     LONGITUDINAL = 0                              
 26     LATERAL = 1                                   
 27                                                   
 28                                                   
 29 @dataclass                                        
 30 class Profile(Observable):                        
 31     """ An abstract class describing behaviour    
 32                                                   
 33     Do not use this class directly. Use Longit    
 34                                                   
 35     """                                           
 36                                                   
 37     def calc_profile(self) -> np.ndarray:         
 38         pass                                      
 39                                                   
 40     def calc_first_moment(self) -> np.ndarray:    
 41         pass                                      
 42                                                   
 43     def calc_second_moment(self) -> np.ndarray    
 44         pass                                      
 45                                                   
 46                                                   
 47 @dataclass                                        
 48 class LongitudinalProfile(Profile):               
 49     """ A class defining observables related t    
 50                                                   
 51     Attributes:                                   
 52         _energies_per_event: A numpy array wit    
 53             element [i, j] is a sum of energie    
 54         _total_energy_per_event: A numpy array    
 55             cells for an ith event.               
 56         _w: A numpy array = [0, 1, ..., Z - 1]    
 57                                                   
 58     """                                           
 59                                                   
 60     def __post_init__(self):                      
 61         self._energies_per_event = np.sum(self    
 62         self._total_energy_per_event = np.sum(    
 63         self._w = np.arange(N_CELLS_Z)            
 64                                                   
 65     def calc_profile(self) -> np.ndarray:         
 66         """ Calculates a longitudinal profile.    
 67                                                   
 68         A longitudinal profile for a given lay    
 69         sum_{i = 0}^{NE - 1} energy_per_event[    
 70                                                   
 71         Returns:                                  
 72             A numpy array of longitudinal prof    
 73                                                   
 74         """                                       
 75         return np.sum(self._energies_per_event    
 76                                                   
 77     def calc_first_moment(self) -> np.ndarray:    
 78         """ Calculates a first moment of profi    
 79                                                   
 80         A first moment of a longitudinal profi    
 81         FM[e] = alpha * (sum_{i = 0}^{Z - 1} e    
 82         w = [0, 1, 2, ..., Z - 1],                
 83         alpha = SIZE_Z defined in core/constan    
 84                                                   
 85         Returns:                                  
 86             A numpy array of first moments of     
 87                                                   
 88         """                                       
 89         return SIZE_Z * np.dot(self._energies_    
 90                                                   
 91     def calc_second_moment(self) -> np.ndarray    
 92         """ Calculates a second moment of a lo    
 93                                                   
 94         A second moment of a longitudinal prof    
 95         SM[e] = (sum_{i = 0}^{Z - 1} (w[i] - a    
 96         where                                     
 97         w = [0, 1, 2, ..., Z - 1],                
 98         alpha = SIZE_Z defined in ochre/consta    
 99                                                   
100         Returns:                                  
101             A numpy array of second moments of    
102         """                                       
103         first_moment = self.calc_first_moment(    
104         first_moment = np.expand_dims(first_mo    
105         w = np.expand_dims(self._w, axis=0)       
106         # w has now a shape = [1, Z] and first    
107         # below how that one create an array w    
108         return np.sum(np.multiply(np.power(w *    
109                       axis=1) / self._total_en    
110                                                   
111                                                   
112 @dataclass                                        
113 class LateralProfile(Profile):                    
114     """ A class defining observables related t    
115                                                   
116     Attributes:                                   
117         _energies_per_event: A numpy array wit    
118             element [i, j] is a sum of energie    
119         _total_energy_per_event: A numpy array    
120             cells for an ith event.               
121         _w: A numpy array = [0, 1, ..., R - 1]    
122                                                   
123     """                                           
124                                                   
125     def __post_init__(self):                      
126         self._energies_per_event = np.sum(self    
127         self._total_energy_per_event = np.sum(    
128         self._w = np.arange(N_CELLS_R)            
129                                                   
130     def calc_profile(self) -> np.ndarray:         
131         """ Calculates a lateral profile.         
132                                                   
133         A lateral profile for a given layer l     
134         sum_{i = 0}^{NE - 1} energy_per_event[    
135                                                   
136         Returns:                                  
137             A numpy array of longitudinal prof    
138                                                   
139         """                                       
140         return np.sum(self._energies_per_event    
141                                                   
142     def calc_first_moment(self) -> np.ndarray:    
143         """ Calculates a first moment of profi    
144                                                   
145         A first moment of a lateral profile fo    
146         FM[e] = alpha * (sum_{i = 0}^{R - 1} e    
147         w = [0, 1, 2, ..., R - 1],                
148         alpha = SIZE_R defined in core/constan    
149                                                   
150         Returns:                                  
151             A numpy array of first moments of     
152                                                   
153         """                                       
154         return SIZE_R * np.dot(self._energies_    
155                                                   
156     def calc_second_moment(self) -> np.ndarray    
157         """ Calculates a second moment of a la    
158                                                   
159         A second moment of a lateral profile f    
160         SM[e] = (sum_{i = 0}^{R - 1} (w[i] - a    
161         where                                     
162         w = [0, 1, 2, ..., R - 1],                
163         alpha = SIZE_R defined in ochre/consta    
164                                                   
165         Returns:                                  
166             A numpy array of second moments of    
167         """                                       
168         first_moment = self.calc_first_moment(    
169         first_moment = np.expand_dims(first_mo    
170         w = np.expand_dims(self._w, axis=0)       
171         # w has now a shape = [1, R] and first    
172         # below how that one create an array w    
173         return np.sum(np.multiply(np.power(w *    
174                       axis=1) / self._total_en    
175                                                   
176                                                   
177 @dataclass                                        
178 class Energy(Observable):                         
179     """ A class defining observables total ene    
180                                                   
181     """                                           
182                                                   
183     def calc_total_energy(self):                  
184         """ Calculates total energy detected i    
185                                                   
186         Total energy for a given event e (e =     
187         for this event.                           
188                                                   
189         Returns:                                  
190             A numpy array of total energy valu    
191         """                                       
192         return np.sum(self._input, axis=(1, 2,    
193                                                   
194     def calc_cell_energy(self):                   
195         """ Calculates cell energy.               
196                                                   
197         Cell energy for a given event (e = 0,     
198         values of energy in particular cells.     
199                                                   
200         Returns:                                  
201             A numpy array of cell energy value    
202                                                   
203         """                                       
204         return np.copy(self._input).reshape(-1    
205                                                   
206     def calc_energy_per_layer(self):              
207         """ Calculates total energy detected i    
208                                                   
209         Energy per layer for a given event (e     
210         values of total energy detected in a p    
211                                                   
212         Returns:                                  
213             A numpy array of cell energy value    
214                                                   
215         """                                       
216         return np.sum(self._input, axis=(1, 2)