CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
TracksterToSimTracksterAssociatorByHitsProducer Class Reference

#include <TracksterToSimTracksterAssociatorByHitsProducer.h>

Inheritance diagram for TracksterToSimTracksterAssociatorByHitsProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 TracksterToSimTracksterAssociatorByHitsProducer (const edm::ParameterSet &)
 
 ~TracksterToSimTracksterAssociatorByHitsProducer () override
 
- Public Member Functions inherited from edm::global::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
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

edm::EDGetTokenT< std::vector< CaloParticle > > caloParticleToken_
 
std::vector< edm::EDGetTokenT< HGCRecHitCollection > > hitsTokens_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToCaloParticleMapToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimClusterMapToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimTracksterFromCPMapToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimTracksterMapToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToTracksterMapToken_
 
edm::EDGetTokenT< std::vector< ticl::Trackster > > recoTracksterCollectionToken_
 
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterCollectionToken_
 
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterFromCPCollectionToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > simTracksterFromCPToHitMapToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > simTracksterToHitMapToken_
 
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > tracksterToHitMapToken_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 23 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Constructor & Destructor Documentation

◆ TracksterToSimTracksterAssociatorByHitsProducer()

TracksterToSimTracksterAssociatorByHitsProducer::TracksterToSimTracksterAssociatorByHitsProducer ( const edm::ParameterSet pset)
explicit

Definition at line 17 of file TracksterToSimTracksterAssociatorByHitsProducer.cc.

References hitsTokens_, edm::ProductRegistryHelper::produces(), muonDTDigis_cfi::pset, and makeGlobalPositionRcd_cfg::tag.

20  consumes<std::vector<ticl::Trackster>>(pset.getParameter<edm::InputTag>("tracksters"))),
22  consumes<std::vector<ticl::Trackster>>(pset.getParameter<edm::InputTag>("simTracksters"))),
24  consumes<std::vector<ticl::Trackster>>(pset.getParameter<edm::InputTag>("simTrackstersFromCP"))),
26  consumes<ticl::AssociationMap<ticl::mapWithFraction>>(pset.getParameter<edm::InputTag>("hitToTracksterMap"))),
28  pset.getParameter<edm::InputTag>("hitToSimTracksterMap"))),
30  pset.getParameter<edm::InputTag>("hitToSimTracksterFromCPMap"))),
32  pset.getParameter<edm::InputTag>("hitToSimClusterMap"))),
34  pset.getParameter<edm::InputTag>("hitToCaloParticleMap"))),
36  consumes<ticl::AssociationMap<ticl::mapWithFraction>>(pset.getParameter<edm::InputTag>("tracksterToHitMap"))),
38  pset.getParameter<edm::InputTag>("simTracksterToHitMap"))),
40  pset.getParameter<edm::InputTag>("simTracksterFromCPToHitMap"))),
41  caloParticleToken_(consumes<std::vector<CaloParticle>>(pset.getParameter<edm::InputTag>("caloParticles"))) {
42  auto hitsTags = pset.getParameter<std::vector<edm::InputTag>>("hits");
43  for (const auto& tag : hitsTags) {
44  hitsTokens_.push_back(consumes<HGCRecHitCollection>(tag));
45  }
46  produces<
48  "tracksterToSimTracksterMap");
49  produces<
51  "simTracksterToTracksterMap");
52  produces<
54  "tracksterToSimTracksterFromCPMap");
55  produces<
57  "simTracksterFromCPToTracksterMap");
58 }
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToCaloParticleMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > simTracksterToHitMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimTracksterMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimTracksterFromCPMapToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterCollectionToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterFromCPCollectionToken_
std::vector< edm::EDGetTokenT< HGCRecHitCollection > > hitsTokens_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > simTracksterFromCPToHitMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > tracksterToHitMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimClusterMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToTracksterMapToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > recoTracksterCollectionToken_

◆ ~TracksterToSimTracksterAssociatorByHitsProducer()

