Пример #1
0
def install(arguments):
    """ Installs docker images and containers."""
    setup_logging(log_file=arguments.log_file)

    if arguments.limit:
        container_setup.limit_install(str(arguments.limit).split(","))

    else:
        container_setup.check_dependencies(log_file=arguments.log_file)
        container_setup.stop_containers([
            "apigateway", "broker", "ldapd", "catalogue", "videoserver",
            "webserver", "elasticsearch", "konga"
        ],
                                        log_file=arguments.log_file)
        container_setup.remove_containers([
            "apigateway", "broker", "ldapd", "catalogue", "videoserver",
            "webserver", "elasticsearch", "konga"
        ],
                                          log_file=arguments.log_file)
        container_setup.remove_volumes(
            ["apigateway", "broker", "cat", "elk", "ldapd", "webserver"],
            log_file=arguments.log_file)
        password.set_passwords(arguments.config_file)
        container_setup.docker_setup(log_file=arguments.log_file,
                                     config_path=arguments.config_file)
        setup.initial_setup(log_file=arguments.log_file)
        password.update_passwords(arguments.config_file)
        setup.initial_setup_cleanup(log_file=arguments.log_file)
Пример #2
0
def install(arguments):
    """ Installs docker images and containers."""
    setup_logging(log_file=arguments.log_file)

    if arguments.limit:

        if arguments.quick:
            quick_setup.limit_install(arguments.limit)
        else:
            container_setup.ansible_installation(arguments.limit)
    else:

        container_setup.check_dependencies(log_file=arguments.log_file)

        if not arguments.quick:
            container_setup.stop_containers(log_file=arguments.log_file)
            container_setup.remove_containers(log_file=arguments.log_file)

        else:
            quick_setup.stop_containers(log_file=arguments.log_file)
            quick_setup.remove_containers(log_file=arguments.log_file)

        if not arguments.quick:
            download_packages.download(arguments.log_file)

        set_passwords(arguments.config_file)

        if arguments.quick:
            quick_setup.docker_setup(log_file=arguments.log_file,config_path=arguments.config_file)
        else:
            container_setup.docker_setup(log_file=arguments.log_file, config_path=arguments.config_file)
            subprocess.call('ansible-playbook -i hosts install.yaml '
                        '--limit "kong, rabbitmq, elasticsearch, apt_repo, tomcat, ldapd,'
                        ' catalogue, videoserver, pushpin"', shell=True)
Пример #3
0
def generalTest(loglev):
    import ROOT

    import modules.DataMC
    import modules.classes

    setup_logging(loglevel=loglev, logname="testoutput", errname="testerror")

    logger = logging.getLogger(__name__)

    logger.info("Starting general test")

    if args.logging > 0:
        ROOT.gErrorIgnoreLevel = ROOT.kError  # kPrint, kInfo, kWarning, kError, kBreak, kSysError, kFatal;

    MCInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v1/ttbar/ttbar_v1_partial2.root"
    DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v1/MuonEG/MuonEG_v1_partial2.root"

    logging.info("Testing if files exist")
    for fpath in [MCInput, DataInput]:
        if os.path.exists(fpath):
            logging.info("File {0} exists".format(fpath.split("/")[-1]))
        else:
            logging.error("File {0} does NOT exist".format(
                fpath.split("/")[-1]))

    MCSample = modules.classes.Sample("ttbar", MCInput, "1", 831.76,
                                      4591.622871124, ROOT.kRed, 9937324)
    DataSample = modules.classes.Sample("MuonEG", DataInput, color=ROOT.kBlack)

    logging.info("Testing samples")
    for sample in [MCSample, DataSample]:
        if sample.tree != 0:
            logging.info("Tree for sample {0} exists".format(sample.name))
            logging.info("Tree has {0} entries".format(sample.nEvents))
        else:
            error.info("Tree for sample {0} does NOT exist".format(
                sample.name))

    OffpT = modules.classes.PlotBase(
        "offJets_pt", "offJets_pt > 30 && Sum$(offJets_csv > 0.6) >= 2", "1",
        [30, 0, 300], "Offline Jet p_{T}")
    OffpT.printVarLog()

    logging.info("Drawing basic DataMC plot w/o ratio")
    modules.DataMC.makeDataMCPlot(OffpT,
                                  DataSample,
                                  MCSample,
                                  normalized=True,
                                  outname="Test_DataMC")

    logging.info("Drawing basic DataMC plot w/ ratio")
    modules.DataMC.makeDataMCPlotwRatio(OffpT,
                                        DataSample,
                                        MCSample,
                                        outname="Test_DataMCwRatio")

    logging.info("Closing general test")
Пример #4
0
def quick_start(arguments):

    setup_logging(log_file=arguments.log_file)
    quickstart.start_containers(arguments.log_file)

    if arguments.limit:
        quickstart.start_services(arguments.limit)
    else:
        quickstart.start_services("kong,rabbitmq,ldapd,elasticsearch,videoserver,tomcat,catalogue")
Пример #5
0
 def __init__(self):
     """
     constructor
     """
     cfg = get_data('config')
     bucket = cfg.get('bucket_name')
     region = cfg.get('region')
     self.trilio_base_dir = cfg.get('trilio_base_dir')
     container_json_path = cfg.get('container_json_path')
     key_pair = cfg.get('key_pair')
     self.app = App(bucket, region, container_json_path,\
                    self.trilio_base_dir, key_pair)
     setup_logging(name=cfg.get('app_name'), level=cfg.get('log_level'))
     self.logger = logging.getLogger(__name__)
Пример #6
0
def start(arguments):
    """ Starts all docker containers. """
    setup_logging(log_file=arguments.log_file)
    container_start.start_containers([
        "apigateway", "broker", "ldapd", "elasticsearch", "videoserver",
        "webserver", "catalogue", "konga"
    ], arguments.log_file)
    container_start.start_volumes(
        ["apigateway", "broker", "cat", "elk", "ldapd", "webserver"],
        log_file=arguments.log_file)

    if arguments.limit:
        container_start.start_services(str(arguments.limit).split(","))

    else:
        container_start.start_services([
            "apigateway", "broker", "ldapd", "elasticsearch", "videoserver",
            "webserver", "catalogue"
        ])
Пример #7
0
    target_compid = config["SESSION"]["TargetCompID"]

    settings = fix.SessionSettings(client_config)
    store = fix.FileStoreFactory(settings)
    app = MarketDataClient()

    app.set_logging(logger)

    initiator = fix.SocketInitiator(app, store, settings)

    initiator.start()

    sleep(1)

    symbol = input("Enter symbol to subscribe: ")

    app.market_data_request(sender_compid, target_compid, [symbol])

    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        logger.info("Caught interrupt, exiting...")
        initiator.stop()
        sys.exit()


if __name__ == "__main__":
    logger = setup_logging("logs/", "client")
    main()
