Esempio n. 1
0
File: h.py Progetto: xbai0624/O_Scan
def stat_theta(theta2offset, theta4offset):
    theta2 = theta2offset
    theta4 = theta4offset

    hname = 'h_'
    h = TH1F(hname, hname, 10000, -100, 100)

    entry = len(x0)
    index = 0
    for index in range(entry):
        tx4 = (x4[index]) * TMath.Cos(theta4)
        tz4 = z[4] + (x4[index]) * TMath.Sin(theta4)
        tx2 = (x2[index]) * TMath.Cos(theta2)
        tz2 = z[2] + (x2[index]) * TMath.Sin(theta2)
        tx0 = x0[index]

        x_project = tx0 + (tx4 - tx0) * tz2 / tz4
        xm = tx2 - x_project
        h.Fill(xm)

    _ax = h.GetMaximumBin()
    ax = h.GetXaxis().GetBinCenter(_ax)
    h.Fit("gaus", "Q0", "", ax - 3.0, ax + 3.0)
    res = h.GetFunction("gaus").GetParameter(2)
    return res
Esempio n. 2
0
File: h.py Progetto: xbai0624/O_Scan
def rms_scan_theta(ii, jj, d):
    i = int(ii)
    j = int(jj)

    theta2 = theta_step[i]
    theta4 = theta_step[j]

    hname = 'h_' + str(i) + '_' + str(j)
    h = TH1F(hname, hname, 10000, -100, 100)

    entry = len(x0)
    index = 0
    for index in range(entry):
        tx4 = (x4[index]) * TMath.Cos(theta4)
        tz4 = z[4] + (x4[index]) * TMath.Sin(theta4)
        tx2 = (x2[index]) * TMath.Cos(theta2)
        tz2 = z[2] + (x2[index]) * TMath.Sin(theta2)
        tx0 = x0[index]

        x_project = tx0 + (tx4 - tx0) * tz2 / tz4
        xm = tx2 - x_project
        h.Fill(xm)

    _ax = h.GetMaximumBin()
    ax = h.GetXaxis().GetBinCenter(_ax)
    h.Fit("gaus", "Q0", "", ax - 3.0, ax + 3.0)
    #h.SetDirectory(file)
    #h.Write()
    res = h.GetFunction("gaus").GetParameter(2)
    d.value = res
Esempio n. 3
0
    def generate(self, add_particle):

        #photon energy and delta in nucleus rest frame
        w = c_double(0)
        d = c_double(0)
        self.dSigDwDt.GetRandom2(w, d)

        w = w.value
        d = d.value

        #polar angle theta
        theta_n = d * self.me / self.Ee_n

        #set the tree output
        self.tree_out.true_phot_w = w
        self.tree_out.true_phot_delta = d
        self.tree_out.true_phot_theta_n = theta_n

        #uniform azimuthal angle
        phi_n = 2. * TMath.Pi() * self.rand.Rndm()  #uniform azimuthal angle

        #photon
        phot = add_particle(particle(22))
        phot.stat = 1
        phot.pxyze_prec = 9

        #set the photon vector in nucleus rest frame
        px_n = w * TMath.Sin(theta_n) * TMath.Cos(phi_n)
        py_n = w * TMath.Sin(theta_n) * TMath.Sin(phi_n)
        pz_n = w * TMath.Cos(theta_n)

        phot.vec.SetPxPyPzE(px_n, py_n, pz_n, w)

        #transform the photon vector to laboratory frame
        phot.vec.Boost(-self.nbvec.x(), -self.nbvec.y(), -self.nbvec.z())

        #rotate the photon for pz < 0
        phot.vec.SetPxPyPzE(phot.vec.Px(), phot.vec.Py(), -phot.vec.Pz(),
                            phot.vec.E())

        #photon kinematics in generator output
        self.tree_out.true_phot_theta = phot.vec.Theta()
        self.tree_out.true_phot_phi = phot.vec.Phi()
        self.tree_out.true_phot_E = phot.vec.E()

        #scattered electron, initialize as beam
        electron = add_particle(beam(self.Ee, 11, -1))
        electron.stat = 1
        electron.pxyze_prec = 9

        #constrain the scattered electron with the photon
        electron.vec -= phot.vec

        #electron kinematics in generator output
        self.tree_out.true_el_theta = electron.vec.Theta()
        self.tree_out.true_el_phi = electron.vec.Phi()
        self.tree_out.true_el_E = electron.vec.E()
