def main():
    if len(sys.argv) < 2:
        usage()

#    HISTONAME = "METInvertedTauIdAfterJets"
    HISTONAME = "METInvertedTauIdAfterCollinearCuts"
    #    HISTONAME = "MET_InvertedTauIdBveto"
    #    HISTONAME = "METInvertedTauIdAfterCollinearCutsPlusBtag"
    #    HISTONAME = "METInvertedTauIdAfterCollinearCutsPlusBtag"
    #    HISTONAME = "MTInvertedTauIdJet"
    #    HISTONAME = "MTInvertedTauIdPhi"

    invertedhisto = HISTONAME
    baselinehisto = HISTONAME.replace("Inverted", "BaseLine")

    dirs = []
    if len(sys.argv) < 2:
        usage()

    dirs.append(sys.argv[1])

    # Create all datasets from a multicrab task
    #datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)
    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,
                                                    dataEra=dataEra,
                                                    searchMode=searchMode,
                                                    analysisName=analysis)
    #    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,counters=counters, dataEra=dataEra, analysisBaseName="signalAnalysisInvertedTau" )

    # As we use weighted counters for MC normalisation, we have to
    # As we use weighted counters for MC normalisation, we have to
    # update the all event count to a separately defined value because
    # the analysis job uses skimmed pattuple as an input
    datasets.updateNAllEventsToPUWeighted()

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(
        filter(lambda name: "TTToHplus" in name and not "M120" in name,
               datasets.getAllDatasetNames()))
    datasets.remove(
        filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK",
                   ["TTJets", "WJets", "DYJetsToLL", "SingleTop", "Diboson"])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())

    if ReBinning:
        rebinfactor = 1.3
        histobins = []
        histobins.append(0)
        histobins.append(1)
        i = 1
        while histobins[len(histobins) - 1] < 400:
            edge = histobins[i] + (histobins[i] -
                                   histobins[i - 1]) * rebinfactor
            histobins.append(edge)
            i += 1
            print histobins


#        metBase_data = metBase_data.Rebin(len(histobins)-1,   metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/"+invertedhisto) "",array.array("d", histobins))
        metInverted_data = metInverted_data.Rebin(
            len(histobins) - 1, "", array.array("d", histobins))
        metBase_EWK = metBase_EWK.Rebin(
            len(histobins) - 1, "", array.array("d", histobins))
        metInverted_EWK = metInverted_EWK.Rebin(
            len(histobins) - 1, "", array.array("d", histobins))

    normData, normEWK = normalisation()

    metInverted = []
    metBaseline = []
    metBaselineQCD = []

    for ptbin in ptbins:
        ## inverted
        met_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/METInvertedTauIdAfterCollinearCuts/METInvertedTauIdAfterCollinearCuts"
                + ptbin)
        ])

        #met_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        met_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        met = met_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        met.Scale(normData[ptbin])

        metEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/METInvertedTauIdAfterCollinearCuts/METInvertedTauIdAfterCollinearCuts"
                + ptbin)
        ])
        #metEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        metEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        metEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metEWK = metEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        metEWK.Scale(normEWK[ptbin])
        met.Add(metEWK, -1)
        metInverted.append(met)

        ## baseline
        met_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "baseline/METBaselineTauIdAfterCollinearCuts/METBaselineTauIdAfterCollinearCuts"
                + ptbin)
        ])

        #met_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        met_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metbaseline = met_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()

        metEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "baseline/METBaselineTauIdAfterCollinearCuts/METBaselineTauIdAfterCollinearCuts"
                + ptbin)
        ])
        #metEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        metEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        metEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metEWKbaseline = metEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        metBaseline.append(metbaseline)
        metbaseline.Add(metEWKbaseline, -1)
        metBaselineQCD.append(metbaseline)

    metInverted_data = metInverted[0].Clone("met")
    metInverted_data.SetName("met")
    metInverted_data.SetTitle("Inverted tau ID")
    metInverted_data.Reset()
    for histo in metInverted:
        metInverted_data.Add(histo)

    metBaseline_data = metBaseline[0].Clone("met")
    metBaseline_data.SetName("met")
    metBaseline_data.SetTitle("baseline tau ID")
    metBaseline_data.Reset()
    for histo in metBaseline:
        metBaseline_data.Add(histo)

    metBaseline_QCD = metBaselineQCD[0].Clone("met")
    metBaseline_QCD.SetName("met")
    metBaseline_QCD.SetTitle("baseline tau ID")
    metBaseline_QCD.Reset()
    for histo in metBaselineQCD:
        metBaseline_QCD.Add(histo)

    #metBase_data.SetTitle("Data: BaseLine TauID")
    #metInverted_data.SetTitle("Data: Inverted TauID")
    #metBase_QCD = metBase_data.Clone("QCD")

    #metBase_QCD.Add(metBase_EWK,-1)
    #metBase_QCD.SetTitle("Data - EWK MC: BaseLine TauID")

    invertedQCD.setLabel("BaseVsInverted")
    invertedQCD.comparison(metInverted_data, metBaseline_data)
    invertedQCD.setLabel("BaseMinusEWKVsInverted")
    invertedQCD.comparison(metInverted_data, metBaseline_QCD)
    invertedQCD.setLabel("McVsInverted")
    #    invertedQCD.comparison(metInverted_data,metInverted_MC)
    invertedQCD.setLabel("EfficiencyBaseMinusEWKVsInverted")
    invertedQCD.cutefficiency(metInverted_data, metBaseline_QCD)
コード例 #2
0
def old_plots():
    
    
    mtAllCuts = []
    mtAllCutsBaseline = []
    mtAfterMetCut = []
    mtAfterMetCutBaseline = []
    mtAfterMetPlusSoftBtagging = []
    mtAfterMetPlusSoftBtaggingBaseline = []
    mtAfterMetPlusBveto = []
    mtAfterMetPlusBvetoBaseline = []
    mtAfterCollinearCuts = []
    mtAfterCollinearCutsBaseline = []
    invertedNoScale = []
  
    
## histograms in bins, normalisation and substraction of EWK contribution
    ## mt with 2dim deltaPhi cut
    for ptbin in ptbins:
        ## -------------   mt with all cuts -----------
    
        mt_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterBackToBackCuts/MTInvertedTauIdAfterBackToBackCuts"+ptbin)])
        mt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mt = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtEvents = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        invertedNoScale.append(mtEvents)
        mt.Scale(normData[ptbin])
    
        
        mtEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterBackToBackCuts/MTInvertedTauIdAfterBackToBackCuts"+ptbin)])
        mtEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtEWK = mtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtEWK.Scale(normEWK[ptbin])
        if includeEWKscale:
            mtEWK.Scale(EWKscale)
        mt.Add(mtEWK, -1)
        mtAllCuts.append(mt)
        
        ## baseline
        mt_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("baseline/MTBaselineTauIdAfterBackToBackCuts/MTBaselineTauIdAfterBackToBackCuts"+ptbin)])
        mt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtBaseline = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
           
        mtEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("baseline/MTBaselineTauIdAfterBackToBackCuts/MTBaselineTauIdAfterBackToBackCuts"+ptbin)])
        mtEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtEWKBaseline = mtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtBaseline.Add(mtEWKBaseline, -1)
        mtAllCutsBaseline.append(mtBaseline)


#################################################
        
        ### ---- mt after met cut
        mtfac_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterMetPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBackToBackCuts"+ptbin)])
        mtfac_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtfac = mtfac_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtNoBtaggingTailKiller = mtfac_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtNoBtaggingTailKiller.Scale(normData[ptbin])
              
        mtfacEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterMetPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBackToBackCuts"+ptbin)])
        mtfacEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtfacEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtNoBtaggingTailKillerEWK = mtfacEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()        
        mtNoBtaggingTailKillerEWK.Scale(normEWK[ptbin])       
        mtNoBtaggingTailKiller.Add(mtNoBtaggingTailKillerEWK, -1)
        mtAfterMetCut.append(mtNoBtaggingTailKiller)
        
        ### ---- mt after met cut baseline
        mtfac_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("baseline/MTBaselineTauIdAfterMetPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBackToBackCuts"+ptbin)])
        mtfac_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtfac = mtfac_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtNoBtaggingTailKillerBaseline = mtfac_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
              
        mtfacEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("baseline/MTBaselineTauIdAfterMetPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBackToBackCuts"+ptbin)])
        mtfacEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtfacEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtNoBtaggingTailKillerEWK = mtfacEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()             
        mtNoBtaggingTailKillerBaseline.Add(mtNoBtaggingTailKillerEWK, -1)
        mtAfterMetCutBaseline.append(mtNoBtaggingTailKillerBaseline)

 ########################################################       
        
        # ----------mt after SOFT b tagging ---------------
        mtbSoft_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"+ptbin)])
        mtbSoft_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtbSoft = mtbSoft_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtbSoft.Scale(normData[ptbin])
       
        mtbSoftEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"+ptbin)])
        mtbSoftEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtbSoftEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtbSoftEWK = mtbSoftEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtbSoftEWK.Scale(normEWK[ptbin])
        mtbSoft.Add(mtbSoftEWK, -1)
        mtAfterMetPlusSoftBtagging.append(mtbSoft)
       
        # ----------mt after SOFT b tagging baseline ---------------
        mtbSoft_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("baseline/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"+ptbin)])
        mtbSoft_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtbSoftBaseline = mtbSoft_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
       
        mtbSoftEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("baseline/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"+ptbin)])
        mtbSoftEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtbSoftEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtbSoftEWKBaseline = mtbSoftEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtbSoftBaseline.Add(mtbSoftEWKBaseline, -1)
        mtAfterMetPlusSoftBtaggingBaseline.append(mtbSoftBaseline)
       

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

# mt after met cut and b-jet veto

        mtPhiv_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts"+ptbin)])
        mtPhiv_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtPhiv = mtPhiv_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtPhiv.Scale(normData[ptbin])
       
        mtPhiEWKv_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts"+ptbin)])
        mtPhiEWKv_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtPhiEWKv_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtPhiEWKv = mtPhiEWKv_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtPhiEWKv.Scale(normEWK[ptbin])
        mtPhiv.Add(mtPhiEWKv, -1)
        mtAfterMetPlusBveto.append(mtPhiv)

        mtPhiv_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("baseline/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts"+ptbin)])
        mtPhiv_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtPhivBaseline = mtPhiv_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
       
        mtPhiEWKv_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("baseline/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts"+ptbin)])
        mtPhiEWKv_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtPhiEWKv_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtPhiEWKvBaseline = mtPhiEWKv_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtPhivBaseline.Add(mtPhiEWKvBaseline, -1)
        mtAfterMetPlusBvetoBaseline.append(mtPhivBaseline)
        
############################################################

        

# mt after jet selection and back-to-back cuts 
        mtj_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts"+ptbin)])
        mtj_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtj = mtj_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtj.Scale(normData[ptbin])
        
        mtjEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts"+ptbin)])
        mtjEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtjEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtjEWK = mtjEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtjEWK.Scale(normEWK[ptbin])
        mtj.Add(mtjEWK, -1)
        mtAfterCollinearCuts.append(mtj)
        
# mt after jet selection and back-to-back cuts baseline
        mtj_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("baseline/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts"+ptbin)])
        mtj_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtjBaseline = mtj_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        
        mtjEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("baseline/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts"+ptbin)])
        mtjEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtjEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtjEWKBaseline = mtjEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtjBaseline.Add(mtjEWKBaseline, -1)
        mtAfterCollinearCutsBaseline.append(mtjBaseline)
        

############################################################
 
## end of loop
        
### sum and plot        

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())
      

    events = invertedNoScale[0].Clone("inv")
    events.SetName("inv")
    events.SetTitle("Inverted tau ID")
    events.Reset()
    print "check events in inverted ",events.GetEntries()
    for histo in invertedNoScale:
        events.Add(histo)  
    print "All unormalised events - EWK = ",events.Integral()
    
 ## mt with all cuts
    hAllCuts = mtAllCuts[0].Clone("mtSum")
    hAllCuts.SetName("transverseMass")
    hAllCuts.SetTitle("Inverted tau ID")
    hAllCuts.Reset()
    for histo in mtAllCuts:
        hAllCuts.Add(histo)  
    print "All events with all cuts - EWK evets= ",hAllCuts.Integral()
    
    hAllCutsBaseline = mtAllCutsBaseline[0].Clone("mtSumBaseline")
    hAllCutsBaseline.SetName("transverseMass")
    hAllCutsBaseline.SetTitle("Inverted tau ID")
    hAllCutsBaseline.Reset()
    for histo in mtAllCutsBaseline:
        hAllCutsBaseline.Add(histo)  
    print "Baseline QCD events with all cuts = ",hAllCutsBaseline.Integral()
    
# mt plot with all cuts
    allCuts_inverted = hAllCuts.Clone("AllCuts")
    allCuts_baseline = hAllCutsBaseline.Clone("allcuts_QCD")
    invertedQCD.setLabel("AllCuts")
    invertedQCD.mtComparison(allCuts_inverted, allCuts_baseline,"AllCuts")

   
# mt plot inverted all cuts  
    invertedQCD.setLabel("MtWithAllCutsTailKiller")
    invertedQCD.mtComparison(allCuts_inverted, allCuts_inverted,"MtWithAllCutsTailKiller")
     
########################################################

    
# mt with SOFT btagging

    hmtAfterMetPlusSoftBtagging = mtAfterMetPlusSoftBtagging[0].Clone("mthmtbSoft")
    hmtAfterMetPlusSoftBtagging.SetName("transverseMassBtag")
    hmtAfterMetPlusSoftBtagging.SetTitle("Inverted tau ID")
    hmtAfterMetPlusSoftBtagging.Reset()
#    print "check hmtsum",hmtSum.GetEntries()
    for histo in mtAfterMetPlusSoftBtagging:
        hmtAfterMetPlusSoftBtagging.Add(histo)  
    print "Integral: after SOFT B tagging - EWK = ",hmtAfterMetPlusSoftBtagging.Integral()
# mt with SOFT btagging baseline
    hmtAfterMetPlusSoftBtaggingBaseline = mtAfterMetPlusSoftBtaggingBaseline[0].Clone("mthmtbSoft")
    hmtAfterMetPlusSoftBtaggingBaseline.SetName("transverseMassBtag")
    hmtAfterMetPlusSoftBtaggingBaseline.SetTitle("Inverted tau ID")
    hmtAfterMetPlusSoftBtaggingBaseline.Reset()
#    print "check hmtsum",hmtSum.GetEntries()
    for histo in mtAfterMetPlusSoftBtaggingBaseline:
        hmtAfterMetPlusSoftBtaggingBaseline.Add(histo)  
    print "Integral Baseline: after SOFT B tagging - EWK = ",hmtAfterMetPlusSoftBtaggingBaseline.Integral()

 
# mt inverted-baseline comparison, SOFT b tagging, MET CUT 
    afterJets_inverted = hmtAfterMetPlusSoftBtagging.Clone("mtbSoft")
    afterJets_baseline = hmtAfterMetPlusSoftBtaggingBaseline.Clone("mtbSoft_QCD")
    invertedQCD.setLabel("AfterMetPlusSoftBtagging")
    invertedQCD.mtComparison(afterJets_inverted,afterJets_baseline,"AfterMetPlusSoftBtagging")

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




    hmtAfterCollinearCuts = mtAfterCollinearCuts[0].Clone("AfterCollinearCuts")
    hmtAfterCollinearCuts.SetName("transverseMassBtag")
    hmtAfterCollinearCuts.SetTitle("Inverted tau ID")
    hmtAfterCollinearCuts.Reset()
    for histo in mtAfterCollinearCuts:
        hmtAfterCollinearCuts.Add(histo)
    print "Integral: after collinear cuts - EWK = ",hmtAfterCollinearCuts.Integral()

    hmtAfterCollinearCutsBaseline = mtAfterCollinearCutsBaseline[0].Clone("AfterCollinearCutsBaseline")
    hmtAfterCollinearCutsBaseline.SetName("transverseMassBtag")
    hmtAfterCollinearCutsBaseline.SetTitle("Inverted tau ID")
    hmtAfterCollinearCutsBaseline.Reset()
    for histo in mtAfterCollinearCutsBaseline:
        hmtAfterCollinearCutsBaseline.Add(histo)
    print "Integral Baseline : after collinear cuts - EWK = ",hmtAfterCollinearCutsBaseline.Integral()
                                 

    # mt inverted-baseline comparison at coll cuts
    afterJets_inverted = hmtAfterCollinearCuts.Clone("AfterCollinearCuts")
    afterJets_baseline = hmtAfterCollinearCutsBaseline.Clone("AfterCollinearCutsBaseline_QCD")
    invertedQCD.setLabel("AfterCollinearCuts")
    invertedQCD.mtComparison(afterJets_inverted,afterJets_baseline,"AfterCollinearCuts")
         
                                  

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

## B veto for closure test With Met cut   
    hmtAfterMetPlusBveto = mtAfterMetPlusBveto[0].Clone("hClosureBveto")
    hmtAfterMetPlusBveto.SetName("transverseMassBveto")
    hmtAfterMetPlusBveto.SetTitle("Inverted tau ID")
    hmtAfterMetPlusBveto.Reset()
    for histo in mtAfterMetPlusBveto:
        hmtAfterMetPlusBveto.Add(histo)  
    print "Integral: Bveto - EWK  with met cut = ",hmtAfterMetPlusBveto.Integral()

    hmtAfterMetPlusBvetoBaseline = mtAfterMetPlusBvetoBaseline[0].Clone("hClosureBvetoBaseline")
    hmtAfterMetPlusBvetoBaseline.SetName("transverseMassBveto")
    hmtAfterMetPlusBvetoBaseline.SetTitle("Inverted tau ID")
    hmtAfterMetPlusBvetoBaseline.Reset()
    for histo in mtAfterMetPlusBvetoBaseline:
        hmtAfterMetPlusBvetoBaseline.Add(histo)  
    print "Integral baseline: Bveto - EWK  with met cut = ",hmtAfterMetPlusBvetoBaseline.Integral()

# mt inverted-baseline comparison with bveto and MET CUT, closure
    #bveto_inverted =hClosureBvetoTailKiller.Clone("hmtvSum")
    bveto_inverted = hmtAfterMetPlusBveto.Clone("bveto")
    bveto_baseline = hmtAfterMetPlusBvetoBaseline.Clone("bvetoBaseline_QCD")
    invertedQCD.setLabel("AfterMetPlusBveto")
#    invertedQCD.mtComparison(bveto_inverted, bveto_baseline,"BvetoTailKillerClosure",sysError=sysError)
    invertedQCD.mtComparison(bveto_inverted, bveto_baseline,"AfterMetPlusBveto")
        




########################################################
    
## no btagging,   with Met cut 
    hmtAfterMetCut = mtAfterMetCut[0].Clone("hClosureNoBtag")
    hmtAfterMetCut.SetName("transverseMassNoBtagging")
    hmtAfterMetCut.SetTitle("Inverted tau ID")
    hmtAfterMetCut.Reset()
    for histo in mtAfterMetCut:
        hmtAfterMetCut.Add(histo)  
    print "Integral: no btagging - EWK  = ",hmtAfterMetCut.Integral()
    
    hmtAfterMetCutBaseline = mtAfterMetCutBaseline[0].Clone("hClosureNoBtag")
    hmtAfterMetCutBaseline.SetName("transverseMassNoBtagging")
    hmtAfterMetCutBaseline.SetTitle("Inverted tau ID")
    hmtAfterMetCutBaseline.Reset()
    for histo in mtAfterMetCutBaseline:
        hmtAfterMetCutBaseline.Add(histo)  
    print "Integral baseline: no btagging - EWK  = ",hmtAfterMetCutBaseline.Integral()

# mt inverted-baseline comparison, no b tagging, with met cut, closure
    afterMet_inverted = hmtAfterMetCut.Clone("afterMet")
    afterMet_baseline = hmtAfterMetCutBaseline.Clone("aftermet_QCD")
    invertedQCD.setLabel("AfterMetCut")
    invertedQCD.mtComparison(afterMet_inverted,afterMet_baseline,"AfterMetCut")
