CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
SimTrackstersProducer Class Reference
Inheritance diagram for SimTrackstersProducer:
edm::stream::EDProducer<>

Public Member Functions

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)
 
void makePUTrackster (const std::vector< float > &inputClusterMask, std::vector< float > &output_mask, std::vector< Trackster > &result, const edm::ProductID seed, int loop_index)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 SimTrackstersProducer (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Attributes

const edm::EDGetTokenT< SimTrackToTPMapassociationSimTrackToTPToken_
 
const edm::EDGetTokenT< hgcal::SimToRecoCollectionassociatorMapCaloParticleToReco_token_
 
const edm::EDGetTokenT< reco::RecoToSimCollectionassociatormapRtSsToken_
 
const edm::EDGetTokenT< hgcal::SimToRecoCollectionWithSimClustersassociatorMapSimClusterToReco_token_
 
const edm::EDGetTokenT< reco::SimToRecoCollectionassociatormapStRsToken_
 
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::TrackcutTk_
 
std::string detector_
 
const bool doNose_ = false
 
const edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
 
const float fractionCut_
 
const edm::ESGetToken< CaloGeometry, CaloGeometryRecordgeom_token_
 
const float qualityCutTrack_
 
const edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
 
hgcal::RecHitTools rhtools_
 
const edm::EDGetTokenT< std::vector< SimCluster > > simclusters_token_
 
const edm::EDGetTokenT< std::vector< SimVertex > > simVerticesToken_
 
const edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticleToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 51 of file SimTrackstersProducer.cc.

Constructor & Destructor Documentation

◆ SimTrackstersProducer()

SimTrackstersProducer::SimTrackstersProducer ( const edm::ParameterSet ps)
explicit

Definition at line 107 of file SimTrackstersProducer.cc.

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"))),
116  consumes(ps.getParameter<edm::InputTag>("layerClusterSimClusterAssociator"))),
118  consumes(ps.getParameter<edm::InputTag>("layerClusterCaloParticleAssociator"))),
120  fractionCut_(ps.getParameter<double>("fractionCut")),
121  qualityCutTrack_(ps.getParameter<double>("qualityCutTrack")),
123  consumes<std::vector<TrackingParticle>>(ps.getParameter<edm::InputTag>("trackingParticles"))),
124  simVerticesToken_(consumes<std::vector<SimVertex>>(ps.getParameter<edm::InputTag>("simVertices"))),
125  recoTracksToken_(consumes<std::vector<reco::Track>>(ps.getParameter<edm::InputTag>("recoTracks"))),
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>>();
136 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::EDGetTokenT< reco::SimToRecoCollection > associatormapStRsToken_
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_
const edm::EDGetTokenT< SimTrackToTPMap > associationSimTrackToTPToken_
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_
const edm::EDGetTokenT< std::vector< SimCluster > > simclusters_token_
const edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
const edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticleToken_

Member Function Documentation

◆ addTrackster()

void SimTrackstersProducer::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 
)

Definition at line 182 of file SimTrackstersProducer.cc.

References PVValHelper::add(), ALCARECOTkAlJpsiMuMu_cff::charge, hcalRecHitTable_cff::energy, f, HLT_2024v13_cff::fraction, fractionCut_, EgammaValidation_cff::pdgId, mps_fire::result, fileCollector::seed, ticl::Trackster::setIdProbability(), ticl::Trackster::setIteration(), ticl::Trackster::setRegressedEnergy(), ticl::Trackster::setSeed(), ticl::tracksterParticleTypeFromPdgId(), ticl::Trackster::vertex_multiplicity(), and ticl::Trackster::vertices().

Referenced by produce().

