Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:38:07

0001 // Original Author: Leonardo Cristella
0002 //
0003 
0004 #include "LCToSimTSAssociatorByEnergyScoreImpl.h"
0005 #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
0006 #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 LCToSimTSAssociatorByEnergyScoreImpl::LCToSimTSAssociatorByEnergyScoreImpl(edm::EDProductGetter const& productGetter)
0011     : productGetter_(&productGetter) {}
0012 
0013 ticl::RecoToSimTracksterCollection LCToSimTSAssociatorByEnergyScoreImpl::associateRecoToSim(
0014     const edm::Handle<reco::CaloClusterCollection>& cCCH,
0015     const edm::Handle<ticl::TracksterCollection>& sTCH,
0016     const edm::Handle<CaloParticleCollection>& cPCH,
0017     const ticl::RecoToSimCollection& lCToCPs,
0018     const edm::Handle<SimClusterCollection>& sCCH,
0019     const ticl::RecoToSimCollectionWithSimClusters& lCToSCs) const {
0020   ticl::RecoToSimTracksterCollection returnValue(productGetter_);
0021 
0022   const auto simTracksters = *sTCH.product();
0023 
0024   for (size_t lcId = 0; lcId < cCCH.product()->size(); ++lcId) {
0025     const edm::Ref<reco::CaloClusterCollection> lcRef(cCCH, lcId);
0026     for (size_t tsId = 0; tsId < simTracksters.size(); ++tsId) {
0027       if (simTracksters[tsId].seedID() == cPCH.id()) {
0028         const auto& cpIt = lCToCPs.find(lcRef);
0029         if (cpIt == lCToCPs.end()) {
0030           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0031               << "LayerCluster Id " << lcId << " not found in CaloParticle association map\n";
0032           continue;
0033         }
0034 
0035         const edm::Ref<CaloParticleCollection> cpRef(cPCH, simTracksters[tsId].seedIndex());
0036         const auto& cps = cpIt->val;
0037         const auto cpPair = std::find_if(
0038             std::begin(cps), std::end(cps), [&cpRef](const std::pair<edm::Ref<CaloParticleCollection>, float>& p) {
0039               return p.first == cpRef;
0040             });
0041         if (cpPair == cps.end()) {
0042           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl") << "CaloParticle Id " << simTracksters[tsId].seedIndex()
0043                                                            << " not found in LayerCluster association map\n";
0044           continue;
0045         } else {
0046           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0047               << "LayerCluster Id: \t" << lcId << "\t CaloParticle Id: \t" << cpPair->first.index() << "\t score \t"
0048               << cpPair->second << "\n";
0049           // Fill AssociationMap
0050           returnValue.insert(lcRef,                                                           // Ref to LC
0051                              std::make_pair(edm::Ref<ticl::TracksterCollection>(sTCH, tsId),  // Pair <Ref to TS, score>
0052                                             cpPair->second));
0053         }
0054       } else if (simTracksters[tsId].seedID() == sCCH.id()) {
0055         const auto& scIt = lCToSCs.find(lcRef);
0056         if (scIt == lCToSCs.end()) {
0057           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0058               << "LayerCluster Id " << lcId << " not found in SimCluster association map\n";
0059           continue;
0060         }
0061 
0062         const edm::Ref<SimClusterCollection> scRef(sCCH, simTracksters[tsId].seedIndex());
0063         const auto& scs = scIt->val;
0064         const auto scPair = std::find_if(
0065             std::begin(scs), std::end(scs), [&scRef](const std::pair<edm::Ref<SimClusterCollection>, float>& p) {
0066               return p.first == scRef;
0067             });
0068         if (scPair == scs.end()) {
0069           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0070               << "SimCluster Id " << simTracksters[tsId].seedIndex() << " not found in LayerCluster association map\n";
0071           continue;
0072         } else {
0073           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0074               << "LayerCluster Id: \t" << lcId << "\t SimCluster Id: \t" << scPair->first.index() << "\t score \t"
0075               << scPair->second << "\n";
0076           // Fill AssociationMap
0077           returnValue.insert(lcRef,                                                           // Ref to LC
0078                              std::make_pair(edm::Ref<ticl::TracksterCollection>(sTCH, tsId),  // Pair <Ref to TS, score>
0079                                             scPair->second));
0080         }
0081       } else {
0082         LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0083             << "The seedID " << simTracksters[tsId].seedID() << " of SimTrackster " << tsId
0084             << " is neither a CaloParticle nor a SimCluster!\n";
0085       }
0086     }  // end loop over simTracksters
0087   }  // end loop over layerClusters
0088 
0089   return returnValue;
0090 }
0091 
0092 ticl::SimTracksterToRecoCollection LCToSimTSAssociatorByEnergyScoreImpl::associateSimToReco(
0093     const edm::Handle<reco::CaloClusterCollection>& cCCH,
0094     const edm::Handle<ticl::TracksterCollection>& sTCH,
0095     const edm::Handle<CaloParticleCollection>& cPCH,
0096     const ticl::SimToRecoCollection& cPToLCs,
0097     const edm::Handle<SimClusterCollection>& sCCH,
0098     const ticl::SimToRecoCollectionWithSimClusters& sCToLCs) const {
0099   ticl::SimTracksterToRecoCollection returnValue(productGetter_);
0100 
0101   const auto simTracksters = *sTCH.product();
0102   for (size_t tsId = 0; tsId < simTracksters.size(); ++tsId) {
0103     if (simTracksters[tsId].seedID() == cPCH.id()) {
0104       const auto cpId = simTracksters[tsId].seedIndex();
0105       const edm::Ref<CaloParticleCollection> cpRef(cPCH, cpId);
0106       const auto& lcIt = cPToLCs.find(cpRef);
0107       if (lcIt == cPToLCs.end()) {
0108         LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0109             << "CaloParticle Id " << cpId << " not found in LayerCluster association map\n";
0110         continue;
0111       }
0112 
0113       const auto& lcs = lcIt->val;
0114       for (size_t lcId = 0; lcId < lcs.size(); ++lcId) {
0115         const edm::Ref<reco::CaloClusterCollection> lcRef(cCCH, lcId);
0116         const auto lcPair =
0117             std::find_if(std::begin(lcs),
0118                          std::end(lcs),
0119                          [&lcRef](const std::pair<edm::Ref<reco::CaloClusterCollection>, std::pair<float, float>>& p) {
0120                            return p.first == lcRef;
0121                          });
0122         if (lcPair == lcs.end()) {
0123           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0124               << "LayerCluster Id " << lcId << " not found in CaloParticle association map\n";
0125           continue;
0126         } else {
0127           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0128               << "CaloParticle Id: \t" << cpId << "\t LayerCluster Id: \t" << lcPair->first.index() << "\t score \t"
0129               << lcPair->second.second << "\n";
0130           // Fill AssociationMap
0131           returnValue.insert(
0132               edm::Ref<ticl::TracksterCollection>(sTCH, tsId),                             // Ref to TS
0133               std::make_pair(lcRef,                                                        // Pair <Ref to LC,
0134                              std::make_pair(lcPair->second.first, lcPair->second.second))  // pair <energy, score> >
0135           );
0136         }
0137       }
0138     } else if (simTracksters[tsId].seedID() == sCCH.id()) {
0139       const auto scId = simTracksters[tsId].seedIndex();
0140       const edm::Ref<SimClusterCollection> scRef(sCCH, scId);
0141       const auto& lcIt = sCToLCs.find(scRef);
0142       if (lcIt == sCToLCs.end()) {
0143         LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0144             << "SimCluster Id " << scId << " not found in LayerCluster association map\n";
0145         continue;
0146       }
0147 
0148       const auto& lcs = lcIt->val;
0149       for (size_t lcId = 0; lcId < lcs.size(); ++lcId) {
0150         const edm::Ref<reco::CaloClusterCollection> lcRef(cCCH, lcId);
0151         const auto lcPair =
0152             std::find_if(std::begin(lcs),
0153                          std::end(lcs),
0154                          [&lcRef](const std::pair<edm::Ref<reco::CaloClusterCollection>, std::pair<float, float>>& p) {
0155                            return p.first == lcRef;
0156                          });
0157         if (lcPair == lcs.end()) {
0158           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0159               << "LayerCluster Id " << lcId << " not found in SimCluster association map\n";
0160           continue;
0161         } else {
0162           LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0163               << "SimCluster Id: \t" << scId << "\t LayerCluster Id: \t" << lcPair->first.index() << "\t score \t"
0164               << lcPair->second.second << "\n";
0165           // Fill AssociationMap
0166           returnValue.insert(
0167               edm::Ref<ticl::TracksterCollection>(sTCH, tsId),                             // Ref to TS
0168               std::make_pair(lcRef,                                                        // Pair <Ref to LC,
0169                              std::make_pair(lcPair->second.first, lcPair->second.second))  // pair <energy, score> >
0170           );
0171         }
0172       }
0173     } else {
0174       LogDebug("LCToSimTSAssociatorByEnergyScoreImpl")
0175           << "The seedID " << simTracksters[tsId].seedID() << " of SimTrackster " << tsId
0176           << " is neither a CaloParticle nor a SimCluster!\n";
0177     }
0178 
0179   }  // end loop over simTracksters
0180   return returnValue;
0181 }