229 auto result = std::make_unique<TracksterCollection>();
230 auto output_mask = std::make_unique<std::vector<float>>();
231 auto result_fromCP = std::make_unique<TracksterCollection>();
232 auto resultPU = std::make_unique<TracksterCollection>();
233 auto output_mask_fromCP = std::make_unique<std::vector<float>>();
234 auto cpToSc_SimTrackstersMap = std::make_unique<std::map<uint, std::vector<uint>>>();
235 auto result_ticlCandidates = std::make_unique<std::vector<TICLCandidate>>();
258 const auto& recoTracks = *recoTracks_h;
263 result->reserve(num_simclusters);
265 result_fromCP->resize(num_caloparticles);
266 std::map<uint, uint> SimClusterToCaloParticleMap;
268 for (
const auto& [
key, lcVec] : caloParticlesToRecoColl) {
269 auto const&
cp = *(
key);
271 for (
const auto& scRef :
cp.simClusters()) {
272 auto const& sc = *(scRef);
274 SimClusterToCaloParticleMap[scIndex] = cpIndex;
277 auto regr_energy =
cp.energy();
278 std::vector<uint> scSimTracksterIdx;
279 scSimTracksterIdx.reserve(
cp.simClusters().size());
282 if (
cp.g4Tracks()[0].crossedBoundary()) {
283 regr_energy =
cp.g4Tracks()[0].getMomentumAtBoundary().energy();
284 float time =
cp.g4Tracks()[0].getPositionAtBoundary().t();
299 for (
const auto& scRef :
cp.simClusters()) {
300 const auto&
it = simClustersToRecoColl.find(scRef);
301 if (
it == simClustersToRecoColl.end())
303 const auto& lcVec =
it->val;
304 auto const& sc = *(scRef);
311 sc.g4Tracks()[0].getMomentumAtBoundary().energy(),
314 sc.g4Tracks()[0].getPositionAtBoundary().t(),
324 if (
std::find(scSimTracksterIdx.begin(), scSimTracksterIdx.end(),
index) == scSimTracksterIdx.end()) {
325 scSimTracksterIdx.emplace_back(
index);
328 scSimTracksterIdx.shrink_to_fit();
347 if (result_fromCP->empty())
349 const auto index = loop_index - 1;
350 if (cpToSc_SimTrackstersMap->find(
index) == cpToSc_SimTrackstersMap->end()) {
351 (*cpToSc_SimTrackstersMap)[
index] = scSimTracksterIdx;
362 makePUTrackster(inputClusterMask, *output_mask, *resultPU, caloParticles_h.
id(), 0);
364 auto simTrackToRecoTrack = [&](
UniqueSimTrackId simTkId) -> std::pair<int, float> {
367 auto ipos = simTrackToTPMap.mapping.find(simTkId);
368 if (ipos != simTrackToTPMap.mapping.end()) {
369 auto jpos = TPtoRecoTrackMap.find((ipos->second));
370 if (jpos != TPtoRecoTrackMap.end()) {
371 auto& associatedRecoTracks = jpos->val;
372 if (!associatedRecoTracks.empty()) {
375 trackIdx = &(*associatedRecoTracks[0].first) - &recoTracks[0];
376 quality = associatedRecoTracks[0].second;
385 auto& simTrackstersFromCP = *result_fromCP;
386 for (
unsigned int i = 0;
i < simTrackstersFromCP.size(); ++
i) {
387 if (simTrackstersFromCP[
i].
vertices().empty())
391 auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
392 if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second >
qualityCutTrack_) {
393 auto trackIndex = bestAssociatedRecoTrack.first;
394 simTrackstersFromCP[
i].setTrackIdx(trackIndex);
398 auto& simTracksters = *
result;
400 std::unordered_map<unsigned int, std::vector<unsigned int>> TPtoSimTracksterMap;
401 for (
unsigned int i = 0;
i < simTracksters.size(); ++
i) {
402 const auto&
simTrack = (simTracksters[
i].seedID() == caloParticles_h.
id())
404 :
simclusters[simTracksters[
i].seedIndex()].g4Tracks()[0];
406 auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
407 if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second >
qualityCutTrack_) {
408 auto trackIndex = bestAssociatedRecoTrack.first;
409 simTracksters[
i].setTrackIdx(trackIndex);
415 result_ticlCandidates->resize(result_fromCP->size());
416 std::vector<int> toKeep;
417 for (
size_t i = 0;
i < simTracksters_h->size(); ++
i) {
418 const auto& simTrackster = (*simTracksters_h)[
i];
419 int cp_index = (simTrackster.seedID() == caloParticles_h.
id())
420 ? simTrackster.seedIndex()
421 : SimClusterToCaloParticleMap[simTrackster.seedIndex()];
422 auto const& tCP = (*result_fromCP)[cp_index];
423 if (!tCP.vertices().empty()) {
424 auto trackIndex = tCP.trackIdx();
426 auto&
cand = (*result_ticlCandidates)[cp_index];
428 if (trackIndex != -1 and (trackIndex < 0 or trackIndex >= (
long int)recoTracks.size())) {
430 cand.setTime((*result_fromCP)[cp_index].
time());
431 cand.setTimeError(0);
434 toKeep.push_back(cp_index);
438 auto isHad = [](
int pdgId) {
445 for (
size_t i = 0;
i < result_ticlCandidates->size(); ++
i) {
446 auto cp_index = (*result_fromCP)[
i].seedIndex();
449 auto&
cand = (*result_ticlCandidates)[
i];
452 float regressedEnergy = 0.f;
454 for (
const auto& trackster :
cand.tracksters()) {
456 regressedEnergy += trackster->regressed_energy();
462 if (
cand.trackPtr().isNonnull() and
charge == 0) {
464 if (
cand.trackPtr().isNonnull() and
charge != 0) {
465 auto const&
track =
cand.trackPtr().get();
473 regressedEnergy *
track->momentum().unit().y(),
474 regressedEnergy *
track->momentum().unit().z(),
484 const auto& simTracksterFromCP = (*result_fromCP)[
i];
485 float regressedEnergy = simTracksterFromCP.regressed_energy();
487 regressedEnergy * simTracksterFromCP.barycenter().unit().y(),
488 regressedEnergy * simTracksterFromCP.barycenter().unit().z(),
494 std::vector<int> all_nums(result_fromCP->size());
495 std::iota(all_nums.begin(), all_nums.end(), 0);
497 std::vector<int> toRemove;
498 std::set_difference(all_nums.begin(), all_nums.end(), toKeep.begin(), toKeep.end(), std::back_inserter(toRemove));
499 std::sort(toRemove.begin(), toRemove.end(), [](
int x,
int y) {
return x >
y; });
500 for (
auto const&
r : toRemove) {
501 result_fromCP->erase(result_fromCP->begin() +
r);
502 result_ticlCandidates->erase(result_ticlCandidates->begin() +
r);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
void addTrackster(const int index, const std::vector< std::pair< edm::Ref< reco::CaloClusterCollection >, std::pair< float, float >>> &lcVec, const std::vector< float > &inputClusterMask, const float fractionCut_, const float energy, const int pdgId, const int charge, float time, const edm::ProductID seed, const Trackster::IterationIndex iter, std::vector< float > &output_mask, std::vector< Trackster > &result, int &loop_index, const bool add=false)
bool get(ProductID const &oid, Handle< PROD > &result) const
const edm::EDGetTokenT< reco::SimToRecoCollection > associatormapStRsToken_
std::pair< uint32_t, EncodedEventId > UniqueSimTrackId
const edm::EDGetTokenT< std::vector< SimVertex > > simVerticesToken_
const edm::EDGetTokenT< hgcal::SimToRecoCollectionWithSimClusters > associatorMapSimClusterToReco_token_
const edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geom_token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const edm::EDGetTokenT< SimTrackToTPMap > associationSimTrackToTPToken_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
U second(std::pair< T, U > const &p)
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.
Trackster::ParticleType tracksterParticleTypeFromPdgId(int pdgId, int charge)
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)
key
prepare the HTCondor submission files and eventually submit them
const edm::EDGetTokenT< std::vector< CaloParticle > > caloparticles_token_
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
const edm::EDGetTokenT< hgcal::SimToRecoCollection > associatorMapCaloParticleToReco_token_
const edm::EDGetTokenT< std::vector< SimCluster > > simclusters_token_
hgcal::RecHitTools rhtools_
const edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
const float qualityCutTrack_
const edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticleToken_
void makePUTrackster(const std::vector< float > &inputClusterMask, std::vector< float > &output_mask, std::vector< Trackster > &result, const edm::ProductID seed, int loop_index)