Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:47

0001 #ifndef Validation_MuonCSCDigis_CSCDigiMatcher_h
0002 #define Validation_MuonCSCDigis_CSCDigiMatcher_h
0003 
0004 /**\class CSCDigiMatcher
0005 
0006    Description: Matching of Digis to SimTrack in CSC
0007 
0008    Author: Sven Dildick (TAMU), Tao Huang (TAMU)
0009 */
0010 
0011 #include "Validation/MuonHits/interface/CSCSimHitMatcher.h"
0012 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0013 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0014 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0015 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0016 
0017 typedef std::vector<CSCComparatorDigi> CSCComparatorDigiContainer;
0018 typedef std::vector<CSCStripDigi> CSCStripDigiContainer;
0019 typedef std::vector<CSCWireDigi> CSCWireDigiContainer;
0020 
0021 typedef std::vector<std::pair<unsigned int, CSCComparatorDigi> > CSCComparatorDigiDetIdContainer;
0022 typedef std::vector<std::pair<unsigned int, CSCStripDigi> > CSCStripDigiDetIdContainer;
0023 typedef std::vector<std::pair<unsigned int, CSCWireDigi> > CSCWireDigiDetIdContainer;
0024 
0025 class CSCDigiMatcher {
0026 public:
0027   // constructor
0028   CSCDigiMatcher(edm::ParameterSet const& iPS, edm::ConsumesCollector&& iC);
0029 
0030   // destructor
0031   ~CSCDigiMatcher() {}
0032 
0033   // initialize the event
0034   void init(const edm::Event& e, const edm::EventSetup& eventSetup);
0035 
0036   // do the matching
0037   void match(const SimTrack& t, const SimVertex& v);
0038 
0039   // layer detIds with digis
0040   std::set<unsigned int> detIdsComparator(int csc_type = MuonHitHelper::CSC_ALL) const;
0041   std::set<unsigned int> detIdsStrip(int csc_type = MuonHitHelper::CSC_ALL) const;
0042   std::set<unsigned int> detIdsWire(int csc_type = MuonHitHelper::CSC_ALL) const;
0043 
0044   // chamber detIds with digis
0045   std::set<unsigned int> chamberIdsComparator(int csc_type = MuonHitHelper::CSC_ALL) const;
0046   std::set<unsigned int> chamberIdsStrip(int csc_type = MuonHitHelper::CSC_ALL) const;
0047   std::set<unsigned int> chamberIdsWire(int csc_type = MuonHitHelper::CSC_ALL) const;
0048 
0049   // CSC strip digis from a particular layer or chamber
0050   const CSCComparatorDigiContainer& comparatorDigisInDetId(unsigned int) const;
0051   const CSCComparatorDigiContainer& comparatorDigisInChamber(unsigned int) const;
0052 
0053   // CSC strip digis from a particular layer or chamber
0054   const CSCStripDigiContainer& stripDigisInDetId(unsigned int) const;
0055   const CSCStripDigiContainer& stripDigisInChamber(unsigned int) const;
0056 
0057   // CSC wire digis from a particular layer or chamber
0058   const CSCWireDigiContainer& wireDigisInDetId(unsigned int) const;
0059   const CSCWireDigiContainer& wireDigisInChamber(unsigned int) const;
0060 
0061   //total digis, no match required
0062   int totalComparators(unsigned int) const;
0063   int totalStrips(unsigned int) const;
0064   int totalWires(unsigned int) const;
0065 
0066   // #layers with hits
0067   int nLayersWithComparatorInChamber(unsigned int) const;
0068   int nLayersWithStripInChamber(unsigned int) const;
0069   int nLayersWithWireInChamber(unsigned int) const;
0070 
0071   // How many CSC chambers with minimum number of layer with digis did this simtrack get?
0072   int nCoincidenceComparatorChambers(int min_n_layers = 4) const;
0073   int nCoincidenceStripChambers(int min_n_layers = 4) const;
0074   int nCoincidenceWireChambers(int min_n_layers = 4) const;
0075 
0076   std::set<int> comparatorsInDetId(unsigned int) const;
0077   std::set<int> stripsInDetId(unsigned int) const;
0078   std::set<int> wiregroupsInDetId(unsigned int) const;
0079 
0080   // A non-zero max_gap_to_fill parameter would insert extra half-strips or wiregroups
0081   // so that gaps of that size or smaller would be filled.
0082   // E.g., if max_gap_to_fill = 1, and there are digis with strips 4 and 6 in a chamber,
0083   // the resulting set of digis would be 4,5,6
0084   std::set<int> comparatorsInChamber(unsigned int, int max_gap_to_fill = 0) const;
0085   std::set<int> stripsInChamber(unsigned int, int max_gap_to_fill = 0) const;
0086   std::set<int> wiregroupsInChamber(unsigned int, int max_gap_to_fill = 0) const;
0087 
0088   std::shared_ptr<CSCSimHitMatcher> muonSimHitMatcher() const { return muonSimHitMatcher_; }
0089 
0090 private:
0091   // match simtracks to digis
0092   void matchComparatorsToSimTrack(const CSCComparatorDigiCollection& comparators);
0093   void matchStripsToSimTrack(const CSCStripDigiCollection& strips);
0094   void matchWiresToSimTrack(const CSCWireDigiCollection& wires);
0095 
0096   void clear();
0097 
0098   template <class T>
0099   std::set<unsigned int> selectDetIds(const T& digis, int csc_type) const;
0100 
0101   edm::EDGetTokenT<CSCComparatorDigiCollection> comparatorDigiInput_;
0102   edm::EDGetTokenT<CSCStripDigiCollection> stripDigiInput_;
0103   edm::EDGetTokenT<CSCWireDigiCollection> wireDigiInput_;
0104 
0105   edm::Handle<CSCComparatorDigiCollection> comparatorDigisH_;
0106   edm::Handle<CSCStripDigiCollection> stripDigisH_;
0107   edm::Handle<CSCWireDigiCollection> wireDigisH_;
0108 
0109   std::shared_ptr<CSCSimHitMatcher> muonSimHitMatcher_;
0110 
0111   int minBXComparator_, maxBXComparator_;
0112   int minBXStrip_, maxBXStrip_;
0113   int minBXWire_, maxBXWire_;
0114 
0115   int matchDeltaComparator_;
0116   int matchDeltaStrip_;
0117   int matchDeltaWG_;
0118 
0119   int verboseComparator_;
0120   int verboseStrip_;
0121   int verboseWG_;
0122 
0123   std::map<unsigned int, CSCComparatorDigiContainer> detid_to_comparators_;
0124   std::map<unsigned int, CSCComparatorDigiContainer> chamber_to_comparators_;
0125   std::map<unsigned int, int> detid_to_totalcomparators_;
0126 
0127   std::map<unsigned int, CSCStripDigiContainer> detid_to_strips_;
0128   std::map<unsigned int, CSCStripDigiContainer> chamber_to_strips_;
0129   std::map<unsigned int, int> detid_to_totalstrips_;
0130 
0131   std::map<unsigned int, CSCWireDigiContainer> detid_to_wires_;
0132   std::map<unsigned int, CSCWireDigiContainer> chamber_to_wires_;
0133   std::map<unsigned int, int> detid_to_totalwires_;
0134 
0135   CSCComparatorDigiContainer no_comparators_;
0136   CSCStripDigiContainer no_strips_;
0137   CSCWireDigiContainer no_wires_;
0138 };
0139 
0140 template <class T>
0141 std::set<unsigned int> CSCDigiMatcher::selectDetIds(const T& digis, int csc_type) const {
0142   std::set<unsigned int> result;
0143   for (const auto& p : digis) {
0144     const auto& id = p.first;
0145     if (csc_type > 0) {
0146       CSCDetId detId(id);
0147       if (MuonHitHelper::toCSCType(detId.station(), detId.ring()) != csc_type)
0148         continue;
0149     }
0150     result.insert(p.first);
0151   }
0152   return result;
0153 }
0154 
0155 #endif