Exemplo n.º 1
0
        for pf_type in pf_types:

            name = pf_type['name']+'_'+eta_bin['name']
            particles_eta_bin_pf_type = filter( pf_type['sel'], particles_eta_bin )
            setattr( maker.event, name+'_sumPt',  sum( [p.pt() for p in particles_eta_bin_pf_type], 0.))
            setattr( maker.event, name+'_mult',   len( particles_eta_bin_pf_type ) )

            MEx = sum( [ -p.pt()*cos(p.phi()) for p in particles_eta_bin_pf_type], 0.)
            MEy = sum( [ -p.pt()*sin(p.phi()) for p in particles_eta_bin_pf_type], 0.)

            setattr( maker.event, name+'_met',     sqrt(MEx**2 + MEy**2 ) )
            setattr( maker.event, name+'_metPhi',  atan2( MEy, MEx ) )
                
    # minimumDR of good muons to high pt charged candidates
    highPt_ch      = filter( lambda p: p.pt()>5 and abs(p.pdgId()) == 211, pf )
    maker.event.minDRGoodMuCh  = sqrt( min( [ deltaR2( toDict(ch), toDict(mu) ) for mu in good_muons for ch in highPt_ch ] + [99**2]) )
    maker.event.maxPtChCloseToMu = 0
    for mu in good_muons:
        chCloseToMu = filter( lambda p: deltaR2( toDict(p), toDict( mu ) )< 0.01**2, highPt_ch )
        ptChCloseToMu = sum( [ p.pt() for p in chCloseToMu ], 0. )
        print mu, ptChCloseToMu
        if ptChCloseToMu>maker.event.maxPtChCloseToMu:
            maker.event.maxPtChCloseToMu = ptChCloseToMu

    #if maker.event.minDRGoodMuCh<0.01: assert False, ""

    # get PF Mu's
    pf_mu          = filter( lambda p: p.pt()>15 and abs(p.pdgId()) == 13, pf )
    # match with the good_muons from slimmed mu
    good_to_pf_mu = {}
    if len( pf_mu )>=2:
Exemplo n.º 2
0
    jets1_ = [j for j in r1.products['jets']]  #if helpers.jetID( j )]
    jets2_ = [j for j in r2.products['jets']]  #if helpers.jetID( j )]
    jets1 = [{
        'pt': j.pt(),
        'eta': j.eta(),
        'phi': j.phi(),
        'j': j
    } for j in jets1_]
    jets2 = [{
        'pt': j.pt(),
        'eta': j.eta(),
        'phi': j.phi(),
        'j': j
    } for j in jets2_]
    for c in zip(jets1, jets2):
        if helpers.deltaR2(*c) < 0.2**2:

            r = c[0]['pt'] / c[1]['pt']

            ref_jet = c[0] if plan1RefJet else c[1]

            if ref_jet['eta'] > 1.1 and ref_jet['eta'] < 3.2:
                if ref_jet['phi'] > -1.07 and ref_jet['phi'] < -0.32:
                    NHEF_HEP17.Fill(c[0]['j'].neutralHadronEnergyFraction())
                else:
                    NHEF_nonHEP17.Fill(c[0]['j'].neutralHadronEnergyFraction())

            if ref_jet['eta'] > 1.1 and ref_jet['eta'] < 3.2 and ref_jet[
                    'phi'] > -1.07 and ref_jet['phi'] < -0.32:
                resp_pt.Fill(ref_jet['pt'], r)
            else:
Exemplo n.º 3
0
# Without sorting, there is a jump between files with almost every event -> extremly slow
positions.sort()
logger.info("Have %i events in common.", len(intersec))

#Looping over common events
for i, p in enumerate(positions):
    p1,p2 = p
    r1.goToPosition(p1)
    r2.goToPosition(p2)
    if i%10000==0: logger.info("At %i/%i of common events.", i, len(positions))
    jets1_ = [ j for j in r1.products['jets'] ] #if helpers.jetID( j )]
    jets2_ = [ j for j in r2.products['jets'] ] #if helpers.jetID( j )]
    jets1 = [{'pt':j.pt(), 'eta':j.eta(), 'phi':j.phi(), 'j':j } for j in jets1_]
    jets2 = [{'pt':j.pt(), 'eta':j.eta(), 'phi':j.phi(), 'j':j } for j in jets2_]
    for c in zip(jets1, jets2):
        if helpers.deltaR2(*c)<0.2**2:

            r = c[0]['pt']/c[1]['pt']

            if c[0]['eta']>1.1 and c[0]['eta']<3.2 and c[0]['phi']>-1.07 and c[0]['phi']<-0.32:
                resp_pt.Fill( c[0]['pt'], r )
            else:
                resp_pt_ref.Fill( c[0]['pt'], r )

            if not c[0]['pt']>pt_threshold: continue
            #if not ( helpers.jetID(c[0]['j']) and helpers.jetID(c[1]['j']) ): continue

            #if not c[1]['nHEF']>0.1: continue
            #r = c[0]['nHEF']/c[1]['nHEF']

            # 2D eta, phi
