def mis_energy(tree, histdict):
    '''Read the tree and fill the histogram event per events'''

    count_ISR_evt = 0

    for iev, evt in enumerate(tree):

        # if evt.reco_lepton_size == 0:
        #     continue

        # ISR_evt_flag = False

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

        # jet1_tlv = TLorentzVector(evt.reco_jet1_px, evt.reco_jet1_py, evt.reco_jet1_pz, evt.reco_jet1_e)
        # jet2_tlv = TLorentzVector(evt.reco_jet2_px, evt.reco_jet2_py, evt.reco_jet2_pz, evt.reco_jet2_e)

        # angle_jets = jet1_tlv.Angle(jet2_tlv.Vect())
        # histdict["h_recoJetsAngle"].Fill(angle_jets)
        # histdict["h_recoJetsTheta"].Fill(evt.reco_jet1_theta)
        # histdict["h_recoJetsTheta"].Fill(evt.reco_jet2_theta)
        # histdict["h_recoJetEnergy"].Fill(evt.reco_jet1_e)
        # histdict["h_recoJetEnergy"].Fill(evt.reco_jet2_e)

        lepton_tlv = TLorentzVector(evt.gen_lepton_px, evt.gen_lepton_py,
                                    evt.gen_lepton_pz, evt.gen_lepton_e)

        FSR_ph = zip(elementSelection(evt.fsr_e), elementSelection(evt.fsr_px),
                     elementSelection(evt.fsr_py),
                     elementSelection(evt.fsr_pz))
        for e, px, py, pz in FSR_ph:
            FSR_ph = TLorentzVector(px, py, pz, e)
            p_FSR = FSR_ph.P()
            E_p_FSR = e / p_FSR

            histdict["h_E_p_vs_E_FSR"].Fill(e, E_p_FSR)

            angle = FSR_ph.Angle(lepton_tlv.Vect())
            if e >= 0.2:
                histdict["h_FSR_lepton_angle_vs_E"].Fill(e, angle)

        nonFSR_ph = zip(elementSelection(evt.nonFSRPh_e),
                        elementSelection(evt.nonFSRPh_px),
                        elementSelection(evt.nonFSRPh_py),
                        elementSelection(evt.nonFSRPh_pz))
        for e, px, py, pz in nonFSR_ph:
            nonFSR_ph = TLorentzVector(px, py, pz, e)
            p_nonFSR = nonFSR_ph.P()
            E_p_nonFSR = e / p_nonFSR

            histdict["h_E_p_vs_E_nonFSR"].Fill(e, E_p_nonFSR)

            angle = nonFSR_ph.Angle(lepton_tlv.Vect())
            if e >= 0.2 and angle > 0.02:
                histdict["h_nonFSR_lepton_angle_vs_E"].Fill(e, angle)
Esempio n. 2
0
 def fixMiss(self):
     self.fillUnknowns()
     miss = TLorentzVector(0., 0., 0., 1.)
     for i in range(5):
         miss -= TLorentzVector(self.x[i]*self.beta[i]*sin(self.theta[i])*cos(self.phi[i]), \
                                self.x[i]*self.beta[i]*sin(self.theta[i])*sin(self.phi[i]), \
                                self.x[i]*self.beta[i]*cos(self.theta[i]), \
                                self.x[i])
     self.alpha[5] = miss.E()
     self.alpha[6] = miss.P() / miss.E()
     self.alpha[7] = miss.Theta()
     self.alpha[8] = miss.Phi()
     self.fillUnknowns()
     self.fillConstraints(False)
Esempio n. 3
0
def cosThetaBoost(pa, ida, pb, idb, doflip=False):
   #  http://xrootd.slac.stanford.edu/BFROOT/www/doc/workbook_backup_010108/analysis/analysis.html
   #  A useful quantity in many analyses is the helicity angle.
   #  In the reaction Y . X . a + b, the helicity angle of
   #  particle a is the angle measured in the rest frame of the
   #  deidaying parent particle, X, between the direction of the
   #  deiday daughter a and the direction of the grandparent particle Y.
   pTmp = pa+pb;                     # this is the mumu system (Z) 4vector
   ZboostVector = pTmp.BoostVector() # this is the 3vector of the Z
   p = TLorentzVector(0,0,-1,1)      # this is the muon 4vector
   if  (ida>0): p.SetPxPyPzE(pa.Px(),pa.Py(),pa.Pz(),pa.E())
   else:        p.SetPxPyPzE(pb.Px(),pb.Py(),pb.Pz(),pb.E())
   p.Boost(-ZboostVector) # boost p to the Ditop CM (rest) frame
   cosThetaB = p.Vect()*pTmp.Vect()/(p.P()*pTmp.P())
   if(ySystem(pa,pb)<0. and doflip): cosThetaB *= -1. # reclassify ???
   return cosThetaB
Esempio n. 4
0
def save(f_in, t, cms, mode):
    m_runNo = array('i', [0])
    m_evtNo = array('i', [0])
    m_indexmc = array('i', [0])
    m_trkidx = array('i', 100 * [0])
    m_motheridx = array('i', 100 * [0])
    m_motherid = array('i', 100 * [0])
    m_pdgid = array('i', 100 * [0])
    m_D0_mode = array('d', [0])
    m_D0_type = array('d', [0])
    m_D0_charge = array('i', [0])
    m_D0_charm = array('d', [0])
    m_D0_numofchildren = array('d', [0])
    m_D0_mass = array('d', [0])
    m_p_D0 = array('d', [0])
    m_E_D0 = array('d', [0])
    m_n_D0trks = array('i', [0])
    m_n_D0shws = array('i', [0])
    m_Dm_mode = array('d', [0])
    m_Dm_type = array('d', [0])
    m_Dm_charge = array('i', [0])
    m_Dm_charm = array('d', [0])
    m_Dm_numofchildren = array('d', [0])
    m_Dm_mass = array('d', [0])
    m_p_Dm = array('d', [0])
    m_E_Dm = array('d', [0])
    m_n_Dmtrks = array('i', [0])
    m_n_Dmshws = array('i', [0])
    m_chi2_4c = array('d', [0.])
    m_chi2_vf = array('d', [0.])
    m_m_D0 = array('d', [0])
    m_m_Dm = array('d', [0])
    m_chi2_6c = array('d', [0.])
    m_m_D0Dm = array('d', [0])
    m_m_D0pip = array('d', [0])
    m_m_Dmpip = array('d', [0])
    m_rm_D0pip = array('d', [0])
    m_rm_Dmpip = array('d', [0])
    m_p4_D0 = array('d', 4 * [0])
    m_p4_Dm = array('d', 4 * [0])
    m_p4_pip = array('d', 4 * [0])
    m_Rxy_D0trks = array('d', 10 * [999.])
    m_Rz_D0trks = array('d', 10 * [999.])
    m_cos_D0trks = array('d', 10 * [999.])
    m_E_D0shws = array('d', 10 * [999.])
    m_dang_D0shws = array('d', 10 * [999.])
    m_module_D0shws = array('d', 10 * [999.])
    m_T_D0shws = array('d', 10 * [999.])
    m_Rxy_Dmtrks = array('d', 10 * [999.])
    m_Rz_Dmtrks = array('d', 10 * [999.])
    m_cos_Dmtrks = array('d', 10 * [999.])
    m_E_Dmshws = array('d', 10 * [999.])
    m_dang_Dmshws = array('d', 10 * [999.])
    m_module_Dmshws = array('d', 10 * [999.])
    m_T_Dmshws = array('d', 10 * [999.])
    m_Rxy_pip = array('d', [999.])
    m_Rz_pip = array('d', [999.])
    m_cos_pip = array('d', [999.])
    m_n_pi0 = array('i', [0])
    m_n_othershws = array('i', [0])
    m_matched_D0trks = array('i', [999])
    m_matched_D0shws = array('i', [999])
    m_matched_Dmtrks = array('i', [999])
    m_matched_Dmshws = array('i', [999])
    m_matched_pip = array('i', [999])
    m_m_delta = array('d', [0])
    m_p_pip = array('d', [0])
    m_chi2_svf_D0 = array('d', [999.])
    m_ctau_svf_D0 = array('d', [999.])
    m_L_svf_D0 = array('d', [999.])
    m_Lerr_svf_D0 = array('d', [999.])
    m_Lxy_svf_D0 = array('d', [999.])
    m_chi2_svf_Dm = array('d', [999.])
    m_ctau_svf_Dm = array('d', [999.])
    m_L_svf_Dm = array('d', [999.])
    m_Lerr_svf_Dm = array('d', [999.])
    m_Lxy_svf_Dm = array('d', [999.])
    t.Branch('runNo', m_runNo, 'm_runNo/I')
    t.Branch('evtNo', m_evtNo, 'm_evtNo/I')
    t.Branch('indexmc', m_indexmc, 'indexmc/I')
    t.Branch('trkidx', m_trkidx, 'trkidx[100]/I')
    t.Branch('motheridx', m_motheridx, 'motheridx[100]/I')
    t.Branch('motherid', m_motherid, 'motherid[100]/I')
    t.Branch('pdgid', m_pdgid, 'pdgid[100]/I')
    t.Branch('D0_mode', m_D0_mode, 'm_D0_mode/D')
    t.Branch('D0_type', m_D0_type, 'm_D0_type/D')
    t.Branch('D0_charge', m_D0_charge, 'm_D0_charge/I')
    t.Branch('D0_charm', m_D0_charm, 'm_D0_charm/D')
    t.Branch('D0_numofchildren', m_D0_numofchildren, 'm_D0_numofchildren/D')
    t.Branch('D0_mass', m_D0_mass, 'm_D0_mass/D')
    t.Branch('p_D0', m_p_D0, 'm_p_D0/D')
    t.Branch('E_D0', m_E_D0, 'm_E_D0/D')
    t.Branch('n_D0trks', m_n_D0trks, 'm_n_D0trks/D')
    t.Branch('n_D0shws', m_n_D0shws, 'm_n_D0shws/D')
    t.Branch('Dm_mode', m_Dm_mode, 'm_Dm_mode/D')
    t.Branch('Dm_type', m_Dm_type, 'm_Dm_type/D')
    t.Branch('Dm_charge', m_Dm_charge, 'm_Dm_charge/I')
    t.Branch('Dm_charm', m_Dm_charm, 'm_Dm_charm/D')
    t.Branch('Dm_numofchildren', m_Dm_numofchildren, 'm_Dm_numofchildren/D')
    t.Branch('Dm_mass', m_Dm_mass, 'm_Dm_mass/D')
    t.Branch('p_Dm', m_p_Dm, 'm_p_Dm/D')
    t.Branch('E_Dm', m_E_Dm, 'm_E_Dm/D')
    t.Branch('n_Dmtrks', m_n_Dmtrks, 'm_n_Dmtrks/D')
    t.Branch('n_Dmshws', m_n_Dmshws, 'm_n_Dmshws/D')
    t.Branch('chi2_4c', m_chi2_4c, 'm_chi2_4c/D')
    t.Branch('chi2_vf', m_chi2_vf, 'm_chi2_vf/D')
    t.Branch('m_D0', m_m_D0, 'm_m_D0/D')
    t.Branch('m_Dm', m_m_Dm, 'm_m_Dm/D')
    t.Branch('chi2_6c', m_chi2_6c, 'm_chi2_6c/D')
    t.Branch('m_D0Dm', m_m_D0Dm, 'm_m_D0Dm/D')
    t.Branch('m_D0pip', m_m_D0pip, 'm_m_D0pip/D')
    t.Branch('m_Dmpip', m_m_Dmpip, 'm_m_Dmpip/D')
    t.Branch('rm_D0pip', m_rm_D0pip, 'm_rm_D0pip/D')
    t.Branch('rm_Dmpip', m_rm_Dmpip, 'm_rm_Dmpip/D')
    t.Branch('p4_D0', m_p4_D0, 'm_p4_D0[4]/D')
    t.Branch('p4_Dm', m_p4_Dm, 'm_p4_Dm[4]/D')
    t.Branch('p4_pip', m_p4_pip, 'm_p4_pip[4]/D')
    t.Branch('Rxy_D0trks', m_Rxy_D0trks, 'm_Rxy_D0trks[10]/D')
    t.Branch('Rz_D0trks', m_Rz_D0trks, 'm_Rz_D0trks[10]/D')
    t.Branch('cos_D0trks', m_cos_D0trks, 'm_cos_D0trks[10]/D')
    t.Branch('E_D0shws', m_E_D0shws, 'm_E_D0shws[10]/D')
    t.Branch('dang_D0shws', m_dang_D0shws, 'm_dang_D0shws[10]/D')
    t.Branch('module_D0shws', m_module_D0shws, 'm_module_D0shws[10]/D')
    t.Branch('T_D0shws', m_T_D0shws, 'm_T_D0shws[10]/D')
    t.Branch('Rxy_Dmtrks', m_Rxy_Dmtrks, 'm_Rxy_Dmtrks[10]/D')
    t.Branch('Rz_Dmtrks', m_Rz_Dmtrks, 'm_Rz_Dmtrks[10]/D')
    t.Branch('cos_Dmtrks', m_cos_Dmtrks, 'm_cos_Dmtrks[10]/D')
    t.Branch('E_Dmshws', m_E_Dmshws, 'm_E_Dmshws[10]/D')
    t.Branch('dang_Dmshws', m_dang_Dmshws, 'm_dang_Dmshws[10]/D')
    t.Branch('module_Dmshws', m_module_Dmshws, 'm_module_Dmshws[10]/D')
    t.Branch('T_Dmshws', m_T_Dmshws, 'm_T_Dmshws[10]/D')
    t.Branch('Rxy_pip', m_Rxy_pip, 'm_Rxy_pip/D')
    t.Branch('Rz_pip', m_Rz_pip, 'm_Rz_pip/D')
    t.Branch('cos_pip', m_cos_pip, 'm_cos_pip/D')
    t.Branch('n_pi0', m_n_pi0, 'm_n_pi0/I')
    t.Branch('n_othershws', m_n_othershws, 'm_n_othershws/I')
    t.Branch('matched_D0trks', m_matched_D0trks, 'm_matched_D0trks/I')
    t.Branch('matched_D0shws', m_matched_D0shws, 'm_matched_D0shws/I')
    t.Branch('matched_Dmtrks', m_matched_Dmtrks, 'm_matched_Dmtrks/I')
    t.Branch('matched_Dmshws', m_matched_Dmshws, 'm_matched_Dmshws/I')
    t.Branch('matched_pip', m_matched_pip, 'm_matched_pip/I')
    t.Branch('m_delta', m_m_delta, 'm_m_delta/D')
    t.Branch('p_pip', m_p_pip, 'm_p_pip/D')
    t.Branch('chi2_svf_D0', m_chi2_svf_D0, 'm_chi2_svf_D0/D')
    t.Branch('ctau_svf_D0', m_ctau_svf_D0, 'm_ctau_svf_D0/D')
    t.Branch('L_svf_D0', m_L_svf_D0, 'm_L_svf_D0/D')
    t.Branch('Lerr_svf_D0', m_Lerr_svf_D0, 'm_Lerr_svf_D0/D')
    t.Branch('Lxy_svf_D0', m_Lxy_svf_D0, 'm_Lxy_svf_D0/D')
    t.Branch('chi2_svf_Dm', m_chi2_svf_Dm, 'm_chi2_svf_Dm/D')
    t.Branch('ctau_svf_Dm', m_ctau_svf_Dm, 'm_ctau_svf_Dm/D')
    t.Branch('L_svf_Dm', m_L_svf_Dm, 'm_L_svf_Dm/D')
    t.Branch('Lerr_svf_Dm', m_Lerr_svf_Dm, 'm_Lerr_svf_Dm/D')
    t.Branch('Lxy_svf_Dm', m_Lxy_svf_Dm, 'm_Lxy_svf_Dm/D')
    M_Dm = 1.86965
    M_D0 = 1.86483
    if mode == 'signal': t_dtd = f_in.Get('DTD_signal')
    if mode == 'side1_low': t_dtd = f_in.Get('DTD_side1_low')
    if mode == 'side1_up': t_dtd = f_in.Get('DTD_side1_up')
    if mode == 'side2_low': t_dtd = f_in.Get('DTD_side2_low')
    if mode == 'side2_up': t_dtd = f_in.Get('DTD_side2_up')
    if mode == 'side3_low': t_dtd = f_in.Get('DTD_side3_low')
    if mode == 'side3_up': t_dtd = f_in.Get('DTD_side3_up')
    if mode == 'side4_low': t_dtd = f_in.Get('DTD_side4_low')
    if mode == 'side4_up': t_dtd = f_in.Get('DTD_side4_up')
    nentries = t_dtd.GetEntries()
    for ientry in range(nentries):
        t_dtd.GetEntry(ientry)
        if t_dtd.D0_mode != 0 and t_dtd.D0_mode != 1 and t_dtd.D0_mode != 3:
            continue
        if t_dtd.Dm_mode != 200 and t_dtd.Dm_mode != 201 and t_dtd.Dm_mode != 202 and t_dtd.Dm_mode != 203 and t_dtd.Dm_mode != 204:
            continue
        ppip_raw = TLorentzVector(0, 0, 0, 0)
        ppip_raw.SetPxPyPzE(t_dtd.rawp4_tagPi[0], t_dtd.rawp4_tagPi[1],
                            t_dtd.rawp4_tagPi[2], t_dtd.rawp4_tagPi[3])
        E_Dm = 0
        pDm_raw = TLorentzVector(0, 0, 0, 0)
        m_matched_Dmtrks[0] = 1
        for iTrk in range(t_dtd.n_Dmtrks):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_dtd.rawp4_Dmtrks[iTrk * 8 + 0],
                                  t_dtd.rawp4_Dmtrks[iTrk * 8 + 1],
                                  t_dtd.rawp4_Dmtrks[iTrk * 8 + 2],
                                  t_dtd.rawp4_Dmtrks[iTrk * 8 + 3])
            pDm_raw += ptrack_raw
            E_Dm += t_dtd.rawp4_Dmtrks[iTrk * 8 + 3]
            if not t_dtd.rawp4_Dmtrks[iTrk * 8 + 6] == 1:
                m_matched_Dmtrks[0] = 0
        if t_dtd.n_Dmshws == 0: m_matched_Dmshws[0] = 0
        else: m_matched_Dmshws[0] = 1
        for iShw in range(t_dtd.n_Dmshws):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_dtd.rawp4_Dmshws[iShw * 6 + 0],
                                   t_dtd.rawp4_Dmshws[iShw * 6 + 1],
                                   t_dtd.rawp4_Dmshws[iShw * 6 + 2],
                                   t_dtd.rawp4_Dmshws[iShw * 6 + 3])
            pDm_raw += pshower_raw
            E_Dm += t_dtd.rawp4_Dmshws[iShw * 6 + 3]
            if not t_dtd.rawp4_Dmshws[iShw * 6 + 4] == 1:
                m_matched_Dmshws[0] = 0
        E_D0 = 0
        pD0_raw = TLorentzVector(0, 0, 0, 0)
        m_matched_D0trks[0] = 1
        for iTrk in range(t_dtd.n_D0trks):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_dtd.rawp4_D0trks[iTrk * 8 + 0],
                                  t_dtd.rawp4_D0trks[iTrk * 8 + 1],
                                  t_dtd.rawp4_D0trks[iTrk * 8 + 2],
                                  t_dtd.rawp4_D0trks[iTrk * 8 + 3])
            pD0_raw += ptrack_raw
            E_D0 += t_dtd.rawp4_D0trks[iTrk * 8 + 3]
            if not t_dtd.rawp4_D0trks[iTrk * 8 + 6] == 1:
                m_matched_D0trks[0] = 0
        if t_dtd.n_D0shws == 0: m_matched_D0shws[0] = 0
        else: m_matched_D0shws[0] = 1
        for iShw in range(t_dtd.n_D0shws):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_dtd.rawp4_D0shws[iShw * 6 + 0],
                                   t_dtd.rawp4_D0shws[iShw * 6 + 1],
                                   t_dtd.rawp4_D0shws[iShw * 6 + 2],
                                   t_dtd.rawp4_D0shws[iShw * 6 + 3])
            pD0_raw += pshower_raw
            E_D0 += t_dtd.rawp4_D0shws[iShw * 6 + 3]
            if not t_dtd.rawp4_D0shws[iShw * 6 + 4] == 1:
                m_matched_D0shws[0] = 0
        m_matched_pip[0] = 1
        if not t_dtd.rawp4_tagPi[4] == 1:
            m_matched_pip[0] = 0
        pD0_4c = TLorentzVector(0, 0, 0, 0)
        pDm_4c = TLorentzVector(0, 0, 0, 0)
        ppip_4c = TLorentzVector(0, 0, 0, 0)
        ppip_raw = TLorentzVector(0, 0, 0, 0)
        ppip_raw.SetPxPyPzE(t_dtd.rawp4_tagPi[0], t_dtd.rawp4_tagPi[1],
                            t_dtd.rawp4_tagPi[2], t_dtd.rawp4_tagPi[3])
        pD0_4c.SetPxPyPzE(t_dtd.p4_D0_4c[0], t_dtd.p4_D0_4c[1],
                          t_dtd.p4_D0_4c[2], t_dtd.p4_D0_4c[3])
        pDm_4c.SetPxPyPzE(t_dtd.p4_Dm_4c[0], t_dtd.p4_Dm_4c[1],
                          t_dtd.p4_Dm_4c[2], t_dtd.p4_Dm_4c[3])
        ppip_4c.SetPxPyPzE(t_dtd.p4_pip_4c[0], t_dtd.p4_pip_4c[1],
                           t_dtd.p4_pip_4c[2], t_dtd.p4_pip_4c[3])
        m_runNo[0] = t_dtd.runNo
        m_evtNo[0] = t_dtd.evtNo
        m_indexmc[0] = t_dtd.indexmc
        for i in range(t_dtd.indexmc):
            m_motheridx[i] = t_dtd.motheridx[i]
            m_motherid[i] = t_dtd.motherid[i]
            m_pdgid[i] = t_dtd.pdgid[i]
            m_trkidx[i] = t_dtd.trkidx[i]
        m_D0_mode[0] = t_dtd.D0_mode
        m_D0_type[0] = t_dtd.D0_type
        m_D0_charge[0] = t_dtd.D0_dcharge
        m_D0_charm[0] = t_dtd.D0_charm
        m_D0_numofchildren[0] = t_dtd.D0_numofchildren
        m_D0_mass[0] = t_dtd.D0_mass
        m_p_D0[0] = pD0_raw.P()
        m_E_D0[0] = E_D0
        m_n_D0trks[0] = t_dtd.n_D0trks
        m_n_D0shws[0] = t_dtd.n_D0shws
        m_Dm_mode[0] = t_dtd.Dm_mode
        m_Dm_type[0] = t_dtd.Dm_type
        m_Dm_charge[0] = t_dtd.Dm_dcharge
        m_Dm_charm[0] = t_dtd.Dm_charm
        m_Dm_numofchildren[0] = t_dtd.Dm_numofchildren
        m_Dm_mass[0] = t_dtd.Dm_mass
        m_p_Dm[0] = pDm_raw.P()
        m_E_Dm[0] = E_Dm
        m_n_Dmtrks[0] = t_dtd.n_Dmtrks
        m_n_Dmshws[0] = t_dtd.n_Dmshws
        m_chi2_4c[0] = t_dtd.chisq_4c
        m_m_D0[0] = pD0_4c.M()
        m_m_Dm[0] = pDm_4c.M()
        m_rm_D0pip[0] = (cms - pD0_4c - ppip_4c).M()
        m_rm_Dmpip[0] = (cms - pDm_4c - ppip_4c).M()
        for i in range(4):
            m_p4_D0[i] = t_dtd.p4_D0_6c[i]
            m_p4_Dm[i] = t_dtd.p4_Dm_6c[i]
            m_p4_pip[i] = t_dtd.p4_pip_6c[i]
        m_Rxy_pip[0] = t_dtd.vtx_tagPi[0]
        m_Rz_pip[0] = t_dtd.vtx_tagPi[1]
        m_cos_pip[0] = t_dtd.vtx_tagPi[2]
        for itrk in xrange(t_dtd.n_D0trks):
            m_Rxy_D0trks[itrk] = abs(t_dtd.vtx_D0trks[itrk * 3 + 0])
            m_Rz_D0trks[itrk] = abs(t_dtd.vtx_D0trks[itrk * 3 + 1])
            m_cos_D0trks[itrk] = abs(t_dtd.vtx_D0trks[itrk * 3 + 2])
        for ishw in xrange(t_dtd.n_D0shws):
            m_E_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 0])
            m_dang_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 3])
            m_module_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 4])
            m_T_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 5])
        for itrk in xrange(t_dtd.n_Dmtrks):
            m_Rxy_Dmtrks[itrk] = abs(t_dtd.vtx_Dmtrks[itrk * 3 + 0])
            m_Rz_Dmtrks[itrk] = abs(t_dtd.vtx_Dmtrks[itrk * 3 + 1])
            m_cos_Dmtrks[itrk] = abs(t_dtd.vtx_Dmtrks[itrk * 3 + 2])
        for ishw in xrange(t_dtd.n_Dmshws):
            m_E_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 0])
            m_dang_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 3])
            m_module_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 4])
            m_T_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 5])
        m_n_pi0[0] = t_dtd.n_pi0
        shw_status = True
        n_othershws = 0
        for iShw in range(t_dtd.n_othershws):
            if abs(t_dtd.vtx_othershws[iShw * 6 + 3]) < 10.:
                shw_status = False
            if t_dtd.vtx_othershws[iShw * 6 +
                                   5] < 0. or t_dtd.vtx_othershws[iShw * 6 +
                                                                  5] > 14:
                shw_status = False
            if t_dtd.vtx_othershws[iShw * 6 +
                                   4] == 1 and t_dtd.vtx_othershws[iShw * 6 +
                                                                   0] < 0.025:
                shw_status = False
            if (t_dtd.vtx_othershws[iShw * 6 + 4] == 0
                    or t_dtd.vtx_othershws[iShw * 6 + 4]
                    == 2) and t_dtd.vtx_othershws[iShw * 6 + 0] < 0.05:
                shw_status = False
            if shw_status:
                n_othershws += 1
        m_n_othershws[0] = n_othershws
        D0_W = width('D0')
        Dm_W = width('Dm')
        D0_signal_low = 1.86483 - D0_W / 2.
        D0_signal_up = 1.86483 + D0_W / 2.
        D0_sidebandlow_up = D0_signal_low - D0_W
        D0_sidebandlow_low = D0_signal_low - 2. * D0_W
        D0_sidebandup_low = D0_signal_up + D0_W
        D0_sidebandup_up = D0_signal_up + 2. * D0_W
        Dm_signal_low = 1.86965 - Dm_W / 2.
        Dm_signal_up = 1.86965 + Dm_W / 2.
        Dm_sidebandlow_up = Dm_signal_low - Dm_W
        Dm_sidebandlow_low = Dm_signal_low - 2. * Dm_W
        Dm_sidebandup_low = Dm_signal_up + Dm_W
        Dm_sidebandup_up = Dm_signal_up + 2. * Dm_W
        if mode == 'signal':
            M_D0 = (D0_signal_low + D0_signal_up) / 2.
            M_Dm = (Dm_signal_low + Dm_signal_up) / 2.
        if mode == 'side1_low':
            M_D0 = (D0_signal_low + D0_signal_up) / 2.
            M_Dm = (Dm_sidebandlow_low + Dm_sidebandlow_up) / 2.
        if mode == 'side1_up':
            M_D0 = (D0_signal_low + D0_signal_up) / 2.
            M_Dm = (Dm_sidebandup_low + Dm_sidebandup_up) / 2.
        if mode == 'side2_low':
            M_D0 = (D0_sidebandlow_low + D0_sidebandlow_up) / 2.
            M_Dm = (Dm_signal_low + Dm_signal_up) / 2.
        if mode == 'side2_up':
            M_D0 = (D0_sidebandup_low + D0_sidebandup_up) / 2.
            M_Dm = (Dm_signal_low + Dm_signal_up) / 2.
        if mode == 'side3_low':
            M_D0 = (D0_sidebandlow_low + D0_sidebandlow_up) / 2.
            M_Dm = (Dm_sidebandlow_low + Dm_sidebandlow_up) / 2.
        if mode == 'side3_up':
            M_D0 = (D0_sidebandlow_low + D0_sidebandlow_up) / 2.
            M_Dm = (Dm_sidebandup_low + Dm_sidebandup_up) / 2.
        if mode == 'side4_low':
            M_D0 = (D0_sidebandup_low + D0_sidebandup_up) / 2.
            M_Dm = (Dm_sidebandlow_low + Dm_sidebandlow_up) / 2.
        if mode == 'side4_up':
            M_D0 = (D0_sidebandup_low + D0_sidebandup_up) / 2.
            M_Dm = (Dm_sidebandup_low + Dm_sidebandup_up) / 2.
        m_m_delta[0] = abs(t_dtd.D0_mass - M_D0) + abs(t_dtd.Dm_mass - M_Dm)
        pD0_6c = TLorentzVector(0, 0, 0, 0)
        pDm_6c = TLorentzVector(0, 0, 0, 0)
        ppip_6c = TLorentzVector(0, 0, 0, 0)
        pD0_6c.SetPxPyPzE(t_dtd.p4_D0_6c[0], t_dtd.p4_D0_6c[1],
                          t_dtd.p4_D0_6c[2], t_dtd.p4_D0_6c[3])
        pDm_6c.SetPxPyPzE(t_dtd.p4_Dm_6c[0], t_dtd.p4_Dm_6c[1],
                          t_dtd.p4_Dm_6c[2], t_dtd.p4_Dm_6c[3])
        ppip_6c.SetPxPyPzE(t_dtd.p4_pip_6c[0], t_dtd.p4_pip_6c[1],
                           t_dtd.p4_pip_6c[2], t_dtd.p4_pip_6c[3])
        m_chi2_6c[0] = t_dtd.chisq_6c
        m_chi2_vf[0] = t_dtd.chisq_vf
        m_m_D0Dm[0] = (pD0_6c + pDm_6c).M()
        m_m_D0pip[0] = (pD0_6c + ppip_6c).M()
        m_m_Dmpip[0] = (pDm_6c + ppip_6c).M()
        m_p_pip[0] = ppip_raw.P()
        m_chi2_svf_D0[0] = t_dtd.chisq_svf_D0
        m_ctau_svf_D0[0] = t_dtd.ctau_svf_D0
        m_L_svf_D0[0] = t_dtd.L_svf_D0
        m_Lerr_svf_D0[0] = t_dtd.Lerr_svf_D0
        m_Lxy_svf_D0[0] = sqrt((t_dtd.vtx[0] - t_dtd.cp_D0[0])**2 +
                               (t_dtd.vtx[1] - t_dtd.cp_D0[1])**2)
        m_chi2_svf_Dm[0] = t_dtd.chisq_svf_Dm
        m_ctau_svf_Dm[0] = t_dtd.ctau_svf_Dm
        m_L_svf_Dm[0] = t_dtd.L_svf_Dm
        m_Lerr_svf_Dm[0] = t_dtd.Lerr_svf_Dm
        m_Lxy_svf_Dm[0] = sqrt((t_dtd.vtx[0] - t_dtd.cp_Dm[0])**2 +
                               (t_dtd.vtx[1] - t_dtd.cp_Dm[1])**2)
        t.Fill()
            ntuple=TNtupleD( treeName, 'flat ntuple for roofit', ':'.join(fillNames))
            print ' joint names ' + ':'.join(fillNames) + 'with size = {0}'.format(len(fillNames))

            hists = { fillName : TH1D(treeName+'_'+fillName, fillName, num[0], num[1], num[2]) for fillName, num in fillPars.iteritems() }
            for event in mytree:
                    nCand=event.candSize

                    for i in range(nCand):
                        tk1p4=TLorentzVector(event.tk1P1[i], event.tk1P2[i], event.tk1P3[i], event.tk1P0[i])
                        tk2p4=TLorentzVector(event.tk2P1[i], event.tk2P2[i], event.tk2P3[i], event.tk2P0[i])
                        pmup4=TLorentzVector(event.pmuP1[i], event.pmuP2[i], event.pmuP3[i], event.pmuP0[i])
                        nmup4=TLorentzVector(event.nmuP1[i], event.nmuP2[i], event.nmuP3[i], event.nmuP0[i])
                        mumup4=pmup4+nmup4
                        tktkp4=tk1p4+tk2p4

                        tk1p4.SetE((ptonMass*ptonMass+tk1p4.P()*tk1p4.P())**0.5)
                        tk2p4.SetE((kaonMass*kaonMass+tk2p4.P()*tk2p4.P())**0.5)
                        lbtkp4=tk1p4+tk2p4+pmup4+nmup4
                        tktkp4=tk1p4+tk2p4

                        tk1p4.SetE((kaonMass*kaonMass+tk1p4.P()*tk1p4.P())**0.5)
                        tk2p4.SetE((ptonMass*ptonMass+tk2p4.P()*tk2p4.P())**0.5)
                        lbtkbarp4=tk1p4+tk2p4+pmup4+nmup4
                        tktkbarp4=tk1p4+tk2p4

                        tk1p4.SetE((kaonMass*kaonMass+tk1p4.P()*tk1p4.P())**0.5)
                        tk2p4.SetE((kaonMass*kaonMass+tk2p4.P()*tk2p4.P())**0.5)
                        bsp4=tk1p4+tk2p4+pmup4+nmup4
                        phip4=tk1p4+tk2p4

                        tk1p4.SetE((kaonMass*kaonMass+tk1p4.P()*tk1p4.P())**0.5)
