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, 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)
 
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< ticl::SimToRecoCollectionassociatorMapCaloParticleToReco_token_
 
const edm::EDGetTokenT< reco::RecoToSimCollectionassociatormapRtSsToken_
 
const edm::EDGetTokenT< ticl::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 bool computeLocalTime_
 
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 edm::EDGetTokenT< MtdSimTracksterCollectionMTDSimTrackstersToken_
 
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 53 of file SimTrackstersProducer.cc.

Constructor & Destructor Documentation

◆ SimTrackstersProducer()

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

Definition at line 111 of file SimTrackstersProducer.cc.

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"))),
120  MTDSimTrackstersToken_(consumes<MtdSimTracksterCollection>(ps.getParameter<edm::InputTag>("MtdSimTracksters"))),
122  consumes(ps.getParameter<edm::InputTag>("layerClusterSimClusterAssociator"))),
124  consumes(ps.getParameter<edm::InputTag>("layerClusterCaloParticleAssociator"))),
126  fractionCut_(ps.getParameter<double>("fractionCut")),
127  qualityCutTrack_(ps.getParameter<double>("qualityCutTrack")),
129  consumes<std::vector<TrackingParticle>>(ps.getParameter<edm::InputTag>("trackingParticles"))),
130  simVerticesToken_(consumes<std::vector<SimVertex>>(ps.getParameter<edm::InputTag>("simVertices"))),
131  recoTracksToken_(consumes<std::vector<reco::Track>>(ps.getParameter<edm::InputTag>("recoTracks"))),
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>>();
142 }
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< MtdSimTracksterCollection > MTDSimTrackstersToken_
const edm::EDGetTokenT< std::vector< SimVertex > > simVerticesToken_
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< ticl::SimToRecoCollectionWithSimClusters > associatorMapSimClusterToReco_token_
const edm::EDGetTokenT< std::vector< SimCluster > > simclusters_token_
const edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
const edm::EDGetTokenT< ticl::SimToRecoCollection > associatorMapCaloParticleToReco_token_
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,
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 
)

Definition at line 190 of file SimTrackstersProducer.cc.

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

Referenced by produce().

204  {
205  Trackster tmpTrackster;
206  if (lcVec.empty()) {
207  result[index] = tmpTrackster;
208  return;
209  }
210 
211  tmpTrackster.vertices().reserve(lcVec.size());
212  tmpTrackster.vertex_multiplicity().reserve(lcVec.size());
213  for (auto const& [lc, energyScorePair] : lcVec) {
214  if (inputClusterMask[lc.index()] > 0) {
215  double fraction = energyScorePair.first / lc->energy();
216  if (fraction < fractionCut_)
217  continue;
218  tmpTrackster.vertices().push_back(lc.index());
219  output_mask[lc.index()] -= fraction;
220  tmpTrackster.vertex_multiplicity().push_back(1. / fraction);
221  }
222  }
223 
225  tmpTrackster.setRegressedEnergy(energy);
226  tmpTrackster.setIteration(iter);
227  tmpTrackster.setSeed(seed, index);
228  tmpTrackster.setBoundaryTime(time * 1e9);
229  if (add) {
230  result[index] = tmpTrackster;
231  loop_index += 1;
232  } else {
233  result.push_back(tmpTrackster);
234  }
235 }
void setSeed(edm::ProductID pid, int index)
Definition: Trackster.h:60
void setRegressedEnergy(float value)
Definition: Trackster.h:68
Trackster::ParticleType tracksterParticleTypeFromPdgId(int pdgId, int charge)
Definition: Common.h:44
double f[11][100]
std::vector< unsigned int > & vertices()
Definition: Trackster.h:57
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:58
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
void setIteration(const Trackster::IterationIndex i)
Definition: Trackster.h:56
void setBoundaryTime(float t)
Definition: Trackster.h:141
void setIdProbability(ParticleType type, float value)
Definition: Trackster.h:139

◆ fillDescriptions()

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

Definition at line 144 of file SimTrackstersProducer.cc.

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