Exemplo n.º 4
0
    while r.run( ):
        if max_events is not None and max_events>0 and count>=max_events:break
        if sample.isData and ( not lumiList.contains(r.evt[0], r.evt[1])) : continue
            
        electrons = [ e for e in r.products['electrons'] if e.energy()>50 ]
        photons   = [ p for p in r.products['photons'] if p.energy()>100 ]
        for e in electrons:

            if abs(e.eta())<1.3 : continue
            if not e.electronID("cutBasedElectronID-Spring15-25ns-V1-standalone-tight"): continue 

            e_sc = {'eta':e.superCluster().eta(), 'phi':e.superCluster().phi()}

            for p in photons:
                p_sc = {'eta':p.superCluster().eta(), 'phi':p.superCluster().phi()}
                if helpers.deltaR2(e_sc, p_sc) == 0.:
                    gOverE[sample.name].Fill( p.pt(), p.pt()/e.pt() )
                    gOverE_2D[sample.name].Fill( p.pt(), p.pt()/e.pt() )

        count += 1

# Make plot
#profiles = [jetResponse_M2_0_100, jetResponse_M2_5_500, jetResponse_M2_0_500, jetResponse_M2_5_100, jetResponse_M0, jetResponse_M21p, jetResponse_M23p]
profiles = [ gOverE[sample.name] for sample in samples ]
prefix   = preprefix+"max_events_%s_"%max_events if max_events is not None and max_events>0 else preprefix
histos = [ [h.ProjectionX()] for h in profiles ]
for i, h in enumerate(histos):
    h[0].__dict__.update(profiles[i].__dict__)
#    h[0].Divide(jetResponse_M2_0_100.ProjectionX())

jetResponsePlot = Plot.fromHisto(name = prefix+"gOverE", histos = histos, texX = "photon p_{T}", texY = "p_{T}(#gamma)/p_{T}(e)" )
Exemplo n.º 5
0
    # Fast intersect
    intersec = set(position_r1.keys()).intersection(set(position_r2.keys()))
    positions = [(position_r1[i], position_r2[i]) for i in intersec]
    positions.sort()
    logger.info("Have %i events in common.", len(intersec))

    #Loop over pairs
    for nEvent, pos in enumerate(positions):
        if nEvent%10000==0: 
            logger.info("At event %i/%i", nEvent, len(intersec))

        p1, p2 = pos
        r1.goToPosition(p1)
        r2.goToPosition(p2)

        n = min([r1.data.nJet, r2.data.nJet])
        jets1 = [{'rawPt':r1.data.Jet_rawPt[i], 'eta':r1.data.Jet_eta[i], 'phi':r1.data.Jet_phi[i]} for i in xrange(n) if abs(r1.data.Jet_eta[i])<1.3]
        jets2 = [{'rawPt':r2.data.Jet_rawPt[i], 'eta':r2.data.Jet_eta[i], 'phi':r2.data.Jet_phi[i]} for i in xrange(n) if abs(r2.data.Jet_eta[i])<1.3]

        if r1.data.evt == 642018L and r1.data.run==260431 and r1.data.lumi==1:
            break

        for c in zip(jets1, jets2):
            if deltaR2(*c)<0.2**2:
                jetResponse.Fill(c[1]['rawPt'],c[1]['rawPt']/c[0]['rawPt'])

## Make plot
#prefix="test3"
#jetResponsePlot = Plot.fromHisto(name = prefix+"jetResponse_eta13", histos = [[jetResponse_mc], [jetResponse_data]], texX = "raw Jet p_{T}", texY = "response ratio M2(0,100)/M2(5,500)" )
#plotting.draw(jetResponsePlot, plot_directory = "/afs/hephy.at/user/r/rschoefbeck/www/etc/", ratio = {'yRange':(0.985,1.025)}, logX = True, logY = False, sorting = False, yRange = (0.965, 1.045) )
Exemplo n.º 6
0
 def match(j1, j2):
     return deltaR2(j1,j2)<0.2**2 
