demo1.py
Go to the documentation of this file.
1 import os
2 import sys
3 sys.path.append('../..')
4 
5 from PandAna.core import *
6 import matplotlib.pyplot as plt
7 
8 # Better var
9 def kPngE(tables):
10  df = tables['rec.vtx.elastic.fuzzyk.png']['calE']
11  return df.groupby(level = KL).sum()
12 kPngE = Var(kPngE)
13 # NOTE: No check that there are actually prongs in the event
14 # The rec.vtx.elastic.fuzzyk.png dataset already only has events with prongs
15 
16 # Vertex fiducial cut
17 def kFiducial(tables):
18  df = tables['rec.vtx.elastic']
19  return (df['vtx.x'] < 180) & \
20  (df['vtx.x'] > -180) & \
21  (df['vtx.y'] < 180) & \
22  (df['vtx.y'] > -180) & \
23  (df['vtx.z'] < 1000) & \
24  (df['vtx.z'] > 50)
25 kFiducial = Cut(kFiducial)
26 
27 if __name__ == '__main__':
28  # Latest h5s from Karl
29  loc = '/pnfs/nova/persistent/users/karlwarb/HDF5-Training-19-02-26/FD-FluxSwap-FHC'
30  files = [os.path.join(loc, f) for f in os.listdir(loc) if 'h5caf.h5' in f]
31  tables = loader(files, limit=100)
32 
33  # Create a spectrum
34  myspectrum = spectrum(tables, kFiducial, kPngE)
35 
36  # Let's do it!
37  tables.Go()
38 
39  print('myspectrum internal dataframe: ')
40  print(myspectrum.df().head())
41 
42  n, bins = myspectrum.histogram(bins=20, range=(1,4))
43 
44  print('Selected '+ str(n.sum()) + ' events')
45 
46  plt.hist(bins[:-1], bins=bins, weights=n)
47 
48  plt.xlabel('Prong Energy')
49  plt.ylabel('Events')
50 
51  plt.legend(loc='upper right')
52 
53  plt.show()
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
bool print
Double_t sum
Definition: plot.C:31