Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-01 03:29:18

0001 // -*- C++ -*-
0002 //
0003 // Package:    MuonAlignmentPreFilter
0004 // Class:      MuonAlignmentPreFilter
0005 //
0006 /**\class MuonAlignmentPreFilter
0007 
0008  Description: pre-select events that are worth considering in muon alignment 
0009 
0010  $Id:$
0011 */
0012 
0013 #include <memory>
0014 
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/stream/EDFilter.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 
0024 #include "DataFormats/TrackReco/interface/Track.h"
0025 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0026 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0027 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0028 #include "DataFormats/DetId/interface/DetId.h"
0029 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0030 
0031 class MuonAlignmentPreFilter : public edm::stream::EDFilter<> {
0032 public:
0033   explicit MuonAlignmentPreFilter(const edm::ParameterSet&);
0034   ~MuonAlignmentPreFilter() override = default;
0035   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0036 
0037 private:
0038   bool filter(edm::Event&, const edm::EventSetup&) override;
0039 
0040   // ----------member data ---------------------------
0041   const edm::InputTag m_tracksTag;
0042   const double m_minTrackPt;
0043   const double m_minTrackP;
0044   const bool m_allowTIDTEC;
0045   const int m_minTrackerHits;
0046   const int m_minDTHits;
0047   const int m_minCSCHits;
0048   const double m_minTrackEta;
0049   const double m_maxTrackEta;
0050   const edm::EDGetTokenT<reco::TrackCollection> m_trackToken;
0051 };
0052 
0053 MuonAlignmentPreFilter::MuonAlignmentPreFilter(const edm::ParameterSet& cfg)
0054     : m_tracksTag(cfg.getParameter<edm::InputTag>("tracksTag")),
0055       m_minTrackPt(cfg.getParameter<double>("minTrackPt")),
0056       m_minTrackP(cfg.getParameter<double>("minTrackP")),
0057       m_allowTIDTEC(cfg.getParameter<bool>("allowTIDTEC")),
0058       m_minTrackerHits(cfg.getParameter<int>("minTrackerHits")),
0059       m_minDTHits(cfg.getParameter<int>("minDTHits")),
0060       m_minCSCHits(cfg.getParameter<int>("minCSCHits")),
0061       m_minTrackEta(cfg.getParameter<double>("minTrackEta")),
0062       m_maxTrackEta(cfg.getParameter<double>("maxTrackEta")),
0063       m_trackToken(consumes<reco::TrackCollection>(m_tracksTag)) {}
0064 
0065 void MuonAlignmentPreFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0066   edm::ParameterSetDescription desc;
0067   desc.add<edm::InputTag>("tracksTag", edm::InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon"));
0068   desc.add<double>("minTrackPt", 20.);
0069   desc.add<double>("minTrackP", 0.);
0070   desc.add<int>("minTrackerHits", 10);
0071   desc.add<int>("minDTHits", 6);
0072   desc.add<int>("minCSCHits", 4);
0073   desc.add<bool>("allowTIDTEC", true);
0074   desc.add<double>("minTrackEta", -2.4);
0075   desc.add<double>("maxTrackEta", 2.4);
0076   descriptions.add("MuonAlignmentPreFilter", desc);
0077 }
0078 
0079 bool MuonAlignmentPreFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0080   const edm::Handle<reco::TrackCollection>& trackColl = iEvent.getHandle(m_trackToken);
0081 
0082   // check if there's at least one interesting track:
0083 
0084   for (reco::TrackCollection::const_iterator it = trackColl->begin(); it != trackColl->end(); it++) {
0085     int tracker_numHits = 0;
0086     bool contains_TIDTEC = false;
0087     int dt_numHits = 0;
0088     int csc_numHits = 0;
0089 
0090     const reco::Track* track = &(*it);
0091 
0092     if (track->pt() < m_minTrackPt || track->p() < m_minTrackP)
0093       continue;
0094     if (track->eta() < m_minTrackEta || track->eta() > m_maxTrackEta)
0095       continue;
0096 
0097     for (auto const& hit : track->recHits()) {
0098       DetId id = hit->geographicalId();
0099       if (id.det() == DetId::Tracker) {
0100         tracker_numHits++;
0101         if (id.subdetId() == StripSubdetector::TID || id.subdetId() == StripSubdetector::TEC)
0102           contains_TIDTEC = true;
0103       }
0104 
0105       if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT)
0106         dt_numHits++;
0107       if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC)
0108         csc_numHits++;
0109     }
0110 
0111     if ((m_allowTIDTEC || !contains_TIDTEC) && m_minTrackerHits <= tracker_numHits &&
0112         (m_minDTHits <= dt_numHits || m_minCSCHits <= csc_numHits))
0113       return true;
0114   }
0115   return false;
0116 }
0117 
0118 //define this as a plug-in
0119 DEFINE_FWK_MODULE(MuonAlignmentPreFilter);