Esempio n. 4
0
def angleBetween(phi1, phi2):

    phi = TMath.ATan2(
        TMath.Sin(phi1) + TMath.Sin(phi2),
        TMath.Cos(phi1) + TMath.Cos(phi2))

    while phi >= TMath.Pi():
        phi -= 2 * TMath.Pi()
    while phi < -TMath.Pi():
        phi += 2 * TMath.Pi()

    return phi
Esempio n. 5
0
def GetCustomColor(x):
    # r,g,b in [0,255]
    omega_r = 2 * 0.12
    phi_r = -3.1415
    omega_g = 2 * 0.08
    phi_g = 1.57
    omega_b = 1.5 * 0.16
    phi_b = -3.1415 / 2.

    theta_r = 3.1415 * omega_r * x + phi_r
    theta_g = 3.1415 * omega_g * x + phi_g
    theta_b = 3.1415 * omega_b * x + phi_b
    r = 128 + round(127. * TMath.Cos(theta_r))
    g = 128 + round(127. * TMath.Cos(theta_g))
    b = 128 + round(127. * TMath.Cos(theta_b))
    #  printf("r,g,b = (%d,%d,%d)\n",r,g,b);
    return TColor.GetColor(r, g, b)
Esempio n. 6
0
    def gen_el(self, add_particle):

        #electron generator

        #energy
        en = self.emin + (self.emax - self.emin) * self.rand.Rndm()

        #polar angle
        theta = self.theta_min + (self.theta_max - self.theta_min) * self.rand.Rndm()

        #azimuthal angle
        phi = 2. * TMath.Pi() * self.rand.Rndm()

        #electron momentum
        ptot = TMath.Sqrt(en**2 - self.me**2)
        px = ptot * TMath.Sin(theta) * TMath.Cos(phi)
        py = ptot * TMath.Sin(theta) * TMath.Sin(phi)
        pz = ptot * TMath.Cos(theta)

        #make the electron
        el = particle(11)
        el.vec.SetPxPyPzE(px, py, pz, en)
        el.stat = 1
        el.pxyze_prec = 9

        #electron kinematics in output tree
        self.out.true_el_pT = el.vec.Pt()
        self.out.true_el_theta = el.vec.Theta()
        self.out.true_el_phi = el.vec.Phi()
        self.out.true_el_E = el.vec.E()

        #electron kinematics in hepmc
        self.hepmc_attrib["true_el_pT"] = self.out.true_el_pT
        self.hepmc_attrib["true_el_theta"] = self.out.true_el_theta
        self.hepmc_attrib["true_el_phi"] = self.out.true_el_phi
        self.hepmc_attrib["true_el_E"] = self.out.true_el_E

        #put the electron to the event
        add_particle( el )
Esempio n. 7
0
                       chain.Jpsi_phi[selectedjpsi], MJpsi)
    ptrimu.SetPtEtaPhiM(chain.Jpsi_mu3_pt[selectedjpsi],
                        chain.Jpsi_mu3_eta[selectedjpsi],
                        chain.Jpsi_mu3_phi[selectedjpsi], MMu)
    pmu3.SetPtEtaPhiM(chain.Jpsi_trimu_pt[selectedjpsi],
                      chain.Jpsi_trimu_eta[selectedjpsi],
                      chain.Jpsi_trimu_phi[selectedjpsi],
                      chain.Jpsi_trimu_mass[selectedjpsi])

    pperp = ptrimu.P() * TMath.Sin(chain.Jpsi_trimu_alpha[selectedjpsi])
    mcorr[0] = TMath.Sqrt((chain.Jpsi_trimu_mass[selectedjpsi])**2 +
                          pperp**2) + pperp

    dphi_Jpsi_mu3[0] = pJpsi.DeltaPhi(pmu3)
    dR_Jpsi_mu3[0] = pJpsi.DeltaR(pmu3)
    cosdphi_Jpsi_mu3[0] = TMath.Cos(dphi_Jpsi_mu3[0])

    for var in outvars:
        tmp = getattr(chain, var)[selectedjpsi]
        getattr(chain, var).clear()
        getattr(chain, var).push_back(tmp)
    if not isData:
        cuthist.Fill(1)
        cuthist.Fill(2, weight_evt)
        #for var in evt_outvars:
        #    tmp = getattr(chain,var)[selectedjpsi]
        #    getattr(chain,var).clear()
        #    getattr(chain,var).push_back(tmp)
    otree.Fill()

