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_2024v13_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_2024v13_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,
373  result->shrink_to_fit();
374  ticl::assignPCAtoTracksters(*result_fromCP,
376  layerClustersTimes,
379 
380  makePUTrackster(inputClusterMask, *output_mask, *resultPU, caloParticles_h.id(), 0);
381 
382  auto simTrackToRecoTrack = [&](UniqueSimTrackId simTkId) -> std::pair<int, float> {
383  int trackIdx = -1;
384  float quality = 0.f;
385  auto ipos = simTrackToTPMap.mapping.find(simTkId);
386  if (ipos != simTrackToTPMap.mapping.end()) {
387  auto jpos = TPtoRecoTrackMap.find((ipos->second));
388  if (jpos != TPtoRecoTrackMap.end()) {
389  auto& associatedRecoTracks = jpos->val;
390  if (!associatedRecoTracks.empty()) {
391  // associated reco tracks are sorted by decreasing quality
392  if (associatedRecoTracks[0].second > qualityCutTrack_) {
393  trackIdx = &(*associatedRecoTracks[0].first) - &recoTracks[0];
394  quality = associatedRecoTracks[0].second;
395  }
396  }
397  }
398  }
399  return {trackIdx, quality};
400  };
401 
402  // Creating the map from TrackingParticle to SimTrackstersFromCP
403  auto& simTrackstersFromCP = *result_fromCP;
404  for (unsigned int i = 0; i < simTrackstersFromCP.size(); ++i) {
405  if (simTrackstersFromCP[i].vertices().empty())
406  continue;
407  const auto& simTrack = caloparticles[simTrackstersFromCP[i].seedIndex()].g4Tracks()[0];
408  UniqueSimTrackId simTkIds(simTrack.trackId(), simTrack.eventId());
409  auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
410  if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second > qualityCutTrack_) {
411  auto trackIndex = bestAssociatedRecoTrack.first;
412  simTrackstersFromCP[i].setTrackIdx(trackIndex);
413  }
414  }
415 
416  auto& simTracksters = *result;
417  // Creating the map from TrackingParticle to SimTrackster
418  std::unordered_map<unsigned int, std::vector<unsigned int>> TPtoSimTracksterMap;
419  for (unsigned int i = 0; i < simTracksters.size(); ++i) {
420  const auto& simTrack = (simTracksters[i].seedID() == caloParticles_h.id())
421  ? caloparticles[simTracksters[i].seedIndex()].g4Tracks()[0]
422  : simclusters[simTracksters[i].seedIndex()].g4Tracks()[0];
423  UniqueSimTrackId simTkIds(simTrack.trackId(), simTrack.eventId());
424  auto bestAssociatedRecoTrack = simTrackToRecoTrack(simTkIds);
425  if (bestAssociatedRecoTrack.first != -1 and bestAssociatedRecoTrack.second > qualityCutTrack_) {
426  auto trackIndex = bestAssociatedRecoTrack.first;
427  simTracksters[i].setTrackIdx(trackIndex);
428  }
429  }
430 
432 
433  // map between simTrack and Mtd SimTracksters to loop on them only one
434  std::unordered_map<unsigned int, const MtdSimTrackster*> SimTrackToMtdST;
435  for (unsigned int i = 0; i < MTDSimTracksters_h->size(); ++i) {
436  const auto& simTrack = (*MTDSimTracksters_h)[i].g4Tracks()[0];
437  SimTrackToMtdST[simTrack.trackId()] = &((*MTDSimTracksters_h)[i]);
438  }
439 
440  result_ticlCandidates->resize(result_fromCP->size());
441  std::vector<int> toKeep;
442  for (size_t i = 0; i < simTracksters_h->size(); ++i) {
443  const auto& simTrackster = (*simTracksters_h)[i];
444  int cp_index = (simTrackster.seedID() == caloParticles_h.id())
445  ? simTrackster.seedIndex()
446  : SimClusterToCaloParticleMap[simTrackster.seedIndex()];
447  auto const& tCP = (*result_fromCP)[cp_index];
448  if (!tCP.vertices().empty()) {
449  auto trackIndex = tCP.trackIdx();
450 
451  auto& cand = (*result_ticlCandidates)[cp_index];
452  cand.addTrackster(edm::Ptr<Trackster>(simTracksters_h, i));
453  if (trackIndex != -1 && caloparticles[cp_index].charge() != 0)
454  cand.setTrackPtr(edm::Ptr<reco::Track>(recoTracks_h, trackIndex));
455  toKeep.push_back(cp_index);
456  }
457  }
458 
459  auto isHad = [](int pdgId) {
460  pdgId = std::abs(pdgId);
461  if (pdgId == 111)
462  return false;
463  return (pdgId > 100 and pdgId < 900) or (pdgId > 1000 and pdgId < 9000);
464  };
465 
466  for (size_t i = 0; i < result_ticlCandidates->size(); ++i) {
467  auto cp_index = (*result_fromCP)[i].seedIndex();
468  if (cp_index < 0)
469  continue;
470  auto& cand = (*result_ticlCandidates)[i];
471  const auto& cp = caloparticles[cp_index];
472  float rawEnergy = 0.f;
473  float regressedEnergy = 0.f;
474 
475  const auto& simTrack = cp.g4Tracks()[0];
476  auto pos = SimTrackToMtdST.find(simTrack.trackId());
477  if (pos != SimTrackToMtdST.end()) {
478  auto MTDst = pos->second;
479  // TODO: once the associators have been implemented check if the MTDst is associated with a reco before adding the MTD time
480  cand.setMTDTime(MTDst->time(), 0);
481  }
482 
483  cand.setTime(simVertices[cp.g4Tracks()[0].vertIndex()].position().t() * pow(10, 9), 0);
484 
485  for (const auto& trackster : cand.tracksters()) {
486  rawEnergy += trackster->raw_energy();
487  regressedEnergy += trackster->regressed_energy();
488  }
489  cand.setRawEnergy(rawEnergy);
490 
491  auto pdgId = cp.pdgId();
492  auto charge = cp.charge();
493  if (cand.trackPtr().isNonnull()) {
494  auto const& track = cand.trackPtr().get();
495  if (std::abs(pdgId) == 13) {
496  cand.setPdgId(pdgId);
497  } else {
498  cand.setPdgId((isHad(pdgId) ? 211 : 11) * charge);
499  }
500  cand.setCharge(charge);
501  math::XYZTLorentzVector p4(regressedEnergy * track->momentum().unit().x(),
502  regressedEnergy * track->momentum().unit().y(),
503  regressedEnergy * track->momentum().unit().z(),
504  regressedEnergy);
505  cand.setP4(p4);
506  } else { // neutral candidates
507  // a neutral candidate with a charged CaloParticle is charged without a reco track associated with it
508  // set the charge = 0, but keep the real pdgId to keep track of that
509  if (charge != 0)
510  cand.setPdgId(isHad(pdgId) ? 211 : 11);
511  else if (pdgId == 111)
512  cand.setPdgId(pdgId);
513  else
514  cand.setPdgId(isHad(pdgId) ? 130 : 22);
515  cand.setCharge(0);
516 
518  cand.setIdProbability(particleType, 1.f);
519 
520  const auto& simTracksterFromCP = (*result_fromCP)[i];
521  float regressedEnergy = simTracksterFromCP.regressed_energy();
522  math::XYZTLorentzVector p4(regressedEnergy * simTracksterFromCP.barycenter().unit().x(),
523  regressedEnergy * simTracksterFromCP.barycenter().unit().y(),
524  regressedEnergy * simTracksterFromCP.barycenter().unit().z(),
525  regressedEnergy);
526  cand.setP4(p4);
527  }
528  }
529 
530  std::vector<int> all_nums(result_fromCP->size()); // vector containing all caloparticles indexes
531  std::iota(all_nums.begin(), all_nums.end(), 0); // fill the vector with consecutive numbers starting from 0
532 
533  std::vector<int> toRemove;
534  std::set_difference(all_nums.begin(), all_nums.end(), toKeep.begin(), toKeep.end(), std::back_inserter(toRemove));
535  std::sort(toRemove.begin(), toRemove.end(), [](int x, int y) { return x > y; });
536  for (auto const& r : toRemove) {
537  result_fromCP->erase(result_fromCP->begin() + r);
538  result_ticlCandidates->erase(result_ticlCandidates->begin() + r);
539  }
540  evt.put(std::move(result_ticlCandidates));
541  evt.put(std::move(output_mask));
542  evt.put(std::move(result_fromCP), "fromCPs");
543  evt.put(std::move(resultPU), "PU");
544  evt.put(std::move(output_mask_fromCP), "fromCPs");
545  evt.put(std::move(cpToSc_SimTrackstersMap));
546 }
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_
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)
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
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool computeLocalTime=false, bool energyWeight=true)
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().