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] [ 10.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/include/Par04InferenceSetup.hh (Version 11.3.0) and /examples/extended/parameterisations/Par04/include/Par04InferenceSetup.hh (Version 10.4.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 #ifdef USE_INFERENCE                              
 27 #  ifndef PAR04INFEERENCESETUP_HH                 
 28 #    define PAR04INFEERENCESETUP_HH               
 29                                                   
 30 #    include "CLHEP/Units/SystemOfUnits.h"  //    
 31                                                   
 32 #    include "G4ThreeVector.hh"  // for G4Thre    
 33                                                   
 34 #    include <G4String.hh>  // for G4String       
 35 #    include <G4SystemOfUnits.hh>  // for mm      
 36 #    include <G4Types.hh>  // for G4int, G4dou    
 37 #    include <memory>  // for unique_ptr          
 38 #    include <vector>  // for vector              
 39 class Par04DetectorConstruction;                  
 40 class Par04InferenceInterface;                    
 41 class Par04InferenceMessenger;                    
 42                                                   
 43 /**                                               
 44  * @brief Inference setup.                        
 45  *                                                
 46  * Constructs the input vector of size b+c to     
 47  * the size of the latent space (or the encode    
 48  * Autoencoder based model), c represents the     
 49  *The b values of the input vector are randoml    
 50  *Gaussian distribution. The c values represen    
 51  *values of the particle energy, angle and det    
 52  *values are user-specific application. The en    
 53  *the original energy scale in MeV. Computes t    
 54  *of each inferred energy value.                  
 55  *                                                
 56  **/                                              
 57                                                   
 58 class Par04InferenceSetup                         
 59 {                                                 
 60   public:                                         
 61     Par04InferenceSetup();                        
 62     ~Par04InferenceSetup();                       
 63                                                   
 64     /// Geometry setup                            
 65     /// Check if inference should be performed    
 66     /// @param[in] aEnergy Particle's energy      
 67     G4bool IfTrigger(G4double aEnergy);           
 68     /// Set mesh size.                            
 69     /// @param aSize (x,y,x) size for Carthesi    
 70     /// cylindrical coordinates.                  
 71     inline void SetMeshSize(const G4ThreeVecto    
 72     /// Get mesh size.                            
 73     /// @return G4ThreeVector (x,y,x) size for    
 74     /// z) for cylindrical coordinates.           
 75     inline G4ThreeVector GetMeshSize() const {    
 76     /// Set number of mesh cells.                 
 77     /// @param aSize (x,y,x) size for Carthesi    
 78     /// cylindrical coordinates.                  
 79     inline void SetMeshNumber(const G4ThreeVec    
 80     /// Get number of mesh cells.                 
 81     /// @return G4ThreeVector (x,y,x) size for    
 82     /// z) for cylindrical coordinates.           
 83     inline G4ThreeVector GetMeshNumber() const    
 84     /// Set size of the condition vector          
 85     inline void SetSizeConditionVector(G4int a    
 86     /// Get size of the condition vector          
 87     inline G4int GetSizeConditionVector() cons    
 88     /// Set size of the latent space vector       
 89     inline void SetSizeLatentVector(G4int aNum    
 90     /// Get size of the latent space vector       
 91     inline G4int GetSizeLatentVector() const {    
 92     /// Set path and name of the model            
 93     inline void SetModelPathName(G4String aNam    
 94     /// Get path and name of the model            
 95     inline G4String GetModelPathName() const {    
 96     /// Set profiling flag                        
 97     inline void SetProfileFlag(G4int aNumber)     
 98     /// Get profiling flag                        
 99     inline G4int GetProfileFlag() const { retu    
100     /// Set optimization flag                     
101     inline void SetOptimizationFlag(G4int aNum    
102     /// Get optimization flag                     
103     inline G4int GetOptimizationFlag() const {    
104     /// Get name of the inference library         
105     inline G4String GetInferenceLibrary() cons    
106     /// Set name of the inference library and     
107     /// interface                                 
108     void SetInferenceLibrary(G4String aName);     
109     /// Check settings of the inference librar    
110     void CheckInferenceLibrary();                 
111     /// Set number of Mesh cells in cylindrica    
112     inline void SetMeshNbOfCells(G4ThreeVector    
113     /// Set number of Mesh cells in cylindrica    
114     /// @param[in] aIndex index of cylindrical    
115     inline void SetMeshNbOfCells(G4int aIndex,    
116     /// Get number of Mesh cells in cylindrica    
117     inline G4ThreeVector GetMeshNbOfCells() co    
118     /// Set size of Mesh cells in cylindrical     
119     inline void SetMeshSizeOfCells(G4ThreeVect    
120     /// Set size of Mesh cells in cylindrical     
121     /// @param[in] aIndex index of cylindrical    
122     inline void SetMeshSizeOfCells(G4int aInde    
123     /// Get size of Mesh cells in cylindrical     
124     inline G4ThreeVector GetMeshSizeOfCells()     
125     /// Setting execution providers flags         
126     /// GPU                                       
127     inline void SetCudaFlag(G4int aNumber) { f    
128     inline G4int GetCudaFlag() const { return     
129     /// Setting execution providers Options       
130     /// Cuda                                      
131     inline void SetCudaDeviceId(G4String aNumb    
132     inline G4String GetCudaDeviceId() const {     
133     inline void SetCudaGpuMemLimit(G4String aN    
134     inline G4String GetCudaGpuMemLimit() const    
135     inline void SetCudaArenaExtendedStrategy(G    
136     {                                             
137       fCudaArenaExtendedStrategy = aNumber;       
138     };                                            
139     inline G4String GetCudaArenaExtendedStrate    
140     inline void SetCudaCudnnConvAlgoSearch(G4S    
141     {                                             
142       fCudaCudnnConvAlgoSearch = aNumber;         
143     };                                            
144     inline G4String GetCudaCudnnConvAlgoSearch    
145     inline void SetCudaDoCopyInDefaultStream(G    
146     {                                             
147       fCudaDoCopyInDefaultStream = aNumber;       
148     };                                            
149     inline G4String GetCudaDoCopyInDefaultStre    
150     inline void SetCudaCudnnConvUseMaxWorkspac    
151     {                                             
152       fCudaCudnnConvUseMaxWorkspace = aNumber;    
153     };                                            
154     inline G4String GetCudaCudnnConvUseMaxWork    
155     {                                             
156       return fCudaCudnnConvUseMaxWorkspace;       
157     };                                            
158                                                   
159     /// Execute inference                         
160     /// @param[out] aDepositsEnergies of infer    
161     /// detector                                  
162     /// @param[in] aParticleEnergy Energy of i    
163     void GetEnergies(std::vector<G4double>& aE    
164                      G4float aInitialAngle);      
165                                                   
166     /// Calculate positions                       
167     /// @param[out] aDepositsPositions Vector     
168     /// energies deposited in the detector        
169     /// @param[in] aParticlePosition Initial p    
170     /// transverse plane of the mesh              
171     ///            and beginning of the mesh i    
172     /// @param[in] aParticleDirection Initial     
173     /// rotation                                  
174     void GetPositions(std::vector<G4ThreeVecto    
175                       G4ThreeVector aParticleP    
176                                                   
177   private:                                        
178     /// Cell's size: (x,y,x) for Carthesian, a    
179     /// coordinates Can be changed with UI com    
180     /// phi z> <unit>`. For cylindrical coordi    
181     /// from fMeshNumber.                         
182     G4ThreeVector fMeshSize = G4ThreeVector(2.    
183     /// Number of cells: (x,y,x) for Carthesia    
184     /// coordinates. Can be changed with UI co    
185     /// Nz>/<Nr Nphi Nz>`                         
186     G4ThreeVector fMeshNumber = G4ThreeVector(    
187     /// Inference interface                       
188     std::unique_ptr<Par04InferenceInterface> f    
189     /// Inference messenger                       
190     Par04InferenceMessenger* fInferenceMesseng    
191     /// Maximum particle energy value (in MeV)    
192     float fMaxEnergy = 1024000.0;                 
193     /// Maximum particle angle (in degrees) in    
194     float fMaxAngle = 90.0;                       
195     /// Name of the inference library             
196     G4String fInferenceLibrary = "ONNX";          
197     /// Size of the latent space vector           
198     G4int fSizeLatentVector = 10;                 
199     /// Size of the condition vector              
200     G4int fSizeConditionVector = 4;               
201     /// Name of the inference library             
202     G4String fModelPathName = "MLModels/Genera    
203     /// ONNX specific                             
204     /// Profiling flag                            
205     G4bool fProfileFlag = false;                  
206     /// Optimization flag                         
207     G4bool fOptimizationFlag = false;             
208     /// Optimization file                         
209     G4String fModelSavePath = "MLModels/Optimi    
210     /// Profiling file                            
211     G4String fProfilingOutputSavePath = "opt.j    
212     /// Intra-operation number of threads         
213     G4int fIntraOpNumThreads = 1;                 
214     /// Flags for execution providers             
215     /// GPU                                       
216     G4bool fCudaFlag = false;                     
217     /// Execution Provider Options                
218     /// Cuda options                              
219     G4String fCudaDeviceId = "0";                 
220     G4String fCudaGpuMemLimit = "2147483648";     
221     G4String fCudaArenaExtendedStrategy = "kSa    
222     G4String fCudaCudnnConvAlgoSearch = "DEFAU    
223     G4String fCudaDoCopyInDefaultStream = "1";    
224     G4String fCudaCudnnConvUseMaxWorkspace = "    
225     std::vector<const char*> cuda_keys{           
226       "device_id",                                
227       "gpu_mem_limit",                            
228       "arena_extend_strategy",                    
229       "cudnn_conv_algo_search",                   
230       "do_copy_in_default_stream",                
231       "cudnn_conv_use_max_workspace",             
232     };                                            
233     std::vector<const char*> cuda_values{         
234       fCudaDeviceId.c_str(),                      
235       fCudaGpuMemLimit.c_str(),                   
236       fCudaArenaExtendedStrategy.c_str(),         
237       fCudaCudnnConvAlgoSearch.c_str(),           
238       fCudaDoCopyInDefaultStream.c_str(),         
239       fCudaCudnnConvUseMaxWorkspace.c_str(),      
240     };                                            
241 };                                                
242                                                   
243 #  endif /* PAR04INFEERENCESETUP_HH */            
244 #endif                                            
245