Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-01 22:40:52

0001 #ifndef RecoHI_HiTracking_HIMuonTrackingRegionProducer_H
0002 #define RecoHI_HiTracking_HIMuonTrackingRegionProducer_H
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 
0007 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducer.h"
0008 #include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
0009 #include "RecoMuon/GlobalTrackingTools/interface/MuonTrackingRegionBuilder.h"
0010 
0011 #include "DataFormats/TrackReco/interface/Track.h"
0012 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0013 
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 
0017 class HIMuonTrackingRegionProducer : public TrackingRegionProducer {
0018 public:
0019   HIMuonTrackingRegionProducer(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC) {
0020     // get parameters from PSet
0021     theMuonSource = cfg.getParameter<edm::InputTag>("MuonSrc");
0022     theMuonSourceToken = iC.consumes<reco::TrackCollection>(theMuonSource);
0023 
0024     // initialize region builder
0025     edm::ParameterSet regionBuilderPSet = cfg.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
0026     theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet, iC);
0027 
0028     // initialize muon service proxy
0029     edm::ParameterSet servicePSet = cfg.getParameter<edm::ParameterSet>("ServiceParameters");
0030   }
0031 
0032   ~HIMuonTrackingRegionProducer() override {}
0033 
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0035     edm::ParameterSetDescription desc;
0036 
0037     desc.add<edm::InputTag>("MuonSrc", edm::InputTag(""));
0038 
0039     edm::ParameterSetDescription descRegion;
0040     MuonTrackingRegionBuilder::fillDescriptionsOffline(descRegion);
0041     desc.add("MuonTrackingRegionBuilder", descRegion);
0042 
0043     edm::ParameterSetDescription descService;
0044     descService.setAllowAnything();
0045     desc.add<edm::ParameterSetDescription>("ServiceParameters", descService);
0046 
0047     descriptions.add("HiTrackingRegionEDProducer", desc);
0048   }
0049 
0050   std::vector<std::unique_ptr<TrackingRegion> > regions(const edm::Event& ev,
0051                                                         const edm::EventSetup& es) const override {
0052     // initialize output vector of tracking regions
0053     std::vector<std::unique_ptr<TrackingRegion> > result;
0054 
0055     // initialize the region builder
0056     theRegionBuilder->setEvent(ev, es);
0057 
0058     // get stand-alone muon collection
0059     edm::Handle<reco::TrackCollection> muonH;
0060     ev.getByToken(theMuonSourceToken, muonH);
0061 
0062     // loop over all muons and add a tracking region for each
0063     // that passes the requirements specified to theRegionBuilder
0064     unsigned int nMuons = muonH->size();
0065     //std::cout << "there are " << nMuons << " muon(s)" << std::endl;
0066 
0067     // TO DO: this can be extended further to a double-loop
0068     // over all combinations of muons, returning tracking regions
0069     // for pairs that pass some loose invariant mass cuts
0070     for (unsigned int imu = 0; imu < nMuons; imu++) {
0071       reco::TrackRef muRef(muonH, imu);
0072       //std::cout << "muon #" << imu << ": pt=" << muRef->pt() << std::endl;
0073       result.push_back(theRegionBuilder->region(muRef));
0074     }
0075 
0076     return result;
0077   }
0078 
0079 private:
0080   edm::InputTag theMuonSource;
0081   edm::EDGetTokenT<reco::TrackCollection> theMuonSourceToken;
0082   MuonTrackingRegionBuilder* theRegionBuilder;
0083 };
0084 
0085 #endif