Example #1
0
    def exportWriter(self):
        """
		导出文件序列化器
		"""
        if self.__exportWriter is None:
            self.__exportWriter = JsonWriter(self.exportTracer)
        return self.__exportWriter
def main():
    if len(sys.argv) == 1:
        usage()

    rootfile = ""
    jsonfile = "limits.json"

    root_re = re.compile("(?P<rootfile>(\S*\.root))")
    json_re = re.compile("(?P<jsonfile>(\S*\.json))")
    for argv in sys.argv:
        match = root_re.search(argv)
        if match:
            rootfile = match.group(0)
        match = json_re.search(argv)
        if match:
            jsonfile = match.group(0)
#    jsonfile = "limits_heavy2016.json"
    jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v3_heavy.json"
#    limits = limit.BRLimits(limitsfile=jsonfile,configfile="configurationHeavy.json")
    limits = limit.BRLimits(limitsfile=jsonfile,configfile="limits2016/heavyHplus_configuration.json")

    # Enable OpenGL
    ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1)

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    #if limit.forPaper:
    #    histograms.cmsTextMode = histograms.CMSMode.PAPER
    #histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp
    #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp
    histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY
    limit.forPaper = True # to get GeV without c^2

    # Get BR limits

    masses = limits.mass
    brs    = limits.observed

    print "Observed masses and sigma*BR's"
    for i in range(len(masses)):
        print "    ",masses[i],brs[i]

    global db
    db = BRXSDB.BRXSDatabaseInterface(rootfile)
    db.BRvariable= "2*0.001*tHp_xsec*BR_Hp_taunu"  # XSEC only for H-, multiply with 2 to get H+ and H- ; multiply by 0.001 to fb -> pb
    for i,m in enumerate(masses):
        db.addExperimentalBRLimit(m,brs[i])


    graphs = {}
    obs = limits.observedGraph()

    # Remove blinded obs points
    for i in reversed(range(0,obs.GetN())):
        if obs.GetY()[i] < 0.00000001:
            print "    REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i]
            obs.RemovePoint(i)
    print

    graphs["exp"] = limits.expectedGraph()
    graphs["exp1"] = limits.expectedBandGraph(sigma=1)
    graphs["exp2"] = limits.expectedBandGraph(sigma=2)

    if obs.GetN() > 0:
        graphs["obs"] = obs
        # Get theory uncertainties on observed
#        obs_th_plus = limit.getObservedPlus(obs,0.32)
#        obs_th_minus = limit.getObservedMinus(obs,0.32)
#        for gr in [obs_th_plus, obs_th_minus]:
#            gr.SetLineWidth(2)
#            gr.SetLineStyle(9)
#        graphs["obs_th_plus"] = obs_th_plus
#        graphs["obs_th_minus"] = obs_th_minus

    # Remove m=180,190
    for gr in graphs.values():
#        limit.cleanGraph(gr, 750)
        limit.cleanGraph(gr, 800)
        limit.cleanGraph(gr, 1000)
        limit.cleanGraph(gr, 2000)
        limit.cleanGraph(gr, 3000)


    print "Plotting graphs"                    
    for key in graphs.keys():
        for i in range(graphs[key].GetN()):
            xs = graphs[key].GetX()
            ys = graphs[key].GetY()
            print "    ",key,xs[i],ys[i]
        print

    # Interpret in MSSM
    xVariable = "mHp"
    selection = "mHp > 0 && mu==200"
#    selection = "mHp > 0 && mu==500"
#    scenario = "MSSM m_{h}^{max}"
    scenario = os.path.split(rootfile)[-1].replace(".root","")
    print scenario

    from JsonWriter import JsonWriter
    jsonWriter = JsonWriter()
    for key in graphs.keys():
        print "Graph--------------------------------",key
        graphs[key] = db.graphToTanBeta(graphs[key],xVariable,selection,highTanbRegion=True)
        #if key == "obs":
            #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+")
            #graphs["obs_th_plus"] = db.graphToTanBeta(obsplus,xVariable,selection)
            #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-")
            #graphs["obs_th_minus"] = db.graphToTanBeta(obsminus,xVariable,selection)
        print key,"done"
        jsonWriter.addGraph(key,graphs[key])