Esempio n. 6
0
    def process(self, event):
        jets = getattr(event, self.cfg_ana.jets)
        lepton = getattr(event, self.cfg_ana.leptons)[0]

        jets_energies = [jet.e() for jet in jets]
        jets_energies.sort()
        max_jet_e = jets_energies[-1]
        min_jet_e = jets_energies[0]

        four_jets_mass = 0.
        min_jets_mass = 0.
        second_min_jets_mass = 0.
        max_jets_mass = 0.

        def invariant_mass(ptc_list):
            totalp4 = TLorentzVector(0., 0., 0., 0.)
            for ptc in ptc_list:
                totalp4 += ptc.p4()
            return totalp4.M()

        four_jets_mass = invariant_mass(jets)

        inv_masses = []
        angles = []

        for combination in combinations(jets, 2):
            aux_m_inv = invariant_mass(combination)
            inv_masses.append(aux_m_inv)
            aux_angle = delta_alpha(combination[0], combination[1])
            angles.append(aux_angle)

        inv_masses.sort(key=lambda x: x)
        min_jets_mass = inv_masses[0]
        second_min_jets_mass = inv_masses[1]
        max_jets_mass = inv_masses[-1]

        angles.sort(key=lambda x: x)
        min_jets_angle = angles[0]
        second_min_jets_angle = angles[1]
        max_jets_angle = angles[-1]

        jets_p4 = TLorentzVector(0., 0., 0., 0.)
        jets_sumpt = 0.
        jets_sump = 0.

        lepton.angle_pt_wrt_jets = []
        for jet in jets:
            lepton.angle_pt_wrt_jets.append(
                (delta_alpha(lepton, jet), pt_wrt_axis(jet.p3(), [lepton])))
            jets_p4 += jet.p4()
            jets_sumpt += jet.p4().Pt()
            jets_sump += jet.p4().P()

        lepton.angle_pt_wrt_jets.sort(key=lambda x: x[0])
        min_jets_lepton_angle = lepton.angle_pt_wrt_jets[0][0]
        second_min_jets_lepton_angle = lepton.angle_pt_wrt_jets[1][0]
        max_jets_lepton_angle = lepton.angle_pt_wrt_jets[-1][0]

        lep_pt_wrt_closest_jet = lepton.angle_pt_wrt_jets[0][1]
        lep_pt_wrt_second_closest_jet = lepton.angle_pt_wrt_jets[1][1]
        lep_pt_wrt_farthest_jet = lepton.angle_pt_wrt_jets[-1][1]

        total_rec_mass = (jets_p4 + lepton.p4()).M()
        jets_vecp_over_sump = jets_p4.P() / jets_sump

        #store variables
        event.max_jet_e = max_jet_e
        event.min_jet_e = min_jet_e

        event.four_jets_mass = four_jets_mass
        event.min_jets_mass = min_jets_mass
        event.second_min_jets_mass = second_min_jets_mass
        event.max_jets_mass = max_jets_mass
        event.min_jets_angle = min_jets_angle
        event.second_min_jets_angle = second_min_jets_angle
        event.max_jets_angle = max_jets_angle

        event.min_jets_lepton_angle = min_jets_lepton_angle
        event.second_min_jets_lepton_angle = second_min_jets_lepton_angle
        event.max_jets_lepton_angle = max_jets_lepton_angle
        event.lep_pt_wrt_closest_jet = lep_pt_wrt_closest_jet
        event.lep_pt_wrt_second_closest_jet = lep_pt_wrt_second_closest_jet
        event.lep_pt_wrt_farthest_jet = lep_pt_wrt_farthest_jet

        event.total_rec_mass = total_rec_mass
        event.jets_sumpt = jets_sumpt
        event.jets_vecp_over_sump = jets_vecp_over_sump
Esempio n. 7
0
for event in events:
    event.getByLabel(label, handle)
    candList = handle.product()
    encodedEffvalueList = handle.product()

    for cand in candList:
        mu1 = cand.daughter(0).daughter(0)
        mu2 = cand.daughter(0).daughter(1)
        tk1 = cand.daughter(1).daughter(0)
        tk2 = cand.daughter(1).daughter(1)
        tlmu1 = TLorentzVector(mu1.px(), mu1.py(), mu1.pz(), mu1.energy())
        tlmu2 = TLorentzVector(mu2.px(), mu2.py(), mu2.pz(), mu2.energy())
        tltk1 = TLorentzVector(tk1.px(), tk1.py(), tk1.pz(), tk1.energy())
        tltk2 = TLorentzVector(tk2.px(), tk2.py(), tk2.pz(), tk2.energy())
        tltk1.SetE((tltk1.P()**2 + 0.493677**2)**0.5)
        tltk2.SetE((tltk2.P()**2 + 0.9382720813**2)**0.5)
        reassignMass = (tlmu1 + tlmu2 + tltk1 + tltk2).Mag()
        distFromCent1 = abs(cand.mass() - 5.619)
        distFromCent2 = abs(reassignMass - 5.619)

        if distFromCent1 < 0.015 and distFromCent2 < 0.015:
            pass
        #elif distFromCent1<distFromCent2:
        #    hMass.Fill(cand.mass())
        #elif distFromCent1>distFromCent2:
        #    hMass.Fill(reassignMass)
        elif tk1.pt() > tk2.pt() and distFromCent1 < distFromCent2:
            hMass.Fill(cand.mass())
        elif tk1.pt() < tk2.pt() and distFromCent1 > distFromCent2:
            hMass.Fill(reassignMass)
Esempio n. 8
0
        hyp = deu + p + pi

        decay_lenght = TVector3(sim.fDecayVtxX, sim.fDecayVtxY, sim.fDecayVtxZ)
        dl = decay_lenght.Mag()

        if hyp.Gamma() == 0 or hyp.Beta() == 0:
            continue

        ct = dl / (hyp.Gamma() * hyp.Beta())

        if hyp.Pt() < 1. or hyp.Pt() > 10.:
            continue

        hist_ctsim.Fill(ct)
        hist_ptsim.Fill(hyp.Pt())
        hist_psim.Fill(hyp.P())
        hist_etasim.Fill(hyp.Eta())
        hist_phisim.Fill(hyp.Phi())

        # rec - sim diff
        # if sim.fRecoIndex >= 0:
        #     r = ev.RHypertriton[sim.fRecoIndex]

        #     hyp_rec = TLorentzVector()
        #     deu_rec = TLorentzVector()
        #     p_rec = TLorentzVector()
        #     pi_rec = TLorentzVector()

        #     deu_rec.SetXYZM(r.fPxDeu, r.fPyDeu, r.fPzDeu, AliPID.ParticleMass(AliPID.kDeuteron))
        #     p_rec.SetXYZM(r.fPxP, r.fPyP, r.fPzP, AliPID.ParticleMass(AliPID.kProton))
        #     pi_rec.SetXYZM(r.fPxPi, r.fPyPi, r.fPzPi, AliPID.ParticleMass(AliPID.kPion))
Esempio n. 9
0
def save_raw(f_in, cms, t, D_sample):
    m_runNo = array('i', [0])
    m_evtNo = array('i', [0])
    m_mode = array('i', [0])
    m_charm = array('i', [0])
    m_charge_pi = array('d', [999.])
    m_rawm_D = array('d', [999.])
    m_m_D = array('d', [999.])
    m_p_D = array('d', [999.])
    m_E_D = array('d', [999.])
    m_rm_D = array('d', [999.])
    m_rm2_D = array('d', [999.])
    m_m_Dpi = array('d', [999.])
    m_m2_Dpi = array('d', [999.])
    m_rm_Dpi = array('d', [999.])
    m_rm_pi = array('d', [999.])
    m_chi2_vf = array('d', [999.])
    m_chi2_kf = array('d', [999.])
    m_n_othershws = array('i', [0])
    m_n_othertrks = array('i', [0])
    m_chi2_pi0 = array('d', [999.])
    m_m_Dpi0 = array('d', [999.])
    m_rm_Dpi0 = array('d', [999.])
    m_n_pi0 = array('i', [0])
    m_indexmc = array('i', [0])
    m_motheridx = array('i', 100*[0])
    m_pdgid = array('i', 100*[0])
    t.Branch('runNo', m_runNo, 'm_runNo/I')
    t.Branch('evtNo', m_evtNo, 'm_evtNo/I')
    t.Branch('mode', m_mode, 'm_mode/I')
    t.Branch('charm', m_charm, 'm_charm/I')
    t.Branch('charge_pi', m_charge_pi, 'm_charge_pi/D')
    t.Branch('rawm_D', m_rawm_D, 'm_rawm_D/D')
    t.Branch('m_D', m_m_D, 'm_m_D/D')
    t.Branch('p_D', m_p_D, 'm_p_D/D')
    t.Branch('E_D', m_E_D, 'm_E_D/D')
    t.Branch('rm_D', m_rm_D, 'm_rm_D/D')
    t.Branch('rm2_D', m_rm2_D, 'm_rm2_D/D')
    t.Branch('m_Dpi', m_m_Dpi, 'm_m_Dpi/D')
    t.Branch('m2_Dpi', m_m2_Dpi, 'm_m2_Dpi/D')
    t.Branch('rm_Dpi', m_rm_Dpi, 'm_rm_Dpi/D')
    t.Branch('rm_pi', m_rm_pi, 'm_rm_pi/D')
    t.Branch('chi2_vf', m_chi2_vf, 'm_chi2_vf/D')
    t.Branch('chi2_kf', m_chi2_kf, 'm_chi2_kf/D')
    t.Branch('n_othertrks', m_n_othertrks, 'm_n_othertrks/I')
    t.Branch('n_othershws', m_n_othershws, 'm_n_othershws/I')
    t.Branch('chi2_pi0', m_chi2_pi0, 'm_chi2_pi0/D')
    t.Branch('m_Dpi0', m_m_Dpi0, 'm_m_Dpi0/D')
    t.Branch('rm_Dpi0', m_rm_Dpi0, 'm_rm_Dpi0/D')
    t.Branch('n_pi0', m_n_pi0, 'm_n_pi0/I')
    t.Branch('indexmc', m_indexmc, 'indexmc/I')
    t.Branch('motheridx', m_motheridx, 'motheridx[100]/I')
    t.Branch('pdgid', m_pdgid, 'pdgid[100]/I')
    t_std = f_in.Get('STD')
    nentries = t_std.GetEntries()
    for ientry in range(nentries):
        t_std.GetEntry(ientry)
        if t_std.mode != 200 and t_std.mode != 0 and t_std.mode != 1 and t_std.mode != 3:
            continue
        pD_raw = TLorentzVector(0, 0, 0, 0)
        pD = TLorentzVector(0, 0, 0, 0)
        for iTrk in range(t_std.n_trkD):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk*6+0], t_std.rawp4_Dtrk[iTrk*6+1], t_std.rawp4_Dtrk[iTrk*6+2], t_std.rawp4_Dtrk[iTrk*6+3])
            ptrack.SetPxPyPzE(t_std.p4_Dtrk[iTrk*4+0], t_std.p4_Dtrk[iTrk*4+1], t_std.p4_Dtrk[iTrk*4+2], t_std.p4_Dtrk[iTrk*4+3])
            pD_raw += ptrack_raw
            pD += ptrack
        for iShw in range(t_std.n_shwD):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_std.rawp4_Dshw[iShw*4+0], t_std.rawp4_Dshw[iShw*4+1], t_std.rawp4_Dshw[iShw*4+2], t_std.rawp4_Dshw[iShw*4+3])
            pshower.SetPxPyPzE(t_std.p4_Dshw[iShw*4+0], t_std.p4_Dshw[iShw*4+1], t_std.p4_Dshw[iShw*4+2], t_std.p4_Dshw[iShw*4+3])
            pD_raw += pshower_raw
            pD += pshower
        pPi = TLorentzVector(0,0,0,0)
        for trk in range(t_std.n_othertrks):
            if abs(t_std.rawp4_otherMdcKaltrk[trk*6+4]) != 1:
                continue
            if t_std.rawp4_otherMdcKaltrk[trk*6+5] != 2:
                continue
            pPi.SetPxPyPzE(t_std.rawp4_otherMdcKaltrk[trk*6+0], t_std.rawp4_otherMdcKaltrk[trk*6+1], t_std.rawp4_otherMdcKaltrk[trk*6+2], t_std.rawp4_otherMdcKaltrk[trk*6+3])
            pPi0 = TLorentzVector(0, 0, 0, 0)
            pPi0.SetPxPyPzE(t_std.p4_pi0_save[0], t_std.p4_pi0_save[1], t_std.p4_pi0_save[2], t_std.p4_pi0_save[3])
            if D_sample == 'Dplus' and t_std.mode == 200:
                if ((t_std.charm == 1 and t_std.rawp4_otherMdcKaltrk[trk*6+4] == -1) or (t_std.charm == -1 and t_std.rawp4_otherMdcKaltrk[trk*6+4] == 1)):
                    m_runNo[0] = t_std.runNo
                    m_evtNo[0] = t_std.evtNo
                    m_mode[0] = t_std.mode
                    m_charm[0] = t_std.charm
                    m_charge_pi[0] = t_std.rawp4_otherMdcKaltrk[trk*6+4]
                    m_rawm_D[0] = pD_raw.M()
                    m_m_D[0] = pD.M()
                    m_p_D[0] = pD.P()
                    m_E_D[0] = pD.E()
                    m_rm_D[0] = (cms-pD).M()
                    m_rm2_D[0] = (cms-pD).M2()
                    m_m_Dpi[0] = (pD+pPi).M()
                    m_m2_Dpi[0] = (pD+pPi).M2()
                    m_rm_Dpi[0] = (cms-pD-pPi).M()
                    m_rm_pi[0] = (cms-pPi).M()
                    m_chi2_vf[0] = t_std.chi2_vf
                    m_chi2_kf[0] = t_std.chi2_kf
                    m_chi2_pi0[0] = t_std.chi2_pi0_save
                    m_Dpi0 = 999.
                    rm_Dpi0 = 999.
                    if pPi0.M() > 0:
                        m_Dpi0 = (pD+pPi0).M()
                        rm_Dpi0 = (cms-pD-pPi0).M()
                    m_m_Dpi0[0] = m_Dpi0
                    m_rm_Dpi0[0] = rm_Dpi0
                    m_n_pi0[0] = t_std.n_pi0
                    m_n_othershws[0] = t_std.n_othershws
                    m_n_othertrks[0] = t_std.n_othertrks
                    m_indexmc[0] = t_std.indexmc
                    for i in range(t_std.indexmc):
                        m_motheridx[i] = t_std.motheridx[i]
                        m_pdgid[i] = t_std.pdgid[i]
                    t.Fill()
            if D_sample == 'D0' and (t_std.mode == 0 or t_std.mode == 1 or t_std.mode == 3):
                if (t_std.charm == 1 and t_std.rawp4_otherMdcKaltrk[trk*6+4] == 1) or (t_std.charm == -1 and t_std.rawp4_otherMdcKaltrk[trk*6+4] == -1):
                    m_runNo[0] = t_std.runNo
                    m_evtNo[0] = t_std.evtNo
                    m_mode[0] = t_std.mode
                    m_charm[0] = t_std.charm
                    m_charge_pi[0] = t_std.rawp4_otherMdcKaltrk[trk*6+4]
                    m_rawm_D[0] = pD_raw.M()
                    m_m_D[0] = pD.M()
                    m_p_D[0] = pD.P()
                    m_E_D[0] = pD.E()
                    m_rm_D[0] = (cms-pD).M()
                    m_rm2_D[0] = (cms-pD).M2()
                    m_m_Dpi[0] = (pD+pPi).M()
                    m_m2_Dpi[0] = (pD+pPi).M2()
                    m_rm_Dpi[0] = (cms-pD-pPi).M()
                    m_rm_pi[0] = (cms-pPi).M()
                    m_chi2_vf[0] = t_std.chi2_vf
                    m_chi2_kf[0] = t_std.chi2_kf
                    m_chi2_pi0[0] = t_std.chi2_pi0_save
                    m_Dpi0 = 999.
                    rm_Dpi0 = 999.
                    if pPi0.M() > 0:
                        m_Dpi0 = (pD+pPi0).M()
                        rm_Dpi0 = (cms-pD-pPi0).M()
                    m_m_Dpi0[0] = m_Dpi0
                    m_rm_Dpi0[0] = rm_Dpi0
                    m_n_pi0[0] = t_std.n_pi0
                    m_n_othershws[0] = t_std.n_othershws
                    m_n_othertrks[0] = t_std.n_othertrks
                    m_indexmc[0] = t_std.indexmc
                    for i in range(t_std.indexmc):
                        m_motheridx[i] = t_std.motheridx[i]
                        m_pdgid[i] = t_std.pdgid[i]
                    t.Fill()
