8 const std::vector<float>& bin_centers,
9 const std::vector<unsigned int>&
counts) {
14 double highestPt = 0.;
15 unsigned int numHighPtTracks = 0;
21 std::vector<double> bin_pt(bin_centers.size(), 0.0);
22 unsigned int ibin = 0;
23 unsigned int itrack = 0;
33 if (
trackPt > settings_->vx_TrackMaxPt()) {
37 if (settings_->vx_TrackMaxPtBehavior() == 0)
39 else if (settings_->vx_TrackMaxPtBehavior() == 1)
40 trackPt = settings_->vx_TrackMaxPt();
44 if (bin_centers.empty() &&
counts.empty()) {
49 if (itrack ==
counts[ibin]) {
50 SumZ += bin_centers[ibin] * bin_pt[ibin];
51 z0square += bin_centers[ibin] * bin_centers[ibin];
58 z0 = SumZ / ((settings_->vx_weightedmean() > 0) ?
pt :
vertex.numTracks());
59 z0square /=
vertex.numTracks();
62 vertex.setParameters(
pt, z0, z0width, highPt, numHighPtTracks, highestPt);
65 void VertexFinder::GapClustering() {
69 for (
unsigned int i = 0;
i < fitTracks_.size(); ++
i) {
72 if ((
i + 1 < fitTracks_.size() and fitTracks_[
i + 1].z0() - fitTracks_[
i].z0() > settings_->vx_distance())
or 73 i == fitTracks_.size() - 1) {
75 computeAndSetVertexParameters(
Vertex, {}, {});
76 vertices_.push_back(
Vertex);
110 float distanceSum = 0;
114 distanceSum +=
std::abs(track0->z0() - track1->z0());
123 computeAndSetVertexParameters(cluster0, {}, {});
124 computeAndSetVertexParameters(cluster1, {}, {});
129 void VertexFinder::agglomerativeHierarchicalClustering() {
135 vClusters.resize(fitTracks_.size());
137 for (
unsigned int i = 0;
i < fitTracks_.size(); ++
i) {
138 vClusters[
i].insert(&fitTracks_[
i]);
143 float MinimumScore = 9999;
145 unsigned int clusterId0 = 0;
146 unsigned int clusterId1 = 0;
147 for (
unsigned int iClust = 0; iClust < vClusters.size() - 1; iClust++) {
151 if (settings_->vx_distanceType() == 0)
152 M =
maxDistance(vClusters[iClust], vClusters[iClust + 1]);
153 else if (settings_->vx_distanceType() == 1)
154 M = minDistance(vClusters[iClust], vClusters[iClust + 1]);
155 else if (settings_->vx_distanceType() == 2)
156 M = meanDistance(vClusters[iClust], vClusters[iClust + 1]);
158 M = centralDistance(vClusters[iClust], vClusters[iClust + 1]);
160 if (M < MinimumScore) {
163 clusterId1 = iClust + 1;
166 if (MinimumScore > settings_->vx_distance()
or vClusters[clusterId1].tracks().empty())
169 vClusters[clusterId1].insert(
track);
171 vClusters.erase(vClusters.begin() + clusterId0);
175 if (clust.numTracks() >= settings_->vx_minTracks()) {
176 computeAndSetVertexParameters(clust, {}, {});
177 vertices_.push_back(clust);
182 void VertexFinder::DBSCAN() {
184 std::vector<unsigned int>
visited;
185 std::vector<unsigned int> saved;
190 for (
unsigned int i = 0;
i < fitTracks_.size(); ++
i) {
196 std::set<unsigned int> neighbourTrackIds;
197 unsigned int numDensityTracks = 0;
198 if (fitTracks_[
i].
pt() > settings_->vx_dbscan_pt())
202 for (
unsigned int k = 0;
k < fitTracks_.size(); ++
k) {
204 if (
k !=
i and
std::abs(fitTracks_[
k].z0() - fitTracks_[
i].z0()) < settings_->vx_distance()) {
205 neighbourTrackIds.insert(
k);
206 if (fitTracks_[
k].
pt() > settings_->vx_dbscan_pt()) {
212 if (numDensityTracks < settings_->vx_dbscan_mintracks()) {
218 for (
unsigned int id : neighbourTrackIds) {
221 std::vector<unsigned int> neighbourTrackIds2;
222 for (
unsigned int k = 0;
k < fitTracks_.size(); ++
k) {
224 if (
std::abs(fitTracks_[
k].z0() - fitTracks_[
id].z0()) < settings_->vx_distance()) {
225 neighbourTrackIds2.push_back(
k);
230 for (
unsigned int id2 : neighbourTrackIds2) {
231 neighbourTrackIds.insert(
id2);
235 if (
find(saved.begin(), saved.end(),
id) == saved.end())
236 vertex.insert(&fitTracks_[
id]);
238 computeAndSetVertexParameters(
vertex, {}, {});
239 if (
vertex.numTracks() >= settings_->vx_minTracks())
240 vertices_.push_back(
vertex);
246 void VertexFinder::PVR() {
251 acceptedTracks.push_back(
track);
254 while (discardedTracks.size() >= settings_->vx_minTracks()
or start ==
true) {
256 bool removing =
true;
257 discardedTracks.clear();
259 float oldDistance = 0.;
261 if (settings_->debug() > 2)
262 edm::LogInfo(
"VertexFinder") <<
"PVR::AcceptedTracks " << acceptedTracks.size();
266 z0start +=
track.z0();
270 z0start /= acceptedTracks.size();
271 if (settings_->debug() > 2)
272 edm::LogInfo(
"VertexFinder") <<
"PVR::z0 vertex " << z0start;
273 FitTrackCollection::iterator badTrackIt = acceptedTracks.end();
276 for (FitTrackCollection::iterator
it = acceptedTracks.begin();
it < acceptedTracks.end(); ++
it) {
279 if (
std::abs(
track->z0() - z0start) > settings_->vx_distance() and
288 const L1Track badTrack = *badTrackIt;
289 if (settings_->debug() > 2)
290 edm::LogInfo(
"VertexFinder") <<
"PVR::Removing track " << badTrack.
z0() <<
" at distance " << oldDistance;
291 discardedTracks.push_back(badTrack);
292 acceptedTracks.erase(badTrackIt);
296 if (acceptedTracks.size() >= settings_->vx_minTracks()) {
301 computeAndSetVertexParameters(
vertex, {}, {});
302 vertices_.push_back(
vertex);
304 if (settings_->debug() > 2)
305 edm::LogInfo(
"VertexFinder") <<
"PVR::DiscardedTracks size " << discardedTracks.size();
306 acceptedTracks.clear();
307 acceptedTracks = discardedTracks;
311 void VertexFinder::adaptiveVertexReconstruction() {
317 discardedTracks.push_back(
track);
320 while (discardedTracks.size() >= settings_->vx_minTracks()
or start ==
true) {
322 discardedTracks2.clear();
323 FitTrackCollection::iterator
it = discardedTracks.begin();
325 acceptedTracks.push_back(
track);
326 float z0sum =
track.z0();
328 for (FitTrackCollection::iterator it2 = discardedTracks.begin(); it2 < discardedTracks.end(); ++it2) {
330 const L1Track secondTrack = *it2;
332 z0sum += secondTrack.
z0();
333 float z0vertex = z0sum / (acceptedTracks.size() + 1);
337 for (
const L1Track& accTrack : acceptedTracks) {
339 float Residual = accTrack.z0() - z0vertex;
349 chi2 += Residual * Residual;
350 dof = (acceptedTracks.size() + 1) * 2 - 1;
352 if (
chi2 / dof < settings_->vx_chi2cut()) {
353 acceptedTracks.push_back(secondTrack);
355 discardedTracks2.push_back(secondTrack);
356 z0sum -= secondTrack.
z0();
361 if (acceptedTracks.size() >= settings_->vx_minTracks()) {
366 computeAndSetVertexParameters(
vertex, {}, {});
367 vertices_.push_back(
vertex);
370 acceptedTracks.clear();
371 discardedTracks.clear();
372 discardedTracks = discardedTracks2;
376 void VertexFinder::HPV() {
384 if (
track.pt() < 50.) {
396 computeAndSetVertexParameters(
vertex, {}, {});
398 vertices_.push_back(
vertex);
401 void VertexFinder::Kmeans() {
402 unsigned int NumberOfClusters = settings_->vx_kmeans_nclusters();
404 vertices_.resize(NumberOfClusters);
405 float ClusterSeparation = 30. / NumberOfClusters;
407 for (
unsigned int i = 0;
i < NumberOfClusters; ++
i) {
408 float ClusterCentre = -15. + ClusterSeparation * (
i + 0.5);
409 vertices_[
i].setZ0(ClusterCentre);
411 unsigned int iterations = 0;
413 while (iterations < settings_->vx_kmeans_iterations()) {
414 for (
unsigned int i = 0;
i < NumberOfClusters; ++
i) {
415 vertices_[
i].clear();
420 if (iterations == settings_->vx_kmeans_iterations() - 3)
421 distance = settings_->vx_distance() * 2;
422 if (iterations > settings_->vx_kmeans_iterations() - 3)
423 distance = settings_->vx_distance();
424 unsigned int ClusterId;
426 for (
unsigned int id = 0;
id < NumberOfClusters; ++
id) {
434 vertices_[ClusterId].insert(&
track);
437 for (
unsigned int i = 0;
i < NumberOfClusters; ++
i) {
438 if (vertices_[
i].numTracks() >= settings_->vx_minTracks())
439 computeAndSetVertexParameters(vertices_[
i], {}, {});
445 void VertexFinder::findPrimaryVertex() {
446 if (settings_->vx_precision() == Precision::Emulation) {
448 std::max_element(verticesEmulation_.begin(),
449 verticesEmulation_.end(),
451 return (vertex0.
pt() < vertex1.pt());
458 return (vertex0.
pt() < vertex1.pt());
464 template <
class data_type,
typename stream_type>
465 void VertexFinder::printHistogram(stream_type&
stream,
466 std::vector<data_type>
data,
472 int tableSize =
data.size();
475 maximum =
float(*std::max_element(std::begin(
data), std::end(
data))) * 1.05;
476 }
else if (maximum <= minimum) {
477 maximum =
float(*std::max_element(std::begin(
data), std::end(
data))) * 1.05;
478 minimum =
float(*std::min_element(std::begin(
data), std::end(
data)));
487 std::vector<std::string> intervals(tableSize,
"");
488 std::vector<std::string>
values(tableSize,
"");
490 int intervalswidth = 0, valueswidth = 0, tmpwidth = 0;
491 for (
int i = 0;
i < tableSize;
i++) {
493 tmpwidth = sprintf(
buffer,
"[%-.5g, %-.5g)",
float(
i),
float(
i + 1));
495 if (
i == (tableSize - 1)) {
496 intervals[
i][intervals[
i].size() - 1] =
']';
498 if (tmpwidth > intervalswidth)
499 intervalswidth = tmpwidth;
502 tmpwidth = sprintf(
buffer,
"%-.5g",
float(
data[
i]));
504 if (tmpwidth > valueswidth)
505 valueswidth = tmpwidth;
508 sprintf(
buffer,
"%-.5g",
float(minimum));
510 sprintf(
buffer,
"%-.5g",
float(maximum));
514 std::max(
int(minimumtext.size() + maximumtext.size()),
width - (intervalswidth + 1 + valueswidth + 1 + 2));
516 minimumtext +
std::string(plotwidth + 2 - minimumtext.size() - maximumtext.size(),
' ') + maximumtext;
518 float norm =
float(plotwidth) /
float(maximum - minimum);
519 int zero = std::round((0.0 - minimum) * norm);
520 std::vector<char>
line(plotwidth,
'-');
522 if ((minimum != 0) && (0 <=
zero) && (
zero < plotwidth)) {
528 std::vector<std::string>
out;
529 if (!
title.empty()) {
534 out.push_back(capstone);
535 for (
int i = 0;
i < tableSize;
i++) {
539 std::fill_n(
line.begin(), plotwidth,
' ');
541 int pos = std::round((
float(
x) - minimum) * norm);
548 if ((minimum != 0) && (0 <=
zero) && (
zero < plotwidth)) {
561 out.push_back(capstone);
564 for (
const auto&
o :
out) {
572 void VertexFinder::sortVerticesInPt() {
573 if (settings_->vx_precision() == Precision::Emulation) {
575 verticesEmulation_.begin(),
576 verticesEmulation_.end(),
580 return (vertex0.
pt() > vertex1.pt());
585 void VertexFinder::sortVerticesInZ0() {
586 if (settings_->vx_precision() == Precision::Emulation) {
588 verticesEmulation_.begin(),
589 verticesEmulation_.end(),
593 return (vertex0.
z0() < vertex1.z0());
598 void VertexFinder::associatePrimaryVertex(
double trueZ0) {
600 for (
unsigned int id = 0;
id < vertices_.size(); ++
id) {
608 void VertexFinder::fastHistoLooseAssociation() {
612 for (
float z = settings_->vx_histogram_min(); z < settings_->vx_histogram_max();
613 z += settings_->vx_histogram_binwidth()) {
620 computeAndSetVertexParameters(
vertex, {}, {});
628 vertices_.emplace_back(leading_vertex);
635 std::ceil((settings_->vx_histogram_max() - settings_->vx_histogram_min()) / settings_->vx_histogram_binwidth());
637 std::vector<RecoVertex<>> sums(
nbins - settings_->vx_windowSize() + 1);
639 strided_iota(std::begin(
bounds),
641 settings_->vx_histogram_min(),
642 settings_->vx_histogram_binwidth());
646 if ((
track.z0() < settings_->vx_histogram_min()) || (
track.z0() > settings_->vx_histogram_max()))
648 if (
track.getTTTrackPtr()->chi2() > settings_->vx_TrackMaxChi2())
650 if (
track.pt() < settings_->vx_TrackMinPt())
654 float nPS = 0., nstubs = 0;
657 const auto& theStubs =
track.getTTTrackPtr()->getStubRefs();
658 if (theStubs.empty()) {
659 edm::LogWarning(
"VertexFinder") <<
"fastHisto::Could not retrieve the vector of stubs.";
664 for (
const auto& stub : theStubs) {
677 if (nstubs < settings_->vx_NStubMin())
679 if (nPS < settings_->vx_NStubPSMin())
683 int trk_nstub = (
int)
track.getTTTrackPtr()->getStubRefs().size();
684 float chi2dof =
track.getTTTrackPtr()->chi2() / (2 * trk_nstub - 4);
686 if (settings_->vx_DoPtComp()) {
687 float trk_consistency =
track.getTTTrackPtr()->stubPtConsistency();
688 if (trk_nstub == 4) {
695 if (settings_->vx_DoTightChi2()) {
696 if (
track.pt() > 10.0 && chi2dof > 5.0)
713 std::vector<float> bin_centers(settings_->vx_windowSize(), 0.0);
714 std::vector<unsigned int>
counts(settings_->vx_windowSize(), 0);
715 for (
unsigned int i = 0;
i < sums.size();
i++) {
716 for (
unsigned int j = 0;
j < settings_->vx_windowSize();
j++) {
717 bin_centers[
j] = settings_->vx_histogram_min() + ((
i +
j) * settings_->vx_histogram_binwidth()) +
718 (0.5 * settings_->vx_histogram_binwidth());
722 computeAndSetVertexParameters(sums.at(
i), bin_centers,
counts);
726 float sigma_max = -999;
728 std::vector<int>
found;
729 found.reserve(settings_->vx_nvtx());
730 for (
unsigned int ivtx = 0; ivtx < settings_->vx_nvtx(); ivtx++) {
733 for (
unsigned int i = 0;
i < sums.size();
i++) {
737 if (sums.at(
i).pt() > sigma_max) {
738 sigma_max = sums.at(
i).pt();
742 found.push_back(imax);
743 vertices_.emplace_back(sums.at(imax));
747 if (settings_->debug() >= 1) {
749 log <<
"fastHisto::Checking the output parameters ... \n";
750 std::vector<double>
tmp;
754 printHistogram<double, edm::LogInfo>(
log,
tmp, 80, 0, -1,
"fastHisto::sums",
"\e[92m");
755 for (
unsigned int i = 0;
i <
found.size();
i++) {
756 log <<
"RecoVertex " <<
i <<
": bin index = " <<
found[
i] <<
"\tsumPt = " << sums.at(imax).pt()
757 <<
"\tz0 = " << sums.at(imax).z0();
762 void VertexFinder::fastHistoEmulation() {
767 kReducedPrecisionPt = 7
773 kBinFixedMagSize = 5,
774 kSlidingSumSize = 11,
777 kWeightedSlidingSumSize = 20,
778 kWeightedSlidingSumMagSize = 10,
782 kSumPtWindowBits =
BitsToRepresent(kWindowSize * (1 << kSumPtLinkSize)),
784 kSumPtUntruncatedLinkSize = kPtSize + 2, kSumPtUntruncatedLinkMagSize =
kPtMagSize + 2;
786 static constexpr unsigned int kTableSize = ((1 << kSumPtLinkSize) - 1) * kWindowSize;
788 typedef ap_ufixed<kPtSize, kPtMagSize, AP_RND_CONV, AP_SAT>
pt_t;
790 typedef ap_int<kZ0Size>
z0_t;
793 typedef ap_ufixed<kReducedPrecisionPt, kReducedPrecisionPt, AP_RND_INF, AP_SAT> track_pt_fixed_t;
795 typedef ap_uint<kBinSize> histbin_t;
797 typedef ap_ufixed<kBinFixedSize, kBinFixedMagSize, AP_RND_INF, AP_SAT> histbin_fixed_t;
800 typedef ap_ufixed<kSumPtUntruncatedLinkSize, kSumPtUntruncatedLinkMagSize, AP_RND_INF, AP_SAT>
801 histbin_pt_sum_fixed_t;
803 typedef ap_ufixed<kSumPtLinkSize, kSumPtLinkSize, AP_RND_INF, AP_SAT> link_pt_sum_fixed_t;
805 typedef ap_ufixed<kSumPtWindowBits, kSumPtWindowBits, AP_RND_INF, AP_SAT> window_pt_sum_fixed_t;
807 typedef ap_fixed<kWeightedSlidingSumSize, kWeightedSlidingSumMagSize, AP_RND_INF, AP_SAT> zsliding_t;
809 typedef ap_uint<kSlidingSumSize> slidingsum_t;
811 typedef ap_ufixed<kInverseSize, kInverseMagSize, AP_RND_INF, AP_SAT> inverse_t;
813 auto track_quality_check = [&](
const track_pt_fixed_t&
pt) ->
bool {
815 if (
pt.to_double() < settings_->vx_TrackMinPt())
820 auto fetch_bin = [&](
const z0_t& z0,
int nbins) -> std::pair<histbin_t, bool> {
822 ap_int<kZ0Size + 1> z0_13 = z0;
824 ap_int<kZ0Size + 1> absz0_13 = z0_13 + (1 << (kZ0Size - 1));
826 ap_int<kZ0Size + 1> absz0_13_reduced = absz0_13 >> (kZ0Size - kBinFixedSize);
828 histbin_t
bin = absz0_13_reduced.range(kBinFixedSize - 1, 0);
830 if (settings_->debug() > 2) {
832 <<
"fastHistoEmulation::fetchBin() Checking the mapping from z0 to bin index ... \n" 833 <<
"histbin_fixed_t(1.0 / settings_->vx_histogram_binwidth()) = " 834 << histbin_fixed_t(1.0 / settings_->vx_histogram_binwidth()) <<
"\n" 835 <<
"histbin_t(std::floor(nbins / 2) = " << histbin_t(std::floor(
nbins / 2.)) <<
"\n" 836 <<
"z0 = " << z0 <<
"\n" 841 return std::make_pair(0,
false);
843 return std::make_pair(0,
false);
849 auto init_inversion_table = [&]() -> std::vector<inverse_t> {
850 std::vector<inverse_t> table_out(kTableSize, 0.);
851 for (
unsigned int ii = 0;
ii < kTableSize;
ii++) {
854 table_out.at(
ii) = (1.0 / (
ii + 1));
859 auto inversion = [&](slidingsum_t& data_den) -> inverse_t {
860 std::vector<inverse_t> inversion_table = init_inversion_table();
866 if (data_den > (kTableSize - 1))
867 data_den = kTableSize - 1;
869 return inversion_table.at(
index);
873 zsliding_t z = iz - histbin_t(std::floor(
nbins / 2.));
874 std::unique_ptr<edm::LogInfo>
log;
875 if (settings_->debug() >= 1) {
876 log = std::make_unique<edm::LogInfo>(
"VertexProducer");
877 *
log <<
"bin_center information ...\n" 878 <<
"iz = " << iz <<
"\n" 879 <<
"histbin_t(std::floor(nbins / 2.)) = " << histbin_t(std::floor(
nbins / 2.)) <<
"\n" 880 <<
"binwidth = " << zsliding_t(settings_->vx_histogram_binwidth()) <<
"\n" 881 <<
"z = " << z <<
"\n" 882 <<
"zsliding_t(z * zsliding_t(binwidth)) = " << std::setprecision(7)
888 auto weighted_position = [&](histbin_t b_max,
889 const std::vector<link_pt_sum_fixed_t>& binpt,
890 slidingsum_t maximums,
891 int nbins) -> zsliding_t {
892 zsliding_t zvtx_sliding = 0;
893 slidingsum_t zvtx_sliding_sum = 0;
896 std::unique_ptr<edm::LogInfo>
log;
897 if (settings_->debug() >= 1) {
898 log = std::make_unique<edm::LogInfo>(
"VertexProducer");
899 *
log <<
"Progression of weighted_position() ...\n" 900 <<
"zvtx_sliding_sum = ";
905 zvtx_sliding_sum += (binpt.at(
w) *
w);
906 if (settings_->debug() >= 1) {
907 *
log <<
"(" <<
w <<
" * " << binpt.at(
w) <<
")";
908 if (
w < kWindowSize - 1) {
914 if (settings_->debug() >= 1) {
915 *
log <<
" = " << zvtx_sliding_sum <<
"\n";
920 slidingsum_t offsetmaximums = maximums - 1;
921 inv = inversion(offsetmaximums);
922 zvtx_sliding = zvtx_sliding_sum * inv;
924 zvtx_sliding = (settings_->vx_windowSize() / 2.0) + (((
int(settings_->vx_windowSize()) % 2) != 0) ? 0.5 : 0.0);
926 if (settings_->debug() >= 1) {
927 *
log <<
"inversion(" << maximums <<
") = " << inv <<
"\nzvtx_sliding = " << zvtx_sliding <<
"\n";
931 zvtx_sliding += b_max;
932 zvtx_sliding += ap_ufixed<1, 0>(0.5);
933 if (settings_->debug() >= 1) {
934 *
log <<
"b_max = " << b_max <<
"\n";
935 *
log <<
"zvtx_sliding + b_max + 0.5 = " << zvtx_sliding <<
"\n";
939 zvtx_sliding = bin_center(zvtx_sliding,
nbins);
940 if (settings_->debug() >= 1) {
941 *
log <<
"bin_center(zvtx_sliding + b_max + 0.5, nbins) = " << std::setprecision(7) << zvtx_sliding;
948 unsigned int nbins = std::round((settings_->vx_histogram_max() - settings_->vx_histogram_min()) /
949 settings_->vx_histogram_binwidth());
950 unsigned int nsums =
nbins - settings_->vx_windowSize() + 1;
951 std::vector<link_pt_sum_fixed_t>
hist(
nbins, 0);
952 std::vector<histbin_pt_sum_fixed_t> hist_untruncated(
nbins, 0);
955 if (settings_->debug() > 2) {
956 edm::LogInfo(
"VertexProducer") <<
"fastHistoEmulation::Processing " << fitTracks_.size() <<
" tracks";
963 tkpt.V =
track.getTTTrackPtr()->getTrackWord()(TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1,
964 TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
965 z0_t tkZ0 =
track.getTTTrackPtr()->getZ0Word();
967 if ((settings_->vx_DoQualityCuts() && track_quality_check(tkpt)) || (!settings_->vx_DoQualityCuts())) {
971 std::pair<histbin_t, bool>
bin = fetch_bin(tkZ0,
nbins);
977 if (settings_->debug() > 2) {
978 edm::LogInfo(
"VertexProducer") <<
"fastHistoEmulation::Checking the track word ... \n" 979 <<
"track word = " <<
track.getTTTrackPtr()->getTrackWord().to_string(2)
981 <<
"tkZ0 = " << tkZ0.to_double() <<
"(" << tkZ0.to_string(2)
982 <<
")\ttkpt = " << tkpt.to_double() <<
"(" << tkpt.to_string(2)
983 <<
")\tbin = " <<
bin.first.to_int() <<
"\n" 984 <<
"pt sum in bin " <<
bin.first.to_int()
985 <<
" BEFORE adding track = " << hist_untruncated.at(
bin.first).to_double();
988 hist_untruncated.at(
bin.first) = hist_untruncated.at(
bin.first) + tkpt;
990 if (settings_->debug() > 2) {
991 edm::LogInfo(
"VertexProducer") <<
"fastHistoEmulation::\npt sum in bin " <<
bin.first.to_int()
992 <<
" AFTER adding track = " << hist_untruncated.at(
bin.first).to_double();
995 if (settings_->debug() > 2) {
996 edm::LogInfo(
"VertexProducer") <<
"fastHistoEmulation::Did not add the following track ... \n" 997 <<
"track word = " <<
track.getTTTrackPtr()->getTrackWord().to_string(2)
999 <<
"tkZ0 = " << tkZ0.to_double() <<
"(" << tkZ0.to_string(2)
1000 <<
")\ttkpt = " << tkpt.to_double() <<
"(" << tkpt.to_string(2) <<
")";
1008 for (
unsigned int hb = 0;
hb <
hist.size(); ++
hb) {
1009 link_pt_sum_fixed_t bin_trunc = hist_untruncated.at(
hb).range(
1010 kSumPtUntruncatedLinkSize - 1, kSumPtUntruncatedLinkSize - kSumPtUntruncatedLinkMagSize);
1012 if (settings_->debug() > 2) {
1013 edm::LogInfo(
"VertexProducer") <<
"fastHistoEmulation::truncating histogram bin pt once filling is complete \n" 1014 <<
"hist_untruncated.at(" <<
hb <<
") = " << hist_untruncated.at(
hb).to_double()
1015 <<
"(" << hist_untruncated.at(
hb).to_string(2)
1016 <<
")\tbin_trunc = " << bin_trunc.to_double() <<
"(" << bin_trunc.to_string(2)
1017 <<
")\n\thist.at(" <<
hb <<
") = " <<
hist.at(
hb).to_double() <<
"(" 1018 <<
hist.at(
hb).to_string(2) <<
")";
1024 std::vector<window_pt_sum_fixed_t> hist_window_sums(nsums, 0);
1025 for (
unsigned int b = 0;
b < nsums; ++
b) {
1026 for (
unsigned int w = 0;
w < kWindowSize; ++
w) {
1033 std::vector<int>
found;
1034 found.reserve(settings_->vx_nvtx());
1035 for (
unsigned int ivtx = 0; ivtx < settings_->vx_nvtx(); ivtx++) {
1036 histbin_t b_max = 0;
1037 window_pt_sum_fixed_t max_pt = 0;
1038 zsliding_t zvtx_sliding = -999;
1039 std::vector<link_pt_sum_fixed_t> binpt_max(kWindowSize, 0);
1042 for (
unsigned int i = 0;
i < hist_window_sums.size();
i++) {
1046 if (hist_window_sums.at(
i) > max_pt) {
1048 max_pt = hist_window_sums.at(b_max);
1049 std::copy(std::begin(
hist) + b_max, std::begin(
hist) + b_max + kWindowSize, std::begin(binpt_max));
1052 zvtx_sliding = weighted_position(b_max, binpt_max, max_pt,
nbins);
1055 if (settings_->debug() >= 1) {
1057 log <<
"fastHistoEmulation::Checking the output parameters ... \n";
1058 if (
found.empty()) {
1059 printHistogram<link_pt_sum_fixed_t, edm::LogInfo>(
log,
hist, 80, 0, -1,
"fastHistoEmulation::hist",
"\e[92m");
1060 printHistogram<window_pt_sum_fixed_t, edm::LogInfo>(
1061 log, hist_window_sums, 80, 0, -1,
"fastHistoEmulation::hist_window_sums",
"\e[92m");
1063 printHistogram<link_pt_sum_fixed_t, edm::LogInfo>(
1064 log, binpt_max, 80, 0, -1,
"fastHistoEmulation::binpt_max",
"\e[92m");
1065 log <<
"bin index (not a VertexWord parameter) = " << b_max <<
"\n" 1066 <<
"sumPt = " << max_pt.to_double() <<
"\n" 1067 <<
"z0 = " << zvtx_sliding.to_double();
1069 found.push_back(b_max);
1081 void VertexFinder::NNVtxEmulation(tensorflow::Session* TrackWeightSesh,
1082 tensorflow::Session* PatternRecSesh,
1083 tensorflow::Session* AssociationSesh) {
1086 tensorflow::Tensor inputTrkWeight(tensorflow::DT_FLOAT, {1, 3});
1089 for (
auto&
track : fitTracks_) {
1091 auto& gttTrack = fitTracks_.at(
counter);
1094 ap_fixed<16, 3> etaEmulation;
1095 etaEmulation.V = (etaEmulationBits.range());
1097 ap_uint<14> ptEmulationBits = gttTrack.getTTTrackPtr()->getTrackWord()(
1098 TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1, TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
1099 ap_ufixed<14, 9> ptEmulation;
1100 ptEmulation.V = (ptEmulationBits.range());
1102 ap_ufixed<22, 9> ptEmulation_rescale;
1103 ptEmulation_rescale = ptEmulation.to_double();
1105 ap_ufixed<22, 9> etaEmulation_rescale;
1106 etaEmulation_rescale =
abs(etaEmulation.to_double());
1108 ap_ufixed<22, 9> MVAEmulation_rescale;
1109 MVAEmulation_rescale = gttTrack.getTTTrackPtr()->getMVAQualityBits();
1111 inputTrkWeight.tensor<
float, 2>()(0, 0) = ptEmulation_rescale.to_double();
1112 inputTrkWeight.tensor<
float, 2>()(0, 1) = MVAEmulation_rescale.to_double();
1113 inputTrkWeight.tensor<
float, 2>()(0, 2) = etaEmulation_rescale.to_double();
1116 std::vector<tensorflow::Tensor> outputTrkWeight;
1117 tensorflow::run(TrackWeightSesh, {{
"weight:0", inputTrkWeight}}, {
"Identity:0"}, &outputTrkWeight);
1120 ap_ufixed<16, 5> NNOutput;
1121 NNOutput = (double)outputTrkWeight[0].tensor<float, 2>()(0, 0);
1125 track.setWeight(NNOutput.to_double());
1130 tensorflow::Tensor inputPV(tensorflow::DT_FLOAT,
1131 {1, settings_->vx_histogram_numbins(), 1});
1132 std::vector<tensorflow::Tensor> outputPV;
1134 std::map<float, int> vertexMap;
1135 std::map<int, float> histogram;
1136 std::map<int, float> nnOutput;
1138 float binWidth = settings_->vx_histogram_binwidth();
1142 for (
int z = 0; z < settings_->vx_histogram_numbins(); z += 1) {
1144 double vxWeight = 0;
1147 auto& gttTrack = fitTracks_.at(
counter);
1148 double temp_z0 = gttTrack.getTTTrackPtr()->z0();
1150 track_z = std::floor((temp_z0 + settings_->vx_histogram_max()) / binWidth);
1152 if (track_z >= z && track_z < (z + 1)) {
1154 vxWeight +=
track.weight();
1159 vertices.at(z).setZ0(((z + 0.5) * binWidth) - settings_->vx_histogram_max());
1161 vertexMap[vxWeight] = z;
1162 inputPV.tensor<
float, 3>()(0, z, 0) = vxWeight;
1164 histogram[z] = vxWeight;
1168 tensorflow::run(PatternRecSesh, {{
"hist:0", inputPV}}, {
"Identity:0"}, &outputPV);
1170 const float histogrammingThreshold_ = 0.0;
1171 for (
int i(0);
i < settings_->vx_histogram_numbins(); ++
i) {
1172 if (outputPV[0].tensor<float, 3>()(0,
i, 0) >= histogrammingThreshold_) {
1173 nnOutput[
i] = outputPV[0].tensor<
float, 3>()(0,
i, 0);
1181 float max_element = 0.0;
1182 for (
int i(0);
i < settings_->vx_histogram_numbins(); ++
i) {
1183 if (nnOutput[
i] > max_element) {
1184 max_element = nnOutput[
i];
1188 for (
int i(0);
i < settings_->vx_histogram_numbins(); ++
i) {
1189 if (nnOutput[
i] == max_element) {
1196 edm::LogVerbatim(
"VertexFinder") <<
" NNVtxEmulation Chosen PV: prob: " << nnOutput[PV_index]
1197 <<
" bin = " << PV_index <<
" z0 = " <<
vertices.at(PV_index).z0() <<
'\n';
1199 verticesEmulation_.emplace_back(1,
vertices.at(PV_index).z0(), 0,
vertices.at(PV_index).pt(), 0, 0, 0);
Log< level::Info, true > LogVerbatim
constexpr int32_t ceil(float num)
double pt() const
Sum of fitted tracks transverse momentum [GeV].
unsigned int tobLayer(const DetId &id) const
::ecal::reco::ComputationScalarType data_type
ap_uint< VertexBitWidths::kUnassignedSize > vtxunassigned_t
ap_ufixed< VertexBitWidths::kNTrackInPVSize, VertexBitWidths::kNTrackInPVSize, AP_RND_CONV, AP_SAT > vtxmultiplicity_t
std::vector< L1Track > FitTrackCollection
double z0() const
Vertex z0 position [cm].
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const std::vector< const T * > & tracks() const
Tracks in the vertex.
void insert(TP &tp)
Assign TP to this vertex.
ap_ufixed< VertexBitWidths::kNTrackOutPVSize, VertexBitWidths::kNTrackOutPVSize, AP_RND_CONV, AP_SAT > vtxinversemult_t
unsigned int numTracks() const
Number of tracks originating from this vertex.
ap_fixed< VertexBitWidths::kZ0Size, VertexBitWidths::kZ0MagSize, AP_RND_CONV, AP_SAT > vtxz0_t
static constexpr unsigned BitsToRepresent(unsigned x)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Simple wrapper class for TTTrack.
Abs< T >::type abs(const T &t)
ap_ufixed< VertexBitWidths::kSumPtSize, VertexBitWidths::kSumPtMagSize, AP_RND_CONV, AP_SAT > vtxsumpt_t
static constexpr auto TOB
ap_uint< VertexBitWidths::kQualitySize > vtxquality_t
Log< level::Info, false > LogInfo
std::vector< RecoVertex<> > RecoVertexCollection
const unsigned int kPtMagSize
char data[epos_bytes_allocation]
ap_uint< TrackBitWidths::kTanlSize > tanl_t
static std::atomic< unsigned int > counter
unsigned int tidRing(const DetId &id) const
size_t max_index(const std::vector< T > &v)
Log< level::Warning, false > LogWarning
static constexpr auto TID
Power< A, B >::type pow(const A &a, const B &b)
unsigned int numTracks() const
Number of tracks originating from this vertex.
ap_uint< VertexBitWidths::kValidSize > vtxvalid_t