|
| 1 | +import ROOT |
| 2 | +import math |
| 3 | + |
| 4 | +ROOT.EnableImplicitMT(4) |
| 5 | + |
| 6 | + |
| 7 | +# Declare filters on RVec objects and JIT with Numba |
| 8 | +@ROOT.Numba.Declare(["int", "int", "RVecI"], "bool") |
| 9 | +def ik_ipi_nhitrp_cut(ik, ipi, nhitrp): |
| 10 | + return nhitrp[ik - 1] * nhitrp[ipi - 1] > 1 |
| 11 | + |
| 12 | + |
| 13 | +@ROOT.Numba.Declare(["int", "RVecF", "RVecF"], "bool") |
| 14 | +def ik_rstart_rend_cut(ik, rstart, rend): |
| 15 | + return rend[ik - 1] - rstart[ik - 1] > 22 |
| 16 | + |
| 17 | + |
| 18 | +@ROOT.Numba.Declare(["int", "RVecF", "RVecF"], "bool") |
| 19 | +def ipi_rstart_rend_cut(ipi, rstart, rend): |
| 20 | + return rend[ipi - 1] - rstart[ipi - 1] > 22 |
| 21 | + |
| 22 | + |
| 23 | +@ROOT.Numba.Declare(["int", "RVecF"], "bool") |
| 24 | +def ik_nlhk_cut(ik, nlhk): |
| 25 | + return nlhk[ik - 1] > 0.1 |
| 26 | + |
| 27 | + |
| 28 | +@ROOT.Numba.Declare(["int", "RVecF"], "bool") |
| 29 | +def ipi_nlhpi_cut(ipi, nlhpi): |
| 30 | + return nlhpi[ipi - 1] > 0.1 |
| 31 | + |
| 32 | + |
| 33 | +@ROOT.Numba.Declare(["int", "RVecF"], "bool") |
| 34 | +def ipis_nlhpi_cut(ipis, nlhpi): |
| 35 | + return nlhpi[ipis - 1] > 0.1 |
| 36 | + |
| 37 | + |
| 38 | +def select(rdf): |
| 39 | + return ( |
| 40 | + rdf.Filter("TMath::Abs(md0_d - 1.8646) < 0.04") |
| 41 | + .Filter("ptds_d > 2.5") |
| 42 | + .Filter("TMath::Abs(etads_d) < 1.5") |
| 43 | + .Filter("Numba::ik_ipi_nhitrp_cut(ik, ipi, nhitrp)") |
| 44 | + .Filter("Numba::ik_rstart_rend_cut(ik, rstart, rend)") |
| 45 | + .Filter("Numba::ipi_rstart_rend_cut(ipi, rstart, rend)") |
| 46 | + .Filter("Numba::ik_nlhk_cut(ik, nlhk)") |
| 47 | + .Filter("Numba::ipi_nlhpi_cut(ipi, nlhpi)") |
| 48 | + .Filter("Numba::ipis_nlhpi_cut(ipis, nlhpi)") |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +dxbin = (0.17 - 0.13) / 40 |
| 53 | +condition = "x > 0.13957" |
| 54 | +xp3 = "(x - [3]) * (x - [3])" |
| 55 | + |
| 56 | + |
| 57 | +def FitAndPlotHdmd(hdmd: ROOT.TH1): |
| 58 | + ROOT.gStyle.SetOptFit() |
| 59 | + c1 = ROOT.TCanvas("c1", "h1analysis analysis", 10, 10, 800, 600) |
| 60 | + |
| 61 | + hdmd.GetXaxis().SetTitleOffset(1.4) |
| 62 | + |
| 63 | + hdraw = hdmd.DrawClone() |
| 64 | + |
| 65 | + # Fit histogram hdmd with function f5 using the loglikelihood option |
| 66 | + formula = f"{dxbin} * ([0] * pow(x - 0.13957, [1]) + [2] / 2.5066 / [4] * exp(-{xp3} / 2 / [4] / [4]))" |
| 67 | + f5 = ROOT.TF1("f5", f"{condition} ? {formula} : 0", 0.139, 0.17, 5) |
| 68 | + f5.SetParameters(1000000, 0.25, 2000, 0.1454, 0.001) |
| 69 | + hdraw.Fit(f5, "lr") |
| 70 | + |
| 71 | + return |
| 72 | + |
| 73 | + |
| 74 | +def FitAndPlotH2(h2: ROOT.TH2): |
| 75 | + # Create the canvas for tau d0 |
| 76 | + c2 = ROOT.TCanvas("c2", "tauD0", 100, 100, 800, 600) |
| 77 | + |
| 78 | + c2.SetGrid() |
| 79 | + c2.SetBottomMargin(0.15) |
| 80 | + |
| 81 | + # Project slices of 2-d histogram h2 along X , then fit each slice |
| 82 | + # with function f2 and make a histogram for each fit parameter |
| 83 | + # Note that the generated histograms are added to the list of objects |
| 84 | + # in the current directory. |
| 85 | + sigma = 0.0012 |
| 86 | + formula = f"{dxbin} * ([0] * pow(x - 0.13957, 0.25) + [1] / 2.5066 / {sigma} * exp(-{xp3} / 2 / {sigma} / {sigma}))" |
| 87 | + print(f"TWO: {condition} ? {formula} : 0") |
| 88 | + |
| 89 | + f2 = ROOT.TF1("f2", f"{condition} ? {formula} : 0", 0.139, 0.17, 2) |
| 90 | + f2.SetParameters(10000, 10) |
| 91 | + h2.FitSlicesX(f2, 0, -1, 1, "qln") |
| 92 | + |
| 93 | + # See TH2::FitSlicesX documentation why h2_1 name is used |
| 94 | + h2_1 = ROOT.gDirectory.Get("h2_1") |
| 95 | + h2_1.SetDirectory(ROOT.nullptr) |
| 96 | + h2_1.GetXaxis().SetTitle("#tau [ps]") |
| 97 | + h2_1.SetMarkerStyle(21) |
| 98 | + h2_1.Draw() |
| 99 | + |
| 100 | + c2.Update() |
| 101 | + |
| 102 | + line = ROOT.TLine(0, 0, 0, c2.GetUymax()) |
| 103 | + line.Draw() |
| 104 | + |
| 105 | + return |
| 106 | + |
| 107 | + |
| 108 | +chain = ROOT.TChain("h42") |
| 109 | +chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root") |
| 110 | +chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp1a.root") |
| 111 | +chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp1b.root") |
| 112 | +chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp2.root") |
| 113 | + |
| 114 | +df = ROOT.RDataFrame(chain) |
| 115 | +selected = select(df) |
| 116 | +# Note: The title syntax is "<Title>;<Label x axis>;<Label y axis>" |
| 117 | +hdmdARP = selected.Histo1D(("hdmd", "Dm_d;m_{K#pi#pi} - m_{K#pi}[GeV/c^{2}]", 40, 0.13, 0.17), "dm_d") |
| 118 | +selected_added_branch = selected.Define("h2_y", "rpd0_t / 0.029979f * 1.8646f / ptd0_d") |
| 119 | +h2ARP = selected_added_branch.Histo2D(("h2", "ptD0 vs Dm_d", 30, 0.135, 0.165, 30, -3, 6), "dm_d", "h2_y") |
| 120 | + |
| 121 | +FitAndPlotHdmd(hdmdARP) |
| 122 | +FitAndPlotH2(h2ARP) |
0 commit comments