Esempio n. 10
0
def save_missing(f_in, cms, t, D_sample, D_type, sample_type):
    m_runNo = array('i', [0])
    m_evtNo = array('i', [0])
    m_mode = array('i', [0])
    m_charm = array('i', [0])
    m_rawm_D = array('d', [999.])
    m_p4_D = array('d', 4*[999.])
    m_p4_Dbar = array('d', 4*[999.])
    m_p4_pi = array('d', 4*[999.])
    m_m_D = array('d', [999.])
    m_p_D = array('d', [999.])
    m_E_D = array('d', [999.])
    m_rm_D = array('d', [999.])
    m_rm_Dmiss = array('d', [999.])
    m_rm2_D = array('d', [999.])
    m_m_Dpi = array('d', [999.])
    m_m_Dmisspi = array('d', [999.])
    m_m2_Dpi = array('d', [999.])
    m_rm_Dpi = array('d', [999.])
    m_rm_Dmisspi = array('d', [999.])
    m_rm_pi = array('d', [999.])
    m_chi2_vf = array('d', [999.])
    m_chi2_kf = array('d', [999.])
    m_chi2_pi0 = array('d', [999.])
    m_m_Dpi0 = array('d', [999.])
    m_rm_Dpi0 = array('d', [999.])
    m_m_Dmisspi0 = array('d', [999.])
    m_rm_Dmisspi0 = array('d', [999.])
    m_n_pi0 = array('i', [0])
    m_n_othershws = array('i', [0])
    m_n_othertrks = array('i', [0])
    m_indexmc = array('i', [0])
    m_motheridx = array('i', 100*[0])
    m_pdgid = array('i', 100*[0])
    m_p4_pi_MCTruth = array('d', 4*[0])
    m_p4_D_MCTruth = array('d', 4*[0])
    m_p4_Dbar_MCTruth = array('d', 4*[0])
    m_rm_pi_MCTruth = array('d', [999.])
    m_rm_D_MCTruth = array('d', [999.])
    m_m_Dpi_MCTruth = array('d', [999.])
    if D_sample == 'Dplus' and D_type == 'D' and sample_type == 'signal':
        m_p_pi = array('d', [999.])
        m_charge_pi = array('d', [999.])
        m_costheta_pi = array('d', [999.])
        m_phi_pi = array('d', [999.])
        m_chi_e_pi = array('d', [999.])
        m_chi_mu_pi = array('d', [999.])
        m_chi_pi_pi = array('d', [999.])
        m_chi_K_pi = array('d', [999.])
        m_chi_p_pi = array('d', [999.])
        m_prob_e_pi = array('d', [999.])
        m_prob_mu_pi = array('d', [999.])
        m_prob_pi_pi = array('d', [999.])
        m_prob_K_pi = array('d', [999.])
        m_prob_p_pi = array('d', [999.])
        m_p_DK = array('d', [999.])
        m_charge_DK = array('d', [999.])
        m_costheta_DK = array('d', [999.])
        m_phi_DK = array('d', [999.])
        m_chi_e_DK = array('d', [999.])
        m_chi_mu_DK = array('d', [999.])
        m_chi_pi_DK = array('d', [999.])
        m_chi_K_DK = array('d', [999.])
        m_chi_p_DK = array('d', [999.])
        m_prob_e_DK = array('d', [999.])
        m_prob_mu_DK = array('d', [999.])
        m_prob_pi_DK = array('d', [999.])
        m_prob_K_DK = array('d', [999.])
        m_prob_p_DK = array('d', [999.])
        m_p_Dpi1 = array('d', [999.])
        m_charge_Dpi1 = array('d', [999.])
        m_costheta_Dpi1 = array('d', [999.])
        m_phi_Dpi1 = array('d', [999.])
        m_chi_e_Dpi1 = array('d', [999.])
        m_chi_mu_Dpi1 = array('d', [999.])
        m_chi_pi_Dpi1 = array('d', [999.])
        m_chi_K_Dpi1 = array('d', [999.])
        m_chi_p_Dpi1 = array('d', [999.])
        m_prob_e_Dpi1 = array('d', [999.])
        m_prob_mu_Dpi1 = array('d', [999.])
        m_prob_pi_Dpi1 = array('d', [999.])
        m_prob_K_Dpi1 = array('d', [999.])
        m_prob_p_Dpi1 = array('d', [999.])
        m_p_Dpi2 = array('d', [999.])
        m_charge_Dpi2 = array('d', [999.])
        m_costheta_Dpi2 = array('d', [999.])
        m_phi_Dpi2 = array('d', [999.])
        m_chi_e_Dpi2 = array('d', [999.])
        m_chi_mu_Dpi2 = array('d', [999.])
        m_chi_pi_Dpi2 = array('d', [999.])
        m_chi_K_Dpi2 = array('d', [999.])
        m_chi_p_Dpi2 = array('d', [999.])
        m_prob_e_Dpi2 = array('d', [999.])
        m_prob_mu_Dpi2 = array('d', [999.])
        m_prob_pi_Dpi2 = array('d', [999.])
        m_prob_K_Dpi2 = array('d', [999.])
        m_prob_p_Dpi2 = array('d', [999.])
    t.Branch('runNo', m_runNo, 'm_runNo/I')
    t.Branch('evtNo', m_evtNo, 'm_evtNo/I')
    t.Branch('mode', m_mode, 'm_mode/I')
    t.Branch('charm', m_charm, 'm_charm/I')
    t.Branch('rawm_D', m_rawm_D, 'm_rawm_D/D')
    t.Branch('p4_D', m_p4_D, 'm_p4_D[4]/D')
    t.Branch('p4_Dbar', m_p4_Dbar, 'm_p4_Dbar[4]/D')
    t.Branch('p4_pi', m_p4_pi, 'm_p4_pi[4]/D')
    t.Branch('m_D', m_m_D, 'm_m_D/D')
    t.Branch('p_D', m_p_D, 'm_p_D/D')
    t.Branch('E_D', m_E_D, 'm_E_D/D')
    t.Branch('rm_D', m_rm_D, 'm_rm_D/D')
    t.Branch('rm_Dmiss', m_rm_Dmiss, 'm_rm_Dmiss/D')
    t.Branch('rm2_D', m_rm2_D, 'm_rm2_D/D')
    t.Branch('m_Dpi', m_m_Dpi, 'm_m_Dpi/D')
    t.Branch('m_Dmisspi', m_m_Dmisspi, 'm_m_Dmisspi/D')
    t.Branch('m2_Dpi', m_m2_Dpi, 'm_m2_Dpi/D')
    t.Branch('rm_Dpi', m_rm_Dpi, 'm_rm_Dpi/D')
    t.Branch('rm_Dmisspi', m_rm_Dmisspi, 'm_rm_Dmisspi/D')
    t.Branch('rm_pi', m_rm_pi, 'm_rm_pi/D')
    t.Branch('chi2_vf', m_chi2_vf, 'm_chi2_vf/D')
    t.Branch('chi2_kf', m_chi2_kf, 'm_chi2_kf/D')
    t.Branch('chi2_pi0', m_chi2_pi0, 'm_chi2_pi0/D')
    t.Branch('m_Dpi0', m_m_Dpi0, 'm_m_Dpi0/D')
    t.Branch('rm_Dpi0', m_rm_Dpi0, 'm_rm_Dpi0/D')
    t.Branch('m_Dmisspi0', m_m_Dmisspi0, 'm_m_Dmisspi0/D')
    t.Branch('rm_Dmisspi0', m_rm_Dmisspi0, 'm_rm_Dmisspi0/D')
    t.Branch('n_pi0', m_n_pi0, 'm_n_pi0/I')
    t.Branch('n_othertrks', m_n_othertrks, 'm_n_othertrks/I')
    t.Branch('n_othershws', m_n_othershws, 'm_n_othershws/I')
    t.Branch('indexmc', m_indexmc, 'indexmc/I')
    t.Branch('motheridx', m_motheridx, 'motheridx[100]/I')
    t.Branch('pdgid', m_pdgid, 'pdgid[100]/I')
    t.Branch('p4_pi_MCTruth', m_p4_pi_MCTruth, 'm_p4_pi_MCTruth[4]/D')
    t.Branch('p4_D_MCTruth', m_p4_D_MCTruth, 'm_p4_D_MCTruth[4]/D')
    t.Branch('p4_Dbar_MCTruth', m_p4_Dbar_MCTruth, 'm_p4_Dbar_MCTruth[4]/D')
    t.Branch('rm_pi_MCTruth', m_rm_pi_MCTruth, 'm_rm_pi_MCTruth/D')
    t.Branch('rm_D_MCTruth', m_rm_D_MCTruth, 'm_rm_D_MCTruth/D')
    t.Branch('m_Dpi_MCTruth', m_m_Dpi_MCTruth, 'm_m_Dpi_MCTruth/D')
    if D_sample == 'Dplus' and D_type == 'D' and sample_type == 'signal':
        t.Branch('p_pi', m_p_pi, 'm_p_pi/D')
        t.Branch('charge_pi', m_charge_pi, 'm_charge_pi/D')
        t.Branch('costheta_pi', m_costheta_pi, 'm_costheta_pi/D')
        t.Branch('phi_pi', m_phi_pi, 'm_phi_pi/D')
        t.Branch('chi_e_pi', m_chi_e_pi, 'm_chi_e_pi/D')
        t.Branch('chi_mu_pi', m_chi_mu_pi, 'm_chi_mu_pi/D')
        t.Branch('chi_pi_pi', m_chi_pi_pi, 'm_chi_pi_pi/D')
        t.Branch('chi_K_pi', m_chi_K_pi, 'm_chi_K_pi/D')
        t.Branch('chi_p_pi', m_chi_p_pi, 'm_chi_p_pi/D')
        t.Branch('prob_e_pi', m_prob_e_pi, 'm_prob_e_pi/D')
        t.Branch('prob_mu_pi', m_prob_mu_pi, 'm_prob_mu_pi/D')
        t.Branch('prob_pi_pi', m_prob_pi_pi, 'm_prob_pi_pi/D')
        t.Branch('prob_K_pi', m_prob_K_pi, 'm_prob_K_pi/D')
        t.Branch('prob_p_pi', m_prob_p_pi, 'm_prob_p_pi/D')
        t.Branch('p_DK', m_p_DK, 'm_p_DK/D')
        t.Branch('charge_DK', m_charge_DK, 'm_charge_DK/D')
        t.Branch('costheta_DK', m_costheta_DK, 'm_costheta_DK/D')
        t.Branch('phi_DK', m_phi_DK, 'm_phi_DK/D')
        t.Branch('chi_e_DK', m_chi_e_DK, 'm_chi_e_DK/D')
        t.Branch('chi_mu_DK', m_chi_mu_DK, 'm_chi_mu_DK/D')
        t.Branch('chi_pi_DK', m_chi_pi_DK, 'm_chi_pi_DK/D')
        t.Branch('chi_K_DK', m_chi_K_DK, 'm_chi_K_DK/D')
        t.Branch('chi_p_DK', m_chi_p_DK, 'm_chi_p_DK/D')
        t.Branch('prob_e_DK', m_prob_e_DK, 'm_prob_e_DK/D')
        t.Branch('prob_mu_DK', m_prob_mu_DK, 'm_prob_mu_DK/D')
        t.Branch('prob_pi_DK', m_prob_pi_DK, 'm_prob_pi_DK/D')
        t.Branch('prob_K_DK', m_prob_K_DK, 'm_prob_K_DK/D')
        t.Branch('prob_p_DK', m_prob_p_DK, 'm_prob_p_DK/D')
        t.Branch('p_Dpi1', m_p_Dpi1, 'm_p_Dpi1/D')
        t.Branch('charge_Dpi1', m_charge_Dpi1, 'm_charge_Dpi1/D')
        t.Branch('costheta_Dpi1', m_costheta_Dpi1, 'm_costheta_Dpi1/D')
        t.Branch('phi_Dpi1', m_phi_Dpi1, 'm_phi_Dpi1/D')
        t.Branch('chi_e_Dpi1', m_chi_e_Dpi1, 'm_chi_e_Dpi1/D')
        t.Branch('chi_mu_Dpi1', m_chi_mu_Dpi1, 'm_chi_mu_Dpi1/D')
        t.Branch('chi_pi_Dpi1', m_chi_pi_Dpi1, 'm_chi_pi_Dpi1/D')
        t.Branch('chi_K_Dpi1', m_chi_K_Dpi1, 'm_chi_K_Dpi1/D')
        t.Branch('chi_p_Dpi1', m_chi_p_Dpi1, 'm_chi_p_Dpi1/D')
        t.Branch('prob_e_Dpi1', m_prob_e_Dpi1, 'm_prob_e_Dpi1/D')
        t.Branch('prob_mu_Dpi1', m_prob_mu_Dpi1, 'm_prob_mu_Dpi1/D')
        t.Branch('prob_pi_Dpi1', m_prob_pi_Dpi1, 'm_prob_pi_Dpi1/D')
        t.Branch('prob_K_Dpi1', m_prob_K_Dpi1, 'm_prob_K_Dpi1/D')
        t.Branch('prob_p_Dpi1', m_prob_p_Dpi1, 'm_prob_p_Dpi1/D')
        t.Branch('p_Dpi2', m_p_Dpi2, 'm_p_Dpi2/D')
        t.Branch('charge_Dpi2', m_charge_Dpi2, 'm_charge_Dpi2/D')
        t.Branch('costheta_Dpi2', m_costheta_Dpi2, 'm_costheta_Dpi2/D')
        t.Branch('phi_Dpi2', m_phi_Dpi2, 'm_phi_Dpi2/D')
        t.Branch('chi_e_Dpi2', m_chi_e_Dpi2, 'm_chi_e_Dpi2/D')
        t.Branch('chi_mu_Dpi2', m_chi_mu_Dpi2, 'm_chi_mu_Dpi2/D')
        t.Branch('chi_pi_Dpi2', m_chi_pi_Dpi2, 'm_chi_pi_Dpi2/D')
        t.Branch('chi_K_Dpi2', m_chi_K_Dpi2, 'm_chi_K_Dpi2/D')
        t.Branch('chi_p_Dpi2', m_chi_p_Dpi2, 'm_chi_p_Dpi2/D')
        t.Branch('prob_e_Dpi2', m_prob_e_Dpi2, 'm_prob_e_Dpi2/D')
        t.Branch('prob_mu_Dpi2', m_prob_mu_Dpi2, 'm_prob_mu_Dpi2/D')
        t.Branch('prob_pi_Dpi2', m_prob_pi_Dpi2, 'm_prob_pi_Dpi2/D')
        t.Branch('prob_K_Dpi2', m_prob_K_Dpi2, 'm_prob_K_Dpi2/D')
        t.Branch('prob_p_Dpi2', m_prob_p_Dpi2, 'm_prob_p_Dpi2/D')
    if D_type == 'D' and sample_type == 'signal':
        t_std = f_in.Get('STDDmiss_sig_D')
    elif D_type == 'Dst' and sample_type == 'signal':
        t_std = f_in.Get('STDDmiss_sig_Dst')
    elif D_type == 'D' and sample_type == 'background':
        t_std = f_in.Get('STDDmiss_bkg_D')
    elif D_type == 'Dst' and sample_type == 'background':
        t_std = f_in.Get('STDDmiss_bkg_Dst')
    nentries = t_std.GetEntries()
    for ientry in range(nentries):
        t_std.GetEntry(ientry)
        if t_std.mode != 200 and t_std.mode != 0 and t_std.mode != 1 and t_std.mode != 3:
            continue
        pD_raw = TLorentzVector(0, 0, 0, 0)
        pD = TLorentzVector(0, 0, 0, 0)
        pKpi = TLorentzVector(0, 0, 0, 0)
        tag = 0
        for iTrk in range(t_std.n_trkD):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk*6+0], t_std.rawp4_Dtrk[iTrk*6+1], t_std.rawp4_Dtrk[iTrk*6+2], t_std.rawp4_Dtrk[iTrk*6+3])
            ptrack.SetPxPyPzE(t_std.p4_Dtrk[iTrk*4+0], t_std.p4_Dtrk[iTrk*4+1], t_std.p4_Dtrk[iTrk*4+2], t_std.p4_Dtrk[iTrk*4+3])
            pD_raw += ptrack_raw
            pD += ptrack
            ptrack_Kpi = TLorentzVector(0, 0, 0, 0)
            if t_std.rawp4_Dtrk[iTrk*6+4] == 1 and t_std.rawp4_Dtrk[iTrk*6+5] == 3 and t_std.mode == 200:
                ptrack_Kpi.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk*6+0], t_std.rawp4_Dtrk[iTrk*6+1], t_std.rawp4_Dtrk[iTrk*6+2], t_std.rawp4_Dtrk[iTrk*6+3])
                pKpi += ptrack_Kpi
            if t_std.rawp4_Dtrk[iTrk*6+4] == -1 and t_std.rawp4_Dtrk[iTrk*6+5] == 3 and t_std.mode == 200:
                ptrack_Kpi.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk*6+0], t_std.rawp4_Dtrk[iTrk*6+1], t_std.rawp4_Dtrk[iTrk*6+2], t_std.rawp4_Dtrk[iTrk*6+3])
                pKpi += ptrack_Kpi
            if t_std.rawp4_Dtrk[iTrk*6+5] == 2 and t_std.mode == 200 and tag == 0:
                tag = 1
                ptrack_Kpi.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk*6+0], t_std.rawp4_Dtrk[iTrk*6+1], t_std.rawp4_Dtrk[iTrk*6+2], t_std.rawp4_Dtrk[iTrk*6+3])
                pKpi += ptrack_Kpi
        for iShw in range(t_std.n_shwD):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_std.rawp4_Dshw[iShw*4+0], t_std.rawp4_Dshw[iShw*4+1], t_std.rawp4_Dshw[iShw*4+2], t_std.rawp4_Dshw[iShw*4+3])
            pshower.SetPxPyPzE(t_std.p4_Dshw[iShw*4+0], t_std.p4_Dshw[iShw*4+1], t_std.p4_Dshw[iShw*4+2], t_std.p4_Dshw[iShw*4+3])
            pD_raw += pshower_raw
            pD += pshower
        pPi = TLorentzVector(0,0,0,0)
        pPi.SetPxPyPzE(t_std.p4_pi[0], t_std.p4_pi[1], t_std.p4_pi[2], t_std.p4_pi[3])
        pDmiss = TLorentzVector(0,0,0,0)
        pDmiss.SetPxPyPzE(t_std.p4_Dmiss[0], t_std.p4_Dmiss[1], t_std.p4_Dmiss[2], t_std.p4_Dmiss[3])
        pPi0 = TLorentzVector(0, 0, 0, 0)
        pPi0.SetPxPyPzE(t_std.p4_pi0_save[0], t_std.p4_pi0_save[1], t_std.p4_pi0_save[2], t_std.p4_pi0_save[3])
        if D_sample == 'Dplus' and t_std.mode == 200:
            m_runNo[0] = t_std.runNo
            m_evtNo[0] = t_std.evtNo
            m_mode[0] = t_std.mode
            m_charm[0] = t_std.charm
            m_rawm_D[0] = pD_raw.M()
            pDbar = cms-pD-pPi
            for i in range(4):
                m_p4_D[i] = pD[i]
                m_p4_Dbar[i] = pDbar[i]
                m_p4_pi[i] = t_std.p4_pi[i]
            m_m_D[0] = pD.M()
            m_p_D[0] = pD.P()
            m_E_D[0] = pD.E()
            m_rm_D[0] = (cms-pD).M()
            m_rm_Dmiss[0] = (cms-pDmiss).M()
            m_rm2_D[0] = (cms-pD).M2()
            m_m_Dpi[0] = (pD+pPi).M()
            m_m_Dmisspi[0] = (pDmiss+pPi).M()
            m_m2_Dpi[0] = (pD+pPi).M2()
            m_rm_Dpi[0] = t_std.rm_Dpi
            m_rm_Dmisspi[0] = (cms-pDmiss-pPi).M()
            m_rm_pi[0] = (cms-pPi).M()
            m_chi2_vf[0] = t_std.chi2_vf
            m_chi2_kf[0] = t_std.chi2_kf
            m_chi2_pi0[0] = t_std.chi2_pi0_save
            m_Dpi0 = 999.
            rm_Dpi0 = 999.
            if pPi0.M() > 0:
                m_Dpi0 = (pD+pPi0).M()
                rm_Dpi0 = (cms-pD-pPi0).M()
            deltaM = 999.
            m_Dmisspi0 = 999.
            rm_Dmisspi0 = 999.
            for iPi0 in range(t_std.n_pi0):
                ppi0 = TLorentzVector(0, 0, 0, 0)
                ppi0.SetPxPyPzE(t_std.p4_pi0[iPi0*4+0], t_std.p4_pi0[iPi0*4+1], t_std.p4_pi0[iPi0*4+2], t_std.p4_pi0[iPi0*4+3])
                if (fabs((pDmiss + ppi0).M() - 2.000685) < deltaM):
                    deltaM = fabs((pDmiss + ppi0).M() - 2.01026)
                    m_Dmisspi0 = (pDmiss + ppi0).M()
                    rm_Dmisspi0 = (cms - pDmiss - ppi0).M()
            m_m_Dmisspi0[0] = m_Dmisspi0
            m_rm_Dmisspi0[0] = rm_Dmisspi0
            m_m_Dpi0[0] = m_Dpi0
            m_rm_Dpi0[0] = rm_Dpi0
            m_n_pi0[0] = t_std.n_pi0
            m_n_othershws[0] = t_std.n_othershws
            m_n_othertrks[0] = t_std.n_othertrks
            m_indexmc[0] = t_std.indexmc
            for i in range(t_std.indexmc):
                m_motheridx[i] = t_std.motheridx[i]
                m_pdgid[i] = t_std.pdgid[i]
            for i in range(4):
                m_p4_pi_MCTruth[i] = t_std.p4_pi_MCTruth[i]
                m_p4_D_MCTruth[i] = t_std.p4_D_MCTruth[i]
                m_p4_Dbar_MCTruth[i] = t_std.p4_Dbar_MCTruth[i]
            pPi_MCTruth = TLorentzVector(0,0,0,0)
            pPi_MCTruth.SetPxPyPzE(t_std.p4_pi_MCTruth[0], t_std.p4_pi_MCTruth[1], t_std.p4_pi_MCTruth[2], t_std.p4_pi_MCTruth[3])
            pD_MCTruth = TLorentzVector(0,0,0,0)
            pD_MCTruth.SetPxPyPzE(t_std.p4_D_MCTruth[0], t_std.p4_D_MCTruth[1], t_std.p4_D_MCTruth[2], t_std.p4_D_MCTruth[3])
            pDbar_MCTruth = TLorentzVector(0,0,0,0)
            pDbar_MCTruth.SetPxPyPzE(t_std.p4_Dbar_MCTruth[0], t_std.p4_Dbar_MCTruth[1], t_std.p4_Dbar_MCTruth[2], t_std.p4_Dbar_MCTruth[3])
            m_rm_pi_MCTruth[0] = (pD_MCTruth+pDbar_MCTruth).M()
            m_rm_D_MCTruth[0] = (pPi_MCTruth+pDbar_MCTruth).M()
            m_m_Dpi_MCTruth[0] = (pPi_MCTruth+pD_MCTruth).M()
            if D_sample == 'Dplus' and D_type == 'D' and sample_type == 'signal':
                m_p_pi[0] = t_std.pid_trk[14*0 + 0]
                m_charge_pi[0] = t_std.pid_trk[14*0 + 1]
                m_costheta_pi[0] = t_std.pid_trk[14*0 + 2]
                m_phi_pi[0] = t_std.pid_trk[14*0 + 3]
                m_chi_e_pi[0] = t_std.pid_trk[14*0 + 4]
                m_chi_mu_pi[0] = t_std.pid_trk[14*0 + 5]
                m_chi_pi_pi[0] = t_std.pid_trk[14*0 + 6]
                m_chi_K_pi[0] = t_std.pid_trk[14*0 + 7]
                m_chi_p_pi[0] = t_std.pid_trk[14*0 + 8]
                m_prob_e_pi[0] = t_std.pid_trk[14*0 + 9]
                m_prob_mu_pi[0] = t_std.pid_trk[14*0 + 10]
                m_prob_pi_pi[0] = t_std.pid_trk[14*0 + 11]
                m_prob_K_pi[0] = t_std.pid_trk[14*0 + 12]
                m_prob_p_pi[0] = t_std.pid_trk[14*0 + 13]
                m_p_DK[0] = t_std.pid_trk[14*1 + 0]
                m_charge_DK[0] = t_std.pid_trk[14*1 + 1]
                m_costheta_DK[0] = t_std.pid_trk[14*1 + 2]
                m_phi_DK[0] = t_std.pid_trk[14*1 + 3]
                m_chi_e_DK[0] = t_std.pid_trk[14*1 + 4]
                m_chi_mu_DK[0] = t_std.pid_trk[14*1 + 5]
                m_chi_pi_DK[0] = t_std.pid_trk[14*1 + 6]
                m_chi_K_DK[0] = t_std.pid_trk[14*1 + 7]
                m_chi_p_DK[0] = t_std.pid_trk[14*1 + 8]
                m_prob_e_DK[0] = t_std.pid_trk[14*1 + 9]
                m_prob_mu_DK[0] = t_std.pid_trk[14*1 + 10]
                m_prob_pi_DK[0] = t_std.pid_trk[14*1 + 11]
                m_prob_K_DK[0] = t_std.pid_trk[14*1 + 12]
                m_prob_p_DK[0] = t_std.pid_trk[14*1 + 13]
                m_p_Dpi1[0] = t_std.pid_trk[14*2 + 0]
                m_charge_Dpi1[0] = t_std.pid_trk[14*2 + 1]
                m_costheta_Dpi1[0] = t_std.pid_trk[14*2 + 2]
                m_phi_Dpi1[0] = t_std.pid_trk[14*2 + 3]
                m_chi_e_Dpi1[0] = t_std.pid_trk[14*2 + 4]
                m_chi_mu_Dpi1[0] = t_std.pid_trk[14*2 + 5]
                m_chi_pi_Dpi1[0] = t_std.pid_trk[14*2 + 6]
                m_chi_K_Dpi1[0] = t_std.pid_trk[14*2 + 7]
                m_chi_p_Dpi1[0] = t_std.pid_trk[14*2 + 8]
                m_prob_e_Dpi1[0] = t_std.pid_trk[14*2 + 9]
                m_prob_mu_Dpi1[0] = t_std.pid_trk[14*2 + 10]
                m_prob_pi_Dpi1[0] = t_std.pid_trk[14*2 + 11]
                m_prob_K_Dpi1[0] = t_std.pid_trk[14*2 + 12]
                m_prob_p_Dpi1[0] = t_std.pid_trk[14*2 + 13]
                m_p_Dpi2[0] = t_std.pid_trk[14*3 + 0]
                m_charge_Dpi2[0] = t_std.pid_trk[14*3 + 1]
                m_costheta_Dpi2[0] = t_std.pid_trk[14*3 + 2]
                m_phi_Dpi2[0] = t_std.pid_trk[14*3 + 3]
                m_chi_e_Dpi2[0] = t_std.pid_trk[14*3 + 4]
                m_chi_mu_Dpi2[0] = t_std.pid_trk[14*3 + 5]
                m_chi_pi_Dpi2[0] = t_std.pid_trk[14*3 + 6]
                m_chi_K_Dpi2[0] = t_std.pid_trk[14*3 + 7]
                m_chi_p_Dpi2[0] = t_std.pid_trk[14*3 + 8]
                m_prob_e_Dpi2[0] = t_std.pid_trk[14*3 + 9]
                m_prob_mu_Dpi2[0] = t_std.pid_trk[14*3 + 10]
                m_prob_pi_Dpi2[0] = t_std.pid_trk[14*3 + 11]
                m_prob_K_Dpi2[0] = t_std.pid_trk[14*3 + 12]
                m_prob_p_Dpi2[0] = t_std.pid_trk[14*3 + 13]
            t.Fill()
        if D_sample == 'D0' and (t_std.mode == 0 or t_std.mode == 1 or t_std.mode == 3):
            m_runNo[0] = t_std.runNo
            m_evtNo[0] = t_std.evtNo
            m_mode[0] = t_std.mode
            m_charm[0] = t_std.charm
            m_rawm_D[0] = pD_raw.M()
            m_m_D[0] = pD.M()
            m_p_D[0] = pD.P()
            m_E_D[0] = pD.E()
            m_rm_D[0] = (cms-pD).M()
            m_rm_Dmiss[0] = (cms-pDmiss).M()
            m_rm2_D[0] = (cms-pD).M2()
            m_m_Dpi[0] = (pD+pPi).M()
            m_m_Dmisspi[0] = (pDmiss+pPi).M()
            m_m2_Dpi[0] = (pD+pPi).M2()
            m_rm_Dpi[0] = t_std.rm_Dpi
            m_rm_Dmisspi[0] = (cms-pDmiss-pPi).M()
            m_rm_pi[0] = (cms-pPi).M()
            m_chi2_vf[0] = t_std.chi2_vf
            m_chi2_kf[0] = t_std.chi2_kf
            m_chi2_pi0[0] = t_std.chi2_pi0_save
            m_Dpi0 = 999.
            rm_Dpi0 = 999.
            if pPi0.M() > 0:
                m_Dpi0 = (pD+pPi0).M()
                rm_Dpi0 = (cms-pD-pPi0).M()
            deltaM = 999.
            m_Dmisspi0 = 999.
            rm_Dmisspi0 = 999.
            for iPi0 in range(t_std.n_pi0):
                ppi0 = TLorentzVector(0, 0, 0, 0)
                ppi0.SetPxPyPzE(t_std.p4_pi0[iPi0*4+0], t_std.p4_pi0[iPi0*4+1], t_std.p4_pi0[iPi0*4+2], t_std.p4_pi0[iPi0*4+3])
                if (fabs((pDmiss + ppi0).M() - 2.000685) < deltaM):
                    deltaM = fabs((pDmiss + ppi0).M() - 2.01026)
                    m_Dmisspi0 = (pDmiss + ppi0).M()
                    rm_Dmisspi0 = (cms - pDmiss - ppi0).M()
            m_m_Dmisspi0[0] = m_Dmisspi0
            m_rm_Dmisspi0[0] = rm_Dmisspi0
            m_m_Dpi0[0] = m_Dpi0
            m_rm_Dpi0[0] = rm_Dpi0
            m_n_pi0[0] = t_std.n_pi0
            m_n_othershws[0] = t_std.n_othershws
            m_n_othertrks[0] = t_std.n_othertrks
            m_indexmc[0] = t_std.indexmc
            for i in range(t_std.indexmc):
                m_motheridx[i] = t_std.motheridx[i]
                m_pdgid[i] = t_std.pdgid[i]
            for i in range(4):
                m_p4_pi_MCTruth[i] = t_std.p4_pi_MCTruth[i]
                m_p4_D_MCTruth[i] = t_std.p4_D_MCTruth[i]
                m_p4_Dbar_MCTruth[i] = t_std.p4_Dbar_MCTruth[i]
            t.Fill()
                nCand = event.candSize

                for i in range(nCand):
                    tk1p4 = TLorentzVector(event.tk1P1[i], event.tk1P2[i],
                                           event.tk1P3[i], event.tk1P0[i])
                    tk2p4 = TLorentzVector(event.tk2P1[i], event.tk2P2[i],
                                           event.tk2P3[i], event.tk2P0[i])
                    pmup4 = TLorentzVector(event.pmuP1[i], event.pmuP2[i],
                                           event.pmuP3[i], event.pmuP0[i])
                    nmup4 = TLorentzVector(event.nmuP1[i], event.nmuP2[i],
                                           event.nmuP3[i], event.nmuP0[i])
                    mumup4 = pmup4 + nmup4
                    tktkp4 = tk1p4 + tk2p4

                    tk1p4.SetE(
                        (ptonMass * ptonMass + tk1p4.P() * tk1p4.P())**0.5)
                    tk2p4.SetE(
                        (kaonMass * kaonMass + tk2p4.P() * tk2p4.P())**0.5)
                    lbtkp4 = tk1p4 + tk2p4 + pmup4 + nmup4
                    tktkp4 = tk1p4 + tk2p4

                    tk1p4.SetE(
                        (kaonMass * kaonMass + tk1p4.P() * tk1p4.P())**0.5)
                    tk2p4.SetE(
                        (ptonMass * ptonMass + tk2p4.P() * tk2p4.P())**0.5)
                    lbtkbarp4 = tk1p4 + tk2p4 + pmup4 + nmup4
                    tktkbarp4 = tk1p4 + tk2p4

                    tk1p4.SetE(
                        (kaonMass * kaonMass + tk1p4.P() * tk1p4.P())**0.5)
                    tk2p4.SetE(
Esempio n. 12
0
    def fitmZ(self):

        dilepton = False
        diele = False
        dimu = False

        if self.leptons[0].pdgId() + self.leptons[1].pdgId() == 0 and \
           abs( self.leptons[0].pdgId() - self.leptons[1].pdgId()) > 20 :
            dilepton = True

        #if not(dilepton) : return -99.

        diele = abs(self.leptons[0].pdgId() - self.leptons[1].pdgId()) == 22
        dimu = abs(self.leptons[0].pdgId() - self.leptons[1].pdgId()) == 26

        l1 = TLorentzVector(self.leptons[0].px(), self.leptons[0].py(),
                            self.leptons[0].pz(), self.leptons[0].energy())
        l2 = TLorentzVector(self.leptons[1].px(), self.leptons[1].py(),
                            self.leptons[1].pz(), self.leptons[1].energy())
        c12 = l1.Vect().Dot(l2.Vect()) / l1.P() / l2.P()
        st1 = l1.Pt() / l1.P()
        st2 = l2.Pt() / l2.P()
        m12 = (l1 + l2).M() / sqrt(l1.E() * l2.E())
        fac = 91.188 / (l1 + l2).M()
        energies = [l1.E() * fac, l2.E() * fac]
        measts = [l1.E(), l2.E()]

        def chi2(e):
            def breitw2(m, m0, g0):
                m02 = m0 * m0
                g02 = g0 * g0
                delta = m * m - m02
                return m02 * g02 / (delta * delta + g02 * m02)

            def breitw(m, m0, g0):
                delta = m - m0
                return m0 * g0 / (delta * delta + g0 * m0)

            chi2 = 0.
            fudge = 1.
            mz = m12 * sqrt(e[0] * e[1])
            mzm = m12 * sqrt(measts[0] * measts[1])
            #mz = sqrt(2.*e[0]*e[1]*(1.-c12))
            #print 'mz = ',mz
            sigma1 = 0
            sigma2 = 0
            if dimu:
                chi2 = ( 1./measts[0]-1./e[0] ) * ( 1./measts[0]-1./e[0] ) / (st1*st1) \
                     + ( 1./measts[1]-1./e[1] ) * ( 1./measts[1]-1./e[1] ) / (st2*st2)
                chi2 /= 25E-8
                sigma1 = 5E-4 * 5E-4 * e[0] * e[0] * e[0] * e[0] * st1 * st1
                sigma2 = 5E-4 * 5E-4 * e[1] * e[1] * e[0] * e[0] * st2 * st2
                fudge = 0.5
            elif diele:
                sigma1 = (0.155 * 0.155 + 0.043 * 0.043 * e[0] +
                          0.02 * 0.02 * e[0] * e[0])
                sigma2 = (0.155 * 0.155 + 0.043 * 0.043 * e[1] +
                          0.02 * 0.02 * e[1] * e[1])
                chi2 = (measts[0]-e[0])*(measts[0]-e[0]) / sigma1 \
                     + (measts[1]-e[1])*(measts[1]-e[1]) / sigma2
                fudge = 2.0
            else:
                sigma1 = (0.5 * 0.5 * e[0] / st1 + 0.04 * 0.04 * e[0] * e[0])
                sigma2 = (0.5 * 0.5 * e[1] / st2 + 0.04 * 0.04 * e[1] * e[1])
                chi2 = (measts[0]-e[0])*(measts[0]-e[0]) / sigma1 \
                     + (measts[1]-e[1])*(measts[1]-e[1]) / sigma2
                fudge = 1.0
            #print 'chi2 partial  = ',chi2
            sigmaM = mz * mz * (sigma1 / (e[0] * e[0]) + sigma2 /
                                (e[1] * e[1])) / 4.
            #chi2 = (mzm-mz)*(mzm-mz)/sigmaM
            self.chi2partiel = copy.copy(chi2)
            chi2 -= fudge * log(breitw2(mz, 91.188,
                                        2.497)) * sqrt(sigmaM) / 2.497
            self.chi2total = copy.copy(chi2)
            #if diele:
            #    print 'chi2 partie/complet = ',dimu,diele,mz,mzm,sqrt(sigma1),sqrt(sigma2),sqrt(sigmaM),self.chi2partiel,self.chi2total
            return chi2

        def fillDerivatives(funga):
            def deriv(funga, gamma, i, epsilon):
                g = deepcopy(gamma)
                g[i] += epsilon
                chip = funga(g)
                g[i] -= 2. * epsilon
                chim = funga(g)
                g[i] += epsilon
                return (chip - chim) / (2. * epsilon)

            def deriv2(funga, gamma, i, j, epsilon, mu):
                g = deepcopy(gamma)
                g[i] += epsilon
                derp = deriv(funga, g, j, mu)
                g[i] -= 2. * epsilon
                derm = deriv(funga, g, j, mu)
                g[i] += epsilon
                return (derp - derm) / (2. * epsilon)

            rows = []
            deri = []
            for i in range(len(energies)):
                column = []
                for j in range(len(energies)):
                    column.append(deriv2(funga, energies, i, j, 0.001, 0.001))
                rows.append(column)
                deri.append(deriv(funga, energies, i, 0.001))
            return array(rows), array(deri)

        from numpy import array, linalg, dot, add
        from copy import deepcopy

        #print chi2(energies)
        Delta = 1E9
        t = 0
        while Delta > 1E-3 and t < 200:
            #print "iteration ",t
            t += 1

            d2, d = fillDerivatives(chi2)
            delta = linalg.solve(d2, d)
            Delta = abs(delta[0]) + abs(delta[1])
            #print '------------------- '
            #print 'Delta = ',Delta
            Ki2 = chi2(energies)

            factor = 1.
            for i in range(len(energies)):
                #print i, energies[i], delta[i], d[i]
                if abs(delta[i]) > energies[i] / 10.:
                    factor = min(factor, energies[i] / 10. / abs(delta[i]))
            delta = map(lambda x: x * factor, delta)

            def chinew(funga, gamma, delta):
                gnew = deepcopy(gamma)
                for i, g in enumerate(gamma):
                    gnew[i] -= delta[i]
                return funga(gnew) - Ki2

            while chinew(chi2, energies, delta) > 1E-5:
                delta = map(lambda x: -x * 0.6, delta)

            #print ' '
            for i in range(len(energies)):
                energies[i] -= delta[i]
        if t >= 199:
            print 'Warning - reached iteration ', t
            print diele, dimu, chi2(energies)
            for i in range(len(energies)):
                print i, energies[i], delta[i], d[i]
        #print t, chi2(energies)

        l1 *= energies[0] / l1.E()
        l2 *= energies[1] / l2.E()
        #if not(dimu):
        #    m12 = (l1+l2).M()
        #    l1 *= sqrt(91.188/m12)
        #    l2 *= sqrt(91.188/m12)

        #print self.leptons[0]
        p41 = self.leptons[0].p4()
        p41.SetPxPyPzE(l1.X(), l1.Y(), l1.Z(), l1.T())
        self.leptons[0].setP4(p41)
        #print self.leptons[1]
        p42 = self.leptons[1].p4()
        p42.SetPxPyPzE(l2.X(), l2.Y(), l2.Z(), l2.T())
        self.leptons[1].setP4(p42)
        return chi2(energies)
Esempio n. 13
0
def save_raw(f_in, cms, t, MODE):
    m_runNo = array('i', [0])
    m_evtNo = array('i', [0])
    m_mode = array('i', [0])
    m_charm = array('i', [0])
    m_rrawm_Dpipi = array('d', [999.])
    m_rawm_D = array('d', [999.])
    m_m_D = array('d', [999.])
    m_p_D = array('d', [999.])
    m_E_D = array('d', [999.])
    m_rm_D = array('d', [999.])
    m_rm_pipi = array('d', [999.])
    m_m_pipi = array('d', [999.])
    m_p_pipi = array('d', [999.])
    m_E_pipi = array('d', [999.])
    m_m_Dpi = array('d', [999.])
    m_rm_Dpi = array('d', [999.])
    m_m_Dpip = array('d', [999.])
    m_m_Dpim = array('d', [999.])
    m_m2_Kpip = array('d', [999.])
    m_m2_Kpim = array('d', [999.])
    m_m_Dpipi = array('d', [999.])
    m_rm_Dpipi = array('d', [999.])
    m_chi2_vf = array('d', [999.])
    m_chi2_kf = array('d', [999.])
    m_n_othershws = array('i', [0])
    m_n_othertrks = array('i', [0])
    m_charge_left = array('i', [0])
    m_m_piplus0 = array('d', [999.])
    m_m_piminus0 = array('d', [999.])
    m_p_piplus0 = array('d', [999.])
    m_p_piminus0 = array('d', [999.])
    m_E_piplus0 = array('d', [999.])
    m_E_piminus0 = array('d', [999.])
    m_chi2_pi0 = array('d', [999.])
    m_m_Dpi0 = array('d', [999.])
    m_m_pi0 = array('d', [999.])
    m_p_pi0 = array('d', [999.])
    m_E_pi0 = array('d', [999.])
    m_n_pi0 = array('i', [0])
    m_matched_D = array('i', [0])
    m_matched_pi = array('i', [0])
    m_indexmc = array('i', [0])
    m_motheridx = array('i', 100 * [0])
    m_pdgid = array('i', 100 * [0])
    t.Branch('runNo', m_runNo, 'm_runNo/I')
    t.Branch('evtNo', m_evtNo, 'm_evtNo/I')
    t.Branch('mode', m_mode, 'm_mode/I')
    t.Branch('charm', m_charm, 'm_charm/I')
    t.Branch('rrawm_Dpipi', m_rrawm_Dpipi, 'm_rrawm_Dpipi/D')
    t.Branch('rawm_D', m_rawm_D, 'm_rawm_D/D')
    t.Branch('m_D', m_m_D, 'm_m_D/D')
    t.Branch('p_D', m_p_D, 'm_p_D/D')
    t.Branch('E_D', m_E_D, 'm_E_D/D')
    t.Branch('rm_D', m_rm_D, 'm_rm_D/D')
    t.Branch('rm_pipi', m_rm_pipi, 'm_rm_pipi/D')
    t.Branch('m_pipi', m_m_pipi, 'm_m_pipi/D')
    t.Branch('p_pipi', m_p_pipi, 'm_p_pipi/D')
    t.Branch('E_pipi', m_E_pipi, 'm_E_pipi/D')
    t.Branch('m_Dpi', m_m_Dpi, 'm_m_Dpi/D')
    t.Branch('rm_Dpi', m_rm_Dpi, 'm_rm_Dpi/D')
    t.Branch('m_Dpip', m_m_Dpip, 'm_m_Dpip/D')
    t.Branch('m_Dpim', m_m_Dpim, 'm_m_Dpim/D')
    t.Branch('m2_Kpip', m_m2_Kpip, 'm_m2_Kpip/D')
    t.Branch('m2_Kpim', m_m2_Kpim, 'm_m2_Kpim/D')
    t.Branch('m_Dpipi', m_m_Dpipi, 'm_m_Dpipi/D')
    t.Branch('rm_Dpipi', m_rm_Dpipi, 'm_rm_Dpipi/D')
    t.Branch('chi2_vf', m_chi2_vf, 'm_chi2_vf/D')
    t.Branch('chi2_kf', m_chi2_kf, 'm_chi2_kf/D')
    t.Branch('n_othertrks', m_n_othertrks, 'm_n_othertrks/I')
    t.Branch('n_othershws', m_n_othershws, 'm_n_othershws/I')
    t.Branch('charge_left', m_charge_left, 'm_charge_left/I')
    t.Branch('m_piplus0', m_m_piplus0, 'm_m_piplus0/D')
    t.Branch('m_piminus0', m_m_piminus0, 'm_m_piminus0/D')
    t.Branch('p_piplus0', m_p_piplus0, 'm_p_piplus0/D')
    t.Branch('p_piminus0', m_p_piminus0, 'm_p_piminus0/D')
    t.Branch('E_piplus0', m_E_piplus0, 'm_E_piplus0/D')
    t.Branch('E_piminus0', m_E_piminus0, 'm_E_piminus0/D')
    t.Branch('chi2_pi0', m_chi2_pi0, 'm_chi2_pi0/D')
    t.Branch('m_Dpi0', m_m_Dpi0, 'm_m_Dpi0/D')
    t.Branch('m_pi0', m_m_pi0, 'm_m_pi0/D')
    t.Branch('p_pi0', m_p_pi0, 'm_p_pi0/D')
    t.Branch('E_pi0', m_E_pi0, 'm_E_pi0/D')
    t.Branch('n_pi0', m_n_pi0, 'm_n_pi0/I')
    t.Branch('matched_D', m_matched_D, 'm_matched_D/I')
    t.Branch('matched_pi', m_matched_pi, 'm_matched_pi/I')
    t.Branch('indexmc', m_indexmc, 'indexmc/I')
    t.Branch('motheridx', m_motheridx, 'motheridx[100]/I')
    t.Branch('pdgid', m_pdgid, 'pdgid[100]/I')
    t_std = f_in.Get('STD')
    nentries = t_std.GetEntries()
    for ientry in range(nentries):
        t_std.GetEntry(ientry)
        if t_std.mode != 200:
            continue
        pD_raw = TLorentzVector(0, 0, 0, 0)
        pD = TLorentzVector(0, 0, 0, 0)
        pKpip = TLorentzVector(0, 0, 0, 0)
        pKpim = TLorentzVector(0, 0, 0, 0)
        for iTrk in range(t_std.n_trkD):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack_Kpip = TLorentzVector(0, 0, 0, 0)
            ptrack_Kpim = TLorentzVector(0, 0, 0, 0)
            ptrack = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk * 6 + 0],
                                  t_std.rawp4_Dtrk[iTrk * 6 + 1],
                                  t_std.rawp4_Dtrk[iTrk * 6 + 2],
                                  t_std.rawp4_Dtrk[iTrk * 6 + 3])
            if MODE == 'raw_signal':
                ptrack.SetPxPyPzE(t_std.p4_Dtrk[iTrk * 4 + 0],
                                  t_std.p4_Dtrk[iTrk * 4 + 1],
                                  t_std.p4_Dtrk[iTrk * 4 + 2],
                                  t_std.p4_Dtrk[iTrk * 4 + 3])
            if MODE == 'raw_sidebandlow':
                ptrack.SetPxPyPzE(t_std.p4_Dlowtrk[iTrk * 4 + 0],
                                  t_std.p4_Dlowtrk[iTrk * 4 + 1],
                                  t_std.p4_Dlowtrk[iTrk * 4 + 2],
                                  t_std.p4_Dlowtrk[iTrk * 4 + 3])
            if MODE == 'raw_sidebandup':
                ptrack.SetPxPyPzE(t_std.p4_Duptrk[iTrk * 4 + 0],
                                  t_std.p4_Duptrk[iTrk * 4 + 1],
                                  t_std.p4_Duptrk[iTrk * 4 + 2],
                                  t_std.p4_Duptrk[iTrk * 4 + 3])
            pD_raw += ptrack_raw
            pD += ptrack
            if t_std.rawp4_Dtrk[iTrk * 6 + 5] == 3:
                ptrack_Kpip.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 3])
                ptrack_Kpim.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 3])
                pKpip += ptrack_Kpip
                pKpim += ptrack_Kpim
            if t_std.rawp4_Dtrk[iTrk * 6 +
                                4] == 1 and t_std.rawp4_Dtrk[iTrk * 6 +
                                                             5] == 2:
                ptrack_Kpip.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 3])
                pKpip += ptrack_Kpip
            if t_std.rawp4_Dtrk[iTrk * 6 +
                                4] == -1 and t_std.rawp4_Dtrk[iTrk * 6 +
                                                              5] == 2:
                ptrack_Kpim.SetPxPyPzE(t_std.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_std.rawp4_Dtrk[iTrk * 6 + 3])
                pKpim += ptrack_Kpim
        for iShw in range(t_std.n_shwD):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_std.rawp4_Dshw[iShw * 4 + 0],
                                   t_std.rawp4_Dshw[iShw * 4 + 1],
                                   t_std.rawp4_Dshw[iShw * 4 + 2],
                                   t_std.rawp4_Dshw[iShw * 4 + 3])
            if MODE == 'raw_signal':
                pshower.SetPxPyPzE(t_std.p4_Dshw[iShw * 4 + 0],
                                   t_std.p4_Dshw[iShw * 4 + 1],
                                   t_std.p4_Dshw[iShw * 4 + 2],
                                   t_std.p4_Dshw[iShw * 4 + 3])
            if MODE == 'raw_sidebandlow':
                pshower.SetPxPyPzE(t_std.p4_Dlowshw[iShw * 4 + 0],
                                   t_std.p4_Dlowshw[iShw * 4 + 1],
                                   t_std.p4_Dlowshw[iShw * 4 + 2],
                                   t_std.p4_Dlowshw[iShw * 4 + 3])
            if MODE == 'raw_sidebandup':
                pshower.SetPxPyPzE(t_std.p4_Dupshw[iShw * 4 + 0],
                                   t_std.p4_Dupshw[iShw * 4 + 1],
                                   t_std.p4_Dupshw[iShw * 4 + 2],
                                   t_std.p4_Dupshw[iShw * 4 + 3])
            pD_raw += pshower_raw
            pD += pshower
        pPip = TLorentzVector(0, 0, 0, 0)
        pPim = TLorentzVector(0, 0, 0, 0)
        count = 0
        for iTrk1 in range(t_std.n_othertrks):
            if t_std.rawp4_otherMdcKaltrk[iTrk1 * 7 + 4] != 1:
                continue
            if t_std.rawp4_otherMdcKaltrk[iTrk1 * 7 + 5] != 2:
                continue
            pPip.SetPxPyPzE(t_std.rawp4_otherMdcKaltrk[iTrk1 * 7 + 0],
                            t_std.rawp4_otherMdcKaltrk[iTrk1 * 7 + 1],
                            t_std.rawp4_otherMdcKaltrk[iTrk1 * 7 + 2],
                            t_std.rawp4_otherMdcKaltrk[iTrk1 * 7 + 3])
            for iTrk2 in range(t_std.n_othertrks):
                if t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 + 4] != -1:
                    continue
                if t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 + 5] != 2:
                    continue
                pPim.SetPxPyPzE(t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 + 0],
                                t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 + 1],
                                t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 + 2],
                                t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 + 3])
                m_runNo[0] = t_std.runNo
                m_evtNo[0] = t_std.evtNo
                m_mode[0] = t_std.mode
                m_charm[0] = t_std.charm
                m_rrawm_Dpipi[0] = (cms - pD_raw - pPip - pPim).M()
                m_rawm_D[0] = pD_raw.M()
                m_m_D[0] = pD.M()
                m_p_D[0] = pD.P()
                m_E_D[0] = pD.E()
                m_rm_D[0] = (cms - pD).M()
                m_rm_pipi[0] = (cms - pPip - pPim).M()
                m_m_pipi[0] = (pPip + pPim).M()
                m_p_pipi[0] = (pPip + pPim).P()
                m_E_pipi[0] = (pPip + pPim).E()
                m_m_Dpim[0] = (pD + pPim).M()
                m_m_Dpip[0] = (pD + pPip).M()
                if t_std.charm > 0 and t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 +
                                                                  4] == -1:
                    m_m_Dpi[0] = (pD + pPim).M()
                    m_rm_Dpi[0] = (cms - pD - pPim).M()
                elif t_std.charm < 0 and t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 +
                                                                    4] == 1:
                    m_m_Dpi[0] = (pD + pPip).M()
                    m_rm_Dpi[0] = (cms - pD - pPip).M()
                m_m2_Kpip[0] = pKpip.M2()
                m_m2_Kpim[0] = pKpim.M2()
                m_m_Dpipi[0] = (pD + pPip + pPim).M()
                m_rm_Dpipi[0] = (cms - pD - pPip - pPim).M()
                m_chi2_vf[0] = t_std.chi2_vf
                if MODE == 'raw_signal':
                    m_chi2_kf[0] = t_std.chi2_kf
                if MODE == 'raw_sidebandlow':
                    m_chi2_kf[0] = t_std.chi2_kf_low
                if MODE == 'raw_sidebandup':
                    m_chi2_kf[0] = t_std.chi2_kf_up
                m_n_othershws[0] = t_std.n_othershws
                m_n_othertrks[0] = t_std.n_othertrks
                charge_left = 0
                for i in range(t_std.n_othertrks):
                    if i != iTrk1 and i != iTrk2:
                        charge_left += t_std.rawp4_otherMdcKaltrk[i * 7 + 4]
                m_charge_left[0] = int(charge_left)
                m_m_piplus0[0] = pPip.M()
                m_m_piminus0[0] = pPim.M()
                m_p_piplus0[0] = pPip.P()
                m_p_piminus0[0] = pPim.P()
                m_E_piplus0[0] = pPip.E()
                m_E_piminus0[0] = pPim.E()
                m_chi2_pi0[0] = t_std.chi2_pi0_save
                m_Dpi0 = pD.M()
                pPi0 = TLorentzVector(0, 0, 0, 0)
                pPi0.SetPxPyPzE(t_std.p4_pi0_save[0], t_std.p4_pi0_save[1],
                                t_std.p4_pi0_save[2], t_std.p4_pi0_save[3])
                if pPi0.M() > 0:
                    m_Dpi0 = (pD + pPi0).M()
                m_m_Dpi0[0] = m_Dpi0
                m_m_pi0[0] = pPi0.M()
                m_p_pi0[0] = pPi0.P()
                m_E_pi0[0] = pPi0.E()
                m_n_pi0[0] = t_std.n_pi0
                m_matched_D[0] = t_std.matched_D
                if t_std.rawp4_otherMdcKaltrk[
                        iTrk1 * 7 +
                        6] == 1 and t_std.rawp4_otherMdcKaltrk[iTrk2 * 7 +
                                                               6] == 1:
                    m_matched_pi[0] = 1
                else:
                    m_matched_pi[0] = 0
                m_indexmc[0] = t_std.indexmc
                for i in range(t_std.indexmc):
                    m_motheridx[i] = t_std.motheridx[i]
                    m_pdgid[i] = t_std.pdgid[i]
                t.Fill()
