#
################################################################################################
#                                                                                                #    
#                                      ```...`                                                   #    
#                                   `......-::::.`...---.`                                       #    
#                                  ``     `.-::-.....---:::-`                                    #    
#                                           ..`      `.--:://-                                   #    
#                                     `//:`            .-:::/+:                                  #    
#                                    +m/`sy            `.-:://+`                                 #    
#                              `    :mMmdN/        .::.`.-:://+-                                 #    
#                   ``-//-----------odMMMs`      -yh:/m+.-:///+-                                 #    
#               `..--------/oyy/---::/+sh.      -mNd/omh-:://++.                                 #    
#             `.-------------:------::///:.     yNMMMMNs-:///+:                                  #    
#           `------------------------:::://:`   omNNNmy-:///+:`                                  #    
#          .--------........---------:::::/+/.  `+sys/-::/+++:`                                  #    
#         .---------.---------------:::::///++:..------::://+o+.                                 #    
#        .---------...-------------:::::://++/----------:::///+o-                                #    
#        -------------------------::::::////:---.-------::::///+o.                               #    
#       `:----------------------:::::::///:---..-------:::::///+o/                               #    
#       .:--------------------:::::://///:-------------::::////+o+             `.-               #    
#       `::---------------:::::::://////:------------::::::///+++/            ..-:               #    
#       `::::--------:::::::////////////-----------::::://///++++-           .--:/`  ``..        #    
#        -/:::::::::::://///////////////--------::::://////+++++/`          .--:/+...--/.        #    
#         :///::::://////++++++++++++++/-----::::///////++++++//.         `.---::----:/:         #    
#          :+//////++++++++++++++++++o+/-:::::///////++++++++/:`         `..-------:/+/`````.`   #    
#           ./++++ooooooooooooooooooo/:::::///+++++++++++++//-`         `.---------///-..--:-    #    
#            `-+osssso/+sssssssssso+/::://+++ooooooooo+++/:-`          `----------------://-     #    
#               .:+:.` `-+ossyyyysooo++++oosssssoooo++//+:.            ---------------:/+/.      #    
#                         `-/+osyyyyyysssyysssssoo++++++oso/.----.````.-------------://+/`       #    
#                             `..-://+++osysssssooosyso+ooossydhs+----------------:://++:        #    
#                                       `+ssssssssssyyyo+++++/:--------------::::////////-`      #    
#                   `                  -+osooooooooosshhs/:----..--------::://////++//:----.     #    
#           ..`    ...`               :ssooooossssssyyy+:------------::/++ooooooooooo+/:----.`   #    
#           .--..``-.--`              .oysssssssssshdo:----------::/++ossyhddhhdo....--------`   #    
#     ``    `:-.---:----`             .----------:+mh:------:://++oohhhdddddddddms`              #    
#    `.......-:----------.`          .-...```````..smy++//++ooooooooyddddddddddddmy`             #    
#      `.-------------------.`````..-/:--.....`````.:shhhdddho/::/+oohdddddhhhhhddms             #    
#         `-------....--------------/:-...````````````..----:/.` ``-/+hddddhhhddddmd:            #    
#           `.-----.--..-----------:/:-....````````````````..::``  `.:ommddhdddmmmmms            #    
#             `---------------::://++:--......``````````....--/:`````.:sdddmmmmmdddmh`           #    
#             .--------:://+++++//:-//:--.....................-/-````.-/yydhyyyhhhhdd`           #    
#           `..----:://///:--..``   :+::--------..............-//.```.-:sdhyyyyyhhhhd`           #    
#          ..--::://::-..-://+///:-`.o/::----.................-:+:.``..:+hyyyyyyhhhhs            #    
#         .-::-..`   `:+ooooooooooso/o+:::---------------------:++-....:/yyyyyyyyhhh:            #    
#          `        .syso+++++++oooosso+/::::::-----------::::::+s/-..--:shyyyyyhhys`            #    
#                `.../yysoooooo+oooossyso///::------------::://++yo:---:/ohyyyyhhys.             #    
#                :o+:`.oysoooooooooossyhhoo+:----------:::::://++dh+::::/+dhhhhhys.              #    
#                .ooo:``ohyssoooooosssyhhoooo+:------::::::////++ymo//::/+dhhddh/`               #    
#                 /sso:``ohyyssssssssyyhdysooooo/:::://++///++++shds+////+mddho-                 #    
#                  :sss/.`odhyyyyyyyyyyhdddyssooso///+oysooooosshNhso++//+hyo-                   #    
#                   -syy+-.sdhhhyyyyyyyyyyhhhyyssssoosyyysssyhdmNdysso++/ossso+/-.               #    
#                    `/syo:-sddhhhyyyyysssyyhhhhyyyysosssssossyyhyyssso+ossoo++//-               #    
#                      `+hy/-oddhhyyyyssssyyyhddddhh+  `/oosssssssssoo+ydhho/:-.`                #    
#                       :osso:+ddhhyyyssssyyyhddhhyo.   `/oosssssssssssyhhhhhhhhy+.              #    
#                        -sso+::yddhyyyyyyyyyhho `       `:+osssssssssyhsoshdhhhhddo-`           #    
#                         .oys/--odddhhhhyyhhhs.           .:osyyyyyyhsoooyhdhyssyhds/           #    
#                          `/yy+:-/dmdddhhhhyo.             `yhhhhhysoosyhddhsoosyyds-           #    
#                            .+ys+/+dmdddhy+.               `shyssoosyhdddhysooosyhdo-`          #    
#                              .+so:-/::-.                   `-+oshhhhhhyyssoooosyhd/-           #    
#                                ``                        .:+oooo++oooooooooooosyhh-.           #    
#                                                        `+oooo++++++++++++++ooosyho`            #    
#                                                        +ssooooo++++++++++++oosyhd/.            #    
#                                                       `yyysssoooooooo+++oooosyyhh-.            #    
#                                                        sdhhyyyssssssssssssyyyhhd+-.            #    
#                                                        .hmddddhhhhhhhhhhhhhddddo:-             #    
#                                                         `:ohddmmddddddddddhyso/::              #    
#                                                            -:/++ooooooo++//:--.`               #    
##################################################################################################
#                           ____       _                                                         #
#                          / ___| __ _| | __ _ _ __   __ _  __ _  ___                            #
#                         | |  _ / _` | |/ _` | '_ \ / _` |/ _` |/ _ \                           #
#                         | |_| | (_| | | (_| | |_) | (_| | (_| | (_) |                          # 
#                     _____\____|\__,_|_|\__,_| .__/ \__,_|\__, |\___/ _                         #  
#                    |  ___| __ __ _ _ __ ___ |_|____      |___/  _ __| | _                      #_
#                    | |_ | '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /                     #
#                    |  _|| | | (_| | | | | | |  __/\ V  V / (_) | |  |   <                      # 
#                    |_|  |_|  \__,_|_| |_| |_|\___| \_/\_/ \___/|_|  |_|\_\                     #
#                                                                                                # 
##################################################################################################

