12 #include "vdt/vdtMath.h" 23 maxIterations_ = 1000;
37 vertexSizeTime_ = conf.
getParameter<
double>(
"vertexSizeTime");
38 coolingFactor_ = conf.
getParameter<
double>(
"coolingFactor");
43 uniquetrkweight_ = conf.
getParameter<
double>(
"uniquetrkweight");
44 uniquetrkminp_ = conf.
getParameter<
double>(
"uniquetrkminp");
48 convergence_mode_ = conf.
getParameter<
int>(
"convergence_mode");
53 std::cout <<
"DAClusterizerInZT_vect: mintrkweight = " << mintrkweight_ << std::endl;
54 std::cout <<
"DAClusterizerInZT_vect: uniquetrkweight = " << uniquetrkweight_ << std::endl;
55 std::cout <<
"DAClusterizerInZT_vect: uniquetrkminp = " << uniquetrkminp_ << std::endl;
56 std::cout <<
"DAClusterizerInZT_vect: zmerge = " << zmerge_ << std::endl;
57 std::cout <<
"DAClusterizerInZT_vect: tmerge = " << tmerge_ << std::endl;
58 std::cout <<
"DAClusterizerInZT_vect: Tmin = " <<
minT << std::endl;
59 std::cout <<
"DAClusterizerInZT_vect: Tpurge = " << purgeT << std::endl;
60 std::cout <<
"DAClusterizerInZT_vect: Tstop = " << stopT << std::endl;
61 std::cout <<
"DAClusterizerInZT_vect: vertexSize = " << vertexSize_ << std::endl;
62 std::cout <<
"DAClusterizerInZT_vect: vertexSizeTime = " << vertexSizeTime_ << std::endl;
63 std::cout <<
"DAClusterizerInZT_vect: coolingFactor = " << coolingFactor_ << std::endl;
64 std::cout <<
"DAClusterizerInZT_vect: d0CutOff = " << d0CutOff_ << std::endl;
65 std::cout <<
"DAClusterizerInZT_vect: dzCutOff = " << dzCutOff_ << std::endl;
66 std::cout <<
"DAClusterizerInZT_vect: dtCutoff = " << dtCutOff_ << std::endl;
67 std::cout <<
"DAClusterizerInZT_vect: zrange = " << sel_zrange_ << std::endl;
68 std::cout <<
"DAClusterizerinZT_vect: convergence mode = " << convergence_mode_ << std::endl;
69 std::cout <<
"DAClusterizerinZT_vect: delta_highT = " << delta_highT_ << std::endl;
70 std::cout <<
"DAClusterizerinZT_vect: delta_lowT = " << delta_lowT_ << std::endl;
71 std::cout <<
"DAClusterizerinZT_vect: DEBUGLEVEL " << DEBUGLEVEL << std::endl;
74 if (convergence_mode_ > 1) {
76 <<
"DAClusterizerInZT_vect: invalid convergence_mode " << convergence_mode_ <<
" reset to default " << 0;
77 convergence_mode_ = 0;
83 <<
"DAClusterizerInZT_vect: invalid Tmin " <<
minT <<
" reset to default " << 1. / betamax_;
88 if ((purgeT >
minT) || (purgeT == 0)) {
90 <<
"DAClusterizerInZT_vect: invalid Tpurge " << purgeT <<
" set to " <<
minT;
93 betapurge_ = 1. / purgeT;
95 if ((stopT > purgeT) || (stopT == 0)) {
97 <<
"DAClusterizerInZT_vect: invalid Tstop " << stopT <<
" set to " <<
max(1., purgeT);
98 stopT =
max(1., purgeT);
100 betastop_ = 1. / stopT;
104 inline double local_exp(
double const& inp) {
return vdt::fast_exp(inp); }
106 inline void local_exp_list_range(
double const* __restrict__ arg_inp,
107 double* __restrict__ arg_out,
110 for (
auto i = kmin;
i != kmax; ++
i)
111 arg_out[
i] = vdt::fast_exp(arg_inp[
i]);
130 assert(
v.zvtx_vec.size() == nv);
131 assert(
v.tvtx_vec.size() == nv);
133 assert(
v.dt2_vec.size() == nv);
134 assert(
v.sumw_vec.size() == nv);
136 assert(
v.rho_vec.size() == nv);
137 assert(
v.swz_vec.size() == nv);
138 assert(
v.swt_vec.size() == nv);
139 assert(
v.exp_arg_vec.size() == nv);
140 assert(
v.exp_vec.size() == nv);
142 assert(
v.nuz_vec.size() == nv);
143 assert(
v.nut_vec.size() == nv);
144 assert(
v.szz_vec.size() == nv);
145 assert(
v.stt_vec.size() == nv);
146 assert(
v.szt_vec.size() == nv);
148 assert(
v.zvtx == &
v.zvtx_vec.front());
149 assert(
v.tvtx == &
v.tvtx_vec.front());
150 assert(
v.rho == &
v.rho_vec.front());
151 assert(
v.exp_arg == &
v.exp_arg_vec.front());
152 assert(
v.swz == &
v.swz_vec.front());
153 assert(
v.swt == &
v.swt_vec.front());
155 assert(
v.nuz == &
v.nuz_vec.front());
156 assert(
v.nut == &
v.nut_vec.front());
157 assert(
v.szz == &
v.szz_vec.front());
158 assert(
v.stt == &
v.stt_vec.front());
159 assert(
v.szt == &
v.szt_vec.front());
161 assert(
v.sumw == &
v.sumw_vec.front());
162 assert(
v.dt2 == &
v.dt2_vec.front());
165 for (
unsigned int k = 0;
k < nv - 1;
k++) {
166 if (
v.zvtx[
k] <=
v.zvtx[
k + 1])
168 cout <<
" ZT, cluster z-ordering assertion failure z[" <<
k <<
"] =" <<
v.zvtx[
k] <<
" z[" <<
k + 1
169 <<
"] =" <<
v.zvtx[
k + 1] << endl;
193 for (
unsigned int i = 0;
i <
nt;
i++) {
196 cout <<
"track vertex range assertion failure" <<
i <<
"/" <<
nt <<
" kmin,kmax=" << tks.
kmin[
i] <<
", " 197 << tks.
kmax[
i] <<
" nv=" << nv << endl;
200 for (
unsigned int i = 0;
i <
nt;
i++) {
211 for (
const auto& tk :
tracks) {
215 double t_z = tk.stateAtBeamLine().trackStateAtPCA().position().z();
216 double t_t = tk.timeExt();
218 if (std::fabs(
t_z) > 1000.)
225 auto const& t_mom = tk.stateAtBeamLine().trackStateAtPCA().momentum();
228 double t_dz2 =
std::pow(tk.track().dzError(), 2)
234 edm::LogWarning(
"DAClusterizerinZT_vect") <<
"rejected track t_dz2 " << t_dz2;
246 edm::LogWarning(
"DAClusterizerinZT_vect") <<
"rejected track t_dt2 " << t_dt2;
256 edm::LogWarning(
"DAClusterizerinZT_vect") <<
"rejected track t_tkwt " << t_tkwt;
261 tks.
addItem(
t_z, t_t, t_dz2, t_dt2, &tk, t_tkwt);
273 if (DEBUGLEVEL > 0) {
282 inline double Eik(
double t_z,
double k_z,
double t_dz2,
double t_t,
double k_t,
double t_dt2) {
288 const unsigned int nv = gvertices.
getSize();
289 const unsigned int nt = gtracks.
getSize();
292 edm::LogWarning(
"DAClusterizerinZT_vect") <<
"empty cluster list in set_vtx_range";
296 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
300 unsigned int kmin =
min(nv - 1, gtracks.
kmin[itrack]);
303 while ((kmin > 0) && (gvertices.
zvtx[kmin - 1] >
zmin)) {
307 while ((kmin < (nv - 1)) && (gvertices.
zvtx[kmin] <
zmin)) {
313 unsigned int kmax =
min(nv - 1, gtracks.
kmax[itrack] - 1);
317 while ((kmax < (nv - 1)) && (gvertices.
zvtx[kmax + 1] <
zmax)) {
321 while ((kmax > 0) && (gvertices.
zvtx[kmax] >
zmax)) {
327 gtracks.
kmin[itrack] = kmin;
328 gtracks.
kmax[itrack] = kmax + 1;
331 gtracks.
kmax[itrack] =
min(nv,
max(kmin, kmax) + 1);
335 if (gtracks.
kmin[itrack] >= gtracks.
kmax[itrack]) {
336 cout <<
"set_vtx_range trk = " << itrack <<
" kmin,kmax=" << kmin <<
"," << kmax
337 <<
" gtrack.kmin,kmax = " << gtracks.
kmin[itrack] <<
"," << gtracks.
kmax[itrack] <<
" zrange = " <<
zrange 345 const unsigned int nt = gtracks.
getSize();
346 const unsigned int nv = gvertices.
getSize();
347 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
348 gtracks.
kmin[itrack] = 0;
349 gtracks.
kmax[itrack] = nv;
354 double beta,
track_t& gtracks,
vertex_t& gvertices,
const double rho0,
const bool updateTc)
const {
359 const unsigned int nt = gtracks.
getSize();
360 const unsigned int nv = gvertices.
getSize();
365 Z_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
370 auto kernel_calc_exp_arg_range = [
beta](
const unsigned int itrack,
373 const unsigned int kmin,
374 const unsigned int kmax) {
375 const auto track_z =
tracks.zpca[itrack];
377 const auto botrack_dz2 = -
beta *
tracks.dz2[itrack];
379 const auto botrack_dt2 = -
beta *
tracks.dt2[itrack];
382 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
383 const auto mult_resz = track_z -
vertices.zvtx[ivertex];
386 const auto botrack_dt2 =
389 vertices.exp_arg[ivertex] = botrack_dz2 * (mult_resz * mult_resz) + botrack_dt2 * (mult_rest * mult_rest);
393 auto kernel_add_Z_range = [Z_init](
394 vertex_t const&
vertices,
const unsigned int kmin,
const unsigned int kmax) ->
double {
395 double ZTemp = Z_init;
396 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
402 auto kernel_calc_normalization_range = [updateTc](
const unsigned int track_num,
405 const unsigned int kmin,
406 const unsigned int kmax) {
407 auto tmp_trk_tkwt =
tracks.tkwt[track_num];
408 auto o_trk_sum_Z = 1. /
tracks.sum_Z[track_num];
409 auto o_trk_err_z =
tracks.dz2[track_num];
410 auto o_trk_err_t =
tracks.dt2[track_num];
411 auto tmp_trk_z =
tracks.zpca[track_num];
412 auto tmp_trk_t =
tracks.tpca[track_num];
416 for (
unsigned int k = kmin;
k < kmax; ++
k) {
420 const auto wz =
w * o_trk_err_z;
421 const auto wt =
w * o_trk_err_t;
430 const auto dsz = (tmp_trk_z -
vertices.zvtx[
k]) * o_trk_err_z;
431 const auto dst = (tmp_trk_t -
vertices.tvtx[
k]) * o_trk_err_t;
438 for (
unsigned int k = kmin;
k < kmax; ++
k) {
441 const auto wz =
w * o_trk_err_z;
442 const auto wt =
w * o_trk_err_t;
454 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
455 gvertices.
se[ivertex] = 0.0;
456 gvertices.
nuz[ivertex] = 0.0;
457 gvertices.
nut[ivertex] = 0.0;
458 gvertices.
swz[ivertex] = 0.0;
459 gvertices.
swt[ivertex] = 0.0;
460 gvertices.
szz[ivertex] = 0.0;
461 gvertices.
stt[ivertex] = 0.0;
462 gvertices.
szt[ivertex] = 0.0;
464 gvertices.sumw[ivertex] = 0.0;
469 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
470 const unsigned int kmin = gtracks.
kmin[itrack];
471 const unsigned int kmax = gtracks.
kmax[itrack];
474 assert((kmin < kmax) && (kmax <= nv));
478 kernel_calc_exp_arg_range(itrack, gtracks, gvertices, kmin, kmax);
479 local_exp_list_range(gvertices.
exp_arg, gvertices.
exp, kmin, kmax);
480 gtracks.
sum_Z[itrack] = kernel_add_Z_range(gvertices, kmin, kmax);
483 gtracks.
sum_Z[itrack] = 0.0;
485 if (gtracks.
sum_Z[itrack] > 1.e-100) {
486 kernel_calc_normalization_range(itrack, gtracks, gvertices, kmin, kmax);
495 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
522 edm::LogInfo(
"sumw") <<
"invalid sum of weights in fit: " << endl;
525 <<
" sumw(z,t) =" <<
vertices.nuz[ivertex] <<
"," <<
vertices.nut[ivertex] << endl;
531 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
538 double delta = kernel_calc_zt(gvertices);
540 if (zorder(gvertices)) {
541 set_vtx_range(
beta, gtracks, gvertices);
549 const unsigned int nv = y.getSize();
552 assert(y.zvtx_vec.size() == nv);
553 assert(y.tvtx_vec.size() == nv);
554 assert(y.rho_vec.size() == nv);
560 bool reordering =
true;
561 bool modified =
false;
565 for (
unsigned int k = 0; (
k + 1) < nv;
k++) {
566 if (y.zvtx[
k + 1] < y.zvtx[
k]) {
567 auto ztemp = y.zvtx[
k];
568 y.zvtx[
k] = y.zvtx[
k + 1];
569 y.zvtx[
k + 1] = ztemp;
570 auto ttemp = y.tvtx[
k];
571 y.tvtx[
k] = y.tvtx[
k + 1];
572 y.tvtx[
k + 1] = ttemp;
574 auto dt2temp = y.dt2[
k];
575 y.dt2[
k] = y.dt2[
k + 1];
576 y.dt2[
k + 1] = dt2temp;
578 auto ptemp = y.rho[
k];
579 y.rho[
k] = y.rho[
k + 1];
580 y.rho[
k + 1] = ptemp;
584 modified |= reordering;
596 double z,
double t,
vertex_t& y,
unsigned int& k_min,
double dz,
double dt)
const {
602 unsigned int nv = y.getSize();
610 for (
unsigned int k0 = 1;
k0 < nv;
k0++) {
616 double delta_min = 1.;
620 while ((k1 > 0) && ((y.zvtx[
k] - y.zvtx[--k1]) <
dz)) {
622 if (
delta < delta_min) {
630 while (((++k1) < nv) && ((y.zvtx[k1] - y.zvtx[
k]) <
dz)) {
632 if (
delta < delta_min) {
638 return (delta_min < 1.);
643 unsigned int niter = 0;
645 double delta_max = delta_lowT_;
647 if (convergence_mode_ == 0) {
648 delta_max = delta_max0;
649 }
else if (convergence_mode_ == 1) {
654 set_vtx_range(
beta, tks,
v);
656 double delta_sum_range = 0;
657 std::vector<double> z0 =
v.zvtx_vec;
659 while (niter++ < maxIterations_) {
661 delta_sum_range +=
delta;
663 if (delta_sum_range > zrange_min_) {
664 for (
unsigned int k = 0;
k <
v.getSize();
k++) {
665 if (
std::abs(
v.zvtx_vec[
k] - z0[
k]) > zrange_min_) {
667 set_vtx_range(
beta, tks,
v);
675 if (
delta < delta_max) {
681 if (DEBUGLEVEL > 0) {
682 std::cout <<
"DAClusterizerInZT_vect.thermalize niter = " << niter <<
" at T = " << 1 /
beta 683 <<
" nv = " <<
v.getSize() << std::endl;
695 const unsigned int nv = y.getSize();
701 unsigned int k1_min = 0, k2_min = 0;
702 double delta_min = 0;
704 for (
unsigned int k1 = 0; (k1 + 1) < nv; k1++) {
705 unsigned int k2 = k1;
706 while ((++k2 < nv) && (std::fabs(y.zvtx[k2] - y.zvtx[k1]) < zmerge_)) {
707 auto delta =
std::pow((y.zvtx[k2] - y.zvtx[k1]) / zmerge_, 2) +
std::pow((y.tvtx[k2] - y.tvtx[k1]) / tmerge_, 2);
708 if ((
delta < delta_min) || (k1_min == k2_min)) {
716 if ((k1_min == k2_min) || (delta_min > 1)) {
720 double rho = y.rho[k1_min] + y.rho[k2_min];
723 assert((k1_min < nv) && (k2_min < nv));
724 if (DEBUGLEVEL > 1) {
725 std::cout <<
"merging (" << setw(8) <<
fixed << setprecision(4) << y.zvtx[k1_min] <<
',' << y.tvtx[k1_min]
726 <<
") and (" << y.zvtx[k2_min] <<
',' << y.tvtx[k2_min] <<
")" 727 <<
" idx=" << k1_min <<
"," << k2_min << std::endl;
732 y.zvtx[k1_min] = (y.rho[k1_min] * y.zvtx[k1_min] + y.rho[k2_min] * y.zvtx[k2_min]) / rho;
733 y.tvtx[k1_min] = (y.rho[k1_min] * y.tvtx[k1_min] + y.rho[k2_min] * y.tvtx[k2_min]) / rho;
735 y.dt2[k1_min] = (y.rho[k1_min] * y.dt2[k1_min] + y.rho[k2_min] * y.dt2[k2_min]) / rho;
738 y.zvtx[k1_min] = 0.5 * (y.zvtx[k1_min] + y.zvtx[k2_min]);
739 y.tvtx[k1_min] = 0.5 * (y.tvtx[k1_min] + y.tvtx[k2_min]);
742 y.removeItem(k2_min, tks);
745 set_vtx_range(
beta, tks, y);
753 const unsigned int nv = y.getSize();
759 std::vector<double> sump_v(nv), arg_cache_v(nv), exp_cache_v(nv), pcut_cache_v(nv);
760 std::vector<int> nUnique_v(nv);
761 double* __restrict__ parg_cache;
762 double* __restrict__ pexp_cache;
763 double* __restrict__ ppcut_cache;
764 double* __restrict__ psump;
765 int* __restrict__ pnUnique;
769 set_vtx_range(
beta, tks, y);
771 parg_cache = arg_cache_v.data();
772 pexp_cache = exp_cache_v.data();
773 ppcut_cache = pcut_cache_v.data();
774 psump = sump_v.data();
775 pnUnique = nUnique_v.data();
777 const auto rhoconst = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
778 for (
unsigned int k = 0;
k < nv; ++
k) {
779 const double pmax = y.rho[
k] / (y.rho[
k] + rhoconst);
780 ppcut_cache[
k] = uniquetrkweight_ * pmax;
783 for (
unsigned int i = 0;
i <
nt;
i++) {
784 const auto invZ = ((tks.
sum_Z[
i] >
eps) && (tks.
tkwt[
i] > uniquetrkminp_)) ? 1. / tks.
sum_Z[
i] : 0.;
785 const auto track_z = tks.
zpca[
i];
787 const auto botrack_dz2 = -
beta * tks.
dz2[
i];
788 const auto botrack_dt2 = -
beta * tks.
dt2[
i];
789 const auto kmin = tks.
kmin[
i];
790 const auto kmax = tks.
kmax[
i];
792 for (
unsigned int k = kmin;
k < kmax;
k++) {
793 const auto mult_resz = track_z - y.zvtx[
k];
794 const auto mult_rest =
track_t - y.tvtx[
k];
795 parg_cache[
k] = botrack_dz2 * (mult_resz * mult_resz) + botrack_dt2 * (mult_rest * mult_rest);
798 local_exp_list_range(parg_cache, pexp_cache, kmin, kmax);
800 for (
unsigned int k = kmin;
k < kmax;
k++) {
801 const double p = y.rho[
k] * pexp_cache[
k] * invZ;
803 pnUnique[
k] += (
p > ppcut_cache[
k]) ? 1 : 0;
808 unsigned int k0 = nv;
809 for (
unsigned k = 0;
k < nv;
k++) {
810 if ((pnUnique[
k] < nunique_min_) && (psump[
k] < sumpmin)) {
819 if (DEBUGLEVEL > 1) {
820 std::cout <<
"eliminating prototype at " << std::setw(10) << std::setprecision(4) << y.zvtx[
k0] <<
"," 821 << y.tvtx[
k0] <<
" with sump=" << sumpmin <<
" rho*nt =" << y.rho[
k0] *
nt << endl;
824 y.removeItem(
k0, tks);
825 set_vtx_range(
beta, tks, y);
836 const unsigned int nv = y.getSize();
838 for (
unsigned int k = 0;
k < nv;
k++) {
844 for (
unsigned int i = 0;
i <
nt;
i++) {
847 sumwz += w_z * tks.
zpca[
i];
848 sumwt += w_t * tks.
tpca[
i];
852 y.zvtx[
k] = sumwz / sumw_z;
853 y.tvtx[
k] = sumwt / sumw_t;
856 double szz = 0, stt = 0, szt = 0;
857 double nuz = 0, nut = 0;
858 for (
unsigned int i = 0;
i <
nt;
i++) {
865 nuz +=
w * tks.
dz2[
i];
866 nut +=
w * tks.
dt2[
i];
868 double Tz = szz / nuz;
873 Tc = Tz + Tt +
sqrt(
pow(Tz - Tt, 2) + 4 * szt * szt / nuz / nut);
883 if (DEBUGLEVEL > 0) {
884 std::cout <<
"DAClusterizerInZT_vect.beta0: Tc = " << T0 << std::endl;
886 std::cout <<
"DAClusterizerInZT_vect.beta0: nstep = " << coolingsteps << std::endl;
890 if (T0 > 1. / betamax) {
892 return betamax *
std::pow(coolingFactor_, coolingsteps);
895 return betamax * coolingFactor_;
900 double Tz = y.szz[
k] / y.nuz[
k];
903 Tt = y.stt[
k] / y.nut[
k];
904 double mx = y.szt[
k] / y.nuz[
k] * y.szt[
k] / y.nut[
k];
905 return Tz + Tt +
sqrt(
pow(Tz - Tt, 2) + 4 * mx);
917 unsigned int nv = y.getSize();
918 const double twoBeta = 2.0 *
beta;
922 std::vector<std::pair<double, unsigned int> >
critical;
923 for (
unsigned int k = 0;
k < nv;
k++) {
924 double Tc = get_Tc(y,
k);
932 std::stable_sort(
critical.begin(),
critical.end(), std::greater<std::pair<double, unsigned int> >());
937 for (
unsigned int ic = 0; ic <
critical.size(); ic++) {
942 double Mzz = y.nuz[
k] - twoBeta * y.szz[
k];
943 double Mtt = y.nut[
k] - twoBeta * y.stt[
k];
944 double Mzt = -twoBeta * y.szt[
k];
945 const double twoMzt = 2.0 * Mzt;
946 double D =
sqrt(
pow(Mtt - Mzz, 2) + twoMzt * twoMzt);
947 double q1 = atan2(-Mtt + Mzz +
D, -twoMzt);
948 double l1 = 0.5 * (-Mzz - Mtt +
D);
949 double l2 = 0.5 * (-Mzz - Mtt -
D);
951 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, bad eigenvalues! idx=" <<
k <<
" z= " << y.zvtx[
k]
952 <<
" Mzz=" << Mzz <<
" Mtt=" << Mtt <<
" Mzt=" << Mzt << endl;
956 double cq =
cos(qsplit);
957 double sq =
sin(qsplit);
964 double p1 = 0, z1 = 0,
t1 = 0, wz1 = 0, wt1 = 0;
965 double p2 = 0,
z2 = 0,
t2 = 0, wz2 = 0, wt2 = 0;
966 for (
unsigned int i = 0;
i <
nt; ++
i) {
967 if (tks.
sum_Z[
i] > 1.e-100) {
968 double lr = (tks.
zpca[
i] - y.zvtx[
k]) * cq + (tks.
tpca[
i] - y.tvtx[
k]) * sq;
970 double tl = lr < 0 ? 1. : 0.;
976 double t = local_exp(-
arg);
981 double p = y.rho[
k] * tks.
tkwt[
i] *
984 double wz =
p * tks.
dz2[
i];
985 double wt =
p * tks.
dt2[
i];
987 z1 += wz * tl * tks.
zpca[
i];
1002 z1 = y.zvtx[
k] - epsilonz * cq;
1003 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wz1 = " << scientific << wz1 << endl;
1008 t1 = y.tvtx[
k] - epsilont * sq;
1009 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wt1 = " << scientific << wt1 << endl;
1014 z2 = y.zvtx[
k] + epsilonz * cq;
1015 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wz2 = " << scientific << wz2 << endl;
1020 t2 = y.tvtx[
k] + epsilont * sq;
1021 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wt2 = " << scientific << wt2 << endl;
1024 unsigned int k_min1 =
k, k_min2 =
k;
1026 while (((find_nearest(z1,
t1, y, k_min1, epsilonz, epsilont) && (k_min1 !=
k)) ||
1027 (find_nearest(
z2,
t2, y, k_min2, epsilonz, epsilont) && (k_min2 !=
k))) &&
1029 z1 = 0.5 * (z1 + y.zvtx[
k]);
1030 t1 = 0.5 * (
t1 + y.tvtx[
k]);
1031 z2 = 0.5 * (
z2 + y.zvtx[
k]);
1032 t2 = 0.5 * (
t2 + y.tvtx[
k]);
1037 if (DEBUGLEVEL > 1) {
1038 if (std::fabs(y.zvtx[
k] - zdumpcenter_) < zdumpwidth_) {
1039 std::cout <<
" T= " << std::setw(10) << std::setprecision(1) << 1. /
beta <<
" Tc= " <<
critical[ic].first
1040 <<
" direction =" << std::setprecision(4) << qsplit <<
" splitting (" << std::setw(8) <<
std::fixed 1041 << std::setprecision(4) << y.zvtx[
k] <<
"," << y.tvtx[
k] <<
")" 1042 <<
" --> (" << z1 <<
',' <<
t1 <<
"),(" <<
z2 <<
',' <<
t2 <<
") [" <<
p1 <<
"," <<
p2 <<
"]";
1043 if (std::fabs(
z2 - z1) > epsilonz || std::fabs(
t2 -
t1) > epsilont) {
1053 edm::LogInfo(
"DAClusterizerInZT") <<
"warning swapping z in split qsplit=" << qsplit <<
" cq=" << cq
1054 <<
" sq=" << sq << endl;
1067 if (std::fabs(
z2 - z1) > epsilonz || std::fabs(
t2 -
t1) > epsilont) {
1069 double rho1 =
p1 * y.rho[
k] / (
p1 +
p2);
1070 double rho2 =
p2 * y.rho[
k] / (
p1 +
p2);
1073 y.removeItem(
k, tks);
1074 unsigned int k2 = y.insertOrdered(
z2,
t2, rho2, tks);
1078 std::cout <<
"unexpected z-ordering in split" << std::endl;
1084 for (
unsigned int jc = ic; jc <
critical.size(); jc++) {
1095 unsigned int k1 = y.insertOrdered(z1,
t1, rho1, tks);
1099 for (
unsigned int jc = ic; jc <
critical.size(); jc++) {
1106 std::cout <<
"warning ! split rejected, too small." << endl;
1127 y.addItem(0, 0, 1.0);
1128 clear_vtx_range(tks, y);
1131 double beta = beta0(betamax_, tks, y);
1137 thermalize(
beta, tks, y, delta_highT_, 0.);
1141 double betafreeze = betamax_ *
sqrt(coolingFactor_);
1143 while (
beta < betafreeze) {
1147 set_vtx_range(
beta, tks, y);
1153 thermalize(
beta, tks, y, delta_highT_, 0.);
1159 if (DEBUGLEVEL > 0) {
1160 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1161 <<
"merging at T=" << 1 /
beta << std::endl;
1166 set_vtx_range(
beta, tks, y);
1172 set_vtx_range(
beta, tks, y);
1178 if (DEBUGLEVEL > 0) {
1179 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1180 <<
"splitting/merging at T=" << 1 /
beta << std::endl;
1184 unsigned int ntry = 0;
1187 thermalize(
beta, tks, y, delta_highT_, 0.);
1191 set_vtx_range(
beta, tks, y);
1205 if (DEBUGLEVEL > 0) {
1206 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1207 <<
"turning on outlier rejection at T=" << 1 /
beta << std::endl;
1212 if (dzCutOff_ > 0) {
1214 for (
unsigned int a = 0;
a < 5;
a++) {
1219 thermalize(
beta, tks, y, delta_lowT_, rho0);
1223 if (DEBUGLEVEL > 0) {
1224 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1225 <<
"merging with outlier rejection at T=" << 1 /
beta << std::endl;
1234 set_vtx_range(
beta, tks, y);
1239 if (DEBUGLEVEL > 0) {
1240 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1241 <<
"after merging with outlier rejection at T=" << 1 /
beta << std::endl;
1248 while (
beta < betapurge_) {
1250 thermalize(
beta, tks, y, delta_lowT_, rho0);
1255 if (DEBUGLEVEL > 0) {
1256 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1257 <<
"purging at T=" << 1 /
beta << std::endl;
1262 while (purge(y, tks, rho0,
beta)) {
1263 thermalize(
beta, tks, y, delta_lowT_, rho0);
1265 set_vtx_range(
beta, tks, y);
1271 if (DEBUGLEVEL > 0) {
1272 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1273 <<
"last cooling T=" << 1 /
beta << std::endl;
1278 while (
beta < betastop_) {
1280 thermalize(
beta, tks, y, delta_lowT_, rho0);
1282 set_vtx_range(
beta, tks, y);
1288 if (DEBUGLEVEL > 0) {
1289 std::cout <<
"DAClusterizerInZT_vect::vertices :" 1290 <<
"stop cooling at T=" << 1 /
beta << std::endl;
1298 double betadummy = 1;
1299 while (
merge(y, tks, betadummy))
1304 set_vtx_range(
beta, tks, y);
1305 const unsigned int nv = y.getSize();
1306 for (
unsigned int k = 0;
k < nv;
k++)
1312 const auto z_sum_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
1313 std::vector<std::vector<unsigned int> > vtx_track_indices(nv);
1314 for (
unsigned int i = 0;
i <
nt;
i++) {
1315 const auto kmin = tks.
kmin[
i];
1316 const auto kmax = tks.
kmax[
i];
1317 for (
auto k = kmin;
k < kmax;
k++) {
1321 local_exp_list_range(y.exp_arg, y.exp, kmin, kmax);
1323 tks.
sum_Z[
i] = z_sum_init;
1324 for (
auto k = kmin;
k < kmax;
k++) {
1325 tks.
sum_Z[
i] += y.rho[
k] * y.exp[
k];
1327 const double invZ = tks.
sum_Z[
i] > 1
e-100 ? 1. / tks.
sum_Z[
i] : 0.0;
1329 for (
auto k = kmin;
k < kmax;
k++) {
1330 double p = y.rho[
k] * y.exp[
k] * invZ;
1331 if (
p > mintrkweight_) {
1333 vtx_track_indices[
k].push_back(
i);
1340 GlobalError dummyError(0.01, 0, 0.01, 0., 0., 0.01);
1341 for (
unsigned int k = 0;
k < nv;
k++) {
1342 if (!vtx_track_indices[
k].
empty()) {
1344 vector<reco::TransientTrack> vertexTracks;
1345 for (
auto i : vtx_track_indices[
k]) {
1346 vertexTracks.push_back(*(tks.
tt[
i]));
1357 const vector<reco::TransientTrack>&
tracks)
const {
1358 vector<vector<reco::TransientTrack> >
clusters;
1362 if (DEBUGLEVEL > 0) {
1363 std::cout <<
"###################################################" << endl;
1364 std::cout <<
"# vectorized DAClusterizerInZT_vect::clusterize nt=" <<
tracks.size() << endl;
1365 std::cout <<
"# DAClusterizerInZT_vect::clusterize pv.size=" <<
pv.size() << endl;
1366 std::cout <<
"###################################################" << endl;
1375 for (
auto k =
pv.begin();
k !=
pv.end();
k++) {
1376 vector<reco::TransientTrack> aCluster =
k->originalTracks();
1377 if (aCluster.size() > 1) {
1387 const unsigned int nv = y.getSize();
1390 std::vector<unsigned int> iz;
1391 for (
unsigned int j = 0;
j <
nt;
j++) {
1394 std::sort(iz.begin(), iz.end(), [tks](
unsigned int a,
unsigned int b) {
return tks.
zpca[
a] < tks.
zpca[
b]; });
1396 std::cout <<
"-----DAClusterizerInZT::dump ----" << nv <<
" clusters " << std::endl;
1399 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1400 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1408 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1409 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1417 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1418 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1424 std::cout <<
"T=" << setw(15) << 1. /
beta <<
" Tmin =" << setw(10) << 1. / betamax_
1426 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1427 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1428 double Tc = get_Tc(y, ivertex);
1436 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1437 sumrho += y.rho[ivertex];
1438 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1440 std::cout << setw(8) << setprecision(4) <<
fixed << y.rho[ivertex];
1445 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1446 sumrho += y.rho[ivertex];
1447 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1454 double E = 0,
F = 0;
1456 std::cout <<
"---- z +/- dz t +/- dt ip +/-dip pt phi eta weights ----" 1459 for (
unsigned int i0 = 0; i0 <
nt; i0++) {
1460 unsigned int i = iz[i0];
1464 double tz = tks.
zpca[
i];
1466 if (std::fabs(tz - zdumpcenter_) > zdumpwidth_)
1468 std::cout << setw(4) <<
i <<
")" << setw(8) <<
fixed << setprecision(4) << tz <<
" +/-" << setw(6)
1471 if (tks.
dt2[
i] > 0) {
1491 .pixelBarrelLayersWithMeasurement();
1492 std::cout << setw(1) << tks.
tt[
i]->track().hitPattern().pixelEndcapLayersWithMeasurement();
1494 << tks.
tt[
i]->track().hitPattern().trackerLayersWithMeasurement() -
1495 tks.
tt[
i]->track().hitPattern().pixelLayersWithMeasurement()
1501 std::cout << setw(8) <<
IP.value() <<
"+/-" << setw(6) <<
IP.error();
1502 std::cout <<
" " << setw(6) << setprecision(2) << tks.
tt[
i]->track().pt() * tks.
tt[
i]->track().charge();
1503 std::cout <<
" " << setw(5) << setprecision(2) << tks.
tt[
i]->track().phi() <<
" " << setw(5) << setprecision(2)
1504 << tks.
tt[
i]->track().eta();
1507 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1508 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1515 Eik(tks.
zpca[
i], y.zvtx[ivertex], tks.
dz2[
i], tks.
tpca[
i], y.tvtx[ivertex], tks.
dt2[
i])) /
1518 if ((ivertex >= tks.
kmin[
i]) && (ivertex < tks.
kmax[
i])) {
1520 std::cout << setw(8) << setprecision(3) <<
p;
1524 E +=
p * Eik(tks.
zpca[
i], y.zvtx[ivertex], tks.
dz2[
i], tks.
tpca[
i], y.tvtx[ivertex], tks.
dt2[
i]);
1529 }
else if (
p > 0.0001) {
1530 std::cout <<
"X" << setw(6) << setprecision(3) <<
p <<
"X";
1539 std::cout <<
" ( " << std::setw(3) << tks.
kmin[
i] <<
"," << std::setw(3) << tks.
kmax[
i] - 1 <<
" ) ";
1543 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1544 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1545 std::cout <<
" " << setw(3) << ivertex <<
" ";
1551 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1552 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1558 <<
"T=" << 1 /
beta <<
" E=" << E <<
" n=" << y.getSize() <<
" F= " <<
F << endl
1559 <<
"----------" << endl;
1566 desc.add<
double>(
"tmerge", 0.1);
1567 desc.add<
double>(
"dtCutOff", 4.);
1568 desc.add<
double>(
"t0Max", 1.0);
1569 desc.add<
double>(
"vertexSizeTime", 0.008);
T getParameter(std::string const &) const
double *__restrict__ tpca
std::vector< double > dt2_vec
int merge(int argc, char *argv[])
constexpr bool isNotFinite(T x)
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
std::vector< unsigned int > kmin
double *__restrict__ exp_arg
Sin< T >::type sin(const T &t)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
double get_Tc(const vertex_t &y, int k) const
DAClusterizerInZT_vect(const edm::ParameterSet &conf)
std::vector< double > tkwt_vec
bool purge(vertex_t &, track_t &, double &, const double) const
void addItem(double new_zpca, double new_tpca, double new_dz2, double new_dt2, const reco::TransientTrack *new_tt, double new_tkwt)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< unsigned int > kmax
U second(std::pair< T, U > const &p)
double *__restrict__ zpca
double update(double beta, track_t >racks, vertex_t &gvertices, const double rho0=0, const bool updateTc=false) const
bool split(const double beta, track_t &t, vertex_t &y, double threshold=1.) const
double beta0(const double betamax, track_t const &tks, vertex_t const &y) const
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks) const override
void set_vtx_range(double beta, track_t >racks, vertex_t &gvertices) const
double *__restrict__ tkwt
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
bool zorder(vertex_t &y) const
bool merge(vertex_t &, track_t &, double &beta) const
std::vector< double > sum_Z_vec
double *__restrict__ zvtx
track_t fill(const std::vector< reco::TransientTrack > &tracks) const
void verify(const vertex_t &v, const track_t &tks, unsigned int nv=999999, unsigned int nt=999999) const
def split(sequence, size)
std::vector< double > zpca_vec
Log< level::Info, false > LogInfo
DecomposeProduct< arg, typename Div::arg > D
std::vector< double > tpca_vec
static void fillPSetDescription(edm::ParameterSetDescription &desc)
double *__restrict__ sum_Z
static constexpr float defaultInvalidTrackTimeReso
void dump(const double beta, const vertex_t &y, const track_t &tks, const int verbosity=0) const
std::vector< const reco::TransientTrack * > tt
std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const override
std::vector< double > dz2_vec
unsigned int thermalize(double beta, track_t >racks, vertex_t &gvertices, const double delta_max, const double rho0=0.) const
Log< level::Warning, false > LogWarning
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
bool find_nearest(double z, double t, vertex_t &y, unsigned int &k_min, double dz, double dt) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
unsigned int getSize() const
void clear_vtx_range(track_t >racks, vertex_t &gvertices) const
Power< A, B >::type pow(const A &a, const B &b)
unsigned int getSize() const