outputfile.cd()
Esempio n. 8
0
def PruneGenr8File(fname_in,
                   fname_out,
                   e_gamma_curr,
                   theta_curr,
                   verbose=False):

    # print "directory: " + os.getcwd()
    # print "input genr8 file: " + fname_in
    # print "output file: " + fname_out

    counter = 1

    line1_out = ""  #Run and event info
    line2_out = ""  #Gamma ID info
    line3_out = ""  #Gamma P4 info
    line4_out = ""  #Proton ID info
    line5_out = ""  #Proton P4 info
    line6_out = ""  #Pi+ ID info
    line7_out = ""  #Pi+ P4 info
    line8_out = ""  #Pi- ID info
    line9_out = ""  #Pi- P4 info

    rand = TRandom3(int(e_gamma_curr * 1000.))
    p4_proton = TLorentzVector()
    for line in open(fname_in, 'r'):

        if (counter % 9 == 1):  #Event info
            value_in_line = 1
            run = ""
            event = ""
            for value in line.split():
                if (value_in_line == 1): run = value
                if (value_in_line == 2): event = value
                if (verbose and value_in_line == 1): print "Run " + value
                if (verbose and value_in_line == 2): print "Event " + value
                if (verbose and value_in_line == 3):
                    print "NParticles " + value
                value_in_line += 1
                line1_out = run + " " + event + " " + "4\n"
        if (counter % 9 == 2):  #Pi0 info
            value_in_line = 1
            for value in line.split():
                if (verbose and value_in_line == 1):
                    print "Particle number in event: " + value
                if (verbose and value_in_line == 2):
                    print "Particle enum value " + value
                if (verbose and value_in_line == 3):
                    print "Particle mass " + value
                value_in_line += 1
        if (counter % 9 == 3):  #Pi0 p4
            value_in_line = 1
            p4_string = line.split()
            p4_gam1 = TLorentzVector(float(p4_string[1]), float(p4_string[2]),
                                     float(p4_string[3]), float(p4_string[4]))
            for value in line.split():
                if (verbose and value_in_line == 1): print "Charge: " + value
                if (verbose and value_in_line == 2): print "Px " + value
                if (verbose and value_in_line == 3): print "Py " + value
                if (verbose and value_in_line == 4): print "Pz " + value
                if (verbose and value_in_line == 5): print "E " + value
                value_in_line += 1
        if (counter % 9 == 4):  #Pi+ info
            value_in_line = 1
            line2_str = line
            for value in line.split():
                if (verbose and value_in_line == 1):
                    print "Particle number in event: " + value
                if (verbose and value_in_line == 2):
                    print "Particle enum value " + value
                if (verbose and value_in_line == 3):
                    print "Particle mass " + value
                value_in_line += 1
                line6_out = "3 8 0.13957\n"
        if (counter % 9 == 5):  #Pi+ p4
            value_in_line = 1
            p4_string = line.split()
            p4_pipl = TLorentzVector(float(p4_string[1]), float(p4_string[2]),
                                     float(p4_string[3]), float(p4_string[4]))
            for value in line.split():
                if (verbose and value_in_line == 1): print "Charge: " + value
                if (verbose and value_in_line == 2): print "Px " + value
                if (verbose and value_in_line == 3): print "Py " + value
                if (verbose and value_in_line == 4): print "Pz " + value
                if (verbose and value_in_line == 5): print "E " + value
                value_in_line += 1
            line7_out = "   1 " + str(p4_pipl.Px()) + " " + str(
                p4_pipl.Py()) + " " + str(p4_pipl.Pz()) + " " + str(
                    p4_pipl.E()) + "\n"
        if (counter % 9 == 6):  #Pi- info
            value_in_line = 1
            for value in line.split():
                if (verbose and value_in_line == 1):
                    print "Particle number in event: " + value
                if (verbose and value_in_line == 2):
                    print "Particle enum value " + value
                if (verbose and value_in_line == 3):
                    print "Particle mass " + value
                value_in_line += 1
                line8_out = "4 9 0.13957\n"
        if (counter % 9 == 7):  #Pi- p4
            value_in_line = 1
            p4_string = line.split()
            p4_pim = TLorentzVector(float(p4_string[1]), float(p4_string[2]),
                                    float(p4_string[3]), float(p4_string[4]))
            for value in line.split():
                if (verbose and value_in_line == 1): print "Charge: " + value
                if (verbose and value_in_line == 2): print "Px " + value
                if (verbose and value_in_line == 3): print "Py " + value
                if (verbose and value_in_line == 4): print "Pz " + value
                if (verbose and value_in_line == 5): print "E " + value
                value_in_line += 1
            line9_out = "   -1 " + str(p4_pim.Px()) + " " + str(
                p4_pim.Py()) + " " + str(p4_pim.Pz()) + " " + str(
                    p4_pim.E()) + "\n"
        if (counter % 9 == 8):  #proton info
            value_in_line = 1
            for value in line.split():
                if (verbose and value_in_line == 1):
                    print "Particle number in event: " + value
                if (verbose and value_in_line == 2):
                    print "Particle enum value " + value
                if (verbose and value_in_line == 3):
                    print "Particle mass " + value
                value_in_line += 1
                line4_out = "2 14 0.938272\n"
        if (counter % 9 == 0):  #proton p4
            value_in_line = 1
            p4_string = line.split()
            p4_proton = TLorentzVector(float(p4_string[1]),
                                       float(p4_string[2]),
                                       float(p4_string[3]),
                                       float(p4_string[4]))
            p4_proton_boost_px = p4_proton.Px()
            p4_proton_boost_py = p4_proton.Py()
            p4_proton_boost_pz = p4_proton.Pz()
            p4_proton_boost_E = sqrt(
                abs(p4_proton_boost_px**2 + p4_proton_boost_py**2 +
                    p4_proton_boost_pz**2 - 0.938272**2))
            p4_proton_boost = TLorentzVector(p4_proton_boost_px,
                                             p4_proton_boost_py,
                                             p4_proton_boost_pz,
                                             p4_proton_boost_E)

            for value in line.split():
                if (verbose and value_in_line == 1): print "Charge: " + value
                if (verbose and value_in_line == 2): print "Px " + value
                if (verbose and value_in_line == 3): print "Py " + value
                if (verbose and value_in_line == 4): print "Pz " + value
                if (verbose and value_in_line == 5): print "E " + value
                value_in_line += 1
                line5_out = "   1 " + str(p4_proton.Px()) + " " + str(
                    p4_proton.Py()) + " " + str(p4_proton.Pz()) + " " + str(
                        p4_proton.E()) + "\n"

            my_phi = p4_proton_boost.Phi() + 3.14159  #Opposite proton
            my_theta = theta_curr * (3.14159 / 180.)
            gamma_px = str(e_gamma_curr * TMath.Sin(my_theta) *
                           TMath.Cos(my_phi))
            gamma_py = str(e_gamma_curr * TMath.Sin(my_theta) *
                           TMath.Sin(my_phi))
            gamma_pz = str(e_gamma_curr * TMath.Cos(my_theta))
            line2_out = "1 1 0\n"
            line3_out = "   0 " + gamma_px + " " + gamma_py + " " + gamma_pz + " " + str(
                e_gamma_curr) + "\n"
            p4_gam_fcal = TLorentzVector(float(gamma_px), float(gamma_py),
                                         float(gamma_pz), e_gamma_curr)

            # print "Beam photon: " + str( (p4_gam_fcal+p4_proton_boost).E())

            with open(fname_out, "a") as myfile:
                myfile.write(line1_out)
                myfile.write(line2_out)
                myfile.write(line3_out)
                myfile.write(line4_out)
                myfile.write(line5_out)
                myfile.write(line6_out)
                myfile.write(line7_out)
                myfile.write(line8_out)
                myfile.write(line9_out)

        counter += 1

        # if(counter>200): break

    return
