def coefficients(tree, histdict):
    '''Computation of the rescaling coefficient, beta, theta and phi uncertainties'''

    from_tree = TreeInfo()

    # Run on events
    for iev, evt in enumerate(tree):

        if iev % 5000 == 0:
            print("Processing events {} over {}".format(
                iev, tree.GetEntries()))

        # Object from_tree to access the rootfile information
        from_tree.set_evt(evt)

        if from_tree.get_dim("reco_jet") != 2:
            continue
        if from_tree.get_dim("quark") != 2:
            continue
        if from_tree.get_pdgid("reco_lepton") < -90:
            continue

        # if evt.gen_jet2_theta < -1. or evt.gen_jet2_theta > 1.:
        #     continue

        ######### Leptonic part
        g_lepton = Particle(from_tree.get_p4("gen_lepton"))
        r_lepton = Particle(from_tree.get_p4("reco_lepton"))
        if not r_lepton:
            continue

        histdict["h_uncert_energy"].Fill(r_lepton.get_E() - g_lepton.get_E())

        ######## Hadronic part
        partons = [Particle() for i in range(from_tree.get_dim("quark"))]
        for iparton, parton in enumerate(partons):
            nparton = str("quark" + str(iparton + 1))
            parton.set_p4(from_tree.get_p4(nparton))

        gen_jets = [Jet() for i in range(from_tree.get_dim("gen_jet"))]
        for ijet, jet in enumerate(gen_jets):
            njet = str("gen_jet" + str(ijet + 1))
            jet.set_p4(from_tree.get_p4(njet))

        rec_jets = [Jet() for i in range(from_tree.get_dim("reco_jet"))]
        for ijet, jet in enumerate(rec_jets):
            njet = str("reco_jet" + str(ijet + 1))
            jet.set_p4(from_tree.get_p4(njet))

        if not rec_jets:
            continue

        association(partons, rec_jets, gen_jets, histdict)
Ejemplo n.º 2
0
def angle_study(tree, histdict):

    for iev, evt in enumerate(tree):

        if iev % 1000 == 0:
            print("Processing events {} on {} ".format(iev, tree.GetEntries()))

        pvec = get_jets_p4(evt, "gen_jet")
        dim = int(get_jet_dim(evt, "gen_jet"))

        jets = [Jet() for i in range(dim)]
        for jid, jet in enumerate(jets):
            jet.set_id(str(jid + 1))
            jet.set_p4(pvec[jid])

        # Good jet pairing
        dijet12_good = Dijet(jets[0], jets[1])
        dijet34_good = Dijet(jets[2], jets[3])

        histdict["h_angle_goodPairing"].Fill(dijet12_good.get_angle())
        histdict["h_angle_goodPairing"].Fill(dijet34_good.get_angle())

        # Bad Pairing
        dijet13_wrong = Dijet(jets[0], jets[2])
        dijet24_wrong = Dijet(jets[1], jets[3])

        dijet14_wrong = Dijet(jets[0], jets[3])
        dijet23_wrong = Dijet(jets[1], jets[2])

        histdict["h_angle_badPairing"].Fill(dijet13_wrong.get_angle())
        histdict["h_angle_badPairing"].Fill(dijet24_wrong.get_angle())
        histdict["h_angle_badPairing"].Fill(dijet14_wrong.get_angle())
        histdict["h_angle_badPairing"].Fill(dijet23_wrong.get_angle())
def coefficients(tree, histdict, reco_type=''):
    '''Computation of the rescaling coefficient, theta and phi uncertainty'''

    from_tree = TreeInfo()

    # Run on events
    for iev, evt in enumerate(tree):

        if iev < 50000:

            if iev%5000 == 0:
                print("Processing events {} over {}".format(iev, tree.GetEntries()))

            # Object from_tree to access the rootfile information
            from_tree.set_evt(evt)

            if from_tree.get_dim("reco_jet{}".format(reco_type)) != 4:
                continue
            if from_tree.get_dim("quark") != 4:
                continue

            partons = [Particle() for i in range(from_tree.get_dim("quark"))]
            for iparton, parton in enumerate(partons):
                nparton = str("quark" + str(iparton + 1))
                parton.set_p4(from_tree.get_p4(nparton))

            gen_jets = [Jet()for i in range(from_tree.get_dim("gen_jet{}".format(reco_type)))]
            for ijet, jet in enumerate(gen_jets):
                njet = str("gen_jet" + str(ijet + 1) + reco_type)
                if from_tree.get_p4(njet).E() < 0:
                    continue
                jet.set_p4(from_tree.get_p4(njet))

            rec_jets = [Jet()for i in range(from_tree.get_dim("reco_jet{}".format(reco_type)))]
            for ijet, jet in enumerate(rec_jets):
                njet = str("reco_jet" + str(ijet + 1) + reco_type)

                if from_tree.get_p4(njet).E() < 0:
                    continue
                jet.set_p4(from_tree.get_p4(njet))

            if not rec_jets:
                continue

            association(partons, rec_jets, gen_jets, histdict)
        else:
            break