TracksterToSimTracksterAssociatorByHitsProducer::~TracksterToSimTracksterAssociatorByHitsProducer ( )
override

Definition at line 60 of file TracksterToSimTracksterAssociatorByHitsProducer.cc.

60 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 416 of file TracksterToSimTracksterAssociatorByHitsProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

416  {
418  desc.add<edm::InputTag>("tracksters", edm::InputTag("ticlTrackstersMerge"));
419  desc.add<edm::InputTag>("simTracksters", edm::InputTag("ticlSimTracksters"));
420  desc.add<edm::InputTag>("simTrackstersFromCP", edm::InputTag("ticlSimTracksters", "fromCPs"));
421 
422  desc.add<edm::InputTag>("hitToTracksterMap", edm::InputTag("hitToTracksterAssociator", "hitToTracksterMap"));
423  desc.add<edm::InputTag>("hitToSimTracksterMap",
424  edm::InputTag("allHitToTracksterAssociations", "hitToticlSimTracksters"));
425  desc.add<edm::InputTag>("hitToSimTracksterFromCPMap",
426  edm::InputTag("allHitToTracksterAssociations", "hitToticlSimTrackstersfromCPs"));
427  desc.add<edm::InputTag>("hitToSimClusterMap",
428  edm::InputTag("hitToSimClusterCaloParticleAssociator", "hitToSimClusterMap"));
429  desc.add<edm::InputTag>("hitToCaloParticleMap",
430  edm::InputTag("hitToSimClusterCaloParticleAssociator", "hitToCaloParticleMap"));
431  desc.add<edm::InputTag>("tracksterToHitMap", edm::InputTag("hitToTrackstersAssociationPR", "tracksterToHitMap"));
432  desc.add<edm::InputTag>("simTracksterToHitMap",
433  edm::InputTag("allHitToTracksterAssociations", "ticlSimTrackstersToHit"));
434  desc.add<edm::InputTag>("simTracksterFromCPToHitMap",
435  edm::InputTag("allHitToTracksterAssociations", "ticlSimTrackstersfromCPsToHit"));
436  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
437 
438  desc.add<std::vector<edm::InputTag>>("hits",
439  {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
440  edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
441  edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
442  descriptions.add("tracksterToSimTracksterAssociatorByHitsProducer", desc);
443 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void TracksterToSimTracksterAssociatorByHitsProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 62 of file TracksterToSimTracksterAssociatorByHitsProducer.cc.

References MultiVectorManager< T >::addVector(), SplitLinear::begin, caloParticleToken_, mps_fire::end, f, HLT_2024v14_cff::fraction, hitsTokens_, hitToCaloParticleMapToken_, hitToSimClusterMapToken_, TSToSimTSAssociationByHits_cfi::hitToSimTracksterFromCPMap, hitToSimTracksterFromCPMapToken_, TSToSimTSAssociationByHits_cfi::hitToSimTracksterMap, hitToSimTracksterMapToken_, TSToSimTSAssociationByHits_cfi::hitToTracksterMap, hitToTracksterMapToken_, mps_fire::i, edm::HandleBase::id(), iEvent, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, SiStripPI::min, eostools::move(), rpcPointValidation_cfi::recHit, recoTracksterCollectionToken_, offlineSlimmedPrimaryVertices_cfi::score, fileCollector::seed, egamma::sharedEnergy(), simTracksterCollectionToken_, simTracksterFromCPCollectionToken_, TSToSimTSAssociationByHits_cfi::simTracksterFromCPToHitMap, simTracksterFromCPToHitMapToken_, TSToSimTSAssociationByHits_cfi::simTracksterToHitMap, simTracksterToHitMapToken_, jetUpdater_cfi::sort, unpackBuffers-CaloStage2::token, TSToSimTSAssociationByHits_cfi::tracksterToHitMap, tracksterToHitMapToken_, and tier0::unique().

64  {
65  using namespace edm;
66 
67  Handle<std::vector<ticl::Trackster>> recoTrackstersHandle;
68  iEvent.getByToken(recoTracksterCollectionToken_, recoTrackstersHandle);
69  const auto& recoTracksters = *recoTrackstersHandle;
70 
71  Handle<std::vector<ticl::Trackster>> simTrackstersHandle;
72  iEvent.getByToken(simTracksterCollectionToken_, simTrackstersHandle);
73  const auto& simTracksters = *simTrackstersHandle;
74 
75  Handle<std::vector<ticl::Trackster>> simTrackstersFromCPHandle;
76  iEvent.getByToken(simTracksterFromCPCollectionToken_, simTrackstersFromCPHandle);
77  const auto& simTrackstersFromCP = *simTrackstersFromCPHandle;
78 
80  iEvent.getByToken(hitToTracksterMapToken_, hitToTracksterMapHandle);
81  const auto& hitToTracksterMap = *hitToTracksterMapHandle;
82 
83  Handle<ticl::AssociationMap<ticl::mapWithFraction>> hitToSimTracksterMapHandle;
84  iEvent.getByToken(hitToSimTracksterMapToken_, hitToSimTracksterMapHandle);
85  const auto& hitToSimTracksterMap = *hitToSimTracksterMapHandle;
86 
87  Handle<ticl::AssociationMap<ticl::mapWithFraction>> hitToSimTracksterFromCPMapHandle;
88  iEvent.getByToken(hitToSimTracksterFromCPMapToken_, hitToSimTracksterFromCPMapHandle);
89  const auto& hitToSimTracksterFromCPMap = *hitToSimTracksterFromCPMapHandle;
90 
92  iEvent.getByToken(hitToSimClusterMapToken_, hitToSimClusterMapHandle);
93  const auto& hitToSimClusterMap = *hitToSimClusterMapHandle;
94 
95  Handle<ticl::AssociationMap<ticl::mapWithFraction>> hitToCaloParticleMapHandle;
96  iEvent.getByToken(hitToCaloParticleMapToken_, hitToCaloParticleMapHandle);
97  const auto& hitToCaloParticleMap = *hitToCaloParticleMapHandle;
98 
100  iEvent.getByToken(tracksterToHitMapToken_, tracksterToHitMapHandle);
101  const auto& tracksterToHitMap = *tracksterToHitMapHandle;
102 
103  Handle<ticl::AssociationMap<ticl::mapWithFraction>> simTracksterToHitMapHandle;
104  iEvent.getByToken(simTracksterToHitMapToken_, simTracksterToHitMapHandle);
105  const auto& simTracksterToHitMap = *simTracksterToHitMapHandle;
106 
107  Handle<ticl::AssociationMap<ticl::mapWithFraction>> simTracksterFromCPToHitMapHandle;
108  iEvent.getByToken(simTracksterFromCPToHitMapToken_, simTracksterFromCPToHitMapHandle);
109  const auto& simTracksterFromCPToHitMap = *simTracksterFromCPToHitMapHandle;
110 
111  Handle<std::vector<CaloParticle>> caloParticlesHandle;
112  iEvent.getByToken(caloParticleToken_, caloParticlesHandle);
113 
114  MultiVectorManager<HGCRecHit> rechitManager;
115  for (const auto& token : hitsTokens_) {
116  Handle<HGCRecHitCollection> hitsHandle;
117  iEvent.getByToken(token, hitsHandle);
118  rechitManager.addVector(*hitsHandle);
119  }
120 
121  auto tracksterToSimTracksterMap = std::make_unique<
123  recoTrackstersHandle, simTrackstersHandle, iEvent);
124  auto tracksterToSimTracksterFromCPMap = std::make_unique<
126  recoTrackstersHandle, simTrackstersFromCPHandle, iEvent);
127 
128  auto simTracksterToTracksterMap = std::make_unique<
130  simTrackstersHandle, recoTrackstersHandle, iEvent);
131  auto simTracksterFromCPToTracksterMap = std::make_unique<
133  simTrackstersFromCPHandle, recoTrackstersHandle, iEvent);
134  for (unsigned int tracksterIndex = 0; tracksterIndex < recoTracksters.size(); ++tracksterIndex) {
135  edm::Ref<std::vector<ticl::Trackster>> recoTracksterRef(recoTrackstersHandle, tracksterIndex);
136  float recoToSimScoresDenominator = 0.f;
137  const auto& recoTracksterHitsAndFractions = tracksterToHitMap[tracksterIndex];
138  ticl::AssociationMap<ticl::mapWithFraction> hitToAssociatedSimTracksterMap(recoTracksterHitsAndFractions.size());
139  std::vector<unsigned int> associatedSimTracksterIndices;
140  ticl::AssociationMap<ticl::mapWithFraction> hitToAssociatedSimTracksterFromCPMap(
141  recoTracksterHitsAndFractions.size());
142  std::vector<unsigned int> associatedSimTracksterFromCPIndices;
143  for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) {
144  const auto& [hitIndex, recoFraction] = recoTracksterHitsAndFractions[i];
145  const auto& recHit = rechitManager[hitIndex];
146  float squaredRecoFraction = recoFraction * recoFraction;
147  float rechitEnergy = recHit.energy();
148  float squaredRecHitEnergy = rechitEnergy * rechitEnergy;
149  recoToSimScoresDenominator += squaredRecoFraction * squaredRecHitEnergy;
150 
151  const auto& hitToSimTracksterVec = hitToSimTracksterMap[hitIndex];
152  for (const auto& [simTracksterIndex, fraction] : hitToSimTracksterVec) {
153  const auto& simTrackster = simTracksters[simTracksterIndex];
154  auto& seed = simTrackster.seedID();
155  float simFraction = 0;
156  if (seed == caloParticlesHandle.id()) {
157  unsigned int caloParticleIndex = simTrackster.seedIndex();
158  auto it = std::find_if(hitToCaloParticleMap[hitIndex].begin(),
159  hitToCaloParticleMap[hitIndex].end(),
160  [caloParticleIndex](const auto& pair) { return pair.first == caloParticleIndex; });
161  if (it != hitToCaloParticleMap[hitIndex].end()) {
162  simFraction = it->second;
163  }
164  } else {
165  unsigned int simClusterIndex = simTracksters[simTracksterIndex].seedIndex();
166  auto it = std::find_if(hitToSimClusterMap[hitIndex].begin(),
167  hitToSimClusterMap[hitIndex].end(),
168  [simClusterIndex](const auto& pair) { return pair.first == simClusterIndex; });
169  if (it != hitToSimClusterMap[hitIndex].end()) {
170  simFraction = it->second;
171  }
172  }
173  hitToAssociatedSimTracksterMap.insert(i, simTracksterIndex, simFraction);
174  associatedSimTracksterIndices.push_back(simTracksterIndex);
175  }
176 
177  // do the same for caloparticles and simTracksterFromCP
178  const auto& hitToSimTracksterFromCPVec = hitToSimTracksterFromCPMap[hitIndex];
179  for (const auto& [simTracksterIndex, simFraction] : hitToSimTracksterFromCPVec) {
180  unsigned int caloParticleIndex = simTracksters[simTracksterIndex].seedIndex();
181  float caloParticleFraction = 0;
182  auto it = std::find_if(hitToCaloParticleMap[hitIndex].begin(),
183  hitToCaloParticleMap[hitIndex].end(),
184  [caloParticleIndex](const auto& pair) { return pair.first == caloParticleIndex; });
185  if (it != hitToCaloParticleMap[hitIndex].end()) {
186  caloParticleFraction = it->second;
187  }
188  hitToAssociatedSimTracksterFromCPMap.insert(i, simTracksterIndex, caloParticleFraction);
189  associatedSimTracksterFromCPIndices.push_back(simTracksterIndex);
190  }
191  }
192  std::sort(associatedSimTracksterIndices.begin(), associatedSimTracksterIndices.end());
193  associatedSimTracksterIndices.erase(
194  std::unique(associatedSimTracksterIndices.begin(), associatedSimTracksterIndices.end()),
195  associatedSimTracksterIndices.end());
196 
197  std::sort(associatedSimTracksterFromCPIndices.begin(), associatedSimTracksterFromCPIndices.end());
198  associatedSimTracksterFromCPIndices.erase(
199  std::unique(associatedSimTracksterFromCPIndices.begin(), associatedSimTracksterFromCPIndices.end()),
200  associatedSimTracksterFromCPIndices.end());
201 
202  // Add missing sim tracksters with 0 shared energy to hitToAssociatedSimTracksterMap and hitToAssociatedSimTracksterFromCPMap
203  for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) {
204  unsigned int hitId = recoTracksterHitsAndFractions[i].first;
205  const auto& simTracksterVec = hitToSimTracksterMap[hitId];
206  for (unsigned int simTracksterIndex : associatedSimTracksterIndices) {
207  if (std::find_if(simTracksterVec.begin(), simTracksterVec.end(), [simTracksterIndex](const auto& pair) {
208  return pair.first == simTracksterIndex;
209  }) == simTracksterVec.end()) {
210  hitToAssociatedSimTracksterMap.insert(i, simTracksterIndex, 0);
211  }
212  }
213 
214  const auto& simTracksterFromCPVec = hitToSimTracksterFromCPMap[hitId];
215  for (unsigned int simTracksterIndex : associatedSimTracksterFromCPIndices) {
216  if (std::find_if(
217  simTracksterFromCPVec.begin(), simTracksterFromCPVec.end(), [simTracksterIndex](const auto& pair) {
218  return pair.first == simTracksterIndex;
219  }) == simTracksterFromCPVec.end()) {
220  hitToAssociatedSimTracksterFromCPMap.insert(i, simTracksterIndex, 0);
221  }
222  }
223  }
224 
225  const float invDenominator = 1.f / recoToSimScoresDenominator;
226 
227  for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) {
228  unsigned int hitIndex = recoTracksterHitsAndFractions[i].first;
229  const auto& recHit = rechitManager[hitIndex];
230  float recoFraction = recoTracksterHitsAndFractions[i].second;
231  float squaredRecoFraction = recoFraction * recoFraction;
232  float squaredRecHitEnergy = recHit.energy() * recHit.energy();
233  float recoSharedEnergy = recHit.energy() * recoFraction;
234  const auto& simTracksterVec = hitToAssociatedSimTracksterMap[i];
235  for (const auto& [simTracksterIndex, simFraction] : simTracksterVec) {
236  edm::Ref<std::vector<ticl::Trackster>> simTracksterRef(simTrackstersHandle, simTracksterIndex);
237  float sharedEnergy = std::min(simFraction * recHit.energy(), recoSharedEnergy);
238  float squaredFraction =
239  std::min(squaredRecoFraction, (recoFraction - simFraction) * (recoFraction - simFraction));
240  float score = invDenominator * squaredFraction * squaredRecHitEnergy;
241  tracksterToSimTracksterMap->insert(recoTracksterRef, simTracksterRef, sharedEnergy, score);
242  }
243 
244  const auto& simTracksterFromCPVec = hitToAssociatedSimTracksterFromCPMap[i];
245  for (const auto& [simTracksterIndex, simFraction] : simTracksterFromCPVec) {
246  edm::Ref<std::vector<ticl::Trackster>> simTracksterRef(simTrackstersFromCPHandle, simTracksterIndex);
247  float sharedEnergy = std::min(simFraction * recHit.energy(), recoSharedEnergy);
248  float squaredFraction =
249  std::min(squaredRecoFraction, (recoFraction - simFraction) * (recoFraction - simFraction));
250  float score = invDenominator * squaredFraction * squaredRecHitEnergy;
251  tracksterToSimTracksterFromCPMap->insert(recoTracksterRef, simTracksterRef, sharedEnergy, score);
252  }
253  }
254  }
255 
256  // Reverse mapping: SimTrackster -> RecoTrackster
257  for (unsigned int tracksterIndex = 0; tracksterIndex < simTracksters.size(); ++tracksterIndex) {
258  edm::Ref<std::vector<ticl::Trackster>> simTracksterRef(simTrackstersHandle, tracksterIndex);
259  float simToRecoScoresDenominator = 0.f;
260  const auto& simTracksterHitsAndFractions = simTracksterToHitMap[tracksterIndex];
261  ticl::AssociationMap<ticl::mapWithFraction> hitToAssociatedRecoTracksterMap(simTracksterHitsAndFractions.size());
262  std::vector<unsigned int> associatedRecoTracksterIndices;
263  const auto& simTrackster = simTracksters[tracksterIndex];
264  auto& seed = simTrackster.seedID();
265  unsigned int simObjectIndex = simTrackster.seedIndex();
266  bool isSimTracksterFromCP = (seed == caloParticlesHandle.id());
267  std::vector<float> simFractions(simTracksterHitsAndFractions.size(), 0.f);
268  for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
269  const auto& [hitIndex, simTracksterFraction] = simTracksterHitsAndFractions[i];
270 
271  auto it = isSimTracksterFromCP
272  ? (std::find_if(hitToCaloParticleMap[hitIndex].begin(),
273  hitToCaloParticleMap[hitIndex].end(),
274  [simObjectIndex](const auto& pair) { return pair.first == simObjectIndex; }))
275  : std::find_if(hitToSimClusterMap[hitIndex].begin(),
276  hitToSimClusterMap[hitIndex].end(),
277  [simObjectIndex](const auto& pair) { return pair.first == simObjectIndex; });
278  if (it != hitToCaloParticleMap[hitIndex].end() and it != hitToSimClusterMap[hitIndex].end()) {
279  simFractions[i] = it->second;
280  }
281  float simFraction = simFractions[i];
282  const auto& recHit = rechitManager[hitIndex];
283  float squaredSimFraction = simFraction * simFraction;
284  float squaredRecHitEnergy = recHit.energy() * recHit.energy();
285  simToRecoScoresDenominator += squaredSimFraction * squaredRecHitEnergy;
286 
287  const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
288  for (const auto& [recoTracksterIndex, recoFraction] : hitToRecoTracksterVec) {
289  hitToAssociatedRecoTracksterMap.insert(i, recoTracksterIndex, recoFraction);
290  associatedRecoTracksterIndices.push_back(recoTracksterIndex);
291  }
292  }
293 
294  std::sort(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end());
295  associatedRecoTracksterIndices.erase(
296  std::unique(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end()),
297  associatedRecoTracksterIndices.end());
298 
299  for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
300  unsigned int hitIndex = simTracksterHitsAndFractions[i].first;
301  const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
302  for (unsigned int recoTracksterIndex : associatedRecoTracksterIndices) {
303  if (std::find_if(
304  hitToRecoTracksterVec.begin(), hitToRecoTracksterVec.end(), [recoTracksterIndex](const auto& pair) {
305  return pair.first == recoTracksterIndex;
306  }) == hitToRecoTracksterVec.end()) {
307  hitToAssociatedRecoTracksterMap.insert(i, recoTracksterIndex, 0);
308  }
309  }
310  }
311 
312  const float invDenominator = 1.f / simToRecoScoresDenominator;
313 
314  for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
315  const auto& [hitIndex, simTracksterFraction] = simTracksterHitsAndFractions[i];
316  float simFraction = simFractions[i];
317  const auto& recHit = rechitManager[hitIndex];
318  float squaredSimFraction = simFraction * simFraction;
319  float squaredRecHitEnergy = recHit.energy() * recHit.energy();
320  float simSharedEnergy = recHit.energy() * simFraction;
321 
322  const auto& hitToRecoTracksterVec = hitToAssociatedRecoTracksterMap[i];
323  for (const auto& [recoTracksterIndex, recoFraction] : hitToRecoTracksterVec) {
324  edm::Ref<std::vector<ticl::Trackster>> recoTracksterRef(recoTrackstersHandle, recoTracksterIndex);
325  float sharedEnergy = std::min(recoFraction * recHit.energy(), simSharedEnergy);
326  float squaredFraction =
327  std::min(squaredSimFraction, (recoFraction - simFraction) * (recoFraction - simFraction));
328  float score = invDenominator * squaredFraction * squaredRecHitEnergy;
329  simTracksterToTracksterMap->insert(simTracksterRef, recoTracksterRef, sharedEnergy, score);
330  }
331  }
332  }
333 
334  // Repeat the reverse mapping process for SimTracksterFromCP
335  for (unsigned int tracksterIndex = 0; tracksterIndex < simTrackstersFromCP.size(); ++tracksterIndex) {
336  edm::Ref<std::vector<ticl::Trackster>> simTracksterRef(simTrackstersFromCPHandle, tracksterIndex);
337  float simToRecoScoresDenominator = 0.f;
338  const auto& simTracksterHitsAndFractions = simTracksterFromCPToHitMap[tracksterIndex];
339  ticl::AssociationMap<ticl::mapWithFraction> hitToAssociatedRecoTracksterMap(simTracksterHitsAndFractions.size());
340  std::vector<unsigned int> associatedRecoTracksterIndices;
341  std::vector<float> simFractions(simTracksterHitsAndFractions.size(), 0.f);
342  const auto& simTrackster = simTrackstersFromCP[tracksterIndex];
343  unsigned int simObjectIndex = simTrackster.seedIndex();
344  for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
345  const auto& [hitIndex, simTracksterFraction] = simTracksterHitsAndFractions[i];
346  auto it = std::find_if(hitToCaloParticleMap[hitIndex].begin(),
347  hitToCaloParticleMap[hitIndex].end(),
348  [simObjectIndex](const auto& pair) { return pair.first == simObjectIndex; });
349  if (it != hitToCaloParticleMap[hitIndex].end()) {
350  simFractions[i] = it->second;
351  }
352  float simFraction = simFractions[i];
353 
354  const auto& recHit = rechitManager[hitIndex];
355  float squaredSimFraction = simFraction * simFraction;
356  float squaredRecHitEnergy = recHit.energy() * recHit.energy();
357  simToRecoScoresDenominator += squaredSimFraction * squaredRecHitEnergy;
358 
359  const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
360  for (const auto& [recoTracksterIndex, recoFraction] : hitToRecoTracksterVec) {
361  hitToAssociatedRecoTracksterMap.insert(i, recoTracksterIndex, recoFraction);
362  associatedRecoTracksterIndices.push_back(recoTracksterIndex);
363  }
364  }
365 
366  std::sort(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end());
367  associatedRecoTracksterIndices.erase(
368  std::unique(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end()),
369  associatedRecoTracksterIndices.end());
370 
371  for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
372  unsigned int hitIndex = simTracksterHitsAndFractions[i].first;
373  const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
374  for (unsigned int recoTracksterIndex : associatedRecoTracksterIndices) {
375  if (std::find_if(
376  hitToRecoTracksterVec.begin(), hitToRecoTracksterVec.end(), [recoTracksterIndex](const auto& pair) {
377  return pair.first == recoTracksterIndex;
378  }) == hitToRecoTracksterVec.end()) {
379  hitToAssociatedRecoTracksterMap.insert(i, recoTracksterIndex, 0.f);
380  }
381  }
382  }
383 
384  const float invDenominator = 1.f / simToRecoScoresDenominator;
385 
386  for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
387  const auto& [hitIndex, simTracksterFraction] = simTracksterHitsAndFractions[i];
388  const auto& recHit = rechitManager[hitIndex];
389  float simFraction = simFractions[i];
390  float squaredSimFraction = simFraction * simFraction;
391  float squaredRecHitEnergy = recHit.energy() * recHit.energy();
392  float simSharedEnergy = recHit.energy() * simFraction;
393 
394  const auto& hitToRecoTracksterVec = hitToAssociatedRecoTracksterMap[i];
395  for (const auto& [recoTracksterIndex, recoFraction] : hitToRecoTracksterVec) {
396  edm::Ref<std::vector<ticl::Trackster>> recoTracksterRef(recoTrackstersHandle, recoTracksterIndex);
397  float sharedEnergy = std::min(recoFraction * recHit.energy(), simSharedEnergy);
398  float squaredFraction =
399  std::min(squaredSimFraction, (recoFraction - simFraction) * (recoFraction - simFraction));
400  float score = invDenominator * squaredFraction * squaredRecHitEnergy;
401  simTracksterFromCPToTracksterMap->insert(simTracksterRef, recoTracksterRef, sharedEnergy, score);
402  }
403  }
404  }
405  tracksterToSimTracksterMap->sort(true);
406  tracksterToSimTracksterFromCPMap->sort(true);
407  simTracksterToTracksterMap->sort(true);
408  simTracksterFromCPToTracksterMap->sort(true);
409 
410  iEvent.put(std::move(tracksterToSimTracksterMap), "tracksterToSimTracksterMap");
411  iEvent.put(std::move(tracksterToSimTracksterFromCPMap), "tracksterToSimTracksterFromCPMap");
412  iEvent.put(std::move(simTracksterToTracksterMap), "simTracksterToTracksterMap");
413  iEvent.put(std::move(simTracksterFromCPToTracksterMap), "simTracksterFromCPToTracksterMap");
414 }
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToCaloParticleMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > simTracksterToHitMapToken_
ProductID id() const
Definition: HandleBase.cc:29
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimTracksterMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimTracksterFromCPMapToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterCollectionToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterFromCPCollectionToken_
int iEvent
Definition: GenABIO.cc:224
std::vector< edm::EDGetTokenT< HGCRecHitCollection > > hitsTokens_
def unique(seq, keepstr=True)
Definition: tier0.py:24
double f[11][100]
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > simTracksterFromCPToHitMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > tracksterToHitMapToken_
void addVector(std::span< const T > vec)
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)
HLT enums.
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToSimClusterMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction > > hitToTracksterMapToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > recoTracksterCollectionToken_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ caloParticleToken_