#    graphs["mintanb"] = db.minimumTanbGraph("mHp",selection)
    if scenario == "lowMH-LHCHXSWG":
        graphs["Allowed"] = db.mhLimit("mH","mHp",selection,"125.0+-3.0")
    else:
        graphs["Allowed"] = db.mhLimit("mh","mHp",selection+"&&mHp>175","125.0+-3.0")

    if scenario == "tauphobic-LHCHXSWG":
        # Fix a buggy second upper limit (the order of points is left to right, then right to left; remove further passes to fix the bug)
        decreasingStatus = False
        i = 0
        while i < graphs["Allowed"].GetN():
            removeStatus = False
            y = graphs["Allowed"].GetY()[i]
            if i > 0:
                if graphs["Allowed"].GetY()[i-1] - y < 0:
                    decreasingStatus = True
                else:
                    if decreasingStatus:
                        graphs["Allowed"].RemovePoint(i)
                        removeStatus = True
            if not removeStatus:
                i += 1
        #for i in range(0, graphs["Allowed"].GetN()):
            #print graphs["Allowed"].GetX()[i], graphs["Allowed"].GetY()[i]
        
#    del graphs["isomass"]

    jsonWriter.addGraph("Allowed",graphs["Allowed"])

    jsonWriter.addParameter("name","limitsTanb_heavy_"+scenario)
    jsonWriter.addParameter("scenario",scenario)
    jsonWriter.addParameter("luminosity",limits.getLuminosity())
    jsonWriter.addParameter("finalStateText",limits.getFinalstateText())
    jsonWriter.addParameter("mHplus",limit.mHplus())
    jsonWriter.addParameter("selection",selection)
    jsonWriter.write("MSSMLimitHeavy_"+scenario+".json")

    limit.doTanBetaPlotHeavy("limitsTanb_heavy_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario)
    sys.exit()	
 
   # mH+ -> mA
    print "Replotting the graphs for (mA,tanb)"
    for key in graphs.keys():
	print key
        #db.PrintGraph(graphs[key])
	#print "check loop db.graphToMa"
        db.graphToMa(graphs[key])

    graphs["isomass"] = db.getIsoMass(200)

#    doPlot("limitsTanb_mA_heavy_"+scenario, graphs, limits, limit.mA(),scenario)
    
    limit.doTanBetaPlotHeavy("limitsTanb_mA_heavy_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
Example #3
0
def main():
    if len(sys.argv) == 1:
        usage()

    rootfile = ""
    jsonfile = "limits.json"

    root_re = re.compile("(?P<rootfile>(\S*\.root))")
    json_re = re.compile("(?P<jsonfile>(\S*\.json))")
    for argv in sys.argv:
        match = root_re.search(argv)
        if match:
            rootfile = match.group(0)
        match = json_re.search(argv)
        if match:
            jsonfile = match.group(0)
#    jsonfile = "limits_light2016.json"
#    jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v2_light.json"
    jsonfile = "limits2016/limits_light_20171011.json"
    #    limits = limit.BRLimits(limitsfile=jsonfile,configfile="limitdata/lightHplus_configuration.json")
    limits = limit.BRLimits(
        limitsfile=jsonfile,
        configfile="limits2016/lightHplus_configuration.json")

    # Enable OpenGL
    ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1)

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    #    if limit.forPaper:
    #        histograms.cmsTextMode = histograms.CMSMode.PAPER
    histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY
    #    histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp
    #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp
    limit.forPaper = True  # to get GeV without c^2

    # Get BR limits

    masses = limits.mass
    brs = limits.observed

    print "Observed masses and BR's"
    for i in range(len(masses)):
        print "    ", masses[i], brs[i]

    global db
    db = BRXSDB.BRXSDatabaseInterface(rootfile)
    for i, m in enumerate(masses):
        db.addExperimentalBRLimit(m, brs[i])

    graphs = {}
    obs = limits.observedGraph()
    # Remove blinded obs points
    for i in reversed(range(0, obs.GetN())):
        if obs.GetY()[i] < 0.00000001:
            print "    REMOVING POINT", obs.GetY(
            )[i], " corresponding mass=", obs.GetX()[i]
            obs.RemovePoint(i)
    print

    graphs["exp"] = limits.expectedGraph()
    graphs["exp1"] = limits.expectedBandGraph(sigma=1)
    graphs["exp2"] = limits.expectedBandGraph(sigma=2)

    if obs.GetN() > 0:
        graphs["obs"] = obs
        # Get theory uncertainties on observed
#        obs_th_plus = limit.getObservedPlus(obs,0.21)
#        obs_th_minus = limit.getObservedMinus(obs,0.21)
#        for gr in [obs_th_plus, obs_th_minus]:
#            gr.SetLineWidth(2)
#            gr.SetLineStyle(9)
#        graphs["obs_th_plus"] = obs_th_plus
#        graphs["obs_th_minus"] = obs_th_minus

# Remove m=80
    for gr in graphs.values():
        limit.cleanGraph(gr, 80)

    print "Plotting graphs"
    for key in graphs.keys():
        for i in range(graphs[key].GetN()):
            xs = graphs[key].GetX()
            ys = graphs[key].GetY()
            print "    ", key, xs[i], ys[i]
        print

    # Interpret in MSSM
    xVariable = "mHp"
    selection = "mu==200"
    #    selection = "mHp > 0"
    #    scenario = "MSSM m_{h}^{max}"
    scenario = os.path.split(rootfile)[-1].replace(".root", "")

    from JsonWriter import JsonWriter
    jsonWriter = JsonWriter()
    for key in graphs.keys():
        print "Graph--------------------------------", key
        graphs[key] = db.graphToTanBetaCombined(graphs[key], xVariable,
                                                selection)
        #if key == "obs":
        #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+")
        #graphs["obs_th_plus"] = db.graphToTanBetaCombined(obsplus,xVariable,selection)
        #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-")
        #graphs["obs_th_minus"] = db.graphToTanBetaCombined(obsminus,xVariable,selection)
        print key, "done"
        jsonWriter.addGraph(key, graphs[key])

    graphs["mintanb"] = db.minimumTanbGraph("mHp", selection)

    if scenario == "lowMH-LHCHXSWG":
        graphs["Allowed"] = db.mhLimit("mH", "mHp", selection, "125.0+-3.0")
    else:
        graphs["Allowed"] = db.mhLimit("mh", "mHp", selection, "125.0+-3.0")


#    graphs["isomass"] = None

    jsonWriter.addGraph("Allowed", graphs["Allowed"])
    jsonWriter.addGraph("mintanb", graphs["mintanb"])

    jsonWriter.addParameter("name", "limitsTanb_light_" + scenario)
    jsonWriter.addParameter("scenario", scenario)
    jsonWriter.addParameter("luminosity", limits.getLuminosity())
    jsonWriter.addParameter("finalStateText", limits.getFinalstateText())
    jsonWriter.addParameter("mHplus", limit.mHplus())
    jsonWriter.addParameter("selection", selection)
    jsonWriter.addParameter("regime", "light")
    jsonWriter.write("MSSMLimitLight_" + scenario + ".json")

    limit.doTanBetaPlotLight("limitsTanb_light_" + scenario, graphs,
                             limits.getLuminosity(),
                             limits.getFinalstateText(), limit.mHplus(),
                             scenario)
    sys.exit()

    # mH+ -> mA
    print "Replotting the graphs for (mA,tanb)"
    for key in graphs.keys():
        print key
        #db.PrintGraph(graphs[key])
        #print "check loop db.graphToMa"
        db.graphToMa(graphs[key])

    graphs["isomass"] = db.getIsoMass(160)

    limit.doTanBetaPlotLight("limitsTanb_mA_light_" + scenario, graphs,
                             limits.getLuminosity(),
                             limits.getFinalstateText(), limit.mA(), scenario)
Example #4
0
def main():
    if len(sys.argv) == 1:
        usage()

    rootfile = ""
    jsonfile = "limits.json"

    root_re = re.compile("(?P<rootfile>(\S*\.root))")
    json_re = re.compile("(?P<jsonfile>(\S*\.json))")
    for argv in sys.argv:
        match = root_re.search(argv)
        if match:
            rootfile = match.group(0)
        match = json_re.search(argv)
        if match:
            jsonfile = match.group(0)
#    jsonfile = "limits_heavy2016.json"
#    jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v3_heavy.json"
    jsonfile = "limits2016/limits_heavy_20171011.json"
    #    limits = limit.BRLimits(limitsfile=jsonfile,configfile="configurationHeavy.json")
    limits = limit.BRLimits(
        limitsfile=jsonfile,
        configfile="limits2016/heavyHplus_configuration.json")

    # Enable OpenGL
    ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1)

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    #if limit.forPaper:
    #    histograms.cmsTextMode = histograms.CMSMode.PAPER
    #histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp
    #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp
    histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY
    limit.forPaper = True  # to get GeV without c^2

    # Get BR limits

    masses = limits.mass
    brs = limits.observed

    print "Observed masses and sigma*BR's"
    for i in range(len(masses)):
        print "    ", masses[i], brs[i]

    global db
    db = BRXSDB.BRXSDatabaseInterface(rootfile)
    db.BRvariable = "2*0.001*tHp_xsec*BR_Hp_taunu"  # XSEC only for H-, multiply with 2 to get H+ and H- ; multiply by 0.001 to fb -> pb
    for i, m in enumerate(masses):
        db.addExperimentalBRLimit(m, brs[i])

    graphs = {}
    obs = limits.observedGraph()

    # Remove blinded obs points
    for i in reversed(range(0, obs.GetN())):
        if obs.GetY()[i] < 0.00000001:
            print "    REMOVING POINT", obs.GetY(
            )[i], " corresponding mass=", obs.GetX()[i]
            obs.RemovePoint(i)
    print

    graphs["exp"] = limits.expectedGraph()
    graphs["exp1"] = limits.expectedBandGraph(sigma=1)
    graphs["exp2"] = limits.expectedBandGraph(sigma=2)

    if obs.GetN() > 0:
        graphs["obs"] = obs
        # Get theory uncertainties on observed
#        obs_th_plus = limit.getObservedPlus(obs,0.32)
#        obs_th_minus = limit.getObservedMinus(obs,0.32)
#        for gr in [obs_th_plus, obs_th_minus]:
#            gr.SetLineWidth(2)
#            gr.SetLineStyle(9)
#        graphs["obs_th_plus"] = obs_th_plus
#        graphs["obs_th_minus"] = obs_th_minus

# Remove m=180,190
    for gr in graphs.values():
        #        limit.cleanGraph(gr, 750)
        limit.cleanGraph(gr, 800)
        limit.cleanGraph(gr, 1000)
        limit.cleanGraph(gr, 2000)
        limit.cleanGraph(gr, 3000)

    print "Plotting graphs"
    for key in graphs.keys():
        for i in range(graphs[key].GetN()):
            xs = graphs[key].GetX()
            ys = graphs[key].GetY()
            print "    ", key, xs[i], ys[i]
        print

    # Interpret in MSSM
    xVariable = "mHp"
    selection = "mHp > 0 && mu==200"
    #    selection = "mHp > 0 && mu==500"
    #    scenario = "MSSM m_{h}^{max}"
    scenario = os.path.split(rootfile)[-1].replace(".root", "")
    print scenario

    from JsonWriter import JsonWriter
    jsonWriter = JsonWriter()
    for key in graphs.keys():
        print "Graph--------------------------------", key
        graphs[key] = db.graphToTanBeta(graphs[key],
                                        xVariable,
                                        selection,
                                        highTanbRegion=True)
        #if key == "obs":
        #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+")
        #graphs["obs_th_plus"] = db.graphToTanBeta(obsplus,xVariable,selection)
        #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-")
        #graphs["obs_th_minus"] = db.graphToTanBeta(obsminus,xVariable,selection)
        print key, "done"
        jsonWriter.addGraph(key, graphs[key])

#    graphs["mintanb"] = db.minimumTanbGraph("mHp",selection)
    if scenario == "lowMH-LHCHXSWG":
        graphs["Allowed"] = db.mhLimit("mH", "mHp", selection, "125.0+-3.0")
    else:
        graphs["Allowed"] = db.mhLimit("mh", "mHp", selection + "&&mHp>175",
                                       "125.0+-3.0")

    if scenario == "tauphobic-LHCHXSWG":
        # Fix a buggy second upper limit (the order of points is left to right, then right to left; remove further passes to fix the bug)
        decreasingStatus = False
        i = 0
        while i < graphs["Allowed"].GetN():
            removeStatus = False
            y = graphs["Allowed"].GetY()[i]
            if i > 0:
                if graphs["Allowed"].GetY()[i - 1] - y < 0:
                    decreasingStatus = True
                else:
                    if decreasingStatus:
                        graphs["Allowed"].RemovePoint(i)
                        removeStatus = True
            if not removeStatus:
                i += 1
        #for i in range(0, graphs["Allowed"].GetN()):
        #print graphs["Allowed"].GetX()[i], graphs["Allowed"].GetY()[i]


#    del graphs["isomass"]

    jsonWriter.addGraph("Allowed", graphs["Allowed"])

    jsonWriter.addParameter("name", "limitsTanb_heavy_" + scenario)
    jsonWriter.addParameter("scenario", scenario)
    jsonWriter.addParameter("luminosity", limits.getLuminosity())
    jsonWriter.addParameter("finalStateText", limits.getFinalstateText())
    jsonWriter.addParameter("mHplus", limit.mHplus())
    jsonWriter.addParameter("selection", selection)
    jsonWriter.addParameter("regime", "heavy")
    jsonWriter.write("MSSMLimitHeavy_" + scenario + ".json")

    limit.doTanBetaPlotHeavy("limitsTanb_heavy_" + scenario, graphs,
                             limits.getLuminosity(),
                             limits.getFinalstateText(), limit.mHplus(),
                             scenario)
    sys.exit()

    # mH+ -> mA
    print "Replotting the graphs for (mA,tanb)"
    for key in graphs.keys():
        print key
        #db.PrintGraph(graphs[key])
        #print "check loop db.graphToMa"
        db.graphToMa(graphs[key])

    graphs["isomass"] = db.getIsoMass(200)

    #    doPlot("limitsTanb_mA_heavy_"+scenario, graphs, limits, limit.mA(),scenario)

    limit.doTanBetaPlotHeavy("limitsTanb_mA_heavy_" + scenario, graphs,
                             limits.getLuminosity(),
                             limits.getFinalstateText(), limit.mA(), scenario)
Example #5
0
def main():
    if len(sys.argv) == 1:
        usage()

    rootfile = ""
    jsonfile = "limits.json"

    root_re = re.compile("(?P<rootfile>(\S*\.root))")
    json_re = re.compile("(?P<jsonfile>(\S*\.json))")
    for argv in sys.argv:
        match = root_re.search(argv)
        if match:
            rootfile = match.group(0)
        match = json_re.search(argv)
        if match:
            jsonfile = match.group(0)

    jsonfile = "limits2016/limits_withLeptonic_180522.json"
    limits = limit.BRLimits(limitsfile=jsonfile,
                            configfile="limits2016/mu_configuration.json")

    # Enable OpenGL
    ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1)

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    if limit.forPaper:
        histograms.cmsTextMode = histograms.CMSMode.PAPER

    # Get BR limits

    masses = limits.mass
    brs = limits.observed

    print "Observed masses and BR's"
    for i in range(len(masses)):
        print "    ", masses[i], brs[i]

    global db
    db = BRXSDB.BRXSDatabaseInterface(
        rootfile, BRvariable="0.001*831.76*2*tHp_xsec*BR_Hp_taunu")
    for i, m in enumerate(masses):
        db.addExperimentalBRLimit(m, brs[i])

    graphs = {}
    obs = limits.observedGraph()
    # Remove blinded obs points
    for i in reversed(range(0, obs.GetN())):
        if obs.GetY()[i] < 0.00000001:
            print "    REMOVING POINT", obs.GetY(
            )[i], " corresponding mass=", obs.GetX()[i]
            obs.RemovePoint(i)
    print

    #    graphs["exp"] = limits.expectedGraph()
    #x = array.array('d',masses)
    #y = array.array('d',[0.02]*len(masses))
    #graphs["exp"] = ROOT.TGraph(len(masses),x,y)
    #    graphs["exp1"] = limits.expectedBandGraph(sigma=1)
    #    graphs["exp2"] = limits.expectedBandGraph(sigma=2)

    if obs.GetN() > 0:
        graphs["obs"] = obs

    # Remove m=80
    for gr in graphs.values():
        limit.cleanGraph(gr, 80)

    print "Plotting graphs"
    for key in graphs.keys():
        for i in range(graphs[key].GetN()):
            xs = graphs[key].GetX()
            ys = graphs[key].GetY()
            print "    ", key, xs[i], ys[i]
        print

    # Interpret in MSSM
    xVariable = "mu"
    scenario = os.path.split(rootfile)[-1].replace(".root", "")
    if scenario == "lowMHaltv-LHCHXSWG":
        xVariable = "mHp"
    selection = ""
    from JsonWriter import JsonWriter
    #    for i in range(len(masses)):
    #        mass = masses[i]
    #        brlimit = brs[i]
    #	if mass < 90:
    #	    continue
    #        if not mass == 160:
    #            continue
    #	selection = "mHp == %s"%mass
    #graphs["muexcluded"] = db.muLimit(mass,"mu",selection,brlimit)
    #db.PrintGraph(graphs["muexcluded"],"muexcluded")

    jsonWriter = JsonWriter()
    print "check keys", graphs.keys()

    for key in graphs.keys():
        print "Graph--------------------------------", key
        #db.PrintGraph(graphs[key],"Before graphToTanBetaCombined")
        graphs[key] = db.graphToTanBetaMu(graphs[key], xVariable, selection,
                                          True)
        print key, "done"
        jsonWriter.addGraph(key, graphs[key])

    #graphs["Allowed"] = db.mhLimit("mH","mu",selection,"125.0+-3.0")
    if xVariable == "mHp":
        graphs["Allowed"] = db.mHLimit_mHp(selection, "125.0+-3.0")
    else:
        graphs["Allowed"] = db.mHLimit_mu(selection, "125.0+-3.0")
    jsonWriter.addGraph("Allowed", graphs["Allowed"])

    graphs["Inaccessible"] = db.inaccessible(xVariable, selection)
    jsonWriter.addGraph("Inaccessible", graphs["Inaccessible"])

    jsonWriter.addParameter("name", "limitsTanb_light_" + scenario)
    jsonWriter.addParameter("scenario", scenario)
    jsonWriter.addParameter("luminosity", limits.getLuminosity())
    jsonWriter.addParameter("finalStateText", limits.getFinalstateText())
    xvar = limit.mu()
    if xVariable == "mHp":
        xvar = limit.mHplus()
    jsonWriter.addParameter("mHplus", xvar)
    jsonWriter.addParameter("selection", selection)
    jsonWriter.addParameter("regime", "mu")
    jsonWriter.write("MSSMLimitMu_" + scenario + ".json")

    #limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario)
    #        if int(mass) in [155, 160]:
    #            graphs["obs_th_plus"] = db.muLimit(mass,"mu",selection,brlimit*(1+0.29))
    #            graphs["obs_th_minus"] = db.muLimit(mass,"mu",selection,brlimit*(1-0.29))
    #
    #            for gr in [graphs["obs_th_plus"], graphs["obs_th_minus"]]:
    #                gr.SetLineWidth(2)
    #                gr.SetLineStyle(9)
    #
    #            graphs["observed"] = graphs["muexcluded"].Clone()
    #            graphs["observed"].SetLineWidth(2)
    #            graphs["observed"].SetLineStyle(ROOT.kSolid)
    #            graphs["observed"].SetLineColor(ROOT.kBlack)
    #
    #            # Remove obs point
    #            for name in ["observed", "obs_th_plus", "obs_th_minus"]:
    #                gr = graphs[name]
    #                print "Graph", name
    #                for i in reversed(range(0,gr.GetN())):
    #                    if gr.GetY()[i] < 2 or gr.GetY()[i] > 65:
    #                        print "    REMOVING POINT",gr.GetY()[i]," corresponding mass=",gr.GetX()[i]
    #                        gr.RemovePoint(i)
    #
    #        graphs["Allowed"]  = db.getHardCoded_mH_limitForMu(mass,0)
    #        graphs["Allowed2"] = db.getHardCoded_mH_limitForMu(mass,1)
    #
    #        doPlot(("limitsMu_light_mHp%s_"+scenario)%(int(mass)), graphs, limits, "#mu (GeV)",scenario, int(mass))
    sys.exit()
def main():
    if len(sys.argv) == 1:
        usage()

    rootfile = ""
    jsonfile = "limits.json"

    root_re = re.compile("(?P<rootfile>(\S*\.root))")
    json_re = re.compile("(?P<jsonfile>(\S*\.json))")
    for argv in sys.argv:
        match = root_re.search(argv)
        if match:
            rootfile = match.group(0)
        match = json_re.search(argv)
        if match:
            jsonfile = match.group(0)
#    jsonfile = "limits_light2016.json"
#    jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v2_light.json"
#    jsonfile = "limits2016/limits_light_20171011.json"
#    jsonfile = "limits2016/limits_light_180131.json"
#    jsonfile = "limits2016/limits_light_180205.json"
#    jsonfile = "limits2016/limits_light_180318.json"
#    jsonfile = "limits2016/limits_light_180417.json"
#    jsonfile = "limits2016/limits_unblinded_180809/limits_light.json"
#    jsonfile = "limits2016/limits_unblinded_180809/limits_full_leptonic+hadronic_with_intermediate.json"
    jsonfile = "limits2016/limits_unblinded_withLeptonic_30082018/taunu_extInt_BR.json"
#    limits = limit.BRLimits(limitsfile=jsonfile,configfile="limitdata/lightHplus_configuration.json")
    limits = limit.BRLimits(limitsfile=jsonfile,configfile="limits2016/lightHplus_configuration.json")

    # Enable OpenGL
    ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1)

    # Apply TDR style
    style = tdrstyle.TDRStyle()
#    if limit.forPaper:
#        histograms.cmsTextMode = histograms.CMSMode.PAPER
    histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY
#    histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp
    #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp
    limit.forPaper = True # to get GeV without c^2

    # Get BR limits

    masses = limits.mass
    brs    = limits.observed

    print "Observed masses and BR's"
    for i in range(len(masses)):
        print "    ",masses[i],brs[i]

    global db
    db = BRXSDB.BRXSDatabaseInterface(rootfile)
    for i,m in enumerate(masses):
        db.addExperimentalBRLimit(m,brs[i])


    graphs = {}
    obs = limits.observedGraph()
    # Remove blinded obs points
    for i in reversed(range(0,obs.GetN())):
        if obs.GetY()[i] < 0.00000001:
            print "    REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i]
            obs.RemovePoint(i)
    print
    
    graphs["exp"] = limits.expectedGraph()
    graphs["exp1"] = limits.expectedBandGraph(sigma=1)
    graphs["exp2"] = limits.expectedBandGraph(sigma=2)

    if obs.GetN() > 0:
        graphs["obs"] = obs
        # Get theory uncertainties on observed
#        obs_th_plus = limit.getObservedPlus(obs,0.21)
#        obs_th_minus = limit.getObservedMinus(obs,0.21)
#        for gr in [obs_th_plus, obs_th_minus]:
#            gr.SetLineWidth(2)
#            gr.SetLineStyle(9)
#        graphs["obs_th_plus"] = obs_th_plus
#        graphs["obs_th_minus"] = obs_th_minus
        

    # Remove m=80
    for gr in graphs.values():
        limit.cleanGraph(gr, 80)

    print "Plotting graphs"                    
    for key in graphs.keys():
        for i in range(graphs[key].GetN()):
            xs = graphs[key].GetX()
            ys = graphs[key].GetY()
            print "    ",key,xs[i],ys[i]
        print

    # Interpret in MSSM
    xVariable = "mHp"
    selection = "mu==200"
#    selection = "mHp > 0"
#    scenario = "MSSM m_{h}^{max}"
    scenario = os.path.split(rootfile)[-1].replace(".root","")

    from JsonWriter import JsonWriter
    jsonWriter = JsonWriter()
    for key in graphs.keys():
        print "Graph--------------------------------",key
        graphs[key] = db.graphToTanBetaCombined(graphs[key],xVariable,selection)
        #if key == "obs":
            #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+")
            #graphs["obs_th_plus"] = db.graphToTanBetaCombined(obsplus,xVariable,selection)
            #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-")
            #graphs["obs_th_minus"] = db.graphToTanBetaCombined(obsminus,xVariable,selection)
        print key,"done"
        jsonWriter.addGraph(key,graphs[key])

    graphs["mintanb"] = db.minimumTanbGraph("mHp",selection)
    
    if scenario == "lowMH-LHCHXSWG":
	graphs["Allowed"] = db.mhLimit("mH","mHp",selection,"125.0+-3.0")
    else:
        graphs["Allowed"] = db.mhLimit("mh","mHp",selection,"125.0+-3.0")
#    graphs["isomass"] = None

    jsonWriter.addGraph("Allowed",graphs["Allowed"])
    jsonWriter.addGraph("mintanb",graphs["mintanb"])

    name = "limitsTanb_light_"
    finalStateText = limits.getFinalstateText()
    if "leptonic" in jsonfile:
        name = "limitsTanb_light_LeptHadrFS_"
        finalStateText = "#tau+jets final state"
    
    jsonWriter.addParameter("name",name+scenario)
    jsonWriter.addParameter("scenario",scenario)
    jsonWriter.addParameter("luminosity",limits.getLuminosity())
    jsonWriter.addParameter("finalStateText",finalStateText)
    jsonWriter.addParameter("mHplus",limit.mHplus())
    jsonWriter.addParameter("selection",selection)
    jsonWriter.addParameter("regime","light")
    jsonWriter.write(name+scenario+".json")

    limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario)
    sys.exit()

    # mH+ -> mA
    print "Replotting the graphs for (mA,tanb)"
    for key in graphs.keys():
        print key
        #db.PrintGraph(graphs[key])
        #print "check loop db.graphToMa"
        db.graphToMa(graphs[key])

    graphs["isomass"] = db.getIsoMass(160)

    limit.doTanBetaPlotLight("limitsTanb_mA_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def main():
    if len(sys.argv) == 1:
        usage()

    rootfile = ""
    jsonfile = "limits.json"

    root_re = re.compile("(?P<rootfile>(\S*\.root))")
    json_re = re.compile("(?P<jsonfile>(\S*\.json))")
    for argv in sys.argv:
        match = root_re.search(argv)
        if match:
            rootfile = match.group(0)
        match = json_re.search(argv)
        if match:
            jsonfile = match.group(0)

    jsonfile = "limits2016/limits_withLeptonic_180522.json"
    limits = limit.BRLimits(limitsfile=jsonfile,configfile="limits2016/mu_configuration.json")

    # Enable OpenGL
    ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1)

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    if limit.forPaper:
        histograms.cmsTextMode = histograms.CMSMode.PAPER

    # Get BR limits

    masses = limits.mass
    brs    = limits.observed

    print "Observed masses and BR's"
    for i in range(len(masses)):
        print "    ",masses[i],brs[i]

    global db
    db = BRXSDB.BRXSDatabaseInterface(rootfile,BRvariable= "0.001*831.76*2*tHp_xsec*BR_Hp_taunu")
    for i,m in enumerate(masses):
        db.addExperimentalBRLimit(m,brs[i])


    graphs = {}
    obs = limits.observedGraph()
    # Remove blinded obs points
    for i in reversed(range(0,obs.GetN())):
        if obs.GetY()[i] < 0.00000001:
            print "    REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i]
            obs.RemovePoint(i)
    print