コード例 #3
0
def controlPlots(datasets):

    normData, normEWK, normFactorisedData, normFactorisedEWK = normalisation()
    norm_inc, normEWK_inc = normalisationInclusive()

    hmet = []
    hmetb = []
    effArray = []

    effErrArray = []

    hmetbveto = []
    hmtBtag = []
    hmtBveto = []
    hmtNoMetBtag = []
    hmtNoMetBveto = []
    effBvetoArray = []
    effErrBvetoArray = []
    effArrayMt = []
    effErrArrayMt = []

    effArrayMtNoMet = []
    effErrArrayMtNoMet = []

    ## histograms in bins, normalisation and substraction of EWK contribution
    ## mt with 2dim deltaPhi cut
    for ptbin in ptbins:

        ### MET
        mmt_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdJets" + ptbin)
        ])
        mmt_tmp._setLegendStyles()
        mmt_tmp._setLegendLabels()
        mmt_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmt = mmt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmt.Scale(normData[ptbin])
        #        hmt.append(mt)

        mmtEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdJets" + ptbin)
        ])
        mmtEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mmtEWK_tmp._setLegendStyles()
        mmtEWK_tmp._setLegendLabels()
        mmtEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtEWK = mmtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtEWK.Scale(normEWK[ptbin])
        mmt.Add(mmtEWK, -1)
        hmet.append(mmt)

        ### MET with btagging
        mmtb_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdBtag" + ptbin)
        ])
        mmtb_tmp._setLegendStyles()
        mmtb_tmp._setLegendLabels()
        mmtb_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtb = mmtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmtb.Scale(normData[ptbin])
        #        hmt.append(mt)

        mmtbEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdBtag" + ptbin)
        ])
        mmtbEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mmtbEWK_tmp._setLegendStyles()
        mmtbEWK_tmp._setLegendLabels()
        mmtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbEWK = mmtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtbEWK.Scale(normEWK[ptbin])
        mmtb.Add(mmtbEWK, -1)
        hmetb.append(mmtb)

        eff = mmtb.Integral() / mmt.Integral()

        ereff = sqrt(eff * (1 - eff) / mmt.Integral())
        print " pt bin ", ptbin, " btag efficiency  from MET = ", eff, " error ", ereff
        effArray.append(eff)
        effErrArray.append(ereff)

        ### MET with bveto
        mmtbveto_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdBveto" + ptbin)
        ])
        mmtbveto_tmp._setLegendStyles()
        mmtbveto_tmp._setLegendLabels()
        mmtbveto_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtbveto_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mmtbveto = mmtbveto_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()
        mmtbveto.Scale(normData[ptbin])
        #        hmt.append(mt)

        mmtbvetoEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdBveto" + ptbin)
        ])
        mmtbvetoEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mmtbvetoEWK_tmp._setLegendStyles()
        mmtbvetoEWK_tmp._setLegendLabels()
        mmtbvetoEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtbvetoEWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mmtbvetoEWK = mmtbvetoEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mmtbvetoEWK.Scale(normEWK[ptbin])
        mmtbveto.Add(mmtbvetoEWK, -1)
        hmetbveto.append(mmtbveto)

        ## normalization  mT(btag/bveto)
        eff = mmtb.Integral() / mmtbveto.Integral()

        ereff = sqrt(eff * (1 - eff) / mmtbveto.Integral())
        print " pt bin ", ptbin, " btag/bveto  efficiency from MET   = ", eff, " error ", ereff
        effBvetoArray.append(eff)
        effErrBvetoArray.append(ereff)

        ## with MT distribution
        if False:
            ###  no MET cut
            mmtb_tmp = plots.PlotBase([
                datasets.getDataset("Data").getDatasetRootHisto(
                    "Inverted/MTInvertedTauIdBtagNoMetCut" + ptbin)
            ])
            mmtb_tmp._setLegendStyles()
            mmtb_tmp._setLegendLabels()
            mmtb_tmp.histoMgr.setHistoDrawStyleAll("P")
            mmtb_tmp.histoMgr.forEachHisto(
                lambda h: h.getRootHisto().Rebin(20))
            mmtb = mmtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
            mmtb.Scale(normData[ptbin])
            #        hmt.append(mt)

            mmtbEWK_tmp = plots.PlotBase([
                datasets.getDataset("EWK").getDatasetRootHisto(
                    "Inverted/MTInvertedTauIdBtagNoMetCut" + ptbin)
            ])
            mmtbEWK_tmp.histoMgr.normalizeMCToLuminosity(
                datasets.getDataset("Data").getLuminosity())
            mmtbEWK_tmp._setLegendStyles()
            mmtbEWK_tmp._setLegendLabels()
            mmtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
            mmtbEWK_tmp.histoMgr.forEachHisto(
                lambda h: h.getRootHisto().Rebin(20))
            mmtbEWK = mmtbEWK_tmp.histoMgr.getHisto(
                "EWK").getRootHisto().Clone()
            mmtbEWK.Scale(normEWK[ptbin])
            mmtb.Add(mmtbEWK, -1)

            hmtNoMetBtag.append(mmtb)

            ### MET with bvet
            mmtbveto_tmp = plots.PlotBase([
                datasets.getDataset("Data").getDatasetRootHisto(
                    "Inverted/MTInvertedTauIdBvetoNoMetCut" + ptbin)
            ])
            mmtbveto_tmp._setLegendStyles()
            mmtbveto_tmp._setLegendLabels()
            mmtbveto_tmp.histoMgr.setHistoDrawStyleAll("P")
            mmtbveto_tmp.histoMgr.forEachHisto(
                lambda h: h.getRootHisto().Rebin(20))
            mmtbveto = mmtbveto_tmp.histoMgr.getHisto(
                "Data").getRootHisto().Clone()
            mmtbveto.Scale(normData[ptbin])
            #        hmt.append(mt)

            mmtbvetoEWK_tmp = plots.PlotBase([
                datasets.getDataset("EWK").getDatasetRootHisto(
                    "Inverted/MTInvertedTauIdBvetoNoMetCut" + ptbin)
            ])
            mmtbvetoEWK_tmp.histoMgr.normalizeMCToLuminosity(
                datasets.getDataset("Data").getLuminosity())
            mmtbvetoEWK_tmp._setLegendStyles()
            mmtbvetoEWK_tmp._setLegendLabels()
            mmtbvetoEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
            mmtbvetoEWK_tmp.histoMgr.forEachHisto(
                lambda h: h.getRootHisto().Rebin(20))
            mmtbvetoEWK = mmtbvetoEWK_tmp.histoMgr.getHisto(
                "EWK").getRootHisto().Clone()
            mmtbvetoEWK.Scale(normEWK[ptbin])
            mmtbveto.Add(mmtbvetoEWK, -1)
            hmtNoMetBveto.append(mmtbveto)

            ## normalization  mT(btag/bveto)

            eff = mmtb.Integral() / mmtbveto.Integral()
            ereff = sqrt(eff * (1 - eff) / mmtbveto.Integral())
            print " pt bin ", ptbin, " btag/bveto  efficiency from mt, no met cut  = ", eff, " error ", ereff
            effArrayMtNoMet.append(eff)
            effErrArrayMtNoMet.append(ereff)

#############################################
###  with MET cut
        mmtb_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBtag" + ptbin)
        ])
        mmtb_tmp._setLegendStyles()
        mmtb_tmp._setLegendLabels()
        mmtb_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtb = mmtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmtb.Scale(normData[ptbin])
        #        hmt.append(mt)

        mmtbEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBtag" + ptbin)
        ])
        mmtbEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mmtbEWK_tmp._setLegendStyles()
        mmtbEWK_tmp._setLegendLabels()
        mmtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbEWK = mmtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtbEWK.Scale(normEWK[ptbin])
        mmtb.Add(mmtbEWK, -1)
        hmtBtag.append(mmtb)

        mmtbveto_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBveto" + ptbin)
        ])
        mmtbveto_tmp._setLegendStyles()
        mmtbveto_tmp._setLegendLabels()
        mmtbveto_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtbveto_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mmtbveto = mmtbveto_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()
        mmtbveto.Scale(normData[ptbin])
        #        hmt.append(mt)

        mmtbvetoEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBveto" + ptbin)
        ])
        mmtbvetoEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mmtbvetoEWK_tmp._setLegendStyles()
        mmtbvetoEWK_tmp._setLegendLabels()
        mmtbvetoEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtbvetoEWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mmtbvetoEWK = mmtbvetoEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mmtbvetoEWK.Scale(normEWK[ptbin])
        mmtbveto.Add(mmtbvetoEWK, -1)
        hmtBveto.append(mmtbveto)

        ## normalization  mT(btag/bveto)
        eff = mmtb.Integral() / mmtbveto.Integral()

        ereff = sqrt(eff * (1 - eff) / mmtbveto.Integral())
        print " pt bin ", ptbin, " btag/bveto  efficiency from mt  = ", eff, " error ", ereff
        effArrayMt.append(eff)
        effErrArrayMt.append(ereff)

## sum histo bins

    met = hmet[0].Clone("met")
    met.SetName("MET")
    met.SetTitle("Inverted tau Met")
    met.Reset()
    print "check met", met.GetEntries()
    for histo in hmet:
        met.Add(histo)

    metb = hmetb[0].Clone("met")
    metb.SetName("MET")
    metb.SetTitle("Inverted tau Met")
    metb.Reset()
    print "check met btagging", metb.GetEntries()
    for histo in hmetb:
        metb.Add(histo)

    metbveto = hmetbveto[0].Clone("met")
    metbveto.SetName("METbveto")
    metbveto.SetTitle("Inverted tau Met")
    metbveto.Reset()
    print "check met bveto", metbveto.GetEntries()
    for histo in hmetbveto:
        metbveto.Add(histo)

## with MT

    if False:
        mtNoMetBtag = hmtNoMetBtag[0].Clone("mt")
        mtNoMetBtag.SetName("MET")
        mtNoMetBtag.SetTitle("Inverted tau Met")
        mtNoMetBtag.Reset()
        print "check MT btagging", mtNoMetBtag.GetEntries()
        for histo in hmtNoMetBtag:
            mtNoMetBtag.Add(histo)

        mtNoMetBveto = hmtNoMetBveto[0].Clone("mt")
        mtNoMetBveto.SetName("MET")
        mtNoMetBveto.SetTitle("Inverted tau Met")
        mtNoMetBveto.Reset()
        print "check MT bveto", mtNoMetBveto.GetEntries()
        for histo in hmtNoMetBveto:
            mtNoMetBveto.Add(histo)

    mtBtag = hmtBtag[0].Clone("mt")
    mtBtag.SetName("MET")
    mtBtag.SetTitle("Inverted tau Met")
    mtBtag.Reset()
    print "check MT btagging", mtBtag.GetEntries()
    for histo in hmtBtag:
        mtBtag.Add(histo)

    mtBveto = hmtBveto[0].Clone("mt")
    mtBveto.SetName("MET")
    mtBveto.SetTitle("Inverted tau Met")
    mtBveto.Reset()
    print "check MT bveto", mtBveto.GetEntries()
    for histo in hmtBveto:
        mtBveto.Add(histo)

##########################################
## plotting
    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())

    ###  effisiency as a function of MET
    metWithBtagging = metb.Clone("MET")
    metWithBtagging.Divide(metbveto)
    BtaggingEffVsMet = metWithBtagging.Clone("Eff")
    invertedQCD.setLabel("BtagToBvetoEffVsMet")
    invertedQCD.mtComparison(BtaggingEffVsMet, BtaggingEffVsMet,
                             "BtagToBvetoEffVsMet")

    if False:
        ###  effisiency as a function of MT
        mtWithBtagging = mtNoMetBtag.Clone("MT")
        mtWithBtagging.Divide(mtNoMetBveto)
        BtaggingEffNoMetVsMt = mtWithBtagging.Clone("Eff")
        invertedQCD.setLabel("BtagToBvetoEffNoMetVsMt")
        invertedQCD.mtComparison(BtaggingEffNoMetVsMt, BtaggingEffNoMetVsMt,
                                 "BtagToBvetoEffNoMetVsMt")

    ###  effisiency as a function of MT
    mtWithBtagging = mtBtag.Clone("MT")
    mtWithBtagging.Divide(mtBveto)
    BtaggingEffVsMt = mtWithBtagging.Clone("Eff")
    invertedQCD.setLabel("BtagToBvetoEffVsMt")
    invertedQCD.mtComparison(BtaggingEffVsMt, BtaggingEffVsMt,
                             "BtagToBvetoEffVsMt")

    # efficiency metb/met
    metbtag = metb.Clone("metb")
    metnobtag = met.Clone("met")
    metbtag.Divide(metnobtag)
    invertedQCD.setLabel("BtagEffVsMet")
    invertedQCD.mtComparison(metbtag, metbtag, "BtagEffVsMet")

    # efficiency metb/metbveto
    metbtag = metb.Clone("metb")
    metbjetveto = metbveto.Clone("met")
    invertedQCD.setLabel("BtagToBvetoEfficiency")
    invertedQCD.mtComparison(metbtag, metbjetveto, "BtagToBvetoEfficiency")

    ### Create and customise TGraph
    cEff = TCanvas("Efficiency", "Efficiency", 1)
    cEff.cd()
    ptbin_error = array.array("d", [5, 5, 5, 5, 10, 10, 30])
    ptbin = array.array("d", [45, 55, 65, 75, 90, 110, 150])

    if False:
        ## no MET cut
        cEff = TCanvas("btaggingEffNoMet", "btaggingEffNoMet", 1)
        cEff.cd()
        graph = TGraphErrors(7, ptbin, array.array("d", effArrayMtNoMet),
                             ptbin_error, array.array("d", effErrArrayMtNoMet))
        graph.SetMaximum(0.25)
        graph.SetMinimum(0.0)
        graph.SetMarkerStyle(kFullCircle)
        graph.SetMarkerColor(kBlue)
        graph.SetMarkerSize(1)
        graph.GetYaxis().SetTitle("N_{b tagged}/N_{b veto}")
        graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
        ### Re-draw graph and update canvas and gPad
        graph.Draw("AP")
        tex4 = ROOT.TLatex(
            0.2, 0.955,
            "8 TeV              19.6 fb^{-1}             CMS preliminary")
        tex4.SetNDC()
        tex4.SetTextSize(20)
        tex4.Draw()
        tex1 = ROOT.TLatex(0.2, 0.88, "All selection cuts")
        tex1.SetNDC()
        tex1.SetTextSize(22)
        #    tex1.Draw()
        tex2 = ROOT.TLatex(0.5, 0.8, "No MET cut")
        tex2.SetNDC()
        tex2.SetTextSize(24)
        tex2.Draw()

        cEff.Update()
        cEff.SaveAs("btagToBvetoEffNoMetVsPtTau_mt.png")


## with MET cut
    cEff = TCanvas("btaggingEff", "btaggingEff", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", effArrayMt), ptbin_error,
                         array.array("d", effErrArrayMt))

    graph.SetMaximum(0.25)
    graph.SetMinimum(0.0)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("N_{b tagged}/N_{b veto}")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")

    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              19.6 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2, 0.88, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    #    tex1.Draw()
    tex2 = ROOT.TLatex(0.5, 0.8, "After MET cut")
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("btagToBvetoEffVsPtTau_mt.png")

    ## no MET cut
    cEff = TCanvas("btaggingEffNoMet", "btaggingEffNoMet", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", effBvetoArray),
                         ptbin_error, array.array("d", effErrBvetoArray))
    graph.SetMaximum(0.25)

    graph.SetMinimum(0.0)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("N_{b tagged}/N_{b veto}")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")

    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              19.6 fb^{-1}             CMS preliminary")

    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2, 0.88, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    #    tex1.Draw()
    tex2 = ROOT.TLatex(0.5, 0.8, "No MET cut")
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()

    cEff.SaveAs("btagToBvetoEffNoMetVsPtTau.png")

    ## with MET cut
    cEff = TCanvas("btaggingEfficiency", "btaggingEfficiency", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", effArray), ptbin_error,
                         array.array("d", effErrArray))
    graph.SetMaximum(0.25)
    graph.SetMinimum(0.0)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)

    graph.GetYaxis().SetTitle("b-tagging efficiency")

    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")

    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              19.6 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()

    tex1 = ROOT.TLatex(0.4, 0.85, "Inverted #tau identification")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.4, 0.78, "At least 3 jets")

    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("btaggingEffVsPtTau.png")

    ##################################3

    fOUT = open("btaggingFactors", "w")

    #    now = datetime.datetime.now()

    #    fOUT.write("# Generated on %s\n"%now.ctime())
    fOUT.write("# by %s\n" % os.path.basename(sys.argv[0]))
    fOUT.write("\n")
    fOUT.write("btaggingFactors = {\n")

    i = 0
    while i < len(effArray):
        line = "    \"" + ptbins[i] + "\": " + str(effArray[i])
        if i < len(effArray) - 1:
            line += ","
        line += "\n"
        fOUT.write(line)
        i = i + 1

    fOUT.write("}\n")
    fOUT.close()
    print "B-tagging efficiensies written in file", "btaggingFactors"

    fOUT = open("btaggingToBvetoFactors.py", "w")

    #    now = datetime.datetime.now()

    #    fOUT.write("# Generated on %s\n"%now.ctime())
    fOUT.write("# by %s\n" % os.path.basename(sys.argv[0]))
    fOUT.write("\n")
    fOUT.write("btaggingToBvetoFactors = {\n")

    i = 0
    while i < len(effBvetoArray):
        line = "    \"" + ptbins[i] + "\": " + str(effBvetoArray[i])
        if i < len(effBvetoArray) - 1:
            line += ","
        line += "\n"
        fOUT.write(line)
        i = i + 1

    fOUT.write("}\n")
    fOUT.close()
    print "BtaggingToBveto efficiensies written in file", "btaggingToBvetoFactors"

    fOUT = open("btaggingToBvetoAfterMetFactors.py", "w")

    #    now = datetime.datetime.now()

    #    fOUT.write("# Generated on %s\n"%now.ctime())
    fOUT.write("# by %s\n" % os.path.basename(sys.argv[0]))
    fOUT.write("\n")
    fOUT.write("btaggingToBvetoAfterMetFactors = {\n")

    i = 0
    while i < len(effArrayMt):
        line = "    \"" + ptbins[i] + "\": " + str(effArrayMt[i])
        if i < len(effArrayMt) - 1:
            line += ","
        line += "\n"
        fOUT.write(line)
        i = i + 1

    fOUT.write("}\n")
    fOUT.close()
    print "BtaggingToBvetoAfterMet efficiensies written in file", "btaggingToBvetoFactors"
