57 void makePUTrackster(
const std::vector<float>& inputClusterMask,
58 std::vector<float>& output_mask,
59 std::vector<Trackster>&
result,
63 void addTrackster(
const int index,
65 const std::vector<float>& inputClusterMask,
66 const float fractionCut_,
73 std::vector<float>& output_mask,
74 std::vector<Trackster>&
result,
76 const bool add =
false);
80 const bool doNose_ =
false;
108 : detector_(ps.getParameter<
std::
string>(
"detector")),
109 doNose_(detector_ ==
"HFNose"),
110 clusters_token_(consumes(ps.getParameter<
edm::
InputTag>(
"layer_clusters"))),
111 clustersTime_token_(consumes(ps.getParameter<
edm::
InputTag>(
"time_layerclusters"))),
112 filtered_layerclusters_mask_token_(consumes(ps.getParameter<
edm::
InputTag>(
"filtered_mask"))),
113 simclusters_token_(consumes(ps.getParameter<
edm::
InputTag>(
"simclusters"))),
114 caloparticles_token_(consumes(ps.getParameter<
edm::
InputTag>(
"caloparticles"))),
115 associatorMapSimClusterToReco_token_(
116 consumes(ps.getParameter<
edm::
InputTag>(
"layerClusterSimClusterAssociator"))),
117 associatorMapCaloParticleToReco_token_(
118 consumes(ps.getParameter<
edm::
InputTag>(
"layerClusterCaloParticleAssociator"))),
120 fractionCut_(ps.getParameter<double>(
"fractionCut")),
121 qualityCutTrack_(ps.getParameter<double>(
"qualityCutTrack")),
122 trackingParticleToken_(
126 cutTk_(ps.getParameter<
std::
string>(
"cutTk")),
127 associatormapStRsToken_(consumes(ps.getParameter<
edm::
InputTag>(
"tpToTrack"))),
128 associationSimTrackToTPToken_(consumes(ps.getParameter<
edm::
InputTag>(
"simTrackToTPMap"))) {
129 produces<TracksterCollection>();
130 produces<std::vector<float>>();
131 produces<TracksterCollection>(
"fromCPs");
132 produces<TracksterCollection>(
"PU");
133 produces<std::vector<float>>(
"fromCPs");
134 produces<std::map<uint, std::vector<uint>>>();
135 produces<std::vector<TICLCandidate>>();
149 edm::InputTag(
"layerClusterCaloParticleAssociationProducer"));
152 "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && " 153 "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
160 desc.add<
double>(
"fractionCut", 0.);
161 desc.add<
double>(
"qualityCutTrack", 0.75);
166 std::vector<float>& output_mask,
167 std::vector<Trackster>&
result,
171 for (
size_t i = 0;
i < output_mask.size();
i++) {
172 const float remaining_fraction = output_mask[
i];
173 if (remaining_fraction > 0.) {
179 result.push_back(tmpTrackster);
185 const std::vector<float>& inputClusterMask,
186 const float fractionCut_,
193 std::vector<float>& output_mask,
194 std::vector<Trackster>&
result,
203 tmpTrackster.
vertices().reserve(lcVec.size());
205 for (
auto const& [lc, energyScorePair] : lcVec) {
206 if (inputClusterMask[lc.index()] > 0) {
207 double fraction = energyScorePair.first / lc->energy();
210 tmpTrackster.
vertices().push_back(lc.index());
211 output_mask[lc.index()] -=
fraction;
224 result.push_back(tmpTrackster);
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);
void setSeed(edm::ProductID pid, int index)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
void setRegressedEnergy(float value)
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
void produce(edm::Event &, const edm::EventSetup &) override
Abs< T >::type abs(const T &t)
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
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 StringCutObjectSelector< reco::Track > cutTk_
const edm::EDGetTokenT< hgcal::SimToRecoCollection > associatorMapCaloParticleToReco_token_
SimTrackstersProducer(const edm::ParameterSet &)
std::vector< unsigned int > & vertices()
const edm::EDGetTokenT< std::vector< SimCluster > > simclusters_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
hgcal::RecHitTools rhtools_
const edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
const float qualityCutTrack_
std::vector< float > & vertex_multiplicity()
const edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticleToken_
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
Monte Carlo truth information used for tracking validation.
void setIteration(const Trackster::IterationIndex i)
void setIdProbability(ParticleType type, float value)
const edm::EDGetTokenT< reco::RecoToSimCollection > associatormapRtSsToken_
void makePUTrackster(const std::vector< float > &inputClusterMask, std::vector< float > &output_mask, std::vector< Trackster > &result, const edm::ProductID seed, int loop_index)