import DataProcessor.DataMultiSet
import DataProcessor.ArtemideReplicaSet

MAINPATH = "/home/vla18041/LinkData2/arTeMiDe_Repository/DataProcessor/"

#%%
#######################################
#Initialize artemide
#######################################
import harpy

path_to_constants = MAINPATH + "FittingPrograms/SV19/Constants-files/" + "DY+SIDIS_nnlo/const-DY+SIDIS_NNPDF31+DSS_nnlo"

harpy.initialize(path_to_constants)

harpy.setNPparameters_TMDR([1.93, 0.0434])
harpy.setNPparameters_uTMDPDF(
    [0.253434, 9.04351, 346.999, 2.47992, -5.69988, 0.1, 0.])
harpy.setNPparameters_uTMDFF([0.264, 0.479, 0.459, 0.539])


#%%
##################Cut function
def cutFunc(p):
    if p["type"] == "DY":
        delta = p["<qT>"] / p["<Q>"]
    return delta < 0.25, p


#%%
### Loading the DY data set
#%%
#######################################
#Initialize artemide
#######################################
import harpy
path_to_constants = MAINPATH + "FittingPrograms/Sivers20/Constants-files/"
#harpy.initialize(path_to_constants+"const-Sivers20_lo")

# harpy.initialize(path_to_constants+"const-Sivers20_nnlo_piK")

if (useOrder == "nnlo"):
    harpy.initialize(path_to_constants + "const-Sivers20_nnlo")

    #### All=0 Case
    harpy.setNPparameters_TMDR([2., 0.0398333])
    harpy.setNPparameters_uTMDPDF([
        0.185239, 6.22706, 580.946, 2.44166, -2.53161, 0., 0.0014, 0.442, 4.14
    ])
    harpy.setNPparameters_uTMDFF([0.279443, 0.460015, 0.435955, 0.551302])

    # # #### All=0 case piK
    # harpy.setNPparameters_TMDR([2., 0.0394095])
    # harpy.setNPparameters_uTMDPDF([0.180718, 4.38119, 426.208, 2.22347, -0.0646396, 0., 0.17, 0.48, 2.15])
    # harpy.setNPparameters_uTMDFF([0.293548, 0.462093, 0.442867, 0.590596, 0.427915, 0.462578, 0.304421,1.18113])
elif (useOrder == "n3lo"):
    harpy.initialize(path_to_constants + "const-Sivers20_n3lo")
    #### All=0 Case n3lo
    harpy.setNPparameters_TMDR([2., 0.0442327])
    harpy.setNPparameters_uTMDPDF(
        [0.17975, 3.9081, 453.883, 2.07199, 1.60774, 0, 0.0014, 0.442, 4.14])
    def SetReplica(self, num=0, part='full'):
        """
        Set the replica according to the list

        Parameters
        ----------
        num : -1 = initla replica
              0  = mean replica
              1.... = replica from list
            The default is 0.
        
        part : string, optional
            Specification which part of the replica to be set. The default is "full".
            Possible values: 'full', 'TMDR', 'uTMDPDF', 'uTMDFF', 'lpTMDPDF', 'SiversTMDPDF', etc

        Returns
        -------
        None.

        """
        import harpy

        if (num == 0):
            r = self.meanReplica
        elif (num == -1):
            r = self.initialReplica
        else:
            r = self.replicaList[num - 1]

        ## resolvinf the part-condition
        if (part == "full"):
            doTMDR = True
            douTMDPDF = True
            douTMDFF = True
            dolpTMDPDF = True
            doSiversTMDPDF = True
        else:
            doTMDR = False
            douTMDPDF = False
            douTMDFF = False
            dolpTMDPDF = False
            doSiversTMDPDF = False

            if (part == 'TMDR'):
                doTMDR = True
            if (part == 'uTMDPDF'):
                douTMDPDF = True
            if (part == 'uTMDFF'):
                douTMDFF = True
            if (part == 'lpTMDPDF'):
                dolpTMDPDF = True
            if (part == 'SiversTMDPDF'):
                doSiversTMDPDF = True

        if (doTMDR and self._TMDRend >= self._TMDRstart + 1 > 0):
            harpy.setNPparameters_TMDR(r[self._TMDRstart:self._TMDRend])

        if (douTMDPDF and self._uTMDPDFend >= self._uTMDPDFstart + 1 > 0):
            if (self._c_uTMDPDFend >= self._c_uTMDPDFstart + 1 > 0):
                harpy.setPDFreplica(r[self._c_uTMDPDFstart])
            harpy.setNPparameters_uTMDPDF(
                r[self._uTMDPDFstart:self._uTMDPDFend])

        if (douTMDFF and self._uTMDFFend >= self._uTMDFFstart + 1 > 0):
            if (self._c_uTMDFFend >= self._c_uTMDFFstart + 1 > 0):
                print("Modification of FF replica is not implimented")
            harpy.setNPparameters_uTMDFF(r[self._uTMDFFstart:self._uTMDFFend])

        if (dolpTMDPDF and self._lpTMDPDFend >= self._lpTMDPDFstart + 1 > 0):
            if (self._c_lpTMDPDFend >= self._c_lpTMDPDFstart + 1 > 0):
                print("Modification of lpPDF replica is not implimented")
            harpy.setNPparameters_lpTMDPDF(
                r[self._lpTMDPDFstart:self._lpTMDPDFend])

        if (doSiversTMDPDF
                and self._SiversTMDPDFend >= self._SiversTMDPDFstart + 1 > 0):
            if (self._SiversTMDPDFend >= self._SiversTMDPDFstart + 1 > 0):
                print("Modification of Sivers replica is not implimented")
            harpy.setNPparameters_SiversTMDPDF(
                r[self._SiversTMDPDFstart:self._SiversTMDPDFend])