コード例 #4
0
def main():
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)
    datasets.loadLuminosities()
    plots.mergeRenameReorderForDataMC(datasets)

    datasets.merge("EWK", [
            "TTJets",
            "WJets",   
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    style = tdrstyle.TDRStyle()

    metInver = plots.DataMCPlot(datasets, analysis+"/MET_InvertedTauIdJets")
    metBase = plots.DataMCPlot(datasets, analysis+"/MET_BaseLineTauIdJets")
    metBasePP = plots.DataMCPlot(datasets, analysisPlusPlus+"/MET_BaseLineTauIdJets")
    metBaseMP = plots.DataMCPlot(datasets, analysisMinusPlus+"/MET_BaseLineTauIdJets")
    metBasePM = plots.DataMCPlot(datasets, analysisPlusMinus+"/MET_BaseLineTauIdJets")
    metBaseMM = plots.DataMCPlot(datasets, analysisMinusMinus+"/MET_BaseLineTauIdJets")


    # Rebin before subtracting
    rebin = 20
    metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin))
    metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin))
    metBasePP.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin))
    metBaseMP.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin))
    metBasePM.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin))
    metBaseMM.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin))


    metInverted_data      = metInver.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets")
    metBase_data          = metBase.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")
    metBase_EWK           = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")
    metBase_EWKplusplus   = metBasePP.histoMgr.getHisto("EWK").getRootHisto().Clone(analysisPlusPlus+"/MET_BaselineTauIdJets")
    metBase_EWKminusplus  = metBaseMP.histoMgr.getHisto("EWK").getRootHisto().Clone(analysisMinusPlus+"/MET_BaselineTauIdJets")
    metBase_EWKplusminus  = metBasePM.histoMgr.getHisto("EWK").getRootHisto().Clone(analysisPlusMinus+"/MET_BaselineTauIdJets")
    metBase_EWKminusminus = metBaseMM.histoMgr.getHisto("EWK").getRootHisto().Clone(analysisMinusMinus+"/MET_BaselineTauIdJets")

    invertedQCD = InvertedTauID()

    invertedQCD.setLabel("noError")
    invertedQCD.fitQCD(metInverted_data)
    invertedQCD.fitEWK(metBase_EWK)
    invertedQCD.fitData(metBase_data)
    normalizationWithEWK = invertedQCD.getNormalization()

    invertedQCD.setLabel("plusplusError")
    invertedQCD.fitEWK(metBase_EWKplusplus)
    invertedQCD.fitData(metBase_data)
    normalizationWithEWKplusplus = invertedQCD.getNormalization()

    invertedQCD.setLabel("minusplusError")
    invertedQCD.fitEWK(metBase_EWKminusplus)
    invertedQCD.fitData(metBase_data)
    normalizationWithEWKminusplus = invertedQCD.getNormalization()

    invertedQCD.setLabel("plusminusError")
    invertedQCD.fitEWK(metBase_EWKplusminus)
    invertedQCD.fitData(metBase_data)
    normalizationWithEWKplusminus = invertedQCD.getNormalization()

    invertedQCD.setLabel("minusminusError")
    invertedQCD.fitEWK(metBase_EWKminusminus)
    invertedQCD.fitData(metBase_data)
    normalizationWithEWKminusminus = invertedQCD.getNormalization()

    invertedQCD.Summary()

    print "Difference in normalization due to JES ++ variation",(normalizationWithEWK - normalizationWithEWKplusplus)/normalizationWithEWK
    print "Difference in normalization due to JES -+ variation",(normalizationWithEWK - normalizationWithEWKminusplus)/normalizationWithEWK
    print "Difference in normalization due to JES +- variation",(normalizationWithEWK - normalizationWithEWKplusminus)/normalizationWithEWK
    print "Difference in normalization due to JES -- variation",(normalizationWithEWK - normalizationWithEWKminusminus)/normalizationWithEWK
コード例 #5
0
def main():
    # Create all datasets from a multicrab task
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)

    # As we use weighted counters for MC normalisation, we have to
    # update the all event count to a separately defined value because
    # the analysis job uses skimmed pattuple as an input
    datasets.updateNAllEventsToPUWeighted()

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(
        filter(lambda name: "TTToHplus" in name and not "M120" in name,
               datasets.getAllDatasetNames()))

    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    ttjets2 = datasets.getDataset("TTJets").deepCopy()
    ttjets2.setCrossSection(
        ttjets2.getCrossSection() -
        datasets.getDataset("TTToHplus_M120").getCrossSection())
    print "Set TTJets2 cross section to %f" % ttjets2.getCrossSection()
    ttjets2.setName("TTJets2")
    datasets.append(ttjets2)

    datasets.merge("EWKnott", ["WJets", "DYJetsToLL", "SingleTop", "Diboson"])
    tmp = datasets.getDataset("EWKnott").deepCopy()
    tmp.setName("EWKnott2")
    datasets.append(tmp)

    datasets.merge("EWK", ["EWKnott", "TTJets"])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()

    metBase = plots.DataMCPlot(datasets, analysis + "/MET_BaseLineTauIdJets")
    metInver = plots.DataMCPlot(datasets, analysis + "/MET_InvertedTauIdJets")
    # Rebin before subtracting
    metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))

    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone(
        analysis + "/MET_InvertedTauIdJets")
    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(
        analysis + "/MET_InvertedTauIdJets")
    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone(
        analysis + "/MET_BaselineTauIdJets")
    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone(
        analysis + "/MET_BaselineTauIdJets")

    metBase_QCD = metBase_data.Clone("QCD")
    metBase_QCD.Add(metBase_EWK, -1)

    metBase_EWK.SetTitle("MC EWK")

    invertedQCD.setLabel("InvData")
    invertedQCD.fitQCD(metInverted_data)

    invertedQCD.setLabel("ChiSq")
    invertedQCD.fitEWK(metBase_EWK, "R")
    invertedQCD.fitData(metBase_data)
    normalizationWithChiSq = invertedQCD.getNormalization()

    invertedQCD.setLabel("LogLikelihood")
    invertedQCD.fitEWK(metBase_EWK, "LR")
    invertedQCD.fitData(metBase_data)
    normalizationWithLogLL = invertedQCD.getNormalization()

    print "Difference Signal vs no signal in EWK fit", (
        normalizationWithLogLL -
        normalizationWithChiSq) / normalizationWithChiSq
コード例 #6
0
def main():
    # Create all datasets from a multicrab task
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))

    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    ttjets2 = datasets.getDataset("TTJets").deepCopy()
    ttjets2.setCrossSection(ttjets2.getCrossSection()-datasets.getDataset("TTToHplus_M120").getCrossSection())
    print "Set TTJets2 cross section to %f" % ttjets2.getCrossSection()
    ttjets2.setName("TTJets2")
    datasets.append(ttjets2)

    datasets.merge("EWKnott", [
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])
    tmp = datasets.getDataset("EWKnott").deepCopy()
    tmp.setName("EWKnott2")
    datasets.append(tmp)

    datasets.merge("EWK", [
        "EWKnott",
        "TTJets"
        ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()

    metBase = plots.DataMCPlot(datasets, analysis+"/MET_BaseLineTauIdJets")
    metInver = plots.DataMCPlot(datasets, analysis+"/MET_InvertedTauIdJets")  
    # Rebin before subtracting
    metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    
    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets")
    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets") 
    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")
    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")

    metBase_QCD = metBase_data.Clone("QCD")
    metBase_QCD.Add(metBase_EWK,-1)

    metBase_EWK.SetTitle("MC EWK")

    invertedQCD.setLabel("InvData")
    invertedQCD.fitQCD(metInverted_data)

    invertedQCD.setLabel("ChiSq")
    invertedQCD.fitEWK(metBase_EWK,"R")
    invertedQCD.fitData(metBase_data)
    normalizationWithChiSq = invertedQCD.getNormalization()

    invertedQCD.setLabel("LogLikelihood")
    invertedQCD.fitEWK(metBase_EWK,"LR")
    invertedQCD.fitData(metBase_data)
    normalizationWithLogLL = invertedQCD.getNormalization()
    
    print "Difference Signal vs no signal in EWK fit",(normalizationWithLogLL - normalizationWithChiSq)/normalizationWithChiSq
コード例 #7
0
def main():

    errorBars = False
    dirs = []
    if len(sys.argv) < 2:
        usage()

    dirs.append(sys.argv[1])
    

    # Create all datasets from a multicrab task
    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,dataEra=dataEra,  searchMode=searchMode, analysisName=analysis) 
#    datasets = dataset.getDatasetsFromMulticrabDirs(dirs, counters=counters, dataEra=dataEra,  analysisBaseName="signalAnalysisInvertedTau")
##    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters, dataEra=dataEra)

    # As we use weighted counters for MC normalisation, we have to
    # update the all event count to a separately defined value because
    # the analysis job uses skimmed pattuple as an input
    datasets.updateNAllEventsToPUWeighted()

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK", [
	    "TTJets",
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())
    invertedQCD.useErrorBars(errorBars)

    metBase = plots.DataMCPlot(datasets, "BaseLine/MET_BaseLineTauIdBvetoCollinear")
    metInver = plots.DataMCPlot(datasets, "Inverted/MET_InvertedTauIdBvetoCollinear")
#    metBase = plots.DataMCPlot(datasets, "BaseLine/MET_BaseLineTauIdJetsCollinear")
#    metInver = plots.DataMCPlot(datasets, "Inverted/MET_InvertedTauIdJetsCollinear")
#    metBase = plots.DataMCPlot(datasets, "BaseLine/MET_BaseLineTauIdBveto")
#    metInver = plots.DataMCPlot(datasets, "Inverted/MET_InvertedTauIdBveto") 

    # Rebin before subtracting
    metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(1))
    metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(1))
    
#    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone("Inverted/MET_InvertedTauIdBveto")
#    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone("Inverted/MET_InvertedTauIdBveto") 
#    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone("BaseLine/MET_BaselineTauIdBveto")
#    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone("BaseLine/MET_BaselineTauIdBveto")

    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone("Inverted/MET_InvertedTauIdBvetoCollinear")
    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone("Inverted/MET_InvertedTauIdBvetoCollinear") 
    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone("BaseLine/MET_BaselineTauIdBvetoCollinear")
    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone("BaseLine/MET_BaselineTauIdBvetoCollinear")
#    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone("Inverted/MET_InvertedTauIdJetsCollinear")
#    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone("Inverted/MET_InvertedTauIdJetsCollinear") 
#    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone("BaseLine/MET_BaselineTauIdJetsCollinear")
#    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone("BaseLine/MET_BaselineTauIdJetsCollinear")


    metBase_data.SetTitle("Data: BaseLine TauID")
    metInverted_data.SetTitle("Data: Inverted TauID")
    metBase_QCD = metBase_data.Clone("QCD")
    metBase_QCD.Add(metBase_EWK,-1)
    metBase_QCD.SetTitle("Data - EWK MC: BaseLine TauID")

    metInverted_data.GetXaxis().SetTitle("PFMET (GeV)")

    invertedQCD.setLabel("BaseVsInverted")
#    invertedQCD.comparison(metInverted_data,metBase_data)
    invertedQCD.setLabel("BaseMinusEWKVsInverted")
#    invertedQCD.comparison(metInverted_data,metBase_QCD)

    invertedQCD.cutefficiency(metInverted_data,metBase_QCD)
コード例 #8
0
def main():

    errorBars = False

    # Create all datasets from a multicrab task
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))

    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK", [
	    "TTJets",
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())
    invertedQCD.useErrorBars(errorBars)

    metBase = plots.DataMCPlot(datasets, analysis+"/MET_BaseLineTauIdJets")
    metInver = plots.DataMCPlot(datasets, analysis+"/MET_InvertedTauIdJets")  

    # Rebin before subtracting
    metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10))
    metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10))
    
    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets")
    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets") 
    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")
    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")

    metBase_data.SetTitle("Data: BaseLine TauID")
    metInverted_data.SetTitle("Data: Inverted TauID")
    metBase_QCD = metBase_data.Clone("QCD")
    metBase_QCD.Add(metBase_EWK,-1)
    metBase_QCD.SetTitle("Data - EWK MC: BaseLine TauID")

    metInverted_data.GetXaxis().SetTitle("PFMET (GeV)")

    invertedQCD.setLabel("BaseVsInverted")
#    invertedQCD.comparison(metInverted_data,metBase_data)
    invertedQCD.setLabel("BaseMinusEWKVsInverted")
#    invertedQCD.comparison(metInverted_data,metBase_QCD)

    invertedQCD.cutefficiency(metInverted_data,metBase_QCD)
コード例 #9
0
def main(argv):

#    HISTONAME = "TauIdJets"
#    HISTONAME = "TauIdJetsCollinear"
#    HISTONAME = "TauIdBtag"
#    HISTONAME = "TauIdBvetoCollinear"
#    HISTONAME = "TauIdBveto"
    HISTONAME = "TauIdAfterCollinearCuts"
   
    dirs = []
    if len(sys.argv) < 2:
	usage()

    dirs.append(sys.argv[1])



    
    # Create all datasets from a multicrab task
    # datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters, dataEra=dataEra, analysisBaseName="signalAnalysisInvertedTau")
    #datasets = dataset.getDatasetsFromMulticrabDirs(dirs,counters=counters, dataEra=dataEra, analysisBaseName="signalAnalysisInvertedTau")
    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,dataEra=dataEra,  searchMode=searchMode, analysisName=analysis, optimizationMode=optimizationMode)
#    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,counters=counters, dataEra=dataEra)

    # Check multicrab consistency
    consistencyCheck.checkConsistencyStandalone(dirs[0],datasets,name="QCD inverted")
   
    # As we use weighted counters for MC normalisation, we have to
    # update the all event count to a separately defined value because
    # the analysis job uses skimmed pattuple as an input
    datasets.updateNAllEventsToPUWeighted()

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "Hplus_taunu_t-channel" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "Hplus_taunu_tW-channel" in name, datasets.getAllDatasetNames()))
    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK", [
	    "TTJets",
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(True)

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())
    invertedQCD.setInfo([dataEra,searchMode,HISTONAME])

    histonames = datasets.getDataset("Data").getDirectoryContent("baseline/METBaseline"+HISTONAME)
    bins = []
    binLabels = []
    for histoname in histonames:
        bins.append(histoname.replace("METBaseline"+HISTONAME,""))
        title = datasets.getDataset("Data").getDatasetRootHisto("baseline/METBaseline"+HISTONAME+"/"+histoname).getHistogram().GetTitle()
        title = title.replace("METBaseline"+HISTONAME,"")
        title = title.replace("#tau p_{T}","taup_T")
        title = title.replace("#tau eta","taueta")
        title = title.replace("<","lt")
        title = title.replace(">","gt")
        title = title.replace("=","eq")
        title = title.replace("..","to")
        title = title.replace(".","p")
        title = title.replace("/","_")
        binLabels.append(title)

    print
    print "Histogram bins available",bins

#    bins = ["Inclusive"]
#    bins = ["taup_Tleq50","taup_Teq50to60"]
    print "Using bins              ",bins
    print
    print "Bin labels"
    for i in range(len(binLabels)):
        line = bins[i]
        while len(line) < 10:
            line += " "
        line += ": "+binLabels[i]
        print line
    print

    for i,bin in enumerate(bins):

	invertedQCD.setLabel(binLabels[i])

        metBase = plots.DataMCPlot(datasets, "baseline/METBaseline"+HISTONAME+"/METBaseline"+HISTONAME+bin)
        metInver = plots.DataMCPlot(datasets, "Inverted/METInverted"+HISTONAME+"/METInverted"+HISTONAME+bin)
        # Rebin before subtracting
        metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        
        metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone("Inverted/METInverted"+HISTONAME+"/METInverted"+HISTONAME+bin)
        metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone("Inverted/METInverted"+HISTONAME+"/METInverted"+HISTONAME+bin)
        metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone("Baseline/METBaseLine"+HISTONAME+"/METBaseline"+HISTONAME+bin)
        metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone("Baseline/METBaseLine"+HISTONAME+"/METBaseline"+HISTONAME+bin)

        metBase_QCD = metBase_data.Clone("QCD")
        metBase_QCD.Add(metBase_EWK,-1)

        metInverted_QCD = metInverted_data.Clone("QCD")
        metInverted_QCD.Add(metInverted_EWK,-1)

        metInverted_data = addlabels(metInverted_data)
        metInverted_EWK  = addlabels(metInverted_EWK)
        metBase_data     = addlabels(metBase_data)
        metBase_EWK      = addlabels(metBase_EWK)
        metInverted_QCD  = addlabels(metInverted_QCD)

        invertedQCD.plotHisto(metInverted_data,"inverted")
        invertedQCD.plotHisto(metInverted_EWK,"invertedEWK")
        invertedQCD.plotHisto(metBase_data,"baseline")
        invertedQCD.plotHisto(metBase_EWK,"baselineEWK")


        fitOptions = "LRB"
#        fitOptions = "RB"
#        fitOptions = "IEB"

#        ROOT.TVirtualFitter.SetDefaultFitter("Minuit")
#        ROOT.TVirtualFitter.SetDefaultFitter("Minuit2")
#        fitOptions = "Q"   # Chi2 Fit
#        fitOptions = "VEB"  # Chi2 Fit with Minos Error
#        fitOptions = "IEB"  # Chi2 Fit with Integral and Minos
#        fitOptions = "VLEB" # Likelihood Fit with Minos Error

#        ROOT.TVirtualFitter.SetDefaultFitter("Fumili")
#        ROOT.TVirtualFitter.SetDefaultFitter("Fumili2")
#        fitOptions = "Q"   # Chi2 Fit
#        fitOptions = "VE"  # Chi2 Fit with Minos Error
#        fitOptions = "IE"  # Chi2 Fit with Integral and Minos
#        fitOptions = "VLE" # Likelihood Fit with Minos Error
        

        invertedQCD.fitEWK(metInverted_EWK,fitOptions)
        invertedQCD.fitEWK(metBase_EWK,fitOptions)
        invertedQCD.fitQCD(metInverted_QCD,fitOptions)
        invertedQCD.fitData(metBase_data)

        invertedQCD.getNormalization()

    invertedQCD.Summary()
    invertedQCD.WriteNormalizationToFile("QCDInvertedNormalizationFactors.py")
    invertedQCD.WriteLatexOutput("fits.tex")
def main():
    if len(sys.argv) < 2:
        usage()


#    HISTONAME = "METInvertedTauIdAfterJets"
    HISTONAME = "METInvertedTauIdAfterCollinearCuts"
#    HISTONAME = "MET_InvertedTauIdBveto"
#    HISTONAME = "METInvertedTauIdAfterCollinearCutsPlusBtag"
#    HISTONAME = "METInvertedTauIdAfterCollinearCutsPlusBtag"
#    HISTONAME = "MTInvertedTauIdJet"
#    HISTONAME = "MTInvertedTauIdPhi"

    invertedhisto = HISTONAME
    baselinehisto = HISTONAME.replace("Inverted","BaseLine")

    dirs = []
    if len(sys.argv) < 2:
        usage()

    dirs.append(sys.argv[1])
    
    # Create all datasets from a multicrab task
    #datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)
    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,dataEra=dataEra,  searchMode=searchMode, analysisName=analysis)
#    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,counters=counters, dataEra=dataEra, analysisBaseName="signalAnalysisInvertedTau" )

    # As we use weighted counters for MC normalisation, we have to
    # As we use weighted counters for MC normalisation, we have to
    # update the all event count to a separately defined value because
    # the analysis job uses skimmed pattuple as an input
    datasets.updateNAllEventsToPUWeighted()

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK", [
	    "TTJets",
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())



    if ReBinning:
        rebinfactor = 1.3
        histobins = []
        histobins.append(0)
        histobins.append(1)
        i = 1
        while histobins[len(histobins)-1] < 400:
            edge = histobins[i] + (histobins[i]-histobins[i-1])*rebinfactor
            histobins.append(edge)
            i += 1
            print histobins
            
#        metBase_data = metBase_data.Rebin(len(histobins)-1,   metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/"+invertedhisto) "",array.array("d", histobins))
        metInverted_data = metInverted_data.Rebin(len(histobins)-1,"",array.array("d", histobins))
        metBase_EWK = metBase_EWK.Rebin(len(histobins)-1,"",array.array("d", histobins))
        metInverted_EWK = metInverted_EWK.Rebin(len(histobins)-1,"",array.array("d", histobins))
    
    normData,normEWK=normalisation()

    metInverted = []
    metBaseline = []
    metBaselineQCD = []
    
    for ptbin in ptbins:
        ## inverted
        met_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/METInvertedTauIdAfterCollinearCuts/METInvertedTauIdAfterCollinearCuts"+ptbin)])

        #met_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        met_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        met = met_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()        
        met.Scale(normData[ptbin])
    
        metEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/METInvertedTauIdAfterCollinearCuts/METInvertedTauIdAfterCollinearCuts"+ptbin)])        
        #metEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        metEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        metEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metEWK = metEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        metEWK.Scale(normEWK[ptbin])
        met.Add(metEWK, -1)
        metInverted.append(met) 

