Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-29 23:13:08

0001 // Original Author: Leonardo Cristella
0002 
0003 #include <vector>
0004 #include <map>
0005 #include <unordered_map>
0006 #include <memory>  // shared_ptr
0007 
0008 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0009 #include "DataFormats/HGCRecHit/interface/HGCRecHit.h"
0010 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0011 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
0012 #include "SimDataFormats/Associations/interface/LayerClusterToSimClusterAssociator.h"
0013 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0014 
0015 namespace edm {
0016   class EDProductGetter;
0017 }
0018 
0019 namespace ticl {
0020   // This structure is used both for LayerClusters and SimClusters storing their id and the fraction of a hit
0021   // that belongs to the LayerCluster or SimCluster. The meaning of the operator is extremely important since
0022   // this struct will be used inside maps and other containers and when searching for one particular occurence
0023   // only the clusterId member will be used in the check, skipping the fraction part.
0024   struct detIdInfoInCluster {
0025     bool operator==(const detIdInfoInCluster &o) const { return clusterId == o.clusterId; };
0026     long unsigned int clusterId;
0027     float fraction;
0028     detIdInfoInCluster(long unsigned int cId, float fr) {
0029       clusterId = cId;
0030       fraction = fr;
0031     }
0032   };
0033 
0034   // This introduces a simCluster on layer concept. For a simCluster it stores:
0035   // 1. Its id: simClusterId.
0036   // 2. The energy that the simCluster deposited in a specific layer and it was reconstructed.
0037   // 3. The hits_and_fractions that contributed to that deposition. SimHits that aren't reconstructed
0038   //    and doesn't have any matched rechits are disregarded.
0039   // 4. A map to save the LayerClusters ids (id is the key) that reconstructed at least one SimHit of the simCluster under study
0040   //    together with the energy that the Layercluster reconstructed from the SimClusters and the score. The energy
0041   //    is not the energy of the LayerCluster, but the energy of the LayerCluster coming from the SimCluster.
0042   //    So, there will be energy of the LayerCluster that is disregarded here, since there may be LayerCluster's
0043   //    cells that the SimCluster didn't contribute.
0044   struct simClusterOnCLayer {
0045     unsigned int simClusterId;
0046     float energy = 0;
0047     std::vector<std::pair<DetId, float>> hits_and_fractions;
0048     std::unordered_map<int, std::pair<float, float>> layerClusterIdToEnergyAndScore;
0049   };
0050 
0051   // This object connects a LayerCluster, identified through its id (lcId), with a vector of pairs containing all the SimClusters
0052   // (via their ids (scIds)) that share at least one cell with the LayerCluster. In that pair it
0053   // stores the score (lcId->(scId,score)).
0054   typedef std::vector<std::vector<std::pair<unsigned int, float>>> layerClusterToSimCluster;
0055   // This is used to save the simClusterOnLayer structure for all simClusters in each layer.
0056   // It is not exactly what is returned outside, but out of its entries, the output object is build.
0057   typedef std::vector<std::vector<ticl::simClusterOnCLayer>> simClusterToLayerCluster;
0058   //This is the output of the makeConnections function that contain all the work with SC2LC and LC2SC
0059   //association. It will be read by the relevant associateSimToReco and associateRecoToSim functions to
0060   //provide the final product.
0061   typedef std::tuple<layerClusterToSimCluster, simClusterToLayerCluster> association;
0062 }  // namespace ticl
0063 
0064 template <typename HIT>
0065 class LCToSCAssociatorByEnergyScoreImpl : public ticl::LayerClusterToSimClusterAssociatorBaseImpl {
0066 public:
0067   explicit LCToSCAssociatorByEnergyScoreImpl(edm::EDProductGetter const &,
0068                                              bool,
0069                                              std::shared_ptr<hgcal::RecHitTools>,
0070                                              const std::unordered_map<DetId, const unsigned int> *,
0071                                              std::vector<const HIT *> &hits);
0072 
0073   ticl::RecoToSimCollectionWithSimClusters associateRecoToSim(
0074       const edm::Handle<reco::CaloClusterCollection> &cCH,
0075       const edm::Handle<SimClusterCollection> &sCCH) const override;
0076 
0077   ticl::SimToRecoCollectionWithSimClusters associateSimToReco(
0078       const edm::Handle<reco::CaloClusterCollection> &cCH,
0079       const edm::Handle<SimClusterCollection> &sCCH) const override;
0080 
0081 private:
0082   const bool hardScatterOnly_;
0083   std::shared_ptr<hgcal::RecHitTools> recHitTools_;
0084   const std::unordered_map<DetId, const unsigned int> *hitMap_;
0085   unsigned layers_;
0086   edm::EDProductGetter const *productGetter_;
0087   ticl::association makeConnections(const edm::Handle<reco::CaloClusterCollection> &cCH,
0088                                     const edm::Handle<SimClusterCollection> &sCCH) const;
0089   std::vector<const HIT *> hits_;
0090 };
0091 
0092 extern template class LCToSCAssociatorByEnergyScoreImpl<HGCRecHit>;
0093 extern template class LCToSCAssociatorByEnergyScoreImpl<reco::PFRecHit>;
0094 
0095 using HGCalLCToSCAssociatorByEnergyScoreImpl = LCToSCAssociatorByEnergyScoreImpl<HGCRecHit>;
0096 using BarrelLCToSCAssociatorByEnergyScoreImpl = LCToSCAssociatorByEnergyScoreImpl<reco::PFRecHit>;