2 #---------------------------------------------------------------------
3 # Given a directory, the script looks for file in the form
5 # then it calls the appropriate gspladd to obtain v*_on_*.xml comprehensive
6 # file. The file name will be total_xsec.xml
7 # The scpript also prodces a root output for the splines
10 # [--dir] : Is the directory which contains all the xml files to be converted. Default: $PWD
11 # [--tune] : Tune option
12 # [--add-list] : additional file list to be included when the total_xsec.xml file is created
13 # [--root-output] : Create an output file with all the splines
14 # [--def-nu-list] : Default list of neutrino PDG to be used if that cannot be derived from local files. Default 14
15 # [--evet-gen-list] : Event generator list used in the root file output
16 # [--add-nucleons] : When the ROOT file is created, also splines for proton and neutrons are created
17 # [--save-space] : remove intermadiate xml files
19 #---------------------------------------------------------------------
23 if($_ eq '--dir') { $dir = $ARGV[$iarg+1]; }
24 if($_ eq '--tune') { $tune = $ARGV[$iarg+1]; }
25 if($_ eq '--add-list') { $add_list = $ARGV[$iarg+1]; }
26 if($_ eq '--root-output') { $root_output = 1 ; }
27 if($_ eq '--event-gen-list') { $event_gen_list = $ARGV[$iarg+1]; }
28 if($_ eq '--def-nu-list') { $def_nu_list = $ARGV[$iarg+1]; }
29 if($_ eq '--add-nucleons') { $add_nucleons = 1 ; }
30 if($_ eq '--save-space' ) { $save_space = 1 ; }
34 $dir=$ENV{'PWD'} unless defined $dir;
35 $def_nu_list = "14" unless defined $def_nu_list ;
37 opendir(DIR, $dir) or die $!;
43 while (my $file = readdir(DIR) ) {
46 next unless (-f "$dir/$file");
48 # Use a regular expression to find files ending in .xml
49 next unless ($file =~ m/\.xml$/);
51 next unless ( index($file, "_on_") != -1 );
53 my $under_counter = $file =~ tr/_//;
54 next unless ( $under_counter == 3 );
56 my $nu = substr($file, 0, index($file, '_') );
57 if ( ! exists( $nus{$nu} ) ) { $nus{$nu}=1; }
59 my $tgt = substr($file, index($file, "on_")+3, rindex($file, '_')-index($file, "on_")-3 );
60 if ( ! exists( $tgts{$tgt} ) ) { $tgts{$tgt}=1; }
62 my $list = substr($file, rindex($file, '_')+1, index($file,'.')-rindex($file, '_')-1 );
63 if ( ! exists( $lists{$list} ) ) { $lists{$list}=1; }
71 print " Neutrinos: \n";
72 foreach my $nu ( keys %nus ) {
76 print "\n targets: \n";
77 foreach my $tgt ( keys %tgts ) {
81 print "\n Processes: \n";
82 foreach my $proc ( keys %lists ) {
87 $nus{'ve'}=12 if ( exists( $nus{'ve'} ) );
88 $nus{'vebar'}=-12 if ( exists( $nus{'vebar'} ) );
89 $nus{'vmu'}=14 if ( exists( $nus{'vmu'} ) );
90 $nus{'vmubar'}=-14 if ( exists( $nus{'vmubar'} ) );
91 $nus{'vtau'}=16 if ( exists( $nus{'vtau'} ) );
92 $nus{'vtaubar'}=-16 if ( exists( $nus{'vtaubar'} ) );
95 foreach $nu ( keys %nus ) {
96 $nu_list .= "," if ( $nu_list ne "" );
97 $nu_list .= $nus{$nu};
99 ##print $nu_list."\n";
102 foreach $proc ( keys %lists ) {
103 $proc_list .= "," if ($proc_list ne "" );
104 $proc_list .= $proc ;
110 foreach my $tgt ( keys %tgts ) {
113 if ( length($tgt) == 1 ) {
114 $tmp_tgt = 1000010010 if ( $tgt eq 'p' );
115 $tmp_tgt = 1000000010 if ( $tgt eq 'n' );
117 else { $tmp_tgt = $tgt; }
121 foreach my $nu ( keys %nus ) {
123 $proc_file_list = "";
125 foreach my $proc ( keys %lists ) {
127 $tmp_proc_file="$dir/".$nu."_on_".$tgt."_".$proc.".xml";
128 if ( -f $tmp_proc_file ) {
129 $proc_file_list .= "," if ( $proc_file_list ne "" );
130 $proc_file_list .= "$tmp_proc_file";
133 print "Warning: Missing file $tmp_proc_file \n";
137 $tmp_nu_file = "$dir/".$nu."_on_".$tgt.".xml";
139 $gspladd_opt = " -o $tmp_nu_file -f $proc_file_list ";
140 $gspladd_cmd = "gspladd $gspladd_opt";
141 print "$gspladd_cmd \n \n";
144 if ( -f $tmp_nu_file ) {
145 $nu_file_list .= "," if ( $nu_file_list ne "" );
146 $nu_file_list .= "$tmp_nu_file";
149 print "Error: $tmp_nu_file not created \n";
154 $tmp_tgt_file = "$dir/".$tgt.".xml";
156 $nus_size = keys %nus ;
158 if ( $nus_size > 1 ) {
159 $gspladd_opt = " -o $tmp_tgt_file -f $nu_file_list ";
160 $gspladd_cmd = "gspladd $gspladd_opt";
161 print "$gspladd_cmd \n \n";
164 elsif ( $nus_size == 1 ) {
165 $cp_cmd = "cp $nu_file_list $tmp_tgt_file ";
166 print "$cp_cmd \n \n";
169 elsif ( $nus_size == 0 ) {
170 print "\nError: No Neutrino flavours \n";
173 if ( -f $tmp_tgt_file ) {
174 $tgt_file_list .= "," if ( $tgt_file_list ne "" );
175 $tgt_file_list .= "$tmp_tgt_file";
176 $tgt_list .= "," if ( $tgt_list ne "" );
177 $tgt_list .= "$tmp_tgt";
180 print "\nError: $tmp_tgt_file not created \n";
185 $glob_file = $dir."/total_xsec.xml";
187 $tgt_size = keys %tgts;
188 if ( ($tgt_size > 1) or (defined $add_list ) ) {
190 if ( defined $add_list ) {
191 $tgt_file_list = "$add_list" . "," . "$tgt_file_list" ;
194 if ( defined $add_nucleons ) {
195 if ( index($tgt_list, "1000010010") == -1 ) {
196 $tgt_list .= ",1000010010";
199 if ( index($tgt_list, "1000000010") == -1 ) {
200 $tgt_list .= ",1000000010";
204 ##$grep_pipe = "grep -B 100 -A 30 -i \"warn\\|error\\|fatal\"";
205 $gspladd_opt = " -o $glob_file -f $tgt_file_list ";
206 $gspladd_cmd = "gspladd $gspladd_opt";
207 print "$gspladd_cmd \n \n";
210 elsif ( $tgt_size == 1 ) {
212 ###if there is only one target, the global file has to be created manually
213 my $temp_name = "$dir/".(keys %tgts)[0].".xml";
216 $cmd = "cp " if defined $save_space ;
218 $cmd .= " $temp_name $glob_file ";
219 print "Executing: $cmd \n" ;
223 if ( defined $root_output ) {
226 ## Create an output file with all the splines in root format
229 if ( $nu_list eq "" ) {
230 $nu_list = $def_nu_list ;
233 if ( index($tgt_list, "1000010010") == -1 ) {
234 $tgt_list .= "," unless ( $tgt_list eq "" ) ;
235 $tgt_list .= "1000010010" ;
238 if ( index($tgt_list, "1000000010") == -1 ) {
239 $tgt_list .= "," unless ( $tgt_list eq "" ) ;
240 $tgt_list .= "1000000010";
243 my $cmd = "gspl2root ";
244 $cmd .= " -p $nu_list ";
245 $cmd .= " -t $tgt_list ";
246 $cmd .= " -f $glob_file ";
247 $cmd .= " -o $dir"."/total_xsec.root " ;
248 if ( defined $event_gen_list ) {
249 $cmd .= " --event-generator-list $event_gen_list "
251 $cmd .= " --tune $tune " if ( defined $tune ) ;
258 if ( defined $save_space ) {
261 ## removing intermediate xml file
264 foreach my $tgt ( keys %tgts ) {
266 foreach my $nu ( keys %nus ) {
268 my $tmp_nu_file = "$dir/".$nu."_on_".$tgt.".xml";
270 if ( -f $tmp_nu_file ) {
276 my $tmp_tgt_file = "$dir/".$tgt.".xml";
278 if ( -f $tmp_tgt_file ) {
284 } ## if defined $save_space