11 #include "vdt/vdtMath.h" 22 maxIterations_ = 1000;
36 coolingFactor_ = conf.
getParameter<
double>(
"coolingFactor");
39 uniquetrkweight_ = conf.
getParameter<
double>(
"uniquetrkweight");
40 uniquetrkminp_ = conf.
getParameter<
double>(
"uniquetrkminp");
43 convergence_mode_ = conf.
getParameter<
int>(
"convergence_mode");
47 block_size_ = conf.
getParameter<
unsigned int>(
"block_size");
48 overlap_frac_ = conf.
getParameter<
double>(
"overlap_frac");
51 std::cout <<
"DAClusterizerinZ_vect: mintrkweight = " << mintrkweight_ << std::endl;
52 std::cout <<
"DAClusterizerinZ_vect: uniquetrkweight = " << uniquetrkweight_ << std::endl;
53 std::cout <<
"DAClusterizerInZ_vect: uniquetrkminp = " << uniquetrkminp_ << std::endl;
54 std::cout <<
"DAClusterizerinZ_vect: zmerge = " << zmerge_ << std::endl;
55 std::cout <<
"DAClusterizerinZ_vect: Tmin = " <<
Tmin << std::endl;
57 std::cout <<
"DAClusterizerinZ_vect: Tstop = " <<
Tstop << std::endl;
58 std::cout <<
"DAClusterizerinZ_vect: vertexSize = " << vertexSize_ << std::endl;
59 std::cout <<
"DAClusterizerinZ_vect: coolingFactor = " << coolingFactor_ << std::endl;
60 std::cout <<
"DAClusterizerinZ_vect: d0CutOff = " << d0CutOff_ << std::endl;
61 std::cout <<
"DAClusterizerinZ_vect: dzCutOff = " << dzCutOff_ << std::endl;
62 std::cout <<
"DAClusterizerInZ_vect: zrange = " << sel_zrange_ << std::endl;
63 std::cout <<
"DAClusterizerinZ_vect: convergence mode = " << convergence_mode_ << std::endl;
64 std::cout <<
"DAClusterizerinZ_vect: delta_highT = " << delta_highT_ << std::endl;
65 std::cout <<
"DAClusterizerinZ_vect: delta_lowT = " << delta_lowT_ << std::endl;
67 std::cout <<
"DAClusterizerinZ_vect: run in blocks = " << runInBlocks_ << std::endl;
68 std::cout <<
"DAClusterizerinZ_vect: block_size = " << block_size_ << std::endl;
69 std::cout <<
"DAClusterizerinZ_vect: overlap_fraction = " << overlap_frac_ << std::endl;
70 std::cout <<
"DAClusterizerinZ_vect: DEBUGLEVEL " << DEBUGLEVEL << std::endl;
73 if (convergence_mode_ > 1) {
75 <<
"DAClusterizerInZ_vect: invalid convergence_mode " << convergence_mode_ <<
" reset to default " << 0;
76 convergence_mode_ = 0;
82 <<
"DAClusterizerInZ_vect: invalid Tmin " <<
Tmin <<
" reset to default " << 1. / betamax_;
89 <<
"DAClusterizerInZ_vect: invalid Tpurge " <<
Tpurge <<
" set to " <<
Tmin;
96 <<
"DAClusterizerInZ_vect: invalid Tstop " <<
Tstop <<
" set to " <<
max(1.,
Tpurge);
99 betastop_ = 1. /
Tstop;
103 inline double local_exp(
double const& inp) {
return vdt::fast_exp(inp); }
105 inline void local_exp_list_range(
double const* __restrict__ arg_inp,
106 double* __restrict__ arg_out,
109 for (
auto i = kmin;
i != kmax; ++
i)
110 arg_out[
i] = vdt::fast_exp(arg_inp[
i]);
116 if (!(nv == 999999)) {
122 if (!(
nt == 999999)) {
128 assert(
v.zvtx_vec.size() == nv);
129 assert(
v.rho_vec.size() == nv);
130 assert(
v.swz_vec.size() == nv);
131 assert(
v.exp_arg_vec.size() == nv);
132 assert(
v.exp_vec.size() == nv);
134 assert(
v.swz_vec.size() == nv);
135 assert(
v.swE_vec.size() == nv);
137 assert(
v.zvtx == &
v.zvtx_vec.front());
138 assert(
v.rho == &
v.rho_vec.front());
139 assert(
v.exp_arg == &
v.exp_arg_vec.front());
141 assert(
v.swz == &
v.swz_vec.front());
143 assert(
v.swE == &
v.swE_vec.front());
145 for (
unsigned int k = 0;
k < nv - 1;
k++) {
146 if (
v.zvtx_vec[
k] <=
v.zvtx_vec[
k + 1])
148 cout <<
" Z, cluster z-ordering assertion failure z[" <<
k <<
"] =" <<
v.zvtx_vec[
k] <<
" z[" <<
k + 1
149 <<
"] =" <<
v.zvtx_vec[
k + 1] << endl;
165 for (
unsigned int i = 0;
i <
nt;
i++) {
168 cout <<
"track vertex range assertion failure" <<
i <<
"/" <<
nt <<
" kmin,kmax=" << tks.
kmin[
i] <<
", " 169 << tks.
kmax[
i] <<
" nv=" << nv << endl;
172 for (
unsigned int i = 0;
i <
nt;
i++) {
182 if (!(*it).isValid())
185 double t_z = ((*it).stateAtBeamLine().trackStateAtPCA()).
position().z();
186 if (std::fabs(
t_z) > 1000.)
188 auto const& t_mom = (*it).stateAtBeamLine().trackStateAtPCA().momentum();
191 double t_dz2 =
std::pow((*it).track().dzError(), 2)
203 edm::LogWarning(
"DAClusterizerinZ_vect") <<
"rejected track t_tkwt " << t_tkwt;
219 if (DEBUGLEVEL > 0) {
227 inline double Eik(
double t_z,
double k_z,
double t_dz2) {
return std::pow(
t_z - k_z, 2) * t_dz2; }
231 const unsigned int nv = gvertices.
getSize();
232 const unsigned int nt = gtracks.
getSize();
235 edm::LogWarning(
"DAClusterizerinZ_vect") <<
"empty cluster list in set_vtx_range";
239 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
243 unsigned int kmin =
min(nv - 1, gtracks.
kmin[itrack]);
246 while ((kmin > 0) && (gvertices.
zvtx[kmin - 1] >
zmin)) {
250 while ((kmin < (nv - 1)) && (gvertices.
zvtx[kmin] <
zmin)) {
256 unsigned int kmax =
min(nv - 1, gtracks.
kmax[itrack] - 1);
260 while ((kmax < (nv - 1)) && (gvertices.
zvtx[kmax + 1] <
zmax)) {
264 while ((kmax > 0) && (gvertices.
zvtx[kmax] >
zmax)) {
270 gtracks.
kmin[itrack] = kmin;
271 gtracks.
kmax[itrack] = kmax + 1;
274 gtracks.
kmax[itrack] =
min(nv,
max(kmin, kmax) + 1);
280 const unsigned int nt = gtracks.
getSize();
281 const unsigned int nv = gvertices.
getSize();
282 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
283 gtracks.
kmin[itrack] = 0;
284 gtracks.
kmax[itrack] = nv;
289 double beta,
track_t& gtracks,
vertex_t& gvertices,
const double rho0,
const bool updateTc)
const {
294 const unsigned int nt = gtracks.
getSize();
295 const unsigned int nv = gvertices.
getSize();
300 Z_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
304 auto kernel_calc_exp_arg_range = [
beta](
const unsigned int itrack,
307 const unsigned int kmin,
308 const unsigned int kmax) {
309 const double track_z =
tracks.zpca[itrack];
310 const double botrack_dz2 = -
beta *
tracks.dz2[itrack];
313 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
314 auto mult_res = track_z -
vertices.zvtx[ivertex];
315 vertices.exp_arg[ivertex] = botrack_dz2 * (mult_res * mult_res);
319 auto kernel_add_Z_range = [Z_init](
320 vertex_t const&
vertices,
const unsigned int kmin,
const unsigned int kmax) ->
double {
321 double ZTemp = Z_init;
322 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
328 auto kernel_calc_normalization_range = [updateTc](
const unsigned int track_num,
331 const unsigned int kmin,
332 const unsigned int kmax) {
333 auto o_trk_sum_Z =
tracks.tkwt[track_num] /
tracks.sum_Z[track_num];
334 auto o_trk_dz2 =
tracks.dz2[track_num];
335 auto tmp_trk_z =
tracks.zpca[track_num];
340 for (
unsigned int k = kmin;
k < kmax; ++
k) {
350 for (
unsigned int k = kmin;
k < kmax; ++
k) {
360 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
361 gvertices.
se[ivertex] = 0.0;
362 gvertices.
sw[ivertex] = 0.0;
363 gvertices.
swz[ivertex] = 0.0;
364 gvertices.
swE[ivertex] = 0.0;
367 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
368 gvertices.
se[ivertex] = 0.0;
369 gvertices.
sw[ivertex] = 0.0;
370 gvertices.
swz[ivertex] = 0.0;
375 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
376 const unsigned int kmin = gtracks.
kmin[itrack];
377 const unsigned int kmax = gtracks.
kmax[itrack];
379 kernel_calc_exp_arg_range(itrack, gtracks, gvertices, kmin, kmax);
380 local_exp_list_range(gvertices.
exp_arg, gvertices.
exp, kmin, kmax);
381 gtracks.
sum_Z[itrack] = kernel_add_Z_range(gvertices, kmin, kmax);
384 gtracks.
sum_Z[itrack] = 0.0;
386 if (gtracks.
sum_Z[itrack] > 1.e-100) {
387 kernel_calc_normalization_range(itrack, gtracks, gvertices, kmin, kmax);
393 auto obeta = -1. /
beta;
394 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
395 gvertices.
swE[ivertex] *= obeta;
403 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
412 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex)
418 double delta = kernel_calc_z(gvertices);
426 unsigned int niter = 0;
428 double delta_max = delta_lowT_;
430 if (convergence_mode_ == 0) {
431 delta_max = delta_max0;
432 }
else if (convergence_mode_ == 1) {
436 set_vtx_range(
beta, tks,
v);
437 double delta_sum_range = 0;
438 std::vector<double> z0 =
v.zvtx_vec;
440 while (niter++ < maxIterations_) {
442 delta_sum_range +=
delta;
444 if (delta_sum_range > zrange_min_) {
445 for (
unsigned int k = 0;
k <
v.getSize();
k++) {
446 if (
std::abs(
v.zvtx_vec[
k] - z0[
k]) > zrange_min_) {
447 set_vtx_range(
beta, tks,
v);
455 if (
delta < delta_max) {
461 if (DEBUGLEVEL > 0) {
462 std::cout <<
"DAClusterizerInZ_vect.thermalize niter = " << niter <<
" at T = " << 1 /
beta 463 <<
" nv = " <<
v.getSize() << std::endl;
476 const unsigned int nv = y.getSize();
482 std::vector<std::pair<double, unsigned int>>
critical;
483 for (
unsigned int k = 0; (
k + 1) < nv;
k++) {
484 if (std::fabs(y.zvtx[
k + 1] - y.zvtx[
k]) < zmerge_) {
485 critical.push_back(make_pair(std::fabs(y.zvtx[
k + 1] - y.zvtx[
k]),
k));
491 std::stable_sort(
critical.begin(),
critical.end(), std::less<std::pair<double, unsigned int>>());
493 for (
unsigned int ik = 0; ik <
critical.size(); ik++) {
495 double rho = y.rho[
k] + y.rho[
k + 1];
499 if (DEBUGLEVEL > 1) {
500 std::cout <<
"merging " <<
fixed << setprecision(4) << y.zvtx[
k + 1] <<
" and " << y.zvtx[
k]
501 <<
" sw = " << y.sw[
k] + y.sw[
k + 1] << std::endl;
506 y.zvtx[
k] = (y.rho[
k] * y.zvtx[
k] + y.rho[
k + 1] * y.zvtx[
k + 1]) / rho;
508 y.zvtx[
k] = 0.5 * (y.zvtx[
k] + y.zvtx[
k + 1]);
510 y.zvtx[
k] = 0.5 * (y.zvtx[
k] + y.zvtx[
k + 1]);
513 y.sw[
k] += y.sw[
k + 1];
514 y.removeItem(
k + 1, tks);
515 set_vtx_range(
beta, tks, y);
526 const unsigned int nv = y.getSize();
532 std::vector<double> sump_v(nv), arg_cache_v(nv), exp_cache_v(nv), pcut_cache_v(nv);
533 std::vector<int> nUnique_v(nv);
534 double* __restrict__ parg_cache;
535 double* __restrict__ pexp_cache;
536 double* __restrict__ ppcut_cache;
537 double* __restrict__ psump;
538 int* __restrict__ pnUnique;
541 set_vtx_range(
beta, tks, y);
543 parg_cache = arg_cache_v.data();
544 pexp_cache = exp_cache_v.data();
545 ppcut_cache = pcut_cache_v.data();
546 psump = sump_v.data();
547 pnUnique = nUnique_v.data();
549 const auto rhoconst = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
550 for (
unsigned int k = 0;
k < nv;
k++) {
551 const double pmax = y.rho[
k] / (y.rho[
k] + rhoconst);
552 ppcut_cache[
k] = uniquetrkweight_ * pmax;
555 for (
unsigned int i = 0;
i <
nt;
i++) {
556 const auto invZ = ((tks.
sum_Z[
i] >
eps) && (tks.
tkwt[
i] > uniquetrkminp_)) ? 1. / tks.
sum_Z[
i] : 0.;
557 const auto track_z = tks.
zpca[
i];
558 const auto botrack_dz2 = -
beta * tks.
dz2[
i];
559 const auto kmin = tks.
kmin[
i];
560 const auto kmax = tks.
kmax[
i];
562 for (
unsigned int k = kmin;
k < kmax;
k++) {
563 const auto mult_resz = track_z - y.zvtx[
k];
564 parg_cache[
k] = botrack_dz2 * (mult_resz * mult_resz);
567 local_exp_list_range(parg_cache, pexp_cache, kmin, kmax);
569 for (
unsigned int k = kmin;
k < kmax;
k++) {
570 const double p = y.rho[
k] * pexp_cache[
k] * invZ;
572 pnUnique[
k] += (
p > ppcut_cache[
k]) ? 1 : 0;
577 unsigned int k0 = nv;
578 for (
unsigned k = 0;
k < nv;
k++) {
579 if ((pnUnique[
k] < nunique_min_) && (psump[
k] < sumpmin)) {
588 if (DEBUGLEVEL > 1) {
589 std::cout <<
"eliminating prototype at " << std::setw(10) << std::setprecision(4) << y.zvtx[
k0]
590 <<
" with sump=" << sumpmin <<
" rho*nt =" << y.rho[
k0] *
nt <<
" pnUnique=" << pnUnique[
k0] << endl;
594 y.removeItem(
k0, tks);
595 set_vtx_range(
beta, tks, y);
606 const unsigned int nv = y.getSize();
608 for (
unsigned int k = 0;
k < nv;
k++) {
612 for (
unsigned int i = 0;
i <
nt;
i++) {
618 y.zvtx[
k] = sumwz / sumw;
622 for (
unsigned int i = 0;
i <
nt;
i++) {
623 double dx = tks.
zpca[
i] - y.zvtx[
k];
628 double Tc = 2. *
a /
b;
636 if (DEBUGLEVEL > 0) {
637 std::cout <<
"DAClusterizerInZ_vect.beta0: Tc = " << T0 << std::endl;
639 std::cout <<
"DAClusterizerInZ_vect.beta0: nstep = " << coolingsteps << std::endl;
643 if (T0 > 1. / betamax) {
646 return betamax *
std::pow(coolingFactor_, coolingsteps);
649 return betamax * coolingFactor_;
661 unsigned int nv = y.getSize();
665 std::vector<std::pair<double, unsigned int>>
critical;
666 for (
unsigned int k = 0;
k < nv;
k++) {
667 double Tc = 2 * y.swE[
k] / y.sw[
k];
675 std::stable_sort(
critical.begin(),
critical.end(), std::greater<std::pair<double, unsigned int>>());
680 for (
unsigned int ic = 0; ic <
critical.size(); ic++) {
684 double p1 = 0, z1 = 0, w1 = 0;
685 double p2 = 0,
z2 = 0,
w2 = 0;
686 for (
unsigned int i = 0;
i <
nt;
i++) {
687 if (tks.
sum_Z[
i] > 1.e-100) {
689 double tl = tks.
zpca[
i] < y.zvtx[
k] ? 1. : 0.;
694 if (std::fabs(
arg) < 20) {
695 double t = local_exp(-
arg);
701 double w =
p * tks.
dz2[
i];
703 z1 +=
w * tl * tks.
zpca[
i];
723 if ((
k > 0) && (z1 < (0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k - 1]))) {
724 z1 = 0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k - 1];
726 if ((
k + 1 < nv) && (
z2 > (0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k + 1]))) {
727 z2 = 0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k + 1];
732 if (DEBUGLEVEL > 1) {
733 if (std::fabs(y.zvtx[
k] - zdumpcenter_) < zdumpwidth_) {
735 <<
std::fixed << std::setprecision(4) << y.zvtx[
k] <<
" --> " << z1 <<
"," <<
z2 <<
" [" <<
p1 749 double pk1 =
p1 * y.rho[
k] / (
p1 +
p2);
750 double pk2 =
p2 * y.rho[
k] / (
p1 +
p2);
757 y.insertItem(
k, z1, pk1, tks);
764 for (
unsigned int jc = ic; jc <
critical.size(); jc++) {
771 std::cout <<
"warning ! split rejected, too small." << endl;
792 clear_vtx_range(tks, y);
795 double beta = beta0(betamax_, tks, y);
801 thermalize(
beta, tks, y, delta_highT_);
805 double betafreeze = betamax_ *
sqrt(coolingFactor_);
807 while (
beta < betafreeze) {
814 thermalize(
beta, tks, y, delta_highT_);
820 if (DEBUGLEVEL > 0) {
821 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 822 <<
"last round of splitting" << std::endl;
826 set_vtx_range(
beta, tks, y);
830 set_vtx_range(
beta, tks, y);
834 unsigned int ntry = 0;
837 thermalize(
beta, tks, y, delta_highT_, rho0);
848 if (DEBUGLEVEL > 0) {
849 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 850 <<
"turning on outlier rejection at T=" << 1 /
beta << std::endl;
856 rho0 = y.getSize() > 1 ? 1. / y.getSize() : 1.;
857 for (
unsigned int a = 0;
a < 5;
a++) {
862 thermalize(
beta, tks, y, delta_lowT_, rho0);
866 if (DEBUGLEVEL > 0) {
867 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 868 <<
"merging with outlier rejection at T=" << 1 /
beta << std::endl;
876 set_vtx_range(
beta, tks, y);
882 if (DEBUGLEVEL > 0) {
883 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 884 <<
"after merging with outlier rejection at T=" << 1 /
beta << std::endl;
891 while (
beta < betapurge_) {
893 thermalize(
beta, tks, y, delta_lowT_, rho0);
898 if (DEBUGLEVEL > 0) {
899 std::cout <<
"DAClusterizerInZ_vect::vertices :" 900 <<
"purging at T=" << 1 /
beta << std::endl;
905 while (purge(y, tks, rho0,
beta)) {
906 thermalize(
beta, tks, y, delta_lowT_, rho0);
911 if (DEBUGLEVEL > 0) {
912 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 913 <<
"last cooling T=" << 1 /
beta << std::endl;
918 while (
beta < betastop_) {
920 thermalize(
beta, tks, y, delta_lowT_, rho0);
925 if (DEBUGLEVEL > 0) {
926 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 927 <<
"stop cooling at T=" << 1 /
beta << std::endl;
934 return fill_vertices(
beta, rho0, tks, y);
938 vector<reco::TransientTrack> sorted_tracks;
939 vector<pair<float, float>> vertices_tot;
940 for (
unsigned int i = 0;
i <
tracks.size();
i++) {
941 sorted_tracks.push_back(
tracks[
i]);
947 return (
a.stateAtBeamLine().trackStateAtPCA()).
position().z() <
948 (
b.stateAtBeamLine().trackStateAtPCA()).
position().z();
951 unsigned int nBlocks = (
unsigned int)std::floor(sorted_tracks.size() / (block_size_ * (1 - overlap_frac_)));
955 <<
"Warning nBlocks was 0 with ntracks = " << sorted_tracks.size() <<
" block_size = " << block_size_
956 <<
" and overlap fraction = " << overlap_frac_ <<
". Setting nBlocks = 1";
959 vector<reco::TransientTrack> block_tracks;
960 unsigned int begin = (
unsigned int)(
block * block_size_ * (1 - overlap_frac_));
961 unsigned int end = (
unsigned int)
std::min(begin + block_size_, (
unsigned int)sorted_tracks.size());
962 for (
unsigned int i = begin;
i < end;
i++) {
963 block_tracks.push_back(sorted_tracks[
i]);
965 if (block_tracks.empty()) {
970 std::cout <<
"Running vertices_in_blocks on" << std::endl;
971 std::cout <<
"- block no." <<
block <<
" on " << nBlocks <<
" blocks " << std::endl;
972 std::cout <<
"- block track size: " << sorted_tracks.size() <<
" - block size: " << block_size_ << std::endl;
983 clear_vtx_range(tks, y);
986 beta = beta0(betamax_, tks, y);
992 thermalize(
beta, tks, y, delta_highT_);
996 double betafreeze = betamax_ *
sqrt(coolingFactor_);
997 while (
beta < betafreeze) {
1004 thermalize(
beta, tks, y, delta_highT_);
1010 if (DEBUGLEVEL > 0) {
1011 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1012 <<
"last round of splitting" << std::endl;
1016 set_vtx_range(
beta, tks, y);
1020 set_vtx_range(
beta, tks, y);
1024 unsigned int ntry = 0;
1027 thermalize(
beta, tks, y, delta_highT_, rho0);
1038 if (DEBUGLEVEL > 0) {
1039 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1040 <<
"turning on outlier rejection at T=" << 1 /
beta << std::endl;
1045 if (dzCutOff_ > 0) {
1046 rho0 = y.getSize() > 1 ? 1. / y.getSize() : 1.;
1047 for (
unsigned int a = 0;
a < 5;
a++) {
1052 thermalize(
beta, tks, y, delta_lowT_, rho0);
1056 if (DEBUGLEVEL > 0) {
1057 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1058 <<
"merging with outlier rejection at T=" << 1 /
beta << std::endl;
1066 set_vtx_range(
beta, tks, y);
1072 if (DEBUGLEVEL > 0) {
1073 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1074 <<
"after merging with outlier rejection at T=" << 1 /
beta << std::endl;
1081 while (
beta < betapurge_) {
1083 thermalize(
beta, tks, y, delta_lowT_, rho0);
1088 if (DEBUGLEVEL > 0) {
1089 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1090 <<
"purging at T=" << 1 /
beta << std::endl;
1095 while (purge(y, tks, rho0,
beta)) {
1096 thermalize(
beta, tks, y, delta_lowT_, rho0);
1101 if (DEBUGLEVEL > 0) {
1102 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1103 <<
"last cooling T=" << 1 /
beta << std::endl;
1108 while (
beta < betastop_) {
1110 thermalize(
beta, tks, y, delta_lowT_, rho0);
1115 if (DEBUGLEVEL > 0) {
1116 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1117 <<
"stop cooling at T=" << 1 /
beta << std::endl;
1123 for (
unsigned int ivertex = 0; ivertex < y.getSize(); ivertex++) {
1124 if (y.zvtx_vec[ivertex] != 0 && y.rho_vec[ivertex] != 0) {
1125 vertices_tot.push_back(pair(y.zvtx_vec[ivertex], y.rho_vec[ivertex]));
1127 std::cout <<
"Found new vertex " << y.zvtx_vec[ivertex] <<
" , " << y.rho_vec[ivertex] << std::endl;
1135 [](
const pair<float, float>&
a,
const pair<float, float>&
b) ->
bool {
return a.first <
b.first; });
1139 const unsigned int nv = vertices_tot.size();
1140 const unsigned int nt = tracks_tot.getSize();
1142 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
1143 double zrange =
max(sel_zrange_ /
sqrt(
beta * tracks_tot.dz2[itrack]), zrange_min_);
1145 double zmin = tracks_tot.zpca[itrack] -
zrange;
1146 unsigned int kmin =
min(nv - 1, tracks_tot.kmin[itrack]);
1149 while ((kmin > 0) && (vertices_tot[kmin - 1].
first >
zmin)) {
1153 while ((kmin < (nv - 1)) && (vertices_tot[kmin].
first <
zmin)) {
1158 double zmax = tracks_tot.zpca[itrack] +
zrange;
1159 unsigned int kmax =
min(nv - 1, tracks_tot.kmax[itrack] - 1);
1163 while ((kmax < (nv - 1)) && (vertices_tot[kmax + 1].
first <
zmax)) {
1167 while ((kmax > 0) && (vertices_tot[kmax].
first >
zmax)) {
1173 tracks_tot.kmin[itrack] = kmin;
1174 tracks_tot.kmax[itrack] = kmax + 1;
1176 tracks_tot.kmin[itrack] =
max(0
U,
min(kmin, kmax));
1177 tracks_tot.kmax[itrack] =
min(nv,
max(kmin, kmax) + 1);
1181 rho0 = nv > 1 ? 1. / nv : 1.;
1182 const auto z_sum_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
1184 std::vector<std::vector<unsigned int>> vtx_track_indices(nv);
1185 for (
unsigned int i = 0;
i <
nt;
i++) {
1186 const auto kmin = tracks_tot.kmin[
i];
1187 const auto kmax = tracks_tot.kmax[
i];
1189 unsigned int iMax = 10000;
1190 float sum_Z = z_sum_init;
1191 for (
auto k = kmin;
k < kmax;
k++) {
1192 float v_exp = local_exp(-
beta * Eik(tracks_tot.zpca[
i], vertices_tot[
k].first, tracks_tot.dz2[
i]));
1193 sum_Z += vertices_tot[
k].second * v_exp;
1195 double invZ = sum_Z > 1
e-100 ? 1. / sum_Z : 0.0;
1196 for (
auto k = kmin;
k < kmax && invZ != 0.0;
k++) {
1197 float v_exp = local_exp(-
beta * Eik(tracks_tot.zpca[
i], vertices_tot[
k].first, tracks_tot.dz2[
i]));
1198 double p = vertices_tot[
k].second * v_exp * invZ;
1199 if (
p > p_max &&
p > mintrkweight_) {
1204 if (iMax < vtx_track_indices.size()) {
1205 vtx_track_indices[iMax].push_back(
i);
1209 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
1210 std::cout <<
"itrack " << itrack <<
" , " << tracks_tot.kmin[itrack] <<
" , " << tracks_tot.kmax[itrack]
1220 GlobalError dummyError(0.01, 0, 0.01, 0., 0., 0.01);
1221 vector<reco::TransientTrack> vertexTracks;
1223 for (
unsigned int k = 0;
k < nv;
k++) {
1224 if (!vtx_track_indices[
k].
empty()) {
1225 for (
auto i : vtx_track_indices[
k]) {
1226 vertexTracks.push_back(*(tracks_tot.tt[
i]));
1229 << (*(tracks_tot.tt[
i])).stateAtBeamLine().trackStateAtPCA().position().z() << std::endl;
1235 if ((
k + 1 == nv) || (
abs(vertices_tot[
k + 1].
first - vertices_tot[
k].
first) > (2 * vertexSize_))) {
1237 if (vertexTracks.size() > 1) {
1242 vertexTracks.clear();
1252 set_vtx_range(
beta, tks, y);
1253 const unsigned int nv = y.getSize();
1254 for (
unsigned int k = 0;
k < nv;
k++) {
1263 const auto z_sum_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
1264 std::vector<std::vector<unsigned int>> vtx_track_indices(nv);
1265 std::vector<std::vector<float>> vtx_track_weights(nv);
1266 for (
unsigned int i = 0;
i <
nt;
i++) {
1267 const auto kmin = tks.
kmin[
i];
1268 const auto kmax = tks.
kmax[
i];
1269 for (
auto k = kmin;
k < kmax;
k++) {
1273 local_exp_list_range(y.exp_arg, y.exp, kmin, kmax);
1275 tks.
sum_Z[
i] = z_sum_init;
1276 for (
auto k = kmin;
k < kmax;
k++) {
1277 tks.
sum_Z[
i] += y.rho[
k] * y.exp[
k];
1279 const double invZ = tks.
sum_Z[
i] > 1
e-100 ? 1. / tks.
sum_Z[
i] : 0.0;
1282 unsigned int k_pmax = 0;
1283 for (
auto k = kmin;
k < kmax;
k++) {
1284 double p = y.rho[
k] * y.exp[
k] * invZ;
1291 if (pmax > mintrkweight_) {
1293 vtx_track_indices[k_pmax].push_back(
i);
1294 vtx_track_weights[k_pmax].push_back(pmax);
1301 for (
unsigned int k = 0;
k < nv;
k++) {
1304 double sumwp = 0, sumwz = 0;
1305 if (!vtx_track_indices[
k].
empty()) {
1306 vector<reco::TransientTrack> vertexTracks;
1309 for (
auto i : vtx_track_indices[
k]) {
1310 auto p = vtx_track_weights[
k][
j];
1311 vertexTracks.push_back(*(tks.
tt[
i]));
1312 trkWeightMap[vertexTracks[
j]] =
p;
1317 sumwz +=
w * tks.
zpca[
i];
1320 float zerror_squared = 1.;
1321 if ((sumw > 0) && (sumwp > 0)) {
1322 zerror_squared = sumwp / (sumw * sumw);
1323 y.zvtx[
k] = sumwz / sumw;
1328 const float xerror_squared =
pow(
bs.BeamWidthX(), 2);
1329 const float yerror_squared =
pow(
bs.BeamWidthY(), 2);
1330 GlobalError err(xerror_squared, 0, yerror_squared, 0., 0., zerror_squared);
1332 v.weightMap(trkWeightMap);
1341 if (runInBlocks_ and (block_size_ <
tracks.size()))
1342 return vertices_in_blocks(
tracks);
1344 return vertices_no_blocks(
tracks);
1348 const vector<reco::TransientTrack>&
tracks)
const {
1349 vector<vector<reco::TransientTrack>>
clusters;
1353 if (DEBUGLEVEL > 0) {
1354 std::cout <<
"###################################################" << endl;
1355 std::cout <<
"# vectorized DAClusterizerInZ_vect::clusterize nt=" <<
tracks.size() << endl;
1356 std::cout <<
"# DAClusterizerInZ_vect::clusterize pv.size=" <<
pv.size() << endl;
1357 std::cout <<
"###################################################" << endl;
1366 vector<reco::TransientTrack> aCluster =
pv.begin()->originalTracks();
1368 for (
auto k =
pv.begin() + 1;
k !=
pv.end();
k++) {
1371 if (aCluster.size() > 1) {
1376 std::cout <<
" one track cluster at " <<
k->position().z() <<
" suppressed" << std::endl;
1381 for (
unsigned int i = 0;
i <
k->originalTracks().size();
i++) {
1382 aCluster.push_back(
k->originalTracks()[
i]);
1393 const unsigned int nv = y.getSize();
1398 update(
beta, tks_local, y_local, rho0,
true);
1400 std::vector<unsigned int> iz;
1401 for (
unsigned int j = 0;
j <
nt;
j++) {
1404 std::sort(iz.begin(), iz.end(), [tks](
unsigned int a,
unsigned int b) {
return tks.
zpca[
a] < tks.
zpca[
b]; });
1406 std::cout <<
"-----DAClusterizerInZ::dump ----" << nv <<
" clusters " << std::endl;
1408 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1409 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1410 std::cout <<
" " << setw(3) << ivertex <<
" ";
1416 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1417 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1422 <<
"T=" << setw(15) << 1. /
beta <<
" Tmin =" << setw(10) << 1. / betamax_
1424 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1425 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1426 double Tc = 2 * y_local.
swE[ivertex] / y_local.
sw[ivertex];
1434 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1435 sumpk += y.rho[ivertex];
1436 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1438 std::cout << setw(8) << setprecision(4) <<
fixed << y.rho[ivertex];
1443 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1444 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1451 double E = 0,
F = 0;
1453 std::cout <<
"---- z +/- dz ip +/-dip pt phi eta weights ----" << endl;
1455 for (
unsigned int i0 = 0; i0 <
nt; i0++) {
1456 unsigned int i = iz[i0];
1460 double tz = tks.
zpca[
i];
1462 if (std::fabs(tz - zdumpcenter_) > zdumpwidth_)
1464 std::cout << setw(4) <<
i <<
")" << setw(8) <<
fixed << setprecision(4) << tz <<
" +/-" << setw(6)
1466 if ((tks.
tt[
i] ==
nullptr)) {
1483 .pixelBarrelLayersWithMeasurement();
1484 std::cout << setw(1) << tks.
tt[
i]->track().hitPattern().pixelEndcapLayersWithMeasurement();
1486 << tks.
tt[
i]->track().hitPattern().trackerLayersWithMeasurement() -
1487 tks.
tt[
i]->track().hitPattern().pixelLayersWithMeasurement()
1493 std::cout << setw(8) <<
IP.value() <<
"+/-" << setw(6) <<
IP.error();
1494 std::cout <<
" " << setw(6) << setprecision(2) << tks.
tt[
i]->track().pt() * tks.
tt[
i]->track().charge();
1495 std::cout <<
" " << setw(5) << setprecision(2) << tks.
tt[
i]->track().phi() <<
" " << setw(5) << setprecision(2)
1496 << tks.
tt[
i]->track().eta();
1500 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1501 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1506 double p = y.rho[ivertex] * local_exp(-
beta * Eik(tks.
zpca[
i], y.zvtx[ivertex], tks.
dz2[
i])) / tks.
sum_Z[
i];
1508 std::cout << setw(8) << setprecision(3) <<
p;
1512 E +=
p * Eik(tks.
zpca[
i], y.zvtx[ivertex], tks.
dz2[
i]);
1518 std::cout <<
" ( " << std::setw(3) << tks.
kmin[
i] <<
"," << std::setw(3) << tks.
kmax[
i] - 1 <<
" ) ";
1522 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1523 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1524 std::cout <<
" " << setw(3) << ivertex <<
" ";
1530 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1531 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1537 <<
"T=" << 1 /
beta <<
" E=" << E <<
" n=" << y.getSize() <<
" F= " <<
F << endl
1538 <<
"----------" << endl;
1544 desc.addUntracked<
double>(
"zdumpcenter", 0.);
1545 desc.addUntracked<
double>(
"zdumpwidth", 20.);
1546 desc.add<
double>(
"d0CutOff", 3.0);
1547 desc.add<
double>(
"Tmin", 2.0);
1548 desc.add<
double>(
"delta_lowT", 0.001);
1549 desc.add<
double>(
"zmerge", 0.01);
1550 desc.add<
double>(
"dzCutOff", 3.0);
1551 desc.add<
double>(
"Tpurge", 2.0);
1552 desc.add<
int>(
"convergence_mode", 0);
1553 desc.add<
double>(
"delta_highT", 0.01);
1554 desc.add<
double>(
"Tstop", 0.5);
1555 desc.add<
double>(
"coolingFactor", 0.6);
1556 desc.add<
double>(
"vertexSize", 0.006);
1557 desc.add<
double>(
"uniquetrkweight", 0.8);
1558 desc.add<
double>(
"uniquetrkminp", 0.0);
1559 desc.add<
double>(
"zrange", 4.0);
1560 desc.add<
bool>(
"runInBlocks",
false);
1561 desc.add<
unsigned int>(
"block_size", 10000);
1562 desc.add<
double>(
"overlap_frac", 0.0);
double beta0(const double betamax, track_t const &tks, vertex_t const &y) const
void addItemSorted(double new_zpca, double new_dz2, const reco::TransientTrack *new_tt, double new_tkwt)
T getParameter(std::string const &) const
bool merge(vertex_t &y, track_t &tks, double &beta) const
common ppss p3p6s2 common epss epspn46 common const1 w2
void clear_vtx_range(track_t >racks, vertex_t &gvertices) const
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)
bool purge(vertex_t &, track_t &, double &, const double) const
double *__restrict__ sum_Z
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
static void fillPSetDescription(edm::ParameterSetDescription &desc)
double *__restrict__ tkwt
std::vector< const reco::TransientTrack * > tt
std::vector< double > dz2_vec
constexpr bool isFinite(T x)
std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const override
std::vector< double > tkwt_vec
T getUntrackedParameter(std::string const &, T const &) const
U second(std::pair< T, U > const &p)
std::vector< TransientVertex > fill_vertices(double beta, double rho0, track_t &tracks, vertex_t &vertices) const
std::vector< unsigned int > kmin
double *__restrict__ zpca
double update(double beta, track_t >racks, vertex_t &gvertices, const double rho0=0, const bool updateTc=false) const
std::vector< unsigned int > kmax
double *__restrict__ exp_arg
void dump(const double beta, const vertex_t &y, const track_t &tks, const int verbosity=0, const double rho0=0.) const
track_t fill(const std::vector< reco::TransientTrack > &tracks) const
double *__restrict__ zvtx
Abs< T >::type abs(const T &t)
unsigned int getSize() const
std::vector< TransientVertex > vertices_no_blocks(const std::vector< reco::TransientTrack > &tracks) const
unsigned int getSize() const
std::vector< TransientVertex > vertices_in_blocks(const std::vector< reco::TransientTrack > &tracks) const
def split(sequence, size)
std::vector< double > sum_Z_vec
DAClusterizerInZ_vect(const edm::ParameterSet &conf)
unsigned int thermalize(double beta, track_t >racks, vertex_t &gvertices, const double delta_max, const double rho0=0.) const
void set_vtx_range(double beta, track_t >racks, vertex_t &gvertices) const
static int position[264][3]
std::vector< double > zpca_vec
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks) const override
Log< level::Warning, false > LogWarning
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
void verify(const vertex_t &v, const track_t &tks, unsigned int nv=999999, unsigned int nt=999999) const
bool split(const double beta, track_t &t, vertex_t &y, double threshold=1.) const
Power< A, B >::type pow(const A &a, const B &b)