23 const auto& tracksters = *tCH.
product();
25 const auto& sC = *sCCH.
product();
26 const auto& cP = *cPCH.
product();
27 const auto cPHandle_id = cPCH.
id();
28 const auto& simTSs = *sTCH.
product();
29 const auto nTracksters = tracksters.size();
30 const auto nSimTracksters = simTSs.size();
32 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdSimTSId_Map;
33 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdSimClusterId_Map;
34 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdCaloParticleId_Map;
35 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdToRecoTSId_Map;
40 recoToSim_sharedEnergyAndScore.resize(nTracksters);
41 simToReco_sharedEnergyAndScore.resize(nSimTracksters);
43 for (
size_t i = 0;
i < nTracksters; ++
i)
44 recoToSim_sharedEnergyAndScore[
i].resize(nSimTracksters);
45 for (
size_t i = 0;
i < nSimTracksters; ++
i)
46 simToReco_sharedEnergyAndScore[
i].resize(nTracksters);
50 for (
size_t i = 0;
i < sC.size(); ++
i) {
51 for (
const auto& haf : sC[
i].hits_and_fractions()) {
52 detIdSimClusterId_Map[haf.first].emplace_back(
i, haf.second);
56 for (
size_t i = 0;
i < cP.size(); ++
i) {
57 for (
const auto& sc : cP[
i].simClusters()) {
58 for (
const auto& haf : sc->hits_and_fractions()) {
59 auto hitId = haf.first;
60 auto found = std::find_if(detIdCaloParticleId_Map[hitId].
begin(),
61 detIdCaloParticleId_Map[hitId].
end(),
62 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
i); });
63 if (
found == detIdCaloParticleId_Map[hitId].
end())
64 detIdCaloParticleId_Map[haf.first].emplace_back(
i, haf.second);
66 found->second += haf.second;
71 for (
size_t i = 0;
i < nSimTracksters; ++
i) {
72 const auto& lcsInSimTrackster = simTSs[
i].vertices();
73 const auto& multiplicities = simTSs[
i].vertex_multiplicity();
74 for (
size_t j = 0;
j < lcsInSimTrackster.size(); ++
j) {
76 const auto&
v = lcsInSimTrackster[
j];
79 detIdSimTSId_Map[haf.first].emplace_back(
i, haf.second *
fraction);
86 for (
size_t i = 0;
i < nTracksters; ++
i) {
87 const auto& lcsInSimTrackster = tracksters[
i].vertices();
88 const auto& multiplicities = tracksters[
i].vertex_multiplicity();
89 for (
size_t j = 0;
j < lcsInSimTrackster.size(); ++
j) {
91 const auto&
v = lcsInSimTrackster[
j];
94 detIdToRecoTSId_Map[haf.first].emplace_back(
i, haf.second *
fraction);
99 std::vector<float> denominator_simToReco(nSimTracksters, 0.
f);
100 std::vector<std::vector<float>> numerator_simToReco(nSimTracksters);
101 std::vector<std::vector<float>>
sharedEnergy(nSimTracksters);
103 for (
size_t i = 0;
i < nSimTracksters; ++
i) {
104 numerator_simToReco[
i].resize(nTracksters, 0.
f);
107 const auto seedIndex = simTSs[
i].seedIndex();
108 const auto& lcsInSimTrackster = simTSs[
i].vertices();
110 for (
const auto&
v : lcsInSimTrackster) {
112 const auto hitId = haf.first;
113 float simFraction = 0.f;
115 std::vector<std::pair<int, float>>::iterator
found;
116 if (simTSs[
i].seedID() == cPHandle_id) {
117 found = std::find_if(detIdSimTSId_Map[hitId].
begin(),
118 detIdSimTSId_Map[hitId].
end(),
119 [=](
const std::pair<int, float>&
v) {
return v.first == seedIndex; });
120 if (
found != detIdSimTSId_Map[hitId].
end()) {
122 const auto lcFraction =
124 simFraction =
found->second * lcFraction;
127 found = std::find_if(detIdSimClusterId_Map[hitId].
begin(),
128 detIdSimClusterId_Map[hitId].
end(),
129 [=](
const std::pair<int, float>&
v) {
return v.first == seedIndex; });
130 if (
found != detIdSimClusterId_Map[hitId].
end()) {
131 simFraction =
found->second;
135 float hitEnergy =
hitMap_->find(hitId)->second->energy();
136 float hitEnergySquared = hitEnergy * hitEnergy;
137 float simFractionSquared = simFraction * simFraction;
138 denominator_simToReco[
i] += simFractionSquared * hitEnergySquared;
139 for (
size_t j = 0;
j < nTracksters; ++
j) {
140 float recoFraction = 0.f;
143 std::find_if(detIdToRecoTSId_Map[hitId].
begin(),
144 detIdToRecoTSId_Map[hitId].
end(),
145 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
j); });
146 if (found_reco != detIdToRecoTSId_Map[hitId].
end())
147 recoFraction = found_reco->second;
148 numerator_simToReco[
i][
j] +=
149 std::min(simFractionSquared, (simFraction - recoFraction) * (simFraction - recoFraction)) *
157 std::vector<float> denominator_recoToSim(nTracksters, 0.
f);
158 std::vector<std::vector<float>> numerator_recoToSim(nTracksters);
160 for (
unsigned int i = 0;
i < nTracksters; ++
i) {
161 numerator_recoToSim[
i].resize(nSimTracksters, 0.
f);
162 const auto& lcsInTrackster = tracksters[
i].vertices();
163 for (
const auto&
v : lcsInTrackster) {
165 const auto hitId = haf.first;
166 float recoFraction = 0.f;
168 auto found = std::find_if(detIdToRecoTSId_Map[hitId].
begin(),
169 detIdToRecoTSId_Map[hitId].
end(),
170 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
i); });
171 if (
found != detIdToRecoTSId_Map[hitId].
end())
172 recoFraction =
found->second;
174 float hitEnergy =
hitMap_->find(hitId)->second->energy();
175 float hitEnergySquared = hitEnergy * hitEnergy;
176 float recoFractionSquared = recoFraction * recoFraction;
177 denominator_recoToSim[
i] += recoFractionSquared * hitEnergySquared;
179 for (
size_t j = 0;
j < nSimTracksters; ++
j) {
180 float simFraction = 0.f;
182 auto found_sim = std::find_if(detIdSimTSId_Map[hitId].
begin(),
183 detIdSimTSId_Map[hitId].
end(),
184 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
j); });
185 if (found_sim != detIdSimTSId_Map[hitId].
end())
186 simFraction = found_sim->second;
187 numerator_recoToSim[
i][
j] +=
188 std::min(recoFractionSquared, (simFraction - recoFraction) * (simFraction - recoFraction)) *
197 for (
size_t i = 0;
i < nSimTracksters; ++
i) {
198 for (
size_t j = 0;
j < nTracksters; ++
j) {
200 simToReco_sharedEnergyAndScore[
i][
j].second = numerator_simToReco[
i][
j] / denominator_simToReco[
i];
202 recoToSim_sharedEnergyAndScore[
j][
i].second = numerator_recoToSim[
j][
i] / denominator_recoToSim[
j];
206 return {recoToSim_sharedEnergyAndScore, simToReco_sharedEnergyAndScore};
T const * product() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< std::vector< std::pair< float, float > > > sharedEnergyAndScore_t
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)