Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-26 22:39:24

0001 #ifndef DQM_GEM_GEMEfficiencyAnalyzer_h
0002 #define DQM_GEM_GEMEfficiencyAnalyzer_h
0003 
0004 /** \class GEMEfficiencyAnalyzer
0005  *
0006  * DQM monitoring source for GEM efficiency and resolution
0007  * based on https://github.com/CPLUOS/MuonPerformance/blob/master/MuonAnalyser/plugins/SliceTestEfficiencyAnalysis.cc
0008  *
0009  * TODO muonEta{Min,Max}Cut{GE11,GE21,GE0} depending on a magnetic field for
0010  *      a cosmic scenario
0011  * TODO cscForGE21, cscForGE0
0012  * TODO use "StraightLinePropagator" if B=0 for a cosmic scenario
0013  *
0014  * \author Seungjin Yang <seungjin.yang@cern.ch>
0015  */
0016 
0017 #include "DQM/GEM/interface/GEMDQMEfficiencySourceBase.h"
0018 #include "FWCore/Utilities/interface/EDGetToken.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 #include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h"
0022 #include "DataFormats/PatCandidates/interface/Muon.h"
0023 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0024 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0025 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0026 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0027 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0028 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0029 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0030 
0031 class GEMEfficiencyAnalyzer : public GEMDQMEfficiencySourceBase {
0032 public:
0033   explicit GEMEfficiencyAnalyzer(const edm::ParameterSet &);
0034   ~GEMEfficiencyAnalyzer() override;
0035   static void fillDescriptions(edm::ConfigurationDescriptions &);
0036 
0037   // currently only for STA muons
0038   enum class StartingStateType {
0039     kOutermostMeasurementState = 0,
0040     kInnermostMeasurementState,
0041     kStateOnSurfaceWithCSCSegment,
0042     kAlignmentStyle,
0043   };
0044 
0045   // Define the metric as the smaller the absolute value, the better the matching.
0046   enum class MatchingMetric {
0047     kDeltaPhi = 0,  // computeDeltaPhi
0048     kRdPhi,         // computeRdPhi
0049   };
0050 
0051   // https://github.com/cms-sw/cmssw/blob/CMSSW_12_4_0_pre3/Configuration/Applications/python/ConfigBuilder.py#L35
0052   enum class ScenarioOption {
0053     kPP = 0,
0054     kCosmics,
0055     kHeavyIons,
0056   };
0057 
0058   struct GEMLayer {
0059     GEMLayer(Disk::DiskPointer disk, std::vector<const GEMChamber *> chambers, GEMDetId id)
0060         : disk(disk), chambers(chambers), id(id) {}
0061     Disk::DiskPointer disk;
0062     std::vector<const GEMChamber *> chambers;
0063     GEMDetId id;
0064   };
0065 
0066   using StartingState = std::tuple<bool, TrajectoryStateOnSurface, DetId>;
0067 
0068 protected:
0069   void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
0070   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0071   void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override;
0072 
0073 private:
0074   StartingStateType getStartingStateType(const std::string);
0075   MatchingMetric getMatchingMetric(const std::string);
0076   reco::Muon::MuonTrackType getMuonTrackType(const std::string);
0077   ScenarioOption getScenarioOption(const std::string);
0078 
0079   void buildGEMLayers(const GEMGeometry *);
0080 
0081   bool checkPropagationDirection(const reco::Track *, const GEMLayer &);
0082 
0083   StartingState buildStartingState(const reco::Muon &, const reco::TransientTrack &, const GEMLayer &);
0084   StartingState getInnermostMeasurementState(const reco::TransientTrack &);
0085   StartingState getOutermostMeasurementState(const reco::TransientTrack &);
0086   StartingState buildStateOnSurfaceWithCSCSegment(const reco::Muon &, const reco::TransientTrack &, const GEMLayer &);
0087   StartingState buildStartingStateAlignmentStyle(const reco::Muon &, const reco::TransientTrack &, const GEMLayer &);
0088 
0089   // for kStateOnSurfaceWithCSCSegment and AlignmentStyle
0090   const CSCSegment *findCSCSegment(const reco::Muon &, const reco::TransientTrack &, const GEMLayer &);
0091   const CSCSegment *findCSCSegmentBeam(const reco::TransientTrack &, const GEMLayer &);
0092   const CSCSegment *findCSCSegmentCosmics(const reco::Muon &, const GEMLayer &);
0093   bool isMuonSubdetAllowed(const DetId &, const int);
0094   bool isCSCAllowed(const CSCDetId &, const int);
0095 
0096   bool checkBounds(const Plane &, const GlobalPoint &);
0097   bool checkBounds(const Plane &, const GlobalPoint &, const GlobalError &, float);
0098   const GEMEtaPartition *findEtaPartition(const GlobalPoint &,
0099                                           const GlobalError &,
0100                                           const std::vector<const GEMChamber *> &);
0101 
0102   float computeRdPhi(const GlobalPoint &, const LocalPoint &, const GEMEtaPartition *);
0103   float computeDeltaPhi(const GlobalPoint &, const LocalPoint &, const GEMEtaPartition *);
0104   float computeMatchingMetric(const GlobalPoint &, const LocalPoint &, const GEMEtaPartition *);
0105 
0106   std::pair<const GEMRecHit *, float> findClosestHit(const GlobalPoint &,
0107                                                      const GEMRecHitCollection::range &,
0108                                                      const GEMEtaPartition *);
0109 
0110   // some helpers
0111   inline bool isInsideOut(const reco::Track &);
0112 
0113   //////////////////////////////////////////////////////////////////////////////
0114   // const data members initialized in the member initializer list
0115   // mainly retrieved from edm::ParameterSet
0116   //////////////////////////////////////////////////////////////////////////////
0117   // ES
0118   const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> kGEMGeometryTokenBeginRun_;
0119   const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> kTransientTrackBuilderToken_;
0120   // ED
0121   const edm::EDGetTokenT<GEMRecHitCollection> kGEMRecHitCollectionToken_;
0122   const edm::EDGetTokenT<edm::View<reco::Muon> > kMuonViewToken_;
0123   //
0124   const std::string kMuonTrackTypeName_;
0125   const reco::Muon::MuonTrackType kMuonTrackType_;
0126   const TString kMuonName_;
0127   const std::string kFolder_;
0128   const ScenarioOption kScenario_;
0129   // cuts
0130   const StartingStateType kStartingStateType_;
0131   const std::vector<std::vector<int> > kMuonSubdetForGEM_;
0132   const std::vector<std::vector<int> > kCSCForGEM_;  // when using StartingStateType::kStateOnSurfaceWithCSCSegment
0133   const float kMuonSegmentMatchDRCut_;               // for cosmics
0134 
0135   const std::vector<double> kMuonPtMinCuts_;   // station as index
0136   const std::vector<double> kMuonEtaMinCuts_;  // station as index
0137   const std::vector<double> kMuonEtaMaxCuts_;  // station as index
0138   const float kPropagationErrorRCut_;          // cm
0139   const float kPropagationErrorPhiCut_;        // degree
0140   const float kBoundsErrorScale_;              // TODO doc
0141   // matching
0142   const MatchingMetric kMatchingMetric_;
0143   const float kMatchingCut_;
0144   // for MinotorElement
0145   const std::vector<double> kMuonPtBins_;  // station as index
0146   const std::vector<int> kMuonEtaNbins_;   // station as index
0147   const std::vector<double> kMuonEtaLow_;  // station as index
0148   const std::vector<double> kMuonEtaUp_;   // station as index
0149 
0150   // const
0151   const bool kModeDev_;
0152 
0153   //////////////////////////////////////////////////////////////////////////////
0154   // const data members
0155   // FIXME static?
0156   //////////////////////////////////////////////////////////////////////////////
0157   // https://github.com/cms-sw/cmssw/blob/CMSSW_12_4_0_pre3/DataFormats/CSCRecHit/interface/CSCSegment.h#L60
0158   const int kCSCSegmentDimension_ = 4;
0159 
0160   //////////////////////////////////////////////////////////////////////////////
0161   // non-const data members
0162   //////////////////////////////////////////////////////////////////////////////
0163   std::unique_ptr<MuonServiceProxy> muon_service_;
0164   std::vector<GEMLayer> gem_layers_;
0165 
0166   // montitor elements
0167   // XXX how about introducing EffPair ?
0168   MEMap me_chamber_ieta_, me_chamber_ieta_matched_;
0169   MEMap me_muon_pt_, me_muon_pt_matched_;
0170   MEMap me_muon_eta_, me_muon_eta_matched_;
0171   MEMap me_muon_phi_, me_muon_phi_matched_;
0172   MEMap me_residual_phi_;  // in global
0173   // dev mode
0174   MEMap me_matching_metric_all_;
0175   MEMap me_matching_metric_;
0176   MEMap me_residual_phi_muon_;      // in global
0177   MEMap me_residual_phi_antimuon_;  // in global
0178   MEMap me_residual_x_;             // in local
0179   MEMap me_residual_y_;             // in global
0180   MEMap me_residual_strip_;
0181   MEMap me_prop_path_length_, me_prop_path_length_matched_;
0182   MEMap me_prop_err_r_, me_prop_err_r_matched_;
0183   MEMap me_prop_err_phi_, me_prop_err_phi_matched_;
0184   MEMap me_muon_pt_all_, me_muon_pt_all_matched_;
0185   MEMap me_muon_eta_all_, me_muon_eta_all_matched_;
0186   MEMap me_muon_charge_, me_muon_charge_matched_;
0187   MEMap me_cutflow_, me_cutflow_matched_;
0188 };
0189 
0190 #endif  // DQM_GEM_GEMEfficiencyAnalyzer_h