## baseline
        met_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("baseline/METBaselineTauIdAfterCollinearCuts/METBaselineTauIdAfterCollinearCuts"+ptbin)])

        #met_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        met_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metbaseline = met_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()        
    
        metEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("baseline/METBaselineTauIdAfterCollinearCuts/METBaselineTauIdAfterCollinearCuts"+ptbin)])        
        #metEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/"+invertedhisto+ptbin)])
        metEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        metEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        metEWKbaseline = metEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        metBaseline.append(metbaseline)
        metbaseline.Add(metEWKbaseline, -1)
        metBaselineQCD.append(metbaseline)

        
    metInverted_data = metInverted[0].Clone("met")
    metInverted_data.SetName("met")
    metInverted_data.SetTitle("Inverted tau ID")
    metInverted_data.Reset()
    for histo in metInverted:
        metInverted_data.Add(histo)
        
    metBaseline_data = metBaseline[0].Clone("met")
    metBaseline_data.SetName("met")
    metBaseline_data.SetTitle("baseline tau ID")
    metBaseline_data.Reset()
    for histo in metBaseline:
        metBaseline_data.Add(histo)

    metBaseline_QCD = metBaselineQCD[0].Clone("met")
    metBaseline_QCD .SetName("met")
    metBaseline_QCD.SetTitle("baseline tau ID")
    metBaseline_QCD.Reset()
    for histo in metBaselineQCD:
        metBaseline_QCD.Add(histo)

        
    #metBase_data.SetTitle("Data: BaseLine TauID")
    #metInverted_data.SetTitle("Data: Inverted TauID")
    #metBase_QCD = metBase_data.Clone("QCD")

    #metBase_QCD.Add(metBase_EWK,-1)
    #metBase_QCD.SetTitle("Data - EWK MC: BaseLine TauID")

    invertedQCD.setLabel("BaseVsInverted")
    invertedQCD.comparison(metInverted_data,metBaseline_data)
    invertedQCD.setLabel("BaseMinusEWKVsInverted")
    invertedQCD.comparison(metInverted_data,metBaseline_QCD)
    invertedQCD.setLabel("McVsInverted")
#    invertedQCD.comparison(metInverted_data,metInverted_MC)
    invertedQCD.setLabel("EfficiencyBaseMinusEWKVsInverted")
    invertedQCD.cutefficiency(metInverted_data,metBaseline_QCD )
コード例 #11
0
def main():

#    HISTONAME = "TauIdJets"
    HISTONAME = "TauIdBtag"
    
    # Create all datasets from a multicrab task
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))

    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK", [
	    "TTJets",
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())



    bins = ["inclusive"]
#    bins = ["4050","5060","6070","7080","80100","100120","120150","150"]
#    bins = ["4050"]


    for bin in bins:

	invertedQCD.setLabel(bin)

	if bin == "inclusive":
	    bin = ""

        metBase = plots.DataMCPlot(datasets, analysis+"/MET_BaseLine"+HISTONAME+bin)
        metInver = plots.DataMCPlot(datasets, analysis+"/MET_Inverted"+HISTONAME+bin)
        # Rebin before subtracting
        metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10))
        metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10))

        metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_Inverted"+HISTONAME+bin)
        metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_Inverted"+HISTONAME+bin)
        metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_Baseline"+HISTONAME+bin)
        metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_Baseline"+HISTONAME+bin)

        metBase_QCD = metBase_data.Clone("QCD")
        metBase_QCD.Add(metBase_EWK,-1)

        invertedQCD.plotHisto(metInverted_data,"inverted")
        invertedQCD.plotHisto(metBase_data,"baseline")
        invertedQCD.fitQCD(metInverted_data)
        invertedQCD.fitEWK(metBase_EWK,"LR")
        invertedQCD.fitData(metBase_data)
        invertedQCD.getNormalization()

    invertedQCD.Summary()
コード例 #12
0
def invertedPurities(datasets):
    
    normData,normEWK,normFactorisedData,normFactorisedEWK=normalisation()
    norm_inc,normEWK_inc = normalisationInclusive()

    noDphi = []
    noDphiEWK = []
    Dphi160 = []
    DphiEWK160 = []
    DphiAll = []
    DphiEWKAll = []
    DphiAllremovett = []
    DphiEWKAllremovett = []
    DphiJet1=[]
    DphiEWKJet1=[]
    DphiJet2=[]
    DphiEWKJet2=[]
    hmt = []
    hmtb = [] 
    hmtv = []
    hmtPhiv = []
    hmet = []
    hmetQCD = []
    hmetEWK = []
    hjetmet = []
    hjetmetphi = [] 
    hMHTJet1phi = []
    hmtph = []
    hmtphj1= []
    hmtphj2= []
    hmtremovett = []
    DphiEWKAllbveto= []
    DphiAllbveto= []
    purityMet= []
    purityErrMet= []
    purityMtRemovett = []
    purityErrMtRemovett = []
    purityMtFirstDeltaPhiCut = []
    purityErrMtFirstDeltaPhiCut = []
    purityMtThirdDeltaPhiCut = []
    purityErrMtThirdDeltaPhiCut = [] 
    purityMtSecondDeltaPhiCut = []
    purityErrMtSecondDeltaPhiCut = []
    purityMtDeltaPhiCut = []
    purityErrMtDeltaPhiCut = []
    purityMtAfterBtagging = []
    purityErrMtAfterBtagging = []
    purityMTInvertedTauIdBvetoDphi = []
    purityErrMTInvertedTauIdBvetoDphi = []
    
## histograms in bins, normalisation and substraction of EWK contribution
    ## mt with 2dim deltaPhi cut
    for ptbin in ptbins:
        mt_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedSecondDeltaPhiCut"+ptbin)])
        mt_tmp._setLegendStyles()
        mt_tmp._setLegendLabels()
        mt_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mt = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mt.Scale(normData[ptbin])
        DphiJet2.append(mt)
        
        mtEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedSecondDeltaPhiCut"+ptbin)])
        mtEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtEWK_tmp._setLegendStyles()
        mtEWK_tmp._setLegendLabels()
        mtEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtEWK = mtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtEWK.Scale(normEWK[ptbin])
#        mt.Add(mtEWK, -1)
#        hmt.append(mt)
        DphiEWKJet2.append(mtEWK)
        
        purity = -999
        error = -999
        if mt.Integral() > 0:
            purity = (mt.Integral() - mtEWK.Integral())/ mt.Integral()
            error = sqrt(purity*(1-purity)/mt.Integral())
            purityMtSecondDeltaPhiCut.append(purity)
            purityErrMtSecondDeltaPhiCut.append(error)                         
#        print " pt bin ", ptbin, " purity Mt Second Delta Phi Cut    = ",purity, " error ",error

############################################        
               
        # mt after b tagging
        mtb_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdBtag"+ptbin)])
        mtb_tmp._setLegendStyles()
        mtb_tmp._setLegendLabels()
        mtb_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtb = mtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mtb.Scale(normData[ptbin])
        hmt.append(mtb)
        noDphi.append(mtb)
        
        mtbEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdBtag"+ptbin)])
        mtbEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtbEWK_tmp._setLegendStyles()
        mtbEWK_tmp._setLegendLabels()
        mtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtbEWK = mtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtbEWK.Scale(normEWK[ptbin])
        mtb.Add(mtbEWK, -1)
        hmtb.append(mtb)
        noDphiEWK.append(mtbEWK)

       
        purity = -999
        error = -999
        if mtb.Integral() > 0:
            purity = (mtb.Integral() - mtbEWK.Integral())/ mtb.Integral()
            error = sqrt(purity*(1-purity)/mtb.Integral())
            purityMtAfterBtagging.append(purity)
            purityErrMtAfterBtagging.append(error)                         
#        print " pt bin ", ptbin, " purity Mt After Btagging    = ",purity, " error ",error 


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

        # mt after deltaPhi cut
        mtph_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdJetDphi"+ptbin)])
        mtph_tmp._setLegendStyles()
        mtph_tmp._setLegendLabels()
        mtph_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtph_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtph = mtph_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mtph.Scale(normData[ptbin])
#        hmt.append(mt)
        Dphi160.append(mtph) 
        mtphEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdJetDphi"+ptbin)])
        mtphEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtphEWK_tmp._setLegendStyles()
        mtphEWK_tmp._setLegendLabels()
        mtphEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphEWK = mtphEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtphEWK.Scale(normEWK[ptbin])
#        mtph.Add(mtphEWK, -1)
#        hmtph.append(mtph)
        DphiEWK160.append(mtphEWK) 
        purity = -999
        error = -999
        if mtph.Integral() > 0:
            purity = (mtph.Integral() - mtphEWK.Integral())/ mtph.Integral()
            error = sqrt(purity*(1-purity)/mtph.Integral())
            purityMtDeltaPhiCut.append(purity)
            purityErrMtDeltaPhiCut.append(error)                         
#        print " pt bin ", ptbin, " purity Mt DeltaPhi Cut    = ",purity, " error ",error 


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


        # mt after deltaphi vs MHTjet1 cut
        mtphj1_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedFirstDeltaPhiCut"+ptbin)])
        #mtphj1_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("MTInvertedTauIdMet"+ptbin)])
        mtphj1_tmp._setLegendStyles()
        mtphj1_tmp._setLegendLabels()
        mtphj1_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphj1_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj1 = mtphj1_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mtphj1.Scale(normData[ptbin])
        DphiJet1.append(mtphj1)
        
        mtphj1EWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedFirstDeltaPhiCut"+ptbin)])
        #mtphj1EWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("MTInvertedTauIdMet"+ptbin)])
        mtphj1EWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtphj1EWK_tmp._setLegendStyles()
        mtphj1EWK_tmp._setLegendLabels()
        mtphj1EWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphj1EWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj1EWK = mtphj1EWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtphj1EWK.Scale(normEWK[ptbin])
#        mtphj1.Add(mtphj1EWK, -1)
#        hmtphj1.append(mtphj1)
        DphiEWKJet1.append(mtphj1EWK)
 
        purity = -999
        error = -999
        if mtphj1.Integral() > 0:
            purity = (mtphj1.Integral() - mtphj1EWK.Integral())/ mtphj1.Integral()
            error = sqrt(purity*(1-purity)/mtphj1.Integral())
            purityMtFirstDeltaPhiCut.append(purity)
            purityErrMtFirstDeltaPhiCut.append(error)                         
#        print " pt bin ", ptbin, " purity Mt First Delta Phi Cut    = ",purity, " error ",error 


############################################
        
        # mt after all cuts
        mtphj2_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedThirdDeltaPhiCut"+ptbin)])
        mtphj2_tmp._setLegendStyles()
        mtphj2_tmp._setLegendLabels()
        mtphj2_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphj2_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj2 = mtphj2_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mtphj2.Scale(normData[ptbin])
#        hmt.append(mt)
        DphiAll.append(mtphj2)
        mtphj2EWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedThirdDeltaPhiCut"+ptbin)])
        mtphj2EWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtphj2EWK_tmp._setLegendStyles()
        mtphj2EWK_tmp._setLegendLabels()
        mtphj2EWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphj2EWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj2EWK = mtphj2EWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtphj2EWK.Scale(normEWK[ptbin])
#        mtphj2.Add(mtphj2EWK, -1)
#        hmtphj2.append(mtphj2)
        DphiEWKAll.append(mtphj2EWK)
        
        purity = -999
        error = -999
        if mtphj2.Integral() > 0:
            purity = (mtphj2.Integral() - mtphj2EWK.Integral())/ mtphj2.Integral()
            error = sqrt(purity*(1-purity)/mtphj2.Integral())
            purityMtThirdDeltaPhiCut.append(purity)
            purityErrMtThirdDeltaPhiCut.append(error)                         
 #       print " pt bin ", ptbin, " purity Mt Third Delta Phi Cut    = ",purity, " error ",error 

        

#######################
       # mt with cut against tt
        mtremovett_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedAgainstTTCut"+ptbin)])
        mtremovett_tmp._setLegendStyles()
        mtremovett_tmp._setLegendLabels()
        mtremovett_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtremovett_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtremovett = mtremovett_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mtremovett.Scale(normData[ptbin])
        DphiAllremovett.append(mtremovett) 
     
        mtremovettEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedAgainstTTCut"+ptbin)])
        mtremovettEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtremovettEWK_tmp._setLegendStyles()
        mtremovettEWK_tmp._setLegendLabels()
        mtremovettEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtremovettEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtremovettEWK = mtremovettEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtremovettEWK.Scale(normEWK[ptbin])
#        mtremovett.Add(mtremovettEWK, -1)
#        hmtremovett.append(mtremovett)
        DphiEWKAllremovett.append(mtremovettEWK) 
        purity = -999
        error = -999
        if  mtremovett.Integral() > 0:
            purity = (mtremovett.Integral() - mtremovettEWK.Integral())/ mtremovett.Integral()
            error = sqrt(purity*(1-purity)/mtremovett.Integral())
            purityMtRemovett.append(purity)
            purityErrMtRemovett.append(error)                         
            print "mtremovett.Integral() ",mtremovett.Integral(), " mmtEWK.Integral() ",   mtremovettEWK.Integral()      

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

        
        ### MET
        mmt_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MET_InvertedTauIdJets"+ptbin)])
        mmt_tmp._setLegendStyles()
        mmt_tmp._setLegendLabels()
        mmt_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmt = mmt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
##        mmt.Scale(normData[ptbin])
        hmet.append(mmt)
        
        mmtEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MET_InvertedTauIdJets"+ptbin)])
        mmtEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mmtEWK_tmp._setLegendStyles()
        mmtEWK_tmp._setLegendLabels()
        mmtEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtEWK = mmtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
##        mmtEWK.Scale(normEWK[ptbin])
        mmt.Add(mmtEWK, -1)
        hmetQCD.append(mmt)
        hmetEWK.append(mmtEWK)

        
        purity = -999
        error = -999
        if mmt.Integral() > 0:
            purity = (mmt.Integral() - mmtEWK.Integral())/ mmt.Integral()
            error = sqrt(purity*(1-purity)/mmt.Integral())
            purityMet.append(purity)
            purityErrMet.append(error)
##            print "mmt.Integral() ",mmt.Integral(), " mmtEWK.Integral() ",   mmtEWK.Integral()




############################################
        
        # mt after all cuts
        mtphj2_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdBvetoDphi"+ptbin)])
        mtphj2_tmp._setLegendStyles()
        mtphj2_tmp._setLegendLabels()
        mtphj2_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphj2_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj2 = mtphj2_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
#        mtphj2.Scale(normData[ptbin])
#        hmt.append(mt)
        DphiAllbveto.append(mtphj2)
        mtphj2EWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdBvetoDphi"+ptbin)])
        mtphj2EWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mtphj2EWK_tmp._setLegendStyles()
        mtphj2EWK_tmp._setLegendLabels()
        mtphj2EWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mtphj2EWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj2EWK = mtphj2EWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
#        mtphj2EWK.Scale(normEWK[ptbin])
#        mtphj2.Add(mtphj2EWK, -1)
#        hmtphj2.append(mtphj2)
        DphiEWKAllbveto.append(mtphj2EWK)
        
        purity = -999
        error = -999
        if mtphj2.Integral() > 0:
            purity = (mtphj2.Integral() - mtphj2EWK.Integral())/ mtphj2.Integral()
            error = sqrt(purity*(1-purity)/mtphj2.Integral())
            purityMTInvertedTauIdBvetoDphi.append(purity)
            purityErrMTInvertedTauIdBvetoDphi.append(error)                         
 #       print " pt bin ", ptbin, " purity Mt Third Delta Phi Cut    = ",purity, " error ",error 



    print " "        
    print " purity met   = ",purityMet, " error ",purityErrMet
    print " purity Mt no DeltaPhi Cuts    = ",purityMtAfterBtagging, " error ",purityErrMtAfterBtagging
    print " purity Mt DeltaPhi160 Cut    = ",purityMtDeltaPhiCut, " error ",purityErrMtDeltaPhiCut
    print " purity Mt First DeltaPhi Cut    = ",purityMtFirstDeltaPhiCut, " error ",purityErrMtFirstDeltaPhiCut
    print " purity Mt Second DeltaPhi Cut    = ",purityMtSecondDeltaPhiCut, " error ",purityErrMtSecondDeltaPhiCut 
    print " purity Mt Third Delta Phi Cut    = ",purityMtThirdDeltaPhiCut, " error ",purityErrMtThirdDeltaPhiCut
    print " purity Mt b veto deltaPhi Cuts    = ",purityMTInvertedTauIdBvetoDphi, " error ",purityErrMTInvertedTauIdBvetoDphi
    print " purity Mt Remove tt    = ",purityMtRemovett, " error ",purityErrMtRemovett



    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())


### Met
    met = hmet[0].Clone("met")
    met.SetName("MET")
    met.SetTitle("Inverted tau Met")
    met.Reset()
    for histo in hmet:
        met.Add(histo)

    metQCD = hmetQCD[0].Clone("met")
    metQCD.SetName("MET")
    metQCD.SetTitle("Inverted tau Met")
    metQCD.Reset()
    for histo in hmetQCD:
        metQCD.Add(histo)
        
    metEWK = hmetEWK[0].Clone("metewk")
    metEWK.SetName("METewk")
    metEWK.SetTitle("Inverted tau Met")
    metEWK.Reset()
    for histo in hmetEWK:
        metEWK.Add(histo)

   
 ### Mt no DeltaPhi Cuts
    mtNoDphi = noDphi[0].Clone("mt")
    mtNoDphi.SetName("mt")
    mtNoDphi.SetTitle("Inverted tau Mt")
    mtNoDphi.Reset()
    for histo in noDphi:
        mtNoDphi.Add(histo)
        
    mtNoDphiEWK = noDphiEWK[0].Clone("mtewk")
    mtNoDphiEWK.SetName("MTewk")
    mtNoDphiEWK.SetTitle("Inverted tau Met")
    mtNoDphiEWK.Reset()
    for histo in noDphiEWK:
        mtNoDphiEWK.Add(histo)
        
 
 ### Mt DeltaPhi < 160 Cut
    mtDphi160 = Dphi160[0].Clone("mt")
    mtDphi160.SetName("mt")
    mtDphi160.SetTitle("Inverted tau Mt")
    mtDphi160.Reset()
    for histo in Dphi160:
        mtDphi160.Add(histo)
        
    mtDphi160EWK = DphiEWK160[0].Clone("mtewk")
    mtDphi160EWK.SetName("MTewk")
    mtDphi160EWK.SetTitle("Inverted tau Met")
    mtDphi160EWK.Reset()
    for histo in DphiEWK160:
        mtDphi160EWK.Add(histo)


 ### Mt Mt all dphi cuts 
    mtDphiAll = DphiAll[0].Clone("mt")
    mtDphiAll.SetName("mt")
    mtDphiAll.SetTitle("Inverted tau Mt")
    mtDphiAll.Reset()
    for histo in DphiAll:
        mtDphiAll.Add(histo)
        
    mtDphiAllEWK = DphiEWKAll[0].Clone("mtewk")
    mtDphiAllEWK.SetName("MTewk")
    mtDphiAllEWK.SetTitle("Inverted tau Met")
    mtDphiAllEWK.Reset()
    for histo in DphiEWKAll:
        mtDphiAllEWK.Add(histo)


 ### Mt bveto all dphi cuts 
    mtDphiAllbveto = DphiAllbveto[0].Clone("mt")
    mtDphiAllbveto.SetName("mt")
    mtDphiAllbveto.SetTitle("Inverted tau Mt")
    mtDphiAllbveto.Reset()
    for histo in DphiAllbveto:
        mtDphiAllbveto.Add(histo)
        
    mtDphiAllEWKbveto = DphiEWKAllbveto[0].Clone("mtewk")
    mtDphiAllEWKbveto.SetName("MTewk")
    mtDphiAllEWKbveto.SetTitle("Inverted tau Met")
    mtDphiAllEWKbveto.Reset()
    for histo in DphiEWKAllbveto:
        mtDphiAllEWKbveto.Add(histo)

        
### Mt Mt dphi jet1 
    mtDphiJet1 = DphiJet1[0].Clone("mt")
    mtDphiJet1.SetName("mt")
    mtDphiJet1.SetTitle("Inverted tau Mt")
    mtDphiJet1.Reset()
    for histo in DphiJet1:
        mtDphiJet1.Add(histo)
        
    mtDphiEWKJet1 = DphiEWKJet1[0].Clone("mtewk")
    mtDphiEWKJet1.SetName("MTewk")
    mtDphiEWKJet1.SetTitle("Inverted tau Met")
    mtDphiEWKJet1.Reset()
    for histo in DphiEWKJet1:
        mtDphiEWKJet1.Add(histo)
        
