59 void makePUTrackster(
const std::vector<float>& inputClusterMask,
60 std::vector<float>& output_mask,
61 std::vector<Trackster>&
result,
65 void addTrackster(
const int index,
67 const std::vector<float>& inputClusterMask,
68 const float fractionCut_,
75 std::vector<float>& output_mask,
76 std::vector<Trackster>&
result,
78 const bool add =
false);
82 const bool doNose_ =
false;
112 : detector_(ps.getParameter<
std::
string>(
"detector")),
113 doNose_(detector_ ==
"HFNose"),
114 computeLocalTime_(ps.getParameter<
bool>(
"computeLocalTime")),
115 clusters_token_(consumes(ps.getParameter<
edm::
InputTag>(
"layer_clusters"))),
116 clustersTime_token_(consumes(ps.getParameter<
edm::
InputTag>(
"time_layerclusters"))),
117 filtered_layerclusters_mask_token_(consumes(ps.getParameter<
edm::
InputTag>(
"filtered_mask"))),
118 simclusters_token_(consumes(ps.getParameter<
edm::
InputTag>(
"simclusters"))),
119 caloparticles_token_(consumes(ps.getParameter<
edm::
InputTag>(
"caloparticles"))),
121 associatorMapSimClusterToReco_token_(
122 consumes(ps.getParameter<
edm::
InputTag>(
"layerClusterSimClusterAssociator"))),
123 associatorMapCaloParticleToReco_token_(
124 consumes(ps.getParameter<
edm::
InputTag>(
"layerClusterCaloParticleAssociator"))),
126 fractionCut_(ps.getParameter<double>(
"fractionCut")),
127 qualityCutTrack_(ps.getParameter<double>(
"qualityCutTrack")),
128 trackingParticleToken_(
132 cutTk_(ps.getParameter<
std::
string>(
"cutTk")),
133 associatormapStRsToken_(consumes(ps.getParameter<
edm::
InputTag>(
"tpToTrack"))),
134 associationSimTrackToTPToken_(consumes(ps.getParameter<
edm::
InputTag>(
"simTrackToTPMap"))) {
135 produces<TracksterCollection>();
136 produces<std::vector<float>>();
137 produces<TracksterCollection>(
"fromCPs");
138 produces<TracksterCollection>(
"PU");
139 produces<std::vector<float>>(
"fromCPs");
140 produces<std::map<uint, std::vector<uint>>>();
141 produces<std::vector<TICLCandidate>>();
147 desc.add<
bool>(
"computeLocalTime",
"false");
157 edm::InputTag(
"layerClusterCaloParticleAssociationProducer"));
160 "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && " 161 "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
168 desc.add<
double>(
"fractionCut", 0.);
169 desc.add<
double>(
"qualityCutTrack", 0.75);
174 std::vector<float>& output_mask,
175 std::vector<Trackster>&
result,
179 for (
size_t i = 0;
i < output_mask.size();
i++) {
180 const float remaining_fraction = output_mask[
i];
187 result.push_back(tmpTrackster);
193 const std::vector<float>& inputClusterMask,
194 const float fractionCut_,
201 std::vector<float>& output_mask,
202 std::vector<Trackster>&
result,
211 tmpTrackster.
vertices().reserve(lcVec.size());
213 for (
auto const& [lc, energyScorePair] : lcVec) {
214 if (inputClusterMask[lc.index()] > 0) {
215 double fraction = energyScorePair.first / lc->energy();
218 tmpTrackster.
vertices().push_back(lc.index());
219 output_mask[lc.index()] -=
fraction;
233 result.push_back(tmpTrackster);
238 auto result = std::make_unique<TracksterCollection>();
239 auto output_mask = std::make_unique<std::vector<float>>();
240 auto result_fromCP = std::make_unique<TracksterCollection>();
241 auto resultPU = std::make_unique<TracksterCollection>();
242 auto output_mask_fromCP = std::make_unique<std::vector<float>>();
243 auto cpToSc_SimTrackstersMap = std::make_unique<std::map<uint, std::vector<uint>>>();
244 auto result_ticlCandidates = std::make_unique<std::vector<TICLCandidate>>();
275 result->reserve(num_simclusters);
277 result_fromCP->resize(num_caloparticles);
278 std::map<uint, uint> SimClusterToCaloParticleMap;
280 for (
const auto& [
key, lcVec] : caloParticlesToRecoColl) {
281 auto const&
cp = *(
key);
283 for (
const auto& scRef :
cp.simClusters()) {
284 auto const& sc = *(scRef);
286 SimClusterToCaloParticleMap[scIndex] = cpIndex;
289 auto regr_energy =
cp.energy();
290 std::vector<uint> scSimTracksterIdx;
291 scSimTracksterIdx.reserve(
cp.simClusters().size());
294 if (
cp.g4Tracks()[0].crossedBoundary()) {
295 regr_energy =
cp.g4Tracks()[0].getMomentumAtBoundary().energy();
296 float time =
cp.g4Tracks()[0].getPositionAtBoundary().t();
311 for (
const auto& scRef :
cp.simClusters()) {
312 const auto&
it = simClustersToRecoColl.find(scRef);
313 if (
it == simClustersToRecoColl.end())
315 const auto& lcVec =
it->val;
316 auto const& sc = *(scRef);
323 sc.g4Tracks()[0].getMomentumAtBoundary().energy(),
326 sc.g4Tracks()[0].getPositionAtBoundary().t(),
336 if (
std::find(scSimTracksterIdx.begin(), scSimTracksterIdx.end(),
index) == scSimTracksterIdx.end()) {
337 scSimTracksterIdx.emplace_back(
index);
340 scSimTracksterIdx.shrink_to_fit();
359 if (result_fromCP->empty())
361 const auto index = loop_index - 1;
362 if (cpToSc_SimTrackstersMap->find(
index) == cpToSc_SimTrackstersMap->end()) {
363 (*cpToSc_SimTrackstersMap)[
index] = scSimTracksterIdx;
382 makePUTrackster(inputClusterMask, *output_mask, *resultPU, caloParticles_h.
id(), 0);
384 auto simTrackToRecoTrack = [&](
UniqueSimTrackId simTkId) -> std::pair<int, float> {
387 auto ipos = simTrackToTPMap.mapping.find(simTkId);
388 if (ipos != simTrackToTPMap.mapping.end()) {
389 auto jpos = TPtoRecoTrackMap.find((ipos->second));
390 if (jpos != TPtoRecoTrackMap.end()) {
391 auto& associatedRecoTracks = jpos->val;
392 if (!associatedRecoTracks.empty()) {
395 trackIdx = &(*associatedRecoTracks[0].first) - &
recoTracks[0];
396 quality = associatedRecoTracks[0].second;
405 auto& simTrackstersFromCP = *result_fromCP;
406 for (
unsigned int i = 0;
i < simTrackstersFromCP.size(); ++
i) {
407 if (simTrackstersFromCP[
i].
vertices().empty())
411 auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
412 if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second >
qualityCutTrack_) {
413 auto trackIndex = bestAssociatedRecoTrack.first;
414 simTrackstersFromCP[
i].setTrackIdx(trackIndex);
418 auto& simTracksters = *
result;
420 std::unordered_map<unsigned int, std::vector<unsigned int>> TPtoSimTracksterMap;
421 for (
unsigned int i = 0;
i < simTracksters.size(); ++
i) {
422 const auto&
simTrack = (simTracksters[
i].seedID() == caloParticles_h.
id())
424 :
simclusters[simTracksters[
i].seedIndex()].g4Tracks()[0];
426 auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
427 if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second >
qualityCutTrack_) {
428 auto trackIndex = bestAssociatedRecoTrack.first;
429 simTracksters[
i].setTrackIdx(trackIndex);
436 std::unordered_map<unsigned int, const MtdSimTrackster*> SimTrackToMtdST;
437 for (
unsigned int i = 0;
i < MTDSimTracksters_h->size(); ++
i) {
438 const auto&
simTrack = (*MTDSimTracksters_h)[
i].g4Tracks()[0];
439 SimTrackToMtdST[
simTrack.trackId()] = &((*MTDSimTracksters_h)[
i]);
442 result_ticlCandidates->resize(result_fromCP->size());
443 std::vector<int> toKeep;
444 for (
size_t i = 0;
i < simTracksters_h->size(); ++
i) {
445 const auto& simTrackster = (*simTracksters_h)[
i];
446 int cp_index = (simTrackster.seedID() == caloParticles_h.
id())
447 ? simTrackster.seedIndex()
448 : SimClusterToCaloParticleMap[simTrackster.seedIndex()];
449 auto const& tCP = (*result_fromCP)[cp_index];
450 if (!tCP.vertices().empty()) {
451 auto trackIndex = tCP.trackIdx();
453 auto&
cand = (*result_ticlCandidates)[cp_index];
457 toKeep.push_back(cp_index);
461 auto isHad = [](
int pdgId) {
468 for (
size_t i = 0;
i < result_ticlCandidates->size(); ++
i) {
469 auto cp_index = (*result_fromCP)[
i].seedIndex();
472 auto&
cand = (*result_ticlCandidates)[
i];
475 float regressedEnergy = 0.f;
478 auto pos = SimTrackToMtdST.find(
simTrack.trackId());
479 if (
pos != SimTrackToMtdST.end()) {
480 auto MTDst =
pos->second;
482 cand.setMTDTime(MTDst->time(), 0);
487 for (
const auto& trackster :
cand.tracksters()) {
489 regressedEnergy += trackster->regressed_energy();
495 if (
cand.trackPtr().isNonnull()) {
496 auto const&
track =
cand.trackPtr().get();
504 regressedEnergy *
track->momentum().unit().y(),
505 regressedEnergy *
track->momentum().unit().z(),
513 else if (
pdgId == 111)
522 const auto& simTracksterFromCP = (*result_fromCP)[
i];
523 float regressedEnergy = simTracksterFromCP.regressed_energy();
525 regressedEnergy * simTracksterFromCP.barycenter().unit().y(),
526 regressedEnergy * simTracksterFromCP.barycenter().unit().z(),
532 std::vector<int> all_nums(result_fromCP->size());
533 std::iota(all_nums.begin(), all_nums.end(), 0);
535 std::vector<int> toRemove;
536 std::set_difference(all_nums.begin(), all_nums.end(), toKeep.begin(), toKeep.end(), std::back_inserter(toRemove));
537 std::sort(toRemove.begin(), toRemove.end(), [](
int x,
int y) {
return x >
y; });
538 for (
auto const&
r : toRemove) {
539 result_fromCP->erase(result_fromCP->begin() +
r);
540 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)
bool get(ProductID const &oid, Handle< PROD > &result) const
const edm::EDGetTokenT< reco::SimToRecoCollection > associatormapStRsToken_
std::pair< uint32_t, EncodedEventId > UniqueSimTrackId
const edm::EDGetTokenT< MtdSimTracksterCollection > MTDSimTrackstersToken_
const edm::EDGetTokenT< std::vector< SimVertex > > simVerticesToken_
const edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
void assignPCAtoTracksters(std::vector< Trackster > &tracksters, const std::vector< reco::CaloCluster > &layerClusters, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, double z_limit_em, hgcal::RecHitTools const &rhTools, bool computeLocalTime=false, bool energyWeight=true, bool clean=false, int minLayer=10, int maxLayer=10)
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)
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
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, const 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)
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< ticl::SimToRecoCollectionWithSimClusters > associatorMapSimClusterToReco_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 edm::EDGetTokenT< ticl::SimToRecoCollection > associatorMapCaloParticleToReco_token_
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)
const bool computeLocalTime_
Monte Carlo truth information used for tracking validation.
void setIteration(const Trackster::IterationIndex i)
void setBoundaryTime(float t)
void setIdProbability(ParticleType type, float value)
const edm::EDGetTokenT< reco::RecoToSimCollection > associatormapRtSsToken_
Power< A, B >::type pow(const A &a, const B &b)
std::vector< MtdSimTrackster > MtdSimTracksterCollection
void makePUTrackster(const std::vector< float > &inputClusterMask, std::vector< float > &output_mask, std::vector< Trackster > &result, const edm::ProductID seed, int loop_index)