Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-07 22:45:14

0001 // Original Author: Marco Rovere
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/LayerClusterToCaloParticleAssociator.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 CaloParticles storing their id and the fraction of a hit
0019   // that belongs to the LayerCluster or CaloParticle. 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 CaloParticle on layer concept. For a CaloParticle it stores:
0033   // 1. Its id: caloParticleId.
0034   // 2. The energy that the CaloParticle 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. Keep in mind that since a CaloParticle
0037   //    should most probably have more than one SimCluster, all different contributions from the same CaloParticle
0038   //    to a single hit are merged into a single entry, with the fractions properly summed.
0039   // 4. A map to save the LayerClusters ids (id is the key) that reconstructed at least one SimHit of the CaloParticle under study
0040   //    together with the energy that the LayerCluster reconstructed from the CaloParticle and the score. The energy
0041   //    is not the energy of the LayerCluster, but the energy of the LayerCluster coming from the CaloParticle.
0042   //    So, there will be energy of the LayerCluster that is disregarded here, since there may be LayerCluster's
0043   //    cells that the CaloParticle didn't contribute.
0044   struct caloParticleOnLayer {
0045     unsigned int caloParticleId;
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 CaloParticles
0052   // (via their ids (cpIds)) that share at least one cell with the LayerCluster. In that pair it
0053   // stores the score (lcId->(cpId,score)). Keep in mind that the association is not unique, since there could be several instances
0054   // of the same CaloParticle from several related SimClusters that each contributed to the same LayerCluster.
0055   typedef std::vector<std::vector<std::pair<unsigned int, float>>> layerClusterToCaloParticle;
0056   // This is used to save the caloParticleOnLayer structure for all CaloParticles in each layer.
0057   // It is not exactly what is returned outside, but out of its entries, the output object is build.
0058   typedef std::vector<std::vector<hgcal::caloParticleOnLayer>> caloParticleToLayerCluster;
0059   //This is the output of the makeConnections function that contain all the work with CP2LC and LC2CP
0060   //association. It will be read by the relevant associateSimToReco and associateRecoToSim functions to
0061   //provide the final product.
0062   typedef std::tuple<layerClusterToCaloParticle, caloParticleToLayerCluster> association;
0063 }  // namespace hgcal
0064 
0065 class LCToCPAssociatorByEnergyScoreImpl : public hgcal::LayerClusterToCaloParticleAssociatorBaseImpl {
0066 public:
0067   explicit LCToCPAssociatorByEnergyScoreImpl(edm::EDProductGetter const &,
0068                                              bool,
0069                                              std::shared_ptr<hgcal::RecHitTools>,
0070                                              const std::unordered_map<DetId, const HGCRecHit *> *);
0071 
0072   hgcal::RecoToSimCollection associateRecoToSim(const edm::Handle<reco::CaloClusterCollection> &cCH,
0073                                                 const edm::Handle<CaloParticleCollection> &cPCH) const override;
0074 
0075   hgcal::SimToRecoCollection associateSimToReco(const edm::Handle<reco::CaloClusterCollection> &cCH,
0076                                                 const edm::Handle<CaloParticleCollection> &cPCH) const override;
0077 
0078 private:
0079   const bool hardScatterOnly_;
0080   std::shared_ptr<hgcal::RecHitTools> recHitTools_;
0081   const std::unordered_map<DetId, const HGCRecHit *> *hitMap_;
0082   unsigned layers_;
0083   edm::EDProductGetter const *productGetter_;
0084   hgcal::association makeConnections(const edm::Handle<reco::CaloClusterCollection> &cCH,
0085                                      const edm::Handle<CaloParticleCollection> &cPCH) const;
0086 };