#from ROOT import TTree, TFile, Double
import numpy as np
from pdg_const import pdg
import Tkinter
import matplotlib
matplotlib.use("agg")
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

import ROOT


modl = rm.model()

load_set = True
draw = True
step_scan = False

mode = "true_data"

modl.mode = mode

set_size = 1e5
nonres_set_size = 44000
modl.reco_steps = 100000

x_min = 3150.0
x_max= 3650.0

# x_min = modl.x_min
# x_max = modl.x_max

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

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

modl.add_cusp(3550, 6e-7, 200, 7)

modl.normalize_pdf(step_scan=step_scan)

modl.param_list()

# print(modl.total_scale_amp)

if load_set:

    if mode == "true_data":

        with open(r"./data/set_true_tot_nonres_{0}_range({1}-{2}).pkl".format(int(nonres_set_size), int(x_min), int(x_max)), "rb") as input_file:
            part_set = pkl.load(input_file)

    else:

        with open(r"./data/set_{0}_range({1}-{2}).pkl".format(int(set_size), int(x_min), int(x_max)), "rb") as input_file:
            part_set = pkl.load(input_file)

        counter = set_dic["counter_tot"]

else:
    part_set = modl.generate_points(set_size, x_min = x_min, x_max = x_max, mode = mode, verbose = 1)

if draw:
    modl.draw_plots(part_set = part_set, x_min = x_min, x_max = x_max, mode = mode)

print("Run finished")
