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;
212 tks.
osumtkwt = sumtkwt > 0 ? 1. / sumtkwt : 0.;
215 if (DEBUGLEVEL > 0) {
223 inline double Eik(
double t_z,
double k_z,
double t_dz2) {
return std::pow(
t_z - k_z, 2) * t_dz2; }
227 const unsigned int nv = gvertices.
getSize();
228 const unsigned int nt = gtracks.
getSize();
231 edm::LogWarning(
"DAClusterizerinZ_vect") <<
"empty cluster list in set_vtx_range";
235 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
239 unsigned int kmin =
min(nv - 1, gtracks.
kmin[itrack]);
242 while ((kmin > 0) && (gvertices.
zvtx[kmin - 1] >
zmin)) {
246 while ((kmin < (nv - 1)) && (gvertices.
zvtx[kmin] <
zmin)) {
252 unsigned int kmax =
min(nv - 1, gtracks.
kmax[itrack] - 1);
256 while ((kmax < (nv - 1)) && (gvertices.
zvtx[kmax + 1] <
zmax)) {
260 while ((kmax > 0) && (gvertices.
zvtx[kmax] >
zmax)) {
266 gtracks.
kmin[itrack] = kmin;
267 gtracks.
kmax[itrack] = kmax + 1;
270 gtracks.
kmax[itrack] =
min(nv,
max(kmin, kmax) + 1);
276 const unsigned int nt = gtracks.
getSize();
277 const unsigned int nv = gvertices.
getSize();
278 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
279 gtracks.
kmin[itrack] = 0;
280 gtracks.
kmax[itrack] = nv;
285 double beta,
track_t& gtracks,
vertex_t& gvertices,
const double rho0,
const bool updateTc)
const {
290 const unsigned int nt = gtracks.
getSize();
291 const unsigned int nv = gvertices.
getSize();
296 Z_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
300 auto kernel_calc_exp_arg_range = [
beta](
const unsigned int itrack,
303 const unsigned int kmin,
304 const unsigned int kmax) {
305 const double track_z =
tracks.zpca[itrack];
306 const double botrack_dz2 = -
beta *
tracks.dz2[itrack];
309 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
310 auto mult_res = track_z -
vertices.zvtx[ivertex];
311 vertices.exp_arg[ivertex] = botrack_dz2 * (mult_res * mult_res);
315 auto kernel_add_Z_range = [Z_init](
316 vertex_t const&
vertices,
const unsigned int kmin,
const unsigned int kmax) ->
double {
317 double ZTemp = Z_init;
318 for (
unsigned int ivertex = kmin; ivertex < kmax; ++ivertex) {
324 auto kernel_calc_normalization_range = [updateTc](
const unsigned int track_num,
327 const unsigned int kmin,
328 const unsigned int kmax) {
329 auto o_trk_sum_Z =
tracks.tkwt[track_num] /
tracks.sum_Z[track_num];
330 auto o_trk_dz2 =
tracks.dz2[track_num];
331 auto tmp_trk_z =
tracks.zpca[track_num];
336 for (
unsigned int k = kmin;
k < kmax; ++
k) {
346 for (
unsigned int k = kmin;
k < kmax; ++
k) {
356 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
357 gvertices.
se[ivertex] = 0.0;
358 gvertices.
sw[ivertex] = 0.0;
359 gvertices.
swz[ivertex] = 0.0;
360 gvertices.
swE[ivertex] = 0.0;
363 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
364 gvertices.
se[ivertex] = 0.0;
365 gvertices.
sw[ivertex] = 0.0;
366 gvertices.
swz[ivertex] = 0.0;
371 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
372 const unsigned int kmin = gtracks.
kmin[itrack];
373 const unsigned int kmax = gtracks.
kmax[itrack];
375 kernel_calc_exp_arg_range(itrack, gtracks, gvertices, kmin, kmax);
376 local_exp_list_range(gvertices.
exp_arg, gvertices.
exp, kmin, kmax);
377 gtracks.
sum_Z[itrack] = kernel_add_Z_range(gvertices, kmin, kmax);
380 gtracks.
sum_Z[itrack] = 0.0;
382 if (gtracks.
sum_Z[itrack] > 1.e-100) {
383 kernel_calc_normalization_range(itrack, gtracks, gvertices, kmin, kmax);
389 auto obeta = -1. /
beta;
390 for (
auto ivertex = 0
U; ivertex < nv; ++ivertex) {
391 gvertices.
swE[ivertex] *= obeta;
399 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
408 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex)
414 double delta = kernel_calc_z(gvertices);
422 unsigned int niter = 0;
424 double delta_max = delta_lowT_;
426 if (convergence_mode_ == 0) {
427 delta_max = delta_max0;
428 }
else if (convergence_mode_ == 1) {
432 set_vtx_range(
beta, tks,
v);
433 double delta_sum_range = 0;
434 std::vector<double> z0 =
v.zvtx_vec;
436 while (niter++ < maxIterations_) {
438 delta_sum_range +=
delta;
440 if (delta_sum_range > zrange_min_) {
441 for (
unsigned int k = 0;
k <
v.getSize();
k++) {
442 if (
std::abs(
v.zvtx_vec[
k] - z0[
k]) > zrange_min_) {
443 set_vtx_range(
beta, tks,
v);
451 if (
delta < delta_max) {
457 if (DEBUGLEVEL > 0) {
458 std::cout <<
"DAClusterizerInZ_vect.thermalize niter = " << niter <<
" at T = " << 1 /
beta 459 <<
" nv = " <<
v.getSize() << std::endl;
472 const unsigned int nv = y.getSize();
478 std::vector<std::pair<double, unsigned int>>
critical;
479 for (
unsigned int k = 0; (
k + 1) < nv;
k++) {
480 if (std::fabs(y.zvtx[
k + 1] - y.zvtx[
k]) < zmerge_) {
481 critical.push_back(make_pair(std::fabs(y.zvtx[
k + 1] - y.zvtx[
k]),
k));
487 std::stable_sort(
critical.begin(),
critical.end(), std::less<std::pair<double, unsigned int>>());
489 for (
unsigned int ik = 0; ik <
critical.size(); ik++) {
491 double rho = y.rho[
k] + y.rho[
k + 1];
495 if (DEBUGLEVEL > 1) {
496 std::cout <<
"merging " <<
fixed << setprecision(4) << y.zvtx[
k + 1] <<
" and " << y.zvtx[
k]
497 <<
" sw = " << y.sw[
k] + y.sw[
k + 1] << std::endl;
502 y.zvtx[
k] = (y.rho[
k] * y.zvtx[
k] + y.rho[
k + 1] * y.zvtx[
k + 1]) / rho;
504 y.zvtx[
k] = 0.5 * (y.zvtx[
k] + y.zvtx[
k + 1]);
507 y.sw[
k] += y.sw[
k + 1];
508 y.removeItem(
k + 1, tks);
509 set_vtx_range(
beta, tks, y);
520 const unsigned int nv = y.getSize();
526 std::vector<double> sump_v(nv), arg_cache_v(nv), exp_cache_v(nv), pcut_cache_v(nv);
527 std::vector<int> nUnique_v(nv);
528 double* __restrict__ parg_cache;
529 double* __restrict__ pexp_cache;
530 double* __restrict__ ppcut_cache;
531 double* __restrict__ psump;
532 int* __restrict__ pnUnique;
535 set_vtx_range(
beta, tks, y);
537 parg_cache = arg_cache_v.data();
538 pexp_cache = exp_cache_v.data();
539 ppcut_cache = pcut_cache_v.data();
540 psump = sump_v.data();
541 pnUnique = nUnique_v.data();
543 const auto rhoconst = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
544 for (
unsigned int k = 0;
k < nv;
k++) {
545 const double pmax = y.rho[
k] / (y.rho[
k] + rhoconst);
546 ppcut_cache[
k] = uniquetrkweight_ * pmax;
549 for (
unsigned int i = 0;
i <
nt;
i++) {
550 const auto invZ = ((tks.
sum_Z[
i] >
eps) && (tks.
tkwt[
i] > uniquetrkminp_)) ? 1. / tks.
sum_Z[
i] : 0.;
551 const auto track_z = tks.
zpca[
i];
552 const auto botrack_dz2 = -
beta * tks.
dz2[
i];
553 const auto kmin = tks.
kmin[
i];
554 const auto kmax = tks.
kmax[
i];
556 for (
unsigned int k = kmin;
k < kmax;
k++) {
557 const auto mult_resz = track_z - y.zvtx[
k];
558 parg_cache[
k] = botrack_dz2 * (mult_resz * mult_resz);
561 local_exp_list_range(parg_cache, pexp_cache, kmin, kmax);
563 for (
unsigned int k = kmin;
k < kmax;
k++) {
564 const double p = y.rho[
k] * pexp_cache[
k] * invZ;
566 pnUnique[
k] += (
p > ppcut_cache[
k]) ? 1 : 0;
571 unsigned int k0 = nv;
572 for (
unsigned k = 0;
k < nv;
k++) {
573 if ((pnUnique[
k] < nunique_min_) && (psump[
k] < sumpmin)) {
582 if (DEBUGLEVEL > 1) {
583 std::cout <<
"eliminating prototype at " << std::setw(10) << std::setprecision(4) << y.zvtx[
k0]
584 <<
" with sump=" << sumpmin <<
" rho*nt =" << y.rho[
k0] *
nt <<
" pnUnique=" << pnUnique[
k0] << endl;
588 y.removeItem(
k0, tks);
589 set_vtx_range(
beta, tks, y);
600 const unsigned int nv = y.getSize();
602 for (
unsigned int k = 0;
k < nv;
k++) {
606 for (
unsigned int i = 0;
i <
nt;
i++) {
612 y.zvtx[
k] = sumwz / sumw;
616 for (
unsigned int i = 0;
i <
nt;
i++) {
617 double dx = tks.
zpca[
i] - y.zvtx[
k];
622 double Tc = 2. *
a /
b;
630 if (DEBUGLEVEL > 0) {
631 std::cout <<
"DAClusterizerInZ_vect.beta0: Tc = " << T0 << std::endl;
633 std::cout <<
"DAClusterizerInZ_vect.beta0: nstep = " << coolingsteps << std::endl;
637 if (T0 > 1. / betamax) {
640 return betamax *
std::pow(coolingFactor_, coolingsteps);
643 return betamax * coolingFactor_;
655 unsigned int nv = y.getSize();
659 std::vector<std::pair<double, unsigned int>>
critical;
660 for (
unsigned int k = 0;
k < nv;
k++) {
661 double Tc = 2 * y.swE[
k] / y.sw[
k];
669 std::stable_sort(
critical.begin(),
critical.end(), std::greater<std::pair<double, unsigned int>>());
674 for (
unsigned int ic = 0; ic <
critical.size(); ic++) {
678 double p1 = 0, z1 = 0, w1 = 0;
679 double p2 = 0,
z2 = 0,
w2 = 0;
680 for (
unsigned int i = 0;
i <
nt;
i++) {
681 if (tks.
sum_Z[
i] > 1.e-100) {
683 double tl = tks.
zpca[
i] < y.zvtx[
k] ? 1. : 0.;
688 if (std::fabs(
arg) < 20) {
689 double t = local_exp(-
arg);
695 double w =
p * tks.
dz2[
i];
697 z1 +=
w * tl * tks.
zpca[
i];
717 if ((
k > 0) && (z1 < (0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k - 1]))) {
718 z1 = 0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k - 1];
720 if ((
k + 1 < nv) && (
z2 > (0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k + 1]))) {
721 z2 = 0.6 * y.zvtx[
k] + 0.4 * y.zvtx[
k + 1];
726 if (DEBUGLEVEL > 1) {
727 if (std::fabs(y.zvtx[
k] - zdumpcenter_) < zdumpwidth_) {
729 <<
std::fixed << std::setprecision(4) << y.zvtx[
k] <<
" --> " << z1 <<
"," <<
z2 <<
" [" <<
p1 743 double pk1 =
p1 * y.rho[
k] / (
p1 +
p2);
744 double pk2 =
p2 * y.rho[
k] / (
p1 +
p2);
747 y.insertItem(
k, z1, pk1, tks);
754 for (
unsigned int jc = ic; jc <
critical.size(); jc++) {
761 std::cout <<
"warning ! split rejected, too small." << endl;
783 clear_vtx_range(tks, y);
786 double beta = beta0(betamax_, tks, y);
792 thermalize(
beta, tks, y, delta_highT_);
796 double betafreeze = betamax_ *
sqrt(coolingFactor_);
798 while (
beta < betafreeze) {
805 thermalize(
beta, tks, y, delta_highT_);
811 if (DEBUGLEVEL > 0) {
812 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 813 <<
"last round of splitting" << std::endl;
817 set_vtx_range(
beta, tks, y);
821 set_vtx_range(
beta, tks, y);
825 unsigned int ntry = 0;
828 thermalize(
beta, tks, y, delta_highT_, rho0);
839 if (DEBUGLEVEL > 0) {
840 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 841 <<
"turning on outlier rejection at T=" << 1 /
beta << std::endl;
847 rho0 = y.getSize() > 1 ? 1. / y.getSize() : 1.;
848 for (
unsigned int a = 0;
a < 5;
a++) {
853 thermalize(
beta, tks, y, delta_lowT_, rho0);
857 if (DEBUGLEVEL > 0) {
858 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 859 <<
"merging with outlier rejection at T=" << 1 /
beta << std::endl;
867 set_vtx_range(
beta, tks, y);
873 if (DEBUGLEVEL > 0) {
874 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 875 <<
"after merging with outlier rejection at T=" << 1 /
beta << std::endl;
882 while (
beta < betapurge_) {
884 thermalize(
beta, tks, y, delta_lowT_, rho0);
889 if (DEBUGLEVEL > 0) {
890 std::cout <<
"DAClusterizerInZ_vect::vertices :" 891 <<
"purging at T=" << 1 /
beta << std::endl;
896 while (purge(y, tks, rho0,
beta)) {
897 thermalize(
beta, tks, y, delta_lowT_, rho0);
902 if (DEBUGLEVEL > 0) {
903 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 904 <<
"last cooling T=" << 1 /
beta << std::endl;
909 while (
beta < betastop_) {
911 thermalize(
beta, tks, y, delta_lowT_, rho0);
916 if (DEBUGLEVEL > 0) {
917 std::cout <<
"DAClusterizerInZ_vect::vertices_no_blocks :" 918 <<
"stop cooling at T=" << 1 /
beta << std::endl;
925 return fill_vertices(
beta, rho0, tks, y);
929 vector<reco::TransientTrack> sorted_tracks;
930 vector<pair<float, float>> vertices_tot;
931 for (
unsigned int i = 0;
i <
tracks.size();
i++) {
932 sorted_tracks.push_back(
tracks[
i]);
938 return (
a.stateAtBeamLine().trackStateAtPCA()).
position().z() <
939 (
b.stateAtBeamLine().trackStateAtPCA()).
position().z();
942 unsigned int nBlocks = (
unsigned int)std::floor(sorted_tracks.size() / (block_size_ * (1 - overlap_frac_)));
946 <<
"Warning nBlocks was 0 with ntracks = " << sorted_tracks.size() <<
" block_size = " << block_size_
947 <<
" and overlap fraction = " << overlap_frac_ <<
". Setting nBlocks = 1";
950 vector<reco::TransientTrack> block_tracks;
951 unsigned int begin = (
unsigned int)(
block * block_size_ * (1 - overlap_frac_));
952 unsigned int end = (
unsigned int)
std::min(begin + block_size_, (
unsigned int)sorted_tracks.size());
953 for (
unsigned int i = begin;
i < end;
i++) {
954 block_tracks.push_back(sorted_tracks[
i]);
956 if (block_tracks.empty()) {
961 std::cout <<
"Running vertices_in_blocks on" << std::endl;
962 std::cout <<
"- block no." <<
block <<
" on " << nBlocks <<
" blocks " << std::endl;
963 std::cout <<
"- block track size: " << sorted_tracks.size() <<
" - block size: " << block_size_ << std::endl;
974 clear_vtx_range(tks, y);
977 beta = beta0(betamax_, tks, y);
983 thermalize(
beta, tks, y, delta_highT_);
987 double betafreeze = betamax_ *
sqrt(coolingFactor_);
988 while (
beta < betafreeze) {
995 thermalize(
beta, tks, y, delta_highT_);
1001 if (DEBUGLEVEL > 0) {
1002 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1003 <<
"last round of splitting" << std::endl;
1007 set_vtx_range(
beta, tks, y);
1011 set_vtx_range(
beta, tks, y);
1015 unsigned int ntry = 0;
1018 thermalize(
beta, tks, y, delta_highT_, rho0);
1029 if (DEBUGLEVEL > 0) {
1030 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1031 <<
"turning on outlier rejection at T=" << 1 /
beta << std::endl;
1036 if (dzCutOff_ > 0) {
1037 rho0 = y.getSize() > 1 ? 1. / y.getSize() : 1.;
1038 for (
unsigned int a = 0;
a < 5;
a++) {
1043 thermalize(
beta, tks, y, delta_lowT_, rho0);
1047 if (DEBUGLEVEL > 0) {
1048 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1049 <<
"merging with outlier rejection at T=" << 1 /
beta << std::endl;
1057 set_vtx_range(
beta, tks, y);
1063 if (DEBUGLEVEL > 0) {
1064 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1065 <<
"after merging with outlier rejection at T=" << 1 /
beta << std::endl;
1072 while (
beta < betapurge_) {
1074 thermalize(
beta, tks, y, delta_lowT_, rho0);
1079 if (DEBUGLEVEL > 0) {
1080 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1081 <<
"purging at T=" << 1 /
beta << std::endl;
1086 while (purge(y, tks, rho0,
beta)) {
1087 thermalize(
beta, tks, y, delta_lowT_, rho0);
1092 if (DEBUGLEVEL > 0) {
1093 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1094 <<
"last cooling T=" << 1 /
beta << std::endl;
1099 while (
beta < betastop_) {
1101 thermalize(
beta, tks, y, delta_lowT_, rho0);
1106 if (DEBUGLEVEL > 0) {
1107 std::cout <<
"DAClusterizerInZSubCluster_vect::vertices :" 1108 <<
"stop cooling at T=" << 1 /
beta << std::endl;
1114 for (
unsigned int ivertex = 0; ivertex < y.getSize(); ivertex++) {
1115 if (y.zvtx_vec[ivertex] != 0 && y.rho_vec[ivertex] != 0) {
1116 vertices_tot.push_back(pair(y.zvtx_vec[ivertex], y.rho_vec[ivertex]));
1118 std::cout <<
"Found new vertex " << y.zvtx_vec[ivertex] <<
" , " << y.rho_vec[ivertex] << std::endl;
1126 [](
const pair<float, float>&
a,
const pair<float, float>&
b) ->
bool {
return a.first <
b.first; });
1130 const unsigned int nv = vertices_tot.size();
1131 const unsigned int nt = tracks_tot.getSize();
1133 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
1134 double zrange =
max(sel_zrange_ /
sqrt(
beta * tracks_tot.dz2[itrack]), zrange_min_);
1136 double zmin = tracks_tot.zpca[itrack] -
zrange;
1137 unsigned int kmin =
min(nv - 1, tracks_tot.kmin[itrack]);
1140 while ((kmin > 0) && (vertices_tot[kmin - 1].
first >
zmin)) {
1144 while ((kmin < (nv - 1)) && (vertices_tot[kmin].
first <
zmin)) {
1149 double zmax = tracks_tot.zpca[itrack] +
zrange;
1150 unsigned int kmax =
min(nv - 1, tracks_tot.kmax[itrack] - 1);
1154 while ((kmax < (nv - 1)) && (vertices_tot[kmax + 1].
first <
zmax)) {
1158 while ((kmax > 0) && (vertices_tot[kmax].
first >
zmax)) {
1164 tracks_tot.kmin[itrack] = kmin;
1165 tracks_tot.kmax[itrack] = kmax + 1;
1167 tracks_tot.kmin[itrack] =
max(0
U,
min(kmin, kmax));
1168 tracks_tot.kmax[itrack] =
min(nv,
max(kmin, kmax) + 1);
1172 rho0 = nv > 1 ? 1. / nv : 1.;
1173 const auto z_sum_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
1175 std::vector<std::vector<unsigned int>> vtx_track_indices(nv);
1176 for (
unsigned int i = 0;
i <
nt;
i++) {
1177 const auto kmin = tracks_tot.kmin[
i];
1178 const auto kmax = tracks_tot.kmax[
i];
1180 unsigned int iMax = 10000;
1181 float sum_Z = z_sum_init;
1182 for (
auto k = kmin;
k < kmax;
k++) {
1183 float v_exp = local_exp(-
beta * Eik(tracks_tot.zpca[
i], vertices_tot[
k].first, tracks_tot.dz2[
i]));
1184 sum_Z += vertices_tot[
k].second * v_exp;
1186 double invZ = sum_Z > 1
e-100 ? 1. / sum_Z : 0.0;
1187 for (
auto k = kmin;
k < kmax && invZ != 0.0;
k++) {
1188 float v_exp = local_exp(-
beta * Eik(tracks_tot.zpca[
i], vertices_tot[
k].first, tracks_tot.dz2[
i]));
1189 double p = vertices_tot[
k].second * v_exp * invZ;
1190 if (
p > p_max &&
p > mintrkweight_) {
1195 if (iMax < vtx_track_indices.size()) {
1196 vtx_track_indices[iMax].push_back(
i);
1200 for (
auto itrack = 0
U; itrack <
nt; ++itrack) {
1201 std::cout <<
"itrack " << itrack <<
" , " << tracks_tot.kmin[itrack] <<
" , " << tracks_tot.kmax[itrack]
1211 GlobalError dummyError(0.01, 0, 0.01, 0., 0., 0.01);
1212 vector<reco::TransientTrack> vertexTracks;
1214 for (
unsigned int k = 0;
k < nv;
k++) {
1215 if (!vtx_track_indices[
k].
empty()) {
1216 for (
auto i : vtx_track_indices[
k]) {
1217 vertexTracks.push_back(*(tracks_tot.tt[
i]));
1220 << (*(tracks_tot.tt[
i])).stateAtBeamLine().trackStateAtPCA().position().z() << std::endl;
1226 if ((
k + 1 == nv) || (
abs(vertices_tot[
k + 1].
first - vertices_tot[
k].
first) > (2 * vertexSize_))) {
1228 if (vertexTracks.size() > 1) {
1233 vertexTracks.clear();
1243 set_vtx_range(
beta, tks, y);
1244 const unsigned int nv = y.getSize();
1245 for (
unsigned int k = 0;
k < nv;
k++) {
1254 const auto z_sum_init = rho0 * local_exp(-
beta * dzCutOff_ * dzCutOff_);
1255 std::vector<std::vector<unsigned int>> vtx_track_indices(nv);
1256 std::vector<std::vector<float>> vtx_track_weights(nv);
1257 for (
unsigned int i = 0;
i <
nt;
i++) {
1258 const auto kmin = tks.
kmin[
i];
1259 const auto kmax = tks.
kmax[
i];
1260 for (
auto k = kmin;
k < kmax;
k++) {
1264 local_exp_list_range(y.exp_arg, y.exp, kmin, kmax);
1266 tks.
sum_Z[
i] = z_sum_init;
1267 for (
auto k = kmin;
k < kmax;
k++) {
1268 tks.
sum_Z[
i] += y.rho[
k] * y.exp[
k];
1270 const double invZ = tks.
sum_Z[
i] > 1
e-100 ? 1. / tks.
sum_Z[
i] : 0.0;
1273 unsigned int k_pmax = 0;
1274 for (
auto k = kmin;
k < kmax;
k++) {
1275 double p = y.rho[
k] * y.exp[
k] * invZ;
1282 if (pmax > mintrkweight_) {
1284 vtx_track_indices[k_pmax].push_back(
i);
1285 vtx_track_weights[k_pmax].push_back(pmax);
1292 for (
unsigned int k = 0;
k < nv;
k++) {
1295 double sumwp = 0, sumwz = 0;
1296 if (!vtx_track_indices[
k].
empty()) {
1297 vector<reco::TransientTrack> vertexTracks;
1300 for (
auto i : vtx_track_indices[
k]) {
1301 auto p = vtx_track_weights[
k][
j];
1302 vertexTracks.push_back(*(tks.
tt[
i]));
1303 trkWeightMap[vertexTracks[
j]] =
p;
1308 sumwz +=
w * tks.
zpca[
i];
1311 float zerror_squared = 1.;
1312 if ((sumw > 0) && (sumwp > 0)) {
1313 zerror_squared = sumwp / (sumw * sumw);
1314 y.zvtx[
k] = sumwz / sumw;
1319 const float xerror_squared =
pow(
bs.BeamWidthX(), 2);
1320 const float yerror_squared =
pow(
bs.BeamWidthY(), 2);
1321 GlobalError err(xerror_squared, 0, yerror_squared, 0., 0., zerror_squared);
1323 v.weightMap(trkWeightMap);
1332 if (runInBlocks_ and (block_size_ <
tracks.size()))
1333 return vertices_in_blocks(
tracks);
1335 return vertices_no_blocks(
tracks);
1339 const vector<reco::TransientTrack>&
tracks)
const {
1340 vector<vector<reco::TransientTrack>>
clusters;
1344 if (DEBUGLEVEL > 0) {
1345 std::cout <<
"###################################################" << endl;
1346 std::cout <<
"# vectorized DAClusterizerInZ_vect::clusterize nt=" <<
tracks.size() << endl;
1347 std::cout <<
"# DAClusterizerInZ_vect::clusterize pv.size=" <<
pv.size() << endl;
1348 std::cout <<
"###################################################" << endl;
1357 vector<reco::TransientTrack> aCluster =
pv.begin()->originalTracks();
1359 for (
auto k =
pv.begin() + 1;
k !=
pv.end();
k++) {
1362 if (aCluster.size() > 1) {
1367 std::cout <<
" one track cluster at " <<
k->position().z() <<
" suppressed" << std::endl;
1372 for (
unsigned int i = 0;
i <
k->originalTracks().size();
i++) {
1373 aCluster.push_back(
k->originalTracks()[
i]);
1384 const unsigned int nv = y.getSize();
1389 update(
beta, tks_local, y_local, rho0,
true);
1391 std::vector<unsigned int> iz;
1392 for (
unsigned int j = 0;
j <
nt;
j++) {
1395 std::sort(iz.begin(), iz.end(), [tks](
unsigned int a,
unsigned int b) {
return tks.
zpca[
a] < tks.
zpca[
b]; });
1397 std::cout <<
"-----DAClusterizerInZ::dump ----" << nv <<
" clusters " << std::endl;
1399 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1400 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1401 std::cout <<
" " << setw(3) << ivertex <<
" ";
1407 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1408 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1413 <<
"T=" << setw(15) << 1. /
beta <<
" Tmin =" << setw(10) << 1. / betamax_
1415 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1416 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1417 double Tc = 2 * y_local.
swE[ivertex] / y_local.
sw[ivertex];
1425 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1426 sumpk += y.rho[ivertex];
1427 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1429 std::cout << setw(8) << setprecision(4) <<
fixed << y.rho[ivertex];
1434 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1435 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1442 double E = 0,
F = 0;
1444 std::cout <<
"---- z +/- dz ip +/-dip pt phi eta weights ----" << endl;
1446 for (
unsigned int i0 = 0; i0 <
nt; i0++) {
1447 unsigned int i = iz[i0];
1451 double tz = tks.
zpca[
i];
1453 if (std::fabs(tz - zdumpcenter_) > zdumpwidth_)
1455 std::cout << setw(4) <<
i <<
")" << setw(8) <<
fixed << setprecision(4) << tz <<
" +/-" << setw(6)
1457 if ((tks.
tt[
i] ==
nullptr)) {
1474 .pixelBarrelLayersWithMeasurement();
1475 std::cout << setw(1) << tks.
tt[
i]->track().hitPattern().pixelEndcapLayersWithMeasurement();
1477 << tks.
tt[
i]->track().hitPattern().trackerLayersWithMeasurement() -
1478 tks.
tt[
i]->track().hitPattern().pixelLayersWithMeasurement()
1484 std::cout << setw(8) <<
IP.value() <<
"+/-" << setw(6) <<
IP.error();
1485 std::cout <<
" " << setw(6) << setprecision(2) << tks.
tt[
i]->track().pt() * tks.
tt[
i]->track().charge();
1486 std::cout <<
" " << setw(5) << setprecision(2) << tks.
tt[
i]->track().phi() <<
" " << setw(5) << setprecision(2)
1487 << tks.
tt[
i]->track().eta();
1491 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1492 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) > zdumpwidth_)
1497 double p = y.rho[ivertex] * local_exp(-
beta * Eik(tks.
zpca[
i], y.zvtx[ivertex], tks.
dz2[
i])) / tks.
sum_Z[
i];
1499 std::cout << setw(8) << setprecision(3) <<
p;
1503 E +=
p * Eik(tks.
zpca[
i], y.zvtx[ivertex], tks.
dz2[
i]);
1509 std::cout <<
" ( " << std::setw(3) << tks.
kmin[
i] <<
"," << std::setw(3) << tks.
kmax[
i] - 1 <<
" ) ";
1513 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1514 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1515 std::cout <<
" " << setw(3) << ivertex <<
" ";
1521 for (
unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
1522 if (std::fabs(y.zvtx[ivertex] - zdumpcenter_) < zdumpwidth_) {
1528 <<
"T=" << 1 /
beta <<
" E=" << E <<
" n=" << y.getSize() <<
" F= " <<
F << endl
1529 <<
"----------" << endl;
1535 desc.addUntracked<
double>(
"zdumpcenter", 0.);
1536 desc.addUntracked<
double>(
"zdumpwidth", 20.);
1537 desc.add<
double>(
"d0CutOff", 3.0);
1538 desc.add<
double>(
"Tmin", 2.0);
1539 desc.add<
double>(
"delta_lowT", 0.001);
1540 desc.add<
double>(
"zmerge", 0.01);
1541 desc.add<
double>(
"dzCutOff", 3.0);
1542 desc.add<
double>(
"Tpurge", 2.0);
1543 desc.add<
int>(
"convergence_mode", 0);
1544 desc.add<
double>(
"delta_highT", 0.01);
1545 desc.add<
double>(
"Tstop", 0.5);
1546 desc.add<
double>(
"coolingFactor", 0.6);
1547 desc.add<
double>(
"vertexSize", 0.006);
1548 desc.add<
double>(
"uniquetrkweight", 0.8);
1549 desc.add<
double>(
"uniquetrkminp", 0.0);
1550 desc.add<
double>(
"zrange", 4.0);
1551 desc.add<
bool>(
"runInBlocks",
false);
1552 desc.add<
unsigned int>(
"block_size", 10000);
1553 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
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)