28 const auto& tracksters = *tCH.
product();
30 const auto& sC = *sCCH.
product();
31 const auto& cP = *cPCH.
product();
32 const auto cPHandle_id = cPCH.
id();
33 const auto& simTSs = *sTCH.
product();
34 const auto nTracksters = tracksters.size();
35 const auto nSimTracksters = simTSs.size();
37 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdSimTSId_Map;
38 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdSimClusterId_Map;
39 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdCaloParticleId_Map;
40 std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdToRecoTSId_Map;
45 recoToSim_sharedEnergyAndScore.resize(nTracksters);
46 simToReco_sharedEnergyAndScore.resize(nSimTracksters);
48 for (
size_t i = 0;
i < nTracksters; ++
i)
49 recoToSim_sharedEnergyAndScore[
i].resize(nSimTracksters);
50 for (
size_t i = 0;
i < nSimTracksters; ++
i)
51 simToReco_sharedEnergyAndScore[
i].resize(nTracksters);
55 for (
size_t i = 0;
i < sC.size(); ++
i) {
56 for (
const auto& haf : sC[
i].hits_and_fractions()) {
57 detIdSimClusterId_Map[haf.first].emplace_back(
i, haf.second);
61 for (
size_t i = 0;
i < cP.size(); ++
i) {
62 for (
const auto& sc : cP[
i].simClusters()) {
63 for (
const auto& haf : sc->hits_and_fractions()) {
64 auto hitId = haf.first;
65 auto found = std::find_if(detIdCaloParticleId_Map[hitId].
begin(),
66 detIdCaloParticleId_Map[hitId].
end(),
67 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
i); });
68 if (
found == detIdCaloParticleId_Map[hitId].
end())
69 detIdCaloParticleId_Map[haf.first].emplace_back(
i, haf.second);
71 found->second += haf.second;
76 for (
size_t i = 0;
i < nSimTracksters; ++
i) {
77 const auto& lcsInSimTrackster = simTSs[
i].vertices();
78 const auto& multiplicities = simTSs[
i].vertex_multiplicity();
79 for (
size_t j = 0;
j < lcsInSimTrackster.size(); ++
j) {
81 const auto&
v = lcsInSimTrackster[
j];
84 detIdSimTSId_Map[haf.first].emplace_back(
i, haf.second *
fraction);
91 for (
size_t i = 0;
i < nTracksters; ++
i) {
92 const auto& lcsInSimTrackster = tracksters[
i].vertices();
93 const auto& multiplicities = tracksters[
i].vertex_multiplicity();
94 for (
size_t j = 0;
j < lcsInSimTrackster.size(); ++
j) {
96 const auto&
v = lcsInSimTrackster[
j];
99 detIdToRecoTSId_Map[haf.first].emplace_back(
i, haf.second *
fraction);
104 std::vector<float> denominator_simToReco(nSimTracksters, 0.
f);
105 std::vector<std::vector<float>> numerator_simToReco(nSimTracksters);
106 std::vector<std::vector<float>>
sharedEnergy(nSimTracksters);
108 for (
size_t i = 0;
i < nSimTracksters; ++
i) {
109 numerator_simToReco[
i].resize(nTracksters, 0.
f);
112 const auto seedIndex = simTSs[
i].seedIndex();
113 const auto& lcsInSimTrackster = simTSs[
i].vertices();
115 for (
const auto&
v : lcsInSimTrackster) {
117 const auto hitId = haf.first;
118 float simFraction = 0.f;
120 std::vector<std::pair<int, float>>::iterator
found;
121 if (simTSs[
i].seedID() == cPHandle_id) {
122 found = std::find_if(detIdSimTSId_Map[hitId].
begin(),
123 detIdSimTSId_Map[hitId].
end(),
124 [=](
const std::pair<int, float>&
v) {
return v.first == seedIndex; });
125 if (
found != detIdSimTSId_Map[hitId].
end()) {
127 const auto lcFraction =
129 simFraction =
found->second * lcFraction;
132 found = std::find_if(detIdSimClusterId_Map[hitId].
begin(),
133 detIdSimClusterId_Map[hitId].
end(),
134 [=](
const std::pair<int, float>&
v) {
return v.first == seedIndex; });
135 if (
found != detIdSimClusterId_Map[hitId].
end()) {
136 simFraction =
found->second;
141 float hitEnergy =
hit->energy();
142 float hitEnergySquared = hitEnergy * hitEnergy;
143 float simFractionSquared = simFraction * simFraction;
144 denominator_simToReco[
i] += simFractionSquared * hitEnergySquared;
145 for (
size_t j = 0;
j < nTracksters; ++
j) {
146 float recoFraction = 0.f;
149 std::find_if(detIdToRecoTSId_Map[hitId].
begin(),
150 detIdToRecoTSId_Map[hitId].
end(),
151 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
j); });
152 if (found_reco != detIdToRecoTSId_Map[hitId].
end())
153 recoFraction = found_reco->second;
154 numerator_simToReco[
i][
j] +=
155 std::min(simFractionSquared, (simFraction - recoFraction) * (simFraction - recoFraction)) *
163 std::vector<float> denominator_recoToSim(nTracksters, 0.
f);
164 std::vector<std::vector<float>> numerator_recoToSim(nTracksters);
166 for (
unsigned int i = 0;
i < nTracksters; ++
i) {
167 numerator_recoToSim[
i].resize(nSimTracksters, 0.
f);
168 const auto& lcsInTrackster = tracksters[
i].vertices();
169 for (
const auto&
v : lcsInTrackster) {
171 const auto hitId = haf.first;
172 float recoFraction = 0.f;
174 auto found = std::find_if(detIdToRecoTSId_Map[hitId].
begin(),
175 detIdToRecoTSId_Map[hitId].
end(),
176 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
i); });
177 if (
found != detIdToRecoTSId_Map[hitId].
end())
178 recoFraction =
found->second;
181 float hitEnergy =
hit->energy();
182 float hitEnergySquared = hitEnergy * hitEnergy;
183 float recoFractionSquared = recoFraction * recoFraction;
184 denominator_recoToSim[
i] += recoFractionSquared * hitEnergySquared;
186 for (
size_t j = 0;
j < nSimTracksters; ++
j) {
187 float simFraction = 0.f;
189 auto found_sim = std::find_if(detIdSimTSId_Map[hitId].
begin(),
190 detIdSimTSId_Map[hitId].
end(),
191 [=](
const std::pair<int, float>&
v) {
return v.first ==
static_cast<int>(
j); });
192 if (found_sim != detIdSimTSId_Map[hitId].
end())
193 simFraction = found_sim->second;
194 numerator_recoToSim[
i][
j] +=
195 std::min(recoFractionSquared, (simFraction - recoFraction) * (simFraction - recoFraction)) *
204 for (
size_t i = 0;
i < nSimTracksters; ++
i) {
205 for (
size_t j = 0;
j < nTracksters; ++
j) {
207 simToReco_sharedEnergyAndScore[
i][
j].second = numerator_simToReco[
i][
j] / denominator_simToReco[
i];
209 recoToSim_sharedEnergyAndScore[
j][
i].second = numerator_recoToSim[
j][
i] / denominator_recoToSim[
j];
213 return {recoToSim_sharedEnergyAndScore, simToReco_sharedEnergyAndScore};
std::vector< const HGCRecHit * > hits_
T const * product() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const std::unordered_map< DetId, const unsigned int > * hitMap_
std::vector< std::vector< std::pair< float, float > > > sharedEnergyAndScore_t
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)