97 iEvent.getByToken(tracksterToken.second, recoTrackstersHandle);
98 const auto& recoTracksters = *recoTrackstersHandle;
102 layerClusterToTracksterMapHandle;
103 auto tracksterMapTokenIter =
106 [&tracksterToken](
const auto& pair) {
return pair.first == tracksterToken.first; });
108 iEvent.getByToken(tracksterMapTokenIter->second, layerClusterToTracksterMapHandle);
110 const auto& layerClusterToTracksterMap = *layerClusterToTracksterMapHandle;
114 iEvent.getByToken(simTracksterToken.second, simTrackstersHandle);
115 const auto& simTracksters = *simTrackstersHandle;
119 layerClusterToSimTracksterMapHandle;
120 auto simTracksterMapTokenIter =
123 [&simTracksterToken](
const auto& pair) {
return pair.first == simTracksterToken.first; });
125 iEvent.getByToken(simTracksterMapTokenIter->second, layerClusterToSimTracksterMapHandle);
127 const auto& layerClusterToSimTracksterMap = *layerClusterToSimTracksterMapHandle;
130 auto tracksterToSimTracksterMap = std::make_unique<
132 recoTrackstersHandle, simTrackstersHandle,
iEvent);
133 auto simTracksterToTracksterMap = std::make_unique<
135 simTrackstersHandle, recoTrackstersHandle,
iEvent);
137 for (
unsigned int tracksterIndex = 0; tracksterIndex < recoTracksters.size(); ++tracksterIndex) {
138 const auto& recoTrackster = recoTracksters[tracksterIndex];
140 const auto& layerClustersIds = recoTrackster.vertices();
141 float recoToSimScoresDenominator = 0.f;
143 std::vector<unsigned int> associatedSimTracksterIndices;
144 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
145 unsigned int layerClusterId = layerClustersIds[
i];
147 float recoFraction = 1.f / recoTrackster.vertex_multiplicity(
i);
148 float squaredRecoFraction = recoFraction * recoFraction;
149 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
150 recoToSimScoresDenominator += squaredLayerClusterEnergy * squaredRecoFraction;
151 const auto& simTracksterVec = layerClusterToSimTracksterMap[layerClusterId];
152 for (
const auto& [simTracksterIndex, simSharedEnergy] : simTracksterVec) {
153 layerClusterToAssociatedSimTracksterMap[
i].push_back({simTracksterIndex, simSharedEnergy});
154 associatedSimTracksterIndices.push_back(simTracksterIndex);
159 std::sort(associatedSimTracksterIndices.begin(), associatedSimTracksterIndices.end());
160 associatedSimTracksterIndices.erase(
161 std::unique(associatedSimTracksterIndices.begin(), associatedSimTracksterIndices.end()),
162 associatedSimTracksterIndices.end());
165 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
166 unsigned int layerClusterId = layerClustersIds[
i];
167 const auto& simTracksterVec = layerClusterToSimTracksterMap[layerClusterId];
168 for (
unsigned int simTracksterIndex : associatedSimTracksterIndices) {
169 if (std::find_if(simTracksterVec.begin(), simTracksterVec.end(), [simTracksterIndex](
const auto& pair) {
170 return pair.first == simTracksterIndex;
171 }) == simTracksterVec.end()) {
172 layerClusterToAssociatedSimTracksterMap[
i].push_back({simTracksterIndex, 0.f});
177 const float invDenominator = 1.f / recoToSimScoresDenominator;
179 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
180 unsigned int layerClusterId = layerClustersIds[
i];
182 float recoFraction = 1.f / recoTrackster.vertex_multiplicity(
i);
183 float squaredRecoFraction = recoFraction * recoFraction;
184 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
185 float recoSharedEnergy = layerCluster.energy() * recoFraction;
186 float invLayerClusterEnergy = 1.f / layerCluster.energy();
187 const auto& simTracksterVec = layerClusterToAssociatedSimTracksterMap[
i];
188 for (
const auto& [simTracksterIndex, simSharedEnergy] : simTracksterVec) {
191 float simFraction = simSharedEnergy * invLayerClusterEnergy;
192 float score = invDenominator *
193 std::min(squaredRecoFraction, (recoFraction - simFraction) * (recoFraction - simFraction)) *
194 squaredLayerClusterEnergy;
195 tracksterToSimTracksterMap->insert(recoTracksterRef, simTracksterRef,
sharedEnergy,
score);
200 for (
unsigned int tracksterIndex = 0; tracksterIndex < simTracksters.size(); ++tracksterIndex) {
201 const auto& simTrackster = simTracksters[tracksterIndex];
203 const auto& layerClustersIds = simTrackster.vertices();
204 float simToRecoScoresDenominator = 0.f;
206 std::vector<unsigned int> associatedRecoTracksterIndices;
207 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
208 unsigned int layerClusterId = layerClustersIds[
i];
210 float simFraction = 1.f / simTrackster.vertex_multiplicity(
i);
211 float squaredSimFraction = simFraction * simFraction;
212 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
213 simToRecoScoresDenominator += squaredLayerClusterEnergy * squaredSimFraction;
214 const auto& recoTracksterVec = layerClusterToTracksterMap[layerClusterId];
215 for (
const auto& [recoTracksterIndex, recoSharedEnergy] : recoTracksterVec) {
216 layerClusterToAssociatedTracksterMap[
i].push_back({recoTracksterIndex, recoSharedEnergy});
217 associatedRecoTracksterIndices.push_back(recoTracksterIndex);
221 std::sort(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end());
222 associatedRecoTracksterIndices.erase(
223 std::unique(associatedRecoTracksterIndices.begin(), associatedRecoTracksterIndices.end()),
224 associatedRecoTracksterIndices.end());
226 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
227 unsigned int layerClusterId = layerClustersIds[
i];
228 const auto& recoTracksterVec = layerClusterToTracksterMap[layerClusterId];
229 for (
unsigned int recoTracksterIndex : associatedRecoTracksterIndices) {
230 if (std::find_if(recoTracksterVec.begin(), recoTracksterVec.end(), [recoTracksterIndex](
const auto& pair) {
231 return pair.first == recoTracksterIndex;
232 }) == recoTracksterVec.end()) {
233 layerClusterToAssociatedTracksterMap[
i].push_back({recoTracksterIndex, 0.f});
238 const float invDenominator = 1.f / simToRecoScoresDenominator;
240 for (
unsigned int i = 0;
i < layerClustersIds.size(); ++
i) {
241 unsigned int layerClusterId = layerClustersIds[
i];
243 float simFraction = 1.f / simTrackster.vertex_multiplicity(
i);
244 float squaredSimFraction = simFraction * simFraction;
245 float squaredLayerClusterEnergy = layerCluster.energy() * layerCluster.energy();
246 float simSharedEnergy = layerCluster.energy() * simFraction;
247 float invLayerClusterEnergy = 1.f / layerCluster.energy();
248 const auto& recoTracksterVec = layerClusterToAssociatedTracksterMap[
i];
249 for (
const auto& [recoTracksterIndex, recoSharedEnergy] : recoTracksterVec) {
252 float recoFraction = recoSharedEnergy * invLayerClusterEnergy;
253 float score = invDenominator *
254 std::min(squaredSimFraction, (simFraction - recoFraction) * (simFraction - recoFraction)) *
255 squaredLayerClusterEnergy;
256 simTracksterToTracksterMap->insert(tracksterIndex, recoTracksterIndex,
sharedEnergy,
score);
260 tracksterToSimTracksterMap->sort(
true);
261 simTracksterToTracksterMap->sort(
true);
264 iEvent.put(
std::move(tracksterToSimTracksterMap), tracksterToken.first +
"To" + simTracksterToken.first);
265 iEvent.put(
std::move(simTracksterToTracksterMap), simTracksterToken.first +
"To" + tracksterToken.first);
std::vector< std::pair< std::string, edm::EDGetTokenT< std::vector< ticl::Trackster > > > > simTracksterCollectionTokens_
std::vector< std::pair< std::string, edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction, std::vector< reco::CaloCluster >, std::vector< ticl::Trackster > > > > > layerClusterToTracksterMapTokens_
std::vector< std::vector< std::pair< unsigned int, float > >> mapWithFraction
def unique(seq, keepstr=True)
std::vector< std::pair< std::string, edm::EDGetTokenT< ticl::AssociationMap< ticl::mapWithFraction, std::vector< reco::CaloCluster >, std::vector< ticl::Trackster > > > > > layerClusterToSimTracksterMapTokens_
edm::EDGetTokenT< std::vector< reco::CaloCluster > > layerClustersToken_
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)
std::vector< std::pair< std::string, edm::EDGetTokenT< std::vector< ticl::Trackster > > > > tracksterCollectionTokens_