36 const auto& recoTracksters = *recoTrackstersHandle;
40 const auto& simTracksters = *simTrackstersHandle;
47 layerClusterToTracksterMapHandle;
49 const auto& layerClusterToTracksterMap = *layerClusterToTracksterMapHandle;
52 layerClusterToSimTracksterMapHandle;
54 const auto& layerClusterToSimTracksterMap = *layerClusterToSimTracksterMapHandle;
56 auto tracksterToSimTracksterMap = std::make_unique<
58 recoTrackstersHandle, simTrackstersHandle,
iEvent);
59 auto simTracksterToTracksterMap = std::make_unique<
61 simTrackstersHandle, recoTrackstersHandle,
iEvent);
63 for (
unsigned int tracksterIndex = 0; tracksterIndex < recoTracksters.size(); ++tracksterIndex) {
64 const auto& recoTrackster = recoTracksters[tracksterIndex];
66 const auto& layerClustersIds = recoTrackster.vertices();
67 float recoToSimScoresDenominator = 0.f;
69 std::vector<unsigned int> associatedSimTracksterIndices;
70 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
71 unsigned int layerClusterId = layerClustersIds[
i];
73 float recoFraction = 1.f / recoTrackster.vertex_multiplicity(
i);
74 float squaredRecoFraction = recoFraction * recoFraction;
75 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
76 recoToSimScoresDenominator += squaredLayerClusterEnergy * squaredRecoFraction;
77 const auto& simTracksterVec = layerClusterToSimTracksterMap[layerClusterId];
78 for (
const auto& [simTracksterIndex, simSharedEnergy] : simTracksterVec) {
79 layerClusterToAssociatedSimTracksterMap[
i].push_back({simTracksterIndex, simSharedEnergy});
80 associatedSimTracksterIndices.push_back(simTracksterIndex);
85 std::sort(associatedSimTracksterIndices.begin(), associatedSimTracksterIndices.end());
86 associatedSimTracksterIndices.erase(
87 std::unique(associatedSimTracksterIndices.begin(), associatedSimTracksterIndices.end()),
88 associatedSimTracksterIndices.end());
91 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
92 unsigned int layerClusterId = layerClustersIds[
i];
93 const auto& simTracksterVec = layerClusterToSimTracksterMap[layerClusterId];
94 for (
unsigned int simTracksterIndex : associatedSimTracksterIndices) {
95 if (std::find_if(simTracksterVec.begin(), simTracksterVec.end(), [simTracksterIndex](
const auto& pair) {
96 return pair.first == simTracksterIndex;
97 }) == simTracksterVec.end()) {
98 layerClusterToAssociatedSimTracksterMap[
i].push_back({simTracksterIndex, 0.f});
103 const float invDenominator = 1.f / recoToSimScoresDenominator;
105 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
106 unsigned int layerClusterId = layerClustersIds[
i];
108 float recoFraction = 1.f / recoTrackster.vertex_multiplicity(
i);
109 float squaredRecoFraction = recoFraction * recoFraction;
110 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
111 float recoSharedEnergy = layerCluster.energy() * recoFraction;
112 float invLayerClusterEnergy = 1.f / layerCluster.energy();
113 const auto& simTracksterVec = layerClusterToAssociatedSimTracksterMap[
i];
114 for (
const auto& [simTracksterIndex, simSharedEnergy] : simTracksterVec) {
117 float simFraction = simSharedEnergy * invLayerClusterEnergy;
118 float score = invDenominator *
119 std::min(squaredRecoFraction, (recoFraction - simFraction) * (recoFraction - simFraction)) *
120 squaredLayerClusterEnergy;
121 tracksterToSimTracksterMap->insert(recoTracksterRef, simTracksterRef,
sharedEnergy,
score);
126 for (
unsigned int tracksterIndex = 0; tracksterIndex < simTracksters.size(); ++tracksterIndex) {
127 const auto& simTrackster = simTracksters[tracksterIndex];
129 const auto& layerClustersIds = simTrackster.vertices();
130 float simToRecoScoresDenominator = 0.f;
132 std::vector<unsigned int> associatedRecoTracksterIndices;
133 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
134 unsigned int layerClusterId = layerClustersIds[
i];
136 float simFraction = 1.f / simTrackster.vertex_multiplicity(
i);
137 float squaredSimFraction = simFraction * simFraction;
138 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
139 simToRecoScoresDenominator += squaredLayerClusterEnergy * squaredSimFraction;
140 const auto& recoTracksterVec = layerClusterToTracksterMap[layerClusterId];
141 for (
const auto& [recoTracksterIndex, recoSharedEnergy] : recoTracksterVec) {
142 layerClusterToAssociatedTracksterMap[
i].push_back({recoTracksterIndex, recoSharedEnergy});
143 associatedRecoTracksterIndices.push_back(recoTracksterIndex);
147 std::sort(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end());
148 associatedRecoTracksterIndices.erase(
149 std::unique(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end()),
150 associatedRecoTracksterIndices.end());
152 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
153 unsigned int layerClusterId = layerClustersIds[
i];
154 const auto& recoTracksterVec = layerClusterToTracksterMap[layerClusterId];
155 for (
unsigned int recoTracksterIndex : associatedRecoTracksterIndices) {
156 if (std::find_if(recoTracksterVec.begin(), recoTracksterVec.end(), [recoTracksterIndex](
const auto& pair) {
157 return pair.first == recoTracksterIndex;
158 }) == recoTracksterVec.end()) {
159 layerClusterToAssociatedTracksterMap[
i].push_back({recoTracksterIndex, 0.f});
164 const float invDenominator = 1.f / simToRecoScoresDenominator;
166 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
167 unsigned int layerClusterId = layerClustersIds[
i];
169 float simFraction = 1.f / simTrackster.vertex_multiplicity(
i);
170 float squaredSimFraction = simFraction * simFraction;
171 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
172 float simSharedEnergy = layerCluster.energy() * simFraction;
173 float invLayerClusterEnergy = 1.f / layerCluster.energy();
174 const auto& recoTracksterVec = layerClusterToAssociatedTracksterMap[
i];
175 for (
const auto& [recoTracksterIndex, recoSharedEnergy] : recoTracksterVec) {
178 float recoFraction = recoSharedEnergy * invLayerClusterEnergy;
179 float score = invDenominator *
180 std::min(squaredSimFraction, (simFraction - recoFraction) * (simFraction - recoFraction)) *
181 squaredLayerClusterEnergy;
182 simTracksterToTracksterMap->insert(tracksterIndex, recoTracksterIndex,
sharedEnergy,
score);
186 tracksterToSimTracksterMap->sort(
true);
187 simTracksterToTracksterMap->sort(
true);
188 iEvent.put(
std::move(tracksterToSimTracksterMap),
"tracksterToSimTracksterMap");
189 iEvent.put(
std::move(simTracksterToTracksterMap),
"simTracksterToTracksterMap");
edm::EDGetTokenT< std::vector< reco::CaloCluster > > layerClustersCollectionToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > simTracksterCollectionToken_
std::vector< std::vector< std::pair< unsigned int, float > >> mapWithFraction
def unique(seq, keepstr=True)
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction, std::vector< reco::CaloCluster >, std::vector< ticl::Trackster > > > LayerClusterToTracksterMapToken_
edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction, std::vector< reco::CaloCluster >, std::vector< ticl::Trackster > > > LayerClusterToSimTracksterMapToken_
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)
edm::EDGetTokenT< std::vector< ticl::Trackster > > recoTracksterCollectionToken_