Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-23 22:40:21

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