2 #include <Math/VectorUtil.h> 17 const std::array<ticl::Vector, 3> &
skeleton,
28 auto const sum = std::accumulate(std::begin(eigenvalues), std::end(eigenvalues), 0.
f);
29 float pcaQuality = eigenvalues[0] / sum;
40 float r1 =
std::sqrt(point1.x() * point1.x() + point1.y() * point1.y());
44 float projective_distance = (
r1 - r2_at_z1) * (
r1 - r2_at_z1) + r2_at_z1 * r2_at_z1 *
delta_phi *
delta_phi;
45 LogDebug(
"TracksterLinkingbySkeletons") <<
"Computing distance between point : " << point1 <<
" And point " 46 << point2 <<
" Distance " << projective_distance << std::endl;
47 return projective_distance;
57 timing_quality_threshold_(conf.getParameter<double>(
"track_time_quality_threshold")),
58 del_(conf.getParameter<double>(
"wind")),
59 min_num_lcs_(conf.getParameter<unsigned
int>(
"min_num_lcs")),
60 min_trackster_energy_(conf.getParameter<double>(
"min_trackster_energy")),
61 pca_quality_th_(conf.getParameter<double>(
"pca_quality_th")),
62 dot_prod_th_(conf.getParameter<double>(
"dot_prod_th")),
63 max_distance_projective_sqr_(conf.getParameter<
std::
vector<double>>(
"max_distance_projective_sqr")),
64 min_distance_z_(conf.getParameter<
std::
vector<double>>(
"min_distance_z")),
65 max_distance_projective_sqr_closest_points_(
66 conf.getParameter<
std::
vector<double>>(
"max_distance_projective_sqr_closest_points")),
67 max_z_distance_closest_points_(conf.getParameter<
std::
vector<double>>(
"max_z_distance_closest_points")),
68 cylinder_radius_sqr_(conf.getParameter<
std::
vector<double>>(
"cylinder_radius_sqr"))
76 std::pair<float, float> rMinMax =
hgcons_->
rangeR(zVal,
true);
79 std::pair<float, float> rMinMax_interface =
hgcons_->
rangeR(zVal_interface,
true);
81 for (
int iSide = 0; iSide < 2; ++iSide) {
82 float zSide = (iSide == 0) ? (-1. * zVal) : zVal;
89 zSide = (iSide == 0) ? (-1. * zVal_interface) : zVal_interface;
93 SimpleDiskBounds(rMinMax_interface.first, rMinMax_interface.second, zSide - 0.5, zSide + 0.5))
112 float lower_percentage,
113 float upper_percentage,
117 auto const trackster_raw_energy = trackster.
raw_energy();
119 std::vector<unsigned int> sortedVertices(
vertices);
126 float cumulativeEnergyFraction = 0.f;
130 float outerLayerZ =
layerClusters[sortedVertices.back()].z();
131 bool foundInnerLayer =
false;
132 bool foundOuterLayer =
false;
133 for (
auto const &
v : sortedVertices) {
136 cumulativeEnergyFraction += lc.energy() / trackster_raw_energy;
137 if (cumulativeEnergyFraction >= lower_percentage and not foundInnerLayer) {
138 innerLayerId = n_lay;
139 innerLayerZ = lc.z();
140 foundInnerLayer =
true;
142 if (cumulativeEnergyFraction >= upper_percentage and not foundOuterLayer) {
143 outerLayerId = n_lay;
144 outerLayerZ = lc.z();
145 foundOuterLayer =
true;
148 std::array<ticl::Vector, 3>
skeleton;
149 int minimumDistanceInLayers = 4;
150 if (outerLayerId - innerLayerId < minimumDistanceInLayers) {
153 auto intersectLineWithSurface = [](
float surfaceZ,
const Vector &origin,
const Vector &direction) ->
Vector {
154 auto const t = (surfaceZ - origin.Z()) / direction.Z();
155 auto const iX =
t * direction.X() + origin.X();
156 auto const iY =
t * direction.Y() + origin.Y();
157 auto const iZ = surfaceZ;
163 auto const t0_p0 = intersectLineWithSurface(innerLayerZ, t0_p1, trackster.
eigenvectors(0));
164 auto const t0_p2 = intersectLineWithSurface(outerLayerZ, t0_p1, trackster.
eigenvectors(0));
173 const std::array<ticl::Vector, 3> &otherSkeleton,
174 const float radius_sqr) {
175 const auto &
first = mySkeleton[0];
176 const auto &
last = mySkeleton[2];
177 const auto &pointToCheck = otherSkeleton[0];
180 const auto &vecToPoint = pointToCheck -
first;
182 auto axisNorm = cylAxis.Dot(cylAxis);
183 auto projLength = vecToPoint.Dot(cylAxis) / axisNorm;
184 bool isWithinLength = projLength >= 0 && projLength <= 1;
189 const auto &
proj = cylAxis * projLength;
193 const auto &
distance = pointToCheck - pointOnAxis;
196 bool isWithinRadius = distance2 <= radius_sqr;
198 return isWithinRadius;
203 const std::array<ticl::Vector, 3> &mySkeleton,
204 const std::array<ticl::Vector, 3> &otherSkeleton) {
208 LogDebug(
"TracksterLinkingbySkeletons") <<
"Inner Trackster with energy " << myTrackster.
raw_energy() <<
" Num LCs " 209 << myTrackster.
vertices().size() <<
" NOT GOOD " << std::endl;
212 LogDebug(
"TracksterLinkingbySkeletons") <<
"Inner Trackster wi energy " << myTrackster.
raw_energy() <<
" Num LCs " 213 << myTrackster.
vertices().size() <<
" IS GOOD " << std::endl;
214 float proj_distance = projective_distance(mySkeleton[1], otherSkeleton[1]);
215 auto isEE = mySkeleton[1].z() <= zVal_interface ? 0 : 1;
217 LogDebug(
"TracksterLinkingbySkeletons")
218 <<
"\t Trying to compare with outer Trackster with energy " << otherTrackster.
raw_energy() <<
" Num LCS " 219 << otherTrackster.
vertices().size() <<
" Projective distance " << proj_distance <<
" areAlignedProjective " 225 if (areAlignedInProjectiveSpace) {
226 auto dotProdSkeletons =
227 ((mySkeleton[2] - mySkeleton[0]).Unit()).Dot((otherSkeleton[2] - otherSkeleton[0]).Unit());
228 bool alignedSkeletons = dotProdSkeletons >
dot_prod_th_;
229 LogDebug(
"TracksterLinkingbySkeletons")
230 <<
"\t Outer Trackster is Good, checking for skeleton alignment " << alignedSkeletons <<
" dotProd " 231 << dotProdSkeletons <<
" Threshold " <<
dot_prod_th_ << std::endl;
232 if (alignedSkeletons)
233 LogDebug(
"TracksterLinkingbySkeletons") <<
"\t\t Linked! " << std::endl;
234 return alignedSkeletons;
237 LogDebug(
"TracksterLinkingbySkeletons")
238 <<
"\t Outer Trackster is not aligned, check skeletons distances " << std::endl;
239 int myClosestPoint = -1;
240 int otherClosestPoint = -1;
242 for (
int i = 0;
i < 3;
i++) {
243 for (
int j = 0;
j < 3;
j++) {
244 float dist_z =
std::abs(mySkeleton[
i].
Z() - otherSkeleton[
j].
Z());
245 if (dist_z < minDistance_z) {
247 otherClosestPoint =
j;
248 minDistance_z = dist_z;
253 LogDebug(
"TracksterLinkingbySkeletons")
254 <<
"\t Trackster have distance in Z " << minDistance_z
255 <<
"Checking if they are aligned in projective space " 256 << projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) <<
" TH " 258 if (projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) <
260 LogDebug(
"TracksterLinkingbySkeletons") <<
"\t\t Linked! " << std::endl;
262 return projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) <
265 LogDebug(
"TracksterLinkingbySkeletons") <<
"\t\t Not Linked Distance Z " << minDistance_z << std::endl;
270 LogDebug(
"TracksterLinkingbySkeletons")
271 <<
"\t Outer Trackster is NOT GOOD, check projective space alignment " << areAlignedInProjectiveSpace
273 if (areAlignedInProjectiveSpace) {
274 LogDebug(
"TracksterLinkingbySkeletons") <<
"\t\t Linked! " << std::endl;
277 LogDebug(
"TracksterLinkingbySkeletons")
278 <<
"\t Not aligned in projective space, check distance between closest points in the two skeletons " 281 int myClosestPoint = -1;
282 int otherClosestPoint = -1;
285 for (
int i = 1;
i < 3;
i++) {
286 for (
int j = 0;
j < 3;
j++) {
287 float dist_z =
std::abs(mySkeleton[
i].
Z() - otherSkeleton[
j].
Z());
288 if (dist_z < minDistance_z) {
290 otherClosestPoint =
j;
291 minDistance_z = dist_z;
295 float d = projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]);
296 LogDebug(
"TracksterLinkingbySkeletons")
297 <<
"\t\t Distance between closest points " <<
d <<
" TH " << 10.f <<
" Z Distance " << minDistance_z
301 LogDebug(
"TracksterLinkingbySkeletons") <<
"\t\t\t Linked! " <<
d << std::endl;
304 LogDebug(
"TracksterLinkingbySkeletons") <<
"Distance between closest point " <<
d <<
" Distance in z " 307 LogDebug(
"TracksterLinkingbySkeletons") <<
"Two Points are in Cylinder " <<
isInCylinder << std::endl;
309 LogDebug(
"TracksterLinkingbySkeletons") <<
"\t\t\t Linked! " <<
d << std::endl;
320 std::vector<Trackster> &resultTracksters,
321 std::vector<std::vector<unsigned int>> &linkedResultTracksters,
322 std::vector<std::vector<unsigned int>> &linkedTracksterIdToInputTracksterId) {
323 const auto &tracksters =
input.tracksters;
327 std::vector<unsigned int> sortedTracksters(tracksters.size());
328 std::iota(sortedTracksters.begin(), sortedTracksters.end(), 0);
329 std::sort(sortedTracksters.begin(), sortedTracksters.end(), [&tracksters](
unsigned int i,
unsigned int j) {
330 return tracksters[
i].raw_energy() > tracksters[
j].raw_energy();
335 std::array<TICLLayerTile, 2> tracksterTile;
338 std::vector<std::array<ticl::Vector, 3>> skeletons(tracksters.size());
339 for (
auto const t_idx : sortedTracksters) {
340 const auto &trackster = tracksters[t_idx];
342 tracksterTile[trackster.
barycenter().eta() > 0.f].fill(
345 std::vector<int> maskReceivedLink(tracksters.size(), 1);
346 std::vector<int> isRootTracksters(tracksters.size(), 1);
348 std::vector<Node> allNodes;
349 for (
size_t it = 0;
it < tracksters.size(); ++
it) {
350 allNodes.emplace_back(
it);
354 for (
auto const &t_idx : sortedTracksters) {
355 auto const &trackster = tracksters[t_idx];
356 auto const &
skeleton = skeletons[t_idx];
362 const auto &tiles = tracksterTile[
tileIndex];
363 std::array<int, 4> search_box = tiles.searchBoxEtaPhi(
eta_min,
eta_max, bary.phi() -
del_, bary.phi() +
del_);
364 if (search_box[2] > search_box[3]) {
368 for (
int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) {
369 for (
int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) {
371 for (
auto n : neighbours) {
374 if (maskReceivedLink[
n] == 0
or allNodes[t_idx].isInnerNeighbour(
n))
377 LogDebug(
"TracksterLinkingbySkeletons")
378 <<
"Trying to Link Trackster " << t_idx <<
" With Trackster " <<
n << std::endl;
380 LogDebug(
"TracksterLinkingbySkeletons")
381 <<
"\t==== LINK: Trackster " << t_idx <<
" Linked with Trackster " <<
n << std::endl;
382 maskReceivedLink[
n] = 0;
383 allNodes[t_idx].addOuterNeighbour(
n);
384 allNodes[
n].addInnerNeighbour(t_idx);
385 isRootTracksters[
n] = 0;
393 LogDebug(
"TracksterLinkingbySkeletons") <<
"**************** FINAL GRAPH **********************" << std::endl;
394 for (
auto const &node : allNodes) {
395 if (isRootTracksters[node.getId()]) {
396 LogDebug(
"TracksterLinkingbySkeletons")
398 <<
" Node " << node.getId() <<
" position " << tracksters[node.getId()].barycenter() <<
" energy " 399 << tracksters[node.getId()].raw_energy() << std::endl;
401 LogDebug(
"TracksterLinkingbySkeletons")
402 <<
"Node " << node.getId() <<
" position " << tracksters[node.getId()].barycenter() <<
" energy " 403 << tracksters[node.getId()].raw_energy() << std::endl;
406 LogDebug(
"TracksterLinkingbySkeletons") <<
"********************************************************" << std::endl;
408 TICLGraph graph(allNodes, isRootTracksters);
412 linkedTracksterIdToInputTracksterId.resize(
components.size());
414 LogDebug(
"TracksterLinkingbySkeletons") <<
"Component " << ic <<
" Node: ";
415 std::vector<unsigned int> linkedTracksters;
417 if (
comp.size() == 1) {
418 if (
input.tracksters[
comp[0]].vertices().size() <= 3) {
422 for (
auto const &node :
comp) {
423 LogDebug(
"TracksterLinkingbySkeletons") << node <<
" ";
424 linkedTracksterIdToInputTracksterId[ic].push_back(node);
427 linkedTracksters.push_back(resultTracksters.size());
428 resultTracksters.push_back(outTrackster);
429 linkedResultTracksters.push_back(linkedTracksters);
430 LogDebug(
"TracksterLinkingbySkeletons") <<
"\n";
double waferZ(int layer, bool reco) const
constexpr double deltaPhi(double phi1, double phi2)
static DiskPointer build(Args &&... args)
std::vector< double > min_distance_z_
edm::ESHandle< MagneticField > bfield_
static constexpr int nPhiBins
std::vector< double > max_distance_projective_sqr_
const Vector & barycenter() const
static constexpr float maxEta
void linkTracksters(const Inputs &input, std::vector< Trackster > &resultTracksters, std::vector< std::vector< unsigned int >> &linkedResultTracksters, std::vector< std::vector< unsigned int >> &linkedTracksterIdToInputTracksterId) override
ticl::Trackster::Vector Vector
edm::ESHandle< Propagator > propagator_
bool areCompatible(const ticl::Trackster &myTrackster, const ticl::Trackster &otherTrackster, const std::array< ticl::Vector, 3 > &mySkeleton, const std::array< ticl::Vector, 3 > &otherSkeleton)
static std::string const input
int32_t tileIndex(int32_t layer, int32_t ring, int32_t phi)
const HGCalDDDConstants * hgcons_
const std::array< Vector, 3 > & eigenvectors() const
double intersection(double r12)
void mergeTracksters(const Trackster &other)
TracksterLinkingbySkeletons(const edm::ParameterSet &conf, edm::ConsumesCollector iC, cms::Ort::ONNXRuntime const *onnxRuntime=nullptr)
std::array< ticl::Vector, 3 > findSkeletonNodes(const ticl::Trackster &trackster, float lower_percentage, float upper_percentage, const std::vector< reco::CaloCluster > &layerClusters, const hgcal::RecHitTools &rhtools)
const float raw_energy() const
hgcal::RecHitTools rhtools_
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
Abs< T >::type abs(const T &t)
std::unique_ptr< GeomDet > interfaceDisk_[2]
static constexpr float minEta
std::vector< double > max_distance_projective_sqr_closest_points_
std::pair< double, double > rangeR(double z, bool reco) const
std::vector< unsigned int > & vertices()
std::vector< std::vector< unsigned int > > findSubComponents()
std::unique_ptr< GeomDet > firstDisk_[2]
float min_trackster_energy_
void initialize(const HGCalDDDConstants *hgcons, const hgcal::RecHitTools rhtools, const edm::ESHandle< MagneticField > bfieldH, const edm::ESHandle< Propagator > propH) override
std::vector< double > max_z_distance_closest_points_
unsigned int min_num_lcs_
const std::array< float, 3 > & eigenvalues() const
std::vector< double > cylinder_radius_sqr_
bool isInCylinder(const std::array< ticl::Vector, 3 > &mySkeleton, const std::array< ticl::Vector, 3 > &otherSkeleton, const float radius_sqr)