### Mt Mt dphi jet2 
    mtDphiJet2 = DphiJet2[0].Clone("mt")
    mtDphiJet2.SetName("mt")
    mtDphiJet2.SetTitle("Inverted tau Mt")
    mtDphiJet2.Reset()
    for histo in DphiJet2:
        mtDphiJet2.Add(histo)
        
    mtDphiEWKJet2 = DphiEWKJet2[0].Clone("mtewk")
    mtDphiEWKJet2.SetName("MTewk")
    mtDphiEWKJet2.SetTitle("Inverted tau Met")
    mtDphiEWKJet2.Reset()
    for histo in DphiEWKJet2:
        mtDphiEWKJet2.Add(histo)
        
### Mt  all dphi + tt cuts 
    mtDphiAllremovett = DphiAllremovett[0].Clone("mt")
    mtDphiAllremovett.SetName("mt")
    mtDphiAllremovett.SetTitle("Inverted tau Mt")
    mtDphiAllremovett.Reset()
    for histo in DphiAllremovett:
        mtDphiAllremovett.Add(histo)
        
    mtDphiAllremovettEWK = DphiEWKAllremovett[0].Clone("mtewk")
    mtDphiAllremovettEWK.SetName("MTewk")
    mtDphiAllremovettEWK.SetTitle("Inverted tau Met")
    mtDphiAllremovettEWK.Reset()
    for histo in DphiEWKAllremovett:
        mtDphiAllremovettEWK.Add(histo)

        

##########################################
  #  met purity
    
    metqcd = metQCD.Clone("metqcd")
    metinv = met.Clone("met")
    invertedQCD.setLabel("MetPurity")
#    invertedQCD.mtComparison(metqcd, metqcd,"MetPurity")
       
##########################################
# mt purity no deltaPhi
    mtQCD = mtNoDphi.Clone("QCD")
    mtQCD.Add(mtNoDphiEWK,-1)
    mtQCD.Divide(mtNoDphi)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtNoDeltaPhiCuts")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtNoDeltaPhiCuts")
##########################################
# mt purity deltaPhi 160
    mtQCD = mtDphi160.Clone("QCD")
    mtQCD.Add(mtDphi160EWK,-1)
    mtQCD.Divide(mtDphi160)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhi160")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtDeltaPhi160")
    ##########################################
# mt purity all deltaPhi cuts 
    mtQCD = mtDphiAll.Clone("QCD")
    mtQCD.Add(mtDphiAllEWK,-1)
    mtQCD.Divide(mtDphiAll)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtAllDeltaPhiCuts")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtAllDeltaPhiCuts")

    ##########################################
# mt bveto purity all deltaPhi cuts
## test
    invertedQCD.setLabel("testMtbveto")
#    invertedQCD.mtComparison(mtDphiAllbveto, mtDphiAllbveto,"testMtbveto")
    invertedQCD.setLabel("testEWKMtbveto")
#    invertedQCD.mtComparison(mtDphiAllEWKbveto, mtDphiAllEWKbveto,"testEWKMtbveto")
    
    mtQCD = mtDphiAllbveto.Clone("QCD")
    mtQCD.Add(mtDphiAllEWKbveto,-1)
    mtQCD.Divide(mtDphiAllbveto)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtbvetoAllDeltaPhiCuts")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtbvetoAllDeltaPhiCuts")
    ##########################################
# mt purity jet1 deltaPhi cuts 
    mtQCD = mtDphiJet1.Clone("QCD")
    mtQCD.Add(mtDphiEWKJet1,-1)
    mtQCD.Divide(mtDphiJet1)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhiJet1Cuts")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtDeltaPhiJet1Cuts")
    ##########################################
# mt purity jet2 deltaPhi cuts 
    mtQCD = mtDphiJet2.Clone("QCD")
    mtQCD.Add(mtDphiEWKJet2,-1)
    mtQCD.Divide(mtDphiJet2)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhiJet2Cuts")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtDeltaPhiJet2Cuts")
    ##########################################
# mt purity all deltaPhi cuts and against tt cut
    mtQCD = mtDphiAllremovett.Clone("QCD")
    mtQCD.Add(mtDphiAllremovettEWK,-1)
    mtQCD.Divide(mtDphiAllremovett)    
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhiAndAgainsttt")
    invertedQCD.mtComparison(mtQCD, mtQCD,"MtDeltaPhiAndAgainsttt")
    
#################################################
 ##  purities as a function of pt tau jet
    
### Create and customise TGraph
    cEff = TCanvas ("MetPurity", "MetPurity", 1)
    cEff.cd()
    ptbin_error = array.array("d",[5, 5, 5, 5, 10, 10 ,30])
    ptbin = array.array("d",[45, 55, 65, 75, 90, 110 ,150])


    
    graph = TGraphErrors(7, ptbin, array.array("d",purityMTInvertedTauIdBvetoDphi),ptbin_error,array.array("d",purityErrMTInvertedTauIdBvetoDphi))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.6)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV/c]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.35,0.35,"B-tagging factorisation")
    tex1.SetNDC()
    tex1.SetTextSize(25)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.35,0.27,"#Delta#phi cuts" )
    tex2.SetNDC()
    tex2.SetTextSize(25)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMTInvertedTauIdBvetoDphiBins.png")            

  
    graph = TGraphErrors(7, ptbin, array.array("d",purityMet),ptbin_error,array.array("d",purityErrMet))    
    graph.SetMaximum(1.1)
    graph.SetMinimum(0.8)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV/c]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.35,0.35,"Inverted #tau jet isolation")
    tex1.SetNDC()
    tex1.SetTextSize(20)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.35,0.3,"at least 3 jets" )
    tex2.SetNDC()
    tex2.SetTextSize(25)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMetPtBins.png")            
  
## Mt without deltaPhi cuts
    cEff = TCanvas ("MtNoDeltaPhiCutsPurity", "MtNoDeltaPhiCutsPurity", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",purityMtAfterBtagging),ptbin_error,array.array("d",purityErrMtAfterBtagging))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.5,0.38,"All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.5,0.3,"no #Delta#phi cuts" )
    tex2.SetNDC()
    tex2.SetTextSize(25)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtNoDeltaPhiCutsBins.png")            
  
## Mt without deltaPhi cuts
    cEff = TCanvas ("MtDeltaPhi160Purity", "MtDeltaPhi160Purity", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",purityMtDeltaPhiCut),ptbin_error,array.array("d",purityErrMtDeltaPhiCut))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.5,0.35,"All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(24)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.5,0.25,"#Delta#phi(#tau jet,MET) < 160^{o}" )
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtDeltaPhi160Bins.png")



## Mt 1st deltaPhi cut
    cEff = TCanvas ("MtFirstDeltaCutPurity", "MtFirstDeltaPhiCutPurity", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",purityMtFirstDeltaPhiCut),ptbin_error,array.array("d",purityErrMtFirstDeltaPhiCut))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.4,0.4,"All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(24)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.3,0.3,"#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1,MET) cut" )
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtFirstDeltaPhiCutBins.png")


## Mt 2nd deltaPhi cut
    cEff = TCanvas ("MtSecondDeltaCutPurity", "MtFirstSecondPhiCutPurity", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",purityMtSecondDeltaPhiCut),ptbin_error,array.array("d",purityErrMtSecondDeltaPhiCut))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2,0.88,"All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.2,0.8,"#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1/2,MET) cuts" )
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtSecondDeltaPhiCutBins.png")



    ## Mt 2nd deltaPhi cut
    cEff = TCanvas ("MtThirdDeltaCutPurity", "MtThirdDeltaPhiCutPurity", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",purityMtThirdDeltaPhiCut),ptbin_error,array.array("d",purityErrMtThirdDeltaPhiCut                            ))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2,0.88, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.2,0.8,"#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1/2/3,MET) cuts" )
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtThirdDeltaPhiCutBins.png")

    
    ## Mt deltaPhi cuts and against tt
    cEff = TCanvas ("MtMtRemovettPurity", "MtMtRemovettPurity", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",purityMtRemovett),ptbin_error,array.array("d",purityErrMtRemovett))    
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2,0.88, "All selection cuts ")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.2,0.8,"#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1/2/3,MET) cuts" )
    tex2.SetNDC()
    tex2.SetTextSize(22)
    tex2.Draw()
    tex3 = ROOT.TLatex(0.2,0.72,"#Delta#phi cut against tt+jets" )
    tex3.SetNDC()
    tex3.SetTextSize(22)
    tex3.Draw()
    
    cEff.Update()
    cEff.SaveAs("purityMtAgainstttCutBins.png")
コード例 #13
0
def old_plots():

    mtAllCuts = []
    mtAllCutsBaseline = []
    mtAfterMetCut = []
    mtAfterMetCutBaseline = []
    mtAfterMetPlusSoftBtagging = []
    mtAfterMetPlusSoftBtaggingBaseline = []
    mtAfterMetPlusBveto = []
    mtAfterMetPlusBvetoBaseline = []
    mtAfterCollinearCuts = []
    mtAfterCollinearCutsBaseline = []
    invertedNoScale = []

    ## histograms in bins, normalisation and substraction of EWK contribution
    ## mt with 2dim deltaPhi cut
    for ptbin in ptbins:
        ## -------------   mt with all cuts -----------

        mt_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterBackToBackCuts/MTInvertedTauIdAfterBackToBackCuts"
                + ptbin)
        ])
        mt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mt = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtEvents = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        invertedNoScale.append(mtEvents)
        mt.Scale(normData[ptbin])

        mtEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterBackToBackCuts/MTInvertedTauIdAfterBackToBackCuts"
                + ptbin)
        ])
        mtEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtEWK = mtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtEWK.Scale(normEWK[ptbin])
        if includeEWKscale:
            mtEWK.Scale(EWKscale)
        mt.Add(mtEWK, -1)
        mtAllCuts.append(mt)

        ## baseline
        mt_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterBackToBackCuts/MTBaselineTauIdAfterBackToBackCuts"
                + ptbin)
        ])
        mt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtBaseline = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()

        mtEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterBackToBackCuts/MTBaselineTauIdAfterBackToBackCuts"
                + ptbin)
        ])
        mtEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtEWKBaseline = mtEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtBaseline.Add(mtEWKBaseline, -1)
        mtAllCutsBaseline.append(mtBaseline)

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

        ### ---- mt after met cut
        mtfac_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterMetPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBackToBackCuts"
                + ptbin)
        ])
        mtfac_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtfac = mtfac_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtNoBtaggingTailKiller = mtfac_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()
        mtNoBtaggingTailKiller.Scale(normData[ptbin])

        mtfacEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterMetPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBackToBackCuts"
                + ptbin)
        ])
        mtfacEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtfacEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtNoBtaggingTailKillerEWK = mtfacEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtNoBtaggingTailKillerEWK.Scale(normEWK[ptbin])
        mtNoBtaggingTailKiller.Add(mtNoBtaggingTailKillerEWK, -1)
        mtAfterMetCut.append(mtNoBtaggingTailKiller)

        ### ---- mt after met cut baseline
        mtfac_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterMetPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBackToBackCuts"
                + ptbin)
        ])
        mtfac_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtfac = mtfac_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtNoBtaggingTailKillerBaseline = mtfac_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()

        mtfacEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterMetPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBackToBackCuts"
                + ptbin)
        ])
        mtfacEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtfacEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtNoBtaggingTailKillerEWK = mtfacEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtNoBtaggingTailKillerBaseline.Add(mtNoBtaggingTailKillerEWK, -1)
        mtAfterMetCutBaseline.append(mtNoBtaggingTailKillerBaseline)

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

        # ----------mt after SOFT b tagging ---------------
        mtbSoft_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"
                + ptbin)
        ])
        mtbSoft_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtbSoft = mtbSoft_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtbSoft.Scale(normData[ptbin])

        mtbSoftEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"
                + ptbin)
        ])
        mtbSoftEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtbSoftEWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(5))
        mtbSoftEWK = mtbSoftEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtbSoftEWK.Scale(normEWK[ptbin])
        mtbSoft.Add(mtbSoftEWK, -1)
        mtAfterMetPlusSoftBtagging.append(mtbSoft)

        # ----------mt after SOFT b tagging baseline ---------------
        mtbSoft_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"
                + ptbin)
        ])
        mtbSoft_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtbSoftBaseline = mtbSoft_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()

        mtbSoftEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusSoftBtaggingPlusBackToBackCuts"
                + ptbin)
        ])
        mtbSoftEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtbSoftEWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(5))
        mtbSoftEWKBaseline = mtbSoftEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtbSoftBaseline.Add(mtbSoftEWKBaseline, -1)
        mtAfterMetPlusSoftBtaggingBaseline.append(mtbSoftBaseline)

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

        # mt after met cut and b-jet veto

        mtPhiv_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts"
                + ptbin)
        ])
        mtPhiv_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtPhiv = mtPhiv_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtPhiv.Scale(normData[ptbin])

        mtPhiEWKv_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTInvertedTauIdAfterMetPlusBvetoPlusBackToBackCuts"
                + ptbin)
        ])
        mtPhiEWKv_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtPhiEWKv_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(5))
        mtPhiEWKv = mtPhiEWKv_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtPhiEWKv.Scale(normEWK[ptbin])
        mtPhiv.Add(mtPhiEWKv, -1)
        mtAfterMetPlusBveto.append(mtPhiv)

        mtPhiv_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts"
                + ptbin)
        ])
        mtPhiv_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtPhivBaseline = mtPhiv_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()

        mtPhiEWKv_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts/MTBaselineTauIdAfterMetPlusBvetoPlusBackToBackCuts"
                + ptbin)
        ])
        mtPhiEWKv_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtPhiEWKv_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(5))
        mtPhiEWKvBaseline = mtPhiEWKv_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtPhivBaseline.Add(mtPhiEWKvBaseline, -1)
        mtAfterMetPlusBvetoBaseline.append(mtPhivBaseline)

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

        # mt after jet selection and back-to-back cuts
        mtj_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts"
                + ptbin)
        ])
        mtj_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtj = mtj_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mtj.Scale(normData[ptbin])

        mtjEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts/MTInvertedTauIdAfterCollinearCutsPlusBackToBackCuts"
                + ptbin)
        ])
        mtjEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtjEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtjEWK = mtjEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mtjEWK.Scale(normEWK[ptbin])
        mtj.Add(mtjEWK, -1)
        mtAfterCollinearCuts.append(mtj)

        # mt after jet selection and back-to-back cuts baseline
        mtj_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts"
                + ptbin)
        ])
        mtj_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtjBaseline = mtj_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()

        mtjEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "baseline/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts/MTBaselineTauIdAfterCollinearCutsPlusBackToBackCuts"
                + ptbin)
        ])
        mtjEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtjEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(5))
        mtjEWKBaseline = mtjEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        mtjBaseline.Add(mtjEWKBaseline, -1)
        mtAfterCollinearCutsBaseline.append(mtjBaseline)

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

## end of loop

### sum and plot

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())

    events = invertedNoScale[0].Clone("inv")
    events.SetName("inv")
    events.SetTitle("Inverted tau ID")
    events.Reset()
    print "check events in inverted ", events.GetEntries()
    for histo in invertedNoScale:
        events.Add(histo)
    print "All unormalised events - EWK = ", events.Integral()

    ## mt with all cuts
    hAllCuts = mtAllCuts[0].Clone("mtSum")
    hAllCuts.SetName("transverseMass")
    hAllCuts.SetTitle("Inverted tau ID")
    hAllCuts.Reset()
    for histo in mtAllCuts:
        hAllCuts.Add(histo)
    print "All events with all cuts - EWK evets= ", hAllCuts.Integral()

    hAllCutsBaseline = mtAllCutsBaseline[0].Clone("mtSumBaseline")
    hAllCutsBaseline.SetName("transverseMass")
    hAllCutsBaseline.SetTitle("Inverted tau ID")
    hAllCutsBaseline.Reset()
    for histo in mtAllCutsBaseline:
        hAllCutsBaseline.Add(histo)
    print "Baseline QCD events with all cuts = ", hAllCutsBaseline.Integral()

    # mt plot with all cuts
    allCuts_inverted = hAllCuts.Clone("AllCuts")
    allCuts_baseline = hAllCutsBaseline.Clone("allcuts_QCD")
    invertedQCD.setLabel("AllCuts")
    invertedQCD.mtComparison(allCuts_inverted, allCuts_baseline, "AllCuts")

    # mt plot inverted all cuts
    invertedQCD.setLabel("MtWithAllCutsTailKiller")
    invertedQCD.mtComparison(allCuts_inverted, allCuts_inverted,
                             "MtWithAllCutsTailKiller")

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

    # mt with SOFT btagging

    hmtAfterMetPlusSoftBtagging = mtAfterMetPlusSoftBtagging[0].Clone(
        "mthmtbSoft")
    hmtAfterMetPlusSoftBtagging.SetName("transverseMassBtag")
    hmtAfterMetPlusSoftBtagging.SetTitle("Inverted tau ID")
    hmtAfterMetPlusSoftBtagging.Reset()
    #    print "check hmtsum",hmtSum.GetEntries()
    for histo in mtAfterMetPlusSoftBtagging:
        hmtAfterMetPlusSoftBtagging.Add(histo)
    print "Integral: after SOFT B tagging - EWK = ", hmtAfterMetPlusSoftBtagging.Integral(
    )
    # mt with SOFT btagging baseline
    hmtAfterMetPlusSoftBtaggingBaseline = mtAfterMetPlusSoftBtaggingBaseline[
        0].Clone("mthmtbSoft")
    hmtAfterMetPlusSoftBtaggingBaseline.SetName("transverseMassBtag")
    hmtAfterMetPlusSoftBtaggingBaseline.SetTitle("Inverted tau ID")
    hmtAfterMetPlusSoftBtaggingBaseline.Reset()
    #    print "check hmtsum",hmtSum.GetEntries()
    for histo in mtAfterMetPlusSoftBtaggingBaseline:
        hmtAfterMetPlusSoftBtaggingBaseline.Add(histo)
    print "Integral Baseline: after SOFT B tagging - EWK = ", hmtAfterMetPlusSoftBtaggingBaseline.Integral(
    )

    # mt inverted-baseline comparison, SOFT b tagging, MET CUT
    afterJets_inverted = hmtAfterMetPlusSoftBtagging.Clone("mtbSoft")
    afterJets_baseline = hmtAfterMetPlusSoftBtaggingBaseline.Clone(
        "mtbSoft_QCD")
    invertedQCD.setLabel("AfterMetPlusSoftBtagging")
    invertedQCD.mtComparison(afterJets_inverted, afterJets_baseline,
                             "AfterMetPlusSoftBtagging")

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

    hmtAfterCollinearCuts = mtAfterCollinearCuts[0].Clone("AfterCollinearCuts")
    hmtAfterCollinearCuts.SetName("transverseMassBtag")
    hmtAfterCollinearCuts.SetTitle("Inverted tau ID")
    hmtAfterCollinearCuts.Reset()
    for histo in mtAfterCollinearCuts:
        hmtAfterCollinearCuts.Add(histo)
    print "Integral: after collinear cuts - EWK = ", hmtAfterCollinearCuts.Integral(
    )

    hmtAfterCollinearCutsBaseline = mtAfterCollinearCutsBaseline[0].Clone(
        "AfterCollinearCutsBaseline")
    hmtAfterCollinearCutsBaseline.SetName("transverseMassBtag")
    hmtAfterCollinearCutsBaseline.SetTitle("Inverted tau ID")
    hmtAfterCollinearCutsBaseline.Reset()
    for histo in mtAfterCollinearCutsBaseline:
        hmtAfterCollinearCutsBaseline.Add(histo)
    print "Integral Baseline : after collinear cuts - EWK = ", hmtAfterCollinearCutsBaseline.Integral(
    )

    # mt inverted-baseline comparison at coll cuts
    afterJets_inverted = hmtAfterCollinearCuts.Clone("AfterCollinearCuts")
    afterJets_baseline = hmtAfterCollinearCutsBaseline.Clone(
        "AfterCollinearCutsBaseline_QCD")
    invertedQCD.setLabel("AfterCollinearCuts")
    invertedQCD.mtComparison(afterJets_inverted, afterJets_baseline,
                             "AfterCollinearCuts")

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

    ## B veto for closure test With Met cut
    hmtAfterMetPlusBveto = mtAfterMetPlusBveto[0].Clone("hClosureBveto")
    hmtAfterMetPlusBveto.SetName("transverseMassBveto")
    hmtAfterMetPlusBveto.SetTitle("Inverted tau ID")
    hmtAfterMetPlusBveto.Reset()
    for histo in mtAfterMetPlusBveto:
        hmtAfterMetPlusBveto.Add(histo)
    print "Integral: Bveto - EWK  with met cut = ", hmtAfterMetPlusBveto.Integral(
    )

    hmtAfterMetPlusBvetoBaseline = mtAfterMetPlusBvetoBaseline[0].Clone(
        "hClosureBvetoBaseline")
    hmtAfterMetPlusBvetoBaseline.SetName("transverseMassBveto")
    hmtAfterMetPlusBvetoBaseline.SetTitle("Inverted tau ID")
    hmtAfterMetPlusBvetoBaseline.Reset()
    for histo in mtAfterMetPlusBvetoBaseline:
        hmtAfterMetPlusBvetoBaseline.Add(histo)
    print "Integral baseline: Bveto - EWK  with met cut = ", hmtAfterMetPlusBvetoBaseline.Integral(
    )

    # mt inverted-baseline comparison with bveto and MET CUT, closure
    #bveto_inverted =hClosureBvetoTailKiller.Clone("hmtvSum")
    bveto_inverted = hmtAfterMetPlusBveto.Clone("bveto")
    bveto_baseline = hmtAfterMetPlusBvetoBaseline.Clone("bvetoBaseline_QCD")
    invertedQCD.setLabel("AfterMetPlusBveto")
    #    invertedQCD.mtComparison(bveto_inverted, bveto_baseline,"BvetoTailKillerClosure",sysError=sysError)
    invertedQCD.mtComparison(bveto_inverted, bveto_baseline,
                             "AfterMetPlusBveto")

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

    ## no btagging,   with Met cut
    hmtAfterMetCut = mtAfterMetCut[0].Clone("hClosureNoBtag")
    hmtAfterMetCut.SetName("transverseMassNoBtagging")
    hmtAfterMetCut.SetTitle("Inverted tau ID")
    hmtAfterMetCut.Reset()
    for histo in mtAfterMetCut:
        hmtAfterMetCut.Add(histo)
    print "Integral: no btagging - EWK  = ", hmtAfterMetCut.Integral()

    hmtAfterMetCutBaseline = mtAfterMetCutBaseline[0].Clone("hClosureNoBtag")
    hmtAfterMetCutBaseline.SetName("transverseMassNoBtagging")
    hmtAfterMetCutBaseline.SetTitle("Inverted tau ID")
    hmtAfterMetCutBaseline.Reset()
    for histo in mtAfterMetCutBaseline:
        hmtAfterMetCutBaseline.Add(histo)
    print "Integral baseline: no btagging - EWK  = ", hmtAfterMetCutBaseline.Integral(
    )

    # mt inverted-baseline comparison, no b tagging, with met cut, closure
    afterMet_inverted = hmtAfterMetCut.Clone("afterMet")
    afterMet_baseline = hmtAfterMetCutBaseline.Clone("aftermet_QCD")
    invertedQCD.setLabel("AfterMetCut")
    invertedQCD.mtComparison(afterMet_inverted, afterMet_baseline,
                             "AfterMetCut")
