172 auto resultTrackstersMerged = std::make_unique<std::vector<Trackster>>();
173 auto resultCandidates = std::make_unique<std::vector<TICLCandidate>>();
176 std::vector<bool> usedTrackstersMerged;
177 std::vector<int> indexInMergedCollTRKEM;
178 std::vector<int> indexInMergedCollEM;
179 std::vector<int> indexInMergedCollTRK;
180 std::vector<int> indexInMergedCollHAD;
181 std::vector<bool> usedSeeds;
184 std::map<int, std::vector<std::pair<int, TracksterIterIndex>>> seedToTracksterAssociator;
185 std::vector<TracksterIterIndex> iterMergedTracksters;
188 const auto &
tracks = *track_h;
196 const auto &layerClustersTimes = *clustersTime_h;
200 const auto &trackstersEM = *trackstersem_h;
204 const auto &trackstersTRKEM = *tracksterstrkem_h;
208 const auto &trackstersTRK = *tracksterstrk_h;
212 const auto &trackstersHAD = *trackstershad_h;
217 usedSeeds.resize(
tracks.size(),
false);
219 fillTile(tracksterTile, trackstersTRKEM, TracksterIterIndex::TRKEM);
220 fillTile(tracksterTile, trackstersEM, TracksterIterIndex::EM);
221 fillTile(tracksterTile, trackstersTRK, TracksterIterIndex::TRK);
222 fillTile(tracksterTile, trackstersHAD, TracksterIterIndex::HAD);
224 auto totalNumberOfTracksters =
225 trackstersTRKEM.size() + trackstersTRK.size() + trackstersEM.size() + trackstersHAD.size();
226 resultTrackstersMerged->reserve(totalNumberOfTracksters);
227 iterMergedTracksters.reserve(totalNumberOfTracksters);
228 usedTrackstersMerged.resize(totalNumberOfTracksters,
false);
229 indexInMergedCollTRKEM.reserve(trackstersTRKEM.size());
230 indexInMergedCollEM.reserve(trackstersEM.size());
231 indexInMergedCollTRK.reserve(trackstersTRK.size());
232 indexInMergedCollHAD.reserve(trackstersHAD.size());
241 for (
auto const &
t : trackstersTRKEM) {
242 indexInMergedCollTRKEM.push_back(resultTrackstersMerged->size());
243 seedToTracksterAssociator[
t.seedIndex()].emplace_back(resultTrackstersMerged->size(), TracksterIterIndex::TRKEM);
244 resultTrackstersMerged->push_back(
t);
245 iterMergedTracksters.push_back(TracksterIterIndex::TRKEM);
248 for (
auto const &
t : trackstersEM) {
249 indexInMergedCollEM.push_back(resultTrackstersMerged->size());
250 resultTrackstersMerged->push_back(
t);
251 iterMergedTracksters.push_back(TracksterIterIndex::EM);
254 for (
auto const &
t : trackstersTRK) {
255 indexInMergedCollTRK.push_back(resultTrackstersMerged->size());
256 seedToTracksterAssociator[
t.seedIndex()].emplace_back(resultTrackstersMerged->size(), TracksterIterIndex::TRK);
257 resultTrackstersMerged->push_back(
t);
258 iterMergedTracksters.push_back(TracksterIterIndex::TRK);
261 for (
auto const &
t : trackstersHAD) {
262 indexInMergedCollHAD.push_back(resultTrackstersMerged->size());
263 resultTrackstersMerged->push_back(
t);
264 iterMergedTracksters.push_back(TracksterIterIndex::HAD);
275 auto trackstersMergedHandle = evt.
put(
std::move(resultTrackstersMerged));
281 for (
unsigned i = 0;
i < trackstersEM.size(); ++
i) {
282 auto mergedIdx = indexInMergedCollEM[
i];
283 usedTrackstersMerged[mergedIdx] =
true;
284 const auto &
t = trackstersEM[
i];
291 t.raw_energy() *
t.barycenter().unit().y(),
292 t.raw_energy() *
t.barycenter().unit().z(),
295 resultCandidates->push_back(tmpCandidate);
299 constexpr
float mpion2 = 0.13957f * 0.13957f;
300 for (
unsigned i = 0;
i < trackstersHAD.size(); ++
i) {
301 auto mergedIdx = indexInMergedCollHAD[
i];
302 usedTrackstersMerged[mergedIdx] =
true;
303 const auto &
t = trackstersHAD[
i];
309 float momentum =
std::sqrt(
t.raw_energy() *
t.raw_energy() - mpion2);
311 momentum *
t.barycenter().unit().y(),
312 momentum *
t.barycenter().unit().z(),
315 resultCandidates->push_back(tmpCandidate);
319 for (
unsigned i = 0;
i < trackstersTRKEM.size(); ++
i) {
320 auto mergedIdx = indexInMergedCollTRKEM[
i];
321 if (!usedTrackstersMerged[mergedIdx]) {
322 const auto &
t = trackstersTRKEM[
i];
323 auto trackIdx =
t.seedIndex();
325 if (!usedSeeds[trackIdx] and
t.raw_energy() > 0) {
326 usedSeeds[trackIdx] =
true;
327 usedTrackstersMerged[mergedIdx] =
true;
329 std::vector<int> trackstersTRKwithSameSeed;
330 std::vector<int> trackstersTRKEMwithSameSeed;
332 for (
const auto &tracksterIterationPair : seedToTracksterAssociator[trackIdx]) {
333 if (tracksterIterationPair.first != mergedIdx and !usedTrackstersMerged[tracksterIterationPair.first] and
334 trackstersMergedHandle->at(tracksterIterationPair.first).raw_energy() > 0.) {
335 if (tracksterIterationPair.second == TracksterIterIndex::TRKEM) {
336 trackstersTRKEMwithSameSeed.push_back(tracksterIterationPair.first);
337 }
else if (tracksterIterationPair.second == TracksterIterIndex::TRK) {
338 trackstersTRKwithSameSeed.push_back(tracksterIterationPair.first);
343 float tracksterTotalRawPt =
t.raw_pt();
344 std::vector<int> haloTrackstersTRKIdx;
345 bool foundCompatibleTRK =
false;
347 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
348 usedTrackstersMerged[otherTracksterIdx] =
true;
349 tracksterTotalRawPt += trackstersMergedHandle->at(otherTracksterIdx).raw_pt();
352 if ((
t.barycenter() - trackstersMergedHandle->at(otherTracksterIdx).barycenter()).
mag2() <
354 haloTrackstersTRKIdx.push_back(otherTracksterIdx);
357 foundCompatibleTRK =
true;
362 if (trackstersTRKEMwithSameSeed.empty()) {
363 if (foundCompatibleTRK) {
366 double raw_energy =
t.raw_energy();
371 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
373 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
377 raw_energy *
track.momentum().unit().y(),
378 raw_energy *
track.momentum().unit().z(),
381 resultCandidates->push_back(tmpCandidate);
386 double raw_energy =
t.raw_energy();
389 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
391 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
397 raw_energy *
track.momentum().unit().y(),
398 raw_energy *
track.momentum().unit().z(),
401 resultCandidates->push_back(tmpCandidate);
406 int closestTrackster = mergedIdx;
408 for (
auto otherTracksterIdx : trackstersTRKEMwithSameSeed) {
409 auto thisPt = tracksterTotalRawPt + trackstersMergedHandle->at(otherTracksterIdx).raw_pt() -
t.raw_pt();
410 closestTrackster =
std::abs(thisPt -
track.pt()) < minPtDiff ? otherTracksterIdx : closestTrackster;
412 usedTrackstersMerged[closestTrackster] =
true;
414 if (foundCompatibleTRK) {
417 double raw_energy = trackstersMergedHandle->at(closestTrackster).raw_energy();
422 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
424 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
427 float momentum =
std::sqrt(raw_energy * raw_energy - mpion2);
429 momentum *
track.momentum().unit().y(),
430 momentum *
track.momentum().unit().z(),
433 resultCandidates->push_back(tmpCandidate);
438 double raw_energy = trackstersMergedHandle->at(closestTrackster).raw_energy();
442 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
444 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
449 raw_energy *
track.momentum().unit().y(),
450 raw_energy *
track.momentum().unit().z(),
453 resultCandidates->push_back(tmpCandidate);
456 for (
auto otherTracksterIdx : trackstersTRKEMwithSameSeed) {
457 auto tmpIndex = (otherTracksterIdx != closestTrackster) ? otherTracksterIdx : mergedIdx;
459 const auto &otherTrackster = trackstersMergedHandle->at(tmpIndex);
460 auto gammaEnergy = otherTrackster.raw_energy();
465 gammaEnergy * otherTrackster.barycenter().unit().y(),
466 gammaEnergy * otherTrackster.barycenter().unit().z(),
468 photonCandidate.
setP4(gammaP4);
470 resultCandidates->push_back(photonCandidate);
477 for (
unsigned i = 0;
i < trackstersTRK.size(); ++
i) {
478 auto mergedIdx = indexInMergedCollTRK[
i];
479 const auto &
t = trackstersTRK[
i];
481 if (!usedTrackstersMerged[mergedIdx] and
t.raw_energy() > 0) {
482 auto trackIdx =
t.seedIndex();
484 if (!usedSeeds[trackIdx]) {
485 usedSeeds[trackIdx] =
true;
486 usedTrackstersMerged[mergedIdx] =
true;
493 float momentum =
std::sqrt(
t.raw_energy() *
t.raw_energy() - mpion2);
495 momentum *
track.momentum().unit().y(),
496 momentum *
track.momentum().unit().z(),
499 resultCandidates->push_back(tmpCandidate);
505 if (usedSeeds[
s.index] ==
false) {
516 resultCandidates->push_back(tmpCandidate);
517 usedSeeds[
s.index] =
true;
522 for (
unsigned i = 0;
i <
tracks.size(); ++
i) {
536 resultCandidates->push_back(tmpCandidate);