File indexing completed on 2024-04-06 12:30:46
0001 #ifndef MuonAssociatorByHitsHelper_h
0002 #define MuonAssociatorByHitsHelper_h
0003
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/Common/interface/Ref.h"
0006 #include "DataFormats/TrackReco/interface/Track.h"
0007 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0008 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0009 #include "FWCore/Framework/interface/ConsumesCollector.h"
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "SimDataFormats/Associations/interface/TrackAssociation.h"
0013 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0014 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0015 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
0016 #include "SimMuon/MCTruth/interface/CSCHitAssociator.h"
0017 #include "SimMuon/MCTruth/interface/DTHitAssociator.h"
0018 #include "SimMuon/MCTruth/interface/GEMHitAssociator.h"
0019 #include "SimMuon/MCTruth/interface/RPCHitAssociator.h"
0020 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
0021
0022 #include <vector>
0023 #include <memory>
0024 #include <functional>
0025
0026 class TrackerTopology;
0027
0028 class MuonAssociatorByHitsHelper {
0029 public:
0030 typedef std::pair<uint32_t, EncodedEventId> SimHitIdpr;
0031
0032 typedef std::pair<unsigned int, std::vector<SimHitIdpr>> uint_SimHitIdpr_pair;
0033 typedef std::vector<std::unique_ptr<uint_SimHitIdpr_pair>> MapOfMatchedIds;
0034 typedef std::vector<std::pair<trackingRecHit_iterator, trackingRecHit_iterator>> TrackHitsCollection;
0035
0036 MuonAssociatorByHitsHelper(const edm::ParameterSet &conf);
0037
0038 struct Resources {
0039 Resources(TrackerTopology const *tTopo,
0040 TrackerHitAssociator const *trackerHitAssoc,
0041 CSCHitAssociator const *cscHitAssoc,
0042 DTHitAssociator const *dtHitAssoc,
0043 RPCHitAssociator const *rpcHitAssoc,
0044 GEMHitAssociator const *gemHitAssoc,
0045 std::function<void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics)
0046 : tTopo_(tTopo),
0047 trackerHitAssoc_(trackerHitAssoc),
0048 cscHitAssoc_(cscHitAssoc),
0049 dtHitAssoc_(dtHitAssoc),
0050 rpcHitAssoc_(rpcHitAssoc),
0051 gemHitAssoc_(gemHitAssoc),
0052 diagnostics_(diagnostics) {}
0053
0054 TrackerTopology const *tTopo_;
0055 TrackerHitAssociator const *trackerHitAssoc_;
0056 CSCHitAssociator const *cscHitAssoc_;
0057 DTHitAssociator const *dtHitAssoc_;
0058 RPCHitAssociator const *rpcHitAssoc_;
0059 GEMHitAssociator const *gemHitAssoc_;
0060 std::function<void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics_;
0061 };
0062
0063 struct IndexMatch {
0064 IndexMatch(size_t index, double global_quality) : idx(index), quality(global_quality) {}
0065 size_t idx;
0066 double quality;
0067 bool operator<(const IndexMatch &other) const { return other.quality < quality; }
0068 };
0069 typedef std::map<size_t, std::vector<IndexMatch>> IndexAssociation;
0070
0071 IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &,
0072 const edm::RefVector<TrackingParticleCollection> &,
0073 Resources const &) const;
0074
0075 IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &,
0076 const edm::RefVector<TrackingParticleCollection> &,
0077 Resources const &) const;
0078
0079 private:
0080 void getMatchedIds(MapOfMatchedIds &tracker_matchedIds_valid,
0081 MapOfMatchedIds &muon_matchedIds_valid,
0082 MapOfMatchedIds &tracker_matchedIds_INVALID,
0083 MapOfMatchedIds &muon_matchedIds_INVALID,
0084 int &n_tracker_valid,
0085 int &n_dt_valid,
0086 int &n_csc_valid,
0087 int &n_rpc_valid,
0088 int &n_gem_valid,
0089 int &n_tracker_matched_valid,
0090 int &n_dt_matched_valid,
0091 int &n_csc_matched_valid,
0092 int &n_rpc_matched_valid,
0093 int &n_gem_matched_valid,
0094 int &n_tracker_INVALID,
0095 int &n_dt_INVALID,
0096 int &n_csc_INVALID,
0097 int &n_rpc_INVALID,
0098 int &n_gem_INVALID,
0099 int &n_tracker_matched_INVALID,
0100 int &n_dt_matched_INVALID,
0101 int &n_csc_matched_INVALID,
0102 int &n_rpc_matched_INVALID,
0103 int &n_gem_matched_INVALID,
0104 trackingRecHit_iterator begin,
0105 trackingRecHit_iterator end,
0106 const TrackerHitAssociator *trackertruth,
0107 const DTHitAssociator &dttruth,
0108 const CSCHitAssociator &csctruth,
0109 const RPCHitAssociator &rpctruth,
0110 const GEMHitAssociator &gemtruth,
0111 bool printRts,
0112 const TrackerTopology *) const;
0113
0114 int getShared(MapOfMatchedIds &matchedIds, TrackingParticleCollection::const_iterator trpart) const;
0115
0116 const bool includeZeroHitMuons;
0117 const bool acceptOneStubMatchings;
0118 const bool rejectBadGlobal;
0119 bool UseTracker;
0120 bool UseMuon;
0121 const bool AbsoluteNumberOfHits_track;
0122 unsigned int NHitCut_track;
0123 double EfficiencyCut_track;
0124 double PurityCut_track;
0125 const bool AbsoluteNumberOfHits_muon;
0126 unsigned int NHitCut_muon;
0127 double EfficiencyCut_muon;
0128 double PurityCut_muon;
0129 const bool UsePixels;
0130 const bool UseGrouped;
0131 const bool UseSplitting;
0132 const bool ThreeHitTracksAreSpecial;
0133 const bool dumpDT;
0134
0135 int LayerFromDetid(const DetId &) const;
0136 const TrackingRecHit *getHitPtr(edm::OwnVector<TrackingRecHit>::const_iterator iter) const { return &*iter; }
0137 const TrackingRecHit *getHitPtr(const trackingRecHit_iterator &iter) const { return &**iter; }
0138
0139 std::string write_matched_simtracks(const std::vector<SimHitIdpr> &) const;
0140 };
0141
0142 #endif