def removeCoreOffEvents(self): ''' Code defines the first shutoff days for each reactor. Then, goes through the experiment, bin by bin, and re-shoots a value for each bin with the average scaled by how many days the reactor was off for that bin. ''' #generate the days that each reactor shuts off core_shutoffs = {'Core_1': [], 'Core_2': []} for core in core_shutoffs: if core == self.unknown_core: shutoff_day = UNKNOWN_FIRSTOFF else: shutoff_day = KNOWN_FIRSTOFF core_shutoffs[core].append(shutoff_day) while ((shutoff_day + self.uptime) < (self.totaldays - self.offtime)): shutoff_day = (shutoff_day + self.offtime) + self.uptime core_shutoffs[core].append(shutoff_day) print("CORE SHUTOFF DAYS: " + str(core_shutoffs)) #Now, go through each bin of core data and remove the appropriate #portion of reactor flux for the shutoff for core in core_shutoffs: for shutdown_day in core_shutoffs[core]: OT_complete = False for j, daybin in enumerate(self.experiment_days): flux_scaler = 1.0 #Stays 1 if no off-days in bin #If a shutdown happened, scale the events according to #Days on before offtime begins if shutdown_day < daybin: dayson_beforeOT = self.resolution - (daybin - shutdown_day) if dayson_beforeOT > 0: flux_scaler = (float(dayson_beforeOT) / float(self.resolution)) else: flux_scaler = 0 #If a reactor started back up, add back the proper #flux ratio if ((shutdown_day + self.offtime) < daybin): dayson_afterOT = daybin - (shutdown_day + self.offtime) flux_scaler += (float(dayson_afterOT) / float(self.resolution)) OT_complete = True #After calculating how much this bin should be scaled for #This day, re-fire the bin value if re-scaled #statistics are needed if flux_scaler < 1.0: if core == self.unknown_core: self.unknown_core_events[j] = pd.RandShoot_p( (flux_scaler * self.unknown_core_binavg), 1) else: self.known_core_events[j] = pd.RandShoot_p( \ (flux_scaler * self.known_core_binavg), 1) if OT_complete: break
def BootstrapCL(self, CL, n): ''' Assuming the a,b,c, and d boxes are means on the true bifurcation box values, re-shoots n values for the boxes and calculates y1y2 using the avg_y1y2 equation. The the upper limit on the contamination y1y2Beta is then calculated to the given CL (between 0 and 1). ''' #Using the bifurcation boxes as averages, shoot values for a,b,c, and d #assuming poisson fluctuations. Calculated background assuming #bkg = b + c + d ashot = pd.RandShoot_p(self.a, n) bshot = pd.RandShoot_p(self.b, n) cshot = pd.RandShoot_p(self.c, n) dshot = pd.RandShoot_p(self.d, n) bkgevts = bshot + cshot + dshot #see how many results have no background (beta=0). These will have an #estimated zero contamination. Trying to run the calculation will result #in code-breaking infinities. Delete the elements and add zeros to #y1y2 later. divzeros = np.where(bkgevts == 0)[0] print("DIVZEROS: " + str(divzeros)) numdivzeros = len(divzeros) ashot = np.delete(ashot, divzeros) bshot = np.delete(bshot, divzeros) cshot = np.delete(cshot, divzeros) dshot = np.delete(dshot, divzeros) bkgevts = np.delete(bkgevts, divzeros) n_nonz = n - numdivzeros #Now shoot values for x1 and x2 assuming a Gaussian prior x1_shot = pd.RandShoot(self.x1, self.x1_unc, n_nonz) x2_shot = pd.RandShoot(self.x2, self.x2_unc, n_nonz) #Calculate all y1y2 values given the re-shot values _avg_y1y2s = self._avg_y1y2(ashot, bshot, cshot, x1_shot, x2_shot, bkgevts) _avg_y1y2Bs = _avg_y1y2s * bkgevts #Add estimated background of zero for events with no background back zero_results = np.zeros(numdivzeros) _avg_y1y2Bs = np.sort(np.append(_avg_y1y2Bs, zero_results)) _avg_y1y2s = np.sort(np.append(_avg_y1y2s, zero_results)) #Find the y1y2 and y1y2B value associated with the input confidence limit y1y2B_CL = _avg_y1y2Bs[int(float(CL) * float(len(_avg_y1y2Bs)))] y1y2_CL = _avg_y1y2s[int(float(CL) * float(len(_avg_y1y2s)))] self.contamination_summary["CL"] = CL self.contamination_summary["y1y2_to_CL"] = y1y2_CL self.contamination_summary["y1y2B_to_CL"] = y1y2B_CL return _avg_y1y2Bs
def generateCoreEvents(self): core_signal_dict = {} core_binavg_dict = {} for signal in self.signals: if signal in CORE_NAMES: core_binavg = self.signals[signal] * float(self.resolution) binned_events = pd.RandShoot_p(core_binavg, self.numcycles) core_signal_dict[signal] = binned_events core_binavg_dict[signal] = core_binavg for core in core_signal_dict: if core == self.unknown_core: self.unknown_core_events = core_signal_dict[core] self.unknown_core_binavg = core_binavg_dict[core] else: self.known_core_events = core_signal_dict[core] self.known_core_binavg = core_binavg_dict[core]
def generateNRBKG(self): bkg_signal_dict = {} avg_NRbackground = 0. #In events/day #Fire average events for each non-reactor BKG signal for each day for signal in self.signals: if signal not in self.allcores: avg_events = self.signals[signal] avg_NRbackground = avg_NRbackground + avg_events events = pd.RandShoot_p(avg_events, self.totaldays) bkg_signal_dict[signal] = events self.avg_NRbackground = avg_NRbackground self.NR_bkg = [] #clear out NR_bkg if already filled previously self.NR_bkg_unc = [] for bkg_signal in bkg_signal_dict: self.NR_bkg.append(bkg_signal_dict[bkg_signal]) self.NR_bkg = np.sum(self.NR_bkg, axis=0) self.NR_bkg_unc = np.sqrt(self.NR_bkg)
def generateNRBKG(self): bkg_signal_dict = {} avg_NRbackground = 0. #In events/day #Fire average events for each for signal in self.signals: if signal not in CORE_NAMES: avg_events = self.signals[signal] * self.resolution avg_NRbackground = avg_NRbackground + avg_events events = pd.RandShoot_p(avg_events, self.numcycles) bkg_signal_dict[signal] = events self.avg_NRbackground = avg_NRbackground self.NR_bkg = [] #clear out NR_bkg if already filled previously for bkg_signal in bkg_signal_dict: self.NR_bkg.append(bkg_signal_dict[bkg_signal]) self.NR_bkg = np.sum(self.NR_bkg, axis=0) self.NR_bkg_unc = [] self.NR_bkg_unc = np.sqrt(self.NR_bkg)
def generateCoreEvents(self): core_signal_dict = {} core_binavg_dict = {} for signal in self.signals: if signal in self.allcores: core_binavg = self.signals[signal] binned_events = pd.RandShoot_p(core_binavg, self.totaldays) if self.killreacs != None: binned_events = self.stripSDDays(binned_events) core_signal_dict[signal] = binned_events core_binavg_dict[signal] = core_binavg for core in core_signal_dict: if core in self.coredict["known_cores"]: self.known_core_events = core_signal_dict[core] self.known_core_binavg = core_binavg_dict[core] elif core in self.coredict["unknown_cores"]: self.unknown_core_events = core_signal_dict[core] self.unknown_core_binavg = core_binavg_dict[core]
def generateCoreEvents(self): #average events/day (binavg) arrays and random shoot events/day core_signal_dict = {} core_binavg_dict = {} for signal in self.signals: if signal in self.allcores: core_binavg = self.signals[signal] core_events = pd.RandShoot_p(core_binavg, self.totaldays) for j, killcore in enumerate(self.killreacs): if signal == killcore: core_events = self.stripSDDays(core_events, self.killdays[j]) core_signal_dict[signal] = core_events core_binavg_dict[signal] = core_binavg #Place the values into their proper class containers for core in core_signal_dict: if core in self.coredict["known_cores"]: self.known_core_events[core] = core_signal_dict[core] self.known_core_binavg += core_binavg_dict[core] elif core in self.coredict["unknown_cores"]: self.unknown_core_events[core] = core_signal_dict[core] self.unknown_core_binavg += core_binavg_dict[core]