196  {
197  Trackster tmpTrackster;
198  if (lcVec.empty()) {
199  result[index] = tmpTrackster;
200  return;
201  }
202 
203  tmpTrackster.vertices().reserve(lcVec.size());
204  tmpTrackster.vertex_multiplicity().reserve(lcVec.size());
205  for (auto const& [lc, energyScorePair] : lcVec) {
206  if (inputClusterMask[lc.index()] > 0) {
207  double fraction = energyScorePair.first / lc->energy();
208  if (fraction < fractionCut_)
209  continue;
210  tmpTrackster.vertices().push_back(lc.index());
211  output_mask[lc.index()] -= fraction;
212  tmpTrackster.vertex_multiplicity().push_back(1. / fraction);
213  }
214  }
215 
217  tmpTrackster.setRegressedEnergy(energy);
218  tmpTrackster.setIteration(iter);
219  tmpTrackster.setSeed(seed, index);
220  if (add) {
221  result[index] = tmpTrackster;
222  loop_index += 1;
223  } else {
224  result.push_back(tmpTrackster);
225  }
226 }
void setSeed(edm::ProductID pid, int index)
Definition: Trackster.h:59
void setRegressedEnergy(float value)
Definition: Trackster.h:67
Trackster::ParticleType tracksterParticleTypeFromPdgId(int pdgId, int charge)
Definition: commons.h:16
double f[11][100]
std::vector< unsigned int > & vertices()
Definition: Trackster.h:56
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:57
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
void setIteration(const Trackster::IterationIndex i)
Definition: Trackster.h:55
void setIdProbability(ParticleType type, float value)
Definition: Trackster.h:119

◆ fillDescriptions()

void SimTrackstersProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 138 of file SimTrackstersProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

