|
||||
File indexing completed on 2025-01-18 09:15:23
0001 # Template variator code 0002 # - use this to start your own variation study 0003 # - see other `var*.rb` files for more examples 0004 # - here we define the class `Variator`, which inherits from `VariatorBase`, 0005 # where we only need to write the constructor `initialize`: 0006 # - first call `VariatorBase` constructor (`super`) to instantiate instance 0007 # variables such as `@varied_settings` (they all start with a single `@`) 0008 # - overwrite the instance variables with your own 0009 0010 ##### begin boilerplate ##### 0011 require './ruby/variator/variator_base.rb' 0012 class Variator < VariatorBase 0013 def initialize 0014 super 0015 ##### end boilerplate ##### 0016 0017 0018 ### PARAMETER VARIATIONS ************************* 0019 # - create the following Hash for each variation, and add it to the 0020 # Array `@varied_settings`: 0021 # { 0022 # :xpath => XPATH to the XML node 0023 # :attribute => node attribute 0024 # :function => variation function (see variator_base.rb) 0025 # :args => variation arguments 0026 # :count => number of variations 0027 # :label => OPTIONAL: unique Symbol representing this variation; see `@derived_settings` below 0028 # } 0029 # - XPATHs can be specific or more general; see https://nokogiri.org/tutorials/searching_a_xml_html_document.html 0030 # - try to make sure the XPATH refers to a unique node 0031 # - note: to vary a "constant" such as `DRICH_Length` in the compact file, use: 0032 # { :xpath=>'//constant[@name="DRICH_Length"]', :attribute=>'value' } 0033 # 0034 @varied_settings = [ 0035 { 0036 :xpath => '//mirror', 0037 :attribute => 'focus_tune_z', 0038 :function => @@min_max, 0039 :args => [30, 40], 0040 :count => 2, 0041 }, 0042 { 0043 :xpath => '//sensors//sphere', 0044 :attribute => 'radius', 0045 :function => @@center_delta, 0046 :args => [140, 20], 0047 :count => 3, 0048 :label => :sensor_sphere_radius, 0049 }, 0050 ] 0051 0052 0053 ### FIXED SETTINGS ******************************* 0054 # - specify specific fixed settings 0055 # - `@fixed_settings` is also an array of Hashes, with one of the following forms: 0056 # { :constant, :value } # for `XPATH=//constant` nodes 0057 # { :xpath, :attribute, :value } # for general attribute (similar to `@varied_settings`) 0058 # - this is optional, don't set it if you don't need it 0059 @fixed_settings = [ 0060 { :constant=>'DRICH_debug_optics', :value=>'0' }, 0061 ] 0062 0063 0064 ### DERIVED SETTINGS ***************************** 0065 # specify settings which depend on variant-specific values 0066 # - `@derived_settings` is also an array of Hashes 0067 # - add a unique `:label` to any variation setting in `@varied_settings`; 0068 # the label will provide access to that variation's variant-specific value 0069 # - the Hash is defined as: 0070 # { 0071 # :xpath => XPATH to the XML node to set 0072 # :attribute => node attribute to set 0073 # :derivation => a Proc, which returns the derived value you want to set (see below) 0074 # } 0075 # - the `:derivation` Proc takes one argument, a Hash which contains 0076 # key=>value pairs where the keys are the `:label`s you defined in 0077 # `@varied_settings`, and the values are the variant-specific values 0078 # - this is optional, don't set it if you don't need it 0079 @derived_settings = [ 0080 # sets sensor sphere `centerz` to `50 - radius` 0081 { 0082 :xpath => '//sensors//sphere', 0083 :attribute => 'centerz', 0084 :derivation => Proc.new{ |value| 50.0 - value[:sensor_sphere_radius] }, 0085 }, 0086 ] 0087 0088 0089 ### SIMULATION COMMANDS ************************** 0090 # - list of commands to run the simulation 0091 # - the full `simulation_pipelines` array is a list of pipelines, which will be 0092 # executed sequentially 0093 # - a pipeline is a list of commands, where stdout of one command is streamed 0094 # to stdin of the next command 0095 # - each command is written as an array, where the first element is the 0096 # command, and the remaining elements are its arguments 0097 # - a pipeline can be a single command 0098 # - the list of pipelines will be executed for each variant 0099 # - example pipelines: 0100 # [[ "ls", "-t" ]] # => `ls -t` 0101 # [ ["ls","-lt"], ["tail","-n3"] ] # => `ls -lt | tail -n3` 0102 # 0103 # - `settings` is a Hash, including the following: 0104 # { 0105 # :id => variant ID 0106 # :compact_drich => dRICH compact file; this file is the variant dRICH configuration 0107 # :compact_detector => full detector compact file; references settings[:compact_drich] 0108 # :output => output ROOT file 0109 # :log => output log file prefix 0110 # :variant_info => Hash of this variant's settings 0111 # } 0112 # 0113 # - some common `simulation_pipelines` are found in `variator_base.rb`, 0114 # for example, optics testing; you are welcome to add your own there too 0115 # 0116 @simulation_pipelines = Proc.new do |settings| 0117 [ 0118 [[ 0119 "./simulate.py", 0120 "-t 1", 0121 "-n 100", 0122 "-c #{settings[:compact_detector]}", 0123 "-o #{settings[:output]}", 0124 ]], 0125 [[ 0126 "bin/draw_hits", 0127 "d", 0128 settings[:output], 0129 ]], 0130 ] 0131 end 0132 0133 0134 ##### begin boilerplate ##### 0135 end # `Variator` constructor 0136 end # class `Variator`
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |