20 template <
typename TILES>
24 criticalDensity_(conf.getParameter<double>(
"criticalDensity")),
25 criticalSelfDensity_(conf.getParameter<double>(
"criticalSelfDensity")),
26 densitySiblingLayers_(conf.getParameter<
int>(
"densitySiblingLayers")),
27 densityEtaPhiDistanceSqr_(conf.getParameter<double>(
"densityEtaPhiDistanceSqr")),
28 densityXYDistanceSqr_(conf.getParameter<double>(
"densityXYDistanceSqr")),
29 kernelDensityFactor_(conf.getParameter<double>(
"kernelDensityFactor")),
30 densityOnSameLayer_(conf.getParameter<
bool>(
"densityOnSameLayer")),
31 nearestHigherOnSameLayer_(conf.getParameter<
bool>(
"nearestHigherOnSameLayer")),
32 useAbsoluteProjectiveScale_(conf.getParameter<
bool>(
"useAbsoluteProjectiveScale")),
33 useClusterDimensionXY_(conf.getParameter<
bool>(
"useClusterDimensionXY")),
34 rescaleDensityByZ_(conf.getParameter<
bool>(
"rescaleDensityByZ")),
35 criticalEtaPhiDistance_(conf.getParameter<double>(
"criticalEtaPhiDistance")),
36 criticalXYDistance_(conf.getParameter<double>(
"criticalXYDistance")),
37 criticalZDistanceLyr_(conf.getParameter<
int>(
"criticalZDistanceLyr")),
38 outlierMultiplier_(conf.getParameter<double>(
"outlierMultiplier")),
39 minNumLayerCluster_(conf.getParameter<
int>(
"minNumLayerCluster")),
40 eidInputName_(conf.getParameter<
std::
string>(
"eid_input_name")),
41 eidOutputNameEnergy_(conf.getParameter<
std::
string>(
"eid_output_name_energy")),
42 eidOutputNameId_(conf.getParameter<
std::
string>(
"eid_output_name_id")),
43 eidMinClusterEnergy_(conf.getParameter<double>(
"eid_min_cluster_energy")),
44 eidNLayers_(conf.getParameter<
int>(
"eid_n_layers")),
45 eidNClusters_(conf.getParameter<
int>(
"eid_n_clusters")){};
47 template <
typename TILES>
51 auto lastLayerPerSide =
static_cast<int>(rhtools_.lastLayer(
false));
52 int maxLayer = 2 * lastLayerPerSide - 1;
56 for (
int phi = 0; phi < nPhiBin; phi++) {
57 int iphi = ((phi % nPhiBin + nPhiBin) % nPhiBin);
59 if (this->algo_verbosity_ > this->Advanced) {
69 template <
typename TILES>
71 const int eventNumber,
72 const std::vector<Trackster> &tracksters)
const {
75 <<
"[evt, tracksterId, cells, prob_photon, prob_ele, prob_chad, prob_nhad, layer_i, x_i, y_i, eta_i, phi_i, " 76 "energy_i, radius_i, rho_i, z_extension, delta_tr, delta_lyr, isSeed_i";
81 for (
auto const &
t : tracksters) {
82 for (
auto v :
t.vertices()) {
83 auto [lyrIdx, soaIdx] = layerIdx2layerandSoa[
v];
84 auto const &thisLayer = clusters_[lyrIdx];
87 << std::setw(4) << eventNumber << sep << std::setw(4) <<
num << sep << std::setw(4) <<
t.vertices().size()
92 << std::setw(10) << thisLayer.x[soaIdx] << sep << std::setw(10) << thisLayer.y[soaIdx] << sep
93 << std::setw(10) << thisLayer.eta[soaIdx] << sep << std::setw(10) << thisLayer.phi[soaIdx] << sep
94 << std::setw(10) << thisLayer.energy[soaIdx] << sep << std::setw(10) << thisLayer.radius[soaIdx] << sep
95 << std::setw(10) << thisLayer.rho[soaIdx] << sep << std::setw(10) << thisLayer.z_extension[soaIdx] << sep
96 << std::setw(10) << thisLayer.delta[soaIdx].first << sep << std::setw(10) << thisLayer.delta[soaIdx].second
97 << sep << std::setw(4) << thisLayer.isSeed[soaIdx];
104 template <
typename TILES>
106 const std::vector<std::pair<int, int>> &layerIdx2layerandSoa,
107 const int eventNumber)
const {
109 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"[evt, lyr, Seed, x, y, z, r/|z|, eta, phi, " 110 "etab, phib, cells, enrgy, e/rho, rho, z_ext, " 112 " nestHL, nestHSoaIdx, radius, clIdx, lClOrigIdx, SOAidx";
116 auto const &thisLayer = clusters_[
layer];
118 for (
auto v : thisLayer.x) {
121 << std::setw(4) << eventNumber <<
", " << std::setw(3) <<
layer <<
", " << std::setw(4)
122 << thisLayer.isSeed[
num] <<
", " << std::setprecision(3) <<
std::fixed <<
v <<
", " << thisLayer.y[
num]
123 <<
", " << thisLayer.z[
num] <<
", " << thisLayer.r_over_absz[
num] <<
", " << thisLayer.eta[
num] <<
", " 124 << thisLayer.phi[
num] <<
", " << std::setw(5) << tiles[
layer].etaBin(thisLayer.eta[
num]) <<
", " 125 << std::setw(5) << tiles[
layer].phiBin(thisLayer.phi[
num]) <<
", " << std::setw(4) << thisLayer.cells[
num]
126 <<
", " << std::setprecision(3) << thisLayer.energy[
num] <<
", " 127 << (thisLayer.energy[
num] / thisLayer.rho[
num]) <<
", " << thisLayer.rho[
num] <<
", " 128 << thisLayer.z_extension[
num] <<
", " << std::scientific << thisLayer.delta[
num].first <<
", " 129 << std::setw(10) << thisLayer.delta[
num].second <<
", " << std::setw(5)
130 << thisLayer.nearestHigher[
num].first <<
", " << std::setw(10) << thisLayer.nearestHigher[
num].second
131 <<
", " << std::defaultfloat << std::setprecision(3) << thisLayer.radius[
num] <<
", " << std::setw(5)
132 << thisLayer.clusterIndex[
num] <<
", " << std::setw(4) << thisLayer.layerClusterOriginalIdx[
num] <<
", " 133 << std::setw(4) <<
num <<
", ClusterInfo";
138 for (
unsigned int lcIdx = 0; lcIdx < layerIdx2layerandSoa.size(); lcIdx++) {
139 auto const &layerandSoa = layerIdx2layerandSoa[lcIdx];
141 if ((layerandSoa.first == -1) && (layerandSoa.second == -1))
145 <<
"lcIdx: " << lcIdx <<
" on Layer: " << layerandSoa.first <<
" SOA: " << layerandSoa.second;
150 template <
typename TILES>
153 std::vector<Trackster> &
result,
154 std::unordered_map<
int, std::vector<int>> &seedToTracksterAssociation) {
156 if (
input.regions.empty())
159 const int eventNumber =
input.ev.eventAuxiliary().event();
166 rhtools_.setGeometry(
geom);
170 for (
unsigned int i = 0;
i < rhtools_.lastLayer(); ++
i) {
171 layersPosZ_.push_back(rhtools_.getPositionLayer(
i + 1).z());
173 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Layer " <<
i <<
" located at Z: " << layersPosZ_.back();
178 clusters_.resize(2 * rhtools_.lastLayer(
false));
179 std::vector<std::pair<int, int>> layerIdx2layerandSoa;
181 layerIdx2layerandSoa.reserve(
input.layerClusters.size());
182 unsigned int layerIdx = 0;
183 for (
auto const &lc :
input.layerClusters) {
184 if (
input.mask[layerIdx] == 0.) {
186 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Skipping masked cluster: " << layerIdx;
188 layerIdx2layerandSoa.emplace_back(-1, -1);
192 const auto firstHitDetId = lc.hitsAndFractions()[0].first;
193 int layer = rhtools_.getLayerWithOffset(firstHitDetId) - 1 +
194 rhtools_.lastLayer(
false) * ((rhtools_.zside(firstHitDetId) + 1) >> 1);
196 auto detId = lc.hitsAndFractions()[0].first;
198 layerIdx2layerandSoa.emplace_back(
layer, clusters_[
layer].
x.size());
201 float sum_sqr_x = 0.;
202 float sum_sqr_y = 0.;
203 float ref_x = lc.x();
204 float ref_y = lc.y();
205 float invClsize = 1. / lc.hitsAndFractions().size();
206 for (
auto const &hitsAndFractions : lc.hitsAndFractions()) {
207 auto const &
point = rhtools_.getPosition(hitsAndFractions.first);
209 sum_sqr_x += (
point.x() - ref_x) * (
point.x() - ref_x);
211 sum_sqr_y += (
point.y() - ref_y) * (
point.y() - ref_y);
218 float radius_x =
sqrt((sum_sqr_x - (
sum_x *
sum_x) * invClsize) * invClsize);
219 float radius_y =
sqrt((sum_sqr_y - (
sum_y *
sum_y) * invClsize) * invClsize);
222 <<
"cluster rx: " << std::setw(5) << radius_x <<
", ry: " << std::setw(5) << radius_y
223 <<
", r: " << std::setw(5) << (radius_x + radius_y) <<
", cells: " << std::setw(4)
224 << lc.hitsAndFractions().size();
229 if (invClsize == 1.) {
231 if (rhtools_.isSilicon(detId)) {
232 radius_x = radius_y = rhtools_.getRadiusToSide(detId);
234 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Single cell cluster in silicon, rx: " << std::setw(5)
235 << radius_x <<
", ry: " << std::setw(5) << radius_y;
238 auto const &
point = rhtools_.getPosition(detId);
239 auto const &eta_phi_window = rhtools_.getScintDEtaDPhi(detId);
240 radius_x = radius_y =
point.perp() * eta_phi_window.second;
243 <<
"Single cell cluster in scintillator. rx: " << std::setw(5) << radius_x <<
", ry: " << std::setw(5)
244 << radius_y <<
", eta-span: " << std::setw(5) << eta_phi_window.first <<
", phi-span: " << std::setw(5)
245 << eta_phi_window.second;
249 clusters_[
layer].x.emplace_back(lc.x());
250 clusters_[
layer].y.emplace_back(lc.y());
251 clusters_[
layer].z.emplace_back(lc.z());
252 clusters_[
layer].r_over_absz.emplace_back(
sqrt(lc.x() * lc.x() + lc.y() * lc.y()) /
std::abs(lc.z()));
253 clusters_[
layer].radius.emplace_back(radius_x + radius_y);
254 clusters_[
layer].eta.emplace_back(lc.eta());
255 clusters_[
layer].phi.emplace_back(lc.phi());
256 clusters_[
layer].cells.push_back(lc.hitsAndFractions().size());
257 clusters_[
layer].isSilicon.push_back(rhtools_.isSilicon(detId));
258 clusters_[
layer].energy.emplace_back(lc.energy());
259 clusters_[
layer].isSeed.push_back(
false);
260 clusters_[
layer].clusterIndex.emplace_back(-1);
261 clusters_[
layer].layerClusterOriginalIdx.emplace_back(layerIdx++);
262 clusters_[
layer].nearestHigher.emplace_back(-1, -1);
263 clusters_[
layer].rho.emplace_back(0.
f);
264 clusters_[
layer].z_extension.emplace_back(0.
f);
265 clusters_[
layer].delta.emplace_back(
269 clusters_[
layer].followers.resize(clusters_[
layer].
x.size());
272 auto lastLayerPerSide =
static_cast<int>(rhtools_.lastLayer(
false));
273 int maxLayer = 2 * lastLayerPerSide - 1;
274 std::vector<int> numberOfClustersPerLayer(maxLayer, 0);
275 for (
int i = 0;
i <= maxLayer;
i++) {
276 calculateLocalDensity(
input.tiles,
i, layerIdx2layerandSoa);
278 for (
int i = 0;
i <= maxLayer;
i++) {
279 calculateDistanceToHigher(
input.tiles,
i, layerIdx2layerandSoa);
282 auto nTracksters = findAndAssignTracksters(
input.tiles, layerIdx2layerandSoa);
284 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Reconstructed " << nTracksters <<
" tracksters" << std::endl;
285 dumpClusters(
input.tiles, layerIdx2layerandSoa, eventNumber);
289 result.resize(nTracksters);
292 const auto &thisLayer = clusters_[
layer];
296 for (
unsigned int lc = 0; lc < thisLayer.x.size(); ++lc) {
298 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Trackster " << thisLayer.clusterIndex[lc];
300 if (thisLayer.clusterIndex[lc] >= 0) {
302 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
" adding lcIdx: " << thisLayer.layerClusterOriginalIdx[lc];
304 result[thisLayer.clusterIndex[lc]].vertices().push_back(thisLayer.layerClusterOriginalIdx[lc]);
305 result[thisLayer.clusterIndex[lc]].vertex_multiplicity().push_back(1);
307 for (
auto [follower_lyrIdx, follower_soaIdx] : thisLayer.followers[lc]) {
308 std::array<unsigned int, 2> edge = {
309 {(
unsigned int)thisLayer.layerClusterOriginalIdx[lc],
310 (
unsigned int)clusters_[follower_lyrIdx].layerClusterOriginalIdx[follower_soaIdx]}};
311 result[thisLayer.clusterIndex[lc]].edges().push_back(edge);
318 std::remove_if(std::begin(
result),
320 [&](
auto const &
v) {
return static_cast<int>(
v.vertices().size()) < minNumLayerCluster_; }),
326 input.layerClustersTime,
327 rhtools_.getPositionLayer(rhtools_.lastLayerEE(
false),
false).z());
333 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Barycenter: " <<
t.barycenter();
334 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"LCs: " <<
t.vertices().size();
336 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Regressed: " <<
t.regressed_energy();
342 dumpTracksters(layerIdx2layerandSoa, eventNumber,
result);
352 template <
typename TILES>
354 const tensorflow::Session *eidSession,
355 std::vector<Trackster> &tracksters) {
379 std::vector<int> tracksterIndices;
380 for (
int i = 0; i < static_cast<int>(tracksters.size());
i++) {
384 float sumClusterEnergy = 0.;
388 if (sumClusterEnergy >= eidMinClusterEnergy_) {
390 tracksters[
i].setRegressedEnergy(0.
f);
391 tracksters[
i].zeroProbabilities();
392 tracksterIndices.push_back(
i);
399 int batchSize =
static_cast<int>(tracksterIndices.size());
400 if (batchSize == 0) {
405 tensorflow::TensorShape shape({batchSize, eidNLayers_, eidNClusters_, eidNFeatures_});
406 tensorflow::Tensor
input(tensorflow::DT_FLOAT, shape);
409 std::vector<tensorflow::Tensor>
outputs;
411 if (!eidOutputNameEnergy_.empty()) {
414 if (!eidOutputNameId_.empty()) {
419 for (
int i = 0;
i < batchSize;
i++) {
420 const Trackster &trackster = tracksters[tracksterIndices[
i]];
425 std::vector<int> clusterIndices(trackster.
vertices().size());
427 clusterIndices[
k] =
k;
429 sort(clusterIndices.begin(), clusterIndices.end(), [&
layerClusters, &trackster](
const int &
a,
const int &
b) {
434 std::vector<int> seenClusters(eidNLayers_);
437 for (
const int &
k : clusterIndices) {
441 if (
j < eidNLayers_ && seenClusters[
j] < eidNClusters_) {
456 for (
int j = 0;
j < eidNLayers_;
j++) {
457 for (
int k = seenClusters[
j];
k < eidNClusters_;
k++) {
459 for (
int l = 0;
l < eidNFeatures_;
l++) {
470 if (!eidOutputNameEnergy_.empty()) {
474 for (
const int &
i : tracksterIndices) {
475 tracksters[
i].setRegressedEnergy(*(
energy++));
480 if (!eidOutputNameId_.empty()) {
482 int probsIdx = eidOutputNameEnergy_.empty() ? 0 : 1;
483 float *probs =
outputs[probsIdx].flat<
float>().
data();
485 for (
const int &
i : tracksterIndices) {
486 tracksters[
i].setProbabilities(probs);
487 probs += tracksters[
i].id_probabilities().size();
492 template <
typename TILES>
494 const TILES &tiles,
const int layerId,
const std::vector<std::pair<int, int>> &layerIdx2layerandSoa) {
497 auto &clustersOnLayer = clusters_[layerId];
498 unsigned int numberOfClusters = clustersOnLayer.x.size();
500 auto isReachable = [](
float r0,
float r1,
float phi0,
float phi1,
float delta_sqr) ->
bool {
504 auto distance_debug = [&](
float x1,
float x2,
float y1,
float y2) ->
float {
508 for (
unsigned int i = 0;
i < numberOfClusters;
i++) {
510 auto lastLayerPerSide =
static_cast<int>(rhtools_.lastLayer(
false));
512 int maxLayer = 2 * lastLayerPerSide - 1;
513 if (layerId < lastLayerPerSide) {
515 maxLayer =
std::min(layerId + densitySiblingLayers_, lastLayerPerSide - 1);
518 maxLayer =
std::min(layerId + densitySiblingLayers_, maxLayer);
520 float deltaLayersZ =
std::abs(layersPosZ_[maxLayer % lastLayerPerSide] - layersPosZ_[
minLayer % lastLayerPerSide]);
522 for (
int currentLayer =
minLayer; currentLayer <= maxLayer; currentLayer++) {
524 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"RefLayer: " << layerId <<
" SoaIDX: " <<
i;
525 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"NextLayer: " << currentLayer;
527 const auto &tileOnLayer = tiles[currentLayer];
528 bool onSameLayer = (currentLayer == layerId);
530 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"onSameLayer: " << onSameLayer;
532 const int etaWindow = 2;
534 int etaBinMin =
std::max(tileOnLayer.etaBin(clustersOnLayer.eta[
i]) - etaWindow, 0);
535 int etaBinMax =
std::min(tileOnLayer.etaBin(clustersOnLayer.eta[
i]) + etaWindow, nEtaBin);
536 int phiBinMin = tileOnLayer.phiBin(clustersOnLayer.phi[
i]) -
phiWindow;
537 int phiBinMax = tileOnLayer.phiBin(clustersOnLayer.phi[
i]) +
phiWindow;
539 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"eta: " << clustersOnLayer.eta[
i];
540 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"phi: " << clustersOnLayer.phi[
i];
541 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"etaBinMin: " << etaBinMin <<
", etaBinMax: " << etaBinMax;
542 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"phiBinMin: " << phiBinMin <<
", phiBinMax: " << phiBinMax;
549 for (
int iphi_it = phiBinMin; iphi_it <= phiBinMax; ++iphi_it) {
550 int iphi = ((iphi_it % nPhiBin + nPhiBin) % nPhiBin);
554 <<
"Entries in tileBin: " << tileOnLayer[
offset +
iphi].size();
556 for (
auto otherClusterIdx : tileOnLayer[
offset +
iphi]) {
557 auto const &layerandSoa = layerIdx2layerandSoa[otherClusterIdx];
559 if ((layerandSoa.first == -1) && (layerandSoa.second == -1)) {
561 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Skipping masked layerIdx " << otherClusterIdx;
565 auto const &clustersLayer = clusters_[layerandSoa.first];
568 <<
"OtherLayer: " << layerandSoa.first <<
" SoaIDX: " << layerandSoa.second;
569 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"OtherEta: " << clustersLayer.eta[layerandSoa.second];
570 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"OtherPhi: " << clustersLayer.phi[layerandSoa.second];
572 bool reachable =
false;
573 if (useAbsoluteProjectiveScale_) {
574 if (useClusterDimensionXY_) {
575 reachable = isReachable(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
576 clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
577 clustersOnLayer.phi[
i],
578 clustersLayer.phi[layerandSoa.second],
579 clustersOnLayer.radius[
i] * clustersOnLayer.radius[
i]);
583 if (clustersOnLayer.isSilicon[
i]) {
584 reachable = isReachable(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
585 clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
586 clustersOnLayer.phi[
i],
587 clustersLayer.phi[layerandSoa.second],
588 densityXYDistanceSqr_);
590 reachable = isReachable(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
591 clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
592 clustersOnLayer.phi[
i],
593 clustersLayer.phi[layerandSoa.second],
594 clustersOnLayer.radius[
i] * clustersOnLayer.radius[
i]);
599 clustersOnLayer.phi[
i],
600 clustersLayer.eta[layerandSoa.second],
601 clustersLayer.phi[layerandSoa.second]) < densityEtaPhiDistanceSqr_);
606 clustersOnLayer.phi[
i],
607 clustersLayer.eta[layerandSoa.second],
608 clustersLayer.phi[layerandSoa.second]);
609 auto dist = distance_debug(
610 clustersOnLayer.r_over_absz[
i],
611 clustersLayer.r_over_absz[layerandSoa.second],
612 clustersOnLayer.r_over_absz[
i] *
std::abs(clustersOnLayer.phi[
i]),
613 clustersLayer.r_over_absz[layerandSoa.second] *
std::abs(clustersLayer.phi[layerandSoa.second]));
614 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Distance[cm]: " << (dist * clustersOnLayer.z[
i]);
616 <<
"Energy Other: " << clustersLayer.energy[layerandSoa.second];
617 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Cluster radius: " << clustersOnLayer.radius[
i];
620 float factor_same_layer_different_cluster = (onSameLayer && !densityOnSameLayer_) ? 0.
f : 1.
f;
621 auto energyToAdd = (clustersOnLayer.layerClusterOriginalIdx[
i] == otherClusterIdx
623 : kernelDensityFactor_ * factor_same_layer_different_cluster) *
624 clustersLayer.energy[layerandSoa.second];
625 clustersOnLayer.rho[
i] += energyToAdd;
626 clustersOnLayer.z_extension[
i] = deltaLayersZ;
629 <<
"Adding " << energyToAdd <<
" partial " << clustersOnLayer.rho[
i];
636 if (rescaleDensityByZ_) {
639 <<
"Rescaling original density: " << clustersOnLayer.rho[
i] <<
" by Z: " << deltaLayersZ
640 <<
" to final density/cm: " << clustersOnLayer.rho[
i] / deltaLayersZ;
642 clustersOnLayer.rho[
i] /= deltaLayersZ;
647 template <
typename TILES>
649 const TILES &tiles,
const int layerId,
const std::vector<std::pair<int, int>> &layerIdx2layerandSoa) {
652 auto &clustersOnLayer = clusters_[layerId];
653 unsigned int numberOfClusters = clustersOnLayer.x.size();
655 auto distanceSqr = [](
float r0,
float r1,
float phi0,
float phi1) ->
float {
660 for (
unsigned int i = 0;
i < numberOfClusters;
i++) {
663 <<
"Starting searching nearestHigher on " << layerId <<
" with rho: " << clustersOnLayer.rho[
i]
664 <<
" at eta, phi: " << tiles[layerId].etaBin(clustersOnLayer.eta[
i]) <<
", " 665 << tiles[layerId].phiBin(clustersOnLayer.phi[
i]);
668 auto lastLayerPerSide =
static_cast<int>(rhtools_.lastLayer(
false));
670 int maxLayer = 2 * lastLayerPerSide - 1;
671 if (layerId < lastLayerPerSide) {
673 maxLayer =
std::min(layerId + densitySiblingLayers_, lastLayerPerSide - 1);
676 maxLayer =
std::min(layerId + densitySiblingLayers_, maxLayer);
680 std::pair<int, int> i_nearestHigher(-1, -1);
682 for (
int currentLayer =
minLayer; currentLayer <= maxLayer; currentLayer++) {
683 if (!nearestHigherOnSameLayer_ && (layerId == currentLayer))
685 const auto &tileOnLayer = tiles[currentLayer];
688 int etaBinMin =
std::max(tileOnLayer.etaBin(clustersOnLayer.eta[
i]) - etaWindow, 0);
689 int etaBinMax =
std::min(tileOnLayer.etaBin(clustersOnLayer.eta[
i]) + etaWindow, nEtaBin);
690 int phiBinMin = tileOnLayer.phiBin(clustersOnLayer.phi[
i]) -
phiWindow;
691 int phiBinMax = tileOnLayer.phiBin(clustersOnLayer.phi[
i]) +
phiWindow;
694 for (
int iphi_it = phiBinMin; iphi_it <= phiBinMax; ++iphi_it) {
695 int iphi = ((iphi_it % nPhiBin + nPhiBin) % nPhiBin);
698 <<
"Searching nearestHigher on " << currentLayer <<
" eta, phi: " <<
ieta <<
", " << iphi_it <<
" " 701 for (
auto otherClusterIdx : tileOnLayer[
offset +
iphi]) {
702 auto const &layerandSoa = layerIdx2layerandSoa[otherClusterIdx];
704 if ((layerandSoa.first == -1) && (layerandSoa.second == -1))
706 auto const &clustersOnOtherLayer = clusters_[layerandSoa.first];
709 int dist_layers =
std::abs(layerandSoa.first - layerId);
710 if (useAbsoluteProjectiveScale_) {
711 dist_transverse = distanceSqr(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
712 clustersOnOtherLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
713 clustersOnLayer.phi[
i],
714 clustersOnOtherLayer.phi[layerandSoa.second]);
716 dist = dist_transverse;
719 clustersOnLayer.phi[
i],
720 clustersOnOtherLayer.eta[layerandSoa.second],
721 clustersOnOtherLayer.phi[layerandSoa.second]);
722 dist_transverse = dist;
724 bool foundHigher = (clustersOnOtherLayer.rho[layerandSoa.second] > clustersOnLayer.rho[
i]) ||
725 (clustersOnOtherLayer.rho[layerandSoa.second] == clustersOnLayer.rho[
i] &&
726 clustersOnOtherLayer.layerClusterOriginalIdx[layerandSoa.second] >
727 clustersOnLayer.layerClusterOriginalIdx[
i]);
730 <<
"Searching nearestHigher on " << currentLayer
731 <<
" with rho: " << clustersOnOtherLayer.rho[layerandSoa.second]
732 <<
" on layerIdxInSOA: " << layerandSoa.first <<
", " << layerandSoa.second
733 <<
" with distance: " <<
sqrt(dist) <<
" foundHigher: " << foundHigher;
735 if (foundHigher && dist <= i_delta) {
738 nearest_distances = std::make_pair(
sqrt(dist_transverse), dist_layers);
740 i_nearestHigher = layerandSoa;
747 bool foundNearestInFiducialVolume = (i_delta !=
maxDelta);
750 <<
"i_delta: " << i_delta <<
" passed: " << foundNearestInFiducialVolume <<
" " << i_nearestHigher.first
751 <<
" " << i_nearestHigher.second <<
" distances: " << nearest_distances.first <<
", " 752 << nearest_distances.second;
754 if (foundNearestInFiducialVolume) {
755 clustersOnLayer.delta[
i] = nearest_distances;
756 clustersOnLayer.nearestHigher[
i] = i_nearestHigher;
761 clustersOnLayer.nearestHigher[
i] = {-1, -1};
766 template <
typename TILES>
768 const TILES &tiles,
const std::vector<std::pair<int, int>> &layerIdx2layerandSoa) {
769 unsigned int nTracksters = 0;
771 std::vector<std::pair<int, int>> localStack;
772 auto critical_transverse_distance = useAbsoluteProjectiveScale_ ? criticalXYDistance_ : criticalEtaPhiDistance_;
774 for (
unsigned int layer = 0;
layer < 2 * rhtools_.lastLayer();
layer++) {
775 auto &clustersOnLayer = clusters_[
layer];
776 unsigned int numberOfClusters = clustersOnLayer.x.size();
777 for (
unsigned int i = 0;
i < numberOfClusters;
i++) {
779 clustersOnLayer.clusterIndex[
i] = -1;
780 bool isSeed = (clustersOnLayer.delta[
i].first > critical_transverse_distance ||
781 clustersOnLayer.delta[
i].second > criticalZDistanceLyr_) &&
782 (clustersOnLayer.rho[
i] >= criticalDensity_) &&
783 (clustersOnLayer.energy[
i] / clustersOnLayer.rho[
i] > criticalSelfDensity_);
784 if (!clustersOnLayer.isSilicon[
i]) {
785 isSeed = (clustersOnLayer.delta[
i].first > clustersOnLayer.radius[
i] ||
786 clustersOnLayer.delta[
i].second > criticalZDistanceLyr_) &&
787 (clustersOnLayer.rho[
i] >= criticalDensity_) &&
788 (clustersOnLayer.energy[
i] / clustersOnLayer.rho[
i] > criticalSelfDensity_);
790 bool isOutlier = (clustersOnLayer.delta[
i].first > outlierMultiplier_ * critical_transverse_distance) &&
791 (clustersOnLayer.rho[
i] < criticalDensity_);
795 <<
"Found seed on Layer " <<
layer <<
" SOAidx: " <<
i <<
" assigned ClusterIdx: " << nTracksters;
797 clustersOnLayer.clusterIndex[
i] = nTracksters++;
798 clustersOnLayer.isSeed[
i] =
true;
799 localStack.emplace_back(
layer,
i);
800 }
else if (!isOutlier) {
801 auto [lyrIdx, soaIdx] = clustersOnLayer.nearestHigher[
i];
804 <<
"Found follower on Layer " <<
layer <<
" SOAidx: " <<
i <<
" attached to cluster on layer: " << lyrIdx
805 <<
" SOAidx: " << soaIdx;
808 clusters_[lyrIdx].followers[soaIdx].emplace_back(
layer,
i);
812 <<
"Found Outlier on Layer " <<
layer <<
" SOAidx: " <<
i <<
" with rho: " << clustersOnLayer.rho[
i]
813 <<
" and delta: " << clustersOnLayer.delta[
i].first <<
", " << clustersOnLayer.delta[
i].second;
820 while (!localStack.empty()) {
821 auto [lyrIdx, soaIdx] = localStack.back();
822 auto &thisSeed = clusters_[lyrIdx].followers[soaIdx];
823 localStack.pop_back();
826 for (
auto [follower_lyrIdx, follower_soaIdx] : thisSeed) {
828 clusters_[follower_lyrIdx].clusterIndex[follower_soaIdx] = clusters_[lyrIdx].clusterIndex[soaIdx];
830 localStack.emplace_back(follower_lyrIdx, follower_soaIdx);
836 template <
typename TILES>
838 iDesc.
add<
int>(
"algo_verbosity", 0);
839 iDesc.
add<
double>(
"criticalDensity", 4)->setComment(
"in GeV");
840 iDesc.
add<
double>(
"criticalSelfDensity", 0.15 )
841 ->setComment(
"Minimum ratio of self_energy/local_density to become a seed.");
842 iDesc.
add<
int>(
"densitySiblingLayers", 3)
844 "inclusive, layers to consider while computing local density and searching for nearestHigher higher");
845 iDesc.
add<
double>(
"densityEtaPhiDistanceSqr", 0.0008);
846 iDesc.
add<
double>(
"densityXYDistanceSqr", 3.24 )
847 ->setComment(
"in cm, 2.6*2.6, distance on the transverse plane to consider for local density");
848 iDesc.
add<
double>(
"kernelDensityFactor", 0.2)
849 ->
setComment(
"Kernel factor to be applied to other LC while computing the local density");
850 iDesc.
add<
bool>(
"densityOnSameLayer",
false);
851 iDesc.
add<
bool>(
"nearestHigherOnSameLayer",
false)
852 ->setComment(
"Allow the nearestHigher to be located on the same layer");
853 iDesc.
add<
bool>(
"useAbsoluteProjectiveScale",
true)
854 ->setComment(
"Express all cuts in terms of r/z*z_0{,phi} projective variables");
855 iDesc.
add<
bool>(
"useClusterDimensionXY",
false)
857 "Boolean. If true use the estimated cluster radius to determine the cluster compatibility while computing " 858 "the local density");
859 iDesc.
add<
bool>(
"rescaleDensityByZ",
false)
861 "Rescale local density by the extension of the Z 'volume' explored. The transvere dimension is, at present, " 862 "fixed and factored out.");
863 iDesc.
add<
double>(
"criticalEtaPhiDistance", 0.025)
864 ->
setComment(
"Minimal distance in eta,phi space from nearestHigher to become a seed");
865 iDesc.
add<
double>(
"criticalXYDistance", 1.8)
866 ->
setComment(
"Minimal distance in cm on the XY plane from nearestHigher to become a seed");
867 iDesc.
add<
int>(
"criticalZDistanceLyr", 5)
868 ->setComment(
"Minimal distance in layers along the Z axis from nearestHigher to become a seed");
869 iDesc.
add<
double>(
"outlierMultiplier", 2);
870 iDesc.
add<
int>(
"minNumLayerCluster", 2)->setComment(
"Not Inclusive");
872 iDesc.
add<
std::string>(
"eid_output_name_energy",
"output/regressed_energy");
873 iDesc.
add<
std::string>(
"eid_output_name_id",
"output/id_probabilities");
874 iDesc.
add<
double>(
"eid_min_cluster_energy", 1.);
875 iDesc.
add<
int>(
"eid_n_layers", 50);
876 iDesc.
add<
int>(
"eid_n_clusters", 10);
constexpr double deltaPhi(double phi1, double phi2)
Log< level::Info, true > LogVerbatim
void setComment(std::string const &value)
std::vector< NamedTensor > NamedTensorList
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result)
void dumpTiles(const TILES &) const
PatternRecognitionbyCLUE3D(const edm::ParameterSet &conf, edm::ConsumesCollector)
double phi() const
azimuthal angle of cluster centroid
void calculateDistanceToHigher(const TILES &, const int layerId, const std::vector< std::pair< int, int >> &)
constexpr std::array< uint8_t, layerIndexSize > layer
static std::string const input
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool energyWeight=true)
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
void makeTracksters(const typename PatternRecognitionAlgoBaseT< TILES >::Inputs &input, std::vector< Trackster > &result, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) override
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Abs< T >::type abs(const T &t)
int findAndAssignTracksters(const TILES &, const std::vector< std::pair< int, int >> &)
bool getData(T &iHolder) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double energy() const
cluster energy
std::vector< unsigned int > & vertices()
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
void dumpClusters(const TILES &tiles, const std::vector< std::pair< int, int >> &layerIdx2layerandSoa, const int) const
std::vector< float > & vertex_multiplicity()
void calculateLocalDensity(const TILES &, const int layerId, const std::vector< std::pair< int, int >> &)
char data[epos_bytes_allocation]
double eta() const
pseudorapidity of cluster centroid
void reset(double vett[256])
int sum_x
More diagnostics.
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
void dumpTracksters(const std::vector< std::pair< int, int >> &layerIdx2layerandSoa, const int, const std::vector< Trackster > &) const