Esempio n. 9
0
def MT(obj1, obj2):
    ''' Transverse mass of the diobject system '''
    return TMath.Sqrt(2 * obj1.Pt() * obj2.Pt() *
                      (1 - TMath.Cos(obj1.DeltaPhi(obj2))))
Esempio n. 10
0
 def getMT(self, lep1Vec):
     met = self.met
     #mt = event.mt/1000.
     #if( self.getDphiL1MET(lep1Vec.Phi()) > -99. ):
     mt = TMath.Sqrt(2*lep1Vec.Pt()*met*(1-TMath.Cos(self.getDphiL1MET(lep1Vec.Phi()))))
     return mt
Esempio n. 11
0
    def generate(self, add_particle):

        #get the x and y for a given range in Q^2
        while True:

            #values of u = log_10(x) and v = log_10(y) from the cross section
            u = c_double(0)
            v = c_double(0)
            self.eq.GetRandom2(u, v)

            u = u.value
            v = v.value

            #x and y from the transformation
            x = 10.**u
            y = 10.**v

            #scattered electron energy and polar angle in proton beam rest frame
            en_p = self.Ee_p*(1 - y)
            theta_p = 2 * TMath.ASin( 0.5*TMath.Sqrt(x*y*self.s/((1-y)*self.Ee_p**2)) )

            #prevent unphysical energy and angle
            if theta_p < 0. or theta_p > pi: continue
            if en_p**2 < self.me**2: continue

            #event Q^2
            Q2 = x*y*self.s

            self.nall += 1 # increment all events counter

            #select the range in Q^2
            if Q2 < self.Q2min or Q2 > self.Q2max: continue

            self.nsel += 1 # increment selected counter

            break

        #scattered electron in the event
        el = add_particle( particle(11) )
        el.stat = 1
        el.pxyze_prec = 9

        #kinematics for scattered electron in proton beam rest frame
        phi_p = 2. * TMath.Pi() * self.rand.Rndm() #uniform azimuthal angle
        elp_p = TMath.Sqrt(en_p**2 - self.me**2) #total momentum

        #set the scattered electron vector in proton beam rest frame
        px_p = elp_p*TMath.Sin(theta_p)*TMath.Cos(phi_p)
        py_p = elp_p*TMath.Sin(theta_p)*TMath.Sin(phi_p)
        pz_p = elp_p*TMath.Cos(theta_p)

        el.vec.SetPxPyPzE(px_p, py_p, pz_p, en_p)

        #transform the scattered electron vector to the laboratory frame, negative z direction
        el.vec.Boost(-self.pbvec.x(), -self.pbvec.y(), -self.pbvec.z()) # transform to lab
        el.vec.SetPxPyPzE(el.vec.Px(), el.vec.Py(), -el.vec.Pz(), el.vec.E()) # rotate for pz<0

        #tree output with generator kinematics
        self.out.gen_u = u
        self.out.gen_v = v
        self.out.true_x = x
        self.out.true_y = y
        self.out.true_Q2 = Q2
        self.out.true_W2 = self.s*y

        #hepmc event attributes
        self.hepmc_attrib["truex"] = x
        self.hepmc_attrib["truey"] = y
        self.hepmc_attrib["trueQ2"] = Q2
        self.hepmc_attrib["trueW2"] = self.s*y

        #electron kinematics
        self.out.true_el_pT = el.vec.Pt()
        self.out.true_el_theta = el.vec.Theta()
        self.out.true_el_phi = el.vec.Phi()
        self.out.true_el_E = el.vec.E()

        self.hepmc_attrib["true_el_pT"] = self.out.true_el_pT
        self.hepmc_attrib["true_el_theta"] = self.out.true_el_theta
        self.hepmc_attrib["true_el_phi"] = self.out.true_el_phi
        self.hepmc_attrib["true_el_E"] = self.out.true_el_E

        #Q^2 from electron energy and angle
        self.out.true_el_Q2 = 2.*self.Ee*el.vec.E()*(1.-TMath.Cos(TMath.Pi()-el.vec.Theta()))

        self.hepmc_attrib["true_el_Q2"] = self.out.true_el_Q2
