Examples for Plotter class

Ploter is the new api for partial wave plots.

First, we can build a simple config.

12 config_str = """
13
14 decay:
15     A:
16        - [R1, B]
17        - [R2, C]
18        - [R3, D]
19     R1: [C, D]
20     R2: [B, D]
21     R3: [B, C]
22
23 particle:
24     $top:
25        A: { mass: 1.86, J: 0, P: -1}
26     $finals:
27        B: { mass: 0.494, J: 0, P: -1}
28        C: { mass: 0.139, J: 0, P: -1}
29        D: { mass: 0.139, J: 0, P: -1}
30     R1: [ R1_a, R1_b ]
31     R1_a: { mass: 0.7, width: 0.05, J: 1, P: -1}
32     R1_b: { mass: 0.5, width: 0.05, J: 0, P: +1}
33     R2: { mass: 0.824, width: 0.05, J: 0, P: +1}
34     R3: { mass: 0.824, width: 0.05, J: 0, P: +1}
35
36
37 plot:
38     mass:
39         R1:
40             display: "m(R1)"
41         R2:
42             display: "m(R2)"
43 """
44
45 import matplotlib.pyplot as plt
46 import yaml
47
48 from tf_pwa.config_loader import ConfigLoader
49
50 config = ConfigLoader(yaml.full_load(config_str))

We set parameters to a blance value. And we can generate some toy data and calclute the weights

56 input_params = {
57     "A->R1_a.BR1_a->C.D_total_0r": 6.0,
58     "A->R1_b.BR1_b->C.D_total_0r": 1.0,
59     "A->R2.CR2->B.D_total_0r": 2.0,
60     "A->R3.DR3->B.C_total_0r": 1.0,
61 }
62 config.set_params(input_params)
63
64 data = config.generate_toy(1000)
65 phsp = config.generate_phsp(10000)
5.8%[▓▓>-----------------------------------------------] 0.57/9.90s eff: 90.000000%
94.2%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>--] 1.93/2.05s eff: 4.824203%
99.6%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>] 2.45/2.46s eff: 4.153819%
99.7%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>] 2.92/2.92s eff: 4.113545%
99.8%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>] 3.38/3.39s eff: 4.099741%
100.0%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>] 3.83/3.83s eff: 4.090407%
100.0%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 3.83/3.83s  eff: 4.089721%

plotter can be created directly from config

71 plotter = config.get_plotter(datasets={"data": [data], "phsp": [phsp]})

Ploting all partial waves is simple.

76 plotter.plot_frame("m_R1")
77 plt.show()
ex4 plotter

Also we can plot other variables in data

82 from tf_pwa.data import data_index
83
84 m2 = config.get_data_index("mass", "R2")
85 m3 = config.get_data_index("mass", "R3")
86
87
88 def f(data):
89     return data_index(data, m2) - data_index(data, m3)
90
91
92 plt.clf()
93 plotter.plot_var(f)
94 plt.xlabel("m(R2)+m(R3)")
95 plt.show()
ex4 plotter

There are 3 main parts in a Plotter

  1. PlotAllData: datasets with weights There is three level: (1). idx: Datasets for combine fit (2). type: data, mc, or bg (3). observations and weights: weights are used for partial wave

  2. Frame: function to get obsevations It is samilar to RooFit’s Frame.

  3. Styles: Plot style for differenct componets

The plot process is as follow:

  1. Plotter.plot_item, extra_plot_item, and hidden_plot_item provide the list of histograms for plotting.

  2. Loop over all data to get the observations though frame.

  3. Frame provide the binning, weights from datas. Their combination is histogram

  4. Plot on the axis with style

Total running time of the script: (0 minutes 5.425 seconds)

Gallery generated by Sphinx-Gallery