コード例 #14
0
def main(argv):

#    HISTONAME = "TauIdJets"
#    HISTONAME = "TauIdJetsCollinear"
#    HISTONAME = "TauIdBtag"
#    HISTONAME = "TauIdBvetoCollinear"
#    HISTONAME = "TauIdBveto"
    HISTONAME = "TauIdAfterCollinearCuts"
    FAKEHISTO = "OnlyEWKFakeTaus"
   
    dirs = []
    if len(sys.argv) < 2:
	usage()

    dirs.append(sys.argv[1])

    
    # Create all datasets from a multicrab task

    datasets = dataset.getDatasetsFromMulticrabDirs(dirs,dataEra=dataEra,  searchMode=searchMode, analysisName="signalAnalysisInvertedTau",optimizationMode="") #no collinear
    #datasets = dataset.getDatasetsFromMulticrabDirs(dirs,dataEra=dataEra,  searchMode=searchMode, analysisName="signalAnalysisInvertedTau",optimizationMode="OptQCDTailKillerLoosePlus") #collinear


    # Check multicrab consistency
    consistencyCheck.checkConsistencyStandalone(dirs[0],datasets,name="QCD inverted")
   
    # As we use weighted counters for MC normalisation, we have to
    # update the all event count to a separately defined value because
    # the analysis job uses skimmed pattuple as an input
    datasets.updateNAllEventsToPUWeighted()

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "Hplus_taunu_t-channel" in name, datasets.getAllDatasetNames()))
    datasets.remove(filter(lambda name: "Hplus_taunu_tW-channel" in name, datasets.getAllDatasetNames()))
    #datasets.remove(filter(lambda name: "TTJets_SemiLept" in name, datasets.getAllDatasetNames()))
    #datasets.remove(filter(lambda name: "TTJets_FullLept" in name, datasets.getAllDatasetNames()))
    #datasets.remove(filter(lambda name: "TTJets_Hadronic" in name, datasets.getAllDatasetNames()))
    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    datasets.merge("EWK", [
	    "TTJets",
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])

    # Apply TDR style
    style = tdrstyle.TDRStyle()
    style.setOptStat(True)

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())
    invertedQCD.setInfo([dataEra,searchMode,HISTONAME])
    
    histonames = datasets.getDataset("Data").getDirectoryContent("baseline/METBaseline"+HISTONAME)
    bins = []
    binLabels = []
    for histoname in histonames:
        bins.append(histoname.replace("METBaseline"+HISTONAME,""))
        title = datasets.getDataset("Data").getDatasetRootHisto("baseline/METBaseline"+HISTONAME+"/"+histoname).getHistogram().GetTitle()
        title = title.replace("METBaseline"+HISTONAME,"")
        title = title.replace("#tau p_{T}","taup_T")
        title = title.replace("#tau eta","taueta")
        title = title.replace("<","lt")
        title = title.replace(">","gt")
        title = title.replace("=","eq")
        title = title.replace("..","to")
        title = title.replace(".","p")
        title = title.replace("/","_")
        binLabels.append(title)
    #binLabels = bins # for this data set
    print
    print "Histogram bins available",bins
    
    #    bins = ["Inclusive"]
    #    bins = ["taup_Tleq50","taup_Teq50to60"]
    print "Using bins              ",bins
    print
    print "Bin labels"
    for i in range(len(binLabels)):
        line = bins[i]
        while len(line) < 10:
            line += " "
        line += ": "+binLabels[i]
        print line
    print

    for i,bin in enumerate(bins):
        invertedQCD.setLabel(binLabels[i])

        metBase = plots.DataMCPlot(datasets, "baseline/METBaseline"+HISTONAME+"/METBaseline"+HISTONAME+bin)
        metInver = plots.DataMCPlot(datasets, "Inverted/METInverted"+HISTONAME+"/METInverted"+HISTONAME+bin)

        metBase_FakeTaus = plots.DataMCPlot(datasets, "baseline/METBaseline"+HISTONAME+FAKEHISTO+"/METBaseline"+HISTONAME+FAKEHISTO+bin)
        metInver_FakeTaus = plots.DataMCPlot(datasets, "Inverted/METInverted"+HISTONAME+FAKEHISTO+"/METInverted"+HISTONAME+FAKEHISTO+bin)


        # Rebin before subtracting
        
        metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) #5
        metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) #5
        
        metBase_FakeTaus.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) #5
        metInver_FakeTaus.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) #5
        
        metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone("Inverted/METInverted"+HISTONAME+"/METInverted"+HISTONAME+bin)
        metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone("baseline/METBaseLine"+HISTONAME+"/METBaseline"+HISTONAME+bin)

        metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone("Inverted/METInverted"+HISTONAME+"/METInverted"+HISTONAME+bin)
        metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone("baseline/METBaseLine"+HISTONAME+"/METBaseline"+HISTONAME+bin)

        metInverted_EWK_FakeTaus = metInver_FakeTaus.histoMgr.getHisto("EWK").getRootHisto().Clone("Inverted/METInverted"+HISTONAME+FAKEHISTO+"/METInverted"+HISTONAME+FAKEHISTO+bin)
        metBase_EWK_FakeTaus = metBase_FakeTaus.histoMgr.getHisto("EWK").getRootHisto().Clone("baseline/METBaseLine"+HISTONAME+FAKEHISTO+"/METBaseline"+HISTONAME+FAKEHISTO+bin)

        metBase_QCD = metBase_data.Clone("QCD")
        metBase_QCD.Add(metBase_EWK,-1)
        metInverted_QCD = metInverted_data.Clone("QCD")
        metInverted_QCD.Add(metInverted_EWK,-1)

        metInverted_data = addlabels(metInverted_data)
        metInverted_EWK  = addlabels(metInverted_EWK)
        metInverted_EWK_FakeTaus  = addlabels(metInverted_EWK_FakeTaus)
        
        metBase_data = addlabels(metBase_data)
        metBase_EWK  = addlabels(metBase_EWK)
        metBase_EWK_FakeTaus = addlabels(metBase_EWK_FakeTaus)

        metInverted_QCD  = addlabels(metInverted_QCD)

        invertedQCD.plotHisto(metInverted_data,"inverted")
        invertedQCD.plotHisto(metInverted_EWK,"invertedEWK")
        invertedQCD.plotHisto(metBase_data,"baseline")
        invertedQCD.plotHisto(metBase_EWK,"baselineEWK")
        invertedQCD.plotHisto(metInverted_EWK_FakeTaus,"invertedEWK_FakeTaus")
        invertedQCD.plotHisto(metBase_EWK_FakeTaus,"baselineEWK_FakeTaus")

        fitOptions = "LRB"
        #fitOptions = "RB"                                                                              
        #fitOptions = "IEB"

        invertedQCD.fitEWK(metInverted_EWK,fitOptions)
        invertedQCD.fitEWK(metBase_EWK,fitOptions)
        invertedQCD.fitQCD(metInverted_QCD,fitOptions)
        invertedQCD.fitData(metBase_data)

        invertedQCD.fitEWK_FakeTaus(metInverted_EWK_FakeTaus,fitOptions)
        invertedQCD.fitEWK_FakeTaus(metBase_EWK_FakeTaus,fitOptions)

        invertedQCD.getNormalization()
        
    invertedQCD.Summary()
    invertedQCD.WriteNormalizationToFile("QCDInvertedNormalizationFactors.py")
    invertedQCD.WriteLatexOutput("fits.tex")
コード例 #15
0
def controlPlots(datasets):
    
    normData,normEWK,normFactorisedData,normFactorisedEWK=normalisation()
    norm_inc,normEWK_inc = normalisationInclusive()



    hmet = []
    hmetb = []
    effArray = []

    effErrArray = []


    hmetbveto = []
    hmtBtag = []
    hmtBveto = []
    hmtNoMetBtag = []
    hmtNoMetBveto = []
    effBvetoArray = []
    effErrBvetoArray = []
    effArrayMt= []
    effErrArrayMt= []

    effArrayMtNoMet= []
    effErrArrayMtNoMet= []
    
## histograms in bins, normalisation and substraction of EWK contribution
    ## mt with 2dim deltaPhi cut
    for ptbin in ptbins:
 
        ### MET
        mmt_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MET_InvertedTauIdJets"+ptbin)])
        mmt_tmp._setLegendStyles()
        mmt_tmp._setLegendLabels()
        mmt_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmt = mmt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmt.Scale(normData[ptbin])
#        hmt.append(mt)

        mmtEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MET_InvertedTauIdJets"+ptbin)])
        mmtEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mmtEWK_tmp._setLegendStyles()
        mmtEWK_tmp._setLegendLabels()
        mmtEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtEWK = mmtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtEWK.Scale(normEWK[ptbin])
        mmt.Add(mmtEWK, -1)
        hmet.append(mmt)


        ### MET with btagging
        mmtb_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MET_InvertedTauIdBtag"+ptbin)])
        mmtb_tmp._setLegendStyles()
        mmtb_tmp._setLegendLabels()
        mmtb_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtb = mmtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmtb.Scale(normData[ptbin])
#        hmt.append(mt)

        mmtbEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MET_InvertedTauIdBtag"+ptbin)])
        mmtbEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mmtbEWK_tmp._setLegendStyles()
        mmtbEWK_tmp._setLegendLabels()
        mmtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbEWK = mmtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtbEWK.Scale(normEWK[ptbin])
        mmtb.Add(mmtbEWK, -1)        
        hmetb.append(mmtb)

        
        eff = mmtb.Integral()/mmt.Integral()

        ereff = sqrt(eff*(1-eff)/mmt.Integral())
        print " pt bin ", ptbin, " btag efficiency  from MET = ",eff, " error ",ereff
        effArray.append(eff)
        effErrArray.append(ereff)


        
          ### MET with bveto
        mmtbveto_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MET_InvertedTauIdBveto"+ptbin)])
        mmtbveto_tmp._setLegendStyles()
        mmtbveto_tmp._setLegendLabels()
        mmtbveto_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtbveto_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbveto = mmtbveto_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmtbveto.Scale(normData[ptbin])
#        hmt.append(mt)

        mmtbvetoEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MET_InvertedTauIdBveto"+ptbin)])
        mmtbvetoEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mmtbvetoEWK_tmp._setLegendStyles()
        mmtbvetoEWK_tmp._setLegendLabels()
        mmtbvetoEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtbvetoEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbvetoEWK = mmtbvetoEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtbvetoEWK.Scale(normEWK[ptbin])
        mmtbveto.Add(mmtbvetoEWK, -1)        
        hmetbveto.append(mmtbveto)

## normalization  mT(btag/bveto)        
        eff = mmtb.Integral()/mmtbveto.Integral()

        ereff = sqrt(eff*(1-eff)/mmtbveto.Integral())
        print " pt bin ", ptbin, " btag/bveto  efficiency from MET   = ",eff, " error ",ereff
        effBvetoArray.append(eff)
        effErrBvetoArray.append(ereff)

## with MT distribution 
        if False:  
        ###  no MET cut 
            mmtb_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdBtagNoMetCut"+ptbin)])
            mmtb_tmp._setLegendStyles()
            mmtb_tmp._setLegendLabels()
            mmtb_tmp.histoMgr.setHistoDrawStyleAll("P") 
            mmtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
            mmtb = mmtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
            mmtb.Scale(normData[ptbin])
            #        hmt.append(mt)
            
            mmtbEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdBtagNoMetCut"+ptbin)])
            mmtbEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
            mmtbEWK_tmp._setLegendStyles()
            mmtbEWK_tmp._setLegendLabels()
            mmtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
            mmtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
            mmtbEWK = mmtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
            mmtbEWK.Scale(normEWK[ptbin])
            mmtb.Add(mmtbEWK, -1)
            
            hmtNoMetBtag.append(mmtb)

        
          ### MET with bvet
            mmtbveto_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdBvetoNoMetCut"+ptbin)])
            mmtbveto_tmp._setLegendStyles()
            mmtbveto_tmp._setLegendLabels()
            mmtbveto_tmp.histoMgr.setHistoDrawStyleAll("P") 
            mmtbveto_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
            mmtbveto = mmtbveto_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
            mmtbveto.Scale(normData[ptbin])
            #        hmt.append(mt)
            
            mmtbvetoEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdBvetoNoMetCut"+ptbin)])
            mmtbvetoEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
            mmtbvetoEWK_tmp._setLegendStyles()
            mmtbvetoEWK_tmp._setLegendLabels()
            mmtbvetoEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
            mmtbvetoEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
            mmtbvetoEWK = mmtbvetoEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
            mmtbvetoEWK.Scale(normEWK[ptbin])
            mmtbveto.Add(mmtbvetoEWK, -1)        
            hmtNoMetBveto.append(mmtbveto)
            
## normalization  mT(btag/bveto)        

            eff = mmtb.Integral()/mmtbveto.Integral()
            ereff = sqrt(eff*(1-eff)/mmtbveto.Integral())
            print " pt bin ", ptbin, " btag/bveto  efficiency from mt, no met cut  = ",eff, " error ",ereff
            effArrayMtNoMet.append(eff)
            effErrArrayMtNoMet.append(ereff)


        
#############################################
        ###  with MET cut 
        mmtb_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdBtag"+ptbin)])
        mmtb_tmp._setLegendStyles()
        mmtb_tmp._setLegendLabels()
        mmtb_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtb = mmtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmtb.Scale(normData[ptbin])
#        hmt.append(mt)

        mmtbEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdBtag"+ptbin)])
        mmtbEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mmtbEWK_tmp._setLegendStyles()
        mmtbEWK_tmp._setLegendLabels()
        mmtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbEWK = mmtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtbEWK.Scale(normEWK[ptbin])
        mmtb.Add(mmtbEWK, -1)
        hmtBtag.append(mmtb)

        mmtbveto_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("Inverted/MTInvertedTauIdBveto"+ptbin)])
        mmtbveto_tmp._setLegendStyles()
        mmtbveto_tmp._setLegendLabels()
        mmtbveto_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtbveto_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbveto = mmtbveto_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        mmtbveto.Scale(normData[ptbin])
#        hmt.append(mt)

        mmtbvetoEWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("Inverted/MTInvertedTauIdBveto"+ptbin)])
        mmtbvetoEWK_tmp.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity())
        mmtbvetoEWK_tmp._setLegendStyles()
        mmtbvetoEWK_tmp._setLegendLabels()
        mmtbvetoEWK_tmp.histoMgr.setHistoDrawStyleAll("P") 
        mmtbvetoEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtbvetoEWK = mmtbvetoEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        mmtbvetoEWK.Scale(normEWK[ptbin])
        mmtbveto.Add(mmtbvetoEWK, -1)        
        hmtBveto.append(mmtbveto)

## normalization  mT(btag/bveto)        
        eff = mmtb.Integral()/mmtbveto.Integral()

        ereff = sqrt(eff*(1-eff)/mmtbveto.Integral())
        print " pt bin ", ptbin, " btag/bveto  efficiency from mt  = ",eff, " error ",ereff
        effArrayMt.append(eff)
        effErrArrayMt.append(ereff)


        
## sum histo bins     


    met = hmet[0].Clone("met")
    met.SetName("MET")
    met.SetTitle("Inverted tau Met")
    met.Reset()
    print "check met",met.GetEntries()
    for histo in hmet:
        met.Add(histo)

    metb = hmetb[0].Clone("met")
    metb.SetName("MET")
    metb.SetTitle("Inverted tau Met")
    metb.Reset()
    print "check met btagging",metb.GetEntries()
    for histo in hmetb:
        metb.Add(histo)

    metbveto = hmetbveto[0].Clone("met")
    metbveto.SetName("METbveto")
    metbveto.SetTitle("Inverted tau Met")
    metbveto.Reset()
    print "check met bveto",metbveto.GetEntries()
    for histo in hmetbveto:
        metbveto.Add(histo)

