def PrintChannelRates(self, fluxname, chan, expt_config, *bgfile): # Iterate over interaction channels for i, chan_name in enumerate(chan.name): # Set output file if bgfile: outfile = get_abs_path( f"out/{fluxname}_bg_chan_{expt_config}_events_unweighted.dat" ) else: outfile = get_abs_path( f"out/{fluxname}_{chan_name}_{expt_config}_events_unweighted.dat" ) print(i, outfile) # Ensure the output dir exists os.makedirs(os.path.dirname(outfile), exist_ok=True) with open(outfile, 'w+') as f_out: ret = self.ShowChannelRates(f_out, 0, chan.num[i], lib.GLB_PRE, lib.GLB_WO_EFF, lib.GLB_WO_BG) if bgfile: outfile_smeared = get_abs_path( f"out/{fluxname}_bg_chan_{expt_config}_events_smeared_unweighted.dat" ) else: outfile_smeared = get_abs_path( f"out/{fluxname}_{chan_name}_{expt_config}_events_smeared_unweighted.dat" ) print(i, outfile_smeared) with open(outfile_smeared, 'w+') as f_out_smeared: ret = self.ShowChannelRates(f_out_smeared, 0, chan.num[i], lib.GLB_POST, lib.GLB_W_EFF, lib.GLB_W_BG)
def SetFlux(self, fluxname): self.flux = get_abs_path("glb/flux.glb") fluxfilename = get_abs_path(f"fluxes/{fluxname}.dat") if not os.path.exists(fluxfilename): print(f"Flux file name {fluxfilename} not found") with open(self.flux) as f_in: flux_contents = f_in.read() flux_contents1 = re.sub('{flux}', fluxfilename, flux_contents) self.file_obj.write(flux_contents1)
def SetCrossSections(self, chan): self.file_obj.write("\n /******** Cross-sections ********/\n\n") for chan_name in chan.name: self.file_obj.write(f"cross(#{chan_name})<\n") self.file_obj.write(" @cross_file= \"{}\"\n".format( get_abs_path(f'xscns/xs_{chan_name}.dat'))) self.file_obj.write(">\n") if self.do_bg == True: self.file_obj.write(f"cross(#{self.bg_chan_name})<\n") self.file_obj.write(" @cross_file= \"{}\"\n".format( get_abs_path('xscns/xs_zero.dat'))) self.file_obj.write(">\n")
def SetBackground(self, expt_config): self.do_bg = False self.bg_chan_name = "bg_chan" self.bg_filename = get_abs_path( f"backgrounds/{self.bg_chan_name}_{expt_config}.dat") if os.path.exists(self.bg_filename): self.do_bg = True print(f"Using background file {self.bg_filename}") else: print("No background file for this configuration") if self.do_bg == True: self.file_obj.write("include \"{}\"\n".format( get_abs_path( f'smear/smear_{self.bg_chan_name}_{expt_config}.dat')))
def apply_weights(filename, fluxname, chan, expt_config): for i, chan_name in enumerate(chan.name): unweightedfilename = get_abs_path( f"out/{fluxname}_{chan_name}_{expt_config}_events{filename}_unweighted.dat" ) weightedfilename = get_abs_path( f"out/{fluxname}_{chan_name}_{expt_config}_events{filename}.dat") data = np.genfromtxt(unweightedfilename, comments="--", dtype=float, encoding=None) data[:, 1] *= chan.factor[i] footer = "-------------------------\nTotal: {:f}".format( data[-1, 1]) np.savetxt(weightedfilename, data[:][:-1], fmt=['%1.6f'] + ['%16.6e'], footer=footer, comments='')
def __init__(self, channame): self.channel = channame self.chan_file_name = get_abs_path( f"channels/channels_{self.channel}.dat") data = np.genfromtxt(self.chan_file_name, dtype=None, encoding=None) self.name = [i[0] for i in data] self.num = [i[1] for i in data] self.cp = [i[2] for i in data] self.flav = [i[3] for i in data] self.factor = [i[4] for i in data]
def __init__(self): __slots__ = ('filename', 'config', 'mass', 'norm') self.filename = get_abs_path("detector_configurations.dat") if not os.path.exists(self.filename): print(f"Detector file name {self.filename} not found") data = np.genfromtxt(self.filename, dtype=None, encoding=None) self.config = [i[0] for i in data] self.mass = [i[1] for i in data] self.norm = [i[2] for i in data]
def SetChannels(self, chan, expt_config): self.file_obj.write("\n /********* Channels ********/\n\n") if not os.path.exists(chan.chan_file_name): print("Channel file name {} not found".format(chan.chan_file_name)) for i, chan_name in enumerate(chan.name): self.file_obj.write(f"channel(#{chan_name}_signal)<\n") self.file_obj.write( f" @channel= #supernova_flux: {chan.cp[i]}: {chan.flav[i]}: {chan.flav[i]}: #{chan_name}: #{chan_name}_smear\n" ) eff_file = get_abs_path( f"effic/effic_{chan_name}_{expt_config}.dat") with open(eff_file) as f_in: eff_file_contents = f_in.read() self.file_obj.write( f" @post_smearing_efficiencies = {eff_file_contents}\n" ) self.file_obj.write(">\n\n")
def supernova(fluxname, chan, expt_config): glb = GLB() channel_file_name = chan.chan_file_name if os.path.exists(channel_file_name): print(f"Channels from {channel_file_name}") print(f"Number of channels found: {len(chan.name)}") else: print("Cannot open channel file") true_values = glb.AllocParams() test_values = glb.AllocParams() theta12 = 0 theta13 = 0 theta23 = 0 deltacp = 0 sdm = 0 ldm = 0 glb.DefineParams(true_values, theta12, theta13, theta23, deltacp, sdm, ldm) glb.SetDensityParams(true_values, 1.0, lib.GLB_ALL) glb.DefineParams(test_values, theta12, theta13, theta23, deltacp, sdm, ldm) glb.SetDensityParams(test_values, 1.0, lib.GLB_ALL) glb.SetOscillationParams(true_values) glb.SetRates() glb.PrintChannelRates(fluxname, chan, expt_config) bgfile = get_abs_path(f'backgrounds/bg_chan_{expt_config}.dat') if os.path.exists(bgfile): bg_file = True glb.PrintChannelRates(fluxname, chan, expt_config, bg_file) else: print("No background file") glb.FreeParams(true_values) glb.FreeParams(test_values) return(0)
def SetSmearing(self, chan, expt_config): for chan_name in chan.name: output_line = "include \"{}\"\n".format( get_abs_path(f'smear/smear_{chan_name}_{expt_config}.dat')) self.file_obj.write(output_line)
def Preamble(self): self.preamble = get_abs_path("glb/preamble.glb") with open(self.preamble) as f_in: preamble_contents = f_in.read() self.file_obj.write(preamble_contents)