##################################################################################################
#                                                                                                #    
#                                      ```...`                                                   #    
#                                   `......-::::.`...---.`                                       #    
#                                  ``     `.-::-.....---:::-`                                    #    
#                                           ..`      `.--:://-                                   #    
#                                     `//:`            .-:::/+:                                  #    
#                                    +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, optparse, 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 = optparse.OptionParser(usage='usage: %prog [opts] FilenameWithSamples', version='%prog 1.0')
    parser.add_option('-o', '--out', action='store', type=str, dest='out', default='', help='Output tag')
    parser.add_option('-q', '--qenv', action='store', type=str, dest='qenv', default='', help='Select if you want to send the job a condor queue')
    parser.add_option('-t', '--test', action='store_true', dest='test', default='', help='Test tag')
    (opts, args) = parser.parse_args()

    if opts.qenv == '': opts.qenv = False

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


    ############# Muon data definition
    DoubleMuon = []
    DoubleMuon.append('DoubleMuon_Run2016F')

    ############# Background definition
    Backgrounds = []
    Backgrounds.append('DYJetsToLL_M-50') 
    Backgrounds.append('DYJetsToLL_M-10to50') 
    Backgrounds.append('WW') 
    Backgrounds.append('WZ') 
    Backgrounds.append('ZZ') 
    #Backgrounds.append('WJetsToLNu') 
    Backgrounds.append('TT') 

    ############# Signal definition
    Signals = []
    #Signals.append('DisplacedSUSY_350_148_173')
    Signals.append('HXX_400_50_400mm')
    Signals.append('HXX_400_50_40mm')
    Signals.append('HXX_400_50_4mm')

    ############# Parameter definition
    lumiB = 5.79
    lumiC = 2.57
    lumiD = 4.25
    lumiE = 4.01
    lumiF = 3.10
    lumiG = 7.54
    lumiH = 8.61
    lumi = lumiF # luminosity

    filename = 'dat/Samples_cern_test.dat' if opts.test else 'dat/Samples_cern.dat'

    ############# Tree creation
    treeMC = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Backgrounds, 'MC'), name = 'MC', isdata = 0 )
    treeSI = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Signals, 'SI'), name = 'SI', isdata = 0 )
    treeDATA = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleMuon, 'DATA'), name = 'DATA', isdata = 1 )

    ############# Cut definition
    cuts = CutManager.CutManager()
    MMall = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.cosmicRejection])
    MMSR = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMSR_dPhi, cuts.cosmicRejection])
    #MMCR = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMCR_dPhi, cuts.cosmicRejection])
    MMCR = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMCR_dPhi, cuts.cosmicRejection, cuts.MM_highpT])
    MMCR_woutCosmicRej = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMCR_dPhi])
    MMCR_OS = cuts.AddListB([MMCR, cuts.MM_OScharge])


    ############# Plotting
    start_time = time.time()

    ###################
    ####  Dimuons  ####
    ###################

    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'nDMDMBase', name = 'All_nDMDMBase', nbin = 4, xmin = 0, xmax = 4, xlabel = 'Number of dimuon candidates', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = cuts.AddListB([cuts.nTrack, cuts.MMChannel]), outtag = opts.out, yshift = 1000.0)

    """

    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_dPhi[DMDMBase_maxIxy]', name = 'All_DMDM_dPhi', nbin = 20, xmin = -3.3, xmax = 3.3, xlabel = 'Dimuon collinearity |#Delta#Phi|', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMall, outtag = opts.out, yshift = 1000.0)

    ## Control region:
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_dPhi[DMDMBase_maxIxy]', name = 'CR_DMDM_dPhi', nbin = 20, xmin = -3.3, xmax = 3.3, xlabel = 'Dimuon collinearity |#Delta#Phi|', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_mass[DMDMBase_maxIxy]', name = 'DMDM_mass', nbin = 35, xmin = 0, xmax = 200, xlabel = 'Dimuon invariant mass m_{#mu#mu} (GeV)', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 800.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_cosAlpha[DMDMBase_maxIxy]', name = 'DMDM_cosAlpha', nbin = 21, xmin = -1.1, xmax = 1.0, xlabel = 'Dimuon cos(#alpha)', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 100.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_trackIxy[DMDMBase_maxIxy]', name = 'DMDM_trackIxy', nbin = 20, xmin = 0, xmax = 20, xlabel = 'Dimuon candidate |d_{0}|/#sigma', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 100.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_Lxy[DMDMBase_maxIxy]', name = 'DMDM_Lxy', nbin = 20, xmin = 0, xmax = 10, xlabel = 'Dimuon vertex L_{xy} (cm)', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'fabs(DMDMBase_trackDxy[DMDMBase_maxIxy])', name = 'DMDM_trackDxy', nbin = 20, xmin = 0, xmax = 10, xlabel = 'Dimuon candidate |d_{0}| (cm)', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_Ixy[DMDMBase_maxIxy]', name = 'DMDM_Ixy', nbin = 20, xmin = 0, xmax = 20, xlabel = 'Dimuon vertex |L_{xy}|/#sigma', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 100.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_normalizedChi2[DMDMBase_maxIxy]', name = 'DMDM_Chi2', nbin = 10, xmin = 0, xmax = 10, xlabel = 'Dimuon vertex fit #chi^{2}/ndf', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_leadingPt[DMDMBase_maxIxy]', name = 'DMDM_leadingPt', nbin = 30, xmin = 0, xmax = 300, xlabel = 'Leading muon transverse momentum p_{T} (GeV)', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 100.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_subleadingPt[DMDMBase_maxIxy]', name = 'DMDM_subleadingPt', nbin = 30, xmin = 0, xmax = 300, xlabel = 'Subleading muon transverse momentum p_{T} (GeV)', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 100.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_relisoA[DMDMBase_maxIxy]', name = 'DMDM_relisoA', nbin = 20, xmin = 0, xmax = 0.2, xlabel = 'Leading muon relIso', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DMDMBase_relisoB[DMDMBase_maxIxy]', name = 'DMDM_relisoB', nbin = 20, xmin = 0, xmax = 0.2, xlabel = 'Subleading muon relIso', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out)

    """

    ################
    ####  DG's  ####
    ################
    ### Control region:
    # Eta:
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_eta[DMDMBase_idxA[DMDMBase_maxIxy]]', name = 'CR_DGA_eta', nbin = 26, xmin = -2.6, xmax = 2.5, xlabel = 'Displaced global muon A #eta', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_eta[DMDMBase_idxB[DMDMBase_maxIxy]]', name = 'CR_DGB_eta', nbin = 26, xmin = -2.6, xmax = 2.5, xlabel = 'Displaced global muon B #eta', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    # dxy:
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_dxy[DMDMBase_idxA[DMDMBase_maxIxy]]', name = 'CR_DGA_dxy', nbin = 17, xmin = -4.5, xmax = 4.0, xlabel = 'Displaced global muon A d_{xy}', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_dxy[DMDMBase_idxB[DMDMBase_maxIxy]]', name = 'CR_DGB_dxy', nbin = 17, xmin = -4.5, xmax = 4.0, xlabel = 'Displaced global muon B d_{xy}', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    # dxyError:
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_dxyError[DMDMBase_idxA[DMDMBase_maxIxy]]', name = 'CR_DGA_dxyError', nbin = 70, xmin = 0, xmax = 0.01, xlabel = 'Displaced global muon A d_{xy}', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_dxyError[DMDMBase_idxB[DMDMBase_maxIxy]]', name = 'CR_DGB_dxyError', nbin = 70, xmin = 0, xmax = 0.01, xlabel = 'Displaced global muon B d_{xy}', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    # Charge
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_charge[DMDMBase_idxA[DMDMBase_maxIxy]]', name = 'CR_DGA_charge', nbin = 3, xmin = -2, xmax = 1, xlabel = 'Displaced global muon A charge', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_charge[DMDMBase_idxB[DMDMBase_maxIxy]]', name = 'CR_DGB_charge', nbin = 3, xmin = -2, xmax = 1, xlabel = 'Displaced global muon B charge', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    # Number of valid hits
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_numberOfValidHits[DMDMBase_idxA[DMDMBase_maxIxy]]', name = 'CR_DGA_numberOfValidHits', nbin = 80, xmin = 0, xmax = 80, xlabel = 'Displaced global muon A N_{hits}', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_numberOfValidHits[DMDMBase_idxB[DMDMBase_maxIxy]]', name = 'CR_DGB_numberOfValidHits', nbin = 80, xmin = 0, xmax = 80, xlabel = 'Displaced global muon B N_{valid}', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    # Chi2/ndof
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_chi2[DMDMBase_idxA[DMDMBase_maxIxy]]/DGM_ndof[DMDMBase_idxA[DMDMBase_maxIxy]]', name = 'CR_DGA_normChi2', nbin = 15, xmin = 0, xmax = 15, xlabel = 'Displaced global muon A #chi^{2}/ndof', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)
    makeFullPlot(queue = opts.qenv, lumi = lumi, var = 'DGM_chi2[DMDMBase_idxB[DMDMBase_maxIxy]]/DGM_ndof[DMDMBase_idxB[DMDMBase_maxIxy]]', name = 'CR_DGB_normChi2', nbin = 15, xmin = 0, xmax = 15, xlabel = 'Displaced global muon B #chi^{2}/ndof', ylog = True, treeMC = treeMC, treeDATA = treeDATA, treeSI = treeSI, cuts = MMCR, outtag = opts.out, yshift = 1000.0)




    print("--- %s seconds ---" % (time.time() - start_time))