Esempio n. 12
0
def MT(Pt, met, dphi):
    return TMath.Sqrt(2 * Pt * met * (1.0 - TMath.Cos(dphi)))
Esempio n. 13
0
def getMT(Pt, met, phi1, phi2):

    dphi = DeltaPhi(phi1, phi2)
    return TMath.Sqrt(2 * Pt * met * (1.0 - TMath.Cos(dphi)))
Esempio n. 14
0
def reconstruct(config):

    #configuration
    cf = read_con(config)

    #input reconstruction matrix Rijk
    mat = rmat(infile=cf.str("inp_rec_Rijk"))

    #input data for reconstruction
    inlist = glob(cf.str("inp_rec_data"))
    tree = TChain("DetectorTree")
    for i in inlist:
        tree.Add(i)

    #output from reconstruction
    out = TFile(cf.str("out_rec"), "recreate")
    rec_tree = TTree("Q2rec", "Q2rec")

    #set the output tree
    gROOT.ProcessLine("struct Entry {Double_t v;};")
    true_Q2 = make_branch("true_Q2", rec_tree, rt.Entry)
    true_el_E = make_branch("true_el_E", rec_tree, rt.Entry)
    true_el_theta = make_branch("true_el_theta", rec_tree, rt.Entry)
    true_mlt = make_branch("true_mlt", rec_tree, rt.Entry)
    true_lq = make_branch("true_lq", rec_tree, rt.Entry)

    hit_x = make_branch("hit_x", rec_tree, rt.Entry)
    hit_y = make_branch("hit_y", rec_tree, rt.Entry)
    hit_E = make_branch("hit_E", rec_tree, rt.Entry)
    rec_mlt = make_branch("rec_mlt", rec_tree, rt.Entry)
    rec_Q2 = make_branch("rec_Q2", rec_tree, rt.Entry)
    rec_lq = make_branch("rec_lq", rec_tree, rt.Entry)

    #number of events
    nev = cf.int("nev")
    if nev < 0: nev = tree.GetEntries()

    #range in mlt
    mlt_range = [cf("tmin"), cf("tmax")]

    print("Event loop, events:", nev)
    iprint = int(nev / 12)
    evt = TagV2Evt(tree, cf)
    for iev in range(nev):

        if iev % iprint == 0:
            print("{0:.1f} %".format(100. * iev / nev))
            stdout.flush()

        #read the event
        if not evt.read(iev): continue

        #input true values
        true_lq.v = evt.true_lq

        #energy index 'i'
        i = mat.hEi.FindBin(evt.hit_E)
        if i < 1 or i > mat.hEi.GetNbinsX(): continue

        #mlt at 'j' and 'k'
        jk = mat.tjks[i].hTjk.FindBin(evt.hit_x, evt.hit_y)
        #print jk
        mlt = mat.tjks[i].hTjk.GetBinContent(jk)
        if mlt < mlt_range[0] or mlt > mlt_range[1]:
            continue

        #electron scattering angle
        theta = 10**(-mlt)
        #print theta

        #reconstructed Q^2
        rec_Q2.v = 2. * 18 * evt.hit_E * (1. - TMath.Cos(theta))
        rec_lq.v = TMath.Log10(rec_Q2.v)
        #print(rec_lq.v, true_lq.v)

        #print mlt, evt.true_mlt

        rec_tree.Fill()

    rec_tree.Write()
    out.Close()

    print("All done")
