コード例 #1
0
#Select and load root files here
#f_ggHTT = TFile.Open('/data/vshang/l1CaloJets_20190806_r2/output_round2_HiggsTauTau_testv2.root', '')
#f_QCD = TFile.Open('/data/vshang/l1CaloJets_20190806_r2/output_round2_QCD_testv2.root', '')
print 'Loading root files...'
f_ggHTT = TFile.Open(
    '/afs/hep.wisc.edu/home/vshang/public/Phase2L1CaloTaus/CMSSW_10_5_0_pre1/src/L1Trigger/L1EGRateStudies/test/crab/l1CaloJets_20190909_r2/output_round2_HiggsTauTau_withTracks_notTrackMatched.root',
    '')
f_QCD = TFile.Open(
    '/afs/hep.wisc.edu/home/vshang/public/Phase2L1CaloTaus/CMSSW_10_5_0_pre1/src/L1Trigger/L1EGRateStudies/test/crab/l1CaloJets_20190909_r2/output_round2_QCDv1.root',
    '')

#Set date and save directory
date = '20191107'
saveDir = '/afs/hep.wisc.edu/home/vshang/public/Phase2L1CaloTaus/CMSSW_10_5_0_pre1/src/L1Trigger/L1EGRateStudies/test/towerStudies/' + date + '/'
checkDir(saveDir)

#Set sameCanvas to True for all plots on same Canvas, False if you want seperate plots
sameCanvas = True

#Set number of histogram bins and maximum value of y axis here
nBins = 20
yMax = 0.4

#Remove stats box from histograms by setting argument to 0
gStyle.SetOptStat(0)

#Get event trees
print 'Getting event trees...'
ggHTT_eventTree = f_ggHTT.Get('analyzer/tree')
QCD_eventTree = f_QCD.Get('analyzer/tree')
コード例 #2
0
        return [hists.GetFunction('f1_'+append).GetParameter(0), hists.GetFunction('f1_'+append).GetParameter(1), \
            hists.GetXaxis().GetBinLowEdge(1), hists.GetXaxis().GetBinUpEdge( hists.GetNbinsX() )]


def to_add(hists):
    h1 = hists.pop(0).Clone()
    h1.SetDirectory(0)
    for h in hists:
        h1.Add(h)
    return h1


