Example #1
0
def acc_from_tmp():

    #spectrometer acceptance from temporary file

    tmp = TFile.Open("tmp/hacc.root")
    hAcc = tmp.Get("divide_hSel_by_hAll")

    can = ut.box_canvas()

    hAcc.Draw("AP")

    ut.set_margin_lbtr(gPad, 0.14, 0.1, 0.01, 0.02)

    en = rt.Double(0)
    av = rt.Double(0)
    iacc = 0.
    for i in xrange(hAcc.GetN()):
        hAcc.GetPoint(i, en, av)

        iacc += av * (hAcc.GetErrorXhigh(i) + hAcc.GetErrorXlow(i))

    print "iacc:", iacc

    #acceptance parametrization
    from spec_acc import spec_acc
    acc = spec_acc()
    acc.scale = iacc / acc.acc_func.Integral(2, 21)

    print "int_func:", acc.acc_func.Integral(2, 21)

    acc.acc_func.Draw("same")

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Example #2
0
def plot_spec_acc():

    #acceptance parametrization
    from spec_acc import spec_acc
    acc0 = spec_acc()
    acc = spec_acc(8200, 0.26, 42, 242)

    #acc.length = 8200

    can = ut.box_canvas()

    frame = gPad.DrawFrame(1, 0, 22, 1)
    frame.Draw()

    acc0.acc_func.Draw("same")
    acc0.acc_func.SetLineStyle(rt.kDashed)
    acc.acc_func.Draw("same")

    gPad.SetGrid()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Example #3
0
def main():

    #field = 0.37 # T, 18 GeV
    #field = 0.2 # T, 10 GeV
    field = 0.1  # T, 5 GeV

    emin = 0
    emax = 19

    amax = 1

    can = ut.box_canvas()
    frame = gPad.DrawFrame(emin, 0, emax, amax)

    ut.put_yx_tit(frame, "Spectrometer acceptance",
                  "Photon energy #it{E} (GeV)", 1.6, 1.3)

    frame.Draw()

    ut.set_margin_lbtr(gPad, 0.12, 0.1, 0.03, 0.02)

    #geometry
    geo = rt.GeoParser("../../config/geom_all.in")

    #distance from magnet center to the front of spectrometer detectors
    length = geo.GetD("lumi_dipole", "zpos") - geo.GetD(
        "vac_lumi_spec_mid", "z0")

    #print(geo.GetD("lumi_dipole", "zpos"))
    #print(geo.GetD("vac_lumi_spec_mid", "z0"))
    #print(geo.GetD("vac_lumi_spec_mid", "dY0"))
    #print(geo.GetD("vac_lumi_mag_spec", "dY1"))

    #acc = spec_acc(9700, 0.26, 42, 242)
    acc = spec_acc(length, field, geo.GetD("vac_lumi_spec_mid", "dY0"),
                   geo.GetD("vac_lumi_mag_spec", "dY1"))
    acc.scale = 1
    acc.acc_func.Draw("same")

    gPad.SetGrid()

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Example #4
0
def acc_spec():

    #infile = "hits_spect.root"
    infile = "/home/jaroslav/sim/lmon/data/luminosity/lm2ax2/hits_spect.root"
    #infile = "/home/jaroslav/sim/lmon/data/luminosity/lm3a/hits_spect.root"
    #infile = "/home/jaroslav/sim/lmon/data/luminosity/lm1bx1/hits_spect.root"
    #infile = "/home/jaroslav/sim/lmon/data/luminosity/lm1cx1/hits_spect.root"

    emin = 0
    emax = 19

    amax = 0.05

    inp_lmon = TFile.Open(infile)
    tree_lmon = inp_lmon.Get("event")

    acc_lmon = rt.acc_Q2_kine(tree_lmon, "gen_en", "is_spect")
    acc_lmon.prec = 0.04
    #acc_lmon.prec = 0.1
    acc_lmon.delt = 1e-2
    acc_lmon.bmin = 0.1
    #acc_lmon.nev = int(1e5)
    gLmon = acc_lmon.get()

    can = ut.box_canvas()
    frame = gPad.DrawFrame(emin, 0, emax, amax)

    ut.put_yx_tit(frame, "Spectrometer acceptance",
                  "Photon energy #it{E}_{#gamma} (GeV)", 1.9, 1.3)

    frame.Draw()

    ut.set_margin_lbtr(gPad, 0.14, 0.1, 0.03, 0.02)

    ut.set_graph(gLmon, rt.kBlue)
    gLmon.Draw("psame")

    #integrate the acceptance to scale the parametrization
    en = c_double(0)
    av = c_double(0)
    iacc = 0.
    for i in range(gLmon.GetN()):
        gLmon.GetPoint(i, en, av)
        iacc += av.value * (gLmon.GetErrorXhigh(i) + gLmon.GetErrorXlow(i))

    print("iacc:", iacc)

    geo = rt.GeoParser("../../config/pro1/geom_all.in")
    length = geo.GetD("lumi_dipole", "zpos") - geo.GetD(
        "vac_lumi_spec_mid", "z0")
    print("Length (mm):", length)
    field = 0.37  # T
    #field = 0.2 # T
    #field = 0.1 # T

    acc = spec_acc(length, field, geo.GetD("vac_lumi_spec_mid", "dY0"),
                   geo.GetD("vac_lumi_mag_spec", "dY1"))
    acc.scale = iacc / acc.acc_func.Integral(1, 21)
    acc.acc_func.Draw("same")

    gPad.SetGrid()

    leg = ut.prepare_leg(0.15, 0.82, 0.24, 0.12, 0.035)  # x, y, dx, dy, tsiz
    leg.AddEntry(gLmon, "Geant4", "lp")
    leg.AddEntry(acc.acc_func, "Geometry model", "l")
    leg.Draw("same")

    #ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Example #5
0
def acceptance():

    #spectrometer acceptance as a function of generated photon energy

    #ebin = 1.5
    ebin = 0.5
    emin = 1
    emax = 20

    edet = 1

    can = ut.box_canvas()

    hRec = ut.prepare_TH1D("hRec", ebin, emin, emax)
    hGen = ut.prepare_TH1D("hGen", ebin, emin, emax)

    #sel = "up_en>"+str(edet*1e3)+" && down_en>"+str(edet*1e3)
    sel = "up_en>" + str(edet) + " && down_en>" + str(edet)

    #tree.Draw("phot_gen/1000 >> hRec", sel)
    #tree.Draw("phot_gen/1000 >> hGen")
    tree.Draw("phot_gen >> hRec", sel)
    tree.Draw("phot_gen >> hGen")

    print "Rec entries:", hRec.GetEntries()
    print "Gen entries:", hGen.GetEntries()

    hAcc = hRec.Clone()
    hAcc.Sumw2()
    hAcc.Divide(hGen)

    #print "Integrated acceptance:", hAcc.Integral()

    hAcc.SetYTitle("Spectrometer acceptance / ({0:.3f}".format(ebin) + " GeV)")
    hAcc.SetXTitle("Generated #it{E}_{#gamma} (GeV)")

    hAcc.SetTitleOffset(1.8, "Y")
    hAcc.SetTitleOffset(1.3, "X")

    gPad.SetTopMargin(0.01)
    gPad.SetRightMargin(0.02)
    gPad.SetBottomMargin(0.1)
    gPad.SetLeftMargin(0.12)

    #hRec.Draw()
    #hGen.Draw()
    hAcc.Draw()

    #acceptance parametrization
    from spec_acc import spec_acc
    acc = spec_acc()
    #acc.scale = 0.081*0.7

    acc.scale = hAcc.GetBinWidth(1) * hAcc.Integral() / acc.acc_func.Integral(
        2, 21)
    #acc.scale = hAcc.Integral("w")/acc.acc_func.Integral(2, 21)

    print
    #print "scale:", acc.scale

    print "int_hacc:", hAcc.Integral() * hAcc.GetBinWidth(1)
    #print "binw:", hAcc.GetBinWidth(1)
    print "int_func:", acc.acc_func.Integral(2, 21)

    #ih = scale*if   scale = ih/if

    acc.acc_func.Draw("same")

    leg = ut.prepare_leg(0.64, 0.84, 0.15, 0.15, 0.027)  # x, y, dx, dy, tsiz
    leg.AddEntry(
        hAcc,
        "#frac{#it{N}(#it{E}_{up}>1 #bf{and} #it{E}_{down}>1 GeV)}{#it{N}_{all}}",
        "lp")
    leg.Draw("same")

    ut.invert_col(rt.gPad)
    can.SaveAs("01fig.pdf")
Example #6
0
def acceptance_autobin():

    #spectrometer acceptance as a function of generated photon energy,
    #size of bins is given by the desired precision

    emin = 1
    emax = 20

    edet = 1

    prec = 0.07
    #prec = 0.02
    delt = 1e-2

    sel = "up_en>" + str(edet * 1e3) + " && down_en>" + str(edet * 1e3)

    can = ut.box_canvas()

    gROOT.LoadMacro("get_acc.C")
    hAcc = rt.get_acc(tree, "phot_gen", sel, prec, delt)

    #ut.set_graph(hAcc, rt.kBlue)
    ut.set_graph(hAcc)

    #hAcc.GetYaxis().SetTitle("Spectrometer acceptance / "+str(prec*1e2)+" %")
    hAcc.GetYaxis().SetTitle("Spectrometer acceptance")
    hAcc.GetXaxis().SetTitle("Generated #it{E}_{#gamma} (GeV)")
    hAcc.SetTitle("")

    hAcc.GetYaxis().SetTitleOffset(2)
    hAcc.GetXaxis().SetTitleOffset(1.3)

    ut.set_margin_lbtr(gPad, 0.14, 0.1, 0.01, 0.02)

    hAcc.Draw("AP")

    #save the acceptance to a temporary file
    #tmp = TFile.Open("tmp/hacc.root", "recreate")
    #hAcc.Write()
    #tmp.Write()
    #tmp.Close()

    #integrate the acceptance to scale the parametrization
    en = rt.Double(0)
    av = rt.Double(0)
    iacc = 0.
    for i in xrange(hAcc.GetN()):
        hAcc.GetPoint(i, en, av)
        iacc += av * (hAcc.GetErrorXhigh(i) + hAcc.GetErrorXlow(i))

    #acceptance parametrization
    from spec_acc import spec_acc
    #acc = spec_acc()
    acc = spec_acc(8200, 0.26, 42, 242)
    acc.scale = iacc / acc.acc_func.Integral(2, 21)

    acc.acc_func.Draw("same")

    leg = ut.prepare_leg(0.63, 0.86, 0.12, 0.1)  #, 0.027) # x, y, dx, dy, tsiz
    #leg.AddEntry(hAcc, "#frac{#it{N}(#it{E}_{up}>1 #bf{and} #it{E}_{down}>1 GeV)}{#it{N}_{all}}", "lp")
    leg.AddEntry(hAcc, "Geant4", "lp")
    leg.AddEntry(acc.acc_func, "Geometry model", "l")
    leg.Draw("same")

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