144  {
146  desc.add<std::string>("detector", "HGCAL");
147  desc.add<bool>("computeLocalTime", "false");
148  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
149  desc.add<edm::InputTag>("time_layerclusters", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster"));
150  desc.add<edm::InputTag>("filtered_mask", edm::InputTag("filteredLayerClustersSimTracksters", "ticlSimTracksters"));
151  desc.add<edm::InputTag>("simclusters", edm::InputTag("mix", "MergedCaloTruth"));
152  desc.add<edm::InputTag>("caloparticles", edm::InputTag("mix", "MergedCaloTruth"));
153  desc.add<edm::InputTag>("MtdSimTracksters", edm::InputTag("mix", "MergedMtdTruthST"));
154  desc.add<edm::InputTag>("layerClusterSimClusterAssociator",
155  edm::InputTag("layerClusterSimClusterAssociationProducer"));
156  desc.add<edm::InputTag>("layerClusterCaloParticleAssociator",
157  edm::InputTag("layerClusterCaloParticleAssociationProducer"));
158  desc.add<edm::InputTag>("recoTracks", edm::InputTag("generalTracks"));
159  desc.add<std::string>("cutTk",
160  "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && "
161  "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
162  desc.add<edm::InputTag>("tpToTrack", edm::InputTag("trackingParticleRecoTrackAsssociation"));
163 
164  desc.add<edm::InputTag>("trackingParticles", edm::InputTag("mix", "MergedTrackTruth"));
165  desc.add<edm::InputTag>("simVertices", edm::InputTag("g4SimHits"));
166 
167  desc.add<edm::InputTag>("simTrackToTPMap", edm::InputTag("simHitTPAssocProducer", "simTrackToTP"));
168  desc.add<double>("fractionCut", 0.);
169  desc.add<double>("qualityCutTrack", 0.75);
170 
171  descriptions.addWithDefaultLabel(desc);
172 }
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 173 of file SimTrackstersProducer.cc.

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

Referenced by produce().

177  {
178  Trackster tmpTrackster;
179  for (size_t i = 0; i < output_mask.size(); i++) {
180  const float remaining_fraction = output_mask[i];
181  if (remaining_fraction > std::numeric_limits<float>::epsilon()) {
182  tmpTrackster.vertices().push_back(i);
183  tmpTrackster.vertex_multiplicity().push_back(1. / remaining_fraction);
184  }
185  }
186  tmpTrackster.setSeed(seed, 0);
187  result.push_back(tmpTrackster);
188 }
void setSeed(edm::ProductID pid, int index)
Definition: Trackster.h:60
std::vector< unsigned int > & vertices()
Definition: Trackster.h:57
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:58

◆ produce()

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

Definition at line 237 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_, computeLocalTime_, 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(), MTDSimTrackstersToken_, or, PbPb_ZMuSkimMuonDPG_cff::particleType, EgammaValidation_cff::pdgId, funct::pow(), edm::Event::put(), quality, qualityCutTrack_, alignCSCRings::r, electrons_cff::rawEnergy, HGCalValidator_cfi::recoTracks, 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_2024v14_cff::track, trackingParticleToken_, ticl::tracksterParticleTypeFromPdgId(), AlignmentTracksFromVertexSelector_cfi::vertices, x, y, and z.

237  {
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>>();
245 
246  const auto& layerClusters = evt.get(clusters_token_);
247  const auto& layerClustersTimes = evt.get(clustersTime_token_);
248  const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_);
249  output_mask->resize(layerClusters.size(), 1.f);
250  output_mask_fromCP->resize(layerClusters.size(), 1.f);
251 
252  const auto& simclusters = evt.get(simclusters_token_);
253  edm::Handle<std::vector<CaloParticle>> caloParticles_h;
254  evt.getByToken(caloparticles_token_, caloParticles_h);
255  const auto& caloparticles = *caloParticles_h;
256 
257  edm::Handle<MtdSimTracksterCollection> MTDSimTracksters_h;
258  evt.getByToken(MTDSimTrackstersToken_, MTDSimTracksters_h);
259 
260  const auto& simClustersToRecoColl = evt.get(associatorMapSimClusterToReco_token_);
261  const auto& caloParticlesToRecoColl = evt.get(associatorMapCaloParticleToReco_token_);
262  const auto& simVertices = evt.get(simVerticesToken_);
263 
264  edm::Handle<std::vector<TrackingParticle>> trackingParticles_h;
265  evt.getByToken(trackingParticleToken_, trackingParticles_h);
267  evt.getByToken(recoTracksToken_, recoTracks_h);
268  const auto& TPtoRecoTrackMap = evt.get(associatormapStRsToken_);
269  const auto& simTrackToTPMap = evt.get(associationSimTrackToTPToken_);
270  const auto& recoTracks = *recoTracks_h;
271 
272  const auto& geom = es.getData(geom_token_);
274  const auto num_simclusters = simclusters.size();
275  result->reserve(num_simclusters); // Conservative size, will call shrink_to_fit later
276  const auto num_caloparticles = caloparticles.size();
277  result_fromCP->resize(num_caloparticles);
278  std::map<uint, uint> SimClusterToCaloParticleMap;
279  int loop_index = 0;
280  for (const auto& [key, lcVec] : caloParticlesToRecoColl) {
281  auto const& cp = *(key);
282  auto cpIndex = &cp - &caloparticles[0];
283  for (const auto& scRef : cp.simClusters()) {
284  auto const& sc = *(scRef);
285  auto const scIndex = &sc - &simclusters[0];
286  SimClusterToCaloParticleMap[scIndex] = cpIndex;
287  }
288 
289  auto regr_energy = cp.energy();
290  std::vector<uint> scSimTracksterIdx;
291  scSimTracksterIdx.reserve(cp.simClusters().size());
292 
293  // Create a Trackster from the object entering HGCal
294  if (cp.g4Tracks()[0].crossedBoundary()) {
295  regr_energy = cp.g4Tracks()[0].getMomentumAtBoundary().energy();
296  float time = cp.g4Tracks()[0].getPositionAtBoundary().t();
297  addTrackster(cpIndex,
298  lcVec,
299  inputClusterMask,
300  fractionCut_,
301  regr_energy,
302  cp.pdgId(),
303  cp.charge(),
304  time,
305  key.id(),
307  *output_mask,
308  *result,
309  loop_index);
310  } else {
311  for (const auto& scRef : cp.simClusters()) {
312  const auto& it = simClustersToRecoColl.find(scRef);
313  if (it == simClustersToRecoColl.end())
314  continue;
315  const auto& lcVec = it->val;
316  auto const& sc = *(scRef);
317  auto const scIndex = &sc - &simclusters[0];
318 
319  addTrackster(scIndex,
320  lcVec,
321  inputClusterMask,
322  fractionCut_,
323  sc.g4Tracks()[0].getMomentumAtBoundary().energy(),
324  sc.pdgId(),
325  sc.charge(),
326  sc.g4Tracks()[0].getPositionAtBoundary().t(),
327  scRef.id(),
329  *output_mask,
330  *result,
331  loop_index);
332 
333  if (result->empty())
334  continue;
335  const auto index = result->size() - 1;
336  if (std::find(scSimTracksterIdx.begin(), scSimTracksterIdx.end(), index) == scSimTracksterIdx.end()) {
337  scSimTracksterIdx.emplace_back(index);
338  }
339  }
340  scSimTracksterIdx.shrink_to_fit();
341  }
342  float time = simVertices[cp.g4Tracks()[0].vertIndex()].position().t();
343  // Create a Trackster from any CP
344  addTrackster(cpIndex,
345  lcVec,
346  inputClusterMask,
347  fractionCut_,
348  regr_energy,
349  cp.pdgId(),
350  cp.charge(),
351  time,
352  key.id(),
354  *output_mask_fromCP,
355  *result_fromCP,
356  loop_index,
357  true);
358 
359  if (result_fromCP->empty())
360  continue;
361  const auto index = loop_index - 1;
362  if (cpToSc_SimTrackstersMap->find(index) == cpToSc_SimTrackstersMap->end()) {
363  (*cpToSc_SimTrackstersMap)[index] = scSimTracksterIdx;
364  }
365  }
366  // TODO: remove time computation from PCA calculation and
367  // store time from boundary position in simTracksters
370  layerClustersTimes,
372  rhtools_,
374  result->shrink_to_fit();
375  ticl::assignPCAtoTracksters(*result_fromCP,
377  layerClustersTimes,
379  rhtools_,
381 
382  makePUTrackster(inputClusterMask, *output_mask, *resultPU, caloParticles_h.id(), 0);
383 
384  auto simTrackToRecoTrack = [&](UniqueSimTrackId simTkId) -> std::pair<int, float> {
385  int trackIdx = -1;
386  float quality = 0.f;
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()) {
393  // associated reco tracks are sorted by decreasing quality
394  if (associatedRecoTracks[0].second > qualityCutTrack_) {
395  trackIdx = &(*associatedRecoTracks[0].first) - &recoTracks[0];
396  quality = associatedRecoTracks[0].second;
397  }
398  }
399  }
400  }
401  return {trackIdx, quality};
402  };
403 
404  // Creating the map from TrackingParticle to SimTrackstersFromCP
405  auto& simTrackstersFromCP = *result_fromCP;
406  for (unsigned int i = 0; i < simTrackstersFromCP.size(); ++i) {
407  if (simTrackstersFromCP[i].vertices().empty())
408  continue;
409  const auto& simTrack = caloparticles[simTrackstersFromCP[i].seedIndex()].g4Tracks()[0];
410  UniqueSimTrackId simTkIds(simTrack.trackId(), simTrack.eventId());
411  auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
412  if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second > qualityCutTrack_) {
413  auto trackIndex = bestAssociatedRecoTrack.first;
414  simTrackstersFromCP[i].setTrackIdx(trackIndex);
415  }
416  }
417 
418  auto& simTracksters = *result;
419  // Creating the map from TrackingParticle to SimTrackster
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())
423  ? caloparticles[simTracksters[i].seedIndex()].g4Tracks()[0]
424  : simclusters[simTracksters[i].seedIndex()].g4Tracks()[0];
425  UniqueSimTrackId simTkIds(simTrack.trackId(), simTrack.eventId());
426  auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
427  if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second > qualityCutTrack_) {
428  auto trackIndex = bestAssociatedRecoTrack.first;
429  simTracksters[i].setTrackIdx(trackIndex);
430  }
431  }
432 
434 
435  // map between simTrack and Mtd SimTracksters to loop on them only one
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]);
440  }
441 
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();
452 
453  auto& cand = (*result_ticlCandidates)[cp_index];
454  cand.addTrackster(edm::Ptr<Trackster>(simTracksters_h, i));
455  if (trackIndex != -1 && caloparticles[cp_index].charge() != 0)
456  cand.setTrackPtr(edm::Ptr<reco::Track>(recoTracks_h, trackIndex));
457  toKeep.push_back(cp_index);
458  }
459  }
460 
461  auto isHad = [](int pdgId) {
462  pdgId = std::abs(pdgId);
463  if (pdgId == 111)
464  return false;
465  return (pdgId > 100 and pdgId < 900) or (pdgId > 1000 and pdgId < 9000);
466  };
467 
468  for (size_t i = 0; i < result_ticlCandidates->size(); ++i) {
469  auto cp_index = (*result_fromCP)[i].seedIndex();
470  if (cp_index < 0)
471  continue;
472  auto& cand = (*result_ticlCandidates)[i];
473  const auto& cp = caloparticles[cp_index];
474  float rawEnergy = 0.f;
475  float regressedEnergy = 0.f;
476 
477  const auto& simTrack = cp.g4Tracks()[0];
478  auto pos = SimTrackToMtdST.find(simTrack.trackId());
479  if (pos != SimTrackToMtdST.end()) {
480  auto MTDst = pos->second;
481  // TODO: once the associators have been implemented check if the MTDst is associated with a reco before adding the MTD time
482  cand.setMTDTime(MTDst->time(), 0);
483  }
484 
485  cand.setTime(simVertices[cp.g4Tracks()[0].vertIndex()].position().t() * pow(10, 9), 0);
486 
487  for (const auto& trackster : cand.tracksters()) {
488  rawEnergy += trackster->raw_energy();
489  regressedEnergy += trackster->regressed_energy();
490  }
491  cand.setRawEnergy(rawEnergy);
492 
493  auto pdgId = cp.pdgId();
494  auto charge = cp.charge();
495  if (cand.trackPtr().isNonnull()) {
496  auto const& track = cand.trackPtr().get();
497  if (std::abs(pdgId) == 13) {
498  cand.setPdgId(pdgId);
499  } else {
500  cand.setPdgId((isHad(pdgId) ? 211 : 11) * charge);
501  }
502  cand.setCharge(charge);
503  math::XYZTLorentzVector p4(regressedEnergy * track->momentum().unit().x(),
504  regressedEnergy * track->momentum().unit().y(),
505  regressedEnergy * track->momentum().unit().z(),
506  regressedEnergy);
507  cand.setP4(p4);
508  } else { // neutral candidates
509  // a neutral candidate with a charged CaloParticle is charged without a reco track associated with it
510  // set the charge = 0, but keep the real pdgId to keep track of that
511  if (charge != 0)
512  cand.setPdgId(isHad(pdgId) ? 211 : 11);
513  else if (pdgId == 111)
514  cand.setPdgId(pdgId);
515  else
516  cand.setPdgId(isHad(pdgId) ? 130 : 22);
517  cand.setCharge(0);
518 
520  cand.setIdProbability(particleType, 1.f);
521 
522  const auto& simTracksterFromCP = (*result_fromCP)[i];
523  float regressedEnergy = simTracksterFromCP.regressed_energy();
524  math::XYZTLorentzVector p4(regressedEnergy * simTracksterFromCP.barycenter().unit().x(),
525  regressedEnergy * simTracksterFromCP.barycenter().unit().y(),
526  regressedEnergy * simTracksterFromCP.barycenter().unit().z(),
527  regressedEnergy);
528  cand.setP4(p4);
529  }
530  }
531 
532  std::vector<int> all_nums(result_fromCP->size()); // vector containing all caloparticles indexes
533  std::iota(all_nums.begin(), all_nums.end(), 0); // fill the vector with consecutive numbers starting from 0
534 
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);
541  }
542  evt.put(std::move(result_ticlCandidates));
543  evt.put(std::move(output_mask));
544  evt.put(std::move(result_fromCP), "fromCPs");
545  evt.put(std::move(resultPU), "PU");
546  evt.put(std::move(output_mask_fromCP), "fromCPs");
547  evt.put(std::move(cpToSc_SimTrackstersMap));
548 }
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
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< 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
Definition: Event.h:526
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)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
string quality
Trackster::ParticleType tracksterParticleTypeFromPdgId(int pdgId, int charge)
Definition: Common.h:44
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
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)
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< ticl::SimToRecoCollectionWithSimClusters > associatorMapSimClusterToReco_token_
const edm::EDGetTokenT< std::vector< SimCluster > > simclusters_token_
hgcal::RecHitTools rhtools_
const edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
const edm::EDGetTokenT< ticl::SimToRecoCollection > associatorMapCaloParticleToReco_token_
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)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
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 106 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ associatorMapCaloParticleToReco_token_

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