Esempio n. 14
0
def save_missing(f_in, cms, t, MODE):
    m_runNo = array('i', [0])
    m_evtNo = array('i', [0])
    m_mode = array('i', [0])
    m_charm = array('i', [0])
    m_rawm_D = array('d', [999.])
    m_m_Dold = array('d', [999.])
    m_rrawm_D = array('d', [999.])
    m_m_D = array('d', [999.])
    m_p_D = array('d', [999.])
    m_E_D = array('d', [999.])
    m_rm_D = array('d', [999.])
    m_rm_D_old = array('d', [999.])
    m_rm_Dmiss = array('d', [999.])
    m_rm_DDmisspip = array('d', [999.])
    m_rm_DDmisspim = array('d', [999.])
    m_rm_pipi = array('d', [999.])
    m_m_pipi = array('d', [999.])
    m_p_pipi = array('d', [999.])
    m_E_pipi = array('d', [999.])
    m_m_Dpi = array('d', [999.])
    m_m_DDmiss = array('d', [999.])
    m_rm_DDmiss = array('d', [999.])
    m_m_Dmisspi = array('d', [999.])
    m_rm_Dmisspi = array('d', [999.])
    m_rm_Dmisspipi = array('d', [999.])
    m_rm_Dpi = array('d', [999.])
    m_m_Dpip = array('d', [999.])
    m_m_Dpim = array('d', [999.])
    m_m2_Kpip = array('d', [999.])
    m_m_Kpip = array('d', [999.])
    m_rm_Kpip = array('d', [999.])
    m_m2_Kpim = array('d', [999.])
    m_m_Kpim = array('d', [999.])
    m_rm_Kpim = array('d', [999.])
    m_m_Dpipi = array('d', [999.])
    m_rm_Dpipi = array('d', [999.])
    m_m_Dmiss = array('d', [999.])
    m_chi2_vf = array('d', [999.])
    m_chi2_kf = array('d', [999.])
    m_chi2_svf = array('d', [999.])
    m_ctau_svf = array('d', [999.])
    m_L_svf = array('d', [999.])
    m_Lerr_svf = array('d', [999.])
    m_n_othershws = array('i', [0])
    m_n_othertrks = array('i', [0])
    m_charge_left = array('i', [0])
    m_m_piplus0 = array('d', [999.])
    m_m_piminus0 = array('d', [999.])
    m_p_piplus0 = array('d', [999.])
    m_p_piminus0 = array('d', [999.])
    m_E_piplus0 = array('d', [999.])
    m_E_piminus0 = array('d', [999.])
    m_chi2_pi0 = array('d', [999.])
    m_m_Dpi0 = array('d', [999.])
    m_rm_Dpi0 = array('d', [999.])
    m_m_Dmisspi0 = array('d', [999.])
    m_rm_Dmisspi0 = array('d', [999.])
    m_m_pi0 = array('d', [999.])
    m_p_pi0 = array('d', [999.])
    m_E_pi0 = array('d', [999.])
    m_n_pi0 = array('i', [0])
    if MODE == 'STDDmiss_signal':
        m_matched_D = array('i', [0])
        m_matched_pi = array('i', [0])
        m_matched_piplus = array('i', [0])
        m_matched_piminus = array('i', [0])
    m_indexmc = array('i', [0])
    m_motheridx = array('i', 100 * [0])
    m_pdgid = array('i', 100 * [0])
    t.Branch('runNo', m_runNo, 'm_runNo/I')
    t.Branch('evtNo', m_evtNo, 'm_evtNo/I')
    t.Branch('mode', m_mode, 'm_mode/I')
    t.Branch('charm', m_charm, 'm_charm/I')
    t.Branch('rawm_D', m_rawm_D, 'm_rawm_D/D')
    t.Branch('m_Dold', m_m_Dold, 'm_m_Dold/D')
    t.Branch('rrawm_D', m_rrawm_D, 'm_rrawm_D/D')
    t.Branch('m_D', m_m_D, 'm_m_D/D')
    t.Branch('p_D', m_p_D, 'm_p_D/D')
    t.Branch('E_D', m_E_D, 'm_E_D/D')
    t.Branch('rm_D', m_rm_D, 'm_rm_D/D')
    t.Branch('rm_D_old', m_rm_D_old, 'm_rm_D_old/D')
    t.Branch('rm_Dmiss', m_rm_Dmiss, 'm_rm_Dmiss/D')
    t.Branch('rm_DDmisspip', m_rm_DDmisspip, 'm_rm_DDmisspip/D')
    t.Branch('rm_DDmisspim', m_rm_DDmisspim, 'm_rm_DDmisspim/D')
    t.Branch('rm_pipi', m_rm_pipi, 'm_rm_pipi/D')
    t.Branch('m_pipi', m_m_pipi, 'm_m_pipi/D')
    t.Branch('p_pipi', m_p_pipi, 'm_p_pipi/D')
    t.Branch('E_pipi', m_E_pipi, 'm_E_pipi/D')
    t.Branch('m_Dpi', m_m_Dpi, 'm_m_Dpi/D')
    t.Branch('m_DDmiss', m_m_DDmiss, 'm_m_DDmiss/D')
    t.Branch('rm_DDmiss', m_rm_DDmiss, 'm_rm_DDmiss/D')
    t.Branch('m_Dmisspi', m_m_Dmisspi, 'm_m_Dmisspi/D')
    t.Branch('rm_Dmisspi', m_rm_Dmisspi, 'm_rm_Dmisspi/D')
    t.Branch('rm_Dmisspipi', m_rm_Dmisspipi, 'm_rm_Dmisspipi/D')
    t.Branch('rm_Dpi', m_rm_Dpi, 'm_rm_Dpi/D')
    t.Branch('m_Dpip', m_m_Dpip, 'm_m_Dpip/D')
    t.Branch('m_Dpim', m_m_Dpim, 'm_m_Dpim/D')
    t.Branch('m2_Kpip', m_m2_Kpip, 'm_m2_Kpip/D')
    t.Branch('m_Kpip', m_m_Kpip, 'm_m_Kpip/D')
    t.Branch('rm_Kpip', m_rm_Kpip, 'm_rm_Kpip/D')
    t.Branch('m2_Kpim', m_m2_Kpim, 'm_m2_Kpim/D')
    t.Branch('m_Kpim', m_m_Kpim, 'm_m_Kpim/D')
    t.Branch('rm_Kpim', m_rm_Kpim, 'm_rm_Kpim/D')
    t.Branch('m_Dpipi', m_m_Dpipi, 'm_m_Dpipi/D')
    t.Branch('rm_Dpipi', m_rm_Dpipi, 'm_rm_Dpipi/D')
    t.Branch('m_Dmiss', m_m_Dmiss, 'm_m_Dmiss/D')
    t.Branch('chi2_vf', m_chi2_vf, 'm_chi2_vf/D')
    t.Branch('chi2_kf', m_chi2_kf, 'm_chi2_kf/D')
    t.Branch('chi2_svf', m_chi2_svf, 'm_chi2_svf/D')
    t.Branch('ctau_svf', m_ctau_svf, 'm_ctau_svf/D')
    t.Branch('L_svf', m_L_svf, 'm_L_svf/D')
    t.Branch('Lerr_svf', m_Lerr_svf, 'm_Lerr_svf/D')
    t.Branch('n_othertrks', m_n_othertrks, 'm_n_othertrks/I')
    t.Branch('n_othershws', m_n_othershws, 'm_n_othershws/I')
    t.Branch('charge_left', m_charge_left, 'm_charge_left/I')
    t.Branch('m_piplus0', m_m_piplus0, 'm_m_piplus0/D')
    t.Branch('m_piminus0', m_m_piminus0, 'm_m_piminus0/D')
    t.Branch('p_piplus0', m_p_piplus0, 'm_p_piplus0/D')
    t.Branch('p_piminus0', m_p_piminus0, 'm_p_piminus0/D')
    t.Branch('E_piplus0', m_E_piplus0, 'm_E_piplus0/D')
    t.Branch('E_piminus0', m_E_piminus0, 'm_E_piminus0/D')
    t.Branch('chi2_pi0', m_chi2_pi0, 'm_chi2_pi0/D')
    t.Branch('m_Dpi0', m_m_Dpi0, 'm_m_Dpi0/D')
    t.Branch('rm_Dpi0', m_rm_Dpi0, 'm_rm_Dpi0/D')
    t.Branch('m_Dmisspi0', m_m_Dmisspi0, 'm_m_Dmisspi0/D')
    t.Branch('rm_Dmisspi0', m_rm_Dmisspi0, 'm_rm_Dmisspi0/D')
    t.Branch('m_pi0', m_m_pi0, 'm_m_pi0/D')
    t.Branch('p_pi0', m_p_pi0, 'm_p_pi0/D')
    t.Branch('E_pi0', m_E_pi0, 'm_E_pi0/D')
    t.Branch('n_pi0', m_n_pi0, 'm_n_pi0/I')
    if MODE == 'STDDmiss_signal':
        t.Branch('matched_D', m_matched_D, 'm_matched_D/I')
        t.Branch('matched_pi', m_matched_pi, 'm_matched_pi/I')
        t.Branch('matched_piplus', m_matched_piplus, 'm_matched_piplus/I')
        t.Branch('matched_piminus', m_matched_piminus, 'm_matched_piminus/I')
    t.Branch('indexmc', m_indexmc, 'indexmc/I')
    t.Branch('motheridx', m_motheridx, 'motheridx[100]/I')
    t.Branch('pdgid', m_pdgid, 'pdgid[100]/I')
    t_in = f_in.Get('STDDmiss')
    nentries = t_in.GetEntries()
    for ientry in range(nentries):
        t_in.GetEntry(ientry)
        if t_in.mode != 200:
            continue
        pD_raw = TLorentzVector(0, 0, 0, 0)
        pD_old = TLorentzVector(0, 0, 0, 0)
        pD = TLorentzVector(0, 0, 0, 0)
        pKpip = TLorentzVector(0, 0, 0, 0)
        pKpim = TLorentzVector(0, 0, 0, 0)
        for iTrk in range(t_in.n_trkD):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack_old = TLorentzVector(0, 0, 0, 0)
            ptrack_Kpip = TLorentzVector(0, 0, 0, 0)
            ptrack_Kpim = TLorentzVector(0, 0, 0, 0)
            ptrack = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_in.rawp4_Dtrk[iTrk * 6 + 0],
                                  t_in.rawp4_Dtrk[iTrk * 6 + 1],
                                  t_in.rawp4_Dtrk[iTrk * 6 + 2],
                                  t_in.rawp4_Dtrk[iTrk * 6 + 3])
            ptrack_old.SetPxPyPzE(t_in.p4_Dtrkold[iTrk * 4 + 0],
                                  t_in.p4_Dtrkold[iTrk * 4 + 1],
                                  t_in.p4_Dtrkold[iTrk * 4 + 2],
                                  t_in.p4_Dtrkold[iTrk * 4 + 3])
            if MODE == 'STDDmiss_signal':
                ptrack.SetPxPyPzE(t_in.p4_Dtrk[iTrk * 4 + 0],
                                  t_in.p4_Dtrk[iTrk * 4 + 1],
                                  t_in.p4_Dtrk[iTrk * 4 + 2],
                                  t_in.p4_Dtrk[iTrk * 4 + 3])
            if MODE == 'STDDmiss_sidebandlow':
                ptrack.SetPxPyPzE(t_in.p4_Dtrk_low[iTrk * 4 + 0],
                                  t_in.p4_Dtrk_low[iTrk * 4 + 1],
                                  t_in.p4_Dtrk_low[iTrk * 4 + 2],
                                  t_in.p4_Dtrk_low[iTrk * 4 + 3])
            if MODE == 'STDDmiss_sidebandup':
                ptrack.SetPxPyPzE(t_in.p4_Dtrk_up[iTrk * 4 + 0],
                                  t_in.p4_Dtrk_up[iTrk * 4 + 1],
                                  t_in.p4_Dtrk_up[iTrk * 4 + 2],
                                  t_in.p4_Dtrk_up[iTrk * 4 + 3])
            pD_raw += ptrack_raw
            pD_old += ptrack_old
            pD += ptrack
            if t_in.rawp4_Dtrk[iTrk * 6 + 5] == 3:
                ptrack_Kpip.SetPxPyPzE(t_in.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 3])
                ptrack_Kpim.SetPxPyPzE(t_in.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 3])
                pKpip += ptrack_Kpip
                pKpim += ptrack_Kpim
            if t_in.rawp4_Dtrk[iTrk * 6 +
                               4] == 1 and t_in.rawp4_Dtrk[iTrk * 6 + 5] == 2:
                ptrack_Kpip.SetPxPyPzE(t_in.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 3])
                pKpip += ptrack_Kpip
            if t_in.rawp4_Dtrk[iTrk * 6 +
                               4] == -1 and t_in.rawp4_Dtrk[iTrk * 6 + 5] == 2:
                ptrack_Kpim.SetPxPyPzE(t_in.rawp4_Dtrk[iTrk * 6 + 0],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 1],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 2],
                                       t_in.rawp4_Dtrk[iTrk * 6 + 3])
                pKpim += ptrack_Kpim
        for iShw in range(t_in.n_shwD):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower_old = TLorentzVector(0, 0, 0, 0)
            pshower = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_in.rawp4_Dshw[iShw * 4 + 0],
                                   t_in.rawp4_Dshw[iShw * 4 + 1],
                                   t_in.rawp4_Dshw[iShw * 4 + 2],
                                   t_in.rawp4_Dshw[iShw * 4 + 3])
            pshower_old.SetPxPyPzE(t_in.p4_Dshwold[iShw * 4 + 0],
                                   t_in.p4_Dshwold[iShw * 4 + 1],
                                   t_in.p4_Dshwold[iShw * 4 + 2],
                                   t_in.p4_Dshwold[iShw * 4 + 3])
            if MODE == 'STDDmiss_signal':
                pshower.SetPxPyPzE(t_in.p4_Dshw[iShw * 4 + 0],
                                   t_in.p4_Dshw[iShw * 4 + 1],
                                   t_in.p4_Dshw[iShw * 4 + 2],
                                   t_in.p4_Dshw[iShw * 4 + 3])
            if MODE == 'STDDmiss_sidebandlow':
                pshower.SetPxPyPzE(t_in.p4_Dshw_low[iShw * 4 + 0],
                                   t_in.p4_Dshw_low[iShw * 4 + 1],
                                   t_in.p4_Dshw_low[iShw * 4 + 2],
                                   t_in.p4_Dshw_low[iShw * 4 + 3])
            if MODE == 'STDDmiss_sidebandup':
                pshower.SetPxPyPzE(t_in.p4_Dshw_up[iShw * 4 + 0],
                                   t_in.p4_Dshw_up[iShw * 4 + 1],
                                   t_in.p4_Dshw_up[iShw * 4 + 2],
                                   t_in.p4_Dshw_up[iShw * 4 + 3])
            pD_raw += pshower_raw
            pD_old += pshower_old
            pD += pshower
        pPip = TLorentzVector(0, 0, 0, 0)
        pPim = TLorentzVector(0, 0, 0, 0)
        pDmiss = TLorentzVector(0, 0, 0, 0)
        rawpPip = TLorentzVector(0, 0, 0, 0)
        rawpPim = TLorentzVector(0, 0, 0, 0)
        pPi0 = TLorentzVector(0, 0, 0, 0)
        if MODE == 'STDDmiss_signal':
            pPip.SetPxPyPzE(t_in.p4_piplus[0], t_in.p4_piplus[1],
                            t_in.p4_piplus[2], t_in.p4_piplus[3])
            pPim.SetPxPyPzE(t_in.p4_piminus[0], t_in.p4_piminus[1],
                            t_in.p4_piminus[2], t_in.p4_piminus[3])
            pDmiss.SetPxPyPzE(t_in.p4_Dmiss[0], t_in.p4_Dmiss[1],
                              t_in.p4_Dmiss[2], t_in.p4_Dmiss[3])
        if MODE == 'STDDmiss_sidebandlow':
            pPip.SetPxPyPzE(t_in.p4_piplus_low[0], t_in.p4_piplus_low[1],
                            t_in.p4_piplus_low[2], t_in.p4_piplus_low[3])
            pPim.SetPxPyPzE(t_in.p4_piminus_low[0], t_in.p4_piminus_low[1],
                            t_in.p4_piminus_low[2], t_in.p4_piminus_low[3])
            pDmiss.SetPxPyPzE(t_in.p4_Dmiss_low[0], t_in.p4_Dmiss_low[1],
                              t_in.p4_Dmiss_low[2], t_in.p4_Dmiss_low[3])
        if MODE == 'STDDmiss_sidebandup':
            pPip.SetPxPyPzE(t_in.p4_piplus_up[0], t_in.p4_piplus_up[1],
                            t_in.p4_piplus_up[2], t_in.p4_piplus_up[3])
            pPim.SetPxPyPzE(t_in.p4_piminus_up[0], t_in.p4_piminus_up[1],
                            t_in.p4_piminus_up[2], t_in.p4_piminus_up[3])
            pDmiss.SetPxPyPzE(t_in.p4_Dmiss_up[0], t_in.p4_Dmiss_up[1],
                              t_in.p4_Dmiss_up[2], t_in.p4_Dmiss_up[3])
        rawpPip.SetPxPyPzE(t_in.rawp4_tagPiplus[0], t_in.rawp4_tagPiplus[1],
                           t_in.rawp4_tagPiplus[2], t_in.rawp4_tagPiplus[3])
        rawpPim.SetPxPyPzE(t_in.rawp4_tagPiminus[0], t_in.rawp4_tagPiminus[1],
                           t_in.rawp4_tagPiminus[2], t_in.rawp4_tagPiminus[3])
        pPi0.SetPxPyPzE(t_in.p4_pi0_save[0], t_in.p4_pi0_save[1],
                        t_in.p4_pi0_save[2], t_in.p4_pi0_save[3])
        m_runNo[0] = t_in.runNo
        m_evtNo[0] = t_in.evtNo
        m_mode[0] = t_in.mode
        m_charm[0] = t_in.charm
        m_rawm_D[0] = pD_raw.M()
        m_m_Dold[0] = pD_old.M()
        m_rrawm_D[0] = (cms - pD_raw).M()
        m_m_D[0] = pD.M()
        m_p_D[0] = pD.P()
        m_E_D[0] = pD.E()
        m_rm_D[0] = (cms - pD).M()
        m_rm_D_old[0] = (cms - pD_old).M()
        m_rm_Dmiss[0] = (cms - pDmiss).M()
        m_rm_pipi[0] = (cms - pPip - pPim).M()
        m_m_pipi[0] = (pPip + pPim).M()
        m_p_pipi[0] = (rawpPip + rawpPim).P()
        m_E_pipi[0] = (rawpPip + rawpPim).E()
        m_m_Dpim[0] = (pD + pPim).M()
        m_m_Dpip[0] = (pD + pPip).M()
        if t_in.charm > 0:
            m_m_Dmisspi[0] = (pDmiss + pPip).M()
            m_rm_Dmisspi[0] = (cms - pDmiss - pPip).M()
            m_m_Dpi[0] = (pD_old + rawpPim).M()
            m_rm_Dpi[0] = (cms - pD_old - rawpPim).M()
        elif t_in.charm < 0:
            m_m_Dmisspi[0] = (pDmiss + pPim).M()
            m_rm_Dmisspi[0] = (cms - pDmiss - pPim).M()
            m_m_Dpi[0] = (pD_old + rawpPip).M()
            m_rm_Dpi[0] = (cms - pD_old - rawpPip).M()
        m_m_DDmiss[0] = (pDmiss + pD).M()
        m_rm_DDmiss[0] = (cms - pDmiss).M() + (cms - pD).M()
        m_rm_DDmisspip[0] = (cms - pDmiss - pD - pPip).M()
        m_rm_DDmisspim[0] = (cms - pDmiss - pD - pPim).M()
        m_rm_Dmisspipi[0] = (cms - pDmiss - pPip - pPim).M()
        m_m2_Kpip[0] = pKpip.M2()
        m_m_Kpip[0] = pKpip.M()
        m_rm_Kpip[0] = (cms - pKpip).M()
        m_m2_Kpim[0] = pKpim.M2()
        m_m_Kpim[0] = pKpim.M()
        m_rm_Kpim[0] = (cms - pKpim).M()
        m_m_Dpipi[0] = (pD + pPip + pPim).M()
        m_rm_Dpipi[0] = t_in.rm_Dpipi
        m_m_Dmiss[0] = pDmiss.M()
        m_chi2_vf[0] = t_in.chi2_vf
        if MODE == 'STDDmiss_signal':
            m_chi2_kf[0] = t_in.chi2_kf
        if MODE == 'STDDmiss_sidebandlow':
            m_chi2_kf[0] = t_in.chi2_kf_low
        if MODE == 'STDDmiss_sidebandup':
            m_chi2_kf[0] = t_in.chi2_kf_up
        m_chi2_svf[0] = t_in.chi2_svf
        m_ctau_svf[0] = t_in.ctau_svf
        m_L_svf[0] = t_in.L_svf
        m_Lerr_svf[0] = t_in.Lerr_svf
        m_n_othershws[0] = t_in.n_othershws
        m_n_othertrks[0] = t_in.n_othertrks
        m_charge_left[0] = t_in.charge_left
        m_m_piplus0[0] = rawpPip.M()
        m_m_piminus0[0] = rawpPim.M()
        m_p_piplus0[0] = rawpPip.P()
        m_p_piminus0[0] = rawpPim.P()
        m_E_piplus0[0] = rawpPip.E()
        m_E_piminus0[0] = rawpPim.E()
        m_chi2_pi0[0] = t_in.chi2_pi0_save
        m_Dpi0 = pD.M()
        rm_Dpi0 = (cms - pD).M()
        if pPi0.M() > 0:
            m_Dpi0 = (pD + pPi0).M()
            rm_Dpi0 = (cms - pD - pPi0).M()
        deltaM = 999.
        m_Dmisspi0 = pDmiss.M()
        rm_Dmisspi0 = (cms - pDmiss).M()
        for iPi0 in range(t_in.n_pi0):
            ppi0 = TLorentzVector(0, 0, 0, 0)
            ppi0.SetPxPyPzE(t_in.p4_pi0[iPi0 * 4 + 0],
                            t_in.p4_pi0[iPi0 * 4 + 1],
                            t_in.p4_pi0[iPi0 * 4 + 2],
                            t_in.p4_pi0[iPi0 * 4 + 3])
            if (fabs((pDmiss + ppi0).M() - 2.000685) < deltaM):
                deltaM = fabs((pDmiss + ppi0).M() - 2.01026)
                m_Dmisspi0 = (pDmiss + ppi0).M()
                rm_Dmisspi0 = (cms - pDmiss - ppi0).M()
        m_m_Dmisspi0[0] = m_Dmisspi0
        m_rm_Dmisspi0[0] = rm_Dmisspi0
        m_m_Dpi0[0] = m_Dpi0
        m_rm_Dpi0[0] = rm_Dpi0
        m_m_pi0[0] = pPi0.M()
        m_p_pi0[0] = pPi0.P()
        m_E_pi0[0] = pPi0.E()
        m_n_pi0[0] = t_in.n_pi0
        if MODE == 'STDDmiss_signal':
            m_matched_D[0] = t_in.matched_D
            m_matched_pi[0] = t_in.matched_pi
            m_matched_piplus[0] = t_in.matched_piplus
            m_matched_piminus[0] = t_in.matched_piminus
        m_indexmc[0] = t_in.indexmc
        for i in range(t_in.indexmc):
            m_motheridx[i] = t_in.motheridx[i]
            m_pdgid[i] = t_in.pdgid[i]
        t.Fill()
