def folding(): ax4.cla() #print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] #try: #if cursor.end < cursor.start:raise ValueError peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] label.period = period print 'candidate period: ', period #binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) peak = {} binvalue, binerr = fold(ix, smoothedy, period, yerr=ie, bins=nbin, peak=peak) ax4.step(np.arange(0, 1, 1. / nbin) + 0.5 / nbin, binvalue, color='b') ax4.errorbar(np.arange(0, 1, 1. / nbin), binvalue, yerr=binerr, fmt='.', color='b') folding_results.append( [kic, bper, peak['offset'], (list(binvalue), list(binerr))])
def folding(): ax3.cla() print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] print peak, period binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) ax3.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') ax3.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b')
def folding(): ax4.cla() #foldedcurve[0].remove() #print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] print 'candidate period: ', period #binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) binvalue,binerr = fold(ix, smoothedy, period, yerr=ie, bins=nbin) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') ax4.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b')
def folding(): ax3.cla() print cursor.end, cursor.start, len(ydata), ydata[cursor.end:cursor.start] peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] print peak, period binvalue, binerr = fold(ix, iy, period, yerr=ie, bins=nbin) ax3.step(np.arange(0, 1, 1. / nbin) + 0.5 / nbin, binvalue, color='b') ax3.errorbar(np.arange(0, 1, 1. / nbin), binvalue, yerr=binerr, fmt='.', color='b')
def recoHW_a1(bjets,jets0,lepton,MET): """ Reconstruction of HWW, requiring at least two b-tags. The two leading bjets are taken out the jets, and the next leading jets with DeltaPhi(jet,lepton)<1.8 DeltaPhi(bjet,bjet)<1.8 are used to form HWW. """ jets = jets0[:] jets.remove(bjets[0]) jets.remove(bjets[1]) jets = [ jet for jet in jets if fold(abs(lepton.Phi-jet.Phi)) < 1.8 ] if len(jets)<2 or fold(abs(bjets[0].Phi-bjets[1].Phi)) > 2.2: # TODO: extend for cases with more than 2 bjets return [ ] #if abs(lepton.Eta-jets[0].Eta)>1 and abs(lepton.Eta-jets[1].Eta)>1: #return [ ] # 1) Make TLorentzVectors. p_l = TLorentzVector() p_l.SetPtEtaPhiM(lepton.PT, lepton.Eta, lepton.Phi, lepton.Mass) p_bjets = [ TLorentzVector(), TLorentzVector() ] p_bjets[0].SetPtEtaPhiM(bjets[0].PT, bjets[0].Eta, bjets[0].Phi, bjets[0].Mass) p_bjets[1].SetPtEtaPhiM(bjets[1].PT, bjets[1].Eta, bjets[1].Phi, bjets[1].Mass) p_jets = [ TLorentzVector(), TLorentzVector() ] p_jets[0].SetPtEtaPhiM(jets[0].PT, jets[0].Eta, jets[0].Phi, jets[0].Mass) p_jets[1].SetPtEtaPhiM(jets[1].PT, jets[1].Eta, jets[1].Phi, jets[1].Mass) # 2) Make Hbb and Wjj LorentzVector. q_Hbb = p_bjets[0] + p_bjets[1] q_Wjj = p_jets[0] + p_jets[1] # # 3) TODO: Find Wlnu via boost to HWW restframe. # beta = q.BoostVector() # q_Wjj.Boost(beta) return [ q_Hbb, q_Wjj ]
def folding(): ax4.cla() #print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] #try: #if cursor.end < cursor.start:raise ValueError peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] label.period = period print 'candidate period: ', period #binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) peak = {} binvalue,binerr = fold(ix, smoothedy, period, yerr=ie, bins=nbin, peak=peak) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') ax4.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') folding_results.append([kic, bper, peak['offset'], (list(binvalue), list(binerr))])
def max_b2b(vectors): """ 1) Loop over all vector-vector combinations from vectors 2) Boost back to rest frame of sum 3) Return combination with DeltaPhi closest to pi: back-to-back """ p_12_b2b = None DeltaPhi_b2b = 0 # > pi for p1,p2 in combinations(vectors,2): p_12 = p1 + p2 q1 = copy(p1) q2 = copy(p2) q1.Boost(-beta) q2.Boost(-beta) beta = p_12.BoostVector() DeltaPhi = fold(abs(q1.Phi()-q2.Phi())) if DeltaPhi > DeltaPhi_b2b: p_12_b2b = copy(p_12) DeltaPhi_b2b = DeltaPhi return p_12_b2b
def processdata(files): ix,iy,ie = readfs(files) ax1.errorbar(ix, iy, yerr=ie, color='b', alpha=0.5) smoothedy = fftsmooth(iy) ax2.plot(ix[:len(smoothedy)], smoothedy, color='r') ix = ix[:len(smoothedy)] T = ix.max() - ix.min() nf = min(10000, ix.size * 2) minperiod, maxperiod = 0.5, T-1 #min([100., T-1]) fmin, df = 1./maxperiod, (1./minperiod - 1./maxperiod)/nf freqs = np.arange(fmin, fmin+df*nf, df)[:nf] p, bper, bpow, depth, qtran, in1, in2 = bls(ix, smoothedy, nf=nf, fmin=fmin, df=df) a = 1./freqs b = p coeff = np.polyfit(a,b,3) polys = np.poly1d(coeff) ys = polys(a) ax3.plot(a, np.exp(p-ys)) #ax3.plot(a, ys, 'r-') ax3.set_xscale('log') ax3.set_xlim([minperiod, maxperiod]) ax3.axvline(x=bper, color='r', linewidth=1) nbin = 100 binvalue,binerr = fold(ix, smoothedy, bper, yerr=ie, bins=nbin) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') foldedcurve = ax4.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') show() return binvalue
def process(self, event): result = { } jets = event.cleanedJets20[:] # remove closest b-jets pair down below alljets = [ j for j in event.jets if j.PT > 20 and abs(j.Eta) < 2.5 ] bjets = event.bjets30[:] result["Njets20"] = len(event.cleanedJets20) result["Njets30"] = len(event.cleanedJets30) result["Nbjets30"] = len(event.bjets30) if len(jets) > 3 and len(event.leadingLeptons) == 1 and event.met[0].MET > 20: result["Nbjets30_cut_PUPPI"] = len(event.bjets30) result["Nbjets30_cut_all"] = len([ j for j in alljets if j.BTag and j.PT > 30 ]) NPU = event.npu[0] # result["NVerticesNJets"] = [[ NPU.HT, len(alljets) ]] # result["NVerticesNPUPPIJets"] = [[ NPU.HT, len(jets) ]] lepton = None p_neutrino = None MET = event.met[0] if len(event.leadingLeptons): lepton = event.leadingLeptons[0] p_neutrino = recoNeutrino(lepton.TLV,MET) # bjet - bjet bl = [ ] p_bl = None if lepton and bjets: bl = sorted( bjets, key=lambda j: TLV.DeltaR(j.TLV,lepton.TLV), reverse=True ) # farthest->closest DeltaPhi = fold(abs(lepton.Phi - bl[0].Phi)) DeltaEta = abs(lepton.Eta - bl[0].Eta) p_bl = lepton.TLV+bl[-1].TLV result["M_bl"] = p_bl.M() # closest b-jet with lepton result["Pt_bl"] = p_bl.Pt() result["DeltaR_b1l"] = TLV.DeltaR(lepton.TLV,bl[0].TLV) result["DeltaPhi_b1l"] = DeltaPhi result["DeltaEtaDeltaPhi_b1l"] = [[ DeltaEta, DeltaPhi ]] if len(bl)>1: DeltaPhi = fold(abs(lepton.Phi - bl[1].Phi)) DeltaEta = abs(lepton.Eta - bl[1].Eta) result["M_bb_farthest"] = (bl[0].TLV+bl[1].TLV).M() result["DeltaR_b2l"] = TLV.DeltaR(lepton.TLV,bl[1].TLV) result["DeltaPhi_b2l"] = DeltaPhi result["DeltaEtaDeltaPhi_b2l"] = [[ DeltaEta, DeltaPhi ]] # bjet comb DeltaR_bb_closest = 1000 # >> pi bjet_closest = [ ] p_bb1 = None for j1, j2 in combinations(bjets,2): p_bb = j1.TLV + j2.TLV DeltaR = TLV.DeltaR(j1.TLV, j2.TLV) if DeltaR < DeltaR_bb_closest: bjet_closest = [j1,j2] p_bb1 = p_bb result["M_bb_closest"] = p_bb.M() result["Pt_bb"] = p_bb.Pt() result["DeltaR_bb1"] = TLV.DeltaR(j1.TLV,j2.TLV) result["DeltaPhi_bb1"] = fold(abs(j1.Phi - j2.Phi)) result["DeltaEtaDeltaPhi_bb1"] = [[ abs(j1.Eta - j2.Eta), result["DeltaPhi_bb1"] ]] DeltaR_bb_closest = DeltaR if len(bjets)>1: result["M_bb_leading"] = (bjets[0].TLV+bjets[1].TLV).M() # leading non-b-jets for bjet in bjet_closest: # remove closest bjet pair from jet list jets.remove(bjet) if len(jets)>0: result["jet1Pt"] = jets[0].PT if len(jets)>1: result["jet2Pt"] = jets[1].PT # leading bjets if len(bjets)>1: result["bjet1Pt"] = bjet_closest[0].PT result["bjet2Pt"] = bjet_closest[1].PT elif len(bjets): result["bjet1Pt"] = bjets[0].PT # jet comb if len(jets)>1: # 120 GeV upper mass limit # jets120 = [ js for js in combinations(jets[:4],2) if (js[0].TLV+js[1].TLV).M() < 120 ] # if len(jets120): # jets = max( jets120, key = lambda js: (js[0].TLV+js[1].TLV).Pt()) p_jj = jets[0].TLV + jets[1].TLV result["M_jj"] = p_jj.M() result["DeltaR_jj"] = TLV.DeltaR(jets[0].TLV, jets[1].TLV) result["DeltaPhi_jj"] = fold(abs(jets[0].Phi - jets[1].Phi)) result["DeltaEtaDeltaPhi_jj"] = [[ abs(jets[0].Eta - jets[1].Eta), result["DeltaPhi_jj"] ]] result["M_jj_NPU"] = [[ p_jj.M(), NPU.HT ]] # jjl if lepton: p_jjl = p_jj + lepton.TLV result["M_jjl"] = p_jjl.M() result["Pt_jjl"] = p_jjl.Pt() result["M_jjlnu"] = (p_jj + lepton.TLV + p_neutrino).M() result["DeltaR_jjl"] = TLV.DeltaR(p_jj,lepton.TLV) result["DeltaPhi_jjl"] = fold(abs(p_jj.Phi()-lepton.Phi)) result["DeltaEtaDeltaPhi_jjl"] = [[ abs(p_jj.Eta() - lepton.Eta), result["DeltaPhi_jjl"] ]] result["DeltaPhi_jjlnu"] = fold(abs(p_jjl.Phi()-MET.Phi)) result["MT_jjlnu"] = sqrt(2 * MET.MET * p_jjl.Pt() * (1-cos( p_jjl.Phi() - MET.Phi)) ) if len(bl)>1: p_blnu = bl[-2].TLV + lepton.TLV + p_neutrino p_b2lnu = bl[-1].TLV + lepton.TLV + p_neutrino result["M_b1lnu"] = p_blnu.M() result["M_b2lnu"] = p_b2lnu.M() # take bjet closest result["M_blnu_2D"] = [[ result["M_b1lnu"], result["M_b2lnu"] ]] result["Pt_b1lnu"] = p_blnu.Pt() result["Pt_b2lnu"] = p_b2lnu.Pt() if len(event.cleanedJets20)>3: # take bjet second closest to lepton jets_tt = event.cleanedJets20[:] jets_tt.remove(bl[-1]) jets_tt.remove(bl[-2]) # 120 GeV upper mass limit # jets120 = [ js for js in combinations(jets_tt[:4],2) if (js[0].TLV+js[1].TLV).M() < 120 ] # if len(jets120): # jets_tt = max( jets120, key = lambda js: (js[0].TLV+js[1].TLV).Pt()) p_jj = jets_tt[0].TLV + jets_tt[1].TLV p_jjb = p_jj + bl[-2].TLV p_jjb2 = p_jj + bl[-1].TLV result["M_jjl"] = p_jjl.M() result["M_jjb1"] = p_jjb.M() result["M_jjb2"] = p_jjb2.M() result["M_jjb_2D"] = [[ result["M_jjb1"], result["M_jjb2"] ]] result["Pt_jjb1"] = p_jjb.Pt() result["Pt_jjb2"] = p_jjb2.Pt() result["DeltaR_jjb"] = TLV.DeltaR(p_jj,bl[-2].TLV) result["DeltaPhi_jjb"] = fold(abs(p_jj.Phi()-bl[-2].Phi)) result["DeltaEtaDeltaPhi_jjb"] = [[ abs(p_jj.Eta() - bl[-2].Eta), result["DeltaPhi_jjb"] ]] result["DeltaR_jjlbb"] = TLV.DeltaR(p_jjl,p_bb1) result["DeltaPhi_jjlbb"] = fold(abs(p_jjl.Phi()-p_bb1.Phi())) result["DeltaEtaDeltaPhi_jjlbb"] = [[ abs(p_jjl.Eta() - p_bb1.Eta()), result["DeltaPhi_jjlbb"] ]] result["DeltaR_jjbbl"] = TLV.DeltaR(p_jjb,p_bl) result["DeltaPhi_jjbbl"] = fold(abs(p_jjb.Phi()-p_bl.Phi())) result["DeltaEtaDeltaPhi_jjbbl"] = [[ abs(p_jjb.Eta() - p_bl.Eta()), result["DeltaPhi_jjbbl"] ]] if lepton: # MET - lepton result["leptonPt"] = lepton.PT result["MET"] = MET.MET result["DeltaPhi_lMET"] = abs(MET.Phi-lepton.Phi) result["MT_lnu"] = recoWlnu2Mt(lepton,MET) # jet i - lepton ji = sorted(jets, key=lambda j: TLV.DeltaR(j.TLV,lepton.TLV))[:3] # closest jets if len(ji)>0 and p_bb1: p_j1l = lepton.TLV+ji[0].TLV result["M_j1l"] = p_j1l.M() result["Pt_j1l"] = p_j1l.Pt() result["DeltaR_j1l"] = TLV.DeltaR(lepton.TLV,ji[0].TLV) result["DeltaPhi_j1l"] = fold(abs(lepton.Phi - ji[0].Phi)) result["DeltaEtaDeltaPhi_j1l"] = [[ abs(lepton.Eta - ji[0].Eta), result["DeltaPhi_j1l"] ]] result["DeltaR_j1lbb"] = TLV.DeltaR(p_j1l,p_bb1) result["DeltaPhi_j1lbb"] = fold(abs(p_j1l.Phi()-p_bb1.Phi())) result["DeltaEtaDeltaPhi_j1lbb"] = [[ abs(p_j1l.Eta() - p_bb1.Eta()), result["DeltaPhi_j1lbb"] ]] if len(ji)>1: # result["M_j2l"] = (lepton.TLV+ji[1].TLV).M() result["DeltaR_j2l"] = TLV.DeltaR(lepton.TLV,ji[1].TLV) result["DeltaPhi_j2l"] = fold(abs(lepton.Phi - ji[1].Phi)) result["DeltaEtaDeltaPhi_j2l"] = [[ abs(lepton.Eta - ji[1].Eta), result["DeltaPhi_j2l"] ]] if len(ji)>2: result["DeltaEtaDeltaPhi_j3l"] = [[ abs(lepton.Eta - ji[2].Eta), fold(abs(lepton.Phi - ji[2].Phi)) ]] # respect the order of branches when adding variables # result["cleanup"] = [ result[var] for var in result if var in tree_vars ] result["cleanup"] = [ ] for var in tree_vars: if var in result: result["cleanup"].append(result[var]) else: # if one variable does not exist for this event, no tree del result["cleanup"] break return result
ax2 = subplot(312) ax3 = subplot(313) ax1.errorbar(ix, iy, yerr=ie, color='b', alpha=0.5) #ax2.errorbar(1./freq[1:len(trans)-1], trans[1:-1], yerr=etrans[1:-1]) ax2.plot(1./freq[1:len(trans)-1], trans[1:-1]) xdata = copy.deepcopy(1./freq[1:len(trans)-1]) ydata = copy.deepcopy(trans[1:-1]) cursor = Cursor(ax2, xdata, ydata) connect('motion_notify_event', cursor.mouse_move) connect('button_press_event', cursor.click) peak = np.argmax(trans[1:len(trans)-1]) period = xdata[peak] print peak, period nbin = 300 binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) ax3.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') ax3.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') def folding(): ax3.cla() print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] print peak, period binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) ax3.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') ax3.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') cursor.link_exe(folding)
def process(self, event): result = { } result["WlnuM"] = [ ] result["WqqM"] = [ ] result["qEta"] = [ ] result["MatchLJets_20"] = [ ] result["MatchLJets_40"] = [ ] result["MatchBJets_20"] = [ ] result["MatchBJets_40"] = [ ] higgs = [ ] leptons = [ ] neutrinos = [ ] quarks = [ ] bquarks = [ ] bquark_had = None bquark_lep = None for particle in event.particles: PID = abs(particle.PID) D1 = particle.D1 D2 = particle.D2 # __top__ if PID == 6 and 0 <= D1 < len(event.particles) and event.particles[D1] and D1!=D2: higgs.append(particle) if abs(event.particles[D2].PID) == 5: # b bquarks.append(event.particles[D2]) elif abs(event.particles[D1].PID) == 5: # b print "Warning in GenControlPlots: b is D1!" bquarks.append(event.particles[D1]) if abs(event.particles[D1].PID) == 24: # look for daughter particle D1 = event.particles[D1].D1 if abs(event.particles[D1].PID) in [11,13,15]: bquark_lep = event.particles[D2] # bquark with leptonic W higgs[-1].ljets = False elif abs(event.particles[D1].PID) in [1,2,3,4,5]: bquark_had = event.particles[D2] # bquark with hadronic W higgs[-1].ljets = True else: print "ERROR: abs(event.particles[D1].PID) not in [1,2,3,4,5,11,13,15]" # looking = True # while looking: # D1 = event.particles[D1].D1 # if abs(event.particles[D1].PID) in [11,13,15]: # bquark_lep = event.particles[D2] # bquark with leptonic W # looking = False # higgs[-1].ljets = False # elif abs(event.particles[D1].PID) in [1,2,3,4,5]: # bquark_had = event.particles[D2] # bquark with hadronic W # looking = False # higgs[-1].ljets = True # __W__ elif PID == 24 and 0 <= D1 < len(event.particles) and event.particles[D1] and D1!=D2: # W PID_D1 = abs( event.particles[D1].PID ) PID_D2 = abs( event.particles[D2].PID ) if PID_D1 in [11,13,15]: # e, mu, tau leptons.append(event.particles[D1]) neutrinos.append(event.particles[D2]) result["WlnuM"].append( particle.Mass ) elif PID_D1 in [1,2,3,4,5]: # d, u, s, c, b quarks.extend([event.particles[D1],event.particles[D2]]) result["WqqM"].append( particle.Mass ) elif PID_D1 in [12,14,16]: print "Warning: in GenControlPlots: PID_D1 of W is a neutrino!" # __Higgs__ elif PID == 25 and 0 <= D1 < len(event.particles) and event.particles[D1] and D1!=D2: # Higgs PID_D1 = abs( event.particles[D1].PID ) higgs.append(particle) if PID_D1 == 5: # b bquarks.extend([ event.particles[D1], event.particles[D2] ]) higgs[-1].ljets = False else: higgs[-1].ljets = True p_q = [ ] if len(quarks) == 2: for q in quarks: result["qEta"].append(q.Eta) p_q.append(TLV()) p_q[-1].SetPtEtaPhiM(q.PT, q.Eta, q.Phi, q.Mass) result["QuarkEta"] = [[ quarks[0].Eta, quarks[1].Eta ]] if len(event.bjets30[:])>1 and len(event.cleanedJets20[:])>3: jets = event.cleanedJets20[:] # remove closest b-jets pair down below bjets = event.bjets30[:] for bjet in min( combinations(bjets,2), key=lambda bj: TLV.DeltaR(bj[0].TLV,bj[1].TLV) ) : # remove closest bjet pair from jet list if bjet in jets: jets.remove(bjet) result["Match_Jet1_q"] = 0 result["Match_Jet2_q"] = 0 for p in p_q: if TLV.DeltaR(p,jets[0].TLV) < 0.4: result["Match_Jet1_q"] += 1 if TLV.DeltaR(p,jets[1].TLV) < 0.4: result["Match_Jet2_q"] += 1 result["Match_Jets_q"] = [[ result["Match_Jet1_q"], result["Match_Jet2_q"] ]] else: return { } # make code faster by ignoring uninteresting events p_b = [ ] if len(bquarks) == 2: for b in bquarks: p_b.append(TLV()) p_b[-1].SetPtEtaPhiM(b.PT, b.Eta, b.Phi, b.Mass) else: return { } # make code faster by ignoring uninteresting events if len(leptons) == 1 and len(neutrinos) == 1: lepton = leptons[0] neutrino = neutrinos[0] p_l = TLV() p_nu = TLV() p_l.SetPtEtaPhiM(lepton.PT, lepton.Eta, lepton.Phi, lepton.Mass) p_nu.SetPtEtaPhiM(neutrino.PT, neutrino.Eta, neutrino.Phi, neutrino.Mass) # result["Pt_l"] = lepton.PT # result["Pt_nu"] = neutrino.PT result["MET_res"] = abs(event.met[0].MET-neutrino.PT)/neutrino.PT result["MET_res_ang"] = fold(abs( event.met[0].Phi-neutrino.Phi )) result["MT_lnu_gen"] = sqrt(2 * neutrino.PT * lepton.PT * (1-cos( lepton.Phi - neutrino.Phi)) ) if len(higgs)==2: # higgs or top higgs[0].P = sqrt(higgs[0].PT*higgs[0].PT + higgs[0].Pz*higgs[0].Pz) higgs[1].P = sqrt(higgs[1].PT*higgs[1].PT + higgs[1].Pz*higgs[1].Pz) higgs = sorted(higgs, key = lambda h: h.P,reverse=True) [ result["H1P"], result["H2P"] ] = [ higgs[0].P , higgs[1].P ] [ result["H1Pt"], result["H2Pt"] ] = [ higgs[0].PT , higgs[1].PT ] [ result["H1Pz"], result["H2Pz"] ] = [ higgs[0].Pz , higgs[1].Pz ] result["H1PH2P"] = [[ result["H1P"], result["H2P"] ]] result["H1PtH2Pt"] = [[ result["H1Pt"], result["H2Pt"] ]] result["H1PzH2Pz"] = [[ result["H1Pz"], result["H2Pz"] ]] if p_q and p_b: [p_q1,p_q2] = sorted(p_q, key = lambda p: TLV.DeltaR(p,p_l))[:2] [p_b1,p_b2] = sorted(p_b, key = lambda p: TLV.DeltaR(p,p_l), reverse=True)[:2] # farthest p_qq = p_q1+p_q2 p_bb = p_b1+p_b2 # result["Pt_q1"] = p_q1.Pt() # result["Pt_q2"] = p_q2.Pt() # result["Pt_b1"] = p_b1.Pt() # result["Pt_b2"] = p_b2.Pt() # result["Pt_bb"] = p_bb.Pt() # result["Pt_q1l"] = (p_q1+p_l).Pt() # result["Pt_bl"] = (p_b2+p_l).Pt() # result["M_qq"] = p_qq.M() # result["M_q1l"] = (p_q1+p_l).M() # result["M_bb"] = p_bb.M() # result["M_qqlnu"] = (p_qq+p_l+p_nu).M() # result["M_qql"] = (p_qq+p_l).M() # result["M_qqb1"] = (p_qq+p_b1).M() # result["M_qqb2"] = (p_qq+p_b2).M() # result["M_bl"] = (p_b2+p_l).M() # result["M_b1lnu"] = (p_b1+p_l+p_nu).M() # result["M_b2lnu"] = (p_b2+p_l+p_nu).M() # q = copy(p_b1) # beta = p_bb.BoostVector() # q.Boost(-beta) # boost b-jet four-momentum back to restframe # q3 = q.Vect() # p_bb3 = p_bb.Vect() # result["CosTheta0_bb"] = p_bb3.Dot(q3) / p_bb3.Mag() / q3.Mag() # cos(theta) #result["theta0_bb"] = q.Angle(p_bb.Vect()) #pz = TLV(0,0,1,0) #result["theta0_b_z"] = q.Angle(pz.Vect()) #result["theta0_bb_z"] = p_bb.Angle(pz.Vect()) result["DeltaR_q1l"] = TLV.DeltaR(p_q1,p_l) result["DeltaR_q2l"] = TLV.DeltaR(p_q2,p_l) result["DeltaR_b1l"] = TLV.DeltaR(p_b1,p_l) result["DeltaR_b2l"] = TLV.DeltaR(p_b2,p_l) result["DeltaR_bb"] = TLV.DeltaR(p_b1,p_b2) result["DeltaR_qq"] = TLV.DeltaR(p_q1,p_q2) result["DeltaR_qql"] = TLV.DeltaR(p_qq,p_l) result["DeltaR_qqb"] = TLV.DeltaR(p_qq,p_b1) result["DeltaEtaDeltaPhi_b1l"] = [[ abs(lepton.Eta - p_b1.Eta()), fold(abs(lepton.Phi - p_b1.Phi())) ]] result["DeltaEtaDeltaPhi_b2l"] = [[ abs(lepton.Eta - p_b2.Eta()), fold(abs(lepton.Phi - p_b2.Phi())) ]] result["DeltaEtaDeltaPhi_bb"] = [[ abs(bquarks[0].Eta - bquarks[1].Eta), fold(abs(bquarks[0].Phi - bquarks[1].Phi)) ]] result["DeltaEtaDeltaPhi_q1l"] = [[ abs(lepton.Eta - p_q1.Eta()), fold(abs(lepton.Phi - p_q1.Phi())) ]] result["DeltaEtaDeltaPhi_q2l"] = [[ abs(lepton.Eta - p_q2.Eta()), fold(abs(lepton.Phi - p_q2.Phi())) ]] result["DeltaEtaDeltaPhi_qq"] = [[ abs(quarks[0].Eta - quarks[1].Eta), fold(abs(quarks[0].Phi - quarks[1].Phi)) ]] if abs(higgs[0].PID) == 25: if higgs[0].ljets: result["DeltaR_bb_HP"] = [[ higgs[1].P, result["DeltaR_bb"] ]] result["DeltaR_qq_HP"] = [[ higgs[0].P, result["DeltaR_qq"] ]] result["DeltaR_qql_HP"] = [[ higgs[0].P, result["DeltaR_qql"] ]] else: result["DeltaR_bb_HP"] = [[ higgs[0].P, result["DeltaR_bb"] ]] result["DeltaR_qq_HP"] = [[ higgs[1].P, result["DeltaR_qq"] ]] result["DeltaR_qql_HP"] = [[ higgs[1].P, result["DeltaR_qql"] ]] elif bquark_had and bquark_lep: p_had = TLV() p_lep = TLV() p_lep.SetPtEtaPhiM(bquark_lep.PT, bquark_lep.Eta, bquark_lep.Phi, bquark_lep.Mass) p_had.SetPtEtaPhiM(bquark_had.PT, bquark_had.Eta, bquark_had.Phi, bquark_had.Mass) result["DeltaR_bl_had"] = TLV.DeltaR(p_had,p_l) result["DeltaR_bl_lep"] = TLV.DeltaR(p_lep,p_l) result["DeltaR_bl_lep_had"] = [[ result["DeltaR_bl_had"], result["DeltaR_bl_lep"] ]] if result["DeltaR_bl_lep"] < result["DeltaR_bl_had"]: result["DeltaR_bl_count"] = 1 else: result["DeltaR_bl_count"] = 0 result["DeltaR_qqb_had"] = TLV.DeltaR(p_had,p_qq) result["DeltaR_qqb_lep"] = TLV.DeltaR(p_lep,p_qq) result["DeltaR_qqb_lep_had"] = [[ result["DeltaR_qqb_had"], result["DeltaR_qqb_lep"] ]] if result["DeltaR_qqb_had"] < result["DeltaR_qqb_lep"]: result["DeltaR_qqb_count"] = 1 else: result["DeltaR_qqb_count"] = 0 if higgs[0].ljets: result["DeltaR_qq_HP"] = [[ higgs[0].P, result["DeltaR_qq"] ]] result["DeltaR_qqb_HP"] = [[ higgs[0].P, result["DeltaR_qqb_had"] ]] result["DeltaR_bl_HP"] = [[ higgs[1].P, result["DeltaR_bl_lep"] ]] else: result["DeltaR_qq_HP"] = [[ higgs[1].P, result["DeltaR_qq"] ]] result["DeltaR_qqb_HP"] = [[ higgs[1].P, result["DeltaR_qqb_had"] ]] result["DeltaR_bl_HP"] = [[ higgs[0].P, result["DeltaR_bl_lep"] ]] else: return { } # make code faster by ignoring uninteresting events # __WW_2D-plots__ if len( result["WlnuM"] ) == 1 and len( result["WqqM"] ) == 1: # semileptonic result["WWM"] = [[ result["WqqM"][0], result["WlnuM"][0] ]] else: print "Warning! GenControlPlots.py: No WW 2D-plot!" # __Matching__ for jet in event.jets: NMatch_lq_20 = 0 NMatch_bq_20 = 0 NMatch_lq_40 = 0 NMatch_bq_40 = 0 p_j = TLV() p_j.SetPtEtaPhiM(jet.PT, jet.Eta, jet.Phi, jet.Mass) for p in p_q: # quarks from W if TLV.DeltaR(p_j,p) < 0.4: NMatch_lq_40 += 1 if TLV.DeltaR(p_j,p) < 0.2: NMatch_lq_20 += 1 for p in p_b: # b quarks if TLV.DeltaR(p_j,p) < 0.4: NMatch_bq_40 += 1 if TLV.DeltaR(p_j,p) < 0.2: NMatch_bq_20 += 1 if jet.BTag: result["MatchBJets_20"].append([NMatch_lq_20,NMatch_bq_20]) result["MatchBJets_40"].append([NMatch_lq_40,NMatch_bq_40]) else: result["MatchLJets_20"].append([NMatch_lq_20,NMatch_bq_20]) result["MatchLJets_40"].append([NMatch_lq_40,NMatch_bq_40]) # result["gen"] = [ ] # for var in tree_vars: # if var in result: # result["gen"].append(result[var]) # else: # if one variable does not exist for this event, no tree # del result["gen"] # break return result
def eventCategory(event): """Check analysis requirements for various steps and return a tuple of data used to decide to what category an event belong""" categoryData = [ ] # preparation for event selection muons20 = [ m for m in event.muons if m.PT>20 and abs(m.Eta) < 2.5 ] electrons25 = [ e for e in event.electrons if e.PT>25 and abs(e.Eta) < 2.5 ] leps = sorted(muons20+electrons25, key=lambda x: x.PT, reverse=True) event.leadingLeptons = leps[:5] event.jets20 = [ j for j in event.jets if j.PT > 20 and abs(j.Eta) < 2.5 ] event.bjets30 = [ j for j in event.jets if j.PT > 30 and abs(j.Eta) < 2.5 and j.BTag ] for m in muons20: m.Mass = 0.1057 for e in electrons25: e.Mass = 0.000511 for l1, l2 in combinations(leps[:3],2): # take opposite charge if l1.Charge*l2.Charge < 0: leps = [l1,l2] break # preparation for clean-up event.M_ll = 100 event.M_bb = 0 event.DeltaR_ll = 100 # >>> pi event.DeltaR_bb = 100 # >>> pi event.DeltaPhi_bbll = 100 # >>> pi p_ll = None if len(leps)>1: p_l1 = TLV(0,0,0,0) p_l2 = TLV(0,0,0,0) p_l1.SetPtEtaPhiM(leps[0].PT,leps[0].Eta,leps[0].Phi,leps[0].Mass) p_l2.SetPtEtaPhiM(leps[1].PT,leps[1].Eta,leps[1].Phi,leps[1].Mass) p_ll = p_l1 + p_l2 event.M_ll = p_ll.M() event.DeltaR_ll = TLV.DeltaR(p_l1,p_l2) if len(event.bjets30)>1: p_b1 = TLV(0,0,0,0) p_b2 = TLV(0,0,0,0) p_b1.SetPtEtaPhiM(event.bjets30[0].PT,event.bjets30[0].Eta,event.bjets30[0].Phi,event.bjets30[0].Mass) p_b2.SetPtEtaPhiM(event.bjets30[1].PT,event.bjets30[1].Eta,event.bjets30[1].Phi,event.bjets30[1].Mass) p_bb = p_b1 + p_b2 event.M_bb = p_bb.M() event.DeltaR_bb = TLV.DeltaR(p_b1,p_b2) if p_ll: event.DeltaPhi_bbll = fold( abs(p_ll.Phi() - (p_bb).Phi()) ) # preparation for gen level selection nLeptons = 0 nBquarks = 0 gen_leptons15 = [ ] gen_quarks15 = [ ] nBquarks15 = 0 for particle in event.particles: D1 = particle.D1 # W, Z -> e, mu, tau if abs(particle.PID) == 24 and 0 <= D1 < len(event.particles) and event.particles[D1]: for D in [ event.particles[particle.D1], event.particles[particle.D2] ]: if abs(D.PID) in [11,13]:#,15]: # e, mu, tau if D.PT > 15 and abs(D.Eta) < 2.5: gen_leptons15.append(D) nLeptons+=1 if abs(D.PID) in [1,2,3,4,5]: # e, mu, tau if D.PT > 15 and abs(D.Eta) < 2.5: gen_quarks15.append(D) # t -> bW if abs(particle.PID) == 6 and 0 <= D1 < len(event.particles) and event.particles[D1]: for D in [ event.particles[particle.D1], event.particles[particle.D2] ]: if abs(D.PID) == 5: # b-quark if D.PT > 15: #and abs(D.Eta) < 2.5: nBquarks15+=1 nBquarks+=1 # preparation for gen level cuts DeltaR_ll_gen = 100 # DeltaR_ql_gen = 100 if len(gen_leptons15)==2: p1 = TLV(0,0,0,0) p2 = TLV(0,0,0,0) p1.SetPtEtaPhiM(gen_leptons15[0].PT,gen_leptons15[0].Eta,gen_leptons15[0].Phi,gen_leptons15[0].Mass) p2.SetPtEtaPhiM(gen_leptons15[1].PT,gen_leptons15[1].Eta,gen_leptons15[1].Phi,gen_leptons15[1].Mass) DeltaR_ll_gen = TLV.DeltaR(p1,p2) # if len(gen_leptons15)==1 and len(gen_quarks15)==2: # pl = TLV(0,0,0,0) # pqs = [ TLV(0,0,0,0), TLV(0,0,0,0) ] # pl.SetPtEtaPhiM(gen_leptons15[0].PT,gen_leptons15[0].Eta,gen_leptons15[0].Phi,gen_leptons15[0].Mass) # pqs[0].SetPtEtaPhiM(gen_quarks15[0].PT,gen_quarks15[0].Eta,gen_quarks15[0].Phi,gen_quarks15[0].Mass) # pqs[1].SetPtEtaPhiM(gen_quarks15[1].PT,gen_quarks15[1].Eta,gen_quarks15[1].Phi,gen_quarks15[1].Mass) # DeltaR_ql_gen = min(TLV.DeltaR(pq,pl) for pq in pqs) # 0-1: generator level: double Wlnu and Hbb categoryData.append((nLeptons==2 and nBquarks==2)) #or event.particles.GetEntries()==0) categoryData.append((len(gen_leptons15)==2 and nBquarks15==2 and DeltaR_ll_gen<2.5)) #or event.particles.GetEntries()==0) # 2: two leptons: muons, electrons with PT > 20, 25 GeV # MET > 20 GeV # at least 2 b-jets with PT > 30 GeV categoryData.append( len(leps)>1 and \ event.met[0].MET>20 and \ len(event.bjets30)>1 ) # 3: two leptons: muons, electrons with PT > 20, 25 GeV # MET > 20 GeV # 2 b-jets with PT > 30 GeV categoryData.append( len(leps)==2 and \ event.met[0].MET>20 and \ # require no other jets? len(event.bjets30)==2 ) # 4: clean-up cuts categoryData.append( event.M_ll<85 and 60<event.M_bb<160 and \ event.DeltaR_ll<2 and event.DeltaR_bb<3.1 and event.DeltaPhi_bbll>1.7 ) # 5-6: generator level: single Wlnu, Wjj and Hbb categoryData.append((nLeptons==1 and nBquarks==2)) # or event.particles.GetEntries()==0) # categoryData.append((nLeptons==1 and nBquarks==2)) # or event.particles.GetEntries()==0) categoryData.append((len(gen_leptons15)==1 and nBquarks15==2)) #or event.particles.GetEntries()==0) # categoryData.append((len(gen_leptons15)==1 and nBquarks15==2 and DeltaR_ql_gen<2.5) or event.particles.GetEntries()==0) # 7: one muon or electron with PT > 20, 25 GeV # MET > 20 GeV # at least 2 jets # at least 2 b-jets with PT > 30 GeV categoryData.append( len(leps)==1 and \ event.met[0].MET>20 and \ len(event.jets20)>3 and \ len(event.bjets30)>1 ) # 8: one muon or electron with PT > 20, 25 GeV # MET > 20 GeV # 2 jets # 2 b-jets with PT > 30 GeV categoryData.append( len(leps)==1 and \ event.met[0].MET>20 and \ len(event.jets20)>3 and \ len(event.bjets30)==2 ) # 9: clean-up cuts categoryData.append( 60<event.M_bb<160 and \ event.DeltaR_bb<3 ) return categoryData
def process(self, event): result = { } result["WlnuM"] = [ ] result["WqqM"] = [ ] result["qEta"] = [ ] result["NMatchLJets_20"] = [ ] result["NMatchLJets_40"] = [ ] result["NMatchBJets_20"] = [ ] result["NMatchBJets_40"] = [ ] dict = event.particle_dict # bquarks = dict['b quarks'] quarks = dict['W quarks'] bquark_had = None bquark_lep = None # __ LEPTONIC / HADRONIC W __ for W in dict['W bosons']: if abs(event.particles[W.D1].PID) in [11,13]: result["WlnuM"].append( W.Mass ) elif abs(event.particles[W.D1].PID) in [1,2,3,4,5]: result["WqqM"].append( W.Mass ) # __ HIGGS __ for H in dict["H bosons"]: if abs(event.particles[H.D1].PID) == 5: H.ljets = False else: H.ljets = True # __ TOP QUARKS __ for t in dict["t quarks"]: if abs(event.particles[t.D1].PID) == 24: if abs(event.particles[event.particles[t.D1].D1].PID) in [11,13,15]: # LEPTONIC bquark_lep = event.particles[t.D2] t.ljets = False elif abs(event.particles[event.particles[t.D1].D1].PID) in [1,2,3,4,5]: # HADRONIC bquark_had = event.particles[t.D2] t.ljets = True elif abs(event.particles[t.D2].PID) == 24: print "Warning! t.D2 is W" # __ QUARK TLV __ p_q = [ ] if len(quarks) == 2: for q in quarks: result["qEta"].append(q.Eta) p_q.append(TLV()) p_q[-1].SetPtEtaPhiM(q.PT, q.Eta, q.Phi, q.Mass) result["QuarkEta"] = [[ quarks[0].Eta, quarks[1].Eta ]] else: return { } # make code faster # __ B QUARK TLV __ p_b = [ ] if len(dict['b quarks']) == 2: for b in dict['b quarks']: p_b.append(TLV()) p_b[-1].SetPtEtaPhiM(b.PT, b.Eta, b.Phi, b.Mass) else: return { } # make code faster if len(dict['leptons']) == 1 and len(dict['neutrinos']) == 1: # __ LEPTON & NEUTRINO __ lepton = dict['leptons'][0] neutrino = dict['neutrinos'][0] p_l = TLV() p_nu = TLV() p_l.SetPtEtaPhiM(lepton.PT, lepton.Eta, lepton.Phi, lepton.Mass) p_nu.SetPtEtaPhiM(neutrino.PT, neutrino.Eta, neutrino.Phi, neutrino.Mass) result["MET_res"] = abs(event.met[0].MET-neutrino.PT)/neutrino.PT result["MET_res_ang"] = fold(abs( event.met[0].Phi-neutrino.Phi )) result["MT_lnu_gen"] = sqrt(2 * neutrino.PT * lepton.PT * (1-cos( lepton.Phi - neutrino.Phi)) ) # __ HIGGS / TOP MOMENTA __ higgs = dict['H bosons'] + dict['t quarks'] if len(higgs) == 2: higgs[0].P = sqrt(higgs[0].PT*higgs[0].PT + higgs[0].Pz*higgs[0].Pz) higgs[1].P = sqrt(higgs[1].PT*higgs[1].PT + higgs[1].Pz*higgs[1].Pz) higgs = sorted(higgs, key = lambda h: h.P,reverse=True) [ result["H1P"], result["H2P"] ] = [ higgs[0].P , higgs[1].P ] [ result["H1Pt"], result["H2Pt"] ] = [ higgs[0].PT , higgs[1].PT ] [ result["H1Pz"], result["H2Pz"] ] = [ higgs[0].Pz , higgs[1].Pz ] result["H1PH2P"] = [[ result["H1P"], result["H2P"] ]] result["H1PtH2Pt"] = [[ result["H1Pt"], result["H2Pt"] ]] result["H1PzH2Pz"] = [[ result["H1Pz"], result["H2Pz"] ]] if p_q and p_b: [p_q1,p_q2] = sorted(p_q, key = lambda p: TLV.DeltaR(p,p_l))[:2] [p_b1,p_b2] = sorted(p_b, key = lambda p: TLV.DeltaR(p,p_l), reverse=True)[:2] # farthest p_qq = p_q1+p_q2 p_bb = p_b1+p_b2 result["DeltaR_q1l"] = TLV.DeltaR(p_q1,p_l) result["DeltaR_q2l"] = TLV.DeltaR(p_q2,p_l) result["DeltaR_b1l"] = TLV.DeltaR(p_b1,p_l) result["DeltaR_b2l"] = TLV.DeltaR(p_b2,p_l) result["DeltaR_bb"] = TLV.DeltaR(p_b1,p_b2) result["DeltaR_qq"] = TLV.DeltaR(p_q1,p_q2) result["DeltaR_qql"] = TLV.DeltaR(p_qq,p_l) result["DeltaR_qqb"] = TLV.DeltaR(p_qq,p_b1) result["DeltaEtaDeltaPhi_b1l"] = [[ abs(lepton.Eta - p_b1.Eta()), fold(abs(lepton.Phi - p_b1.Phi())) ]] result["DeltaEtaDeltaPhi_b2l"] = [[ abs(lepton.Eta - p_b2.Eta()), fold(abs(lepton.Phi - p_b2.Phi())) ]] result["DeltaEtaDeltaPhi_bb"] = [[ abs(dict['b quarks'][0].Eta - dict['b quarks'][1].Eta), fold(abs(dict['b quarks'][0].Phi - dict['b quarks'][1].Phi)) ]] result["DeltaEtaDeltaPhi_q1l"] = [[ abs(lepton.Eta - p_q1.Eta()), fold(abs(lepton.Phi - p_q1.Phi())) ]] result["DeltaEtaDeltaPhi_q2l"] = [[ abs(lepton.Eta - p_q2.Eta()), fold(abs(lepton.Phi - p_q2.Phi())) ]] result["DeltaEtaDeltaPhi_qq"] = [[ abs(quarks[0].Eta - quarks[1].Eta), fold(abs(quarks[0].Phi - quarks[1].Phi)) ]] if abs(higgs[0].PID) == 25: if higgs[0].ljets: result["DeltaR_bb_HP"] = [[ higgs[1].P, result["DeltaR_bb"] ]] result["DeltaR_qq_HP"] = [[ higgs[0].P, result["DeltaR_qq"] ]] result["DeltaR_qql_HP"] = [[ higgs[0].P, result["DeltaR_qql"] ]] else: result["DeltaR_bb_HP"] = [[ higgs[0].P, result["DeltaR_bb"] ]] result["DeltaR_qq_HP"] = [[ higgs[1].P, result["DeltaR_qq"] ]] result["DeltaR_qql_HP"] = [[ higgs[1].P, result["DeltaR_qql"] ]] elif bquark_had and bquark_lep: p_had = TLV() p_lep = TLV() p_lep.SetPtEtaPhiM(bquark_lep.PT, bquark_lep.Eta, bquark_lep.Phi, bquark_lep.Mass) p_had.SetPtEtaPhiM(bquark_had.PT, bquark_had.Eta, bquark_had.Phi, bquark_had.Mass) result["DeltaR_bl_had"] = TLV.DeltaR(p_had,p_l) result["DeltaR_bl_lep"] = TLV.DeltaR(p_lep,p_l) result["DeltaR_bl_lep_had"] = [[ result["DeltaR_bl_had"], result["DeltaR_bl_lep"] ]] if result["DeltaR_bl_lep"] < result["DeltaR_bl_had"]: result["DeltaR_bl_count"] = 1 else: result["DeltaR_bl_count"] = 0 result["DeltaR_qqb_had"] = TLV.DeltaR(p_had,p_qq) result["DeltaR_qqb_lep"] = TLV.DeltaR(p_lep,p_qq) result["DeltaR_qqb_lep_had"] = [[ result["DeltaR_qqb_had"], result["DeltaR_qqb_lep"] ]] if result["DeltaR_qqb_had"] < result["DeltaR_qqb_lep"]: result["DeltaR_qqb_count"] = 1 else: result["DeltaR_qqb_count"] = 0 if higgs[0].ljets: result["DeltaR_qq_HP"] = [[ higgs[0].P, result["DeltaR_qq"] ]] result["DeltaR_qqb_HP"] = [[ higgs[0].P, result["DeltaR_qqb_had"] ]] result["DeltaR_bl_HP"] = [[ higgs[1].P, result["DeltaR_bl_lep"] ]] else: result["DeltaR_qq_HP"] = [[ higgs[1].P, result["DeltaR_qq"] ]] result["DeltaR_qqb_HP"] = [[ higgs[1].P, result["DeltaR_qqb_had"] ]] result["DeltaR_bl_HP"] = [[ higgs[0].P, result["DeltaR_bl_lep"] ]] else: return { } # make code faster # __ WW 2D-PLOTS __ if len( result["WlnuM"] ) == 1 and len( result["WqqM"] ) == 1: # semileptonic result["WWM"] = [[ result["WqqM"][0], result["WlnuM"][0] ]] else: print "Warning! GenControlPlots.py: No WW 2D-plot!" # __ MATCHING LEADING JETS __ if len(event.bjets30[:])>1 and len(event.cleanedJets20[:])>3 and len(p_q) == 2: jets = event.cleanedJets[:] # keep b-jets jets20 = event.cleanedJets20[:] # remove closest b-jets pair down below bjets = event.bjets30[:] for bjet in min( combinations(bjets,2), key=lambda bj: TLV.DeltaR(bj[0].TLV,bj[1].TLV) ) : # remove closest bjet pair from jet list # if bjet in jets: # jets.remove(bjet) if bjet in jets20: jets20.remove(bjet) result["NMatchJet1_q"] = 0 result["NMatchJet2_q"] = 0 NMatchQuark = [ 0, 0 ] NMatchQuark_cut = [ 0, 0 ] # result["NMatchedQuarks"] = 0 # result["NMatchedQuarksMakesCut"] = 0 i = 0 for p in p_q: # quarks from W if TLV.DeltaR(p,jets20[0].TLV) < 0.4: result["NMatchJet1_q"] += 1 if TLV.DeltaR(p,jets20[1].TLV) < 0.4: result["NMatchJet2_q"] += 1 for jet in jets: if TLV.DeltaR(p,jet.TLV) < 0.4: NMatchQuark[i] += 1 if jet.PT > 20 and abs(jet.Eta) < 2.5: NMatchQuark_cut[i] += 1 # if NMatchQuark[i]>0: # count quark matching any jet # result["NMatchedQuarks"] += 1 # if NMatchQuark_cut[i]>0: # count quark matching any jet that passes cut # result["NMatchedQuarksMakesCut"] += 1 i += 1 result["NMatchQuark"] = [ NMatchQuark ] result["NMatchQuark_cut"] = [ NMatchQuark_cut ] result["NMatchJets_q"] = [[ result["NMatchJet1_q"], result["NMatchJet2_q"] ]] # __ MATCHING for B TAGGING __ for jet in event.jets: NMatch_lq_20 = 0 NMatch_bq_20 = 0 NMatch_lq_40 = 0 NMatch_bq_40 = 0 p_j = TLV() p_j.SetPtEtaPhiM(jet.PT, jet.Eta, jet.Phi, jet.Mass) for p in p_q: # quarks from W if TLV.DeltaR(p_j,p) < 0.4: NMatch_lq_40 += 1 if TLV.DeltaR(p_j,p) < 0.2: NMatch_lq_20 += 1 for p in p_b: # b quarks if TLV.DeltaR(p_j,p) < 0.4: NMatch_bq_40 += 1 if TLV.DeltaR(p_j,p) < 0.2: NMatch_bq_20 += 1 if jet.BTag: result["NMatchBJets_20"].append([NMatch_lq_20,NMatch_bq_20]) result["NMatchBJets_40"].append([NMatch_lq_40,NMatch_bq_40]) else: result["NMatchLJets_20"].append([NMatch_lq_20,NMatch_bq_20]) result["NMatchLJets_40"].append([NMatch_lq_40,NMatch_bq_40]) # result["gen"] = [ ] # for var in tree_vars: # if var in result: # result["gen"].append(result[var]) # else: # if one variable does not exist for this event, no tree # del result["gen"] # break return result
ntbin = 16*1 # number of bins the time series is split into for folding ntw = min(10000, nt*ntint) # number of samples to combine for waterfall samplerate = 33333955.033217516*2 # for comparison with fortran routines, which have a bug in calculating # sample time t0 -= 2*nblock/samplerate fbottom = 306. # MHz fband = 2*16.6666666 # MHz verbose = True foldspec2, waterfall = fold(file1, file2, samplerate, fbottom, fband, nblock, nt, ntint, nhead, ngate, ntbin, ntw, dm, phasepol, do_waterfall=False, verbose=verbose) foldspec1 = foldspec2.sum(axis=2) fluxes = foldspec1.sum(axis=0) foldspec3 = foldspec2.sum(axis=0) dynspect = foldspec2[:,igate[0]-1:igate[1],:].sum(axis=1) dynspect2 = foldspec2[:,igate[2]-1:igate[3],:].sum(axis=1) f = open('dynspect'+psr+'.bin', 'wb') f.write(dynspect.T.tostring()) f.write(dynspect2.T.tostring()) f.close() f = open('flux.dat', 'w') for i, flux in enumerate(fluxes): f.write('{0:12d} {1:12.9g}\n'.format(i+1, flux)) f.close()
# nt=45 for 1508, 180 for 0809 and 156 for 0531 nt = 1024//2*8*2 # number of sets to fold -> //128 for quick try ntint = 1024*32*1024//(nblock*2)//4 # total # of blocks per set ngate = 32//2 # number of bins over the pulsar period ntbin = 16*1 # number of bins the time series is split into for folding ntw = min(10000, nt*ntint) # number of samples to combine for waterfall samplerate = 100.e6/3. * 2 #* (1.+2./16/622.156270897/1100) fbottom = 306. # MHz fband = 2*16.6666666 # MHz verbose = True foldspec2, waterfall = fold(file1, file2, samplerate, fbottom, fband, nblock, nt, ntint, nhead, ngate, ntbin, ntw, dm, phasepol, do_waterfall=False, verbose=verbose) foldspec1 = foldspec2.sum(axis=2) fluxes = foldspec1.sum(axis=0) foldspec3 = foldspec2.sum(axis=0) dynspect = foldspec2[:,igate[0]-1:igate[1],:].sum(axis=1) dynspect2 = foldspec2[:,igate[2]-1:igate[3],:].sum(axis=1) f = open('dynspect'+psr+'.bin', 'wb') f.write(dynspect.T.tostring()) f.write(dynspect2.T.tostring()) f.close() f = open('flux.dat', 'w') for i, flux in enumerate(fluxes): f.write('{0:12d} {1:12.9g}\n'.format(i+1, flux)) f.close()
ax3.plot(a, np.exp(p-ys)) #ax3.plot(a, ys, 'r-') ax3.set_xscale('log') ax3.set_xlim([minperiod, maxperiod]) ax3.axvline(x=bper, color='r', linewidth=1) #print chi2.sf(bpow, 500-1)/nf xdata = copy.deepcopy(1./freqs) ydata = copy.deepcopy(p) cursor = Cursor(ax3, xdata, ydata) connect('motion_notify_event', cursor.mouse_move) connect('button_press_event', cursor.click) nbin = 100 binvalue,binerr = fold(ix, smoothedy, bper, yerr=ie, bins=nbin) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') foldedcurve = ax4.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') def folding(): ax4.cla() #foldedcurve[0].remove() #print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] print 'candidate period: ', period #binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) binvalue,binerr = fold(ix, smoothedy, period, yerr=ie, bins=nbin) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b')
def main(kic, path='.'): files = glob.glob('%s/*%s/*llc.fits' % (path, kic)) #print files results = [] folding_results = [] label.results = results label.folding_results = folding_results ax1 = subplot(411) ax2 = subplot(412) ax3 = subplot(413) ax4 = subplot(414) ax1.grid(visible=False) #turn off the grid ax2.grid(visible=False) #turn off the grid ax3.grid(visible=False) #turn off the grid ax4.grid(visible=False) #turn off the grid ix,iy,ie = readfs(files) ax1.errorbar(ix, iy, yerr=ie, color='b', alpha=0.5) smoothedy = fftsmooth(iy) #smoothedy = filtersmooth(iy) ax2.plot(ix[:len(smoothedy)], smoothedy, color='r') ix = ix[:len(smoothedy)] T = ix.max() - ix.min() #nf = 10000 nf = min(10000, ix.size * 2) minperiod, maxperiod = 0.5, T-1 #min([100., T-1]) fmin, df = 1./maxperiod, (1./minperiod - 1./maxperiod)/nf #nf,fmin,df = 8000, 0.15, 2.e-4 freqs = np.arange(fmin, fmin+df*nf, df)[:nf] p, bper, bpow, depth, qtran, in1, in2 = bls(ix, smoothedy, nf=nf, fmin=fmin, df=df) #print bper, bpow, depth, qtran, in1, in2 a = 1./freqs b = p coeff = np.polyfit(a,b,3) polys = np.poly1d(coeff) ys = polys(a) label.period = bper ax3.plot(a, np.exp(p-ys)) #ax3.plot(a, ys, 'r-') ax3.set_xscale('log') ax3.set_xlim([minperiod, maxperiod]) ax3.axvline(x=bper, color='g', linewidth=1) #print chi2.sf(bpow, 500-1)/nf xdata = copy.deepcopy(1./freqs) ydata = copy.deepcopy(p) cursor = Cursor(ax3, xdata, ydata) #connect('motion_notify_event', cursor.mouse_move) connect('button_press_event', cursor.click) nbin = 100 peak = {} binvalue,binerr = fold(ix, smoothedy, bper, yerr=ie, bins=nbin, peak=peak) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') foldedcurve = ax4.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') print 'candidate period: ', bper folding_results.append([kic, bper, peak['offset'], (list(binvalue), list(binerr))]) connect('key_press_event', label.labeling) def folding(): ax4.cla() #print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] #try: #if cursor.end < cursor.start:raise ValueError peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] label.period = period print 'candidate period: ', period #binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) peak = {} binvalue,binerr = fold(ix, smoothedy, period, yerr=ie, bins=nbin, peak=peak) ax4.step(np.arange(0,1,1./nbin)+0.5/nbin, binvalue, color='b') ax4.errorbar(np.arange(0,1,1./nbin), binvalue, yerr=binerr, fmt='.', color='b') folding_results.append([kic, bper, peak['offset'], (list(binvalue), list(binerr))]) #except ValueError: #print "clicking too soon? try again" cursor.link_exe(folding) ax1.set_xlabel('day') ax2.set_xlabel('day') ax3.set_xlabel('day') ax4.set_xlabel('phase') show() return results
ax2 = subplot(312) ax3 = subplot(313) ax1.errorbar(ix, iy, yerr=ie, color='b', alpha=0.5) #ax2.errorbar(1./freq[1:len(trans)-1], trans[1:-1], yerr=etrans[1:-1]) ax2.plot(1. / freq[1:len(trans) - 1], trans[1:-1]) xdata = copy.deepcopy(1. / freq[1:len(trans) - 1]) ydata = copy.deepcopy(trans[1:-1]) cursor = Cursor(ax2, xdata, ydata) connect('motion_notify_event', cursor.mouse_move) connect('button_press_event', cursor.click) peak = np.argmax(trans[1:len(trans) - 1]) period = xdata[peak] print peak, period nbin = 300 binvalue, binerr = fold(ix, iy, period, yerr=ie, bins=nbin) ax3.step(np.arange(0, 1, 1. / nbin) + 0.5 / nbin, binvalue, color='b') ax3.errorbar(np.arange(0, 1, 1. / nbin), binvalue, yerr=binerr, fmt='.', color='b') def folding(): ax3.cla() print cursor.end, cursor.start, len(ydata), ydata[cursor.end:cursor.start] peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] print peak, period binvalue, binerr = fold(ix, iy, period, yerr=ie, bins=nbin)
def main(kic, path='.'): files = glob.glob('%s/*%s/*llc.fits' % (path, kic)) #print files results = [] folding_results = [] label.results = results label.folding_results = folding_results ax1 = subplot(411) ax2 = subplot(412) ax3 = subplot(413) ax4 = subplot(414) ax1.grid(visible=False) #turn off the grid ax2.grid(visible=False) #turn off the grid ax3.grid(visible=False) #turn off the grid ax4.grid(visible=False) #turn off the grid ix, iy, ie = readfs(files) ax1.errorbar(ix, iy, yerr=ie, color='b', alpha=0.5) smoothedy = fftsmooth(iy) #smoothedy = filtersmooth(iy) ax2.plot(ix[:len(smoothedy)], smoothedy, color='r') ix = ix[:len(smoothedy)] T = ix.max() - ix.min() #nf = 10000 nf = min(10000, ix.size * 2) minperiod, maxperiod = 0.5, T - 1 #min([100., T-1]) fmin, df = 1. / maxperiod, (1. / minperiod - 1. / maxperiod) / nf #nf,fmin,df = 8000, 0.15, 2.e-4 freqs = np.arange(fmin, fmin + df * nf, df)[:nf] p, bper, bpow, depth, qtran, in1, in2 = bls(ix, smoothedy, nf=nf, fmin=fmin, df=df) #print bper, bpow, depth, qtran, in1, in2 a = 1. / freqs b = p coeff = np.polyfit(a, b, 3) polys = np.poly1d(coeff) ys = polys(a) label.period = bper ax3.plot(a, np.exp(p - ys)) #ax3.plot(a, ys, 'r-') ax3.set_xscale('log') ax3.set_xlim([minperiod, maxperiod]) ax3.axvline(x=bper, color='g', linewidth=1) #print chi2.sf(bpow, 500-1)/nf xdata = copy.deepcopy(1. / freqs) ydata = copy.deepcopy(p) cursor = Cursor(ax3, xdata, ydata) #connect('motion_notify_event', cursor.mouse_move) connect('button_press_event', cursor.click) nbin = 100 peak = {} binvalue, binerr = fold(ix, smoothedy, bper, yerr=ie, bins=nbin, peak=peak) ax4.step(np.arange(0, 1, 1. / nbin) + 0.5 / nbin, binvalue, color='b') foldedcurve = ax4.errorbar(np.arange(0, 1, 1. / nbin), binvalue, yerr=binerr, fmt='.', color='b') print 'candidate period: ', bper folding_results.append( [kic, bper, peak['offset'], (list(binvalue), list(binerr))]) connect('key_press_event', label.labeling) def folding(): ax4.cla() #print cursor.end,cursor.start, len(ydata), ydata[cursor.end:cursor.start] #try: #if cursor.end < cursor.start:raise ValueError peak = cursor.end + np.argmax(ydata[cursor.end:cursor.start]) period = xdata[peak] label.period = period print 'candidate period: ', period #binvalue,binerr = fold(ix, iy, period, yerr=ie, bins=nbin) peak = {} binvalue, binerr = fold(ix, smoothedy, period, yerr=ie, bins=nbin, peak=peak) ax4.step(np.arange(0, 1, 1. / nbin) + 0.5 / nbin, binvalue, color='b') ax4.errorbar(np.arange(0, 1, 1. / nbin), binvalue, yerr=binerr, fmt='.', color='b') folding_results.append( [kic, bper, peak['offset'], (list(binvalue), list(binerr))]) #except ValueError: #print "clicking too soon? try again" cursor.link_exe(folding) ax1.set_xlabel('day') ax2.set_xlabel('day') ax3.set_xlabel('day') ax4.set_xlabel('phase') show() return results
def process(self, event): result = { } leptons = [ ] neutrinos = [ ] #quark1s = [ ] quarks = [ ] nHiggs = 0 nt = 0 nW = 0 nWlnu = 0 nWjj = 0 nHbb = 0 ntb = 0 nb = 0 b = [] W = [] nVirtualWs = 0 nVirtualWjjs = 0 for label in labels: for var in vars: result[label+var] = [ ] result["WlnuMt"] = [ ] result["DeltaPhi_qq"] = [ ] p_Hbb = TLV(0,0,0,0) p_HWW = TLV(0,0,0,0) p_t = [TLV(0,0,0,0), TLV(0,0,0,0)] # four-momenta of the top quarks for particle in event.particles: PID = abs(particle.PID) D1 = particle.D1 D2 = particle.D2 ## __lepton__ #if PID in [11,13,15]:#,15]: # e, mu, tau #result["lPt"].append( particle.PT ) #result["lEta"].append( particle.Eta ) #result["lPhi"].append( particle.Phi ) #result["lM"].append( particle.Mass ) #nLeptons += 1 # top if PID == 6 and D1>=0 and D1<len(event.particles) and event.particles[D1] and D1!=D2: nt += 1 p_t[nt-1].SetPtEtaPhiM(particle.PT, particle.Eta, particle.Phi, particle.Mass) if abs(event.particles[D2].PID) == 5: # b ntb+=1 b.append(event.particles[D2]) W.append(event.particles[D1]) elif abs(event.particles[D1].PID) == 5: # b print "Warning in GenControlPlots: b is D1!" ntb+=1 b.append(event.particles[D1]) W.append(event.particles[D2]) # __W__ if PID == 24 and D1>=0 and D1<len(event.particles) and event.particles[D1] and D1!=D2: # W nW += 1 PID_D1 = abs( event.particles[D1].PID ) PID_D2 = abs( event.particles[D2].PID ) if PID_D1 in [11,13,15]: # e, mu, tau leptons.append(event.particles[D1]) neutrinos.append(event.particles[D2]) nWlnu+=1 result["WlnuPt"].append( particle.PT ) result["WlnuEta"].append( particle.Eta ) result["WlnuPhi"].append( particle.Phi ) result["WlnuM"].append( particle.Mass ) result["WlnuMt"].append(sqrt( 2 * event.particles[D1].PT * event.particles[D2].PT * \ (1-cos( event.particles[D1].Phi - event.particles[D2].Phi )))) if abs(80.4-particle.Mass) > 10: # check if W is virtual nVirtualWs += 1 result["nuPt"].append( event.particles[D2].PT ) result["nuEta"].append( event.particles[D2].Eta ) result["nuPhi"].append( event.particles[D2].Phi ) result["nuM"].append( event.particles[D2].Mass ) elif PID_D1 in [1,2,3,4,5]: # d, u, s, c, b nWjj+=1 #quark1s.append(event.particles[D1]) quarks.extend([event.particles[D1],event.particles[D2]]) result["DeltaPhi_qq"].append(fold(abs(event.particles[D1].Phi-event.particles[D2].Phi))) result["WjjPt"].append( particle.PT ) result["WjjEta"].append( particle.Eta ) result["WjjPhi"].append( particle.Phi ) result["WjjM"].append( particle.Mass ) if abs(80.4-particle.Mass) > 10: nVirtualWs += 1 nVirtualWjjs += 1 elif PID_D1 in [12,14,16]: print "Warning: in GenControlPlots: PID_D1 of W is a neutrino!" # __Higgs__ elif PID == 25 and D1>=0 and D1<len(event.particles) and event.particles[D1] and D1!=D2: # Higgs PID_D1 = abs( event.particles[D1].PID ) nHiggs+=1 if PID_D1 == 5: # b nHbb+=1 b.extend([ event.particles[D1], event.particles[D2] ]) p_Hbb.SetPtEtaPhiM(particle.PT, particle.Eta, particle.Phi, particle.Mass) result["HbbPt"].append( particle.PT ) result["HbbEta"].append( particle.Eta ) result["HbbPhi"].append( particle.Phi ) result["HbbM"].append( particle.Mass ) if PID_D1 in [24]: # W W.extend([ event.particles[D1], event.particles[D2] ]) p_HWW.SetPtEtaPhiM(particle.PT, particle.Eta, particle.Phi, particle.Mass) result["HWWPt"].append( particle.PT ) result["HWWEta"].append( particle.Eta ) result["HWWPhi"].append( particle.Phi ) result["HWWM"].append( particle.Mass ) if len(b)==2: if abs(b[0].Eta) > abs(b[1].Eta): # order b-jets w.r.t. to Eta b1 = b[1] b2 = b[0] else: b1 = b[0] b2 = b[1] result["b1Pt"].append( b1.PT ) result["b1Eta"].append( b1.Eta ) result["b1Phi"].append( b1.Phi ) result["b1M"].append( b1.Mass ) result["b2Pt"].append( b2.PT ) result["b2Eta"].append( b2.Eta ) result["b2Phi"].append( b2.Phi ) result["b2M"].append( b2.Mass ) if nt == 2: # tt q_tt = p_t[0] + p_t[1] result["ttbbWWPt"].append( q_tt.Pt() ) result["ttbbWWEta"].append( q_tt.Eta() ) result["ttbbWWPhi"].append( q_tt.Phi() ) result["ttbbWWM"].append( q_tt.M() ) if nHiggs == 2: q_HH = p_Hbb + p_HWW result["HHbbWWPt"].append( q_HH.Pt() ) result["HHbbWWEta"].append( q_HH.Eta() ) result["HHbbWWPhi"].append( q_HH.Phi() ) result["HHbbWWM"].append( q_HH.M() ) if len(result["HWWM"]) and len(result["HbbM"]): # needed when relaxed cut 4 jets pT < 20 GeV result["HHM"] = [[ result["HWWM"][0], result["HbbM"][0] ]] # result["HHMt"] = [[ result["HWWM"][0], result["HbbM"][0] ]] # __WW_2D-plots__ if len( result["WlnuM"] ) == 1 and len( result["WjjM"] ) == 1: # monoleptonic result["WWM"] = [[ result["WlnuM"][0], result["WjjM"][0] ]] result["WWMt"] = [[ result["WlnuMt"][0], result["WjjM"][0] ]] if nVirtualWjjs == 0: result["WlnuMt_Wjjonshell"] = result["WlnuMt"] elif len( result["WlnuM"] ) == 0 and len( result["WjjM"] ) == 2: # hadronic result["WjjWjjM"] = [[ result["WjjM"][0], result["WjjM"][1] ]] elif len( result["WlnuM"] ) == 2 and len( result["WjjM"] ) == 0: # dileptonic result["WlnuWlnuM"] = [[ result["WlnuM"][0], result["WlnuM"][1] ]] result["WlnuWlnuMt"] = [[ result["WlnuMt"][0], result["WlnuMt"][1] ]] else: print "Warning! GenControlPlots.py: No WW 2D-plot!" # __bbWW_2D-plots__ p_b = [TLV(), TLV()] if len(b) == 2: p_b[0].SetPtEtaPhiM(b[0].PT, b[0].Eta, b[0].Phi, b[0].Mass) p_b[1].SetPtEtaPhiM(b[1].PT, b[1].Eta, b[1].Phi, b[1].Mass) result["DeltaR_bb"] = TLV.DeltaR(p_b[0],p_b[1]) result["DeltaEtaDeltaPhi_bb"] = [[ abs(b[0].Eta - b[1].Eta), fold(abs(b[0].Phi - b[1].Phi)) ]] if len(b) == 2 and len(W) > 1: q_W = [TLV(), TLV()] q_W[0].SetPtEtaPhiM(W[0].PT, W[0].Eta, W[0].Phi, W[0].Mass) q_W[1].SetPtEtaPhiM(W[1].PT, W[1].Eta, W[1].Phi, W[1].Mass) result["bbWWM"] = [[ (p_b[0]+p_b[1]).M(), (q_W[0]+q_W[1]).M() ]] p_q = [ ] if quarks: for quark in quarks: p_q.append(TLV()) p_q[-1].SetPtEtaPhiM(quark.PT, quark.Eta, quark.Phi, quark.Mass) result["DeltaR_qq"] = TLV.DeltaR(p_q[0],p_q[1]) result["DeltaEtaDeltaPhi_qq"] = [[ abs(quarks[0].Eta - quarks[1].Eta), fold(abs(quarks[0].Phi - quarks[1].Phi)) ]] if leptons: lepton = max(leptons, key=attrgetter('PT')) p_lepton = TLV() p_lepton.SetPtEtaPhiM(lepton.PT, lepton.Eta, lepton.Phi, lepton.Mass) if quarks: # DeltaR_ql = sorted([ TLV.DeltaR(p_lepton,p) for p in p_q ])[:2] [p_q1,p_q2] = sorted(p_q, key = lambda p: TLV.DeltaR(p,p_lepton))[:2] result["DeltaR_q1l"] = TLV.DeltaR(p_lepton,p_q1) result["DeltaR_q2l"] = TLV.DeltaR(p_lepton,p_q2) result["DeltaEtaDeltaPhi_q1l"] = [[ abs(lepton.Eta - p_q1.Eta()), fold(abs(lepton.Phi - p_q1.Phi())) ]] result["DeltaEtaDeltaPhi_q2l"] = [[ abs(lepton.Eta - p_q2.Eta()), fold(abs(lepton.Phi - p_q2.Phi())) ]] if len(b)>1: [p_b1,p_b2] = sorted(p_b, key = lambda p: TLV.DeltaR(p,p_lepton), reverse=True)[:2] # farthest result["DeltaR_b1l"] = TLV.DeltaR(p_lepton,p_b1) result["DeltaR_b2l"] = TLV.DeltaR(p_lepton,p_b2) result["DeltaEtaDeltaPhi_b1l"] = [[ abs(lepton.Eta - p_b1.Eta()), fold(abs(lepton.Phi - p_b1.Phi())) ]] result["DeltaEtaDeltaPhi_b2l"] = [[ abs(lepton.Eta - p_b2.Eta()), fold(abs(lepton.Phi - p_b2.Phi())) ]] result["NWlnu"] = nWlnu result["NWjj"] = nWjj result["NHbb"] = nHbb result["Ntb"] = ntb result["NVirtualWs"] = nVirtualWs return result