Skip to content
Snippets Groups Projects
Commit 861be23e authored by Thijs vanEeden's avatar Thijs vanEeden
Browse files

make plot for maarten

parent d8e9a2ae
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:6b9d9ddb-8cf4-4c9c-bdc0-0de78f0ec35d tags:
``` python
#pip install km3dia
```
%% Cell type:code id:4d699873-c366-4870-a262-56b4c1312855 tags:
``` python
#pip install xmltodict
```
%% Cell type:code id:9034b755-3525-4a06-bbd5-59fe2a1ce3d3 tags:
``` python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import xmltodict
import km3db
import km3dia
```
%% Cell type:code id:d9bf120b-39cc-4adc-8c2f-ecb425d7cd18 tags:
``` python
dia = km3dia.DBManager(container='pd')
DOMInt = km3dia.DOMIntegrationSummary()
```
%% Cell type:code id:1959e023-8415-465c-90a2-7da4b9c3a93b tags:
``` python
#Get measurement results
df_tests = DOMInt.test_results
df_tests = df_tests.reset_index().set_index('UPI')
```
%% Cell type:code id:8ba41596-7e7a-4925-80f9-98c697e705f4 tags:
``` python
# Generate the list of relevant keys
gain_keys = [key for key in df_tests.columns if key.lower().find('gain') != -1]
dc_keys = [key for key in df_tests.columns if key.lower().find('dark') != -1]
pmt_keys = gain_keys + dc_keys
DOMid_keys = ['SERIAL', 'SiteID']
```
%% Cell type:code id:7f681bc2-bfb5-4232-8983-de877bf2f1d4 tags:
``` python
# Cut the dataframe to no NaN
df_pmt = df_tests.dropna(subset=pmt_keys)
df_pmt = df_pmt[pmt_keys + DOMid_keys]
```
%% Cell type:code id:5d602ade-f9d6-4303-ab4c-94938eb0660a tags:
``` python
# Convert pmt results result branches to float
df_pmt = df_pmt.astype(dict(zip(pmt_keys, [float]*len(pmt_keys))))
```
%% Cell type:code id:7c303c75-fa66-48f2-a09f-a5bf146538bc tags:
``` python
def count_chan_above_threshold( gain_threshold = 1.7, ncr_pmt_threshold = 3, siteID = "999" ):
"""
Count number of channels above a gain threshold for each DOM
siteID = "999" means for all sites, "1" is Amsterdam
"""
doms = []
bad_channels = [] # number of bad channels
for index, row in df_pmt.iterrows():
bad = 0
if siteID != "999" and row["SiteID"] != siteID: continue # only amsterdam
for gain_key in gain_keys:
if row[gain_key] > gain_threshold: bad +=1
if bad == 31: continue # there is a group of (older?) DOMS with all gains around 29
doms.append( row["SERIAL"] )
bad_channels.append( bad )
bad_doms = [i for i,v in enumerate(bad_channels) if v > ncr_pmt_threshold]
return doms, bad_channels, len(bad_doms)
```
%% Cell type:code id:4a9a5b4b-4d41-450d-bc2e-fdb10a870ed8 tags:
``` python
import matplotlib.pyplot as plt
gain_threshold = 1.7
ncr_pmt_threshold = 3
location = {"Amsterdam":"1", "All":"999"}
# amsterdam
doms, bad_channels, n_bad_doms = count_chan_above_threshold( gain_threshold, ncr_pmt_threshold, location["Amsterdam"] )
fig, axes = plt.subplots(1,2, figsize=[20,5] )
axes[0].hist(bad_channels, [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5])
axes[0].plot([bad_pmt_threshold,bad_pmt_threshold], [0,30], color='red')
axes[0].set_xlabel("Number of channels with gain > " + str(gain_threshold))
axes[0].set_ylabel("Number of DOMs")
axes[0].set_title("Location: Amsterdam, NCR doms: " + str(n_bad_doms) )
print("failed doms in Amsterdam", n_bad_doms)
# all locations
doms, bad_channels, n_bad_doms = count_chan_above_threshold( gain_threshold, ncr_pmt_threshold, location["All"] )
axes[1].hist(bad_channels, [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5])
axes[1].plot([bad_pmt_threshold,bad_pmt_threshold], [0,60], color='red')
axes[1].set_xlabel("Number of channels with gain > " + str(gain_threshold))
axes[1].set_ylabel("Number of DOMs")
axes[1].set_title("Location: All, NCR doms: " + str(n_bad_doms) )
print("failed doms in All", n_bad_doms)
```
%% Output
failed doms in Amsterdam 20
failed doms in All 30
%% Cell type:code id:4eaed37c-3cae-44ef-88db-fac0ce64acbf tags:
``` python
import numpy as np
def ncr_doms_vs_gain_threshold( gain_min, gain_max, gain_step, ncr_pmt_threshold = 3, siteID = "999" ):
"""
Plot number of bad doms (doms with ncr) versus max gain threshold
"""
gain_thresholds = np.arange( gain_min, gain_max, gain_step )
number_bad_doms = []
for gain_tmp in gain_thresholds:
doms, bad_channels, n_bad_doms = count_chan_above_threshold( gain_tmp, ncr_pmt_threshold, siteID )
number_bad_doms.append( n_bad_doms )
return gain_thresholds, number_bad_doms
# amsterdam
gain_thresholds, number_bad_doms = ncr_doms_vs_gain_threshold(1.7, 2.0, 0.05, 3, location["Amsterdam"] )
fig, axes = plt.subplots(1,2, figsize=[20,5] )
axes[0].plot(gain_thresholds, number_bad_doms)
axes[0].set_xlabel("Max gain in acceptance test")
axes[0].set_ylabel("Number of DOMs with NCR")
axes[0].set_title("Location: Amsterdam" )
# all locations
gain_thresholds, number_bad_doms = ncr_doms_vs_gain_threshold(1.7, 2.0, 0.05, 3, location["All"] )
axes[1].plot(gain_thresholds, number_bad_doms)
axes[1].set_xlabel("Max gain in acceptance test")
axes[1].set_ylabel("Number of DOMs with NCR")
axes[1].set_title("Location: Amsterdam" )
```
%% Output
Text(0.5, 1.0, 'Location: Amsterdam')
%% Cell type:code id:ca1f27e5-fecb-42d5-8e17-dd58da923f08 tags:
``` python
###
### Maarten asked in the group meeting (27-01-2022) what the distribution of all PMTs is
###
bins = np.arange( -0.1, 2.1, 0.1 )
df_gains = df_pmt[gain_keys].stack().reset_index()
df_gains = df_gains[ df_gains[0] < 2.5 ]
df_gains.hist(bins=bins)
plt.plot([0.3,0.3], [0,1500], color='red')
plt.plot([1.7,1.7], [0,1500], color='red')
plt.xlabel("Fitted gain in acceptance test")
plt.ylabel("Counts")
plt.title("Mean: {}, std_dev: {}".format( round(df_gains[0].mean(),3), round(df_gains[0].std(),3) ) )
```
%% Output
Text(0.5, 1.0, 'Mean: 1.299, std_dev: 0.247')
......
%% Cell type:code id:6b9d9ddb-8cf4-4c9c-bdc0-0de78f0ec35d tags:
``` python
#pip install km3dia
```
%% Cell type:code id:4d699873-c366-4870-a262-56b4c1312855 tags:
``` python
#pip install xmltodict
```
%% Cell type:code id:9034b755-3525-4a06-bbd5-59fe2a1ce3d3 tags:
``` python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import xmltodict
import km3db
import km3dia
```
%% Cell type:code id:d9bf120b-39cc-4adc-8c2f-ecb425d7cd18 tags:
``` python
dia = km3dia.DBManager(container='pd')
DOMInt = km3dia.DOMIntegrationSummary()
```
%% Cell type:code id:1959e023-8415-465c-90a2-7da4b9c3a93b tags:
``` python
#Get measurement results
df_tests = DOMInt.test_results
df_tests = df_tests.reset_index().set_index('UPI')
```
%% Cell type:code id:8ba41596-7e7a-4925-80f9-98c697e705f4 tags:
``` python
# Generate the list of relevant keys
gain_keys = [key for key in df_tests.columns if key.lower().find('gain') != -1]
dc_keys = [key for key in df_tests.columns if key.lower().find('dark') != -1]
pmt_keys = gain_keys + dc_keys
DOMid_keys = ['SERIAL', 'SiteID']
```
%% Cell type:code id:7f681bc2-bfb5-4232-8983-de877bf2f1d4 tags:
``` python
# Cut the dataframe to no NaN
df_pmt = df_tests.dropna(subset=pmt_keys)
df_pmt = df_pmt[pmt_keys + DOMid_keys]
```
%% Cell type:code id:5d602ade-f9d6-4303-ab4c-94938eb0660a tags:
``` python
# Convert pmt results result branches to float
df_pmt = df_pmt.astype(dict(zip(pmt_keys, [float]*len(pmt_keys))))
```
%% Cell type:code id:7c303c75-fa66-48f2-a09f-a5bf146538bc tags:
``` python
def count_chan_above_threshold( gain_threshold = 1.7, ncr_pmt_threshold = 3, siteID = "999" ):
"""
Count number of channels above a gain threshold for each DOM
siteID = "999" means for all sites, "1" is Amsterdam
"""
doms = []
bad_channels = [] # number of bad channels
for index, row in df_pmt.iterrows():
bad = 0
if siteID != "999" and row["SiteID"] != siteID: continue # only amsterdam
for gain_key in gain_keys:
if row[gain_key] > gain_threshold: bad +=1
if bad == 31: continue # there is a group of (older?) DOMS with all gains around 29
doms.append( row["SERIAL"] )
bad_channels.append( bad )
bad_doms = [i for i,v in enumerate(bad_channels) if v > ncr_pmt_threshold]
return doms, bad_channels, len(bad_doms)
```
%% Cell type:code id:4a9a5b4b-4d41-450d-bc2e-fdb10a870ed8 tags:
``` python
import matplotlib.pyplot as plt
gain_threshold = 1.7
ncr_pmt_threshold = 3
location = {"Amsterdam":"1", "All":"999"}
# amsterdam
doms, bad_channels, n_bad_doms = count_chan_above_threshold( gain_threshold, ncr_pmt_threshold, location["Amsterdam"] )
fig, axes = plt.subplots(1,2, figsize=[20,5] )
axes[0].hist(bad_channels, [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5])
axes[0].plot([bad_pmt_threshold,bad_pmt_threshold], [0,30], color='red')
axes[0].set_xlabel("Number of channels with gain > " + str(gain_threshold))
axes[0].set_ylabel("Number of DOMs")
axes[0].set_title("Location: Amsterdam, NCR doms: " + str(n_bad_doms) )
print("failed doms in Amsterdam", n_bad_doms)
# all locations
doms, bad_channels, n_bad_doms = count_chan_above_threshold( gain_threshold, ncr_pmt_threshold, location["All"] )
axes[1].hist(bad_channels, [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5])
axes[1].plot([bad_pmt_threshold,bad_pmt_threshold], [0,60], color='red')
axes[1].set_xlabel("Number of channels with gain > " + str(gain_threshold))
axes[1].set_ylabel("Number of DOMs")
axes[1].set_title("Location: All, NCR doms: " + str(n_bad_doms) )
print("failed doms in All", n_bad_doms)
```
%% Output
failed doms in Amsterdam 20
failed doms in All 30
%% Cell type:code id:4eaed37c-3cae-44ef-88db-fac0ce64acbf tags:
``` python
import numpy as np
def ncr_doms_vs_gain_threshold( gain_min, gain_max, gain_step, ncr_pmt_threshold = 3, siteID = "999" ):
"""
Plot number of bad doms (doms with ncr) versus max gain threshold
"""
gain_thresholds = np.arange( gain_min, gain_max, gain_step )
number_bad_doms = []
for gain_tmp in gain_thresholds:
doms, bad_channels, n_bad_doms = count_chan_above_threshold( gain_tmp, ncr_pmt_threshold, siteID )
number_bad_doms.append( n_bad_doms )
return gain_thresholds, number_bad_doms
# amsterdam
gain_thresholds, number_bad_doms = ncr_doms_vs_gain_threshold(1.7, 2.0, 0.05, 3, location["Amsterdam"] )
fig, axes = plt.subplots(1,2, figsize=[20,5] )
axes[0].plot(gain_thresholds, number_bad_doms)
axes[0].set_xlabel("Max gain in acceptance test")
axes[0].set_ylabel("Number of DOMs with NCR")
axes[0].set_title("Location: Amsterdam" )
# all locations
gain_thresholds, number_bad_doms = ncr_doms_vs_gain_threshold(1.7, 2.0, 0.05, 3, location["All"] )
axes[1].plot(gain_thresholds, number_bad_doms)
axes[1].set_xlabel("Max gain in acceptance test")
axes[1].set_ylabel("Number of DOMs with NCR")
axes[1].set_title("Location: Amsterdam" )
```
%% Output
Text(0.5, 1.0, 'Location: Amsterdam')
%% Cell type:code id:ca1f27e5-fecb-42d5-8e17-dd58da923f08 tags:
``` python
###
### Maarten asked in the group meeting (27-01-2022) what the distribution of all PMTs is
###
bins = np.arange( -0.1, 2.1, 0.1 )
df_gains = df_pmt[gain_keys].stack().reset_index()
df_gains = df_gains[ df_gains[0] < 2.5 ]
df_gains.hist(bins=bins)
plt.plot([0.3,0.3], [0,1500], color='red')
plt.plot([1.7,1.7], [0,1500], color='red')
plt.xlabel("Fitted gain in acceptance test")
plt.ylabel("Counts")
plt.title("Mean: {}, std_dev: {}".format( round(df_gains[0].mean(),3), round(df_gains[0].std(),3) ) )
```
%% Output
Text(0.5, 1.0, 'Mean: 1.299, std_dev: 0.247')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment