From 5aec7c4c7a1ca4f838e4ef911ff2bbaa07e9fb96 Mon Sep 17 00:00:00 2001 From: amanmdesai Date: Mon, 26 Jun 2023 06:44:15 +0530 Subject: [PATCH 1/5] update cross section --- pymcabc/cross_section.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pymcabc/cross_section.py b/pymcabc/cross_section.py index c438575..67144ed 100644 --- a/pymcabc/cross_section.py +++ b/pymcabc/cross_section.py @@ -23,7 +23,12 @@ def __init__(self): def s_channel(self): """definition for s channel""" - return (self.g**2) / (self.Ecm**2 - self.mx**2) + deno = self.Ecm**2 - self.mx**2 + if abs(deno) <= 0.01: + return (self.g**2) / (deno + 100) + else: + return (self.g**2) / deno + def t_channel(self, costh, pf): """definition for t channel""" @@ -134,7 +139,7 @@ def calc_xsection(self, N: int = 40000): w_square = library["w_square"][0] w_max = library["w_max"][0] sigma_x = w_sum * pymcabc.constants.convert / (N * 1e12) - variance = math.sqrt(w_square / N - (w_sum / N) ** 2) # barn unit + variance = math.sqrt(abs(w_square / N - (w_sum / N) ** 2)) # barn unit error = ( variance * pymcabc.constants.convert / (math.sqrt(N) * 1e12) ) # barn unit From a1d23c5c66bc76bf6fb395f1719c2b705312a3e5 Mon Sep 17 00:00:00 2001 From: amanmdesai Date: Mon, 26 Jun 2023 06:44:27 +0530 Subject: [PATCH 2/5] update identify process to include channel --- pymcabc/identify_process.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pymcabc/identify_process.py b/pymcabc/identify_process.py index 2399dd6..bd626a2 100644 --- a/pymcabc/identify_process.py +++ b/pymcabc/identify_process.py @@ -80,6 +80,7 @@ def __init__( self.library["mC"].append(mC) self.library["channel"].append(channel) self.process() + self.channel() self.masses() self.ECM() self.identify_mediator() @@ -105,6 +106,13 @@ def process(self): json.dump(self.library, f) return None + def channel(self): + process_type = self.library["process_type"][0] + channel = self.library["channel"][0] + if channel not in process_type: + raise Exception("Channel " +channel + " not available for process type "+process_type) + return None + def masses(self): """assign masses to m1, m2, m3, m4 and mediator""" string = self.input_string.replace(" > ", " ") From 324b8ec671cda1e9d8a400adc533103cb7e754b0 Mon Sep 17 00:00:00 2001 From: amanmdesai Date: Mon, 26 Jun 2023 06:58:06 +0530 Subject: [PATCH 3/5] update identify --- pymcabc/identify_process.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymcabc/identify_process.py b/pymcabc/identify_process.py index bd626a2..9fff689 100644 --- a/pymcabc/identify_process.py +++ b/pymcabc/identify_process.py @@ -109,8 +109,9 @@ def process(self): def channel(self): process_type = self.library["process_type"][0] channel = self.library["channel"][0] - if channel not in process_type: - raise Exception("Channel " +channel + " not available for process type "+process_type) + if channel != "none": + if channel not in process_type: + raise Exception("Channel " +channel + " not available for process type "+process_type) return None def masses(self): From faa72b6b1a7ff704d29f4b17062dabe3850788d9 Mon Sep 17 00:00:00 2001 From: amanmdesai Date: Mon, 26 Jun 2023 07:35:56 +0530 Subject: [PATCH 4/5] update formatting --- pymcabc/cross_section.py | 1 - pymcabc/decay_particle.py | 71 ++++++++++++++++++++----------------- pymcabc/detector.py | 38 ++++++++++++-------- pymcabc/feynman_diagram.py | 6 ++-- pymcabc/identify_process.py | 11 +++--- pymcabc/particle.py | 17 ++++----- pymcabc/plotting.py | 2 +- pymcabc/save_events.py | 47 +++++++++++++++--------- tests/test_boost.py | 7 ++-- tests/test_crosssection.py | 9 +++-- tests/test_evengen.py | 47 +++++++++++++----------- tests/test_identify.py | 13 ++++--- tests/test_plot.py | 13 +++---- 13 files changed, 159 insertions(+), 123 deletions(-) diff --git a/pymcabc/cross_section.py b/pymcabc/cross_section.py index 67144ed..50429e1 100644 --- a/pymcabc/cross_section.py +++ b/pymcabc/cross_section.py @@ -29,7 +29,6 @@ def s_channel(self): else: return (self.g**2) / deno - def t_channel(self, costh, pf): """definition for t channel""" deno = ( diff --git a/pymcabc/decay_particle.py b/pymcabc/decay_particle.py index af977cf..bdf676e 100644 --- a/pymcabc/decay_particle.py +++ b/pymcabc/decay_particle.py @@ -24,27 +24,32 @@ def __init__(self): def rotate(self, pdecay: Particle): """rotate particle""" - costh = (2*random.random()) - 1 + costh = (2 * random.random()) - 1 sinth = math.sqrt(1 - costh**2) phi = 2 * math.pi * random.random() sinPhi = math.sin(phi) cosPhi = math.cos(phi) - pdecay_out = Particle(0,0,0,0) - pdecay_out.px = pdecay.pz * sinth *cosPhi - pdecay_out.py = pdecay.pz * sinth *sinPhi + pdecay_out = Particle(0, 0, 0, 0) + pdecay_out.px = pdecay.pz * sinth * cosPhi + pdecay_out.py = pdecay.pz * sinth * sinPhi pdecay_out.pz = pdecay.pz * costh - pdecay_out.E = pdecay.E - + pdecay_out.E = pdecay.E + return pdecay_out def decay(self, top: Particle): """decay particle""" - E1 = (top.mass()**2 - self.decay2_mass**2 + self.decay1_mass**2)/(2*top.mass()) - - E2 = top.mass() - E1 + E1 = (top.mass() ** 2 - self.decay2_mass**2 + self.decay1_mass**2) / ( + 2 * top.mass() + ) + + E2 = top.mass() - E1 - self.decay_p = math.sqrt((top.mass()**2 - (self.decay1_mass + self.decay2_mass)**2) * (top.mass()**2 - (self.decay1_mass - self.decay2_mass)**2)) / (2*top.mass()) + self.decay_p = math.sqrt( + (top.mass() ** 2 - (self.decay1_mass + self.decay2_mass) ** 2) + * (top.mass() ** 2 - (self.decay1_mass - self.decay2_mass) ** 2) + ) / (2 * top.mass()) """ self.decay_p = ( @@ -71,15 +76,15 @@ def decay(self, top: Particle): ) """ - decay1 = Particle(0,0,0,0) - decay2 = Particle(0,0,0,0) + decay1 = Particle(0, 0, 0, 0) + decay2 = Particle(0, 0, 0, 0) decay1.set4momenta(E1, 0, 0, self.decay_p) decay2.set4momenta(E2, 0, 0, -self.decay_p) decay1 = self.rotate(decay1) decay2.set4momenta(E2, -decay1.px, -decay1.py, -decay1.pz) - #decay2 = self.rotate(decay2) + # decay2 = self.rotate(decay2) return decay1, decay2 @@ -94,26 +99,25 @@ def prepare_decay(self, top: Particle): # decay_process = decay_process.replace(" < "," ") # decay_process = decay_process.split(" ") # print(top.mass()[0], self.massive) - decay_array1_px = [0]*len(top.px) - decay_array1_py = [0]*len(top.px) - decay_array1_pz = [0]*len(top.px) - decay_array1_E = [0]*len(top.px) + decay_array1_px = [0] * len(top.px) + decay_array1_py = [0] * len(top.px) + decay_array1_pz = [0] * len(top.px) + decay_array1_E = [0] * len(top.px) - decay_array2_px = [0]*len(top.px) - decay_array2_py = [0]*len(top.px) - decay_array2_pz = [0]*len(top.px) - decay_array2_E = [0]*len(top.px) + decay_array2_px = [0] * len(top.px) + decay_array2_py = [0] * len(top.px) + decay_array2_pz = [0] * len(top.px) + decay_array2_E = [0] * len(top.px) for i in range(len(top.px)): - heavy_state = Particle(top.E[i],top.px[i], top.py[i],top.pz[i]) - if self.nearlyequal(heavy_state.mass(), self.massive) and heavy_state.mass() > ( - self.decay1_mass + self.decay2_mass - ): - + heavy_state = Particle(top.E[i], top.px[i], top.py[i], top.pz[i]) + if self.nearlyequal( + heavy_state.mass(), self.massive + ) and heavy_state.mass() > (self.decay1_mass + self.decay2_mass): decay1, decay2 = self.decay(heavy_state) decay1 = decay1.boost(heavy_state) decay2 = decay2.boost(heavy_state) - + decay_array1_px[i] = decay1.px decay_array1_py[i] = decay1.py decay_array1_pz[i] = decay1.pz @@ -134,10 +138,11 @@ def prepare_decay(self, top: Particle): decay_array2_py[i] = output decay_array2_pz[i] = output decay_array2_E[i] = output - - decay1 = Particle(decay_array1_E,decay_array1_px, decay_array1_py, decay_array1_pz) - decay2 = Particle(decay_array2_E,decay_array2_px, decay_array2_py, decay_array2_pz) - return decay1, decay2 - - + decay1 = Particle( + decay_array1_E, decay_array1_px, decay_array1_py, decay_array1_pz + ) + decay2 = Particle( + decay_array2_E, decay_array2_px, decay_array2_py, decay_array2_pz + ) + return decay1, decay2 diff --git a/pymcabc/detector.py b/pymcabc/detector.py index 441b4e9..f2e13b4 100644 --- a/pymcabc/detector.py +++ b/pymcabc/detector.py @@ -5,7 +5,8 @@ class Detector: """Applies gaussian smearing on E and momenta""" - def __init__(self, sigma: float =1., factor: float =1.): + + def __init__(self, sigma: float = 1.0, factor: float = 1.0): self.sigma = sigma self.factor = factor @@ -20,28 +21,35 @@ def gauss_smear(self, particle: Particle): if particle.px[0] == -9 and particle.py[0] == -9: return particle else: - output_px = [0]*len(particle.px) - output_py = [0]*len(particle.px) - output_pz = [0]*len(particle.px) - output_E = [0]*len(particle.px) + output_px = [0] * len(particle.px) + output_py = [0] * len(particle.px) + output_pz = [0] * len(particle.px) + output_E = [0] * len(particle.px) for i in range(len(particle.px)): - - momentum = math.sqrt(particle.px[i]**2 + particle.py[i]**2 + particle.pz[i]**2 ) - random_measure_momentum = random.gauss(momentum, self.factor*self.sigma) / momentum - random_measure_energy = random.gauss(particle.E[i], self.sigma) / particle.E[i] - - output_px[i] = random_measure_momentum*particle.px[i] - output_py[i] = random_measure_momentum*particle.py[i] - output_pz[i] = random_measure_momentum*particle.pz[i] + momentum = math.sqrt( + particle.px[i] ** 2 + particle.py[i] ** 2 + particle.pz[i] ** 2 + ) + random_measure_momentum = ( + random.gauss(momentum, self.factor * self.sigma) / momentum + ) + random_measure_energy = ( + random.gauss(particle.E[i], self.sigma) / particle.E[i] + ) + + output_px[i] = random_measure_momentum * particle.px[i] + output_py[i] = random_measure_momentum * particle.py[i] + output_pz[i] = random_measure_momentum * particle.pz[i] - output_E[i] = random_measure_energy*particle.E[i] + output_E[i] = random_measure_energy * particle.E[i] """output_px[i] = random.gauss(particle.px[i], self.sigma) output_py[i] = random.gauss(particle.py[i], self.sigma) output_pz[i] = random.gauss(particle.pz[i], self.sigma) output_E[i] = random.gauss(particle.E[i], self.sigma) """ - mass = (output_E[i]**2 - (output_px[i]**2 + output_py[i]**2 +output_pz[i]**2 )) + mass = output_E[i] ** 2 - ( + output_px[i] ** 2 + output_py[i] ** 2 + output_pz[i] ** 2 + ) print(mass) particle_output = Particle(output_E, output_px, output_py, output_pz) return particle_output diff --git a/pymcabc/feynman_diagram.py b/pymcabc/feynman_diagram.py index 3d788e7..874bf84 100644 --- a/pymcabc/feynman_diagram.py +++ b/pymcabc/feynman_diagram.py @@ -31,11 +31,11 @@ def __init__(self): return 0 else: if channel == "s": - self.s_chan() + self.s_chan() if channel == "t": - self.t_chan() + self.t_chan() if channel == "u": - self.u_chan() + self.u_chan() else: print("Possible channels: s, t, and u") return diff --git a/pymcabc/identify_process.py b/pymcabc/identify_process.py index 9fff689..6f17960 100644 --- a/pymcabc/identify_process.py +++ b/pymcabc/identify_process.py @@ -41,8 +41,6 @@ class DefineProcess: mC (float): mass of particle C Ecm (float): center of mass energy channel (str): optional, use to study effect a particular channel - - """ def __init__( @@ -63,8 +61,6 @@ def __init__( mC (float): mass of particle C Ecm (float): center of mass energy channel (str): optional, use to study effect a particular channel - - """ build_json() @@ -111,7 +107,12 @@ def channel(self): channel = self.library["channel"][0] if channel != "none": if channel not in process_type: - raise Exception("Channel " +channel + " not available for process type "+process_type) + raise Exception( + "Channel " + + channel + + " not available for process type " + + process_type + ) return None def masses(self): diff --git a/pymcabc/particle.py b/pymcabc/particle.py index fe1cfcb..f15a7ad 100644 --- a/pymcabc/particle.py +++ b/pymcabc/particle.py @@ -67,9 +67,11 @@ def mass(self): else: x = math.sqrt(x) except: - x = [0]*len(self.px) + x = [0] * len(self.px) for i in range(len(x)): - x[i] = self.E[i]**2 - self.px[i]**2 - self.py[i]**2 - self.pz[i]**2 + x[i] = ( + self.E[i] ** 2 - self.px[i] ** 2 - self.py[i] ** 2 - self.pz[i] ** 2 + ) print(x[i]) if x[i] < 0: x[i] = 0 @@ -91,21 +93,20 @@ def boost(self, other): other is used to boost """ - new = Particle(0., 0., 0., 0.) - new_other = Particle(0., 0., 0., 0.) - + new = Particle(0.0, 0.0, 0.0, 0.0) + new_other = Particle(0.0, 0.0, 0.0, 0.0) + new_other.set4momenta( other.E, other.px / other.E, other.py / other.E, other.pz / other.E ) beta = new_other.p2() gamma = 1.0 / math.sqrt(1.0 - beta) - if beta>0: + if beta > 0: gamma_2 = (gamma - 1.0) / beta else: gamma_2 = 0.0 - dotproduct = ( self.px * new_other.px + self.py * new_other.py + self.pz * new_other.pz ) @@ -113,4 +114,4 @@ def boost(self, other): new.py = self.py + (gamma_2 * dotproduct + gamma * self.E) * new_other.py new.pz = self.pz + (gamma_2 * dotproduct + gamma * self.E) * new_other.pz new.E = gamma * (self.E + dotproduct) - return new \ No newline at end of file + return new diff --git a/pymcabc/plotting.py b/pymcabc/plotting.py index bd1a71a..01e9479 100644 --- a/pymcabc/plotting.py +++ b/pymcabc/plotting.py @@ -16,7 +16,7 @@ def plot(data, key): label = key.replace("_", " ") plt.xlabel(label) plt.ylabel("Events") - #plt.show() + # plt.show() plt.savefig(key + ".png") def file(filename="ABC_events.root"): diff --git a/pymcabc/save_events.py b/pymcabc/save_events.py index 3efa8ce..fa59606 100644 --- a/pymcabc/save_events.py +++ b/pymcabc/save_events.py @@ -24,8 +24,8 @@ def __init__( boolDecay: bool = True, boolDetector: bool = True, boolTruth: bool = True, - detector_sigma = 1., - detector_factor=1., + detector_sigma=1.0, + detector_factor=1.0, ): """ saving events @@ -36,8 +36,8 @@ def __init__( boolTruth (bool): optional. save truth events """ self.Nevent = Nevent - self.detector_sigma = detector_sigma - self.detector_factor = detector_factor + self.detector_sigma = detector_sigma + self.detector_factor = detector_factor with open("library.json", "r") as f: library = json.load(f) @@ -92,8 +92,12 @@ def to_root(self, name: str = "ABC_events.root"): if self.boolDecay == False or self.decay_process == "NaN": if self.boolDetector == True: - self.top1 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top1) - self.top2 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top2) + self.top1 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(self.top1) + self.top2 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(self.top2) file = uproot.recreate(name) file["events"] = { @@ -113,18 +117,29 @@ def to_root(self, name: str = "ABC_events.root"): decay1, decay2 = DecayParticle().prepare_decay(top1) decay3, decay4 = DecayParticle().prepare_decay(top2) if self.boolDetector == True: - if decay1.px[0] == -9 and decay1.E[0] == -9: - self.top1 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top1) + self.top1 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(self.top1) if decay2.px[0] == -9 and decay2.E[0] == -9: - self.top2 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top2) - #self.top1 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top1) - #self.top2 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top2) + self.top2 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(self.top2) + # self.top1 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top1) + # self.top2 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(self.top2) - decay1 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(decay1) - decay2 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(decay2) - decay3 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(decay3) - decay4 = Detector(self.detector_sigma,self.detector_factor).gauss_smear(decay4) + decay1 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(decay1) + decay2 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(decay2) + decay3 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(decay3) + decay4 = Detector( + self.detector_sigma, self.detector_factor + ).gauss_smear(decay4) file["events"] = { self.output_1 + "_E": self.top1.E, @@ -151,4 +166,4 @@ def to_root(self, name: str = "ABC_events.root"): self.output_2 + "_Px_decay_" + self.decayed2: decay4.px, self.output_2 + "_Py_decay_" + self.decayed2: decay4.py, self.output_2 + "_Pz_decay_" + self.decayed2: decay4.pz, - } \ No newline at end of file + } diff --git a/tests/test_boost.py b/tests/test_boost.py index 4ef7d87..5eb6974 100644 --- a/tests/test_boost.py +++ b/tests/test_boost.py @@ -2,10 +2,9 @@ def test_boost(): - a = pymcabc.Particle(2.,0.,0.,2.) - b = pymcabc.Particle(3.,0.,0.,1.) + a = pymcabc.Particle(2.0, 0.0, 0.0, 2.0) + b = pymcabc.Particle(3.0, 0.0, 0.0, 1.0) c = a.boost(b) assert c.px == 0 assert c.py == 0 - assert c.pz**2 - c.E**2 <=1e-5 - \ No newline at end of file + assert c.pz**2 - c.E**2 <= 1e-5 diff --git a/tests/test_crosssection.py b/tests/test_crosssection.py index 60e981c..7cad804 100644 --- a/tests/test_crosssection.py +++ b/tests/test_crosssection.py @@ -1,10 +1,9 @@ import pymcabc import os + def test_xsec(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) sigma, error = pymcabc.CrossSection().calc_xsection() - assert sigma >= 10e-14, \ - "Sigma under estimated" - assert sigma <= 10e-12, \ - "Sigma over estimated" + assert sigma >= 10e-14, "Sigma under estimated" + assert sigma <= 10e-12, "Sigma over estimated" diff --git a/tests/test_evengen.py b/tests/test_evengen.py index 9f83f8a..c358b66 100644 --- a/tests/test_evengen.py +++ b/tests/test_evengen.py @@ -1,38 +1,43 @@ import pymcabc import os + # test if the file is prepared def test_eventGen_detector_decay(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) pymcabc.CrossSection().calc_xsection() - pymcabc.SaveEvent(100,boolDecay=True,boolDetector=True).to_root('test_eventGen_detector_decay.root') - #pymcabc.PlotData.file('test_eventGen_detector_decay.root') - assert 'test_eventGen_detector_decay.root' in os.listdir(), \ - "file not created" + pymcabc.SaveEvent(100, boolDecay=True, boolDetector=True).to_root( + "test_eventGen_detector_decay.root" + ) + # pymcabc.PlotData.file('test_eventGen_detector_decay.root') + assert "test_eventGen_detector_decay.root" in os.listdir(), "file not created" def test_eventGen_decay(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) pymcabc.CrossSection().calc_xsection() - pymcabc.SaveEvent(100,boolDecay=True,boolDetector=False).to_root('test_eventGen_decay.root') - #pymcabc.PlotData.file('test_eventGen_decay.root') - assert 'test_eventGen_decay.root' in os.listdir(), \ - "file not created" + pymcabc.SaveEvent(100, boolDecay=True, boolDetector=False).to_root( + "test_eventGen_decay.root" + ) + # pymcabc.PlotData.file('test_eventGen_decay.root') + assert "test_eventGen_decay.root" in os.listdir(), "file not created" + def test_eventGen_detector(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) pymcabc.CrossSection().calc_xsection() - pymcabc.SaveEvent(100,boolDecay=False,boolDetector=True).to_root('test_eventGen_detector.root') - #pymcabc.PlotData.file('test_eventGen_detector.root') - assert 'test_eventGen_detector.root' in os.listdir(), \ - "file not created" + pymcabc.SaveEvent(100, boolDecay=False, boolDetector=True).to_root( + "test_eventGen_detector.root" + ) + # pymcabc.PlotData.file('test_eventGen_detector.root') + assert "test_eventGen_detector.root" in os.listdir(), "file not created" def test_eventGen(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) pymcabc.CrossSection().calc_xsection() - pymcabc.SaveEvent(100,boolDecay=False,boolDetector=False).to_root('test_eventGen.root') - #pymcabc.PlotData.file('test_eventGen.root') - assert 'test_eventGen.root' in os.listdir(), \ - "file not created" - + pymcabc.SaveEvent(100, boolDecay=False, boolDetector=False).to_root( + "test_eventGen.root" + ) + # pymcabc.PlotData.file('test_eventGen.root') + assert "test_eventGen.root" in os.listdir(), "file not created" diff --git a/tests/test_identify.py b/tests/test_identify.py index 2f267b5..a138ce8 100644 --- a/tests/test_identify.py +++ b/tests/test_identify.py @@ -2,8 +2,9 @@ import os import json + def test_identify_tu(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) with open("library.json", "r") as f: library = json.load(f) assert library["m1"][0] == 4 @@ -12,10 +13,11 @@ def test_identify_tu(): assert library["m4"][0] == 10 assert library["mx"][0] == 1 assert library["Ecm"][0] == 30 - library["process_type"][0] == 'tu' + library["process_type"][0] == "tu" + def test_identify_st(): - pymcabc.DefineProcess('A B > A B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A B > A B", mA=4, mB=10, mC=1, Ecm=30) with open("library.json", "r") as f: library = json.load(f) assert library["m1"][0] == 4 @@ -24,7 +26,8 @@ def test_identify_st(): assert library["m4"][0] == 10 assert library["mx"][0] == 1 assert library["Ecm"][0] == 30 - library["process_type"][0] == 'st' + library["process_type"][0] == "st" + """ def test_feynmandiagram_tu(): @@ -42,4 +45,4 @@ def test_feynmandiagram_st(): "file not created" assert 'tchan.pdf' in os.listdir(), \ "file not created" -""" \ No newline at end of file +""" diff --git a/tests/test_plot.py b/tests/test_plot.py index 152bd73..df294c2 100644 --- a/tests/test_plot.py +++ b/tests/test_plot.py @@ -1,12 +1,13 @@ import pymcabc import os + # test if the file is prepared def test_plot(): - pymcabc.DefineProcess('A A > B B',mA=4,mB=10,mC=1,Ecm=30) + pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) pymcabc.CrossSection().calc_xsection() - pymcabc.SaveEvent(100,boolDecay=True,boolDetector=True).to_root('test_eventGen_detector_decay.root') - pymcabc.PlotData.file('test_eventGen_detector_decay.root') - assert 'B_E_decay_A.png' in os.listdir(), \ - "file not created" - + pymcabc.SaveEvent(100, boolDecay=True, boolDetector=True).to_root( + "test_eventGen_detector_decay.root" + ) + pymcabc.PlotData.file("test_eventGen_detector_decay.root") + assert "B_E_decay_A.png" in os.listdir(), "file not created" From b8ac24fddd78d7113f4fcf9b9aa2a5e751353f38 Mon Sep 17 00:00:00 2001 From: amanmdesai Date: Mon, 26 Jun 2023 09:50:17 +0530 Subject: [PATCH 5/5] update --- pymcabc/identify_process.py | 7 +++++-- tests/test_identify.py | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pymcabc/identify_process.py b/pymcabc/identify_process.py index 6f17960..91b5b24 100644 --- a/pymcabc/identify_process.py +++ b/pymcabc/identify_process.py @@ -71,6 +71,10 @@ def __init__( self.mB = mB self.mC = mC self.Ecm = Ecm + if self.mA<0 or self.mB<0 or self.mC < 0: + raise Exception("Negative masses not accepted") + if self.Ecm < 0: + raise Exception("Negative center of mass energy not accepted") self.library["mA"].append(mA) self.library["mB"].append(mB) self.library["mC"].append(mC) @@ -212,5 +216,4 @@ def identify_decay(self): self.library["decay_process"].append("NaN") with open("library.json", "w") as f: json.dump(self.library, f) - - return None + return None \ No newline at end of file diff --git a/tests/test_identify.py b/tests/test_identify.py index a138ce8..41b56d2 100644 --- a/tests/test_identify.py +++ b/tests/test_identify.py @@ -1,7 +1,7 @@ import pymcabc import os import json - +import pytest def test_identify_tu(): pymcabc.DefineProcess("A A > B B", mA=4, mB=10, mC=1, Ecm=30) @@ -28,6 +28,14 @@ def test_identify_st(): assert library["Ecm"][0] == 30 library["process_type"][0] == "st" +def test_negative_param(): + with pytest.raises(Exception, match="Negative masses not accepted"): + pymcabc.DefineProcess("A B > A B", mA=4, mB=-10, mC=1, Ecm=30) + + with pytest.raises(Exception, match="Negative center of mass energy not accepted"): + pymcabc.DefineProcess("A B > A B", mA=4, mB=10, mC=1, Ecm=-30) + + """ def test_feynmandiagram_tu():