edm::EDGetTokenT<std::vector<CaloParticle> > TracksterToSimTracksterAssociatorByHitsProducer::caloParticleToken_
private

Definition at line 44 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ hitsTokens_

std::vector<edm::EDGetTokenT<HGCRecHitCollection> > TracksterToSimTracksterAssociatorByHitsProducer::hitsTokens_
private

◆ hitToCaloParticleMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::hitToCaloParticleMapToken_
private

Definition at line 40 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ hitToSimClusterMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::hitToSimClusterMapToken_
private

Definition at line 39 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ hitToSimTracksterFromCPMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::hitToSimTracksterFromCPMapToken_
private

Definition at line 38 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ hitToSimTracksterMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::hitToSimTracksterMapToken_
private

Definition at line 37 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ hitToTracksterMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::hitToTracksterMapToken_
private

Definition at line 36 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ recoTracksterCollectionToken_

edm::EDGetTokenT<std::vector<ticl::Trackster> > TracksterToSimTracksterAssociatorByHitsProducer::recoTracksterCollectionToken_
private

Definition at line 33 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ simTracksterCollectionToken_

edm::EDGetTokenT<std::vector<ticl::Trackster> > TracksterToSimTracksterAssociatorByHitsProducer::simTracksterCollectionToken_
private

Definition at line 34 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ simTracksterFromCPCollectionToken_

edm::EDGetTokenT<std::vector<ticl::Trackster> > TracksterToSimTracksterAssociatorByHitsProducer::simTracksterFromCPCollectionToken_
private

Definition at line 35 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ simTracksterFromCPToHitMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::simTracksterFromCPToHitMapToken_
private

Definition at line 43 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ simTracksterToHitMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::simTracksterToHitMapToken_
private

Definition at line 42 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().

◆ tracksterToHitMapToken_

edm::EDGetTokenT<ticl::AssociationMap<ticl::mapWithFraction> > TracksterToSimTracksterAssociatorByHitsProducer::tracksterToHitMapToken_
private

Definition at line 41 of file TracksterToSimTracksterAssociatorByHitsProducer.h.

Referenced by produce().