Definition at line 93 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ associatormapRtSsToken_

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

Definition at line 105 of file SimTrackstersProducer.cc.

◆ associatorMapSimClusterToReco_token_

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

Definition at line 92 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ associatormapStRsToken_

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

Definition at line 104 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ caloparticles_token_

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

Definition at line 89 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ clusters_token_

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

Definition at line 84 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 85 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ computeLocalTime_

const bool SimTrackstersProducer::computeLocalTime_
private

Definition at line 83 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ cutTk_

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

Definition at line 102 of file SimTrackstersProducer.cc.

◆ detector_

std::string SimTrackstersProducer::detector_
private

Definition at line 81 of file SimTrackstersProducer.cc.

◆ doNose_

const bool SimTrackstersProducer::doNose_ = false
private

Definition at line 82 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 86 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ fractionCut_

const float SimTrackstersProducer::fractionCut_
private

Definition at line 96 of file SimTrackstersProducer.cc.

Referenced by addTrackster(), and produce().

◆ geom_token_

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

Definition at line 94 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ MTDSimTrackstersToken_

const edm::EDGetTokenT<MtdSimTracksterCollection> SimTrackstersProducer::MTDSimTrackstersToken_
private

Definition at line 90 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ qualityCutTrack_

const float SimTrackstersProducer::qualityCutTrack_
private

Definition at line 97 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ recoTracksToken_

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

Definition at line 101 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ rhtools_

hgcal::RecHitTools SimTrackstersProducer::rhtools_
private

Definition at line 95 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ simclusters_token_

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

Definition at line 88 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ simVerticesToken_

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

Definition at line 99 of file SimTrackstersProducer.cc.

Referenced by produce().

◆ trackingParticleToken_

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

Definition at line 98 of file SimTrackstersProducer.cc.

Referenced by produce().