Пример #8
0
def efficiencies(loglev, run, doMC, doData, doCSV, doDeepCSV, CSVWPs,
                 DeepCSVWPs, ptordered, csvordered, doinclusive,
                 nInclusiveIter, dosplit, nSplitIter, doCross, compWPs,
                 looseSel):
    import ROOT

    import modules.classes
    import modules.effPlots

    setup_logging(loglevel=loglev,
                  logname="efficiencyoutput",
                  errname="efficiencyerror")

    logger = logging.getLogger(__name__)

    logger.info("Starting shape comparison")
    t0 = time.time()

    if not (doMC or doData):
        if __name__ == "__main__":
            logging.warning(
                "At least on of the flags --mc and --data should to be set")
            logging.warning("Falling back the only mc")
        else:
            logging.warning(
                "At least on of the paramters doMC and doData should to be set"
            )
            logging.warning("Falling back the only mc")
        doMC = True

    if not (ptordered or csvordered):
        if __name__ == "__main__":
            logging.warning(
                "At least on of the flags --ptorderd and --csvordered should to be set"
            )
            logging.warning("Falling back to pt ordered")
        else:
            logging.warning(
                "At least on of the paramters ptordered and ptordered should to be set"
            )
            logging.warning("Falling back to pt ordered")
        ptordered = True

    if loglev > 0:
        ROOT.gErrorIgnoreLevel = ROOT.kBreak  # kPrint, kInfo, kWarning, kError, kBreak, kSysError, kFatal;

    if run == "CD":
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v8/MuonEG/MuonEG_RunCD_phase1_0p9970p996_mod_mod_mod.root"
        basepaths = "v8nTuples/Efficiencies/RunCD/"
        fileprefix = "RunCD_"
    if run == "E":
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v8/MuonEG/RunE/phase1/MuonEG_RunE_phase1_mod_mod_mod.root"
        basepaths = "v8nTuples/Efficiencies/RunE/"
        fileprefix = "RunE_EmilSel_"
    if run == "F":
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v8/MuonEG/RunF/phase1/MuonEG_RunF_phase1_mod_mod_mod.root"
        basepaths = "v8nTuples/Efficiencies/RunF/"
        fileprefix = "RunF_"

    if run == "Test":
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/trigger/onlineBTV/CMSSW_9_2_12_patch1/src/HLTBTagging/nTuples/tree_phase1.root"
        basepaths = "testing/emilComp3K/"
        fileprefix = "Tesing_"

    #MCInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v3/ttbar/ttbar_v3.root"
    MCInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v8/ttbar/phase1/ttbar_0p85_mod_mod_mod.root"

    MCSelection = "1"
    VarSelection = "1"

    DeepCSVSelWP = "0.8958"
    if looseSel:
        TriggerSelection = "1"
        LeptonSelection = "1"
        offlineSelection = "1"
        CSVSelection = "1"

    else:
        TriggerSelection = "HLT_Mu12_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v4 > 0 || HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_v4 > 0"
        LeptonSelection = "Sum$((abs(offTightElectrons_superClusterEta) <= 1.4442 || abs(offTightElectrons_superClusterEta) >= 1.5660) && offTightElectrons_pt > 30 && abs(offTightElectrons_eta) < 2.4) > 0 && Sum$(offTightMuons_iso < 0.25 && offTightMuons_pt > 20 && abs(offTightMuons_eta) < 2.4) > 0"
        offlineSelection = "Sum$(cleanJets_pt > 30 && abs(cleanJets_eta) < 2.4) > 2"
        CSVSelection = "Sum$(cleanJets_deepcsv > {0}) >= 1".format(
            DeepCSVSelWP)

    logging.info(
        "Using: doMC: {0} | doData: {1} | doCSV: {2} | doDeepCSV: {3}".format(
            doMC, doData, doCSV, doDeepCSV))

    samples = []
    if doMC:
        eventSelection = "({0}) && ({1}) && ({2}) && ({3})".format(
            VarSelection, TriggerSelection, LeptonSelection, MCSelection)
        samples.append(
            (modules.classes.Sample("ttbar",
                                    MCInput,
                                    eventSelection,
                                    831.76,
                                    4591.622871124,
                                    ROOT.kRed,
                                    9937324,
                                    legendText="Dataset: t#bar{t}"), "MC",
             getLabel("Dataset: t#bar{t}", 0.7)))
    if doData:
        eventSelection = "({0}) && ({1}) && ({2})".format(
            VarSelection, TriggerSelection, LeptonSelection)
        samples.append(
            (modules.classes.Sample("data",
                                    DataInput,
                                    eventSelection,
                                    legendText="Dataset: MuonEG"), "MuonEG",
             getLabel("Dataset: MuonEG", 0.7)))

    CSVSelWP = "0.9535"

    WPColors = [
        ROOT.kRed, ROOT.kBlue, ROOT.kGreen + 2, ROOT.kPink + 7, ROOT.kViolet,
        ROOT.kCyan
    ]

    #CSVSelection = "Sum$(cleanJets_csv > {0}) >= 1".format(CSVSelWP)

    refbyCSVRank = {
        0: "cleanJets_ileadingCSV",
        1: "cleanJets_isecondCSV",
        2: "cleanJets_ithirdCSV",
        3: "cleanJets_ifourthCSV"
    }

    refbyDeepCSVRank = {
        0: "cleanJets_ileadingDeepCSV",
        1: "cleanJets_isecondDeepCSV",
        2: "cleanJets_ithirdDeepCSV",
        3: "cleanJets_ifourthDeepCSV"
    }

    if doCSV:
        logging.info("Processing plots for CSV")
        CSVPlotBaseObjs = {}

        collections = []
        if ptordered:
            #collections.append( ("pT", "cleanJets") )
            collections.append(("pT", "offJets"))
            logging.debug("Adding {1} to collecton as ordered by {0}".format(
                "ptOrdered", "offJets"))
        if csvordered:
            collections.append(("CSV", "cleanCSVJets"))
            logging.debug("Adding {1} to collecton as ordered by {0}".format(
                "csvOrdered", "cleanCSVJets"))

        for WP in CSVWPs:
            WPLabel = getLabel("PF WP: {0}".format(WP), 0.7, "under")
            CaloWPLabel = getLabel("Calo WP: {0}".format(WP), 0.7, "under")
            logging.info("Using WP: {0}".format(WP))
            for collectionName, collection in collections:

                if dosplit:
                    for i in range(nSplitIter):
                        if looseSel:
                            JetSelection = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format(
                                i, collection)
                        else:
                            JetSelection = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                                i, collection)

                        logging.info(
                            "Making effciency for Jet {0} ordered by {1} w/ CSV as tagger"
                            .format(i, collectionName))
                        logging.subinfo(
                            "Using collection: {0}".format(collection))
                        CSVPlotBaseObjs[i] = modules.classes.PlotBase(
                            "{1}_csv[{0}]".format(i, collection),
                            "{0} && {1} && ({2})".format(
                                CSVSelection, offlineSelection, JetSelection),
                            "1", [20, 0, 1],
                            modules.utils.getAxisTitle("csv", i,
                                                       collectionName.lower()),
                            LegendPosition=[0.1, 0.6, 0.4, 0.76])

                        CSVPlotBaseObjs[i].color = WPColors[i]
                        onlysamples = []

                        for sampleStuff in samples:
                            sample, name, label = sampleStuff
                            onlysamples.append(sample)
                            if not (doMC and doData):
                                modules.effPlots.makeEffPlot(
                                    CSVPlotBaseObjs[i],
                                    sample,
                                    "pfJets_csv[{2}_matchPF[{1}]] >= {0}".
                                    format(WP, i, collection),
                                    basepaths +
                                    "CSV/{3}/{4}Eff_{2}_Jet{0}_pfWP_{1}_CSV_order{3}"
                                    .format(i, WP, name, collectionName,
                                            fileprefix),
                                    addSel="{1}_matchPF[{0}] >= 0".format(
                                        i, collection),
                                    label=[label, WPLabel])

                                modules.effPlots.makeEffPlot(
                                    CSVPlotBaseObjs[i],
                                    sample,
                                    "caloJets_csv[{2}_matchCalo[{1}]] >= {0}".
                                    format(WP, i, collection),
                                    basepaths +
                                    "CSV/{3}/{4}Eff_{2}_Jet{0}_caloWP_{1}_CSV_order{3}"
                                    .format(i, WP, name, collectionName,
                                            fileprefix),
                                    addSel="{1}_matchCalo[{0}] >= 0".format(
                                        i, collection),
                                    label=[label, CaloWPLabel])

                        if doMC and doData:
                            modules.effPlots.makeEffSCompPlot(
                                CSVPlotBaseObjs[i],
                                onlysamples,
                                "pfJets_csv[{2}_matchPF[{1}]] >= {0}".format(
                                    WP, i, collection),
                                basepaths +
                                "CSV/{2}/{3}Eff_DataMC_Jet{0}_pfWP_{1}_CSV_order{2}"
                                .format(i, WP, collectionName, fileprefix),
                                addSel="{1}_matchPF[{0}] >= 0".format(
                                    i, collection),
                                label=WPLabel)
                            modules.effPlots.makeEffSCompPlot(
                                CSVPlotBaseObjs[i],
                                onlysamples,
                                "caloJets_csv[{2}_matchCalo[{1}]] >= {0}".
                                format(WP, i, collection),
                                basepaths +
                                "CSV/{2}/{3}Eff_DataMC_Jet{0}_caloWP_{1}_CSV_order{2}"
                                .format(i, WP, collectionName, fileprefix),
                                addSel="{1}_matchCalo[{0}] >= 0".format(
                                    i, collection),
                                label=CaloWPLabel)
                if doinclusive:
                    JetSelectionIter = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                        "?", collection)
                    logging.info(
                        "Making inclusive effciency ordered by {0} w/ CSV as tagger"
                        .format(collectionName))
                    logging.subinfo("Using collection: {0}".format(collection))
                    CSVPlotBaseObjIter = modules.classes.PlotBase(
                        "{1}_csv[{0}]".format("?", collection),
                        "{0} && {1} && ({2})".format(CSVSelection,
                                                     offlineSelection,
                                                     JetSelectionIter),
                        "1", [20, 0, 1],
                        modules.utils.getAxisTitle("csv",
                                                   0,
                                                   collectionName.lower(),
                                                   inclusive=True),
                        LegendPosition=[0.1, 0.6, 0.4, 0.76])
                    #CSVPlotBaseObjIter.color = WPColors[0]
                    onlysamples = []

                    for sampleStuff in samples:
                        sample, name, label = sampleStuff
                        onlysamples.append(sample)
                        if not (doMC and doData):
                            modules.effPlots.makeEffSumPlot(
                                CSVPlotBaseObjIter,
                                sample,
                                "pfJets_csv[{2}_matchPF[{1}]] >= {0}".format(
                                    WP, "?", collection),
                                nInclusiveIter,
                                basepaths +
                                "CSV/{3}/{4}Eff_{2}_Jet{0}_pfWP_{1}_CSV_order{3}"
                                .format("incl", WP, name, collectionName,
                                        fileprefix),
                                addSel="{1}_matchPF[{0}] >= 0".format(
                                    "?", collection),
                                label=[label, WPLabel])
                            modules.effPlots.makeEffSumPlot(
                                CSVPlotBaseObjIter,
                                sample,
                                "caloJets_csv[{2}_matchCalo[{1}]] >= {0}".
                                format(WP, "?", collection),
                                nInclusiveIter,
                                basepaths +
                                "CSV/{3}/{4}Eff_{2}_Jet{0}_caloWP_{1}_CSV_order{3}"
                                .format("incl", WP, name, collectionName,
                                        fileprefix),
                                addSel="{1}_matchCalo[{0}] >= 0".format(
                                    "?", collection),
                                label=[label, CaloWPLabel])

                    if doMC and doData:
                        modules.effPlots.makeEffSummSCompPlot(
                            CSVPlotBaseObjIter,
                            onlysamples,
                            "pfJets_csv[{2}_matchPF[{1}]] >= {0}".format(
                                WP, "?", collection),
                            nInclusiveIter,
                            basepaths +
                            "CSV/{2}/{3}Eff_DataMC_Jet{0}_pfWP_{1}_CSV_order{2}"
                            .format("incl", WP, collectionName, fileprefix),
                            addSel="{1}_matchPF[{0}] >= 0".format(
                                "?", collection),
                            label=WPLabel)
                        modules.effPlots.makeEffSummSCompPlot(
                            CSVPlotBaseObjIter,
                            onlysamples,
                            "caloJets_csv[{2}_matchCalo[{1}]] >= {0}".format(
                                WP, "?", collection),
                            nInclusiveIter,
                            basepaths +
                            "CSV/{2}/{3}Eff_DataMC_Jet{0}_caloWP_{1}_CSV_order{2}"
                            .format("incl", WP, collectionName, fileprefix),
                            addSel="{1}_matchCalo[{0}] >= 0".format(
                                "?", collection),
                            label=CaloWPLabel)

                if doCross:
                    if dosplit:
                        pass
                    if doinclusive:
                        if looseSel:
                            JetSelectionIter = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format(
                                "?", collection)
                        else:
                            JetSelectionIter = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                                "?", collection)
                        logging.info(
                            "Making inclusive effciency ordered by {0} w/ DeepCSV as tagger"
                            .format(collectionName))
                        logging.subinfo(
                            "Using collection: {0}".format(collection))
                        DeepCSVPlotBaseIter = modules.classes.PlotBase(
                            "{1}_deepcsv[{0}]".format("?", collection),
                            "{0} && {1} && ({2})".format(
                                CSVSelection, offlineSelection,
                                JetSelectionIter),
                            "1", [20, 0, 1],
                            modules.utils.getAxisTitle("deepcsv",
                                                       0,
                                                       collectionName.lower(),
                                                       inclusive=True),
                            LegendPosition=[0.1, 0.6, 0.4, 0.76])
                        onlysamples = []
                        for sampleStuff in samples:
                            sample, name, label = sampleStuff
                            onlysamples.append(sample)

                        if doMC and doData:
                            modules.effPlots.makeEffSummSCompPlot(
                                DeepCSVPlotBaseIter,
                                onlysamples,
                                "pfJets_csv[{2}_matchPF[{1}]] >= {0}".format(
                                    WP, "?", collection),
                                nInclusiveIter,
                                basepaths +
                                "CSV/{2}/{3}Eff_DataMC_Jet{0}_pfWP_{1}_CSV_order{2}"
                                .format("cross", WP, collectionName,
                                        fileprefix),
                                addSel="{1}_matchPF[{0}] >= 0".format(
                                    "?", collection),
                                label=WPLabel)
                            modules.effPlots.makeEffSummSCompPlot(
                                DeepCSVPlotBaseIter,
                                onlysamples,
                                "caloJets_csv[{2}_matchCalo[{1}]] >= {0}".
                                format(WP, "?", collection),
                                nInclusiveIter,
                                basepaths +
                                "CSV/{2}/{3}Eff_DataMC_Jet{0}_caloWP_{1}_CSV_order{2}"
                                .format("cross", WP, collectionName,
                                        fileprefix),
                                addSel="{1}_matchCalo[{0}] >= 0".format(
                                    "?", collection),
                                label=CaloWPLabel)

        if compWPs:
            logging.info("Makeing CSV WP comparison")
            for collectionName, collection in collections:
                #JetSelectionIter = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format("?", collection)
                if looseSel:
                    JetSelectionIter = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format(
                        "?", collection)
                else:
                    JetSelectionIter = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                        "?", collection)
                logging.info(
                    "Making inclusive  WP comparison ordered by {0} w/ CSV as tagger"
                    .format(collectionName))
                logging.subinfo("Using collection: {0}".format(collection))
                CSVPlotBaseObjIter = modules.classes.PlotBase(
                    "{1}_csv[{0}]".format("?", collection),
                    "{0} && {1} && ({2})".format(CSVSelection,
                                                 offlineSelection,
                                                 JetSelectionIter),
                    "1", [20, 0, 1],
                    modules.utils.getAxisTitle("csv",
                                               0,
                                               collectionName.lower(),
                                               inclusive=True),
                    LegendPosition=[0.1, 0.6, 0.4, 0.76])

                for sampleStuff in samples:
                    sample, name, label = sampleStuff
                    logging.info("Plotting sample {0}".format(name))
                    modules.effPlots.makeSumWPComp(
                        CSVPlotBaseObjIter,
                        sample,
                        "pfJets_csv[{1}_matchPF[{0}]]".format("?", collection),
                        nInclusiveIter,
                        CSVWPs,
                        basepaths +
                        "CSV/{3}/{4}Eff_{2}_Jet{0}_pfWPComp_{1}_CSV_order{3}".
                        format("incl", WP, name, collectionName, fileprefix),
                        addSel="{1}_matchPF[{0}] >= 0".format("?", collection))
                    modules.effPlots.makeSumWPComp(
                        CSVPlotBaseObjIter,
                        sample,
                        "caloJets_csv[{1}_matchCalo[{0}]]".format(
                            "?", collection),
                        nInclusiveIter,
                        CSVWPs,
                        basepaths +
                        "CSV/{3}/{4}Eff_{2}_Jet{0}_caloWPComp_{1}_CSV_order{3}"
                        .format("incl", WP, name, collectionName, fileprefix),
                        addSel="{1}_matchCalo[{0}] >= 0".format(
                            "?", collection))

    if doDeepCSV:
        logging.info("Processing plots for DeepCSV")
        DeepCSVPlotBaseObjs = {}

        collections = []
        if ptordered:
            collections.append(("pT", "offJets"))
            logging.debug("Adding {1} to collecton as ordered by {0}".format(
                "ptOrdered", "cleanJets"))
        if csvordered:
            collections.append(("DeepCSV", "cleanDeepCSVJets"))
            logging.debug("Adding {1} to collecton as ordered by {0}".format(
                "csvOrdered", "cleanDeepCSVJets"))

        for WP in DeepCSVWPs:
            WPLabel = getLabel("PF WP: {0}".format(WP), 0.7, "under")
            CaloWPLabel = getLabel("Calo WP: {0}".format(WP), 0.7, "under")
            logging.info("Using WP: {0}".format(WP))
            for collectionName, collection in collections:

                if dosplit:
                    for i in range(nSplitIter):
                        if looseSel:
                            JetSelection = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format(
                                i, collection)
                        else:
                            JetSelection = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                                i, collection)
                        logging.info(
                            "Making effciency for Jet {0} ordered by {1} w/ DeepCSV as tagger"
                            .format(i, collectionName))
                        logging.subinfo(
                            "Using collection: {0}".format(collection))
                        DeepCSVPlotBaseObjs[i] = modules.classes.PlotBase(
                            "{1}_deepcsv[{0}]".format(i, collection),
                            "{0} && {1} && ({2})".format(
                                CSVSelection, offlineSelection, JetSelection),
                            "1", [20, 0, 1],
                            modules.utils.getAxisTitle("deepcsv", i,
                                                       collectionName.lower()),
                            LegendPosition=[0.1, 0.6, 0.4, 0.76])

                        DeepCSVPlotBaseObjs[i].color = WPColors[i]
                        onlysamples = []
                        for sampleStuff in samples:
                            sample, name, label = sampleStuff
                            onlysamples.append(sample)
                            if not (doMC and doData):
                                modules.effPlots.makeEffPlot(
                                    DeepCSVPlotBaseObjs[i],
                                    sample,
                                    "(pfJets_deepcsv[{2}_matchPF[{1}]]) >= {0}"
                                    .format(WP, i, collection),
                                    basepaths +
                                    "DeepCSV/{3}/{4}Eff_{2}_Jet{0}_pfWP_{1}_DeepCSV_order{3}"
                                    .format(i, WP, name, collectionName,
                                            fileprefix),
                                    addSel="{1}_matchPF[{0}] >= 0".format(
                                        i, collection),
                                    label=[label, WPLabel])
                                modules.effPlots.makeEffPlot(
                                    DeepCSVPlotBaseObjs[i],
                                    sample,
                                    "(caloJets_deepcsv[{2}_matchCalo[{1}]]) >= {0}"
                                    .format(WP, i, collection),
                                    basepaths +
                                    "DeepCSV/{3}/{4}Eff_{2}_Jet{0}_caloWP_{1}_DeepCSV_order{3}"
                                    .format(i, WP, name, collectionName,
                                            fileprefix),
                                    addSel="{1}_matchCalo[{0}] >= 0".format(
                                        i, collection),
                                    label=[label, CaloWPLabel])

                        if doMC and doData:
                            modules.effPlots.makeEffSCompPlot(
                                DeepCSVPlotBaseObjs[i],
                                onlysamples,
                                "(pfJets_deepcsv[{2}_matchPF[{1}]]) >= {0}".
                                format(WP, i, collection),
                                basepaths +
                                "DeepCSV/{2}/{3}Eff_DataMC_Jet{0}_pfWP_{1}_DeepCSV_order{2}"
                                .format(i, WP, collectionName, fileprefix),
                                addSel="{1}_matchPF[{0}] >= 0".format(
                                    i, collection),
                                label=WPLabel)
                            modules.effPlots.makeEffSCompPlot(
                                DeepCSVPlotBaseObjs[i],
                                onlysamples,
                                "(caloJets_deepcsv[{2}_matchCalo[{1}]]) >= {0}"
                                .format(WP, i, collection),
                                basepaths +
                                "DeepCSV/{2}/{3}Eff_DataMC_Jet{0}_caloWP_{1}_DeepCSV_order{2}"
                                .format(i, WP, collectionName, fileprefix),
                                addSel="{1}_matchCalo[{0}] >= 0".format(
                                    i, collection),
                                label=CaloWPLabel)
                if doinclusive:
                    if looseSel:
                        JetSelectionIter = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format(
                            "?", collection)
                    else:
                        JetSelectionIter = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                            "?", collection)
                    logging.info(
                        "Making inclusive effciency ordered by {0} w/ DeepCSV as tagger"
                        .format(collectionName))
                    logging.subinfo("Using collection: {0}".format(collection))
                    DeepCSVPlotBaseIter = modules.classes.PlotBase(
                        "{1}_deepcsv[{0}]".format("?", collection),
                        "{0} && {1} && ({2})".format(CSVSelection,
                                                     offlineSelection,
                                                     JetSelectionIter),
                        "1", [20, 0, 1],
                        modules.utils.getAxisTitle("deepcsv",
                                                   0,
                                                   collectionName.lower(),
                                                   inclusive=True),
                        LegendPosition=[0.1, 0.6, 0.4, 0.76])

                    onlysamples = []
                    for sampleStuff in samples:
                        sample, name, label = sampleStuff
                        onlysamples.append(sample)
                        if not (doMC and doData):
                            modules.effPlots.makeEffSumPlot(
                                DeepCSVPlotBaseIter,
                                sample,
                                "(pfJets_deepcsv[{2}_matchPF[{1}]]) >= {0}".
                                format(WP, "?", collection),
                                nInclusiveIter,
                                basepaths +
                                "DeepCSV/{3}/{4}Eff_{2}_Jet{0}_pfWP_{1}_DeepCSV_order{3}"
                                .format("incl", WP, name, collectionName,
                                        fileprefix),
                                addSel="{1}_matchPF[{0}] >= 0".format(
                                    "?", collection),
                                label=[label, WPLabel])
                            modules.effPlots.makeEffSumPlot(
                                DeepCSVPlotBaseIter,
                                sample,
                                "(caloJets_deepcsv[{2}_matchCalo[{1}]]) >= {0}"
                                .format(WP, "?", collection),
                                nInclusiveIter,
                                basepaths +
                                "DeepCSV/{3}/{4}Eff_{2}_Jet{0}_caloWP_{1}_DeepCSV_order{3}"
                                .format("incl", WP, name, collectionName,
                                        fileprefix),
                                addSel="{1}_matchCalo[{0}] >= 0".format(
                                    "?", collection),
                                label=[label, CaloWPLabel])

                    if doMC and doData:
                        modules.effPlots.makeEffSummSCompPlot(
                            DeepCSVPlotBaseIter,
                            onlysamples,
                            "(pfJets_deepcsv[{2}_matchPF[{1}]]) >= {0} && {2}_matchPF[{1}] >= 0"
                            .format(WP, "?", collection),
                            nInclusiveIter,
                            basepaths +
                            "DeepCSV/{2}/{3}Eff_DataMC_Jet{0}_pfWP_{1}_DeepCSV_order{2}"
                            .format("incl", WP, collectionName, fileprefix),
                            addSel="{1}_matchPF[{0}] >= 0".format(
                                "?", collection),
                            label=WPLabel)
                        modules.effPlots.makeEffSummSCompPlot(
                            DeepCSVPlotBaseIter,
                            onlysamples,
                            "(caloJets_deepcsv[{2}_matchCalo[{1}]]) >= {0}".
                            format(WP, "?", collection),
                            nInclusiveIter,
                            basepaths +
                            "DeepCSV/{2}/{3}Eff_DataMC_Jet{0}_caloWP_{1}_DeepCSV_order{2}"
                            .format("incl", WP, collectionName, fileprefix),
                            addSel="{1}_matchCalo[{0}] >= 0".format(
                                "?", collection),
                            label=CaloWPLabel)

        if compWPs:
            logging.info("Makeing DeepCSV WP comparison")
            for collectionName, collection in collections:
                if looseSel:
                    #JetSelectionIter = "abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30".format("?", collection)
                    JetSelectionIter = "{1}_pt[{0}] > 0".format(
                        "?", collection)
                else:
                    JetSelectionIter = "{1}_deepcsv[{0}] >= 0 && abs({1}_eta[{0}]) < 2.4 && {1}_pt[{0}] > 30 && {1}_passesTightLeptVetoID[{0}] > 0".format(
                        "?", collection)
                logging.info(
                    "Making inclusive  WP comparison ordered by {0} w/ DeepCSV as tagger"
                    .format(collectionName))
                logging.subinfo("Using collection: {0}".format(collection))
                DeepCSVPlotBaseIter = modules.classes.PlotBase(
                    "{1}_deepcsv[{0}]".format("?", collection),
                    "{0} && {1} && ({2})".format(CSVSelection,
                                                 offlineSelection,
                                                 JetSelectionIter),
                    "1", [25, 0, 1],
                    modules.utils.getAxisTitle("deepcsv",
                                               0,
                                               collectionName.lower(),
                                               inclusive=True),
                    LegendPosition=[0.1, 0.6, 0.4, 0.76])

                for sampleStuff in samples:
                    sample, name, label = sampleStuff
                    logging.info("Plotting sample {0}".format(name))
                    modules.effPlots.makeSumWPComp(
                        DeepCSVPlotBaseIter,
                        sample,
                        "pfJets_deepcsv[{1}_matchPF[{0}]]".format(
                            "?", collection),
                        nInclusiveIter,
                        DeepCSVWPs,
                        basepaths +
                        "DeepCSV/{3}/{4}Eff_{2}_Jet{0}_pfWPComp_{1}_DeepCSV_order{3}"
                        .format("incl", WP, name, collectionName, fileprefix),
                        #addSel = "pfJets_deepcsv[{1}_matchPF[{0}]] >= 0 && {1}_matchPF[{0}] >= 0 && pfJets_pt[{1}_matchPF[{0}]] > 30 && abs(pfJets_eta[{1}_matchPF[{0}]]) < 2.4".format("?", collection)
                        addSel="{1}_matchPF[{0}] >= 0 && emilSourceValid == 1".
                        format("?", collection),
                        saveGraph=True)
                    """
                    modules.effPlots.makeSumWPComp(DeepCSVPlotBaseIter, sample,
                                                   "caloJets_deepcsv[{1}_matchCalo[{0}]]".format("?", collection), nInclusiveIter, DeepCSVWPs, 
                                                   basepaths+"DeepCSV/{3}/{4}Eff_{2}_Jet{0}_caloWPComp_{1}_DeepCSV_order{3}".format("incl", WP, name, collectionName, fileprefix),
                                                   addSel = "caloJets_deepcsv[{1}_matchCalo[{0}]] >= 0 && {1}_matchCalo[{0}] >= 0 && pfJets_pt[{1}_matchCalo[{0}]] > 30 && abs(pfJets_eta[{1}_matchCalo[{0}]]) < 2.4".format("?", collection),
                                                   #addSel = "caloJets_deepcsv[{1}_matchCalo[{0}]] >= 0".format("?", collection),
                    )

                    """

    logger.info("Runtime: {0:8f}s".format(time.time() - t0))
    logger.info("Closing efficiency turnon calc")