Ejemplo n.º 4
0
def w_mass_semi_leptonic(ecm, tree, histdict, reco_level):
    '''Run over the events and fill the histograms'''

    from_tree = TreeInfo()

    nDiscarded = 0
    for iev, evt in enumerate(tree):

        if iev % 5000 == 0:
            print("Processing event {} on {} ".format(iev, tree.GetEntries()))

        # Object from_tree to access the rootfile information
        from_tree.set_evt(evt, reco_level)

        if from_tree.get_dim("lepton") != 1 or from_tree.get_dim("jet") != 2:
            nDiscarded += 1
            continue

        if not check_jet_compo(from_tree):
            nDiscarded += 1
            continue

        #### Leptonic decay part
        lepton = Particle(from_tree.get_p4("lepton"))
        misenergy = Particle(from_tree.get_p4("misenergy"))

        # Compute W mass from the lepton and the missing energy
        lep_decay = LeptonicDecay(lepton, misenergy)
        lep_decay.set_true_mass(from_tree.get_w_mass("leptonic_W"))
        lep_decay.compute()

        #### hadronic decay part
        jets = [Jet() for i in range(from_tree.get_dim("jet"))]
        for jid, jet in enumerate(jets):
            njet = str("jet" + str(jid + 1))
            jet.set_p4(from_tree.get_p4(njet))

        # Compute W mass from the jet and their angle
        dijet = Dijet(jets[0], jets[1])
        dijet.set_true_mass(from_tree.get_w_mass("hadronic_W"))
        dijet.compute()

        fill_histograms(ecm, histdict, dijet, lep_decay)
    print nDiscarded
Ejemplo n.º 5
0
def energy_jet(tree, histdict, jet_type, outdir):
    '''Energy jet distribution'''

    # Run on events
    for iev, e in enumerate(tree):

        if iev % 1000 == 0:
            print("Processing events {} over {}".format(
                iev, tree.GetEntries()))

        partons = [Parton() for i in range(int(get_parton_dim(e)))]
        for iparton, parton in enumerate(partons):
            parton.set_p4(get_parton_p4(e)[iparton])

        gen_jet = "gen_jet" + jet_type

        p4_gen_jets = get_jets_p4(e, gen_jet)
        gen_jets = [Jet() for i in range(int(get_jet_dim(e, gen_jet)))]
        for ijet, jet in enumerate(gen_jets):
            jet.set_p4(p4_gen_jets[ijet])

            if math.log(jet.get_boost()) == float('inf'):
                _logger.info(
                    "This event contains at least one gen jet with infinity boost (beta = 1) -> Discarded"
                )
                _logger.info("Bad jet with single photon")
                continue

        # elem[0] = reco_jet, elem[1] = parton
        pj_asso = object_association(gen_jets, partons)

        for iel, elem in enumerate(pj_asso):
            histdict['h_jet_energy'].Fill(elem[0].get_E() - elem[1].get_E())

    c_ = TCanvas('c_', '', 700, 500)
    c_.cd()
    histdict["h_jet_energy"].Draw()
    c_.Print("{}.pdf".format(outdir))
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
def coefficients(tree, histdict, reco_type=''):
    '''Computation of the rescaling coefficient, theta and phi uncertainty'''

    from_tree = TreeInfo()

    # Run on events
    for iev, evt in enumerate(tree):

        if iev % 5000 == 0:
            print("Processing events {} over {}".format(
                iev, tree.GetEntries()))

        # Object from_tree to access the rootfile information
        from_tree.set_evt(evt)

        #value for normalisation
        histweight = from_tree.get_file_type()
        if (histweight == 1 or histweight == 2 or histweight == 3):
            print histweight

        #value distinguish ZZllll from ZZqqll from ZZqqqq in ZZall
        ZZqqll = 0
        ZZqqqq = 0
        if (histweight == 3 & from_tree.get_dim("quark") == 2):
            ZZqqll = 1
        if (histweight == 3 & from_tree.get_dim("quark") == 4):
            ZZqqqq = 1
#ecarte les evenements purement leptoniques du background ZZAll
#if (histweight == 3 & from_tree.get_dim("quark") == 0):
#    continue

#if (histweight==0 or histweight ==3):
#if from_tree.get_dim("reco_jet{}".format(reco_type)) != 4:
#    continue
#if(histweight==1 or histweight ==2):
#    if from_tree.get_dim("reco_jet{}".format(reco_type)) != 2:
#        continue

#if from_tree.get_dim("quark") != 4:
#    continue

        partons = [Particle() for i in range(from_tree.get_dim("quark"))]
        #print "range partons "+str(from_tree.get_dim("quark"))
        for iparton, parton in enumerate(partons):
            nparton = str("quark" + str(iparton + 1))
            #print "nparton "+str(nparton)
            parton.set_p4(from_tree.get_p4(nparton))

        gen_jets = [
            Jet()
            for i in range(from_tree.get_dim("gen_jet{}".format(reco_type)))
        ]
        #print "gen_jets"+str(from_tree.get_dim("gen_jet{}".format(reco_type)))
        for ijet, jet in enumerate(gen_jets):
            #print "range ijet "+str(gen_jets)
            njet = str("gen_jet" + str(ijet + 1) + reco_type)
            #print njet
            if from_tree.get_p4(njet).E() < 0:
                continue
            jet.set_p4(from_tree.get_p4(njet))

        rec_jets = [
            Jet()
            for i in range(from_tree.get_dim("reco_jet{}".format(reco_type)))
        ]
        for ijet, jet in enumerate(rec_jets):
            njet = str("reco_jet" + str(ijet + 1) + reco_type)

            if from_tree.get_p4(njet).E() < 0:
                continue
            jet.set_p4(from_tree.get_p4(njet))

        if not rec_jets:
            print "No rec_jets"
            continue

#print iev
        association(partons, rec_jets, gen_jets, histdict, histweight, ZZqqll,
                    ZZqqqq)
Ejemplo n.º 9
0
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()