Esempio n. 1
0
def make2Dresponse(responses, jetPt, meas, true, misses=None, fakes=None):
    print("++++++++ Create Response from 3D histograms ++++++++")
    response2D = RooUnfoldResponse(meas, true)
    for r, pT, i in zip(responses, jetPt, range(len(responses))):
        nx = r.GetNbinsX()
        ny = r.GetNbinsY()
        nz = r.GetNbinsZ()
        pttrue = (pT[0] + pT[1]) / 2.0
        print("{:.0f}%".format(100.0 * i / len(jetPt)))
        for ix in range(0, nx):
            for iy in range(0, ny):
                for iz in range(1, nz):
                    ib = r.GetBin(ix, iy, iz)
                    c = r.GetBinContent(ib)
                    jttrue = r.GetZaxis().GetBinCenter(iz)
                    # if iy == 0 and ix == 0:
                    # response2D.Miss(jttrue,pttrue,c)
                    if ix > 0 and iy > 0:
                        jtobs = r.GetXaxis().GetBinCenter(ix)
                        jtobs_meas = meas.GetXaxis().GetBinCenter(ix)
                        ptobs_meas = meas.GetYaxis().GetBinCenter(iy)
                        if TMath.Abs(jtobs - jtobs_meas) > 0.01:
                            print("jtobs: {}, jtobs_meas: {}".format(
                                jtobs, jtobs_meas))
                            raise ValueError(
                                "Incorrect binning in make2Dresponse")
                        ptobs = r.GetYaxis().GetBinCenter(iy)
                        if TMath.Abs(ptobs - ptobs_meas) > 0.01:
                            print("ptobs: {}, ptobs_meas: {}".format(
                                ptobs, ptobs_meas))
                            raise ValueError(
                                "Incorrect binning in make2Dresponse")
                        jttrue = r.GetZaxis().GetBinCenter(iz)
                        response2D.Fill(jtobs, ptobs, jttrue, pttrue, c)
    print("{:.0f}%".format(100))

    if misses != None:
        nx = misses.GetNbinsX()
        ny = misses.GetNbinsY()
        for ix in range(1, nx):
            for iy in range(1, ny):
                ib = misses.GetBin(ix, iy)
                c = misses.GetBinContent(ib)
                jttrue = misses.GetXaxis().GetBinCenter(ix)
                pttrue = misses.GetYaxis().GetBinCenter(iy)
                # print("jtTrue: {}, ptTrue: {}, Misses: {}".format(jttrue,pttrue,c))
                response2D.Miss(jttrue, pttrue, c)
    if fakes != None:
        nx = fakes.GetNbinsX()
        ny = fakes.GetNbinsY()
        for ix in range(1, nx):
            for iy in range(1, ny):
                ib = fakes.GetBin(ix, iy)
                c = fakes.GetBinContent(ib)
                jtobs = fakes.GetXaxis().GetBinCenter(ix)
                ptobs = fakes.GetYaxis().GetBinCenter(iy)
                # print("jtObs: {}, ptObs: {}, Fakes: {}".format(jtobs,ptobs,c))
                response2D.Fake(jtobs, ptobs, c)
    return response2D
Esempio n. 2
0
def SelectKfromDevents(TrueID, TrueMID):
    if mt.Abs(TrueID) in Kcodes:
        if mt.Abs(TrueMID) in Dcodes:
            return 1
        else:
            return 0
    else:
        return 0
Esempio n. 3
0
    def read(self, iev):

        #read a given event

        if iev >= self.nev: return False

        self.tree.GetEntry(iev)

        #initialize event variables
        self.epos = 0.
        self.eneg = 0.

        self.npos = 0
        self.nneg = 0

        self.is_XnXn = False
        self.is_Cen = True

        vec = TLorentzVector()

        #particle loop
        for imc in xrange(self.particles.GetEntriesFast()):
            part = self.particles.At(imc)

            #central electron and positron
            if TMath.Abs(part.GetPdgCode()) == 11:
                if TMath.Abs(part.Eta()) > self.aeta_max: self.is_Cen = False
                #if part.P() < self.p_min: self.is_Cen = False
                pv = TLorentzVector()
                part.Momentum(pv)
                vec += pv

            #select the neutrons
            if part.GetPdgCode() != 2112: continue

            #energy at positive and negative rapidity
            if part.Eta() > 0:
                self.epos += part.Energy()
                self.npos += 1
            else:
                self.eneg += part.Energy()
                self.nneg += 1

        #particle loop

        #flag for XnXn event
        if self.npos > 0 and self.nneg > 0: self.is_XnXn = True

        #J/psi kinematics
        self.pT = vec.Pt()
        self.y = vec.Rapidity()
        self.m = vec.M()

        return True
Esempio n. 4
0
def AssignMassIsoParticle_wTrueID(TrueID):
    m = m_pi
    isK = 0
    if mt.Abs(TrueID) in Kcodes:
        m = m_K
        isK = 1
    else:
        if mt.Abs(TrueID) == 2212:
            m = m_p
        else:
            m = m_pi
    return m, isK