Esempio n. 15
0
    def generate(self, add_particle):

        #return

        #photon energy and delta in nucleus rest frame
        #w = c_double(0)
        #d = c_double(0)
        #self.dSigDwDt.GetRandom2(w, d)

        #w = w.value
        #d = d.value

        #photon energy and delta in nucleus rest frame by FOAM
        wdvec = std.vector("double")(2)
        self.foam.MakeEvent()
        self.foam.GetMCvect(wdvec.data())

        w = wdvec[0] * self.Ee
        d = wdvec[1] * self.dmax

        #set the tree output
        self.tree_out.true_phot_w = w
        self.tree_out.true_phot_delta = d

        #polar angle theta
        theta = d * self.me / self.Ee

        #uniform azimuthal angle
        phi = 2. * TMath.Pi() * self.rand.Rndm()

        #photon
        phot = add_particle(particle(22))
        phot.stat = 1
        phot.pxyze_prec = 9

        #photon vector, negative pz
        px = w * TMath.Sin(theta) * TMath.Cos(phi)
        py = w * TMath.Sin(theta) * TMath.Sin(phi)
        pz = w * TMath.Cos(theta)

        phot.vec.SetPxPyPzE(px, py, -pz, w)

        #photon kinematics in generator output
        self.tree_out.true_phot_theta = phot.vec.Theta()
        self.tree_out.true_phot_phi = phot.vec.Phi()
        self.tree_out.true_phot_E = phot.vec.E()

        #scattered electron, initialize as beam and constrain with the photon
        electron = add_particle(beam(self.Ee, 11, -1))
        electron.stat = 1
        electron.pxyze_prec = 9

        electron.vec -= phot.vec

        #z-vertex from the pressure
        zpos = self.pressure_func.GetRandom()
        phot.vz = zpos
        electron.vz = zpos

        #xy vertex and divergence from lattice
        xpos, ypos, divx, divy = self.beam_par(zpos)
        phot.vx = xpos
        phot.vy = ypos
        electron.vx = xpos
        electron.vy = ypos

        #vertex position and divergence in output tree
        self.tree_out.vtx_x = xpos
        self.tree_out.vtx_y = ypos
        self.tree_out.vtx_z = zpos
        self.tree_out.divx = divx
        self.tree_out.divy = divy

        #divergence in x by rotation along y
        phot.vec.RotateY(divx)
        electron.vec.RotateY(divx)

        #divergence in y by rotation along x
        phot.vec.RotateX(divy)
        phot.vec.RotateX(divy)
Esempio n. 16
0
 def getMT(self, lep1Vec):
     met = self.met
     mt = TMath.Sqrt(2 * lep1Vec.Pt() * met *
                     (1 - TMath.Cos(self.getDphiL1MET(lep1Vec.Phi()))))
     return mt
