All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
lib.dedx Namespace Reference

Functions

def Calc_MPV_DEDX
 
def Calc_MEAN_DEDX
 
def make_mpv_map
 
def recombination
 
def Birks_recombination
 
def landau_gaus
 
def langau_chi2
 
def gain_predicted_MPV
 
def gain_predicted_MPV_Birks
 
def gain_chi2
 
def gain_chi2_Birks
 
def valid_mpv
 
def calibrate_plot
 

Variables

float LAr_density_gmL = 1.3973
 
tuple CSDA_RR_REF
 
tuple KE_REF
 
float mass_electron = 0.5109989461
 
float mass = 105.6583745
 
float Ival = 188.0e-6
 
float Zval = 18.0
 
float Aval = 39.948
 
float Kfactor = 0.307075
 
tuple RRpitch2dEdx = make_mpv_map()
 
float MODA = 0.930
 
float MODB = 0.212
 
int Wion = 1
 
float Efield = 0.5
 
float k = 0.0486
 
float A = 0.8
 

Function Documentation

def lib.dedx.Birks_recombination (   dEdx)

Definition at line 139 of file dedx.py.

140 def Birks_recombination(dEdx):
141  R = A / (1 + k*dEdx / (Efield*LAr_density_gmL))
142  return R * dEdx / Wion
def Birks_recombination
Definition: dedx.py:139
def lib.dedx.Calc_MEAN_DEDX (   T)

Definition at line 70 of file dedx.py.

70 
71 def Calc_MEAN_DEDX(T):
72  gamma = (mass+T)/mass
73  beta = np.power(1.0-np.power(gamma,-2.0),0.5)
74  Wmax = (2.0*mass_electron*np.power(beta,2.0)*np.power(gamma,2.0))/(1.0+2.0*gamma*(mass_electron/mass)+np.power(mass_electron/mass,2.0))
75 
76  # Medium energy
77  dens_factor = 2.0*np.log(10)*np.log10(beta*gamma)-5.2146+0.19559*np.power(3.0-np.log10(beta*gamma),3.0)
78  # low energy
79  dens_factor[np.log10(beta*gamma) < 0.2] = 0.
80  dens_factor[beta < 1e-6] = 0.
81  # high energy
82  dens_factor[np.log10(beta*gamma) > 3.0] = (2.0*np.log(10)*np.log10(beta*gamma)-5.2146)[np.log10(beta*gamma) > 3.0]
83  dEdx_mean = LAr_density_gmL*Kfactor*(Zval/Aval)*np.power(beta,-2.0)*(0.5*np.log(2.0*mass_electron*np.power(beta,2.0)*np.power(gamma,2.0)*Wmax*np.power(Ival,-2.0))-np.power(beta,2.0)-dens_factor/2.0)
84 
85  return dEdx_mean
86 
# Map R.R. to KE
def Calc_MEAN_DEDX
Definition: dedx.py:70
def lib.dedx.Calc_MPV_DEDX (   pitch,
  T 
)

Definition at line 53 of file dedx.py.

53 
54 def Calc_MPV_DEDX(pitch, T):
55  gamma = (mass+T)/mass
56  beta = np.power(1.0-np.power(gamma,-2.0),0.5)
57  Wmax = (2.0*mass_electron*np.power(beta,2.0)*np.power(gamma,2.0))/(1.0+2.0*gamma*(mass_electron/mass)+np.power(mass_electron/mass,2.0))
58 
59  # Medium energy
60  dens_factor = 2.0*np.log(10)*np.log10(beta*gamma)-5.2146+0.19559*np.power(3.0-np.log10(beta*gamma),3.0)
61  # low energy
62  dens_factor[np.log10(beta*gamma) < 0.2] = 0.
63  # high energy
64  dens_factor[np.log10(beta*gamma) > 3.0] = (2.0*np.log(10)*np.log10(beta*gamma)-5.2146)[np.log10(beta*gamma) > 3.0]
65  xi = (Kfactor/2.0)*(Zval/Aval)*np.power(beta,-2.0)*LAr_density_gmL*pitch
66  kappa = xi/Wmax
67  dEdx_MPV = xi*(np.log((2.0*mass_electron*np.power(beta*gamma,2.0))/Ival)+np.log(xi/Ival)+0.200-np.power(beta,2.0)-dens_factor)/pitch
68 
69  return dEdx_MPV
def Calc_MPV_DEDX
Definition: dedx.py:53
def lib.dedx.calibrate_plot (   fig,
  Xlist,
  preds,
  datas,
  errs,
  text = None,
  title = None,
  labels = None 
)

Definition at line 178 of file dedx.py.

179 def calibrate_plot(fig, Xlist, preds, datas, errs, text=None, title=None, labels=None):
180  if not isinstance(preds, list):
181  preds = [preds]
182 
183  if not isinstance(datas, list):
184  datas = [datas]
185 
186  if not isinstance(Xlist, list):
187  Xlist = [Xlist]
188 
189  assert(len(preds) == len(datas) == len(Xlist))
190 
191  gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1])
192  ax1 = fig.subplot(gs[0])
193  ax2 = fig.subplot(gs[1], sharex = ax1)
194 
195  colors = fig.rcParams['axes.prop_cycle'].by_key()['color']
196 
197  ps = []
198  ds = []
199 
200  for i, (Xs,pred) in enumerate(zip(Xlist,preds)):
201  color = None if len(preds) == 1 else colors[i]
202  label = "Cal. Fit"
203  if labels is not None:
204  label = label + " " + labels[i]
205  p = ax1.plot(Xs, pred, label=label, color=color)
206  ps.append(p[0])
207 
208  for i, (Xs, data, err) in enumerate(zip(Xlist, datas, errs)):
209  color = None if len(preds) == 1 else colors[i]
210  label = "Data M.P.V."
211  if labels is not None:
212  label = label + " " + labels[i]
213  d = ax1.errorbar(Xs, data, yerr=err, ls="none",
214  color=color, label=label, marker=".", markersize=5.)
215  ds.append(d)
216 
217  leg_labels = ["Fit/Data" for _ in ps]
218  if labels is not None:
219  leg_labels = [ll+l for ll,l in zip(leg_labels, labels)]
220 
221  ax1.legend(list(zip(ps, ds)), leg_labels, numpoints=1,
222  handler_map={tuple: HandlerTuple(ndivide=None)})
223 
224  ax2.set_label("Residual Range [cm]")
225  ax1.set_ylabel("dQ/dx [ADDC/cm]")
226 
227  if text:
228  ax1.text(0.5, 2.25, text, transform=fig.gca().transAxes, verticalalignment="top")
229  if title:
230  ax1.set_title(title)
231 
232  ax1.get_shared_x_axes().join(ax1, ax2)
233  fig.subplots_adjust(hspace=.0)
234 
235  for i, (Xs, data, pred, err) in enumerate(zip(Xlist, datas, preds, errs)):
236  color = None if len(preds) == 1 else colors[i]
237  ax2.plot(Xs, (data - pred) / err, color=color) #, linestyle="None", marker=".", markersize=5)
238 
239  ax2.set_ylim([-4, 4])
240  ax2.axhline(0, color="gray")
241  ax2.axhline(1, color="gray", linestyle="--")
242  ax2.axhline(-1, color="gray", linestyle="--")
243  ax2.axhline(2, color="gray", linestyle=":")
244  ax2.axhline(-2, color="gray", linestyle=":")
245  ax2.set_ylabel("Data - Pred. [$\\sigma$]")
246  ax2.set_xlabel("Residual Range [cm]")
247 
248  yticks = ax2.yaxis.get_major_ticks()
249  yticks[-1].label1.set_visible(False)
250  return ax1, ax2
def calibrate_plot
Definition: dedx.py:178
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
list
Definition: file_to_url.sh:28
def lib.dedx.gain_chi2 (   RRs,
  CAL,
  MPV,
  err,
  pitch,
  when,
  A = MODA,
  B = MODB 
)

Definition at line 161 of file dedx.py.

162 def gain_chi2(RRs, CAL, MPV, err, pitch, when, A=MODA, B=MODB):
163  dEdxs = RRpitch2dEdx(RRs, pitch)
164  dQdxs = recombination(dEdxs, A, B)
165  dQdxs_ADC = np.outer(1. / CAL, dQdxs[when])
166  chi2s = (MPV[when] - dQdxs_ADC)**2 / err[when]**2
167  return np.sum(chi2s, axis=-1)
tuple RRpitch2dEdx
Definition: dedx.py:120
def recombination
Definition: dedx.py:128
def gain_chi2
Definition: dedx.py:161
def lib.dedx.gain_chi2_Birks (   RRs,
  CAL,
  MPV,
  err,
  pitch,
  when 
)

Definition at line 168 of file dedx.py.

169 def gain_chi2_Birks(RRs, CAL, MPV, err, pitch, when):
170  dEdxs = RRpitch2dEdx(RRs, pitch)
171  dQdxs = Birks_recombination(dEdxs)
172  dQdxs_ADC = np.outer(1. / CAL, dQdxs[when])
173  chi2s = (MPV[when] - dQdxs_ADC)**2 / err[when]**2
174  return np.sum(chi2s, axis=-1)
def gain_chi2_Birks
Definition: dedx.py:168
tuple RRpitch2dEdx
Definition: dedx.py:120
def Birks_recombination
Definition: dedx.py:139
def lib.dedx.gain_predicted_MPV (   RRs,
  CAL,
  pitch,
  A = MODA,
  B = MODB,
  E = Efield 
)

Definition at line 151 of file dedx.py.

152 def gain_predicted_MPV(RRs, CAL, pitch, A=MODA, B=MODB, E=Efield):
153  dEdxs = RRpitch2dEdx(RRs, pitch)
154  dQdxs = recombination(dEdxs, A, B, E)
155  return dQdxs / CAL
tuple RRpitch2dEdx
Definition: dedx.py:120
def gain_predicted_MPV
Definition: dedx.py:151
def recombination
Definition: dedx.py:128
def lib.dedx.gain_predicted_MPV_Birks (   RRs,
  CAL,
  pitch 
)

Definition at line 156 of file dedx.py.

157 def gain_predicted_MPV_Birks(RRs, CAL, pitch):
158  dEdxs = RRpitch2dEdx(RRs, pitch)
159  dQdxs = Birks_recombination(dEdxs)
160  return dQdxs / CAL
tuple RRpitch2dEdx
Definition: dedx.py:120
def Birks_recombination
Definition: dedx.py:139
def gain_predicted_MPV_Birks
Definition: dedx.py:156
def lib.dedx.landau_gaus (   X,
  p 
)

Definition at line 143 of file dedx.py.

144 def landau_gaus(X, *p):
145  mpv, eta, sigma, A = p
146  sigma = np.minimum(sigma, 100*eta)
147  return landau.landau.gauss_landau(X, mpv, eta, sigma, A)
def landau_gaus
Definition: dedx.py:143
def lib.dedx.langau_chi2 (   x,
  y,
  yerr,
  popt 
)

Definition at line 148 of file dedx.py.

149 def langau_chi2(x, y, yerr, popt):
150  return np.sum(((landau_gaus(x, *popt) - y) / yerr)**2)
def langau_chi2
Definition: dedx.py:148
def landau_gaus
Definition: dedx.py:143
def lib.dedx.make_mpv_map ( )

Definition at line 87 of file dedx.py.

87 
88 def make_mpv_map():
89  KE_points_max = 1000.
90  dRR = 0.01
91  thisKE = KE_points_max
92 
93  KE_points = [thisKE]
94  RR_points = [0.]
95 
96  while thisKE > 0.0:
97  deltaKE = Calc_MEAN_DEDX(np.array([thisKE])) * dRR
98  RR_points.append(RR_points[-1] + dRR)
99  thisKE -= deltaKE[0]
100  KE_points.append(thisKE)
101 
102  KE_points = np.array(list(reversed(KE_points[:-1])))
103  RR_points = np.array(RR_points[:-1])
104 
105 
106  # Map KE to MPV dE/dx
107 
108  # pitches
109  PITCH_points = np.linspace(0.2, 3, 28*100+1)
110 
111  KE_points_2d = np.tile(KE_points, (PITCH_points.size, 1))
112  RR_points_2d = np.tile(RR_points, (PITCH_points.size, 1))
113  PITCH_points_2d = np.tile(PITCH_points, (KE_points.size, 1)).T
114 
115  MPV_dEdx_points_2d = Calc_MPV_DEDX(PITCH_points_2d, KE_points_2d)
116 
117  RRpitch2dEdx = interp2d(RR_points, PITCH_points, MPV_dEdx_points_2d, kind="cubic")
118 
119  return RRpitch2dEdx
def Calc_MPV_DEDX
Definition: dedx.py:53
def make_mpv_map
Definition: dedx.py:87
def Calc_MEAN_DEDX
Definition: dedx.py:70
list
Definition: file_to_url.sh:28
def lib.dedx.recombination (   dEdx,
  A = MODA,
  B = MODB,
  E = Efield 
)

Definition at line 128 of file dedx.py.

129 def recombination(dEdx, A=MODA, B=MODB, E=Efield):
130  alpha = A
131  beta = B / (LAr_density_gmL * E)
132 
133  dQdx = np.log(alpha + dEdx*beta) / (Wion * beta)
134  return dQdx
135 
# ICARUS params
def recombination
Definition: dedx.py:128
def lib.dedx.valid_mpv (   RRs,
  MPV,
  err,
  minRR = 2. 
)

Definition at line 175 of file dedx.py.

176 def valid_mpv(RRs, MPV, err, minRR=2.):
177  return np.isfinite(err) & (RRs > minRR) & (err/MPV < 0.1)
def valid_mpv
Definition: dedx.py:175

Variable Documentation

float lib.dedx.A = 0.8

Definition at line 137 of file dedx.py.

float lib.dedx.Aval = 39.948

Definition at line 50 of file dedx.py.

tuple lib.dedx.CSDA_RR_REF
Initial value:
1 = np.array([
2  9.833e-1,
3  1.786e0,
4  3.321e0,
5  6.598e0,
6  1.058e1,
7  3.084e1,
8  4.250e1,
9  6.732e1,
10  1.063e2,
11  1.725e2,
12  2.385e2,
13  4.934e2,
14  6.163e2
15 ])

Definition at line 13 of file dedx.py.

float lib.dedx.Efield = 0.5

Definition at line 126 of file dedx.py.

float lib.dedx.Ival = 188.0e-6

Definition at line 48 of file dedx.py.

float lib.dedx.k = 0.0486

Definition at line 136 of file dedx.py.

tuple lib.dedx.KE_REF
Initial value:
1 = np.array([
2  10.,
3  14.,
4  20.,
5  30.,
6  40.,
7  80.,
8  100.,
9  140.,
10  200.,
11  300.,
12  400.,
13  800.,
14  1000.
15 ])

Definition at line 29 of file dedx.py.

float lib.dedx.Kfactor = 0.307075

Definition at line 51 of file dedx.py.

float lib.dedx.LAr_density_gmL = 1.3973

Definition at line 10 of file dedx.py.

float lib.dedx.mass = 105.6583745

Definition at line 47 of file dedx.py.

float lib.dedx.mass_electron = 0.5109989461

Definition at line 46 of file dedx.py.

float lib.dedx.MODA = 0.930

Definition at line 123 of file dedx.py.

float lib.dedx.MODB = 0.212

Definition at line 124 of file dedx.py.

tuple lib.dedx.RRpitch2dEdx = make_mpv_map()

Definition at line 120 of file dedx.py.

int lib.dedx.Wion = 1

Definition at line 125 of file dedx.py.

float lib.dedx.Zval = 18.0

Definition at line 49 of file dedx.py.