import ROOT as r
from   ROOT import gROOT, TCanvas, TFile, TGraphErrors, SetOwnership
import math, sys, argparse, array, copy, os
import gc, inspect, __main__
import numpy as np
import time

import include.Sample as Sample
import include.Launcher as Launcher
import include.helper as helper
import include.Canvas as Canvas
import include.CutManager as CutManager
from include.Utils import *

####################################### CLASS DEFINITION #########################################

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'



################################# GLOBAL VARIABLES DEFINITION ####################################

runningfile = os.path.abspath(__file__)
WORKPATH = ''
for level in runningfile.split('/')[:-1]: 
    WORKPATH += level
    WORKPATH += '/'

if __name__ == "__main__":

    print bcolors.HEADER
    print "                                 ```.....`                              "        
    print "                               `.````.-:::-.-------.                    "        
    print "                              ``      .--.`````.--://-                  "
    print "                                   `   `        `-::://`                "
    print "                                `os/y:           .-::/+/                "
    print "                                yNdod+        ````-:://+`               "
    print "                 ``-/-..------.-hNMMs`     `oy/sy.-:://+.               "
    print "              `..------:+ss/--::/+sh.     `dNh/sN/-://+/`               "
    print "           `.-------------------::///.    /NMMMNm::///+-                "
    print "         `.---------------------:::://:`  -dmNNh/:///+-                 "
    print "        `--------.---.----------:::::/+/.``-++/:-://+o+.                "
    print "       `--------..--------------:::://++/---------:://++:               "
    print "       .----------------------::::::/++:----------::://+o:              "
    print "       ---------------------::::::://:---..------:::://++o`             "
    print "      `:-------------------::::::///:----.------::::://++o.             "
    print "      `::--------------::::::://///:-----------:::::///+++.             "
    print "       ::::------:::::::://////////----------:::::////+++/`             "
    print "       ./:::::::::::///////////////-------:::://////++++/-              "
    print "        -///////////++++++++++++++/----:::///////++++++/-               "
    print "         ./+///+++++ooooooooo+ooo+::::::///++++++++++//.                "
    print "          `-+ooosssooooosssssso+/:::///+++++oooo+++//-`                 "
    print "            `-+so/-.:+sssyyysso++///+oooooooooo++//-`                   "
    print "               ``    `.:+osyyyyysssssssssssoo++++oo+:`..```             "
    print "                         `.-:/+++oooyyysssooosso+ooosoyhyo/-.           "
    print "                                  ``+sssssssssyyso++++/:------::        "
    print "                                  -+oooooooooosyhy+:----.-------::      "
    print '########################################################################' 
    print '                  Starting IFCA-LLP analysis...                         '
    print '########################################################################' + bcolors.ENDC

    parser = argparse.ArgumentParser(usage='usage: %prog [args] FilenameWithSamples', version='%prog 1.0')
    parser.add_argument('-o', '--out', action='store', type=str, dest='out', default='', help='Output tag')
    parser.add_argument('-d', '--dat', action='store', type=str, dest='dat', default='dat/Samples_cern_UltraLegacy_Spring23.dat', help='dat file')
    parser.add_argument('-m', '--mode', action='store', type=str, dest='mode', default='plot', help='Select mode to process config file')
    parser.add_argument('-c', '--config', action='store', type=str, dest='config', help='Select config file')
    parser.add_argument('-q', '--condor', action='store_true', dest='condor', help='Select if you want to send the job a condor queue')
    parser.add_argument('-r', '--raw', action='store_true', dest='raw', help='Select if you DONT want to apply scale factors')
    parser.add_argument('-t', '--test', action='store_true', dest='test', default='', help='Test tag')
    args = parser.parse_args()

    doDATA = True
    doMC = True
    doSignals = True

    ############# Set the TDR plot style
    #r.gROOT.LoadMacro(WORKPATH + 'include/tdrstyle.C+')
    r.gROOT.SetBatch(1)
    #r.setTDRStyle()


    ############# Muon data definition
    DoubleMuon2016 = []
    DoubleMuon2018 = []
    DoubleMuon2016.append('DoubleMuon_Run2016B_HIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016C_HIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016D_HIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016E_HIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016F_HIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016F_noHIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016G_noHIPM')
    DoubleMuon2016.append('DoubleMuon_Run2016H_noHIPM')
    DoubleMuon2018.append('DoubleMuon_Run2018A')
    DoubleMuon2018.append('DoubleMuon_Run2018B')
    DoubleMuon2018.append('DoubleMuon_Run2018C')
    DoubleMuon2018.append('DoubleMuon_Run2018D')

    DoubleEG2016 = []
    DoubleEG2017 = []
    DoubleEG2018 = []
    DoubleEG2016.append('DoubleEG_Run2016B_HIPM')
    DoubleEG2016.append('DoubleEG_Run2016C_HIPM')
    DoubleEG2016.append('DoubleEG_Run2016D_HIPM')
    DoubleEG2016.append('DoubleEG_Run2016E_HIPM')
    DoubleEG2016.append('DoubleEG_Run2016F_HIPM')
    DoubleEG2016.append('DoubleEG_Run2016F_noHIPM')
    DoubleEG2016.append('DoubleEG_Run2016G_noHIPM')
    DoubleEG2016.append('DoubleEG_Run2016H_noHIPM')
    DoubleEG2017.append('DoubleEG_Run2017B')
    DoubleEG2017.append('DoubleEG_Run2017C')
    DoubleEG2017.append('DoubleEG_Run2017D')
    DoubleEG2017.append('DoubleEG_Run2017E')
    DoubleEG2017.append('DoubleEG_Run2017F')
    DoubleEG2018.append('EGamma_Run2018A')
    DoubleEG2018.append('EGamma_Run2018B')
    DoubleEG2018.append('EGamma_Run2018C')
    DoubleEG2018.append('EGamma_Run2018D')

    ############# Background definition
    Backgrounds_preVFP = []
    Backgrounds_preVFP.append('DYJetsToLL_M-50_preVFP') 
    Backgrounds_preVFP.append('DYJetsToLL_M-10to50_preVFP') 
    Backgrounds_preVFP.append('TTTo2L2Nu_preVFP') 
    Backgrounds_preVFP.append('WJetsToLNu_preVFP') 
    Backgrounds_preVFP.append('WW_preVFP') 
    Backgrounds_preVFP.append('WZ_preVFP') 
    Backgrounds_preVFP.append('ZZ_preVFP') 
    Backgrounds_postVFP = []
    Backgrounds_postVFP.append('DYJetsToLL_M-50_postVFP') 
    Backgrounds_postVFP.append('DYJetsToLL_M-10to50_postVFP') 
    Backgrounds_postVFP.append('TTTo2L2Nu_postVFP') 
    Backgrounds_postVFP.append('WJetsToLNu_postVFP') 
    Backgrounds_postVFP.append('WW_postVFP') 
    Backgrounds_postVFP.append('WZ_postVFP') 
    Backgrounds_postVFP.append('ZZ_postVFP') 
    Backgrounds_2017 = []
    Backgrounds_2017.append('DYJetsToLL_M-50_2017') 
    Backgrounds_2017.append('DYJetsToLL_M-10to50_2017') 
    Backgrounds_2017.append('TTTo2L2Nu_2017') 
    Backgrounds_2017.append('WJetsToLNu_2017') 
    Backgrounds_2017.append('WW_2017') 
    Backgrounds_2017.append('WZ_2017') 
    Backgrounds_2017.append('ZZ_2017') 
    Backgrounds_2018 = []
    Backgrounds_2018.append('DYJetsToLL_M-50_2018') 
    Backgrounds_2018.append('DYJetsToLL_M-10to50_2018') 
    Backgrounds_2018.append('TTTo2L2Nu_2018') 
    Backgrounds_2018.append('WJetsToLNu_2018') 
    Backgrounds_2018.append('WW_2018') 
    Backgrounds_2018.append('WZ_2018') 
    Backgrounds_2018.append('ZZ_2018') 



    ############# Signal definition
    Masses = []
    Masses.append('HSS_125_50')
    Masses.append('HSS_300_50')
    Masses.append('HSS_500_50')
    Masses.append('HSS_500_150')
    Masses.append('HSS_600_50')
    Masses.append('HSS_600_150')
    Masses.append('HSS_600_250')
    Masses.append('HSS_800_50')
    Masses.append('HSS_800_250')
    Masses.append('HSS_800_350')
    Masses.append('HSS_1000_250')
    Masses.append('HSS_1000_350')
    Masses.append('HSS_1000_450')
    Masses.append('RPV_350_148')
    Masses.append('RPV_1500_494')
    Signals = []
    for mass in Masses:
        Signals.append(mass + '_1')
        Signals.append(mass + '_10')
        Signals.append(mass + '_100')
        Signals.append(mass + '_1000')
        Signals.append(mass + '_10000')
    Signals_2016preVFP = [i + '_2016APV' for i in Signals]
    Signals_2016postVFP = [i + '_2016' for i in Signals]
    Signals_2017 = [i + '_2017' for i in Signals]
    Signals_2018 = [i + '_2018' for i in Signals]


    ############# Luminosity definition
    lumiB = 5.79
    lumiC = 2.57
    lumiD = 4.25
    lumiE = 4.01
    lumiF = 2.53 # total 3.10
    lumiF_noHIMP = 0.57
    lumiG = 7.54
    lumiH = 8.61
    lumi =  lumiB + lumiC + lumiD + lumiE + lumiF + lumiG + lumiH# luminosity

    lumi_preVFP = 5.79 + 2.57 + 4.25 + 4.01 + 3.10
    lumi_postVFP = 7.54 + 8.61
    lumi_2017 = 41.48
    lumi_2018 = 59.83 # Note: Use 54.53 for electrons unless scaled option is activated

    filename = args.dat


    ############# Tree creation
    if doDATA:
        treeDATA2016_EE = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleEG2016, 'DATA'), name = 'DATA', isdata = 1 )
        treeDATA2016_MM = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleMuon2016, 'DATA'), name = 'DATA', isdata = 1 )
        treeDATA2017_EE = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleEG2017, 'DATA'), name = 'DATA', isdata = 1 )
        treeDATA2018_EE = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleEG2018, 'DATA'), name = 'DATA', isdata = 1 )
        treeDATA2018_MM = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleMuon2018, 'DATA'), name = 'DATA', isdata = 1 )

    if doMC:
        treeMCpreVFP = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Backgrounds_preVFP, 'MC'), name = 'MC', isdata = 0 )
        treeMCpostVFP = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Backgrounds_postVFP, 'MC'), name = 'MC', isdata = 0 )
        treeMC2017 = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Backgrounds_2017, 'MC'), name = 'MC', isdata = 0 )
        treeMC2018 = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Backgrounds_2018, 'MC'), name = 'MC', isdata = 0 )

    if doSignals:
        treeSI_2016APV   = Sample.Tree( fileName = helper.selectSamples(WORKPATH + 'dat/CombSignal_2016UL_Spring23.dat', Signals_2016preVFP, 'SI'), name = 'SI', isdata = 0 )
        treeSI_2016      = Sample.Tree( fileName = helper.selectSamples(WORKPATH + 'dat/CombSignal_2016UL_Spring23.dat', Signals_2016postVFP, 'SI'), name = 'SI', isdata = 0 )
        treeSI_2017      = Sample.Tree( fileName = helper.selectSamples(WORKPATH + 'dat/CombSignal_2017UL_Spring23.dat', Signals_2017, 'SI'), name = 'SI', isdata = 0 )
        treeSI_2018      = Sample.Tree( fileName = helper.selectSamples(WORKPATH + 'dat/CombSignal_2018UL_Spring23.dat', Signals_2018, 'SI'), name = 'SI', isdata = 0 )

    start_time = time.time()

    ############# Make output dir
    if not os.path.exists(WORKPATH +  args.out + '/'): os.makedirs(WORKPATH +  args.out + '/')

    ##################
    ####  Launch  ####
    ##################
    
    if args.condor:
        if doMC:
            print('Launching background Monte Carlo...')
            treeMCpreVFP.launchLoop(lumi_preVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2016APV', raw = args.raw)
            treeMCpostVFP.launchLoop(lumi_postVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2016', raw = args.raw)
            treeMC2017.launchLoop(lumi_2017, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2017', raw = args.raw)
            treeMC2018.launchLoop(lumi_2018, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2018', raw = args.raw)
        if doDATA:
            print('Launching Data...')
            treeDATA2016_EE.launchLoop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2016')
            treeDATA2016_MM.launchLoop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2016')
            treeDATA2017_EE.launchLoop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2017')
            treeDATA2018_EE.launchLoop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2018')
            treeDATA2018_MM.launchLoop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, queue = 'workday', year = '2018')
        if doSignals:
            print('Launching signal simulation...')
            treeSI_2016APV.launchLoop(lumi_preVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016APV', queue = 'microcentury', raw = args.raw)
            treeSI_2016.launchLoop(lumi_postVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016', queue = 'microcentury', raw = args.raw)
            treeSI_2017.launchLoop(lumi_2017, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2017', queue = 'microcentury', raw = args.raw)
            treeSI_2018.launchLoop(lumi_2018, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2018', queue = 'microcentury', raw = args.raw)
    else:
        if doMC:
            print('Launching background Monte Carlo...')
            treeMCpreVFP.Loop(lumi_preVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016APV', raw = args.raw)
            treeMCpostVFP.Loop(lumi_postVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016', raw = args.raw)
            treeMC2017.Loop(lumi_2017, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2017', raw = args.raw)
            treeMC2018.Loop(lumi_2018, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2018', raw = args.raw)
        if doDATA:
            print('Launching Data...')
            treeDATA2016_EE.Loop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016')
            treeDATA2016_MM.Loop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016')
            treeDATA2017_EE.Loop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2017')
            treeDATA2018_EE.Loop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2018')
            treeDATA2018_MM.Loop(lumi, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2018')
        if doSignals:
            print('Launching signal simulation...')
            treeSI_2016APV.Loop(lumi_preVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016APV', raw = args.raw)
            treeSI_2016.Loop(lumi_postVFP, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2016', raw = args.raw)
            treeSI_2017.Loop(lumi_2017, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2017', raw = args.raw)
            treeSI_2018.Loop(lumi_2018, WORKPATH + args.out + '/', mode = args.mode, config = WORKPATH + args.config, year = '2018', raw = args.raw)
    print("--- %s seconds ---" % (time.time() - start_time))


