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;
53 for (
int layer = 0; layer <= maxLayer; layer++) {
56 for (
int phi = 0; phi < nPhiBin; phi++) {
57 int iphi = ((phi % nPhiBin + nPhiBin) % nPhiBin);
60 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Layer: " << layer <<
" ieta: " <<
ieta <<
" phi: " << phi
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";
115 for (
unsigned int layer = 0; layer < clusters_.size(); layer++) {
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(
268 for (
unsigned int layer = 0; layer < clusters_.size(); layer++) {
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);
291 for (
unsigned int layer = 0; layer < clusters_.size(); ++layer) {
292 const auto &thisLayer = clusters_[layer];
294 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Examining Layer: " << 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());
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()) {
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];
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 {
505 return sqrt((x1 - x2) * (x1 - x2) + (
y1 -
y2) * (
y1 -
y2));
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 - 1);
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];
573 bool onSameCluster = clustersOnLayer.layerClusterOriginalIdx[
i] == otherClusterIdx;
574 if (onSameLayer && !densityOnSameLayer_ && !onSameCluster) {
577 <<
"Skipping different cluster " << otherClusterIdx <<
"in the same layer " << currentLayer;
582 bool reachable =
false;
583 if (useAbsoluteProjectiveScale_) {
584 if (useClusterDimensionXY_) {
585 reachable = isReachable(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
586 clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
587 clustersOnLayer.phi[
i],
588 clustersLayer.phi[layerandSoa.second],
589 clustersOnLayer.radius[
i] * clustersOnLayer.radius[
i]);
593 if (clustersOnLayer.isSilicon[
i]) {
594 reachable = isReachable(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
595 clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
596 clustersOnLayer.phi[
i],
597 clustersLayer.phi[layerandSoa.second],
598 densityXYDistanceSqr_);
600 reachable = isReachable(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
601 clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
602 clustersOnLayer.phi[
i],
603 clustersLayer.phi[layerandSoa.second],
604 clustersOnLayer.radius[
i] * clustersOnLayer.radius[
i]);
609 clustersOnLayer.phi[
i],
610 clustersLayer.eta[layerandSoa.second],
611 clustersLayer.phi[layerandSoa.second]) < densityEtaPhiDistanceSqr_);
616 clustersOnLayer.phi[
i],
617 clustersLayer.eta[layerandSoa.second],
618 clustersLayer.phi[layerandSoa.second]);
619 auto dist = distance_debug(
620 clustersOnLayer.r_over_absz[
i],
621 clustersLayer.r_over_absz[layerandSoa.second],
622 clustersOnLayer.r_over_absz[
i] *
std::abs(clustersOnLayer.phi[
i]),
623 clustersLayer.r_over_absz[layerandSoa.second] *
std::abs(clustersLayer.phi[layerandSoa.second]));
624 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Distance[cm]: " << (dist * clustersOnLayer.z[
i]);
626 <<
"Energy Other: " << clustersLayer.energy[layerandSoa.second];
627 edm::LogVerbatim(
"PatternRecognitionbyCLUE3D") <<
"Cluster radius: " << clustersOnLayer.radius[
i];
631 (onSameCluster ? 1.f : kernelDensityFactor_) * clustersLayer.energy[layerandSoa.second];
632 clustersOnLayer.rho[
i] += energyToAdd;
633 clustersOnLayer.z_extension[
i] = deltaLayersZ;
636 <<
"Adding " << energyToAdd <<
" partial " << clustersOnLayer.rho[
i];
643 if (rescaleDensityByZ_) {
646 <<
"Rescaling original density: " << clustersOnLayer.rho[
i] <<
" by Z: " << deltaLayersZ
647 <<
" to final density/cm: " << clustersOnLayer.rho[
i] / deltaLayersZ;
649 clustersOnLayer.rho[
i] /= deltaLayersZ;
654 template <
typename TILES>
656 const TILES &tiles,
const int layerId,
const std::vector<std::pair<int, int>> &layerIdx2layerandSoa) {
659 auto &clustersOnLayer = clusters_[layerId];
662 auto distanceSqr = [](
float r0,
float r1,
float phi0,
float phi1) ->
float {
670 <<
"Starting searching nearestHigher on " << layerId <<
" with rho: " << clustersOnLayer.rho[
i]
671 <<
" at eta, phi: " << tiles[layerId].etaBin(clustersOnLayer.eta[
i]) <<
", " 672 << tiles[layerId].phiBin(clustersOnLayer.phi[
i]);
675 auto lastLayerPerSide =
static_cast<int>(rhtools_.lastLayer(
false));
677 int maxLayer = 2 * lastLayerPerSide - 1;
678 if (layerId < lastLayerPerSide) {
680 maxLayer =
std::min(layerId + densitySiblingLayers_, lastLayerPerSide - 1);
683 maxLayer =
std::min(layerId + densitySiblingLayers_, maxLayer);
687 std::pair<int, int> i_nearestHigher(-1, -1);
689 for (
int currentLayer =
minLayer; currentLayer <= maxLayer; currentLayer++) {
690 if (!nearestHigherOnSameLayer_ && (layerId == currentLayer))
692 const auto &tileOnLayer = tiles[currentLayer];
695 int etaBinMin =
std::max(tileOnLayer.etaBin(clustersOnLayer.eta[
i]) - etaWindow, 0);
696 int etaBinMax =
std::min(tileOnLayer.etaBin(clustersOnLayer.eta[
i]) + etaWindow, nEtaBin - 1);
697 int phiBinMin = tileOnLayer.phiBin(clustersOnLayer.phi[
i]) -
phiWindow;
698 int phiBinMax = tileOnLayer.phiBin(clustersOnLayer.phi[
i]) +
phiWindow;
701 for (
int iphi_it = phiBinMin; iphi_it <= phiBinMax; ++iphi_it) {
702 int iphi = ((iphi_it % nPhiBin + nPhiBin) % nPhiBin);
705 <<
"Searching nearestHigher on " << currentLayer <<
" eta, phi: " <<
ieta <<
", " << iphi_it <<
" " 708 for (
auto otherClusterIdx : tileOnLayer[
offset +
iphi]) {
709 auto const &layerandSoa = layerIdx2layerandSoa[otherClusterIdx];
711 if ((layerandSoa.first == -1) && (layerandSoa.second == -1))
713 auto const &clustersOnOtherLayer = clusters_[layerandSoa.first];
716 int dist_layers =
std::abs(layerandSoa.first - layerId);
717 if (useAbsoluteProjectiveScale_) {
718 dist_transverse = distanceSqr(clustersOnLayer.r_over_absz[
i] * clustersOnLayer.z[
i],
719 clustersOnOtherLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[
i],
720 clustersOnLayer.phi[
i],
721 clustersOnOtherLayer.phi[layerandSoa.second]);
723 dist = dist_transverse;
726 clustersOnLayer.phi[
i],
727 clustersOnOtherLayer.eta[layerandSoa.second],
728 clustersOnOtherLayer.phi[layerandSoa.second]);
729 dist_transverse = dist;
731 bool foundHigher = (clustersOnOtherLayer.rho[layerandSoa.second] > clustersOnLayer.rho[
i]) ||
732 (clustersOnOtherLayer.rho[layerandSoa.second] == clustersOnLayer.rho[
i] &&
733 clustersOnOtherLayer.layerClusterOriginalIdx[layerandSoa.second] >
734 clustersOnLayer.layerClusterOriginalIdx[
i]);
737 <<
"Searching nearestHigher on " << currentLayer
738 <<
" with rho: " << clustersOnOtherLayer.rho[layerandSoa.second]
739 <<
" on layerIdxInSOA: " << layerandSoa.first <<
", " << layerandSoa.second
740 <<
" with distance: " <<
sqrt(dist) <<
" foundHigher: " << foundHigher;
742 if (foundHigher && dist <= i_delta) {
745 nearest_distances = std::make_pair(
sqrt(dist_transverse), dist_layers);
747 i_nearestHigher = layerandSoa;
754 clustersOnLayer.delta[
i] = nearest_distances;
755 clustersOnLayer.nearestHigher[
i] = i_nearestHigher;
759 template <
typename TILES>
761 const TILES &tiles,
const std::vector<std::pair<int, int>> &layerIdx2layerandSoa) {
762 unsigned int nTracksters = 0;
764 std::vector<std::pair<int, int>> localStack;
765 auto critical_transverse_distance = useAbsoluteProjectiveScale_ ? criticalXYDistance_ : criticalEtaPhiDistance_;
767 for (
unsigned int layer = 0; layer < 2 * rhtools_.lastLayer(); layer++) {
768 auto &clustersOnLayer = clusters_[layer];
772 clustersOnLayer.clusterIndex[
i] = -1;
773 bool isSeed = (clustersOnLayer.delta[
i].first > critical_transverse_distance ||
774 clustersOnLayer.delta[
i].second > criticalZDistanceLyr_) &&
775 (clustersOnLayer.rho[
i] >= criticalDensity_) &&
776 (clustersOnLayer.energy[
i] / clustersOnLayer.rho[
i] > criticalSelfDensity_);
777 if (!clustersOnLayer.isSilicon[
i]) {
778 isSeed = (clustersOnLayer.delta[
i].first > clustersOnLayer.radius[
i] ||
779 clustersOnLayer.delta[
i].second > criticalZDistanceLyr_) &&
780 (clustersOnLayer.rho[
i] >= criticalDensity_) &&
781 (clustersOnLayer.energy[
i] / clustersOnLayer.rho[
i] > criticalSelfDensity_);
783 bool isOutlier = (clustersOnLayer.delta[
i].first > outlierMultiplier_ * critical_transverse_distance) &&
784 (clustersOnLayer.rho[
i] < criticalDensity_);
788 <<
"Found seed on Layer " << layer <<
" SOAidx: " <<
i <<
" assigned ClusterIdx: " << nTracksters;
790 clustersOnLayer.clusterIndex[
i] = nTracksters++;
791 clustersOnLayer.isSeed[
i] =
true;
792 localStack.emplace_back(layer,
i);
793 }
else if (!isOutlier) {
794 auto [lyrIdx, soaIdx] = clustersOnLayer.nearestHigher[
i];
797 <<
"Found follower on Layer " << layer <<
" SOAidx: " <<
i <<
" attached to cluster on layer: " << lyrIdx
798 <<
" SOAidx: " << soaIdx;
801 clusters_[lyrIdx].followers[soaIdx].emplace_back(layer,
i);
805 <<
"Found Outlier on Layer " << layer <<
" SOAidx: " <<
i <<
" with rho: " << clustersOnLayer.rho[
i]
806 <<
" and delta: " << clustersOnLayer.delta[
i].first <<
", " << clustersOnLayer.delta[
i].second;
813 while (!localStack.empty()) {
814 auto [lyrIdx, soaIdx] = localStack.back();
815 auto &thisSeed = clusters_[lyrIdx].followers[soaIdx];
816 localStack.pop_back();
819 for (
auto [follower_lyrIdx, follower_soaIdx] : thisSeed) {
821 clusters_[follower_lyrIdx].clusterIndex[follower_soaIdx] = clusters_[lyrIdx].clusterIndex[soaIdx];
823 localStack.emplace_back(follower_lyrIdx, follower_soaIdx);
829 template <
typename TILES>
831 iDesc.
add<
int>(
"algo_verbosity", 0);
832 iDesc.
add<
double>(
"criticalDensity", 4)->setComment(
"in GeV");
833 iDesc.
add<
double>(
"criticalSelfDensity", 0.15 )
834 ->setComment(
"Minimum ratio of self_energy/local_density to become a seed.");
835 iDesc.
add<
int>(
"densitySiblingLayers", 3)
837 "inclusive, layers to consider while computing local density and searching for nearestHigher higher");
838 iDesc.
add<
double>(
"densityEtaPhiDistanceSqr", 0.0008);
839 iDesc.
add<
double>(
"densityXYDistanceSqr", 3.24 )
840 ->setComment(
"in cm, 2.6*2.6, distance on the transverse plane to consider for local density");
841 iDesc.
add<
double>(
"kernelDensityFactor", 0.2)
842 ->
setComment(
"Kernel factor to be applied to other LC while computing the local density");
843 iDesc.
add<
bool>(
"densityOnSameLayer",
false);
844 iDesc.
add<
bool>(
"nearestHigherOnSameLayer",
false)
845 ->setComment(
"Allow the nearestHigher to be located on the same layer");
846 iDesc.
add<
bool>(
"useAbsoluteProjectiveScale",
true)
847 ->setComment(
"Express all cuts in terms of r/z*z_0{,phi} projective variables");
848 iDesc.
add<
bool>(
"useClusterDimensionXY",
false)
850 "Boolean. If true use the estimated cluster radius to determine the cluster compatibility while computing " 851 "the local density");
852 iDesc.
add<
bool>(
"rescaleDensityByZ",
false)
854 "Rescale local density by the extension of the Z 'volume' explored. The transvere dimension is, at present, " 855 "fixed and factored out.");
856 iDesc.
add<
double>(
"criticalEtaPhiDistance", 0.025)
857 ->
setComment(
"Minimal distance in eta,phi space from nearestHigher to become a seed");
858 iDesc.
add<
double>(
"criticalXYDistance", 1.8)
859 ->
setComment(
"Minimal distance in cm on the XY plane from nearestHigher to become a seed");
860 iDesc.
add<
int>(
"criticalZDistanceLyr", 5)
861 ->setComment(
"Minimal distance in layers along the Z axis from nearestHigher to become a seed");
862 iDesc.
add<
double>(
"outlierMultiplier", 2);
863 iDesc.
add<
int>(
"minNumLayerCluster", 2)->setComment(
"Not Inclusive");
865 iDesc.
add<
std::string>(
"eid_output_name_energy",
"output/regressed_energy");
866 iDesc.
add<
std::string>(
"eid_output_name_id",
"output/id_probabilities");
867 iDesc.
add<
double>(
"eid_min_cluster_energy", 1.);
868 iDesc.
add<
int>(
"eid_n_layers", 50);
869 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
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
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 >> &)
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 >> &)
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])
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
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