Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/TracksterToSimTracksterAssociator.h"
0011 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0012 
0013 namespace edm {
0014   class EDProductGetter;
0015 }
0016 
0017 namespace ticl {
0018   // This structure is used for SimTracksters storing its id and the energy fraction of
0019   // a LayerCluster that is related to that SimTrackster. Be careful not to be confused by the fact that
0020   // similar structs are used in other HGCAL associators where the fraction is a hit's fraction.
0021   // The meaning of the operator is extremely important since this struct will be used inside maps and
0022   // other containers and when searching for one particular occurence only the clusterId member will be
0023   // used in the check, skipping the fraction part.
0024   struct lcInfoInTrackster {
0025     bool operator==(const lcInfoInTrackster &o) const { return clusterId == o.clusterId; };
0026     long unsigned int clusterId;
0027     float fraction;
0028     lcInfoInTrackster(long unsigned int cId, float fr) {
0029       clusterId = cId;
0030       fraction = fr;
0031     }
0032   };
0033 
0034   // In this structure, although it contains LayerClusters and per layer information through them,
0035   // most of the information is 3D information. For a simTrackster it stores:
0036   // 1. Its id: simTracksterId.
0037   // 2. The energy related to the SimTrackster. It is the sum of the LayerClusters energy in which a SimCluster
0038   //    contributed. Therefore, there will be energy from each LayerCluster that is disregarded.
0039   // 3. lcs_and_fractions: This is a vector of pairs. The pair is build from the LayerCluster id and the energy
0040   //    fraction of that LayerCluster which contributed to SimTrackster under study. So, be careful this is not the
0041   //    fraction of the hits. This is the fraction of the LayerCluster's energy in which the SimCluster contributed.
0042   //    This quantifies the statement above in 2 about the disregarded energy, by exactly storing the ratio of the
0043   //    reconstructed from SimCluster energy over the total LayerCluster energy.
0044   // 4. A map to save the tracksters id (id is the key) that have at least one LayerCluster in common with the
0045   //    SimTrackster under study together with the energy and score. Energy in this case is defined as the sum of all
0046   //    LayerClusters (shared between the SimTrackster and the trackster) energy (coming from SimCluster of the SimTrackster)
0047   //    times the LayerCluster's fraction in trackster.
0048   struct simTracksterOnLayer {
0049     unsigned int simTracksterId;
0050     float energy = 0;
0051     std::vector<std::pair<unsigned int, float>> lcs_and_fractions;
0052     std::unordered_map<int, std::pair<float, float>> tracksterIdToEnergyAndScore;
0053   };
0054 
0055   // This object connects a Trackster, identified through its id (tsId), with a vector of pairs containing all
0056   // the SimTracksters (via their ids (stIds)) that share at least one LayerCluster. In that pair
0057   // it stores the score (tsId->(stId,score)). Keep in mind that the association is not unique, since there could be
0058   // several instances of the same SimTrackster from several related SimClusters that each contributed to the same Trackster.
0059   typedef std::vector<std::vector<std::pair<unsigned int, std::pair<float, float>>>> tracksterToSimTrackster;
0060   // This is used to save the simTracksterOnLayer structure for all simTracksters.
0061   // It is not exactly what is returned outside, but out of its entries, the output object is build.
0062   typedef std::vector<ticl::simTracksterOnLayer> simTracksterToTrackster;
0063   typedef std::tuple<tracksterToSimTrackster, simTracksterToTrackster> association;
0064 }  // namespace ticl
0065 
0066 class TSToSimTSAssociatorByEnergyScoreImpl : public ticl::TracksterToSimTracksterAssociatorBaseImpl {
0067 public:
0068   explicit TSToSimTSAssociatorByEnergyScoreImpl(edm::EDProductGetter const &,
0069                                                 bool,
0070                                                 std::shared_ptr<hgcal::RecHitTools>,
0071                                                 const std::unordered_map<DetId, const unsigned int> *,
0072                                                 std::vector<const HGCRecHit *> &hits);
0073 
0074   ticl::RecoToSimCollectionSimTracksters associateRecoToSim(
0075       const edm::Handle<ticl::TracksterCollection> &tCH,
0076       const edm::Handle<reco::CaloClusterCollection> &lCCH,
0077       const edm::Handle<ticl::TracksterCollection> &sTCH) const override;
0078 
0079   ticl::SimToRecoCollectionSimTracksters associateSimToReco(
0080       const edm::Handle<ticl::TracksterCollection> &tCH,
0081       const edm::Handle<reco::CaloClusterCollection> &lCCH,
0082       const edm::Handle<ticl::TracksterCollection> &sTCH) const override;
0083 
0084 private:
0085   const bool hardScatterOnly_;
0086   std::shared_ptr<hgcal::RecHitTools> recHitTools_;
0087   const std::unordered_map<DetId, const unsigned int> *hitMap_;
0088   std::vector<const HGCRecHit *> hits_;
0089   unsigned layers_;
0090   edm::EDProductGetter const *productGetter_;
0091   ticl::association makeConnections(const edm::Handle<ticl::TracksterCollection> &tCH,
0092                                     const edm::Handle<reco::CaloClusterCollection> &lCCH,
0093                                     const edm::Handle<ticl::TracksterCollection> &sTCH) const;
0094 };