5
except Exception, error:
7
print "ERROR: This parameter scanning script requires numpy, which is not installed"
15
maddm_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]
16
pieces = maddm_path.split('/')
17
#MAKE SURE TO ADD REAL AND COMPLEX FOLDERS TO PATH
18
maddm_path = maddm_path.replace(pieces[-1], '')
19
sys.path.append(maddm_path)
22
from darkmatter import *
24
#Read in the DM information
25
with open('dm_object.pik', 'r') as f:
28
#Change the directory to MadDM root folder so that code can run properly.
31
#Print out some basic information about the dark matter particle.
32
print "--------------------------------------------"
33
print "Model: "+dm._modelname
34
print "Project Name: "+dm._projectname
35
print "Project Path: "+dm._projectpath
36
print "Parameter Card: "+dm._paramcard
37
print "DM particles: "+dm._dm_particles[0].get('name')
38
print "DM spin (2s+1): "+str(dm._dm_particles[0].get('spin'))
39
print "--------------------------------------------"
41
#-------------------------------------------------------------------------
42
#-------------------------------------------------------------------------
43
#CHANGE THIS PART FOR YOUR PARAMETER SCAN
44
#-------------------------------------------------------------------------
45
#-------------------------------------------------------------------------
46
#Add as many for loops as you wish to scan over parameters
47
#NOTE: The default script varies over two parameters (param1 and param2), and outputs the
48
# results in the format "param1 param2 omegah^2 ..." on the screen and in the output file.
49
# Please make sure to change the number of "for" loops, calls to ChangeParameter() and the
50
# output commands to account for the number of parameters you wish to vary. The critical
51
# places where changes are usually required are marked with "<-----Change here ----!!!"
54
#Define the arrays of values your parameters should take.
55
#If you are using np.arrange, the format is np.arange(init_val, final_val, step_size)
56
param1_name = 'parameter1' #"<-----Change here ----!!!"
57
param2_name = 'parameter2' #"<-----Change here ----!!!"
58
param1_values = np.arange(0.001, 0.501, 0.01) #"<-----Change here ----!!!"
59
param2_values = np.arange(0.001, 0.501, 0.01) #"<-----Change here ----!!!"
61
#File in which to write the output.
62
outputfile_name = dm._projectpath+"/output/parameter_scan.txt" #"<-----Change here ----!!!"
64
#Check if the file already exists.
65
if os.path.exists(outputfile_name):
67
while (not legit_answer):
68
answer = raw_input("Output file already exists. Overwrite?[n] (y/n):")
69
if ((answer == 'y') or (answer == 'Y')):
71
if ((answer == 'n') or (answer == 'N') or (answer == '')):
73
print "Nothing to do... exiting."
76
outputfile = open(outputfile_name, "w")
78
for param1 in param1_values:
79
for param2 in param2_values: #"<-----Change here ----!!!" (you can add additional loops)
80
#Change the parameter with name param1_name in the param_card.dat to the value param1
81
dm.ChangeParameter(param1_name, param1)
82
#Change the parameter with name param2_name in the param_card.dat to the value param2
83
dm.ChangeParameter(param2_name, param2)
84
#Calculate relic density, spin independent/dependent scattering cross sections ...
85
[omegah2, x_freezeout, wimp_mass, sigmav_xf, sigmaN_SI_proton, sigmaN_SI_neutron, \
86
sigmaN_SD_proton, sigmaN_SD_neutron, Nevents, sm_switch] = dm.Calculate()
88
#Output the results on the screen and in the output file
89
print param1, param2, omegah2, x_freezeout, sigmav_xf, sigmaN_SI_proton, sigmaN_SI_neutron, \
90
sigmaN_SD_proton, sigmaN_SD_neutron, Nevents #"<-----Change here ----!!!"
91
outputstring = " %.3e %.3e %.3e %.3e %.3e %.3e %.3e %.3e %.3e %.3e \n" % \
92
(param1, param2, omegah2, x_freezeout, sigmav_xf, sigmaN_SI_proton*GeV2pb, sigmaN_SI_neutron*GeV2pb, \
93
sigmaN_SD_proton*GeV2pb, sigmaN_SD_neutron*GeV2pb, Nevents)#"<-----Change here ----!!!"
94
outputfile.write(outputstring)
96
#If you are generating the recoil rate distributions, angular distributions etc.
97
#the following part of the code will change the output file names so that they
98
#are not overwritten. For instance, it will move 'rate.dat' to rate_param1_param2.dat
99
if dm._do_directional_detection:
100
suffix = "_"+str(param1)+"_"+str(param2)+".dat"
101
shutil.move(dm._projectpath+"/output/d2NdEdcos.dat", dm._projectpath+"/output/d2NdEdcos"+suffix)
102
shutil.move(dm._projectpath+"/output/dNdE.dat", dm._projectpath+"/output/dNdE"+suffix)
103
shutil.move(dm._projectpath+"/output/dNdcos.dat", dm._projectpath+"/output/dNdcos"+suffix)
104
shutil.move(dm._projectpath+"/output/rate.dat", dm._projectpath+"/output/rate"+suffix)
107
#---------------------------------------------------------------------------
108
#-------------------------------------------------------------------------