def generateM_dd(p_signal, n_files=100, n_entries=10000): mMs = 1.0 mMs_resolution = 0.01 mMlow = 0.5 mMhigh = 1.5 masses = array.array('d', [0.1, 0.1]) features = ['p1x', 'p1y', 'p1z', 'E1', 'p2x', 'p2y', 'p2z', 'E2'] for n_file in range(n_files + 1): if n_file % 10 == 0: print("n_file : ", n_file) mass, p1x, p1y, p1z, E1, p2x, p2y, p2z, E2 = [], [], [], [], [], [], [], [], [] for n in range(n_entries): choice = random.random() if choice < p_signal: mM = numpy.random.normal(loc=mMs, scale=mMs_resolution) else: mM = numpy.random.uniform(mMlow, mMhigh) MotherMom = TLorentzVector(0.0, 0.0, 0.0, mM) event = TGenPhaseSpace() event.SetDecay(MotherMom, 2, masses) while True: weight = event.Generate() weightmax = event.GetWtMax() assert (0. < weight / weightmax) & (weight / weightmax < 1.) if random.random() < weight / (weightmax): break pd1 = event.GetDecay(0) pd2 = event.GetDecay(1) p1x.append(pd1.Px()) p1y.append(pd1.Py()) p1z.append(pd1.Pz()) E1.append(pd1.E()) p2x.append(pd2.Px()) p2y.append(pd2.Py()) p2z.append(pd2.Pz()) E2.append(pd2.E()) mass.append(mM) df = pd.DataFrame(np.array([p1x, p1y, p1z, E1, p2x, p2y, p2z, E2]).transpose(), columns=features) df2 = pd.DataFrame(np.array([mass]).transpose(), columns=['mM']) #print('df : ', df) if n_file == n_files: n_file = "optimisation_0" #df.to_csv("../data/M-dd/M-dd_{}_res_{}_{}.txt".format(p_signal, mMs_resolution, n_file), sep="\t", header = None, index=False) df2.to_csv("../data/M-dd/M-dd_{}_res_{}_1Dmass_{}.txt".format( p_signal, mMs_resolution, n_file), sep="\t", header=None, index=False)
Theta = ThetaMin + rndm() * (ThetaMax - ThetaMin) vm = TLorentzVector(P * math.sin(Theta) * math.cos(Phi), P * math.sin(Theta) * math.sin(Phi), P * math.cos(Theta), math.sqrt(P * P + MotherMass * MotherMass)) r = abs(gauss(0., VR)) f = rndm() * 2 * math.pi vertex = (Vx + r * math.cos(f), Vy + r * math.sin(f), VzMin + rndm() * (VzMax - VzMin)) parts.append(storeParticle(PDGmother, vm, vertex, 0)) # prepare decay Decay = TGenPhaseSpace() Decay.SetDecay(vm, len(DaughterMass), array('d', DaughterMass)) test = True Decay.Generate() for j, p in enumerate(PDGs): vp = Decay.GetDecay(j) parts.append(storeParticle(p, vp, vertex, 1)) if math.isnan(vp.Px()): test = False if test == False: continue
# check photon pi = pdic[22] if pi.Theta() > ThetaMax: return False pi = pdic[1022] if pi.Theta() > ThetaMax: return False return test # generate with open(fname, "w") as fout: # generate event Event = TGenPhaseSpace() Event.SetDecay(CME, len(FSMasses), array('d', FSMasses)) # loop on events for i in range(1, NEVENTS + 1): # generate event counter = 1 w = Event.Generate() # generate vertex vertex = (VxMin + rndm() * (VxMax - VxMin), VyMin + rndm() * (VyMax - VyMin), VzMin + rndm() * (VzMax - VzMin)) # write header
def decay_Ds(myd): mygen = TGenPhaseSpace() mygen.SetDecay(myd, 2, array.array("d", [mmuon, mmuon])) mygen.Generate() return [mygen.GetDecay(i) for i in range(2)]
proton = pdic[2212] if proton.Theta() < PThetaMin: return False if proton.Theta() > PThetaMax: return False return test h2p = TH2F("hp", "", 180, -180, 180, 180, -180, 180) h2t = TH2F("ht", "", 180, 0, 180, 90, 0, 45) # generate with open(fname, "w") as fout: # generate event Event = TGenPhaseSpace() Event.SetDecay(CME, len(FSMasses), array('d', FSMasses)) # loop on events i = 0 while i < NEVENTS: # generate event counter = 1 w = Event.Generate() # generate vertex vertex = (VxMin + rndm() * (VxMax - VxMin), VyMin + rndm() * (VyMax - VyMin), VzMin + rndm() * (VzMax - VzMin))