Esempio n. 17
0
                    chain.JpsiMu_B_mass[selectedmu3])
    #pmet.SetPtEtaPhiE(chain.MET_et[0], 2, chain.MET_phi[0], -chain.MET_et[0])

    pperp = pB.P() * TMath.Sin(TMath.ACos(chain.JpsiMu_B_alpha[selectedmu3]))
    JpsiMu_B_mcorr[0] = TMath.Sqrt((chain.JpsiMu_B_mass[selectedmu3])**2 +
                                   pperp**2) + pperp

    dphi_mu1_mu3[0] = pmu1.DeltaPhi(pmu3)
    dphi_mu1_mu2[0] = pmu1.DeltaPhi(pmu2)
    dphi_mu2_mu3[0] = pmu2.DeltaPhi(pmu3)
    #dphi_Jpsi_MET[0] = pJpsi.DeltaPhi(pmet)
    #dphi_mu3_MET[0] = pmu3.DeltaPhi(pmet)
    dR_mu1_mu3[0] = pmu1.DeltaR(pmu3)
    dR_mu1_mu2[0] = pmu1.DeltaR(pmu2)
    dR_mu2_mu3[0] = pmu2.DeltaR(pmu3)
    cosdphi_mu1_mu3[0] = TMath.Cos(dphi_mu1_mu3[0])
    cosdphi_mu1_mu2[0] = TMath.Cos(dphi_mu1_mu2[0])
    cosdphi_mu2_mu3[0] = TMath.Cos(dphi_mu2_mu3[0])
    #cosdphi_Jpsi_MET[0] = TMath.Cos(dphi_Jpsi_MET[0])
    #cosdphi_mu3_MET[0] = TMath.Cos(dphi_mu3_MET[0])

    JpsiMu_B_reliso[
        0] = chain.JpsiMu_B_iso[selectedmu3] / chain.JpsiMu_B_pt[selectedmu3]
    JpsiMu_mu3_reldbiso[0] = chain.JpsiMu_mu3_dbiso[
        selectedmu3] / chain.JpsiMu_mu3_pt[selectedmu3]
    JpsiMu_mu2_reldbiso[0] = chain.JpsiMu_mu2_dbiso[
        selectedmu3] / chain.JpsiMu_mu2_pt[selectedmu3]
    JpsiMu_mu1_reldbiso[0] = chain.JpsiMu_mu1_dbiso[
        selectedmu3] / chain.JpsiMu_mu1_pt[selectedmu3]

    #Gen Level
