2 from scipy.interpolate
import interp2d
4 from matplotlib
import gridspec
5 from matplotlib.legend_handler
import HandlerLine2D, HandlerTuple
10 LAr_density_gmL = 1.3973
13 CSDA_RR_REF = np.array([
46 mass_electron = 0.5109989461
55 beta = np.power(1.0-np.power(gamma,-2.0),0.5)
56 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))
59 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 dens_factor[np.log10(beta*gamma) < 0.2] = 0.
63 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]
64 xi = (Kfactor/2.0)*(Zval/Aval)*np.power(beta,-2.0)*LAr_density_gmL*pitch
66 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
72 beta = np.power(1.0-np.power(gamma,-2.0),0.5)
73 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))
76 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 dens_factor[np.log10(beta*gamma) < 0.2] = 0.
79 dens_factor[beta < 1e-6] = 0.
81 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]
82 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)
90 thisKE = KE_points_max
97 RR_points.append(RR_points[-1] + dRR)
99 KE_points.append(thisKE)
101 KE_points = np.array(
list(reversed(KE_points[:-1])))
102 RR_points = np.array(RR_points[:-1])
108 PITCH_points = np.linspace(0.2, 3, 28*100+1)
110 KE_points_2d = np.tile(KE_points, (PITCH_points.size, 1))
111 RR_points_2d = np.tile(RR_points, (PITCH_points.size, 1))
112 PITCH_points_2d = np.tile(PITCH_points, (KE_points.size, 1)).T
114 MPV_dEdx_points_2d =
Calc_MPV_DEDX(PITCH_points_2d, KE_points_2d)
116 RRpitch2dEdx = interp2d(RR_points, PITCH_points, MPV_dEdx_points_2d, kind=
"cubic")
130 beta = B / (LAr_density_gmL * E)
132 dQdx = np.log(alpha + dEdx*beta) / (Wion * beta)
140 R = A / (1 + k*dEdx / (Efield*LAr_density_gmL))
141 return R * dEdx / Wion
144 mpv, eta, sigma, A = p
145 sigma = np.minimum(sigma, 100*eta)
146 return landau.landau.gauss_landau(X, mpv, eta, sigma, A)
149 return np.sum(((
landau_gaus(x, *popt) - y) / yerr)**2)
161 def gain_chi2(RRs, CAL, MPV, err, pitch, when, A=MODA, B=MODB):
164 dQdxs_ADC = np.outer(1. / CAL, dQdxs[when])
165 chi2s = (MPV[when] - dQdxs_ADC)**2 / err[when]**2
166 return np.sum(chi2s, axis=-1)
171 dQdxs_ADC = np.outer(1. / CAL, dQdxs[when])
172 chi2s = (MPV[when] - dQdxs_ADC)**2 / err[when]**2
173 return np.sum(chi2s, axis=-1)
176 return np.isfinite(err) & (RRs > minRR) & (err/MPV < 0.1)
178 def calibrate_plot(fig, Xlist, preds, datas, errs, text=None, title=None, labels=None):
179 if not isinstance(preds, list):
182 if not isinstance(datas, list):
185 if not isinstance(Xlist, list):
188 assert(len(preds) == len(datas) == len(Xlist))
190 gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1])
191 ax1 = fig.subplot(gs[0])
192 ax2 = fig.subplot(gs[1], sharex = ax1)
194 colors = fig.rcParams[
'axes.prop_cycle'].by_key()[
'color']
200 color =
None if len(preds) == 1
else colors[i]
202 if labels
is not None:
203 label = label +
" " + labels[i]
204 p = ax1.plot(Xs, pred, label=label, color=color)
207 for i, (Xs, data, err)
in enumerate(
zip(Xlist, datas, errs)):
208 color =
None if len(preds) == 1
else colors[i]
209 label =
"Data M.P.V."
210 if labels
is not None:
211 label = label +
" " + labels[i]
212 d = ax1.errorbar(Xs, data, yerr=err, ls=
"none",
213 color=color, label=label, marker=
".", markersize=5.)
216 leg_labels = [
"Fit/Data" for _
in ps]
217 if labels
is not None:
218 leg_labels = [ll+l
for ll,l
in zip(leg_labels, labels)]
220 ax1.legend(
list(
zip(ps, ds)), leg_labels, numpoints=1,
221 handler_map={tuple: HandlerTuple(ndivide=
None)})
223 ax2.set_label(
"Residual Range [cm]")
224 ax1.set_ylabel(
"dQ/dx [ADDC/cm]")
227 ax1.text(0.5, 2.25, text, transform=fig.gca().transAxes, verticalalignment=
"top")
231 ax1.get_shared_x_axes().
join(ax1, ax2)
232 fig.subplots_adjust(hspace=.0)
234 for i, (Xs, data, pred, err)
in enumerate(
zip(Xlist, datas, preds, errs)):
235 color =
None if len(preds) == 1
else colors[i]
236 ax2.plot(Xs, (data - pred) / err, color=color)
238 ax2.set_ylim([-4, 4])
239 ax2.axhline(0, color=
"gray")
240 ax2.axhline(1, color=
"gray", linestyle=
"--")
241 ax2.axhline(-1, color=
"gray", linestyle=
"--")
242 ax2.axhline(2, color=
"gray", linestyle=
":")
243 ax2.axhline(-2, color=
"gray", linestyle=
":")
244 ax2.set_ylabel(
"Data - Pred. [$\\sigma$]")
245 ax2.set_xlabel(
"Residual Range [cm]")
247 yticks = ax2.yaxis.get_major_ticks()
248 yticks[-1].label1.set_visible(
False)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
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.
def gain_predicted_MPV_Birks