Esempio n. 5
0
def get_pos(
    event
):  # Each detector is a 'collection', the No. of Elements are the hits.

    n = TH1F("n", "Zenith Angles", 100, 0,
             2)  # first histogram to be filled with particles below the cut
    m = TH1F("m", "Zenith Angles", 100, 0, 2)  # second for above
    k = 0  # counter for the number of particles below
    mcpart = event.getCollection(
        "MCParticle")  # essentially 'opens up' the collection

    for ding in mcpart:  # for every entry in the collection - can be called whatever
        mom = ding.getMomentum(
        )  # gets the momentum in a 3 vector fro mthe slcio file collection

        if ding.getPDG() == 11 or ding.getPDG() == -11 and mom[
                2] != 0:  # condition that only allows electrons or positrons (their pdg id) also, the momenta cant be 0

            x = mom[0]  # assign a vales from the 3 vector to a variable
            y = mom[1]
            z = mom[2]
            if z == 0:
                print "weird angle..."  # was to show me how many zeros I was getting

            t = TMath.Sqrt(
                (x * x) +
                (y * y))  # calculates transverse momentum using Pythatgoras
            if t < 0.0075:  # this is the cut value of 7.5 GeV

                k += 1

                try:  # try statement allows to get around division by 0
                    theta = TMath.ATan(t / TMath.Abs(z))  # calculate the angle
                except ZeroDivisionError:

                    theta = 90  # if the z momentum is 0, the angle is 90.

                n.Fill(
                    theta, 1
                )  # fills up the histogram so the value of theta gets 1 extra weight per cycle

            else:  # if the transverse momentum is above
                try:
                    theta = TMath.ATan(t / TMath.Abs(z))
                except ZeroDivisionError:

                    theta = 90

                m.Fill(theta, 1)  # fills the other histogram

    print "number of particles with transverse momenta < 7.5 MeV: ", k

    return n, m  # returns the two histograms
Esempio n. 6
0
def SelectTrueKevents(TrueID, TrueMID, TrueID2, TrueMID2):
    Kfound, Kfound2 = 0, 0
    KfromDfound, KfromDfound2 = 0, 0
    if mt.Abs(TrueID) in Kcodes:
        Kfound = 1
        if mt.Abs(TrueMID) in Dcodes:
            KfromDfound = 1
    if mt.Abs(TrueID2) in Kcodes:
        Kfound2 = 1
        if mt.Abs(TrueMID2) in Dcodes:
            KfromDfound2 = 1
    if Kfound == 1 or Kfound2 == 1:
        if KfromDfound == 1 or KfromDfound2 == 1:
            return 1
        else:
            return 0
    else:
        return 0
Esempio n. 7
0
    def _SideBandsFunc(self, x, par):
        '''
        Function where only sidebands are considered.

        Parameters
        ----------
        - x: function variable
        - par: function parameters
        '''
        if self.removePeak and TMath.Abs(x[0] -
                                         self.peakMass) < self.peakDelta:
            TF1.RejectPoint()
            return 0
        if self.removeSecPeak and TMath.Abs(
                x[0] - self.secPeakMass) < self.secPeakDelta:
            TF1.RejectPoint()
            return 0

        return getattr(self, self.__implFunc[self.funcName])(x, par)
Esempio n. 8
0
def fnc_dscb(xx, pp):
    x = xx[0]
    N = pp[0]
    mu = pp[1]
    sig = pp[2]
    a1 = pp[3]
    p1 = pp[4]
    a2 = pp[5]
    p2 = pp[6]

    u = (x - mu) / sig
    A1 = TMath.Power(p1 / TMath.Abs(a1), p1) * TMath.Exp(-a1 * a1 / 2.0)
    A2 = TMath.Power(p2 / TMath.Abs(a2), p2) * TMath.Exp(-a2 * a2 / 2.0)
    B1 = p1 / TMath.Abs(a1) - TMath.Abs(a1)
    B2 = p2 / TMath.Abs(a2) - TMath.Abs(a2)

    result = N
    if (u < -a1):
        result *= A1 * TMath.Power(B1 - u, -p1)
    if (-a1 < u < a2):
        result *= TMath.Exp(-u * u / 2.0)
    if (u > a2):
        result *= A2 * TMath.Power(B2 + u, -p2)

    return result
Esempio n. 9
0
 def __call__(self, x, par):
     out = 0
     t = (x[0] - par[1]) / par[2]
     if (par[0] < 0): t = -t
     absAlpha = TMath.Abs(par[3])
     if (t >= -absAlpha):
         out = par[0] * TMath.Exp(-0.5 * t * t)
     else:
         a = TMath.Power(par[4] / absAlpha, par[4]) * TMath.Exp(
             -0.5 * absAlpha * absAlpha)
         b = par[4] / absAlpha - absAlpha
         out = par[0] * (a / TMath.Power(b - t, par[4]))
     return out
Esempio n. 10
0
 def testPdgId(fname):
     global error_code
     if debug: print 'testing for PDG id'
     bn = basename(fname).split(".")[0].split("-")[0]
     if (not bn.startswith("all")) or (("bkg" or "background" or "back")
                                       in bn.lower()):
         return True
     else:
         try:
             particle = bn.replace("all", "")
             assert particle in pdgs.keys(), "particle type not supported"
             part = pdgs[particle]
             ch = TChain("CollectionTree")
             ch.Add(fname)
             h1 = TH1D("h1", "hPdgId", 10, part - 5, part + 5)
             if part < 10:
                 if debug: print 'Ion mode, subtract'
                 ch.Project(
                     "h1",
                     "TMath::Floor(DmpEvtSimuPrimaries.pvpart_pdg/10000.) - 100000"
                 )
             else:
                 ch.Project("h1", "DmpEvtSimuPrimaries.pvpart_pdg")
             delta = TMath.Abs(part - h1.GetMean())
             width = h1.GetRMS()
             if width > 0.1:
                 raise ValueError(
                     "pdg Id verification failed, distribution too broad, expect delta"
                 )
             if delta > 0.1:
                 raise ValueError(
                     "pdg Id verification failed, distribution not centered on %i but on %1.1f"
                     % (part, h1.GetMean()))
             if debug:
                 print "Pdg Hist: Mean = {mean}, RMS = {rms}".format(
                     mean=h1.GetMean(), rms=h1.GetRMS())
             del h1
             del ch
         except Exception as err:
             error_code = 1003
             raise Exception(err.message)
         return True
Esempio n. 11
0
for jentry in xrange( entries ):
    # get the next tree in the chain and verify
    ientry = tree.LoadTree( jentry )
    if ientry < 0:
        break
    
    # copy next entry into memory and verify
    nb = tree.GetEntry( jentry )
    if nb <= 0:
        continue
    
    nJet[0] = tree.nJet
    mindr_lep1_jet[0] = tree.mindr_lep1_jet
    mindr_lep3_jet[0] = tree.mindr_lep3_jet
    avg_dr_jet[0] = tree.avg_dr_jet
    lep1_abs_eta[0] = TMath.Abs(tree.lep1_eta)
    lep1_conePt[0] = tree.lep1_conePt
    lep2_conePt[0] = tree.lep2_conePt
    lep3_conePt[0] = tree.lep3_conePt
    htmiss[0] = TMath.Min(tree.htmiss, 500)
    dr_lep1_tau[0] = tree.dr_lep1_tau
    dr_lep2_tau[0] = tree.dr_lep2_tau
    mTauTauVis2[0] = tree.mTauTauVis2
    evtWeight = tree.evtWeight    
    if tree.lep1_genLepPt > 0:
        lep1_frWeight = 1.0
    else:
        lep1_frWeight = tree.lep1_fake_prob
    if tree.lep2_genLepPt > 0:
            lep2_frWeight =1.0
    else:
Esempio n. 12
0
for jentry in xrange( entries ):
    # get the next tree in the chain and verify
    ientry = tree_l.LoadTree( jentry )
    if ientry < 0:
        break
    
    # copy next entry into memory and verify
    nb = tree_l.GetEntry( jentry )
    if nb <= 0:
        continue
    
    nJet[0] = tree_l.nJet
    mindr_lep1_jet[0] = tree_l.mindr_lep1_jet
    mindr_lep2_jet[0] = tree_l.mindr_lep2_jet
    avg_dr_jet[0] = tree_l.avg_dr_jet
    lep1_abs_eta[0] = TMath.Abs(tree_l.lep1_eta)
    lep2_abs_eta[0] = TMath.Abs(tree_l.lep2_eta)
    max_lep_eta[0] = TMath.Max(TMath.Abs(tree_l.lep1_eta), TMath.Abs(tree_l.lep2_eta))
    lep1_conePt[0] = tree_l.lep1_conePt
    lep2_conePt[0] = tree_l.lep2_conePt
    mindr_tau_jet[0] = tree_l.mindr_tau_jet
    ptmiss[0] = TMath.Min(tree_l.ptmiss, 500)
    mT_lep1[0] = tree_l.mT_lep1
    mT_lep2[0] = tree_l.mT_lep2
    htmiss[0] = tree_l.htmiss
    dr_leps[0] = tree_l.dr_leps
    tau_pt[0] = tree_l.tau_pt
    tau_abs_eta[0] = TMath.Abs(tree_l.tau_eta)
    dr_lep1_tau[0] = tree_l.dr_lep1_tau
    dr_lep2_tau[0] = tree_l.dr_lep2_tau
    mTauTauVis1[0] = tree_l.mTauTauVis1
Esempio n. 13
0
for jentry in xrange(entries):
    # get the next tree in the chain and verify
    ientry = tree.LoadTree(jentry)
    if ientry < 0:
        break

    # copy next entry into memory and verify
    nb = tree.GetEntry(jentry)
    if nb <= 0:
        continue

    mindr_lep1_jet[0] = tree.mindr_lep1_jet
    mindr_lep2_jet[0] = tree.mindr_lep2_jet
    avg_dr_jet[0] = tree.avg_dr_jet
    max_lep_eta[0] = TMath.Max(TMath.Abs(tree.lep1_eta),
                               TMath.Abs(tree.lep2_eta))
    mT_lep1[0] = tree.mT_lep1
    dr_leps[0] = tree.dr_leps
    lep1_conePt[0] = tree.lep1_conePt
    lep2_conePt[0] = tree.lep2_conePt
    mTauTauVis1[0] = tree.mTauTauVis1
    mTauTauVis2[0] = tree.mTauTauVis2
    evtWeight = tree.evtWeight
    if tree.lep1_genLepPt > 0:
        lep1_frWeight = 1.0
    else:
        lep1_frWeight = tree.lep1_fake_prob
    if tree.lep2_genLepPt > 0:
        lep2_frWeight = 1.0
    else:
