Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:36

0001 // -*- C++ -*-
0002 //
0003 // Package:    METProducers
0004 // Class:      MuonMETValueMapProducer
0005 //
0006 //
0007 // Original Author:  Puneeth Kalavase
0008 //         Created:  Sun Mar 15 11:33:20 CDT 2009
0009 //
0010 
0011 /*
0012    The meanings ofr reco::MuonMETCorrectionData::Type
0013    NotUsed = 0:
0014      The muon is not used to correct the MET by default
0015 
0016    CombinedTrackUsed = 1, GlobalTrackUsed = 1:
0017 
0018      The muon is used to correct the MET. The Global pt is used. For
0019      backward compatibility only
0020 
0021    InnerTrackUsed = 2, TrackUsed = 2:
0022      The muon is used to correct the MET. The tracker pt is used. For
0023      backward compatibility only
0024 
0025    OuterTrackUsed = 3, StandAloneTrackUsed = 3:
0026      The muon is used to correct the MET. The standalone pt is used.
0027      For backward compatibility only. In general, the flag should
0028      never be 3. You do not want to correct the MET using the pt
0029      measurement from the standalone system (unless you really know
0030      what you're doing.
0031 
0032    TreatedAsPion = 4:
0033      The muon was treated as a Pion. This is used for the tcMET
0034      producer
0035 
0036    MuonP4V4QUsed = 5, MuonCandidateValuesUsed = 5:
0037      The default fit is used, i.e, we get the pt from muon->pt
0038 
0039    (see DataFormats/MuonReco/interface/MuonMETCorrectionData.h)
0040 */
0041 
0042 //____________________________________________________________________________||
0043 #include "RecoMET/METProducers/interface/MuonMETValueMapProducer.h"
0044 
0045 #include "RecoMET/METAlgorithms/interface/MuonMETAlgo.h"
0046 #include "DataFormats/TrackReco/interface/Track.h"
0047 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0048 #include "DataFormats/Common/interface/ValueMap.h"
0049 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0050 #include "FWCore/Framework/interface/MakerMacros.h"
0051 
0052 //____________________________________________________________________________||
0053 namespace cms {
0054 
0055   MuonMETValueMapProducer::MuonMETValueMapProducer(const edm::ParameterSet& iConfig)
0056       : minPt_(iConfig.getParameter<double>("minPt")),
0057         maxEta_(iConfig.getParameter<double>("maxEta")),
0058         isAlsoTkMu_(iConfig.getParameter<bool>("isAlsoTkMu")),
0059         maxNormChi2_(iConfig.getParameter<double>("maxNormChi2")),
0060         maxd0_(iConfig.getParameter<double>("maxd0")),
0061         minnHits_(iConfig.getParameter<int>("minnHits")),
0062         minnValidStaHits_(iConfig.getParameter<int>("minnValidStaHits")),
0063         useTrackAssociatorPositions_(iConfig.getParameter<bool>("useTrackAssociatorPositions")),
0064         useHO_(iConfig.getParameter<bool>("useHO")),
0065         towerEtThreshold_(iConfig.getParameter<double>("towerEtThreshold")),
0066         useRecHits_(iConfig.getParameter<bool>("useRecHits")) {
0067     muonToken_ = consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("muonInputTag"));
0068     beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
0069     magFieldToken_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
0070 
0071     edm::ParameterSet trackAssociatorParams = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
0072     edm::ConsumesCollector iC = consumesCollector();
0073     trackAssociatorParameters_.loadParameters(trackAssociatorParams, iC);
0074     trackAssociator_.useDefaultPropagator();
0075 
0076     produces<edm::ValueMap<reco::MuonMETCorrectionData>>("muCorrData");
0077   }
0078 
0079   //____________________________________________________________________________||
0080   void MuonMETValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0081     edm::Handle<edm::View<reco::Muon>> muons;
0082     iEvent.getByToken(muonToken_, muons);
0083 
0084     edm::Handle<reco::BeamSpot> beamSpot;
0085     iEvent.getByToken(beamSpotToken_, beamSpot);
0086 
0087     const MagneticField& magneticField = iSetup.getData(magFieldToken_);
0088 
0089     double bfield = magneticField.inTesla(GlobalPoint(0., 0., 0.)).z();
0090 
0091     std::vector<reco::MuonMETCorrectionData> muCorrDataList;
0092 
0093     for (edm::View<reco::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
0094       double deltax = 0.0;
0095       double deltay = 0.0;
0096       determine_deltax_deltay(deltax, deltay, *muon, bfield, magneticField, iEvent, iSetup);
0097 
0098       reco::MuonMETCorrectionData::Type muCorrType = decide_correction_type(*muon, beamSpot->position());
0099 
0100       reco::MuonMETCorrectionData muMETCorrData(muCorrType, deltax, deltay);
0101       muCorrDataList.push_back(muMETCorrData);
0102     }
0103 
0104     auto valueMapMuCorrData = std::make_unique<edm::ValueMap<reco::MuonMETCorrectionData>>();
0105 
0106     edm::ValueMap<reco::MuonMETCorrectionData>::Filler dataFiller(*valueMapMuCorrData);
0107 
0108     dataFiller.insert(muons, muCorrDataList.begin(), muCorrDataList.end());
0109     dataFiller.fill();
0110 
0111     iEvent.put(std::move(valueMapMuCorrData), "muCorrData");
0112   }
0113 
0114   //____________________________________________________________________________||
0115   void MuonMETValueMapProducer::determine_deltax_deltay(double& deltax,
0116                                                         double& deltay,
0117                                                         const reco::Muon& muon,
0118                                                         double bfield,
0119                                                         const MagneticField& magneticField,
0120                                                         edm::Event& iEvent,
0121                                                         const edm::EventSetup& iSetup) {
0122     reco::TrackRef mu_track;
0123     if (muon.isGlobalMuon())
0124       mu_track = muon.globalTrack();
0125     else if (muon.isTrackerMuon() || muon.isRPCMuon() || muon.isGEMMuon() || muon.isME0Muon())
0126       mu_track = muon.innerTrack();
0127     else
0128       mu_track = muon.outerTrack();
0129 
0130     TrackDetMatchInfo info = trackAssociator_.associate(
0131         iEvent, iSetup, trackAssociator_.getFreeTrajectoryState(&magneticField, *mu_track), trackAssociatorParameters_);
0132 
0133     MuonMETAlgo alg;
0134     alg.GetMuDepDeltas(
0135         &muon, info, useTrackAssociatorPositions_, useRecHits_, useHO_, towerEtThreshold_, deltax, deltay, bfield);
0136   }
0137 
0138   //____________________________________________________________________________||
0139   reco::MuonMETCorrectionData::Type MuonMETValueMapProducer::decide_correction_type(
0140       const reco::Muon& muon, const math::XYZPoint& beamSpotPosition) {
0141     if (should_type_MuonCandidateValuesUsed(muon, beamSpotPosition))
0142       return reco::MuonMETCorrectionData::Type::MuonCandidateValuesUsed;
0143 
0144     return reco::MuonMETCorrectionData::Type::NotUsed;
0145   }
0146 
0147   //____________________________________________________________________________||
0148   bool MuonMETValueMapProducer::should_type_MuonCandidateValuesUsed(const reco::Muon& muon,
0149                                                                     const math::XYZPoint& beamSpotPosition) {
0150     if (!muon.isGlobalMuon())
0151       return false;
0152     if (!muon.isTrackerMuon() && isAlsoTkMu_)
0153       return false;
0154     reco::TrackRef globTk = muon.globalTrack();
0155     reco::TrackRef siTk = muon.innerTrack();
0156 
0157     if (muon.pt() < minPt_ || fabs(muon.eta()) > maxEta_)
0158       return false;
0159     if (globTk->chi2() / globTk->ndof() > maxNormChi2_)
0160       return false;
0161     if (fabs(globTk->dxy(beamSpotPosition)) > fabs(maxd0_))
0162       return false;
0163     if (siTk->numberOfValidHits() < minnHits_)
0164       return false;
0165     if (globTk->hitPattern().numberOfValidMuonHits() < minnValidStaHits_)
0166       return false;
0167     return true;
0168   }
0169 
0170   //____________________________________________________________________________||
0171 }  // namespace cms
0172 
0173 //____________________________________________________________________________||