138  {
140  desc.add<std::string>("detector", "HGCAL");
141  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
142  desc.add<edm::InputTag>("time_layerclusters", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster"));
143  desc.add<edm::InputTag>("filtered_mask", edm::InputTag("filteredLayerClustersSimTracksters", "ticlSimTracksters"));
144  desc.add<edm::InputTag>("simclusters", edm::InputTag("mix", "MergedCaloTruth"));
145  desc.add<edm::InputTag>("caloparticles", edm::InputTag("mix", "MergedCaloTruth"));
146  desc.add<edm::InputTag>("layerClusterSimClusterAssociator",
147  edm::InputTag("layerClusterSimClusterAssociationProducer"));
148  desc.add<edm::InputTag>("layerClusterCaloParticleAssociator",
149  edm::InputTag("layerClusterCaloParticleAssociationProducer"));
150  desc.add<edm::InputTag>("recoTracks", edm::InputTag("generalTracks"));
151  desc.add<std::string>("cutTk",
152  "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && "
153  "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
154  desc.add<edm::InputTag>("tpToTrack", edm::InputTag("trackingParticleRecoTrackAsssociation"));
155 
156  desc.add<edm::InputTag>("trackingParticles", edm::InputTag("mix", "MergedTrackTruth"));
157  desc.add<edm::InputTag>("simVertices", edm::InputTag("g4SimHits"));
158 
159  desc.add<edm::InputTag>("simTrackToTPMap", edm::InputTag("simHitTPAssocProducer", "simTrackToTP"));
160  desc.add<double>("fractionCut", 0.);
161  desc.add<double>("qualityCutTrack", 0.75);
162 
163  descriptions.addWithDefaultLabel(desc);
164 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ makePUTrackster()

void SimTrackstersProducer::makePUTrackster ( const std::vector< float > &  inputClusterMask,
std::vector< float > &  output_mask,
std::vector< Trackster > &  result,
const edm::ProductID  seed,
int  loop_index 
)

Definition at line 165 of file SimTrackstersProducer.cc.

References mps_fire::i, mps_fire::result, fileCollector::seed, ticl::Trackster::setSeed(), ticl::Trackster::vertex_multiplicity(), and ticl::Trackster::vertices().

Referenced by produce().

169  {
170  Trackster tmpTrackster;
171  for (size_t i = 0; i < output_mask.size(); i++) {
172  const float remaining_fraction = output_mask[i];
173  if (remaining_fraction > 0.) {
174  tmpTrackster.vertices().push_back(i);
175  tmpTrackster.vertex_multiplicity().push_back(1. / remaining_fraction);
176  }
177  }
178  tmpTrackster.setSeed(seed, 0);
179  result.push_back(tmpTrackster);
180 }
void setSeed(edm::ProductID pid, int index)
Definition: Trackster.h:59
std::vector< unsigned int > & vertices()
Definition: Trackster.h:56
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:57

◆ produce()

void SimTrackstersProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 228 of file SimTrackstersProducer.cc.

References funct::abs(), addTrackster(), ticl::assignPCAtoTracksters(), associationSimTrackToTPToken_, associatorMapCaloParticleToReco_token_, associatorMapSimClusterToReco_token_, associatormapStRsToken_, SimTracksters_cff::caloparticles, caloparticles_token_, ALCARECOTkAlJpsiMuMu_cff::charge, clusters_token_, clustersTime_token_, doNose_, f, filtered_layerclusters_mask_token_, spr::find(), fractionCut_, relativeConstraints::geom, geom_token_, edm::Event::get(), edm::Event::getByToken(), edm::EventSetup::getData(), hgcal::RecHitTools::getPositionLayer(), mps_fire::i, edm::HandleBase::id(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, submitPVResolutionJobs::key, hgcal::RecHitTools::lastLayerEE(), hltEgammaHGCALIDVarsL1Seeded_cfi::layerClusters, makePUTrackster(), eostools::move(), or, PbPb_ZMuSkimMuonDPG_cff::particleType, EgammaValidation_cff::pdgId, edm::Event::put(), quality, qualityCutTrack_, alignCSCRings::r, electrons_cff::rawEnergy, recoTracksToken_, mps_fire::result, rhtools_, edm::second(), DBoxMetadataHelper::set_difference(), hgcal::RecHitTools::setGeometry(), ticl::Trackster::SIM, ticl::Trackster::SIM_CP, SimTracksters_cff::simclusters, simclusters_token_, cscDigiValidation_cfi::simTrack, HGCalValidator_cfi::simVertices, simVerticesToken_, jetUpdater_cfi::sort, hcalRecHitTable_cff::time, HLT_2024v13_cff::track, trackingParticleToken_, ticl::tracksterParticleTypeFromPdgId(), AlignmentTracksFromVertexSelector_cfi::vertices, x, y, and z.

228  {
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>>();
236 
237  const auto& layerClusters = evt.get(clusters_token_);
238  const auto& layerClustersTimes = evt.get(clustersTime_token_);
239  const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_);
240  output_mask->resize(layerClusters.size(), 1.f);
241  output_mask_fromCP->resize(layerClusters.size(), 1.f);
242 
243  const auto& simclusters = evt.get(simclusters_token_);
244  edm::Handle<std::vector<CaloParticle>> caloParticles_h;
245  evt.getByToken(caloparticles_token_, caloParticles_h);
246  const auto& caloparticles = *caloParticles_h;
247 
248  const auto& simClustersToRecoColl = evt.get(associatorMapSimClusterToReco_token_);
249  const auto& caloParticlesToRecoColl = evt.get(associatorMapCaloParticleToReco_token_);
250  const auto& simVertices = evt.get(simVerticesToken_);
251 
252  edm::Handle<std::vector<TrackingParticle>> trackingParticles_h;
253  evt.getByToken(trackingParticleToken_, trackingParticles_h);
255  evt.getByToken(recoTracksToken_, recoTracks_h);
256  const auto& TPtoRecoTrackMap = evt.get(associatormapStRsToken_);
257  const auto& simTrackToTPMap = evt.get(associationSimTrackToTPToken_);
258  const auto& recoTracks = *recoTracks_h;
259 
260  const auto& geom = es.getData(geom_token_);
262  const auto num_simclusters = simclusters.size();
263  result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later
264  const auto num_caloparticles = caloparticles.size();
265  result_fromCP->resize(num_caloparticles);
266  std::map<uint, uint> SimClusterToCaloParticleMap;
267  int loop_index = 0;
268  for (const auto& [key, lcVec] : caloParticlesToRecoColl) {
269  auto const& cp = *(key);
270  auto cpIndex = &cp - &caloparticles[0];
271  for (const auto& scRef : cp.simClusters()) {
272  auto const& sc = *(scRef);
273  auto const scIndex = &sc - &simclusters[0];
274  SimClusterToCaloParticleMap[scIndex] = cpIndex;
275  }
276 
277  auto regr_energy = cp.energy();
278  std::vector<uint> scSimTracksterIdx;
279  scSimTracksterIdx.reserve(cp.simClusters().size());
280 
281  // Create a Trackster from the object entering HGCal
282  if (cp.g4Tracks()[0].crossedBoundary()) {
283  regr_energy = cp.g4Tracks()[0].getMomentumAtBoundary().energy();
284  float time = cp.g4Tracks()[0].getPositionAtBoundary().t();
285  addTrackster(cpIndex,
286  lcVec,
287  inputClusterMask,
288  fractionCut_,
289  regr_energy,
290  cp.pdgId(),
291  cp.charge(),
292  time,
293  key.id(),
295  *output_mask,
296  *result,
297  loop_index);
298  } else {
299  for (const auto& scRef : cp.simClusters()) {
300  const auto& it = simClustersToRecoColl.find(scRef);
301  if (it == simClustersToRecoColl.end())
302  continue;
303  const auto& lcVec = it->val;
304  auto const& sc = *(scRef);
305  auto const scIndex = &sc - &simclusters[0];
306 
307  addTrackster(scIndex,
308  lcVec,
309  inputClusterMask,
310  fractionCut_,
311  sc.g4Tracks()[0].getMomentumAtBoundary().energy(),
312  sc.pdgId(),
313  sc.charge(),
314  sc.g4Tracks()[0].getPositionAtBoundary().t(),
315  scRef.id(),
317  *output_mask,
318  *result,
319  loop_index);
320 
321  if (result->empty())
322  continue;
323  const auto index = result->size() - 1;
324  if (std::find(scSimTracksterIdx.begin(), scSimTracksterIdx.end(), index) == scSimTracksterIdx.end()) {
325  scSimTracksterIdx.emplace_back(index);
326  }
327  }
328  scSimTracksterIdx.shrink_to_fit();
329  }
330  float time = simVertices[cp.g4Tracks()[0].vertIndex()].position().t();
331  // Create a Trackster from any CP
332  addTrackster(cpIndex,
333  lcVec,
334  inputClusterMask,
335  fractionCut_,
336  regr_energy,
337  cp.pdgId(),
338  cp.charge(),
339  time,
340  key.id(),
342  *output_mask_fromCP,
343  *result_fromCP,
344  loop_index,
345  true);
346 
347  if (result_fromCP->empty())
348  continue;
349  const auto index = loop_index - 1;
350  if (cpToSc_SimTrackstersMap->find(index) == cpToSc_SimTrackstersMap->end()) {
351  (*cpToSc_SimTrackstersMap)[index] = scSimTracksterIdx;
352  }
353  }
354  // TODO: remove time computation from PCA calculation and
355  // store time from boundary position in simTracksters
358  result->shrink_to_fit();
360  *result_fromCP, layerClusters, layerClustersTimes, rhtools_.getPositionLayer(rhtools_.lastLayerEE(doNose_)).z());
361 
362  makePUTrackster(inputClusterMask, *output_mask, *resultPU, caloParticles_h.id(), 0);
363 
364  auto simTrackToRecoTrack = [&](UniqueSimTrackId simTkId) -> std::pair<int, float> {
365  int trackIdx = -1;
366  float quality = 0.f;
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()) {
373  // associated reco tracks are sorted by decreasing quality
374  if (associatedRecoTracks[0].second > qualityCutTrack_) {
375  trackIdx = &(*associatedRecoTracks[0].first) - &recoTracks[0];
376  quality = associatedRecoTracks[0].second;
377  }
378  }
379  }
380  }
381  return {trackIdx, quality};
382  };
383 
384  // Creating the map from TrackingParticle to SimTrackstersFromCP
385  auto& simTrackstersFromCP = *result_fromCP;
386  for (unsigned int i = 0; i < simTrackstersFromCP.size(); ++i) {
387  if (simTrackstersFromCP[i].vertices().empty())
388  continue;
389  const auto& simTrack = caloparticles[simTrackstersFromCP[i].seedIndex()].g4Tracks()[0];
390  UniqueSimTrackId simTkIds(simTrack.trackId(), simTrack.eventId());
391  auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
392  if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second > qualityCutTrack_) {
393  auto trackIndex = bestAssociatedRecoTrack.first;
394  simTrackstersFromCP[i].setTrackIdx(trackIndex);
395  }
396  }
397 
398  auto& simTracksters = *result;
399  // Creating the map from TrackingParticle to SimTrackster
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())
403  ? caloparticles[simTracksters[i].seedIndex()].g4Tracks()[0]
404  : simclusters[simTracksters[i].seedIndex()].g4Tracks()[0];
405  UniqueSimTrackId simTkIds(simTrack.trackId(), simTrack.eventId());
406  auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
407  if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second > qualityCutTrack_) {
408  auto trackIndex = bestAssociatedRecoTrack.first;
409  simTracksters[i].setTrackIdx(trackIndex);
410  }
411  }
412 
414 
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();
425 
426  auto& cand = (*result_ticlCandidates)[cp_index];
427  cand.addTrackster(edm::Ptr<Trackster>(simTracksters_h, i));
428  if (trackIndex != -1 and (trackIndex < 0 or trackIndex >= (long int)recoTracks.size())) {
429  }
430  cand.setTime((*result_fromCP)[cp_index].time());
431  cand.setTimeError(0);
432  if (trackIndex != -1 && caloparticles[cp_index].charge() != 0)
433  cand.setTrackPtr(edm::Ptr<reco::Track>(recoTracks_h, trackIndex));
434  toKeep.push_back(cp_index);
435  }
436  }
437 
438  auto isHad = [](int pdgId) {
439  pdgId = std::abs(pdgId);
440  if (pdgId == 111)
441  return false;
442  return (pdgId > 100 and pdgId < 900) or (pdgId > 1000 and pdgId < 9000);
443  };
444 
445  for (size_t i = 0; i < result_ticlCandidates->size(); ++i) {
446  auto cp_index = (*result_fromCP)[i].seedIndex();
447  if (cp_index < 0)
448  continue;
449  auto& cand = (*result_ticlCandidates)[i];
450  const auto& cp = caloparticles[cp_index];
451  float rawEnergy = 0.f;
452  float regressedEnergy = 0.f;
453 
454  for (const auto& trackster : cand.tracksters()) {
455  rawEnergy += trackster->raw_energy();
456  regressedEnergy += trackster->regressed_energy();
457  }
458  cand.setRawEnergy(rawEnergy);
459 
460  auto pdgId = cp.pdgId();
461  auto charge = cp.charge();
462  if (cand.trackPtr().isNonnull() and charge == 0) {
463  }
464  if (cand.trackPtr().isNonnull() and charge != 0) {
465  auto const& track = cand.trackPtr().get();
466  if (std::abs(pdgId) == 13) {
467  cand.setPdgId(pdgId);
468  } else {
469  cand.setPdgId((isHad(pdgId) ? 211 : 11) * charge);
470  }
471  cand.setCharge(charge);
472  math::XYZTLorentzVector p4(regressedEnergy * track->momentum().unit().x(),
473  regressedEnergy * track->momentum().unit().y(),
474  regressedEnergy * track->momentum().unit().z(),
475  regressedEnergy);
476  cand.setP4(p4);
477  } else { // neutral candidates
478  cand.setPdgId(isHad(pdgId) ? 130 : 22);
479  cand.setCharge(0);
480 
482  cand.setIdProbability(particleType, 1.f);
483 
484  const auto& simTracksterFromCP = (*result_fromCP)[i];
485  float regressedEnergy = simTracksterFromCP.regressed_energy();
486  math::XYZTLorentzVector p4(regressedEnergy * simTracksterFromCP.barycenter().unit().x(),
487  regressedEnergy * simTracksterFromCP.barycenter().unit().y(),
488  regressedEnergy * simTracksterFromCP.barycenter().unit().z(),
489  regressedEnergy);
490  cand.setP4(p4);
491  }
492  }
493 
494  std::vector<int> all_nums(result_fromCP->size()); // vector containing all caloparticles indexes
495  std::iota(all_nums.begin(), all_nums.end(), 0); // fill the vector with consecutive numbers starting from 0
496 
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);
503  }
504  evt.put(std::move(result_ticlCandidates));
505  evt.put(std::move(output_mask));
506  evt.put(std::move(result_fromCP), "fromCPs");
507  evt.put(std::move(resultPU), "PU");
508  evt.put(std::move(output_mask_fromCP), "fromCPs");
509  evt.put(std::move(cpToSc_SimTrackstersMap));
510 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ProductID id() const
Definition: HandleBase.cc:29
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
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
Definition: Event.h:344
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
Definition: Event.h:528
const edm::EDGetTokenT< SimTrackToTPMap > associationSimTrackToTPToken_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
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.
Definition: LorentzVector.h:29
string quality
Trackster::ParticleType tracksterParticleTypeFromPdgId(int pdgId, int charge)
Definition: commons.h:16
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
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
key
prepare the HTCondor submission files and eventually submit them
double f[11][100]
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 edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticleToken_
GlobalPoint getPositionLayer(int layer, bool nose=false) const
Definition: RecHitTools.cc:152
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:79
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
def move(src, dest)
Definition: eostools.py:511
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:76
void makePUTrackster(const std::vector< float > &inputClusterMask, std::vector< float > &output_mask, std::vector< Trackster > &result, const edm::ProductID seed, int loop_index)

Member Data Documentation

◆ associationSimTrackToTPToken_

const edm::EDGetTokenT<SimTrackToTPMap> SimTrackstersProducer::associationSimTrackToTPToken_
private

Definition at line 102 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ associatorMapCaloParticleToReco_token_

const edm::EDGetTokenT<hgcal::SimToRecoCollection> SimTrackstersProducer::associatorMapCaloParticleToReco_token_
private

Definition at line 89 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ associatormapRtSsToken_

const edm::EDGetTokenT<reco::RecoToSimCollection> SimTrackstersProducer::associatormapRtSsToken_
private

Definition at line 101 of file SimTrackstersProducer.cc.

◆ associatorMapSimClusterToReco_token_

const edm::EDGetTokenT<hgcal::SimToRecoCollectionWithSimClusters> SimTrackstersProducer::associatorMapSimClusterToReco_token_
private

Definition at line 88 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ associatormapStRsToken_

const edm::EDGetTokenT<reco::SimToRecoCollection> SimTrackstersProducer::associatormapStRsToken_
private

Definition at line 100 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ caloparticles_token_

const edm::EDGetTokenT<std::vector<CaloParticle> > SimTrackstersProducer::caloparticles_token_
private

Definition at line 86 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ clusters_token_

const edm::EDGetTokenT<std::vector<reco::CaloCluster> > SimTrackstersProducer::clusters_token_
private