Esempio n. 14
0
def FillMotherHisto(h, pdg, w):
    if mt.Abs(pdg) == 113:  #rho0
        h.Fill(1, w)
    elif mt.Abs(pdg) == 213:  #rho+
        h.Fill(2, w)
    elif mt.Abs(pdg) == 221:  #eta
        h.Fill(3, w)
    elif mt.Abs(pdg) == 331:  #eta'
        h.Fill(4, w)
    elif mt.Abs(pdg) == 223:  #omega(782)
        h.Fill(5, w)
    elif mt.Abs(pdg) == 333:  #phi
        h.Fill(6, w)
    elif mt.Abs(pdg) == 310:  #K0S
        h.Fill(7, w)
    elif mt.Abs(pdg) == 411:  #D+
        h.Fill(8, w)
    elif mt.Abs(pdg) == 421:  #D0
        h.Fill(9, w)
    elif mt.Abs(pdg) == 413:  #D*+
        h.Fill(10, w)
    elif mt.Abs(pdg) == 423:  #D*0
        h.Fill(11, w)
    elif mt.Abs(pdg) == 431:  #Ds
        h.Fill(12, w)
    elif mt.Abs(pdg) == 433:  #D*s
        h.Fill(13, w)
    elif mt.Abs(pdg) == 10433:  #Ds1(2536)+
        h.Fill(14, w)
    elif mt.Abs(pdg) == 20433:  #Ds1(2460)+
        h.Fill(15, w)
    elif mt.Abs(pdg) == 4122:  #Lc
        h.Fill(16, w)
    elif mt.Abs(pdg) == 104124:  #Lc(2625)
        h.Fill(17, w)
    elif mt.Abs(pdg) == 14122:  #Lc(2593)
        h.Fill(18, w)
    elif mt.Abs(pdg) == 5122:  #Lb
        h.Fill(19, w)
    else:
        h.Fill(20, w)
    h.SetDirectory(0)
    return h
