def w_mass_hadronic(tree, ecm, m_w, histdict, reconstruction, reco_level, reco_type=''): '''Run over the hadronic events and save the histograms''' from_tree = TreeInfo() sign = {} #eeqq bkg1 = {} #ZZqqll bkg2 = {} #ZZqqqq bkg3 = {} #WWqqll bkg4 = {} purete = [] efficacite = [] x = [] #cut y34 # for i in range(0,101): # j=i*0.001 # x.append(j) # print x # for index, value in enumerate(x): # print value #cut ejetcut # for i in range(0,2): # j=i*0.001 # x.append(j) # print x # print len(x) #boucle sur les valeurs de cut for iev, evt in enumerate(tree): if iev % 5000 == 0: print("Processing events {} on {} ".format(iev, tree.GetEntries())) # Object from_tree to access the rootfile information from_tree.set_evt(evt, reco_level, reco_type) # Discard event where one jet is containing only photons and/or no clustered particles if from_tree.get_dim("jet") != 4: continue if not check_content(from_tree): continue #cut masses "similaires" des 2 W #if abs(m_large-m_small)<13: # continue # cut y34 if from_tree.get_y34() <= 0.001: continue #cut energy part chargees < 0.96 * energy jet energyjet1 = from_tree.get_reco_jet1_e() energyjet2 = from_tree.get_reco_jet2_e() energyjet3 = from_tree.get_reco_jet3_e() energyjet4 = from_tree.get_reco_jet4_e() # partchargees=['11','13','211'] energypartchargeesjet1 = from_tree.get_reco_jet1_11_e( ) + from_tree.get_reco_jet1_13_e() + from_tree.get_reco_jet1_211_e() energypartchargeesjet2 = from_tree.get_reco_jet2_11_e( ) + from_tree.get_reco_jet2_13_e() + from_tree.get_reco_jet2_211_e() energypartchargeesjet3 = from_tree.get_reco_jet3_11_e( ) + from_tree.get_reco_jet3_13_e() + from_tree.get_reco_jet3_211_e() energypartchargeesjet4 = from_tree.get_reco_jet4_11_e( ) + from_tree.get_reco_jet4_13_e() + from_tree.get_reco_jet4_211_e() if energypartchargeesjet1 > 0.996 * energyjet1 or energypartchargeesjet2 > 0.996 * energyjet2 or energypartchargeesjet3 > 0.996 * energyjet3 or energypartchargeesjet4 > 0.996 * energyjet4: continue # Jets pvec = [] for part in range(4): njet = str("jet" + str(part + 1)) pvec.append(from_tree.get_p4(njet)) jets = [Jet() for i in range(from_tree.get_dim("jet"))] # Direct reconstruction if reconstruction == "direct": for jid, jet in enumerate(jets): jet.set_id(str("jet" + str(jid + 1))) jet.set_mref(m_w) jet.set_p4(pvec[jid]) # Energy Rescaling else: beta = get_beta_matrix(pvec) energy = energy_from_direction(ecm, beta, from_tree.get_dim("jet")) # discarded events with energy < 0 solutions (no physics) if any(energy < 0): continue # Need to rescale the p4 matrix p4_resc = rescaling_factors.rescale( pvec, rescaling_factors.factor(energy, pvec)) for jid, jet in enumerate(jets): jet.set_id(str("jet" + str(jid + 1))) jet.set_mref(m_w) jet.set_p4(p4_resc[jid]) dijet = get_dijets_pairs(jets) # If the pairing conditions are not full if not dijet: continue #cut energie dijets similaires diffedjets = return_edijets(dijet) if diffedjets >= 30: continue openingangledj1, openingangledj2 = return_opening_angle(dijet) #if openingangledj1 <= 80 or openingangledj2 <= 80: # continue m_small, m_large = return_mass(dijet) #cut sur la masse de mW2 #if m_large<=65 or m_small<40: # continue #fonction qui rempli les histos fill_histograms(dijet, histdict)
def w_mass_hadronic(tree, ecm, m_w, histdict, reconstruction, reco_level, reco_type=''): '''Run over the hadronic events and save the histograms''' from_tree = TreeInfo() for iev, evt in enumerate(tree): if iev % 5000 == 0: print("Processing events {} on {} ".format(iev, tree.GetEntries())) # Object from_tree to access the rootfile information from_tree.set_evt(evt, reco_level, reco_type) # Discard event where one jet is containing only photons and/or no clustered particles if from_tree.get_dim("jet") != 4: continue if not check_content(from_tree): continue # cut y34 # if from_tree.get_y34()<0.0015: # continue # L = ['1','2','3','4'] # for jetnumber in range(0,4): energyjet1 = from_tree.get_reco_jet1_e() energyjet2 = from_tree.get_reco_jet2_e() energyjet3 = from_tree.get_reco_jet3_e() energyjet4 = from_tree.get_reco_jet4_e() # print energyjet1 # print energyjet2 # print energyjet3 # print energyjet4 # partchargees=['11','13','130','211'] energypartchargeesjet1 = from_tree.get_reco_jet1_11_e( ) + from_tree.get_reco_jet1_13_e() + from_tree.get_reco_jet1_211_e() energypartchargeesjet2 = from_tree.get_reco_jet2_11_e( ) + from_tree.get_reco_jet2_13_e() + from_tree.get_reco_jet2_211_e() energypartchargeesjet3 = from_tree.get_reco_jet3_11_e( ) + from_tree.get_reco_jet3_13_e() + from_tree.get_reco_jet3_211_e() energypartchargeesjet4 = from_tree.get_reco_jet4_11_e( ) + from_tree.get_reco_jet4_13_e() + from_tree.get_reco_jet4_211_e() #cut energy part chargees < 0.9 * energy jet # if energypartchargeesjet1 > 0.9 * energyjet1 or energypartchargeesjet2 > 0.9 * energyjet2 or energypartchargeesjet3 > 0.9 * energyjet3 or energypartchargeesjet4 > 0.9 * energyjet4: # continue # print energypartchargeesjet1 # print energypartchargeesjet2 # print energypartchargeesjet3 # print energypartchargeesjet4 #for ptcharged in partchargees #get_reco_jet + L[jetnumber]+"_e" ## partchargees=['11','13','130','211'] ## for ptcharged in partchargees: ## energy_part_chargees_jet_number+=from_tree.get_reco_jet+L[jetnumber]+_+partchargees[ptcharged]+_e ## if energy_part_chargees_jet_number < 0.9*energyjet+L[jetnumber]: #continue #print y34 value for each event #print from_tree.get_y34() #for jet in range (4): #energypartjet = fromtree.getenergyjet #if pdgif = 211 or 11 or 13 # energypartchargeesjet+=energypartchargeesjet #if from_tree_get_jet1_e()<0.9.*energypartchargeesjet #continue #cut particules chargees, #for jet_"number" in range (0,4): #energyjet"number" = fromtree.get_reco_jet_"number"_e # for part in (list particules chargees): # energy_part_chargees_jet_"number"+=from_tree?get_reco_jet_"number"_"part"_e #if energy_part_chargees_jet_"number"<0.9.*energy_part_chargees_jet_"number" # continue # Jets pvec = [] for part in range(4): njet = str("jet" + str(part + 1)) pvec.append(from_tree.get_p4(njet)) jets = [Jet() for i in range(from_tree.get_dim("jet"))] # Direct reconstruction if reconstruction == "direct": for jid, jet in enumerate(jets): jet.set_id(str("jet" + str(jid + 1))) jet.set_mref(m_w) jet.set_p4(pvec[jid]) # Energy Rescaling else: beta = get_beta_matrix(pvec) energy = energy_from_direction(ecm, beta, from_tree.get_dim("jet")) # discarded events with energy < 0 solutions (no physics) if any(energy < 0): continue # Need to rescale the p4 matrix p4_resc = rescaling_factors.rescale( pvec, rescaling_factors.factor(energy, pvec)) for jid, jet in enumerate(jets): jet.set_id(str("jet" + str(jid + 1))) jet.set_mref(m_w) jet.set_p4(p4_resc[jid]) dijet = get_dijets_pairs(jets) # If the pairing conditions are not full if not dijet: continue fill_histograms(dijet, histdict)
def w_mass_hadronic(tree, ecm, m_w, histdict, reconstruction, reco_level, reco_type=''): '''Run over the hadronic events and save the histograms''' f1 = TFile('signal_and_bkg_cut_240GeV.root', "update") treecut = TTree(treename, "tree title") y34 = array('f', [0]) reco_jet1_e = array('f', [0]) reco_jet2_e = array('f', [0]) reco_jet3_e = array('f', [0]) reco_jet4_e = array('f', [0]) reco_jet1_px = array('f', [0]) reco_jet2_px = array('f', [0]) reco_jet3_px = array('f', [0]) reco_jet4_px = array('f', [0]) reco_jet1_py = array('f', [0]) reco_jet2_py = array('f', [0]) reco_jet3_py = array('f', [0]) reco_jet4_py = array('f', [0]) reco_jet1_pz = array('f', [0]) reco_jet2_pz = array('f', [0]) reco_jet3_pz = array('f', [0]) reco_jet4_pz = array('f', [0]) reco_jet_size = array('f', [0]) file_type = array('f', [0]) quark_size = array('f', [0]) quark1_e = array('f', [0]) quark2_e = array('f', [0]) quark3_e = array('f', [0]) quark4_e = array('f', [0]) quark1_px = array('f', [0]) quark2_px = array('f', [0]) quark3_px = array('f', [0]) quark4_px = array('f', [0]) quark1_py = array('f', [0]) quark2_py = array('f', [0]) quark3_py = array('f', [0]) quark4_py = array('f', [0]) quark1_pz = array('f', [0]) quark2_pz = array('f', [0]) quark3_pz = array('f', [0]) quark4_pz = array('f', [0]) gen_jet_size = array('f', [0]) gen_jet1_e = array('f', [0]) gen_jet2_e = array('f', [0]) gen_jet3_e = array('f', [0]) gen_jet4_e = array('f', [0]) gen_jet1_px = array('f', [0]) gen_jet2_px = array('f', [0]) gen_jet3_px = array('f', [0]) gen_jet4_px = array('f', [0]) gen_jet1_py = array('f', [0]) gen_jet2_py = array('f', [0]) gen_jet3_py = array('f', [0]) gen_jet4_py = array('f', [0]) gen_jet1_pz = array('f', [0]) gen_jet2_pz = array('f', [0]) gen_jet3_pz = array('f', [0]) gen_jet4_pz = array('f', [0]) treecut.Branch("y34", y34, 'y34/F') treecut.Branch("reco_jet1_e", reco_jet1_e, 'reco_jet1_e/F') treecut.Branch("reco_jet2_e", reco_jet2_e, 'reco_jet2_e/F') treecut.Branch("reco_jet3_e", reco_jet3_e, 'reco_jet3_e/F') treecut.Branch("reco_jet4_e", reco_jet4_e, 'reco_jet4_e/F') treecut.Branch("reco_jet1_px", reco_jet1_px, 'reco_jet1_px/F') treecut.Branch("reco_jet2_px", reco_jet2_px, 'reco_jet2_px/F') treecut.Branch("reco_jet3_px", reco_jet3_px, 'reco_jet3_px/F') treecut.Branch("reco_jet4_px", reco_jet4_px, 'reco_jet4_px/F') treecut.Branch("reco_jet1_py", reco_jet1_py, 'reco_jet1_py/F') treecut.Branch("reco_jet2_py", reco_jet2_py, 'reco_jet2_py/F') treecut.Branch("reco_jet3_py", reco_jet3_py, 'reco_jet3_py/F') treecut.Branch("reco_jet4_py", reco_jet4_py, 'reco_jet4_py/F') treecut.Branch("reco_jet1_pz", reco_jet1_pz, 'reco_jet1_pz/F') treecut.Branch("reco_jet2_pz", reco_jet2_pz, 'reco_jet2_pz/F') treecut.Branch("reco_jet3_pz", reco_jet3_pz, 'reco_jet3_pz/F') treecut.Branch("reco_jet4_pz", reco_jet4_pz, 'reco_jet4_pz/F') treecut.Branch("reco_jet_size", reco_jet_size, 'reco_jet_size/F') treecut.Branch("file_type", file_type, 'file_type/F') treecut.Branch("quark_size", quark_size, 'quark_size/F') treecut.Branch("quark1_e", quark1_e, 'quark1_e/F') treecut.Branch("quark2_e", quark2_e, 'quark2_e/F') treecut.Branch("quark3_e", quark3_e, 'quark3_e/F') treecut.Branch("quark4_e", quark4_e, 'quark4_e/F') treecut.Branch("quark1_px", quark1_px, 'quark1_px/F') treecut.Branch("quark2_px", quark2_px, 'quark2_px/F') treecut.Branch("quark3_px", quark3_px, 'quark3_px/F') treecut.Branch("quark4_px", quark4_px, 'quark4_px/F') treecut.Branch("quark1_py", quark1_py, 'quark1_py/F') treecut.Branch("quark2_py", quark2_py, 'quark2_py/F') treecut.Branch("quark3_py", quark3_py, 'quark3_py/F') treecut.Branch("quark4_py", quark4_py, 'quark4_py/F') treecut.Branch("quark1_pz", quark1_pz, 'quark1_pz/F') treecut.Branch("quark2_pz", quark2_pz, 'quark2_pz/F') treecut.Branch("quark3_pz", quark3_pz, 'quark3_pz/F') treecut.Branch("quark4_pz", quark4_pz, 'quark4_pz/F') treecut.Branch("gen_jet_size", gen_jet_size, 'gen_jet_size/F') treecut.Branch("gen_jet1_e", gen_jet1_e, 'gen_jet1_e/F') treecut.Branch("gen_jet2_e", gen_jet2_e, 'gen_jet2_e/F') treecut.Branch("gen_jet3_e", gen_jet3_e, 'gen_jet3_e/F') treecut.Branch("gen_jet4_e", gen_jet4_e, 'gen_jet4_e/F') treecut.Branch("gen_jet1_px", gen_jet1_px, 'gen_jet1_px/F') treecut.Branch("gen_jet2_px", gen_jet2_px, 'gen_jet2_px/F') treecut.Branch("gen_jet3_px", gen_jet3_px, 'gen_jet3_px/F') treecut.Branch("gen_jet4_px", gen_jet4_px, 'gen_jet4_px/F') treecut.Branch("gen_jet1_py", gen_jet1_py, 'gen_jet1_py/F') treecut.Branch("gen_jet2_py", gen_jet2_py, 'gen_jet2_py/F') treecut.Branch("gen_jet3_py", gen_jet3_py, 'gen_jet3_py/F') treecut.Branch("gen_jet4_py", gen_jet4_py, 'gen_jet4_py/F') treecut.Branch("gen_jet1_pz", gen_jet1_pz, 'gen_jet1_pz/F') treecut.Branch("gen_jet2_pz", gen_jet2_pz, 'gen_jet2_pz/F') treecut.Branch("gen_jet3_pz", gen_jet3_pz, 'gen_jet3_pz/F') treecut.Branch("gen_jet4_pz", gen_jet4_pz, 'gen_jet4_pz/F') from_tree = TreeInfo() sign = {} #eeqq bkg1 = {} #ZZqqll bkg2 = {} #ZZqqqq bkg3 = {} #WWqqll bkg4 = {} purete = [] efficacite = [] x = [] #cut y34 # for i in range(0,101): # j=i*0.001 # x.append(j) # print x # for index, value in enumerate(x): # print value #cut ejetcut # for i in range(0,2): # j=i*0.001 # x.append(j) # print x # print len(x) #boucle sur les valeurs de cut for iev, evt in enumerate(tree): if iev % 5000 == 0: print("Processing events {} on {} ".format(iev, tree.GetEntries())) # Object from_tree to access the rootfile information from_tree.set_evt(evt, reco_level, reco_type) # Discard event where one jet is containing only photons and/or no clustered particles if from_tree.get_dim("jet") != 4: continue if not check_content(from_tree): continue #cut masses "similaires" des 2 W #if abs(m_large-m_small)<13: # continue # cut y34 if from_tree.get_y34() <= 0.001: continue #cut energy part chargees < 0.96 * energy jet energyjet1 = from_tree.get_reco_jet1_e() energyjet2 = from_tree.get_reco_jet2_e() energyjet3 = from_tree.get_reco_jet3_e() energyjet4 = from_tree.get_reco_jet4_e() # partchargees=['11','13','211'] energypartchargeesjet1 = from_tree.get_reco_jet1_11_e( ) + from_tree.get_reco_jet1_13_e() + from_tree.get_reco_jet1_211_e() energypartchargeesjet2 = from_tree.get_reco_jet2_11_e( ) + from_tree.get_reco_jet2_13_e() + from_tree.get_reco_jet2_211_e() energypartchargeesjet3 = from_tree.get_reco_jet3_11_e( ) + from_tree.get_reco_jet3_13_e() + from_tree.get_reco_jet3_211_e() energypartchargeesjet4 = from_tree.get_reco_jet4_11_e( ) + from_tree.get_reco_jet4_13_e() + from_tree.get_reco_jet4_211_e() if energypartchargeesjet1 > 0.996 * energyjet1 or energypartchargeesjet2 > 0.996 * energyjet2 or energypartchargeesjet3 > 0.996 * energyjet3 or energypartchargeesjet4 > 0.996 * energyjet4: continue # Jets pvec = [] for part in range(4): njet = str("jet" + str(part + 1)) pvec.append(from_tree.get_p4(njet)) jets = [Jet() for i in range(from_tree.get_dim("jet"))] # Direct reconstruction if reconstruction == "direct": for jid, jet in enumerate(jets): jet.set_id(str("jet" + str(jid + 1))) jet.set_mref(m_w) jet.set_p4(pvec[jid]) # Energy Rescaling else: beta = get_beta_matrix(pvec) energy = energy_from_direction(ecm, beta, from_tree.get_dim("jet")) # discarded events with energy < 0 solutions (no physics) if any(energy < 0): continue # Need to rescale the p4 matrix p4_resc = rescaling_factors.rescale( pvec, rescaling_factors.factor(energy, pvec)) for jid, jet in enumerate(jets): jet.set_id(str("jet" + str(jid + 1))) jet.set_mref(m_w) jet.set_p4(p4_resc[jid]) dijet = get_dijets_pairs(jets) # If the pairing conditions are not full if not dijet: continue #cut energie dijets similaires #diffedjets = return_edijets(dijet) #if diffedjets>=30: continue openingangledj1, openingangledj2 = return_opening_angle(dijet) if openingangledj1 <= 60 or openingangledj2 <= 60 or openingangledj1 >= 145 or openingangledj2 >= 145: continue m_small, m_large = return_mass(dijet) #cut sur la masse de mW1 small mW2 large if m_large <= 70: #or m_small<40: continue #fonction qui rempli les histos fill_histograms(dijet, histdict) #y34=from_tree.get_y34() #treecuts.Fill() y34[0] = from_tree.get_y34() reco_jet1_e[0] = from_tree.get_reco_jet1_e() reco_jet2_e[0] = from_tree.get_reco_jet2_e() reco_jet3_e[0] = from_tree.get_reco_jet3_e() reco_jet4_e[0] = from_tree.get_reco_jet4_e() reco_jet1_px[0] = from_tree.get_reco_jet1_px() reco_jet2_px[0] = from_tree.get_reco_jet2_px() reco_jet3_px[0] = from_tree.get_reco_jet3_px() reco_jet4_px[0] = from_tree.get_reco_jet4_px() reco_jet1_py[0] = from_tree.get_reco_jet1_py() reco_jet2_py[0] = from_tree.get_reco_jet2_py() reco_jet3_py[0] = from_tree.get_reco_jet3_py() reco_jet4_py[0] = from_tree.get_reco_jet4_py() reco_jet1_pz[0] = from_tree.get_reco_jet1_pz() reco_jet2_pz[0] = from_tree.get_reco_jet2_pz() reco_jet3_pz[0] = from_tree.get_reco_jet3_pz() reco_jet4_pz[0] = from_tree.get_reco_jet4_pz() reco_jet_size[0] = from_tree.get_reco_jet_size() quark_size[0] = from_tree.get_quark_size() file_type[0] = float(fileoutput1) quark1_e[0] = from_tree.get_quark1_e() quark2_e[0] = from_tree.get_quark2_e() quark3_e[0] = from_tree.get_quark3_e() quark4_e[0] = from_tree.get_quark4_e() quark1_px[0] = from_tree.get_quark1_px() quark2_px[0] = from_tree.get_quark2_px() quark3_px[0] = from_tree.get_quark3_px() quark4_px[0] = from_tree.get_quark4_px() quark1_py[0] = from_tree.get_quark1_py() quark2_py[0] = from_tree.get_quark2_py() quark3_py[0] = from_tree.get_quark3_py() quark4_py[0] = from_tree.get_quark4_py() quark1_pz[0] = from_tree.get_quark1_pz() quark2_pz[0] = from_tree.get_quark2_pz() quark3_pz[0] = from_tree.get_quark3_pz() quark4_pz[0] = from_tree.get_quark4_pz() gen_jet_size[0] = from_tree.get_gen_jet_size() gen_jet1_e[0] = from_tree.get_gen_jet1_e() gen_jet2_e[0] = from_tree.get_gen_jet2_e() gen_jet3_e[0] = from_tree.get_gen_jet3_e() gen_jet4_e[0] = from_tree.get_gen_jet4_e() gen_jet1_px[0] = from_tree.get_gen_jet1_px() gen_jet2_px[0] = from_tree.get_gen_jet2_px() gen_jet3_px[0] = from_tree.get_gen_jet3_px() gen_jet4_px[0] = from_tree.get_gen_jet4_px() gen_jet1_py[0] = from_tree.get_gen_jet1_py() gen_jet2_py[0] = from_tree.get_gen_jet2_py() gen_jet3_py[0] = from_tree.get_gen_jet3_py() gen_jet4_py[0] = from_tree.get_gen_jet4_py() gen_jet1_pz[0] = from_tree.get_gen_jet1_pz() gen_jet2_pz[0] = from_tree.get_gen_jet2_pz() gen_jet3_pz[0] = from_tree.get_gen_jet3_pz() gen_jet4_pz[0] = from_tree.get_gen_jet4_pz() #print str(quark4_pz[0]) treecut.Fill() f1.cd() f1.Write() f1.Close()