Exemplo n.º 7
0
            MEx = sum(
                [-p.pt() * cos(p.phi()) for p in particles_eta_bin_pf_type],
                0.)
            MEy = sum(
                [-p.pt() * sin(p.phi()) for p in particles_eta_bin_pf_type],
                0.)

            setattr(maker.event, name + '_met', sqrt(MEx**2 + MEy**2))
            setattr(maker.event, name + '_metPhi', atan2(MEy, MEx))

    # minimumDR of good muons to high pt charged candidates
    highPt_ch = filter(lambda p: p.pt() > 5 and abs(p.pdgId()) == 211, pf)
    maker.event.minDRGoodMuCh = sqrt(
        min([
            deltaR2(toDict(ch), toDict(mu)) for mu in good_muons
            for ch in highPt_ch
        ] + [99**2]))
    maker.event.maxPtChCloseToMu = 0
    for mu in good_muons:
        chCloseToMu = filter(
            lambda p: deltaR2(toDict(p), toDict(mu)) < 0.01**2, highPt_ch)
        ptChCloseToMu = sum([p.pt() for p in chCloseToMu], 0.)
        print mu, ptChCloseToMu
        if ptChCloseToMu > maker.event.maxPtChCloseToMu:
            maker.event.maxPtChCloseToMu = ptChCloseToMu

    #if maker.event.minDRGoodMuCh<0.01: assert False, ""

    # get PF Mu's
    pf_mu = filter(lambda p: p.pt() > 15 and abs(p.pdgId()) == 13, pf)
Exemplo n.º 8
0
    while r.run( ):
        if max_events is not None and max_events>0 and count>=max_events:break
        if sample.isData and ( not lumiList.contains(r.evt[0], r.evt[1])) : continue
            
        electrons = [ e for e in r.products['electrons'] if e.energy()>50 ]
        photons   = [ p for p in r.products['photons'] if p.energy()>100 ]
        for e in electrons:

            if abs(e.eta())<1.3 : continue
            if not e.electronID("cutBasedElectronID-Spring15-25ns-V1-standalone-tight"): continue 

            e_sc = {'eta':e.superCluster().eta(), 'phi':e.superCluster().phi()}

            for p in photons:
                p_sc = {'eta':p.superCluster().eta(), 'phi':p.superCluster().phi()}
                if helpers.deltaR2(e_sc, p_sc) == 0.:
                    gOverE[sample.name].Fill( p.pt(), p.pt()/e.pt() )
                    gOverE_2D[sample.name].Fill( p.pt(), p.pt()/e.pt() )

        count += 1

# Make plot
#profiles = [jetResponse_M2_0_100, jetResponse_M2_5_500, jetResponse_M2_0_500, jetResponse_M2_5_100, jetResponse_M0, jetResponse_M21p, jetResponse_M23p]
profiles = [ gOverE[sample.name] for sample in samples ]
prefix   = preprefix+"max_events_%s_"%max_events if max_events is not None and max_events>0 else preprefix
histos = [ [h.ProjectionX()] for h in profiles ]
for i, h in enumerate(histos):
    h[0].__dict__.update(profiles[i].__dict__)
#    h[0].Divide(jetResponse_M2_0_100.ProjectionX())

jetResponsePlot = Plot.fromHisto(name = prefix+"gOverE", histos = histos, texX = "photon p_{T}", texY = "p_{T}(#gamma)/p_{T}(e)" )
Exemplo n.º 9
0
 def match(j1, j2):
     return deltaR2(j1, j2) < 0.2**2
Exemplo n.º 10
0
    'genInfo':   {'type':' GenEventInfoProduct', 'label': "generator"},
    'rho':       {'type':'double', 'label':"fixedGridRhoFastjetAll"},
    }

r1 = sample.fwliteReader( products = products )
r1.start()
i=0
while r1.run():
    #pt_hat = r1.products['genInfo'].binningValues()[0]
    #if i%10000==0: logger.info("At %i", i)
    #if not (pt_hat > pt_hat_min and pt_hat <pt_hat_max): continue
        
    id_jets = [ j.correctedJet("Uncorrected") for j in r1.products['jets'] if helpers.jetID( j )]
    for j in id_jets:
        gj = j.genJet()
        if gj and helpers.deltaR2({'eta':gj.eta(), 'phi':gj.phi()}, {'eta':j.eta(), 'phi':j.phi()}) < 0.2**2:

            jet_corr_factor =  jetCorrector_mc.correction( j.pt(), j.eta(), j.jetArea(), r1.products['rho'][0], 1 ) 

            for eta_th in reversed(eta_thresholds):
                if abs(gj.eta())>eta_th:
                    resp[eta_th].Fill( gj.pt(), j.pt()*jet_corr_factor / gj.pt() )
                    #print eta_th, gj.eta(), j.pt(), gj.pt()
                    break

    i+=1
    if i>max_events: break

        
# Make plot
profiles = [resp[t] for t in eta_thresholds]