Esempio n. 15
0
def main():

    gROOT.SetBatch()

    #range for |t|
    ptmin = 0.
    ptmax = 0.109  #   0.109  0.01 for interference range

    #default binning
    ptbin = 0.004  # 0.004  0.0005 for interference range

    #long bins at high |t|
    ptmid = 0.06  # 0.08, value > ptmax will switch it off   0.06
    ptlon = 0.01  # 0.01

    #short bins at low |t|
    ptlow = 0.01
    ptshort = 0.0005

    #mass interval
    mmin = 2.8
    mmax = 3.2

    #dy = 2. # rapidity interval, for integrated sigma
    dy = 1.

    ngg = 131  # number of gamma-gamma from mass fit

    lumi = 13871.907  # lumi in inv. ub

    #correction to luminosity for ana/triggered events
    ratio_ana = 3420950. / 3694000

    #scale the lumi for |z| around nominal bunch crossing
    ratio_zdc_vtx = 0.502

    Reta = 0.503  # pseudorapidity preselection
    #Reta = 1.

    trg_eff = 0.67  # bemc trigger efficiency

    ratio_tof = 1.433  # tof correction to efficiency

    bbceff = 0.97  # BBC veto inefficiency

    zdc_acc = 0.49  # ZDC acceptance to XnXn 0.7
    #zdc_acc = 1.

    br = 0.05971  # dielectrons branching ratio

    #data
    basedir = "../../../star-upc-data/ana/muDst/muDst_run1/sel5"
    infile = "ana_muDst_run1_all_sel5z.root"

    #MC
    basedir_sl = "../../../star-upc-data/ana/starsim/slight14e/sel5"
    #infile_sl = "ana_slight14e1x2_s6_sel5z.root"
    infile_sl = "ana_slight14e1x3_s6_sel5z.root"
    #
    basedir_sart = "../../../star-upc-data/ana/starsim/sartre14a/sel5"
    infile_sart = "ana_sartre14a1_sel5z_s6_v2.root"
    #
    basedir_bgen = "../../../star-upc-data/ana/starsim/bgen14a/sel5"
    infile_bgen = "ana_bgen14a1_v0_sel5z_s6.root"
    #infile_bgen = "ana_bgen14a2_sel5z_s6.root"
    #
    basedir_gg = "../../../star-upc-data/ana/starsim/slight14e/sel5"
    infile_gg = "ana_slight14e2x1_sel5_nzvtx.root"

    #model predictions
    gSlight = load_starlight(dy)
    gSartre = load_sartre()
    gFlat = loat_flat_pt2()
    gMS = load_ms()
    gCCK = load_cck()

    #open the inputs
    inp = TFile.Open(basedir + "/" + infile)
    tree = inp.Get("jRecTree")
    #
    inp_gg = TFile.Open(basedir_gg + "/" + infile_gg)
    tree_gg = inp_gg.Get("jRecTree")
    #
    inp_sl = TFile.Open(basedir_sl + "/" + infile_sl)
    tree_sl_gen = inp_sl.Get("jGenTree")
    #
    inp_sart = TFile.Open(basedir_sart + "/" + infile_sart)
    tree_sart_gen = inp_sart.Get("jGenTree")
    #
    inp_bgen = TFile.Open(basedir_bgen + "/" + infile_bgen)
    tree_bgen_gen = inp_bgen.Get("jGenTree")

    #evaluate binning
    #print "bins:", ut.get_nbins(ptbin, ptmin, ptmax)

    bins = ut.get_bins_vec_2pt(ptbin, ptlon, ptmin, ptmax, ptmid)
    #bins = ut.get_bins_vec_3pt(ptshort, ptbin, ptlon, ptmin, ptmax, ptlow, ptmid)
    #print "bins2:", bins.size()-1

    #load the data
    strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax)

    hPt = ut.prepare_TH1D_vec("hPt", bins)
    tree.Draw("jRecPt*jRecPt >> hPt", strsel)

    #distribution for bin centers
    hPtCen = hPt.Clone("hPtCen")

    #gamma-gamma component
    hPtGG = ut.prepare_TH1D_vec("hPtGG", bins)
    tree_gg.Draw("jRecPt*jRecPt >> hPtGG", strsel)

    #normalize the gamma-gamma component
    ut.norm_to_num(hPtGG, ngg, rt.kGreen)

    #incoherent functional shape
    func_incoh_pt2 = TF1("func_incoh", "[0]*exp(-[1]*x)", 0., 10.)
    func_incoh_pt2.SetParameters(873.04, 3.28)

    #fill incoherent histogram from functional shape
    hPtIncoh = ut.prepare_TH1D_vec("hPtIncoh", bins)
    ut.fill_h1_tf(hPtIncoh, func_incoh_pt2, rt.kRed)

    #print "Entries before gamma-gamma and incoherent subtraction:", hPt.GetEntries()

    #subtract gamma-gamma and incoherent components
    hPt.Sumw2()
    hPt.Add(hPtGG, -1)
    #print "Gamma-gamma entries:", hPtGG.Integral()
    #print "Entries after gamma-gamma subtraction:", hPt.Integral()
    #print "Incoherent entries:", hPtIncoh.Integral()
    hPt.Add(hPtIncoh, -1)

    #print "Entries after all subtraction:", hPt.Integral()

    #scale the luminosity
    lumi_scaled = lumi * ratio_ana * ratio_zdc_vtx
    #print "lumi_scaled:", lumi_scaled

    #denominator for deconvoluted distribution, conversion ub to mb
    den = Reta * br * zdc_acc * trg_eff * bbceff * ratio_tof * lumi_scaled * 1000. * dy

    #deconvolution
    deconv_min = bins[0]
    deconv_max = bins[bins.size() - 1]
    deconv_nbin = bins.size() - 1
    gROOT.LoadMacro("fill_response_matrix.C")

    #Starlight response
    #resp_sl = RooUnfoldResponse(deconv_nbin, deconv_min, deconv_max, deconv_nbin, deconv_min, deconv_max)
    resp_sl = RooUnfoldResponse(hPt, hPt)
    rt.fill_response_matrix(tree_sl_gen, resp_sl)
    #
    unfold_sl = RooUnfoldBayes(resp_sl, hPt, 15)
    #unfold_sl = RooUnfoldSvd(resp_sl, hPt, 15)
    hPtSl = unfold_sl.Hreco()
    #ut.set_H1D(hPtSl)
    #apply the denominator and bin width
    ut.norm_to_den_w(hPtSl, den)

    #Sartre response
    #resp_sart = RooUnfoldResponse(deconv_nbin, deconv_min, deconv_max, deconv_nbin, deconv_min, deconv_max)
    #resp_sart = RooUnfoldResponse(hPt, hPt)
    #rt.fill_response_matrix(tree_sart_gen, resp_sart)
    #
    #unfold_sart = RooUnfoldBayes(resp_sart, hPt, 10)
    #hPtSart = unfold_sart.Hreco()
    #ut.set_H1D(hPtSart)
    #hPtSart.SetMarkerStyle(21)

    #Flat pT^2 response
    #resp_bgen = RooUnfoldResponse(deconv_nbin, deconv_min, deconv_max, deconv_nbin, deconv_min, deconv_max)
    resp_bgen = RooUnfoldResponse(hPt, hPt)
    rt.fill_response_matrix(tree_bgen_gen, resp_bgen)
    #
    unfold_bgen = RooUnfoldBayes(resp_bgen, hPt, 14)
    hPtFlat = unfold_bgen.Hreco()
    #ut.set_H1D(hPtFlat)
    #apply the denominator and bin width
    ut.norm_to_den_w(hPtFlat, den)
    #hPtFlat.SetMarkerStyle(22)
    #hPtFlat.SetMarkerSize(1.3)

    #systematical errors
    err_zdc_acc = 0.1
    err_bemc_eff = 0.03
    #sys_err = rt.TMath.Sqrt(err_zdc_acc*err_zdc_acc + err_bemc_eff*err_bemc_eff)
    sys_err = err_zdc_acc * err_zdc_acc + err_bemc_eff * err_bemc_eff
    #print "Total sys err:", sys_err
    hSys = ut.prepare_TH1D_vec("hSys", bins)
    hSys.SetOption("E2")
    hSys.SetFillColor(rt.kOrange + 1)
    hSys.SetLineColor(rt.kOrange)
    for ibin in xrange(1, hPtFlat.GetNbinsX() + 1):
        hSys.SetBinContent(ibin, hPtFlat.GetBinContent(ibin))
        sig_sl = hPtSl.GetBinContent(ibin)
        sig_fl = hPtFlat.GetBinContent(ibin)
        err_deconv = TMath.Abs(sig_fl - sig_sl) / sig_fl
        #print "err_deconv", err_deconv
        #sys_err += err_deconv*err_deconv
        sys_err_sq = sys_err + err_deconv * err_deconv
        sys_err_bin = TMath.Sqrt(sys_err_sq)
        stat_err = hPtFlat.GetBinError(ibin) / hPtFlat.GetBinContent(ibin)
        tot_err = TMath.Sqrt(stat_err * stat_err + sys_err_sq)
        #hSys.SetBinError(ibin, hPtFlat.GetBinContent(ibin)*err_deconv)
        hSys.SetBinError(ibin, hPtFlat.GetBinContent(ibin) * sys_err_bin)
        #hPtFlat.SetBinError(ibin, hPtFlat.GetBinContent(ibin)*tot_err)

    #draw the results
    gStyle.SetPadTickX(1)
    gStyle.SetFrameLineWidth(2)

    #frame for models plot only
    frame = ut.prepare_TH1D("frame", ptbin, ptmin, ptmax)

    can = ut.box_canvas()
    #ut.set_margin_lbtr(gPad, 0.1, 0.09, 0.03, 0.03)
    ut.set_margin_lbtr(gPad, 0.1, 0.09, 0.055, 0.01)

    ytit = "d#it{#sigma}/d#it{t}d#it{y} (mb/(GeV/c)^{2})"
    xtit = "|#kern[0.3]{#it{t}}| ((GeV/c)^{2})"

    ut.put_yx_tit(frame, ytit, xtit, 1.4, 1.2)
    frame.SetMaximum(11)
    #frame.SetMinimum(1.e-6)
    #frame.SetMinimum(2e-4)
    frame.SetMinimum(1e-5)  # 3e-5
    frame.Draw()

    #hSys.Draw("e2same")

    #bin center points from data
    #gSig = apply_centers(hPtFlat, hPtCen)
    gSig = fixed_centers(hPtFlat)
    ut.set_graph(gSig)

    #hPtSl.Draw("e1same")
    #hPtSart.Draw("e1same")
    #hPtFlat.Draw("e1same")

    #put model predictions
    #gSartre.Draw("lsame")
    #gFlat.Draw("lsame")
    gMS.Draw("lsame")
    gCCK.Draw("lsame")
    gSlight.Draw("lsame")

    gSig.Draw("P")

    frame.Draw("same")

    gPad.SetLogy()

    cleg = ut.prepare_leg(0.1, 0.96, 0.14, 0.01, 0.035)
    cleg.AddEntry(
        None,
        "Au+Au #rightarrow J/#psi + Au+Au + XnXn, #sqrt{#it{s}_{#it{NN}}} = 200 GeV",
        "")
    cleg.Draw("same")

    leg = ut.prepare_leg(0.45, 0.82, 0.18, 0.1, 0.035)
    leg.AddEntry(None, "#bf{|#kern[0.3]{#it{y}}| < 1}", "")
    hx = ut.prepare_TH1D("hx", 1, 0, 1)
    leg.AddEntry(hx, "STAR")
    hx.Draw("same")
    leg.Draw("same")

    #legend for models
    mleg = ut.prepare_leg(0.68, 0.76, 0.3, 0.16, 0.035)
    #mleg = ut.prepare_leg(0.68, 0.8, 0.3, 0.12, 0.035)
    mleg.AddEntry(gSlight, "STARLIGHT", "l")
    mleg.AddEntry(gMS, "MS", "l")
    mleg.AddEntry(gCCK, "CCK-hs", "l")
    #mleg.AddEntry(gSartre, "Sartre", "l")
    #mleg.AddEntry(gFlat, "Flat #it{p}_{T}^{2}", "l")
    mleg.Draw("same")

    #legend for deconvolution method
    dleg = ut.prepare_leg(0.3, 0.75, 0.2, 0.18, 0.035)
    #dleg = ut.prepare_leg(0.3, 0.83, 0.2, 0.1, 0.035)
    dleg.AddEntry(None, "Unfolding with:", "")
    dleg.AddEntry(hPtSl, "Starlight", "p")
    #dleg.AddEntry(hPtSart, "Sartre", "p")
    dleg.AddEntry(hPtFlat, "Flat #it{p}_{T}^{2}", "p")
    #dleg.Draw("same")

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")

    #to prevent 'pure virtual method called'
    gPad.Close()

    #save the cross section to output file
    out = TFile("sigma.root", "recreate")
    gSig.Write("sigma")
    out.Close()

    #beep when finished
    gSystem.Exec("mplayer ../computerbeep_1.mp3 > /dev/null 2>&1")