## with MT

    if False:   
        mtNoMetBtag = hmtNoMetBtag[0].Clone("mt")
        mtNoMetBtag.SetName("MET")
        mtNoMetBtag.SetTitle("Inverted tau Met")
        mtNoMetBtag.Reset()
        print "check MT btagging",mtNoMetBtag.GetEntries()
        for histo in hmtNoMetBtag:
            mtNoMetBtag.Add(histo)
            
            
        mtNoMetBveto = hmtNoMetBveto[0].Clone("mt")
        mtNoMetBveto.SetName("MET")
        mtNoMetBveto.SetTitle("Inverted tau Met")
        mtNoMetBveto.Reset()
        print "check MT bveto",mtNoMetBveto.GetEntries()
        for histo in hmtNoMetBveto:
            mtNoMetBveto.Add(histo)


    mtBtag = hmtBtag[0].Clone("mt")
    mtBtag.SetName("MET")
    mtBtag.SetTitle("Inverted tau Met")
    mtBtag.Reset()
    print "check MT btagging",mtBtag.GetEntries()
    for histo in hmtBtag:
        mtBtag.Add(histo)

    
    mtBveto = hmtBveto[0].Clone("mt")
    mtBveto.SetName("MET")
    mtBveto.SetTitle("Inverted tau Met")
    mtBveto.Reset()
    print "check MT bveto",mtBveto.GetEntries()
    for histo in hmtBveto:
        mtBveto.Add(histo)

        
##########################################
        ## plotting
    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())
    
###  effisiency as a function of MET
    metWithBtagging = metb.Clone("MET")
    metWithBtagging.Divide(metbveto)
    BtaggingEffVsMet = metWithBtagging.Clone("Eff")
    invertedQCD.setLabel("BtagToBvetoEffVsMet")
    invertedQCD.mtComparison(BtaggingEffVsMet, BtaggingEffVsMet,"BtagToBvetoEffVsMet")


    if False:
   ###  effisiency as a function of MT
        mtWithBtagging = mtNoMetBtag.Clone("MT")
        mtWithBtagging.Divide(mtNoMetBveto)
        BtaggingEffNoMetVsMt = mtWithBtagging.Clone("Eff")
        invertedQCD.setLabel("BtagToBvetoEffNoMetVsMt")
        invertedQCD.mtComparison(BtaggingEffNoMetVsMt, BtaggingEffNoMetVsMt,"BtagToBvetoEffNoMetVsMt")


    ###  effisiency as a function of MT
    mtWithBtagging = mtBtag.Clone("MT")
    mtWithBtagging.Divide(mtBveto)
    BtaggingEffVsMt = mtWithBtagging.Clone("Eff")
    invertedQCD.setLabel("BtagToBvetoEffVsMt")
    invertedQCD.mtComparison(BtaggingEffVsMt, BtaggingEffVsMt,"BtagToBvetoEffVsMt")
    
 # efficiency metb/met
    metbtag = metb.Clone("metb")
    metnobtag = met.Clone("met")
    metbtag.Divide(metnobtag)
    invertedQCD.setLabel("BtagEffVsMet")
    invertedQCD.mtComparison(metbtag, metbtag,"BtagEffVsMet")

  # efficiency metb/metbveto
    metbtag = metb.Clone("metb")
    metbjetveto = metbveto.Clone("met")
    invertedQCD.setLabel("BtagToBvetoEfficiency")
    invertedQCD.mtComparison(metbtag, metbjetveto,"BtagToBvetoEfficiency")

### Create and customise TGraph
    cEff = TCanvas ("Efficiency", "Efficiency", 1)
    cEff.cd()
    ptbin_error = array.array("d",[5, 5, 5, 5, 10, 10 ,30])
    ptbin = array.array("d",[45, 55, 65, 75, 90, 110 ,150])



    if False:
## no MET cut 
        cEff = TCanvas ("btaggingEffNoMet", "btaggingEffNoMet", 1)
        cEff.cd()     
        graph = TGraphErrors(7, ptbin, array.array("d",effArrayMtNoMet),ptbin_error,array.array("d",effErrArrayMtNoMet))    
        graph.SetMaximum(0.25)
        graph.SetMinimum(0.0)
        graph.SetMarkerStyle(kFullCircle)
        graph.SetMarkerColor(kBlue)
        graph.SetMarkerSize(1)
        graph.GetYaxis().SetTitle("N_{b tagged}/N_{b veto}")
        graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
        graph.Draw("AP")
        tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              19.6 fb^{-1}             CMS preliminary")
        tex4.SetNDC()
        tex4.SetTextSize(20)
        tex4.Draw()
        tex1 = ROOT.TLatex(0.2,0.88,"All selection cuts")
        tex1.SetNDC()
        tex1.SetTextSize(22)
        #    tex1.Draw()
        tex2 = ROOT.TLatex(0.5,0.8,"No MET cut" )
        tex2.SetNDC()
        tex2.SetTextSize(24)
        tex2.Draw()

        cEff.Update()
        cEff.SaveAs("btagToBvetoEffNoMetVsPtTau_mt.png")



## with MET cut 
    cEff = TCanvas ("btaggingEff", "btaggingEff", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",effArrayMt),ptbin_error,array.array("d",effErrArrayMt))    

    graph.SetMaximum(0.25)
    graph.SetMinimum(0.0)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("N_{b tagged}/N_{b veto}")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")


    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              19.6 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2,0.88,"All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
#    tex1.Draw()
    tex2 = ROOT.TLatex(0.5,0.8,"After MET cut" )
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("btagToBvetoEffVsPtTau_mt.png")

## no MET cut 
    cEff = TCanvas ("btaggingEffNoMet", "btaggingEffNoMet", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",effBvetoArray),ptbin_error,array.array("d",effErrBvetoArray))    
    graph.SetMaximum(0.25)

    graph.SetMinimum(0.0)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("N_{b tagged}/N_{b veto}")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")

    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              19.6 fb^{-1}             CMS preliminary")


    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2,0.88,"All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
#    tex1.Draw()
    tex2 = ROOT.TLatex(0.5,0.8,"No MET cut" )
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()

    cEff.SaveAs("btagToBvetoEffNoMetVsPtTau.png")



## with MET cut 
    cEff = TCanvas ("btaggingEfficiency", "btaggingEfficiency", 1)
    cEff.cd()     
    graph = TGraphErrors(7, ptbin, array.array("d",effArray),ptbin_error,array.array("d",effErrArray))    
    graph.SetMaximum(0.25)
    graph.SetMinimum(0.0)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)

    graph.GetYaxis().SetTitle("b-tagging efficiency")

    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
### Re-draw graph and update canvas and gPad
    graph.Draw("AP")

    tex4 = ROOT.TLatex(0.2,0.955,"8 TeV              19.6 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()

    tex1 = ROOT.TLatex(0.4,0.85,"Inverted #tau identification")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.4,0.78,"At least 3 jets" )

    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("btaggingEffVsPtTau.png")


##################################3
    
    fOUT = open("btaggingFactors","w")

    #    now = datetime.datetime.now()
    
#    fOUT.write("# Generated on %s\n"%now.ctime())
    fOUT.write("# by %s\n"%os.path.basename(sys.argv[0]))
    fOUT.write("\n")
    fOUT.write("btaggingFactors = {\n")

    i = 0
    while i < len(effArray):
        line = "    \"" + ptbins[i] + "\": " + str(effArray[i])
        if i < len(effArray) - 1:
            line += ","
        line += "\n"
        fOUT.write(line)
        i = i + 1
        
    fOUT.write("}\n")
    fOUT.close()
    print "B-tagging efficiensies written in file","btaggingFactors"    

    

    
    
    fOUT = open("btaggingToBvetoFactors.py","w")

    #    now = datetime.datetime.now()
    
#    fOUT.write("# Generated on %s\n"%now.ctime())
    fOUT.write("# by %s\n"%os.path.basename(sys.argv[0]))
    fOUT.write("\n")
    fOUT.write("btaggingToBvetoFactors = {\n")

    i = 0
    while i < len(effBvetoArray):
        line = "    \"" + ptbins[i] + "\": " + str(effBvetoArray[i])
        if i < len(effBvetoArray) - 1:
            line += ","
        line += "\n"
        fOUT.write(line)
        i = i + 1
        
    fOUT.write("}\n")
    fOUT.close()
    print "BtaggingToBveto efficiensies written in file","btaggingToBvetoFactors"    


    
    fOUT = open("btaggingToBvetoAfterMetFactors.py","w")

    #    now = datetime.datetime.now()
    
#    fOUT.write("# Generated on %s\n"%now.ctime())
    fOUT.write("# by %s\n"%os.path.basename(sys.argv[0]))
    fOUT.write("\n")
    fOUT.write("btaggingToBvetoAfterMetFactors = {\n")

    i = 0
    while i < len(effArrayMt):
        line = "    \"" + ptbins[i] + "\": " + str(effArrayMt[i])
        if i < len(effArrayMt) - 1:
            line += ","
        line += "\n"
        fOUT.write(line)
        i = i + 1
        
    fOUT.write("}\n")
    fOUT.close()
    print "BtaggingToBvetoAfterMet efficiensies written in file","btaggingToBvetoFactors"    
コード例 #16
0
def invertedPurities(datasets):

    normData, normEWK, normFactorisedData, normFactorisedEWK = normalisation()
    norm_inc, normEWK_inc = normalisationInclusive()

    noDphi = []
    noDphiEWK = []
    Dphi160 = []
    DphiEWK160 = []
    DphiAll = []
    DphiEWKAll = []
    DphiAllremovett = []
    DphiEWKAllremovett = []
    DphiJet1 = []
    DphiEWKJet1 = []
    DphiJet2 = []
    DphiEWKJet2 = []
    hmt = []
    hmtb = []
    hmtv = []
    hmtPhiv = []
    hmet = []
    hmetQCD = []
    hmetEWK = []
    hjetmet = []
    hjetmetphi = []
    hMHTJet1phi = []
    hmtph = []
    hmtphj1 = []
    hmtphj2 = []
    hmtremovett = []
    DphiEWKAllbveto = []
    DphiAllbveto = []
    purityMet = []
    purityErrMet = []
    purityMtRemovett = []
    purityErrMtRemovett = []
    purityMtFirstDeltaPhiCut = []
    purityErrMtFirstDeltaPhiCut = []
    purityMtThirdDeltaPhiCut = []
    purityErrMtThirdDeltaPhiCut = []
    purityMtSecondDeltaPhiCut = []
    purityErrMtSecondDeltaPhiCut = []
    purityMtDeltaPhiCut = []
    purityErrMtDeltaPhiCut = []
    purityMtAfterBtagging = []
    purityErrMtAfterBtagging = []
    purityMTInvertedTauIdBvetoDphi = []
    purityErrMTInvertedTauIdBvetoDphi = []

    ## histograms in bins, normalisation and substraction of EWK contribution
    ## mt with 2dim deltaPhi cut
    for ptbin in ptbins:
        mt_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedSecondDeltaPhiCut" + ptbin)
        ])
        mt_tmp._setLegendStyles()
        mt_tmp._setLegendLabels()
        mt_tmp.histoMgr.setHistoDrawStyleAll("P")
        mt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mt = mt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        #        mt.Scale(normData[ptbin])
        DphiJet2.append(mt)

        mtEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedSecondDeltaPhiCut" + ptbin)
        ])
        mtEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtEWK_tmp._setLegendStyles()
        mtEWK_tmp._setLegendLabels()
        mtEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtEWK = mtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        #        mtEWK.Scale(normEWK[ptbin])
        #        mt.Add(mtEWK, -1)
        #        hmt.append(mt)
        DphiEWKJet2.append(mtEWK)

        purity = -999
        error = -999
        if mt.Integral() > 0:
            purity = (mt.Integral() - mtEWK.Integral()) / mt.Integral()
            error = sqrt(purity * (1 - purity) / mt.Integral())
            purityMtSecondDeltaPhiCut.append(purity)
            purityErrMtSecondDeltaPhiCut.append(error)
#        print " pt bin ", ptbin, " purity Mt Second Delta Phi Cut    = ",purity, " error ",error

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

# mt after b tagging
        mtb_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBtag" + ptbin)
        ])
        mtb_tmp._setLegendStyles()
        mtb_tmp._setLegendLabels()
        mtb_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtb_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtb = mtb_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        #        mtb.Scale(normData[ptbin])
        hmt.append(mtb)
        noDphi.append(mtb)

        mtbEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBtag" + ptbin)
        ])
        mtbEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtbEWK_tmp._setLegendStyles()
        mtbEWK_tmp._setLegendLabels()
        mtbEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtbEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtbEWK = mtbEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        #        mtbEWK.Scale(normEWK[ptbin])
        mtb.Add(mtbEWK, -1)
        hmtb.append(mtb)
        noDphiEWK.append(mtbEWK)

        purity = -999
        error = -999
        if mtb.Integral() > 0:
            purity = (mtb.Integral() - mtbEWK.Integral()) / mtb.Integral()
            error = sqrt(purity * (1 - purity) / mtb.Integral())
            purityMtAfterBtagging.append(purity)
            purityErrMtAfterBtagging.append(error)
#        print " pt bin ", ptbin, " purity Mt After Btagging    = ",purity, " error ",error

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

# mt after deltaPhi cut
        mtph_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdJetDphi" + ptbin)
        ])
        mtph_tmp._setLegendStyles()
        mtph_tmp._setLegendLabels()
        mtph_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtph_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtph = mtph_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        #        mtph.Scale(normData[ptbin])
        #        hmt.append(mt)
        Dphi160.append(mtph)
        mtphEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdJetDphi" + ptbin)
        ])
        mtphEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtphEWK_tmp._setLegendStyles()
        mtphEWK_tmp._setLegendLabels()
        mtphEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphEWK = mtphEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        #        mtphEWK.Scale(normEWK[ptbin])
        #        mtph.Add(mtphEWK, -1)
        #        hmtph.append(mtph)
        DphiEWK160.append(mtphEWK)
        purity = -999
        error = -999
        if mtph.Integral() > 0:
            purity = (mtph.Integral() - mtphEWK.Integral()) / mtph.Integral()
            error = sqrt(purity * (1 - purity) / mtph.Integral())
            purityMtDeltaPhiCut.append(purity)
            purityErrMtDeltaPhiCut.append(error)
#        print " pt bin ", ptbin, " purity Mt DeltaPhi Cut    = ",purity, " error ",error

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

# mt after deltaphi vs MHTjet1 cut
        mtphj1_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedFirstDeltaPhiCut" + ptbin)
        ])
        #mtphj1_tmp = plots.PlotBase([datasets.getDataset("Data").getDatasetRootHisto("MTInvertedTauIdMet"+ptbin)])
        mtphj1_tmp._setLegendStyles()
        mtphj1_tmp._setLegendLabels()
        mtphj1_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphj1_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj1 = mtphj1_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        #        mtphj1.Scale(normData[ptbin])
        DphiJet1.append(mtphj1)

        mtphj1EWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedFirstDeltaPhiCut" + ptbin)
        ])
        #mtphj1EWK_tmp = plots.PlotBase([datasets.getDataset("EWK").getDatasetRootHisto("MTInvertedTauIdMet"+ptbin)])
        mtphj1EWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtphj1EWK_tmp._setLegendStyles()
        mtphj1EWK_tmp._setLegendLabels()
        mtphj1EWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphj1EWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mtphj1EWK = mtphj1EWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        #        mtphj1EWK.Scale(normEWK[ptbin])
        #        mtphj1.Add(mtphj1EWK, -1)
        #        hmtphj1.append(mtphj1)
        DphiEWKJet1.append(mtphj1EWK)

        purity = -999
        error = -999
        if mtphj1.Integral() > 0:
            purity = (mtphj1.Integral() -
                      mtphj1EWK.Integral()) / mtphj1.Integral()
            error = sqrt(purity * (1 - purity) / mtphj1.Integral())
            purityMtFirstDeltaPhiCut.append(purity)
            purityErrMtFirstDeltaPhiCut.append(error)
#        print " pt bin ", ptbin, " purity Mt First Delta Phi Cut    = ",purity, " error ",error

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

# mt after all cuts
        mtphj2_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedThirdDeltaPhiCut" + ptbin)
        ])
        mtphj2_tmp._setLegendStyles()
        mtphj2_tmp._setLegendLabels()
        mtphj2_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphj2_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj2 = mtphj2_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        #        mtphj2.Scale(normData[ptbin])
        #        hmt.append(mt)
        DphiAll.append(mtphj2)
        mtphj2EWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedThirdDeltaPhiCut" + ptbin)
        ])
        mtphj2EWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtphj2EWK_tmp._setLegendStyles()
        mtphj2EWK_tmp._setLegendLabels()
        mtphj2EWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphj2EWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mtphj2EWK = mtphj2EWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        #        mtphj2EWK.Scale(normEWK[ptbin])
        #        mtphj2.Add(mtphj2EWK, -1)
        #        hmtphj2.append(mtphj2)
        DphiEWKAll.append(mtphj2EWK)

        purity = -999
        error = -999
        if mtphj2.Integral() > 0:
            purity = (mtphj2.Integral() -
                      mtphj2EWK.Integral()) / mtphj2.Integral()
            error = sqrt(purity * (1 - purity) / mtphj2.Integral())
            purityMtThirdDeltaPhiCut.append(purity)
            purityErrMtThirdDeltaPhiCut.append(error)
#       print " pt bin ", ptbin, " purity Mt Third Delta Phi Cut    = ",purity, " error ",error

#######################
# mt with cut against tt
        mtremovett_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedAgainstTTCut" + ptbin)
        ])
        mtremovett_tmp._setLegendStyles()
        mtremovett_tmp._setLegendLabels()
        mtremovett_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtremovett_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mtremovett = mtremovett_tmp.histoMgr.getHisto(
            "Data").getRootHisto().Clone()
        #        mtremovett.Scale(normData[ptbin])
        DphiAllremovett.append(mtremovett)

        mtremovettEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedAgainstTTCut" + ptbin)
        ])
        mtremovettEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtremovettEWK_tmp._setLegendStyles()
        mtremovettEWK_tmp._setLegendLabels()
        mtremovettEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtremovettEWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mtremovettEWK = mtremovettEWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        #        mtremovettEWK.Scale(normEWK[ptbin])
        #        mtremovett.Add(mtremovettEWK, -1)
        #        hmtremovett.append(mtremovett)
        DphiEWKAllremovett.append(mtremovettEWK)
        purity = -999
        error = -999
        if mtremovett.Integral() > 0:
            purity = (mtremovett.Integral() -
                      mtremovettEWK.Integral()) / mtremovett.Integral()
            error = sqrt(purity * (1 - purity) / mtremovett.Integral())
            purityMtRemovett.append(purity)
            purityErrMtRemovett.append(error)
            print "mtremovett.Integral() ", mtremovett.Integral(
            ), " mmtEWK.Integral() ", mtremovettEWK.Integral()

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

### MET
        mmt_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdJets" + ptbin)
        ])
        mmt_tmp._setLegendStyles()
        mmt_tmp._setLegendLabels()
        mmt_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmt_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmt = mmt_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        ##        mmt.Scale(normData[ptbin])
        hmet.append(mmt)

        mmtEWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MET_InvertedTauIdJets" + ptbin)
        ])
        mmtEWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mmtEWK_tmp._setLegendStyles()
        mmtEWK_tmp._setLegendLabels()
        mmtEWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mmtEWK_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mmtEWK = mmtEWK_tmp.histoMgr.getHisto("EWK").getRootHisto().Clone()
        ##        mmtEWK.Scale(normEWK[ptbin])
        mmt.Add(mmtEWK, -1)
        hmetQCD.append(mmt)
        hmetEWK.append(mmtEWK)

        purity = -999
        error = -999
        if mmt.Integral() > 0:
            purity = (mmt.Integral() - mmtEWK.Integral()) / mmt.Integral()
            error = sqrt(purity * (1 - purity) / mmt.Integral())
            purityMet.append(purity)
            purityErrMet.append(error)
##            print "mmt.Integral() ",mmt.Integral(), " mmtEWK.Integral() ",   mmtEWK.Integral()

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

# mt after all cuts
        mtphj2_tmp = plots.PlotBase([
            datasets.getDataset("Data").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBvetoDphi" + ptbin)
        ])
        mtphj2_tmp._setLegendStyles()
        mtphj2_tmp._setLegendLabels()
        mtphj2_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphj2_tmp.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
        mtphj2 = mtphj2_tmp.histoMgr.getHisto("Data").getRootHisto().Clone()
        #        mtphj2.Scale(normData[ptbin])
        #        hmt.append(mt)
        DphiAllbveto.append(mtphj2)
        mtphj2EWK_tmp = plots.PlotBase([
            datasets.getDataset("EWK").getDatasetRootHisto(
                "Inverted/MTInvertedTauIdBvetoDphi" + ptbin)
        ])
        mtphj2EWK_tmp.histoMgr.normalizeMCToLuminosity(
            datasets.getDataset("Data").getLuminosity())
        mtphj2EWK_tmp._setLegendStyles()
        mtphj2EWK_tmp._setLegendLabels()
        mtphj2EWK_tmp.histoMgr.setHistoDrawStyleAll("P")
        mtphj2EWK_tmp.histoMgr.forEachHisto(
            lambda h: h.getRootHisto().Rebin(20))
        mtphj2EWK = mtphj2EWK_tmp.histoMgr.getHisto(
            "EWK").getRootHisto().Clone()
        #        mtphj2EWK.Scale(normEWK[ptbin])
        #        mtphj2.Add(mtphj2EWK, -1)
        #        hmtphj2.append(mtphj2)
        DphiEWKAllbveto.append(mtphj2EWK)

        purity = -999
        error = -999
        if mtphj2.Integral() > 0:
            purity = (mtphj2.Integral() -
                      mtphj2EWK.Integral()) / mtphj2.Integral()
            error = sqrt(purity * (1 - purity) / mtphj2.Integral())
            purityMTInvertedTauIdBvetoDphi.append(purity)
            purityErrMTInvertedTauIdBvetoDphi.append(error)
#       print " pt bin ", ptbin, " purity Mt Third Delta Phi Cut    = ",purity, " error ",error

    print " "
    print " purity met   = ", purityMet, " error ", purityErrMet
    print " purity Mt no DeltaPhi Cuts    = ", purityMtAfterBtagging, " error ", purityErrMtAfterBtagging
    print " purity Mt DeltaPhi160 Cut    = ", purityMtDeltaPhiCut, " error ", purityErrMtDeltaPhiCut
    print " purity Mt First DeltaPhi Cut    = ", purityMtFirstDeltaPhiCut, " error ", purityErrMtFirstDeltaPhiCut
    print " purity Mt Second DeltaPhi Cut    = ", purityMtSecondDeltaPhiCut, " error ", purityErrMtSecondDeltaPhiCut
    print " purity Mt Third Delta Phi Cut    = ", purityMtThirdDeltaPhiCut, " error ", purityErrMtThirdDeltaPhiCut
    print " purity Mt b veto deltaPhi Cuts    = ", purityMTInvertedTauIdBvetoDphi, " error ", purityErrMTInvertedTauIdBvetoDphi
    print " purity Mt Remove tt    = ", purityMtRemovett, " error ", purityErrMtRemovett

    invertedQCD = InvertedTauID()
    invertedQCD.setLumi(datasets.getDataset("Data").getLuminosity())

    ### Met
    met = hmet[0].Clone("met")
    met.SetName("MET")
    met.SetTitle("Inverted tau Met")
    met.Reset()
    for histo in hmet:
        met.Add(histo)

    metQCD = hmetQCD[0].Clone("met")
    metQCD.SetName("MET")
    metQCD.SetTitle("Inverted tau Met")
    metQCD.Reset()
    for histo in hmetQCD:
        metQCD.Add(histo)

    metEWK = hmetEWK[0].Clone("metewk")
    metEWK.SetName("METewk")
    metEWK.SetTitle("Inverted tau Met")
    metEWK.Reset()
    for histo in hmetEWK:
        metEWK.Add(histo)

### Mt no DeltaPhi Cuts
    mtNoDphi = noDphi[0].Clone("mt")
    mtNoDphi.SetName("mt")
    mtNoDphi.SetTitle("Inverted tau Mt")
    mtNoDphi.Reset()
    for histo in noDphi:
        mtNoDphi.Add(histo)

    mtNoDphiEWK = noDphiEWK[0].Clone("mtewk")
    mtNoDphiEWK.SetName("MTewk")
    mtNoDphiEWK.SetTitle("Inverted tau Met")
    mtNoDphiEWK.Reset()
    for histo in noDphiEWK:
        mtNoDphiEWK.Add(histo)

### Mt DeltaPhi < 160 Cut
    mtDphi160 = Dphi160[0].Clone("mt")
    mtDphi160.SetName("mt")
    mtDphi160.SetTitle("Inverted tau Mt")
    mtDphi160.Reset()
    for histo in Dphi160:
        mtDphi160.Add(histo)

    mtDphi160EWK = DphiEWK160[0].Clone("mtewk")
    mtDphi160EWK.SetName("MTewk")
    mtDphi160EWK.SetTitle("Inverted tau Met")
    mtDphi160EWK.Reset()
    for histo in DphiEWK160:
        mtDphi160EWK.Add(histo)

### Mt Mt all dphi cuts
    mtDphiAll = DphiAll[0].Clone("mt")
    mtDphiAll.SetName("mt")
    mtDphiAll.SetTitle("Inverted tau Mt")
    mtDphiAll.Reset()
    for histo in DphiAll:
        mtDphiAll.Add(histo)

    mtDphiAllEWK = DphiEWKAll[0].Clone("mtewk")
    mtDphiAllEWK.SetName("MTewk")
    mtDphiAllEWK.SetTitle("Inverted tau Met")
    mtDphiAllEWK.Reset()
    for histo in DphiEWKAll:
        mtDphiAllEWK.Add(histo)

### Mt bveto all dphi cuts
    mtDphiAllbveto = DphiAllbveto[0].Clone("mt")
    mtDphiAllbveto.SetName("mt")
    mtDphiAllbveto.SetTitle("Inverted tau Mt")
    mtDphiAllbveto.Reset()
    for histo in DphiAllbveto:
        mtDphiAllbveto.Add(histo)

    mtDphiAllEWKbveto = DphiEWKAllbveto[0].Clone("mtewk")
    mtDphiAllEWKbveto.SetName("MTewk")
    mtDphiAllEWKbveto.SetTitle("Inverted tau Met")
    mtDphiAllEWKbveto.Reset()
    for histo in DphiEWKAllbveto:
        mtDphiAllEWKbveto.Add(histo)

### Mt Mt dphi jet1
    mtDphiJet1 = DphiJet1[0].Clone("mt")
    mtDphiJet1.SetName("mt")
    mtDphiJet1.SetTitle("Inverted tau Mt")
    mtDphiJet1.Reset()
    for histo in DphiJet1:
        mtDphiJet1.Add(histo)

    mtDphiEWKJet1 = DphiEWKJet1[0].Clone("mtewk")
    mtDphiEWKJet1.SetName("MTewk")
    mtDphiEWKJet1.SetTitle("Inverted tau Met")
    mtDphiEWKJet1.Reset()
    for histo in DphiEWKJet1:
        mtDphiEWKJet1.Add(histo)

### Mt Mt dphi jet2
    mtDphiJet2 = DphiJet2[0].Clone("mt")
    mtDphiJet2.SetName("mt")
    mtDphiJet2.SetTitle("Inverted tau Mt")
    mtDphiJet2.Reset()
    for histo in DphiJet2:
        mtDphiJet2.Add(histo)

    mtDphiEWKJet2 = DphiEWKJet2[0].Clone("mtewk")
    mtDphiEWKJet2.SetName("MTewk")
    mtDphiEWKJet2.SetTitle("Inverted tau Met")
    mtDphiEWKJet2.Reset()
    for histo in DphiEWKJet2:
        mtDphiEWKJet2.Add(histo)

### Mt  all dphi + tt cuts
    mtDphiAllremovett = DphiAllremovett[0].Clone("mt")
    mtDphiAllremovett.SetName("mt")
    mtDphiAllremovett.SetTitle("Inverted tau Mt")
    mtDphiAllremovett.Reset()
    for histo in DphiAllremovett:
        mtDphiAllremovett.Add(histo)

    mtDphiAllremovettEWK = DphiEWKAllremovett[0].Clone("mtewk")
    mtDphiAllremovettEWK.SetName("MTewk")
    mtDphiAllremovettEWK.SetTitle("Inverted tau Met")
    mtDphiAllremovettEWK.Reset()
    for histo in DphiEWKAllremovett:
        mtDphiAllremovettEWK.Add(histo)


##########################################
#  met purity

    metqcd = metQCD.Clone("metqcd")
    metinv = met.Clone("met")
    invertedQCD.setLabel("MetPurity")
    #    invertedQCD.mtComparison(metqcd, metqcd,"MetPurity")

    ##########################################
    # mt purity no deltaPhi
    mtQCD = mtNoDphi.Clone("QCD")
    mtQCD.Add(mtNoDphiEWK, -1)
    mtQCD.Divide(mtNoDphi)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtNoDeltaPhiCuts")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtNoDeltaPhiCuts")
    ##########################################
    # mt purity deltaPhi 160
    mtQCD = mtDphi160.Clone("QCD")
    mtQCD.Add(mtDphi160EWK, -1)
    mtQCD.Divide(mtDphi160)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhi160")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtDeltaPhi160")
    ##########################################
    # mt purity all deltaPhi cuts
    mtQCD = mtDphiAll.Clone("QCD")
    mtQCD.Add(mtDphiAllEWK, -1)
    mtQCD.Divide(mtDphiAll)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtAllDeltaPhiCuts")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtAllDeltaPhiCuts")

    ##########################################
    # mt bveto purity all deltaPhi cuts
    ## test
    invertedQCD.setLabel("testMtbveto")
    #    invertedQCD.mtComparison(mtDphiAllbveto, mtDphiAllbveto,"testMtbveto")
    invertedQCD.setLabel("testEWKMtbveto")
    #    invertedQCD.mtComparison(mtDphiAllEWKbveto, mtDphiAllEWKbveto,"testEWKMtbveto")

    mtQCD = mtDphiAllbveto.Clone("QCD")
    mtQCD.Add(mtDphiAllEWKbveto, -1)
    mtQCD.Divide(mtDphiAllbveto)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtbvetoAllDeltaPhiCuts")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtbvetoAllDeltaPhiCuts")
    ##########################################
    # mt purity jet1 deltaPhi cuts
    mtQCD = mtDphiJet1.Clone("QCD")
    mtQCD.Add(mtDphiEWKJet1, -1)
    mtQCD.Divide(mtDphiJet1)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhiJet1Cuts")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtDeltaPhiJet1Cuts")
    ##########################################
    # mt purity jet2 deltaPhi cuts
    mtQCD = mtDphiJet2.Clone("QCD")
    mtQCD.Add(mtDphiEWKJet2, -1)
    mtQCD.Divide(mtDphiJet2)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhiJet2Cuts")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtDeltaPhiJet2Cuts")
    ##########################################
    # mt purity all deltaPhi cuts and against tt cut
    mtQCD = mtDphiAllremovett.Clone("QCD")
    mtQCD.Add(mtDphiAllremovettEWK, -1)
    mtQCD.Divide(mtDphiAllremovett)
    mtqcd = mtQCD.Clone("mtqcd")
    invertedQCD.setLabel("MtDeltaPhiAndAgainsttt")
    invertedQCD.mtComparison(mtQCD, mtQCD, "MtDeltaPhiAndAgainsttt")

    #################################################
    ##  purities as a function of pt tau jet

    ### Create and customise TGraph
    cEff = TCanvas("MetPurity", "MetPurity", 1)
    cEff.cd()
    ptbin_error = array.array("d", [5, 5, 5, 5, 10, 10, 30])
    ptbin = array.array("d", [45, 55, 65, 75, 90, 110, 150])

    graph = TGraphErrors(7, ptbin,
                         array.array("d", purityMTInvertedTauIdBvetoDphi),
                         ptbin_error,
                         array.array("d", purityErrMTInvertedTauIdBvetoDphi))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.6)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV/c]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.35, 0.35, "B-tagging factorisation")
    tex1.SetNDC()
    tex1.SetTextSize(25)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.35, 0.27, "#Delta#phi cuts")
    tex2.SetNDC()
    tex2.SetTextSize(25)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMTInvertedTauIdBvetoDphiBins.png")

    graph = TGraphErrors(7, ptbin, array.array("d", purityMet), ptbin_error,
                         array.array("d", purityErrMet))
    graph.SetMaximum(1.1)
    graph.SetMinimum(0.8)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV/c]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.35, 0.35, "Inverted #tau jet isolation")
    tex1.SetNDC()
    tex1.SetTextSize(20)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.35, 0.3, "at least 3 jets")
    tex2.SetNDC()
    tex2.SetTextSize(25)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMetPtBins.png")

    ## Mt without deltaPhi cuts
    cEff = TCanvas("MtNoDeltaPhiCutsPurity", "MtNoDeltaPhiCutsPurity", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin,
                         array.array("d", purityMtAfterBtagging), ptbin_error,
                         array.array("d", purityErrMtAfterBtagging))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.5, 0.38, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.5, 0.3, "no #Delta#phi cuts")
    tex2.SetNDC()
    tex2.SetTextSize(25)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtNoDeltaPhiCutsBins.png")

    ## Mt without deltaPhi cuts
    cEff = TCanvas("MtDeltaPhi160Purity", "MtDeltaPhi160Purity", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", purityMtDeltaPhiCut),
                         ptbin_error, array.array("d", purityErrMtDeltaPhiCut))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.5, 0.35, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(24)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.5, 0.25, "#Delta#phi(#tau jet,MET) < 160^{o}")
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtDeltaPhi160Bins.png")

    ## Mt 1st deltaPhi cut
    cEff = TCanvas("MtFirstDeltaCutPurity", "MtFirstDeltaPhiCutPurity", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", purityMtFirstDeltaPhiCut),
                         ptbin_error,
                         array.array("d", purityErrMtFirstDeltaPhiCut))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.4, 0.4, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(24)
    tex1.Draw()
    tex2 = ROOT.TLatex(0.3, 0.3,
                       "#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1,MET) cut")
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtFirstDeltaPhiCutBins.png")

    ## Mt 2nd deltaPhi cut
    cEff = TCanvas("MtSecondDeltaCutPurity", "MtFirstSecondPhiCutPurity", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", purityMtSecondDeltaPhiCut),
                         ptbin_error,
                         array.array("d", purityErrMtSecondDeltaPhiCut))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2, 0.88, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(
        0.2, 0.8, "#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1/2,MET) cuts")
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtSecondDeltaPhiCutBins.png")

    ## Mt 2nd deltaPhi cut
    cEff = TCanvas("MtThirdDeltaCutPurity", "MtThirdDeltaPhiCutPurity", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", purityMtThirdDeltaPhiCut),
                         ptbin_error,
                         array.array("d", purityErrMtThirdDeltaPhiCut))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2, 0.88, "All selection cuts")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(
        0.2, 0.8, "#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1/2/3,MET) cuts")
    tex2.SetNDC()
    tex2.SetTextSize(24)
    tex2.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtThirdDeltaPhiCutBins.png")

    ## Mt deltaPhi cuts and against tt
    cEff = TCanvas("MtMtRemovettPurity", "MtMtRemovettPurity", 1)
    cEff.cd()
    graph = TGraphErrors(7, ptbin, array.array("d", purityMtRemovett),
                         ptbin_error, array.array("d", purityErrMtRemovett))
    graph.SetMaximum(1.0)
    graph.SetMinimum(0.4)
    graph.SetMarkerStyle(kFullCircle)
    graph.SetMarkerColor(kBlue)
    graph.SetMarkerSize(1)
    graph.GetYaxis().SetTitle("QCD purity")
    graph.GetXaxis().SetTitle("p_{T}^{#tau jet} [GeV]")
    ### Re-draw graph and update canvas and gPad
    graph.Draw("AP")
    tex4 = ROOT.TLatex(
        0.2, 0.955,
        "8 TeV              12.2 fb^{-1}             CMS preliminary")
    tex4.SetNDC()
    tex4.SetTextSize(20)
    tex4.Draw()
    tex1 = ROOT.TLatex(0.2, 0.88, "All selection cuts ")
    tex1.SetNDC()
    tex1.SetTextSize(22)
    tex1.Draw()
    tex2 = ROOT.TLatex(
        0.2, 0.8, "#Delta#phi(#tau jet,MET) vs #Delta#phi(jet1/2/3,MET) cuts")
    tex2.SetNDC()
    tex2.SetTextSize(22)
    tex2.Draw()
    tex3 = ROOT.TLatex(0.2, 0.72, "#Delta#phi cut against tt+jets")
    tex3.SetNDC()
    tex3.SetTextSize(22)
    tex3.Draw()

    cEff.Update()
    cEff.SaveAs("purityMtAgainstttCutBins.png")
コード例 #17
0
def main():
    # Create all datasets from a multicrab task
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)

    # Read integrated luminosities of data datasets from lumi.json
    datasets.loadLuminosities()

    # Include only 120 mass bin of HW and HH datasets
    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))

    # Default merging nad ordering of data and MC datasets
    # All data datasets to "Data"
    # All QCD datasets to "QCD"
    # All single top datasets to "SingleTop"
    # WW, WZ, ZZ to "Diboson"
    plots.mergeRenameReorderForDataMC(datasets)

    # Set BR(t->H) to 0.05, keep BR(H->tau) in 1
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Merge WH and HH datasets to one (for each mass bin)
    # TTToHplusBWB_MXXX and TTToHplusBHminusB_MXXX to "TTToHplus_MXXX"
    plots.mergeWHandHH(datasets)

    ttjets2 = datasets.getDataset("TTJets").deepCopy()
    ttjets2.setCrossSection(ttjets2.getCrossSection()-datasets.getDataset("TTToHplus_M120").getCrossSection())
    print "Set TTJets2 cross section to %f" % ttjets2.getCrossSection()
    ttjets2.setName("TTJets2")
    datasets.append(ttjets2)

    datasets.merge("EWKnott", [
            "WJets",
            "DYJetsToLL",
            "SingleTop",
            "Diboson"
            ])
    tmp = datasets.getDataset("EWKnott").deepCopy()
    tmp.setName("EWKnott2")
    datasets.append(tmp)

    datasets.merge("EWK", [
        "EWKnott",
        "TTJets"
        ])
    datasets.merge("EWKS", [
        "EWKnott2",
        "TTJets2",
        "TTToHplus_M120",
        ])


    # Apply TDR style
    style = tdrstyle.TDRStyle()

    invertedQCD = InvertedTauID()

    metBase = plots.DataMCPlot(datasets, analysis+"/MET_BaseLineTauIdJets")
    metInver = plots.DataMCPlot(datasets, analysis+"/MET_InvertedTauIdJets")  
    # Rebin before subtracting
    metBase.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    metInver.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    
    metInverted_data = metInver.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets")
    metInverted_EWK = metInver.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_InvertedTauIdJets") 
    metBase_data = metBase.histoMgr.getHisto("Data").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")
    metBase_EWK = metBase.histoMgr.getHisto("EWK").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")
    metBase_EWKS = metBase.histoMgr.getHisto("EWKS").getRootHisto().Clone(analysis+"/MET_BaselineTauIdJets")

    metBase_QCD = metBase_data.Clone("QCD")
    metBase_QCD.Add(metBase_EWK,-1)

    metBase_EWK.SetTitle("MC EWK")
    metBase_EWKS.SetTitle("MC EWK + Signal")
    invertedQCD.setLabel("EWK_vs_SEWK")
    invertedQCD.comparison(metBase_EWK,metBase_EWKS,0)

    invertedQCD.setLabel("EWK_vs_SEWK_Normalized")
    invertedQCD.comparison(metBase_EWK,metBase_EWKS,1)   


    invertedQCD.setLabel("InvData")
    invertedQCD.fitQCD(metInverted_data)

    invertedQCD.setLabel("EWK")
    invertedQCD.fitEWK(metBase_EWK)  
    invertedQCD.fitData(metBase_data)
    normalizationWithEWK = invertedQCD.getNormalization()

    invertedQCD.setLabel("EWKS")
    invertedQCD.fitEWK(metBase_EWKS)
    invertedQCD.fitData(metBase_data)
    normalizationWithEWKS = invertedQCD.getNormalization()
    
    print "Difference Signal vs no signal in EWK fit",(normalizationWithEWKS - normalizationWithEWK)/normalizationWithEWK