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]);
133 assert(v.dt2_vec.size() == nv);
134 assert(v.sumw_vec.size() == nv);
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++) {
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;
241 if ((tk.dtErrorExt() > 0.3) || (
std::abs(t_t) > t0Max_)) {
246 edm::LogWarning(
"DAClusterizerinZT_vect") <<
"rejected track t_dt2 " << t_dt2;
252 Measurement1D atIP = tk.stateAtBeamLine().transverseImpactParameter();
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);
266 tks.
osumtkwt = sumtkwt > 0 ? 1. / sumtkwt : 0.;
269 if (DEBUGLEVEL > 0) {
270 std::cout <<
"Track count (ZT) filled " << tks.
getSize() <<
" initial " << tracks.size() << std::endl;
278 inline double Eik(
double t_z,
double k_z,
double t_dz2,
double t_t,
double k_t,
double t_dt2) {
284 const unsigned int nv = gvertices.
getSize();
285 const unsigned int nt = gtracks.
getSize();
288 edm::LogWarning(
"DAClusterizerinZT_vect") <<
"empty cluster list in set_vtx_range";
292 for (
auto itrack = 0U; itrack <
nt; ++itrack) {
293 double zrange =
max(sel_zrange_ /
sqrt(beta * gtracks.
dz2[itrack]), zrange_min_);
295 double zmin = gtracks.
zpca[itrack] - zrange;
296 unsigned int kmin =
min(nv - 1, gtracks.
kmin[itrack]);
298 if (gvertices.
zvtx[kmin] > zmin) {
299 while ((kmin > 0) && (gvertices.
zvtx[kmin - 1] > zmin)) {
303 while ((kmin < (nv - 1)) && (gvertices.
zvtx[kmin] < zmin)) {
308 double zmax = gtracks.
zpca[itrack] + zrange;
309 unsigned int kmax =
min(nv - 1, gtracks.
kmax[itrack] - 1);
312 if (gvertices.
zvtx[kmax] < zmax) {
313 while ((kmax < (nv - 1)) && (gvertices.
zvtx[kmax + 1] < zmax)) {
317 while ((kmax > 0) && (gvertices.
zvtx[kmax] > zmax)) {
323 gtracks.
kmin[itrack] = kmin;
324 gtracks.
kmax[itrack] = kmax + 1;
326 gtracks.
kmin[itrack] =
max(0U,
min(kmin, kmax));
327 gtracks.
kmax[itrack] =
min(nv,
max(kmin, kmax) + 1);
331 if (gtracks.
kmin[itrack] >= gtracks.
kmax[itrack]) {
332 cout <<
"set_vtx_range trk = " << itrack <<
" kmin,kmax=" << kmin <<
"," << kmax
333 <<
" gtrack.kmin,kmax = " << gtracks.
kmin[itrack] <<
"," << gtracks.
kmax[itrack] <<
" zrange = " << zrange
341 const unsigned int nt = gtracks.
getSize();
342 const unsigned int nv = gvertices.
getSize();
343 for (
auto itrack = 0U; itrack <
nt; ++itrack) {
344 gtracks.
kmin[itrack] = 0;
345 gtracks.
kmax[itrack] = nv;
350 double beta,
track_t& gtracks,
vertex_t& gvertices,
const double rho0,
const bool updateTc)
const {
355 const unsigned int nt = gtracks.
getSize();
356 const unsigned int nv = gvertices.
getSize();
361 Z_init = rho0 * local_exp(-beta * dzCutOff_ * dzCutOff_);
366 auto kernel_calc_exp_arg_range = [
beta](
const unsigned int itrack,
369 const unsigned int kmin,
370 const unsigned int kmax) {
371 const auto track_z = tracks.zpca[itrack];
373 const auto botrack_dz2 = -beta * tracks.dz2[itrack];
375 const auto botrack_dt2 = -beta * tracks.dt2[itrack];
378 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
379 const auto mult_resz = track_z - vertices.zvtx[ivertex];
380 const auto mult_rest =
track_t - vertices.tvtx[ivertex];
382 const auto botrack_dt2 =
383 -beta * tracks.
dt2[itrack] * vertices.dt2[ivertex] / (tracks.dt2[itrack] + vertices.dt2[ivertex] + 1.e-10);
385 vertices.exp_arg[ivertex] = botrack_dz2 * (mult_resz * mult_resz) + botrack_dt2 * (mult_rest * mult_rest);
389 auto kernel_add_Z_range = [Z_init](
390 vertex_t const&
vertices,
const unsigned int kmin,
const unsigned int kmax) ->
double {
391 double ZTemp = Z_init;
392 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
393 ZTemp += vertices.
rho[ivertex] * vertices.
exp[ivertex];
398 auto kernel_calc_normalization_range = [updateTc](
const unsigned int track_num,
401 const unsigned int kmin,
402 const unsigned int kmax) {
403 auto tmp_trk_tkwt = tracks.tkwt[track_num];
404 auto o_trk_sum_Z = 1. / tracks.sum_Z[track_num];
405 auto o_trk_err_z = tracks.dz2[track_num];
406 auto o_trk_err_t = tracks.dt2[track_num];
407 auto tmp_trk_z = tracks.zpca[track_num];
408 auto tmp_trk_t = tracks.tpca[track_num];
412 for (
unsigned int k = kmin;
k < kmax; ++
k) {
414 vertices.se[
k] += tmp_trk_tkwt * (vertices.exp[
k] * o_trk_sum_Z);
415 const auto w = tmp_trk_tkwt * (vertices.rho[
k] * vertices.exp[
k] * o_trk_sum_Z);
416 const auto wz = w * o_trk_err_z;
417 const auto wt = w * o_trk_err_t;
419 vertices.sumw[
k] +=
w;
421 vertices.nuz[
k] += wz;
422 vertices.nut[
k] += wt;
423 vertices.swz[
k] += wz * tmp_trk_z;
424 vertices.swt[
k] += wt * tmp_trk_t;
426 const auto dsz = (tmp_trk_z - vertices.zvtx[
k]) * o_trk_err_z;
427 const auto dst = (tmp_trk_t - vertices.tvtx[
k]) * o_trk_err_t;
428 vertices.szz[
k] += w * dsz * dsz;
429 vertices.stt[
k] += w *
dst *
dst;
430 vertices.szt[
k] += w * dsz *
dst;
434 for (
unsigned int k = kmin;
k < kmax; ++
k) {
435 vertices.se[
k] += tmp_trk_tkwt * (vertices.exp[
k] * o_trk_sum_Z);
436 const auto w = tmp_trk_tkwt * (vertices.rho[
k] * vertices.exp[
k] * o_trk_sum_Z);
437 const auto wz = w * o_trk_err_z;
438 const auto wt = w * o_trk_err_t;
440 vertices.sumw[
k] +=
w;
442 vertices.nuz[
k] += wz;
443 vertices.nut[
k] += wt;
444 vertices.swz[
k] += wz * tmp_trk_z;
445 vertices.swt[
k] += wt * tmp_trk_t;
450 for (
auto ivertex = 0U; ivertex < nv; ++ivertex) {
451 gvertices.
se[ivertex] = 0.0;
452 gvertices.
nuz[ivertex] = 0.0;
453 gvertices.
nut[ivertex] = 0.0;
454 gvertices.
swz[ivertex] = 0.0;
455 gvertices.
swt[ivertex] = 0.0;
456 gvertices.
szz[ivertex] = 0.0;
457 gvertices.
stt[ivertex] = 0.0;
458 gvertices.
szt[ivertex] = 0.0;
460 gvertices.sumw[ivertex] = 0.0;
465 for (
auto itrack = 0U; itrack <
nt; ++itrack) {
466 const unsigned int kmin = gtracks.
kmin[itrack];
467 const unsigned int kmax = gtracks.
kmax[itrack];
470 assert((kmin < kmax) && (kmax <= nv));
474 kernel_calc_exp_arg_range(itrack, gtracks, gvertices, kmin, kmax);
475 local_exp_list_range(gvertices.
exp_arg, gvertices.
exp, kmin, kmax);
476 gtracks.
sum_Z[itrack] = kernel_add_Z_range(gvertices, kmin, kmax);
479 gtracks.
sum_Z[itrack] = 0.0;
481 if (gtracks.
sum_Z[itrack] > 1.e-100) {
482 kernel_calc_normalization_range(itrack, gtracks, gvertices, kmin, kmax);
491 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
492 if (vertices.nuz[ivertex] > 0.) {
493 auto znew = vertices.swz[ivertex] / vertices.nuz[ivertex];
494 delta =
max(
std::abs(vertices.zvtx[ivertex] - znew), delta);
495 vertices.zvtx[ivertex] = znew;
498 if (vertices.nut[ivertex] > 0.) {
499 auto tnew = vertices.swt[ivertex] / vertices.nut[ivertex];
501 vertices.tvtx[ivertex] = tnew;
503 vertices.dt2[ivertex] = vertices.nut[ivertex] / vertices.sumw[ivertex];
510 vertices.tvtx[ivertex] = 0;
512 vertices.dt2[ivertex] = 0;
517 if ((vertices.nut[ivertex] <= 0.) && (vertices.nuz[ivertex] <= 0.)) {
518 edm::LogInfo(
"sumw") <<
"invalid sum of weights in fit: " << endl;
520 <<
" zk=" << vertices.zvtx[ivertex] <<
" rho=" << vertices.rho[ivertex]
521 <<
" sumw(z,t) =" << vertices.nuz[ivertex] <<
"," << vertices.nut[ivertex] << endl;
527 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
528 vertices.rho[ivertex] = vertices.rho[ivertex] * vertices.se[ivertex] * osumtkwt;
534 double delta = kernel_calc_zt(gvertices);
536 if (zorder(gvertices)) {
537 set_vtx_range(beta, gtracks, gvertices);
545 const unsigned int nv = y.
getSize();
556 bool reordering =
true;
557 bool modified =
false;
561 for (
unsigned int k = 0; (
k + 1) < nv;
k++) {
563 auto ztemp = y.
zvtx[
k];
565 y.
zvtx[
k + 1] = ztemp;
566 auto ttemp = y.
tvtx[
k];
568 y.
tvtx[
k + 1] = ttemp;
570 auto dt2temp = y.dt2[
k];
571 y.dt2[
k] = y.dt2[
k + 1];
572 y.dt2[
k + 1] = dt2temp;
574 auto ptemp = y.
rho[
k];
576 y.
rho[
k + 1] = ptemp;
580 modified |= reordering;
592 double z,
double t,
vertex_t& y,
unsigned int& k_min,
double dz,
double dt)
const {
606 for (
unsigned int k0 = 1;
k0 < nv;
k0++) {
612 double delta_min = 1.;
616 while ((k1 > 0) && ((y.
zvtx[k] - y.
zvtx[--k1]) < dz)) {
618 if (
delta < delta_min) {
626 while (((++k1) < nv) && ((y.
zvtx[k1] - y.
zvtx[k]) < dz)) {
628 if (
delta < delta_min) {
634 return (delta_min < 1.);
639 unsigned int niter = 0;
641 double delta_max = delta_lowT_;
643 if (convergence_mode_ == 0) {
644 delta_max = delta_max0;
645 }
else if (convergence_mode_ == 1) {
650 set_vtx_range(beta, tks, v);
652 double delta_sum_range = 0;
653 std::vector<double> z0 = v.
zvtx_vec;
655 while (niter++ < maxIterations_) {
656 delta =
update(beta, tks, v, rho0);
657 delta_sum_range +=
delta;
659 if (delta_sum_range > zrange_min_) {
660 for (
unsigned int k = 0;
k < v.
getSize();
k++) {
663 set_vtx_range(beta, tks, v);
671 if (delta < delta_max) {
677 if (DEBUGLEVEL > 0) {
678 std::cout <<
"DAClusterizerInZT_vect.thermalize niter = " << niter <<
" at T = " << 1 / beta
679 <<
" nv = " << v.
getSize() << std::endl;
681 dump(beta, v, tks, 0);
691 const unsigned int nv = y.
getSize();
697 unsigned int k1_min = 0, k2_min = 0;
698 double delta_min = 0;
700 for (
unsigned int k1 = 0; (k1 + 1) < nv; k1++) {
701 unsigned int k2 = k1;
702 while ((++k2 < nv) && (std::fabs(y.
zvtx[k2] - y.
zvtx[k1]) < zmerge_)) {
704 if ((
delta < delta_min) || (k1_min == k2_min)) {
712 if ((k1_min == k2_min) || (delta_min > 1)) {
716 double rho = y.
rho[k1_min] + y.
rho[k2_min];
719 assert((k1_min < nv) && (k2_min < nv));
720 if (DEBUGLEVEL > 1) {
721 std::cout <<
"merging (" << setw(8) << fixed << setprecision(4) << y.
zvtx[k1_min] <<
',' << y.
tvtx[k1_min]
722 <<
") and (" << y.
zvtx[k2_min] <<
',' << y.
tvtx[k2_min] <<
")"
723 <<
" idx=" << k1_min <<
"," << k2_min << std::endl;
728 y.
zvtx[k1_min] = (y.
rho[k1_min] * y.
zvtx[k1_min] + y.
rho[k2_min] * y.
zvtx[k2_min]) / rho;
729 y.
tvtx[k1_min] = (y.
rho[k1_min] * y.
tvtx[k1_min] + y.
rho[k2_min] * y.
tvtx[k2_min]) / rho;
731 y.dt2[k1_min] = (y.
rho[k1_min] * y.dt2[k1_min] + y.
rho[k2_min] * y.dt2[k2_min]) / rho;
734 y.
zvtx[k1_min] = 0.5 * (y.
zvtx[k1_min] + y.
zvtx[k2_min]);
735 y.
tvtx[k1_min] = 0.5 * (y.
tvtx[k1_min] + y.
tvtx[k2_min]);
741 set_vtx_range(beta, tks, y);
747 constexpr
double eps = 1.e-100;
749 const unsigned int nv = y.
getSize();
755 std::vector<double> sump_v(nv), arg_cache_v(nv), exp_cache_v(nv), pcut_cache_v(nv);
756 std::vector<int> nUnique_v(nv);
757 double* __restrict__ parg_cache;
758 double* __restrict__ pexp_cache;
759 double* __restrict__ ppcut_cache;
760 double* __restrict__ psump;
761 int* __restrict__ pnUnique;
762 int constexpr nunique_min_ = 2;
765 set_vtx_range(beta, tks, y);
767 parg_cache = arg_cache_v.data();
768 pexp_cache = exp_cache_v.data();
769 ppcut_cache = pcut_cache_v.data();
770 psump = sump_v.data();
771 pnUnique = nUnique_v.data();
773 const auto rhoconst = rho0 * local_exp(-beta * dzCutOff_ * dzCutOff_);
774 for (
unsigned int k = 0;
k < nv; ++
k) {
775 const double pmax = y.
rho[
k] / (y.
rho[
k] + rhoconst);
776 ppcut_cache[
k] = uniquetrkweight_ * pmax;
779 for (
unsigned int i = 0;
i <
nt;
i++) {
780 const auto invZ = ((tks.
sum_Z[
i] >
eps) && (tks.
tkwt[
i] > uniquetrkminp_)) ? 1. / tks.
sum_Z[
i] : 0.;
781 const auto track_z = tks.
zpca[
i];
783 const auto botrack_dz2 = -beta * tks.
dz2[
i];
784 const auto botrack_dt2 = -beta * tks.
dt2[
i];
785 const auto kmin = tks.
kmin[
i];
786 const auto kmax = tks.
kmax[
i];
788 for (
unsigned int k = kmin;
k < kmax;
k++) {
789 const auto mult_resz = track_z - y.
zvtx[
k];
791 parg_cache[
k] = botrack_dz2 * (mult_resz * mult_resz) + botrack_dt2 * (mult_rest * mult_rest);
794 local_exp_list_range(parg_cache, pexp_cache, kmin, kmax);
796 for (
unsigned int k = kmin;
k < kmax;
k++) {
797 const double p = y.
rho[
k] * pexp_cache[
k] * invZ;
799 pnUnique[
k] += (p > ppcut_cache[
k]) ? 1 : 0;
804 unsigned int k0 = nv;
805 for (
unsigned k = 0;
k < nv;
k++) {
806 if ((pnUnique[
k] < nunique_min_) && (psump[
k] < sumpmin)) {
815 if (DEBUGLEVEL > 1) {
816 std::cout <<
"eliminating prototype at " << std::setw(10) << std::setprecision(4) << y.
zvtx[
k0] <<
","
817 << y.
tvtx[
k0] <<
" with sump=" << sumpmin <<
" rho*nt =" << y.
rho[
k0] * nt << endl;
821 set_vtx_range(beta, tks, y);
832 const unsigned int nv = y.
getSize();
834 for (
unsigned int k = 0;
k < nv;
k++) {
840 for (
unsigned int i = 0;
i <
nt;
i++) {
843 sumwz += w_z * tks.
zpca[
i];
844 sumwt += w_t * tks.
tpca[
i];
848 y.
zvtx[
k] = sumwz / sumw_z;
849 y.
tvtx[
k] = sumwt / sumw_t;
852 double szz = 0, stt = 0, szt = 0;
853 double nuz = 0, nut = 0;
854 for (
unsigned int i = 0;
i <
nt;
i++) {
861 nuz += w * tks.
dz2[
i];
862 nut += w * tks.
dt2[
i];
864 double Tz = szz / nuz;
869 Tc = Tz + Tt +
sqrt(
pow(Tz - Tt, 2) + 4 * szt * szt / nuz / nut);
879 if (DEBUGLEVEL > 0) {
880 std::cout <<
"DAClusterizerInZT_vect.beta0: Tc = " << T0 << std::endl;
881 int coolingsteps = 1 - int(
std::log(T0 * betamax) /
std::log(coolingFactor_));
882 std::cout <<
"DAClusterizerInZT_vect.beta0: nstep = " << coolingsteps << std::endl;
886 if (T0 > 1. / betamax) {
887 int coolingsteps = 1 - int(
std::log(T0 * betamax) /
std::log(coolingFactor_));
888 return betamax *
std::pow(coolingFactor_, coolingsteps);
891 return betamax * coolingFactor_;
901 return Tz + Tt +
sqrt(
pow(Tz - Tt, 2) + 4 * mx);
911 constexpr
double epsilonz = 1
e-3;
912 constexpr
double epsilont = 1
e-2;
914 const double twoBeta = 2.0 *
beta;
918 std::vector<std::pair<double, unsigned int> >
critical;
919 for (
unsigned int k = 0;
k < nv;
k++) {
920 double Tc = get_Tc(y,
k);
921 if (beta * Tc > threshold) {
922 critical.push_back(make_pair(Tc,
k));
925 if (critical.empty())
928 std::stable_sort(critical.begin(), critical.end(), std::greater<std::pair<double, unsigned int> >());
933 for (
unsigned int ic = 0; ic < critical.size(); ic++) {
934 unsigned int k = critical[ic].second;
938 double Mzz = y.
nuz[
k] - twoBeta * y.
szz[
k];
939 double Mtt = y.
nut[
k] - twoBeta * y.
stt[
k];
940 double Mzt = -twoBeta * y.
szt[
k];
941 const double twoMzt = 2.0 * Mzt;
942 double D =
sqrt(
pow(Mtt - Mzz, 2) + twoMzt * twoMzt);
943 double q1 = atan2(-Mtt + Mzz + D, -twoMzt);
944 double l1 = 0.5 * (-Mzz - Mtt +
D);
945 double l2 = 0.5 * (-Mzz - Mtt -
D);
947 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, bad eigenvalues! idx=" << k <<
" z= " << y.
zvtx[
k]
948 <<
" Mzz=" << Mzz <<
" Mtt=" << Mtt <<
" Mzt=" << Mzt << endl;
952 double cq =
cos(qsplit);
953 double sq =
sin(qsplit);
960 double p1 = 0, z1 = 0, t1 = 0, wz1 = 0, wt1 = 0;
961 double p2 = 0, z2 = 0, t2 = 0, wz2 = 0, wt2 = 0;
962 for (
unsigned int i = 0;
i <
nt; ++
i) {
963 if (tks.
sum_Z[
i] > 1.e-100) {
966 double tl = lr < 0 ? 1. : 0.;
972 double t = local_exp(-arg);
980 double wz = p * tks.
dz2[
i];
981 double wt = p * tks.
dt2[
i];
983 z1 += wz * tl * tks.
zpca[
i];
984 t1 += wt * tl * tks.
tpca[
i];
988 z2 += wz * tr * tks.
zpca[
i];
989 t2 += wt * tr * tks.
tpca[
i];
998 z1 = y.
zvtx[
k] - epsilonz * cq;
999 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wz1 = " << scientific << wz1 << endl;
1004 t1 = y.
tvtx[
k] - epsilont * sq;
1005 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wt1 = " << scientific << wt1 << endl;
1010 z2 = y.
zvtx[
k] + epsilonz * cq;
1011 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wz2 = " << scientific << wz2 << endl;
1016 t2 = y.
tvtx[
k] + epsilont * sq;
1017 edm::LogWarning(
"DAClusterizerInZT_vect") <<
"warning, wt2 = " << scientific << wt2 << endl;
1020 unsigned int k_min1 =
k, k_min2 =
k;
1021 constexpr
double spliteps = 1
e-8;
1022 while (((find_nearest(z1, t1, y, k_min1, epsilonz, epsilont) && (k_min1 != k)) ||
1023 (find_nearest(z2, t2, y, k_min2, epsilonz, epsilont) && (k_min2 != k))) &&
1025 z1 = 0.5 * (z1 + y.
zvtx[
k]);
1026 t1 = 0.5 * (t1 + y.
tvtx[
k]);
1027 z2 = 0.5 * (z2 + y.
zvtx[
k]);
1028 t2 = 0.5 * (t2 + y.
tvtx[
k]);
1033 if (DEBUGLEVEL > 1) {
1034 if (std::fabs(y.
zvtx[k] - zdumpcenter_) < zdumpwidth_) {
1035 std::cout <<
" T= " << std::setw(10) << std::setprecision(1) << 1. / beta <<
" Tc= " << critical[ic].first
1036 <<
" direction =" << std::setprecision(4) << qsplit <<
" splitting (" << std::setw(8) << std::fixed
1037 << std::setprecision(4) << y.
zvtx[
k] <<
"," << y.
tvtx[
k] <<
")"
1038 <<
" --> (" << z1 <<
',' << t1 <<
"),(" << z2 <<
',' << t2 <<
") [" << p1 <<
"," << p2 <<
"]";
1039 if (std::fabs(z2 - z1) > epsilonz || std::fabs(t2 - t1) > epsilont) {
1049 edm::LogInfo(
"DAClusterizerInZT") <<
"warning swapping z in split qsplit=" << qsplit <<
" cq=" << cq
1050 <<
" sq=" << sq << endl;
1063 if (std::fabs(z2 - z1) > epsilonz || std::fabs(t2 - t1) > epsilont) {
1065 double rho1 = p1 * y.
rho[
k] / (p1 +
p2);
1066 double rho2 = p2 * y.
rho[
k] / (p1 +
p2);
1074 std::cout <<
"unexpected z-ordering in split" << std::endl;
1080 for (
unsigned int jc = ic; jc < critical.size(); jc++) {
1081 if (critical[jc].
second > k) {
1082 critical[jc].second--;
1084 if (critical[jc].
second >= k2) {
1085 critical[jc].second++;
1095 for (
unsigned int jc = ic; jc < critical.size(); jc++) {
1096 if (critical[jc].
second >= k1) {
1097 critical[jc].second++;
1102 std::cout <<
"warning ! split rejected, too small." << endl;
1125 clear_vtx_range(tks, y);
1128 double beta = beta0(betamax_, tks, y);
1131 std::cout <<
"Beta0 is " << beta << std::endl;
1134 thermalize(beta, tks, y, delta_highT_, 0.);
1138 double betafreeze = betamax_ *
sqrt(coolingFactor_);
1140 while (beta < betafreeze) {
1141 update(beta, tks, y, rho0,
true);
1142 while (
merge(y, tks, beta)) {
1144 set_vtx_range(beta, tks, y);
1145 update(beta, tks, y, rho0,
true);
1147 split(beta, tks, y);
1149 beta = beta / coolingFactor_;
1150 thermalize(beta, tks, y, delta_highT_, 0.);
1156 if (DEBUGLEVEL > 0) {
1157 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1158 <<
"merging at T=" << 1 / beta << std::endl;
1163 set_vtx_range(beta, tks, y);
1165 update(beta, tks, y, rho0,
true);
1167 while (
merge(y, tks, beta)) {
1169 set_vtx_range(beta, tks, y);
1170 update(beta, tks, y, rho0,
true);
1175 if (DEBUGLEVEL > 0) {
1176 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1177 <<
"splitting/merging at T=" << 1 / beta << std::endl;
1181 unsigned int ntry = 0;
1183 while (
split(beta, tks, y, threshold) && (ntry++ < 10)) {
1184 thermalize(beta, tks, y, delta_highT_, 0.);
1186 while (
merge(y, tks, beta)) {
1188 set_vtx_range(beta, tks, y);
1189 update(beta, tks, y, rho0,
true);
1202 if (DEBUGLEVEL > 0) {
1203 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1204 <<
"turning on outlier rejection at T=" << 1 / beta << std::endl;
1209 if (dzCutOff_ > 0) {
1211 for (
unsigned int a = 0;
a < 5;
a++) {
1212 update(beta, tks, y,
a * rho0 / 5);
1216 thermalize(beta, tks, y, delta_lowT_, rho0);
1220 if (DEBUGLEVEL > 0) {
1221 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1222 <<
"merging with outlier rejection at T=" << 1 / beta << std::endl;
1225 dump(beta, y, tks, 2);
1230 while (
merge(y, tks, beta)) {
1231 set_vtx_range(beta, tks, y);
1232 update(beta, tks, y, rho0);
1236 if (DEBUGLEVEL > 0) {
1237 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1238 <<
"after merging with outlier rejection at T=" << 1 / beta << std::endl;
1241 dump(beta, y, tks, 2);
1245 while (beta < betapurge_) {
1246 beta =
min(beta / coolingFactor_, betapurge_);
1247 thermalize(beta, tks, y, delta_lowT_, rho0);
1252 if (DEBUGLEVEL > 0) {
1253 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1254 <<
"purging at T=" << 1 / beta << std::endl;
1259 while (purge(y, tks, rho0, beta)) {
1260 thermalize(beta, tks, y, delta_lowT_, rho0);
1262 set_vtx_range(beta, tks, y);
1268 if (DEBUGLEVEL > 0) {
1269 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1270 <<
"last cooling T=" << 1 / beta << std::endl;
1275 while (beta < betastop_) {
1276 beta =
min(beta / coolingFactor_, betastop_);
1277 thermalize(beta, tks, y, delta_lowT_, rho0);
1279 set_vtx_range(beta, tks, y);
1285 if (DEBUGLEVEL > 0) {
1286 std::cout <<
"DAClusterizerInZT_vect::vertices :"
1287 <<
"stop cooling at T=" << 1 / beta << std::endl;
1290 dump(beta, y, tks, 2);
1295 double betadummy = 1;
1296 while (
merge(y, tks, betadummy))
1301 set_vtx_range(beta, tks, y);
1302 const unsigned int nv = y.
getSize();
1303 for (
unsigned int k = 0;
k < nv;
k++)
1309 const auto z_sum_init = rho0 * local_exp(-beta * dzCutOff_ * dzCutOff_);
1310 std::vector<std::vector<unsigned int> > vtx_track_indices(nv);
1311 for (
unsigned int i = 0;
i <
nt;
i++) {
1312 const auto kmin = tks.
kmin[
i];
1313 const auto kmax = tks.
kmax[
i];
1314 for (
auto k = kmin;
k < kmax;
k++) {
1318 local_exp_list_range(y.
exp_arg, y.
exp, kmin, kmax);
1320 tks.
sum_Z[
i] = z_sum_init;
1321 for (
auto k = kmin;
k < kmax;
k++) {
1324 const double invZ = tks.
sum_Z[
i] > 1
e-100 ? 1. / tks.
sum_Z[
i] : 0.0;
1326 for (
auto k = kmin;
k < kmax;
k++) {
1328 if (p > mintrkweight_) {
1330 vtx_track_indices[
k].push_back(
i);
1337 GlobalError dummyError(0.01, 0, 0.01, 0., 0., 0.01);
1338 for (
unsigned int k = 0;
k < nv;
k++) {
1339 if (!vtx_track_indices[
k].
empty()) {
1341 vector<reco::TransientTrack> vertexTracks;
1342 for (
auto i : vtx_track_indices[
k]) {
1343 vertexTracks.push_back(*(tks.
tt[
i]));
1346 clusters.push_back(v);
1354 const vector<reco::TransientTrack>&
tracks)
const {
1355 vector<vector<reco::TransientTrack> >
clusters;
1356 vector<TransientVertex>&&
pv =
vertices(tracks);
1359 if (DEBUGLEVEL > 0) {
1360 std::cout <<
"###################################################" << endl;
1361 std::cout <<
"# vectorized DAClusterizerInZT_vect::clusterize nt=" << tracks.size() << endl;
1362 std::cout <<
"# DAClusterizerInZT_vect::clusterize pv.size=" << pv.size() << endl;
1363 std::cout <<
"###################################################" << endl;
1372 for (
auto k = pv.begin();
k != pv.end();
k++) {
1373 vector<reco::TransientTrack> aCluster =
k->originalTracks();
1374 if (aCluster.size() > 1) {
1375 clusters.push_back(aCluster);
1384 const unsigned int nv = y.
getSize();
1387 std::vector<unsigned int> iz;
1388 for (
unsigned int j = 0;
j <
nt;
j++) {
1391 std::sort(iz.begin(), iz.end(), [tks](
unsigned int a,
unsigned int b) {
return tks.
zpca[
a] < tks.
zpca[
b]; });
1393 std::cout <<
"-----DAClusterizerInZT::dump ----" << nv <<
" clusters " << std::endl;
1396 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1397 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1398 std::cout << setw(8) << fixed << ivertex;
1405 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1406 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1414 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1415 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1421 std::cout <<
"T=" << setw(15) << 1. / beta <<
" Tmin =" << setw(10) << 1. / betamax_
1423 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1424 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1425 double Tc = get_Tc(y, ivertex);
1426 std::cout << setw(8) << fixed << setprecision(1) << Tc;
1433 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1434 sumrho += y.
rho[ivertex];
1435 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1437 std::cout << setw(8) << setprecision(4) << fixed << y.
rho[ivertex];
1442 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1443 sumrho += y.
rho[ivertex];
1444 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1446 std::cout << setw(8) << setprecision(1) << fixed << y.
rho[ivertex] *
nt;
1450 if (verbosity > 0) {
1451 double E = 0,
F = 0;
1453 std::cout <<
"---- z +/- dz t +/- dt ip +/-dip pt phi eta weights ----"
1456 for (
unsigned int i0 = 0; i0 <
nt; i0++) {
1457 unsigned int i = iz[i0];
1458 if (tks.
sum_Z[i] > 0) {
1461 double tz = tks.
zpca[
i];
1463 if (std::fabs(tz - zdumpcenter_) > zdumpwidth_)
1465 std::cout << setw(4) << i <<
")" << setw(8) << fixed << setprecision(4) << tz <<
" +/-" << setw(6)
1468 if (tks.
dt2[i] > 0) {
1469 std::cout << setw(8) << fixed << setprecision(4) << tks.
tpca[
i] <<
" +/-" << setw(6) <<
sqrt(1. / tks.
dt2[i]);
1488 .pixelBarrelLayersWithMeasurement();
1489 std::cout << setw(1) << tks.
tt[
i]->track().hitPattern().pixelEndcapLayersWithMeasurement();
1491 << tks.
tt[
i]->track().hitPattern().trackerLayersWithMeasurement() -
1492 tks.
tt[
i]->track().hitPattern().pixelLayersWithMeasurement()
1499 std::cout <<
" " << setw(6) << setprecision(2) << tks.
tt[
i]->track().pt() * tks.
tt[
i]->track().charge();
1500 std::cout <<
" " << setw(5) << setprecision(2) << tks.
tt[
i]->track().phi() <<
" " << setw(5) << setprecision(2)
1501 << tks.
tt[
i]->track().eta();
1504 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1505 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1508 if ((tks.
tkwt[i] > 0) && (tks.
sum_Z[i] > 0)) {
1515 if ((ivertex >= tks.
kmin[i]) && (ivertex < tks.
kmax[i])) {
1517 std::cout << setw(8) << setprecision(3) <<
p;
1526 }
else if (p > 0.0001) {
1527 std::cout <<
"X" << setw(6) << setprecision(3) << p <<
"X";
1536 std::cout <<
" ( " << std::setw(3) << tks.
kmin[
i] <<
"," << std::setw(3) << tks.
kmax[
i] - 1 <<
" ) ";
1540 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1541 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1542 std::cout <<
" " << setw(3) << ivertex <<
" ";
1548 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1549 if (std::fabs(y.
zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1555 <<
"T=" << 1 / beta <<
" E=" << E <<
" n=" << y.
getSize() <<
" F= " <<
F << endl
1556 <<
"----------" << endl;
1563 desc.
add<
double>(
"tmerge", 0.01);
1564 desc.
add<
double>(
"dtCutOff", 4.);
1565 desc.
add<
double>(
"t0Max", 1.0);
1566 desc.
add<
double>(
"vertexSizeTime", 0.008);
T getUntrackedParameter(std::string const &, T const &) const
void removeItem(unsigned int k, track_t &tks)
unsigned int thermalize(double beta, track_t >racks, vertex_t &gvertices, const double delta_max, const double rho0=0.) const
static std::vector< std::string > checklist log
double *__restrict__ tpca
std::vector< double > dt2_vec
bool zorder(vertex_t &y) const
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks) const
std::vector< double > nut_vec
std::vector< double > szz_vec
constexpr bool isNotFinite(T x)
bool split(const double beta, track_t &t, vertex_t &y, double threshold=1.) const
std::vector< unsigned int > kmin
double *__restrict__ exp_arg
Sin< T >::type sin(const T &t)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
std::vector< double > exp_vec
DAClusterizerInZT_vect(const edm::ParameterSet &conf)
auto const & tracks
cannot be loose
std::vector< double > tkwt_vec
void addItem(double new_zpca, double new_tpca, double new_dz2, double new_dt2, const reco::TransientTrack *new_tt, double new_tkwt)
void verify(const vertex_t &v, const track_t &tks, unsigned int nv=999999, unsigned int nt=999999) const
double update(double beta, track_t >racks, vertex_t &gvertices, const double rho0=0, const bool updateTc=false) const
std::vector< unsigned int > kmax
U second(std::pair< T, U > const &p)
double *__restrict__ zpca
double get_Tc(const vertex_t &y, int k) const
bool purge(vertex_t &, track_t &, double &, const double) const
std::vector< double > stt_vec
double *__restrict__ tkwt
Cos< T >::type cos(const T &t)
void addItem(double new_zvtx, double new_tvtx, double new_rho)
Abs< T >::type abs(const T &t)
bool find_nearest(double z, double t, vertex_t &y, unsigned int &k_min, double dz, double dt) const
double BeamWidthX() const
beam width X
std::vector< double > zvtx_vec
std::vector< double > sum_Z_vec
double *__restrict__ zvtx
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< double > szt_vec
for(Iditer=Id.begin();Iditer!=Id.end();Iditer++)
std::vector< double > zpca_vec
Log< level::Info, false > LogInfo
unsigned int getSize() const
void clear_vtx_range(track_t >racks, vertex_t &gvertices) const
DecomposeProduct< arg, typename Div::arg > D
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
std::vector< double > tpca_vec
static void fillPSetDescription(edm::ParameterSetDescription &desc)
T getParameter(std::string const &) const
std::vector< double > se_vec
double BeamWidthY() const
beam width Y
double *__restrict__ sum_Z
track_t fill(const std::vector< reco::TransientTrack > &tracks) const
std::vector< double > swt_vec
std::vector< const reco::TransientTrack * > tt
std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const override
std::vector< double > swz_vec
std::vector< double > dz2_vec
unsigned int getSize() const
std::vector< double > nuz_vec
double beta0(const double betamax, track_t const &tks, vertex_t const &y) const
bool merge(vertex_t &, track_t &, double &beta) const
Log< level::Warning, false > LogWarning
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
std::vector< double > tvtx_vec
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void dump(const double beta, const vertex_t &y, const track_t &tks, const int verbosity=0) const
unsigned int insertOrdered(double zvtx, double tvtx, double rho, track_t &tks)
double *__restrict__ tvtx
std::vector< double > exp_arg_vec
Power< A, B >::type pow(const A &a, const B &b)
tuple dump
OutputFilePath = cms.string('/tmp/zhokin/'), OutputFileExt = cms.string(''),.
void set_vtx_range(double beta, track_t >racks, vertex_t &gvertices) const
std::vector< double > rho_vec