hRawYieldDistr = []
hRMS = hRawYields.Clone('hRMS')
hRMS.Reset()
hMeanShift = hRawYields.Clone('hMeanShift')
hMeanShift.Reset()
hSyst = hRawYields.Clone('hSyst')
hSyst.Reset()
inFileMT = TFile.Open(args.inFileNameMultiTrial)
for iPt in range(1, nPtBins + 1):
    ptMin = hRawYields.GetBinLowEdge(iPt)
    ptMax = ptMin + hRawYields.GetBinWidth(iPt)
    hRawYieldDistr.append(
        inFileMT.Get(f'hRawYield_pT_{ptMin*10:.0f}-{ptMax*10:.0f}'))
    rms = hRawYieldDistr[-1].GetRMS() / hRawYieldDistr[-1].GetMean() * 100
    shift = TMath.Abs(
        hRawYields.GetBinContent(iPt) -
        hRawYieldDistr[-1].GetMean()) / hRawYieldDistr[-1].GetMean() * 100
    syst = TMath.Sqrt(rms**2 + shift**2)
    hRMS.SetBinContent(iPt, rms)
    hMeanShift.SetBinContent(iPt, shift)
    hSyst.SetBinContent(iPt, syst)

cRMS = TCanvas('cRMS', '', 800, 800)
cRMS.DrawFrame(hRMS.GetBinLowEdge(1), 0.1, ptMax, 20.,
               ';#it{p}_{T} (GeV/#it{c});RMS (%)')
hRMS.DrawCopy('same')
axisSoverB = TGaxis(gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmax(),
                    gPad.GetUymax(), 0.01, 20., 510, "+LG")
axisSoverB.SetLineColor(kRed + 1)
axisSoverB.SetLabelColor(kRed + 1)
axisSoverB.SetLabelFont(42)
Esempio n. 17
0
def getDiffR(phi1, phi2, eta1, eta2):
    diffPhi = TMath.Abs(phi1 - phi2)
    if diffPhi > math.pi:
        diffPhi = 2 * math.pi - diffPhi

    return math.sqrt(diffPhi**2 + (eta1 - eta2)**2)
Esempio n. 18
0
    def __init__(self, 
                 base,                   geom,
                 volume="EMSS",          geomvolume="same",
                 stat="radlen",                    
                 xmin=+0.,                xmax=-1.,
                 ymin=+0.,                ymax=-1.,
                 canvas=0,
                 legend=False
                 ):

        self.name = volume
        self.base = base
        self.geom = geom

        baseFile = get_geom_file(base)                                       # get the files
        compFile = get_geom_file(geom)

        hname = "h_"+stat+"_"+volume+"_eta"                             # retrive the histograms from the files
        print "Get histo: " + str(hname)


        self.histo_base = stat_histo( stat, volume, file=baseFile )
        if ( geomvolume == "same" ):
            self.histo_comp = stat_histo( stat, volume, compFile )
        else:
            self.histo_comp = stat_histo( stat, geomvolume, compFile )

        self.histo_diff = self.histo_base.Clone( hname + "_diff" )      # difference the histograms
        self.histo_diff.Add( self.histo_comp, -1.0 )
        self.histo_diff.Divide(self.histo_base)                         # diff will be (old-new)/old * 100%

        if ( canvas == 0 ):
            canvas = TCanvas("temp"+base+geom+volume+geomvolume,"Differential 1D: baseline="+base+" compare="+geom,500,400);
            self.canvas = canvas

        # Detect and apply optional x-axis range
        if ( xmax > xmin ):
            self.histo_base.GetXaxis().SetRangeUser(xmin,xmax)
            self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax)
        # ... or zoom in on an appropriate scale
        else:
#            auto_range( self.histo_base )
#            auto_range( self.histo_comp )
            xmin = auto_min( self.histo_base )
            xmax = auto_max( self.histo_base )
            self.histo_base.GetXaxis().SetRangeUser(xmin,xmax)
            self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax)

#        xmin = TMath.Min( self.histo_base.GetXaxis().GetXmin(),self.histo_comp.GetXaxis().GetXmin() )
#        xmax = TMath.Max( self.histo_base.GetXaxis().GetXmax(),self.histo_comp.GetXaxis().GetXmax() )

#        print "xmin="+str(xmin)
#        print "xmax="+str(xmax)

        # Detect and apply optional y-axis range
        if ( ymax > ymin ):
            self.histo_base.GetYaxis().SetRangeUser(ymin,ymax)
        else:
            ymin = self.histo_base.GetMinimum()
            ymax = TMath.Max( self.histo_base.GetMaximum(),
                              self.histo_comp.GetMaximum())
            ymax *= 1.05

        # Current range in y-axis extends from 0 to ymax.  We want
        # to expand this to go from -0.2*ymax to ymax.
        ymin = -0.2 * ymax
        self.histo_base.GetYaxis().SetRangeUser(ymin,ymax)

        # Draw the baseline and comparison histograms
        self.histo_base.SetLineWidth(2)
        self.histo_base.SetFillStyle(1001)
        self.histo_base.SetFillColor(22)
        self.histo_base.Draw()

        self.histo_comp.SetLineColor(2)
        self.histo_comp.SetLineStyle(2)
        self.histo_comp.SetFillStyle(3345)
        self.histo_comp.SetFillColor(2)
        self.histo_comp.Draw("same")

        # Rescale difference histogram so that it is in percent
        self.histo_diff.Scale(100.0)

        # This is the maximum of the histogram.
        yfull_max = self.histo_diff.GetMaximum()
        yfull_min = self.histo_diff.GetMinimum()
        yfull = TMath.Max( yfull_max, TMath.Abs( yfull_min ) )
        self.max_differential = yfull

        yfull *= 1.3

        if ( yfull == 0. ):
            yfull = 1.0

        # We need to rescale the histogram so that it fits w/in 10% of ymax
        self.histo_diff.Scale( 0.10 * ymax / yfull )

        # Next we shift the histogram down by 0.1 * ymax
        nbinx=self.histo_diff.GetNbinsX();
        i=1
        while ( i<=nbinx ):
            self.histo_diff[i] -= 0.1 * ymax
            i+=1
        
        # Reset the line color and draw on the same plot
        self.histo_diff.SetLineColor(4)
        self.histo_diff.Draw("same")

        self.line = TLine(xmin, -0.1 * ymax, xmax, -0.1*ymax )
        self.line.SetLineStyle(3)
        self.line.Draw()

        # And superimpose an axis on the  new plot
        xa = xmax

        self.axis = TGaxis( xa, -0.2*ymax, xa, 0.0, -yfull, +yfull, 50510, "-+L" )
        self.axis.SetLabelSize(0.03)
        self.axis.SetLabelOffset(-0.02)
        self.axis.SetLineColor(4)
        self.axis.SetTextColor(4)
        self.axis.SetLabelColor(4)
        self.axis.SetNdivisions(4)
#       self.axis.SetTitle("(base-comp)/base [%]")
        self.axis.SetTitleSize(0.0175)
        self.axis.SetTitleOffset(-0.5)
        self.axis.Draw();

        # Add the legend if requested
        if ( legend ):
            self.legend = TLegend( 0.78, 0.80, 0.98, 0.98 )
            self.legend.AddEntry( self.histo_base, base )
            self.legend.AddEntry( self.histo_comp, geom )
            self.legend.AddEntry( self.histo_diff, "#frac{"+base+"-"+geom+"}{"+base+"} [%]" )
            self.legend.Draw()
    ientry = tree_l.LoadTree(jentry)
    if ientry < 0:
        break

    # copy next entry into memory and verify
    nb = tree_l.GetEntry(jentry)
    if nb <= 0:
        continue

    nJet[0] = tree_l.nJet
    mindr_lep1_jet[0] = tree_l.mindr_lep1_jet
    mindr_lep2_jet[0] = tree_l.mindr_lep2_jet
    avg_dr_jet[0] = tree_l.avg_dr_jet
    mindr_tau_jet[0] = tree_l.mindr_tau_jet
    tau_pt[0] = tree_l.tau_pt
    tau_abs_eta[0] = TMath.Abs(tree_l.tau_eta)
    dr_lep1_tau[0] = tree_l.dr_lep1_tau
    dr_lep2_tau[0] = tree_l.dr_lep2_tau
    dr_lep2_tau[0] = tree_l.dr_lep2_tau
    evtWeight = tree_l.evtWeight
    if tree_l.lep1_genLepPt > 0:
        lep1_frWeight = 1.0
    else:
        lep1_frWeight = tree_l.lep1_fake_prob
    if tree_l.lep2_genLepPt > 0:
        lep2_frWeight = 1.0
    else:
        lep2_frWeight = tree_l.lep2_fake_prob
    if tree_l.lep3_genLepPt > 0:
        lep3_frWeight = 1.0
    else:
Esempio n. 20
0
        dRthresh_mu1 = 0.1
        dRthresh_mu2 = 0.1
        dRthresh_mu3 = 0.1
        genmatch_thresh_list = [dRthresh_mu1, dRthresh_mu2, dRthresh_mu3]
        # first we pick out what gen level particle our reco mu3 most likely corresponds to
        matchedparticles = multimindr(genmatch_thresh_list, [pmu1, pmu2, pmu3])
        mu3_gen_num = matchedparticles[2][0]
        mu3_sisters = getsisterids(mu3_gen_num, False)
        if mu3_gen_num == -1: continue
        JpsiGen[0] = False
        iGenJpsi = -1
        for sis in mu3_sisters:
            if JpsiGen[0]:
                continue
            if TMath.Abs(chain.genParticle_pdgId[sis]) != 443:
                continue
            else:
                #print "Jpsi found", chain.genParticle_pdgId[sis]
                JpsiGen[0] = True
                iGenJpsi = sis
        isBplusJpsiKplus[0] = False
        isBplusJpsiPiplus[0] = False
        isBplusJpsi3Kplus[0] = False
        isBplusJpsiKPiPiplus[0] = False
        isBplusJpsiPhiKplus[0] = False
        isBplusJpsiK0Piplus[0] = False
        #print "Mu3 ID", chain.genParticle_pdgId[mu3_gen_num]
        #for sis in mu3_sisters:
        #    print "Sister ID", chain.genParticle_pdgId[sis]
        if iGenJpsi == -1: