Skip to content

Commit b77149f

Browse files
authored
Page for users' guide on pedestal estimation tool (#159)
* first stab at doc for pedestal estimation tool * links and fixes * additions/corrections suggested by JPL
1 parent 8a02577 commit b77149f

File tree

4 files changed

+105
-33
lines changed

4 files changed

+105
-33
lines changed

docs/user-guide/howto-pedestal.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.. _pedestal:
2+
3+
Pedestal estimation tool
4+
-------------------------------
5+
The pedestal estimation tool processes pedestal calibration data
6+
(dedicated pedestal runs or runs containing interleaved pedestal
7+
events) and returns estimates of the pedestal in ADC counts as a function of gain channel/pixel/sample within the readout window.
8+
9+
Run the tool locally
10+
=========================
11+
To use the pedestal estimation tool, first activate the ``nectarchain`` environment:
12+
13+
.. code-block:: console
14+
15+
$ mamba activate nectarchain
16+
17+
18+
The user script `nectarchain/user_scripts/ltibaldo/example_pedestal.py` showcases the usage of the tool.
19+
20+
The input data are identified by run number. See :ref:`env-vars` to
21+
set up the ``$NECTARCAMDATA`` environment variable. Events in the
22+
selected runs are
23+
processed in slices with a fixed number of events set by the
24+
``events_per_slice`` parameter (see `~nectarchain.makers.core.EventsLoopNectarCAMCalibrationTool`).
25+
26+
The pedestal
27+
estimation tool inherits the configurable parameters of the
28+
`~nectarchain.makers.component.PedestalComponent.PedestalEstimationComponent`.
29+
The data can be filtered based on time using the ``ucts_tmin`` and
30+
``ucts_tmax`` parameters and to eliminate outlier waveforms using the ``filter_method`` parameter. Two different methods to exclude outlier
31+
waveforms are implemented:
32+
33+
* ``WaveformsStdFilter`` discards waveforms with a standard deviation
34+
exceeding the threshold value defined by the parameter
35+
``wfs_std_threshold``;
36+
37+
* ``ChargeDistributionFilter`` discards waveforms with a total charge integrated over the entire readout window in the tails of the charge distribution, either below ``charge_sigma_low_thr`` or above ``charge_sigma_high_thr``.
38+
39+
40+
To run the example script:
41+
42+
.. code-block:: console
43+
44+
$ python -i example_pedestal.py
45+
46+
Inspect the results
47+
=========================
48+
The results are stored in a
49+
`~nectarchain.data.container.pedestalContainer.NectarCAMPedestalContainer`. The
50+
results include information on pixels that were flagged as having
51+
an abnormal behavior during the computation of the pedestals. The
52+
flags are defined in in
53+
`~nectarchain.data.container.pedestalContainer.PedestalFlagBits`. The
54+
results are accessible on the fly if the tool is run interactively (as in the example above) and stored in a `.h5` file.
55+
56+
The user script `nectarchain/user_scripts/ltibaldo/show_pedestal_output.py` provides an example of how to access the results from disk and produce some plots:
57+
58+
.. code-block:: console
59+
60+
$ python -i plot_pedestal_output.py
61+
62+

docs/user-guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ User Guide
1010
env-vars
1111
howto-dirac
1212
dqm
13+
howto-pedestal
1314
troubleshooting

src/nectarchain/user_scripts/ltibaldo/example_pedestal.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
log = logging.getLogger(__name__)
99
log.handlers = logging.getLogger("__main__").handlers
1010

11-
from nectarchain.makers.calibration import (
12-
PedestalNectarCAMCalibrationTool,
13-
)
11+
from nectarchain.makers.calibration import PedestalNectarCAMCalibrationTool
1412

1513
run_number = 3938
16-
max_events= 2999
14+
max_events = 2999
1715
events_per_slice = 300
18-
outfile = "/Users/ltibaldo/tmp/test_pedestal/pedestal_{}.h5".format(run_number)
16+
outfile = os.environ["NECTARCAMDATA"] + "/runs/pedestal_{}.h5".format(run_number)
1917

2018
tool = PedestalNectarCAMCalibrationTool(
2119
progress_bar=True,
@@ -24,13 +22,13 @@
2422
events_per_slice=events_per_slice,
2523
log_level=20,
2624
output_path=outfile,
27-
overwrite = True,
28-
filter_method = 'WaveformsStdFilter',
29-
wfs_std_threshold = 4.,
25+
overwrite=True,
26+
filter_method="WaveformsStdFilter",
27+
wfs_std_threshold=4.0,
3028
)
3129

3230
tool.initialize()
3331
tool.setup()
3432

3533
tool.start()
36-
output = tool.finish(return_output_component=True)
34+
output = tool.finish(return_output_component=True)
Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import os
2+
3+
import matplotlib.pyplot as plt
14
import numpy as np
25
import tables
3-
import matplotlib.pyplot as plt
46

5-
filename = '/Users/ltibaldo/tmp/test_pedestal/pedestal_3938.h5'
7+
filename = os.environ["NECTARCAMDATA"] + "/runs/pedestal_3938.h5"
68
pixel_id = 132
79
sample = 13
810
nsamples = 60
911

10-
container_name = 'NectarCAMPedestalContainer'
12+
container_name = "NectarCAMPedestalContainer"
1113

1214
h5file = tables.open_file(filename)
1315

@@ -20,41 +22,50 @@
2022
# fill results for plotting
2123
i = 0
2224
for result in h5file.root.__members__:
23-
table = h5file.root[result]['NectarCAMPedestalContainer'][0]
24-
wf = table['pedestal_mean_hg'][table['pixels_id'] == pixel_id][0]
25-
std = table['pedestal_std_hg'][table['pixels_id'] == pixel_id][0]
26-
if result == 'data_combined':
25+
table = h5file.root[result]["NectarCAMPedestalContainer"][0]
26+
wf = table["pedestal_mean_hg"][table["pixels_id"] == pixel_id][0]
27+
std = table["pedestal_std_hg"][table["pixels_id"] == pixel_id][0]
28+
if result == "data_combined":
2729
pedestal_combined = wf
2830
pedestal_std = std
2931
else:
3032
pedestals[i] = wf
3133
pedestals_std[i] = std
32-
tmin = np.append(tmin,table['ucts_timestamp_min'])
33-
tmax = np.append(tmax, table['ucts_timestamp_max'])
34+
tmin = np.append(tmin, table["ucts_timestamp_min"])
35+
tmax = np.append(tmax, table["ucts_timestamp_max"])
3436
i += 1
3537

3638
tmean = 0.5 * (tmin + tmax)
3739

3840
fig1 = plt.figure()
3941
ax1 = plt.axes()
4042
ax1.set_title(f"Pixel {pixel_id}")
41-
ax1.set_xlabel('sample (ns)')
42-
ax1.set_ylabel('pedestal (ADC counts)')
43+
ax1.set_xlabel("sample (ns)")
44+
ax1.set_ylabel("pedestal (ADC counts)")
4345
for s in range(len(pedestals)):
44-
ax1.plot(pedestals[s],color='0.5',alpha=0.2)
45-
ax1.plot(pedestal_combined,color='r')
46+
ax1.plot(pedestals[s], color="0.5", alpha=0.2)
47+
ax1.plot(pedestal_combined, color="r")
4648

4749
fig2 = plt.figure()
4850
ax2 = plt.axes()
4951
ax2.set_title(f"Pixel {pixel_id} Sample {sample}")
50-
ax2.set_xlabel('UCTS timestamp')
51-
ax2.set_ylabel('pedestal (ADC counts)')
52-
ax2.errorbar(tmean,pedestals[:,sample],
53-
xerr=[tmean-tmin,tmax-tmean],
54-
yerr=[pedestals_std[:,sample]],
55-
fmt = 'o', color='k',capsize=0.)
56-
ax2.axhspan(pedestal_combined[sample]-pedestal_std[sample],
57-
pedestal_combined[sample]+pedestal_std[sample],
58-
facecolor='r', alpha=0.2, zorder=0)
59-
60-
plt.show()
52+
ax2.set_xlabel("UCTS timestamp")
53+
ax2.set_ylabel("pedestal (ADC counts)")
54+
ax2.errorbar(
55+
tmean,
56+
pedestals[:, sample],
57+
xerr=[tmean - tmin, tmax - tmean],
58+
yerr=[pedestals_std[:, sample]],
59+
fmt="o",
60+
color="k",
61+
capsize=0.0,
62+
)
63+
ax2.axhspan(
64+
pedestal_combined[sample] - pedestal_std[sample],
65+
pedestal_combined[sample] + pedestal_std[sample],
66+
facecolor="r",
67+
alpha=0.2,
68+
zorder=0,
69+
)
70+
71+
plt.show()

0 commit comments

Comments
 (0)