import ROOT
#from ROOT import TTree, TFile, Double
import numpy as np
from pdg_const import pdg
import matplotlib
matplotlib.use("Qt5Agg")
import matplotlib.pyplot as plt
import pickle as pkl
import sys
import time
from helperfunctions import display_time
import cmath as c
import raremodel as rm

    
modl = rm.model()

load_set = False

draw = False

mode = "slim_points"

modl.mode = mode

min_bin_scaling = 100

set_size = 2e4

jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale = pdg["jpsi"]
modl.add_resonance(jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale)

psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale = pdg["psi2s"]
modl.add_resonance(psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale)

modl.add_cusp(3525, 3e-7, 200, 7)

modl.normalize_pdf()

if load_set:

    with open(r"./data/set_1000.pkl", "rb") as input_file:
        set_dic = pkl.load(input_file)
    
    part_set = (set_dic["x_part"], set_dic["y_part"])
    counter_tot = set_dic["counter_tot"]

else:
    x_part, y_part, counter = modl.generate_points(set_size, mode = mode, min_bin_scaling = min_bin_scaling, verbose = 0)
    part_set = (x_part, y_part)

if draw:
    modl.draw_plots(part_set = part_set, counter = counter_tot, mode = mode, min_bin_scaling = min_bin_scaling)
    

print("Run finished")
