def main(): name = "AmC" secBetaArr, secAntiBetaArr = bloader.loadPrmBeta("../data/gamma/" + name + "_J19.txt") print(">>>>>>>>>> Loading primary beta distribution <<<<<<<<<<") mu_arr, sigma_arr = [], [] for i in range(len(secBetaArr)): tmppe, tmpsigma = 0, 0 for j in secBetaArr[i]: if j == 0: break tmppe += eloader.getNPE(j) tmpsigma += eloader.getSPE(j) * eloader.getSPE(j) for j in secAntiBetaArr[i]: if j == 0: break tmppe += eloader.getNPE(j) + 2 * 660.8 tmpsigma += eloader.getSPE(j) * eloader.getSPE(j) + 2 * 27.02**2 tmpsigma = np.sqrt(tmpsigma) mu_arr.append(tmppe) sigma_arr.append(tmpsigma) hist = ROOT.TH2D("hist", "", 100, 8300, 9300, 100, 70, 130) for i, j in zip(mu_arr, sigma_arr): hist.Fill(i, j) hist.SaveAs("AmC_model.root")
def preSampling_inGPU(secBeta, secAntiBeta, indexarr, npearr, spearr, muarr, sigmaarr): # shared memory usage : sNPE = cuda.shared.array(shape=(1, 845), dtype=float32) sSPE = cuda.shared.array(shape=(1, 845), dtype=float32) x, y = cuda.grid(2) # threading positioning tx = cuda.threadIdx.x ty = cuda.blockIdx.x bw = cuda.blockDim.x pos = tx + ty * bw if pos < muarr.size: ii = indexarr[pos] tmpmu, tmpsigma = 0, 0 for j in secBeta[ii, :]: if j == 0: break tmpmu += eloader.getNPE(j) tmpsigma += eloader.getSPE(j)**2 for j in secAntiBeta[ii, :]: if j == 0: break tmpmu += ( eloader.getNPE(j) + 660.8*2 ) tmpsigma += ( eloader.getSPE(j)**2 + 2*27.07**2 ) tmpsigma = np.sqrt(tmpsigma) muarr[pos] = tmpmu sigmaarr[pos] = tmpsigma cuda.syncthreads()
def preSampling(secBeta, secAntiBeta): st = time.time() Nevents = 5000 mu_arr, sigma_arr = [], [] sample_id = np.random.randint(0, 5000, size=Nevents) for ii in sample_id: tmpmu, tmpsigma = 0, 0 for j in secBeta[ii, :]: if j == 0: break tmpmu += eloader.getNPE(j) tmpsigma += eloader.getSPE(j)**2 for j in secAntiBeta[ii, :]: if j == 0: break tmpmu += ( eloader.getNPE(j) + 660.8*2 ) tmpsigma += ( eloader.getSPE(j)**2 + 2*27.07**2 ) tmpsigma = np.sqrt(tmpsigma) mu_arr.append(tmpmu) sigma_arr.append(tmpsigma) et = time.time() mu_arr = np.array(mu_arr) sigma_arr = np.array(sigma_arr) print("Time consumed during pre-sampling: %s s" %(et-st)) return mu_arr, sigma_arr
def calcSingleEvent(self): st = time.time() if self.loadPrmBetaFlag == False: self.loadPrmBeta() mu_arr, sigma_arr = [], [] smu_arr, ssigma_arr = [], [] cmu_arr, csigma_arr = [], [] self.nSamples = len(self.prmBetaArr) for i in range(len(self.prmBetaArr)): tmpnpe, tmpspe = 0, 0 tmpcnpe, tmpsnpe = 0, 0 tmpcspe, tmpsspe = 0, 0 for j in self.prmBetaArr[i]: if j == 0: break if self.mode == "Truth": tmpnpe += (eloader.getNPE(j)) tmpspe += (eloader.getSPE(j)**2) if self.mode == "Fit": tmpnpe += (self.getFitNPE(j)) tmpspe += (self.getFitSPE(j)**2) tmpcnpe += self.getFitCNPE(j) tmpsnpe += self.getFitSNPE(j) for j in self.prmAntiBetaArr[i]: if j == 0: break if self.mode == "Truth": tmpnpe += (eloader.getNPE(j) + 2 * 660.8) tmpspe += (eloader.getSPE(j)**2 + 27.07**2 * 2) if self.mode == "Fit": tmpnpe += (self.getFitNPE(j) + 2 * 660.8) tmpspe += (self.getFitSPE(j)**2 + 27.07**2 * 2) tmpcnpe += (self.getFitCNPE(j) + 2.49) tmpsnpe += (self.getFitSNPE(j) + 2 * 660.8 - 2.49) mu_arr.append(tmpnpe) sigma_arr.append(np.sqrt(tmpspe)) cmu_arr.append(tmpcnpe) csigma_arr.append(np.sqrt(tmpcspe)) smu_arr.append(tmpsnpe) ssigma_arr.append(np.sqrt(tmpsspe)) mu_arr = np.array(mu_arr) sigma_arr = np.array(sigma_arr) cmu_arr = np.array(cmu_arr) csigma_arr = np.array(csigma_arr) smu_arr = np.array(smu_arr) ssigma_arr = np.array(ssigma_arr) et = time.time() #print("Primary beta dist calculation time : %.3f s" %(et-st)) return mu_arr, sigma_arr, smu_arr, ssigma_arr, cmu_arr, csigma_arr
def main(): es = 3134.078 / 2.223 for k in range(315, 380, 1): # Load PrmBeta filename = "../data/gamma/Livermore-" + str(k) + ".txt" print(filename) prmBeta, prmAntiBeta = bloader.loadPrmBeta(filename) # calcSingleEvent : nSamples = 5000 mu_arr, sigma_arr = [], [] for i in range(nSamples): tmpnpe, tmpspe = 0, 0 for j in prmBeta[i]: if j == 0: break tmpnpe += (eloader.getNPE(j)) tmpspe += (eloader.getSPE(j)**2) for j in prmAntiBeta[i]: if j == 0: break tmpnpe += (eloader.getNPE(j) + 2 * 660.8) tmpspe += (eloader.getSPE(j)**2 + 27.07**2 * 2) mu_arr.append(tmpnpe) sigma_arr.append(np.sqrt(tmpspe)) mu = np.array(mu_arr) sigma = np.array(sigma_arr) npe, spe = 0, 0 sigma_part1, sigma_part2 = 0, 0 for i in mu: npe += i npe = npe / nSamples for i, j in zip(mu, sigma): spe += (i - npe)**2 + j**2 sigma_part1 += (i - npe)**2 sigma_part2 += j**2 spe = np.sqrt(spe / nSamples) sigma_part1 /= nSamples sigma_part2 /= nSamples print((k - 300) / 10., npe / es, spe / es)
def GammaPePred(secBeta, secAntiBeta): # two-times sampling alg here sc = 1.00 calcpe = [] ctime = [] sample_id = np.random.randint(0, 5000, size=5000) for i in sample_id: st = time.time() tmppe = 0 for j in secBeta[i]: if j == 0: break tmppe += random.gauss(eloader.getNPE(j), eloader.getSPE(j)*sc) for j in secAntiBeta[i]: if j == 0: break tmppe += random.gauss(eloader.getNPE(j), eloader.getSPE(j)*sc) + 2*random.gauss(660.8, 27.07*sc) calcpe.append(tmppe) et = time.time() ctime.append(et-st) return calcpe, ctime
def main(): totpe, edep = [], [] for i in range(1000, 1300, 1): filename = "/junofs/users/miaoyu/energy_model/production/J19v1r0-Pre4/B12/user-" + str( i) + ".root" print(filename) tmp_totpe, tmp_edep = readSim(filename) totpe.extend(tmp_totpe) for i in range(2000, 2100, 1): filename = "/junofs/users/miaoyu/energy_model/production/J19v1r0-Pre4/B12/user-" + str( i) + ".root" print(filename) tmp_totpe, tmp_edep = readSim(filename) edep.extend(tmp_edep) pe_pred, pe_pred1 = [], [] for i in edep: sample = eloader.getNPE(i) sample1 = 1.126 * eloader.getSctNPE(i) - 0.812 * eloader.getSPE(i) #sample = random.gauss(eloader.getNPE(i), eloader.getSPE(i)) #sample1 = random.gauss((1.126* eloader.getSctNPE(i) - 0.812*eloader.getCerNPE(i)), eloader.getSPE(i)) pe_pred.append(sample) pe_pred1.append(sample1) plt.hist(totpe, bins=300, range=(0, 20000), density=True, histtype="step", label="simulation") plt.hist(pe_pred, bins=300, range=(0, 20000), density=True, histtype="step", label="kA=1, kC=1 (nominal)") plt.hist(pe_pred1, bins=300, range=(0, 20000), density=True, histtype="step", label="kA=1.126, kC=-0.812") plt.legend() plt.xlabel("# P.E.") plt.tight_layout() #plt.savefig("B12_totpe.pdf") plt.show()
#print(el.getFitResol(Evis[-1]), el.getFitCerSigma(Evis[-1]), el.getFitSctSigma(Evis[-1]), el.getFitCov(Evis[-1])) resFit = np.array(resFit) resConstFit = np.array(resConstFit) resCerFit = np.array(resCerFit) resSctFit = np.array(resSctFit) resCovFit = np.array(resCovFit) resCerConstFit = np.array(resCerConstFit) resCovConstFit = np.array(resCovConstFit) # Load Truth Points NPE_truth, SPE_truth = [], [] for i in Edep: NPE_truth.append(el.getNPE(i)) SPE_truth.append(el.getSPE(i)) NPE_truth = np.array(NPE_truth) SPE_truth = np.array(SPE_truth) fig, ax = plt.subplots() #ax.plot(Evis, resFit**2, "-", lw=2, color="crimson", label=r"$\sigma_E^2$") #ax.plot(Evis, resConstFit**2, "--", lw=2, color="crimson", label=r"$\sigma_{const}^2$") ax.plot(Evis, resSctFit**2, "-", lw=2, color="dimgray", label=r"$\sigma_{sct}^2$") ax.plot(Evis,
from matplotlib import gridspec A, kB, kC, p1, p2 = 1408.45, 6.29e-3, 0.991, 0.979, 6.13e-5 if __name__ == "__main__" : globalES = 3134.078/2.223 Edep = np.arange(0.50, 8.10, 0.10) Edep1 = np.arange(0.50, 8.10, 0.50) # load simulation npeSim = [] speSim = [] for i in Edep: npeSim.append(el.getNPE(i)) speSim.append(el.getSPE(i)) npeSim = np.array(npeSim) speSim = np.array(speSim) nonlSim = npeSim / Edep / globalES resSim = speSim/npeSim # fitting results npeCalc = [] npeCalc1 = [] speCalc = [] for i in Edep: sctpe = el.getQPE(i, kB, A) cerpe = kC * el.getCerNPE(i) npeCalc.append((sctpe+cerpe)) speCalc.append(np.sqrt(p1*(sctpe+cerpe) + p2*(sctpe+cerpe)**2)) for i in Edep1: