249 auto resultTrackstersMerged = std::make_unique<std::vector<Trackster>>();
250 auto resultCandidates = std::make_unique<std::vector<TICLCandidate>>();
251 auto resultFromTracks = std::make_unique<std::vector<TICLCandidate>>();
259 const auto &
tracks = *track_h;
270 track_h, trackTime, trackTimeErr, trackTimeQual,
muons, trackstersclue3d_h, *resultCandidates, *resultFromTracks);
273 LogDebug(
"TrackstersMergeProducer") <<
"Results from the linking step : " << std::endl
274 <<
"No. of Tracks : " <<
tracks.size()
275 <<
" No. of Tracksters : " << (*trackstersclue3d_h).size() << std::endl
276 <<
"(neutral candidates have track id -1)" << std::endl;
278 std::vector<TICLCandidate> &
candidates = *resultCandidates;
280 auto track_ptr =
cand.trackPtr();
281 auto trackster_ptrs =
cand.tracksters();
285 track_idx = (track_ptr.isNull()) ? -1 : track_idx;
286 LogDebug(
"TrackstersMergeProducer") <<
"PDG ID " <<
cand.pdgId() <<
" charge " <<
cand.charge() <<
" p " <<
cand.p()
288 LogDebug(
"TrackstersMergeProducer") <<
"track id (p) : " << track_idx <<
" (" 289 << (track_ptr.isNull() ? -1 : track_ptr->p()) <<
") " 290 <<
" trackster ids (E) : ";
295 auto updated_size = 0;
296 for (
const auto &ts_ptr : trackster_ptrs) {
299 LogDebug(
"TrackstersMergeProducer") << ts_idx <<
" (" << ts_ptr->raw_energy() <<
") ";
302 auto &thisTrackster = *ts_ptr;
303 updated_size += thisTrackster.vertices().size();
304 outTrackster.vertices().reserve(updated_size);
305 outTrackster.vertex_multiplicity().reserve(updated_size);
306 std::copy(std::begin(thisTrackster.vertices()),
307 std::end(thisTrackster.vertices()),
308 std::back_inserter(outTrackster.vertices()));
309 std::copy(std::begin(thisTrackster.vertex_multiplicity()),
310 std::end(thisTrackster.vertex_multiplicity()),
311 std::back_inserter(outTrackster.vertex_multiplicity()));
314 LogDebug(
"TrackstersMergeProducer") << std::endl;
317 auto &orig_vtx = outTrackster.vertices();
318 auto vtx_sorted{orig_vtx};
319 std::sort(std::begin(vtx_sorted), std::end(vtx_sorted));
320 for (
unsigned int iLC = 1; iLC < vtx_sorted.size(); ++iLC) {
321 if (vtx_sorted[iLC] == vtx_sorted[iLC - 1]) {
323 const auto lcIdx = vtx_sorted[iLC];
324 const auto firstEl =
std::find(orig_vtx.begin(), orig_vtx.end(), lcIdx);
325 const auto firstPos =
std::distance(std::begin(orig_vtx), firstEl);
327 while (iDup != orig_vtx.end()) {
328 orig_vtx.erase(iDup);
329 outTrackster.vertex_multiplicity().erase(outTrackster.vertex_multiplicity().begin() +
331 outTrackster.vertex_multiplicity()[firstPos] -= 1;
337 outTrackster.zeroProbabilities();
338 if (!track_ptr.isNull())
340 if (!outTrackster.vertices().empty()) {
341 resultTrackstersMerged->push_back(outTrackster);
352 assert(resultTrackstersMerged->size() == resultCandidates->size());
354 auto isHad = [](
const Trackster &tracksterMerge) {
359 for (
size_t i = 0;
i < resultTrackstersMerged->size();
i++) {
360 auto const &tm = (*resultTrackstersMerged)[
i];
361 auto &
cand = (*resultCandidates)[
i];
363 cand.setIdProbabilities(tm.id_probabilities());
365 if (!
cand.trackPtr().isNull()) {
366 auto pdgId = isHad(tm) ? 211 : 11;
367 auto const &tk =
cand.trackPtr().get();
369 cand.setCharge(tk->charge());
370 cand.setRawEnergy(tm.raw_energy());
371 auto const ®rE = tm.regressed_energy();
373 regrE * tk->momentum().unit().y(),
374 regrE * tk->momentum().unit().z(),
378 auto pdgId = isHad(tm) ? 130 : 22;
381 cand.setRawEnergy(tm.raw_energy());
382 const float ®rE = tm.regressed_energy();
384 regrE * tm.barycenter().unit().y(),
385 regrE * tm.barycenter().unit().z(),
390 for (
auto &
cand : *resultFromTracks) {
391 auto const &tk =
cand.trackPtr().get();
392 cand.setPdgId(211 * tk->charge());
393 cand.setCharge(tk->charge());
400 resultCandidates->insert(resultCandidates->end(), resultFromTracks->begin(), resultFromTracks->end());
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool get(ProductID const &oid, Handle< PROD > &result) const
const edm::EDGetTokenT< std::vector< Trackster > > tracksters_clue3d_token_
ProductID id() const
Accessor for product ID.
void assignTimeToCandidates(std::vector< TICLCandidate > &resultCandidates) const
const tensorflow::Session * tfSession_
hgcal::RecHitTools rhtools_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_quality_token_
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)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_err_token_
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result) const
const edm::EDGetTokenT< std::vector< reco::Muon > > muons_token_
bool getData(T &iHolder) const
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
const edm::EDGetTokenT< std::vector< reco::Track > > tracks_token_
std::unique_ptr< LinkingAlgoBase > linkingAlgo_
auto const & tracks
cannot be loose
const edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_token_
const edm::ESGetToken< TfGraphDefWrapper, TfGraphRecord > tfDnnToken_