def get_norm_spectra(iso, lab, mass): print "Extracting: ",iso, lab, "mWIMP=",mass data = np.loadtxt("{0}/Xe{1}/Xe{1}_{2}.dat".format(pathtodat,iso,lab)) print "Normalising spectrum for Xe iso={0}, operator={1}, mWIMP={2}".format(iso,lab,mass) index = np.where(masses==mass)[0][0]+1 #first column is ER spectrum = data[:,[0,index]] scaled_spectrum, c = ns.normalise_spectrum(spectrum,exposure,normrate=5) # output normalised spectrum to file np.savetxt("{0}/Xe{1}_{2}_M={3}GeV_EinkeV_sumdRdE=1.dat".format(pathtodat,iso,lab,mass),scaled_spectrum) #double check data = np.loadtxt("{0}/Xe{1}_{2}_M={3}GeV_EinkeV_sumdRdE=1.dat".format(pathtodat,iso,lab,mass)) fig = plt.figure() #figsize=(8,6)) ax = fig.add_subplot(111) ax.plot(scaled_spectrum["ER"], scaled_spectrum["dRdE"]) ax.plot(data[:,0],data[:,1]) ax.set_xlabel("Recoil energy (keV)") ax.set_ylabel("dR/dE (per keV)") fig.savefig("{0}/Xe{1}_{2}_M={3}GeV_EinkeV_sumdRdE=1.png".format(pathtodat,iso,lab,mass))
#newtable += ["{0:{1}}".format("",3)+" | " + " | ".join("{0:{1}d}".format(x,9) for x in masses) + " |"] return newtable table = [] for O in operators: rowa = [] rowb = [] rowc = [] for m in masses: print "Extracting: ",iso, O, "mWIMP=",m data = np.loadtxt("{0}/Xe{1}/Xe{1}_{2}.dat".format(pathtodat,iso,O)) print "Normalising spectrum for Xe iso={0}, operator={1}, mWIMP={2}".format(iso,O,m) index = np.where(allmasses==m)[0][0]+1 #first column is ER print index spectrum = data[:,[0,index]] scaled_spectrum, c1a = ns.normalise_spectrum(spectrum,exposure,normrate=Nevents,normrange=(8,30),verbose=True) scaled_spectrum, c1b = ns.normalise_spectrum(spectrum,exposure,normrate=Nevents,normrange=(8,240),verbose=True) scaled_spectrum, c1c = ns.normalise_spectrum(spectrum,exposure,normrate=Nevents,normrange=(8,1000),verbose=True) c1a2 = c1a**2 c1b2 = c1b**2 c1c2 = c1c**2 # Sanity check: # should have c1a2 > c1b2 > c1c2 if (c1c2 > c1b2) or (c1c2 > c1a2): raise ValueError("Relative coupling sizes make no sense! Should have c1a^2 > c1b^2 > c1c^2, but have instead {0},{1},{2}".format(c1a2,c1b2,c1c2)) if c1a**2>2*c1b**2: c1b2 = -c1b**2 if c1b**2>1.2*c1c**2: c1c2 = -c1c**2 rowa+=[c1a2] rowb+=[c1b2]