171 auto resultTrackstersMerged = std::make_unique<std::vector<Trackster>>();
172 auto resultCandidates = std::make_unique<std::vector<TICLCandidate>>();
177 std::vector<bool> usedTrackstersMerged;
178 std::vector<int> indexInMergedCollTRKEM;
179 std::vector<int> indexInMergedCollEM;
180 std::vector<int> indexInMergedCollTRK;
181 std::vector<int> indexInMergedCollHAD;
182 std::vector<bool> usedSeeds;
185 std::map<int, std::vector<std::pair<int, TracksterIterIndex>>> seedToTracksterAssociator;
189 const auto &
tracks = *track_h;
199 usedSeeds.resize(
tracks.size(),
false);
201 fillTile(tracksterTile, trackstersTRKEM, TracksterIterIndex::TRKEM);
202 fillTile(tracksterTile, trackstersEM, TracksterIterIndex::EM);
203 fillTile(tracksterTile, trackstersTRK, TracksterIterIndex::TRKHAD);
204 fillTile(tracksterTile, trackstersHAD, TracksterIterIndex::HAD);
206 auto totalNumberOfTracksters =
207 trackstersTRKEM.size() + trackstersTRK.size() + trackstersEM.size() + trackstersHAD.size();
208 resultTrackstersMerged->reserve(totalNumberOfTracksters);
209 usedTrackstersMerged.resize(totalNumberOfTracksters,
false);
210 indexInMergedCollTRKEM.reserve(trackstersTRKEM.size());
211 indexInMergedCollEM.reserve(trackstersEM.size());
212 indexInMergedCollTRK.reserve(trackstersTRK.size());
213 indexInMergedCollHAD.reserve(trackstersHAD.size());
220 for (
auto const &
t : trackstersTRKEM) {
221 indexInMergedCollTRKEM.push_back(resultTrackstersMerged->size());
222 seedToTracksterAssociator[
t.seedIndex()].emplace_back(resultTrackstersMerged->size(), TracksterIterIndex::TRKEM);
223 resultTrackstersMerged->push_back(
t);
226 for (
auto const &
t : trackstersEM) {
227 indexInMergedCollEM.push_back(resultTrackstersMerged->size());
228 resultTrackstersMerged->push_back(
t);
231 for (
auto const &
t : trackstersTRK) {
232 indexInMergedCollTRK.push_back(resultTrackstersMerged->size());
233 seedToTracksterAssociator[
t.seedIndex()].emplace_back(resultTrackstersMerged->size(), TracksterIterIndex::TRKHAD);
234 resultTrackstersMerged->push_back(
t);
237 for (
auto const &
t : trackstersHAD) {
238 indexInMergedCollHAD.push_back(resultTrackstersMerged->size());
239 resultTrackstersMerged->push_back(
t);
250 auto trackstersMergedHandle = evt.
put(
std::move(resultTrackstersMerged));
256 for (
unsigned i = 0;
i < trackstersEM.size(); ++
i) {
257 auto mergedIdx = indexInMergedCollEM[
i];
258 usedTrackstersMerged[mergedIdx] =
true;
259 const auto &
t = trackstersEM[
i];
266 t.raw_energy() *
t.barycenter().unit().y(),
267 t.raw_energy() *
t.barycenter().unit().z(),
269 tmpCandidate.
setP4(p4);
270 resultCandidates->push_back(tmpCandidate);
276 for (
unsigned i = 0;
i < trackstersHAD.size(); ++
i) {
277 auto mergedIdx = indexInMergedCollHAD[
i];
278 usedTrackstersMerged[mergedIdx] =
true;
279 const auto &
t = trackstersHAD[
i];
287 momentum *
t.barycenter().unit().y(),
288 momentum *
t.barycenter().unit().z(),
290 tmpCandidate.
setP4(p4);
291 resultCandidates->push_back(tmpCandidate);
295 for (
unsigned i = 0;
i < trackstersTRKEM.size(); ++
i) {
296 auto mergedIdx = indexInMergedCollTRKEM[
i];
297 if (!usedTrackstersMerged[mergedIdx]) {
298 const auto &
t = trackstersTRKEM[
i];
299 auto trackIdx =
t.seedIndex();
301 if (!usedSeeds[trackIdx] and
t.raw_energy() > 0) {
302 usedSeeds[trackIdx] =
true;
303 usedTrackstersMerged[mergedIdx] =
true;
305 std::vector<int> trackstersTRKwithSameSeed;
306 std::vector<int> trackstersTRKEMwithSameSeed;
308 for (
const auto &tracksterIterationPair : seedToTracksterAssociator[trackIdx]) {
309 if (tracksterIterationPair.first != mergedIdx and !usedTrackstersMerged[tracksterIterationPair.first] and
310 trackstersMergedHandle->at(tracksterIterationPair.first).raw_energy() > 0.) {
311 if (tracksterIterationPair.second == TracksterIterIndex::TRKEM) {
312 trackstersTRKEMwithSameSeed.push_back(tracksterIterationPair.first);
313 }
else if (tracksterIterationPair.second == TracksterIterIndex::TRKHAD) {
314 trackstersTRKwithSameSeed.push_back(tracksterIterationPair.first);
319 float tracksterTotalRawPt =
t.raw_pt();
320 std::vector<int> haloTrackstersTRKIdx;
321 bool foundCompatibleTRK =
false;
323 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
324 usedTrackstersMerged[otherTracksterIdx] =
true;
325 tracksterTotalRawPt += trackstersMergedHandle->at(otherTracksterIdx).raw_pt();
328 if ((
t.barycenter() - trackstersMergedHandle->at(otherTracksterIdx).barycenter()).
mag2() <
330 haloTrackstersTRKIdx.push_back(otherTracksterIdx);
333 foundCompatibleTRK =
true;
338 if (trackstersTRKEMwithSameSeed.empty()) {
339 if (foundCompatibleTRK) {
342 double raw_energy =
t.raw_energy();
347 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
349 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
353 raw_energy *
track.momentum().unit().y(),
354 raw_energy *
track.momentum().unit().z(),
356 tmpCandidate.
setP4(p4);
357 resultCandidates->push_back(tmpCandidate);
362 double raw_energy =
t.raw_energy();
365 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
367 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
373 raw_energy *
track.momentum().unit().y(),
374 raw_energy *
track.momentum().unit().z(),
376 tmpCandidate.
setP4(p4);
377 resultCandidates->push_back(tmpCandidate);
382 int closestTrackster = mergedIdx;
384 for (
auto otherTracksterIdx : trackstersTRKEMwithSameSeed) {
385 auto thisPt = tracksterTotalRawPt + trackstersMergedHandle->at(otherTracksterIdx).raw_pt() -
t.raw_pt();
386 closestTrackster =
std::abs(thisPt -
track.pt()) < minPtDiff ? otherTracksterIdx : closestTrackster;
388 usedTrackstersMerged[closestTrackster] =
true;
390 if (foundCompatibleTRK) {
393 double raw_energy = trackstersMergedHandle->at(closestTrackster).raw_energy();
398 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
400 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
405 momentum *
track.momentum().unit().y(),
406 momentum *
track.momentum().unit().z(),
408 tmpCandidate.
setP4(p4);
409 resultCandidates->push_back(tmpCandidate);
414 double raw_energy = trackstersMergedHandle->at(closestTrackster).raw_energy();
418 for (
auto otherTracksterIdx : trackstersTRKwithSameSeed) {
420 raw_energy += trackstersMergedHandle->at(otherTracksterIdx).raw_energy();
425 raw_energy *
track.momentum().unit().y(),
426 raw_energy *
track.momentum().unit().z(),
428 tmpCandidate.
setP4(p4);
429 resultCandidates->push_back(tmpCandidate);
432 for (
auto otherTracksterIdx : trackstersTRKEMwithSameSeed) {
433 auto tmpIndex = (otherTracksterIdx != closestTrackster) ? otherTracksterIdx : mergedIdx;
435 const auto &otherTrackster = trackstersMergedHandle->at(tmpIndex);
436 auto gammaEnergy = otherTrackster.raw_energy();
441 gammaEnergy * otherTrackster.barycenter().unit().y(),
442 gammaEnergy * otherTrackster.barycenter().unit().z(),
444 photonCandidate.
setP4(gammaP4);
446 resultCandidates->push_back(photonCandidate);
453 for (
unsigned i = 0;
i < trackstersTRK.size(); ++
i) {
454 auto mergedIdx = indexInMergedCollTRK[
i];
455 const auto &
t = trackstersTRK[
i];
457 if (!usedTrackstersMerged[mergedIdx] and
t.raw_energy() > 0) {
458 auto trackIdx =
t.seedIndex();
460 if (!usedSeeds[trackIdx]) {
461 usedSeeds[trackIdx] =
true;
462 usedTrackstersMerged[mergedIdx] =
true;
471 momentum *
track.momentum().unit().y(),
472 momentum *
track.momentum().unit().z(),
474 tmpCandidate.
setP4(p4);
475 resultCandidates->push_back(tmpCandidate);
481 if (usedSeeds[
s.index] ==
false) {
491 tmpCandidate.
setP4(p4Polar);
492 resultCandidates->push_back(tmpCandidate);
493 usedSeeds[
s.index] =
true;
498 for (
unsigned i = 0;
i <
tracks.size(); ++
i) {
511 tmpCandidate.
setP4(p4Polar);
512 resultCandidates->push_back(tmpCandidate);
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
void printTrackstersDebug(const std::vector< Trackster > &, const char *label) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
bool get(ProductID const &oid, Handle< PROD > &result) const
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometry_token_
const edm::EDGetTokenT< std::vector< Trackster > > trackstershad_token_
const double halo_max_distance2_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const int track_max_missing_outerhits_
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool energyWeight=true)
void setCharge(Charge q) final
set electric charge
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const edm::EDGetTokenT< std::vector< Trackster > > trackstersem_token_
const edm::EDGetTokenT< std::vector< TICLSeedingRegion > > seedingTrk_token_
void setRawEnergy(float rawEnergy)
const edm::EDGetTokenT< std::vector< reco::Track > > tracks_token_
const tensorflow::Session * tfSession_
Abs< T >::type abs(const T &t)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
hgcal::RecHitTools rhtools_
const edm::EDGetTokenT< std::vector< Trackster > > tracksterstrkem_token_
const double track_max_eta_
void assignTimeToCandidates(std::vector< TICLCandidate > &resultCandidates) const
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result) const
const edm::ESGetToken< TfGraphDefWrapper, TfGraphRecord > tfDnnToken_
const edm::EDGetTokenT< std::vector< Trackster > > tracksterstrk_token_
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
const double track_min_eta_
void addTrackster(const edm::Ptr< ticl::Trackster > &trackster)
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
const double track_min_pt_
void setPdgId(int pdgId) final
void setTrackPtr(const edm::Ptr< reco::Track > &trackPtr)
void setP4(const LorentzVector &p4) final
set 4-momentum
void fillTile(TICLTracksterTiles &, const std::vector< Trackster > &, TracksterIterIndex)