Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
########################
### Datasets loading ###
########################
import hax
print("starting!!!")
hax.init(pax_version_policy='v6.10.1',
make_minitrees=False,
minitree_paths=[#'/scratch/midway2/coderre/arianna/'
'/scratch/midway2/rocchetti/minitrees',
'/project2/lgrandi/xenon1t/minitrees/pax_v6.10.1/',
'/project/lgrandi/xenon1t/minitrees/pax_v6.10.1/',
'/dali/lgrandi/xenon1t/minitrees/pax_v6.10.1'],
main_data_paths=['/dali/lgrandi/xenon1t/processed/pax_v6.10.1']
)
import logging
hax.minitrees.log.setLevel(logging.DEBUG)
from hax import cuts
import lax
from lax.lichens import sciencerun1
from lax.lichens.sciencerun1 import *
from lax.lichen import ManyLichen
datasets = hax.runs.datasets
#tsel = hax.runs.tags_selection
datasets = hax.runs.tags_selection(datasets,include='sciencerun1')
#datasets = hax.runs.datasets.query('source__type == "Kr83m"')
#datasets = datasets[(datasets.location != '')]
datasets = datasets[-2000:-1000]
bad_runs = ['181118_0527','180102_1343', '171226_2251', '180102_1944', '180103_0546', '180104_0149', '171226_2251', '171227_0953', '180105_0855',
'180105_1601', '180107_0208', '180107_0308', '180107_1210', '180111_1228', '180112_1916', '180112_2017', '180112_2217', '180113_0518', '180113_0619', '180113_0719',
'180113_1621', '180114_0123', '180114_1225', '180114_1826', '171226_1549', '171229_1546', '170327_0147',
]
datasets = cuts.selection(datasets, np.invert(datasets['name'].isin(bad_runs)), 'Ad hoc bad runs removal')
preselection = ['FiducialZOptimized',
'InteractionExists',
'S2Threshold',
#'InteractionPeaksBiggest',
#'CS2AreaFractionTop',
#'S2SingleScatter',
'S2Width',
'DAQVeto',
'S1SingleScatter',
#'S2PatternLikelihood',
#'KryptonMisIdS',
'Flash',
#'PosDiff',
#'SingleElectronS2s'
]
#dsets = [6732, 6733]
#print('\n###############')
#print_info(datasets_selected)
#print('###############\n')
df = hax.minitrees.load(datasets.name, ['Basics', 'Corrections', 'Extended', 'Fundamentals','PatternReconstruction', 'Proximity', 'FlashIdentification'],
preselection = preselection)
#pickle_name = '/scratch/midway2/rocchetti/S1AFT_Kr83_0_100.p'
#pickle_name = '/scratch/midway2/rocchetti/S1AFT_test.p'
pickle_name = '/scratch/midway2/coderre/arianna/S1AFT_another1000.p'
df.to_pickle(pickle_name)
print(df.head())
#######################################
def acceptance_s1_combined(data2, data3, data4, data5):
bin_edges = np.arange(0,20000, 300)
bin_width = (bin_edges[1]-bin_edges[0])/2
bin_centers = bin_edges[:-1] + bin_width
b2,_ = np.histogram(np.concatenate((data3['s1'],data2['s1'])),bins=bin_edges)
b1,_ = np.histogram(data2['s1'],bins=bin_edges)
acc = b1/b2
#acc_err = [(1-2*x/y)*x/y**2 + x**2/y**3 if x != y else 0 for x,y in zip(b1,b2)]
acc_err = [1/y * np.sqrt((x**2+x*y)/y) if x != y else 0 for x,y in zip(b1,b2)]
#acc_err = [(1./np.sqrt(y)) if x != y else 0 for x,y in zip(b1,b2)]
plt.errorbar(x=bin_centers,y=acc,yerr=acc_err,xerr=[bin_width for i in range(len(bin_centers))],
linestyle='',capsize=0,c='red', label = 'oldcut')
plt.xlabel('s1')
plt.ylabel('acceptance')
#bin_edges = np.arange(0,3000, 150)
b2,_ = np.histogram(np.concatenate((data4['s1'],data5['s1'])),bins=bin_edges)
b1,_ = np.histogram(data4['s1'],bins=bin_edges)
acc = b1/b2
#print (acc,b1,b2)
#acc_err = [(1-2*x/y)*x/y**2 + x**2/y**3 if x != y else 0 for x,y in zip(b1,b2)]
acc_err = [1/y * np.sqrt((x**2+x*y)/y) if x != y else 0 for x,y in zip(b1,b2)]
#print(acc_err)
#acc_err = [1./np.sqrt(y) if x != y else 0 for x,y in zip(b1,b2)]
plt.errorbar(x=bin_centers,y=acc,yerr=acc_err,xerr=[bin_width for i in range(len(bin_centers))],
linestyle='',capsize=0,c='blue', label = 'newcut' )
plt.xlabel('s1')
plt.ylabel('acceptance')
plt.xlim(0,20000)
plt.ylim(0.6,1.1)
plt.plot([3000,3000],[0, 1.2], color = 'black', linestyle = 'dotted')
#plt.plot([0,1],[1, 1], color = 'blue', linestyle = 'dotted')
plt.legend(loc=3)
plt.show()
acceptance_s1_combined(pass_oldcut, fail_oldcut, pass_cut2, fail_cut2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.