-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsupernova.pl
executable file
·1067 lines (797 loc) · 29.1 KB
/
supernova.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# Script to run supernova rates programs
# K. Scholberg July 2010
# arguments: run mode, flux name, channel file name, experiment configuration name, noweight
# e.g. ./supernova.pl 0 livermore water wc100kt30prct 0
# If noweight is set, then the output spectra will not have channel weighting factors applied (default is that weighting factors are applied)
##
$run_choice = $ARGV[0];
$fluxname = $ARGV[1];
$channame = $ARGV[2];
$expt_config = $ARGV[3];
$noweight = $ARGV[4];
$exename = "bin/supernova";
unless ( -f $exename ) {
print $exename,
" executable not found. Please compile and install, with SNOWGLOBES variable set.",
"\n";
exit;
}
$chanfilename = "channels/channels_" . $channame . ".dat";
$globesfilename = "supernova.glb";
# open( GLOBESFILE, ">$globesfilename" );
$energywindowset = "standard";
# This block of code will look for essential files
print
"\nBefore running SNOWGLOBES, it will check see if you have the corresponding files for each channel\n\n* Smearing matrix\n* Cross Section \n* Energy Effic\n\n";
# Open channel file
open( CHANFILE, $chanfilename );
while (<CHANFILE>) {
# body...
#split each line into an array
if (/%/) { next; }
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
# if it has the SN_ID skip it
@stuff = split( /\ /, $_ );
if ( scalar(@stuff) == '12' ) {
shift(@stuff);
}
$chan_name = $stuff[0];
print( "\nChecking for: " . $chan_name . "\n" );
$file_found = 1;
# Formated names of each file type
$xsc_file = "xscns/xs_" . $chan_name . ".dat";
$smear_file = "smear/". $expt_config . "/smear_" . $chan_name . "_" . $expt_config . ".dat";
$eff_file = "effic/". $expt_config . "/effic_" . $chan_name . "_" . $expt_config . ".dat";
#File names
# if not found post message
unless ( -f $xsc_file ) {
print "WARNING: XSC file: ", $xsc_file, " not found\n";
$file_found = 0;
}
unless ( -f $smear_file ) {
print "WARNING: Smear file: ", $smear_file, " not found\n";
}
unless ( -f $eff_file ) {
print "WARNING: Effic file: ", $eff_file, " not found\n";
$file_found = 0;
}
if ($file_found==1){
print("All good !\n")
}
} # End of while loop
# Close chanfile
close(CHANFILE);
# Done looking for essential files
# #####################################
# ##### START of old supernova.pl #####
# #####################################
if ( $run_choice == '0' ) {
# Time benchmark
use Time::HiRes qw( time );
my $start = time();
$ewins{'bins'} = "200";
$ewins{'emin'} = "0.0005"; #GeV
$ewins{'emax'} = "0.100"; #GeV
$ewins{'sampling_points'} = "200";
$ewins{'sampling_min'} = "0.0005"; #GeV
$ewins{'sampling_max'} = "0.100"; #GeV
$energywindowset = "standard";
open( CHANFILE, $chanfilename );
$firstchanline = <CHANFILE>;
$firstchanline =~ s/^s+//; # remove leading whitespace
if ( index( $firstchanline, "%" ) != -1 ) {
@binningarray = split /\s+/, $firstchanline;
$ewins{'bins'} = @binningarray[1];
$ewins{'emin'} = @binningarray[2];
$ewins{'emax'} = @binningarray[3];
$ewins{'sampling_points'} = @binningarray[4];
$ewins{'sampling_min'} = @binningarray[5];
$ewins{'sampling_max'} = @binningarray[6];
}
close(CHANFILE);
# these energy window/binning values are now ready for the preamble
# now that we've read in the channel file, we should know what energy windows we have
if ( $ewins{'emax'} > 0.199 and $ewins{'emax'} < 0.201 ) {
$energywindowset = "_he";
print "using high energy window!\n";
}
# Create the globes file
$globesfilename = "supernova.glb";
open( GLOBESFILE, ">$globesfilename" );
# Here we add the globes preamble, with any modifications needed for rebinning taken care of
open( PREAMBLE, "glb/preamble.glb" );
$ready_to_modify = 0;
while (<PREAMBLE>) {
if ( index( $_, "Energy window" ) != -1 ) { $ready_to_modify = 1; }
$ourline = $_;
if ($ready_to_modify) {
keys %ewins
; # reset the internal iterator so a prior each() doesn't affect the loop
while ( my ( $k, $v ) = each %ewins ) {
if ( index( $ourline, $k ) != -1 ) {
@vallist = split /\s+/, $ourline;
$ourline =~ s/$vallist[2]/$v/;
last; # we have done the replacement, no need to continue
}
} # end while loop over ewin replacements
} # any necessary modification is done
print GLOBESFILE $ourline;
}
close(PREAMBLE);
# Put in the flux info
$fluxfilename = "fluxes/" . $fluxname . ".dat";
unless ( -f $fluxfilename ) {
print "Flux file name ", $fluxfilename, " not found\n";
exit;
}
open( FLUX, "glb/flux.glb" );
while (<FLUX>) {
# Replace the flux file name with the input argument
if (/flux_file/) {
$_ = " \@flux_file= \"" . $fluxfilename . "\"\n";
}
print GLOBESFILE $_;
}
close(FLUX);
# Now go through the channels and put in the relevant lines
# First, smearing for each channel
unless ( -f $chanfilename ) {
print "Channel file name ", $chanfilename, " not found\n";
exit;
}
open( CHANFILE, $chanfilename );
while (<CHANFILE>) {
# skip energy window info line
if (/%/) { next; }
# Grab the channel name
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff = split( /\ /, $_ );
$chan_name = $stuff[0];
$output_line =
"include \"smear/". $expt_config . "/smear_"
. $chan_name . "_"
. $expt_config
. ".dat\"\n";
print GLOBESFILE $output_line;
}
close(CHANFILE);
# Detector info
$detfilename = "detector_configurations.dat";
unless ( -f $detfilename ) {
print "Detector file name ", $detfilename, " not found\n";
exit;
}
open( DETFILENAME, $detfilename );
while (<DETFILENAME>) {
chop($_);
# Skip comments
if (/\#/) { next; }
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff = split( /\ /, $_ );
$detname = $stuff[0];
$masses{$detname} = $stuff[1];
$normfact{$detname} = $stuff[2];
if ( $detname eq ""
|| $masses{$detname} eq ""
|| $normfact{$detname} eq "" )
{
next;
}
}
close(DETFILENAME);
# Mass and target normalization by species
#%masses = ("sk1",22.5,"sk2",22.5,"100kt15pc",100, "100kt30pc",100,"ar17",17,"scint50kt",50,"halo",1.0);
#%normfact = ("sk1",2/18,"sk2",2/18,"100kt15pc",2/18, "100kt30pc",2/18,"ar17kt",1/40,"scint50kt",2/14,"halo",1/208);
if ( $masses{$expt_config} == 0 ) {
print "Error: please enter a valid experiment configuration\n";
exit;
}
$target_mass =
sprintf( "%13.6f", $masses{$expt_config} * $normfact{$expt_config} )
; # This is ktons of free protons
print "Experiment config: ", $expt_config, " Mass: ",
$masses{$expt_config}, " kton \n";
#print " Target mass: ",$normfact{$expt_config}," ",$target_mass,"\n";
# Add the background smearing here, for the given detector configuration
# (Not yet implemented: for multiple background channels,
# read them from a file labeled by detector configuration)
$do_bg = 0;
$bg_chan_name = "bg_chan";
$bg_filename = "backgrounds/" . $bg_chan_name . "_" . $expt_config . ".dat";
if ( -e $bg_filename ) {
$do_bg = 1;
print "Using background file ", $bg_filename, "\n";
}
else {
print "No background file for this configuration\n";
}
if ( $do_bg == 1 ) {
$output_line =
"include \"smear/". $expt_config . "/smear_"
. $bg_chan_name . "_"
. $expt_config
. ".dat\"\n";
print GLOBESFILE $output_line;
}
open( DETECTOR, "glb/detector.glb" );
while (<DETECTOR>) {
# Replace the flux file name with the input argument
if (/mass/) {
$_ = "\$target_mass= " . $target_mass . "\n";
}
print GLOBESFILE $_;
}
close(DETECTOR);
print GLOBESFILE "\n /******** Cross-sections *********/\n \n";
# Now the cross-sections. Note that some of these are repeated
# even thougn it is not necessary (xscns for several flavors can be in the
# same file).
# This is just to make a consistent loop over channels.
open( CHANFILE, $chanfilename );
while (<CHANFILE>) {
# skip energy window info line
if (/%/) { next; }
# Grab the channel name
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff = split( /\ /, $_ );
$chan_name = $stuff[0];
$output_line = "cross(\#" . $chan_name . ")<\n";
print GLOBESFILE $output_line;
$output_line =
" \@cross_file= \"xscns/xs_" . $chan_name . ".dat\"\n";
# print $output_line;
print GLOBESFILE $output_line;
$output_line = "\>\n";
# print $output_line;
print GLOBESFILE $output_line;
}
close(CHANFILE);
# Now the fake bg channel cross section, if it exists
if ( $do_bg == 1 ) {
$output_line = "cross(\#" . $bg_chan_name . ")<\n";
print GLOBESFILE $output_line;
$output_line = " \@cross_file= \"xscns/xs_zero.dat\"\n";
# print $output_line;
print GLOBESFILE $output_line;
$output_line = "\>\n";
# print $output_line;
print GLOBESFILE $output_line;
}
print GLOBESFILE "\n \/******** Channels *********\/\n \n";
# Now, the channel definitions
unless ( -f $chanfilename ) {
print "Channel file name ", $chanfilename, " not found\n";
exit;
}
open( CHANFILE, $chanfilename );
while (<CHANFILE>) {
# skip energy window info line
if (/%/) { next; }
# Grab the channel name
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff = split( /\ /, $_ );
$chan_name = $stuff[0];
$cpstate = $stuff[2];
$inflav = $stuff[3];
$output_line = "channel(\#" . $chan_name . "_signal)<\n";
print GLOBESFILE $output_line;
$output_line =
" \@channel= \#supernova_flux: "
. $cpstate . ": "
. $inflav
. ": "
. $inflav
. ": \#"
. $chan_name
. ": \#"
. $chan_name
. "_smear\n";
# print $output_line;
print GLOBESFILE $output_line;
# Get the post-smearing efficiencies by channel
$eff_file =
"effic/"
. $expt_config
. "/effic_"
. $chan_name_post . "_"
. $expt_config . ".dat";
# print $eff_file,"\n";
open( EFF_FILE, $eff_file );
while (<EFF_FILE>) {
$output_line = " \@post_smearing_efficiencies = " . $_;
print GLOBESFILE $output_line;
}
close(EFF_FILE);
# Try crazy reformatting
# or else get mysterious (but apparently harmless?) error from GLoBES
# Should try to track it down... -> error goes away with development GLoBES version
$output_line = "\n\>\n\n";
print GLOBESFILE $output_line;
}
close(CHANFILE);
if ( $do_bg == 1 ) {
# Now make a fake channel for the background (just one possible bg file for now)
# This is dummy info
$cpstate = "-";
$inflav = "e";
$output_line = "channel(\#" . $bg_chan_name . "_signal)<\n";
print GLOBESFILE $output_line;
$output_line =
" \@channel= \#supernova_flux: "
. $cpstate . ": "
. $inflav
. ": "
. $inflav
. ": \#"
. $bg_chan_name
. ": \#"
. $bg_chan_name
. "_smear\n";
# print $output_line;
print GLOBESFILE $output_line;
# Get the pre-smearing backgrounds by channel
$bg_file = "backgrounds/" . $bg_chan_name . "_" . $expt_config . ".dat";
print $bg_file, "\n";
open( BG_FILE, $bg_file );
while (<BG_FILE>) {
$output_line = " \@pre_smearing_background = " . $_;
print GLOBESFILE $output_line;
}
close(BG_FILE);
# Try crazy reformatting
# or else get mysterious (but apparently harmless?) error from GLoBES
# Should try to track it down... -> error goes away with development GLoBES version
$output_line = "\n\>\n\n";
print GLOBESFILE $output_line;
}
# End-matter
if ( $energywindowset eq "standard" ) {
open( POSTAMBLE, "glb/postamble.glb" );
}
elsif ( $energywindowset eq "_he" ) {
open( POSTAMBLE, "glb/postamble_he.glb" );
}
while (<POSTAMBLE>) {
print GLOBESFILE $_;
}
close(POSTAMBLE);
close(GLOBESFILE);
# Now run the executable
$comstring =
$exename . " " . $fluxname . " " . $chanfilename . " " . $expt_config;
system($comstring);
# Now apply channel-weighting factors-- this is the default
unless ( $noweight == 1 ) {
print "Applying channel weighting factors to output\n";
&apply_weights("");
&apply_weights("_smeared");
}
print("All done !!\n");
# Time benchmark
my $end = time();
printf( "Execution Time: %0.02f s\n", $end - $start );
} #END of old supernova.pl
sub apply_weights {
open( CHANFILE, $chanfilename );
while (<CHANFILE>) {
# skip energy window info line
if (/%/) { next; }
# Grab the channel name
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff = split( /\ /, $_ );
$chan_name = $stuff[0];
$cpstate = $stuff[2];
$inflav = $stuff[3];
$num_target_factor = $stuff[4];
# Open the unweighted output file to read and the weighted file to write
$unweightfilename = "out/"
. $fluxname . "_"
. $chan_name . "_"
. $expt_config
. "_events"
. $_[0]
. "_unweighted.dat";
$weightedfilename =
"> out/"
. $fluxname . "_"
. $chan_name . "_"
. $expt_config
. "_events"
. $_[0] . ".dat";
open( UNWEIGHT, $unweightfilename );
open( WEIGHTED, $weightedfilename );
while (<UNWEIGHT>) {
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
if (/---/) {
print WEIGHTED $_, "\n";
}
else {
@stuff2 = split( /\ /, $_ );
$enbin = $stuff2[0];
$evrate = $stuff2[1];
if ( $enbin ne "" ) {
print WEIGHTED $enbin, " ",
$evrate * $num_target_factor, "\n";
}
}
}
close(UNWEIGHT);
close(WEIGHTED);
}
close(CHANFILE);
}
# ###################################
# #### START of new supernova.pl ####
# ###################################
# 08/10/20 Now supernova.pl will treat each interaction in the channel file as its own simulation
# This while loop will iterate through each interaction.
# the rest of the CHANFILE loops were deleted.
# S. Torres-Lara
if ( $run_choice == '1' ) {
# Time benchmark
use Time::HiRes qw( time );
my $start = time();
$my_chan_num = 0;
#Start of main while loop
open( CHANFILE, $chanfilename );
while (<CHANFILE>) {
print "\n";
"===================================================================";
print "\n\n";
@arr = split /\s+/, $_;
shift(@arr);
# skip energy window info line
if (/%/) { next; }
# Grab the channel name
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff = split( /\ /, $_ );
# print @stuff,"\n";
$general_id = $stuff[0];
shift(@stuff);
# print @stuff,"\n";
$chan_name = $stuff[0];
$cpstate = $stuff[2];
$inflav = $stuff[3];
$num_target_factor = $stuff[4];
# $chan_POSTAMBLE = sprintf( "postamble_%s.glb", $chan_name );
# $path_to_POSTAMBLE = sprintf( "glb/%s/%s", $channame, $chan_POSTAMBLE );
$GLOBAL_POSTAMBLE = "glb/postamble_SN.glb";
## If binning parameters are found use them
if ( scalar(@arr) == '11' ) {
print "| Using custom binning for: ", $arr[0], " |\n\n";
print "_________________________________________________\n\n";
# Flux parameters
$ewins{'sampling_points'} = $arr[5];
$ewins{'sampling_min'} = $arr[6]; #GeV
$ewins{'sampling_max'} = $arr[7]; #GeV
# Detected Energy parameters
$ewins{'bins'} = $arr[8];
$ewins{'emin'} = $arr[9]; #GeV
$ewins{'emax'} = $arr[10]; #GeV
$energywindowset = "standard";
}
# If NO binning parameters are found use the standard set
else {
print "| Using standard binning for:", $arr[0], " |\n";
print "_________________________________________________\n\n";
$ewins{'bins'} = "200";
$ewins{'emin'} = "0.0005"; #GeV
$ewins{'emax'} = "0.100"; #GeV
$ewins{'sampling_points'} = "200";
$ewins{'sampling_min'} = "0.0005"; #GeV
$ewins{'sampling_max'} = "0.100"; #GeV
$energywindowset = "standard";
}
if ( $ewins{'emax'} > 0.199 and $ewins{'emax'} < 0.201 ) {
$energywindowset = "_he";
print "using high energy window!\n";
}
open( GLOBESFILE, ">$globesfilename" );
# Here we add the globes preamble, with any modifications needed for rebinning taken care of
open( PREAMBLE, "glb/preamble.glb" );
$ready_to_modify = 0;
while (<PREAMBLE>) {
if ( index( $_, "Energy window" ) != -1 ) { $ready_to_modify = 1; }
$ourline = $_;
if ($ready_to_modify) {
keys %ewins
; # reset the internal iterator so a prior each() doesn't affect the loop
while ( my ( $k, $v ) = each %ewins ) {
if ( index( $ourline, $k ) != -1 ) {
@vallist = split /\s+/, $ourline;
$ourline =~ s/$vallist[2]/$v/;
last
; # we have done the replacement, no need to continue
}
} # end while loop over ewin replacements
} # any necessary modification is done
print GLOBESFILE $ourline;
}
close(PREAMBLE);
$fluxfilename = "fluxes/" . $fluxname . ".dat";
unless ( -f $fluxfilename ) {
print "Flux file name ", $fluxfilename, " not found\n";
exit;
}
open( FLUX, "glb/flux.glb" );
while (<FLUX>) {
# Replace the flux file name with the input argument
if (/flux_file/) {
$_ = " \@flux_file= \"" . $fluxfilename . "\"\n";
}
print GLOBESFILE $_;
}
close(FLUX);
# Now go through the channels and put in the relevant lines
# First, smearing for each channel
unless ( -f $chanfilename ) {
print "Channel file name ", $chanfilename, " not found\n";
exit;
}
$output_line =
"include \"smear/". $expt_config . "/smear_"
. $chan_name . "_"
. $expt_config
. ".dat\"\n";
print GLOBESFILE $output_line;
# Detector info
$detfilename = "detector_configurations.dat";
unless ( -f $detfilename ) {
print "Detector file name ", $detfilename, " not found\n";
exit;
}
open( DETFILENAME, $detfilename );
while (<DETFILENAME>) {
chop($_);
# Skip comments
if (/\#/) { next; }
$_ =~ s/\s*//;
$_ =~ s/\s+/ /g;
@stuff_det = split( /\ /, $_ );
$detname = $stuff_det[0];
$masses{$detname} = $stuff_det[1];
$normfact{$detname} = $stuff_det[2];
if ( $detname eq ""
|| $masses{$detname} eq ""
|| $normfact{$detname} eq "" )
{
next;
}
}
close(DETFILENAME);
# Mass and target normalization by species
#%masses = ("sk1",22.5,"sk2",22.5,"100kt15pc",100, "100kt30pc",100,"ar17",17,"scint50kt",50,"halo",1.0);
#%normfact = ("sk1",2/18,"sk2",2/18,"100kt15pc",2/18, "100kt30pc",2/18,"ar17kt",1/40,"scint50kt",2/14,"halo",1/208);
if ( $masses{$expt_config} == 0 ) {
print "Error: please enter a valid experiment configuration\n";
exit;
}
$target_mass =
sprintf( "%13.6f", $masses{$expt_config} * $normfact{$expt_config} )
; # This is ktons of free protons
print "Experiment config: ", $expt_config, " Mass: ",
$masses{$expt_config},
" kton \n";
#print " Target mass: ",$normfact{$expt_config}," ",$target_mass,"\n";
# Add the background smearing here, for the given detector configuration
# (Not yet implemented: for multiple background channels,
# read them from a file labeled by detector configuration)
$do_bg = 0;
$bg_chan_name = "bg_chan";
$bg_filename =
"backgrounds/" . $bg_chan_name . "_" . $expt_config . ".dat";
if ( -e $bg_filename ) {
$do_bg = 1;
print "Using background file ", $bg_filename, "\n";
}
else {
print "No background file for this configuration\n";
}
if ( $do_bg == 1 ) {
$output_line =
"include \"smear/". $expt_config . "/smear_"
. $bg_chan_name . "_"
. $expt_config
. ".dat\"\n";
print GLOBESFILE $output_line;
}
open( DETECTOR, "glb/detector.glb" );
while (<DETECTOR>) {
# Replace the flux file name with the input argument
if (/mass/) {
$_ = "\$target_mass= " . $target_mass . "\n";
}
print GLOBESFILE $_;
}
close(DETECTOR);
print GLOBESFILE "\n /******** Cross-sections *********/\n \n";
# Now the cross-sections. Note that some of these are repeated
# even thougn it is not necessary (xscns for several flavors can be in the
# same file).
# This is just to make a consistent loop over channels.
$output_line = "cross(\#" . $general_id . ")<\n";
print GLOBESFILE $output_line;
$output_line =
" \@cross_file= \"xscns/xs_" . $chan_name . ".dat\"\n";
# print $output_line;
print GLOBESFILE $output_line;
$output_line = "\>\n";
# print $output_line;
print GLOBESFILE $output_line;
# Now the fake bg channel cross section, if it exists
if ( $do_bg == 1 ) {
$output_line = "cross(\#" . $bg_chan_name . ")<\n";
print GLOBESFILE $output_line;
$output_line = " \@cross_file= \"xscns/xs_zero.dat\"\n";
# print $output_line;
print GLOBESFILE $output_line;
$output_line = "\>\n";
# print $output_line;
print GLOBESFILE $output_line;
}
print GLOBESFILE "\n \/******** Channels *********\/\n \n";
# Now, the channel definitions
unless ( -f $chanfilename ) {
print "Channel file name ", $chanfilename, " not found\n";
exit;
}
$chan_name_post = $stuff[0];
$cpstate_post = $stuff[2];
$inflav_post = $stuff[3];
$output_line = "channel(\#" . $general_id . "_signal)<\n";
print GLOBESFILE $output_line;
$output_line =
" \@channel= \#supernova_flux: "
. $cpstate_post . ": "
. $inflav_post
. ": "
. $inflav_post
. ": \#"
. $general_id
. ": \#"
. $chan_name
. "_smear\n";
print GLOBESFILE $output_line;
# Get the post-smearing efficiencies by channel
$eff_file =
"effic/"
. $expt_config
. "/effic_"
. $chan_name_post . "_"
. $expt_config . ".dat";
print $eff_file, "\n";
open( EFF_FILE, $eff_file );
while (<EFF_FILE>) {
$output_line = " \@post_smearing_efficiencies = " . $_;
print GLOBESFILE $output_line;
}
close(EFF_FILE);
# Try crazy reformatting
# or else get mysterious (but apparently harmless?) error from GLoBES
# Should try to track it down... -> error goes away with development GLoBES version
$output_line = "\n\>\n\n";
print GLOBESFILE $output_line;
if ( $do_bg == 1 ) {
# Now make a fake channel for the background (just one possible bg file for now)
# This is dummy info
$cpstate = "-";
$inflav = "e";
$output_line = "channel(\#" . $bg_chan_name . "_signal)<\n";
print GLOBESFILE $output_line;
$output_line =
" \@channel= \#supernova_flux: "
. $cpstate . ": "
. $inflav
. ": "
. $inflav
. ": \#"
. $bg_chan_name
. ": \#"
. $bg_chan_name
. "_smear\n";
# print $output_line;
print GLOBESFILE $output_line;
# Get the pre-smearing backgrounds by channel
$bg_file =
"backgrounds/" . $bg_chan_name . "_" . $expt_config . ".dat";
print $bg_file, "\n";
open( BG_FILE, $bg_file );
while (<BG_FILE>) {
$output_line = " \@pre_smearing_background = " . $_;
print GLOBESFILE $output_line;
}
close(BG_FILE);
# Try crazy reformatting
# or else get mysterious (but apparently harmless?) error from GLoBES
# Should try to track it down... -> error goes away with development GLoBES version
$output_line = "\n\>\n\n";
print GLOBESFILE $output_line;
}
# End-matter
if ( $energywindowset eq "standard" ) {
open( POSTAMBLE, $GLOBAL_POSTAMBLE );
}
elsif ( $energywindowset eq "_he" ) {
open( POSTAMBLE, $GLOBAL_POSTAMBLE );
}
while (<POSTAMBLE>) {
print GLOBESFILE $_;
}
close(POSTAMBLE);
close(GLOBESFILE);
# Now run the executable
$comstring =
$exename . " "
. $fluxname . " "
. $chanfilename . " "
. $expt_config . " "
. $my_chan_num;
system($comstring);
# Now apply channel-weighting factors-- this is the default
unless ( $noweight == 1 ) {
print "Applying channel weighting factors to output\n";
&apply_weights("");
&apply_weights("_smeared");
}