Definition at line 81 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ clustersTime_token_

const edm::EDGetTokenT<edm::ValueMap<std::pair<float, float> > > SimTrackstersProducer::clustersTime_token_
private

Definition at line 82 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ cutTk_

const StringCutObjectSelector<reco::Track> SimTrackstersProducer::cutTk_
private

Definition at line 98 of file SimTrackstersProducer.cc.

◆ detector_

std::string SimTrackstersProducer::detector_
private

Definition at line 79 of file SimTrackstersProducer.cc.

◆ doNose_

const bool SimTrackstersProducer::doNose_ = false
private

Definition at line 80 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ filtered_layerclusters_mask_token_

const edm::EDGetTokenT<std::vector<float> > SimTrackstersProducer::filtered_layerclusters_mask_token_
private

Definition at line 83 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ fractionCut_

const float SimTrackstersProducer::fractionCut_
private

Definition at line 92 of file SimTrackstersProducer.cc.

Referenced by addTrackster(), and produce().

◆ geom_token_

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> SimTrackstersProducer::geom_token_
private

Definition at line 90 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ qualityCutTrack_

const float SimTrackstersProducer::qualityCutTrack_
private

Definition at line 93 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ recoTracksToken_

const edm::EDGetTokenT<std::vector<reco::Track> > SimTrackstersProducer::recoTracksToken_
private

Definition at line 97 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ rhtools_

hgcal::RecHitTools SimTrackstersProducer::rhtools_
private

Definition at line 91 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ simclusters_token_

const edm::EDGetTokenT<std::vector<SimCluster> > SimTrackstersProducer::simclusters_token_
private

Definition at line 85 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ simVerticesToken_

const edm::EDGetTokenT<std::vector<SimVertex> > SimTrackstersProducer::simVerticesToken_
private

Definition at line 95 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ trackingParticleToken_

const edm::EDGetTokenT<std::vector<TrackingParticle> > SimTrackstersProducer::trackingParticleToken_
private

Definition at line 94 of file SimTrackstersProducer.cc.

Referenced by produce().