if '__main__' in __name__:
    date = '20190306v2'
    saveDir = '/afs/cern.ch/user/t/truggles/www/Phase-II/puTest_' + date + 'v1/'
    trigHelpers.checkDir(saveDir)
    base = '/data/truggles/l1Towers_' + date + '/'
    c = ROOT.TCanvas('c', 'c', 800, 800)
    names = [
        #'minBias_PU0.root',
        'minBias_PU200.root',
        #'ttbar_PU0.root',
        #'ttbar_PU200.root',
        #'qcd_PU0.root',
        'qcd_PU200.root'
    ]
    scan = [0, 10]
    hist_max = 10
    var_map = {
        'total_hits_et': ([0, 50], 50),
        #'total_et_sum' : ([0, 3000], -1),
コード例 #3
0
def make_PU_SFs(c, base, name, calo):
    eta_map = get_n_towers_map(calo)

    # Output function file
    f_out = ROOT.TFile('PU_SF_%s_functions.root' % calo, 'RECREATE')
    trigHelpers.checkDir(saveDir + 'SFs/')

    # Return map
    fits_map = OrderedDict()

    h_max = 270
    n_bins = 27
    bin_width = h_max / n_bins
    half_bw = (h_max / n_bins) / 2

    f200 = ROOT.TFile(base + name, 'r')
    #f140 = ROOT.TFile( base+name.replace('200','140'), 'r' )
    #FIXME f0 = ROOT.TFile( base+name.replace('200','0'), 'r' )
    h = ROOT.TH2F(calo + ' SF hist',
                  calo + ' SF hist;Eta Bin;Gen Nvtx;E_{T} To Subtract (GeV)',
                  len(eta_map.keys()), 0, len(eta_map.keys()), 27, 0, h_max)
    t200 = f200.Get('analyzer/hit_tree')
    #t140 = f140.Get( 'analyzer/hit_tree' )
    #FIXME t0 = f0.Get( 'analyzer/hit_tree' )
    iEta_index = 0
    for iEta in eta_map.keys():
        h1 = ROOT.TH1F('SF_hist_%s' % iEta, 'SF_hist;nvtx', 27, 0, h_max)
        x_vals = array('f', [])
        y_vals = array('f', [])
        for nvtx in range(0, h_max + 1, bin_width):
            nvtx_low = nvtx
            nvtx_high = nvtx + 10
            cut = '(nvtx_init >= %i && nvtx_init < %i)' % (nvtx_low, nvtx_high)
            h_ET_sum = ROOT.TH1F('et_sum', 'et_sum', 1000, 0, 10000)
            # Use PU0 sample for lowest nvtx bin
            #FIXME No PU 0 10_3_X MTD samples, only use PU200
            #FIXME if nvtx == 0 :
            #FIXME     t0.Draw( 'f_%s_hits_%s >> et_sum' % (calo, iEta), cut )
            #FIXME #elif nvtx >= 90 and nvtx < 160 :
            #FIXME #    t140.Draw( 'f_%s_hits_%s >> et_sum' % (calo, iEta), cut )
            #FIXME else :
            #FIXME    t200.Draw( 'f_%s_hits_%s >> et_sum' % (calo, iEta), cut )
            if nvtx >= 150:
                t200.Draw('f_%s_hits_%s >> et_sum' % (calo, iEta), cut)

            #FIXME remove this
            if nvtx_low == 0:
                #for eta_bin in range( len(eta_map.keys())+1 ) :
                #    h.SetBinContent( eta_bin, 1, 1e-5 )
                h_ET_sum.SetBinContent(1, 1e-5)

            if h_ET_sum.Integral() > 0.:
                # Total energy / nTowers = Energy per Tower to subtract
                energy_per_tower = h_ET_sum.GetMean() / eta_map[iEta]

                # Default to a tiny bit above zero for plotting purposes in TH2 which does zero suppress
                if nvtx_low == 0 and energy_per_tower == 0.0:
                    energy_per_tower = 1e-5

                print iEta_index, nvtx + half_bw, energy_per_tower
                h.Fill(iEta_index, nvtx + half_bw, energy_per_tower)
                x_vals.append(nvtx + half_bw)
                y_vals.append(energy_per_tower)
                h1.SetBinContent(h1.FindBin(nvtx + half_bw), energy_per_tower)
                #h1.SetBinError( h1.FindBin( nvtx+half_bw), 1./math.sqrt(h_ET_sum.Integral()) )

            del h_ET_sum
        h.GetXaxis().SetBinLabel(iEta_index + 1, iEta)
        iEta_index += 1
        f = ROOT.TF1('%s_%s' % (calo, iEta), '[0] + [1] * x',
                     h1.GetXaxis().GetBinLowEdge(1),
                     h1.GetXaxis().GetBinUpEdge(h1.GetNbinsX()))
        h1.Fit(f)
        #f2 = ROOT.TF1('%s_%s' % (calo, iEta),'[0] + [1] * x', h1.GetXaxis().GetBinLowEdge(2), h1.GetXaxis().GetBinUpEdge( h1.GetNbinsX() ) )
        #h1.Fit( f2, "R" )
        h1.SetLineWidth(2)
        f.SetLineWidth(2)
        #f2.SetLineWidth( 2 )
        #f2.SetLineColor( ROOT.kBlue )
        g1 = ROOT.TGraph(len(x_vals), x_vals, y_vals)
        g1.SetTitle('ET_sum_graph_%s_%s' % (calo, iEta))
        g1.SetName('ET_sum_graph_%s_%s' % (calo, iEta))
        g1.SetLineColor(ROOT.kBlack)
        g1.SetLineWidth(2)
        g1.GetYaxis().SetTitle('MinBias E_{T} Sum (GeV)')
        g1.GetXaxis().SetTitle('Number of Simulated Vertices')
        g1.Draw()
        f.Draw('l same')
        fits_map[iEta] = [f.GetParameter(0), f.GetParameter(1)]
        #f2.Draw('l same')
        f_out.cd()
        f.Write()
        g1.Write()
        #f2.Write()
        c.SaveAs(saveDir + 'SFs/SFs_%s_%s.png' % (calo, iEta))
        del h1, f
    f_out.Close()
    h.SetMinimum(h.GetMinimum())
    h.GetZaxis().SetRangeUser(0., h.GetMaximum())
    h.Draw('colz')
    ROOT.gPad.SetRightMargin(.15)
    c.SaveAs(saveDir + 'SFs/SFs_%s.png' % calo)
    return fits_map
コード例 #4
0
    p2Obj = 'calibPtHH'
    #p2Obj = 'tau_pt'
    #s2Obj = 'stage2tau_pt'
    s2Obj = 'stage2tau_pt_calibration3'
    s2ObjEta = 'stage2tau_eta'

text = 'Jet' if not doTau else 'Tau'

if doEff:
    #fName = 'output_round2_HiggsTauTau_withTracks_trackMatchedwithTrackdR'
    fName = 'output_round2_HiggsTauTau_withTracks_passJEFThreshold'
    #fName = 'output_round2_QCDv1'
    date = '20200128'
    base = '/afs/hep.wisc.edu/home/vshang/public/Phase2L1CaloTaus/CMSSW_10_5_0_pre1/src/L1Trigger/L1EGRateStudies/test/crab/l1CaloJets_20190909_r2/'
    universalSaveDir = "/afs/hep.wisc.edu/home/vshang/public/Phase2L1CaloTaus/CMSSW_10_5_0_pre1/src/L1Trigger/L1EGRateStudies/test/efficiencies/" + date + "/" + fName + "/"
    checkDir(universalSaveDir)

    f = ROOT.TFile(base + fName + '.root', 'r')
    t = f.Get('analyzer/tree')

    # Threshold cuts for passing region
    #pt_cut = 100
    #pt_cut = 40
    #pt_cut = 20
    pt_cut = 32
    #pt_cut = 80
    #pt_cut = 150
    #pt_cut = 200
    #pt_cut = 400
    #pt_cut = 100
    #pt_cut = 0