Esempio n. 18
0
    def fill(self, event):
        #print 'this is the DSID: %s' % self.DSID
        weight=float(1.0)
        totalWeight=float(1.0)
        intLumi = 36300.0 #Same as used by Lorenzo Rossini
        #intLumi = 3230.0 #data16PeriodC (in pb^-1)
        #intLumi = 2582.0 #date16PeriodK (in pb^-1)
        #intLumi = 2222.0 #(in pb^-1)
        #intLumi = 2147.0 #(in pb^-1)
        #intLumi = 1948.44 #(in pb^-1)
        #intLumi = 5812.0 #(in pb^-1)
        #intLumi = 1.0

        #Initialize TLorentz vectors
        lep1Vec = ROOT.TLorentzVector()
        lep2Vec = ROOT.TLorentzVector()
        jet1Vec = ROOT.TLorentzVector()
        jet2Vec = ROOT.TLorentzVector()

        #Get variables from tree for filling histogram
        mu = event.mu
        nVtx = event.nVtx
        datasetNum = event.DatasetNumber
        MET=event.met_Et
        MET_Phi = event.met_Phi
        ht30 = event.Ht30
        if event.jetPt.size() > 0: jet1Vec.SetPtEtaPhiM(event.jetPt[0], event.jetEta[0], event.jetPhi[0], event.jetM[0])
        if event.jetPt.size() > 1: jet2Vec.SetPtEtaPhiM(event.jetPt[1], event.jetEta[1], event.jetPhi[1], event.jetM[1])
        dphi_j1met = TVector2.Phi_mpi_pi(jet1Vec.Phi() - MET_Phi) 
        dphi_j2met = TVector2.Phi_mpi_pi(jet2Vec.Phi() - MET_Phi) 
        nJet25 = event.nJet25
        mt = event.mt
        nLep_base = event.nLep_base
        nLep_signal = event.nLep_signal

        obs = observable()
        lep1Vec, lep1Charge, lep1Flavor = obs.getLep1TLVChargeFlavor(event)
        lep2Vec, lep2Charge, lep2Flavor = obs.getLep2TLVChargeFlavor(event)

        #Calculate dilepton variables
        lepPairVec = lep1Vec + lep2Vec
        mll = lepPairVec.M()
        ptll = lepPairVec.Pt()
        qlql = lep1Charge*lep2Charge
        dphi_l1met = TVector2.Phi_mpi_pi(lep1Vec.Phi() - MET_Phi) 
        dphi_l2met = TVector2.Phi_mpi_pi(lep2Vec.Phi() - MET_Phi) 
        dphi_l1l2  = lep2Vec.DeltaPhi(lep1Vec)
        mt_l1met = TMath.Sqrt(2*lep1Vec.Pt()*MET*(1-TMath.Cos(dphi_l1met)))
        mt_l2met = TMath.Sqrt(2*lep2Vec.Pt()*MET*(1-TMath.Cos(dphi_l2met)))
        mtautau = -999.
        dR_l1l2 = -999.
        if nLep_signal >= 2:
            dR_l1l2  = lep2Vec.DeltaR(lep1Vec)
            mtautau = obs.calcMtautau(event)

        genWeight = event.genWeight

        #Calculating weight
        if self.isdata:
            totalWeight = 1.0
        else:
            totalWeight = float(event.SherpaVjetsNjetsWeight*event.ttbarNNLOWeight*event.pileupWeight*event.eventWeight*event.leptonWeight*event.jvtWeight*event.bTagWeight*genWeight) #TODO: NO TRIGGER WEIGHT!!

        self.hists["mu"].Fill(float(mu), totalWeight)
        self.hists["MET"].Fill(float(MET), totalWeight)
        self.hists["Lep1Pt"].Fill(float(lep1Vec.Pt()), totalWeight)
        self.hists["Lep2Pt"].Fill(float(lep2Vec.Pt()), totalWeight)
        self.hists["Lep1Eta"].Fill(float(lep1Vec.Eta()), totalWeight)
        if lep1Flavor == 1: self.hists["ElPt"].Fill(int(lep1Vec.Pt()), totalWeight) 
        elif lep1Flavor == 2: self.hists["MuPt"].Fill(int(lep1Vec.Pt()), totalWeight) 
        if lep2Flavor == 1: self.hists["ElPt"].Fill(int(lep2Vec.Pt()), totalWeight) 
        elif lep2Flavor == 2: self.hists["MuPt"].Fill(int(lep2Vec.Pt()), totalWeight) 
        self.hists["Lep2Eta"].Fill(float(lep2Vec.Eta()), totalWeight)
        self.hists["Jet1Pt"].Fill(float(jet1Vec.Pt()), totalWeight)
        self.hists["Jet2Pt"].Fill(float(jet2Vec.Pt()), totalWeight)
        self.hists["nLepSignal"].Fill(float(nLep_signal), totalWeight)
        self.hists["nJet25"].Fill(float(nJet25), totalWeight)
        self.hists["nVtx"].Fill(float(nVtx), totalWeight)
        self.hists["mll"].Fill(float(mll), totalWeight)
        self.hists["mll2"].Fill(float(mll), totalWeight)
        self.hists["ptll"].Fill(float(ptll), totalWeight)
        self.hists["dphiJ1met"].Fill(float((-1)*math.fabs(dphi_j1met)), totalWeight)
        self.hists["dphiJ2met"].Fill(float((-1)*math.fabs(dphi_j2met)), totalWeight)
        self.hists["dphiL1met"].Fill(float(math.fabs(dphi_l1met)), totalWeight)
        self.hists["dphiL2met"].Fill(float(math.fabs(dphi_l2met)), totalWeight)
        self.hists["dphiL1L2"].Fill(float( math.fabs(dphi_l1l2)), totalWeight)
        self.hists["dRL1L2"].Fill(float(dR_l1l2), totalWeight)
        self.hists["lepCharge"].Fill(int(lep1Charge), totalWeight)
        self.hists["lepCharge"].Fill(int(lep2Charge), totalWeight)
        self.hists["qlql"].Fill(int(qlql), totalWeight)
        self.hists["lepFlavor"].Fill(int(lep1Flavor), totalWeight)
        self.hists["lepFlavor"].Fill(int(lep2Flavor), totalWeight)
        if (ht30): self.hists["METoverHt"].Fill(float(MET/ht30), totalWeight)
        self.hists["Ht30"].Fill(float(ht30), totalWeight)
        self.hists["Mt"].Fill(float(mt), totalWeight)
        self.hists["MtL1met"].Fill(float(mt_l1met), totalWeight)
        self.hists["MtL2met"].Fill(float(mt_l2met), totalWeight)
        self.hists["MTauTau"].Fill(float(mtautau), totalWeight)