Skip to content

Commit bcfe963

Browse files
GoodingJamiemdessole
authored andcommitted
[tutorials] Define formulae in df101_h1Analysis.py by strings
1 parent 286b8bd commit bcfe963

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

tutorials/analysis/dataframe/df101_h1Analysis.py

+12-24
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,10 @@ def select(rdf):
4040
.Filter("Numba::ipi_nlhpi_cut(ipi, nlhpi)")\
4141
.Filter("Numba::ipis_nlhpi_cut(ipis, nlhpi)")\
4242

43-
dxbin = (0.17 - 0.13) / 40 # Bin-width
4443

45-
def fdm5(xx, par):
46-
x = xx[0]
47-
if x <= 0.13957:
48-
return 0
49-
xp3 = (x - par[3]) ** 2
50-
res = dxbin * (par[0] * (x - 0.13957) ** par[1]) + par[2] / 2.5066 / par[4] * math.exp(-xp3 / 2 / par[4] ** 2)
51-
return res
52-
53-
def fdm2(xx, par):
54-
sigma = 0.0012
55-
x = xx[0]
56-
if x <= 0.13957:
57-
return 0
58-
xp3 = (x - 0.1454) ** 2
59-
res = dxbin * (par[0] * (x - 0.13957) ** 0.25) + par[1] / 2.5066 / sigma * math.exp(-xp3 / 2 / sigma **2)
60-
return res
44+
dxbin = (0.17 - 0.13) / 40
45+
condition = "x > 0.13957"
46+
xp3 = "(x - [3]) * (x - [3])"
6147

6248
def FitAndPlotHdmd(hdmd: ROOT.TH1):
6349
ROOT.gStyle.SetOptFit()
@@ -68,13 +54,13 @@ def FitAndPlotHdmd(hdmd: ROOT.TH1):
6854
hdraw = hdmd.DrawClone()
6955

7056
# Fit histogram hdmd with function f5 using the loglikelihood option
71-
f5 = ROOT.TF1("f5", fdm5, 0.139, 0.17, 5)
57+
formula = f"{dxbin} * ([0] * pow(x - 0.13957, [1]) + [2] / 2.5066 / [4] * exp(-{xp3} / 2 / [4] / [4]))"
58+
f5 = ROOT.TF1("f5", f"{condition} ? {formula} : 0", 0.139, 0.17, 5)
7259
f5.SetParameters(1000000, .25, 2000, .1454, .001)
73-
hdraw.Fit("f5", "lr")
60+
hdraw.Fit(f5, "lr")
7461

7562
return
7663

77-
7864
def FitAndPlotH2(h2: ROOT.TH2):
7965

8066
# Create the canvas for tau d0
@@ -87,8 +73,11 @@ def FitAndPlotH2(h2: ROOT.TH2):
8773
# with function f2 and make a histogram for each fit parameter
8874
# Note that the generated histograms are added to the list of objects
8975
# in the current directory.
90-
91-
f2 = ROOT.TF1("f2", fdm2, 0.139, 0.17, 2)
76+
sigma = 0.0012
77+
formula = f"{dxbin} * ([0] * pow(x - 0.13957, 0.25) + [1] / 2.5066 / {sigma} * exp(-{xp3} / 2 / {sigma} / {sigma}))"
78+
print(f"TWO: {condition} ? {formula} : 0")
79+
80+
f2 = ROOT.TF1("f2", f"{condition} ? {formula} : 0", 0.139, 0.17, 2)
9281
f2.SetParameters(10000, 10)
9382
h2.FitSlicesX(f2, 0, -1, 1, "qln")
9483

@@ -101,12 +90,11 @@ def FitAndPlotH2(h2: ROOT.TH2):
10190

10291
c2.Update()
10392

104-
line = ROOT.Tline(0, 0, 0, c2.GetUymax())
93+
line = ROOT.TLine(0, 0, 0, c2.GetUymax())
10594
line.Draw()
10695

10796
return
10897

109-
11098
chain = ROOT.TChain("h42")
11199
chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root")
112100
chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp1a.root")

0 commit comments

Comments
 (0)