Пример #9
0
def flavourComposition(loglev,
                       run,
                       doData,
                       doCSV,
                       doDeepCSV,
                       plotinclusive,
                       plotTagAndProbe,
                       calcEfficiency,
                       TagWPCSV=0.8484,
                       TagWPDeepCSV=0.8001,
                       test=False):
    import ROOT

    import modules.classes
    import modules.DataMC
    import modules.TagNProbe

    styleconfig = SafeConfigParser()
    #logging.debug("Loading style config")
    styleconfig.read("config/plotting.cfg")

    setup_logging(loglevel=loglev, logname="shapeoutput", errname="shapeerror")

    logger = logging.getLogger(__name__)
    #logging.getLogger(__name__).setLevel("SUBDEBUG")

    logger.info("Starting flavour composition analysis")
    t0 = time.time()

    if not (doCSV or doDeepCSV):
        if __name__ == "__main__":
            logging.warning(
                "At least on of the flags --CSV and --deepCSV should to be set"
            )
        else:
            logging.warning(
                "At least on of the paramters doCSV and doDeepCSV should to be set"
            )
        logging.warning("Falling back the only CSV")
        doCSV = True

    if run not in ["C", "CD", "E", "F", "CDF"]:
        logging.error("Run not supported!")
        exit()
    ##############################################################################################################
    ############################################## Plotting Code #################################################
    ##############################################################################################################

    if loglev > 0:
        ROOT.gErrorIgnoreLevel = ROOT.kError  # kPrint, kInfo, kWarning, kError, kBreak, kSysError, kFatal;

    MCInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v10/ttbar/ttbar_98p0_mod_mod_mod_mod_mod_mod.root"
    MC2Input = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v10/ST/ST_tW_part_mod_mod_mod.root"
    MC3Input = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v10/SantiT/ST_antitW_mod_mod_mod.root"
    if run == "C":
        logging.info("Setting file, name and basepath for Run C")
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v10_2/RunC/RunCFull.root"
        puweight = "get_puWeight_C_ReReco(pu)"
        globalPrefix = "ProdGTData_RunC_TESTTESTFull_XS"
        basepath = "v10_2nTuples_Final/FlavourSplitting/RunC/"

    #Run C-D
    if run == "CD":
        logging.info("Setting file, pu weight, name and basepath for Run CD")
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v10_2/RunCD.root"
        puweight = "get_puWeight_CD(pu)"
        globalPrefix = "ProdGTData_RunCD_TESTTESTFull_XS"
        basepath = "v10_2nTuples_Final/FlavourSplitting/RunCD/"

    if run == "CDF":
        logging.info("Setting file, pu weight, name and basepath for Run CDF")
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v10_2/RunCDF.root"
        #puweight = "get_puWeight_CDF(pu)"
        #globalPrefix = "ProdGTData_RunCDF_TESTTESTFull_XS_MWP"
        #puweight = "get_puWeight_CDF(pu)*wDeepCSV"
        #globalPrefix = "ProdGTData_RunCDF_TESTTESTFull_XS_mod_deep_MWP"
        puweight = "get_puWeight_CDF(pu) * offTightElectrons_SF[0] * offTightMuons_SF[0]"
        globalPrefix = "ProdGTData_RunCDF_LeptonSF_XS_mod_v2_MWP"
        basepath = "v10_2nTuples_Finalv2/FlavourSplitting/RunCDF/jetW_finebinning/"

    #Run F
    if run == "F":
        logging.info("Setting file, pu weight, name and basepath for Run F")
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v8/MuonEG/RunF/phase1/MuonEG_RunF_phase1_mod_mod_mod.root"
        puweight = "wPURunF"
        globalPrefix = "DeepCSVMPresel_phase1_RunF"
        basepath = "v8nTuples/FlavourSplitting/RunF/"

    #Run E
    if run == "E":
        logging.info("Setting file, pu weight, name and basepath for Run E")
        DataInput = "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v8/MuonEG/RunE/phase1/MuonEG_RunE_phase1_mod_mod_mod.root"
        puweight = "wPURunE"
        globalPrefix = "DeepCSVMPresel_phase1_RunE"
        basepath = "v8nTuples/FlavourSplitting/RunE/"

    MCSelection = "1"
    DataSelection = "1"
    VarSelection = "Sum$(offCleanJets_deepcsv > 0.8001 && offCleanJets_pt > 30 && abs(offCleanJets_eta) < 2.4) >= 1 && Sum$(offCleanJets_pt > 30 && abs(offCleanJets_eta) < 2.4) >= 2"
    TriggerSelection = "HLT_Mu12_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v4 > 0 || HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_v4 > 0"
    LeptonSelection = "Sum$((abs(offTightElectrons_superClusterEta) <= 1.4442 || abs(offTightElectrons_superClusterEta) >= 1.5660) && offTightElectrons_pt > 30 && abs(offTightElectrons_eta) < 2.4) == 1 && Sum$(offTightMuons_iso < 0.25 && offTightMuons_pt > 20 && abs(offTightMuons_eta) < 2.4) == 1"

    offlineSelection = "abs(offCleanJets_eta) < 2.4 && offCleanJets_pt > 30 && offCleanJets_passesTightLeptVetoID > 0"
    offlineSelectionIter = "abs(offCleanJets_eta[?]) < 2.4 && offCleanJets_pt[?] > 30 && offCleanJets_passesTightLeptVetoID[?] > 0"

    MCsamples = []
    MCsamplesIter = []

    datalumi = 14000

    eventSelection = "({0}) && ({1}) && ({2}) && ({3})".format(
        VarSelection, TriggerSelection, LeptonSelection, MCSelection)
    ttbarOnly = False
    if ttbarOnly:
        MCsamples.append(
            modules.classes.Sample(
                "ttbar_udsgJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour == 0".format(
                    eventSelection),
                88.341903326,
                datalumi,
                ROOT.kBlue,
                941634,
                weight=puweight,
                legendText="light jets (t#bar{t})"))
        MCsamples.append(
            modules.classes.Sample(
                "ttbar_cJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour == 4".format(
                    eventSelection),
                88.341903326,
                datalumi,
                ROOT.kGreen + 2,
                941634,
                weight=puweight,
                legendText="c jets (t#bar{t})"))
        MCsamples.append(
            modules.classes.Sample(
                "ttbar_bJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour == 5".format(
                    eventSelection),
                88.341903326,
                datalumi,
                ROOT.kRed,
                941634,
                weight=puweight,
                legendText="b jets (t#bar{t})"))

        MCsamplesIter.append(
            modules.classes.Sample(
                "ttbar_udsgJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour[?] == 0".format(
                    eventSelection),
                88.341903326,
                datalumi,
                ROOT.kBlue,
                941634,
                weight=puweight,
                legendText="light jets (t#bar{t})"))
        MCsamplesIter.append(
            modules.classes.Sample(
                "ttbar_cJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour[?] == 4".format(
                    eventSelection),
                88.341903326,
                datalumi,
                ROOT.kGreen + 2,
                941634,
                weight=puweight,
                legendText="c jets (t#bar{t})"))
        MCsamplesIter.append(
            modules.classes.Sample(
                "ttbar_bJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour[?] == 5".format(
                    eventSelection),
                88.341903326,
                datalumi,
                ROOT.kRed,
                941634,
                weight=puweight,
                legendText="b jets (t#bar{t})"))

    else:
        """ ttbar """
        MCsamples.append(
            modules.classes.Sample(
                "ttbar_udsgJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour == 0".format(
                    eventSelection),
                88.34,
                datalumi,
                ROOT.kBlue,
                941634,
                weight=puweight,
                legendText="light jets"))
        MCsamples.append(
            modules.classes.Sample(
                "ttbar_cJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour == 4".format(
                    eventSelection),
                88.34,
                datalumi,
                ROOT.kOrange + 2,
                941634,
                weight=puweight,
                legendText="c jets "))
        MCsamples.append(
            modules.classes.Sample(
                "ttbar_bJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour == 5".format(
                    eventSelection),
                88.34,
                datalumi,
                ROOT.kRed,
                941634,
                weight=puweight,
                legendText="b jets"))

        MCsamplesIter.append(
            modules.classes.Sample(
                "ttbar_udsgJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour[?] == 0".format(
                    eventSelection),
                88.34,
                datalumi,
                ROOT.kBlue,
                941634,
                weight=puweight,
                legendText="light jets "))
        MCsamplesIter.append(
            modules.classes.Sample(
                "ttbar_cJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour[?] == 4".format(
                    eventSelection),
                88.34,
                datalumi,
                ROOT.kGreen + 2,
                941634,
                weight=puweight,
                legendText="c jets "))
        MCsamplesIter.append(
            modules.classes.Sample(
                "ttbar_bJets",
                MCInput,
                "{0} && offCleanJets_hadronFlavour[?] == 5".format(
                    eventSelection),
                88.34,
                datalumi,
                ROOT.kRed,
                941634,
                weight=puweight,
                legendText="b jets"))
        """ ST """
        MCsamples.append(
            modules.classes.Sample(
                "st_udsgJets",
                MC2Input,
                "{0} && offCleanJets_hadronFlavour == 0".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kBlue + 3,
                727212,
                weight=puweight,
                legendText="light jets (single t)"))
        MCsamples.append(
            modules.classes.Sample(
                "st_cJets",
                MC2Input,
                "{0} && offCleanJets_hadronFlavour == 4".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kGreen + 4,
                727212,
                weight=puweight,
                legendText="c jets (single t)"))
        MCsamples.append(
            modules.classes.Sample(
                "st_bJets",
                MC2Input,
                "{0} && offCleanJets_hadronFlavour == 5".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kRed + 3,
                727212,
                weight=puweight,
                legendText="b jets (single t)"))

        MCsamplesIter.append(
            modules.classes.Sample(
                "st_udsgJets",
                MC2Input,
                "{0} && offCleanJets_hadronFlavour[?] == 0".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kBlue + 3,
                727212,
                weight=puweight,
                legendText="light jets (single t)"))
        MCsamplesIter.append(
            modules.classes.Sample(
                "st_cJets",
                MC2Input,
                "{0} && offCleanJets_hadronFlavour[?] == 4".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kGreen + 4,
                727212,
                weight=puweight,
                legendText="c jets (single t)"))
        MCsamplesIter.append(
            modules.classes.Sample(
                "st_bJets",
                MC2Input,
                "{0} && offCleanJets_hadronFlavour[?] == 5".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kRed + 3,
                727212,
                weight=puweight,
                legendText="b jets (single t)"))
        """ SAntiT """
        MCsamples.append(
            modules.classes.Sample(
                "santit_udsgJets",
                MC3Input,
                "{0} && offCleanJets_hadronFlavour == 0".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kBlue - 9,
                5603226,
                weight=puweight,
                legendText="light jets (single #bar{t})"))
        MCsamples.append(
            modules.classes.Sample(
                "santit_cJets",
                MC3Input,
                "{0} && offCleanJets_hadronFlavour == 4".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kGreen - 3,
                5603226,
                weight=puweight,
                legendText="c jets (single #bar{t})"))
        MCsamples.append(
            modules.classes.Sample(
                "santit_bJets",
                MC3Input,
                "{0} && offCleanJets_hadronFlavour == 5".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kRed - 9,
                5603226,
                weight=puweight,
                legendText="b jets (single #bar{t})"))

        MCsamplesIter.append(
            modules.classes.Sample(
                "santit_udsgJets",
                MC3Input,
                "{0} && offCleanJets_hadronFlavour[?] == 0".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kBlue - 9,
                5603226,
                weight=puweight,
                legendText="light jets (single #bar{t})"))
        MCsamplesIter.append(
            modules.classes.Sample(
                "santit_cJets",
                MC3Input,
                "{0} && offCleanJets_hadronFlavour[?] == 4".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kGreen - 3,
                5603226,
                weight=puweight,
                legendText="c jets (single #bar{t})"))
        MCsamplesIter.append(
            modules.classes.Sample(
                "santit_bJets",
                MC3Input,
                "{0} && offCleanJets_hadronFlavour[?] == 5".format(
                    eventSelection),
                35.85,
                datalumi,
                ROOT.kRed - 9,
                5603226,
                weight=puweight,
                legendText="b jets (single #bar{t})"))
        """
        MCsamples.append( modules.classes.Sample("ttbar", MCInput, "{0}".format(eventSelection),
                                                88.341903326, datalumi, ROOT.kBlue, 941634, weight = puweight, legendText = "t#bar{t}") )
        MCsamples.append( modules.classes.Sample("STtW", MC2Input, "{0}".format(eventSelection),
                                                 1, datalumi, ROOT.kRed, 727212, weight = puweight, legendText = "ST tW") )
        
        MCsamplesIter.append( modules.classes.Sample("ttbar", MCInput, "{0}".format(eventSelection),
                                                    88.341903326, datalumi, ROOT.kBlue, 941634, weight = puweight, legendText = "t#bar{t}") )
        MCsamplesIter.append( modules.classes.Sample("STtW", MC2Input, "{0}".format(eventSelection),
                                                     1, datalumi, ROOT.kBlue, 727212, weight = puweight, legendText = "ST tW") )
        """
    if doData:
        eventSelection = "({0}) && ({1}) && ({2})".format(
            VarSelection, TriggerSelection, LeptonSelection)
        dataSample = modules.classes.Sample("data",
                                            DataInput,
                                            eventSelection,
                                            color=ROOT.kBlue,
                                            legendText="Data")
    else:
        dataSample = None

    if plotinclusive:
        logging.info("Making inclusive stack plots")
        if doCSV:
            CSVOffline = modules.classes.PlotBase("offCleanJets_csv",
                                                  offlineSelection, "1",
                                                  [100, 0, 1],
                                                  "Offline jet csv value")
            CSVOfflineIter = modules.classes.PlotBase("offCleanJets_csv", "1",
                                                      "1", [100, 0, 1],
                                                      "Offline jet csv value")
            CSVPF = modules.classes.PlotBase(
                "pfJets_csv[offCleanJets_matchPF]",
                "{0} && {1}".format(offlineSelection,
                                    "1"), "1", [100, 0, 1], "PF jet csv value")
            CSVPFIter = modules.classes.PlotBase("offCleanJets_csv", "1", "1",
                                                 [100, 0, 1],
                                                 "PF jet csv value")
            CSVCaloIter = modules.classes.PlotBase("offCleanJets_csv", "1",
                                                   "1", [100, 0, 1],
                                                   "Calo jet csv value")
            #modules.DataMC.makeStackDMCPlot(CSVOffline, MCsamples, dataSample, drawRatio = True, outname = basepath+globalPrefix+"_off_csv", normalized = True)
            #modules.DataMC.makeStackDMCPlot(CSVPF, MCsamples, dataSample, drawRatio = True, outname = basepath+globalPrefix+"_pf_csv", normalized = True)
            modules.DataMC.makeSumDMCPlot(CSVOfflineIter,
                                          MCsamplesIter,
                                          "offCleanJets_csv[?]",
                                          15,
                                          offlineSelectionIter,
                                          dataSample,
                                          drawRatio=True,
                                          outname=basepath + globalPrefix +
                                          "_off_sum_csv",
                                          normalized=True)
            modules.DataMC.makeSumDMCPlot(
                CSVPFIter,
                MCsamplesIter,
                "pfJets_csv[offCleanJets_matchPF[?]]",
                15,
                "{0} && {1}".format(offlineSelectionIter,
                                    "offCleanJets_matchPF[?] >= 0"),
                dataSample,
                drawRatio=True,
                outname=basepath + globalPrefix + "_pf_inclusive_csv",
                normalized=True)
            modules.DataMC.makeSumDMCPlot(
                CSVCaloIter,
                MCsamplesIter,
                "caloJets_csv[offCleanJets_matchCalo[?]]",
                15,
                "{0} && {1}".format(offlineSelectionIter,
                                    "offCleanJets_matchCalo[?] >= 0"),
                dataSample,
                drawRatio=True,
                outname=basepath + globalPrefix + "_calo_inclusive_csv",
                normalized=True)
        if doDeepCSV:
            DeepCSVOfflineIter = modules.classes.PlotBase(
                "offCleanJets_deepcsv", "1", "1", [100, 0, 1],
                "Offline jet DeepCSV value")
            DeepCSVPFIter = modules.classes.PlotBase("offCleanJets_deepcsv",
                                                     "1", "1", [100, 0, 1],
                                                     "PF jet DeepCSV value")
            DeepCSVCaloIter = modules.classes.PlotBase(
                "offCleanJets_deepcsv", "1", "1", [100, 0, 1],
                "Calo jet DeepCSV value")
            #modules.DataMC.makeStackDMCPlot(CSVOffline, MCsamples, dataSample, drawRatio = True, outname = basepath+globalPrefix+"_off_csv", normalized = True)
            #modules.DataMC.makeStackDMCPlot(CSVPF, MCsamples, dataSample, drawRatio = True, outname = basepath+globalPrefix+"_pf_csv", normalized = True)
            modules.DataMC.makeSumDMCPlot(DeepCSVOfflineIter,
                                          MCsamplesIter,
                                          "offCleanJets_deepcsv[?]",
                                          15,
                                          offlineSelectionIter,
                                          dataSample,
                                          drawRatio=True,
                                          outname=basepath + globalPrefix +
                                          "_off_sum_csv",
                                          normalized=True)
            modules.DataMC.makeSumDMCPlot(
                DeepCSVPFIter,
                MCsamplesIter,
                "pfJets_deepcsv[offCleanJets_matchPF[?]]",
                15,
                "{0} && {1}".format(offlineSelectionIter,
                                    "offCleanJets_matchPF[?] >= 0"),
                dataSample,
                drawRatio=True,
                outname=basepath + globalPrefix + "_pf_inclusive_deepcsv",
                normalized=True)
            modules.DataMC.makeSumDMCPlot(
                DeepCSVCaloIter,
                MCsamplesIter,
                "caloJets_deepcsv[offCleanJets_matchCalo[?]]",
                15,
                "{0} && {1}".format(offlineSelectionIter,
                                    "offCleanJets_matchCalo[?] >= 0"),
                dataSample,
                drawRatio=True,
                outname=basepath + globalPrefix + "_calo_inclusive_deepcsv",
                normalized=True)

    ##############################################################################################################
    ##############################################################################################################
    ########################################### Tag&Probe plots ##################################################
    ##############################################################################################################
    ##############################################################################################################

    if plotTagAndProbe:
        lepoverfix = False
        logging.info("Making Tag&Probe plots")
        probeSel = offlineSelectionIter
        if doCSV:
            logging.info("Processing CSV plots")
            OffCSVnthJet = modules.classes.PlotBase(
                "offCleanJets_csv[?]", "1", "1", [100, 0, 1],
                "Probe offline jet CSV value")
            PFCSVnthJet = modules.classes.PlotBase(
                "pfJets_csv[offCleanJets_matchPF[?]]", "1", "1", [100, 0, 1],
                "PF jet matched to probe CSV value")
            CaloCSVnthJet = modules.classes.PlotBase(
                "caloJets_csv[offCleanJets_matchCalo[?]]", "1", "1",
                [100, 0, 1], "Calo jet matched to probe CSV value")

            thisProbeWeight = "offCleanJets_csvv2SF[?]"
            thisTagWeight = "offCleanJets_deepcsvSF[?]"

            #tagSel = "{0} && {1}".format(offlineSelectionIter, "offCleanJets_csv[?] >= {0}".format(TagWPCSV))
            tagSel = "{0} && {1}".format(
                offlineSelectionIter,
                "offCleanJets_deepcsv[?] >= {0}".format(TagWPDeepCSV))
            WPlabel = getLabel("Tag DeepCSV WP: {0}".format(TagWPDeepCSV),
                               styleconfig.getfloat("CMSLabel", "xStart"),
                               pos="topSup",
                               scale=0.8)
            #tagSel = "1"
            if calcEfficiency:
                logging.error("New reweighting missing !")
                exit()
                logging.info("Calculating PF Efficiency")
                if not test:
                    pfCSVWPs = [0.405, 0.840, 0.975]
                else:
                    logging.warning("Test flag set! Only using one WP")
                    pfCSVWPs = [0.840]
                if not lepoverfix:
                    modules.TagNProbe.getBEfficiency(
                        PFCSVnthJet,
                        MCsamplesIter,
                        "{0} && {1}".format(probeSel,
                                            "offCleanJets_matchPF[?] >= 0"),
                        tagSel,
                        "pfJets_csv[offCleanJets_matchPF[?]]",
                        pfCSVWPs,
                        2,
                        data=dataSample,
                        normalized=True,
                        outname=basepath + "PFCSV/" + globalPrefix +
                        "_TnP_leading_pf_csv",
                        label=[WPlabel])
                else:
                    logging.info("Plotting with tmp. lepton overlap removal")
                    modules.TagNProbe.getBEfficiencyHack(
                        PFCSVnthJet,
                        MCsamplesIter,
                        "{0} && {1}".format(probeSel,
                                            "offCleanJets_matchPF[?] >= 0"),
                        tagSel,
                        "pfJets_csv[offCleanJets_matchPF[?]]",
                        pfCSVWPs,
                        2,
                        lepveto,
                        probeIndices=[0, 1, 2],
                        tagIndices=[[1, 2, 3], [2, 3, 4], [3]],
                        data=dataSample,
                        normalized=True,
                        outname=basepath + "PFCSV/" + globalPrefix +
                        "_TnP_leading_pf_csv",
                        label=[WPlabel])

                if not test:
                    logging.info("Calculating Calo Efficiency")
                    if not lepoverfix:
                        modules.TagNProbe.getBEfficiency(
                            CaloCSVnthJet,
                            MCsamplesIter,
                            "{0} && {1}".format(
                                probeSel, "offCleanJets_matchCalo[?] >= 0"),
                            tagSel,
                            "caloJets_csv[offCleanJets_matchCalo[?]]",
                            [0.435, 0.840, 0.97],
                            2,
                            data=dataSample,
                            normalized=True,
                            outname=basepath + "CaloCSV/" + globalPrefix +
                            "_TnP_leading_calo_csv",
                            label=[WPlabel])
                    else:
                        logging.info(
                            "Plotting with tmp. lepton overlap removal")
                        modules.TagNProbe.getBEfficiencyHack(
                            CaloCSVnthJet,
                            MCsamplesIter,
                            "{0} && {1}".format(
                                probeSel, "offCleanJets_matchCalo[?] >= 0"),
                            tagSel,
                            "caloJets_csv[offCleanJets_matchCalo[?]]",
                            [0.435, 0.840, 0.97],
                            2,
                            lepveto,
                            probeIndices=[0, 1, 2],
                            tagIndices=[[1, 2, 3], [2, 3], [3]],
                            data=dataSample,
                            normalized=True,
                            outname=basepath + "CaloCSV/" + globalPrefix +
                            "_TnP_leading_calo_csv",
                            label=[WPlabel])
                else:
                    logging.warning("Test flag set! Skipping calo efficiancy")

            else:
                modules.TagNProbe.LeadingProbe(
                    OffCSVnthJet,
                    MCsamplesIter,
                    probeSel,
                    tagSel,
                    data=dataSample,
                    convertIterSelection=True,
                    outname=basepath + globalPrefix + "_TnP_leadingoff_csv",
                    normalized=True,
                    label=[WPlabel],
                    probeWeight=thisProbeWeight,
                    tagWeight=thisTagWeight)
                modules.TagNProbe.LeadingProbe(
                    PFCSVnthJet,
                    MCsamplesIter,
                    "{0} && {1}".format(probeSel,
                                        "offCleanJets_matchPF[?] >= 0"),
                    tagSel,
                    data=dataSample,
                    convertIterSelection=True,
                    outname=basepath + globalPrefix + "_TnP_leading_pf_csv",
                    normalized=True,
                    label=[WPlabel],
                    probeWeight=thisProbeWeight,
                    tagWeight=thisTagWeight)
                modules.TagNProbe.LeadingProbe(
                    CaloCSVnthJet,
                    MCsamplesIter,
                    "{0} && {1}".format(probeSel,
                                        "offCleanJets_matchCalo[?] >= 0"),
                    tagSel,
                    data=dataSample,
                    convertIterSelection=True,
                    outname=basepath + globalPrefix + "_TnP_leading_calo_csv",
                    normalized=True,
                    label=[WPlabel],
                    probeWeight=thisProbeWeight,
                    tagWeight=thisTagWeight)
        if doDeepCSV:
            logging.info("Processing DeepCSV plots")
            WPlabel = getLabel("Tag DeepCSV WP: {0}".format(TagWPDeepCSV),
                               styleconfig.getfloat("CMSLabel", "xStart"),
                               pos="topSup",
                               scale=0.8)
            OffDeepCSVnthJet = modules.classes.PlotBase(
                "offCleanJets_deepcsv[?]", "1", "1", [100, 0, 1],
                "Probe offline jet DeepCSV value")
            PFDeepCSVnthJet = modules.classes.PlotBase(
                "pfJets_deepcsv[offCleanJets_matchPF[?]]", "1", "1",
                [100, 0, 1], "PF jet matched to probe DeepCSV value")
            CaloDeepCSVnthJet = modules.classes.PlotBase(
                "caloJets_deepcsv[offCleanJets_matchCalo[?]]", "1", "1",
                [100, 0, 1], "Calo jet matched to probe DeepCSV value")

            thisProbeWeight = "offCleanJets_deepcsvSF[?]"
            thisTagWeight = "offCleanJets_deepcsvSF[?]"

            tagSel = "{0} && {1}".format(
                offlineSelectionIter,
                "offCleanJets_deepcsv[?] >= {0}".format(TagWPDeepCSV))
            #tagSel = "1"
            if calcEfficiency:
                logging.error("New reweighting missing !")
                exit()
                logging.info("Calculating PF Efficiency")
                if not lepoverfix:
                    modules.TagNProbe.getBEfficiency(
                        PFDeepCSVnthJet,
                        MCsamplesIter,
                        "{0} && {1}".format(probeSel,
                                            "offCleanJets_matchPF[?] >= 0"),
                        tagSel,
                        "pfJets_deepcsv[offCleanJets_matchPF[?]]",
                        [0.2, 0.67, 0.955],
                        2,
                        data=dataSample,
                        normalized=False,
                        outname=basepath + "PFDeepCSV/" + globalPrefix +
                        "_TnP_leading_pf_deepcsv",
                        label=[WPlabel])
                else:
                    modules.TagNProbe.getBEfficiencyHack(
                        PFDeepCSVnthJet,
                        MCsamplesIter,
                        "{0} && {1}".format(probeSel,
                                            "offCleanJets_matchPF[?] >= 0"),
                        tagSel,
                        "pfJets_deepcsv[offCleanJets_matchPF[?]]",
                        [0.2, 0.67, 0.955],
                        2,
                        lepveto,
                        probeIndices=[0, 1, 2],
                        tagIndices=[[1, 2, 3], [2, 3], [3]],
                        data=dataSample,
                        normalized=True,
                        outname=basepath + "PFDeepCSV/" + globalPrefix +
                        "_TnP_leading_pf_deepcsv",
                        label=[WPlabel])
                logging.info("Calculating Calo Efficiency")
                if not lepoverfix:
                    modules.TagNProbe.getBEfficiency(
                        CaloDeepCSVnthJet,
                        MCsamplesIter,
                        "{0} && {1}".format(probeSel,
                                            "offCleanJets_matchCalo[?] >= 0"),
                        tagSel,
                        "caloJets_deepcsv[offCleanJets_matchCalo[?]]",
                        [0.205, 0.675, 0.95],
                        2,
                        data=dataSample,
                        normalized=False,
                        outname=basepath + "CaloDeepCSV/" + globalPrefix +
                        "_TnP_leading_calo_deepcsv",
                        label=[WPlabel])
                else:
                    modules.TagNProbe.getBEfficiencyHack(
                        CaloDeepCSVnthJet,
                        MCsamplesIter,
                        "{0} && {1}".format(probeSel,
                                            "offCleanJets_matchCalo[?] >= 0"),
                        tagSel,
                        "caloJets_deepcsv[offCleanJets_matchCalo[?]]",
                        [0.205, 0.675, 0.95],
                        2,
                        lepveto,
                        probeIndices=[0, 1, 2],
                        tagIndices=[[1, 2, 3], [2, 3], [3]],
                        data=dataSample,
                        normalized=True,
                        outname=basepath + "CaloDeepCSV/" + globalPrefix +
                        "_TnP_leading_calo_deepcsv",
                        label=[WPlabel])
            else:
                modules.TagNProbe.LeadingProbe(OffDeepCSVnthJet,
                                               MCsamplesIter,
                                               probeSel,
                                               tagSel,
                                               data=dataSample,
                                               convertIterSelection=True,
                                               outname=basepath +
                                               globalPrefix +
                                               "_TnP_leadingoff_deepcsv",
                                               normalized=True,
                                               label=[WPlabel],
                                               probeWeight=thisProbeWeight,
                                               tagWeight=thisTagWeight)
                modules.TagNProbe.LeadingProbe(
                    PFDeepCSVnthJet,
                    MCsamplesIter,
                    "{0} && {1}".format(probeSel,
                                        "offCleanJets_matchPF[?] >= 0"),
                    tagSel,
                    data=dataSample,
                    convertIterSelection=True,
                    outname=basepath + globalPrefix +
                    "_TnP_leading_pf_deepcsv",
                    normalized=True,
                    label=[WPlabel],
                    probeWeight=thisProbeWeight,
                    tagWeight=thisTagWeight)
                modules.TagNProbe.LeadingProbe(
                    CaloDeepCSVnthJet,
                    MCsamplesIter,
                    "{0} && {1}".format(probeSel,
                                        "offCleanJets_matchCalo[?] >= 0"),
                    tagSel,
                    data=dataSample,
                    convertIterSelection=True,
                    outname=basepath + globalPrefix +
                    "_TnP_leading_calo_deepcsv",
                    normalized=True,
                    label=[WPlabel],
                    probeWeight=thisProbeWeight,
                    tagWeight=thisTagWeight)

    ##############################################################################################################
    ##############################################################################################################
    ##############################################################################################################

    logger.info("Runtime: {0:8f}s".format(time.time() - t0))
    logger.info("Closing falvour compostion analysis")
Пример #10
0
def perioComparison(loglev, doCSV, doDeepCSV):
    import ROOT

    import modules.classes
    import modules.DataMC
    import modules.TagNProbe

    styleconfig = SafeConfigParser()
    #logging.debug("Loading style config")
    styleconfig.read("config/plotting.cfg")

    setup_logging(loglevel=loglev, logname="shapeoutput", errname="shapeerror")

    logger = logging.getLogger(__name__)

    logger.info("Starting flavour composition analysis")

    if not (doCSV or doDeepCSV):
        if __name__ == "__main__":
            logging.warning(
                "At least on of the flags --CSV and --deepCSV should to be set"
            )
        else:
            logging.warning(
                "At least on of the paramters doCSV and doDeepCSV should to be set"
            )
        logging.warning("Falling back the only CSV")
        doCSV = True

    ##############################################################################################################
    ############################################## Plotting Code #################################################
    ##############################################################################################################

    if loglev > 0:
        ROOT.gErrorIgnoreLevel = ROOT.kError  # kPrint, kInfo, kWarning, kError, kBreak, kSysError, kFatal;

    DataInput = []
    DataInput.append((
        "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v5/MuonEG/MuonEG_RunCD_phase1_part.root",
        "Run C+D"))
    DataInput.append((
        "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v5/MuonEG/RunE/phase1/MuonEG_RunE_phase1.root",
        "Run E"))
    DataInput.append((
        "/mnt/t3nfs01/data01/shome/koschwei/scratch/HLTBTagging/DiLepton_v5/MuonEG/RunF/phase1/MuonEG_RunF_phase1_part.root",
        "Run F"))

    MCSelection = "1"
    DataSelection = "1"
    VarSelection = "Sum$(offJets_deepcsv > 0.8958 && offJets_pt > 30 && abs(offJets_eta) < 2.4) >= 1 && Sum$(offJets_pt > 30 && abs(offJets_eta) < 2.4) >= 2"
    TriggerSelection = "HLT_Mu12_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v4 > 0 || HLT_Mu23_TrkIsoVVL_Ele12_CaloIdL_TrackIdL_IsoVL_v4 > 0"
    LeptonSelection = "Sum$((abs(offTightElectrons_superClusterEta) <= 1.4442 || abs(offTightElectrons_superClusterEta) >= 1.5660) && offTightElectrons_pt > 30 && abs(offTightElectrons_eta) < 2.4) > 0 && Sum$(offTightMuons_iso < 0.25 && offTightMuons_pt > 20 && abs(offTightMuons_eta) < 2.4) > 0"

    offlineSelection = "abs(offJets_eta) < 2.4 && offJets_pt > 30 && offJets_passesTightLeptVetoID > 0"
    offlineSelectionIter = "abs(offJets_eta[?]) < 2.4 && offJets_pt[?] > 30 && offJets_passesTightLeptVetoID[?] > 0"

    dataSample = []
    colors = [ROOT.kBlue, ROOT.kRed, ROOT.kGreen + 2]
    iInput = 0
    eventSelection = "({0}) && ({1}) && ({2})".format(VarSelection,
                                                      TriggerSelection,
                                                      LeptonSelection)
    for inputData, inputname in DataInput:
        dataSample.append(
            modules.classes.Sample("data" + inputname.replace(" ", "_"),
                                   DataInput,
                                   eventSelection,
                                   color=colors[iInput],
                                   legendText="MuonEG " + inputname))
        iInput += 1

    if doCSV:
        pass
    if doDeepCSV:
        pass
Пример #11
0
    book = Book("Market", [(1, 1)], [(1, 1)], [])

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()

        logger.info("FIX.4.2 maarket data server started.")
        logger.debug(f"Starting listener on port {port}.")

        conn = Listener(address, authkey=b"Dj$0.Jkx1@").accept()

        logger.debug(f"Accepted orderbook connection on port {port}.")

        while True:
            book = conn.recv()
            app.dispatch(book)

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()


if __name__ == "__main__":
    logger = setup_logging("logs/", "marketdata")
    main()
Пример #12
0
        conn = Client(address, authkey=b"Dj$0.Jkx1@")

        logger.info(f"Started market data publisher at port {port}.")

        while True:
            sleep(1)
            if MARKETS:
                for market in MARKETS:
                    # remove the comment below to print debug orderbook
                    # logger.debug(f"\n{MARKETS[market]._show_orderbook()}")
                    if market in FLUSH_BOOK:
                        bids, asks = MARKETS[market].book()
                        trades = []
                        if FLUSH_BOOK[market]:
                            # trades
                            trades = list(set(FLUSH_BOOK[market]))
                        book = Book(market, bids, asks, trades)
                        conn.send(book)
                        FLUSH_BOOK.pop(market)

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()


if __name__ == "__main__":
    logger = setup_logging("logs/", "server")
    main()