Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-01 03:54:08

0001 #ifndef Validation_MuonGEMDigis_GEMDigiMatcher_h
0002 #define Validation_MuonGEMDigis_GEMDigiMatcher_h
0003 
0004 /**\class DigiMatcher
0005 
0006  Description: Matching of Digis for SimTrack in GEM
0007 
0008  Author: Vadim Khotilovich, Sven Dildick (TAMU), Tao Huang (TAMU)
0009 */
0010 
0011 #include "Validation/MuonHits/interface/GEMSimHitMatcher.h"
0012 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0013 #include "SimDataFormats/GEMDigiSimLink/interface/GEMDigiSimLink.h"
0014 #include "DataFormats/GEMDigi/interface/GEMDigiCollection.h"
0015 #include "DataFormats/GEMDigi/interface/GEMPadDigiCollection.h"
0016 #include "DataFormats/GEMDigi/interface/GEMPadDigiClusterCollection.h"
0017 #include "DataFormats/GEMDigi/interface/GEMCoPadDigiCollection.h"
0018 #include "DataFormats/Common/interface/DetSetVector.h"
0019 
0020 #include <vector>
0021 #include <map>
0022 #include <set>
0023 #include <unordered_set>
0024 
0025 typedef std::vector<GEMDigiSimLink> GEMDigiSimLinkContainer;
0026 typedef std::vector<GEMDigi> GEMDigiContainer;
0027 typedef std::vector<GEMPadDigi> GEMPadDigiContainer;
0028 typedef std::vector<GEMPadDigiCluster> GEMPadDigiClusterContainer;
0029 typedef std::vector<GEMCoPadDigi> GEMCoPadDigiContainer;
0030 
0031 class GEMDigiMatcher {
0032 public:
0033   // constructor
0034   GEMDigiMatcher(edm::ParameterSet const& iPS, edm::ConsumesCollector&& iC);
0035 
0036   // destructor
0037   ~GEMDigiMatcher() {}
0038 
0039   // initialize the event
0040   void init(const edm::Event& e, const edm::EventSetup& eventSetup);
0041 
0042   // do the matching
0043   void match(const SimTrack& t, const SimVertex& v);
0044 
0045   std::set<unsigned int> detIdsSimLink(int gem_type = MuonHitHelper::GEM_ALL) const;
0046 
0047   // partition GEM detIds with digis
0048   std::set<unsigned int> detIdsDigi(int gem_type = MuonHitHelper::GEM_ALL) const;
0049   std::set<unsigned int> detIdsPad(int gem_type = MuonHitHelper::GEM_ALL) const;
0050   std::set<unsigned int> detIdsCluster(int gem_type = MuonHitHelper::GEM_ALL) const;
0051 
0052   // chamber detIds with digis
0053   std::set<unsigned int> chamberIdsDigi(int gem_type = MuonHitHelper::GEM_ALL) const;
0054   std::set<unsigned int> chamberIdsPad(int gem_type = MuonHitHelper::GEM_ALL) const;
0055   std::set<unsigned int> chamberIdsCluster(int gem_type = MuonHitHelper::GEM_ALL) const;
0056 
0057   // superchamber detIds with digis
0058   std::set<unsigned int> superChamberIdsDigi(int gem_type = MuonHitHelper::GEM_ALL) const;
0059   std::set<unsigned int> superChamberIdsPad(int gem_type = MuonHitHelper::GEM_ALL) const;
0060   std::set<unsigned int> superChamberIdsCluster(int gem_type = MuonHitHelper::GEM_ALL) const;
0061   std::set<unsigned int> superChamberIdsCoPad(int gem_type = MuonHitHelper::GEM_ALL) const;
0062 
0063   const GEMDigiSimLinkContainer& simLinksInDetId(unsigned int) const;
0064 
0065   // GEM digis from a particular partition, chamber or superchamber
0066   const GEMDigiContainer& digisInDetId(unsigned int) const;
0067   const GEMDigiContainer& digisInChamber(unsigned int) const;
0068   const GEMDigiContainer& digisInSuperChamber(unsigned int) const;
0069 
0070   // GEM pads from a particular partition, chamber or superchamber
0071   const GEMPadDigiContainer& padsInDetId(unsigned int) const;
0072   const GEMPadDigiContainer& padsInChamber(unsigned int) const;
0073   const GEMPadDigiContainer& padsInSuperChamber(unsigned int) const;
0074 
0075   // GEM clusters from a particular partition, chamber or superchamber
0076   const GEMPadDigiClusterContainer& clustersInDetId(unsigned int) const;
0077   const GEMPadDigiClusterContainer& clustersInChamber(unsigned int) const;
0078   const GEMPadDigiClusterContainer& clustersInSuperChamber(unsigned int) const;
0079 
0080   // GEM co-pads from a particular partition or superchamber
0081   const GEMCoPadDigiContainer& coPadsInSuperChamber(unsigned int) const;
0082 
0083   const std::map<unsigned int, GEMPadDigiContainer> allPads() const { return detid_to_pads_; }
0084 
0085   // #layers with digis from this simtrack
0086   int nLayersWithDigisInSuperChamber(unsigned int) const;
0087   int nLayersWithPadsInSuperChamber(unsigned int) const;
0088   int nLayersWithClustersInSuperChamber(unsigned int) const;
0089 
0090   /// How many pads in GEM did this simtrack get in total?
0091   int nPads() const;
0092 
0093   /// How many coincidence pads in GEM did this simtrack get in total?
0094   int nCoPads() const;
0095 
0096   std::set<int> stripNumbersInDetId(unsigned int) const;
0097   std::set<int> padNumbersInDetId(unsigned int) const;
0098 
0099   int extrapolateHsfromGEMPad(unsigned int, int) const;
0100   int extrapolateHsfromGEMStrip(unsigned int, int) const;
0101 
0102   // what unique partitions numbers with digis from this simtrack?
0103   std::set<int> partitionNumbers() const;
0104   std::set<int> partitionNumbersWithCoPads() const;
0105 
0106   GlobalPoint getGlobalPointDigi(unsigned int rawId, const GEMDigi& d) const;
0107   GlobalPoint getGlobalPointPad(unsigned int rawId, const GEMPadDigi& tp) const;
0108 
0109   // get the GEMSimHitMatcher
0110   std::shared_ptr<GEMSimHitMatcher> muonSimHitMatcher() { return muonSimHitMatcher_; }
0111 
0112 private:
0113   // match digi simlink to a simtrack (based on track Id and particle type)
0114   void matchDigisSLToSimTrack(const edm::DetSetVector<GEMDigiSimLink>&);
0115   // match digi to a simtrack (based on BX and strip number)
0116   void matchDigisToSimTrack(const GEMDigiCollection&);
0117   // match pad to a simtrack (based on BX and pad number)
0118   void matchPadsToSimTrack(const GEMPadDigiCollection&);
0119   // match pad to a simtrack (based on BX and pad number)
0120   void matchPadsInDetId(const GEMDetId& simhitId, const GEMPadDigiCollection&);
0121   // match cluster to a simtrack (based on BX and pad number)
0122   void matchClustersToSimTrack(const GEMPadDigiClusterCollection&);
0123   // match copad to a simtrack (based on previously matching pads)
0124   void matchCoPadsToSimTrack(const GEMCoPadDigiCollection&);
0125 
0126   void clear();
0127 
0128   edm::EDGetTokenT<edm::DetSetVector<GEMDigiSimLink>> gemSimLinkToken_;
0129   edm::EDGetTokenT<GEMDigiCollection> gemDigiToken_;
0130   edm::EDGetTokenT<GEMPadDigiCollection> gemPadToken_;
0131   edm::EDGetTokenT<GEMPadDigiClusterCollection> gemClusterToken_;
0132   edm::EDGetTokenT<GEMCoPadDigiCollection> gemCoPadToken_;
0133 
0134   edm::Handle<edm::DetSetVector<GEMDigiSimLink>> gemDigisSLH_;
0135   edm::Handle<GEMDigiCollection> gemDigisH_;
0136   edm::Handle<GEMPadDigiCollection> gemPadsH_;
0137   edm::Handle<GEMPadDigiClusterCollection> gemClustersH_;
0138   edm::Handle<GEMCoPadDigiCollection> gemCoPadsH_;
0139 
0140   std::shared_ptr<GEMSimHitMatcher> muonSimHitMatcher_;
0141 
0142   edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geomToken_;
0143   const GEMGeometry* gemGeometry_;
0144 
0145   template <class T>
0146   std::set<unsigned int> selectDetIds(const T&, int) const;
0147 
0148   bool simMuOnly_;
0149   bool discardEleHits_;
0150 
0151   int minBXDigi_, maxBXDigi_;
0152   int minBXPad_, maxBXPad_;
0153   int minBXCluster_, maxBXCluster_;
0154   int minBXCoPad_, maxBXCoPad_;
0155 
0156   int matchDeltaStrip_;
0157 
0158   bool verboseSimLink_;
0159   bool verboseDigi_;
0160   bool verbosePad_;
0161   bool verboseCluster_;
0162   bool verboseCoPad_;
0163 
0164   bool matchToSimLink_;
0165 
0166   // map of raw GEMDetId to containers
0167   std::map<unsigned int, GEMDigiSimLinkContainer> detid_to_simLinks_;
0168 
0169   std::map<unsigned int, GEMDigiContainer> detid_to_digis_;
0170   std::map<unsigned int, GEMDigiContainer> chamber_to_digis_;
0171   std::map<unsigned int, GEMDigiContainer> superchamber_to_digis_;
0172 
0173   std::map<unsigned int, GEMPadDigiContainer> detid_to_pads_;
0174   std::map<unsigned int, GEMPadDigiContainer> chamber_to_pads_;
0175   std::map<unsigned int, GEMPadDigiContainer> superchamber_to_pads_;
0176 
0177   std::map<unsigned int, GEMPadDigiClusterContainer> detid_to_clusters_;
0178   std::map<unsigned int, GEMPadDigiClusterContainer> chamber_to_clusters_;
0179   std::map<unsigned int, GEMPadDigiClusterContainer> superchamber_to_clusters_;
0180 
0181   std::map<unsigned int, GEMCoPadDigiContainer> superchamber_to_copads_;
0182 
0183   GEMDigiSimLinkContainer no_gem_simLinks_;
0184   GEMDigiContainer no_gem_digis_;
0185   GEMPadDigiContainer no_gem_pads_;
0186   GEMPadDigiClusterContainer no_gem_clusters_;
0187   GEMCoPadDigiContainer no_gem_copads_;
0188 };
0189 
0190 template <class T>
0191 std::set<unsigned int> GEMDigiMatcher::selectDetIds(const T& digis, int gem_type) const {
0192   std::set<unsigned int> result;
0193   for (const auto& p : digis) {
0194     const auto& id = p.first;
0195     if (gem_type > 0) {
0196       GEMDetId detId(id);
0197       if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
0198         continue;
0199     }
0200     result.insert(p.first);
0201   }
0202   return result;
0203 }
0204 
0205 #endif