Esempio n. 15
0
            continue

        if nCand > 1:
            continue
        for candIdx in range(nCand):
            tk1p4 = TLorentzVector(event.tk1P1[candIdx], event.tk1P2[candIdx],
                                   event.tk1P3[candIdx], event.tk1P0[candIdx])
            tk2p4 = TLorentzVector(event.tk2P1[candIdx], event.tk2P2[candIdx],
                                   event.tk2P3[candIdx], event.tk2P0[candIdx])
            pmup4 = TLorentzVector(event.pmuP1[candIdx], event.pmuP2[candIdx],
                                   event.pmuP3[candIdx], event.pmuP0[candIdx])
            nmup4 = TLorentzVector(event.nmuP1[candIdx], event.nmuP2[candIdx],
                                   event.nmuP3[candIdx], event.nmuP0[candIdx])
            for idx, name in enumerate(strs):
                if pMass[idx] < 0. and nMass[idx] < 0.:
                    tk1p4.SetE((tk1p4.P()**2 + pMass[idx]**2)**0.5)
                    tk2p4.SetE((tk2p4.P()**2 + nMass[idx]**2)**0.5)
                    interFakeComp = tk1p4 + tk2p4
                    fakeCompCand = interFakeComp + pmup4 + nmup4

                    h[idx][0].Fill(fakeCompCand.Mag())
                    h[idx][2].Fill(interFakeComp.Mag())

                    tk1p4.SetE((tk1p4.P()**2 + nMass[idx]**2)**0.5)
                    tk2p4.SetE((tk2p4.P()**2 + pMass[idx]**2)**0.5)

                    interFakeComp = tk1p4 + tk2p4
                    fakeCompCand = interFakeComp + pmup4 + nmup4
                    h[idx][1].Fill(fakeCompCand.Mag())
                    h[idx][3].Fill(interFakeComp.Mag())
                    continue