submit_eA_hadron_attenuation_validation_mc_jobs.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 #-----------------------------------------------------------------------------------------------------------
4 # Submit jobs to generate data needed for validating GENIE's hadronization + intranuclear transport model
5 # (with emphasis on the modeling of medium effects to the hadronization) in a set of comparisons against
6 # the CLAS and HERMES nuclear attenuation data.
7 #
8 # Syntax:
9 # perl submit-vld_hadroatten.pl <options>
10 #
11 # Options:
12 # --version : GENIE version number
13 # --run : runs to submit (eg --run 101102 / --run 101102,154002 / -run all)
14 # [--model-enum] : physics model enumeration, default: 0
15 # [--nsubruns] : number of subruns per run, default: 1
16 # [--offset] : subrun offset (for augmenting existing sample), default: 0
17 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
18 # [--production] : production name, default: <version>
19 # [--cycle] : cycle in current production, default: 01
20 # [--use-valgrind] : default: off
21 # [--batch-system] : <PBS, LSF, slurm, none>, default: PBS
22 # [--queue] : default: prod
23 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE/
24 # [--jobs-topdir] : top level dir for job files, default: /opt/ppd/t2k/softw/scratch/GENIE/
25 #
26 # EVENT SAMPLES:
27 #
28 # Run number key: ITTJJMxxx
29 # I : probe (1:e-, 2:e+)
30 # TT : nuclear target (01:H1, 02:D2, 03:He4, 06:C12, 07:N14, 08:O16, 10:Ne20, 26:Fe56, 36:Kr83, 54:Xe131)
31 # JJ : flux setting (01: 12.0 GeV [HERMES], 02: 27.6 GeV [HERMES])
32 # M : model enumeration
33 # xxx : sub-run ID, 000-999, 50k events each
34 #
35 #...................................................................................
36 # run number | init state | energy | event gen. | flux
37 # | | (GeV) | list |
38 #...................................................................................
39 #
40 # 10202Mxxx | e- + D2 | 27.6 | EM | monoenergetic
41 # 10302Mxxx | e- + He4 | 27.6 | EM | monoenergetic
42 # 10702Mxxx | e- + N14 | 27.6 | EM | monoenergetic
43 # 11002Mxxx | e- + Ne20 | 27.6 | EM | monoenergetic
44 # 13602Mxxx | e- + Kr83 | 27.6 | EM | monoenergetic
45 # 15402Mxxx | e- + Xe131 | 27.6 | EM | monoenergetic
46 #
47 #...................................................................................
48 #
49 # Author:
50 # Costas Andreopoulos <costas.andreopoulos \st stfc.ac.uk>
51 # University of Liverpool & STFC Rutherford Appleton Laboratory
52 #
53 # Copyright:
54 # Copyright (c) 2003-2020, The GENIE Collaboration
55 # For the full text of the license visit http://copyright.genie-mc.org
56 #-----------------------------------------------------------------------------------------------------------
57 #
58 
59 use File::Path;
60 
61 # inputs
62 #
63 $iarg=0;
64 foreach (@ARGV) {
65  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
66  if($_ eq '--run') { $runnu = $ARGV[$iarg+1]; }
67  if($_ eq '--model-enum') { $model_enum = $ARGV[$iarg+1]; }
68  if($_ eq '--nsubruns') { $nsubruns = $ARGV[$iarg+1]; }
69  if($_ eq '--offset') { $offset = $ARGV[$iarg+1]; }
70  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
71  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
72  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
73  if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
74  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
75  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
76  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
77  if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
78  $iarg++;
79 }
80 die("** Aborting [Undefined GENIE version. Use the --version option]")
81 unless defined $genie_version;
82 die("** Aborting [You need to specify which runs to submit. Use the --run option]")
83 unless defined $runnu;
84 
85 $model_enum = "0" unless defined $model_enum;
86 $nsubruns = 1 unless defined $nsubruns;
87 $offset = 0 unless defined $offset;
88 $use_valgrind = 0 unless defined $use_valgrind;
89 $arch = "SL5_64bit" unless defined $arch;
90 $production = "$genie_version" unless defined $production;
91 $cycle = "01" unless defined $cycle;
92 $batch_system = "PBS" unless defined $batch_system;
93 $queue = "prod" unless defined $queue;
94 $softw_topdir = "/opt/ppd/t2k/softw/GENIE" unless defined $softw_topdir;
95 $jobs_topdir = "/opt/ppd/t2k/scratch/GENIE/" unless defined $jobs_topdir;
96 $time_limit = "60:00:00";
97 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
98 $jobs_dir = "$jobs_topdir/vld\_hadroatten-$production\_$cycle";
99 $xspl_file = "$softw_topdir/data/job_inputs/xspl/gxspl-eA-$genie_version.xml";
100 $mcseed = 210921029;
101 $nev_per_subrun = 50000;
102 
103 # inputs for event generation jobs
104 %evg_pdg_hash = (
105  '10202' => '11',
106  '10302' => '11',
107  '10702' => '11',
108  '11002' => '11',
109  '13602' => '11',
110  '15402' => '11'
111 );
112 %evg_tgtpdg_hash = (
113  '10202' => '1000010020',
114  '10302' => '1000020040',
115  '10702' => '1000070140',
116  '11002' => '1000100200',
117  '13602' => '1000360830',
118  '15402' => '1000541310'
119 );
120 %evg_energy_hash = (
121  '10202' => '27.6',
122  '10302' => '27.6',
123  '10702' => '27.6',
124  '11002' => '27.6',
125  '13602' => '27.6',
126  '15402' => '27.6'
127 );
128 %evg_gevgl_hash = (
129  '10202' => 'EM',
130  '10302' => 'EM',
131  '10702' => 'EM',
132  '11002' => 'EM',
133  '13602' => 'EM',
134  '15402' => 'EM'
135 );
136 %evg_fluxopt_hash = (
137  '10202' => '',
138  '10302' => '',
139  '10702' => '',
140  '11002' => '',
141  '13602' => '',
142  '15402' => ''
143 );
144 
145 # make the jobs directory
146 #
147 mkpath ($jobs_dir, {verbose => 1, mode=>0777});
148 
149 #
150 # submit event generation jobs
151 #
152 
153 # run loop
154 for my $curr_runnu (keys %evg_gevgl_hash) {
155 
156  # check whether to commit current run
157  if($runnu=~m/$curr_runnu/ || $runnu eq "all") {
158 
159  print "** submitting event generation run: $curr_runnu \n";
160 
161  #
162  # get runnu-dependent info
163  #
164  $probe = $evg_pdg_hash {$curr_runnu};
165  $tgt = $evg_tgtpdg_hash {$curr_runnu};
166  $en = $evg_energy_hash {$curr_runnu};
167  $gevgl = $evg_gevgl_hash {$curr_runnu};
168  $fluxopt = $evg_fluxopt_hash {$curr_runnu};
169 
170  # submit subruns
171  for($isubrun = 0; $isubrun < $nsubruns; $isubrun++) {
172 
173  # Run number key: ITTJJMxxx
174  $curr_subrunnu = 10000 * $curr_runnu + 1000 * $model_enum + $isubrun + $offset;
175  $curr_seed = $mcseed + $isubrun + $offset;
176  $fntemplate = "$jobs_dir/hadroatten-$curr_subrunnu";
177 # $grep_pipe = "grep -B 20 -A 30 -i \"warn\\|error\\|fatal\"";
178  $grep_pipe = "grep -B 20 -A 30 -i fatal";
179  $valgrind_cmd = "valgrind --tool=memcheck --error-limit=no --leak-check=yes --show-reachable=yes";
180  $evgen_opt = "-n $nev_per_subrun -e $en -p $probe -t $tgt $fluxopt -r $curr_subrunnu --seed $curr_seed --cross-sections $xspl_file --event-generator-list $gevgl";
181  $evgen_cmd = "gevgen $evgen_opt | $grep_pipe &> $fntemplate.evgen.log";
182  $conv_cmd = "gntpc -f gst -i gntp.$curr_subrunnu.ghep.root";
183 
184  print "@@ exec: $evgen_cmd \n";
185 
186  #
187  # submit
188  #
189 
190  # PBS case
191  if($batch_system eq 'PBS') {
192  $batch_script = "$fntemplate.pbs";
193  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
194  print PBS "#!/bin/bash \n";
195  print PBS "#PBS -N hadroatten-$curr_subrunnu \n";
196  print PBS "#PBS -l cput=$time_limit \n";
197  print PBS "#PBS -o $fntemplate.pbsout.log \n";
198  print PBS "#PBS -e $fntemplate.pbserr.log \n";
199  print PBS "source $genie_setup \n";
200  print PBS "cd $jobs_dir \n";
201  print PBS "$evgen_cmd \n";
202  print PBS "$conv_cmd \n";
203  close(PBS);
204  `qsub -q $queue $batch_script`;
205  } #PBS
206 
207  # LSF case
208  if($batch_system eq 'LSF') {
209  $batch_script = "$fntemplate.sh";
210  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
211  print LSF "#!/bin/bash \n";
212  print LSF "#BSUB-j hadroatten-$curr_subrunnu \n";
213  print LSF "#BSUB-q $queue \n";
214  print LSF "#BSUB-c $time_limit \n";
215  print LSF "#BSUB-o $fntemplate.lsfout.log \n";
216  print LSF "#BSUB-e $fntemplate.lsferr.log \n";
217  print LSF "source $genie_setup \n";
218  print LSF "cd $jobs_dir \n";
219  print LSF "$evgen_cmd \n";
220  print LSF "$conv_cmd \n";
221  close(LSF);
222  `qsub < $batch_script`;
223  } #LSF
224 
225  # slurm case
226  if($batch_system eq 'slurm') {
227  my $time_lim = `sinfo -h -p batch -o %l`;
228  my ($days, $hours, $remainder) = $time_lim =~ /([0]+)-([0-9]+):(.*)/;
229  my $newhours = $days * 24 + $hours;
230  my $new_time_lim = "$newhours:$remainder";
231  $time_limit = $new_time_lim lt $time_limit ? $new_time_lim : $time_limit;
232  $batch_script = "$fntemplate.sh";
233  open(SLURM, ">$batch_script") or die("Can not create the slurm batch script");
234  print SLURM "#!/bin/bash \n";
235  print SLURM "#SBATCH-p $queue \n";
236  print SLURM "#SBATCH-o $fntemplate.lsfout.log \n";
237  print SLURM "#SBATCH-e $fntemplate.lsferr.log \n";
238  print SLURM "#SBATCH-t $time_limit \n";
239  print SLURM "source $genie_setup \n";
240  print SLURM "cd $jobs_dir \n";
241  print SLURM "$evgen_cmd \n";
242  print SLURM "$conv_cmd \n";
243  close(SLURM);
244  `sbatch --job-name=hadroatten-$curr_subrunnu $batch_script`;
245  } #slurm
246 
247  # no batch system, run jobs interactively
248  if($batch_system eq 'none') {
249  system("source $genie_setup; cd $jobs_dir; $evgen_cmd; $conv_cmd");
250  } # interactive mode
251 
252 
253  } # loop over subruns
254  } #checking whether to submit current run
255 } # loop over runs
256