#    graphs["exp"] = limits.expectedGraph()
    #x = array.array('d',masses)
    #y = array.array('d',[0.02]*len(masses))
    #graphs["exp"] = ROOT.TGraph(len(masses),x,y)
#    graphs["exp1"] = limits.expectedBandGraph(sigma=1)
#    graphs["exp2"] = limits.expectedBandGraph(sigma=2)

    if obs.GetN() > 0:
        graphs["obs"] = obs



    # Remove m=80
    for gr in graphs.values():
        limit.cleanGraph(gr, 80)

    print "Plotting graphs"
    for key in graphs.keys():
        for i in range(graphs[key].GetN()):
            xs = graphs[key].GetX()
            ys = graphs[key].GetY()
            print "    ",key,xs[i],ys[i]
        print

    # Interpret in MSSM
    xVariable = "mu"
    scenario = os.path.split(rootfile)[-1].replace(".root","")
    if scenario == "lowMHaltv-LHCHXSWG":
        xVariable = "mHp"
    selection = ""
    from JsonWriter import JsonWriter
#    for i in range(len(masses)):
#        mass = masses[i]
#        brlimit = brs[i]
#	if mass < 90:
#	    continue 
#        if not mass == 160:
#            continue
#	selection = "mHp == %s"%mass 
        #graphs["muexcluded"] = db.muLimit(mass,"mu",selection,brlimit)
        #db.PrintGraph(graphs["muexcluded"],"muexcluded")

    jsonWriter = JsonWriter()
    print "check keys",graphs.keys()

    for key in graphs.keys():
        print "Graph--------------------------------",key
        #db.PrintGraph(graphs[key],"Before graphToTanBetaCombined")
        graphs[key] = db.graphToTanBetaMu(graphs[key],xVariable,selection,True)
        print key,"done"
        jsonWriter.addGraph(key,graphs[key])

    #graphs["Allowed"] = db.mhLimit("mH","mu",selection,"125.0+-3.0")
    if xVariable == "mHp":
        graphs["Allowed"] = db.mHLimit_mHp(selection,"125.0+-3.0")
    else:
        graphs["Allowed"] = db.mHLimit_mu(selection,"125.0+-3.0")
    jsonWriter.addGraph("Allowed",graphs["Allowed"])

    graphs["Inaccessible"] = db.inaccessible(xVariable,selection)
    jsonWriter.addGraph("Inaccessible",graphs["Inaccessible"])
    
    jsonWriter.addParameter("name","limitsTanb_light_"+scenario)
    jsonWriter.addParameter("scenario",scenario)
    jsonWriter.addParameter("luminosity",limits.getLuminosity())
    jsonWriter.addParameter("finalStateText",limits.getFinalstateText())
    xvar = limit.mu()
    if xVariable == "mHp":
        xvar = limit.mHplus()
    jsonWriter.addParameter("mHplus",xvar)
    jsonWriter.addParameter("selection",selection)
    jsonWriter.addParameter("regime","mu")
    jsonWriter.write("MSSMLimitMu_"+scenario+".json")

        #limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario)
#        if int(mass) in [155, 160]:
#            graphs["obs_th_plus"] = db.muLimit(mass,"mu",selection,brlimit*(1+0.29))
#            graphs["obs_th_minus"] = db.muLimit(mass,"mu",selection,brlimit*(1-0.29))
#
#            for gr in [graphs["obs_th_plus"], graphs["obs_th_minus"]]:
#                gr.SetLineWidth(2)
#                gr.SetLineStyle(9)
#
#            graphs["observed"] = graphs["muexcluded"].Clone()
#            graphs["observed"].SetLineWidth(2)
#            graphs["observed"].SetLineStyle(ROOT.kSolid)
#            graphs["observed"].SetLineColor(ROOT.kBlack)
#
#            # Remove obs point
#            for name in ["observed", "obs_th_plus", "obs_th_minus"]:
#                gr = graphs[name]
#                print "Graph", name
#                for i in reversed(range(0,gr.GetN())):
#                    if gr.GetY()[i] < 2 or gr.GetY()[i] > 65:
#                        print "    REMOVING POINT",gr.GetY()[i]," corresponding mass=",gr.GetX()[i]
#                        gr.RemovePoint(i)
#
#        graphs["Allowed"]  = db.getHardCoded_mH_limitForMu(mass,0)
#        graphs["Allowed2"] = db.getHardCoded_mH_limitForMu(mass,1)
#
#        doPlot(("limitsMu_light_mHp%s_"+scenario)%(int(mass)), graphs, limits, "#mu (GeV)",scenario, int(mass))
    sys.exit()